79 static int sorcery_function_read(
struct ast_channel *chan,
80 const char *cmd,
char *data,
struct ast_str **buf, ssize_t len)
84 RAII_VAR(
void *, sorcery_obj, NULL, ao2_cleanup);
87 int found, field_number = 1, ix, method;
88 char *separator =
",";
105 if (ast_strlen_zero(parsed_data)) {
106 ast_log(AST_LOG_ERROR,
"Cannot call %s without arguments\n", cmd);
112 if (ast_strlen_zero(args.module_name)) {
113 ast_log(AST_LOG_ERROR,
"Cannot call %s without a module name to query\n", cmd);
117 if (ast_strlen_zero(args.object_type)) {
118 ast_log(AST_LOG_ERROR,
"Cannot call %s with an empty object type\n", cmd);
122 if (ast_strlen_zero(args.object_id)) {
123 ast_log(AST_LOG_ERROR,
"Cannot call %s with an empty object name\n", cmd);
127 if (ast_strlen_zero(args.field_name)) {
128 ast_log(AST_LOG_ERROR,
"Cannot call %s with an empty field name\n", cmd);
132 if (ast_strlen_zero(args.method)) {
135 if (strcmp(args.method,
"concat") == 0) {
137 if (ast_strlen_zero(args.method_arg)) {
140 separator = args.method_arg;
143 }
else if (strcmp(args.method,
"single") == 0) {
145 if (!ast_strlen_zero(args.method_arg)) {
146 if (sscanf(args.method_arg,
"%30d", &field_number) <= 0 || field_number <= 0 ) {
147 ast_log(AST_LOG_ERROR,
"occurrence_number must be a positive integer\n");
152 ast_log(AST_LOG_ERROR,
"Retrieval method must be 'concat' or 'single'\n");
159 ast_log(AST_LOG_ERROR,
"Failed to retrieve sorcery instance for module %s\n", args.module_name);
175 for (it_change_set = change_set; it_change_set; it_change_set = it_change_set->
next) {
177 if (method == CONCAT && strcmp(it_change_set->
name, args.field_name) == 0) {
183 if (method == SINGLE && strcmp(it_change_set->
name, args.field_name) == 0 && ix++ == field_number) {
196 if (method == CONCAT) {
204 .
name =
"AST_SORCERY",
205 .read2 = sorcery_function_read,
208 static int unload_module(
void)
213 static int load_module(
void)
218 AST_MODULE_INFO_STANDARD(
ASTERISK_GPL_KEY,
"Get a field from a sorcery object");
struct ast_variable * next
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
Structure for variables, used for configurations and for channel variables.
Full structure for sorcery.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
char * ast_str_truncate(struct ast_str *buf, ssize_t len)
Truncates the enclosed string to the given length.
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
#define ast_sorcery_unref(sorcery)
Decrease the reference count of a sorcery structure.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Data structure associated with a custom dialplan function.
Core PBX routines and definitions.
Support for dynamic strings.
struct ast_sorcery * ast_sorcery_retrieve_by_module_name(const char *module_name)
Retrieves an existing sorcery instance by module name.
#define ast_sorcery_objectset_create(sorcery, object)
Create an object set (KVP list) for an object.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_custom_function_register(acf)
Register a custom function.
Sorcery Data Access Layer API.
#define AST_APP_ARG(name)
Define an application argument.