[asterisk-commits] tilghman: branch tilghman/adaptive_realtime r115575 - in /team/tilghman/adapt...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu May 8 22:10:08 CDT 2008
Author: tilghman
Date: Thu May 8 22:10:08 2008
New Revision: 115575
URL: http://svn.digium.com/view/asterisk?view=rev&rev=115575
Log:
Add checks to existing realtime updates
Modified:
team/tilghman/adaptive_realtime/apps/app_meetme.c
team/tilghman/adaptive_realtime/apps/app_queue.c
team/tilghman/adaptive_realtime/apps/app_voicemail.c
team/tilghman/adaptive_realtime/channels/chan_iax2.c
team/tilghman/adaptive_realtime/channels/chan_sip.c
team/tilghman/adaptive_realtime/include/asterisk/config.h
team/tilghman/adaptive_realtime/include/asterisk/res_odbc.h
team/tilghman/adaptive_realtime/res/res_config_odbc.c
Modified: team/tilghman/adaptive_realtime/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/apps/app_meetme.c?view=diff&rev=115575&r1=115574&r2=115575
==============================================================================
--- team/tilghman/adaptive_realtime/apps/app_meetme.c (original)
+++ team/tilghman/adaptive_realtime/apps/app_meetme.c Thu May 8 22:10:08 2008
@@ -1743,6 +1743,7 @@
if (rt_log_members) {
/* Update table */
snprintf(members, sizeof(members), "%d", conf->users);
+ ast_realtime_require_field("meetme", "confno", RQ_INTEGER, strlen(conf->confno), "members", RQ_INTEGER, strlen(members), NULL);
ast_update_realtime("meetme", "confno", conf->confno, "members", members, NULL);
}
setusercount = 1;
@@ -2682,6 +2683,7 @@
if (rt_log_members) {
/* Update table */
snprintf(members, sizeof(members), "%d", conf->users);
+ ast_realtime_require_field("meetme", "confno", RQ_INTEGER, strlen(conf->confno), "members", RQ_INTEGER, strlen(members), NULL);
ast_update_realtime("meetme", "confno", conf->confno, "members", members, NULL);
}
if (confflags & CONFFLAG_MARKEDUSER)
@@ -5707,6 +5709,7 @@
res |= ast_devstate_prov_add("SLA", sla_state);
res |= ast_custom_function_register(&meetme_info_acf);
+ ast_realtime_require_field("meetme", "confno", RQ_INTEGER, 3, "members", RQ_INTEGER, 3, NULL);
return res;
}
Modified: team/tilghman/adaptive_realtime/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/apps/app_queue.c?view=diff&rev=115575&r1=115574&r2=115575
==============================================================================
--- team/tilghman/adaptive_realtime/apps/app_queue.c (original)
+++ team/tilghman/adaptive_realtime/apps/app_queue.c Thu May 8 22:10:08 2008
@@ -6284,6 +6284,7 @@
if (!(device_state_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE, device_state_cb, NULL, AST_EVENT_IE_END)))
res = -1;
+ ast_realtime_require_field("queue_members", "paused", RQ_INTEGER, 1, "uniqueid", RQ_INTEGER, 5, NULL);
return res ? AST_MODULE_LOAD_DECLINE : 0;
}
Modified: team/tilghman/adaptive_realtime/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/apps/app_voicemail.c?view=diff&rev=115575&r1=115574&r2=115575
==============================================================================
--- team/tilghman/adaptive_realtime/apps/app_voicemail.c (original)
+++ team/tilghman/adaptive_realtime/apps/app_voicemail.c Thu May 8 22:10:08 2008
@@ -836,6 +836,9 @@
{
int res;
if (!ast_strlen_zero(vmu->uniqueid)) {
+ if (strlen(password) > 10) {
+ ast_realtime_require_field("voicemail", "password", RQ_CHAR, strlen(password), NULL);
+ }
res = ast_update_realtime("voicemail", "uniqueid", vmu->uniqueid, "password", password, NULL);
if (res > 0) {
ast_copy_string(vmu->password, password, sizeof(vmu->password));
@@ -9670,6 +9673,8 @@
ast_cli_register_multiple(cli_voicemail, sizeof(cli_voicemail) / sizeof(struct ast_cli_entry));
ast_install_vm_functions(has_voicemail, inboxcount, messagecount, sayname);
+ ast_realtime_require_field("voicemail", "uniqueid", RQ_INTEGER, 11, "password", RQ_CHAR, 10, NULL);
+ ast_realtime_require_field("voicemail_data", "filename", RQ_CHAR, 30, "duration", RQ_INTEGER, 5, NULL);
return res;
}
Modified: team/tilghman/adaptive_realtime/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/channels/chan_iax2.c?view=diff&rev=115575&r1=115574&r2=115575
==============================================================================
--- team/tilghman/adaptive_realtime/channels/chan_iax2.c (original)
+++ team/tilghman/adaptive_realtime/channels/chan_iax2.c Thu May 8 22:10:08 2008
@@ -12027,6 +12027,8 @@
reload_firmware(0);
iax_provision_reload(0);
+ ast_realtime_require_field("iaxpeers", "name", RQ_CHAR, 10, "ipaddr", RQ_CHAR, 15, "port", RQ_INTEGER, 5, "regseconds", RQ_INTEGER, 6, NULL);
+
return AST_MODULE_LOAD_SUCCESS;
}
Modified: team/tilghman/adaptive_realtime/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/channels/chan_sip.c?view=diff&rev=115575&r1=115574&r2=115575
==============================================================================
--- team/tilghman/adaptive_realtime/channels/chan_sip.c (original)
+++ team/tilghman/adaptive_realtime/channels/chan_sip.c Thu May 8 22:10:08 2008
@@ -22641,6 +22641,16 @@
/* And start the monitor for the first time */
restart_monitor();
+ ast_realtime_require_field(ast_check_realtime("sipregs") ? "sipregs" : "sippeers",
+ "name", RQ_CHAR, 10,
+ "ipaddr", RQ_CHAR, 15,
+ "port", RQ_INTEGER, 5,
+ "regseconds", RQ_INTEGER, 5,
+ "defaultuser", RQ_CHAR, 10,
+ "fullcontact", RQ_CHAR, 20,
+ "regserver", RQ_CHAR, 20,
+ NULL);
+
return AST_MODULE_LOAD_SUCCESS;
}
Modified: team/tilghman/adaptive_realtime/include/asterisk/config.h
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/include/asterisk/config.h?view=diff&rev=115575&r1=115574&r2=115575
==============================================================================
--- team/tilghman/adaptive_realtime/include/asterisk/config.h (original)
+++ team/tilghman/adaptive_realtime/include/asterisk/config.h Thu May 8 22:10:08 2008
@@ -45,6 +45,17 @@
};
#define CONFIG_STATUS_FILEUNCHANGED (void *)-1
+
+/*!
+ * \brief Types used in ast_realtime_require_field
+ */
+typedef enum {
+ RQ_INTEGER,
+ RQ_CHAR,
+ RQ_FLOAT,
+ RQ_DATE,
+ RQ_DATETIME,
+} require_type;
/*! \brief Structure for variables, used for configurations and for channel variables
*/
Modified: team/tilghman/adaptive_realtime/include/asterisk/res_odbc.h
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/include/asterisk/res_odbc.h?view=diff&rev=115575&r1=115574&r2=115575
==============================================================================
--- team/tilghman/adaptive_realtime/include/asterisk/res_odbc.h (original)
+++ team/tilghman/adaptive_realtime/include/asterisk/res_odbc.h Thu May 8 22:10:08 2008
@@ -33,14 +33,6 @@
#include "asterisk/linkedlists.h"
typedef enum { ODBC_SUCCESS=0, ODBC_FAIL=-1} odbc_status;
-
-typedef enum {
- RQ_INTEGER,
- RQ_CHAR,
- RQ_FLOAT,
- RQ_DATE,
- RQ_DATETIME,
-} require_type;
/*! \brief ODBC container */
struct odbc_obj {
Modified: team/tilghman/adaptive_realtime/res/res_config_odbc.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/res/res_config_odbc.c?view=diff&rev=115575&r1=115574&r2=115575
==============================================================================
--- team/tilghman/adaptive_realtime/res/res_config_odbc.c (original)
+++ team/tilghman/adaptive_realtime/res/res_config_odbc.c Thu May 8 22:10:08 2008
@@ -51,6 +51,7 @@
const char *sql;
const char *extra;
va_list ap;
+ unsigned long long skip;
};
/*!\brief The structures referenced are in include/asterisk/res_odbc.h */
@@ -66,6 +67,8 @@
AST_RWLIST_HEAD_DESTROY(&table->columns);
ast_free(table);
}
+
+#define release_table(ptr) if (ptr) { AST_RWLIST_UNLOCK(&(ptr)->columns); }
/*!
* \brief Find or create an entry describing the table specified.
@@ -186,9 +189,20 @@
return tableptr;
}
+static struct odbc_cache_columns *find_column(struct odbc_cache_tables *table, const char *colname)
+{
+ struct odbc_cache_columns *col;
+ AST_RWLIST_TRAVERSE(&table->columns, col, list) {
+ if (strcasecmp(col->name, colname) == 0) {
+ return col;
+ }
+ }
+ return NULL;
+}
+
static SQLHSTMT custom_prepare(struct odbc_obj *obj, void *data)
{
- int res, x = 1;
+ int res, x = 1, count = 0;
struct custom_prepare_struct *cps = data;
const char *newparam, *newval;
SQLHSTMT stmt;
@@ -211,6 +225,9 @@
while ((newparam = va_arg(ap, const char *))) {
newval = va_arg(ap, const char *);
+ if ((1 << count) & cps->skip) {
+ continue;
+ }
SQLBindParameter(stmt, x++, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(newval), 0, (void *)newval, 0, NULL);
}
va_end(ap);
@@ -531,33 +548,51 @@
char sql[256];
SQLLEN rowcount=0;
const char *newparam, *newval;
- int res;
+ int res, count = 0;
va_list aq;
struct custom_prepare_struct cps = { .sql = sql, .extra = lookup };
+ struct odbc_cache_tables *tableptr = find_table(database, table);
+ struct odbc_cache_columns *column;
va_copy(cps.ap, ap);
va_copy(aq, ap);
- if (!table)
- return -1;
+ if (!table) {
+ release_table(tableptr);
+ return -1;
+ }
obj = ast_odbc_request_obj(database, 0);
- if (!obj)
- return -1;
+ if (!obj) {
+ release_table(tableptr);
+ return -1;
+ }
newparam = va_arg(aq, const char *);
if (!newparam) {
ast_odbc_release_obj(obj);
+ release_table(tableptr);
return -1;
}
newval = va_arg(aq, const char *);
+
+ if (tableptr && !(column = find_column(tableptr, newparam))) {
+ ast_log(LOG_WARNING, "Key field '%s' does not exist in table '%s@%s'. Update will fail\n", newparam, table, database);
+ }
+
snprintf(sql, sizeof(sql), "UPDATE %s SET %s=?", table, newparam);
while((newparam = va_arg(aq, const char *))) {
- snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), ", %s=?", newparam);
- newval = va_arg(aq, const char *);
+ if ((tableptr && (column = find_column(tableptr, newparam))) || count > 63) {
+ snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), ", %s=?", newparam);
+ newval = va_arg(aq, const char *);
+ } else { /* the column does not exist in the table OR we've exceeded the space in our flag field */
+ cps.skip |= (((long long)1) << count);
+ }
+ count++;
}
va_end(aq);
snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " WHERE %s=?", keyfield);
+ release_table(tableptr);
stmt = ast_odbc_prepare_and_execute(obj, custom_prepare, &cps);
@@ -859,7 +894,7 @@
while ((elm = va_arg(ap, char *))) {
type = va_arg(ap, int);
size = va_arg(ap, require_type);
- /* TODO Check if the field matches the criteria */
+ /* Check if the field matches the criteria */
AST_RWLIST_TRAVERSE(&tableptr->columns, col, list) {
if (strcmp(col->name, elm) == 0) {
/* Type check, first. Some fields are more particular than others */
@@ -916,6 +951,7 @@
}
}
va_end(ap);
+ AST_RWLIST_UNLOCK(&tableptr->columns);
return 0;
}
@@ -944,7 +980,22 @@
return 0;
}
+static int reload_module(void)
+{
+ struct odbc_cache_tables *table;
+
+ /* Empty the cache; it will get rebuilt the next time the tables are needed. */
+ AST_RWLIST_WRLOCK(&odbc_tables);
+ while ((table = AST_RWLIST_REMOVE_HEAD(&odbc_tables, list))) {
+ destroy_table_cache(table);
+ }
+ AST_RWLIST_UNLOCK(&odbc_tables);
+
+ return 0;
+}
+
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Realtime ODBC configuration",
.load = load_module,
.unload = unload_module,
+ .reload = reload_module,
);
More information about the asterisk-commits
mailing list