Asterisk - The Open Source Telephony Project GIT-master-590b490
Loading...
Searching...
No Matches
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.
 
int ast_sip_session_check_supplement_create (struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, const char *location, const char *request_user, struct ast_stream_topology *req_topology)
 Check registered supplements for permission to create an outgoing session.
 
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.
 
void ast_sip_session_remove_supplements (struct ast_sip_session *session)
 Remove supplements from a SIP session.
 
void ast_sip_session_unregister_supplement (struct ast_sip_session_supplement *supplement)
 Unregister a an supplement to SIP session processing.
 
static struct ast_sip_session_supplementsupplement_dup (const struct ast_sip_session_supplement *src)
 

Variables

struct session_supplements session_supplements = AST_RWLIST_HEAD_INIT_VALUE
 

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:337
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.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
#define AST_RWLIST_TRAVERSE
#define SCOPED_LOCK(varname, lock, lockfunc, unlockfunc)
Scoped Locks.
Definition lock.h:590
#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)
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_check_supplement_create()

int ast_sip_session_check_supplement_create ( struct ast_sip_endpoint endpoint,
struct ast_sip_contact contact,
const char *  location,
const char *  request_user,
struct ast_stream_topology req_topology 
)

Check registered supplements for permission to create an outgoing session.

Iterates the global supplement list and calls any registered session_create callbacks. The first callback to return a non-zero value stops the iteration and causes this function to return -1, blocking the session creation.

This is called at the beginning of ast_sip_session_create_outgoing() before any dialog or invite session resources are allocated.

Since
20.20.0
22.10.0
23.4.0
Parameters
endpointThe endpoint the outgoing session would be created for
contactThe contact to use for the outgoing session, or NULL
locationName of the location to call, be it named location or explicit URI, or NULL
request_userOptional request user to place in the request URI, or NULL
req_topologyThe requested stream capabilities
Return values
0Session creation is allowed
-1Session creation is blocked by a supplement

Definition at line 111 of file pjsip_session.c.

114{
115 struct ast_sip_session_supplement *iter;
117
119 if (iter->session_create && iter->session_create(endpoint, contact, location,
120 request_user, req_topology)) {
121 return -1;
122 }
123 }
124
125 return 0;
126}
int(* session_create)(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, const char *location, const char *request_user, struct ast_stream_topology *req_topology)
Called before an outgoing session is created.

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, lock, ast_sip_session_supplement::next, SCOPED_LOCK, and ast_sip_session_supplement::session_create.

Referenced by ast_sip_session_create_outgoing().

◆ 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
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition linkedlists.h:52
#define AST_RWLIST_TRAVERSE_SAFE_END
#define AST_RWLIST_INSERT_TAIL
#define AST_RWLIST_INSERT_BEFORE_CURRENT
@ AST_SIP_SESSION_BEFORE_MEDIA
#define NULL
Definition resample.c:96
enum ast_sip_session_response_priority response_priority
enum ast_sip_supplement_priority priority
#define ast_assert(a)
Definition utils.h:779

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::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 128 of file pjsip_session.c.

129{
130 struct ast_sip_session_supplement *iter;
131
132 if (!session) {
133 return;
134 }
135
136 /* free the supplements */
137 while ((iter = AST_LIST_REMOVE_HEAD(&session->supplements, next))) {
138 if (iter->module) {
139 /* referenced session closed. decreasing module reference. */
140 ast_module_unref(iter->module);
141 }
142
143 ast_free(iter);
144 }
145
146 return;
147}
#define ast_free(a)
Definition astmm.h:180
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
#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::next, and session.

Referenced by session_destructor().

◆ ast_sip_session_unregister_supplement()

void ast_sip_session_unregister_supplement ( struct ast_sip_session_supplement supplement)

◆ 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