Asterisk - The Open Source Telephony Project GIT-master-f36a736
Functions | Variables
res_config_curl.c File Reference

curl plugin for portable configuration engine More...

#include "asterisk.h"
#include <curl/curl.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/threadstorage.h"
Include dependency graph for res_config_curl.c:

Go to the source code of this file.

Functions

static void __init_query_buf (void)
 
static void __init_result_buf (void)
 
static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static struct ast_configconfig_curl (const char *url, const char *unused, const char *file, struct ast_config *cfg, struct ast_flags flags, const char *sugg_incl, const char *who_asked)
 
static int destroy_curl (const char *url, const char *unused, const char *keyfield, const char *lookup, const struct ast_variable *fields)
 Execute an DELETE query. More...
 
static int load_module (void)
 
static struct ast_variablerealtime_curl (const char *url, const char *unused, const struct ast_variable *fields)
 Execute a curl query and return ast_variable list. More...
 
static struct ast_configrealtime_multi_curl (const char *url, const char *unused, const struct ast_variable *fields)
 Execute an Select query and return ast_config list. More...
 
static int reload_module (void)
 
static int require_curl (const char *url, const char *unused, va_list ap)
 
static int store_curl (const char *url, const char *unused, const struct ast_variable *fields)
 Execute an INSERT query. More...
 
static int unload_module (void)
 
static int update2_curl (const char *url, const char *unused, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields)
 
static int update_curl (const char *url, const char *unused, const char *keyfield, const char *lookup, const struct ast_variable *fields)
 Execute an UPDATE query. More...
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Realtime Curl configuration" , .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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = AST_MODPRI_REALTIME_DRIVER, .requires = "extconfig,res_curl,func_curl", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_config_engine curl_engine
 
static struct ast_threadstorage query_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_query_buf , .custom_init = NULL , }
 
static struct ast_threadstorage result_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_result_buf , .custom_init = NULL , }
 

Detailed Description

curl plugin for portable configuration engine

Author
Tilghman Lesher res_c.nosp@m.onfi.nosp@m.g_cur.nosp@m.l_v1.nosp@m.@the-.nosp@m.tilg.nosp@m.hman..nosp@m.com

Depends on the CURL library - http://curl.haxx.se/

Definition in file res_config_curl.c.

Function Documentation

◆ __init_query_buf()

static void __init_query_buf ( void  )
static

Definition at line 49 of file res_config_curl.c.

62{

◆ __init_result_buf()

static void __init_result_buf ( void  )
static

Definition at line 50 of file res_config_curl.c.

62{

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 659 of file res_config_curl.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 659 of file res_config_curl.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 659 of file res_config_curl.c.

◆ config_curl()

static struct ast_config * config_curl ( const char *  url,
const char *  unused,
const char *  file,
struct ast_config cfg,
struct ast_flags  flags,
const char *  sugg_incl,
const char *  who_asked 
)
static

Definition at line 515 of file res_config_curl.c.

516{
517 struct ast_str *query, *buffer;
518 char buf1[200];
519 char *stringp, *line, *pair, *key;
520 int last_cat_metric = -1, cat_metric = -1;
521 struct ast_category *cat = NULL;
522 char *cur_cat = "";
523 char *category = "", *var_name = "", *var_val = "";
524 struct ast_flags loader_flags = { 0 };
525
526 if (!ast_custom_function_find("CURL")) {
527 ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
528 return NULL;
529 }
530
531 if (!(query = ast_str_thread_get(&query_buf, 100))) {
532 return NULL;
533 }
534
535 if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
536 return NULL;
537 }
538
540 ast_str_set(&query, 0, "${CURL(%s/static?file=%s)}", url, buf1);
541
542 /* Do the CURL query */
544
545 /* Line oriented output */
546 stringp = ast_str_buffer(buffer);
548
549 while ((line = strsep(&stringp, "\r\n"))) {
550 if (ast_strlen_zero(line)) {
551 continue;
552 }
553
554 while ((pair = strsep(&line, "&"))) {
555 key = strsep(&pair, "=");
557 if (pair) {
559 }
560
561 if (!strcasecmp(key, "category")) {
562 category = S_OR(pair, "");
563 } else if (!strcasecmp(key, "var_name")) {
564 var_name = S_OR(pair, "");
565 } else if (!strcasecmp(key, "var_val")) {
566 var_val = S_OR(pair, "");
567 } else if (!strcasecmp(key, "cat_metric")) {
568 cat_metric = pair ? atoi(pair) : 0;
569 }
570 }
571
572 if (!strcmp(var_name, "#include")) {
573 if (!ast_config_internal_load(var_val, cfg, loader_flags, "", who_asked))
574 return NULL;
575 }
576
577 if (!cat || strcmp(category, cur_cat) || last_cat_metric != cat_metric) {
578 cat = ast_category_new_dynamic(category);
579 if (!cat) {
580 break;
581 }
582 cur_cat = category;
583 last_cat_metric = cat_metric;
584 ast_category_append(cfg, cat);
585 }
586 ast_variable_append(cat, ast_variable_new(var_name, var_val, ""));
587 }
588
589 return cfg;
590}
#define ast_log
Definition: astobj2.c:42
static struct ast_threadstorage buf1
char * strsep(char **str, const char *delims)
void ast_category_append(struct ast_config *config, struct ast_category *category)
Appends a category to a config.
Definition: extconf.c:2833
void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
Definition: extconf.c:1177
#define ast_variable_new(name, value, filename)
struct ast_category * ast_config_get_current_category(const struct ast_config *cfg)
Retrieve the current category name being built.
Definition: extconf.c:2781
struct ast_config * ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked)
Definition: main/config.c:3294
#define ast_category_new_dynamic(name)
Create a category that is not backed by a file.
#define LOG_ERROR
struct ast_custom_function * ast_custom_function_find(const char *name)
Definition: ael_main.c:173
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
static struct ast_threadstorage result_buf
static struct ast_threadstorage query_buf
static char url[512]
#define NULL
Definition: resample.c:96
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1113
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:909
Structure used to handle boolean flags.
Definition: utils.h:199
Support for dynamic strings.
Definition: strings.h:623
char * ast_uri_encode(const char *string, char *outbuf, int buflen, struct ast_flags spec)
Turn text string to URI-encoded XX version.
Definition: utils.c:723
const struct ast_flags ast_uri_http
Definition: utils.c:719
void ast_uri_decode(char *s, struct ast_flags spec)
Decode URI, URN, URL (overwrite string)
Definition: utils.c:762

References ast_category_append(), ast_category_new_dynamic, ast_config_get_current_category(), ast_config_internal_load(), ast_custom_function_find(), ast_log, ast_str_buffer(), ast_str_set(), ast_str_substitute_variables(), ast_str_thread_get(), ast_strlen_zero(), ast_uri_decode(), ast_uri_encode(), ast_uri_http, ast_variable_append(), ast_variable_new, buf1, make_ari_stubs::file, LOG_ERROR, NULL, query_buf, result_buf, S_OR, strsep(), and url.

◆ destroy_curl()

static int destroy_curl ( const char *  url,
const char *  unused,
const char *  keyfield,
const char *  lookup,
const struct ast_variable fields 
)
static

Execute an DELETE query.

Parameters
url
unused
keyfieldwhere clause field
lookupvalue of field for where clause
fieldslist containing one or more field/value set(s)

Delete a row from a database table, prepare the sql statement using keyfield and lookup control the number of records to change. Additional params to match rows are stored in ap list. Sub-in the values to the prepared statement and execute it.

Return values
numberof rows affected
-1on failure

Definition at line 415 of file res_config_curl.c.

416{
417 struct ast_str *query, *buffer;
418 char buf1[200], buf2[200];
419 const struct ast_variable *field;
420 char *stringp;
421 int start = 1, rowcount = -1;
422
423 if (!ast_custom_function_find("CURL")) {
424 ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
425 return -1;
426 }
427
428 if (!(query = ast_str_thread_get(&query_buf, 1000))) {
429 return -1;
430 }
431
432 if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
433 return -1;
434 }
435
436 ast_uri_encode(keyfield, buf1, sizeof(buf1), ast_uri_http);
437 ast_uri_encode(lookup, buf2, sizeof(buf2), ast_uri_http);
438 ast_str_set(&query, 0, "${CURL(%s/destroy,%s=%s&", url, buf1, buf2);
439
440 for (field = fields; field; field = field->next) {
441 ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
442 ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
443 ast_str_append(&query, 0, "%s%s=%s", !start ? "&" : "", buf1, buf2);
444 start = 0;
445 }
446
447 ast_str_append(&query, 0, ")}");
449
450 /* Line oriented output */
451 stringp = ast_str_buffer(buffer);
452 while (*stringp <= ' ') {
453 stringp++;
454 }
455 sscanf(stringp, "%30d", &rowcount);
456
457 if (rowcount >= 0) {
458 return (int)rowcount;
459 }
460
461 return -1;
462}
static struct ast_threadstorage buf2
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1139
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next

References ast_custom_function_find(), ast_log, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_substitute_variables(), ast_str_thread_get(), ast_uri_encode(), ast_uri_http, buf1, buf2, LOG_ERROR, ast_variable::name, ast_variable::next, NULL, query_buf, result_buf, url, and ast_variable::value.

◆ load_module()

static int load_module ( void  )
static

Definition at line 643 of file res_config_curl.c.

644{
646
648
649 return 0;
650}
int ast_config_engine_register(struct ast_config_engine *newconfig)
Register config engine.
Definition: main/config.c:3172
static struct ast_config_engine curl_engine
static int reload_module(void)

References ast_config_engine_register(), curl_engine, and reload_module().

◆ realtime_curl()

static struct ast_variable * realtime_curl ( const char *  url,
const char *  unused,
const struct ast_variable fields 
)
static

Execute a curl query and return ast_variable list.

Parameters
urlThe base URL from which to retrieve data
unusedNot currently used
fieldslist containing one or more field/operator/value set.
Return values
varon success
NULLon failure

Definition at line 61 of file res_config_curl.c.

62{
63 struct ast_str *query, *buffer;
64 char buf1[256], buf2[256];
65 const struct ast_variable *field;
66 char *stringp, *pair, *key;
67 unsigned int start = 1;
68 struct ast_variable *var = NULL, *prev = NULL;
69
70 if (!ast_custom_function_find("CURL")) {
71 ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
72 return NULL;
73 }
74
75 if (!(query = ast_str_thread_get(&query_buf, 16))) {
76 return NULL;
77 }
78
79 if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
80 return NULL;
81 }
82
83 ast_str_set(&query, 0, "${CURL(%s/single,", url);
84
85 for (field = fields; field; field = field->next) {
86 ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
87 ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
88 ast_str_append(&query, 0, "%s%s=%s", !start ? "&" : "", buf1, buf2);
89 start = 0;
90 }
91
92 ast_str_append(&query, 0, ")}");
94
95 /* Remove any trailing newline characters */
96 if ((stringp = strchr(ast_str_buffer(buffer), '\r')) || (stringp = strchr(ast_str_buffer(buffer), '\n'))) {
97 *stringp = '\0';
98 }
99
100 stringp = ast_str_buffer(buffer);
101 while ((pair = strsep(&stringp, "&"))) {
102 key = strsep(&pair, "=");
104 if (pair) {
106 }
107
108 if (!ast_strlen_zero(key)) {
109 if (prev) {
110 prev->next = ast_variable_new(key, S_OR(pair, ""), "");
111 if (prev->next) {
112 prev = prev->next;
113 }
114 } else {
115 prev = var = ast_variable_new(key, S_OR(pair, ""), "");
116 }
117 }
118 }
119
120 return var;
121}
#define var
Definition: ast_expr2f.c:605

References ast_custom_function_find(), ast_log, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_substitute_variables(), ast_str_thread_get(), ast_strlen_zero(), ast_uri_decode(), ast_uri_encode(), ast_uri_http, ast_variable_new, buf1, buf2, LOG_ERROR, ast_variable::name, ast_variable::next, NULL, query_buf, result_buf, S_OR, strsep(), url, ast_variable::value, and var.

◆ realtime_multi_curl()

static struct ast_config * realtime_multi_curl ( const char *  url,
const char *  unused,
const struct ast_variable fields 
)
static

Execute an Select query and return ast_config list.

Parameters
url
unused
fieldslist containing one or more field/operator/value set.
Return values
structast_config pointer on success
NULLon failure

Definition at line 132 of file res_config_curl.c.

133{
134 struct ast_str *query, *buffer;
135 char buf1[256], buf2[256];
136 const struct ast_variable *field;
137 char *stringp, *line, *pair, *key, *initfield = NULL;
138 int start = 1;
139 struct ast_variable *var = NULL;
140 struct ast_config *cfg = NULL;
141 struct ast_category *cat = NULL;
142
143 if (!ast_custom_function_find("CURL")) {
144 ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
145 return NULL;
146 }
147
148 if (!(query = ast_str_thread_get(&query_buf, 16))) {
149 return NULL;
150 }
151
152 if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
153 return NULL;
154 }
155
156 ast_str_set(&query, 0, "${CURL(%s/multi,", url);
157
158 for (field = fields; field; field = field->next) {
159 if (start) {
160 char *op;
161 initfield = ast_strdup(field->name);
162 if ((op = strchr(initfield, ' ')))
163 *op = '\0';
164 }
165 ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
166 ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
167 ast_str_append(&query, 0, "%s%s=%s", !start ? "&" : "", buf1, buf2);
168 start = 0;
169 }
170
171 ast_str_append(&query, 0, ")}");
172
173 /* Do the CURL query */
175
176 if (!(cfg = ast_config_new())) {
177 ast_free(initfield);
178 return NULL;
179 }
180
181 /* Line oriented output */
182 stringp = ast_str_buffer(buffer);
183 while ((line = strsep(&stringp, "\r\n"))) {
184 if (ast_strlen_zero(line)) {
185 continue;
186 }
187
189 if (!cat) {
190 continue;
191 }
192
193 while ((pair = strsep(&line, "&"))) {
194 key = strsep(&pair, "=");
196 if (pair) {
198 }
199
200 if (!strcasecmp(key, initfield) && pair) {
202 }
203
204 if (!ast_strlen_zero(key)) {
205 var = ast_variable_new(key, S_OR(pair, ""), "");
207 }
208 }
209 ast_category_append(cfg, cat);
210 }
211
212 ast_free(initfield);
213
214 return cfg;
215}
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
void ast_category_rename(struct ast_category *cat, const char *name)
Definition: main/config.c:1460
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
Definition: extconf.c:3274
#define ast_category_new_anonymous()
Create a nameless category that is not backed by a file.

References ast_category_append(), ast_category_new_anonymous, ast_category_rename(), ast_config_new(), ast_custom_function_find(), ast_free, ast_log, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_substitute_variables(), ast_str_thread_get(), ast_strdup, ast_strlen_zero(), ast_uri_decode(), ast_uri_encode(), ast_uri_http, ast_variable_append(), ast_variable_new, buf1, buf2, LOG_ERROR, ast_variable::name, ast_variable::next, NULL, query_buf, result_buf, S_OR, strsep(), url, ast_variable::value, and var.

◆ reload_module()

static int reload_module ( void  )
static

Definition at line 604 of file res_config_curl.c.

605{
607 struct ast_config *cfg;
608 struct ast_variable *var;
609
610 if (!(cfg = ast_config_load("res_curl.conf", flags))) {
611 return 0;
612 } else if (cfg == CONFIG_STATUS_FILEINVALID) {
613 ast_log(LOG_WARNING, "res_curl.conf could not be parsed!\n");
614 return 0;
615 }
616
617 if (!(var = ast_variable_browse(cfg, "globals")) && !(var = ast_variable_browse(cfg, "global")) && !(var = ast_variable_browse(cfg, "general"))) {
618 ast_log(LOG_WARNING, "[globals] not found in res_curl.conf\n");
620 return 0;
621 }
622
623 for (; var; var = var->next) {
624 if (strncmp(var->name, "CURLOPT(", 8)) {
625 char name[256];
626 snprintf(name, sizeof(name), "CURLOPT(%s)", var->name);
628 } else {
629 pbx_builtin_setvar_helper(NULL, var->name, var->value);
630 }
631 }
633 return 0;
634}
static const char name[]
Definition: format_mp3.c:68
#define ast_config_load(filename, flags)
Load a config file.
#define CONFIG_STATUS_FILEINVALID
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition: extconf.c:1289
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition: extconf.c:1215
@ CONFIG_FLAG_NOREALTIME
#define LOG_WARNING
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
unsigned int flags
Definition: utils.h:200

References ast_config_destroy(), ast_config_load, ast_log, ast_variable_browse(), CONFIG_FLAG_NOREALTIME, CONFIG_STATUS_FILEINVALID, ast_flags::flags, LOG_WARNING, name, NULL, pbx_builtin_setvar_helper(), and var.

Referenced by load_module().

◆ require_curl()

static int require_curl ( const char *  url,
const char *  unused,
va_list  ap 
)
static

Definition at line 464 of file res_config_curl.c.

465{
466 struct ast_str *query, *buffer;
467 char *elm, field[256];
468 int type, size, i = 0;
469
470 if (!ast_custom_function_find("CURL")) {
471 ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
472 return -1;
473 }
474
475 if (!(query = ast_str_thread_get(&query_buf, 100))) {
476 return -1;
477 }
478
479 if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
480 return -1;
481 }
482
483 ast_str_set(&query, 0, "${CURL(%s/require,", url);
484
485 while ((elm = va_arg(ap, char *))) {
486 type = va_arg(ap, require_type);
487 size = va_arg(ap, int);
488 ast_uri_encode(elm, field, sizeof(field), ast_uri_http);
489 ast_str_append(&query, 0, "%s%s=%s%%3A%d",
490 i > 0 ? "&" : "",
491 field,
492 type == RQ_CHAR ? "char" :
493 type == RQ_INTEGER1 ? "integer1" :
494 type == RQ_UINTEGER1 ? "uinteger1" :
495 type == RQ_INTEGER2 ? "integer2" :
496 type == RQ_UINTEGER2 ? "uinteger2" :
497 type == RQ_INTEGER3 ? "integer3" :
498 type == RQ_UINTEGER3 ? "uinteger3" :
499 type == RQ_INTEGER4 ? "integer4" :
500 type == RQ_UINTEGER4 ? "uinteger4" :
501 type == RQ_INTEGER8 ? "integer8" :
502 type == RQ_UINTEGER8 ? "uinteger8" :
503 type == RQ_DATE ? "date" :
504 type == RQ_DATETIME ? "datetime" :
505 type == RQ_FLOAT ? "float" :
506 "unknown", size);
507 i++;
508 }
509
510 ast_str_append(&query, 0, ")}");
512 return atoi(ast_str_buffer(buffer));
513}
static const char type[]
Definition: chan_ooh323.c:109
require_type
Types used in ast_realtime_require_field.

References ast_custom_function_find(), ast_log, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_substitute_variables(), ast_str_thread_get(), ast_uri_encode(), ast_uri_http, LOG_ERROR, NULL, query_buf, result_buf, RQ_CHAR, RQ_DATE, RQ_DATETIME, RQ_FLOAT, RQ_INTEGER1, RQ_INTEGER2, RQ_INTEGER3, RQ_INTEGER4, RQ_INTEGER8, RQ_UINTEGER1, RQ_UINTEGER2, RQ_UINTEGER3, RQ_UINTEGER4, RQ_UINTEGER8, type, and url.

◆ store_curl()

static int store_curl ( const char *  url,
const char *  unused,
const struct ast_variable fields 
)
static

Execute an INSERT query.

Parameters
url
unused
fieldslist containing one or more field/value set(s)

Insert a new record into database table, prepare the sql statement. All values to be changed are stored in ap list. Sub-in the values to the prepared statement and execute it.

Return values
numberof rows affected
-1on failure

Definition at line 354 of file res_config_curl.c.

355{
356 struct ast_str *query, *buffer;
357 char buf1[256], buf2[256];
358 const struct ast_variable *field;
359 char *stringp;
360 int start = 1, rowcount = -1;
361
362 if (!ast_custom_function_find("CURL")) {
363 ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
364 return -1;
365 }
366
367 if (!(query = ast_str_thread_get(&query_buf, 1000))) {
368 return -1;
369 }
370
371 if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
372 return -1;
373 }
374
375 ast_str_set(&query, 0, "${CURL(%s/store,", url);
376
377 for (field = fields; field; field = field->next) {
378 ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
379 ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
380 ast_str_append(&query, 0, "%s%s=%s", !start ? "&" : "", buf1, buf2);
381 start = 0;
382 }
383
384 ast_str_append(&query, 0, ")}");
386
387 stringp = ast_str_buffer(buffer);
388 while (*stringp <= ' ') {
389 stringp++;
390 }
391 sscanf(stringp, "%30d", &rowcount);
392
393 if (rowcount >= 0) {
394 return rowcount;
395 }
396
397 return -1;
398}

References ast_custom_function_find(), ast_log, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_substitute_variables(), ast_str_thread_get(), ast_uri_encode(), ast_uri_http, buf1, buf2, LOG_ERROR, ast_variable::name, ast_variable::next, NULL, query_buf, result_buf, url, and ast_variable::value.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 636 of file res_config_curl.c.

637{
639
640 return 0;
641}
int ast_config_engine_deregister(struct ast_config_engine *del)
Deregister config engine.
Definition: main/config.c:3188

References ast_config_engine_deregister(), and curl_engine.

◆ update2_curl()

static int update2_curl ( const char *  url,
const char *  unused,
const struct ast_variable lookup_fields,
const struct ast_variable update_fields 
)
static

Definition at line 281 of file res_config_curl.c.

282{
283 struct ast_str *query, *buffer;
284 char buf1[200], buf2[200];
285 const struct ast_variable *field;
286 char *stringp;
287 unsigned int start = 1;
288 int rowcount = -1;
289
290 if (!ast_custom_function_find("CURL")) {
291 ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
292 return -1;
293 }
294
295 if (!(query = ast_str_thread_get(&query_buf, 1000)))
296 return -1;
297
298 if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
299 return -1;
300 }
301
302 ast_str_set(&query, 0, "${CURL(%s/update?", url);
303
304 for (field = lookup_fields; field; field = field->next) {
305 ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
306 ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
307 ast_str_append(&query, 0, "%s%s=%s", !start ? "" : "&", buf1, buf2);
308 start = 0;
309 }
310 ast_str_append(&query, 0, ",");
311 start = 1;
312
313 for (field = update_fields; field; field = field->next) {
314 ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
315 ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
316 ast_str_append(&query, 0, "%s%s=%s", !start ? "" : "&", buf1, buf2);
317 start = 0;
318 }
319
320 ast_str_append(&query, 0, ")}");
321 /* Proxies work, by setting CURLOPT options in the [globals] section of
322 * extensions.conf. Unfortunately, this means preloading pbx_config.so
323 * so that they have an opportunity to be set prior to startup realtime
324 * queries. */
326
327 /* Line oriented output */
328 stringp = ast_str_buffer(buffer);
329 while (*stringp <= ' ') {
330 stringp++;
331 }
332 sscanf(stringp, "%30d", &rowcount);
333
334 if (rowcount >= 0) {
335 return (int)rowcount;
336 }
337
338 return -1;
339}

References ast_custom_function_find(), ast_log, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_substitute_variables(), ast_str_thread_get(), ast_uri_encode(), ast_uri_http, buf1, buf2, LOG_ERROR, ast_variable::name, ast_variable::next, NULL, query_buf, result_buf, url, and ast_variable::value.

◆ update_curl()

static int update_curl ( const char *  url,
const char *  unused,
const char *  keyfield,
const char *  lookup,
const struct ast_variable fields 
)
static

Execute an UPDATE query.

Parameters
url
unused
keyfieldwhere clause field
lookupvalue of field for where clause
fieldslist containing one or more field/value set(s).

Update a database table, prepare the sql statement using keyfield and lookup control the number of records to change. All values to be changed are stored in ap list. Sub-in the values to the prepared statement and execute it.

Return values
numberof rows affected
-1on failure

Definition at line 232 of file res_config_curl.c.

233{
234 struct ast_str *query, *buffer;
235 char buf1[256], buf2[256];
236 const struct ast_variable *field;
237 char *stringp;
238 int start = 1, rowcount = -1;
239
240 if (!ast_custom_function_find("CURL")) {
241 ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
242 return -1;
243 }
244
245 if (!(query = ast_str_thread_get(&query_buf, 16))) {
246 return -1;
247 }
248
249 if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
250 return -1;
251 }
252
253 ast_uri_encode(keyfield, buf1, sizeof(buf1), ast_uri_http);
254 ast_uri_encode(lookup, buf2, sizeof(buf2), ast_uri_http);
255 ast_str_set(&query, 0, "${CURL(%s/update?%s=%s,", url, buf1, buf2);
256
257 for (field = fields; field; field = field->next) {
258 ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
259 ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
260 ast_str_append(&query, 0, "%s%s=%s", !start ? "&" : "", buf1, buf2);
261 start = 0;
262 }
263
264 ast_str_append(&query, 0, ")}");
266
267 /* Line oriented output */
268 stringp = ast_str_buffer(buffer);
269 while (*stringp <= ' ') {
270 stringp++;
271 }
272 sscanf(stringp, "%30d", &rowcount);
273
274 if (rowcount >= 0) {
275 return (int)rowcount;
276 }
277
278 return -1;
279}

References ast_custom_function_find(), ast_log, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_substitute_variables(), ast_str_thread_get(), ast_uri_encode(), ast_uri_http, buf1, buf2, LOG_ERROR, ast_variable::name, ast_variable::next, NULL, query_buf, result_buf, url, and ast_variable::value.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Realtime Curl configuration" , .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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = AST_MODPRI_REALTIME_DRIVER, .requires = "extconfig,res_curl,func_curl", }
static

Definition at line 659 of file res_config_curl.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 659 of file res_config_curl.c.

◆ curl_engine

struct ast_config_engine curl_engine
static

Definition at line 592 of file res_config_curl.c.

Referenced by load_module(), and unload_module().

◆ query_buf

struct ast_threadstorage query_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_query_buf , .custom_init = NULL , }
static

◆ result_buf

struct ast_threadstorage result_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_result_buf , .custom_init = NULL , }
static