view libsip/uas_basic.c @ 7:6d832abad660

test-fsk: gather and print full line of modem Rx characters
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 05 Mar 2024 10:57:45 -0800
parents 35c0d9f03c0a
children
line wrap: on
line source

/*
 * 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);
}