38 #include <curl/curl.h>
65 const char *newparam, *newval;
66 char *stringp, *pair, *key;
69 const int EncodeSpecialChars = 1;
72 ast_log(
LOG_ERROR,
"func_curl.so must be loaded in order to use res_config_curl.so!!\n");
86 for (i = 0; (newparam = va_arg(ap,
const char *)); i++) {
87 newval = va_arg(ap,
const char *);
90 ast_str_append(&query, 0,
"%s%s=%s", i > 0 ?
"&" :
"", buf1, buf2);
102 while ((pair =
strsep(&stringp,
"&"))) {
135 struct ast_str *query, *buffer;
137 const char *newparam, *newval;
138 char *stringp, *line, *pair, *key, *initfield = NULL;
140 const int EncodeSpecialChars = 1;
146 ast_log(
LOG_ERROR,
"func_curl.so must be loaded in order to use res_config_curl.so!!\n");
160 for (i = 0; (newparam = va_arg(ap,
const char *)); i++) {
161 newval = va_arg(ap,
const char *);
165 if ((op = strchr(initfield,
' ')))
170 ast_str_append(&query, 0,
"%s%s=%s", i > 0 ?
"&" :
"", buf1, buf2);
184 while ((line =
strsep(&stringp,
"\r\n"))) {
193 while ((pair =
strsep(&line,
"&"))) {
200 if (!strcasecmp(key, initfield) && pair) {
230 static int update_curl(
const char *
url,
const char *unused,
const char *keyfield,
const char *lookup, va_list ap)
232 struct ast_str *query, *buffer;
234 const char *newparam, *newval;
236 int i, rowcount = -1;
237 const int EncodeSpecialChars = 1;
240 ast_log(
LOG_ERROR,
"func_curl.so must be loaded in order to use res_config_curl.so!!\n");
254 ast_str_set(&query, 0,
"${CURL(%s/update?%s=%s,", url, buf1, buf2);
256 for (i = 0; (newparam = va_arg(ap,
const char *)); i++) {
257 newval = va_arg(ap,
const char *);
260 ast_str_append(&query, 0,
"%s%s=%s", i > 0 ?
"&" :
"", buf1, buf2);
268 while (*stringp <=
' ') {
271 sscanf(stringp,
"%30d", &rowcount);
274 return (
int)rowcount;
282 struct ast_str *query, *buffer;
284 const char *newparam, *newval;
286 int rowcount = -1, lookup = 1,
first = 1;
287 const int EncodeSpecialChars = 1;
290 ast_log(
LOG_ERROR,
"func_curl.so must be loaded in order to use res_config_curl.so!!\n");
304 if ((newparam = va_arg(ap,
const char *)) ==
SENTINEL) {
315 newval = va_arg(ap,
const char *);
331 while (*stringp <=
' ') {
334 sscanf(stringp,
"%30d", &rowcount);
337 return (
int)rowcount;
358 struct ast_str *query, *buffer;
360 const char *newparam, *newval;
362 int i, rowcount = -1;
363 const int EncodeSpecialChars = 1;
366 ast_log(
LOG_ERROR,
"func_curl.so must be loaded in order to use res_config_curl.so!!\n");
380 for (i = 0; (newparam = va_arg(ap,
const char *)); i++) {
381 newval = va_arg(ap,
const char *);
384 ast_str_append(&query, 0,
"%s%s=%s", i > 0 ?
"&" :
"", buf1, buf2);
391 while (*stringp <=
' ') {
394 sscanf(stringp,
"%30d", &rowcount);
418 static int destroy_curl(
const char *
url,
const char *unused,
const char *keyfield,
const char *lookup, va_list ap)
420 struct ast_str *query, *buffer;
422 const char *newparam, *newval;
424 int i, rowcount = -1;
425 const int EncodeSpecialChars = 1;
428 ast_log(
LOG_ERROR,
"func_curl.so must be loaded in order to use res_config_curl.so!!\n");
442 ast_str_set(&query, 0,
"${CURL(%s/destroy,%s=%s&", url, buf1, buf2);
444 for (i = 0; (newparam = va_arg(ap,
const char *)); i++) {
445 newval = va_arg(ap,
const char *);
448 ast_str_append(&query, 0,
"%s%s=%s", i > 0 ?
"&" :
"", buf1, buf2);
456 while (*stringp <=
' ') {
459 sscanf(stringp,
"%30d", &rowcount);
462 return (
int)rowcount;
470 struct ast_str *query, *buffer;
471 char *elm, field[256];
472 int type, size, i = 0;
473 const int EncodeSpecialChars = 1;
476 ast_log(
LOG_ERROR,
"func_curl.so must be loaded in order to use res_config_curl.so!!\n");
490 while ((elm = va_arg(ap,
char *))) {
492 size = va_arg(ap,
int);
522 struct ast_str *query, *buffer;
524 char *stringp, *line, *pair, *key;
525 const int EncodeSpecialChars = 1;
526 int last_cat_metric = -1, cat_metric = -1;
529 char *category =
"", *var_name =
"", *var_val =
"";
533 ast_log(
LOG_ERROR,
"func_curl.so must be loaded in order to use res_config_curl.so!!\n");
546 ast_str_set(&query, 0,
"${CURL(%s/static?file=%s)}", url, buf1);
555 while ((line =
strsep(&stringp,
"\r\n"))) {
560 while ((pair =
strsep(&line,
"&"))) {
567 if (!strcasecmp(key,
"category")) {
568 category =
S_OR(pair,
"");
569 }
else if (!strcasecmp(key,
"var_name")) {
570 var_name =
S_OR(pair,
"");
571 }
else if (!strcasecmp(key,
"var_val")) {
572 var_val =
S_OR(pair,
"");
573 }
else if (!strcasecmp(key,
"cat_metric")) {
574 cat_metric = pair ? atoi(pair) : 0;
578 if (!strcmp(var_name,
"#include")) {
583 if (!cat || strcmp(category, cur_cat) || last_cat_metric != cat_metric) {
587 last_cat_metric = cat_metric;
628 if (strncmp(var->
name,
"CURLOPT(", 8)) {
630 snprintf(name,
sizeof(name),
"CURLOPT(%s)", var->
name);
643 ast_verb(1,
"res_config_curl unloaded.\n");
651 ast_log(
LOG_ERROR,
"Cannot load res_curl, so res_config_curl cannot be loaded\n");
658 ast_log(
LOG_ERROR,
"Cannot load func_curl, so res_config_curl cannot be loaded\n");
666 ast_verb(1,
"res_config_curl loaded.\n");
static int reload_module(void)
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
char * strsep(char **str, const char *delims)
enum ast_module_load_result ast_load_resource(const char *resource_name)
Load a module.
static int store_curl(const char *url, const char *unused, va_list ap)
Execute an INSERT query.
void ast_uri_decode(char *s)
Decode URI, URN, URL (overwrite string)
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
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)
struct ast_category * ast_config_get_current_category(const struct ast_config *cfg)
Retrieve the current category name being built.
Structure for variables, used for configurations and for channel variables.
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
Configuration File Parser.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
static struct ast_threadstorage buf2
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
char * ast_uri_encode(const char *string, char *outbuf, int buflen, int do_special_char)
Turn text string to URI-encoded XX version.
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
Definitions to aid in the use of thread local storage.
#define ast_verb(level,...)
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Configuration engine structure, used to define realtime drivers.
int ast_module_check(const char *name)
Check if module with the name given is loaded.
struct ast_category * ast_category_new(const char *name, const char *in_file, int lineno)
Create a category structure.
static struct ast_config * realtime_multi_curl(const char *url, const char *unused, va_list ap)
Excute an Select query and return ast_config list.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
General Asterisk PBX channel definitions.
#define ast_config_load(filename, flags)
Load a config file.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
static struct ast_config_engine curl_engine
static struct ast_threadstorage result_buf
static struct ast_variable * realtime_curl(const char *url, const char *unused, va_list ap)
Execute a curl query and return ast_variable list.
Core PBX routines and definitions.
static int require_curl(const char *url, const char *unused, va_list ap)
#define ast_strdupa(s)
duplicate a string in memory from the stack
struct ast_custom_function * ast_custom_function_find(const char *name)
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
static int destroy_curl(const char *url, const char *unused, const char *keyfield, const char *lookup, va_list ap)
Execute an DELETE query.
struct sla_ringing_trunk * first
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
int ast_config_engine_register(struct ast_config_engine *newconfig)
Register config engine.
static struct ast_threadstorage buf1
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
static int update2_curl(const char *url, const char *unused, va_list ap)
Structure used to handle boolean flags.
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...
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
static int unload_module(void)
struct ast_variable * next
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
void ast_category_append(struct ast_config *config, struct ast_category *cat)
#define CONFIG_STATUS_FILEINVALID
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)
void ast_category_rename(struct ast_category *cat, const char *name)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
require_type
Types used in ast_realtime_require_field.
static int load_module(void)
static int update_curl(const char *url, const char *unused, const char *keyfield, const char *lookup, va_list ap)
Execute an UPDATE query.
struct ast_variable * ast_variable_new(const char *name, const char *value, const char *filename)
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
int ast_config_engine_deregister(struct ast_config_engine *del)
Deregister config engine.
static struct ast_threadstorage query_buf