comparison libsip/to_tag.c @ 72:9ca6f0708237

libsip: add extract_to_tag() function
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 20 Sep 2022 10:54:10 -0800
parents
children
comparison
equal deleted inserted replaced
71:d74b545a3c2a 72:9ca6f0708237
1 /*
2 * The function implemented in this module extracts the tag
3 * from the To header of a SIP destination server's response.
4 */
5
6 #include <ctype.h>
7 #include <string.h>
8 #include <strings.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include "parse.h"
12
13 extern char *get_single_header();
14
15 char *
16 extract_to_tag(msg, expect_uri)
17 struct sip_pkt_rx *msg;
18 char *expect_uri;
19 {
20 char *cp, *tag;
21 int bracketed, c;
22 unsigned expect_uri_len;
23
24 cp = get_single_header(msg, "To", "t", (int *) 0);
25 if (!cp)
26 return 0;
27 if (*cp == '<') {
28 cp++;
29 bracketed = 1;
30 } else
31 bracketed = 0;
32 expect_uri_len = strlen(expect_uri);
33 if (strncasecmp(cp, expect_uri, expect_uri_len))
34 return 0;
35 cp += expect_uri_len;
36 if (bracketed) {
37 if (*cp++ != '>')
38 return 0;
39 }
40 while (isspace(*cp))
41 cp++;
42 if (*cp++ != ';')
43 return 0;
44 while (isspace(*cp))
45 cp++;
46 if (strncasecmp(cp, "tag", 3))
47 return 0;
48 cp += 3;
49 while (isspace(*cp))
50 cp++;
51 if (*cp++ != '=')
52 return 0;
53 while (isspace(*cp))
54 cp++;
55 tag = cp;
56 for (; c = *cp; cp++) {
57 switch (c) {
58 case '-':
59 case '.':
60 case '!':
61 case '%':
62 case '*':
63 case '_':
64 case '+':
65 case '`':
66 case '\'':
67 case '~':
68 continue;
69 default:
70 if (isalnum(c))
71 continue;
72 return 0;
73 }
74 }
75 return tag;
76 }