Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
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 = ASTERISK_GPL_KEY , .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:2982
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:1170
#define ast_channel_unlock(chan)
Definition channel.h:2983
#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.
struct ast_frame_subclass subclass

References ast_channel_lock, ast_channel_unlock, AST_FEATURE_MAX_LEN, AST_FRAME_DTMF, ast_get_feature(), ast_queue_frame(), ast_strlen_zero(), digit, ast_frame_subclass::integer, NULL, send_response(), session, and ast_frame::subclass.

◆ 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.

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 = ASTERISK_GPL_KEY , .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:3334
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.

103 {
104 .method = "INFO",
106 .incoming_request = handle_incoming_request,
107};

Referenced by load_module(), and unload_module().