24 #include "asterisk/res_pjsip.h"
25 #include "include/res_pjsip_private.h"
30 #include "asterisk/res_pjsip_cli.h"
32 #define DEFAULT_MAX_FORWARDS 70
33 #define DEFAULT_KEEPALIVE_INTERVAL 90
34 #define DEFAULT_USERAGENT_PREFIX "Asterisk PBX"
35 #define DEFAULT_OUTBOUND_ENDPOINT "default_outbound_endpoint"
36 #define DEFAULT_DEBUG "no"
37 #define DEFAULT_ENDPOINT_IDENTIFIER_ORDER "ip,username,anonymous"
38 #define DEFAULT_MAX_INITIAL_QUALIFY_TIME 0
39 #define DEFAULT_FROM_USER "asterisk"
40 #define DEFAULT_REALM "asterisk"
41 #define DEFAULT_REGCONTEXT ""
42 #define DEFAULT_CONTACT_EXPIRATION_CHECK_INTERVAL 30
43 #define DEFAULT_DISABLE_MULTI_DOMAIN 0
44 #define DEFAULT_VOICEMAIL_EXTENSION ""
45 #define DEFAULT_UNIDENTIFIED_REQUEST_COUNT 5
46 #define DEFAULT_UNIDENTIFIED_REQUEST_PERIOD 5
47 #define DEFAULT_UNIDENTIFIED_REQUEST_PRUNE_INTERVAL 30
48 #define DEFAULT_MWI_TPS_QUEUE_HIGH AST_TASKPROCESSOR_HIGH_WATER_LEVEL
49 #define DEFAULT_MWI_TPS_QUEUE_LOW -1
50 #define DEFAULT_MWI_DISABLE_INITIAL_UNSOLICITED 0
51 #define DEFAULT_ALLOW_SENDING_180_AFTER_183 0
52 #define DEFAULT_IGNORE_URI_USER_OPTIONS 0
53 #define DEFAULT_USE_CALLERID_CONTACT 0
54 #define DEFAULT_SEND_CONTACT_STATUS_ON_UPDATE_REGISTRATION 0
55 #define DEFAULT_TASKPROCESSOR_OVERLOAD_TRIGGER TASKPROCESSOR_OVERLOAD_TRIGGER_GLOBAL
56 #define DEFAULT_NOREFERSUB 1
57 #define DEFAULT_ALL_CODECS_ON_EMPTY_REINVITE 0
68 static char default_useragent[256];
71 SORCERY_OBJECT(details);
127 static void global_destructor(
void *obj)
134 static void *global_alloc(
const char *name)
151 static char *previous_regcontext = NULL;
155 char *current = NULL;
157 if (previous_regcontext && !strcmp(previous_regcontext, cfg->regcontext)) {
162 if (!ast_strlen_zero(cfg->regcontext)) {
168 if (ast_sip_persistent_endpoint_add_to_regcontext(cfg->regcontext)) {
174 if (!ast_strlen_zero(previous_regcontext)) {
176 ast_free(previous_regcontext);
177 previous_regcontext = NULL;
181 previous_regcontext = current;
187 static int global_apply(
const struct ast_sorcery *sorcery,
void *obj)
192 if (ast_strlen_zero(cfg->
debug)) {
194 "Global option 'debug' can't be empty. Set it to a valid value or remove the entry to accept 'no' as the default\n");
200 "Global option 'default_from_user' can't be empty. Set it to a valid value or remove the entry to accept 'asterisk' as the default\n");
204 snprintf(max_forwards,
sizeof(max_forwards),
"%u", cfg->
max_forwards);
206 ast_sip_add_global_request_header(
"Max-Forwards", max_forwards, 1);
207 ast_sip_add_global_request_header(
"User-Agent", cfg->useragent, 1);
208 ast_sip_add_global_response_header(
"Server", cfg->useragent, 1);
210 if (check_regcontext(cfg)) {
214 ao2_t_global_obj_replace_unref(global_cfg, cfg,
"Applying global settings");
223 char *ast_sip_global_default_outbound_endpoint(
void)
228 cfg = get_global_cfg();
233 str =
ast_strdup(cfg->default_outbound_endpoint);
238 char *ast_sip_get_debug(
void)
243 cfg = get_global_cfg();
253 char *ast_sip_get_regcontext(
void)
258 cfg = get_global_cfg();
269 char *ast_sip_get_default_voicemail_extension(
void)
274 cfg = get_global_cfg();
276 return ast_strdup(DEFAULT_VOICEMAIL_EXTENSION);
285 char *ast_sip_get_endpoint_identifier_order(
void)
290 cfg = get_global_cfg();
292 return ast_strdup(DEFAULT_ENDPOINT_IDENTIFIER_ORDER);
300 unsigned int ast_sip_get_keep_alive_interval(
void)
302 unsigned int interval;
305 cfg = get_global_cfg();
307 return DEFAULT_KEEPALIVE_INTERVAL;
315 unsigned int ast_sip_get_contact_expiration_check_interval(
void)
317 unsigned int interval;
320 cfg = get_global_cfg();
322 return DEFAULT_CONTACT_EXPIRATION_CHECK_INTERVAL;
330 unsigned int ast_sip_get_disable_multi_domain(
void)
335 cfg = get_global_cfg();
337 return DEFAULT_DISABLE_MULTI_DOMAIN;
345 unsigned int ast_sip_get_max_initial_qualify_time(
void)
350 cfg = get_global_cfg();
352 return DEFAULT_MAX_INITIAL_QUALIFY_TIME;
360 void ast_sip_get_unidentified_request_thresholds(
unsigned int *count,
unsigned int *period,
361 unsigned int *prune_interval)
365 cfg = get_global_cfg();
367 *count = DEFAULT_UNIDENTIFIED_REQUEST_COUNT;
368 *period = DEFAULT_UNIDENTIFIED_REQUEST_PERIOD;
369 *prune_interval = DEFAULT_UNIDENTIFIED_REQUEST_PRUNE_INTERVAL;
381 void ast_sip_get_default_realm(
char *realm,
size_t size)
385 cfg = get_global_cfg();
394 void ast_sip_get_default_from_user(
char *from_user,
size_t size)
398 cfg = get_global_cfg();
408 unsigned int ast_sip_get_mwi_tps_queue_high(
void)
413 cfg = get_global_cfg();
415 return DEFAULT_MWI_TPS_QUEUE_HIGH;
423 int ast_sip_get_mwi_tps_queue_low(
void)
428 cfg = get_global_cfg();
430 return DEFAULT_MWI_TPS_QUEUE_LOW;
438 unsigned int ast_sip_get_mwi_disable_initial_unsolicited(
void)
443 cfg = get_global_cfg();
445 return DEFAULT_MWI_DISABLE_INITIAL_UNSOLICITED;
453 unsigned int ast_sip_get_allow_sending_180_after_183(
void)
458 cfg = get_global_cfg();
460 return DEFAULT_ALLOW_SENDING_180_AFTER_183;
468 unsigned int ast_sip_get_ignore_uri_user_options(
void)
473 cfg = get_global_cfg();
475 return DEFAULT_IGNORE_URI_USER_OPTIONS;
483 unsigned int ast_sip_get_use_callerid_contact(
void)
488 cfg = get_global_cfg();
490 return DEFAULT_USE_CALLERID_CONTACT;
498 unsigned int ast_sip_get_send_contact_status_on_update_registration(
void)
503 cfg = get_global_cfg();
505 return DEFAULT_SEND_CONTACT_STATUS_ON_UPDATE_REGISTRATION;
513 enum ast_sip_taskprocessor_overload_trigger ast_sip_get_taskprocessor_overload_trigger(
void)
515 enum ast_sip_taskprocessor_overload_trigger trigger;
518 cfg = get_global_cfg();
520 return DEFAULT_TASKPROCESSOR_OVERLOAD_TRIGGER;
528 unsigned int ast_sip_get_norefersub(
void)
533 cfg = get_global_cfg();
535 return DEFAULT_NOREFERSUB;
543 unsigned int ast_sip_get_all_codecs_on_empty_reinvite(
void)
548 cfg = get_global_cfg();
550 return DEFAULT_ALL_CODECS_ON_EMPTY_REINVITE;
558 static int overload_trigger_handler(
const struct aco_option *opt,
562 if (!strcasecmp(var->
value,
"none")) {
564 }
else if (!strcasecmp(var->
value,
"global")) {
566 }
else if (!strcasecmp(var->
value,
"pjsip_only")) {
569 ast_log(LOG_WARNING,
"Unknown overload trigger '%s' specified for %s\n",
576 static const char *overload_trigger_map[] = {
577 [TASKPROCESSOR_OVERLOAD_TRIGGER_NONE] =
"none",
578 [TASKPROCESSOR_OVERLOAD_TRIGGER_GLOBAL] =
"global",
579 [TASKPROCESSOR_OVERLOAD_TRIGGER_PJSIP_ONLY] =
"pjsip_only"
582 const char *ast_sip_overload_trigger_to_str(
enum ast_sip_taskprocessor_overload_trigger trigger)
585 overload_trigger_map[trigger] :
"";
588 static int overload_trigger_to_str(
const void *obj,
const intptr_t *args,
char **buf)
604 static void global_loaded_observer(
const char *name,
const struct ast_sorcery *sorcery,
const char *object_type,
int reloaded)
609 if (strcmp(object_type,
"global")) {
624 "At most one pjsip.conf type=global object can be defined. You have %d defined.\n",
633 ast_debug(1,
"No pjsip.conf type=global object exists so applying defaults.\n");
638 global_apply(sorcery, cfg);
658 ast_sip_cli_print_sorcery_objectset(cfg, context, 0);
664 int ast_sip_destroy_sorcery_global(
void)
666 struct ast_sorcery *sorcery = ast_sip_get_sorcery();
670 if (previous_regcontext) {
672 ast_free(previous_regcontext);
675 ao2_t_global_obj_release(global_cfg,
"Module is unloading");
681 int ast_sip_initialize_sorcery_global(
void)
683 struct ast_sorcery *sorcery = ast_sip_get_sorcery();
685 snprintf(default_useragent,
sizeof(default_useragent),
"%s %s",
688 ast_sorcery_apply_default(sorcery,
"global",
"config",
"pjsip.conf,criteria=type=global,single_object=yes,explicit_name=global");
696 __stringify(DEFAULT_MAX_FORWARDS),
701 DEFAULT_OUTBOUND_ENDPOINT,
706 DEFAULT_ENDPOINT_IDENTIFIER_ORDER,
709 __stringify(DEFAULT_KEEPALIVE_INTERVAL),
712 __stringify(DEFAULT_MAX_INITIAL_QUALIFY_TIME),
718 default_voicemail_extension));
722 __stringify(DEFAULT_CONTACT_EXPIRATION_CHECK_INTERVAL),
725 DEFAULT_DISABLE_MULTI_DOMAIN ?
"yes" :
"no",
728 __stringify(DEFAULT_UNIDENTIFIED_REQUEST_COUNT),
731 __stringify(DEFAULT_UNIDENTIFIED_REQUEST_PERIOD),
734 __stringify(DEFAULT_UNIDENTIFIED_REQUEST_PRUNE_INTERVAL),
739 __stringify(DEFAULT_MWI_TPS_QUEUE_HIGH),
742 __stringify(DEFAULT_MWI_TPS_QUEUE_LOW),
745 DEFAULT_MWI_DISABLE_INITIAL_UNSOLICITED ?
"yes" :
"no",
748 DEFAULT_ALLOW_SENDING_180_AFTER_183 ?
"yes" :
"no",
751 DEFAULT_IGNORE_URI_USER_OPTIONS ?
"yes" :
"no",
754 DEFAULT_USE_CALLERID_CONTACT ?
"yes" :
"no",
757 DEFAULT_SEND_CONTACT_STATUS_ON_UPDATE_REGISTRATION ?
"yes" :
"no",
760 overload_trigger_map[DEFAULT_TASKPROCESSOR_OVERLOAD_TRIGGER],
761 overload_trigger_handler, overload_trigger_to_str, NULL, 0, 0);
763 DEFAULT_NOREFERSUB ?
"yes" :
"no",
766 DEFAULT_ALL_CODECS_ON_EMPTY_REINVITE ?
"yes" :
"no",
struct ast_str * output_buffer
unsigned int send_contact_status_on_update_registration
#define ARRAY_IN_BOUNDS(v, a)
Checks to see if value is within the bounds of the given array.
Asterisk main include file. File version handling, generic pbx functions.
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
unsigned int contact_expiration_check_interval
Asterisk version information.
int ast_sorcery_instance_observer_add(struct ast_sorcery *sorcery, const struct ast_sorcery_instance_observer *callbacks)
Add an observer to a sorcery instance.
unsigned int disable_multi_domain
const char * ast_get_version(void)
Retrieve the Asterisk version string.
static int debug
Global debug status.
Structure for variables, used for configurations and for channel variables.
unsigned int keep_alive_interval
Perform no matching, return all objects.
Full structure for sorcery.
Type for a default handler that should do nothing.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
Return all matching objects.
const ast_string_field endpoint_identifier_order
unsigned int unidentified_request_prune_interval
#define ast_strdup(str)
A wrapper for strdup()
CLI Formatter Context passed to all formatters.
enum ast_sip_taskprocessor_overload_trigger overload_trigger
const ast_string_field debug
const ast_string_field default_realm
int ast_context_destroy_by_name(const char *context, const char *registrar)
Destroy a context by name.
unsigned int unidentified_request_count
Type for default option handler for bools (ast_true/ast_false)
const ast_string_field default_voicemail_extension
#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.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
Type for default option handler for unsigned integers.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Interface for the sorcery instance observer.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
Core PBX routines and definitions.
void ast_sorcery_instance_observer_remove(struct ast_sorcery *sorcery, const struct ast_sorcery_instance_observer *callbacks)
Remove an observer from a sorcery instance.
unsigned int max_forwards
unsigned int allow_sending_180_after_183
Type for default option handler for bools (ast_true/ast_false)
Channel datastore data for max forwards.
void * ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id)
Allocate an object.
unsigned int use_callerid_contact
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
unsigned int all_codecs_on_empty_reinvite
An API for managing task processing threads that can be shared across modules.
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.
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
void(* object_type_loaded)(const char *name, const struct ast_sorcery *sorcery, const char *object_type, int reloaded)
Callback after any object_type is loaded/reloaded.
unsigned int ignore_uri_user_options
unsigned int disable_initial_unsolicited
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Type for default option handler for stringfields.
unsigned int unidentified_request_period
unsigned int max_initial_qualify_time
const ast_string_field default_from_user
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
Type for default option handler for signed integers.
#define AO2_GLOBAL_OBJ_STATIC(name)
Define a global object holder to be used to hold an ao2 object, statically initialized.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
unsigned int tps_queue_high
Sorcery Data Access Layer API.