annotate libsip/out_msg.c @ 70:47976db01894

sip-in/sip_log.c: extern declaration of global variable
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 19 Sep 2022 21:30:33 -0800
parents 5427b26525cd
children 915f0f397fb6
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 * Functions for constructing outgoing SIP messages.
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 <stdio.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
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "out_msg.h"
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 start_request_out_msg(msg, method, uri)
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 struct sip_msg_out *msg;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 char *method, *uri;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 {
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 unsigned len;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 len = strlen(method) + strlen(uri) + (2 + 7 + 2);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 if (len + 2 > MAX_SIP_TX_PACKET)
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 return(-1);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 sprintf(msg->buf, "%s %s SIP/2.0\r\n", method, uri);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 msg->msg_len = len;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 return(0);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 }
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 start_response_out_msg(msg, status)
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 struct sip_msg_out *msg;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 char *status;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 {
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 unsigned len;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 len = strlen(status) + (8 + 2);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (len + 2 > MAX_SIP_TX_PACKET)
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 return(-1);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 sprintf(msg->buf, "SIP/2.0 %s\r\n", status);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 msg->msg_len = len;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 return(0);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 out_msg_add_header(msg, name, value)
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 struct sip_msg_out *msg;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 char *name, *value;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 {
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 unsigned len;
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 len = strlen(name) + strlen(value) + 4;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (msg->msg_len + len + 2 > MAX_SIP_TX_PACKET)
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 return(-1);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 sprintf(msg->buf + msg->msg_len, "%s: %s\r\n", name, value);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 msg->msg_len += len;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 return(0);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 out_msg_finish(msg)
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 struct sip_msg_out *msg;
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 msg->buf[msg->msg_len++] = '\r';
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 msg->buf[msg->msg_len++] = '\n';
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 return(0);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 out_msg_finish_body(msg, body, bodylen)
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 struct sip_msg_out *msg;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 char *body;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 unsigned bodylen;
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 msg->buf[msg->msg_len++] = '\r';
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 msg->buf[msg->msg_len++] = '\n';
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (msg->msg_len + bodylen > MAX_SIP_TX_PACKET)
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return(-1);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 bcopy(body, msg->buf + msg->msg_len, bodylen);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 msg->msg_len += bodylen;
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 return(0);
5427b26525cd libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }