FreeCalypso > hg > themwi-system-sw
diff libsip/uas_basic.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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libsip/uas_basic.c Tue Sep 06 20:29:44 2022 -0800 @@ -0,0 +1,88 @@ +/* + * Here we implement some essential UAS functions. + */ + +#include <ctype.h> +#include <string.h> +#include <strings.h> +#include <stdio.h> +#include <stdlib.h> +#include "parse.h" +#include "uas_basic.h" +#include "out_msg.h" + +extern char *get_single_header(); + +uas_get_basic_headers(msg, ess) + struct sip_pkt_rx *msg; + struct uas_parse_hdrs *ess; +{ + char *hval, *cp; + int dup_flag = 0; + + hval = get_single_header(msg, "Call-ID", "i", &dup_flag); + if (!hval || dup_flag) { + ess->error_field = "Call-ID"; + return(-1); + } + ess->call_id = hval; + hval = get_single_header(msg, "CSeq", (char *) 0, &dup_flag); + if (!hval || dup_flag) { +bad_cseq: ess->error_field = "CSeq"; + return(-1); + } + if (!isdigit(*hval)) + goto bad_cseq; + ess->cseq_num = strtoul(hval, &cp, 10); + if (*cp) { + if (!isspace(*cp)) + goto bad_cseq; + while (isspace(*cp)) + cp++; + if (strcmp(cp, msg->req_method)) + goto bad_cseq; + } + hval = get_single_header(msg, "From", "f", &dup_flag); + if (!hval || dup_flag) { + ess->error_field = "From"; + return(-1); + } + ess->from = hval; + hval = get_single_header(msg, "To", "t", &dup_flag); + if (!hval || dup_flag) { + ess->error_field = "To"; + return(-1); + } + ess->to = hval; + hval = get_single_header(msg, "Via", "v", &dup_flag); + if (!hval || dup_flag) { + ess->error_field = "Via"; + return(-1); + } + ess->via = hval; + return(0); +} + +add_resp_basic_headers(msg, ess, req_method) + struct sip_msg_out *msg; + struct uas_parse_hdrs *ess; + char *req_method; +{ + char cseq_str[80]; + int rc; + + rc = out_msg_add_header(msg, "From", ess->from); + if (rc < 0) + return rc; + rc = out_msg_add_header(msg, "To", ess->to); + if (rc < 0) + return rc; + rc = out_msg_add_header(msg, "Call-ID", ess->call_id); + if (rc < 0) + return rc; + sprintf(cseq_str, "%u %.64s", ess->cseq_num, req_method); + rc = out_msg_add_header(msg, "CSeq", cseq_str); + if (rc < 0) + return rc; + return out_msg_add_header(msg, "Via", ess->via); +}