config_global.c File Reference

#include "asterisk.h"
#include <pjsip.h>
#include <pjlib.h>
#include "asterisk/res_pjsip.h"
#include "include/res_pjsip_private.h"
#include "asterisk/sorcery.h"
#include "asterisk/ast_version.h"
#include "asterisk/res_pjsip_cli.h"

Include dependency graph for config_global.c:

Go to the source code of this file.

Data Structures

struct  global_config

Defines

#define DEFAULT_DEBUG   "no"
#define DEFAULT_ENDPOINT_IDENTIFIER_ORDER   "ip,username,anonymous"
#define DEFAULT_KEEPALIVE_INTERVAL   0
#define DEFAULT_MAX_FORWARDS   70
#define DEFAULT_OUTBOUND_ENDPOINT   "default_outbound_endpoint"
#define DEFAULT_USERAGENT_PREFIX   "Asterisk PBX"

Functions

int ast_sip_destroy_sorcery_global (void)
char * ast_sip_get_debug (void)
 Retrieve the system debug setting (yes|no|host).
char * ast_sip_get_endpoint_identifier_order (void)
 Retrieve the global endpoint_identifier_order setting.
unsigned int ast_sip_get_keep_alive_interval (void)
 Retrieve the system keep alive interval setting.
char * ast_sip_global_default_outbound_endpoint (void)
int ast_sip_initialize_sorcery_global (void)
static struct global_configget_global_cfg (void)
static void * global_alloc (const char *name)
static int global_apply (const struct ast_sorcery *sorcery, void *obj)
static void global_destructor (void *obj)
static void global_loaded_observer (const char *name, const struct ast_sorcery *sorcery, const char *object_type, int reloaded)
int sip_cli_print_global (struct ast_sip_cli_context *context)

Variables

static char default_useragent [256]
static struct
ast_sorcery_instance_observer 
observer_callbacks_global


Define Documentation

#define DEFAULT_DEBUG   "no"

Definition at line 34 of file config_global.c.

Referenced by ast_sip_get_debug(), and ast_sip_initialize_sorcery_global().

#define DEFAULT_ENDPOINT_IDENTIFIER_ORDER   "ip,username,anonymous"

#define DEFAULT_KEEPALIVE_INTERVAL   0

Definition at line 31 of file config_global.c.

#define DEFAULT_MAX_FORWARDS   70

Definition at line 30 of file config_global.c.

#define DEFAULT_OUTBOUND_ENDPOINT   "default_outbound_endpoint"

#define DEFAULT_USERAGENT_PREFIX   "Asterisk PBX"

Definition at line 32 of file config_global.c.

Referenced by ast_sip_initialize_sorcery_global().


Function Documentation

int ast_sip_destroy_sorcery_global ( void   ) 

Definition at line 235 of file config_global.c.

References ast_sip_get_sorcery(), ast_sorcery_instance_observer_remove(), and sorcery.

Referenced by ast_res_pjsip_destroy_configuration().

00236 {
00237    struct ast_sorcery *sorcery = ast_sip_get_sorcery();
00238 
00239    ast_sorcery_instance_observer_remove(sorcery, &observer_callbacks_global);
00240 
00241    return 0;
00242 }

char* ast_sip_get_debug ( void   ) 

Retrieve the system debug setting (yes|no|host).

Note:
returned string needs to be de-allocated by caller.
Return values:
the system debug setting.

Definition at line 119 of file config_global.c.

References ao2_ref, ast_strdup, global_config::debug, DEFAULT_DEBUG, and get_global_cfg().

Referenced by check_debug().

00120 {
00121    char *res;
00122    struct global_config *cfg;
00123 
00124    cfg = get_global_cfg();
00125    if (!cfg) {
00126       return ast_strdup(DEFAULT_DEBUG);
00127    }
00128 
00129    res = ast_strdup(cfg->debug);
00130    ao2_ref(cfg, -1);
00131    return res;
00132 }

char* ast_sip_get_endpoint_identifier_order ( void   ) 

Retrieve the global endpoint_identifier_order setting.

Specifies the order by which endpoint identifiers should be regarded.

Return values:
the global endpoint_identifier_order value

Definition at line 134 of file config_global.c.

References ao2_ref, ast_strdup, DEFAULT_ENDPOINT_IDENTIFIER_ORDER, global_config::endpoint_identifier_order, and get_global_cfg().

Referenced by ast_sip_register_endpoint_identifier_with_name().

00135 {
00136    char *res;
00137    struct global_config *cfg;
00138 
00139    cfg = get_global_cfg();
00140    if (!cfg) {
00141       return ast_strdup(DEFAULT_ENDPOINT_IDENTIFIER_ORDER);
00142    }
00143 
00144    res = ast_strdup(cfg->endpoint_identifier_order);
00145    ao2_ref(cfg, -1);
00146    return res;
00147 }

unsigned int ast_sip_get_keep_alive_interval ( void   ) 

Retrieve the system keep alive interval setting.

Return values:
the keep alive interval.

Definition at line 149 of file config_global.c.

References ao2_ref, DEFAULT_KEEPALIVE_INTERVAL, get_global_cfg(), and global_config::keep_alive_interval.

Referenced by keepalive_global_loaded().

00150 {
00151    unsigned int interval;
00152    struct global_config *cfg;
00153 
00154    cfg = get_global_cfg();
00155    if (!cfg) {
00156       return DEFAULT_KEEPALIVE_INTERVAL;
00157    }
00158 
00159    interval = cfg->keep_alive_interval;
00160    ao2_ref(cfg, -1);
00161    return interval;
00162 }

char* ast_sip_global_default_outbound_endpoint ( void   ) 

Definition at line 104 of file config_global.c.

References ao2_ref, ast_strdup, global_config::default_outbound_endpoint, DEFAULT_OUTBOUND_ENDPOINT, get_global_cfg(), and str.

Referenced by ast_sip_default_outbound_endpoint().

00105 {
00106    char *str;
00107    struct global_config *cfg;
00108 
00109    cfg = get_global_cfg();
00110    if (!cfg) {
00111       return ast_strdup(DEFAULT_OUTBOUND_ENDPOINT);
00112    }
00113 
00114    str = ast_strdup(cfg->default_outbound_endpoint);
00115    ao2_ref(cfg, -1);
00116    return str;
00117 }

int ast_sip_initialize_sorcery_global ( void   ) 

Definition at line 244 of file config_global.c.

References __stringify, ast_get_version(), ast_sip_get_sorcery(), ast_sorcery_apply_default, ast_sorcery_instance_observer_add(), ast_sorcery_object_field_register, ast_sorcery_object_register, debug, DEFAULT_DEBUG, DEFAULT_ENDPOINT_IDENTIFIER_ORDER, DEFAULT_KEEPALIVE_INTERVAL, DEFAULT_MAX_FORWARDS, DEFAULT_OUTBOUND_ENDPOINT, default_useragent, DEFAULT_USERAGENT_PREFIX, FLDSET, global_alloc(), global_apply(), NULL, OPT_NOOP_T, OPT_STRINGFIELD_T, OPT_UINT_T, sorcery, and STRFLDSET.

Referenced by ast_res_pjsip_initialize_configuration().

00245 {
00246    struct ast_sorcery *sorcery = ast_sip_get_sorcery();
00247 
00248    snprintf(default_useragent, sizeof(default_useragent), "%s %s",
00249       DEFAULT_USERAGENT_PREFIX, ast_get_version());
00250 
00251    ast_sorcery_apply_default(sorcery, "global", "config", "pjsip.conf,criteria=type=global");
00252 
00253    if (ast_sorcery_object_register(sorcery, "global", global_alloc, NULL, global_apply)) {
00254       return -1;
00255    }
00256 
00257    ast_sorcery_object_field_register(sorcery, "global", "type", "", OPT_NOOP_T, 0, 0);
00258    ast_sorcery_object_field_register(sorcery, "global", "max_forwards",
00259       __stringify(DEFAULT_MAX_FORWARDS),
00260       OPT_UINT_T, 0, FLDSET(struct global_config, max_forwards));
00261    ast_sorcery_object_field_register(sorcery, "global", "user_agent", default_useragent,
00262       OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, useragent));
00263    ast_sorcery_object_field_register(sorcery, "global", "default_outbound_endpoint",
00264       DEFAULT_OUTBOUND_ENDPOINT,
00265       OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, default_outbound_endpoint));
00266    ast_sorcery_object_field_register(sorcery, "global", "debug", DEFAULT_DEBUG,
00267       OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, debug));
00268    ast_sorcery_object_field_register(sorcery, "global", "endpoint_identifier_order",
00269       DEFAULT_ENDPOINT_IDENTIFIER_ORDER,
00270       OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, endpoint_identifier_order));
00271    ast_sorcery_object_field_register(sorcery, "global", "keep_alive_interval",
00272       __stringify(DEFAULT_KEEPALIVE_INTERVAL),
00273       OPT_UINT_T, 0, FLDSET(struct global_config, keep_alive_interval));
00274 
00275    if (ast_sorcery_instance_observer_add(sorcery, &observer_callbacks_global)) {
00276       return -1;
00277    }
00278 
00279    return 0;
00280 }

static struct global_config* get_global_cfg ( void   )  [static, read]

Definition at line 88 of file config_global.c.

References ao2_find, ao2_ref, AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_FLAG_MULTIPLE, ast_sip_get_sorcery(), ast_sorcery_retrieve_by_fields(), globals, and NULL.

Referenced by ast_sip_get_debug(), ast_sip_get_endpoint_identifier_order(), ast_sip_get_keep_alive_interval(), ast_sip_global_default_outbound_endpoint(), and sip_cli_print_global().

00089 {
00090    struct global_config *cfg;
00091    struct ao2_container *globals;
00092 
00093    globals = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "global",
00094       AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
00095    if (!globals) {
00096       return NULL;
00097    }
00098 
00099    cfg = ao2_find(globals, NULL, 0);
00100    ao2_ref(globals, -1);
00101    return cfg;
00102 }

static void* global_alloc ( const char *  name  )  [static]

Definition at line 62 of file config_global.c.

References ao2_cleanup, ast_sorcery_generic_alloc(), ast_string_field_init, global_destructor(), and NULL.

Referenced by ast_sip_initialize_sorcery_global().

00063 {
00064    struct global_config *cfg;
00065 
00066    cfg = ast_sorcery_generic_alloc(sizeof(*cfg), global_destructor);
00067    if (!cfg || ast_string_field_init(cfg, 100)) {
00068       ao2_cleanup(cfg);
00069       return NULL;
00070    }
00071 
00072    return cfg;
00073 }

static int global_apply ( const struct ast_sorcery sorcery,
void *  obj 
) [static]

Definition at line 75 of file config_global.c.

References ast_sip_add_global_request_header(), ast_sip_add_global_response_header(), global_config::max_forwards, and global_config::useragent.

Referenced by ast_sip_initialize_sorcery_global(), and global_loaded_observer().

00076 {
00077    struct global_config *cfg = obj;
00078    char max_forwards[10];
00079 
00080    snprintf(max_forwards, sizeof(max_forwards), "%u", cfg->max_forwards);
00081 
00082    ast_sip_add_global_request_header("Max-Forwards", max_forwards, 1);
00083    ast_sip_add_global_request_header("User-Agent", cfg->useragent, 1);
00084    ast_sip_add_global_response_header("Server", cfg->useragent, 1);
00085    return 0;
00086 }

static void global_destructor ( void *  obj  )  [static]

Definition at line 55 of file config_global.c.

References ast_string_field_free_memory.

Referenced by global_alloc().

00056 {
00057    struct global_config *cfg = obj;
00058 
00059    ast_string_field_free_memory(cfg);
00060 }

static void global_loaded_observer ( const char *  name,
const struct ast_sorcery sorcery,
const char *  object_type,
int  reloaded 
) [static]

Definition at line 175 of file config_global.c.

References ao2_container_count(), ao2_ref, ast_debug, ast_log, AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_FLAG_MULTIPLE, ast_sorcery_alloc(), ast_sorcery_retrieve_by_fields(), global_apply(), globals, LOG_ERROR, and NULL.

00176 {
00177    struct ao2_container *globals;
00178    struct global_config *cfg;
00179 
00180    if (strcmp(object_type, "global")) {
00181       /* Not interested */
00182       return;
00183    }
00184 
00185    globals = ast_sorcery_retrieve_by_fields(sorcery, "global",
00186       AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
00187    if (globals) {
00188       int count;
00189 
00190       count = ao2_container_count(globals);
00191       ao2_ref(globals, -1);
00192 
00193       if (1 < count) {
00194          ast_log(LOG_ERROR,
00195             "At most one pjsip.conf type=global object can be defined.  You have %d defined.\n",
00196             count);
00197          return;
00198       }
00199       if (count) {
00200          return;
00201       }
00202    }
00203 
00204    ast_debug(1, "No pjsip.conf type=global object exists so applying defaults.\n");
00205    cfg = ast_sorcery_alloc(sorcery, "global", NULL);
00206    if (!cfg) {
00207       return;
00208    }
00209    global_apply(sorcery, cfg);
00210    ao2_ref(cfg, -1);
00211 }

int sip_cli_print_global ( struct ast_sip_cli_context context  ) 

Definition at line 217 of file config_global.c.

References ao2_ref, ast_sip_cli_print_sorcery_objectset(), ast_sip_get_sorcery(), ast_sorcery_alloc(), ast_str_append(), get_global_cfg(), NULL, and ast_sip_cli_context::output_buffer.

Referenced by cli_show_settings().

00218 {
00219    struct global_config *cfg = get_global_cfg();
00220 
00221    if (!cfg) {
00222       cfg = ast_sorcery_alloc(ast_sip_get_sorcery(), "global", NULL);
00223       if (!cfg) {
00224          return -1;
00225       }
00226    }
00227 
00228    ast_str_append(&context->output_buffer, 0, "\nGlobal Settings:\n\n");
00229    ast_sip_cli_print_sorcery_objectset(cfg, context, 0);
00230 
00231    ao2_ref(cfg, -1);
00232    return 0;
00233 }


Variable Documentation

char default_useragent[256] [static]

Definition at line 37 of file config_global.c.

Referenced by ast_sip_initialize_sorcery_global().

Initial value:

 {
   .object_type_loaded = global_loaded_observer,
}

Definition at line 213 of file config_global.c.


Generated on Thu Apr 16 06:30:26 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6