Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Functions | Variables
pjsip_session.c File Reference
#include "asterisk.h"
#include <pjsip.h>
#include <pjsip_ua.h>
#include <pjlib.h>
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_session.h"
#include "include/res_pjsip_private.h"
#include "asterisk/linkedlists.h"
#include "asterisk/lock.h"
#include "asterisk/module.h"
Include dependency graph for pjsip_session.c:

Go to the source code of this file.

Data Structures

struct  session_supplements
 

Functions

int ast_sip_session_add_supplements (struct ast_sip_session *session)
 Add supplements to a SIP session. More...
 
void ast_sip_session_register_supplement_with_module (struct ast_module *module, struct ast_sip_session_supplement *supplement)
 Register a supplement to SIP session processing. More...
 
void ast_sip_session_remove_supplements (struct ast_sip_session *session)
 Remove supplements from a SIP session. More...
 
void ast_sip_session_unregister_supplement (struct ast_sip_session_supplement *supplement)
 Unregister a an supplement to SIP session processing. More...
 
static struct ast_sip_session_supplementsupplement_dup (const struct ast_sip_session_supplement *src)
 

Variables

struct session_supplements session_supplements = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 

Function Documentation

◆ ast_sip_session_add_supplements()

int ast_sip_session_add_supplements ( struct ast_sip_session session)

Add supplements to a SIP session.

Parameters
sessionThe session to initialize

Definition at line 90 of file pjsip_session.c.

References AST_LIST_INSERT_TAIL, ast_module_ref, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, copy(), lock, ast_sip_session_supplement::module, ast_sip_session_supplement::next, SCOPED_LOCK, supplement_dup(), and ast_sip_session::supplements.

Referenced by ast_sip_session_alloc().

91 {
92  struct ast_sip_session_supplement *iter;
94 
97 
98  if (!copy) {
99  return -1;
100  }
101 
102  /* referenced session created. increasing module reference. */
103  ast_module_ref(copy->module);
104 
105  AST_LIST_INSERT_TAIL(&session->supplements, copy, next);
106  }
107 
108  return 0;
109 }
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
static int copy(char *infile, char *outfile)
Utility function to copy a file.
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
ast_mutex_t lock
Definition: app_meetme.c:1091
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
#define SCOPED_LOCK(varname, lock, lockfunc, unlockfunc)
Scoped Locks.
Definition: lock.h:581
struct ast_module * module
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
struct ast_sip_session::@308 supplements
struct ast_sip_session_supplement * next
A supplement to SIP message processing.
static struct ast_sip_session_supplement * supplement_dup(const struct ast_sip_session_supplement *src)
Definition: pjsip_session.c:77
#define ast_module_ref(mod)
Hold a reference to the module.
Definition: module.h:443

◆ ast_sip_session_register_supplement_with_module()

void ast_sip_session_register_supplement_with_module ( struct ast_module module,
struct ast_sip_session_supplement supplement 
)

Register a supplement to SIP session processing.

This allows for someone to insert themselves in the processing of SIP requests and responses. This, for example could allow for a module to set channel data based on headers in an incoming message. Similarly, a module could reject an incoming request if desired.

Parameters
moduleReferenced module(NULL safe)
supplementThe supplement to register

Definition at line 35 of file pjsip_session.c.

References ast_assert, AST_RWLIST_INSERT_BEFORE_CURRENT, AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, AST_SIP_SESSION_BEFORE_MEDIA, lock, ast_sip_session_supplement::module, ast_sip_session_supplement::next, NULL, ast_sip_session_supplement::priority, ast_sip_session_supplement::response_priority, and SCOPED_LOCK.

36 {
37  struct ast_sip_session_supplement *iter;
38  int inserted = 0;
40 
41  ast_assert(supplement != NULL);
42 
43  supplement->module = module;
44 
45  if (!supplement->response_priority) {
47  }
48 
50  if (iter->priority > supplement->priority) {
52  inserted = 1;
53  break;
54  }
55  }
57 
58  if (!inserted) {
60  }
61 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
enum ast_sip_session_response_priority response_priority
ast_mutex_t lock
Definition: app_meetme.c:1091
#define SCOPED_LOCK(varname, lock, lockfunc, unlockfunc)
Scoped Locks.
Definition: lock.h:581
#define AST_RWLIST_INSERT_BEFORE_CURRENT
Definition: linkedlists.h:609
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
struct ast_module * module
enum ast_sip_supplement_priority priority
struct ast_sip_session_supplement * next
A supplement to SIP message processing.
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:740
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616

◆ ast_sip_session_remove_supplements()

void ast_sip_session_remove_supplements ( struct ast_sip_session session)

Remove supplements from a SIP session.

Parameters
sessionThe session to remove

Definition at line 111 of file pjsip_session.c.

References ast_free, AST_LIST_REMOVE_HEAD, ast_module_unref, ast_sip_session_supplement::module, ast_sip_session_supplement::next, and ast_sip_session::supplements.

Referenced by session_destructor().

112 {
113  struct ast_sip_session_supplement *iter;
114 
115  if (!session) {
116  return;
117  }
118 
119  /* free the supplements */
120  while ((iter = AST_LIST_REMOVE_HEAD(&session->supplements, next))) {
121  if (iter->module) {
122  /* referenced session closed. decreasing modue reference. */
123  ast_module_unref(iter->module);
124  }
125 
126  ast_free(iter);
127  }
128 
129  return;
130 }
#define ast_module_unref(mod)
Release a reference to the module.
Definition: module.h:469
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
struct ast_module * module
#define ast_free(a)
Definition: astmm.h:182
struct ast_sip_session::@308 supplements
struct ast_sip_session_supplement * next
A supplement to SIP message processing.

◆ ast_sip_session_unregister_supplement()

void ast_sip_session_unregister_supplement ( struct ast_sip_session_supplement supplement)

Unregister a an supplement to SIP session processing.

Parameters
supplementThe supplement to unregister

Definition at line 63 of file pjsip_session.c.

References AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, lock, ast_sip_session_supplement::next, and SCOPED_LOCK.

Referenced by ast_res_pjsip_cleanup_message_filter(), load_module(), and unload_module().

64 {
65  struct ast_sip_session_supplement *iter;
67 
69  if (supplement == iter) {
71  break;
72  }
73  }
75 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
ast_mutex_t lock
Definition: app_meetme.c:1091
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:569
#define SCOPED_LOCK(varname, lock, lockfunc, unlockfunc)
Scoped Locks.
Definition: lock.h:581
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
struct ast_sip_session_supplement * next
A supplement to SIP message processing.
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616

◆ supplement_dup()

static struct ast_sip_session_supplement* supplement_dup ( const struct ast_sip_session_supplement src)
static

Definition at line 77 of file pjsip_session.c.

References ast_calloc, and NULL.

Referenced by ast_sip_session_add_supplements().

78 {
79  struct ast_sip_session_supplement *dst = ast_calloc(1, sizeof(*dst));
80 
81  if (!dst) {
82  return NULL;
83  }
84  /* Will need to revisit if shallow copy becomes an issue */
85  *dst = *src;
86 
87  return dst;
88 }
#define NULL
Definition: resample.c:96
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
A supplement to SIP message processing.

Variable Documentation

◆ session_supplements

struct session_supplements session_supplements = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }