Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Functions | Variables
res_pjsip_dtmf_info.c File Reference
#include "asterisk.h"
#include <pjsip.h>
#include <pjsip_ua.h>
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_session.h"
#include "asterisk/module.h"
Include dependency graph for res_pjsip_dtmf_info.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int dtmf_info_incoming_request (struct ast_sip_session *session, struct pjsip_rx_data *rdata)
 
static char get_event (const char *c)
 
static int is_media_type (pjsip_rx_data *rdata, char *subtype)
 
static int load_module (void)
 
static void send_response (struct ast_sip_session *session, struct pjsip_rx_data *rdata, int code)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP DTMF INFO Support" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND, .requires = "res_pjsip,res_pjsip_session", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_sip_session_supplement dtmf_info_supplement
 

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 189 of file res_pjsip_dtmf_info.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 189 of file res_pjsip_dtmf_info.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 189 of file res_pjsip_dtmf_info.c.

◆ dtmf_info_incoming_request()

static int dtmf_info_incoming_request ( struct ast_sip_session session,
struct pjsip_rx_data *  rdata 
)
static

Definition at line 82 of file res_pjsip_dtmf_info.c.

83{
84 pjsip_msg_body *body = rdata->msg_info.msg->body;
85 char buf[body ? body->len + 1 : 1];
86 char *cur = buf;
87 char *line;
88 char event = '\0';
89 unsigned int duration = 100;
90 char is_dtmf, is_dtmf_relay, is_flash;
91 int res;
92
93 if (!session->channel) {
94 return 0;
95 }
96
97 is_dtmf = is_media_type(rdata, "dtmf");
98 is_dtmf_relay = is_media_type(rdata, "dtmf-relay");
99 is_flash = is_media_type(rdata, "hook-flash");
100
101 if (!is_flash && !is_dtmf && !is_dtmf_relay) {
102 return 0;
103 }
104
105 if (!body || !body->len) {
106 /* need to return 200 OK on empty body */
107 send_response(session, rdata, 200);
108 return 1;
109 }
110
111 res = body->print_body(body, buf, body->len);
112 if (res < 0) {
113 send_response(session, rdata, 500);
114 return 1;
115 }
116 buf[res] = '\0';
117
118 if (is_dtmf) {
119 /* directly use what is in the message body */
120 event = get_event(cur);
121 } else if (is_dtmf_relay) { /* content type = application/dtmf-relay */
122 while ((line = strsep(&cur, "\r\n"))) {
123 char *c;
124
125 if (!(c = strchr(line, '='))) {
126 continue;
127 }
128
129 *c++ = '\0';
131
132 if (!strcasecmp(line, "signal")) {
133 if (!(event = get_event(c))) {
134 break;
135 }
136 } else if (!strcasecmp(line, "duration")) {
137 sscanf(c, "%30u", &duration);
138 }
139 }
140 }
141
142 if (event == '!' || is_flash) {
143 struct ast_frame f = { AST_FRAME_CONTROL, { AST_CONTROL_FLASH, } };
144 ast_queue_frame(session->channel, &f);
145 } else if (event != '\0') {
146 struct ast_frame f = { AST_FRAME_DTMF, };
147 f.len = duration;
149 ast_queue_frame(session->channel, &f);
150 } else {
151 ast_log(LOG_ERROR, "Invalid DTMF event signal in INFO message.\n");
152 }
153
154 send_response(session, rdata, event ? 200 : 500);
155 return 1;
156}
static struct ast_mansession session
#define ast_log
Definition: astobj2.c:42
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
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
char * strsep(char **str, const char *delims)
#define AST_FRAME_DTMF
@ AST_FRAME_CONTROL
@ AST_CONTROL_FLASH
#define LOG_ERROR
static char get_event(const char *c)
static int is_media_type(pjsip_rx_data *rdata, char *subtype)
static void send_response(struct ast_sip_session *session, struct pjsip_rx_data *rdata, int code)
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:161
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
Definition: astman.c:222
static struct test_val c

References AST_CONTROL_FLASH, AST_FRAME_CONTROL, AST_FRAME_DTMF, ast_log, ast_queue_frame(), ast_skip_blanks(), buf, c, get_event(), ast_frame_subclass::integer, is_media_type(), ast_frame::len, LOG_ERROR, send_response(), session, strsep(), and ast_frame::subclass.

◆ get_event()

static char get_event ( const char *  c)
static

Definition at line 55 of file res_pjsip_dtmf_info.c.

56{
57 unsigned int event;
58
59 if (*c == '!' || *c == '*' || *c == '#' ||
60 ('A' <= *c && *c <= 'D') ||
61 ('a' <= *c && *c <= 'd')) {
62 return *c;
63 }
64
65 if ((sscanf(c, "%30u", &event) != 1) || event > 16) {
66 return '\0';
67 }
68
69 if (event < 10) {
70 return *c;
71 }
72
73 switch (event) {
74 case 10: return '*';
75 case 11: return '#';
76 case 16: return '!';
77 }
78
79 return 'A' + (event - 12);
80}

References c.

Referenced by dtmf_info_incoming_request().

◆ is_media_type()

static int is_media_type ( pjsip_rx_data *  rdata,
char *  subtype 
)
static

Definition at line 35 of file res_pjsip_dtmf_info.c.

36{
37 return rdata->msg_info.ctype
38 && !pj_strcmp2(&rdata->msg_info.ctype->media.type, "application")
39 && !pj_strcmp2(&rdata->msg_info.ctype->media.subtype, subtype);
40}

Referenced by dtmf_info_incoming_request().

◆ load_module()

static int load_module ( void  )
static

Definition at line 164 of file res_pjsip_dtmf_info.c.

165{
166 static const pj_str_t STR_INFO = { "INFO", 4 };
167
168 if (pjsip_endpt_add_capability(ast_sip_get_pjsip_endpoint(),
169 NULL, PJSIP_H_ALLOW, NULL, 1, &STR_INFO) != PJ_SUCCESS) {
171 }
172
175}
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
Definition: res_pjsip.c:520
static struct ast_sip_session_supplement dtmf_info_supplement
#define ast_sip_session_register_supplement(supplement)
#define NULL
Definition: resample.c:96

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_sip_get_pjsip_endpoint(), ast_sip_session_register_supplement, dtmf_info_supplement, and NULL.

◆ send_response()

static void send_response ( struct ast_sip_session session,
struct pjsip_rx_data *  rdata,
int  code 
)
static

Definition at line 42 of file res_pjsip_dtmf_info.c.

44{
45 pjsip_tx_data *tdata;
46 pjsip_dialog *dlg = session->inv_session->dlg;
47
48 if (pjsip_dlg_create_response(dlg, rdata, code,
49 NULL, &tdata) == PJ_SUCCESS) {
50 struct pjsip_transaction *tsx = pjsip_rdata_get_tsx(rdata);
51 pjsip_dlg_send_response(dlg, tsx, tdata);
52 }
53}

References NULL, and session.

Referenced by dtmf_info_incoming_request().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 177 of file res_pjsip_dtmf_info.c.

178{
180 return 0;
181}
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

References ast_sip_session_unregister_supplement(), and dtmf_info_supplement.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP DTMF INFO Support" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND, .requires = "res_pjsip,res_pjsip_session", }
static

Definition at line 189 of file res_pjsip_dtmf_info.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 189 of file res_pjsip_dtmf_info.c.

◆ dtmf_info_supplement

struct ast_sip_session_supplement dtmf_info_supplement
static
Initial value:
= {
.method = "INFO",
.incoming_request = dtmf_info_incoming_request,
}
@ AST_SIP_SUPPLEMENT_PRIORITY_FIRST
Definition: res_pjsip.h:3181
static int dtmf_info_incoming_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata)

Definition at line 158 of file res_pjsip_dtmf_info.c.

Referenced by load_module(), and unload_module().