annotate libsip/to_tag.c @ 128:5685412bd6aa

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