static int acf_curl_exec(struct ast_channel *chan, const char *cmd, char *info, char *buf, size_t len)
{
- struct ast_module_user *u;
struct MemoryStruct chunk = { NULL, 0 };
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(url);
return -1;
}
- u = ast_module_user_add(chan);
-
AST_STANDARD_APP_ARGS(args, info);
if (!curl_internal(&chunk, args.url, args.postdata)) {
ast_log(LOG_ERROR, "Cannot allocate curl structure\n");
}
- ast_module_user_remove(u);
-
return 0;
}
static int acf_sort_exec(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
{
- struct ast_module_user *u;
int ret = -1;
- u = ast_module_user_add(chan);
-
switch (sort_internal(chan, data, buf, len)) {
case ERROR_NOARG:
ast_log(LOG_ERROR, "SORT() requires an argument\n");
ast_log(LOG_ERROR, "Unknown internal error\n");
}
- ast_module_user_remove(u);
-
return ret;
}
static int acf_cut_exec(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
{
int ret = -1;
- struct ast_module_user *u;
-
- u = ast_module_user_add(chan);
switch (cut_internal(chan, data, buf, len)) {
case ERROR_NOARG:
ast_log(LOG_ERROR, "Unknown internal error\n");
}
- ast_module_user_remove(u);
-
return ret;
}
int res = 0;
char tech[80];
char dest[256] = "", tmp[2] = "", num[AST_MAX_EXTENSION] = "";
- struct ast_module_user *u;
char *s, *p;
unsigned int record = 1;
return -1;
}
- u = ast_module_user_add(chan);
-
ast_copy_string(tech, args.tech ? args.tech : "sip", sizeof(tech));
if (!args.zone)
else
ast_copy_string(buf, dest, len);
- ast_module_user_remove(u);
-
return 0;
}
{
struct enum_result_datastore *erds;
struct ast_datastore *datastore;
- struct ast_module_user *u;
char *parse, tech[128], dest[128];
int res = -1;
AST_APP_ARG(zone);
);
- u = ast_module_user_add(chan);
-
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "ENUMQUERY requires at least a number as an argument...\n");
goto finish;
res = 0;
finish:
- ast_module_user_remove(u);
return res;
}
static int enum_result_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
{
- struct ast_module_user *u;
struct enum_result_datastore *erds;
struct ast_datastore *datastore;
char *parse, *p;
AST_APP_ARG(resultnum);
);
- u = ast_module_user_add(chan);
-
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "ENUMRESULT requires two arguments (id and resultnum)\n");
goto finish;
res = 0;
finish:
- ast_module_user_remove(u);
return res;
}
char tech[80];
char txt[256] = "";
char dest[80];
- struct ast_module_user *u;
buf[0] = '\0';
return -1;
}
- u = ast_module_user_add(chan);
-
res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt,
sizeof(txt));
if (!ast_strlen_zero(txt))
ast_copy_string(buf, txt, len);
- ast_module_user_remove(u);
-
return 0;
}
static int acf_rand_exec(struct ast_channel *chan, const char *cmd,
char *parse, char *buffer, size_t buflen)
{
- struct ast_module_user *u;
int min_int, response_int, max_int;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(min);
AST_APP_ARG(max);
);
- u = ast_module_user_add(chan);
-
AST_STANDARD_APP_ARGS(args, parse);
if (ast_strlen_zero(args.min) || sscanf(args.min, "%d", &min_int) != 1)
ast_debug(1, "%d was the lucky number in range [%d,%d]\n", response_int, min_int, max_int);
snprintf(buffer, buflen, "%d", response_int);
- ast_module_user_remove(u);
-
return 0;
}
static int function_realtime_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
{
struct ast_variable *var, *head;
- struct ast_module_user *u;
struct ast_str *out;
size_t resultslen;
int n;
return -1;
}
- u = ast_module_user_add(chan);
-
AST_STANDARD_APP_ARGS(args, data);
if (!args.delim1)
head = ast_load_realtime_all(args.family, args.fieldmatch, args.value, NULL);
- if (!head) {
- ast_module_user_remove(u);
+ if (!head)
return -1;
- }
+
resultslen = 0;
n = 0;
for (var = head; var; n++, var = var->next)
ast_str_append(&out, 0, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1);
ast_copy_string(buf, out->str, len);
- ast_module_user_remove(u);
-
return 0;
}
static int function_realtime_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
{
- struct ast_module_user *u;
int res = 0;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(family);
return -1;
}
- u = ast_module_user_add(chan);
-
AST_STANDARD_APP_ARGS(args, data);
res = ast_update_realtime(args.family, args.fieldmatch, args.value, args.field, (char *)value, NULL);
ast_log(LOG_WARNING, "Failed to update. Check the debug log for possible data repository related entries.\n");
}
- ast_module_user_remove(u);
-
return 0;
}
static int acf_version_exec(struct ast_channel *chan, const char *cmd,
char *parse, char *buffer, size_t buflen)
{
- struct ast_module_user *u;
char *response_char = ASTERISK_VERSION;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(info);
);
- u = ast_module_user_add(chan);
-
AST_STANDARD_APP_ARGS(args, parse);
if (!ast_strlen_zero(args.info) ) {
ast_debug(1, "VERSION returns %s result, given %s argument\n", response_char, args.info);
snprintf(buffer, buflen, "%s", response_char);
- ast_module_user_remove(u);
-
return 0;
}
static int acf_vmcount_exec(struct ast_channel *chan, const char *cmd, char *argsstr, char *buf, size_t len)
{
- struct ast_module_user *u;
char *context;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(vmbox);
AST_APP_ARG(folder);
);
- u = ast_module_user_add(chan);
-
buf[0] = '\0';
AST_STANDARD_APP_ARGS(args, argsstr);
}
snprintf(buf, len, "%d", ast_app_messagecount(context, args.vmbox, args.folder));
-
- ast_module_user_remove(u);
return 0;
}
const char *syntax; /*!< Syntax description */
int (*read)(struct ast_channel *, const char *, char *, char *, size_t); /*!< Read function, if read is supported */
int (*write)(struct ast_channel *, const char *, char *, const char *); /*!< Write function, if write is supported */
+ struct ast_module *mod; /*!< Module this custom function belongs to */
AST_RWLIST_ENTRY(ast_custom_function) acflist;
};
int ast_custom_function_unregister(struct ast_custom_function *acf);
/*!
- * \brief Reigster a custom function
+ * \brief Register a custom function
*/
-int ast_custom_function_register(struct ast_custom_function *acf);
+#define ast_custom_function_register(acf) ast_custom_function_register2(acf, ast_module_info->self)
+
+/*!
+ * \brief Register a custom function
+ */
+int ast_custom_function_register2(struct ast_custom_function *acf, struct ast_module *mod);
/*!
* \brief Retrieve the number of active calls
return acf ? 0 : -1;
}
-int ast_custom_function_register(struct ast_custom_function *acf)
+int ast_custom_function_register2(struct ast_custom_function *acf, struct ast_module *mod)
{
struct ast_custom_function *cur;
if (!acf)
return -1;
+ acf->mod = mod;
+
AST_RWLIST_WRLOCK(&acf_root);
AST_RWLIST_TRAVERSE(&acf_root, cur, acflist) {
ast_log(LOG_ERROR, "Function %s not registered\n", copy);
else if (!acfptr->read)
ast_log(LOG_ERROR, "Function %s cannot be read\n", copy);
- else
- return acfptr->read(chan, copy, args, workspace, len);
+ else {
+ int res;
+ struct ast_module_user *u = NULL;
+ if (acfptr->mod)
+ u = __ast_module_user_add(acfptr->mod, chan);
+ res = acfptr->read(chan, copy, args, workspace, len);
+ if (acfptr->mod && u)
+ __ast_module_user_remove(acfptr->mod, u);
+ return res;
+ }
return -1;
}
ast_log(LOG_ERROR, "Function %s not registered\n", copy);
else if (!acfptr->write)
ast_log(LOG_ERROR, "Function %s cannot be written to\n", copy);
- else
- return acfptr->write(chan, copy, args, value);
+ else {
+ int res;
+ struct ast_module_user *u = NULL;
+ if (acfptr->mod)
+ u = __ast_module_user_add(acfptr->mod, chan);
+ res = acfptr->write(chan, copy, args, value);
+ if (acfptr->mod && u)
+ __ast_module_user_remove(acfptr->mod, u);
+ return res;
+ }
return -1;
}