提交 05b1ac74 authored 作者: Leon de Rooij's avatar Leon de Rooij

trying to get ini_id's autoincremented count in mysql transaction

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/contrib@15295 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 86328bea
...@@ -79,7 +79,7 @@ static switch_xml_config_item_t instructions[] = { ...@@ -79,7 +79,7 @@ static switch_xml_config_item_t instructions[] = {
"localhost", &config_opt_valid_addr, NULL, NULL), "localhost", &config_opt_valid_addr, NULL, NULL),
SWITCH_CONFIG_ITEM("remote_port", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &pcli_globals.remote_port, SWITCH_CONFIG_ITEM("remote_port", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &pcli_globals.remote_port,
(void*)10741, &config_opt_valid_port, NULL, NULL), (void*)10741, &config_opt_valid_port, NULL, NULL),
SWITCH_CONFIG_ITEM_END() SWITCH_CONFIG_ITEM_END()
}; };
/* called at startup and reload of the module */ /* called at startup and reload of the module */
...@@ -160,7 +160,7 @@ static switch_status_t do_config(switch_bool_t reload) ...@@ -160,7 +160,7 @@ static switch_status_t do_config(switch_bool_t reload)
/* called when SWITCH_EVENT_RELOADXML is sent to this module */ /* called when SWITCH_EVENT_RELOADXML is sent to this module */
static void reload_event_handler(switch_event_t *event) static void reload_event_handler(switch_event_t *event)
{ {
do_config(SWITCH_TRUE); do_config(SWITCH_TRUE);
} }
/* generate a PacketCable Lawful Intercept header, that can be prepended to an RTP packet */ /* generate a PacketCable Lawful Intercept header, that can be prepended to an RTP packet */
...@@ -170,7 +170,7 @@ static switch_status_t gen_pcli_header(uint32_t *pcli_header, pcli_media_directi ...@@ -170,7 +170,7 @@ static switch_status_t gen_pcli_header(uint32_t *pcli_header, pcli_media_directi
/* some sanity checks */ /* some sanity checks */
if (media_direction > 3) { if (media_direction > 3) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Invalid media direction, may only be 0-3\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Invalid media direction, may only be 0-3\n");
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
...@@ -190,7 +190,7 @@ static switch_status_t gen_pcli_header(uint32_t *pcli_header, pcli_media_directi ...@@ -190,7 +190,7 @@ static switch_status_t gen_pcli_header(uint32_t *pcli_header, pcli_media_directi
*pcli_header |= (media_direction); *pcli_header |= (media_direction);
*pcli_header |= (call_id << 2); *pcli_header |= (call_id << 2);
*pcli_header |= (switch_id << 12); *pcli_header |= (switch_id << 12);
*pcli_header |= (ini_id << 16); *pcli_header |= (ini_id << 16);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -251,102 +251,102 @@ static switch_event_node_t *NODE = NULL; ...@@ -251,102 +251,102 @@ static switch_event_node_t *NODE = NULL;
SWITCH_STANDARD_APP(pcli_start_function) SWITCH_STANDARD_APP(pcli_start_function)
{ {
switch_media_bug_t *bug; switch_media_bug_t *bug;
switch_status_t status; switch_status_t status;
switch_channel_t *channel; switch_channel_t *channel;
pcli_session_helper_t *pcli_session_helper; pcli_session_helper_t *pcli_session_helper;
const char *p; const char *p;
if (session == NULL) if (session == NULL)
return; return;
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
/* Is this channel already set? */ /* Is this channel already set? */
bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_pcli_"); bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_pcli_");
/* If yes */ /* If yes */
if (bug != NULL) { if (bug != NULL) {
/* If we have a stop remove audio bug */ /* If we have a stop remove audio bug */
if (strcasecmp(data, "stop") == 0) { if (strcasecmp(data, "stop") == 0) {
switch_channel_set_private(channel, "_pcli_", NULL); switch_channel_set_private(channel, "_pcli_", NULL);
switch_core_media_bug_remove(session, &bug); switch_core_media_bug_remove(session, &bug);
return;
}
/* We have already started */
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
return;
}
/* create a new pcli_session_helper */
pcli_session_helper = (pcli_session_helper_t *) switch_core_session_alloc(session, sizeof(pcli_session_helper_t));
/* make session available from pcli_session_helper */
pcli_session_helper->session = session;
/* get LI_ID and store in pcli_session_helper */
if ((p = switch_channel_get_variable(channel, "LI_ID")) && switch_true(p)) {
pcli_session_helper->ini_id = switch_core_session_strdup(session, p);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No LI_ID was set!\n");
return; return;
} }
/* add the bug */ /* We have already started */
//status = switch_core_media_bug_add(session, pcli_callback, pcli_session_helper, 0, SMBF_BOTH, &bug); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
//status = switch_core_media_bug_add(session, pcli_callback, pcli_session_helper, 0, SMBF_READ_STREAM | SMBF_WRITE_STREAM, &bug);
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_REPLACE, &bug);
if (status != SWITCH_STATUS_SUCCESS) { return;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failure hooking to stream\n"); }
return;
} /* create a new pcli_session_helper */
pcli_session_helper = (pcli_session_helper_t *) switch_core_session_alloc(session, sizeof(pcli_session_helper_t));
/* make session available from pcli_session_helper */
pcli_session_helper->session = session;
/* get LI_ID and store in pcli_session_helper */
if ((p = switch_channel_get_variable(channel, "LI_ID")) && switch_true(p)) {
pcli_session_helper->ini_id = switch_core_session_strdup(session, p);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No LI_ID was set!\n");
return;
}
/* add the bug */
//status = switch_core_media_bug_add(session, pcli_callback, pcli_session_helper, 0, SMBF_BOTH, &bug);
//status = switch_core_media_bug_add(session, pcli_callback, pcli_session_helper, 0, SMBF_READ_STREAM | SMBF_WRITE_STREAM, &bug);
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_REPLACE, &bug);
switch_channel_set_private(channel, "_pcli_", bug); if (status != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failure hooking to stream\n");
return;
}
switch_channel_set_private(channel, "_pcli_", bug);
} }
SWITCH_MODULE_LOAD_FUNCTION(mod_pcli_load) SWITCH_MODULE_LOAD_FUNCTION(mod_pcli_load)
{ {
switch_application_interface_t *app_interface; switch_application_interface_t *app_interface;
/* initialize pcli_globals struct */ /* initialize pcli_globals struct */
memset(&pcli_globals, 0, sizeof(pcli_globals)); memset(&pcli_globals, 0, sizeof(pcli_globals));
/* make the pool available from pcli_globals */ /* make the pool available from pcli_globals */
pcli_globals.pool = pool; pcli_globals.pool = pool;
/* do config */ /* do config */
do_config(SWITCH_FALSE); do_config(SWITCH_FALSE);
/* connect my internal structure to the blank pointer passed to me */ /* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname); *module_interface = switch_loadable_module_create_module_interface(pool, modname);
/* make the pcli application available to the system */ /* make the pcli application available to the system */
SWITCH_ADD_APP(app_interface, "pcli", "PacketCable Lawful Intercept", "PacketCable Lawful Intercept", pcli_start_function, "<start>", SAF_NONE); SWITCH_ADD_APP(app_interface, "pcli", "PacketCable Lawful Intercept", "PacketCable Lawful Intercept", pcli_start_function, "<start>", SAF_NONE);
/* subscribe to reloadxml event, and hook it to reload_event_handler */ /* 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, &NODE) != SWITCH_STATUS_SUCCESS)) { if ((switch_event_bind_removable(modname, SWITCH_EVENT_RELOADXML, NULL, reload_event_handler, NULL, &NODE) != SWITCH_STATUS_SUCCESS)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind event!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind event!\n");
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;
} }
/* say it */ /* say it */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Lawful Intercept enabled\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Lawful Intercept enabled\n");
/* indicate that the module should continue to be loaded */ /* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_pcli_shutdown) SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_pcli_shutdown)
{ {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "PacketCable Lawful Intercept disabled\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "PacketCable Lawful Intercept disabled\n");
/* TODO DESTROY THE SOCKET HERE ! */ /* TODO DESTROY THE SOCKET HERE ! */
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
......
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 >= 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 >= 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 $$
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论