FreeCalypso > hg > themwi-system-sw
changeset 93:ff5e96162430
libsip: new function for extracting Call-ID and CSeq from responses
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 24 Sep 2022 15:13:53 -0800 |
parents | a9137bdb6047 |
children | 2c22b40408fb |
files | libsip/Makefile libsip/resp_ident.c libsip/resp_ident.h |
diffstat | 3 files changed, 67 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libsip/Makefile Fri Sep 23 19:18:07 2022 -0800 +++ b/libsip/Makefile Sat Sep 24 15:13:53 2022 -0800 @@ -1,7 +1,7 @@ CC= gcc CFLAGS= -O2 -OBJS= get_header.o grok_from.o out_msg.o primary_parse.o req_supp.o sdp_gen.o\ - sdp_parse.o to_tag.o uas_basic.o uri_utils.o +OBJS= get_header.o grok_from.o out_msg.o primary_parse.o req_supp.o \ + resp_ident.o sdp_gen.o sdp_parse.o to_tag.o uas_basic.o uri_utils.o LIB= libsip.a all: ${LIB}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libsip/resp_ident.c Sat Sep 24 15:13:53 2022 -0800 @@ -0,0 +1,52 @@ +/* + * In this module we implement an essential step in the process + * of handling incoming SIP response messages: extracting Call-ID + * and CSeq headers and preparsing the latter, providing key info + * for matching these incoming responses with call state and + * with outstanding UAC requests. + */ + +#include <ctype.h> +#include <string.h> +#include <strings.h> +#include <stdio.h> +#include <stdlib.h> +#include "parse.h" +#include "resp_ident.h" + +extern char *get_single_header(); + +sip_resp_extract_ident(msg, id) + struct sip_pkt_rx *msg; + struct sip_resp_ident *id; +{ + char *hval, *cp; + int dup_flag = 0; + + hval = get_single_header(msg, "Call-ID", "i", &dup_flag); + if (!hval || dup_flag) { + id->error_field = "Call-ID"; + return(-1); + } + id->call_id = hval; + hval = get_single_header(msg, "CSeq", (char *) 0, &dup_flag); + if (!hval || dup_flag) { +bad_cseq: id->error_field = "CSeq"; + return(-1); + } + if (!isdigit(*hval)) + goto bad_cseq; + id->cseq_num = strtoul(hval, &cp, 10); + if (!isspace(*cp)) + goto bad_cseq; + while (isspace(*cp)) + cp++; + if (!isupper(*cp)) + goto bad_cseq; + id->cseq_method = cp; + while (isalnum(*cp)) + cp++; + if (*cp) + goto bad_cseq; + return(0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libsip/resp_ident.h Sat Sep 24 15:13:53 2022 -0800 @@ -0,0 +1,13 @@ +/* + * Here we define struct sip_resp_ident, a structure that captures + * Call-ID and CSeq headers from initial parsing of SIP responses, + * allowing these responses to be matched with call state and + * with UAC requests that elicited them. + */ + +struct sip_resp_ident { + char *call_id; + unsigned cseq_num; + char *cseq_method; + char *error_field; +};