Asterisk - The Open Source Telephony Project GIT-master-a358458
res_pjsip_one_touch_record_info.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2013, malleable, llc.
5 *
6 * Sean Bright <sean@malleable.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*** MODULEINFO
20 <depend>pjproject</depend>
21 <depend>res_pjsip</depend>
22 <depend>res_pjsip_session</depend>
23 <support_level>core</support_level>
24***/
25
26#include "asterisk.h"
27
28#include <pjsip.h>
29#include <pjsip_ua.h>
30
31#include "asterisk/features.h"
32#include "asterisk/res_pjsip.h"
34#include "asterisk/module.h"
36
37static void send_response(struct ast_sip_session *session, int code, struct pjsip_rx_data *rdata)
38{
39 pjsip_tx_data *tdata;
40
41 if (pjsip_dlg_create_response(session->inv_session->dlg, rdata, code, NULL, &tdata) == PJ_SUCCESS) {
42 struct pjsip_transaction *tsx = pjsip_rdata_get_tsx(rdata);
43
44 pjsip_dlg_send_response(session->inv_session->dlg, tsx, tdata);
45 }
46}
47
48static int handle_incoming_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
49{
50 static const pj_str_t rec_str = { "Record", 6 };
51 pjsip_generic_string_hdr *record;
52 int feature_res;
53 char feature_code[AST_FEATURE_MAX_LEN];
54 const char *feature;
55 char *digit;
56
57 record = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &rec_str, NULL);
58
59 /* If we don't have Record header, we have nothing to do */
60 if (!record) {
61 return 0;
62 }
63
64 if (!pj_stricmp2(&record->hvalue, "on")) {
65 feature = session->endpoint->info.recording.onfeature;
66 } else if (!pj_stricmp2(&record->hvalue, "off")) {
67 feature = session->endpoint->info.recording.offfeature;
68 } else {
69 /* Don't send response because another module may handle this */
70 return 0;
71 }
72
73 if (!session->channel) {
74 send_response(session, 481, rdata);
75 return 1;
76 }
77
78 /* Is this endpoint configured with One Touch Recording? */
79 if (!session->endpoint->info.recording.enabled || ast_strlen_zero(feature)) {
80 send_response(session, 403, rdata);
81 return 1;
82 }
83
84 ast_channel_lock(session->channel);
85 feature_res = ast_get_feature(session->channel, feature, feature_code, sizeof(feature_code));
87
88 if (feature_res || ast_strlen_zero(feature_code)) {
89 send_response(session, 403, rdata);
90 return 1;
91 }
92
93 for (digit = feature_code; *digit; ++digit) {
94 struct ast_frame f = { AST_FRAME_DTMF, .subclass.integer = *digit, .len = 100 };
95 ast_queue_frame(session->channel, &f);
96 }
97
98 send_response(session, 200, rdata);
99
100 return 1;
101}
102
104 .method = "INFO",
106 .incoming_request = handle_incoming_request,
107};
108
109static int load_module(void)
110{
112
114}
115
116static int unload_module(void)
117{
119 return 0;
120}
121
122AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP INFO One Touch Recording Support",
123 .support_level = AST_MODULE_SUPPORT_CORE,
124 .load = load_module,
125 .unload = unload_module,
126 .load_pri = AST_MODPRI_APP_DEPEND,
127 .requires = "res_pjsip,res_pjsip_session",
char digit
Asterisk main include file. File version handling, generic pbx functions.
static struct ast_mansession session
#define ast_channel_lock(chan)
Definition: channel.h:2922
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel's frame queue.
Definition: channel.c:1139
#define ast_channel_unlock(chan)
Definition: channel.h:2923
Call Parking and Pickup API Includes code and algorithms from the Zapata library.
#define AST_FEATURE_MAX_LEN
int ast_get_feature(struct ast_channel *chan, const char *feature, char *buf, size_t len)
Get the DTMF code for a call feature.
#define AST_FRAME_DTMF
Asterisk module definitions.
@ AST_MODFLAG_LOAD_ORDER
Definition: module.h:317
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:543
@ AST_MODPRI_APP_DEPEND
Definition: module.h:328
@ AST_MODULE_SUPPORT_CORE
Definition: module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_SIP_SUPPLEMENT_PRIORITY_FIRST
Definition: res_pjsip.h:3181
static void send_response(struct ast_sip_session *session, int code, struct pjsip_rx_data *rdata)
static int handle_incoming_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
static int load_module(void)
static int unload_module(void)
static struct ast_sip_session_supplement info_supplement
#define ast_sip_session_register_supplement(supplement)
void ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement)
Unregister a an supplement to SIP session processing.
Definition: pjsip_session.c:63
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Data structure associated with a single frame of data.
A supplement to SIP message processing.
A structure describing a SIP session.