<p>Joshua Colp has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16303">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_mysql: Remove deprecated module.<br><br>ASTERISK-29585<br><br>Change-Id: I262930d0387d043f2a3345e8a977b314528059bf<br>---<br>M addons/Makefile<br>D addons/app_mysql.c<br>A doc/UPGRADE-staging/app_mysql_removal.txt<br>3 files changed, 7 insertions(+), 671 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/03/16303/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/addons/Makefile b/addons/Makefile</span><br><span>index 866d34b..401f52c 100644</span><br><span>--- a/addons/Makefile</span><br><span>+++ b/addons/Makefile</span><br><span>@@ -28,8 +28,7 @@</span><br><span> </span><br><span> H323CFLAGS:=-Iooh323c/src -Iooh323c/src/h323</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-ALL_C_MODS:=app_mysql \</span><br><span style="color: hsl(0, 100%, 40%);">- cdr_mysql \</span><br><span style="color: hsl(120, 100%, 40%);">+ALL_C_MODS:=cdr_mysql \</span><br><span> chan_mobile \</span><br><span> chan_ooh323 \</span><br><span> format_mp3 \</span><br><span>diff --git a/addons/app_mysql.c b/addons/app_mysql.c</span><br><span>deleted file mode 100644</span><br><span>index 6e35a7c..0000000</span><br><span>--- a/addons/app_mysql.c</span><br><span>+++ /dev/null</span><br><span>@@ -1,669 +0,0 @@</span><br><span style="color: hsl(0, 100%, 40%);">-/*</span><br><span style="color: hsl(0, 100%, 40%);">- * Asterisk -- An open source telephony toolkit.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * Copyright (C) 2004, Constantine Filin and Christos Ricudis</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * Christos Ricudis <ricudis@itc.auth.gr></span><br><span style="color: hsl(0, 100%, 40%);">- * Constantine Filin <cf@intermedia.net></span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * See http://www.asterisk.org for more information about</span><br><span style="color: hsl(0, 100%, 40%);">- * the Asterisk project. Please do not directly contact</span><br><span style="color: hsl(0, 100%, 40%);">- * any of the maintainers of this project for assistance;</span><br><span style="color: hsl(0, 100%, 40%);">- * the project provides a web site, mailing lists and IRC</span><br><span style="color: hsl(0, 100%, 40%);">- * channels for your use.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is free software, distributed under the terms of</span><br><span style="color: hsl(0, 100%, 40%);">- * the GNU General Public License Version 2. See the LICENSE file</span><br><span style="color: hsl(0, 100%, 40%);">- * at the top of the source tree.</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*!</span><br><span style="color: hsl(0, 100%, 40%);">- * \file</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief MYSQL dialplan application</span><br><span style="color: hsl(0, 100%, 40%);">- * \ingroup applications</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*! \li \ref app_mysql.c uses the configuration file \ref app_mysql.conf</span><br><span style="color: hsl(0, 100%, 40%);">- * \addtogroup configuration_file Configuration Files</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*!</span><br><span style="color: hsl(0, 100%, 40%);">- * \page app_mysql.conf app_mysql.conf</span><br><span style="color: hsl(0, 100%, 40%);">- * \verbinclude app_mysql.conf.sample</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*** MODULEINFO</span><br><span style="color: hsl(0, 100%, 40%);">- <depend>mysqlclient</depend></span><br><span style="color: hsl(0, 100%, 40%);">- <defaultenabled>no</defaultenabled></span><br><span style="color: hsl(0, 100%, 40%);">- <support_level>deprecated</support_level></span><br><span style="color: hsl(0, 100%, 40%);">- <replacement>func_odbc</replacement></span><br><span style="color: hsl(0, 100%, 40%);">- <deprecated_in>1.8</deprecated_in></span><br><span style="color: hsl(0, 100%, 40%);">- <removed_in>19</removed_in></span><br><span style="color: hsl(0, 100%, 40%);">- ***/</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#include "asterisk.h"</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#include <mysql/mysql.h></span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#include "asterisk/file.h"</span><br><span style="color: hsl(0, 100%, 40%);">-#include "asterisk/logger.h"</span><br><span style="color: hsl(0, 100%, 40%);">-#include "asterisk/channel.h"</span><br><span style="color: hsl(0, 100%, 40%);">-#include "asterisk/pbx.h"</span><br><span style="color: hsl(0, 100%, 40%);">-#include "asterisk/module.h"</span><br><span style="color: hsl(0, 100%, 40%);">-#include "asterisk/linkedlists.h"</span><br><span style="color: hsl(0, 100%, 40%);">-#include "asterisk/chanvars.h"</span><br><span style="color: hsl(0, 100%, 40%);">-#include "asterisk/lock.h"</span><br><span style="color: hsl(0, 100%, 40%);">-#include "asterisk/options.h"</span><br><span style="color: hsl(0, 100%, 40%);">-#include "asterisk/app.h"</span><br><span style="color: hsl(0, 100%, 40%);">-#include "asterisk/config.h"</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#define EXTRA_LOG 0</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-enum { NULLSTRING, NULLVALUE, EMPTYSTRING } nullvalue = NULLSTRING;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static const char app[] = "MYSQL";</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static const char synopsis[] = "Do several mySQLy things";</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static const char descrip[] =</span><br><span style="color: hsl(0, 100%, 40%);">-"MYSQL(): Do several mySQLy things\n"</span><br><span style="color: hsl(0, 100%, 40%);">-"Syntax:\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" MYSQL(Set timeout <num>)\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" Set the connection timeout, in seconds.\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" MYSQL(Connect connid dhhost[:dbport] dbuser dbpass dbname [dbcharset])\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" Connects to a database. Arguments contain standard MySQL parameters\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" passed to function mysql_real_connect. Optional parameter dbcharset\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" defaults to 'latin1'. Connection identifer returned in ${connid}\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" MYSQL(Query resultid ${connid} query-string)\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" Executes standard MySQL query contained in query-string using established\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" connection identified by ${connid}. Result of query is stored in ${resultid}.\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" MYSQL(Nextresult resultid ${connid}\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" If last query returned more than one result set, it stores the next\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" result set in ${resultid}. It's useful with stored procedures\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" MYSQL(Fetch fetchid ${resultid} var1 var2 ... varN)\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" Fetches a single row from a result set contained in ${result_identifier}.\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" Assigns returned fields to ${var1} ... ${varn}. ${fetchid} is set TRUE\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" if additional rows exist in result set.\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" MYSQL(Clear ${resultid})\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" Frees memory and datastructures associated with result set.\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" MYSQL(Disconnect ${connid})\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" Disconnects from named connection to MySQL.\n"</span><br><span style="color: hsl(0, 100%, 40%);">-" On exit, always returns 0. Sets MYSQL_STATUS to 0 on success and -1 on error.\n";</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*</span><br><span style="color: hsl(0, 100%, 40%);">-EXAMPLES OF USE :</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-exten => s,2,MYSQL(Connect connid localhost asterisk mypass credit utf8)</span><br><span style="color: hsl(0, 100%, 40%);">-exten => s,3,MYSQL(Query resultid ${connid} SELECT username,credit FROM credit WHERE callerid=${CALLERIDNUM})</span><br><span style="color: hsl(0, 100%, 40%);">-exten => s,4,MYSQL(Fetch fetchid ${resultid} datavar1 datavar2)</span><br><span style="color: hsl(0, 100%, 40%);">-exten => s,5,GotoIf(${fetchid}?6:8)</span><br><span style="color: hsl(0, 100%, 40%);">-exten => s,6,Festival("User ${datavar1} currently has credit balance of ${datavar2} dollars.")</span><br><span style="color: hsl(0, 100%, 40%);">-exten => s,7,Goto(s,4)</span><br><span style="color: hsl(0, 100%, 40%);">-exten => s,8,MYSQL(Clear ${resultid})</span><br><span style="color: hsl(0, 100%, 40%);">-exten => s,9,MYSQL(Disconnect ${connid})</span><br><span style="color: hsl(0, 100%, 40%);">-*/</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-AST_MUTEX_DEFINE_STATIC(_mysql_mutex);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#define MYSQL_CONFIG "app_mysql.conf"</span><br><span style="color: hsl(0, 100%, 40%);">-#define MYSQL_CONFIG_OLD "mysql.conf"</span><br><span style="color: hsl(0, 100%, 40%);">-#define AST_MYSQL_ID_DUMMY 0</span><br><span style="color: hsl(0, 100%, 40%);">-#define AST_MYSQL_ID_CONNID 1</span><br><span style="color: hsl(0, 100%, 40%);">-#define AST_MYSQL_ID_RESID 2</span><br><span style="color: hsl(0, 100%, 40%);">-#define AST_MYSQL_ID_FETCHID 3</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int autoclear = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static void mysql_ds_destroy(void *data);</span><br><span style="color: hsl(0, 100%, 40%);">-static void mysql_ds_fixup(void *data, struct ast_channel *oldchan, struct ast_channel *newchan);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static const struct ast_datastore_info mysql_ds_info = {</span><br><span style="color: hsl(0, 100%, 40%);">- .type = "APP_ADDON_SQL_MYSQL",</span><br><span style="color: hsl(0, 100%, 40%);">- .destroy = mysql_ds_destroy,</span><br><span style="color: hsl(0, 100%, 40%);">- .chan_fixup = mysql_ds_fixup,</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-struct ast_MYSQL_id {</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_channel *owner;</span><br><span style="color: hsl(0, 100%, 40%);">- int identifier_type; /* 0=dummy, 1=connid, 2=resultid */</span><br><span style="color: hsl(0, 100%, 40%);">- int identifier;</span><br><span style="color: hsl(0, 100%, 40%);">- void *data;</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_ENTRY(ast_MYSQL_id) entries;</span><br><span style="color: hsl(0, 100%, 40%);">-} *ast_MYSQL_id;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-AST_LIST_HEAD(MYSQLidshead,ast_MYSQL_id) _mysql_ids_head;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static void mysql_ds_destroy(void *data)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- /* Destroy any IDs owned by the channel */</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_MYSQL_id *i;</span><br><span style="color: hsl(0, 100%, 40%);">- if (AST_LIST_LOCK(&_mysql_ids_head)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Unable to lock identifiers list\n");</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_TRAVERSE_SAFE_BEGIN(&_mysql_ids_head, i, entries) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (i->owner == data) {</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_REMOVE_CURRENT(entries);</span><br><span style="color: hsl(0, 100%, 40%);">- if (i->identifier_type == AST_MYSQL_ID_CONNID) {</span><br><span style="color: hsl(0, 100%, 40%);">- /* Drop connection */</span><br><span style="color: hsl(0, 100%, 40%);">- mysql_close(i->data);</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (i->identifier_type == AST_MYSQL_ID_RESID) {</span><br><span style="color: hsl(0, 100%, 40%);">- /* Drop result */</span><br><span style="color: hsl(0, 100%, 40%);">- mysql_free_result(i->data);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(i);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_TRAVERSE_SAFE_END</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_UNLOCK(&_mysql_ids_head);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static void mysql_ds_fixup(void *data, struct ast_channel *oldchan, struct ast_channel *newchan)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- /* Destroy any IDs owned by the channel */</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_MYSQL_id *i;</span><br><span style="color: hsl(0, 100%, 40%);">- if (AST_LIST_LOCK(&_mysql_ids_head)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Unable to lock identifiers list\n");</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_TRAVERSE_SAFE_BEGIN(&_mysql_ids_head, i, entries) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (i->owner == data) {</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_REMOVE_CURRENT(entries);</span><br><span style="color: hsl(0, 100%, 40%);">- if (i->identifier_type == AST_MYSQL_ID_CONNID) {</span><br><span style="color: hsl(0, 100%, 40%);">- /* Drop connection */</span><br><span style="color: hsl(0, 100%, 40%);">- mysql_close(i->data);</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (i->identifier_type == AST_MYSQL_ID_RESID) {</span><br><span style="color: hsl(0, 100%, 40%);">- /* Drop result */</span><br><span style="color: hsl(0, 100%, 40%);">- mysql_free_result(i->data);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(i);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_TRAVERSE_SAFE_END</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_UNLOCK(&_mysql_ids_head);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* helpful procs */</span><br><span style="color: hsl(0, 100%, 40%);">-static void *find_identifier(int identifier, int identifier_type)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- struct MYSQLidshead *headp = &_mysql_ids_head;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_MYSQL_id *i;</span><br><span style="color: hsl(0, 100%, 40%);">- void *res=NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- int found=0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (AST_LIST_LOCK(headp)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Unable to lock identifiers list\n");</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_TRAVERSE(headp, i, entries) {</span><br><span style="color: hsl(0, 100%, 40%);">- if ((i->identifier == identifier) && (i->identifier_type == identifier_type)) {</span><br><span style="color: hsl(0, 100%, 40%);">- found = 1;</span><br><span style="color: hsl(0, 100%, 40%);">- res = i->data;</span><br><span style="color: hsl(0, 100%, 40%);">- break;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- if (!found) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Identifier %d, identifier_type %d not found in identifier list\n", identifier, identifier_type);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_UNLOCK(headp);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return res;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int add_identifier(struct ast_channel *chan, int identifier_type, void *data)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_MYSQL_id *i = NULL, *j = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- struct MYSQLidshead *headp = &_mysql_ids_head;</span><br><span style="color: hsl(0, 100%, 40%);">- int maxidentifier = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (AST_LIST_LOCK(headp)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Unable to lock identifiers list\n");</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- i = ast_malloc(sizeof(*i));</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_TRAVERSE(headp, j, entries) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (j->identifier > maxidentifier) {</span><br><span style="color: hsl(0, 100%, 40%);">- maxidentifier = j->identifier;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- i->identifier = maxidentifier + 1;</span><br><span style="color: hsl(0, 100%, 40%);">- i->identifier_type = identifier_type;</span><br><span style="color: hsl(0, 100%, 40%);">- i->data = data;</span><br><span style="color: hsl(0, 100%, 40%);">- i->owner = chan;</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_INSERT_HEAD(headp, i, entries);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_UNLOCK(headp);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- return i->identifier;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int del_identifier(int identifier, int identifier_type)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_MYSQL_id *i;</span><br><span style="color: hsl(0, 100%, 40%);">- struct MYSQLidshead *headp = &_mysql_ids_head;</span><br><span style="color: hsl(0, 100%, 40%);">- int found = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (AST_LIST_LOCK(headp)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Unable to lock identifiers list\n");</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_TRAVERSE(headp, i, entries) {</span><br><span style="color: hsl(0, 100%, 40%);">- if ((i->identifier == identifier) &&</span><br><span style="color: hsl(0, 100%, 40%);">- (i->identifier_type == identifier_type)) {</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_REMOVE(headp, i, entries);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(i);</span><br><span style="color: hsl(0, 100%, 40%);">- found = 1;</span><br><span style="color: hsl(0, 100%, 40%);">- break;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_UNLOCK(headp);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (found == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Could not find identifier %d, identifier_type %d in list to delete\n", identifier, identifier_type);</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int set_asterisk_int(struct ast_channel *chan, char *varname, int id)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- if (id >= 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- char s[12] = "";</span><br><span style="color: hsl(0, 100%, 40%);">- snprintf(s, sizeof(s), "%d", id);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_debug(5, "MYSQL: setting var '%s' to value '%s'\n", varname, s);</span><br><span style="color: hsl(0, 100%, 40%);">- pbx_builtin_setvar_helper(chan, varname, s);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- return id;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int add_identifier_and_set_asterisk_int(struct ast_channel *chan, char *varname, int identifier_type, void *data)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- return set_asterisk_int(chan, varname, add_identifier(chan, identifier_type, data));</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int safe_scan_int(char **data, char *delim, int def)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- char *end;</span><br><span style="color: hsl(0, 100%, 40%);">- int res = def;</span><br><span style="color: hsl(0, 100%, 40%);">- char *s = strsep(data, delim);</span><br><span style="color: hsl(0, 100%, 40%);">- if (s) {</span><br><span style="color: hsl(0, 100%, 40%);">- res = strtol(s, &end, 10);</span><br><span style="color: hsl(0, 100%, 40%);">- if (*end)</span><br><span style="color: hsl(0, 100%, 40%);">- res = def; /* not an integer */</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- return res;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int aMYSQL_set(struct ast_channel *chan, const char *data)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- char *var, *tmp, *parse;</span><br><span style="color: hsl(0, 100%, 40%);">- AST_DECLARE_APP_ARGS(args,</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(set);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(variable);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(value);</span><br><span style="color: hsl(0, 100%, 40%);">- );</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- parse = ast_strdupa(data);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_NONSTANDARD_APP_ARGS(args, parse, ' ');</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (args.argc == 3) {</span><br><span style="color: hsl(0, 100%, 40%);">- var = ast_alloca(6 + strlen(args.variable) + 1);</span><br><span style="color: hsl(0, 100%, 40%);">- sprintf(var, "MYSQL_%s", args.variable);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- /* Make the parameter case-insensitive */</span><br><span style="color: hsl(0, 100%, 40%);">- for (tmp = var + 6; *tmp; tmp++)</span><br><span style="color: hsl(0, 100%, 40%);">- *tmp = toupper(*tmp);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- pbx_builtin_setvar_helper(chan, var, args.value);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* MYSQL operations */</span><br><span style="color: hsl(0, 100%, 40%);">-static int aMYSQL_connect(struct ast_channel *chan, const char *data)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- AST_DECLARE_APP_ARGS(args,</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(connect);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(connid);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(dbhost);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(dbuser);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(dbpass);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(dbname);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(dbcharset);</span><br><span style="color: hsl(0, 100%, 40%);">- );</span><br><span style="color: hsl(0, 100%, 40%);">- MYSQL *mysql;</span><br><span style="color: hsl(0, 100%, 40%);">- int timeout;</span><br><span style="color: hsl(0, 100%, 40%);">- const char *ctimeout;</span><br><span style="color: hsl(0, 100%, 40%);">- unsigned int port = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- char *port_str;</span><br><span style="color: hsl(0, 100%, 40%);">- char *parse = ast_strdupa(data);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- AST_NONSTANDARD_APP_ARGS(args, parse, ' ');</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (args.argc < 6) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "MYSQL_connect is missing some arguments\n");</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(mysql = mysql_init(NULL))) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "mysql_init returned NULL\n");</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- ctimeout = pbx_builtin_getvar_helper(chan, "MYSQL_TIMEOUT");</span><br><span style="color: hsl(0, 100%, 40%);">- if (ctimeout && sscanf(ctimeout, "%30d", &timeout) == 1) {</span><br><span style="color: hsl(0, 100%, 40%);">- mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (void *)&timeout);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- if(args.dbcharset && strlen(args.dbcharset) > 2){</span><br><span style="color: hsl(0, 100%, 40%);">- char set_names[255];</span><br><span style="color: hsl(0, 100%, 40%);">- char statement[512];</span><br><span style="color: hsl(0, 100%, 40%);">- snprintf(set_names, sizeof(set_names), "SET NAMES %s", args.dbcharset);</span><br><span style="color: hsl(0, 100%, 40%);">- mysql_real_escape_string(mysql, statement, set_names, sizeof(set_names));</span><br><span style="color: hsl(0, 100%, 40%);">- mysql_options(mysql, MYSQL_INIT_COMMAND, set_names);</span><br><span style="color: hsl(0, 100%, 40%);">- mysql_options(mysql, MYSQL_SET_CHARSET_NAME, args.dbcharset);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if ((port_str = strchr(args.dbhost, ':'))) {</span><br><span style="color: hsl(0, 100%, 40%);">- *port_str++ = '\0';</span><br><span style="color: hsl(0, 100%, 40%);">- if (sscanf(port_str, "%u", &port) != 1) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Invalid port: '%s'\n", port_str);</span><br><span style="color: hsl(0, 100%, 40%);">- port = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!mysql_real_connect(mysql, args.dbhost, args.dbuser, args.dbpass, args.dbname, port, NULL,</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef CLIENT_MULTI_STATEMENTS</span><br><span style="color: hsl(0, 100%, 40%);">- CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS</span><br><span style="color: hsl(0, 100%, 40%);">-#elif defined(CLIENT_MULTI_QUERIES)</span><br><span style="color: hsl(0, 100%, 40%);">- CLIENT_MULTI_QUERIES</span><br><span style="color: hsl(0, 100%, 40%);">-#else</span><br><span style="color: hsl(0, 100%, 40%);">- 0</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">- )) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "mysql_real_connect(mysql,%s,%s,dbpass,%s,...) failed(%d): %s\n",</span><br><span style="color: hsl(0, 100%, 40%);">- args.dbhost, args.dbuser, args.dbname, mysql_errno(mysql), mysql_error(mysql));</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- add_identifier_and_set_asterisk_int(chan, args.connid, AST_MYSQL_ID_CONNID, mysql);</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int aMYSQL_query(struct ast_channel *chan, const char *data)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- AST_DECLARE_APP_ARGS(args,</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(query);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(resultid);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(connid);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(sql);</span><br><span style="color: hsl(0, 100%, 40%);">- );</span><br><span style="color: hsl(0, 100%, 40%);">- MYSQL *mysql;</span><br><span style="color: hsl(0, 100%, 40%);">- MYSQL_RES *mysqlres;</span><br><span style="color: hsl(0, 100%, 40%);">- int connid;</span><br><span style="color: hsl(0, 100%, 40%);">- int mysql_query_res;</span><br><span style="color: hsl(0, 100%, 40%);">- char *parse = ast_strdupa(data);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- AST_NONSTANDARD_APP_ARGS(args, parse, ' ');</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (args.argc != 4 || (connid = atoi(args.connid)) == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "missing some arguments\n");</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(mysql = find_identifier(connid, AST_MYSQL_ID_CONNID))) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Invalid connection identifier %s passed in aMYSQL_query\n", args.connid);</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if ((mysql_query_res = mysql_query(mysql, args.sql)) != 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "aMYSQL_query: mysql_query failed. Error: %s\n", mysql_error(mysql));</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if ((mysqlres = mysql_store_result(mysql))) {</span><br><span style="color: hsl(0, 100%, 40%);">- add_identifier_and_set_asterisk_int(chan, args.resultid, AST_MYSQL_ID_RESID, mysqlres);</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (!mysql_field_count(mysql)) {</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">- } else</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "mysql_store_result() failed on query %s\n", args.sql);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int aMYSQL_nextresult(struct ast_channel *chan, const char *data)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- MYSQL *mysql;</span><br><span style="color: hsl(0, 100%, 40%);">- MYSQL_RES *mysqlres;</span><br><span style="color: hsl(0, 100%, 40%);">- AST_DECLARE_APP_ARGS(args,</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(nextresult);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(resultid);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(connid);</span><br><span style="color: hsl(0, 100%, 40%);">- );</span><br><span style="color: hsl(0, 100%, 40%);">- int connid = -1;</span><br><span style="color: hsl(0, 100%, 40%);">- char *parse = ast_strdupa(data);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- AST_NONSTANDARD_APP_ARGS(args, parse, ' ');</span><br><span style="color: hsl(0, 100%, 40%);">- sscanf(args.connid, "%30d", &connid);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (args.argc != 3 || connid <= 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "missing some arguments\n");</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(mysql = find_identifier(connid, AST_MYSQL_ID_CONNID))) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Invalid connection identifier %d passed in aMYSQL_query\n", connid);</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (mysql_more_results(mysql)) {</span><br><span style="color: hsl(0, 100%, 40%);">- mysql_next_result(mysql);</span><br><span style="color: hsl(0, 100%, 40%);">- if ((mysqlres = mysql_store_result(mysql))) {</span><br><span style="color: hsl(0, 100%, 40%);">- add_identifier_and_set_asterisk_int(chan, args.resultid, AST_MYSQL_ID_RESID, mysqlres);</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (!mysql_field_count(mysql)) {</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">- } else</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "mysql_store_result() failed on storing next_result\n");</span><br><span style="color: hsl(0, 100%, 40%);">- } else</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "mysql_more_results() result set has no more results\n");</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int aMYSQL_fetch(struct ast_channel *chan, const char *data)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- MYSQL_RES *mysqlres;</span><br><span style="color: hsl(0, 100%, 40%);">- MYSQL_ROW mysqlrow;</span><br><span style="color: hsl(0, 100%, 40%);">- AST_DECLARE_APP_ARGS(args,</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(fetch);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(resultvar);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(fetchid);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_APP_ARG(vars);</span><br><span style="color: hsl(0, 100%, 40%);">- );</span><br><span style="color: hsl(0, 100%, 40%);">- char *s5, *parse;</span><br><span style="color: hsl(0, 100%, 40%);">- int resultid = -1, numFields, j;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- parse = ast_strdupa(data);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_NONSTANDARD_APP_ARGS(args, parse, ' ');</span><br><span style="color: hsl(0, 100%, 40%);">- sscanf(args.fetchid, "%30d", &resultid);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (args.resultvar && (resultid >= 0) ) {</span><br><span style="color: hsl(0, 100%, 40%);">- if ((mysqlres = find_identifier(resultid, AST_MYSQL_ID_RESID)) != NULL) {</span><br><span style="color: hsl(0, 100%, 40%);">- /* Grab the next row */</span><br><span style="color: hsl(0, 100%, 40%);">- if ((mysqlrow = mysql_fetch_row(mysqlres)) != NULL) {</span><br><span style="color: hsl(0, 100%, 40%);">- numFields = mysql_num_fields(mysqlres);</span><br><span style="color: hsl(0, 100%, 40%);">- for (j = 0; j < numFields; j++) {</span><br><span style="color: hsl(0, 100%, 40%);">- s5 = strsep(&args.vars, " ");</span><br><span style="color: hsl(0, 100%, 40%);">- if (s5 == NULL) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "ast_MYSQL_fetch: More fields (%d) than variables (%d)\n", numFields, j);</span><br><span style="color: hsl(0, 100%, 40%);">- break;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- pbx_builtin_setvar_helper(chan, s5, mysqlrow[j] ? mysqlrow[j] :</span><br><span style="color: hsl(0, 100%, 40%);">- nullvalue == NULLSTRING ? "NULL" :</span><br><span style="color: hsl(0, 100%, 40%);">- nullvalue == EMPTYSTRING ? "" :</span><br><span style="color: hsl(0, 100%, 40%);">- NULL);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- ast_debug(5, "ast_MYSQL_fetch: numFields=%d\n", numFields);</span><br><span style="color: hsl(0, 100%, 40%);">- set_asterisk_int(chan, args.resultvar, 1); /* try more rows */</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_debug(5, "ast_MYSQL_fetch : EOF\n");</span><br><span style="color: hsl(0, 100%, 40%);">- set_asterisk_int(chan, args.resultvar, 0); /* no more rows */</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- set_asterisk_int(chan, args.resultvar, 0);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "aMYSQL_fetch: Invalid result identifier %d passed\n", resultid);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "aMYSQL_fetch: missing some arguments\n");</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int aMYSQL_clear(struct ast_channel *chan, const char *data)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- MYSQL_RES *mysqlres;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- int id;</span><br><span style="color: hsl(0, 100%, 40%);">- char *parse = ast_strdupa(data);</span><br><span style="color: hsl(0, 100%, 40%);">- strsep(&parse, " "); /* eat the first token, we already know it :P */</span><br><span style="color: hsl(0, 100%, 40%);">- id = safe_scan_int(&parse, " \n", -1);</span><br><span style="color: hsl(0, 100%, 40%);">- if ((mysqlres = find_identifier(id, AST_MYSQL_ID_RESID)) == NULL) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Invalid result identifier %d passed in aMYSQL_clear\n", id);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- mysql_free_result(mysqlres);</span><br><span style="color: hsl(0, 100%, 40%);">- del_identifier(id, AST_MYSQL_ID_RESID);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int aMYSQL_disconnect(struct ast_channel *chan, const char *data)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- MYSQL *mysql;</span><br><span style="color: hsl(0, 100%, 40%);">- int id;</span><br><span style="color: hsl(0, 100%, 40%);">- char *parse = ast_strdupa(data);</span><br><span style="color: hsl(0, 100%, 40%);">- strsep(&parse, " "); /* eat the first token, we already know it :P */</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- id = safe_scan_int(&parse, " \n", -1);</span><br><span style="color: hsl(0, 100%, 40%);">- if ((mysql = find_identifier(id, AST_MYSQL_ID_CONNID)) == NULL) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Invalid connection identifier %d passed in aMYSQL_disconnect\n", id);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- mysql_close(mysql);</span><br><span style="color: hsl(0, 100%, 40%);">- del_identifier(id, AST_MYSQL_ID_CONNID);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int MYSQL_exec(struct ast_channel *chan, const char *data)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- int result;</span><br><span style="color: hsl(0, 100%, 40%);">- char sresult[10];</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- ast_debug(5, "MYSQL: data=%s\n", data);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!data) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "MYSQL requires an argument (see manual)\n");</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- result = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (autoclear) {</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_datastore *mysql_store = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- ast_channel_lock(chan);</span><br><span style="color: hsl(0, 100%, 40%);">- mysql_store = ast_channel_datastore_find(chan, &mysql_ds_info, NULL);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!mysql_store) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(mysql_store = ast_datastore_alloc(&mysql_ds_info, NULL))) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Unable to allocate new datastore.\n");</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- mysql_store->data = chan;</span><br><span style="color: hsl(0, 100%, 40%);">- ast_channel_datastore_add(chan, mysql_store);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- ast_channel_unlock(chan);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- ast_mutex_lock(&_mysql_mutex);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (strncasecmp("connect", data, strlen("connect")) == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- result = aMYSQL_connect(chan, data);</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (strncasecmp("query", data, strlen("query")) == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- result = aMYSQL_query(chan, data);</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (strncasecmp("nextresult", data, strlen("nextresult")) == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- result = aMYSQL_nextresult(chan, data);</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (strncasecmp("fetch", data, strlen("fetch")) == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- result = aMYSQL_fetch(chan, data);</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (strncasecmp("clear", data, strlen("clear")) == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- result = aMYSQL_clear(chan, data);</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (strncasecmp("disconnect", data, strlen("disconnect")) == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- result = aMYSQL_disconnect(chan, data);</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (strncasecmp("set", data, 3) == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- result = aMYSQL_set(chan, data);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Unknown argument to MYSQL application : %s\n", data);</span><br><span style="color: hsl(0, 100%, 40%);">- result = -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- ast_mutex_unlock(&_mysql_mutex);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- snprintf(sresult, sizeof(sresult), "%d", result);</span><br><span style="color: hsl(0, 100%, 40%);">- pbx_builtin_setvar_helper(chan, "MYSQL_STATUS", sresult);</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int unload_module(void)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- return ast_unregister_application(app);</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*!</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief Load the module</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * Module loading including tests for configuration or dependencies.</span><br><span style="color: hsl(0, 100%, 40%);">- * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,</span><br><span style="color: hsl(0, 100%, 40%);">- * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails</span><br><span style="color: hsl(0, 100%, 40%);">- * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the</span><br><span style="color: hsl(0, 100%, 40%);">- * configuration file or other non-critical problem return</span><br><span style="color: hsl(0, 100%, 40%);">- * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-static int load_module(void)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- struct MYSQLidshead *headp = &_mysql_ids_head;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_flags config_flags = { 0 };</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_config *cfg = ast_config_load(MYSQL_CONFIG, config_flags);</span><br><span style="color: hsl(0, 100%, 40%);">- const char *temp;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!cfg) {</span><br><span style="color: hsl(0, 100%, 40%);">- /* Backwards compatibility ftw */</span><br><span style="color: hsl(0, 100%, 40%);">- cfg = ast_config_load(MYSQL_CONFIG_OLD, config_flags);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (cfg) {</span><br><span style="color: hsl(0, 100%, 40%);">- if ((temp = ast_variable_retrieve(cfg, "general", "nullvalue"))) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!strcasecmp(temp, "nullstring")) {</span><br><span style="color: hsl(0, 100%, 40%);">- nullvalue = NULLSTRING;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (!strcasecmp(temp, "emptystring")) {</span><br><span style="color: hsl(0, 100%, 40%);">- nullvalue = EMPTYSTRING;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (!strcasecmp(temp, "null")) {</span><br><span style="color: hsl(0, 100%, 40%);">- nullvalue = NULLVALUE;</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Illegal value for 'nullvalue': '%s' (must be 'nullstring', 'null', or 'emptystring')\n", temp);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- if ((temp = ast_variable_retrieve(cfg, "general", "autoclear")) && ast_true(temp)) {</span><br><span style="color: hsl(0, 100%, 40%);">- autoclear = 1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- ast_config_destroy(cfg);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- AST_LIST_HEAD_INIT(headp);</span><br><span style="color: hsl(0, 100%, 40%);">- return ast_register_application(app, MYSQL_exec, synopsis, descrip);</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-AST_MODULE_INFO_STANDARD_DEPRECATED(ASTERISK_GPL_KEY, "Simple Mysql Interface");</span><br><span>diff --git a/doc/UPGRADE-staging/app_mysql_removal.txt b/doc/UPGRADE-staging/app_mysql_removal.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..7af75fa</span><br><span>--- /dev/null</span><br><span>+++ b/doc/UPGRADE-staging/app_mysql_removal.txt</span><br><span>@@ -0,0 +1,6 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: app_mysql</span><br><span style="color: hsl(120, 100%, 40%);">+Master-Only: True</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+This module was deprecated in Asterisk 1.8</span><br><span style="color: hsl(120, 100%, 40%);">+and is now being removed in accordance with</span><br><span style="color: hsl(120, 100%, 40%);">+the Asterisk Module Deprecation policy.</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16303">change 16303</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/16303"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I262930d0387d043f2a3345e8a977b314528059bf </div>
<div style="display:none"> Gerrit-Change-Number: 16303 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>