Asterisk - The Open Source Telephony Project  18.5.0
pjsip_session.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2017, CFWare, LLC
5  *
6  * Corey Farrell <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 #include "asterisk.h"
20 
21 #include <pjsip.h>
22 #include <pjsip_ua.h>
23 #include <pjlib.h>
24 
25 #include "asterisk/res_pjsip.h"
28 #include "asterisk/linkedlists.h"
29 #include "asterisk/lock.h"
30 #include "asterisk/module.h"
31 
32 
34 
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 }
62 
64 {
65  struct ast_sip_session_supplement *iter;
67 
69  if (supplement == iter) {
71  break;
72  }
73  }
75 }
76 
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 }
89 
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 }
110 
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 }
131 
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
int ast_sip_session_add_supplements(struct ast_sip_session *session)
Add supplements to a SIP session.
Definition: pjsip_session.c:90
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
Definition: linkedlists.h:332
#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
static int copy(char *infile, char *outfile)
Utility function to copy a file.
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
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.
Definition: pjsip_session.c:35
A structure describing a SIP session.
enum ast_sip_session_response_priority response_priority
#define ast_module_unref(mod)
Release a reference to the module.
Definition: module.h:469
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
static struct ast_mansession session
ast_mutex_t lock
Definition: app_meetme.c:1091
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:569
#define SCOPED_LOCK(varname, lock, lockfunc, unlockfunc)
Scoped Locks.
Definition: lock.h:581
A set of macros to manage forward-linked lists.
#define AST_RWLIST_INSERT_BEFORE_CURRENT
Definition: linkedlists.h:609
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
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
enum ast_sip_supplement_priority priority
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
struct ast_sip_session::@308 supplements
void ast_sip_session_remove_supplements(struct ast_sip_session *session)
Remove supplements from a SIP session.
struct ast_sip_session_supplement * next
A supplement to SIP message processing.
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:740
static struct ast_sip_session_supplement * supplement_dup(const struct ast_sip_session_supplement *src)
Definition: pjsip_session.c:77
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
Asterisk module definitions.
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616
#define ast_module_ref(mod)
Hold a reference to the module.
Definition: module.h:443