FreeCalypso > hg > sipout-test-utils
comparison libsip/uas_basic.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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:35c0d9f03c0a |
---|---|
1 /* | |
2 * Here we implement some essential UAS functions. | |
3 */ | |
4 | |
5 #include <ctype.h> | |
6 #include <string.h> | |
7 #include <strings.h> | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include "parse.h" | |
11 #include "uas_basic.h" | |
12 #include "out_msg.h" | |
13 | |
14 extern char *get_single_header(); | |
15 | |
16 uas_get_basic_headers(msg, ess) | |
17 struct sip_pkt_rx *msg; | |
18 struct uas_parse_hdrs *ess; | |
19 { | |
20 char *hval, *cp; | |
21 int dup_flag = 0; | |
22 | |
23 hval = get_single_header(msg, "Call-ID", "i", &dup_flag); | |
24 if (!hval || dup_flag) { | |
25 ess->error_field = "Call-ID"; | |
26 return(-1); | |
27 } | |
28 ess->call_id = hval; | |
29 hval = get_single_header(msg, "CSeq", (char *) 0, &dup_flag); | |
30 if (!hval || dup_flag) { | |
31 bad_cseq: ess->error_field = "CSeq"; | |
32 return(-1); | |
33 } | |
34 if (!isdigit(*hval)) | |
35 goto bad_cseq; | |
36 ess->cseq_num = strtoul(hval, &cp, 10); | |
37 if (*cp) { | |
38 if (!isspace(*cp)) | |
39 goto bad_cseq; | |
40 while (isspace(*cp)) | |
41 cp++; | |
42 if (strcmp(cp, msg->req_method)) | |
43 goto bad_cseq; | |
44 } | |
45 hval = get_single_header(msg, "From", "f", &dup_flag); | |
46 if (!hval || dup_flag) { | |
47 ess->error_field = "From"; | |
48 return(-1); | |
49 } | |
50 ess->from = hval; | |
51 hval = get_single_header(msg, "To", "t", &dup_flag); | |
52 if (!hval || dup_flag) { | |
53 ess->error_field = "To"; | |
54 return(-1); | |
55 } | |
56 ess->to = hval; | |
57 hval = get_single_header(msg, "Via", "v", &dup_flag); | |
58 if (!hval || dup_flag) { | |
59 ess->error_field = "Via"; | |
60 return(-1); | |
61 } | |
62 ess->via = hval; | |
63 return(0); | |
64 } | |
65 | |
66 add_resp_basic_headers(msg, ess, req_method) | |
67 struct sip_msg_out *msg; | |
68 struct uas_parse_hdrs *ess; | |
69 char *req_method; | |
70 { | |
71 char cseq_str[80]; | |
72 int rc; | |
73 | |
74 rc = out_msg_add_header(msg, "From", ess->from); | |
75 if (rc < 0) | |
76 return rc; | |
77 rc = out_msg_add_header(msg, "To", ess->to); | |
78 if (rc < 0) | |
79 return rc; | |
80 rc = out_msg_add_header(msg, "Call-ID", ess->call_id); | |
81 if (rc < 0) | |
82 return rc; | |
83 sprintf(cseq_str, "%u %.64s", ess->cseq_num, req_method); | |
84 rc = out_msg_add_header(msg, "CSeq", cseq_str); | |
85 if (rc < 0) | |
86 return rc; | |
87 return out_msg_add_header(msg, "Via", ess->via); | |
88 } |