[asterisk-commits] tzafrir: branch tzafrir/monitor-rtp r214149 - in /team/tzafrir/monitor-rtp: f...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 25 15:59:26 CDT 2009


Author: tzafrir
Date: Tue Aug 25 15:59:22 2009
New Revision: 214149

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=214149
Log:
Coding guidelines fixes. No functional change.

Modified:
    team/tzafrir/monitor-rtp/formats/format_rtp.c
    team/tzafrir/monitor-rtp/main/file.c
    team/tzafrir/monitor-rtp/res/res_monitor.c

Modified: team/tzafrir/monitor-rtp/formats/format_rtp.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/tzafrir/monitor-rtp/formats/format_rtp.c?view=diff&rev=214149&r1=214148&r2=214149
==============================================================================
--- team/tzafrir/monitor-rtp/formats/format_rtp.c (original)
+++ team/tzafrir/monitor-rtp/formats/format_rtp.c Tue Aug 25 15:59:22 2009
@@ -41,54 +41,60 @@
 #include "asterisk/monitor.h"
 
 #define	SLIN_SAMPLES	160
-#define BUF_SIZE	(SLIN_SAMPLES*2)		/* 320 bytes, 160 samples */
+#define BUF_SIZE	(SLIN_SAMPLES*2)	/* 320 bytes, 160 samples */
 
 /*
  * Grabbed from DAHDI sources
  */
 static unsigned char lineartoulaw(short sample)
 {
-  static int exp_lut[256] = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
-                             4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
-                             5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
-                             5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
-                             6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
-                             6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
-                             6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
-                             6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
-                             7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
-                             7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
-                             7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
-                             7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
-                             7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
-                             7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
-                             7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
-                             7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7};
-  int sign, exponent, mantissa;
-  unsigned char ulawbyte;
-  const int CLIP = 32635;
-  const int BIAS = 0x84;   /* define the add-in bias for 16 bit samples */
+	static int exp_lut[256] = {
+		0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
+		4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+		5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+		5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+		6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+		6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+		6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+		6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+		7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+		7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+		7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+		7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+		7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+		7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+		7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+		7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
+	};
+	int sign, exponent, mantissa;
+	unsigned char ulawbyte;
+	const int CLIP = 32635;
+	const int BIAS = 0x84;		/* define the add-in bias for 16 bit samples */
 
-  /* Get the sample into sign-magnitude. */
-  sign = (sample >> 8) & 0x80;          /* set aside the sign */
-  if (sign != 0) sample = -sample;              /* get magnitude */
-  if (sample > CLIP) sample = CLIP;             /* clip the magnitude */
+	/* Get the sample into sign-magnitude. */
+	sign = (sample >> 8) & 0x80;	/* set aside the sign */
+	if (sign != 0)
+		sample = -sample;	/* get magnitude */
+	if (sample > CLIP)
+		sample = CLIP;		/* clip the magnitude */
 
-  /* Convert from 16 bit linear to ulaw. */
-  sample = sample + BIAS;
-  exponent = exp_lut[(sample >> 7) & 0xFF];
-  mantissa = (sample >> (exponent + 3)) & 0x0F;
-  ulawbyte = ~(sign | (exponent << 4) | mantissa);
-  if (ulawbyte == 0) ulawbyte = 0x02;   /* optional CCITT trap */
-  if (ulawbyte == 0xff) ulawbyte = 0x7f;   /* never return 0xff */
-  return(ulawbyte);
+	/* Convert from 16 bit linear to ulaw. */
+	sample = sample + BIAS;
+	exponent = exp_lut[(sample >> 7) & 0xFF];
+	mantissa = (sample >> (exponent + 3)) & 0x0F;
+	ulawbyte = ~(sign | (exponent << 4) | mantissa);
+	if (ulawbyte == 0)
+		ulawbyte = 0x02;	/* optional CCITT trap */
+	if (ulawbyte == 0xff)
+		ulawbyte = 0x7f;	/* never return 0xff */
+	return (ulawbyte);
 }
 
-static void rtp_convert_toulaw(unsigned char *dst, const int16_t *src, int samples)
+static void rtp_convert_toulaw(unsigned char *dst, const int16_t * src, int samples)
 {
-	int	i;
+	int i;
 
-	for(i = 0; i < samples; i++)
+	for (i = 0; i < samples; i++)
 		dst[i] = lineartoulaw(src[i]);
 }
 
@@ -110,8 +116,8 @@
 		ast_log(LOG_WARNING, "Asked to write non-slinear frame (%d)!\n", f->subclass);
 		return -1;
 	}
-	rtp_state = (struct monitor_rtp_state *)fs->filename;
-	if(!rtp_state) {
+	rtp_state = (struct monitor_rtp_state *) fs->filename;
+	if (!rtp_state) {
 		ast_log(LOG_WARNING, "No RTP state information for filestream\n");
 		return -1;
 	}
@@ -119,20 +125,24 @@
 	/*
 	 * Build RTP header
 	 */
-	codec = 0;	/* AST_FORMAT_ULAW */
-	tdiff = (long)ast_tvdiff_ms(ast_tvnow(), rtp_state->ts_start);
+	codec = 0;					/* AST_FORMAT_ULAW */
+	tdiff = (long) ast_tvdiff_ms(ast_tvnow(), rtp_state->ts_start);
 	buf[0] = htonl((2 << 30) | (codec << 16) | (rtp_state->seqno) | (0 << 23));
 	buf[1] = htonl(tdiff * 8);
 	buf[2] = htonl(rtp_state->ssrc);
 	//memcpy(&buf[3], f->data, f->datalen);
-	rtp_convert_toulaw((unsigned char*)&buf[3], f->data.ptr, f->datalen / 2);
-	if((res = sendto(fd, buf, 4*3 + f->datalen / 2, 0, &rtp_state->dest, sizeof(rtp_state->dest))) < 0) {
-		ast_log(LOG_WARNING, "Bad sendto #%d (%d bytes): %s\n", rtp_state->seqno, f->datalen, strerror(errno));
+	rtp_convert_toulaw((unsigned char *) &buf[3], f->data.ptr, f->datalen / 2);
+	if ((res =
+		 sendto(fd, buf, 4 * 3 + f->datalen / 2, 0, &rtp_state->dest,
+				sizeof(rtp_state->dest))) < 0) {
+		ast_log(LOG_WARNING, "Bad sendto #%d (%d bytes): %s\n", rtp_state->seqno,
+				f->datalen, strerror(errno));
 		return -1;
 	}
 	rtp_state->seqno++;
-	if((rate_limit++ % 1000) == 0)
-		ast_log(LOG_NOTICE, "%s (fd=%d, datalen=%d res=%d)\n", __FUNCTION__, fd, f->datalen, res);
+	if ((rate_limit++ % 1000) == 0)
+		ast_log(LOG_NOTICE, "%s (fd=%d, datalen=%d res=%d)\n", __FUNCTION__, fd,
+				f->datalen, res);
 	return 0;
 }
 

Modified: team/tzafrir/monitor-rtp/main/file.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/tzafrir/monitor-rtp/main/file.c?view=diff&rev=214149&r1=214148&r2=214149
==============================================================================
--- team/tzafrir/monitor-rtp/main/file.c (original)
+++ team/tzafrir/monitor-rtp/main/file.c Tue Aug 25 15:59:22 2009
@@ -1076,7 +1076,7 @@
 	/*
 	 * Use 'check' for an open file descriptor
 	 */
-	if(check > 0) {
+	if (check > 0) {
 		return ast_writefd((void *)filename, check, type);
 	}
 	AST_RWLIST_RDLOCK(&formats);

Modified: team/tzafrir/monitor-rtp/res/res_monitor.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/tzafrir/monitor-rtp/res/res_monitor.c?view=diff&rev=214149&r1=214148&r2=214149
==============================================================================
--- team/tzafrir/monitor-rtp/res/res_monitor.c (original)
+++ team/tzafrir/monitor-rtp/res/res_monitor.c Tue Aug 25 15:59:22 2009
@@ -292,7 +292,7 @@
 {
 	struct ast_hostent he;
 
-	if(!ast_gethostbyname(str, &he)) {
+	if (!ast_gethostbyname(str, &he)) {
 		ast_log(LOG_NOTICE, "Failed to resolve hostname '%s'\n", str);
 		return 0;
 	}
@@ -304,12 +304,12 @@
 {
 	int sock;
 
-	if(!get_ipaddr(server, &(saddr->sin_addr)))
+	if (!get_ipaddr(server, &(saddr->sin_addr)))
 		return -EINVAL;
 	ast_log(LOG_NOTICE, "%s: %s:%d\n", __FUNCTION__, server, port);
 	saddr->sin_family = AF_INET;
 	saddr->sin_port = htons(port);
-	if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+	if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
 		ast_log(LOG_NOTICE, "Failed to create UDP socket: %s\n", strerror(errno));
 		return -errno;
 	}
@@ -318,28 +318,29 @@
 
 static int sip_stream(const char *server, in_port_t port, struct sockaddr_in *saddr)
 {
-	int			sock;
-
-	if((sock = udp_stream(server, port, saddr)) < 0) {
+	int sock;
+
+	if ((sock = udp_stream(server, port, saddr)) < 0) {
 		ast_log(LOG_WARNING, "Failed to create SIP stream to '%s:%d'\n", server, port);
 		return -errno;
 	}
 	return sock;
 }
 
-static struct ast_filestream *rtp_stream(struct ast_channel *chan, const char *server, in_port_t port, uint32_t ssrc)
+static struct ast_filestream *rtp_stream(struct ast_channel *chan,
+		const char *server, in_port_t port, uint32_t ssrc)
 {
 	int sock;
 	struct ast_filestream *fs = NULL;
 	struct sockaddr_in saddr;
 	struct monitor_rtp_state *rtp_state;
 
-	if((sock = udp_stream(server, port, &saddr)) < 0) {
+	if ((sock = udp_stream(server, port, &saddr)) < 0) {
 		ast_log(LOG_WARNING, "Failed to create RTP stream to '%s:%d'\n", server, port);
 		return NULL;
 	}
 	rtp_state = ast_calloc(1, sizeof(*rtp_state));
-	if(!rtp_state) {
+	if (!rtp_state) {
 		ast_log(LOG_NOTICE, "Failed to allocate memory for rtp_state\n");
 		close(sock);
 		return NULL;
@@ -347,11 +348,12 @@
 	rtp_state->ssrc = ssrc;
 	rtp_state->seqno = 0;
 	rtp_state->ts_start = ast_tvnow();
-	ast_log(LOG_NOTICE, "%s: '%s:%d' (ssrc=%ld)\n", __FUNCTION__, server, port, (unsigned long)rtp_state->ssrc);
+	ast_log(LOG_NOTICE, "%s: '%s:%d' (ssrc=%ld)\n", __FUNCTION__,
+			server, port, (unsigned long) rtp_state->ssrc);
 	rtp_state->dest = saddr;
 	ast_log(LOG_NOTICE, "%s: sockfd=%d\n", __FUNCTION__, sock);
-	fs = ast_writefile((const char *)rtp_state, PCM_FORMAT, "UDP", 0, sock, 0);
-	if(!fs) {
+	fs = ast_writefile((const char *) rtp_state, PCM_FORMAT, "UDP", 0, sock, 0);
+	if (!fs) {
 		ast_log(LOG_WARNING, "No such format '%s'\n", PCM_FORMAT);
 		ast_free(rtp_state);
 	}
@@ -359,41 +361,41 @@
 }
 
 #ifdef RTP_MONITOR_DEBUG
-static	const char *cdr_readonly_vars[] = { "clid", "src", "dst", "dcontext", "channel", "dstchannel",
-				    "lastapp", "lastdata", "start", "answer", "end", "duration",
-				    "billsec", "disposition", "amaflags", "accountcode", "uniqueid",
-				    "userfield", NULL };
+static const char *cdr_readonly_vars[] =
+	{ "clid", "src", "dst", "dcontext", "channel", "dstchannel",
+	"lastapp", "lastdata", "start", "answer", "end", "duration",
+	"billsec", "disposition", "amaflags", "accountcode", "uniqueid",
+	"userfield", NULL
+};
 #endif /* ifdef RTP_MONITOR_DEBUG */
 
 static int send_cdr(struct ast_channel *chan, int begin, int is_rx, struct monitor_rtp_state *rtp_state)
 {
-	char		*src;
-	char		*dst;
-	char		*clid;
-	char		srcbuf[BUFSIZ];
-	char		dstbuf[BUFSIZ];
-	char		clidbuf[BUFSIZ];
-	char		header[BUFSIZ];
-	char		payload[BUFSIZ];
-	char		packet[BUFSIZ];
-	struct sockaddr_in	my_addr;
-	char		my_ip[INET_ADDRSTRLEN + 1];
-	in_port_t	rtp_port = rtp_state->dest.sin_port;
+	char *src;
+	char *dst;
+	char *clid;
+	char srcbuf[BUFSIZ];
+	char dstbuf[BUFSIZ];
+	char clidbuf[BUFSIZ];
+	char header[BUFSIZ];
+	char payload[BUFSIZ];
+	char packet[BUFSIZ];
+	struct sockaddr_in my_addr;
+	char my_ip[INET_ADDRSTRLEN + 1];
+	in_port_t rtp_port = rtp_state->dest.sin_port;
 	struct ast_cdr *cdr = chan ? chan->cdr : NULL;
-	int		content_length;
-	int		i;
+	int content_length;
+	int i;
 
 	if (!cdr)
 		return -1;
 	ast_log(LOG_NOTICE, "%s-%s(%d): %s\n",
-		(begin) ? "BEGIN" : "END",
-		(is_rx) ? "RX" : "TX",
-		ntohs(rtp_port),
-		chan->uniqueid);
+			(begin) ? "BEGIN" : "END",
+			(is_rx) ? "RX" : "TX", ntohs(rtp_port), chan->uniqueid);
 #if 0
 	/* Debugging code */
 	{
-		char		buf[BUFSIZ];
+		char buf[BUFSIZ];
 
 		buf[0] = '\0';
 		ast_cdr_serialize_variables(cdr, buf, sizeof(buf), '\t', '\n', 1);
@@ -402,24 +404,24 @@
 #endif
 #ifdef RTP_MONITOR_DEBUG
 	{
-		char		buf[BUFSIZ];
-		int		len = sizeof(buf);
-
-		for(i = 0; cdr_readonly_vars[i]; i++) {
+		char buf[BUFSIZ];
+		int len = sizeof(buf);
+
+		for (i = 0; cdr_readonly_vars[i]; i++) {
 			buf[0] = '\0';
 			ast_cdr_getvar(cdr, cdr_readonly_vars[i], &ret, buf, len, 0, 0);
-			if(ret) {
+			if (ret) {
 				ast_log(LOG_NOTICE, "%-20s - '%s'\n",
 						cdr_readonly_vars[i], ret);
 			}
 		}
 	}
 #endif /* ifdef RTP_MONITOR_DEBUG */
-	if(!get_ipaddr(reporting_host, &(my_addr.sin_addr))) {
+	if (!get_ipaddr(reporting_host, &(my_addr.sin_addr))) {
 		ast_log(LOG_WARNING, "Bad reporting_host: '%s'\n", reporting_host);
 		return -1;
 	}
-	if(inet_ntop(AF_INET, &my_addr.sin_addr, my_ip, sizeof(my_ip)) == NULL) {
+	if (inet_ntop(AF_INET, &my_addr.sin_addr, my_ip, sizeof(my_ip)) == NULL) {
 		ast_log(LOG_WARNING, "Cannot convert ip address: %s\n", strerror(errno));
 		return -1;
 	}
@@ -463,7 +465,7 @@
 		(begin) ? "BEGIN" : "END",
 		(is_rx) ? "RX" : "TX",
 		clid);
-	if(begin) {
+	if (begin) {
 		i += snprintf(header + i, sizeof(header) - i, "Content-Type: application/sdp\r\n");
 	}
 	i += snprintf(header + i, sizeof(header) - i, "Content-Length: %d\r\n", content_length);
@@ -471,7 +473,7 @@
 	ast_log(LOG_WARNING, "SIP header: %s\n", header);
 	ast_log(LOG_WARNING, "SIP payload: %s\n", payload);
 	ast_log(LOG_WARNING, "SIP packet: %s\n", packet);
-	if(sendto(sip_socket, packet, i, 0, &sip_server_addr, sizeof(sip_server_addr)) < 0) {
+	if (sendto(sip_socket, packet, i, 0, &sip_server_addr, sizeof(sip_server_addr)) < 0) {
 		ast_log(LOG_WARNING, "Bad SIP sendto (%d bytes): %s\n", i, strerror(errno));
 		return -1;
 	}
@@ -493,7 +495,7 @@
 
 		if (chan->monitor->read_stream) {
 			ast_log(LOG_NOTICE, "%s: close read_stream\n", __FUNCTION__);
-			if(rtp_state_rx) {
+			if (rtp_state_rx) {
 				send_cdr(chan, 0, 1, rtp_state_rx);
 				/* FIXME: make sure no memory leak on the 'close' below:
 				chan->monitor->read_stream->filename = NULL;
@@ -518,18 +520,19 @@
 	return 0;
 }
 
-static void calc_ssrc(struct ast_channel *chan, uint32_t *rx_ssrc, uint32_t *tx_ssrc)
-{
-	float	val;
-
-	if(chan->uniqueid && sscanf(chan->uniqueid, "%f", &val) == 1) {
-		time_t		t;
-		int		a;
-		uint32_t	ssrc;
-
-		t = (time_t)val;
+static void calc_ssrc(struct ast_channel *chan, uint32_t * rx_ssrc, uint32_t * tx_ssrc)
+{
+	float val;
+
+	if (chan->uniqueid && sscanf(chan->uniqueid, "%f", &val) == 1) {
+		time_t t;
+		int a;
+		uint32_t ssrc;
+
+		t = (time_t) val;
 		a = (val - t) * 10;
-		ast_log(LOG_DEBUG, "%s: val=%f t=%lu a=%d\n", __FUNCTION__, val, (unsigned long)t, a);
+		ast_log(LOG_DEBUG, "%s: val=%f t=%lu a=%d\n", __FUNCTION__, val,
+				(unsigned long)t, a);
 		ssrc = (t << 8) | ((a << 4) & 0xFF);
 		ast_log(LOG_DEBUG, "%s: ssrc=%u\n", __FUNCTION__, ssrc);
 		*rx_ssrc = ssrc;
@@ -537,8 +540,8 @@
 		return;
 	}
 	ast_log(LOG_WARNING,
-		"%s: Failed to parse uniqueid='%s' using random SSRC\n",
-		__FUNCTION__, chan->uniqueid);
+			"%s: Failed to parse uniqueid='%s' using random SSRC\n",
+			__FUNCTION__, chan->uniqueid);
 	*rx_ssrc = ast_random();
 	*tx_ssrc = ast_random();
 }
@@ -548,17 +551,17 @@
 	struct ast_channel_monitor *monitor;
 	struct monitor_rtp_state *rtp_state_rx;
 	struct monitor_rtp_state *rtp_state_tx;
-	const char	*port_offset;
-	uint32_t	rx_ssrc;
-	uint32_t	tx_ssrc;
-	int		portnum;
-	int		ret = -1;
+	const char *port_offset;
+	uint32_t rx_ssrc;
+	uint32_t tx_ssrc;
+	int portnum;
+	int ret = -1;
 
 	ast_log(LOG_NOTICE, "START monitor2rtp\n");
 	LOCK_IF_NEEDED(chan, need_lock);
 	port_offset = pbx_builtin_getvar_helper(chan, "RTP_PORT_OFFSET");
 	portnum = atoi(port_offset);
-	if(portnum <= 0) {
+	if (portnum <= 0) {
 		ast_log(LOG_WARNING, "Bad RTP_PORT_OFFSET='%s'\n", port_offset);
 		goto out;
 	}
@@ -570,13 +573,15 @@
 	/* RTP uses even port numbers */
 	portnum = (portnum - 1) * 2;
 	/* RX port */
-	monitor->read_stream = rtp_stream(chan, rtp_server_name, rtp_portbase_rx + portnum, rx_ssrc);
+	monitor->read_stream =
+		rtp_stream(chan, rtp_server_name, rtp_portbase_rx + portnum, rx_ssrc);
 	if (!monitor->read_stream) {
 		ast_log(LOG_WARNING, "Could not create UDP stream for read\n");
 		goto out;
 	}
 	/* TX port */
-	monitor->write_stream = rtp_stream(chan, rtp_server_name, rtp_portbase_tx + portnum, tx_ssrc);
+	monitor->write_stream =
+		rtp_stream(chan, rtp_server_name, rtp_portbase_tx + portnum, tx_ssrc);
 	if (!monitor->write_stream) {
 		ast_log(LOG_WARNING, "Could not create UDP stream for write\n");
 		ast_closestream(monitor->read_stream);
@@ -592,9 +597,9 @@
 	chan->monitor = monitor;
 	ast_monitor_set_state(chan, AST_MONITOR_RUNNING);
 	/* so we know this call has been monitored in case we need to bill for it or something */
-	pbx_builtin_setvar_helper(chan, "__MONITORED","true");
+	pbx_builtin_setvar_helper(chan, "__MONITORED", "true");
 	ret = 0;
-out:
+  out:
 	UNLOCK_IF_NEEDED(chan, need_lock);
 	return 0;
 }
@@ -615,8 +620,8 @@
 {
 	int res = 0;
 
-	if(rtp_server_name[0] != '\0') {
-		if(monitor2rtp_start(chan, need_lock) < 0) {
+	if (rtp_server_name[0] != '\0') {
+		if (monitor2rtp_start(chan, need_lock) < 0) {
 			return -1;
 		}
 		return 0;
@@ -1190,18 +1195,19 @@
 {
 	return do_pause_or_unpause(s, m, MONITOR_ACTION_UNPAUSE);
 }
-	
+
 static int reload_config(enum channelreloadreason reason)
 {
-	struct ast_config	*cfg;
-	struct ast_variable	*v;
+	struct ast_config *cfg;
+	struct ast_variable *v;
 	/* FIXME: config flags for ast_config_load: */
-	struct ast_flags	config_flags = {};
+	struct ast_flags config_flags = { };
 
 	ast_log(LOG_DEBUG, "%s [%s]\n", channelreloadreason2txt(reason), config_file);
 	cfg = ast_config_load(config_file, config_flags);
 	if (!cfg) {
-		ast_log(LOG_NOTICE, "Unable to load config %s. No monitoring to RTP\n", config_file);
+		ast_log(LOG_NOTICE, "Unable to load config %s. No monitoring to RTP\n",
+				config_file);
 		return 0;
 	}
 	rtp_server_name[0] = '\0';
@@ -1209,24 +1215,26 @@
 		if (!strcasecmp(v->name, "rtp_server")) {
 			ast_copy_string(rtp_server_name, v->value, sizeof(rtp_server_name));
 		} else if (!strcasecmp(v->name, "rtp_portbase_rx")) {
-			char		portstr[BUFSIZ];
-			unsigned int	port_value;
+			char portstr[BUFSIZ];
+			unsigned int port_value;
 
 			ast_copy_string(portstr, v->value, sizeof(portstr));
-			if ((sscanf(v->value, "%u", &port_value) != 1) /* TBD: || (port_value > MAXPORTNUM) */) {
+			if ((sscanf(v->value, "%u", &port_value) != 1)
+					/* TBD: || (port_value > MAXPORTNUM) */ ) {
 				ast_log(LOG_WARNING, "%s:%d: invalid port number '%s'.\n",
-					config_file, v->lineno, v->value);
+						config_file, v->lineno, v->value);
 			} else {
 				rtp_portbase_rx = port_value;
 			}
 		} else if (!strcasecmp(v->name, "rtp_portbase_tx")) {
-			char		portstr[BUFSIZ];
-			unsigned int	port_value;
+			char portstr[BUFSIZ];
+			unsigned int port_value;
 
 			ast_copy_string(portstr, v->value, sizeof(portstr));
-			if ((sscanf(v->value, "%u", &port_value) != 1) /* TBD: || (port_value > MAXPORTNUM) */) {
+			if ((sscanf(v->value, "%u", &port_value) != 1)
+					/* TBD: || (port_value > MAXPORTNUM) */) {
 				ast_log(LOG_WARNING, "%s:%d: invalid port number '%s'.\n",
-					config_file, v->lineno, v->value);
+						config_file, v->lineno, v->value);
 			} else {
 				rtp_portbase_tx = port_value;
 			}
@@ -1234,24 +1242,23 @@
 			ast_copy_string(reporting_host, v->value, sizeof(reporting_host));
 		} else {
 			ast_log(LOG_NOTICE, "%s:%d: Bad config option '%s' - (ignoring)\n",
-				config_file, v->lineno, v->name);
+					config_file, v->lineno, v->name);
 		}
 	}
 	ast_log(LOG_DEBUG, "monitor to %s [RX=%d, TX=%d]\n",
-		rtp_server_name, rtp_portbase_rx, rtp_portbase_tx);
+			rtp_server_name, rtp_portbase_rx, rtp_portbase_tx);
 	ast_config_destroy(cfg);
 	return 0;
 }
 
 static int load_module(void)
 {
-	if(reload_config(CHANNEL_MODULE_LOAD))
+	if (reload_config(CHANNEL_MODULE_LOAD))
 		return AST_MODULE_LOAD_DECLINE;
-	if(rtp_server_name[0] != '\0') {
-		if((sip_socket = sip_stream(rtp_server_name, 5060, &sip_server_addr)) < 0) {
+	if (rtp_server_name[0] != '\0') {
+		if ((sip_socket = sip_stream(rtp_server_name, 5060, &sip_server_addr)) < 0) {
 			ast_log(LOG_WARNING,
-				"Failed to create SIP stream to '%s:%d'\n",
-				rtp_server_name, 5060);
+					"Failed to create SIP stream to '%s:%d'\n", rtp_server_name, 5060);
 			return AST_MODULE_LOAD_DECLINE;
 		}
 	}
@@ -1282,7 +1289,7 @@
 	ast_manager_unregister("PauseMonitor");
 	ast_manager_unregister("UnpauseMonitor");
 
-	if(sip_socket != -1)
+	if (sip_socket != -1)
 		close(sip_socket);
 	return 0;
 }




More information about the asterisk-commits mailing list