FreeCalypso > hg > themwi-system-sw
annotate libsip/out_msg.c @ 200:834656633fa0
sip-manual-out TFO: use is_hunt_fill mechanism
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 02 Apr 2023 17:44:23 -0800 |
parents | 915f0f397fb6 |
children |
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 |
81
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
25 start_request_out_msg_urilen(msg, method, uri, uri_len) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
26 struct sip_msg_out *msg; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
27 char *method, *uri; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
28 unsigned uri_len; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
29 { |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
30 unsigned len; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
31 |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
32 len = strlen(method) + uri_len + (2 + 7 + 2); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
33 if (len + 2 > MAX_SIP_TX_PACKET) |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
34 return(-1); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
35 sprintf(msg->buf, "%s %.*s SIP/2.0\r\n", method, uri_len, uri); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
36 msg->msg_len = len; |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
37 return(0); |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
38 } |
915f0f397fb6
sip-in: beginning of outgoing BYE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
46
diff
changeset
|
39 |
46
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 start_response_out_msg(msg, status) |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 struct sip_msg_out *msg; |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 char *status; |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 { |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 unsigned len; |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 len = strlen(status) + (8 + 2); |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (len + 2 > MAX_SIP_TX_PACKET) |
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 sprintf(msg->buf, "SIP/2.0 %s\r\n", status); |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 msg->msg_len = len; |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 return(0); |
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 |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 out_msg_add_header(msg, name, value) |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 struct sip_msg_out *msg; |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 char *name, *value; |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 { |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 unsigned len; |
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 len = strlen(name) + strlen(value) + 4; |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 if (msg->msg_len + len + 2 > MAX_SIP_TX_PACKET) |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 return(-1); |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 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
|
64 msg->msg_len += len; |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 return(0); |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 out_msg_finish(msg) |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 struct sip_msg_out *msg; |
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 msg->buf[msg->msg_len++] = '\r'; |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 msg->buf[msg->msg_len++] = '\n'; |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 return(0); |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 } |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 out_msg_finish_body(msg, body, bodylen) |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 struct sip_msg_out *msg; |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 char *body; |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 unsigned bodylen; |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 { |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 msg->buf[msg->msg_len++] = '\r'; |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 msg->buf[msg->msg_len++] = '\n'; |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 if (msg->msg_len + bodylen > MAX_SIP_TX_PACKET) |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 return(-1); |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 bcopy(body, msg->buf + msg->msg_len, bodylen); |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 msg->msg_len += bodylen; |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 return(0); |
5427b26525cd
libsip: beginning to flesh out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 } |