Asterisk - The Open Source Telephony Project GIT-master-f36a736
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.

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}
ast_mutex_t lock
Definition: app_sla.c:331
static int copy(char *infile, char *outfile)
Utility function to copy a file.
static struct ast_mansession session
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:731
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:494
#define SCOPED_LOCK(varname, lock, lockfunc, unlockfunc)
Scoped Locks.
Definition: lock.h:583
#define ast_module_ref(mod)
Hold a reference to the module.
Definition: module.h:457
static struct ast_sip_session_supplement * supplement_dup(const struct ast_sip_session_supplement *src)
Definition: pjsip_session.c:77
A supplement to SIP message processing.
struct ast_sip_session_supplement * next

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

Referenced by ast_sip_session_alloc().

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

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_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:545
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:617
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:741
#define AST_RWLIST_INSERT_BEFORE_CURRENT
Definition: linkedlists.h:610
@ AST_SIP_SESSION_BEFORE_MEDIA
#define NULL
Definition: resample.c:96
enum ast_sip_session_response_priority response_priority
struct ast_module * module
enum ast_sip_supplement_priority priority
#define ast_assert(a)
Definition: utils.h:739

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.

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

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 module reference. */
124 }
125
126 ast_free(iter);
127 }
128
129 return;
130}
#define ast_free(a)
Definition: astmm.h:180
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:833
#define ast_module_unref(mod)
Release a reference to the module.
Definition: module.h:483

References ast_free, AST_LIST_REMOVE_HEAD, ast_module_unref, ast_sip_session_supplement::module, ast_sip_session_supplement::next, and session.

Referenced by session_destructor().

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

64{
65 struct ast_sip_session_supplement *iter;
67
69 if (supplement == iter) {
71 break;
72 }
73 }
75}
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:570

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(), pjsip_reason_header_unload(), and unload_module().

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

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 ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202

References ast_calloc, and NULL.

Referenced by ast_sip_session_add_supplements().

Variable Documentation

◆ session_supplements

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