Browse code

ims_charging: fix for app_provided_party functionality, also support interim/stop reqs

Henning Westerholt authored on 09/07/2020 19:24:49
Showing 1 changed files
... ...
@@ -196,11 +196,11 @@ void destroy_dlg_table(void) {
196 196
 
197 197
 struct ro_session* build_new_ro_session(int direction, int auth_appid, int auth_session_type, str *session_id, str *callid, str *asserted_identity, 
198 198
 	str* called_asserted_identity, str* mac, unsigned int dlg_h_entry, unsigned int dlg_h_id, unsigned int requested_secs, unsigned int validity_timeout,
199
-	int active_rating_group, int active_service_identifier, str *incoming_trunk_id, str *outgoing_trunk_id, str *pani){
199
+	int active_rating_group, int active_service_identifier, str *incoming_trunk_id, str *outgoing_trunk_id, str *pani, str *app_provided_party){
200 200
     LM_DBG("Building Ro Session **********\n");
201 201
     char *p;
202 202
     unsigned int len = /*session_id->len + */callid->len + asserted_identity->len + called_asserted_identity->len + mac->len + 
203
-        incoming_trunk_id->len + outgoing_trunk_id->len + pani->len + sizeof (struct ro_session);
203
+        incoming_trunk_id->len + outgoing_trunk_id->len + pani->len + app_provided_party->len + sizeof (struct ro_session);
204 204
     struct ro_session *new_ro_session = (struct ro_session*) shm_malloc(len);
205 205
 
206 206
     if (!new_ro_session) {
... ...
@@ -276,6 +276,11 @@ struct ro_session* build_new_ro_session(int direction, int auth_appid, int auth_
276 276
     new_ro_session->pani.len = pani->len;
277 277
     p += pani->len;
278 278
 
279
+    new_ro_session->app_provided_party.s = p;
280
+    memcpy(p, app_provided_party->s, app_provided_party->len);
281
+    new_ro_session->app_provided_party.len = app_provided_party->len;
282
+    p += app_provided_party->len;
283
+
279 284
     if (p != (((char*) new_ro_session) + len)) {
280 285
         LM_ERR("buffer overflow\n");
281 286
         shm_free(new_ro_session);
Browse code

ims_charging: fix missing line-breaks for log messages

Henning Westerholt authored on 10/06/2020 11:50:51
Showing 1 changed files
... ...
@@ -22,7 +22,7 @@ struct ro_session_table *ro_session_table = 0;
22 22
 void link_ro_session(struct ro_session *ro_session, int n) {
23 23
     struct ro_session_entry *ro_session_entry;
24 24
     
25
-    LM_DBG("Linking Ro session [%.*s] into entries hash index [%d]", ro_session->ro_session_id.len, ro_session->ro_session_id.s, ro_session->h_entry);
25
+    LM_DBG("Linking Ro session [%.*s] into entries hash index [%d]\n", ro_session->ro_session_id.len, ro_session->ro_session_id.s, ro_session->h_entry);
26 26
 
27 27
     ro_session_entry = &(ro_session_table->entries[ro_session->h_entry]);
28 28
 
... ...
@@ -197,7 +197,7 @@ void destroy_dlg_table(void) {
197 197
 struct ro_session* build_new_ro_session(int direction, int auth_appid, int auth_session_type, str *session_id, str *callid, str *asserted_identity, 
198 198
 	str* called_asserted_identity, str* mac, unsigned int dlg_h_entry, unsigned int dlg_h_id, unsigned int requested_secs, unsigned int validity_timeout,
199 199
 	int active_rating_group, int active_service_identifier, str *incoming_trunk_id, str *outgoing_trunk_id, str *pani){
200
-    LM_DBG("Building Ro Session **********");
200
+    LM_DBG("Building Ro Session **********\n");
201 201
     char *p;
202 202
     unsigned int len = /*session_id->len + */callid->len + asserted_identity->len + called_asserted_identity->len + mac->len + 
203 203
         incoming_trunk_id->len + outgoing_trunk_id->len + pani->len + sizeof (struct ro_session);
Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,332 @@
1
+/* 
2
+ * File:   ro_session_hash.c
3
+ * Author: Jason Penton
4
+ *
5
+ * Created on 08 April 2011, 1:10 PM
6
+ */
7
+
8
+#include "ro_session_hash.h"
9
+#include "ims_ro.h"
10
+
11
+#define MAX_ROSESSION_LOCKS  2048
12
+#define MIN_ROSESSION_LOCKS  2
13
+
14
+/*! global ro_session table */
15
+struct ro_session_table *ro_session_table = 0;
16
+
17
+/*!
18
+ * \brief Link a ro_session structure
19
+ * \param ro_session Ro Session
20
+ * \param n extra increments for the reference counter
21
+ */
22
+void link_ro_session(struct ro_session *ro_session, int n) {
23
+    struct ro_session_entry *ro_session_entry;
24
+    
25
+    LM_DBG("Linking Ro session [%.*s] into entries hash index [%d]", ro_session->ro_session_id.len, ro_session->ro_session_id.s, ro_session->h_entry);
26
+
27
+    ro_session_entry = &(ro_session_table->entries[ro_session->h_entry]);
28
+
29
+    ro_session_lock(ro_session_table, ro_session_entry);
30
+
31
+    ro_session->h_id = ro_session_entry->next_id++;
32
+    if (ro_session_entry->first == 0) {
33
+        ro_session_entry->first = ro_session_entry->last = ro_session;
34
+    } else {
35
+        ro_session_entry->last->next = ro_session;
36
+        ro_session->prev = ro_session_entry->last;
37
+        ro_session_entry->last = ro_session;
38
+    }
39
+
40
+    ro_session->ref += 1 + n;
41
+    
42
+    ro_session_unlock(ro_session_table, ro_session_entry);
43
+
44
+    return;
45
+}
46
+
47
+/*!
48
+ * \brief Refefence an ro_session with locking
49
+ * \see ref_ro_session_unsafe
50
+ * \param ro_session Ro Session
51
+ * \param cnt increment for the reference counter
52
+ */
53
+void ref_ro_session_helper(struct ro_session *ro_session, unsigned int cnt, unsigned int mustlock, char *fname, int fline) {
54
+    struct ro_session_entry *ro_session_entry;
55
+
56
+	LM_DBG("ref op on %p with %d from %s:%d\n", ro_session, cnt, fname, fline);
57
+    ro_session_entry = &(ro_session_table->entries[ro_session->h_entry]);
58
+
59
+    if (mustlock)
60
+		ro_session_lock(ro_session_table, ro_session_entry);
61
+    
62
+	ref_ro_session_unsafe(ro_session, cnt);
63
+    
64
+	if (mustlock)
65
+		ro_session_unlock(ro_session_table, ro_session_entry);
66
+}
67
+
68
+/*!
69
+ * \brief Unreference an ro_session with locking
70
+ * \see unref_ro_session_unsafe
71
+ * \param ro_session Ro Session
72
+ * \param cnt decrement for the reference counter
73
+ */
74
+void unref_ro_session_helper(struct ro_session *ro_session, unsigned int cnt, unsigned int mustlock, char *fname, int fline) {
75
+    struct ro_session_entry *ro_session_entry;
76
+
77
+	LM_DBG("unref op on %p with %d from %s:%d\n", ro_session, cnt, fname, fline);
78
+
79
+	ro_session_entry = &(ro_session_table->entries[ro_session->h_entry]);
80
+	if (mustlock)
81
+		ro_session_lock(ro_session_table, ro_session_entry);
82
+    unref_ro_session_unsafe(ro_session, cnt, ro_session_entry);
83
+	if (mustlock)
84
+		ro_session_unlock(ro_session_table, ro_session_entry);
85
+}
86
+
87
+/*!
88
+ * \brief Initialize the global ro_session table
89
+ * \param size size of the table
90
+ * \return 0 on success, -1 on failure
91
+ */
92
+int init_ro_session_table(unsigned int size) {
93
+    unsigned int n;
94
+    unsigned int i;
95
+
96
+    ro_session_table = (struct ro_session_table*) shm_malloc(sizeof (struct ro_session_table) + size * sizeof (struct ro_session_entry));
97
+    if (ro_session_table == 0) {
98
+        LM_ERR("no more shm mem (1)\n");
99
+        goto error0;
100
+    }
101
+
102
+    memset(ro_session_table, 0, sizeof (struct ro_session_table));
103
+    ro_session_table->size = size;
104
+    ro_session_table->entries = (struct ro_session_entry*) (ro_session_table + 1);
105
+
106
+    n = (size < MAX_ROSESSION_LOCKS) ? size : MAX_ROSESSION_LOCKS;
107
+    for (; n >= MIN_ROSESSION_LOCKS; n--) {
108
+        ro_session_table->locks = lock_set_alloc(n);
109
+        if (ro_session_table->locks == 0)
110
+            continue;
111
+        if (lock_set_init(ro_session_table->locks) == 0) {
112
+            lock_set_dealloc(ro_session_table->locks);
113
+            ro_session_table->locks = 0;
114
+            continue;
115
+        }
116
+        ro_session_table->locks_no = n;
117
+        break;
118
+    }
119
+
120
+    if (ro_session_table->locks == 0) {
121
+        LM_ERR("unable to allocate at least %d locks for the hash table\n",
122
+                MIN_ROSESSION_LOCKS);
123
+        goto error1;
124
+    }
125
+
126
+    for (i = 0; i < size; i++) {
127
+        memset(&(ro_session_table->entries[i]), 0, sizeof (struct ro_session_entry));
128
+        ro_session_table->entries[i].next_id = kam_rand() % (3*size);
129
+        ro_session_table->entries[i].lock_idx = i % ro_session_table->locks_no;
130
+    }
131
+
132
+    return 0;
133
+error1:
134
+    shm_free(ro_session_table);
135
+    ro_session_table = NULL;
136
+error0:
137
+    return -1;
138
+}
139
+
140
+int put_ro_session_on_wait(struct ro_session* session) {
141
+    LM_DBG("Putting Ro session [%p] - [%.*s] on wait queue for deletion\n", session, session->ro_session_id.len, session->ro_session_id.s);
142
+    session->event_type = delayed_delete;
143
+    session->last_event_timestamp = get_current_time_micro();
144
+    insert_ro_timer(&session->ro_tl, 120);
145
+    
146
+    return 0;
147
+}
148
+
149
+/*!
150
+ * \brief Destroy an ro_session and free memory
151
+ * \param ro_session destroyed Ro Session
152
+ */
153
+inline void destroy_ro_session(struct ro_session *ro_session) {
154
+
155
+    LM_DBG("destroying Ro Session %p\n", ro_session);
156
+
157
+    remove_ro_timer(&ro_session->ro_tl);
158
+    
159
+    if (ro_session->ro_session_id.s && (ro_session->ro_session_id.len > 0)) {
160
+        shm_free(ro_session->ro_session_id.s);
161
+    }
162
+
163
+    shm_free(ro_session);
164
+}
165
+
166
+/*!
167
+ * \brief Destroy the global Ro session table
168
+ */
169
+void destroy_dlg_table(void) {
170
+    struct ro_session *ro_session, *l_ro_session;
171
+    unsigned int i;
172
+
173
+    if (ro_session_table == 0)
174
+        return;
175
+
176
+    if (ro_session_table->locks) {
177
+        lock_set_destroy(ro_session_table->locks);
178
+        lock_set_dealloc(ro_session_table->locks);
179
+    }
180
+
181
+    for (i = 0; i < ro_session_table->size; i++) {
182
+        ro_session = ro_session_table->entries[i].first;
183
+        while (ro_session) {
184
+            l_ro_session = ro_session;
185
+            ro_session = ro_session->next;
186
+            destroy_ro_session(l_ro_session);
187
+        }
188
+
189
+    }
190
+
191
+    shm_free(ro_session_table);
192
+    ro_session_table = 0;
193
+
194
+    return;
195
+}
196
+
197
+struct ro_session* build_new_ro_session(int direction, int auth_appid, int auth_session_type, str *session_id, str *callid, str *asserted_identity, 
198
+	str* called_asserted_identity, str* mac, unsigned int dlg_h_entry, unsigned int dlg_h_id, unsigned int requested_secs, unsigned int validity_timeout,
199
+	int active_rating_group, int active_service_identifier, str *incoming_trunk_id, str *outgoing_trunk_id, str *pani){
200
+    LM_DBG("Building Ro Session **********");
201
+    char *p;
202
+    unsigned int len = /*session_id->len + */callid->len + asserted_identity->len + called_asserted_identity->len + mac->len + 
203
+        incoming_trunk_id->len + outgoing_trunk_id->len + pani->len + sizeof (struct ro_session);
204
+    struct ro_session *new_ro_session = (struct ro_session*) shm_malloc(len);
205
+
206
+    if (!new_ro_session) {
207
+        LM_ERR("no more shm mem.\n");
208
+        shm_free(new_ro_session);
209
+        return 0;
210
+    }
211
+    
212
+    LM_DBG("New Ro Session given memory at address [%p]\n", new_ro_session);
213
+
214
+    memset(new_ro_session, 0, len);
215
+    
216
+//    if (pani->len < MAX_PANI_LEN) {
217
+//		p = new_ro_session->pani;
218
+//		memcpy(p, pani->s, pani->len);
219
+//    }
220
+
221
+    new_ro_session->direction = direction;
222
+    new_ro_session->auth_appid = auth_appid;
223
+    new_ro_session->auth_session_type = auth_session_type;
224
+
225
+    new_ro_session->ro_tl.next = new_ro_session->ro_tl.prev;// = 0;
226
+    new_ro_session->ro_tl.timeout = 0; //requested_secs;
227
+
228
+    new_ro_session->reserved_secs = requested_secs;
229
+    new_ro_session->valid_for = validity_timeout;
230
+
231
+    new_ro_session->hop_by_hop = 0;
232
+    new_ro_session->next = 0;
233
+    new_ro_session->dlg_h_entry = dlg_h_entry;
234
+    new_ro_session->dlg_h_id = dlg_h_id;
235
+
236
+    new_ro_session->h_entry = dlg_h_entry; /* we will use the same entry ID as the dlg - saves us using our own hash function */
237
+    new_ro_session->h_id = 0;
238
+    new_ro_session->ref = 1;
239
+    
240
+    new_ro_session->rating_group = active_rating_group;
241
+    new_ro_session->service_identifier = active_service_identifier;
242
+
243
+    p = (char*) (new_ro_session + 1);
244
+    new_ro_session->callid.s = p;
245
+    new_ro_session->callid.len = callid->len;
246
+    memcpy(p, callid->s, callid->len);
247
+    p += callid->len;
248
+
249
+    new_ro_session->asserted_identity.s = p;
250
+    new_ro_session->asserted_identity.len = asserted_identity->len;
251
+    memcpy(p, asserted_identity->s, asserted_identity->len);
252
+    p += asserted_identity->len;
253
+
254
+    new_ro_session->called_asserted_identity.s = p;
255
+    new_ro_session->called_asserted_identity.len = called_asserted_identity->len;
256
+    memcpy(p, called_asserted_identity->s, called_asserted_identity->len);
257
+    p += called_asserted_identity->len;
258
+    
259
+    new_ro_session->incoming_trunk_id.s = p;
260
+    new_ro_session->incoming_trunk_id.len = incoming_trunk_id->len;
261
+    memcpy(p, incoming_trunk_id->s, incoming_trunk_id->len);
262
+    p += incoming_trunk_id->len;
263
+    
264
+    new_ro_session->outgoing_trunk_id.s = p;
265
+    new_ro_session->outgoing_trunk_id.len = outgoing_trunk_id->len;
266
+    memcpy(p, outgoing_trunk_id->s, outgoing_trunk_id->len);
267
+    p += outgoing_trunk_id->len;
268
+    
269
+    new_ro_session->mac.s = p;
270
+    new_ro_session->mac.len = mac->len;
271
+    memcpy(p, mac->s, mac->len);
272
+    p += mac->len;
273
+    
274
+    new_ro_session->pani.s = p;
275
+    memcpy(p, pani->s, pani->len);
276
+    new_ro_session->pani.len = pani->len;
277
+    p += pani->len;
278
+
279
+    if (p != (((char*) new_ro_session) + len)) {
280
+        LM_ERR("buffer overflow\n");
281
+        shm_free(new_ro_session);
282
+        return 0;
283
+    }
284
+
285
+    return new_ro_session;
286
+
287
+}
288
+
289
+/*!
290
+ * \brief Lookup an Ro session in the global list
291
+ * \param h_entry number of the hash table entry
292
+ * \param h_id id of the hash table entry
293
+ * \return ro_session on success, NULL on failure
294
+ */
295
+struct ro_session* lookup_ro_session(unsigned int h_entry, str* callid, int direction, unsigned int *del) {
296
+    struct ro_session *ro_session;
297
+    struct ro_session_entry *ro_session_entry;
298
+
299
+    if (del != NULL)
300
+        *del = 0;
301
+
302
+    if (h_entry >= ro_session_table->size)
303
+        goto not_found;
304
+    ro_session_entry = &(ro_session_table->entries[h_entry]);
305
+
306
+    ro_session_lock(ro_session_table, ro_session_entry);
307
+
308
+    for (ro_session = ro_session_entry->first; ro_session; ro_session = ro_session->next) {
309
+        if ((direction==0 || direction==ro_session->direction) && (strncmp(ro_session->callid.s, callid->s, callid->len)==0)) {
310
+		ref_ro_session(ro_session, 1, 0);
311
+            LM_DBG("ref ro_session %p with 1 -> %d\n", ro_session, ro_session->ref);
312
+            ro_session_unlock(ro_session_table, ro_session_entry);
313
+            LM_DBG("ro_session id=%u found on entry %u\n", ro_session->h_id, h_entry);
314
+            return ro_session;
315
+        }
316
+    }
317
+
318
+    ro_session_unlock(ro_session_table, ro_session_entry);
319
+not_found:
320
+    LM_DBG("no ro_session for callid=%.*s found on entry %u\n", callid->len, callid->s, h_entry);
321
+    return 0;
322
+}
323
+
324
+/*
325
+ * \brief free impu_data parcel
326
+ */
327
+void free_impu_data(struct impu_data *impu_data) {
328
+    if(impu_data){
329
+	shm_free(impu_data);
330
+	impu_data=0;
331
+    }
332
+}