Asterisk - The Open Source Telephony Project  18.5.0
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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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.

References ast_channel_lock, ast_channel_unlock, AST_FEATURE_MAX_LEN, AST_FRAME_DTMF, ast_get_feature(), ast_queue_frame(), ast_strlen_zero, ast_sip_session::channel, digit, ast_sip_info_recording_configuration::enabled, ast_sip_session::endpoint, ast_sip_endpoint::info, NULL, ast_sip_info_recording_configuration::offfeature, ast_sip_info_recording_configuration::onfeature, ast_sip_endpoint_info_configuration::recording, and send_response().

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));
86  ast_channel_unlock(session->channel);
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
#define ast_channel_lock(chan)
Definition: channel.h:2945
struct ast_sip_endpoint * endpoint
struct ast_sip_info_recording_configuration recording
Definition: res_pjsip.h:683
#define NULL
Definition: resample.c:96
#define AST_FRAME_DTMF
#define ast_strlen_zero(foo)
Definition: strings.h:52
static void send_response(struct ast_sip_session *session, int code, struct pjsip_rx_data *rdata)
const ast_string_field offfeature
Definition: res_pjsip.h:673
struct ast_channel * channel
int ast_get_feature(struct ast_channel *chan, const char *feature, char *buf, size_t len)
Get the DTMF code for a call feature.
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel&#39;s frame queue.
Definition: channel.c:1139
struct ast_sip_endpoint_info_configuration info
Definition: res_pjsip.h:849
#define ast_channel_unlock(chan)
Definition: channel.h:2946
const ast_string_field onfeature
Definition: res_pjsip.h:671
#define AST_FEATURE_MAX_LEN
Data structure associated with a single frame of data.

◆ load_module()

static int load_module ( void  )
static

Definition at line 109 of file res_pjsip_one_touch_record_info.c.

References AST_MODULE_LOAD_SUCCESS, and ast_sip_session_register_supplement.

Referenced by unload_module().

110 {
112 
114 }
static struct ast_sip_session_supplement info_supplement
#define ast_sip_session_register_supplement(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.

References ast_sip_session::inv_session, and NULL.

Referenced by handle_incoming_request().

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 }
#define NULL
Definition: resample.c:96
struct pjsip_inv_session * inv_session

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 116 of file res_pjsip_one_touch_record_info.c.

References AST_MODFLAG_LOAD_ORDER, AST_MODPRI_APP_DEPEND, AST_MODULE_INFO(), AST_MODULE_SUPPORT_CORE, ast_sip_session_unregister_supplement(), ASTERISK_GPL_KEY, and load_module().

117 {
119  return 0;
120 }
static struct ast_sip_session_supplement info_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

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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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,
}
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.