FreeCalypso > hg > sipout-test-utils
view libsip/out_msg.c @ 3:cc997f9ae186
test-fsk: rm TFO code
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 04 Mar 2024 21:22:27 -0800 |
parents | 35c0d9f03c0a |
children |
line wrap: on
line source
/* * 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); }