<!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][15015] </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=15015">15015</a></dd>
<dt>Author</dt> <dd>ledr</dd>
<dt>Date</dt> <dd>2009-09-29 15:09:24 -0500 (Tue, 29 Sep 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Initial import mod_li -- not doing much yet</pre>

<h3>Added Paths</h3>
<ul>
<li>freeswitch/trunk/contrib/ledr/c/mod_li/</li>
<li><a href="#freeswitchtrunkcontribledrcmod_liMakefile">freeswitch/trunk/contrib/ledr/c/mod_li/Makefile</a></li>
<li><a href="#freeswitchtrunkcontribledrcmod_liliconfxml">freeswitch/trunk/contrib/ledr/c/mod_li/li.conf.xml</a></li>
<li><a href="#freeswitchtrunkcontribledrcmod_limod_lic">freeswitch/trunk/contrib/ledr/c/mod_li/mod_li.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunkcontribledrcmod_liMakefile"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/contrib/ledr/c/mod_li/Makefile (0 => 15015)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/ledr/c/mod_li/Makefile                                (rev 0)
+++ freeswitch/trunk/contrib/ledr/c/mod_li/Makefile        2009-09-29 20:09:24 UTC (rev 15015)
</span><span class="lines">@@ -0,0 +1,2 @@
</span><ins>+BASE=/usr/src/freeswitch/trunk
+include $(BASE)/build/modmake.rules
</ins></span></pre></div>
<a id="freeswitchtrunkcontribledrcmod_liliconfxml"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/contrib/ledr/c/mod_li/li.conf.xml (0 => 15015)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/ledr/c/mod_li/li.conf.xml                                (rev 0)
+++ freeswitch/trunk/contrib/ledr/c/mod_li/li.conf.xml        2009-09-29 20:09:24 UTC (rev 15015)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+&lt;configuration name=&quot;li.conf&quot; description=&quot;Legal Intercept Configuration&quot;&gt;
+
+  &lt;settings&gt;
+    &lt;param name=&quot;local_addr&quot; value=&quot;172.31.1.5&quot;/&gt;
+    &lt;param name=&quot;local_port&quot; value=&quot;8000&quot;/&gt;
+    &lt;param name=&quot;target_addr&quot; value=&quot;172.31.1.4&quot;/&gt;
+    &lt;param name=&quot;target_port&quot; value=&quot;8000&quot;/&gt;
+  &lt;/settings&gt;
+
+&lt;/configuration&gt;
</ins></span></pre></div>
<a id="freeswitchtrunkcontribledrcmod_limod_lic"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/contrib/ledr/c/mod_li/mod_li.c (0 => 15015)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/ledr/c/mod_li/mod_li.c                                (rev 0)
+++ freeswitch/trunk/contrib/ledr/c/mod_li/mod_li.c        2009-09-29 20:09:24 UTC (rev 15015)
</span><span class="lines">@@ -0,0 +1,309 @@
</span><ins>+/* 
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005-2009, Anthony Minessale II &lt;anthm@freeswitch.org&gt;
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the &quot;License&quot;); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an &quot;AS IS&quot; basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * The Initial Developer of the Original Code is
+ * Anthony Minessale II &lt;anthm@freeswitch.org&gt;
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * 
+ * Leon de Rooij &lt;leon@toyos.nl&gt;
+ *
+ *
+ * mod_li.c -- Legal Intercept
+ *
+ * THIS MODULE IS STILL UNDER CONSTRUCTION !!!!!!!!!!!!!!!!!!!
+ *
+ * Enable Legal Intercept, copy all frame data, prepend it with
+ * LI_ID, SEQ, TIMESTAMP, DIRECTION, CIN (can I use call-uuid for this?) - perhaps ETSI232 compliant would be nice ?
+ * and send it over UDP to remote_addr:remote_port
+ *
+ */
+#include &lt;switch.h&gt;
+#include &lt;netdb.h&gt;
+
+SWITCH_MODULE_LOAD_FUNCTION(mod_li_load);
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_li_shutdown);
+SWITCH_MODULE_DEFINITION(mod_li, mod_li_load, mod_li_shutdown, NULL);
+
+SWITCH_STANDARD_APP(li_start_function);
+
+static struct {
+        switch_memory_pool_t *pool;
+        char *local_addr;
+        int local_port;
+        char *remote_addr;
+        int remote_port;
+        switch_socket_t *socket;
+} li_globals;
+
+typedef struct {
+        /*! Internal FreeSWITCH session. */
+        switch_core_session_t *session;
+        char *li_id; /* legal intercept id */
+} li_session_helper_t;
+
+/* config item validations */
+static switch_xml_config_string_options_t config_opt_valid_addr = { NULL, 0, &quot;.+&quot; };
+static switch_xml_config_int_options_t config_opt_valid_port = { SWITCH_TRUE, 0, SWITCH_TRUE, 65535 };
+
+/* config items */
+static switch_xml_config_item_t instructions[] = {
+        SWITCH_CONFIG_ITEM(&quot;local_addr&quot;, SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &amp;li_globals.local_addr,
+                &quot;localhost&quot;, &amp;config_opt_valid_addr, NULL, NULL),
+        SWITCH_CONFIG_ITEM(&quot;local_port&quot;, SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &amp;li_globals.local_port,
+                (void*)10741, &amp;config_opt_valid_port, NULL, NULL),
+        SWITCH_CONFIG_ITEM(&quot;remote_addr&quot;, SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &amp;li_globals.remote_addr,
+                &quot;localhost&quot;, &amp;config_opt_valid_addr, NULL, NULL),
+        SWITCH_CONFIG_ITEM(&quot;remote_port&quot;, SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &amp;li_globals.remote_port,
+                (void*)10741, &amp;config_opt_valid_port, NULL, NULL),
+  SWITCH_CONFIG_ITEM_END()
+};
+
+static switch_status_t do_config(switch_bool_t reload)
+{
+        switch_socket_t *socket = NULL;
+        switch_sockaddr_t *local_sockaddr;
+        switch_sockaddr_t *remote_sockaddr;
+
+        if (switch_xml_config_parse_module_settings(&quot;li.conf&quot;, reload, instructions) != SWITCH_STATUS_SUCCESS) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, &quot;Could not open li.conf\n&quot;);
+                return SWITCH_STATUS_FALSE;
+        }
+
+        /* for now, only init port on startup, fix reload later !! */
+        if (!reload) {
+
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, &quot;Trying to create a udp socket !!\n&quot;);
+
+                if (switch_sockaddr_info_get(&amp;local_sockaddr, li_globals.local_addr, SWITCH_UNSPEC, li_globals.local_port, 0, li_globals.pool) != SWITCH_STATUS_SUCCESS || !local_sockaddr) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, &quot;Local Address Error!\n&quot;);
+                        return SWITCH_STATUS_FALSE;
+                }
+
+                if (switch_socket_create(&amp;socket, switch_sockaddr_get_family(local_sockaddr), SOCK_DGRAM, 0, li_globals.pool) != SWITCH_STATUS_SUCCESS) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, &quot;Socket Error!\n&quot;);
+                        return SWITCH_STATUS_FALSE;
+                }
+
+                if (switch_socket_opt_set(socket, SWITCH_SO_REUSEADDR, 1) != SWITCH_STATUS_SUCCESS) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, &quot;Socket Error!\n&quot;);
+                        return SWITCH_STATUS_FALSE;
+                }
+
+                if (switch_socket_bind(socket, local_sockaddr) != SWITCH_STATUS_SUCCESS) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, &quot;Bind Error!\n&quot;);
+                        return SWITCH_STATUS_FALSE;
+                }
+
+                /* HAVE A LOOK AT switch_rtp.c LINE 746 and 796 FOR WIN32 COMPATIBILITY ! */
+
+                li_globals.socket = socket;
+
+                /* TEST SENDING A PACKET */
+                if (switch_sockaddr_info_get(&amp;remote_sockaddr, li_globals.remote_addr, SWITCH_UNSPEC, li_globals.remote_port, 0, li_globals.pool) != SWITCH_STATUS_SUCCESS || !remote_sockaddr) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, &quot;Remote Address Error!\n&quot;);
+                        return SWITCH_STATUS_FALSE;
+                }
+
+                switch_size_t len = sizeof(&quot;X&quot;);
+                switch_socket_sendto(li_globals.socket, remote_sockaddr, 0, &quot;X&quot;, &amp;len);
+
+        }
+
+        return SWITCH_STATUS_SUCCESS;
+}
+
+/* called when SWITCH_EVENT_RELOADXML is sent to this module */
+static void reload_event_handler(switch_event_t *event)
+{
+  do_config(SWITCH_TRUE);
+}
+
+/* necessary for hooking to SWITCH_EVENT_RELOADXML */
+static switch_event_node_t *NODE = NULL;
+
+static switch_bool_t li_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
+{
+//        li_session_helper_t *li_session_helper = (li_session_helper_t *) user_data;
+        switch_size_t len;
+
+        switch_sockaddr_t *remote_sockaddr;
+
+//        switch_buffer_t *buffer = (switch_buffer_t *) user_data;
+        uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
+        switch_frame_t frame = { 0 };
+
+        frame.data = data;
+        frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
+
+        switch (type) {
+        case SWITCH_ABC_TYPE_INIT:
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;--&gt; INIT\n&quot;);
+                break;
+
+        case SWITCH_ABC_TYPE_READ_PING:
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;--&gt; PING\n&quot;);
+                break;
+
+        case SWITCH_ABC_TYPE_CLOSE:
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;--&gt; CLOSE\n&quot;);
+                break;
+
+        case SWITCH_ABC_TYPE_READ:
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;--&gt; READ\n&quot;);
+
+                if (switch_sockaddr_info_get(&amp;remote_sockaddr, li_globals.remote_addr, SWITCH_UNSPEC, li_globals.remote_port, 0, li_globals.pool) != SWITCH_STATUS_SUCCESS || !remote_sockaddr) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, &quot;Remote Address Error!\n&quot;);
+                        return SWITCH_STATUS_FALSE;
+                }
+
+                while (switch_core_media_bug_read(bug, &amp;frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
+switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, &quot;HUK SEQ[%u]!\n&quot;, (unsigned)frame.seq);
+                        len = (switch_size_t) frame.datalen / 2;
+                        if (len) switch_socket_sendto(li_globals.socket, remote_sockaddr, 0, frame.data, &amp;len);
+                }
+switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, &quot;TILDE!\n&quot;);
+
+                break;
+
+        case SWITCH_ABC_TYPE_WRITE:
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;--&gt; WRITE\n&quot;);
+                break;
+
+        case SWITCH_ABC_TYPE_READ_REPLACE:
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;--&gt; READ_REPLACE\n&quot;);
+                break;
+
+        case SWITCH_ABC_TYPE_WRITE_REPLACE:
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;--&gt; WRITE_REPLACE\n&quot;);
+                break;
+        }
+
+        return SWITCH_TRUE;
+}
+
+SWITCH_STANDARD_APP(li_start_function)
+{
+    switch_media_bug_t *bug;
+    switch_status_t status;
+    switch_channel_t *channel;
+    li_session_helper_t *li_session_helper;
+                const char *p;
+
+    if (session == NULL)
+        return;
+
+    channel = switch_core_session_get_channel(session);
+
+    /* Is this channel already set? */
+    bug = (switch_media_bug_t *) switch_channel_get_private(channel, &quot;_li_&quot;);
+    /* If yes */
+    if (bug != NULL) {
+        /* If we have a stop remove audio bug */
+        if (strcasecmp(data, &quot;stop&quot;) == 0) {
+            switch_channel_set_private(channel, &quot;_li_&quot;, NULL);
+            switch_core_media_bug_remove(session, &amp;bug);
+            return;
+        }
+
+        /* We have already started */
+        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, &quot;Cannot run 2 at once on the same channel!\n&quot;);
+
+        return;
+    }
+
+                /* create a new li_session_helper */
+    li_session_helper = (li_session_helper_t *) switch_core_session_alloc(session, sizeof(li_session_helper_t));
+
+                /* make session available from li_session_helper */
+    li_session_helper-&gt;session = session;
+
+                /* get LI_ID and store in li_session_helper */
+                if ((p = switch_channel_get_variable(channel, &quot;LI_ID&quot;)) &amp;&amp; switch_true(p)) {
+                        li_session_helper-&gt;li_id = switch_core_session_strdup(session, p);
+                } else {
+                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;No LI_ID was set!\n&quot;);
+                        return;
+                }
+
+                /* add the bug */
+    status = switch_core_media_bug_add(session, li_callback, li_session_helper, 0, SMBF_BOTH, &amp;bug);
+
+    if (status != SWITCH_STATUS_SUCCESS) {
+        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Failure hooking to stream\n&quot;);
+        return;
+    }
+
+    switch_channel_set_private(channel, &quot;_li_&quot;, bug);
+}
+
+SWITCH_MODULE_LOAD_FUNCTION(mod_li_load)
+{
+    switch_application_interface_t *app_interface;
+
+                /* initialize li_globals struct */
+                memset(&amp;li_globals, 0, sizeof(li_globals));
+
+                /* make the pool available from li_globals */
+                li_globals.pool = pool;
+
+                /* do config */
+                do_config(SWITCH_FALSE);
+
+    /* connect my internal structure to the blank pointer passed to me */
+    *module_interface = switch_loadable_module_create_module_interface(pool, modname);
+
+                /* make the li application available to the system */
+    SWITCH_ADD_APP(app_interface, &quot;li&quot;, &quot;Legal Intercept&quot;, &quot;Legal Intercept&quot;, li_start_function, &quot;&lt;start&gt;&quot;, SAF_NONE);
+
+                /* subscribe to reloadxml event, and hook it to reload_event_handler */
+                if ((switch_event_bind_removable(modname, SWITCH_EVENT_RELOADXML, NULL, reload_event_handler, NULL, &amp;NODE) != SWITCH_STATUS_SUCCESS)) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Couldn't bind event!\n&quot;);
+                        return SWITCH_STATUS_TERM;
+                }
+
+                /* say it */
+    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;Legal Intercept enabled\n&quot;);
+
+    /* indicate that the module should continue to be loaded */
+    return SWITCH_STATUS_SUCCESS;
+}
+
+
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_li_shutdown)
+{
+    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;Legal Intercept disabled\n&quot;);
+
+/* TODO DESTROY THE SOCKET HERE ! */
+
+    return SWITCH_STATUS_SUCCESS;
+}
+
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:t
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4:
+ */
</ins></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>