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
deleted file mode 100644
... ...
@@ -1,505 +0,0 @@
1
-/*
2
- * pua_reginfo module - Presence-User-Agent Handling of reg events
3
- *
4
- * Copyright (C) 2011-2012 Carsten Bock, carsten@ng-voice.com
5
- * http://www.ng-voice.com
6
- *
7
- * This file is part of Kamailio, a free SIP server.
8
- *
9
- * Kamailio is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version
13
- *
14
- * Kamailio is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
- * GNU General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License 
20
- * along with this program; if not, write to the Free Software 
21
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
- */
23
-
24
-#include "notify.h"
25
-#include "../../parser/parse_from.h"
26
-#include "../../parser/parse_content.h"
27
-#include "../../parser/parse_uri.h"
28
-#include "../../modules/usrloc/usrloc.h"
29
-#include "../../lib/srutils/sruid.h"
30
-#include <libxml/parser.h>
31
-#include "usrloc_cb.h"
32
-#include "pua_reginfo.h"
33
-
34
-/*<?xml version="1.0"?>
35
-<reginfo xmlns="urn:ietf:params:xml:ns:reginfo" version="0" state="full">
36
-.<registration aor="sip:carsten@ng-voice.com" id="0xb33fa860" state="active">
37
-..<contact id="0xb33fa994" state="active" event="registered" expires="3600">
38
-...<uri>sip:carsten@10.157.87.36:43582;transport=udp</uri>
39
-...<unknown-param name="+g.3gpp.cs-voice"></unknown-param>
40
-...<unknown-param name="+g.3gpp.icsi-ref">urn0X0.0041FB74E7B54P-1022urn-70X0P+03gpp-application.ims.iari.gsma-vs</unknown-param>
41
-...<unknown-param name="audio"></unknown-param>
42
-...<unknown-param name="+g.oma.sip-im.large-message"></unknown-param>
43
-...<unknown-param name="+g.3gpp.smsip"></unknown-param>
44
-...<unknown-param name="language">en,fr</unknown-param>
45
-...<unknown-param name="+g.oma.sip-im"></unknown-param>
46
-...<unknown-param name="expires">600000</unknown-param>
47
-..</contact>
48
-.</registration>
49
-</reginfo> */
50
-
51
-#define STATE_ACTIVE 1
52
-#define STATE_TERMINATED 0
53
-#define STATE_UNKNOWN -1
54
-
55
-#define EVENT_UNKNOWN -1
56
-#define EVENT_REGISTERED 0
57
-#define EVENT_UNREGISTERED 1
58
-#define EVENT_TERMINATED 2
59
-#define EVENT_CREATED 3
60
-#define EVENT_REFRESHED 4
61
-#define EVENT_EXPIRED 5
62
-
63
-#define RESULT_ERROR -1
64
-#define RESULT_CONTACTS_FOUND 1
65
-#define RESULT_NO_CONTACTS 2
66
-
67
-extern sruid_t _reginfo_sruid;
68
-
69
-int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str callid,
70
-		int cseq, int expires, int event, str contact_uri) {
71
-	str no_str = {0, 0};
72
-	static str no_ua = str_init("n/a");
73
-	static ucontact_info_t ci;
74
-	ucontact_t * ul_contact;
75
-	int ret;
76
-
77
-	pua_reginfo_update_self_op(1);
78
-	if (*ul_record == NULL) {
79
-		switch(event) {
80
-			case EVENT_REGISTERED:
81
-			case EVENT_CREATED:
82
-			case EVENT_REFRESHED:
83
-				/* In case, no record exists and new one should be created,
84
-				   create a new entry for this user in the usrloc-DB */
85
-				if (ul.insert_urecord(domain, &aor, ul_record) < 0) {
86
-					LM_ERR("failed to insert new user-record\n");
87
-					ret = RESULT_ERROR;
88
-					goto done;
89
-				}
90
-				break;
91
-			default:
92
-				/* No entry in usrloc and the contact is expired, deleted, unregistered, whatever:
93
-                                   We do not need to do anything. */
94
-				ret = RESULT_NO_CONTACTS;
95
-				goto done;
96
-		}
97
-	}
98
-	
99
-	/* Make sure, no crap is in the structure: */
100
-	memset( &ci, 0, sizeof(ucontact_info_t));	
101
-	/* Get callid of the message */
102
-	ci.callid = &callid;
103
-	/* Get CSeq number of the message */
104
-	ci.cseq = cseq;
105
-	ci.sock = NULL;
106
-	/* additional info from message */
107
-	ci.user_agent = &no_ua;
108
-	ci.last_modified = time(0);
109
-
110
-	/* set expire time */
111
-	ci.expires = time(0) + expires;
112
-
113
-	/* set ruid */
114
-	if(sruid_next(&_reginfo_sruid) < 0) {
115
-		LM_ERR("failed to generate ruid");
116
-	} else {
117
-		ci.ruid = _reginfo_sruid.uid;
118
-	}
119
-
120
-	/* Now we start looking for the contact: */
121
-	if (((*ul_record)->contacts == 0)
122
-		|| (ul.get_ucontact(*ul_record, &contact_uri, &callid, &no_str, cseq+1, &ul_contact) != 0)) {
123
-		if (ul.insert_ucontact(*ul_record, &contact_uri, &ci, &ul_contact) < 0) {
124
-			LM_ERR("failed to insert new contact\n");
125
-			ret = RESULT_ERROR;
126
-			goto done;
127
-		}
128
-	} else {
129
-		if (ul.update_ucontact(*ul_record, ul_contact, &ci) < 0) {
130
-			LM_ERR("failed to update contact\n");
131
-			ret = RESULT_ERROR;
132
-			goto done;
133
-		}
134
-	}
135
-	ul_contact = (*ul_record)->contacts;
136
-	while (ul_contact) {
137
-		if (VALID_CONTACT(ul_contact, time(0))) return RESULT_CONTACTS_FOUND;
138
-		ul_contact = ul_contact->next;
139
-	}
140
-
141
-	ret = RESULT_NO_CONTACTS;
142
-done:
143
-	pua_reginfo_update_self_op(0);
144
-	return ret;
145
-}
146
-
147
-xmlNodePtr xmlGetNodeByName(xmlNodePtr parent, const char *name) {
148
-	xmlNodePtr cur = parent;
149
-	xmlNodePtr match = NULL;
150
-	while (cur) {
151
-		if (xmlStrcasecmp(cur->name, (unsigned char*)name) == 0)
152
-			return cur;
153
-		match = xmlGetNodeByName(cur->children, name);
154
-		if (match)
155
-			return match;
156
-		cur = cur->next;
157
-	}
158
-	return NULL;
159
-}
160
-
161
-char * xmlGetAttrContentByName(xmlNodePtr node, const char *name) {
162
-	xmlAttrPtr attr = node->properties;
163
-	while (attr) {
164
-		if (xmlStrcasecmp(attr->name, (unsigned char*)name) == 0)
165
-			return (char*)xmlNodeGetContent(attr->children);
166
-		attr = attr->next;
167
-	}
168
-	return NULL;
169
-}
170
-
171
-int reginfo_parse_state(char * s) {
172
-	if (s == NULL) {
173
-		return STATE_UNKNOWN;
174
-	}
175
-	switch (strlen(s)) {
176
-		case 6:
177
-			if (strncmp(s, "active", 6) ==  0) return STATE_ACTIVE;
178
-			break;
179
-		case 10:
180
-			if (strncmp(s, "terminated", 10) ==  0) return STATE_TERMINATED;
181
-			break;
182
-		default:
183
-			LM_ERR("Unknown State %s\n", s);
184
-			return STATE_UNKNOWN;
185
-	}
186
-	LM_ERR("Unknown State %s\n", s);
187
-	return STATE_UNKNOWN;
188
-}
189
-
190
-int reginfo_parse_event(char * s) {
191
-	if (s == NULL) {
192
-		return EVENT_UNKNOWN;
193
-	}
194
-	switch (strlen(s)) {
195
-		case 7:
196
-			if (strncmp(s, "created", 7) ==  0) return EVENT_CREATED;
197
-			if (strncmp(s, "expired", 7) ==  0) return EVENT_EXPIRED;
198
-			break;
199
-		case 9:
200
-			if (strncmp(s, "refreshed", 9) ==  0) return EVENT_CREATED;
201
-			break;
202
-		case 10:
203
-			if (strncmp(s, "registered", 10) ==  0) return EVENT_REGISTERED;
204
-			if (strncmp(s, "terminated", 10) ==  0) return EVENT_TERMINATED;
205
-			break;
206
-		case 12:
207
-			if (strncmp(s, "unregistered", 12) ==  0) return EVENT_UNREGISTERED;
208
-			break;
209
-		default:
210
-			LM_ERR("Unknown Event %s\n", s);
211
-			return EVENT_UNKNOWN;
212
-	}
213
-	LM_ERR("Unknown Event %s\n", s);
214
-	return EVENT_UNKNOWN;
215
-}
216
-
217
-int process_body(str notify_body, udomain_t * domain) {
218
-	xmlDocPtr doc= NULL;
219
-	xmlNodePtr doc_root = NULL, registrations = NULL, contacts = NULL, uris = NULL, params = NULL;
220
-	char uri[MAX_URI_SIZE];
221
-	str aor_key = {0, 0};
222
-	str aor = {0, 0};
223
-	str callid = {0, 0};
224
-	str contact = {0, 0};
225
-	str contact_uri = {0, 0};
226
-	str contact_params = {0, 0};
227
-	str param = {0, 0};
228
-	str received = {0,0};
229
-	str path = {0,0};
230
-	str user_agent = {0, 0};
231
-	int state, event, expires, result, final_result = RESULT_ERROR;
232
-	char * expires_char,  * cseq_char;
233
-	int cseq = 0;
234
-	int len;
235
-	urecord_t * ul_record;
236
-	ucontact_t * ul_contact;
237
-	struct sip_uri parsed_aor;
238
-
239
-	/* Temporary */
240
-	int mem_only = 1;
241
-
242
-	doc = xmlParseMemory(notify_body.s, notify_body.len);
243
-	if(doc== NULL)  {
244
-		LM_ERR("Error while parsing the xml body message, Body is:\n%.*s\n",
245
-			notify_body.len, notify_body.s);
246
-		return -1;
247
-	}
248
-	doc_root = xmlGetNodeByName(doc->children, "reginfo");
249
-	if(doc_root == NULL) {
250
-		LM_ERR("while extracting the reginfo node\n");
251
-		goto error;
252
-	}
253
-	registrations = doc_root->children;
254
-	while (registrations) {
255
-		/* Only process registration sub-items */
256
-		if (xmlStrcasecmp(registrations->name, BAD_CAST "registration") != 0)
257
-			goto next_registration;
258
-		state = reginfo_parse_state(xmlGetAttrContentByName(registrations, "state"));
259
-		if (state == STATE_UNKNOWN) {
260
-			LM_ERR("No state for this contact!\n");		
261
-			goto next_registration;
262
-		}
263
-		aor.s = xmlGetAttrContentByName(registrations, "aor");
264
-		if (aor.s == NULL) {
265
-			LM_ERR("No AOR for this contact!\n");		
266
-			goto next_registration;
267
-		}
268
-		aor.len = strlen(aor.s);
269
-		LM_DBG("AOR %.*s has state \"%d\"\n", aor.len, aor.s, state);
270
-
271
-		/* Get username part of the AOR, search for @ in the AOR. */
272
-		if (parse_uri(aor.s, aor.len, &parsed_aor) < 0) {
273
-			LM_ERR("failed to parse Address of Record (%.*s)\n",
274
-				aor.len, aor.s);
275
-			goto next_registration;
276
-		}
277
-
278
-		if (reginfo_use_domain) {
279
-			aor_key.s = uri;
280
-		} else {
281
-			aor_key.s = parsed_aor.user.s;
282
-		}
283
-		aor_key.len = strlen(aor_key.s);
284
-		/* Now let's lock that domain for this AOR: */		
285
-		ul.lock_udomain(domain, &aor_key);
286
-		/* and retrieve the user-record for this user: */
287
-		result = ul.get_urecord(domain, &aor_key, &ul_record);
288
-		if (result < 0) {
289
-			ul.unlock_udomain(domain, &aor_key);
290
-			LM_ERR("failed to query usrloc (AOR %.*s)\n",
291
-				aor_key.len, aor_key.s);
292
-			goto next_registration;
293
-		}
294
-		/* If no contacts found, then set the ul_record to NULL */
295
-		if (result != 0) ul_record = NULL;
296
-
297
-		/* If the state is terminated, we just can delete all bindings */
298
-		if (state == STATE_TERMINATED) {
299
-			if (ul_record) {
300
-				ul_contact = ul_record->contacts;
301
-				while(ul_contact) {
302
-					if (mem_only) {
303
-						ul_contact->flags |= FL_MEM;
304
-					} else {
305
-						ul_contact->flags &= ~FL_MEM;
306
-					}
307
-					ul_contact = ul_contact->next;
308
-				}
309
-				if (ul.delete_urecord(domain, &aor_key, ul_record) < 0) {
310
-					LM_ERR("failed to remove record from usrloc\n");
311
-				}
312
-				/* If already a registration with contacts was found, then keep that result.
313
-				   otherwise the result is now "No contacts found" */
314
-				if (final_result != RESULT_CONTACTS_FOUND) final_result = RESULT_NO_CONTACTS;
315
-			}
316
-		/* Otherwise, process the content */
317
-		} else {
318
-			/* Now lets process the Contact's from this Registration: */
319
-			contacts = registrations->children;
320
-			while (contacts) {
321
-				if (xmlStrcasecmp(contacts->name, BAD_CAST "contact") != 0)
322
-					goto next_contact;
323
-				callid.len = 0;
324
-				callid.s = xmlGetAttrContentByName(contacts, "callid");
325
-				// If no CallID present, try the "id"-field instead:
326
-				if (callid.s == NULL)
327
-					callid.s = xmlGetAttrContentByName(contacts, "id");
328
-				callid.len = strlen(callid.s);
329
-				LM_DBG("Got Call-ID \"%.*s\"\n", callid.len, callid.s);
330
-				received.s = xmlGetAttrContentByName(contacts, "received");
331
-				if (received.s == NULL) {
332
-                    LM_DBG("No received for this contact!\n");
333
-					received.len = 0;
334
-                } else {
335
-					received.len = strlen(received.s);
336
-				}
337
-
338
-				path.s = xmlGetAttrContentByName(contacts, "path");	
339
-				if (path.s == NULL) {
340
-                    LM_DBG("No path for this contact!\n");
341
-					path.len = 0;
342
-                } else {
343
-					path.len = strlen(path.s);
344
-				}
345
-
346
-				user_agent.s = xmlGetAttrContentByName(contacts, "user_agent");
347
-				if (user_agent.s == NULL) {
348
-                    LM_DBG("No user_agent for this contact!\n");
349
-					user_agent.len = 0;
350
-                } else {
351
-					user_agent.len = strlen(user_agent.s);
352
-				}
353
-				event = reginfo_parse_event(xmlGetAttrContentByName(contacts, "event"));
354
-				if (event == EVENT_UNKNOWN) {
355
-					LM_ERR("No event for this contact!\n");		
356
-					goto next_contact;
357
-				}
358
-				expires_char = xmlGetAttrContentByName(contacts, "expires");
359
-				if (expires_char == NULL) {
360
-					LM_ERR("No expires for this contact!\n");		
361
-					goto next_contact;
362
-				}
363
-				expires = atoi(expires_char);
364
-				if (expires < 0) {
365
-					LM_ERR("No valid expires for this contact!\n");		
366
-					goto next_contact;
367
-				}
368
-				LM_DBG("%.*s: Event \"%d\", expires %d\n",
369
-					callid.len, callid.s, event, expires);
370
-
371
-				cseq_char = xmlGetAttrContentByName(contacts, "cseq");
372
-				if (cseq_char == NULL) {
373
-					LM_DBG("No cseq for this contact!\n");		
374
-				} else {
375
-					cseq = atoi(cseq_char);
376
-					if (cseq < 0) {
377
-						LM_WARN("No valid cseq for this contact!\n");		
378
-					}
379
-				}
380
-
381
-				// <unknown-param name="+g.oma.sip-im"></unknown-param>
382
-				// <unknown-param name="language">en,fr</unknown-param>
383
-				/* 1) Iterate through the params, to get the full content-length */
384
-				params = contacts->children;
385
-				contact_params.len = 0;
386
-				len = 0;
387
-				while (params) {
388
-					if (xmlStrcasecmp(params->name, BAD_CAST "unknown-param") != 0)
389
-						goto next_param;
390
-					len += 1 /* ; */ + strlen(xmlGetAttrContentByName(params, "name"));
391
-					param.s = (char*)xmlNodeGetContent(params);
392
-					param.len = strlen(param.s);
393
-					if (param.len > 0)
394
-						len += 1 /* = */ + param.len;
395
-next_param:
396
-					params = params->next;
397
-				}
398
-				LM_DBG("Calculated length for params: %i\n", len);
399
-
400
-				if (len > 0) {
401
-					len += 1;
402
-					if (contact_params.s) pkg_free(contact_params.s);
403
-					contact_params.s = pkg_malloc(len);
404
-					params = contacts->children;
405
-					contact_params.len = 0;
406
-					while (params) {
407
-						if (xmlStrcasecmp(params->name, BAD_CAST "unknown-param") != 0)
408
-							goto next_param2;
409
-						contact_params.len += snprintf(contact_params.s + contact_params.len, len - contact_params.len, ";%s", xmlGetAttrContentByName(params, "name"));
410
-						param.s = (char*)xmlNodeGetContent(params);
411
-						param.len = strlen(param.s);
412
-						if (param.len > 0)
413
-							contact_params.len += snprintf(contact_params.s + contact_params.len, len - contact_params.len, "=%.*s", param.len, param.s);
414
-
415
-						LM_DBG("Contact params are: %.*s\n", contact_params.len, contact_params.s);
416
-			
417
-next_param2:
418
-						params = params->next;
419
-					}
420
-					LM_DBG("Contact params are: %.*s\n", contact_params.len, contact_params.s);
421
-				}
422
-
423
-				/* Now lets process the URI's from this Contact: */
424
-				uris = contacts->children;
425
-				while (uris) {
426
-					if (xmlStrcasecmp(uris->name, BAD_CAST "uri") != 0)
427
-						goto next_uri;
428
-					contact_uri.s = (char*)xmlNodeGetContent(uris);	
429
-					if (contact_uri.s == NULL) {
430
-						LM_ERR("No URI for this contact!\n");		
431
-						goto next_registration;
432
-					}
433
-					contact_uri.len = strlen(contact_uri.s);
434
-					if (contact_params.len > 0) {
435
-						if (contact.s) pkg_free(contact.s);
436
-						contact.s = (char*)pkg_malloc(contact_uri.len + contact_params.len + 1);
437
-						contact.len = snprintf(contact.s, contact_uri.len + contact_params.len + 1, "%.*s%.*s", contact_uri.len, contact_uri.s, contact_params.len, contact_params.s);
438
-						LM_DBG("Contact: %.*s\n",
439
-							contact.len, contact.s);
440
-
441
-						/* Add to Usrloc: */
442
-						result = process_contact(domain, &ul_record, aor_key, callid, cseq, expires, event, contact);
443
-					} else {
444
-						LM_DBG("Contact: %.*s\n",
445
-							contact_uri.len, contact_uri.s);
446
-
447
-						/* Add to Usrloc: */
448
-						result = process_contact(domain, &ul_record, aor_key, callid, cseq, expires, event, contact_uri);
449
-					}
450
-				
451
-					/* Process the result */
452
-					if (final_result != RESULT_CONTACTS_FOUND) final_result = result;
453
-next_uri:
454
-					uris = uris->next;
455
-				}
456
-next_contact:
457
-				contacts = contacts->next;
458
-			}
459
-		}
460
-next_registration:
461
-		// if (ul_record) ul.release_urecord(ul_record);		
462
-		/* Unlock the domain for this AOR: */
463
-		if (aor_key.len > 0)
464
-			ul.unlock_udomain(domain, &aor_key);
465
-
466
-		registrations = registrations->next;
467
-	}
468
-error:
469
-	if (contact.s) pkg_free(contact.s);
470
-	if (contact_params.s) pkg_free(contact_params.s);
471
-	/* Free the XML-Document */
472
-
473
-    	if(doc) xmlFreeDoc(doc);
474
-	return final_result;
475
-}
476
-
477
-int reginfo_handle_notify(struct sip_msg* msg, char* domain, char* s2) {
478
- 	str body;
479
-	int result = 1;
480
-
481
-  	/* If not done yet, parse the whole message now: */
482
-  	if (parse_headers(msg, HDR_EOH_F, 0) == -1) {
483
-  		LM_ERR("Error parsing headers\n");
484
-  		return -1;
485
-  	}
486
-	if (get_content_length(msg) == 0) {
487
-   		LM_DBG("Content length = 0\n");
488
-		/* No Body? Then there is no published information available, which is ok. */
489
-   		return 1;
490
-   	} else {
491
-   		body.s=get_body(msg);
492
-   		if (body.s== NULL) {
493
-   			LM_ERR("cannot extract body from msg\n");
494
-   			return -1;
495
-   		}
496
-   		body.len = get_content_length(msg);
497
-   	}
498
-
499
-	LM_DBG("Body is %.*s\n", body.len, body.s);
500
-	
501
-	result = process_body(body, (udomain_t*)domain);
502
-
503
-	return result;
504
-}
505
-
Browse code

pua_reginfo: Add support for custom params as contact parameters (e.g. <unknown-param name="+g.oma.sip-im"></unknown-param>)

Carsten Bock authored on 02/06/2015 18:18:50
Showing 1 changed files
... ...
@@ -216,18 +216,22 @@ int reginfo_parse_event(char * s) {
216 216
 
217 217
 int process_body(str notify_body, udomain_t * domain) {
218 218
 	xmlDocPtr doc= NULL;
219
-	xmlNodePtr doc_root = NULL, registrations = NULL, contacts = NULL, uris = NULL;
219
+	xmlNodePtr doc_root = NULL, registrations = NULL, contacts = NULL, uris = NULL, params = NULL;
220 220
 	char uri[MAX_URI_SIZE];
221 221
 	str aor_key = {0, 0};
222 222
 	str aor = {0, 0};
223 223
 	str callid = {0, 0};
224
+	str contact = {0, 0};
224 225
 	str contact_uri = {0, 0};
226
+	str contact_params = {0, 0};
227
+	str param = {0, 0};
225 228
 	str received = {0,0};
226 229
 	str path = {0,0};
227 230
 	str user_agent = {0, 0};
228 231
 	int state, event, expires, result, final_result = RESULT_ERROR;
229 232
 	char * expires_char,  * cseq_char;
230 233
 	int cseq = 0;
234
+	int len;
231 235
 	urecord_t * ul_record;
232 236
 	ucontact_t * ul_contact;
233 237
 	struct sip_uri parsed_aor;
... ...
@@ -316,12 +320,13 @@ int process_body(str notify_body, udomain_t * domain) {
316 320
 			while (contacts) {
317 321
 				if (xmlStrcasecmp(contacts->name, BAD_CAST "contact") != 0)
318 322
 					goto next_contact;
323
+				callid.len = 0;
319 324
 				callid.s = xmlGetAttrContentByName(contacts, "callid");
320
-				if (callid.s == NULL) {
321
-					LM_ERR("No Call-ID for this contact!\n");		
322
-					goto next_contact;
323
-				}
325
+				// If no CallID present, try the "id"-field instead:
326
+				if (callid.s == NULL)
327
+					callid.s = xmlGetAttrContentByName(contacts, "id");
324 328
 				callid.len = strlen(callid.s);
329
+				LM_DBG("Got Call-ID \"%.*s\"\n", callid.len, callid.s);
325 330
 				received.s = xmlGetAttrContentByName(contacts, "received");
326 331
 				if (received.s == NULL) {
327 332
                     LM_DBG("No received for this contact!\n");
... ...
@@ -365,7 +370,7 @@ int process_body(str notify_body, udomain_t * domain) {
365 370
 
366 371
 				cseq_char = xmlGetAttrContentByName(contacts, "cseq");
367 372
 				if (cseq_char == NULL) {
368
-					LM_WARN("No cseq for this contact!\n");		
373
+					LM_DBG("No cseq for this contact!\n");		
369 374
 				} else {
370 375
 					cseq = atoi(cseq_char);
371 376
 					if (cseq < 0) {
... ...
@@ -373,6 +378,48 @@ int process_body(str notify_body, udomain_t * domain) {
373 378
 					}
374 379
 				}
375 380
 
381
+				// <unknown-param name="+g.oma.sip-im"></unknown-param>
382
+				// <unknown-param name="language">en,fr</unknown-param>
383
+				/* 1) Iterate through the params, to get the full content-length */
384
+				params = contacts->children;
385
+				contact_params.len = 0;
386
+				len = 0;
387
+				while (params) {
388
+					if (xmlStrcasecmp(params->name, BAD_CAST "unknown-param") != 0)
389
+						goto next_param;
390
+					len += 1 /* ; */ + strlen(xmlGetAttrContentByName(params, "name"));
391
+					param.s = (char*)xmlNodeGetContent(params);
392
+					param.len = strlen(param.s);
393
+					if (param.len > 0)
394
+						len += 1 /* = */ + param.len;
395
+next_param:
396
+					params = params->next;
397
+				}
398
+				LM_DBG("Calculated length for params: %i\n", len);
399
+
400
+				if (len > 0) {
401
+					len += 1;
402
+					if (contact_params.s) pkg_free(contact_params.s);
403
+					contact_params.s = pkg_malloc(len);
404
+					params = contacts->children;
405
+					contact_params.len = 0;
406
+					while (params) {
407
+						if (xmlStrcasecmp(params->name, BAD_CAST "unknown-param") != 0)
408
+							goto next_param2;
409
+						contact_params.len += snprintf(contact_params.s + contact_params.len, len - contact_params.len, ";%s", xmlGetAttrContentByName(params, "name"));
410
+						param.s = (char*)xmlNodeGetContent(params);
411
+						param.len = strlen(param.s);
412
+						if (param.len > 0)
413
+							contact_params.len += snprintf(contact_params.s + contact_params.len, len - contact_params.len, "=%.*s", param.len, param.s);
414
+
415
+						LM_DBG("Contact params are: %.*s\n", contact_params.len, contact_params.s);
416
+			
417
+next_param2:
418
+						params = params->next;
419
+					}
420
+					LM_DBG("Contact params are: %.*s\n", contact_params.len, contact_params.s);
421
+				}
422
+
376 423
 				/* Now lets process the URI's from this Contact: */
377 424
 				uris = contacts->children;
378 425
 				while (uris) {
... ...
@@ -384,11 +431,22 @@ int process_body(str notify_body, udomain_t * domain) {
384 431
 						goto next_registration;
385 432
 					}
386 433
 					contact_uri.len = strlen(contact_uri.s);
387
-					LM_DBG("Contact: %.*s\n",
388
-						contact_uri.len, contact_uri.s);
434
+					if (contact_params.len > 0) {
435
+						if (contact.s) pkg_free(contact.s);
436
+						contact.s = (char*)pkg_malloc(contact_uri.len + contact_params.len + 1);
437
+						contact.len = snprintf(contact.s, contact_uri.len + contact_params.len + 1, "%.*s%.*s", contact_uri.len, contact_uri.s, contact_params.len, contact_params.s);
438
+						LM_DBG("Contact: %.*s\n",
439
+							contact.len, contact.s);
440
+
441
+						/* Add to Usrloc: */
442
+						result = process_contact(domain, &ul_record, aor_key, callid, cseq, expires, event, contact);
443
+					} else {
444
+						LM_DBG("Contact: %.*s\n",
445
+							contact_uri.len, contact_uri.s);
389 446
 
390
-					/* Add to Usrloc: */
391
-					result = process_contact(domain, &ul_record, aor_key, callid, cseq, expires, event, contact_uri);
447
+						/* Add to Usrloc: */
448
+						result = process_contact(domain, &ul_record, aor_key, callid, cseq, expires, event, contact_uri);
449
+					}
392 450
 				
393 451
 					/* Process the result */
394 452
 					if (final_result != RESULT_CONTACTS_FOUND) final_result = result;
... ...
@@ -408,7 +466,10 @@ next_registration:
408 466
 		registrations = registrations->next;
409 467
 	}
410 468
 error:
469
+	if (contact.s) pkg_free(contact.s);
470
+	if (contact_params.s) pkg_free(contact_params.s);
411 471
 	/* Free the XML-Document */
472
+
412 473
     	if(doc) xmlFreeDoc(doc);
413 474
 	return final_result;
414 475
 }
Browse code

pua_reginfo: avoid sending notify when processing location record action triggered by itself

Daniel-Constantin Mierla authored on 04/11/2014 15:32:13
Showing 1 changed files
... ...
@@ -28,6 +28,7 @@
28 28
 #include "../../modules/usrloc/usrloc.h"
29 29
 #include "../../lib/srutils/sruid.h"
30 30
 #include <libxml/parser.h>
31
+#include "usrloc_cb.h"
31 32
 #include "pua_reginfo.h"
32 33
 
33 34
 /*<?xml version="1.0"?>
... ...
@@ -71,7 +72,9 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
71 72
 	static str no_ua = str_init("n/a");
72 73
 	static ucontact_info_t ci;
73 74
 	ucontact_t * ul_contact;
75
+	int ret;
74 76
 
77
+	pua_reginfo_update_self_op(1);
75 78
 	if (*ul_record == NULL) {
76 79
 		switch(event) {
77 80
 			case EVENT_REGISTERED:
... ...
@@ -81,14 +84,15 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
81 84
 				   create a new entry for this user in the usrloc-DB */
82 85
 				if (ul.insert_urecord(domain, &aor, ul_record) < 0) {
83 86
 					LM_ERR("failed to insert new user-record\n");
84
-					return RESULT_ERROR;
87
+					ret = RESULT_ERROR;
88
+					goto done;
85 89
 				}
86 90
 				break;
87 91
 			default:
88 92
 				/* No entry in usrloc and the contact is expired, deleted, unregistered, whatever:
89 93
                                    We do not need to do anything. */
90
-				return RESULT_NO_CONTACTS;
91
-				break;
94
+				ret = RESULT_NO_CONTACTS;
95
+				goto done;
92 96
 		}
93 97
 	}
94 98
 	
... ...
@@ -118,12 +122,14 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
118 122
 		|| (ul.get_ucontact(*ul_record, &contact_uri, &callid, &no_str, cseq+1, &ul_contact) != 0)) {
119 123
 		if (ul.insert_ucontact(*ul_record, &contact_uri, &ci, &ul_contact) < 0) {
120 124
 			LM_ERR("failed to insert new contact\n");
121
-			return RESULT_ERROR;
125
+			ret = RESULT_ERROR;
126
+			goto done;
122 127
 		}
123 128
 	} else {
124 129
 		if (ul.update_ucontact(*ul_record, ul_contact, &ci) < 0) {
125 130
 			LM_ERR("failed to update contact\n");
126
-			return RESULT_ERROR;
131
+			ret = RESULT_ERROR;
132
+			goto done;
127 133
 		}
128 134
 	}
129 135
 	ul_contact = (*ul_record)->contacts;
... ...
@@ -132,7 +138,10 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
132 138
 		ul_contact = ul_contact->next;
133 139
 	}
134 140
 
135
-	return RESULT_NO_CONTACTS;
141
+	ret = RESULT_NO_CONTACTS;
142
+done:
143
+	pua_reginfo_update_self_op(0);
144
+	return ret;
136 145
 }
137 146
 
138 147
 xmlNodePtr xmlGetNodeByName(xmlNodePtr parent, const char *name) {
Browse code

all: updated FSF address in GPL text

Anthony Messina authored on 04/07/2014 09:36:37 • Daniel-Constantin Mierla committed on 04/07/2014 09:37:36
Showing 1 changed files
... ...
@@ -18,7 +18,7 @@
18 18
  *
19 19
  * You should have received a copy of the GNU General Public License 
20 20
  * along with this program; if not, write to the Free Software 
21
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 22
  */
23 23
 
24 24
 #include "notify.h"
Browse code

pua_reginfo: reflect use domain from usrloc

- avoid duplicate contacts if domain is not considered
- patch by Wonbin Cho, FS#350

Daniel-Constantin Mierla authored on 04/11/2013 09:04:35
Showing 1 changed files
... ...
@@ -208,6 +208,8 @@ int reginfo_parse_event(char * s) {
208 208
 int process_body(str notify_body, udomain_t * domain) {
209 209
 	xmlDocPtr doc= NULL;
210 210
 	xmlNodePtr doc_root = NULL, registrations = NULL, contacts = NULL, uris = NULL;
211
+	char uri[MAX_URI_SIZE];
212
+	str aor_key = {0, 0};
211 213
 	str aor = {0, 0};
212 214
 	str callid = {0, 0};
213 215
 	str contact_uri = {0, 0};
... ...
@@ -260,14 +262,20 @@ int process_body(str notify_body, udomain_t * domain) {
260 262
 			goto next_registration;
261 263
 		}
262 264
 
265
+		if (reginfo_use_domain) {
266
+			aor_key.s = uri;
267
+		} else {
268
+			aor_key.s = parsed_aor.user.s;
269
+		}
270
+		aor_key.len = strlen(aor_key.s);
263 271
 		/* Now let's lock that domain for this AOR: */		
264
-		ul.lock_udomain(domain, &aor);
272
+		ul.lock_udomain(domain, &aor_key);
265 273
 		/* and retrieve the user-record for this user: */
266
-		result = ul.get_urecord(domain, &aor, &ul_record);
274
+		result = ul.get_urecord(domain, &aor_key, &ul_record);
267 275
 		if (result < 0) {
268
-			ul.unlock_udomain(domain, &aor);
276
+			ul.unlock_udomain(domain, &aor_key);
269 277
 			LM_ERR("failed to query usrloc (AOR %.*s)\n",
270
-				aor.len, aor.s);
278
+				aor_key.len, aor_key.s);
271 279
 			goto next_registration;
272 280
 		}
273 281
 		/* If no contacts found, then set the ul_record to NULL */
... ...
@@ -285,7 +293,7 @@ int process_body(str notify_body, udomain_t * domain) {
285 293
 					}
286 294
 					ul_contact = ul_contact->next;
287 295
 				}
288
-				if (ul.delete_urecord(domain, &aor, ul_record) < 0) {
296
+				if (ul.delete_urecord(domain, &aor_key, ul_record) < 0) {
289 297
 					LM_ERR("failed to remove record from usrloc\n");
290 298
 				}
291 299
 				/* If already a registration with contacts was found, then keep that result.
... ...
@@ -371,7 +379,7 @@ int process_body(str notify_body, udomain_t * domain) {
371 379
 						contact_uri.len, contact_uri.s);
372 380
 
373 381
 					/* Add to Usrloc: */
374
-					result = process_contact(domain, &ul_record, parsed_aor.user, callid, cseq, expires, event, contact_uri);
382
+					result = process_contact(domain, &ul_record, aor_key, callid, cseq, expires, event, contact_uri);
375 383
 				
376 384
 					/* Process the result */
377 385
 					if (final_result != RESULT_CONTACTS_FOUND) final_result = result;
... ...
@@ -385,8 +393,8 @@ next_contact:
385 393
 next_registration:
386 394
 		// if (ul_record) ul.release_urecord(ul_record);		
387 395
 		/* Unlock the domain for this AOR: */
388
-		if (aor.len > 0)
389
-			ul.unlock_udomain(domain, &aor);
396
+		if (aor_key.len > 0)
397
+			ul.unlock_udomain(domain, &aor_key);
390 398
 
391 399
 		registrations = registrations->next;
392 400
 	}
Browse code

pua_reginfo: add ruid for location records

- patch by Wonbin Cho, FS#339

Daniel-Constantin Mierla authored on 18/09/2013 20:17:55
Showing 1 changed files
... ...
@@ -26,6 +26,7 @@
26 26
 #include "../../parser/parse_content.h"
27 27
 #include "../../parser/parse_uri.h"
28 28
 #include "../../modules/usrloc/usrloc.h"
29
+#include "../../lib/srutils/sruid.h"
29 30
 #include <libxml/parser.h>
30 31
 #include "pua_reginfo.h"
31 32
 
... ...
@@ -62,7 +63,10 @@
62 63
 #define RESULT_CONTACTS_FOUND 1
63 64
 #define RESULT_NO_CONTACTS 2
64 65
 
65
-int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str callid, int cseq, int expires, int event, str contact_uri) {
66
+extern sruid_t _reginfo_sruid;
67
+
68
+int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str callid,
69
+		int cseq, int expires, int event, str contact_uri) {
66 70
 	str no_str = {0, 0};
67 71
 	static str no_ua = str_init("n/a");
68 72
 	static ucontact_info_t ci;
... ...
@@ -102,6 +106,13 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
102 106
 	/* set expire time */
103 107
 	ci.expires = time(0) + expires;
104 108
 
109
+	/* set ruid */
110
+	if(sruid_next(&_reginfo_sruid) < 0) {
111
+		LM_ERR("failed to generate ruid");
112
+	} else {
113
+		ci.ruid = _reginfo_sruid.uid;
114
+	}
115
+
105 116
 	/* Now we start looking for the contact: */
106 117
 	if (((*ul_record)->contacts == 0)
107 118
 		|| (ul.get_ucontact(*ul_record, &contact_uri, &callid, &no_str, cseq+1, &ul_contact) != 0)) {
Browse code

pua_reginfo: unlock udomain only when aor is set

- patch by Wonbin Cho, FS#338

Daniel-Constantin Mierla authored on 18/09/2013 20:02:04
Showing 1 changed files
... ...
@@ -374,7 +374,8 @@ next_contact:
374 374
 next_registration:
375 375
 		// if (ul_record) ul.release_urecord(ul_record);		
376 376
 		/* Unlock the domain for this AOR: */
377
-		ul.unlock_udomain(domain, &aor);
377
+		if (aor.len > 0)
378
+			ul.unlock_udomain(domain, &aor);
378 379
 
379 380
 		registrations = registrations->next;
380 381
 	}
Browse code

pua_reginfo: fix setting lengths of contact attributes

- fix also for warning from FS#255 reported by Ovidiu Sas

Daniel-Constantin Mierla authored on 22/01/2013 12:40:11
Showing 1 changed files
... ...
@@ -296,22 +296,27 @@ int process_body(str notify_body, udomain_t * domain) {
296 296
 				callid.len = strlen(callid.s);
297 297
 				received.s = xmlGetAttrContentByName(contacts, "received");
298 298
 				if (received.s == NULL) {
299
-                                        LM_DBG("No received for this contact!\n");
300
-                                }
301
-				received.len - strlen(received.s);
299
+                    LM_DBG("No received for this contact!\n");
300
+					received.len = 0;
301
+                } else {
302
+					received.len = strlen(received.s);
303
+				}
302 304
 
303 305
 				path.s = xmlGetAttrContentByName(contacts, "path");	
304
-				if (received.s == NULL) {
305
-                                        LM_DBG("No path for this contact!\n");
306
-                                }
307
-				path.len = strlen(path.s);
306
+				if (path.s == NULL) {
307
+                    LM_DBG("No path for this contact!\n");
308
+					path.len = 0;
309
+                } else {
310
+					path.len = strlen(path.s);
311
+				}
308 312
 
309 313
 				user_agent.s = xmlGetAttrContentByName(contacts, "user_agent");
310
-				if (received.s == NULL) {
311
-                                        LM_DBG("No user_agent for this contact!\n");
312
-                                }
313
-				user_agent.len = strlen(user_agent.s);
314
-
314
+				if (user_agent.s == NULL) {
315
+                    LM_DBG("No user_agent for this contact!\n");
316
+					user_agent.len = 0;
317
+                } else {
318
+					user_agent.len = strlen(user_agent.s);
319
+				}
315 320
 				event = reginfo_parse_event(xmlGetAttrContentByName(contacts, "event"));
316 321
 				if (event == EVENT_UNKNOWN) {
317 322
 					LM_ERR("No event for this contact!\n");		
Browse code

modules/*: updated include paths

Daniel-Constantin Mierla authored on 20/01/2013 12:26:01
Showing 1 changed files
... ...
@@ -25,7 +25,7 @@
25 25
 #include "../../parser/parse_from.h"
26 26
 #include "../../parser/parse_content.h"
27 27
 #include "../../parser/parse_uri.h"
28
-#include "../../modules_k/usrloc/usrloc.h"
28
+#include "../../modules/usrloc/usrloc.h"
29 29
 #include <libxml/parser.h>
30 30
 #include "pua_reginfo.h"
31 31
 
Browse code

modules_k/*: moved k modules in directory modules/

Daniel-Constantin Mierla authored on 20/01/2013 11:57:52
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,410 @@
1
+/*
2
+ * pua_reginfo module - Presence-User-Agent Handling of reg events
3
+ *
4
+ * Copyright (C) 2011-2012 Carsten Bock, carsten@ng-voice.com
5
+ * http://www.ng-voice.com
6
+ *
7
+ * This file is part of Kamailio, a free SIP server.
8
+ *
9
+ * Kamailio is free software; you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation; either version 2 of the License, or
12
+ * (at your option) any later version
13
+ *
14
+ * Kamailio is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License