comparison libsip/out_msg.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 * 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_request_out_msg_urilen(msg, method, uri, uri_len)
26 struct sip_msg_out *msg;
27 char *method, *uri;
28 unsigned uri_len;
29 {
30 unsigned len;
31
32 len = strlen(method) + uri_len + (2 + 7 + 2);
33 if (len + 2 > MAX_SIP_TX_PACKET)
34 return(-1);
35 sprintf(msg->buf, "%s %.*s SIP/2.0\r\n", method, uri_len, uri);
36 msg->msg_len = len;
37 return(0);
38 }
39
40 start_response_out_msg(msg, status)
41 struct sip_msg_out *msg;
42 char *status;
43 {
44 unsigned len;
45
46 len = strlen(status) + (8 + 2);
47 if (len + 2 > MAX_SIP_TX_PACKET)
48 return(-1);
49 sprintf(msg->buf, "SIP/2.0 %s\r\n", status);
50 msg->msg_len = len;
51 return(0);
52 }
53
54 out_msg_add_header(msg, name, value)
55 struct sip_msg_out *msg;
56 char *name, *value;
57 {
58 unsigned len;
59
60 len = strlen(name) + strlen(value) + 4;
61 if (msg->msg_len + len + 2 > MAX_SIP_TX_PACKET)
62 return(-1);
63 sprintf(msg->buf + msg->msg_len, "%s: %s\r\n", name, value);
64 msg->msg_len += len;
65 return(0);
66 }
67
68 out_msg_finish(msg)
69 struct sip_msg_out *msg;
70 {
71 msg->buf[msg->msg_len++] = '\r';
72 msg->buf[msg->msg_len++] = '\n';
73 return(0);
74 }
75
76 out_msg_finish_body(msg, body, bodylen)
77 struct sip_msg_out *msg;
78 char *body;
79 unsigned bodylen;
80 {
81 msg->buf[msg->msg_len++] = '\r';
82 msg->buf[msg->msg_len++] = '\n';
83 if (msg->msg_len + bodylen > MAX_SIP_TX_PACKET)
84 return(-1);
85 bcopy(body, msg->buf + msg->msg_len, bodylen);
86 msg->msg_len += bodylen;
87 return(0);
88 }