view libsip/sdp_gen.c @ 240:c7a3ba56c636

themwi-short-dial: fix bug in printf arguments
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 15:37:59 -0800
parents 9f045dcff60e
children
line wrap: on
line source

/*
 * Here we implement generation of outgoing SDP descriptions.
 */

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "sdp.h"
#include "out_msg.h"

format_sdp_in_buffer(gen, buf, lenptr)
	struct sdp_gen *gen;
	char *buf;
	unsigned *lenptr;
{
	char *dp, *codec_list;

	dp = buf;
	strcpy(dp, "v=0\r\n");
	dp += 5;
	sprintf(dp, "o=- %u %u IN IP4 %s\r\n", gen->session_id, gen->version,
		inet_ntoa(gen->owner_ip));
	dp = index(dp, '\0');
	strcpy(dp, "s=-\r\n");
	dp += 5;
	sprintf(dp, "c=IN IP4 %s\r\n", inet_ntoa(gen->conn_ip));
	dp = index(dp, '\0');
	strcpy(dp, "t=0 0\r\n");
	dp += 7;
	switch (gen->codec_mask) {
	case SDP_CODEC_MASK_PCMU:
		codec_list = "0";
		break;
	case SDP_CODEC_MASK_PCMA:
		codec_list = "8";
		break;
	case SDP_CODEC_MASK_BOTH:
		codec_list = "0 8";
		break;
	case SDP_CODEC_MASK_BOTH | SDP_CODEC_MASK_PCMA_PREF:
		codec_list = "8 0";
		break;
	default:
		return(-2);
	}
	sprintf(dp, "m=audio %u RTP/AVP %s\r\n", gen->conn_port, codec_list);
	dp = index(dp, '\0');
	if (gen->codec_mask & SDP_CODEC_MASK_PCMU) {
		strcpy(dp, "a=rtpmap:0 PCMU/8000\r\n");
		dp += 22;
	}
	if (gen->codec_mask & SDP_CODEC_MASK_PCMA) {
		strcpy(dp, "a=rtpmap:8 PCMA/8000\r\n");
		dp += 22;
	}
	strcpy(dp, "a=sendrecv\r\n");
	dp += 12;
	strcpy(dp, "a=ptime:20\r\n");
	dp += 12;
	*lenptr = (dp - buf);
	return(0);
}

out_msg_finish_sdp(msg, gen)
	struct sip_msg_out *msg;
	struct sdp_gen *gen;
{
	char sdp_buf[256];
	unsigned sdp_len;
	int rc;

	rc = format_sdp_in_buffer(gen, sdp_buf, &sdp_len);
	if (rc < 0)
		return rc;
	return out_msg_finish_body(msg, sdp_buf, sdp_len);
}