REALTIME dialplan function. More...
#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 = "7a1b8b48c852d7a7061c7e499b9bd0d2" , .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 |
REALTIME dialplan function.
Definition in file func_realtime.c.
| static void __init_buf1 | ( | void | ) | [static] |
Definition at line 170 of file func_realtime.c.
{
| static void __init_buf2 | ( | void | ) | [static] |
Definition at line 171 of file func_realtime.c.
{
| static void __init_buf3 | ( | void | ) | [static] |
Definition at line 172 of file func_realtime.c.
{
| 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 var, AST_DECLARE_APP_ARGS, args, AST_APP_ARG, value, ast_strlen_zero(), ast_log(), LOG_WARNING, AST_STANDARD_APP_ARGS, ast_autoservice_start(), ast_load_realtime_all(), SENTINEL, ast_autoservice_stop(), ast_variable::next, ast_str_alloca, ast_str_append(), ast_copy_string(), ast_str_buffer(), and ast_variables_destroy().
{
struct ast_variable *var, *head;
struct ast_str *out;
size_t resultslen;
int n;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(family);
AST_APP_ARG(fieldmatch);
AST_APP_ARG(value);
AST_APP_ARG(delim1);
AST_APP_ARG(delim2);
);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Syntax: REALTIME(family,fieldmatch[,value[,delim1[,delim2]]]) - missing argument!\n");
return -1;
}
AST_STANDARD_APP_ARGS(args, data);
if (!args.delim1)
args.delim1 = ",";
if (!args.delim2)
args.delim2 = "=";
if (chan)
ast_autoservice_start(chan);
head = ast_load_realtime_all(args.family, args.fieldmatch, args.value, SENTINEL);
if (!head) {
if (chan)
ast_autoservice_stop(chan);
return -1;
}
resultslen = 0;
n = 0;
for (var = head; var; n++, var = var->next)
resultslen += strlen(var->name) + strlen(var->value);
/* add space for delimiters and final '\0' */
resultslen += n * (strlen(args.delim1) + strlen(args.delim2)) + 1;
out = ast_str_alloca(resultslen);
for (var = head; var; var = var->next)
ast_str_append(&out, 0, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1);
ast_copy_string(buf, ast_str_buffer(out), len);
ast_variables_destroy(head);
if (chan)
ast_autoservice_stop(chan);
return 0;
}
| 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 var, AST_DECLARE_APP_ARGS, args, AST_APP_ARG, value, ast_strlen_zero(), ast_log(), LOG_WARNING, AST_STANDARD_APP_ARGS, ast_autoservice_start(), ast_load_realtime_all(), SENTINEL, ast_autoservice_stop(), ast_variable::next, ast_str_alloca, ast_str_append(), ast_copy_string(), ast_str_buffer(), ast_destroy_realtime(), and ast_variables_destroy().
{
struct ast_variable *var, *head;
struct ast_str *out;
size_t resultslen;
int n;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(family);
AST_APP_ARG(fieldmatch);
AST_APP_ARG(value);
AST_APP_ARG(delim1);
AST_APP_ARG(delim2);
);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Syntax: REALTIME_DESTROY(family,fieldmatch[,value[,delim1[,delim2]]]) - missing argument!\n");
return -1;
}
AST_STANDARD_APP_ARGS(args, data);
if (!args.delim1)
args.delim1 = ",";
if (!args.delim2)
args.delim2 = "=";
if (chan)
ast_autoservice_start(chan);
head = ast_load_realtime_all(args.family, args.fieldmatch, args.value, SENTINEL);
if (!head) {
if (chan)
ast_autoservice_stop(chan);
return -1;
}
resultslen = 0;
n = 0;
for (var = head; var; n++, var = var->next)
resultslen += strlen(var->name) + strlen(var->value);
/* add space for delimiters and final '\0' */
resultslen += n * (strlen(args.delim1) + strlen(args.delim2)) + 1;
out = ast_str_alloca(resultslen);
for (var = head; var; var = var->next) {
ast_str_append(&out, 0, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1);
}
ast_copy_string(buf, ast_str_buffer(out), len);
ast_destroy_realtime(args.family, args.fieldmatch, args.value, SENTINEL);
ast_variables_destroy(head);
if (chan)
ast_autoservice_stop(chan);
return 0;
}
| 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_DECLARE_APP_ARGS, AST_APP_ARG, f, ast_strlen_zero(), ast_log(), LOG_WARNING, ast_autoservice_start(), ast_strdupa, AST_STANDARD_APP_ARGS, ast_store_realtime(), SENTINEL, pbx_builtin_setvar_helper(), and ast_autoservice_stop().
{
int res = 0;
char storeid[32];
char *valcopy;
AST_DECLARE_APP_ARGS(a,
AST_APP_ARG(family);
AST_APP_ARG(f)[30]; /* fields */
);
AST_DECLARE_APP_ARGS(v,
AST_APP_ARG(v)[30]; /* values */
);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Syntax: REALTIME_STORE(family,field1,field2,...,field30) - missing argument!\n");
return -1;
}
if (chan)
ast_autoservice_start(chan);
valcopy = ast_strdupa(value);
AST_STANDARD_APP_ARGS(a, data);
AST_STANDARD_APP_ARGS(v, valcopy);
res = ast_store_realtime(a.family,
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],
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],
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],
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],
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],
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
);
if (res < 0) {
ast_log(LOG_WARNING, "Failed to store. Check the debug log for possible data repository related entries.\n");
} else {
snprintf(storeid, sizeof(storeid), "%d", res);
pbx_builtin_setvar_helper(chan, "RTSTOREID", storeid);
}
if (chan)
ast_autoservice_stop(chan);
return 0;
}
| 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 AST_DECLARE_APP_ARGS, args, AST_APP_ARG, ast_strlen_zero(), ast_log(), LOG_WARNING, ast_autoservice_start(), AST_STANDARD_APP_ARGS, ast_update_realtime(), SENTINEL, and ast_autoservice_stop().
{
int res = 0;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(family);
AST_APP_ARG(fieldmatch);
AST_APP_ARG(value);
AST_APP_ARG(field);
);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Syntax: %s(family,fieldmatch,value,newcol) - missing argument!\n", cmd);
return -1;
}
if (chan)
ast_autoservice_start(chan);
AST_STANDARD_APP_ARGS(args, data);
res = ast_update_realtime(args.family, args.fieldmatch, args.value, args.field, (char *)value, SENTINEL);
if (res < 0) {
ast_log(LOG_WARNING, "Failed to update. Check the debug log for possible data repository related entries.\n");
}
if (chan)
ast_autoservice_stop(chan);
return 0;
}
| static int load_module | ( | void | ) | [static] |
Definition at line 484 of file func_realtime.c.
References ast_custom_function_register.
{
int res = 0;
res |= ast_custom_function_register(&realtime_function);
res |= ast_custom_function_register(&realtime_store_function);
res |= ast_custom_function_register(&realtime_destroy_function);
res |= ast_custom_function_register(&realtimefield_function);
res |= ast_custom_function_register(&realtimehash_function);
return res;
}
| 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 var, ast_str_thread_get(), buf1, buf2, buf3, first, AST_DECLARE_APP_ARGS, args, AST_APP_ARG, value, ast_strlen_zero(), ast_log(), LOG_WARNING, AST_STANDARD_APP_ARGS, ast_autoservice_start(), ast_load_realtime_all(), SENTINEL, ast_autoservice_stop(), ast_str_reset(), ast_variable::next, ast_debug, ast_variable::name, ast_variable::value, ast_copy_string(), ast_str_append(), ast_str_set_escapecommas(), ast_variables_destroy(), pbx_builtin_setvar_helper(), and ast_str_buffer().
{
struct ast_variable *var, *head;
struct ast_str *escapebuf = ast_str_thread_get(&buf1, 16);
struct ast_str *fields = ast_str_thread_get(&buf2, 16);
struct ast_str *values = ast_str_thread_get(&buf3, 16);
int first = 0;
enum { rtfield, rthash } which;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(family);
AST_APP_ARG(fieldmatch);
AST_APP_ARG(value);
AST_APP_ARG(fieldname);
);
if (!strcmp(cmd, "REALTIME_FIELD")) {
which = rtfield;
} else {
which = rthash;
}
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Syntax: %s(family,fieldmatch,value%s) - missing argument!\n", cmd, which == rtfield ? ",fieldname" : "");
return -1;
}
AST_STANDARD_APP_ARGS(args, data);
if ((which == rtfield && args.argc != 4) || (which == rthash && args.argc != 3)) {
ast_log(LOG_WARNING, "Syntax: %s(family,fieldmatch,value%s) - missing argument!\n", cmd, which == rtfield ? ",fieldname" : "");
return -1;
}
if (chan) {
ast_autoservice_start(chan);
}
if (!(head = ast_load_realtime_all(args.family, args.fieldmatch, args.value, SENTINEL))) {
if (chan) {
ast_autoservice_stop(chan);
}
return -1;
}
ast_str_reset(fields);
ast_str_reset(values);
for (var = head; var; var = var->next) {
if (which == rtfield) {
ast_debug(1, "Comparing %s to %s\n", var->name, args.fieldname);
if (!strcasecmp(var->name, args.fieldname)) {
ast_debug(1, "Match! Value is %s\n", var->value);
ast_copy_string(buf, var->value, len);
break;
}
} else if (which == rthash) {
ast_debug(1, "Setting hash key %s to value %s\n", var->name, var->value);
ast_str_append(&fields, 0, "%s%s", first ? "" : ",", ast_str_set_escapecommas(&escapebuf, 0, var->name, INT_MAX));
ast_str_append(&values, 0, "%s%s", first ? "" : ",", ast_str_set_escapecommas(&escapebuf, 0, var->value, INT_MAX));
first = 0;
}
}
ast_variables_destroy(head);
if (which == rthash) {
pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", ast_str_buffer(fields));
ast_copy_string(buf, ast_str_buffer(values), len);
}
if (chan) {
ast_autoservice_stop(chan);
}
return 0;
}
| static int unload_module | ( | void | ) | [static] |
Definition at line 473 of file func_realtime.c.
References ast_custom_function_unregister().
{
int res = 0;
res |= ast_custom_function_unregister(&realtime_function);
res |= ast_custom_function_unregister(&realtime_store_function);
res |= ast_custom_function_unregister(&realtime_destroy_function);
res |= ast_custom_function_unregister(&realtimefield_function);
res |= ast_custom_function_unregister(&realtimehash_function);
return res;
}
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 = "7a1b8b48c852d7a7061c7e499b9bd0d2" , .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(), adsi_status(), adsi_status2(), audiohook_read_frame_both(), iax2_bridge(), realtimefield_read(), gen_prios(), fix_gotos_in_extensions(), realtime_curl(), realtime_multi_curl(), update_curl(), update2_curl(), store_curl(), destroy_curl(), config_curl(), and destroy_pgsql().
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 rpt_exec(), adsi_message(), adsi_status(), adsi_status2(), audiohook_read_frame_both(), read_config(), HandleSelectCodec(), realtimefield_read(), show_dialplan_helper(), gen_prios(), ast_compile_ael2(), realtime_curl(), realtime_multi_curl(), update_curl(), update2_curl(), store_curl(), destroy_curl(), and destroy_pgsql().
struct ast_threadstorage buf3 = { .once = PTHREAD_ONCE_INIT , .key_init = __init_buf3 , .custom_init = NULL , } [static] |
Definition at line 172 of file func_realtime.c.
Referenced by realtimefield_read().
struct ast_custom_function realtime_destroy_function [static] |
{
.name = "REALTIME_DESTROY",
.read = function_realtime_readdestroy,
}
Definition at line 468 of file func_realtime.c.
struct ast_custom_function realtime_function [static] |
{
.name = "REALTIME",
.read = function_realtime_read,
.write = function_realtime_write,
}
Definition at line 446 of file func_realtime.c.
struct ast_custom_function realtime_store_function [static] |
{
.name = "REALTIME_STORE",
.write = function_realtime_store,
}
Definition at line 463 of file func_realtime.c.
struct ast_custom_function realtimefield_function [static] |
{
.name = "REALTIME_FIELD",
.read = realtimefield_read,
.write = function_realtime_write,
}
Definition at line 452 of file func_realtime.c.
struct ast_custom_function realtimehash_function [static] |
{
.name = "REALTIME_HASH",
.read = realtimefield_read,
}
Definition at line 458 of file func_realtime.c.