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