FreeCalypso > hg > sipout-test-utils
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libsip/out_msg.c Sun Mar 03 23:20:19 2024 -0800 @@ -0,0 +1,88 @@ +/* + * Functions for constructing outgoing SIP messages. + */ + +#include <stdio.h> +#include <string.h> +#include <strings.h> + +#include "out_msg.h" + +start_request_out_msg(msg, method, uri) + struct sip_msg_out *msg; + char *method, *uri; +{ + unsigned len; + + len = strlen(method) + strlen(uri) + (2 + 7 + 2); + if (len + 2 > MAX_SIP_TX_PACKET) + return(-1); + sprintf(msg->buf, "%s %s SIP/2.0\r\n", method, uri); + msg->msg_len = len; + return(0); +} + +start_request_out_msg_urilen(msg, method, uri, uri_len) + struct sip_msg_out *msg; + char *method, *uri; + unsigned uri_len; +{ + unsigned len; + + len = strlen(method) + uri_len + (2 + 7 + 2); + if (len + 2 > MAX_SIP_TX_PACKET) + return(-1); + sprintf(msg->buf, "%s %.*s SIP/2.0\r\n", method, uri_len, uri); + msg->msg_len = len; + return(0); +} + +start_response_out_msg(msg, status) + struct sip_msg_out *msg; + char *status; +{ + unsigned len; + + len = strlen(status) + (8 + 2); + if (len + 2 > MAX_SIP_TX_PACKET) + return(-1); + sprintf(msg->buf, "SIP/2.0 %s\r\n", status); + msg->msg_len = len; + return(0); +} + +out_msg_add_header(msg, name, value) + struct sip_msg_out *msg; + char *name, *value; +{ + unsigned len; + + len = strlen(name) + strlen(value) + 4; + if (msg->msg_len + len + 2 > MAX_SIP_TX_PACKET) + return(-1); + sprintf(msg->buf + msg->msg_len, "%s: %s\r\n", name, value); + msg->msg_len += len; + return(0); +} + +out_msg_finish(msg) + struct sip_msg_out *msg; +{ + msg->buf[msg->msg_len++] = '\r'; + msg->buf[msg->msg_len++] = '\n'; + return(0); +} + +out_msg_finish_body(msg, body, bodylen) + struct sip_msg_out *msg; + char *body; + unsigned bodylen; +{ + msg->buf[msg->msg_len++] = '\r'; + msg->buf[msg->msg_len++] = '\n'; + if (msg->msg_len + bodylen > MAX_SIP_TX_PACKET) + return(-1); + bcopy(body, msg->buf + msg->msg_len, bodylen); + msg->msg_len += bodylen; + return(0); +}