Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Functions | Variables
res_pjsip_header_funcs.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/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
Include dependency graph for res_pjsip_header_funcs.c:

Go to the source code of this file.

Data Structures

struct  hdr_list
 
struct  hdr_list_entry
 Linked list for accumulating headers. More...
 
struct  header_data
 Data structure used for ast_sip_push_task_wait_serializer. More...
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int add_header (void *obj)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static pjsip_hdr * find_header (struct hdr_list *list, const char *header_name, int header_number)
 
static int func_read_header (struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)
 Implements function 'read' callback. More...
 
static int func_write_header (struct ast_channel *chan, const char *cmd, char *data, const char *value)
 Implements function 'write' callback. More...
 
static int incoming_request (struct ast_sip_session *session, pjsip_rx_data *rdata)
 
static int insert_headers (pj_pool_t *pool, struct hdr_list *list, pjsip_msg *msg)
 
static int load_module (void)
 
static void outgoing_request (struct ast_sip_session *session, pjsip_tx_data *tdata)
 
static int read_header (void *obj)
 
static int remove_header (void *obj)
 
static int unload_module (void)
 
static int update_header (void *obj)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP Header Functions" , .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 const struct ast_datastore_info header_datastore
 Datastore for saving headers. More...
 
static struct ast_sip_session_supplement header_funcs_supplement
 
static struct ast_custom_function pjsip_header_function
 

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 624 of file res_pjsip_header_funcs.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 624 of file res_pjsip_header_funcs.c.

◆ add_header()

static int add_header ( void *  obj)
static

Definition at line 315 of file res_pjsip_header_funcs.c.

References ao2_cleanup, ast_debug, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_TAIL, ast_log, AST_LOG_ERROR, ast_sip_session_add_datastore(), ast_sip_session_alloc_datastore(), ast_sip_session_get_datastore(), header_data::channel, hdr_list_entry::hdr, header_data::header_name, header_data::header_value, ast_sip_session::inv_session, hdr_list_entry::nextptr, pool, RAII_VAR, session, ast_sip_channel_pvt::session, and ast_datastore_info::type.

Referenced by func_write_header().

316 {
317  struct header_data *data = obj;
318  struct ast_sip_session *session = data->channel->session;
319  pj_pool_t *pool = session->inv_session->dlg->pool;
320  pj_str_t pj_header_name;
321  pj_str_t pj_header_value;
322  struct hdr_list_entry *le;
323  struct hdr_list *list;
324 
325  RAII_VAR(struct ast_datastore *, datastore,
327 
328  if (!datastore) {
331  || !(datastore->data = pj_pool_alloc(pool, sizeof(struct hdr_list)))
332  || ast_sip_session_add_datastore(session, datastore)) {
333  ast_log(AST_LOG_ERROR, "Unable to create datastore for header functions.\n");
334  return -1;
335  }
336  AST_LIST_HEAD_INIT_NOLOCK((struct hdr_list *) datastore->data);
337  }
338 
339  ast_debug(1, "Adding header %s with value %s\n", data->header_name,
340  data->header_value);
341 
342  pj_cstr(&pj_header_name, data->header_name);
343  pj_cstr(&pj_header_value, data->header_value);
344  le = pj_pool_zalloc(pool, sizeof(struct hdr_list_entry));
345  le->hdr = (pjsip_hdr *) pjsip_generic_string_hdr_create(pool, &pj_header_name,
346  &pj_header_value);
347  list = datastore->data;
348 
349  AST_LIST_INSERT_TAIL(list, le, nextptr);
350 
351  return 0;
352 }
const char * type
Definition: datastore.h:32
struct ast_sip_channel_pvt * channel
static pj_pool_t * pool
Global memory pool for configuration and timers.
struct ast_sip_session * session
Pointer to session.
Data structure used for ast_sip_push_task_wait_serializer.
Structure for a data store object.
Definition: datastore.h:68
struct pjsip_inv_session * inv_session
A structure describing a SIP session.
static const struct ast_datastore_info header_datastore
Datastore for saving headers.
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define AST_LOG_ERROR
Definition: logger.h:290
struct ast_datastore * ast_sip_session_alloc_datastore(const struct ast_datastore_info *info, const char *uid)
Alternative for ast_datastore_alloc()
struct ast_datastore * ast_sip_session_get_datastore(struct ast_sip_session *session, const char *name)
Retrieve a session datastore.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
static struct ast_mansession session
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:680
Linked list for accumulating headers.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
pjsip_hdr * hdr
const char * header_value
int ast_sip_session_add_datastore(struct ast_sip_session *session, struct ast_datastore *datastore)
Add a datastore to a SIP session.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 624 of file res_pjsip_header_funcs.c.

◆ find_header()

static pjsip_hdr* find_header ( struct hdr_list list,
const char *  header_name,
int  header_number 
)
static

Definition at line 222 of file res_pjsip_header_funcs.c.

References AST_LIST_TRAVERSE, ast_strlen_zero, hdr_list_entry::hdr, hdr_list_entry::nextptr, and NULL.

Referenced by read_header(), and update_header().

224 {
225  struct hdr_list_entry *le;
226  pjsip_hdr *hdr = NULL;
227  int i = 1;
228 
229  if (!list || ast_strlen_zero(header_name) || header_number < 1) {
230  return NULL;
231  }
232 
233  AST_LIST_TRAVERSE(list, le, nextptr) {
234  if (pj_stricmp2(&le->hdr->name, header_name) == 0 && i++ == header_number) {
235  hdr = le->hdr;
236  break;
237  }
238  }
239 
240  return hdr;
241 }
struct hdr_list_entry::@482 nextptr
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
Linked list for accumulating headers.
pjsip_hdr * hdr

◆ func_read_header()

static int func_read_header ( struct ast_channel chan,
const char *  function,
char *  data,
char *  buf,
size_t  len 
)
static

Implements function 'read' callback.

Valid actions are 'read' and 'remove'.

Definition at line 442 of file res_pjsip_header_funcs.c.

References args, AST_APP_ARG, ast_channel_name(), ast_channel_tech_pvt(), AST_DECLARE_APP_ARGS, ast_log, AST_LOG_ERROR, ast_sip_push_task_wait_serializer(), AST_STANDARD_APP_ARGS, ast_strlen_zero, buf, header_data::buf, header_data::channel, header_data::header_name, header_data::header_number, header_data::header_value, header_data::len, len(), LOG_ERROR, NULL, read_header(), remove_header(), ast_sip_session::serializer, and ast_sip_channel_pvt::session.

444 {
445  struct ast_sip_channel_pvt *channel = chan ? ast_channel_tech_pvt(chan) : NULL;
446  struct header_data header_data;
447  int number;
449  AST_APP_ARG(action);
452 
453  if (!channel || strncmp(ast_channel_name(chan), "PJSIP/", 6)) {
454  ast_log(LOG_ERROR, "This function requires a PJSIP channel.\n");
455  return -1;
456  }
457 
458  if (ast_strlen_zero(args.action)) {
459  ast_log(AST_LOG_ERROR, "This function requires an action.\n");
460  return -1;
461  }
462  if (ast_strlen_zero(args.header_name)) {
463  ast_log(AST_LOG_ERROR, "This function requires a header name.\n");
464  return -1;
465  }
466  if (!args.header_number) {
467  number = 1;
468  } else {
469  sscanf(args.header_number, "%30d", &number);
470  if (number < 1) {
471  number = 1;
472  }
473  }
474 
476  header_data.header_name = args.header_name;
477  header_data.header_number = number;
479  header_data.buf = buf;
480  header_data.len = len;
481 
482  if (!strcasecmp(args.action, "read")) {
485  } else if (!strcasecmp(args.action, "remove")) {
488  } else {
490  "Unknown action '%s' is not valid, must be 'read' or 'remove'.\n",
491  args.action);
492  return -1;
493  }
494 }
void * ast_channel_tech_pvt(const struct ast_channel *chan)
struct ast_sip_channel_pvt * channel
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
A structure which contains a channel implementation and session.
struct ast_sip_session * session
Pointer to session.
Data structure used for ast_sip_push_task_wait_serializer.
Definition: muted.c:95
const char * args
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
Number structure.
Definition: app_followme.c:154
#define ast_log
Definition: astobj2.c:42
#define AST_LOG_ERROR
Definition: logger.h:290
static int read_header(void *obj)
int ast_sip_push_task_wait_serializer(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to the serializer and wait for it to complete.
Definition: res_pjsip.c:5218
static int remove_header(void *obj)
struct ast_taskprocessor * serializer
#define LOG_ERROR
Definition: logger.h:285
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
const char * ast_channel_name(const struct ast_channel *chan)
const char * header_value
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ func_write_header()

static int func_write_header ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
)
static

Implements function 'write' callback.

Valid actions are 'add', 'update' and 'remove'.

Definition at line 501 of file res_pjsip_header_funcs.c.

References add_header(), args, AST_APP_ARG, ast_channel_name(), ast_channel_tech_pvt(), AST_DECLARE_APP_ARGS, ast_log, AST_LOG_ERROR, ast_sip_push_task_wait_serializer(), AST_STANDARD_APP_ARGS, ast_strlen_zero, header_data::buf, header_data::channel, header_data::header_name, header_data::header_number, header_data::header_value, header_data::len, LOG_ERROR, NULL, remove_header(), ast_sip_session::serializer, ast_sip_channel_pvt::session, update_header(), and value.

503 {
504  struct ast_sip_channel_pvt *channel = chan ? ast_channel_tech_pvt(chan) : NULL;
505  struct header_data header_data;
506  int header_number;
508  AST_APP_ARG(action);
509  AST_APP_ARG(header_name); AST_APP_ARG(header_number););
511 
512  if (!channel || strncmp(ast_channel_name(chan), "PJSIP/", 6)) {
513  ast_log(LOG_ERROR, "This function requires a PJSIP channel.\n");
514  return -1;
515  }
516 
517  if (ast_strlen_zero(args.action)) {
518  ast_log(AST_LOG_ERROR, "This function requires an action.\n");
519  return -1;
520  }
521  if (ast_strlen_zero(args.header_name)) {
522  ast_log(AST_LOG_ERROR, "This function requires a header name.\n");
523  return -1;
524  }
525  if (!args.header_number) {
526  header_number = 1;
527  } else {
528  sscanf(args.header_number, "%30d", &header_number);
529  if (header_number < 1) {
530  header_number = 1;
531  }
532  }
533 
535  header_data.header_name = args.header_name;
538  header_data.buf = NULL;
539  header_data.len = 0;
540 
541  if (!strcasecmp(args.action, "add")) {
544  } else if (!strcasecmp(args.action, "update")) {
547  } else if (!strcasecmp(args.action, "remove")) {
550  } else {
552  "Unknown action '%s' is not valid, must be 'add', 'update', or 'remove'.\n",
553  args.action);
554  return -1;
555  }
556 }
void * ast_channel_tech_pvt(const struct ast_channel *chan)
struct ast_sip_channel_pvt * channel
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
A structure which contains a channel implementation and session.
struct ast_sip_session * session
Pointer to session.
Data structure used for ast_sip_push_task_wait_serializer.
Definition: muted.c:95
const char * args
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
#define AST_LOG_ERROR
Definition: logger.h:290
int ast_sip_push_task_wait_serializer(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to the serializer and wait for it to complete.
Definition: res_pjsip.c:5218
static int remove_header(void *obj)
struct ast_taskprocessor * serializer
#define LOG_ERROR
Definition: logger.h:285
const char * ast_channel_name(const struct ast_channel *chan)
static int update_header(void *obj)
static int add_header(void *obj)
const char * header_value
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ incoming_request()

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

Definition at line 196 of file res_pjsip_header_funcs.c.

References ao2_cleanup, AST_LIST_HEAD_INIT_NOLOCK, ast_log, AST_LOG_ERROR, ast_sip_session_add_datastore(), ast_sip_session_alloc_datastore(), ast_sip_session_get_datastore(), insert_headers(), ast_sip_session::inv_session, pool, RAII_VAR, and ast_datastore_info::type.

197 {
198  pj_pool_t *pool = session->inv_session->dlg->pool;
199  RAII_VAR(struct ast_datastore *, datastore,
201 
202  if (!datastore) {
203  if (!(datastore =
205  ||
206  !(datastore->data = pj_pool_alloc(pool, sizeof(struct hdr_list))) ||
207  ast_sip_session_add_datastore(session, datastore)) {
208  ast_log(AST_LOG_ERROR, "Unable to create datastore for header functions.\n");
209  return 0;
210  }
211  AST_LIST_HEAD_INIT_NOLOCK((struct hdr_list *) datastore->data);
212  }
213  insert_headers(pool, (struct hdr_list *) datastore->data, rdata->msg_info.msg);
214 
215  return 0;
216 }
const char * type
Definition: datastore.h:32
static pj_pool_t * pool
Global memory pool for configuration and timers.
static int insert_headers(pj_pool_t *pool, struct hdr_list *list, pjsip_msg *msg)
Structure for a data store object.
Definition: datastore.h:68
struct pjsip_inv_session * inv_session
static const struct ast_datastore_info header_datastore
Datastore for saving headers.
#define ast_log
Definition: astobj2.c:42
#define AST_LOG_ERROR
Definition: logger.h:290
struct ast_datastore * ast_sip_session_alloc_datastore(const struct ast_datastore_info *info, const char *uid)
Alternative for ast_datastore_alloc()
struct ast_datastore * ast_sip_session_get_datastore(struct ast_sip_session *session, const char *name)
Retrieve a session datastore.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:680
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
int ast_sip_session_add_datastore(struct ast_sip_session *session, struct ast_datastore *datastore)
Add a datastore to a SIP session.

◆ insert_headers()

static int insert_headers ( pj_pool_t *  pool,
struct hdr_list list,
pjsip_msg *  msg 
)
static

Definition at line 173 of file res_pjsip_header_funcs.c.

References AST_LIST_INSERT_TAIL, hdr_list_entry::hdr, and hdr_list_entry::nextptr.

Referenced by incoming_request().

174 {
175  pjsip_hdr *hdr = msg->hdr.next;
176  struct hdr_list_entry *le;
177 
178  while (hdr && hdr != &msg->hdr) {
179  le = pj_pool_zalloc(pool, sizeof(struct hdr_list_entry));
180  le->hdr = pjsip_hdr_clone(pool, hdr);
181  AST_LIST_INSERT_TAIL(list, le, nextptr);
182  hdr = hdr->next;
183  }
184 
185  return 0;
186 }
struct hdr_list_entry::@482 nextptr
static pj_pool_t * pool
Global memory pool for configuration and timers.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
Linked list for accumulating headers.
pjsip_hdr * hdr

◆ load_module()

static int load_module ( void  )
static

Definition at line 603 of file res_pjsip_header_funcs.c.

References ast_custom_function_register, AST_MODULE_LOAD_SUCCESS, and ast_sip_session_register_supplement.

Referenced by unload_module().

604 {
607 
609 }
static struct ast_custom_function pjsip_header_function
static struct ast_sip_session_supplement header_funcs_supplement
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1508
#define ast_sip_session_register_supplement(supplement)

◆ outgoing_request()

static void outgoing_request ( struct ast_sip_session session,
pjsip_tx_data *  tdata 
)
static

Definition at line 576 of file res_pjsip_header_funcs.c.

References ao2_cleanup, AST_LIST_TRAVERSE, ast_sip_session_get_datastore(), ast_sip_session_remove_datastore(), hdr_list_entry::hdr, ast_sip_session::inv_session, hdr_list_entry::nextptr, pool, RAII_VAR, and ast_datastore_info::type.

577 {
578  pj_pool_t *pool = session->inv_session->dlg->pool;
579  struct hdr_list *list;
580  struct hdr_list_entry *le;
581  RAII_VAR(struct ast_datastore *, datastore,
583 
584  if (!datastore || !datastore->data ||
585  (session->inv_session->state >= PJSIP_INV_STATE_CONFIRMED)) {
586  return;
587  }
588 
589  list = datastore->data;
590  AST_LIST_TRAVERSE(list, le, nextptr) {
591  pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) pjsip_hdr_clone(pool, le->hdr));
592  }
593  ast_sip_session_remove_datastore(session, datastore->uid);
594 }
const char * type
Definition: datastore.h:32
struct hdr_list_entry::@482 nextptr
static pj_pool_t * pool
Global memory pool for configuration and timers.
Structure for a data store object.
Definition: datastore.h:68
struct pjsip_inv_session * inv_session
static const struct ast_datastore_info header_datastore
Datastore for saving headers.
void ast_sip_session_remove_datastore(struct ast_sip_session *session, const char *name)
Remove a session datastore from the session.
struct ast_datastore * ast_sip_session_get_datastore(struct ast_sip_session *session, const char *name)
Retrieve a session datastore.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
Linked list for accumulating headers.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
pjsip_hdr * hdr

◆ read_header()

static int read_header ( void *  obj)
static

Definition at line 254 of file res_pjsip_header_funcs.c.

References ao2_cleanup, ast_alloca, ast_copy_string(), ast_debug, ast_log, AST_LOG_ERROR, ast_sip_session_get_datastore(), ast_strip(), header_data::buf, header_data::channel, find_header(), hdr_list_entry::hdr, header_data::header_name, header_data::header_number, header_data::len, NULL, RAII_VAR, ast_sip_channel_pvt::session, and ast_datastore_info::type.

Referenced by func_read_header().

255 {
256  struct header_data *data = obj;
257  pjsip_hdr *hdr = NULL;
258  char *pj_hdr_string;
259  size_t pj_hdr_string_len;
260  char *p;
261  size_t plen;
262  RAII_VAR(struct ast_datastore *, datastore,
264  ao2_cleanup);
265 
266  if (!datastore || !datastore->data) {
267  ast_debug(1, "There was no datastore from which to read headers.\n");
268  return -1;
269  }
270 
271  hdr = find_header((struct hdr_list *) datastore->data, data->header_name,
272  data->header_number);
273 
274  if (!hdr) {
275  ast_debug(1, "There was no header named %s.\n", data->header_name);
276  return -1;
277  }
278 
279  pj_hdr_string = ast_alloca(data->len);
280  pj_hdr_string_len = pjsip_hdr_print_on(hdr, pj_hdr_string, data->len);
281  pj_hdr_string[pj_hdr_string_len] = '\0';
282 
283  p = strchr(pj_hdr_string, ':');
284  if (!p) {
286  "A malformed header was returned from pjsip_hdr_print_on.\n");
287  return -1;
288  }
289 
290  ++p;
291  p = ast_strip(p);
292  plen = strlen(p);
293  if (plen + 1 > data->len) {
295  "Buffer isn't big enough to hold header value. %zu > %zu\n", plen + 1,
296  data->len);
297  return -1;
298  }
299 
300  ast_copy_string(data->buf, p, data->len);
301 
302  return 0;
303 }
const char * type
Definition: datastore.h:32
struct ast_sip_channel_pvt * channel
struct ast_sip_session * session
Pointer to session.
Data structure used for ast_sip_push_task_wait_serializer.
Structure for a data store object.
Definition: datastore.h:68
#define NULL
Definition: resample.c:96
static const struct ast_datastore_info header_datastore
Datastore for saving headers.
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define AST_LOG_ERROR
Definition: logger.h:290
struct ast_datastore * ast_sip_session_get_datastore(struct ast_sip_session *session, const char *name)
Retrieve a session datastore.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:219
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
static pjsip_hdr * find_header(struct hdr_list *list, const char *header_name, int header_number)
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ remove_header()

static int remove_header ( void *  obj)
static

Definition at line 398 of file res_pjsip_header_funcs.c.

References ao2_cleanup, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log, AST_LOG_ERROR, ast_sip_session_get_datastore(), header_data::buf, header_data::channel, hdr_list_entry::hdr, header_data::header_name, header_data::len, len(), hdr_list_entry::nextptr, RAII_VAR, ast_sip_channel_pvt::session, and ast_datastore_info::type.

Referenced by func_read_header(), and func_write_header().

399 {
400  struct header_data *data = obj;
401  size_t len = strlen(data->header_name);
402  struct hdr_list *list;
403  struct hdr_list_entry *le;
404  int removed_count = 0;
405  RAII_VAR(struct ast_datastore *, datastore,
407  ao2_cleanup);
408 
409  if (!datastore || !datastore->data) {
410  ast_log(AST_LOG_ERROR, "No headers had been previously added to this session.\n");
411  return -1;
412  }
413 
414  list = datastore->data;
416  if (data->header_name[len - 1] == '*') {
417  if (pj_strnicmp2(&le->hdr->name, data->header_name, len - 1) == 0) {
419  removed_count++;
420  }
421  } else {
422  if (pj_stricmp2(&le->hdr->name, data->header_name) == 0) {
424  removed_count++;
425  }
426  }
427  }
429 
430  if (data->buf && data->len) {
431  snprintf(data->buf, data->len, "%d", removed_count);
432  }
433 
434  return 0;
435 }
const char * type
Definition: datastore.h:32
struct ast_sip_channel_pvt * channel
struct hdr_list_entry::@482 nextptr
struct ast_sip_session * session
Pointer to session.
Data structure used for ast_sip_push_task_wait_serializer.
Structure for a data store object.
Definition: datastore.h:68
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
static const struct ast_datastore_info header_datastore
Datastore for saving headers.
#define ast_log
Definition: astobj2.c:42
#define AST_LOG_ERROR
Definition: logger.h:290
struct ast_datastore * ast_sip_session_get_datastore(struct ast_sip_session *session, const char *name)
Retrieve a session datastore.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
Linked list for accumulating headers.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
pjsip_hdr * hdr
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 611 of file res_pjsip_header_funcs.c.

References ast_custom_function_unregister(), 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().

612 {
615  return 0;
616 }
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
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
static struct ast_custom_function pjsip_header_function
static struct ast_sip_session_supplement header_funcs_supplement

◆ update_header()

static int update_header ( void *  obj)
static

Definition at line 364 of file res_pjsip_header_funcs.c.

References ao2_cleanup, ast_log, AST_LOG_ERROR, ast_sip_session_get_datastore(), header_data::channel, find_header(), hdr_list_entry::hdr, header_data::header_name, header_data::header_number, header_data::header_value, NULL, RAII_VAR, ast_sip_channel_pvt::session, and ast_datastore_info::type.

Referenced by func_write_header().

365 {
366  struct header_data *data = obj;
367  pjsip_hdr *hdr = NULL;
368  RAII_VAR(struct ast_datastore *, datastore,
370  ao2_cleanup);
371 
372  if (!datastore || !datastore->data) {
373  ast_log(AST_LOG_ERROR, "No headers had been previously added to this session.\n");
374  return -1;
375  }
376 
377  hdr = find_header((struct hdr_list *) datastore->data, data->header_name,
378  data->header_number);
379 
380  if (!hdr) {
381  ast_log(AST_LOG_ERROR, "There was no header named %s.\n", data->header_name);
382  return -1;
383  }
384 
385  pj_strcpy2(&((pjsip_generic_string_hdr *) hdr)->hvalue, data->header_value);
386 
387  return 0;
388 }
const char * type
Definition: datastore.h:32
struct ast_sip_channel_pvt * channel
struct ast_sip_session * session
Pointer to session.
Data structure used for ast_sip_push_task_wait_serializer.
Structure for a data store object.
Definition: datastore.h:68
#define NULL
Definition: resample.c:96
static const struct ast_datastore_info header_datastore
Datastore for saving headers.
#define ast_log
Definition: astobj2.c:42
#define AST_LOG_ERROR
Definition: logger.h:290
struct ast_datastore * ast_sip_session_get_datastore(struct ast_sip_session *session, const char *name)
Retrieve a session datastore.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
static pjsip_hdr * find_header(struct hdr_list *list, const char *header_name, int header_number)
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
const char * header_value

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP Header Functions" , .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 624 of file res_pjsip_header_funcs.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 624 of file res_pjsip_header_funcs.c.

◆ header_datastore

const struct ast_datastore_info header_datastore
static
Initial value:
= {
.type = "header_datastore",
}

Datastore for saving headers.

Definition at line 152 of file res_pjsip_header_funcs.c.

◆ header_funcs_supplement

struct ast_sip_session_supplement header_funcs_supplement
static

Definition at line 596 of file res_pjsip_header_funcs.c.

◆ pjsip_header_function

struct ast_custom_function pjsip_header_function
static
Initial value:
= {
.name = "PJSIP_HEADER",
}
static int func_write_header(struct ast_channel *chan, const char *cmd, char *data, const char *value)
Implements function &#39;write&#39; callback.
static int func_read_header(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)
Implements function &#39;read&#39; callback.

Definition at line 558 of file res_pjsip_header_funcs.c.