38 #include <curl/curl.h> 66 char *stringp, *
pair, *key;
67 unsigned int start = 1;
71 ast_log(
LOG_ERROR,
"func_curl.so must be loaded in order to use res_config_curl.so!!\n");
85 for (field = fields; field; field = field->
next) {
88 ast_str_append(&query, 0,
"%s%s=%s", !start ?
"&" :
"", buf1, buf2);
101 while ((pair =
strsep(&stringp,
"&"))) {
134 struct ast_str *query, *buffer;
137 char *stringp, *line, *
pair, *key, *initfield =
NULL;
144 ast_log(
LOG_ERROR,
"func_curl.so must be loaded in order to use res_config_curl.so!!\n");
158 for (field = fields; field; field = field->
next) {
162 if ((op = strchr(initfield,
' ')))
167 ast_str_append(&query, 0,
"%s%s=%s", !start ?
"&" :
"", buf1, buf2);
183 while ((line =
strsep(&stringp,
"\r\n"))) {
193 while ((pair =
strsep(&line,
"&"))) {
200 if (!strcasecmp(key, initfield) && pair) {
234 struct ast_str *query, *buffer;
238 int start = 1, rowcount = -1;
241 ast_log(
LOG_ERROR,
"func_curl.so must be loaded in order to use res_config_curl.so!!\n");
255 ast_str_set(&query, 0,
"${CURL(%s/update?%s=%s,", url, buf1, buf2);
257 for (field = fields; field; field = field->
next) {
260 ast_str_append(&query, 0,
"%s%s=%s", !start ?
"&" :
"", buf1, buf2);
269 while (*stringp <=
' ') {
272 sscanf(stringp,
"%30d", &rowcount);
275 return (
int)rowcount;
283 struct ast_str *query, *buffer;
287 unsigned int start = 1;
291 ast_log(
LOG_ERROR,
"func_curl.so must be loaded in order to use res_config_curl.so!!\n");
304 for (field = lookup_fields; field; field = field->
next) {
307 ast_str_append(&query, 0,
"%s%s=%s", !start ?
"" :
"&", buf1, buf2);
313 for (field = update_fields; field; field = field->
next) {
316 ast_str_append(&query, 0,
"%s%s=%s", !start ?
"" :
"&", buf1, buf2);
329 while (*stringp <=
' ') {
332 sscanf(stringp,
"%30d", &rowcount);
335 return (
int)rowcount;
356 struct ast_str *query, *buffer;
360 int start = 1, rowcount = -1;
363 ast_log(
LOG_ERROR,
"func_curl.so must be loaded in order to use res_config_curl.so!!\n");
377 for (field = fields; field; field = field->
next) {
380 ast_str_append(&query, 0,
"%s%s=%s", !start ?
"&" :
"", buf1, buf2);
388 while (*stringp <=
' ') {
391 sscanf(stringp,
"%30d", &rowcount);
417 struct ast_str *query, *buffer;
421 int start = 1, rowcount = -1;
424 ast_log(
LOG_ERROR,
"func_curl.so must be loaded in order to use res_config_curl.so!!\n");
438 ast_str_set(&query, 0,
"${CURL(%s/destroy,%s=%s&", url, buf1, buf2);
440 for (field = fields; field; field = field->
next) {
443 ast_str_append(&query, 0,
"%s%s=%s", !start ?
"&" :
"", buf1, buf2);
452 while (*stringp <=
' ') {
455 sscanf(stringp,
"%30d", &rowcount);
458 return (
int)rowcount;
466 struct ast_str *query, *buffer;
467 char *elm, field[256];
468 int type, size, i = 0;
471 ast_log(
LOG_ERROR,
"func_curl.so must be loaded in order to use res_config_curl.so!!\n");
485 while ((elm = va_arg(ap,
char *))) {
487 size = va_arg(ap,
int);
517 struct ast_str *query, *buffer;
519 char *stringp, *line, *
pair, *key;
520 int last_cat_metric = -1, cat_metric = -1;
523 char *category =
"", *var_name =
"", *var_val =
"";
527 ast_log(
LOG_ERROR,
"func_curl.so must be loaded in order to use res_config_curl.so!!\n");
540 ast_str_set(&query, 0,
"${CURL(%s/static?file=%s)}", url, buf1);
549 while ((line =
strsep(&stringp,
"\r\n"))) {
554 while ((pair =
strsep(&line,
"&"))) {
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;
572 if (!strcmp(var_name,
"#include")) {
577 if (!cat || strcmp(category, cur_cat) || last_cat_metric != cat_metric) {
583 last_cat_metric = cat_metric;
624 if (strncmp(var->
name,
"CURLOPT(", 8)) {
626 snprintf(name,
sizeof(name),
"CURLOPT(%s)", var->
name);
658 .requires =
"extconfig,res_curl,func_curl",
void ast_uri_decode(char *s, struct ast_flags spec)
Decode URI, URN, URL (overwrite string)
struct ast_variable * next
static int reload_module(void)
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
require_type
Types used in ast_realtime_require_field.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
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.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
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)
#define CONFIG_STATUS_FILEINVALID
static struct ast_config * realtime_multi_curl(const char *url, const char *unused, const struct ast_variable *fields)
Excute an Select query and return ast_config list.
Structure for variables, used for configurations and for channel variables.
char * ast_uri_encode(const char *string, char *outbuf, int buflen, struct ast_flags spec)
Turn text string to URI-encoded XX version.
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
int ast_config_engine_deregister(struct ast_config_engine *del)
Deregister config engine.
struct ast_category * ast_config_get_current_category(const struct ast_config *cfg)
Retrieve the current category name being built.
int ast_config_engine_register(struct ast_config_engine *newconfig)
Register config engine.
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_strdup(str)
A wrapper for strdup()
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.
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)
Configuration engine structure, used to define realtime drivers.
static struct ast_variable * realtime_curl(const char *url, const char *unused, const struct ast_variable *fields)
Execute a curl query and return ast_variable list.
#define ast_strlen_zero(foo)
#define ast_category_new_anonymous()
Create a nameless category that is not backed by a file.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Configuration File Parser.
void ast_category_rename(struct ast_category *cat, const char *name)
#define ast_config_load(filename, flags)
Load a config file.
General Asterisk PBX channel definitions.
static struct ast_config_engine curl_engine
void ast_config_destroy(struct ast_config *config)
Destroys a config.
static struct ast_threadstorage result_buf
#define ast_variable_new(name, value, filename)
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
Core PBX routines and definitions.
static int require_curl(const char *url, const char *unused, va_list ap)
static int update2_curl(const char *url, const char *unused, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields)
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 ...
static struct ast_threadstorage buf1
static int store_curl(const char *url, const char *unused, const struct ast_variable *fields)
Execute an INSERT query.
#define ast_category_new_dynamic(name)
Create a category that is not backed by a file.
Structure used to handle boolean flags.
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
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...
void ast_category_append(struct ast_config *config, struct ast_category *cat)
Appends a category to a config.
char * strsep(char **str, const char *delims)
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.
#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)
const struct ast_flags ast_uri_http
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
static int load_module(void)
static struct ast_threadstorage query_buf