Asterisk - The Open Source Telephony Project GIT-master-f36a736
Functions | Variables
res_pjsip_one_touch_record_info.c File Reference
#include "asterisk.h"
#include <pjsip.h>
#include <pjsip_ua.h>
#include "asterisk/features.h"
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_session.h"
#include "asterisk/module.h"
#include "asterisk/features_config.h"
Include dependency graph for res_pjsip_one_touch_record_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 handle_incoming_request (struct ast_sip_session *session, struct pjsip_rx_data *rdata)
 
static int load_module (void)
 
static void send_response (struct ast_sip_session *session, int code, struct pjsip_rx_data *rdata)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP INFO One Touch Recording 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 info_supplement
 

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 128 of file res_pjsip_one_touch_record_info.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 128 of file res_pjsip_one_touch_record_info.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 128 of file res_pjsip_one_touch_record_info.c.

◆ handle_incoming_request()

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

Definition at line 48 of file res_pjsip_one_touch_record_info.c.

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}
char digit
static struct ast_mansession session
#define ast_channel_lock(chan)
Definition: channel.h:2968
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:1158
#define ast_channel_unlock(chan)
Definition: channel.h:2969
#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
static void send_response(struct ast_sip_session *session, int code, struct pjsip_rx_data *rdata)
#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.

References ast_channel_lock, ast_channel_unlock, AST_FEATURE_MAX_LEN, AST_FRAME_DTMF, ast_get_feature(), ast_queue_frame(), ast_strlen_zero(), digit, NULL, send_response(), and session.

◆ load_module()

static int load_module ( void  )
static

Definition at line 109 of file res_pjsip_one_touch_record_info.c.

110{
112
114}
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
static struct ast_sip_session_supplement info_supplement
#define ast_sip_session_register_supplement(supplement)

References AST_MODULE_LOAD_SUCCESS, ast_sip_session_register_supplement, and info_supplement.

◆ send_response()

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

Definition at line 37 of file res_pjsip_one_touch_record_info.c.

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}

References NULL, and session.

Referenced by handle_incoming_request().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 116 of file res_pjsip_one_touch_record_info.c.

117{
119 return 0;
120}
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 info_supplement.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP INFO One Touch Recording 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 128 of file res_pjsip_one_touch_record_info.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 128 of file res_pjsip_one_touch_record_info.c.

◆ info_supplement

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

Definition at line 103 of file res_pjsip_one_touch_record_info.c.

Referenced by load_module(), and unload_module().