#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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .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 495 of file func_realtime.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 495 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 174 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.
00175 { 00176 struct ast_variable *var, *head; 00177 struct ast_str *out; 00178 size_t resultslen; 00179 int n; 00180 AST_DECLARE_APP_ARGS(args, 00181 AST_APP_ARG(family); 00182 AST_APP_ARG(fieldmatch); 00183 AST_APP_ARG(value); 00184 AST_APP_ARG(delim1); 00185 AST_APP_ARG(delim2); 00186 ); 00187 00188 if (ast_strlen_zero(data)) { 00189 ast_log(LOG_WARNING, "Syntax: REALTIME(family,fieldmatch[,value[,delim1[,delim2]]]) - missing argument!\n"); 00190 return -1; 00191 } 00192 00193 AST_STANDARD_APP_ARGS(args, data); 00194 00195 if (!args.delim1) 00196 args.delim1 = ","; 00197 if (!args.delim2) 00198 args.delim2 = "="; 00199 00200 if (chan) 00201 ast_autoservice_start(chan); 00202 00203 head = ast_load_realtime_all(args.family, args.fieldmatch, args.value, SENTINEL); 00204 00205 if (!head) { 00206 if (chan) 00207 ast_autoservice_stop(chan); 00208 return -1; 00209 } 00210 00211 resultslen = 0; 00212 n = 0; 00213 for (var = head; var; n++, var = var->next) 00214 resultslen += strlen(var->name) + strlen(var->value); 00215 /* add space for delimiters and final '\0' */ 00216 resultslen += n * (strlen(args.delim1) + strlen(args.delim2)) + 1; 00217 00218 out = ast_str_alloca(resultslen); 00219 for (var = head; var; var = var->next) 00220 ast_str_append(&out, 0, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1); 00221 ast_copy_string(buf, ast_str_buffer(out), len); 00222 00223 ast_variables_destroy(head); 00224 00225 if (chan) 00226 ast_autoservice_stop(chan); 00227 00228 return 0; 00229 }
static int function_realtime_readdestroy | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 387 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.
00388 { 00389 struct ast_variable *var, *head; 00390 struct ast_str *out; 00391 size_t resultslen; 00392 int n; 00393 AST_DECLARE_APP_ARGS(args, 00394 AST_APP_ARG(family); 00395 AST_APP_ARG(fieldmatch); 00396 AST_APP_ARG(value); 00397 AST_APP_ARG(delim1); 00398 AST_APP_ARG(delim2); 00399 ); 00400 00401 if (ast_strlen_zero(data)) { 00402 ast_log(LOG_WARNING, "Syntax: REALTIME_DESTROY(family,fieldmatch[,value[,delim1[,delim2]]]) - missing argument!\n"); 00403 return -1; 00404 } 00405 00406 AST_STANDARD_APP_ARGS(args, data); 00407 00408 if (!args.delim1) 00409 args.delim1 = ","; 00410 if (!args.delim2) 00411 args.delim2 = "="; 00412 00413 if (chan) 00414 ast_autoservice_start(chan); 00415 00416 head = ast_load_realtime_all(args.family, args.fieldmatch, args.value, SENTINEL); 00417 00418 if (!head) { 00419 if (chan) 00420 ast_autoservice_stop(chan); 00421 return -1; 00422 } 00423 00424 resultslen = 0; 00425 n = 0; 00426 for (var = head; var; n++, var = var->next) 00427 resultslen += strlen(var->name) + strlen(var->value); 00428 /* add space for delimiters and final '\0' */ 00429 resultslen += n * (strlen(args.delim1) + strlen(args.delim2)) + 1; 00430 00431 out = ast_str_alloca(resultslen); 00432 for (var = head; var; var = var->next) { 00433 ast_str_append(&out, 0, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1); 00434 } 00435 ast_copy_string(buf, ast_str_buffer(out), len); 00436 00437 ast_destroy_realtime(args.family, args.fieldmatch, args.value, SENTINEL); 00438 ast_variables_destroy(head); 00439 00440 if (chan) 00441 ast_autoservice_stop(chan); 00442 00443 return 0; 00444 }
static int function_realtime_store | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
const char * | value | |||
) | [static] |
Definition at line 339 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.
00340 { 00341 int res = 0; 00342 char storeid[32]; 00343 char *valcopy; 00344 AST_DECLARE_APP_ARGS(a, 00345 AST_APP_ARG(family); 00346 AST_APP_ARG(f)[30]; /* fields */ 00347 ); 00348 00349 AST_DECLARE_APP_ARGS(v, 00350 AST_APP_ARG(v)[30]; /* values */ 00351 ); 00352 00353 if (ast_strlen_zero(data)) { 00354 ast_log(LOG_WARNING, "Syntax: REALTIME_STORE(family,field1,field2,...,field30) - missing argument!\n"); 00355 return -1; 00356 } 00357 00358 if (chan) 00359 ast_autoservice_start(chan); 00360 00361 valcopy = ast_strdupa(value); 00362 AST_STANDARD_APP_ARGS(a, data); 00363 AST_STANDARD_APP_ARGS(v, valcopy); 00364 00365 res = ast_store_realtime(a.family, 00366 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], 00367 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], 00368 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], 00369 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], 00370 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], 00371 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 00372 ); 00373 00374 if (res < 0) { 00375 ast_log(LOG_WARNING, "Failed to store. Check the debug log for possible data repository related entries.\n"); 00376 } else { 00377 snprintf(storeid, sizeof(storeid), "%d", res); 00378 pbx_builtin_setvar_helper(chan, "RTSTOREID", storeid); 00379 } 00380 00381 if (chan) 00382 ast_autoservice_stop(chan); 00383 00384 return 0; 00385 }
static int function_realtime_write | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
const char * | value | |||
) | [static] |
Definition at line 231 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.
00232 { 00233 int res = 0; 00234 AST_DECLARE_APP_ARGS(args, 00235 AST_APP_ARG(family); 00236 AST_APP_ARG(fieldmatch); 00237 AST_APP_ARG(value); 00238 AST_APP_ARG(field); 00239 ); 00240 00241 if (ast_strlen_zero(data)) { 00242 ast_log(LOG_WARNING, "Syntax: %s(family,fieldmatch,value,newcol) - missing argument!\n", cmd); 00243 return -1; 00244 } 00245 00246 if (chan) 00247 ast_autoservice_start(chan); 00248 00249 AST_STANDARD_APP_ARGS(args, data); 00250 00251 res = ast_update_realtime(args.family, args.fieldmatch, args.value, args.field, (char *)value, SENTINEL); 00252 00253 if (res < 0) { 00254 ast_log(LOG_WARNING, "Failed to update. Check the debug log for possible data repository related entries.\n"); 00255 } 00256 00257 if (chan) 00258 ast_autoservice_stop(chan); 00259 00260 return 0; 00261 }
static int load_module | ( | void | ) | [static] |
Definition at line 484 of file func_realtime.c.
References ast_custom_function_register, realtime_destroy_function, realtime_function, realtime_store_function, realtimefield_function, and realtimehash_function.
00485 { 00486 int res = 0; 00487 res |= ast_custom_function_register(&realtime_function); 00488 res |= ast_custom_function_register(&realtime_store_function); 00489 res |= ast_custom_function_register(&realtime_destroy_function); 00490 res |= ast_custom_function_register(&realtimefield_function); 00491 res |= ast_custom_function_register(&realtimehash_function); 00492 return res; 00493 }
static int realtimefield_read | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 263 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.
00264 { 00265 struct ast_variable *var, *head; 00266 struct ast_str *escapebuf = ast_str_thread_get(&buf1, 16); 00267 struct ast_str *fields = ast_str_thread_get(&buf2, 16); 00268 struct ast_str *values = ast_str_thread_get(&buf3, 16); 00269 int first = 0; 00270 enum { rtfield, rthash } which; 00271 AST_DECLARE_APP_ARGS(args, 00272 AST_APP_ARG(family); 00273 AST_APP_ARG(fieldmatch); 00274 AST_APP_ARG(value); 00275 AST_APP_ARG(fieldname); 00276 ); 00277 00278 if (!strcmp(cmd, "REALTIME_FIELD")) { 00279 which = rtfield; 00280 } else { 00281 which = rthash; 00282 } 00283 00284 if (ast_strlen_zero(data)) { 00285 ast_log(LOG_WARNING, "Syntax: %s(family,fieldmatch,value%s) - missing argument!\n", cmd, which == rtfield ? ",fieldname" : ""); 00286 return -1; 00287 } 00288 00289 AST_STANDARD_APP_ARGS(args, data); 00290 00291 if ((which == rtfield && args.argc != 4) || (which == rthash && args.argc != 3)) { 00292 ast_log(LOG_WARNING, "Syntax: %s(family,fieldmatch,value%s) - missing argument!\n", cmd, which == rtfield ? ",fieldname" : ""); 00293 return -1; 00294 } 00295 00296 if (chan) { 00297 ast_autoservice_start(chan); 00298 } 00299 00300 if (!(head = ast_load_realtime_all(args.family, args.fieldmatch, args.value, SENTINEL))) { 00301 if (chan) { 00302 ast_autoservice_stop(chan); 00303 } 00304 return -1; 00305 } 00306 00307 ast_str_reset(fields); 00308 ast_str_reset(values); 00309 00310 for (var = head; var; var = var->next) { 00311 if (which == rtfield) { 00312 ast_debug(1, "Comparing %s to %s\n", var->name, args.fieldname); 00313 if (!strcasecmp(var->name, args.fieldname)) { 00314 ast_debug(1, "Match! Value is %s\n", var->value); 00315 ast_copy_string(buf, var->value, len); 00316 break; 00317 } 00318 } else if (which == rthash) { 00319 ast_debug(1, "Setting hash key %s to value %s\n", var->name, var->value); 00320 ast_str_append(&fields, 0, "%s%s", first ? "" : ",", ast_str_set_escapecommas(&escapebuf, 0, var->name, INT_MAX)); 00321 ast_str_append(&values, 0, "%s%s", first ? "" : ",", ast_str_set_escapecommas(&escapebuf, 0, var->value, INT_MAX)); 00322 first = 0; 00323 } 00324 } 00325 ast_variables_destroy(head); 00326 00327 if (which == rthash) { 00328 pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", ast_str_buffer(fields)); 00329 ast_copy_string(buf, ast_str_buffer(values), len); 00330 } 00331 00332 if (chan) { 00333 ast_autoservice_stop(chan); 00334 } 00335 00336 return 0; 00337 }
static int unload_module | ( | void | ) | [static] |
Definition at line 473 of file func_realtime.c.
References ast_custom_function_unregister(), realtime_destroy_function, realtime_function, realtime_store_function, realtimefield_function, and realtimehash_function.
00474 { 00475 int res = 0; 00476 res |= ast_custom_function_unregister(&realtime_function); 00477 res |= ast_custom_function_unregister(&realtime_store_function); 00478 res |= ast_custom_function_unregister(&realtime_destroy_function); 00479 res |= ast_custom_function_unregister(&realtimefield_function); 00480 res |= ast_custom_function_unregister(&realtimehash_function); 00481 return res; 00482 }
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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
Definition at line 495 of file func_realtime.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 495 of file func_realtime.c.
struct ast_threadstorage buf1 = { .once = PTHREAD_ONCE_INIT , .key_init = __init_buf1 , .custom_init = NULL , } [static] |
Definition at line 170 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 171 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 468 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 446 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 463 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 452 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 458 of file func_realtime.c.
Referenced by load_module(), and unload_module().