#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
Go to the source code of this file.
Functions | |
static void | __init_buf1 (void) |
static void | __init_buf2 (void) |
static void | __init_buf3 (void) |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | function_realtime_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | function_realtime_readdestroy (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | function_realtime_store (struct ast_channel *chan, const char *cmd, char *data, const char *value) |
static int | function_realtime_write (struct ast_channel *chan, const char *cmd, char *data, const char *value) |
static int | load_module (void) |
static int | realtimefield_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Read/Write/Store/Destroy values from a RealTime repository" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "88eaa8f5c1bd988bedd71113385e0886" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_threadstorage | buf1 = { .once = PTHREAD_ONCE_INIT , .key_init = __init_buf1 , .custom_init = NULL , } |
static struct ast_threadstorage | buf2 = { .once = PTHREAD_ONCE_INIT , .key_init = __init_buf2 , .custom_init = NULL , } |
static struct ast_threadstorage | buf3 = { .once = PTHREAD_ONCE_INIT , .key_init = __init_buf3 , .custom_init = NULL , } |
static struct ast_custom_function | realtime_destroy_function |
static struct ast_custom_function | realtime_function |
static struct ast_custom_function | realtime_store_function |
static struct ast_custom_function | realtimefield_function |
static struct ast_custom_function | realtimehash_function |
Definition in file func_realtime.c.
static void __init_buf1 | ( | void | ) | [static] |
static void __init_buf2 | ( | void | ) | [static] |
static void __init_buf3 | ( | void | ) | [static] |
static void __reg_module | ( | void | ) | [static] |
Definition at line 499 of file func_realtime.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 499 of file func_realtime.c.
static int function_realtime_read | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 178 of file func_realtime.c.
References args, AST_APP_ARG, ast_autoservice_start(), ast_autoservice_stop(), ast_copy_string(), AST_DECLARE_APP_ARGS, ast_load_realtime_all(), ast_log(), AST_STANDARD_APP_ARGS, ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_strlen_zero(), ast_variables_destroy(), LOG_WARNING, ast_variable::next, SENTINEL, value, and var.
00179 { 00180 struct ast_variable *var, *head; 00181 struct ast_str *out; 00182 size_t resultslen; 00183 int n; 00184 AST_DECLARE_APP_ARGS(args, 00185 AST_APP_ARG(family); 00186 AST_APP_ARG(fieldmatch); 00187 AST_APP_ARG(value); 00188 AST_APP_ARG(delim1); 00189 AST_APP_ARG(delim2); 00190 ); 00191 00192 if (ast_strlen_zero(data)) { 00193 ast_log(LOG_WARNING, "Syntax: REALTIME(family,fieldmatch[,value[,delim1[,delim2]]]) - missing argument!\n"); 00194 return -1; 00195 } 00196 00197 AST_STANDARD_APP_ARGS(args, data); 00198 00199 if (!args.delim1) 00200 args.delim1 = ","; 00201 if (!args.delim2) 00202 args.delim2 = "="; 00203 00204 if (chan) 00205 ast_autoservice_start(chan); 00206 00207 head = ast_load_realtime_all(args.family, args.fieldmatch, args.value, SENTINEL); 00208 00209 if (!head) { 00210 if (chan) 00211 ast_autoservice_stop(chan); 00212 return -1; 00213 } 00214 00215 resultslen = 0; 00216 n = 0; 00217 for (var = head; var; n++, var = var->next) 00218 resultslen += strlen(var->name) + strlen(var->value); 00219 /* add space for delimiters and final '\0' */ 00220 resultslen += n * (strlen(args.delim1) + strlen(args.delim2)) + 1; 00221 00222 out = ast_str_alloca(resultslen); 00223 for (var = head; var; var = var->next) 00224 ast_str_append(&out, 0, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1); 00225 ast_copy_string(buf, ast_str_buffer(out), len); 00226 00227 ast_variables_destroy(head); 00228 00229 if (chan) 00230 ast_autoservice_stop(chan); 00231 00232 return 0; 00233 }
static int function_realtime_readdestroy | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 391 of file func_realtime.c.
References args, AST_APP_ARG, ast_autoservice_start(), ast_autoservice_stop(), ast_copy_string(), AST_DECLARE_APP_ARGS, ast_destroy_realtime(), ast_load_realtime_all(), ast_log(), AST_STANDARD_APP_ARGS, ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_strlen_zero(), ast_variables_destroy(), LOG_WARNING, ast_variable::next, SENTINEL, value, and var.
00392 { 00393 struct ast_variable *var, *head; 00394 struct ast_str *out; 00395 size_t resultslen; 00396 int n; 00397 AST_DECLARE_APP_ARGS(args, 00398 AST_APP_ARG(family); 00399 AST_APP_ARG(fieldmatch); 00400 AST_APP_ARG(value); 00401 AST_APP_ARG(delim1); 00402 AST_APP_ARG(delim2); 00403 ); 00404 00405 if (ast_strlen_zero(data)) { 00406 ast_log(LOG_WARNING, "Syntax: REALTIME_DESTROY(family,fieldmatch[,value[,delim1[,delim2]]]) - missing argument!\n"); 00407 return -1; 00408 } 00409 00410 AST_STANDARD_APP_ARGS(args, data); 00411 00412 if (!args.delim1) 00413 args.delim1 = ","; 00414 if (!args.delim2) 00415 args.delim2 = "="; 00416 00417 if (chan) 00418 ast_autoservice_start(chan); 00419 00420 head = ast_load_realtime_all(args.family, args.fieldmatch, args.value, SENTINEL); 00421 00422 if (!head) { 00423 if (chan) 00424 ast_autoservice_stop(chan); 00425 return -1; 00426 } 00427 00428 resultslen = 0; 00429 n = 0; 00430 for (var = head; var; n++, var = var->next) 00431 resultslen += strlen(var->name) + strlen(var->value); 00432 /* add space for delimiters and final '\0' */ 00433 resultslen += n * (strlen(args.delim1) + strlen(args.delim2)) + 1; 00434 00435 out = ast_str_alloca(resultslen); 00436 for (var = head; var; var = var->next) { 00437 ast_str_append(&out, 0, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1); 00438 } 00439 ast_copy_string(buf, ast_str_buffer(out), len); 00440 00441 ast_destroy_realtime(args.family, args.fieldmatch, args.value, SENTINEL); 00442 ast_variables_destroy(head); 00443 00444 if (chan) 00445 ast_autoservice_stop(chan); 00446 00447 return 0; 00448 }
static int function_realtime_store | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
const char * | value | |||
) | [static] |
Definition at line 343 of file func_realtime.c.
References AST_APP_ARG, ast_autoservice_start(), ast_autoservice_stop(), AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_store_realtime(), ast_strdupa, ast_strlen_zero(), f, LOG_WARNING, pbx_builtin_setvar_helper(), and SENTINEL.
00344 { 00345 int res = 0; 00346 char storeid[32]; 00347 char *valcopy; 00348 AST_DECLARE_APP_ARGS(a, 00349 AST_APP_ARG(family); 00350 AST_APP_ARG(f)[30]; /* fields */ 00351 ); 00352 00353 AST_DECLARE_APP_ARGS(v, 00354 AST_APP_ARG(v)[30]; /* values */ 00355 ); 00356 00357 if (ast_strlen_zero(data)) { 00358 ast_log(LOG_WARNING, "Syntax: REALTIME_STORE(family,field1,field2,...,field30) - missing argument!\n"); 00359 return -1; 00360 } 00361 00362 if (chan) 00363 ast_autoservice_start(chan); 00364 00365 valcopy = ast_strdupa(value); 00366 AST_STANDARD_APP_ARGS(a, data); 00367 AST_STANDARD_APP_ARGS(v, valcopy); 00368 00369 res = ast_store_realtime(a.family, 00370 a.f[0], v.v[0], a.f[1], v.v[1], a.f[2], v.v[2], a.f[3], v.v[3], a.f[4], v.v[4], 00371 a.f[5], v.v[5], a.f[6], v.v[6], a.f[7], v.v[7], a.f[8], v.v[8], a.f[9], v.v[9], 00372 a.f[10], v.v[10], a.f[11], v.v[11], a.f[12], v.v[12], a.f[13], v.v[13], a.f[14], v.v[14], 00373 a.f[15], v.v[15], a.f[16], v.v[16], a.f[17], v.v[17], a.f[18], v.v[18], a.f[19], v.v[19], 00374 a.f[20], v.v[20], a.f[21], v.v[21], a.f[22], v.v[22], a.f[23], v.v[23], a.f[24], v.v[24], 00375 a.f[25], v.v[25], a.f[26], v.v[26], a.f[27], v.v[27], a.f[28], v.v[28], a.f[29], v.v[29], SENTINEL 00376 ); 00377 00378 if (res < 0) { 00379 ast_log(LOG_WARNING, "Failed to store. Check the debug log for possible data repository related entries.\n"); 00380 } else { 00381 snprintf(storeid, sizeof(storeid), "%d", res); 00382 pbx_builtin_setvar_helper(chan, "RTSTOREID", storeid); 00383 } 00384 00385 if (chan) 00386 ast_autoservice_stop(chan); 00387 00388 return 0; 00389 }
static int function_realtime_write | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
const char * | value | |||
) | [static] |
Definition at line 235 of file func_realtime.c.
References args, AST_APP_ARG, ast_autoservice_start(), ast_autoservice_stop(), AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_update_realtime(), LOG_WARNING, and SENTINEL.
00236 { 00237 int res = 0; 00238 AST_DECLARE_APP_ARGS(args, 00239 AST_APP_ARG(family); 00240 AST_APP_ARG(fieldmatch); 00241 AST_APP_ARG(value); 00242 AST_APP_ARG(field); 00243 ); 00244 00245 if (ast_strlen_zero(data)) { 00246 ast_log(LOG_WARNING, "Syntax: %s(family,fieldmatch,value,newcol) - missing argument!\n", cmd); 00247 return -1; 00248 } 00249 00250 if (chan) 00251 ast_autoservice_start(chan); 00252 00253 AST_STANDARD_APP_ARGS(args, data); 00254 00255 res = ast_update_realtime(args.family, args.fieldmatch, args.value, args.field, (char *)value, SENTINEL); 00256 00257 if (res < 0) { 00258 ast_log(LOG_WARNING, "Failed to update. Check the debug log for possible data repository related entries.\n"); 00259 } 00260 00261 if (chan) 00262 ast_autoservice_stop(chan); 00263 00264 return 0; 00265 }
static int load_module | ( | void | ) | [static] |
Definition at line 488 of file func_realtime.c.
References ast_custom_function_register, realtime_destroy_function, realtime_function, realtime_store_function, realtimefield_function, and realtimehash_function.
00489 { 00490 int res = 0; 00491 res |= ast_custom_function_register(&realtime_function); 00492 res |= ast_custom_function_register(&realtime_store_function); 00493 res |= ast_custom_function_register(&realtime_destroy_function); 00494 res |= ast_custom_function_register(&realtimefield_function); 00495 res |= ast_custom_function_register(&realtimehash_function); 00496 return res; 00497 }
static int realtimefield_read | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 267 of file func_realtime.c.
References args, AST_APP_ARG, ast_autoservice_start(), ast_autoservice_stop(), ast_copy_string(), ast_debug, AST_DECLARE_APP_ARGS, ast_load_realtime_all(), ast_log(), AST_STANDARD_APP_ARGS, ast_str_append(), ast_str_reset(), ast_str_set_escapecommas(), ast_str_thread_get(), ast_strlen_zero(), buf1, buf2, buf3, first, LOG_WARNING, SENTINEL, value, and var.
00268 { 00269 struct ast_variable *var, *head; 00270 struct ast_str *escapebuf = ast_str_thread_get(&buf1, 16); 00271 struct ast_str *fields = ast_str_thread_get(&buf2, 16); 00272 struct ast_str *values = ast_str_thread_get(&buf3, 16); 00273 int first = 0; 00274 enum { rtfield, rthash } which; 00275 AST_DECLARE_APP_ARGS(args, 00276 AST_APP_ARG(family); 00277 AST_APP_ARG(fieldmatch); 00278 AST_APP_ARG(value); 00279 AST_APP_ARG(fieldname); 00280 ); 00281 00282 if (!strcmp(cmd, "REALTIME_FIELD")) { 00283 which = rtfield; 00284 } else { 00285 which = rthash; 00286 } 00287 00288 if (ast_strlen_zero(data)) { 00289 ast_log(LOG_WARNING, "Syntax: %s(family,fieldmatch,value%s) - missing argument!\n", cmd, which == rtfield ? ",fieldname" : ""); 00290 return -1; 00291 } 00292 00293 AST_STANDARD_APP_ARGS(args, data); 00294 00295 if ((which == rtfield && args.argc != 4) || (which == rthash && args.argc != 3)) { 00296 ast_log(LOG_WARNING, "Syntax: %s(family,fieldmatch,value%s) - missing argument!\n", cmd, which == rtfield ? ",fieldname" : ""); 00297 return -1; 00298 } 00299 00300 if (chan) { 00301 ast_autoservice_start(chan); 00302 } 00303 00304 if (!(head = ast_load_realtime_all(args.family, args.fieldmatch, args.value, SENTINEL))) { 00305 if (chan) { 00306 ast_autoservice_stop(chan); 00307 } 00308 return -1; 00309 } 00310 00311 ast_str_reset(fields); 00312 ast_str_reset(values); 00313 00314 for (var = head; var; var = var->next) { 00315 if (which == rtfield) { 00316 ast_debug(1, "Comparing %s to %s\n", var->name, args.fieldname); 00317 if (!strcasecmp(var->name, args.fieldname)) { 00318 ast_debug(1, "Match! Value is %s\n", var->value); 00319 ast_copy_string(buf, var->value, len); 00320 break; 00321 } 00322 } else if (which == rthash) { 00323 ast_debug(1, "Setting hash key %s to value %s\n", var->name, var->value); 00324 ast_str_append(&fields, 0, "%s%s", first ? "" : ",", ast_str_set_escapecommas(&escapebuf, 0, var->name, INT_MAX)); 00325 ast_str_append(&values, 0, "%s%s", first ? "" : ",", ast_str_set_escapecommas(&escapebuf, 0, var->value, INT_MAX)); 00326 first = 0; 00327 } 00328 } 00329 ast_variables_destroy(head); 00330 00331 if (which == rthash) { 00332 pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", ast_str_buffer(fields)); 00333 ast_copy_string(buf, ast_str_buffer(values), len); 00334 } 00335 00336 if (chan) { 00337 ast_autoservice_stop(chan); 00338 } 00339 00340 return 0; 00341 }
static int unload_module | ( | void | ) | [static] |
Definition at line 477 of file func_realtime.c.
References ast_custom_function_unregister(), realtime_destroy_function, realtime_function, realtime_store_function, realtimefield_function, and realtimehash_function.
00478 { 00479 int res = 0; 00480 res |= ast_custom_function_unregister(&realtime_function); 00481 res |= ast_custom_function_unregister(&realtime_store_function); 00482 res |= ast_custom_function_unregister(&realtime_destroy_function); 00483 res |= ast_custom_function_unregister(&realtimefield_function); 00484 res |= ast_custom_function_unregister(&realtimehash_function); 00485 return res; 00486 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Read/Write/Store/Destroy values from a RealTime repository" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "88eaa8f5c1bd988bedd71113385e0886" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
Definition at line 499 of file func_realtime.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 499 of file func_realtime.c.
struct ast_threadstorage buf1 = { .once = PTHREAD_ONCE_INIT , .key_init = __init_buf1 , .custom_init = NULL , } [static] |
Definition at line 174 of file func_realtime.c.
Referenced by adsi_message(), audiohook_read_frame_both(), config_curl(), destroy_curl(), destroy_pgsql(), fix_gotos_in_extensions(), gen_prios(), realtime_curl(), realtime_multi_curl(), realtimefield_read(), store_curl(), update2_curl(), and update_curl().
struct ast_threadstorage buf2 = { .once = PTHREAD_ONCE_INIT , .key_init = __init_buf2 , .custom_init = NULL , } [static] |
Definition at line 175 of file func_realtime.c.
Referenced by adsi_message(), ast_compile_ael2(), audiohook_read_frame_both(), destroy_curl(), destroy_pgsql(), gen_prios(), HandleSelectCodec(), read_config(), realtime_curl(), realtime_multi_curl(), realtimefield_read(), rpt_exec(), show_dialplan_helper(), store_curl(), update2_curl(), and update_curl().
struct ast_threadstorage buf3 = { .once = PTHREAD_ONCE_INIT , .key_init = __init_buf3 , .custom_init = NULL , } [static] |
struct ast_custom_function realtime_destroy_function [static] |
Initial value:
{ .name = "REALTIME_DESTROY", .read = function_realtime_readdestroy, }
Definition at line 472 of file func_realtime.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function realtime_function [static] |
Initial value:
{ .name = "REALTIME", .read = function_realtime_read, .write = function_realtime_write, }
Definition at line 450 of file func_realtime.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function realtime_store_function [static] |
Initial value:
{ .name = "REALTIME_STORE", .write = function_realtime_store, }
Definition at line 467 of file func_realtime.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function realtimefield_function [static] |
Initial value:
{ .name = "REALTIME_FIELD", .read = realtimefield_read, .write = function_realtime_write, }
Definition at line 456 of file func_realtime.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function realtimehash_function [static] |
Initial value:
{ .name = "REALTIME_HASH", .read = realtimefield_read, }
Definition at line 462 of file func_realtime.c.
Referenced by load_module(), and unload_module().