comparison libsip/out_msg.c @ 46:5427b26525cd

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