annotate libsip/uas_basic.c @ 111:7a4d4b8d5f04

sip-in call clearing: unlink and free implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 28 Sep 2022 18:45:16 -0800
parents 5427b26525cd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Here we implement some essential UAS functions.
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <ctype.h>
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <string.h>
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <strings.h>
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "parse.h"
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "uas_basic.h"
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "out_msg.h"
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern char *get_single_header();
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 uas_get_basic_headers(msg, ess)
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 struct sip_pkt_rx *msg;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 struct uas_parse_hdrs *ess;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 {
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 char *hval, *cp;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 int dup_flag = 0;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 hval = get_single_header(msg, "Call-ID", "i", &dup_flag);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 if (!hval || dup_flag) {
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 ess->error_field = "Call-ID";
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 return(-1);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 ess->call_id = hval;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 hval = get_single_header(msg, "CSeq", (char *) 0, &dup_flag);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 if (!hval || dup_flag) {
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 bad_cseq: ess->error_field = "CSeq";
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return(-1);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (!isdigit(*hval))
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 goto bad_cseq;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 ess->cseq_num = strtoul(hval, &cp, 10);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 if (*cp) {
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 if (!isspace(*cp))
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 goto bad_cseq;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 while (isspace(*cp))
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 cp++;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (strcmp(cp, msg->req_method))
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 goto bad_cseq;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 hval = get_single_header(msg, "From", "f", &dup_flag);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (!hval || dup_flag) {
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 ess->error_field = "From";
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 return(-1);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 ess->from = hval;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 hval = get_single_header(msg, "To", "t", &dup_flag);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (!hval || dup_flag) {
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 ess->error_field = "To";
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 return(-1);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 ess->to = hval;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 hval = get_single_header(msg, "Via", "v", &dup_flag);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 if (!hval || dup_flag) {
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 ess->error_field = "Via";
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return(-1);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 ess->via = hval;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 return(0);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 add_resp_basic_headers(msg, ess, req_method)
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 struct sip_msg_out *msg;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 struct uas_parse_hdrs *ess;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 char *req_method;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 {
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 char cseq_str[80];
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 int rc;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 rc = out_msg_add_header(msg, "From", ess->from);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 if (rc < 0)
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 return rc;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 rc = out_msg_add_header(msg, "To", ess->to);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if (rc < 0)
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 return rc;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 rc = out_msg_add_header(msg, "Call-ID", ess->call_id);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (rc < 0)
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 return rc;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 sprintf(cseq_str, "%u %.64s", ess->cseq_num, req_method);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 rc = out_msg_add_header(msg, "CSeq", cseq_str);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 if (rc < 0)
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 return rc;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 return out_msg_add_header(msg, "Via", ess->via);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }