<!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][15295] </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=15295">15295</a></dd>
<dt>Author</dt> <dd>ledr</dd>
<dt>Date</dt> <dd>2009-10-30 16:19:08 -0500 (Fri, 30 Oct 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>trying to get ini_id's autoincremented count in mysql transaction</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>

<h3>Added Paths</h3>
<ul>
<li><a href="#freeswitchtrunkcontribledrcmod_pclipclistructuremysql">freeswitch/trunk/contrib/ledr/c/mod_pcli/pcli.structure.mysql</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 (15294 => 15295)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/ledr/c/mod_pcli/mod_pcli.c        2009-10-30 20:01:09 UTC (rev 15294)
+++ freeswitch/trunk/contrib/ledr/c/mod_pcli/mod_pcli.c        2009-10-30 21:19:08 UTC (rev 15295)
</span><span class="lines">@@ -79,7 +79,7 @@
</span><span class="cx">                 &quot;localhost&quot;, &amp;config_opt_valid_addr, NULL, NULL),
</span><span class="cx">         SWITCH_CONFIG_ITEM(&quot;remote_port&quot;, SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &amp;pcli_globals.remote_port,
</span><span class="cx">                 (void*)10741, &amp;config_opt_valid_port, NULL, NULL),
</span><del>-  SWITCH_CONFIG_ITEM_END()
</del><ins>+        SWITCH_CONFIG_ITEM_END()
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> /* called at startup and reload of the module */
</span><span class="lines">@@ -160,7 +160,7 @@
</span><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><del>-  do_config(SWITCH_TRUE);
</del><ins>+        do_config(SWITCH_TRUE);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /* generate a PacketCable Lawful Intercept header, that can be prepended to an RTP packet */
</span><span class="lines">@@ -170,7 +170,7 @@
</span><span class="cx"> 
</span><span class="cx">         /* some sanity checks */
</span><span class="cx"> 
</span><del>-  if (media_direction &gt; 3) {
</del><ins>+        if (media_direction &gt; 3) {
</ins><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, &quot;Invalid media direction, may only be 0-3\n&quot;);
</span><span class="cx">                 return SWITCH_STATUS_FALSE;
</span><span class="cx">         }
</span><span class="lines">@@ -190,7 +190,7 @@
</span><span class="cx">         *pcli_header |= (media_direction);
</span><span class="cx">         *pcli_header |= (call_id &lt;&lt; 2);
</span><span class="cx">         *pcli_header |= (switch_id &lt;&lt; 12);
</span><del>-  *pcli_header |= (ini_id &lt;&lt; 16);
</del><ins>+        *pcli_header |= (ini_id &lt;&lt; 16);
</ins><span class="cx"> 
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="lines">@@ -251,102 +251,102 @@
</span><span class="cx"> 
</span><span class="cx"> SWITCH_STANDARD_APP(pcli_start_function)
</span><span class="cx"> {
</span><del>-    switch_media_bug_t *bug;
-    switch_status_t status;
-    switch_channel_t *channel;
-    pcli_session_helper_t *pcli_session_helper;
-                const char *p;
</del><ins>+        switch_media_bug_t *bug;
+        switch_status_t status;
+        switch_channel_t *channel;
+        pcli_session_helper_t *pcli_session_helper;
+        const char *p;
</ins><span class="cx"> 
</span><del>-    if (session == NULL)
-        return;
</del><ins>+        if (session == NULL)
+                return;
</ins><span class="cx"> 
</span><del>-    channel = switch_core_session_get_channel(session);
</del><ins>+        channel = switch_core_session_get_channel(session);
</ins><span class="cx"> 
</span><del>-    /* Is this channel already set? */
-    bug = (switch_media_bug_t *) switch_channel_get_private(channel, &quot;_pcli_&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;_pcli_&quot;, NULL);
-            switch_core_media_bug_remove(session, &amp;bug);
-            return;
-        }
</del><ins>+        /* Is this channel already set? */
+        bug = (switch_media_bug_t *) switch_channel_get_private(channel, &quot;_pcli_&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;_pcli_&quot;, NULL);
+                        switch_core_media_bug_remove(session, &amp;bug);
+                        return;
+                }
</ins><span class="cx"> 
</span><del>-        /* 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;);
</del><ins>+                /* 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;);
</ins><span class="cx"> 
</span><del>-        return;
-    }
</del><ins>+                return;
+        }
</ins><span class="cx"> 
</span><del>-                /* create a new pcli_session_helper */
-    pcli_session_helper = (pcli_session_helper_t *) switch_core_session_alloc(session, sizeof(pcli_session_helper_t));
</del><ins>+        /* create a new pcli_session_helper */
+        pcli_session_helper = (pcli_session_helper_t *) switch_core_session_alloc(session, sizeof(pcli_session_helper_t));
</ins><span class="cx"> 
</span><del>-                /* make session available from pcli_session_helper */
-    pcli_session_helper-&gt;session = session;
</del><ins>+        /* make session available from pcli_session_helper */
+        pcli_session_helper-&gt;session = session;
</ins><span class="cx"> 
</span><del>-                /* get LI_ID and store in pcli_session_helper */
-                if ((p = switch_channel_get_variable(channel, &quot;LI_ID&quot;)) &amp;&amp; switch_true(p)) {
-                        pcli_session_helper-&gt;ini_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;
-                }
</del><ins>+        /* get LI_ID and store in pcli_session_helper */
+        if ((p = switch_channel_get_variable(channel, &quot;LI_ID&quot;)) &amp;&amp; switch_true(p)) {
+                pcli_session_helper-&gt;ini_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;
+        }
</ins><span class="cx"> 
</span><del>-                /* add the bug */
-    //status = switch_core_media_bug_add(session, pcli_callback, pcli_session_helper, 0, SMBF_BOTH, &amp;bug);
-    //status = switch_core_media_bug_add(session, pcli_callback, pcli_session_helper, 0, SMBF_READ_STREAM | SMBF_WRITE_STREAM, &amp;bug);
-    status = switch_core_media_bug_add(session, pcli_callback, pcli_session_helper, 0, SMBF_READ_REPLACE | SMBF_WRITE_REPLACE, &amp;bug);
-    //status = switch_core_media_bug_add(session, pcli_callback, pcli_session_helper, 0, SMBF_READ_REPLACE, &amp;bug);
</del><ins>+        /* add the bug */
+        //status = switch_core_media_bug_add(session, pcli_callback, pcli_session_helper, 0, SMBF_BOTH, &amp;bug);
+        //status = switch_core_media_bug_add(session, pcli_callback, pcli_session_helper, 0, SMBF_READ_STREAM | SMBF_WRITE_STREAM, &amp;bug);
+        status = switch_core_media_bug_add(session, pcli_callback, pcli_session_helper, 0, SMBF_READ_REPLACE | SMBF_WRITE_REPLACE, &amp;bug);
+        //status = switch_core_media_bug_add(session, pcli_callback, pcli_session_helper, 0, SMBF_READ_REPLACE, &amp;bug);
</ins><span class="cx"> 
</span><del>-    if (status != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Failure hooking to stream\n&quot;);
-        return;
-    }
</del><ins>+        if (status != SWITCH_STATUS_SUCCESS) {
+                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Failure hooking to stream\n&quot;);
+                return;
+        }
</ins><span class="cx"> 
</span><del>-    switch_channel_set_private(channel, &quot;_pcli_&quot;, bug);
</del><ins>+        switch_channel_set_private(channel, &quot;_pcli_&quot;, bug);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> SWITCH_MODULE_LOAD_FUNCTION(mod_pcli_load)
</span><span class="cx"> {
</span><del>-    switch_application_interface_t *app_interface;
</del><ins>+        switch_application_interface_t *app_interface;
</ins><span class="cx"> 
</span><del>-                /* initialize pcli_globals struct */
-                memset(&amp;pcli_globals, 0, sizeof(pcli_globals));
</del><ins>+        /* initialize pcli_globals struct */
+        memset(&amp;pcli_globals, 0, sizeof(pcli_globals));
</ins><span class="cx"> 
</span><del>-                /* make the pool available from pcli_globals */
-                pcli_globals.pool = pool;
</del><ins>+        /* make the pool available from pcli_globals */
+        pcli_globals.pool = pool;
</ins><span class="cx"> 
</span><del>-                /* do config */
-                do_config(SWITCH_FALSE);
</del><ins>+        /* do config */
+        do_config(SWITCH_FALSE);
</ins><span class="cx"> 
</span><del>-    /* connect my internal structure to the blank pointer passed to me */
-    *module_interface = switch_loadable_module_create_module_interface(pool, modname);
</del><ins>+        /* connect my internal structure to the blank pointer passed to me */
+        *module_interface = switch_loadable_module_create_module_interface(pool, modname);
</ins><span class="cx"> 
</span><del>-                /* make the pcli application available to the system */
-    SWITCH_ADD_APP(app_interface, &quot;pcli&quot;, &quot;PacketCable Lawful Intercept&quot;, &quot;PacketCable Lawful Intercept&quot;, pcli_start_function, &quot;&lt;start&gt;&quot;, SAF_NONE);
</del><ins>+        /* make the pcli application available to the system */
+        SWITCH_ADD_APP(app_interface, &quot;pcli&quot;, &quot;PacketCable Lawful Intercept&quot;, &quot;PacketCable Lawful Intercept&quot;, pcli_start_function, &quot;&lt;start&gt;&quot;, SAF_NONE);
</ins><span class="cx"> 
</span><del>-                /* 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;
-                }
</del><ins>+        /* 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;
+        }
</ins><span class="cx"> 
</span><del>-                /* say it */
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;Lawful Intercept enabled\n&quot;);
</del><ins>+        /* say it */
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;Lawful Intercept enabled\n&quot;);
</ins><span class="cx"> 
</span><del>-    /* indicate that the module should continue to be loaded */
-    return SWITCH_STATUS_SUCCESS;
</del><ins>+        /* indicate that the module should continue to be loaded */
+        return SWITCH_STATUS_SUCCESS;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_pcli_shutdown)
</span><span class="cx"> {
</span><del>-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;PacketCable Lawful Intercept disabled\n&quot;);
</del><ins>+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;PacketCable Lawful Intercept disabled\n&quot;);
</ins><span class="cx"> 
</span><span class="cx"> /* TODO DESTROY THE SOCKET HERE ! */
</span><span class="cx"> 
</span><del>-    return SWITCH_STATUS_SUCCESS;
</del><ins>+        return SWITCH_STATUS_SUCCESS;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="freeswitchtrunkcontribledrcmod_pclipclistructuremysql"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/contrib/ledr/c/mod_pcli/pcli.structure.mysql (0 => 15295)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/ledr/c/mod_pcli/pcli.structure.mysql                                (rev 0)
+++ freeswitch/trunk/contrib/ledr/c/mod_pcli/pcli.structure.mysql        2009-10-30 21:19:08 UTC (rev 15295)
</span><span class="lines">@@ -0,0 +1,52 @@
</span><ins>+CREATE TABLE IF NOT EXISTS `pcli` (
+  `ini_id` varchar(255) NOT NULL,
+  `count` int(11) NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+
+#### FUNCTIONS CAN'T SUPPORT TRANSACTIONS ?!
+DROP FUNCTION IF EXISTS test;
+delimiter $$
+CREATE FUNCTION test(i VARCHAR(255)) RETURNS INT
+BEGIN
+        declare c int;
+        SELECT `count` INTO c FROM `pcli` WHERE `ini_id` = i;
+        IF (c &gt;= 0) THEN
+                SET c = c + 1;
+                UPDATE `pcli` SET `count` = c WHERE `ini_id` = i;
+        ELSE
+                SET c = 0;
+                INSERT INTO `pcli` (`ini_id`, `count`) VALUES (i, c);
+        END IF;
+        return c;
+END $$
+delimiter ;
+
+
+
+DROP PROCEDURE IF EXISTS test;
+delimiter $$
+CREATE PROCEDURE test(i VARCHAR(255), OUT c INT)
+BEGIN
+        SELECT `count` INTO c FROM `pcli` WHERE `ini_id` = i;
+        IF (c &gt;= 0) THEN
+                SET c = c + 1;
+                UPDATE `pcli` SET `count` = c WHERE `ini_id` = i;
+        ELSE
+                SET c = 0;
+                INSERT INTO `pcli` (`ini_id`, `count`) VALUES (i, c);
+        END IF;
+END $$
+delimiter ;
+
+
+DROP FUNCTION IF EXISTS test;
+delimiter $$
+CREATE FUNCTION test(i VARCHAR(255)) RETURNS INT
+BEGIN
+        declare c int;
+        CALL test(i, @c);
+        SELECT (@c) into c;
+        return c;
+END $$
+delimiter $$
</ins></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>