FreeCalypso > hg > themwi-system-sw
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libsip/out_msg.c Tue Sep 06 20:29:44 2022 -0800 @@ -0,0 +1,73 @@ +/* + * 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_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); +}