1 /*
2 eXosip - This is the eXtended osip library.
3 Copyright (C) 2001-2020 Aymeric MOIZARD amoizard@antisip.com
4
5 eXosip is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 eXosip is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
23 including the two.
24 You must obey the GNU General Public License in all respects
25 for all of the code used other than OpenSSL. If you modify
26 file(s) with this exception, you may extend this exception to your
27 version of the file(s), but you are not obligated to do so. If you
28 do not wish to do so, delete this exception statement from your
29 version. If you delete this exception statement from all source
30 files in the program, then also delete it here.
31 */
32
33 #include "eXosip2.h"
34
_eXosip_call_find(struct eXosip_t * excontext,int cid,eXosip_call_t ** jc)35 int _eXosip_call_find(struct eXosip_t *excontext, int cid, eXosip_call_t **jc) {
36 if (cid <= 0)
37 return OSIP_BADPARAMETER;
38
39 for (*jc = excontext->j_calls; *jc != NULL; *jc = (*jc)->next) {
40 if ((*jc)->c_id == cid) {
41 return OSIP_SUCCESS;
42 }
43 }
44
45 *jc = NULL;
46 return OSIP_NOTFOUND;
47 }
48
_eXosip_call_renew_expire_time(eXosip_call_t * jc)49 void _eXosip_call_renew_expire_time(eXosip_call_t *jc) {
50 time_t now = osip_getsystemtime(NULL);
51
52 jc->expire_time = now + 180;
53 }
54
_eXosip_call_init(struct eXosip_t * excontext,eXosip_call_t ** jc)55 int _eXosip_call_init(struct eXosip_t *excontext, eXosip_call_t **jc) {
56 *jc = (eXosip_call_t *) osip_malloc(sizeof(eXosip_call_t));
57
58 if (*jc == NULL)
59 return OSIP_NOMEM;
60
61 memset(*jc, 0, sizeof(eXosip_call_t));
62
63 (*jc)->c_id = -1; /* make sure the _eXosip_update will assign a valid id to the call */
64
65 #ifndef MINISIZE
66 {
67 struct timeval now;
68
69 excontext->statistics.allocated_calls++;
70 osip_gettimeofday(&now, NULL);
71 _eXosip_counters_update(&excontext->average_calls, 1, &now);
72 }
73 #endif
74 return OSIP_SUCCESS;
75 }
76
_eXosip_call_remove_dialog_reference_in_call(eXosip_call_t * jc,eXosip_dialog_t * jd)77 void _eXosip_call_remove_dialog_reference_in_call(eXosip_call_t *jc, eXosip_dialog_t *jd) {
78 eXosip_dialog_t *_jd;
79
80 if (jc == NULL)
81 return;
82
83 if (jd == NULL)
84 return;
85
86 for (_jd = jc->c_dialogs; _jd != NULL; _jd = _jd->next) {
87 if (jd == _jd)
88 break;
89 }
90
91 if (_jd == NULL) {
92 /* dialog not found??? */
93 }
94
95 _jd = (eXosip_dialog_t *) osip_transaction_get_reserved3(jc->c_inc_tr);
96
97 if (_jd != NULL && _jd == jd)
98 osip_transaction_set_reserved3(jc->c_inc_tr, NULL);
99
100 _jd = (eXosip_dialog_t *) osip_transaction_get_reserved3(jc->c_out_tr);
101
102 if (_jd != NULL && _jd == jd)
103 osip_transaction_set_reserved3(jc->c_out_tr, NULL);
104
105 _jd = (eXosip_dialog_t *) osip_transaction_get_reserved3(jc->c_cancel_tr);
106
107 if (_jd != NULL && _jd == jd)
108 osip_transaction_set_reserved3(jc->c_cancel_tr, NULL);
109 }
110
_eXosip_call_free(struct eXosip_t * excontext,eXosip_call_t * jc)111 void _eXosip_call_free(struct eXosip_t *excontext, eXosip_call_t *jc) {
112 eXosip_dialog_t *jd;
113
114 if (jc->c_inc_tr != NULL && jc->c_inc_tr->orig_request != NULL && jc->c_inc_tr->orig_request->call_id != NULL && jc->c_inc_tr->orig_request->call_id->number != NULL)
115 _eXosip_delete_nonce(excontext, jc->c_inc_tr->orig_request->call_id->number);
116
117 else if (jc->c_out_tr != NULL && jc->c_out_tr->orig_request != NULL && jc->c_out_tr->orig_request->call_id != NULL && jc->c_out_tr->orig_request->call_id->number != NULL)
118 _eXosip_delete_nonce(excontext, jc->c_out_tr->orig_request->call_id->number);
119
120 for (jd = jc->c_dialogs; jd != NULL; jd = jc->c_dialogs) {
121 REMOVE_ELEMENT(jc->c_dialogs, jd);
122 _eXosip_dialog_free(excontext, jd);
123 }
124
125 _eXosip_delete_reserved(jc->c_inc_tr);
126 _eXosip_delete_reserved(jc->c_out_tr);
127 _eXosip_delete_reserved(jc->c_cancel_tr);
128
129 if (jc->c_inc_tr != NULL)
130 osip_list_add(&excontext->j_transactions, jc->c_inc_tr, 0);
131
132 if (jc->c_out_tr != NULL)
133 osip_list_add(&excontext->j_transactions, jc->c_out_tr, 0);
134
135 if (jc->c_cancel_tr != NULL)
136 osip_list_add(&excontext->j_transactions, jc->c_cancel_tr, 0);
137
138 osip_free(jc);
139 #ifndef MINISIZE
140 excontext->statistics.allocated_calls--;
141 #endif
142 }
143