Asterisk - The Open Source Telephony Project  18.5.0
Functions
general.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

const char * ast_stir_shaken_ca_file (const struct stir_shaken_general *cfg)
 Retrieve the 'ca_file' general configuration option value. More...
 
const char * ast_stir_shaken_ca_path (const struct stir_shaken_general *cfg)
 Retrieve the 'ca_path' general configuration option value. More...
 
unsigned int ast_stir_shaken_cache_max_size (const struct stir_shaken_general *cfg)
 Retrieve the 'cache_max_size' general configuration option value. More...
 
unsigned int ast_stir_shaken_curl_timeout (const struct stir_shaken_general *cfg)
 Retrieve the 'curl_timeout' general configuration option value. More...
 
unsigned int ast_stir_shaken_signature_timeout (const struct stir_shaken_general *cfg)
 Retrieve the 'signature_timeout' general configuration option value. More...
 
struct stir_shaken_generalstir_shaken_general_get (void)
 Retrieve the stir/shaken 'general' configuration object. More...
 
int stir_shaken_general_load (void)
 Load time initialization for the stir/shaken 'general' configuration. More...
 
int stir_shaken_general_unload (void)
 Unload time cleanup for the stir/shaken 'general' configuration. More...
 

Function Documentation

◆ ast_stir_shaken_ca_file()

const char* ast_stir_shaken_ca_file ( const struct stir_shaken_general cfg)

Retrieve the 'ca_file' general configuration option value.

Note
If a NULL configuration is given, then the default value is returned
Parameters
cfgA 'general' configuration object
Return values
The'ca_file' value

Definition at line 72 of file general.c.

References stir_shaken_general::ca_file, and DEFAULT_CA_FILE.

73 {
74  return cfg ? cfg->ca_file : DEFAULT_CA_FILE;
75 }
#define DEFAULT_CA_FILE
Definition: general.c:30
const ast_string_field ca_file
Definition: general.c:43

◆ ast_stir_shaken_ca_path()

const char* ast_stir_shaken_ca_path ( const struct stir_shaken_general cfg)

Retrieve the 'ca_path' general configuration option value.

Note
If a NULL configuration is given, then the default value is returned
Parameters
cfgA 'general' configuration object
Return values
The'ca_path' value

Definition at line 77 of file general.c.

References stir_shaken_general::ca_path, and DEFAULT_CA_PATH.

78 {
79  return cfg ? cfg->ca_path : DEFAULT_CA_PATH;
80 }
#define DEFAULT_CA_PATH
Definition: general.c:31
const ast_string_field ca_path
Definition: general.c:43

◆ ast_stir_shaken_cache_max_size()

unsigned int ast_stir_shaken_cache_max_size ( const struct stir_shaken_general cfg)

Retrieve the 'cache_max_size' general configuration option value.

Note
If a NULL configuration is given, then the default value is returned
Parameters
cfgA 'general' configuration object
Return values
The'cache_max_size' value

Definition at line 82 of file general.c.

References stir_shaken_general::cache_max_size, and DEFAULT_CACHE_MAX_SIZE.

83 {
84  return cfg ? cfg->cache_max_size : DEFAULT_CACHE_MAX_SIZE;
85 }
#define DEFAULT_CACHE_MAX_SIZE
Definition: general.c:32
unsigned int cache_max_size
Definition: general.c:45

◆ ast_stir_shaken_curl_timeout()

unsigned int ast_stir_shaken_curl_timeout ( const struct stir_shaken_general cfg)

Retrieve the 'curl_timeout' general configuration option value.

Note
If a NULL configuration is given, then the default value is returned
Parameters
cfgA 'general' configuration object
Return values
The'curl_timeout' value

Definition at line 87 of file general.c.

References stir_shaken_general::curl_timeout, and DEFAULT_CURL_TIMEOUT.

Referenced by get_curl_instance().

88 {
89  return cfg ? cfg->curl_timeout : DEFAULT_CURL_TIMEOUT;
90 }
unsigned int curl_timeout
Definition: general.c:47
#define DEFAULT_CURL_TIMEOUT
Definition: general.c:33

◆ ast_stir_shaken_signature_timeout()

unsigned int ast_stir_shaken_signature_timeout ( const struct stir_shaken_general cfg)

Retrieve the 'signature_timeout' general configuration option value.

Note
if a NULL configuration is given, then the default value is returned
Parameters
cfgA 'general' configuration object
Return values
The'signature_timeout' value

Definition at line 92 of file general.c.

References DEFAULT_SIGNATURE_TIMEOUT, and stir_shaken_general::signature_timeout.

Referenced by ast_stir_shaken_get_signature_timeout().

93 {
94  return cfg ? cfg->signature_timeout : DEFAULT_SIGNATURE_TIMEOUT;
95 }
unsigned int signature_timeout
Definition: general.c:49
#define DEFAULT_SIGNATURE_TIMEOUT
Definition: general.c:34

◆ stir_shaken_general_get()

struct stir_shaken_general* stir_shaken_general_get ( void  )

Retrieve the stir/shaken 'general' configuration object.

A default configuration object is returned if no configuration was specified. As well, NULL can be returned if there is no configuration, and a problem occurred while loading the defaults.

Note
Object is returned with a reference that the caller is responsible for de-referencing.
Return values
A'general' configuration object, or NULL

Definition at line 54 of file general.c.

References ao2_bump, ao2_cleanup, ao2_container_count(), ao2_find, ao2_ref, AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_FLAG_MULTIPLE, ast_sorcery_retrieve_by_fields(), ast_stir_shaken_sorcery(), CONFIG_TYPE, container, and NULL.

Referenced by ast_stir_shaken_get_signature_timeout(), get_curl_instance(), stir_shaken_general_loaded(), and stir_shaken_general_show().

55 {
56  struct stir_shaken_general *cfg;
57  struct ao2_container *container;
58 
61  if (!container || ao2_container_count(container) == 0) {
62  ao2_cleanup(container);
63  return ao2_bump(default_config);
64  }
65 
66  cfg = ao2_find(container, NULL, 0);
67  ao2_ref(container, -1);
68 
69  return cfg;
70 }
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
Perform no matching, return all objects.
Definition: sorcery.h:123
static struct stir_shaken_general * default_config
Definition: general.c:52
Return all matching objects.
Definition: sorcery.h:120
#define NULL
Definition: resample.c:96
#define CONFIG_TYPE
Definition: general.c:28
#define ao2_bump(obj)
Definition: astobj2.h:491
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ao2_container * container
Definition: res_fax.c:502
struct ast_sorcery * ast_stir_shaken_sorcery(void)
Retrieve the stir/shaken sorcery context.
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
void * ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields)
Retrieve an object or multiple objects using specific fields.
Definition: sorcery.c:1897
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Generic container type.

◆ stir_shaken_general_load()

int stir_shaken_general_load ( void  )

Load time initialization for the stir/shaken 'general' configuration.

Return values
0on success, -1 on error

Definition at line 248 of file general.c.

References __stringify, ARRAY_LEN, ast_cli_register_multiple, ast_log, ast_sorcery_apply_default, ast_sorcery_instance_observer_add(), ast_sorcery_object_field_register, ast_sorcery_object_field_register_custom, ast_sorcery_object_register, ast_stir_shaken_sorcery(), ca_file_to_str(), ca_path_to_str(), stir_shaken_general::cache_max_size, CONFIG_TYPE, stir_shaken_general::curl_timeout, DEFAULT_CA_FILE, DEFAULT_CA_PATH, DEFAULT_CACHE_MAX_SIZE, DEFAULT_CURL_TIMEOUT, DEFAULT_SIGNATURE_TIMEOUT, FLDSET, LOG_ERROR, NULL, on_load_ca_file(), on_load_ca_path(), OPT_NOOP_T, OPT_UINT_T, stir_shaken_general::signature_timeout, sorcery, stir_shaken_general_alloc(), and stir_shaken_general_apply().

Referenced by load_module().

249 {
251 
252  ast_sorcery_apply_default(sorcery, CONFIG_TYPE, "config",
253  "stir_shaken.conf,criteria=type=general,single_object=yes,explicit_name=general");
254 
257  ast_log(LOG_ERROR, "stir/shaken - failed to register '%s' sorcery object\n", CONFIG_TYPE);
258  return -1;
259  }
260 
261  ast_sorcery_object_field_register(sorcery, CONFIG_TYPE, "type", "", OPT_NOOP_T, 0, 0);
266  ast_sorcery_object_field_register(sorcery, CONFIG_TYPE, "cache_max_size",
268  FLDSET(struct stir_shaken_general, cache_max_size));
269  ast_sorcery_object_field_register(sorcery, CONFIG_TYPE, "curl_timeout",
271  FLDSET(struct stir_shaken_general, curl_timeout));
272  ast_sorcery_object_field_register(sorcery, CONFIG_TYPE, "signature_timeout",
274  FLDSET(struct stir_shaken_general, signature_timeout));
275 
277  ast_log(LOG_ERROR, "stir/shaken - failed to register loaded observer for '%s' "
278  "sorcery object type\n", CONFIG_TYPE);
279  return -1;
280  }
281 
284 
285  return 0;
286 }
static int stir_shaken_general_apply(const struct ast_sorcery *sorcery, void *obj)
Definition: general.c:121
#define DEFAULT_CA_FILE
Definition: general.c:30
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_sorcery_instance_observer_add(struct ast_sorcery *sorcery, const struct ast_sorcery_instance_observer *callbacks)
Add an observer to a sorcery instance.
Definition: sorcery.c:520
static int on_load_ca_file(const struct aco_option *opt, struct ast_variable *var, void *obj)
Definition: general.c:188
static int ca_file_to_str(const void *obj, const intptr_t *args, char **buf)
Definition: general.c:201
Full structure for sorcery.
Definition: sorcery.c:230
Type for a default handler that should do nothing.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
static struct ast_cli_entry stir_shaken_general_cli[]
Definition: general.c:184
#define NULL
Definition: resample.c:96
static const struct ast_sorcery_instance_observer stir_shaken_general_observer
Definition: general.c:154
#define CONFIG_TYPE
Definition: general.c:28
#define ast_log
Definition: astobj2.c:42
#define ast_sorcery_object_field_register_custom(sorcery, type, name, default_val, config_handler, sorcery_handler, multiple_handler, flags,...)
Register a field within an object with custom handlers.
Definition: sorcery.h:1005
#define __stringify(x)
Definition: asterisk.h:214
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
static int on_load_ca_path(const struct aco_option *opt, struct ast_variable *var, void *obj)
Definition: general.c:210
Type for default option handler for unsigned integers.
#define DEFAULT_SIGNATURE_TIMEOUT
Definition: general.c:34
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
Definition: sorcery.h:838
#define DEFAULT_CA_PATH
Definition: general.c:31
#define LOG_ERROR
Definition: logger.h:285
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition: sorcery.h:477
static int ca_path_to_str(const void *obj, const intptr_t *args, char **buf)
Definition: general.c:223
static void * stir_shaken_general_alloc(const char *name)
Definition: general.c:104
#define DEFAULT_CURL_TIMEOUT
Definition: general.c:33
struct ast_sorcery * ast_stir_shaken_sorcery(void)
Retrieve the stir/shaken sorcery context.
#define DEFAULT_CACHE_MAX_SIZE
Definition: general.c:32
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
Definition: sorcery.h:955
static struct ast_sorcery * sorcery

◆ stir_shaken_general_unload()

int stir_shaken_general_unload ( void  )

Unload time cleanup for the stir/shaken 'general' configuration.

Return values
0on success, -1 on error

Definition at line 232 of file general.c.

References ao2_ref, ARRAY_LEN, ast_cli_unregister_multiple(), ast_sorcery_instance_observer_remove(), ast_stir_shaken_sorcery(), and NULL.

Referenced by unload_module().

233 {
236 
239 
240  if (default_config) {
241  ao2_ref(default_config, -1);
243  }
244 
245  return 0;
246 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
static struct stir_shaken_general * default_config
Definition: general.c:52
static struct ast_cli_entry stir_shaken_general_cli[]
Definition: general.c:184
#define NULL
Definition: resample.c:96
static const struct ast_sorcery_instance_observer stir_shaken_general_observer
Definition: general.c:154
#define ao2_ref(o, delta)
Definition: astobj2.h:464
void ast_sorcery_instance_observer_remove(struct ast_sorcery *sorcery, const struct ast_sorcery_instance_observer *callbacks)
Remove an observer from a sorcery instance.
Definition: sorcery.c:537
struct ast_sorcery * ast_stir_shaken_sorcery(void)
Retrieve the stir/shaken sorcery context.