<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][15442] </title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=15442">15442</a></dd>
<dt>Author</dt> <dd>ledr</dd>
<dt>Date</dt> <dd>2009-11-12 06:32:08 -0600 (Thu, 12 Nov 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>now generating fake headers - still sucks this way</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunkcontribledrcmod_pclimod_pclic">freeswitch/trunk/contrib/ledr/c/mod_pcli/mod_pcli.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunkcontribledrcmod_pclimod_pclic"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/contrib/ledr/c/mod_pcli/mod_pcli.c (15441 => 15442)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/ledr/c/mod_pcli/mod_pcli.c        2009-11-12 03:52:07 UTC (rev 15441)
+++ freeswitch/trunk/contrib/ledr/c/mod_pcli/mod_pcli.c        2009-11-12 12:32:08 UTC (rev 15442)
</span><span class="lines">@@ -37,6 +37,11 @@
</span><span class="cx">
</span><span class="cx"> SWITCH_STANDARD_APP(pcli_start_function);
</span><span class="cx">
</span><ins>+#define PCLI_HEADER_LEN 4
+#define IP_HEADER_LEN 20
+#define UDP_HEADER_LEN 8
+#define RTP_HEADER_LEN 12
+
</ins><span class="cx"> typedef enum {
</span><span class="cx">         PCLI_MEDIA_DIRECTION_UNKNOWN, /* 0 */
</span><span class="cx">         PCLI_MEDIA_DIRECTION_FROM_TARGET, /* 1 */
</span><span class="lines">@@ -57,8 +62,8 @@
</span><span class="cx"> } pcli_globals;
</span><span class="cx">
</span><span class="cx"> // temporary declaration here.. remove after testing is done !!!!
</span><del>-static switch_status_t gen_pcli_header(uint32_t *pcli_header, pcli_media_direction_t media_direction, uint16_t call_id, uint8_t switch_id, uint16_t ini_id);
-static switch_status_t send_packet();
</del><ins>+static switch_status_t gen_pcli_header(char *pcli_header, pcli_media_direction_t media_direction, uint16_t call_id, uint8_t switch_id, uint16_t ini_id);
+//static switch_status_t send_packet();
</ins><span class="cx">
</span><span class="cx"> typedef struct {
</span><span class="cx">         switch_core_session_t *session;
</span><span class="lines">@@ -138,61 +143,45 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx">
</span><del>-static switch_status_t send_packet() {
-        /* create a pcli header */
-        uint32_t pcli_header;
-        pcli_media_direction_t media_direction = PCLI_MEDIA_DIRECTION_FROM_TARGET;
-        uint16_t call_id = 123;
-        uint8_t switch_id = 12;
-        uint16_t ini_id = 10741;
-        gen_pcli_header(&pcli_header, media_direction, call_id, switch_id, ini_id);
</del><ins>+//static switch_status_t send_packet() {
+//        /* create a pcli header */
+//        uint32_t pcli_header;
+//        pcli_media_direction_t media_direction = PCLI_MEDIA_DIRECTION_FROM_TARGET;
+//        uint16_t call_id = 123;
+//        uint8_t switch_id = 12;
+//        uint16_t ini_id = 10741;
+//        gen_pcli_header(&pcli_header, media_direction, call_id, switch_id, ini_id);
+//
+//        uint32_t network_byte_order_pcli_header;
+//        network_byte_order_pcli_header = htonl(pcli_header);
+//
+//        /* create a pcli body */
+//        char *pcli_body = "ABCD";
+//
+//        /* create a full packet */
+//        char *packet; // TODO shouldn't this be unsigned ?
+//        packet = malloc(sizeof(network_byte_order_pcli_header) + sizeof(pcli_body));
+//        memcpy(packet, &network_byte_order_pcli_header, sizeof(network_byte_order_pcli_header));
+//        memcpy(packet + sizeof(network_byte_order_pcli_header), pcli_body, sizeof(pcli_body));
+//
+//        size_t packetsize;
+//        packetsize = sizeof(packet);
+//
+//        //switch_socket_sendto(pcli_globals.socket, remote_sockaddr, 0, packet, &packetsize);
+//        switch_socket_sendto(pcli_globals.socket, pcli_globals.remote_sockaddr, 0, packet, &packetsize);
+//
+//        return SWITCH_STATUS_SUCCESS;
+//}
</ins><span class="cx">
</span><del>-        uint32_t network_byte_order_pcli_header;
-        network_byte_order_pcli_header = htonl(pcli_header);
</del><span class="cx">
</span><del>-        /* create a pcli body */
-        char *pcli_body = "ABCD";
-
-        /* create a full packet */
-        char *packet; // TODO shouldn't this be unsigned ?
-        packet = malloc(sizeof(network_byte_order_pcli_header) + sizeof(pcli_body));
-        memcpy(packet, &network_byte_order_pcli_header, sizeof(network_byte_order_pcli_header));
-        memcpy(packet + sizeof(network_byte_order_pcli_header), pcli_body, sizeof(pcli_body));
-
-        size_t packetsize;
-        packetsize = sizeof(packet);
-
-        //switch_socket_sendto(pcli_globals.socket, remote_sockaddr, 0, packet, &packetsize);
-        switch_socket_sendto(pcli_globals.socket, pcli_globals.remote_sockaddr, 0, packet, &packetsize);
-
-        return SWITCH_STATUS_SUCCESS;
-}
-
-
-
-
</del><span class="cx"> /* called when SWITCH_EVENT_RELOADXML is sent to this module */
</span><span class="cx"> static void reload_event_handler(switch_event_t *event)
</span><span class="cx"> {
</span><span class="cx">         do_config(SWITCH_TRUE);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-/*
-static switch_status_t gen_fake_ipv4_header()
-{
-}
-
-static switch_status_t gen_fake_udp_header()
-{
-}
-
-static switch_status_t gen_fake_rtp_body()
-{
-}
-*/
-
</del><span class="cx"> /* generate a PacketCable Lawful Intercept header, that can be prepended to an RTP packet */
</span><del>-static switch_status_t gen_pcli_header(uint32_t *pcli_header, pcli_media_direction_t media_direction, uint16_t instance_id, uint8_t switch_id, uint16_t ini_id)
</del><ins>+static switch_status_t gen_pcli_header(char *pcli_header, pcli_media_direction_t media_direction, uint16_t instance_id, uint8_t switch_id, uint16_t ini_id)
</ins><span class="cx"> {
</span><span class="cx">         /* some sanity checks */
</span><span class="cx">
</span><span class="lines">@@ -222,6 +211,27 @@
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static switch_status_t gen_ip_header(char *ip_header, uint16_t payload_size)
+{
+        return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t gen_udp_header(char *udp_header, uint16_t payload_size)
+{
+        return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t gen_rtp_header(char *rtp_header, switch_payload_t payload, uint16_t seq, uint32_t timestamp, uint32_t ssrc)
+{
+        return SWITCH_STATUS_SUCCESS;
+}
+
+static void print_frame_stats(switch_frame_t *frame)
+{
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "FRAME STATISTICS: seq[%u] ssrc[%lu] datalen[%lu] rate [%lu] samples [%lu]\n",
+                (unsigned)frame->seq, (unsigned long)frame->ssrc, (unsigned long)frame->datalen, (unsigned long)frame->rate, (unsigned long)frame->samples);
+}
+
</ins><span class="cx"> static switch_bool_t pcli_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
</span><span class="cx"> {
</span><span class="cx">         //pcli_session_helper_t *helper = (pcli_session_helper_t *) user_data;
</span><span class="lines">@@ -232,35 +242,61 @@
</span><span class="cx">                 case SWITCH_ABC_TYPE_CLOSE:
</span><span class="cx">                 case SWITCH_ABC_TYPE_READ:
</span><span class="cx">                 case SWITCH_ABC_TYPE_WRITE:
</span><del>-                case SWITCH_ABC_TYPE_READ_REPLACE:
-                case SWITCH_ABC_TYPE_WRITE_REPLACE:
</del><span class="cx">                         break;
</span><span class="cx">
</span><del>-                case SWITCH_ABC_TYPE_READ_EARLY:
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "--> SWITCH_ABC_TYPE_READ_EARLY\n");
-                        
-/*
</del><ins>+                case SWITCH_ABC_TYPE_READ_REPLACE:
</ins><span class="cx">                         {
</span><del>-                        switch_frame_t *rframe = switch_core_media_bug_get_read_replace_frame(bug);
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "--> READ_REPLACE seq[%u] ssrc[%lu] packetlen[%lu] rate [%lu] samples [%lu]\n",
-                                (unsigned)rframe->seq, (unsigned long)rframe->ssrc, (unsigned long)rframe->packetlen, (unsigned long)rframe->rate, (unsigned long)rframe->samples);
-switch_size_t packetlength = sizeof(rframe->packet);
-switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, ">>> [%lu]\n", (unsigned long)packetlength);
</del><ins>+                                switch_frame_t *rframe = switch_core_media_bug_get_read_replace_frame(bug);
+                                print_frame_stats(rframe);
</ins><span class="cx">
</span><del>-                        //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "HELPER.SESSION->RAW_READ_FRAME.DATALEN [%lu]\n", helper->session->raw_read_frame.datalen);
</del><ins>+                                char pcli_header[PCLI_HEADER_LEN];
+                                char ip_header[IP_HEADER_LEN];
+                                char udp_header[UDP_HEADER_LEN];
+                                char rtp_header[RTP_HEADER_LEN];
</ins><span class="cx">
</span><ins>+                                char packet[PCLI_HEADER_LEN + IP_HEADER_LEN + UDP_HEADER_LEN + RTP_HEADER_LEN + rframe->datalen];
+                                char *in_packet_pointer = packet;
</ins><span class="cx">
</span><ins>+                                gen_rtp_header(rtp_header, rframe->payload, rframe->seq, rframe->timestamp, rframe->ssrc);
+                                gen_udp_header(udp_header, RTP_HEADER_LEN + rframe->datalen);
+                                gen_ip_header(ip_header, UDP_HEADER_LEN + RTP_HEADER_LEN + rframe->datalen);
+                                gen_pcli_header(pcli_header, PCLI_MEDIA_DIRECTION_FROM_TARGET, 1, 1, 1); // 1,1,1 = instance_id, switch_id, ini_id
+
+                                memcpy(in_packet_pointer, pcli_header, sizeof(pcli_header));                                
+                                in_packet_pointer += PCLI_HEADER_LEN;
+
+                                memcpy(in_packet_pointer, ip_header, sizeof(ip_header));                
+                                in_packet_pointer += IP_HEADER_LEN;
+
+                                memcpy(in_packet_pointer, udp_header, sizeof(udp_header));
+                                in_packet_pointer += UDP_HEADER_LEN;
+
+                                memcpy(in_packet_pointer, rtp_header, sizeof(rtp_header));
+                                in_packet_pointer += RTP_HEADER_LEN;
+
+                                memcpy(in_packet_pointer, rframe->data, rframe->datalen);
+
+                                /* since the (fake) rtp header is almost static, we know the size in advance */
+                                //packet = malloc(packet_len);
+
+//                                memcpy(packet, rframe->data, rframe->datalen);
+//                                packet_len += rframe->datalen;
+                                
+        //memcpy(packet, &network_byte_order_pcli_header, sizeof(network_byte_order_pcli_header));
+        //memcpy(packet + sizeof(network_byte_order_pcli_header), pcli_body, sizeof(pcli_body));
+
+//                                free(packet);
+
</ins><span class="cx">                         }
</span><del>-*/
</del><span class="cx">                         break;
</span><span class="cx">
</span><del>-                case SWITCH_ABC_TYPE_WRITE_LATE:
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "--> SWITCH_ABC_TYPE_WRITE_LATE\n");
</del><ins>+                case SWITCH_ABC_TYPE_WRITE_REPLACE:
</ins><span class="cx">                         break;
</span><ins>+
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">
</span><del>-        send_packet();
</del><ins>+        //send_packet();
</ins><span class="cx">
</span><span class="cx">         return SWITCH_TRUE;
</span><span class="cx"> }
</span><span class="lines">@@ -321,8 +357,7 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         /* add the bug */
</span><del>-        //status = switch_core_media_bug_add(session, pcli_callback, pcli_session_helper, 0, SMBF_READ_REPLACE | SMBF_WRITE_REPLACE, &bug);
-        status = switch_core_media_bug_add(session, pcli_callback, pcli_session_helper, 0, SMBF_READ_STREAM, &bug);
</del><ins>+        status = switch_core_media_bug_add(session, pcli_callback, pcli_session_helper, 0, SMBF_READ_REPLACE | SMBF_WRITE_REPLACE, &bug);
</ins><span class="cx">
</span><span class="cx">         if (status != SWITCH_STATUS_SUCCESS) {
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failure hooking to stream\n");
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>