Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Macros | Enumerations | Functions | Variables
res_sorcery_realtime.c File Reference

Sorcery Realtime Object Wizard. More...

#include "asterisk.h"
#include <regex.h>
#include "asterisk/module.h"
#include "asterisk/sorcery.h"

Go to the source code of this file.

Data Structures

struct  sorcery_config
 Structure for storing configuration file sourced objects. More...
 

Macros

#define UUID_FIELD   "id"
 They key field used to store the unique identifier for the object.
 

Enumerations

enum  unqualified_fetch { UNQUALIFIED_FETCH_NO, UNQUALIFIED_FETCH_WARN, UNQUALIFIED_FETCH_YES, UNQUALIFIED_FETCH_ERROR }
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static void sorcery_realtime_close (void *data)
 
static int sorcery_realtime_create (const struct ast_sorcery *sorcery, void *data, void *object)
 
static int sorcery_realtime_delete (const struct ast_sorcery *sorcery, void *data, void *object)
 
static struct ast_variablesorcery_realtime_filter_objectset (struct ast_variable *objectset, struct ast_variable **id, const struct ast_sorcery *sorcery, const char *type)
 Internal helper function which returns a filtered objectset. More...
 
static void * sorcery_realtime_open (const char *data)
 
static void * sorcery_realtime_retrieve_fields (const struct ast_sorcery *sorcery, void *data, const char *type, const struct ast_variable *fields)
 
static void * sorcery_realtime_retrieve_id (const struct ast_sorcery *sorcery, void *data, const char *type, const char *id)
 
static void sorcery_realtime_retrieve_multiple (const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const struct ast_variable *fields)
 
static void sorcery_realtime_retrieve_prefix (const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const char *prefix, const size_t prefix_len)
 
static void sorcery_realtime_retrieve_regex (const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const char *regex)
 
static int sorcery_realtime_update (const struct ast_sorcery *sorcery, void *data, void *object)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Sorcery Realtime Object Wizard" , .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, .load_pri = AST_MODPRI_REALTIME_DRIVER, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_sorcery_wizard realtime_object_wizard
 

Detailed Description

Sorcery Realtime Object Wizard.

Author
Joshua Colp jcolp.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file res_sorcery_realtime.c.

Function Documentation

static struct ast_variable* sorcery_realtime_filter_objectset ( struct ast_variable objectset,
struct ast_variable **  id,
const struct ast_sorcery sorcery,
const char *  type 
)
static

Internal helper function which returns a filtered objectset.

The following are filtered out of the objectset:

  • The id field. This is returned to the caller in an out parameter.
  • Fields that are not registered with sorcery.
Parameters
objectsetObjectset to filter.
[out]idThe ID of the sorcery object, as found in the objectset.
sorceryThe sorcery instance that is requesting an objectset.
typeThe object type
Returns
The filtered objectset

Definition at line 111 of file res_sorcery_realtime.c.

References ast_debug, ast_sorcery_get_object_type(), ast_sorcery_is_object_field_registered(), ast_variables_destroy(), ast_sorcery_object_type::name, ast_variable::next, and UUID_FIELD.

113 {
114  struct ast_variable *previous = NULL, *field = objectset;
115  struct ast_sorcery_object_type *object_type;
116 
117  object_type = ast_sorcery_get_object_type(sorcery, type);
118  if (!object_type) {
119  ast_log(LOG_WARNING, "Unknown sorcery object type %s. Expect errors\n", type);
120  /* Continue since we still want to filter out the id */
121  }
122 
123  while (field) {
124  int remove_field = 0;
125  int delete_field = 0;
126 
127  if (!strcmp(field->name, UUID_FIELD)) {
128  *id = field;
129  remove_field = 1;
130  } else if (object_type &&
131  !ast_sorcery_is_object_field_registered(object_type, field->name)) {
132  ast_debug(1, "Filtering out realtime field '%s' from retrieval\n", field->name);
133  remove_field = 1;
134  delete_field = 1;
135  }
136 
137  if (remove_field) {
138  struct ast_variable *removed;
139 
140  if (previous) {
141  previous->next = field->next;
142  } else {
143  objectset = field->next;
144  }
145 
146  removed = field;
147  field = field->next;
148  removed->next = NULL;
149  if (delete_field) {
150  ast_variables_destroy(removed);
151  }
152  } else {
153  previous = field;
154  field = field->next;
155  }
156  }
157 
158  ao2_cleanup(object_type);
159 
160  return objectset;
161 }
struct ast_variable * next
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1262
Structure for variables, used for configurations and for channel variables.
Structure for registered object type.
Definition: sorcery.c:148
#define ast_debug(level,...)
Log a DEBUG message.
struct aco_type type
Type details.
Definition: sorcery.c:177
struct ast_sorcery_object_type * ast_sorcery_get_object_type(const struct ast_sorcery *sorcery, const char *type)
Get the sorcery object type given a type name.
Definition: sorcery.c:2494
int ast_sorcery_is_object_field_registered(const struct ast_sorcery_object_type *object_type, const char *field_name)
Determine if a particular object field has been registered with sorcery.
Definition: sorcery.c:2514
#define UUID_FIELD
They key field used to store the unique identifier for the object.
char name[MAX_OBJECT_TYPE]
Unique name of the object type.
Definition: sorcery.c:150