[asterisk-commits] tzafrir: branch tzafrir/monitor-rtp-14 r213893 - /team/tzafrir/monitor-rtp-14...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Aug 24 18:34:04 CDT 2009
Author: tzafrir
Date: Mon Aug 24 18:34:01 2009
New Revision: 213893
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=213893
Log:
send dummy SIP packet with metadata on startup/end
On stream startup send a SIP INVITE message and on stream end send a BYE
message.
Each of those include practically the same data and are intended to pass
information about the stream to the remote party. The remote recording
server is not expected to respond to those messages.
This method is used to pass CDR information to the remote side. Currrently
only src, dst, and clid are passed along.
Also note that unlike any standard SIP call, a separate INVITE/BYE pair
will be used for any separate direction (tx, rx) of the channel.
Modified:
team/tzafrir/monitor-rtp-14/res/res_monitor.c
Modified: team/tzafrir/monitor-rtp-14/res/res_monitor.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/tzafrir/monitor-rtp-14/res/res_monitor.c?view=diff&rev=213893&r1=213892&r2=213893
==============================================================================
--- team/tzafrir/monitor-rtp-14/res/res_monitor.c (original)
+++ team/tzafrir/monitor-rtp-14/res/res_monitor.c Mon Aug 24 18:34:01 2009
@@ -212,6 +212,126 @@
return fs;
}
+#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 };
+#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;
+ struct ast_cdr *cdr = chan ? chan->cdr : NULL;
+ 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);
+#if 0
+ /* Debugging code */
+ {
+ char buf[BUFSIZ];
+
+ buf[0] = '\0';
+ ast_cdr_serialize_variables(cdr, buf, sizeof(buf), '\t', '\n', 1);
+ ast_log(LOG_NOTICE, "%s\n", buf);
+ }
+#endif
+#ifdef RTP_MONITOR_DEBUG
+ {
+ 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) {
+ 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))) {
+ 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) {
+ ast_log(LOG_WARNING, "Cannot convert ip address: %s\n", strerror(errno));
+ return -1;
+ }
+ ast_cdr_getvar(cdr, "src", &src, srcbuf, sizeof(srcbuf), 0, 0);
+ ast_cdr_getvar(cdr, "dst", &dst, dstbuf, sizeof(dstbuf), 0, 0);
+ ast_cdr_getvar(cdr, "clid", &clid, clidbuf, sizeof(clidbuf), 0, 0);
+ if(begin) {
+ snprintf(payload, sizeof(payload),
+ "v=0\r\n"
+ "o=asterisk %s 1 IN IP4 %s\r\n"
+ "c=IN IP4 %s\r\n"
+ "s=Phone recording (%s)\r\n"
+ "i=Asterisk Monitor (pid=%d)\r\n"
+ "m=audio %d RTP/AVP 0 \r\n"
+ "a=rtpmap:0 PCMU/8000\r\n",
+ chan->uniqueid, my_ip,
+ my_ip,
+ (is_rx) ? "RX" : "TX",
+ getpid(),
+ ntohs(rtp_port));
+ } else
+ payload[0] = '\0';
+ content_length = strlen(payload);
+ i = 0;
+ i += snprintf(header + i, sizeof(header) - i,
+ "%s sip:%s@%s:5060 SIP/2.0\r\n",
+ (begin) ? "INVITE" : "BYE",
+ srcbuf, my_ip);
+ i += snprintf(header + i, sizeof(header) - i,
+ "Via: SIP/2.0/UDP %s:5061;branch=z9hG4bK-%s\r\n",
+ my_ip, chan->uniqueid);
+ i += snprintf(header + i, sizeof(header) - i, "From: <sip:%s@%s:5061>;tag=1\r\n", src, my_ip);
+ i += snprintf(header + i, sizeof(header) - i, "To: <sip:%s@%s:5060>\r\n", dst, my_ip);
+ i += snprintf(header + i, sizeof(header) - i, "Call-ID: %s\r\n", chan->uniqueid);
+ i += snprintf(header + i, sizeof(header) - i, "CSeq: 1 %s\r\n", (begin) ? "INVITE" : "BYE");
+ i += snprintf(header + i, sizeof(header) - i,
+ "Contact: sip:asterisk@%s:5061\r\n"
+ "Max-Forwards: 70\r\n"
+ "Subject: %s %s recording of %s\r\n",
+ my_ip,
+ (begin) ? "BEGIN" : "END",
+ (is_rx) ? "RX" : "TX",
+ clid);
+ 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);
+ i = snprintf(packet, sizeof(packet), "%s\r\n%s", header, payload);
+ 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) {
+ ast_log(LOG_WARNING, "Bad SIP sendto (%d bytes): %s\n", i, strerror(errno));
+ return -1;
+ }
+ return 0;
+}
+
/* Start monitoring a channel */
int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
const char *fname_base, int need_lock)
More information about the asterisk-commits
mailing list