Browse code

lost: use of parser functions parse_pai_header() and parse_from_header() related to #2723

- lost_get_pai_header(): parsing method update
lost_get_from_header(): parsing method update

- memset(): fixed number of bytes to be filled (unrelated)

Wolfgang Kampichler authored on 05/05/2021 16:40:05
Showing 1 changed files
... ...
@@ -129,7 +129,7 @@ p_lost_loc_t lost_new_loc(str rurn)
129 129
 		goto err;
130 130
 	}
131 131
 
132
-	memset(urn, 0, rurn.len + 1);
132
+	memset(urn, 0, rurn.len);
133 133
 	memcpy(urn, rurn.s, rurn.len);
134 134
 	urn[rurn.len] = '\0';
135 135
 
... ...
@@ -182,11 +182,11 @@ p_lost_held_t lost_new_held(str s_uri, str s_type, int time, int exact)
182 182
 		goto err;
183 183
 	}
184 184
 
185
-	memset(uri, 0, s_uri.len + 1);
185
+	memset(uri, 0, s_uri.len);
186 186
 	memcpy(uri, s_uri.s, s_uri.len);
187 187
 	uri[s_uri.len] = '\0';
188 188
 
189
-	memset(type, 0, s_type.len + 1);
189
+	memset(type, 0, s_type.len);
190 190
 	memcpy(type, s_type.s, s_type.len);
191 191
 	type[s_type.len] = '\0';
192 192
 
... ...
@@ -280,7 +280,7 @@ char *lost_copy_string(str src, int *lgth)
280 280
 		if(res == NULL) {
281 281
 			PKG_MEM_ERROR;
282 282
 		} else {
283
-			memset(res, 0, src.len + 1);
283
+			memset(res, 0, src.len);
284 284
 			memcpy(res, src.s, src.len);
285 285
 			res[src.len] = '\0';
286 286
 			*lgth = (int)strlen(res);
... ...
@@ -343,7 +343,7 @@ char *lost_get_content(xmlNodePtr node, const char *name, int *lgth)
343 343
 			xmlFree(content);
344 344
 			return cnt;
345 345
 		}
346
-		memset(cnt, 0, len + 1);
346
+		memset(cnt, 0, len);
347 347
 		memcpy(cnt, trimmed, len);
348 348
 		cnt[len] = '\0';
349 349
 	}
... ...
@@ -379,7 +379,7 @@ char *lost_get_property(xmlNodePtr node, const char *name, int *lgth)
379 379
 			xmlFree(content);
380 380
 			return cnt;
381 381
 		}
382
-		memset(cnt, 0, len + 1);
382
+		memset(cnt, 0, len);
383 383
 		memcpy(cnt, content, len);
384 384
 		cnt[len] = '\0';
385 385
 	}
... ...
@@ -423,7 +423,7 @@ char *lost_get_childname(xmlNodePtr node, const char *name, int *lgth)
423 423
 		PKG_MEM_ERROR;
424 424
 		return cnt;
425 425
 	}
426
-	memset(cnt, 0, len + 1);
426
+	memset(cnt, 0, len);
427 427
 	memcpy(cnt, trimmed, len);
428 428
 	cnt[len] = '\0';
429 429
 
... ...
@@ -476,62 +476,51 @@ p_lost_geolist_t lost_get_geolocation_header(struct sip_msg *msg, int *items)
476 476
  */
477 477
 char *lost_get_pai_header(struct sip_msg *msg, int *lgth)
478 478
 {
479
-	struct hdr_field *hf;
480
-	to_body_t *pai_body;
479
+	p_id_body_t *p_body;
480
+
481
+	char *tmp = NULL;
481 482
 	char *res = NULL;
483
+	int len = 0;
482 484
 
483 485
 	*lgth = 0;
484 486
 
485
-	if(parse_headers(msg, HDR_EOH_F, 0) == -1) {
486
-		LM_ERR("failed to parse SIP headers\n");
487
+	if(parse_pai_header(msg) == -1) {
488
+		
489
+		LM_DBG("failed to parse P-A-I header\n");
490
+		
487 491
 		return res;
488 492
 	}
489 493
 
490
-	for(hf = msg->headers; hf; hf = hf->next) {
491
-		if((hf->type == HDR_PAI_T)
492
-				&& (hf->name.len == LOST_PAI_HEADER_SIZE - 2)) {
493
-			/* possible hit */
494
-			if(strncasecmp(hf->name.s, LOST_PAI_HEADER,
495
-								LOST_PAI_HEADER_SIZE) == 0) {
494
+	if(msg->pai == NULL || get_pai(msg) == NULL) {
495
+		LM_ERR("P-A-I header not found\n");
496
+		return res;
497
+	}
498
+	p_body = get_pai(msg);
496 499
 
497
-				LM_DBG("P-A-I body:  [%.*s]\n", hf->body.len, hf->body.s);
500
+	/* warning in case multiple P-A-I headers were found and use first */
501
+	if(p_body->num_ids > 1) {
502
+		LM_WARN("multiple P-A-I headers found, selecting first!\n");
503
+	}
498 504
 
499
-				/* first, get some memory */
500
-				pai_body = pkg_malloc(sizeof(to_body_t));
501
-				if(pai_body == NULL) {
502
-					PKG_MEM_ERROR;
503
-					return res;
504
-				}
505
-				/* parse P-A-I body */
506
-				memset(pai_body, 0, sizeof(to_body_t));
507
-				parse_to(hf->body.s, hf->body.s + hf->body.len + 1, pai_body);
508
-				if(pai_body->error == PARSE_ERROR) {
509
-					LM_ERR("bad P-A-I header\n");
510
-					pkg_free(pai_body);
511
-					return res;
512
-				}
513
-				if(pai_body->error == PARSE_OK) {
514
-					res = (char *)pkg_malloc(
515
-							(pai_body->uri.len + 1) * sizeof(char));
516
-					if(res == NULL) {
517
-						PKG_MEM_ERROR;
518
-						pkg_free(pai_body);
519
-						return res;
520
-					} else {
521
-						memset(res, 0, pai_body->uri.len + 1);
522
-						memcpy(res, pai_body->uri.s, pai_body->uri.len + 1);
523
-						res[pai_body->uri.len] = '\0';
524
-						pkg_free(pai_body);
505
+	LM_DBG("P-A-I body: [%.*s]\n", p_body->id->body.len, p_body->id->body.s);
525 506
 
526
-						*lgth = strlen(res);
527
-					}
528
-				}
529
-			} else {
530
-				LM_ERR("header '%.*s' length %d\n", hf->body.len, hf->body.s,
531
-						hf->body.len);
532
-			}
533
-			break;
534
-		}
507
+	/* accept any identity string (body), but remove <..> if present */ 
508
+	tmp = p_body->id->body.s;
509
+	len = p_body->id->body.len;
510
+	if(tmp[0] == '<' && tmp[len - 1] == '>') {
511
+		tmp++;
512
+		len -= 2;
513
+	}
514
+	/* allocate memory, copy and \0 terminate string */
515
+	res = (char *)pkg_malloc((len + 1) * sizeof(char));
516
+	if(res == NULL) {
517
+		PKG_MEM_ERROR;
518
+		return res;
519
+	} else {
520
+		memset(res, 0, len);
521
+		memcpy(res, tmp, len);
522
+		res[len] = '\0';
523
+		*lgth = strlen(res);
535 524
 	}
536 525
 
537 526
 	return res;
... ...
@@ -641,53 +630,35 @@ int lost_get_nameinfo(char *ip, str *name, int flag)
641 630
  */
642 631
 char *lost_get_from_header(struct sip_msg *msg, int *lgth)
643 632
 {
644
-	struct hdr_field *hf;
645
-	to_body_t *from_body;
633
+	to_body_t *f_body;
646 634
 	char *res = NULL;
647 635
 
648 636
 	*lgth = 0;
649 637
 
650
-	if(parse_headers(msg, HDR_EOH_F, 0) == -1) {
651
-		LM_ERR("failed to parse SIP headers\n");
638
+	if(parse_from_header(msg) == -1) {
639
+		LM_ERR("failed to parse From header\n");
652 640
 		return res;
653 641
 	}
654 642
 
655
-	for(hf = msg->headers; hf; hf = hf->next) {
656
-		if(hf->type == HDR_FROM_T) {
643
+	if(msg->from == NULL || get_from(msg) == NULL) {
644
+		LM_ERR("From header not found\n");
645
+		return res;
646
+	}
647
+	f_body = get_from(msg);
657 648
 
658
-			LM_DBG("From body:  [%.*s]\n", hf->body.len, hf->body.s);
649
+	LM_DBG("From body: [%.*s]\n", f_body->body.len, f_body->body.s);
659 650
 
660
-			/* first, get some memory */
661
-			from_body = pkg_malloc(sizeof(to_body_t));
662
-			if(from_body == NULL) {
663
-				PKG_MEM_ERROR;
664
-				return res;
665
-			}
666
-			/* parse From body */
667
-			memset(from_body, 0, sizeof(to_body_t));
668
-			parse_to(hf->body.s, hf->body.s + hf->body.len + 1, from_body);
669
-			if(from_body->error == PARSE_ERROR) {
670
-				LM_ERR("bad From header\n");
671
-				pkg_free(from_body);
672
-				return res;
673
-			}
674
-			if(from_body->error == PARSE_OK) {
675
-				res = (char *)pkg_malloc(
676
-						(from_body->uri.len + 1) * sizeof(char));
677
-				if(res == NULL) {
678
-					PKG_MEM_ERROR;
679
-					pkg_free(from_body);
680
-					return res;
681
-				} else {
682
-					memset(res, 0, from_body->uri.len + 1);
683
-					memcpy(res, from_body->uri.s, from_body->uri.len + 1);
684
-					res[from_body->uri.len] = '\0';
685
-					pkg_free(from_body);
651
+	/* allocate memory, copy and \0 terminate string */
652
+	res = (char *)pkg_malloc((f_body->uri.len + 1) * sizeof(char));
653
+	if(res == NULL) {
654
+		PKG_MEM_ERROR;
655
+		return res;
656
+	} else {
657
+		memset(res, 0, f_body->uri.len);
658
+		memcpy(res, f_body->uri.s, f_body->uri.len);
659
+		res[f_body->uri.len] = '\0';
686 660
 
687
-					*lgth = strlen(res);
688
-				}
689
-			}
690
-		}
661
+		*lgth = strlen(res);
691 662
 	}
692 663
 
693 664
 	return res;
... ...
@@ -784,8 +755,8 @@ char *lost_copy_geoheader_value(char *src, int len)
784 755
 		PKG_MEM_ERROR;
785 756
 		return res;
786 757
 	} else {
787
-		memset(res, 0, len + 1);
788
-		memcpy(res, src, len + 1);
758
+		memset(res, 0, len);
759
+		memcpy(res, src, len);
789 760
 		res[len] = '\0';
790 761
 	}
791 762
 
... ...
@@ -892,8 +863,8 @@ int lost_new_geoheader_list(p_lost_geolist_t *list, str hdr)
892 863
 
893 864
 							new->type = HTTP;
894 865
 						} else if(((*(search + 5) == 's')
895
-										  || (*(search + 5) == 'S'))
896
-								  && (*(search + 6) == ':')) {
866
+								|| (*(search + 5) == 'S'))
867
+								&& (*(search + 6) == ':')) {
897 868
 
898 869
 							LM_DBG("adding https url [%s]\n", new->value);
899 870
 
... ...
@@ -1397,7 +1368,7 @@ https://tools.ietf.org/html/rfc6753
1397 1368
 		return doc;
1398 1369
 	}
1399 1370
 
1400
-	memset(doc, 0, buffersize + 1);
1371
+	memset(doc, 0, buffersize);
1401 1372
 	memcpy(doc, (char *)xmlbuff, buffersize);
1402 1373
 	doc[buffersize] = '\0';
1403 1374
 
... ...
@@ -1508,7 +1479,7 @@ https://tools.ietf.org/html/rfc5985
1508 1479
 		return doc;
1509 1480
 	}
1510 1481
 
1511
-	memset(doc, 0, buffersize + 1);
1482
+	memset(doc, 0, buffersize);
1512 1483
 	memcpy(doc, (char *)xmlbuff, buffersize);
1513 1484
 	doc[buffersize] = '\0';
1514 1485
 
... ...
@@ -1668,7 +1639,7 @@ https://tools.ietf.org/html/rfc5222
1668 1639
 		return doc;
1669 1640
 	}
1670 1641
 
1671
-	memset(doc, 0, buffersize + 1);
1642
+	memset(doc, 0, buffersize);
1672 1643
 	memcpy(doc, (char *)xmlbuff, buffersize);
1673 1644
 	doc[buffersize] = '\0';
1674 1645
 
Browse code

lost: change in the method for parsing the From header in lost_get_from_header() related to #2723

Wolfgang Kampichler authored on 04/05/2021 21:24:53
Showing 1 changed files
... ...
@@ -442,9 +442,10 @@ p_lost_geolist_t lost_get_geolocation_header(struct sip_msg *msg, int *items)
442 442
 	str hdr = STR_NULL;
443 443
 	p_lost_geolist_t list = NULL;
444 444
 
445
+	*items = 0;
446
+
445 447
 	if(parse_headers(msg, HDR_EOH_F, 0) == -1) {
446 448
 		LM_ERR("failed to parse SIP headers\n");
447
-		*items = 0;
448 449
 		return list;
449 450
 	}
450 451
 
... ...
@@ -481,8 +482,8 @@ char *lost_get_pai_header(struct sip_msg *msg, int *lgth)
481 482
 
482 483
 	*lgth = 0;
483 484
 
484
-	if(parse_headers(msg, HDR_PAI_F, 0) == -1) {
485
-		LM_ERR("could not parse P-A-I header\n");
485
+	if(parse_headers(msg, HDR_EOH_F, 0) == -1) {
486
+		LM_ERR("failed to parse SIP headers\n");
486 487
 		return res;
487 488
 	}
488 489
 
... ...
@@ -640,34 +641,53 @@ int lost_get_nameinfo(char *ip, str *name, int flag)
640 641
  */
641 642
 char *lost_get_from_header(struct sip_msg *msg, int *lgth)
642 643
 {
643
-	to_body_t *f_body;
644
+	struct hdr_field *hf;
645
+	to_body_t *from_body;
644 646
 	char *res = NULL;
645 647
 
646 648
 	*lgth = 0;
647 649
 
648
-	if(parse_headers(msg, HDR_FROM_F, 0) == -1) {
649
-		LM_ERR("failed to parse From header\n");
650
+	if(parse_headers(msg, HDR_EOH_F, 0) == -1) {
651
+		LM_ERR("failed to parse SIP headers\n");
650 652
 		return res;
651 653
 	}
652 654
 
653
-	if(msg->from == NULL || get_from(msg) == NULL) {
654
-		LM_ERR("From header not found\n");
655
-		return res;
656
-	}
657
-	f_body = get_from(msg);
655
+	for(hf = msg->headers; hf; hf = hf->next) {
656
+		if(hf->type == HDR_FROM_T) {
658 657
 
659
-	LM_DBG("From body:  [%.*s]\n", f_body->body.len, f_body->body.s);
658
+			LM_DBG("From body:  [%.*s]\n", hf->body.len, hf->body.s);
660 659
 
661
-	res = (char *)pkg_malloc((f_body->uri.len + 1) * sizeof(char));
662
-	if(res == NULL) {
663
-		PKG_MEM_ERROR;
664
-		return res;
665
-	} else {
666
-		memset(res, 0, f_body->uri.len + 1);
667
-		memcpy(res, f_body->uri.s, f_body->uri.len + 1);
668
-		res[f_body->uri.len] = '\0';
660
+			/* first, get some memory */
661
+			from_body = pkg_malloc(sizeof(to_body_t));
662
+			if(from_body == NULL) {
663
+				PKG_MEM_ERROR;
664
+				return res;
665
+			}
666
+			/* parse From body */
667
+			memset(from_body, 0, sizeof(to_body_t));
668
+			parse_to(hf->body.s, hf->body.s + hf->body.len + 1, from_body);
669
+			if(from_body->error == PARSE_ERROR) {
670
+				LM_ERR("bad From header\n");
671
+				pkg_free(from_body);
672
+				return res;
673
+			}
674
+			if(from_body->error == PARSE_OK) {
675
+				res = (char *)pkg_malloc(
676
+						(from_body->uri.len + 1) * sizeof(char));
677
+				if(res == NULL) {
678
+					PKG_MEM_ERROR;
679
+					pkg_free(from_body);
680
+					return res;
681
+				} else {
682
+					memset(res, 0, from_body->uri.len + 1);
683
+					memcpy(res, from_body->uri.s, from_body->uri.len + 1);
684
+					res[from_body->uri.len] = '\0';
685
+					pkg_free(from_body);
669 686
 
670
-		*lgth = strlen(res);
687
+					*lgth = strlen(res);
688
+				}
689
+			}
690
+		}
671 691
 	}
672 692
 
673 693
 	return res;
Browse code

lost: Coverity Scan fixes

Wolfgang Kampichler authored on 25/04/2021 20:44:01
Showing 1 changed files
... ...
@@ -272,20 +272,19 @@ void lost_free_held(p_lost_held_t *held)
272 272
 char *lost_copy_string(str src, int *lgth)
273 273
 {
274 274
 	char *res = NULL;
275
+	*lgth = 0;
275 276
 
276
-	if(src.s == NULL && src.len == 0) {
277
-		*lgth = 0;
278
-		return NULL;
279
-	}
280
-	res = (char *)pkg_malloc((src.len + 1) * sizeof(char));
281
-	if(res == NULL) {
282
-		PKG_MEM_ERROR;
283
-		*lgth = 0;
284
-	} else {
285
-		memset(res, 0, src.len + 1);
286
-		memcpy(res, src.s, src.len);
287
-		res[src.len] = '\0';
288
-		*lgth = (int)strlen(res);
277
+	/* only copy a valid string */
278
+	if(src.s != NULL && src.len > 0) {
279
+		res = (char *)pkg_malloc((src.len + 1) * sizeof(char));
280
+		if(res == NULL) {
281
+			PKG_MEM_ERROR;
282
+		} else {
283
+			memset(res, 0, src.len + 1);
284
+			memcpy(res, src.s, src.len);
285
+			res[src.len] = '\0';
286
+			*lgth = (int)strlen(res);
287
+		}
289 288
 	}
290 289
 
291 290
 	return res;
... ...
@@ -590,7 +589,7 @@ int lost_parse_host(const char *uri, str *host, int *flag)
590 589
 	host->len = end - search;
591 590
 
592 591
 	if(ip6) {
593
-		*flag = AF_INET;
592
+		*flag = AF_INET6;
594 593
 	} else {
595 594
 		*flag = AF_INET;
596 595
 	}
... ...
@@ -1194,7 +1193,7 @@ int lost_xpath_location(xmlDocPtr doc, char *path, p_lost_loc_t loc)
1194 1193
 				/* nothing found */
1195 1194
 				if((select < 0) && (i == size - 1)) {
1196 1195
 					LM_ERR("could not find proper location-info element\n");
1197
-					xmlFree(xmlbuff);
1196
+					xmlFree(xmlbuff); /* clean up */
1198 1197
 					xmlFreeDoc(new);
1199 1198
 					xmlXPathFreeObject(result);
1200 1199
 					return -1;
... ...
@@ -1202,22 +1201,28 @@ int lost_xpath_location(xmlDocPtr doc, char *path, p_lost_loc_t loc)
1202 1201
 
1203 1202
 				if(i == select) {
1204 1203
 					/* return the current profile */
1205
-					loc->profile = (char *)pkg_malloc(strlen(s_profile) + 1);
1206
-					if(loc->profile == NULL) {
1207
-						xmlFree(xmlbuff);
1204
+					if(s_profile != NULL) {
1205
+						loc->profile = (char *)pkg_malloc(strlen(s_profile) + 1);
1206
+						if(loc->profile == NULL) {
1207
+							xmlFree(xmlbuff); /* clean up */
1208
+							xmlFreeDoc(new);
1209
+							xmlXPathFreeObject(result);
1210
+							goto err;
1211
+						}
1212
+						memset(loc->profile, 0, strlen(s_profile) + 1);
1213
+						memcpy(loc->profile, s_profile, strlen(s_profile));
1214
+					} else {
1215
+						xmlFree(xmlbuff); /* clean up */
1208 1216
 						xmlFreeDoc(new);
1209 1217
 						xmlXPathFreeObject(result);
1210 1218
 						goto err;
1211 1219
 					}
1212
-					memset(loc->profile, 0, strlen(s_profile) + 1);
1213
-					memcpy(loc->profile, s_profile, strlen(s_profile));
1214
-
1215 1220
 					/* remove xml header from location element */
1216 1221
 					remove = strlen("<?xml version='1.0'?>\n");
1217 1222
 					buffersize = buffersize - remove;
1218 1223
 					ptr = (char *)pkg_malloc((buffersize + 1) * sizeof(char));
1219 1224
 					if(ptr == NULL) {
1220
-						xmlFree(xmlbuff);
1225
+						xmlFree(xmlbuff); /* clean up */
1221 1226
 						xmlFreeDoc(new);
1222 1227
 						xmlXPathFreeObject(result);
1223 1228
 						goto err;
... ...
@@ -1233,7 +1238,7 @@ int lost_xpath_location(xmlDocPtr doc, char *path, p_lost_loc_t loc)
1233 1238
 					/* return the location DOM */
1234 1239
 					loc->xpath = (char *)pkg_malloc(len + 1);
1235 1240
 					if(loc->xpath == NULL) {
1236
-						pkg_free(ptr);
1241
+						pkg_free(ptr); /* clean up */
1237 1242
 						ptr = NULL;
1238 1243
 						xmlFree(xmlbuff);
1239 1244
 						xmlFreeDoc(new);
... ...
@@ -1242,8 +1247,7 @@ int lost_xpath_location(xmlDocPtr doc, char *path, p_lost_loc_t loc)
1242 1247
 					}
1243 1248
 					memset(loc->xpath, 0, len + 1);
1244 1249
 					memcpy(loc->xpath, tmp, len);
1245
-					/* free memory */
1246
-					pkg_free(ptr);
1250
+					pkg_free(ptr); /* clean up */
1247 1251
 					ptr = NULL;
1248 1252
 				} else {
1249 1253
 					LM_WARN("xpath location-info element(%d) ignored\n", i + 1);
Browse code

lost: fixing a memory leak and minor code refactoring and improvements

Wolfgang Kampichler authored on 18/04/2021 16:08:13
Showing 1 changed files
... ...
@@ -232,6 +232,10 @@ void lost_free_loc(p_lost_loc_t *loc)
232 232
 
233 233
 	pkg_free(ptr);
234 234
 	*loc = NULL;
235
+
236
+	LM_DBG("### location object removed\n");
237
+
238
+	return;
235 239
 }
236 240
 
237 241
 /*
... ...
@@ -242,7 +246,7 @@ void lost_free_held(p_lost_held_t *held)
242 246
 {
243 247
 	p_lost_held_t ptr;
244 248
 
245
-	if(held == NULL)
249
+	if(*held == NULL)
246 250
 		return;
247 251
 
248 252
 	ptr = *held;
... ...
@@ -254,6 +258,10 @@ void lost_free_held(p_lost_held_t *held)
254 258
 
255 259
 	pkg_free(ptr);
256 260
 	*held = NULL;
261
+
262
+	LM_DBG("### location-request object removed\n");
263
+
264
+	return;
257 265
 }
258 266
 
259 267
 /*
... ...
@@ -275,7 +283,7 @@ char *lost_copy_string(str src, int *lgth)
275 283
 		*lgth = 0;
276 284
 	} else {
277 285
 		memset(res, 0, src.len + 1);
278
-		memcpy(res, src.s, src.len + 1);
286
+		memcpy(res, src.s, src.len);
279 287
 		res[src.len] = '\0';
280 288
 		*lgth = (int)strlen(res);
281 289
 	}
... ...
@@ -298,6 +306,9 @@ void lost_free_string(str *string)
298 306
 
299 307
 	if(ptr.s != NULL && ptr.len > 0) {
300 308
 		pkg_free(ptr.s);
309
+
310
+		LM_DBG("### string object removed\n");
311
+	
301 312
 	}
302 313
 
303 314
 	string->s = NULL;
... ...
@@ -684,6 +695,8 @@ void lost_free_geoheader_list(p_lost_geolist_t *list)
684 695
 
685 696
 	*list = NULL;
686 697
 
698
+	LM_DBG("### geoheader list removed\n");
699
+
687 700
 	return;
688 701
 }
689 702
 
Browse code

lost: memory leak fix and code refactoring

Wolfgang Kampichler authored on 31/03/2021 21:14:14
Showing 1 changed files
... ...
@@ -104,14 +104,14 @@ void lost_rand_str(char *dest, size_t lgth)
104 104
  * lost_new_loc(urn)
105 105
  * creates a new location object in private memory and returns a pointer
106 106
  */
107
-p_loc_t lost_new_loc(str rurn)
107
+p_lost_loc_t lost_new_loc(str rurn)
108 108
 {
109
-	s_loc_t *ptr = NULL;
109
+	s_lost_loc_t *ptr = NULL;
110 110
 
111 111
 	char *id = NULL;
112 112
 	char *urn = NULL;
113 113
 
114
-	ptr = (s_loc_t *)pkg_malloc(sizeof(s_loc_t));
114
+	ptr = (s_lost_loc_t *)pkg_malloc(sizeof(s_lost_loc_t));
115 115
 	if(ptr == NULL) {
116 116
 		goto err;
117 117
 	}
... ...
@@ -149,7 +149,7 @@ p_loc_t lost_new_loc(str rurn)
149 149
 	return ptr;
150 150
 
151 151
 err:
152
-	LM_ERR("no more private memory\n");
152
+	PKG_MEM_ERROR;
153 153
 	return NULL;
154 154
 }
155 155
 
... ...
@@ -157,14 +157,14 @@ err:
157 157
  * lost_new_held(uri, type, time, exact)
158 158
  * creates a new held object in private memory and returns a pointer
159 159
  */
160
-p_held_t lost_new_held(str s_uri, str s_type, int time, int exact)
160
+p_lost_held_t lost_new_held(str s_uri, str s_type, int time, int exact)
161 161
 {
162
-	s_held_t *ptr = NULL;
162
+	s_lost_held_t *ptr = NULL;
163 163
 
164 164
 	char *uri = NULL;
165 165
 	char *type = NULL;
166 166
 
167
-	ptr = (s_held_t *)pkg_malloc(sizeof(s_held_t));
167
+	ptr = (s_lost_held_t *)pkg_malloc(sizeof(s_lost_held_t));
168 168
 	if(ptr == NULL) {
169 169
 		goto err;
170 170
 	}
... ...
@@ -198,7 +198,7 @@ p_held_t lost_new_held(str s_uri, str s_type, int time, int exact)
198 198
 	return ptr;
199 199
 
200 200
 err:
201
-	LM_ERR("no more private memory\n");
201
+	PKG_MEM_ERROR;
202 202
 	return NULL;
203 203
 }
204 204
 
... ...
@@ -206,9 +206,9 @@ err:
206 206
  * lost_free_loc(ptr)
207 207
  * frees a location object
208 208
  */
209
-void lost_free_loc(p_loc_t *loc)
209
+void lost_free_loc(p_lost_loc_t *loc)
210 210
 {
211
-	p_loc_t ptr;
211
+	p_lost_loc_t ptr;
212 212
 
213 213
 	if(*loc == NULL)
214 214
 		return;
... ...
@@ -238,9 +238,9 @@ void lost_free_loc(p_loc_t *loc)
238 238
  * lost_free_loc(ptr)
239 239
  * frees a held location request object
240 240
  */
241
-void lost_free_held(p_held_t *held)
241
+void lost_free_held(p_lost_held_t *held)
242 242
 {
243
-	p_held_t ptr;
243
+	p_lost_held_t ptr;
244 244
 
245 245
 	if(held == NULL)
246 246
 		return;
... ...
@@ -258,7 +258,8 @@ void lost_free_held(p_held_t *held)
258 258
 
259 259
 /*
260 260
  * lost_copy_string(str, int*) {
261
- * copies a string and returns string allocated in private memory 
261
+ * copies a string and returns a zero terminated string allocated
262
+ * in private memory
262 263
  */
263 264
 char *lost_copy_string(str src, int *lgth)
264 265
 {
... ...
@@ -270,7 +271,7 @@ char *lost_copy_string(str src, int *lgth)
270 271
 	}
271 272
 	res = (char *)pkg_malloc((src.len + 1) * sizeof(char));
272 273
 	if(res == NULL) {
273
-		LM_ERR("no more private memory\n");
274
+		PKG_MEM_ERROR;
274 275
 		*lgth = 0;
275 276
 	} else {
276 277
 		memset(res, 0, src.len + 1);
... ...
@@ -328,7 +329,7 @@ char *lost_get_content(xmlNodePtr node, const char *name, int *lgth)
328 329
 		trimmed = lost_trim_content(content, &len);
329 330
 		cnt = (char *)pkg_malloc((len + 1) * sizeof(char));
330 331
 		if(cnt == NULL) {
331
-			LM_ERR("no more private memory\n");
332
+			PKG_MEM_ERROR;
332 333
 			xmlFree(content);
333 334
 			return cnt;
334 335
 		}
... ...
@@ -364,7 +365,7 @@ char *lost_get_property(xmlNodePtr node, const char *name, int *lgth)
364 365
 		len = strlen(content);
365 366
 		cnt = (char *)pkg_malloc((len + 1) * sizeof(char));
366 367
 		if(cnt == NULL) {
367
-			LM_ERR("no more private memory\n");
368
+			PKG_MEM_ERROR;
368 369
 			xmlFree(content);
369 370
 			return cnt;
370 371
 		}
... ...
@@ -409,7 +410,7 @@ char *lost_get_childname(xmlNodePtr node, const char *name, int *lgth)
409 410
 	trimmed = lost_trim_content((char *)child->name, &len);
410 411
 	cnt = (char *)pkg_malloc((len + 1) * sizeof(char));
411 412
 	if(cnt == NULL) {
412
-		LM_ERR("no more private memory\n");
413
+		PKG_MEM_ERROR;
413 414
 		return cnt;
414 415
 	}
415 416
 	memset(cnt, 0, len + 1);
... ...
@@ -425,11 +426,11 @@ char *lost_get_childname(xmlNodePtr node, const char *name, int *lgth)
425 426
  * lost_get_geolocation_header(msg, hdr)
426 427
  * gets the Geolocation header value and returns 1 on success
427 428
  */
428
-p_geolist_t lost_get_geolocation_header(struct sip_msg *msg, int *items)
429
+p_lost_geolist_t lost_get_geolocation_header(struct sip_msg *msg, int *items)
429 430
 {
430 431
 	struct hdr_field *hf;
431 432
 	str hdr = STR_NULL;
432
-	p_geolist_t list = NULL;
433
+	p_lost_geolist_t list = NULL;
433 434
 
434 435
 	if(parse_headers(msg, HDR_EOH_F, 0) == -1) {
435 436
 		LM_ERR("failed to parse SIP headers\n");
... ...
@@ -487,7 +488,7 @@ char *lost_get_pai_header(struct sip_msg *msg, int *lgth)
487 488
 				/* first, get some memory */
488 489
 				pai_body = pkg_malloc(sizeof(to_body_t));
489 490
 				if(pai_body == NULL) {
490
-					LM_ERR("no more private memory\n");
491
+					PKG_MEM_ERROR;
491 492
 					return res;
492 493
 				}
493 494
 				/* parse P-A-I body */
... ...
@@ -502,7 +503,7 @@ char *lost_get_pai_header(struct sip_msg *msg, int *lgth)
502 503
 					res = (char *)pkg_malloc(
503 504
 							(pai_body->uri.len + 1) * sizeof(char));
504 505
 					if(res == NULL) {
505
-						LM_ERR("no more private memory\n");
506
+						PKG_MEM_ERROR;
506 507
 						pkg_free(pai_body);
507 508
 						return res;
508 509
 					} else {
... ...
@@ -649,7 +650,7 @@ char *lost_get_from_header(struct sip_msg *msg, int *lgth)
649 650
 
650 651
 	res = (char *)pkg_malloc((f_body->uri.len + 1) * sizeof(char));
651 652
 	if(res == NULL) {
652
-		LM_ERR("no more private memory\n");
653
+		PKG_MEM_ERROR;
653 654
 		return res;
654 655
 	} else {
655 656
 		memset(res, 0, f_body->uri.len + 1);
... ...
@@ -666,9 +667,9 @@ char *lost_get_from_header(struct sip_msg *msg, int *lgth)
666 667
  * lost_free_geoheader_list(list)
667 668
  * removes geoheader list from private memory
668 669
  */
669
-void lost_free_geoheader_list(p_geolist_t *list)
670
+void lost_free_geoheader_list(p_lost_geolist_t *list)
670 671
 {
671
-	p_geolist_t curr;
672
+	p_lost_geolist_t curr;
672 673
 
673 674
 	while((curr = *list) != NULL) {
674 675
 		*list = curr->next;
... ...
@@ -690,9 +691,9 @@ void lost_free_geoheader_list(p_geolist_t *list)
690 691
  * lost_get_geoheader_value(list, type, rtype)
691 692
  * returns geoheader value and type (rtype) of given type
692 693
  */
693
-char *lost_get_geoheader_value(p_geolist_t list, geotype_t type, int *rtype)
694
+char *lost_get_geoheader_value(p_lost_geolist_t list, lost_geotype_t type, int *rtype)
694 695
 {
695
-	p_geolist_t head = list;
696
+	p_lost_geolist_t head = list;
696 697
 	char *value = NULL;
697 698
 
698 699
 	if(head == NULL) {
... ...
@@ -722,11 +723,11 @@ char *lost_get_geoheader_value(p_geolist_t list, geotype_t type, int *rtype)
722 723
  * lost_reverse_geoheader_list(list)
723 724
  * reverses list order
724 725
  */
725
-void lost_reverse_geoheader_list(p_geolist_t *head)
726
+void lost_reverse_geoheader_list(p_lost_geolist_t *head)
726 727
 {
727
-	p_geolist_t prev = NULL;
728
-	p_geolist_t next = NULL;
729
-	p_geolist_t current = *head;
728
+	p_lost_geolist_t prev = NULL;
729
+	p_lost_geolist_t next = NULL;
730
+	p_lost_geolist_t current = *head;
730 731
 
731 732
 	while(current != NULL) {
732 733
 		next = current->next;
... ...
@@ -748,7 +749,7 @@ char *lost_copy_geoheader_value(char *src, int len)
748 749
 
749 750
 	res = (char *)pkg_malloc((len + 1) * sizeof(char));
750 751
 	if(res == NULL) {
751
-		LM_ERR("no more private memory\n");
752
+		PKG_MEM_ERROR;
752 753
 		return res;
753 754
 	} else {
754 755
 		memset(res, 0, len + 1);
... ...
@@ -764,7 +765,7 @@ char *lost_copy_geoheader_value(char *src, int len)
764 765
  * searches and parses Geolocation header and returns a list
765 766
  * allocated in private memory and an item count
766 767
  */
767
-int lost_new_geoheader_list(p_geolist_t *list, str hdr)
768
+int lost_new_geoheader_list(p_lost_geolist_t *list, str hdr)
768 769
 {
769 770
 	char *search = NULL;
770 771
 	char *cidptr = NULL;
... ...
@@ -775,7 +776,7 @@ int lost_new_geoheader_list(p_geolist_t *list, str hdr)
775 776
 	int len = 0;
776 777
 	int i = 0;
777 778
 
778
-	p_geolist_t new = NULL;
779
+	p_lost_geolist_t new = NULL;
779 780
 
780 781
 	LM_DBG("parsing geolocation header value ...\n");
781 782
 
... ...
@@ -802,9 +803,9 @@ int lost_new_geoheader_list(p_geolist_t *list, str hdr)
802 803
 					len++;
803 804
 				}
804 805
 				if((*(ptr + len) == '>') && (len > 6)) {
805
-					new = (p_geolist_t)pkg_malloc(sizeof(s_geolist_t));
806
+					new = (p_lost_geolist_t)pkg_malloc(sizeof(s_lost_geolist_t));
806 807
 					if(new == NULL) {
807
-						LM_ERR("no more private memory\n");
808
+						PKG_MEM_ERROR;
808 809
 					} else {
809 810
 
810 811
 						LM_DBG("\t[%.*s]\n", len + 1, cidptr);
... ...
@@ -844,9 +845,9 @@ int lost_new_geoheader_list(p_geolist_t *list, str hdr)
844 845
 					len++;
845 846
 				}
846 847
 				if((*(ptr + len) == '>') && (len > 10)) {
847
-					new = (p_geolist_t)pkg_malloc(sizeof(s_geolist_t));
848
+					new = (p_lost_geolist_t)pkg_malloc(sizeof(s_lost_geolist_t));
848 849
 					if(new == NULL) {
849
-						LM_ERR("no more private memory\n");
850
+						PKG_MEM_ERROR;
850 851
 					} else {
851 852
 
852 853
 						LM_DBG("\t[%.*s]\n", len, urlptr);
... ...
@@ -885,10 +886,10 @@ int lost_new_geoheader_list(p_geolist_t *list, str hdr)
885 886
  * lost_parse_pidf(pidf, urn)
886 887
  * parses pidf and returns a new location object
887 888
  */
888
-p_loc_t lost_parse_pidf(str pidf, str urn)
889
+p_lost_loc_t lost_parse_pidf(str pidf, str urn)
889 890
 {
890 891
 
891
-	p_loc_t loc = NULL;
892
+	p_lost_loc_t loc = NULL;
892 893
 
893 894
 	xmlDocPtr doc = NULL;
894 895
 	xmlNodePtr root = NULL;
... ...
@@ -955,7 +956,7 @@ err:
955 956
  * parses locationResponse (pos|circle) and writes 
956 957
  * results to location object
957 958
  */
958
-int lost_parse_geo(xmlNodePtr node, p_loc_t loc)
959
+int lost_parse_geo(xmlNodePtr node, p_lost_loc_t loc)
959 960
 {
960 961
 	xmlNodePtr cur = NULL;
961 962
 
... ...
@@ -1021,7 +1022,7 @@ int lost_parse_geo(xmlNodePtr node, p_loc_t loc)
1021 1022
 	return 0;
1022 1023
 
1023 1024
 err:
1024
-	LM_ERR("no more private memory\n");
1025
+	PKG_MEM_ERROR;
1025 1026
 	return -1;
1026 1027
 }
1027 1028
 
... ...
@@ -1030,7 +1031,7 @@ err:
1030 1031
  * performs xpath expression on locationResponse and writes 
1031 1032
  * results (location-info child element) to location object
1032 1033
  */
1033
-int lost_xpath_location(xmlDocPtr doc, char *path, p_loc_t loc)
1034
+int lost_xpath_location(xmlDocPtr doc, char *path, p_lost_loc_t loc)
1034 1035
 {
1035 1036
 	xmlXPathObjectPtr result = NULL;
1036 1037
 	xmlNodeSetPtr nodes = NULL;
... ...
@@ -1251,7 +1252,7 @@ int lost_xpath_location(xmlDocPtr doc, char *path, p_loc_t loc)
1251 1252
 	return 0;
1252 1253
 
1253 1254
 err:
1254
-	LM_ERR("no more private memory\n");
1255
+	PKG_MEM_ERROR;
1255 1256
 	return -1;
1256 1257
 }
1257 1258
 
... ...
@@ -1259,7 +1260,7 @@ err:
1259 1260
  * lost_parse_location_info(node, loc)
1260 1261
  * wrapper to call xpath or simple pos|circle parser (last resort)
1261 1262
  */
1262
-int lost_parse_location_info(xmlNodePtr root, p_loc_t loc)
1263
+int lost_parse_location_info(xmlNodePtr root, p_lost_loc_t loc)
1263 1264
 {
1264 1265
 	if(lost_xpath_location(root->doc, LOST_XPATH_GP, loc) == 0) {
1265 1266
 		return 0;
... ...
@@ -1353,7 +1354,7 @@ https://tools.ietf.org/html/rfc6753
1353 1354
 
1354 1355
 	doc = (char *)pkg_malloc((buffersize + 1) * sizeof(char));
1355 1356
 	if(doc == NULL) {
1356
-		LM_ERR("no more private memory\n");
1357
+		PKG_MEM_ERROR;
1357 1358
 		xmlFree(xmlbuff);
1358 1359
 		xmlFreeDoc(request);
1359 1360
 		return doc;
... ...
@@ -1375,7 +1376,7 @@ https://tools.ietf.org/html/rfc6753
1375 1376
  * lost_held_location_request(held, lgth)
1376 1377
  * assembles and returns locationRequest string (allocated in private memory)
1377 1378
  */
1378
-char *lost_held_location_request(p_held_t held, int *lgth)
1379
+char *lost_held_location_request(p_lost_held_t held, int *lgth)
1379 1380
 {
1380 1381
 	int buffersize = 0;
1381 1382
 
... ...
@@ -1464,7 +1465,7 @@ https://tools.ietf.org/html/rfc5985
1464 1465
 
1465 1466
 	doc = (char *)pkg_malloc((buffersize + 1) * sizeof(char));
1466 1467
 	if(doc == NULL) {
1467
-		LM_ERR("no more private memory\n");
1468
+		PKG_MEM_ERROR;
1468 1469
 		xmlFree(xmlbuff);
1469 1470
 		xmlFreeDoc(request);
1470 1471
 		return doc;
... ...
@@ -1486,7 +1487,7 @@ https://tools.ietf.org/html/rfc5985
1486 1487
  * lost_find_service_request(loc, lgth)
1487 1488
  * assembles and returns findService request string (allocated in private memory)
1488 1489
  */
1489
-char *lost_find_service_request(p_loc_t loc, int *lgth)
1490
+char *lost_find_service_request(p_lost_loc_t loc, int *lgth)
1490 1491
 {
1491 1492
 	int buffersize = 0;
1492 1493
 
... ...
@@ -1624,7 +1625,7 @@ https://tools.ietf.org/html/rfc5222
1624 1625
 
1625 1626
 	doc = (char *)pkg_malloc((buffersize + 1) * sizeof(char));
1626 1627
 	if(doc == NULL) {
1627
-		LM_ERR("no more private memory\n");
1628
+		PKG_MEM_ERROR;
1628 1629
 		xmlFree(xmlbuff);
1629 1630
 		xmlFreeDoc(request);
1630 1631
 		return doc;
Browse code

lost: DOM level count fix

Wolfgang Kampichler authored on 30/03/2021 19:15:56
Showing 1 changed files
... ...
@@ -1234,8 +1234,11 @@ int lost_xpath_location(xmlDocPtr doc, char *path, p_loc_t loc)
1234 1234
 				} else {
1235 1235
 					LM_WARN("xpath location-info element(%d) ignored\n", i + 1);
1236 1236
 				}
1237
+				/* clean up */
1237 1238
 				xmlFree(xmlbuff);
1238 1239
 				xmlFreeDoc(new);
1240
+				/* reset level count */
1241
+				nok = -1;
1239 1242
 			}
1240 1243
 		}
1241 1244
 	} else {
Browse code

lost: bug-fix due to a code formatting error

Wolfgang Kampichler authored on 16/03/2021 09:29:04
Showing 1 changed files
... ...
@@ -442,7 +442,10 @@ p_geolist_t lost_get_geolocation_header(struct sip_msg *msg, int *items)
442 442
 				&& (hf->name.len == LOST_GEOLOC_HEADER_SIZE - 2)) {
443 443
 			/* possible hit */
444 444
 			if(strncasecmp(hf->name.s, LOST_GEOLOC_HEADER,
445
-								LOST_GEOLOC_HEADER_SIZE) == 0) {
445
+					LOST_GEOLOC_HEADER_SIZE) == 0) {
446
+                
447
+				hdr.s = hf->body.s;
448
+                hdr.len = hf->body.len;
446 449
 
447 450
 				LM_DBG("found geolocation header [%.*s]\n", hdr.len, hdr.s);
448 451
 
Browse code

lost: new features, attributes and a new function to dereference location

- features: LoST redirect, dynamic HELD url resolving (#2574), LoST NAPTR,
POST request to dereference loation
- attributes: reponse_time (-1:emergencyDispatch, 0:emergencyRouting, >0[ms]);
post_request (POST method to dereference location #2641); recursion (yes/no);
location_profile (PIDF/LO profile selection: firs