[asterisk-commits] tilghman: branch tilghman/realtime_update2 r148569 - /team/tilghman/realtime_...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Oct 13 18:21:04 CDT 2008
Author: tilghman
Date: Mon Oct 13 18:21:04 2008
New Revision: 148569
URL: http://svn.digium.com/view/asterisk?view=rev&rev=148569
Log:
Amazing what errors we find when we test drivers
Modified:
team/tilghman/realtime_update2/res/res_config_sqlite.c
team/tilghman/realtime_update2/res/res_realtime.c
Modified: team/tilghman/realtime_update2/res/res_config_sqlite.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/realtime_update2/res/res_config_sqlite.c?view=diff&rev=148569&r1=148568&r2=148569
==============================================================================
--- team/tilghman/realtime_update2/res/res_config_sqlite.c (original)
+++ team/tilghman/realtime_update2/res/res_config_sqlite.c Mon Oct 13 18:21:04 2008
@@ -302,7 +302,7 @@
* \retval 0 if an error occurred.
*/
static size_t get_params(va_list ap, const char ***params_ptr,
- const char ***vals_ptr);
+ const char ***vals_ptr, int warn);
/*!
* \brief SQLite callback function for RealTime configuration.
@@ -955,7 +955,7 @@
return cfg;
}
-static size_t get_params(va_list ap, const char ***params_ptr, const char ***vals_ptr)
+static size_t get_params(va_list ap, const char ***params_ptr, const char ***vals_ptr, int warn)
{
const char **tmp, *param, *val, **params, **vals;
size_t params_count;
@@ -987,8 +987,9 @@
if (params_count > 0) {
*params_ptr = params;
*vals_ptr = vals;
- } else
+ } else if (warn) {
ast_log(LOG_WARNING, "1 parameter and 1 value at least required\n");
+ }
return params_count;
}
@@ -1035,7 +1036,7 @@
return NULL;
}
- params_count = get_params(ap, ¶ms, &vals);
+ params_count = get_params(ap, ¶ms, &vals, 1);
if (params_count == 0)
return NULL;
@@ -1044,10 +1045,10 @@
/* \cond DOXYGEN_CAN_PARSE_THIS */
#undef QUERY
-#define QUERY "SELECT * FROM '%q' WHERE commented = 0 AND %q%s '%q'"
+#define QUERY "SELECT * FROM '%q' WHERE%s %q%s '%q'"
/* \endcond */
- query = sqlite_mprintf(QUERY, table, params[0], op, vals[0]);
+ query = sqlite_mprintf(QUERY, table, !strcmp(config_table, table) ? " commented = 0 AND" : "", params[0], op, vals[0]);
if (!query) {
ast_log(LOG_WARNING, "Unable to allocate SQL query\n");
@@ -1180,7 +1181,7 @@
return NULL;
}
- if (!(params_count = get_params(ap, ¶ms, &vals))) {
+ if (!(params_count = get_params(ap, ¶ms, &vals, 1))) {
ast_config_destroy(cfg);
return NULL;
}
@@ -1292,7 +1293,7 @@
return -1;
}
- if (!(params_count = get_params(ap, ¶ms, &vals)))
+ if (!(params_count = get_params(ap, ¶ms, &vals, 1)))
return -1;
/* \cond DOXYGEN_CAN_PARSE_THIS */
@@ -1398,6 +1399,7 @@
return -1;
}
+ first = 1;
while ((param = va_arg(ap, const char *))) {
value = va_arg(ap, const char *);
ast_str_append(&sql, 0, "%s %s = %s",
@@ -1447,7 +1449,7 @@
return -1;
}
- if (!(params_count = get_params(ap, ¶ms, &vals)))
+ if (!(params_count = get_params(ap, ¶ms, &vals, 1)))
return -1;
/* \cond DOXYGEN_CAN_PARSE_THIS */
@@ -1471,10 +1473,10 @@
}
if ( tmp_vals2 ) {
- tmp_vals = sqlite_mprintf("%s, '%q'", tmp_vals2, params[i]);
+ tmp_vals = sqlite_mprintf("%s, '%q'", tmp_vals2, vals[i]);
sqlite_freemem(tmp_vals2);
} else {
- tmp_vals = sqlite_mprintf("'%q'", params[i]);
+ tmp_vals = sqlite_mprintf("'%q'", vals[i]);
}
if (!tmp_vals) {
ast_log(LOG_WARNING, "Unable to reallocate SQL query\n");
@@ -1532,7 +1534,7 @@
const char *keyfield, const char *entity, va_list ap)
{
char *query, *errormsg = NULL, *tmp_str;
- const char **params, **vals;
+ const char **params = NULL, **vals = NULL;
size_t params_count;
int error, rows_num;
size_t i;
@@ -1542,8 +1544,7 @@
return -1;
}
- if (!(params_count = get_params(ap, ¶ms, &vals)))
- return -1;
+ params_count = get_params(ap, ¶ms, &vals, 0);
/* \cond DOXYGEN_CAN_PARSE_THIS */
#undef QUERY
@@ -1588,10 +1589,11 @@
error = sqlite_exec(db, query, NULL, NULL, &errormsg);
RES_CONFIG_SQLITE_END(error)
- if (!error)
+ if (!error) {
rows_num = sqlite_changes(db);
- else
+ } else {
rows_num = -1;
+ }
ast_mutex_unlock(&mutex);
Modified: team/tilghman/realtime_update2/res/res_realtime.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/realtime_update2/res/res_realtime.c?view=diff&rev=148569&r1=148568&r2=148569
==============================================================================
--- team/tilghman/realtime_update2/res/res_realtime.c (original)
+++ team/tilghman/realtime_update2/res/res_realtime.c Mon Oct 13 18:21:04 2008
@@ -117,7 +117,7 @@
case CLI_INIT:
e->command = "realtime update2";
e->usage =
- "Usage: realtime update2 <family> <colupdate> <newvalue> <colmatch> <valuematch> [... <colmatchN> <valuematchN>]\n"
+ "Usage: realtime update2 <family> <colupdate> <newvalue> <colmatch> <valuematch> [... <colmatch5> <valuematch5>]\n"
" Update a single variable using the RealTime driver.\n"
" You must supply a family name, a column to update on, a new value, column to match, and value to match.\n"
" Ex: realtime update sipfriends name bobsphone port 4343\n"
@@ -138,6 +138,8 @@
res = ast_update2_realtime(a->argv[2], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], SENTINEL, a->argv[3], a->argv[4], SENTINEL);
} else if (a->argc == 13) {
res = ast_update2_realtime(a->argv[2], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], SENTINEL, a->argv[3], a->argv[4], SENTINEL);
+ } else if (a->argc == 15) {
+ res = ast_update2_realtime(a->argv[2], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], a->argv[13], a->argv[14], SENTINEL, a->argv[3], a->argv[4], SENTINEL);
} else {
return CLI_SHOWUSAGE;
}
@@ -148,6 +150,93 @@
}
ast_cli(a->fd, "Updated %d RealTime record%s.\n", res, ESS(res));
+
+ return CLI_SUCCESS;
+}
+
+static char *cli_realtime_store(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ int res = -1;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "realtime store";
+ e->usage =
+ "Usage: realtime store <family> <colname1> <value1> [<colname2> <value2> [... <colmatch5> <valuematch5>]]\n"
+ " Create a stored row using the RealTime driver.\n"
+ " You must supply a family name and name/value pairs (up to 5). If\n"
+ " you need to store more than 5 key/value pairs, start with the first\n"
+ " five, then use 'realtime update' or 'realtime update2' to add\n"
+ " additional columns.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc < 5) {
+ return CLI_SHOWUSAGE;
+ } else if (a->argc == 5) {
+ res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL);
+ } else if (a->argc == 7) {
+ res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL);
+ } else if (a->argc == 9) {
+ res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], SENTINEL);
+ } else if (a->argc == 11) {
+ res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], SENTINEL);
+ } else if (a->argc == 13) {
+ res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], SENTINEL);
+ } else {
+ return CLI_SHOWUSAGE;
+ }
+
+ if (res < 0) {
+ ast_cli(a->fd, "Failed to store record. Check the debug log for possible SQL related entries.\n");
+ return CLI_FAILURE;
+ }
+
+ ast_cli(a->fd, "Stored RealTime record.\n");
+
+ return CLI_SUCCESS;
+}
+
+static char *cli_realtime_destroy(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ int res = -1;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "realtime destroy";
+ e->usage =
+ "Usage: realtime destroy <family> <colname1> <value1> [<colname2> <value2> [... <colmatch5> <valuematch5>]]\n"
+ " Remove a stored row using the RealTime driver.\n"
+ " You must supply a family name and name/value pairs (up to 5).\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc < 5) {
+ return CLI_SHOWUSAGE;
+ } else if (a->argc == 5) {
+ res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL);
+ } else if (a->argc == 7) {
+ res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL);
+ } else if (a->argc == 9) {
+ res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], SENTINEL);
+ } else if (a->argc == 11) {
+ res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], SENTINEL);
+ } else if (a->argc == 13) {
+ res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], SENTINEL);
+ } else {
+ return CLI_SHOWUSAGE;
+ }
+
+ if (res < 0) {
+ ast_cli(a->fd, "Failed to remove record. Check the debug log for possible SQL related entries.\n");
+ return CLI_FAILURE;
+ }
+
+ ast_cli(a->fd, "Removed %d RealTime record%s.\n", res, ESS(res));
return CLI_SUCCESS;
}
@@ -156,6 +245,8 @@
AST_CLI_DEFINE(cli_realtime_load, "Used to print out RealTime variables."),
AST_CLI_DEFINE(cli_realtime_update, "Used to update RealTime variables."),
AST_CLI_DEFINE(cli_realtime_update2, "Used to test the RealTime update2 method"),
+ AST_CLI_DEFINE(cli_realtime_store, "Store a new row into a RealTime database"),
+ AST_CLI_DEFINE(cli_realtime_destroy, "Delete a row from a RealTime database"),
};
static int unload_module(void)
More information about the asterisk-commits
mailing list