Browse code

replased own code to get_body_part_by_filter

Eugene Sukhanov authored on 26/04/2021 21:08:26 • Sergey Safarov committed on 03/05/2021 06:03:50
Showing 1 changed files
... ...
@@ -36,6 +36,7 @@
36 36
 #include "../../core/parser/parse_content.h"
37 37
 #include "../../core/parser/parse_param.h"
38 38
 #include "../../core/parser/parse_uri.h"
39
+#include "../../core/parser/parse_body.h"
39 40
 #include "../../core/strutils.h"
40 41
 #include "../../core/trim.h"
41 42
 #include "../../core/msg_translator.h"
... ...
@@ -122,12 +123,7 @@ static char* strstri(char* string, int len, char* substring)
122 123
 }
123 124
 
124 125
 static int sel_lost(str* res, select_t* s, struct sip_msg* msg)
125
-{
126
-	// test
127
-	static char buf[128];
128
-	strcpy(buf, "Lost module root selector\n");
129
-	res->s = buf;
130
-	res->len = strlen(buf);
126
+{ /* dummy */
131 127
 	return 0;
132 128
 }
133 129
 
... ...
@@ -291,7 +287,6 @@ static int sel_hdrs(str* res, select_t* s, struct sip_msg* msg, char *prps, char
291 287
 	}
292 288
 	memcpy(res->s, ts.s, res->len);
293 289
 	pkg_free(buf);
294
-
295 290
 	return cnt;
296 291
 }
297 292
 
... ...
@@ -404,34 +399,6 @@ static int sel_provider_info_uri_type(str* res, select_t* s, struct sip_msg* msg
404 399
 	return err;
405 400
 }
406 401
 
407
-static int GetNextBodyPart(str* body, str* boundary, str* bodypart)
408
-{
409
-	char *start = body->s;
410
-	int len = body->len;
411
-
412
-	if (bodypart->len > 0)
413
-	{
414
-		start = bodypart->s + bodypart->len;
415
-		len -= start - body->s;
416
-	}
417
-	if (len > 0)
418
-	{
419
-		char* pos = strstri(start, len, "Content-Type:");
420
-		if (pos)
421
-		{
422
-			len -= pos - start;
423
-			start = pos;
424
-			pos = strstrin(start, len, boundary->s, boundary->len);
425
-			if (pos) len = pos - start;
426
-			bodypart->s = start;
427
-			bodypart->len = len;
428
-			return 1;
429
-		}
430
-	}
431
-
432
-	return 0;	// no more parts
433
-}
434
-
435 402
 static int GetNextBodyPartHdr(str *bodypart, str *bhr)
436 403
 {
437 404
 	str ts = *bodypart;
... ...
@@ -467,60 +434,25 @@ static int sel_uri_raw(str* res, select_t* s, struct sip_msg* msg)
467 434
 	char* pos = strstri(res->s, res->len, "cid:");
468 435
 	if (pos)
469 436
 	{
470
-		str boundary = {0, 0};
471
-		str body = {0, 0};
472
-		str bodypart = {0, 0};
473
-		str cid, bhr;
437
+		int content_length;
438
+		char *d;
439
+		str cid;
440
+		char *buf;
474 441
 		int l = strlen("cid:");
475
-
476
-		// get message body
477
-		body.len = 0;
478
-		body.s = get_body(msg);
479
-		if (!body.s)
480
-		{
481
-			LM_ERR("failed to get the content message body\n");
482
-			res->len = 0;
483
-			return -1;
484
-		}
485
-		body.len = msg->buf + msg->len - body.s;
486
-		if (body.len <= 0)
487
-		{
488
-			LM_DBG("empty body in the message\n");
489
-			res->len = 0;
490
-			return 1;
491
-		}
492
-
442
+		
493 443
 		// get Content-Id:
494 444
 		cid.len = res->len - l - (pos - res->s);
495 445
 		cid.s = pos + l;
496
-
497
-		// find relevant to Content-Id multipart part
498
-		if (get_boundary(msg, &boundary))
499
-		{
500
-			// Content is not multipart
501
-			boundary.len = 0;
502
-		}
503
-
504
-		res->len = 0;
505
-		while (!res->len && GetNextBodyPart(&body, &boundary, &bodypart))
506
-		{
507
-			bhr.len = 0;
508
-			while (!res->len && GetNextBodyPartHdr(&bodypart, &bhr))
509
-			{
510
-				if (!strncasecmp(bhr.s, "Content-Id:", strlen("Content-Id:")))
511
-				{
512
-					// check Content-Id in cid->s
513
-					pos = strstrin(bhr.s, bhr.len, cid.s, cid.len);
514
-					if (pos)	//the cid found
515
-					{
516
-						res->len = bodypart.len;
517
-						res->s = bodypart.s;
518
-					}
519
-				}
520
-			}
521
-		}
522
-
523
-		if(boundary.s) pkg_free(boundary.s);
446
+		buf = pkg_malloc(cid.len + 1);
447
+		memcpy(buf, cid.s, cid.len);
448
+		buf[cid.len] = 0;
449
+		
450
+		// get body part - filter => Content-Id
451
+		d = get_body_part_by_filter(msg, 0, 0, buf, NULL, &content_length);
452
+		if (!d) content_length = 0;
453
+		res->len = content_length;
454
+		res->s = d;
455
+		pkg_free(buf);
524 456
 	}
525 457
 	else res->len = 0;
526 458
 	return 0;