| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "asterisk.h" |
| 20 |
|
| 21 |
#include <pjsip.h> |
| 22 |
#include <pjlib.h> |
| 23 |
|
| 24 |
#include "asterisk/res_pjsip.h" |
| 25 |
#include "include/res_pjsip_private.h" |
| 26 |
#include "asterisk/pbx.h" |
| 27 |
#include "asterisk/sorcery.h" |
| 28 |
#include "asterisk/taskprocessor.h" |
| 29 |
#include "asterisk/ast_version.h" |
| 30 |
#include "asterisk/res_pjsip_cli.h" |
| 31 |
|
| 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 |
| 58 |
#define DEFAULT_AUTH_ALGORITHMS_UAS "MD5" |
| 59 |
#define DEFAULT_AUTH_ALGORITHMS_UAC "MD5" |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
static AO2_GLOBAL_OBJ_STATIC(global_cfg); |
| 69 |
|
| 70 |
static char default_useragent[256]; |
| 71 |
|
| 72 |
struct global_config { |
| 73 |
SORCERY_OBJECT(details); |
| 74 |
AST_DECLARE_STRING_FIELDS( |
| 75 |
AST_STRING_FIELD(useragent); |
| 76 |
AST_STRING_FIELD(regcontext); |
| 77 |
AST_STRING_FIELD(default_outbound_endpoint); |
| 78 |
|
| 79 |
AST_STRING_FIELD(debug); |
| 80 |
|
| 81 |
AST_STRING_FIELD(endpoint_identifier_order); |
| 82 |
|
| 83 |
AST_STRING_FIELD(default_from_user); |
| 84 |
|
| 85 |
AST_STRING_FIELD(default_voicemail_extension); |
| 86 |
|
| 87 |
AST_STRING_FIELD(default_realm); |
| 88 |
|
| 89 |
AST_STRING_FIELD(default_auth_algorithms_uas); |
| 90 |
|
| 91 |
AST_STRING_FIELD(default_auth_algorithms_uac); |
| 92 |
); |
| 93 |
|
| 94 |
unsigned int max_forwards; |
| 95 |
|
| 96 |
unsigned int keep_alive_interval; |
| 97 |
|
| 98 |
unsigned int max_initial_qualify_time; |
| 99 |
|
| 100 |
unsigned int contact_expiration_check_interval; |
| 101 |
|
| 102 |
unsigned int disable_multi_domain; |
| 103 |
|
| 104 |
unsigned int allow_sending_180_after_183; |
| 105 |
|
| 106 |
unsigned int unidentified_request_count; |
| 107 |
|
| 108 |
unsigned int unidentified_request_period; |
| 109 |
|
| 110 |
unsigned int unidentified_request_prune_interval; |
| 111 |
struct { |
| 112 |
|
| 113 |
unsigned int tps_queue_high; |
| 114 |
|
| 115 |
int tps_queue_low; |
| 116 |
|
| 117 |
unsigned int disable_initial_unsolicited; |
| 118 |
} mwi; |
| 119 |
|
| 120 |
unsigned int ignore_uri_user_options; |
| 121 |
|
| 122 |
unsigned int use_callerid_contact; |
| 123 |
|
| 124 |
unsigned int send_contact_status_on_update_registration; |
| 125 |
|
| 126 |
enum ast_sip_taskprocessor_overload_trigger overload_trigger; |
| 127 |
|
| 128 |
unsigned int norefersub; |
| 129 |
|
| 130 |
unsigned int all_codecs_on_empty_reinvite; |
| 131 |
}; |
| 132 |
|
| 133 |
static void global_destructor(void *obj) |
| 134 |
{ |
| 135 |
struct global_config *cfg = obj; |
| 136 |
|
| 137 |
ast_string_field_free_memory(cfg); |
| 138 |
} |
| 139 |
|
| 140 |
static void *global_alloc(const char *name) |
| 141 |
{ |
| 142 |
struct global_config *cfg; |
| 143 |
|
| 144 |
cfg = ast_sorcery_generic_alloc(sizeof(*cfg), global_destructor); |
| 145 |
if (!cfg || ast_string_field_init(cfg, 100)) { |
| 146 |
ao2_cleanup(cfg); |
| 147 |
return NULL; |
| 148 |
} |
| 149 |
|
| 150 |
return cfg; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
static char *previous_regcontext = NULL; |
| 158 |
|
| 159 |
static int check_regcontext(const struct global_config *cfg) |
| 160 |
{ |
| 161 |
char *current = NULL; |
| 162 |
|
| 163 |
if (previous_regcontext && !strcmp(previous_regcontext, cfg->regcontext)) { |
| 164 |
|
| 165 |
return 0; |
| 166 |
} |
| 167 |
|
| 168 |
if (!ast_strlen_zero(cfg->regcontext)) { |
| 169 |
current = ast_strdup(cfg->regcontext); |
| 170 |
if (!current) { |
| 171 |
return -1; |
| 172 |
} |
| 173 |
|
| 174 |
if (ast_sip_persistent_endpoint_add_to_regcontext(cfg->regcontext)) { |
| 175 |
ast_free(current); |
| 176 |
return -1; |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
if (!ast_strlen_zero(previous_regcontext)) { |
| 181 |
ast_context_destroy_by_name(previous_regcontext, "PJSIP"); |
| 182 |
ast_free(previous_regcontext); |
| 183 |
previous_regcontext = NULL; |
| 184 |
} |
| 185 |
|
| 186 |
if (current) { |
| 187 |
previous_regcontext = current; |
| 188 |
} |
| 189 |
|
| 190 |
return 0; |
| 191 |
} |
| 192 |
|
| 193 |
static int global_apply(const struct ast_sorcery *sorcery, void *obj) |
| 194 |
{ |
| 195 |
struct global_config *cfg = obj; |
| 196 |
char max_forwards[10]; |
| 197 |
struct pjsip_auth_algorithm_type_vector algorithms; |
| 198 |
int res = 0; |
| 199 |
|
| 200 |
if (ast_strlen_zero(cfg->debug)) { |
| 201 |
ast_log(LOG_ERROR, |
| 202 |
"Global option 'debug' can't be empty. Set it to a valid value or remove the entry to accept 'no' as the default\n"); |
| 203 |
return -1; |
| 204 |
} |
| 205 |
|
| 206 |
if (ast_strlen_zero(cfg->default_from_user)) { |
| 207 |
ast_log(LOG_ERROR, |
| 208 |
"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"); |
| 209 |
return -1; |
| 210 |
} |
| 211 |
|
| 212 |
snprintf(max_forwards, sizeof(max_forwards), "%u", cfg->max_forwards); |
| 213 |
|
| 214 |
ast_sip_add_global_request_header("Max-Forwards", max_forwards, 1); |
| 215 |
ast_sip_add_global_request_header("User-Agent", cfg->useragent, 1); |
| 216 |
ast_sip_add_global_response_header("Server", cfg->useragent, 1); |
| 217 |
|
| 218 |
if (check_regcontext(cfg)) { |
| 219 |
return -1; |
| 220 |
} |
| 221 |
|
| 222 |
AST_VECTOR_INIT(&algorithms, 0); |
| 223 |
res = ast_sip_auth_digest_algorithms_vector_init("global", |
| 224 |
&algorithms, "UAS", cfg->default_auth_algorithms_uas); |
| 225 |
AST_VECTOR_FREE(&algorithms); |
| 226 |
if (res) { |
| 227 |
ast_log(LOG_WARNING, "global: Invalid values in default_auth_algorithms_uas. " |
| 228 |
"Defaulting to %s\n", DEFAULT_AUTH_ALGORITHMS_UAS); |
| 229 |
ast_string_field_set(cfg, default_auth_algorithms_uas, DEFAULT_AUTH_ALGORITHMS_UAS); |
| 230 |
} |
| 231 |
AST_VECTOR_INIT(&algorithms, 0); |
| 232 |
res = ast_sip_auth_digest_algorithms_vector_init("global", |
| 233 |
&algorithms, "UAC", cfg->default_auth_algorithms_uac); |
| 234 |
AST_VECTOR_FREE(&algorithms); |
| 235 |
if (res) { |
| 236 |
ast_log(LOG_WARNING, "global: Invalid values in default_auth_algorithms_uac. " |
| 237 |
"Defaulting to %s\n", DEFAULT_AUTH_ALGORITHMS_UAC); |
| 238 |
ast_string_field_set(cfg, default_auth_algorithms_uac, DEFAULT_AUTH_ALGORITHMS_UAC); |
| 239 |
} |
| 240 |
|
| 241 |
ao2_t_global_obj_replace_unref(global_cfg, cfg, "Applying global settings"); |
| 242 |
return 0; |
| 243 |
} |
| 244 |
|
| 245 |
static struct global_config *get_global_cfg(void) |
| 246 |
{ |
| 247 |
return ao2_global_obj_ref(global_cfg); |
| 248 |
} |
| 249 |
|
| 250 |
char *ast_sip_global_default_outbound_endpoint(void) |
| 251 |
{ |
| 252 |
char *str; |
| 253 |
struct global_config *cfg; |
| 254 |
|
| 255 |
cfg = get_global_cfg(); |
| 256 |
if (!cfg) { |
| 257 |
return ast_strdup(DEFAULT_OUTBOUND_ENDPOINT); |
| 258 |
} |
| 259 |
|
| 260 |
str = ast_strdup(cfg->default_outbound_endpoint); |
| 261 |
ao2_ref(cfg, -1); |
| 262 |
return str; |
| 263 |
} |
| 264 |
|
| 265 |
char *ast_sip_get_debug(void) |
| 266 |
{ |
| 267 |
char *res; |
| 268 |
struct global_config *cfg; |
| 269 |
|
| 270 |
cfg = get_global_cfg(); |
| 271 |
if (!cfg) { |
| 272 |
return ast_strdup(DEFAULT_DEBUG); |
| 273 |
} |
| 274 |
|
| 275 |
res = ast_strdup(cfg->debug); |
| 276 |
ao2_ref(cfg, -1); |
| 277 |
return res; |
| 278 |
} |
| 279 |
|
| 280 |
char *ast_sip_get_regcontext(void) |
| 281 |
{ |
| 282 |
char *res; |
| 283 |
struct global_config *cfg; |
| 284 |
|
| 285 |
cfg = get_global_cfg(); |
| 286 |
if (!cfg) { |
| 287 |
return ast_strdup(DEFAULT_REGCONTEXT); |
| 288 |
} |
| 289 |
|
| 290 |
res = ast_strdup(cfg->regcontext); |
| 291 |
ao2_ref(cfg, -1); |
| 292 |
|
| 293 |
return res; |
| 294 |
} |
| 295 |
|
| 296 |
char *ast_sip_get_default_voicemail_extension(void) |
| 297 |
{ |
| 298 |
char *res; |
| 299 |
struct global_config *cfg; |
| 300 |
|
| 301 |
cfg = get_global_cfg(); |
| 302 |
if (!cfg) { |
| 303 |
return ast_strdup(DEFAULT_VOICEMAIL_EXTENSION); |
| 304 |
} |
| 305 |
|
| 306 |
res = ast_strdup(cfg->default_voicemail_extension); |
| 307 |
ao2_ref(cfg, -1); |
| 308 |
|
| 309 |
return res; |
| 310 |
} |
| 311 |
|
| 312 |
char *ast_sip_get_endpoint_identifier_order(void) |
| 313 |
{ |
| 314 |
char *res; |
| 315 |
struct global_config *cfg; |
| 316 |
|
| 317 |
cfg = get_global_cfg(); |
| 318 |
if (!cfg) { |
| 319 |
return ast_strdup(DEFAULT_ENDPOINT_IDENTIFIER_ORDER); |
| 320 |
} |
| 321 |
|
| 322 |
res = ast_strdup(cfg->endpoint_identifier_order); |
| 323 |
ao2_ref(cfg, -1); |
| 324 |
return res; |
| 325 |
} |
| 326 |
|
| 327 |
unsigned int ast_sip_get_keep_alive_interval(void) |
| 328 |
{ |
| 329 |
unsigned int interval; |
| 330 |
struct global_config *cfg; |
| 331 |
|
| 332 |
cfg = get_global_cfg(); |
| 333 |
if (!cfg) { |
| 334 |
return DEFAULT_KEEPALIVE_INTERVAL; |
| 335 |
} |
| 336 |
|
| 337 |
interval = cfg->keep_alive_interval; |
| 338 |
ao2_ref(cfg, -1); |
| 339 |
return interval; |
| 340 |
} |
| 341 |
|
| 342 |
unsigned int ast_sip_get_contact_expiration_check_interval(void) |
| 343 |
{ |
| 344 |
unsigned int interval; |
| 345 |
struct global_config *cfg; |
| 346 |
|
| 347 |
cfg = get_global_cfg(); |
| 348 |
if (!cfg) { |
| 349 |
return DEFAULT_CONTACT_EXPIRATION_CHECK_INTERVAL; |
| 350 |
} |
| 351 |
|
| 352 |
interval = cfg->contact_expiration_check_interval; |
| 353 |
ao2_ref(cfg, -1); |
| 354 |
return interval; |
| 355 |
} |
| 356 |
|
| 357 |
unsigned int ast_sip_get_disable_multi_domain(void) |
| 358 |
{ |
| 359 |
unsigned int disable_multi_domain; |
| 360 |
struct global_config *cfg; |
| 361 |
|
| 362 |
cfg = get_global_cfg(); |
| 363 |
if (!cfg) { |
| 364 |
return DEFAULT_DISABLE_MULTI_DOMAIN; |
| 365 |
} |
| 366 |
|
| 367 |
disable_multi_domain = cfg->disable_multi_domain; |
| 368 |
ao2_ref(cfg, -1); |
| 369 |
return disable_multi_domain; |
| 370 |
} |
| 371 |
|
| 372 |
unsigned int ast_sip_get_max_initial_qualify_time(void) |
| 373 |
{ |
| 374 |
unsigned int time; |
| 375 |
struct global_config *cfg; |
| 376 |
|
| 377 |
cfg = get_global_cfg(); |
| 378 |
if (!cfg) { |
| 379 |
return DEFAULT_MAX_INITIAL_QUALIFY_TIME; |
| 380 |
} |
| 381 |
|
| 382 |
time = cfg->max_initial_qualify_time; |
| 383 |
ao2_ref(cfg, -1); |
| 384 |
return time; |
| 385 |
} |
| 386 |
|
| 387 |
void ast_sip_get_unidentified_request_thresholds(unsigned int *count, unsigned int *period, |
| 388 |
unsigned int *prune_interval) |
| 389 |
{ |
| 390 |
struct global_config *cfg; |
| 391 |
|
| 392 |
cfg = get_global_cfg(); |
| 393 |
if (!cfg) { |
| 394 |
*count = DEFAULT_UNIDENTIFIED_REQUEST_COUNT; |
| 395 |
*period = DEFAULT_UNIDENTIFIED_REQUEST_PERIOD; |
| 396 |
*prune_interval = DEFAULT_UNIDENTIFIED_REQUEST_PRUNE_INTERVAL; |
| 397 |
return; |
| 398 |
} |
| 399 |
|
| 400 |
*count = cfg->unidentified_request_count; |
| 401 |
*period = cfg->unidentified_request_period; |
| 402 |
*prune_interval = cfg->unidentified_request_prune_interval; |
| 403 |
|
| 404 |
ao2_ref(cfg, -1); |
| 405 |
return; |
| 406 |
} |
| 407 |
|
| 408 |
void ast_sip_get_default_realm(char *realm, size_t size) |
| 409 |
{ |
| 410 |
struct global_config *cfg; |
| 411 |
|
| 412 |
cfg = get_global_cfg(); |
| 413 |
if (!cfg) { |
| 414 |
ast_copy_string(realm, DEFAULT_REALM, size); |
| 415 |
} else { |
| 416 |
ast_copy_string(realm, cfg->default_realm, size); |
| 417 |
ao2_ref(cfg, -1); |
| 418 |
} |
| 419 |
} |
| 420 |
|
| 421 |
void ast_sip_get_default_auth_algorithms_uas(char *default_auth_algorithms_uas, size_t size) |
| 422 |
{ |
| 423 |
struct global_config *cfg; |
| 424 |
|
| 425 |
cfg = get_global_cfg(); |
| 426 |
if (!cfg) { |
| 427 |
ast_copy_string(default_auth_algorithms_uas, DEFAULT_AUTH_ALGORITHMS_UAS, size); |
| 428 |
} else { |
| 429 |
ast_copy_string(default_auth_algorithms_uas, cfg->default_auth_algorithms_uas, size); |
| 430 |
ao2_ref(cfg, -1); |
| 431 |
} |
| 432 |
} |
| 433 |
|
| 434 |
void ast_sip_get_default_auth_algorithms_uac(char *default_auth_algorithms_uac, size_t size) |
| 435 |
{ |
| 436 |
struct global_config *cfg; |
| 437 |
|
| 438 |
cfg = get_global_cfg(); |
| 439 |
if (!cfg) { |
| 440 |
ast_copy_string(default_auth_algorithms_uac, DEFAULT_AUTH_ALGORITHMS_UAC, size); |
| 441 |
} else { |
| 442 |
ast_copy_string(default_auth_algorithms_uac, cfg->default_auth_algorithms_uac, size); |
| 443 |
ao2_ref(cfg, -1); |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
void ast_sip_get_default_from_user(char *from_user, size_t size) |
| 448 |
{ |
| 449 |
struct global_config *cfg; |
| 450 |
|
| 451 |
cfg = get_global_cfg(); |
| 452 |
if (!cfg) { |
| 453 |
ast_copy_string(from_user, DEFAULT_FROM_USER, size); |
| 454 |
} else { |
| 455 |
ast_copy_string(from_user, cfg->default_from_user, size); |
| 456 |
ao2_ref(cfg, -1); |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
|
| 461 |
unsigned int ast_sip_get_mwi_tps_queue_high(void) |
| 462 |
{ |
| 463 |
unsigned int tps_queue_high; |
| 464 |
struct global_config *cfg; |
| 465 |
|
| 466 |
cfg = get_global_cfg(); |
| 467 |
if (!cfg) { |
| 468 |
return DEFAULT_MWI_TPS_QUEUE_HIGH; |
| 469 |
} |
| 470 |
|
| 471 |
tps_queue_high = cfg->mwi.tps_queue_high; |
| 472 |
ao2_ref(cfg, -1); |
| 473 |
return tps_queue_high; |
| 474 |
} |
| 475 |
|
| 476 |
int ast_sip_get_mwi_tps_queue_low(void) |
| 477 |
{ |
| 478 |
int tps_queue_low; |
| 479 |
struct global_config *cfg; |
| 480 |
|
| 481 |
cfg = get_global_cfg(); |
| 482 |
if (!cfg) { |
| 483 |
return DEFAULT_MWI_TPS_QUEUE_LOW; |
| 484 |
} |
| 485 |
|
| 486 |
tps_queue_low = cfg->mwi.tps_queue_low; |
| 487 |
ao2_ref(cfg, -1); |
| 488 |
return tps_queue_low; |
| 489 |
} |
| 490 |
|
| 491 |
unsigned int ast_sip_get_mwi_disable_initial_unsolicited(void) |
| 492 |
{ |
| 493 |
unsigned int disable_initial_unsolicited; |
| 494 |
struct global_config *cfg; |
| 495 |
|
| 496 |
cfg = get_global_cfg(); |
| 497 |
if (!cfg) { |
| 498 |
return DEFAULT_MWI_DISABLE_INITIAL_UNSOLICITED; |
| 499 |
} |
| 500 |
|
| 501 |
disable_initial_unsolicited = cfg->mwi.disable_initial_unsolicited; |
| 502 |
ao2_ref(cfg, -1); |
| 503 |
return disable_initial_unsolicited; |
| 504 |
} |
| 505 |
|
| 506 |
unsigned int ast_sip_get_allow_sending_180_after_183(void) |
| 507 |
{ |
| 508 |
unsigned int allow_sending_180_after_183; |
| 509 |
struct global_config *cfg; |
| 510 |
|
| 511 |
cfg = get_global_cfg(); |
| 512 |
if (!cfg) { |
| 513 |
return DEFAULT_ALLOW_SENDING_180_AFTER_183; |
| 514 |
} |
| 515 |
|
| 516 |
allow_sending_180_after_183 = cfg->allow_sending_180_after_183; |
| 517 |
ao2_ref(cfg, -1); |
| 518 |
return allow_sending_180_after_183; |
| 519 |
} |
| 520 |
|
| 521 |
unsigned int ast_sip_get_ignore_uri_user_options(void) |
| 522 |
{ |
| 523 |
unsigned int ignore_uri_user_options; |
| 524 |
struct global_config *cfg; |
| 525 |
|
| 526 |
cfg = get_global_cfg(); |
| 527 |
if (!cfg) { |
| 528 |
return DEFAULT_IGNORE_URI_USER_OPTIONS; |
| 529 |
} |
| 530 |
|
| 531 |
ignore_uri_user_options = cfg->ignore_uri_user_options; |
| 532 |
ao2_ref(cfg, -1); |
| 533 |
return ignore_uri_user_options; |
| 534 |
} |
| 535 |
|
| 536 |
unsigned int ast_sip_get_use_callerid_contact(void) |
| 537 |
{ |
| 538 |
unsigned int use_callerid_contact; |
| 539 |
struct global_config *cfg; |
| 540 |
|
| 541 |
cfg = get_global_cfg(); |
| 542 |
if (!cfg) { |
| 543 |
return DEFAULT_USE_CALLERID_CONTACT; |
| 544 |
} |
| 545 |
|
| 546 |
use_callerid_contact = cfg->use_callerid_contact; |
| 547 |
ao2_ref(cfg, -1); |
| 548 |
return use_callerid_contact; |
| 549 |
} |
| 550 |
|
| 551 |
unsigned int ast_sip_get_send_contact_status_on_update_registration(void) |
| 552 |
{ |
| 553 |
unsigned int send_contact_status_on_update_registration; |
| 554 |
struct global_config *cfg; |
| 555 |
|
| 556 |
cfg = get_global_cfg(); |
| 557 |
if (!cfg) { |
| 558 |
return DEFAULT_SEND_CONTACT_STATUS_ON_UPDATE_REGISTRATION; |
| 559 |
} |
| 560 |
|
| 561 |
send_contact_status_on_update_registration = cfg->send_contact_status_on_update_registration; |
| 562 |
ao2_ref(cfg, -1); |
| 563 |
return send_contact_status_on_update_registration; |
| 564 |
} |
| 565 |
|
| 566 |
enum ast_sip_taskprocessor_overload_trigger ast_sip_get_taskprocessor_overload_trigger(void) |
| 567 |
{ |
| 568 |
enum ast_sip_taskprocessor_overload_trigger trigger; |
| 569 |
struct global_config *cfg; |
| 570 |
|
| 571 |
cfg = get_global_cfg(); |
| 572 |
if (!cfg) { |
| 573 |
return DEFAULT_TASKPROCESSOR_OVERLOAD_TRIGGER; |
| 574 |
} |
| 575 |
|
| 576 |
trigger = cfg->overload_trigger; |
| 577 |
ao2_ref(cfg, -1); |
| 578 |
return trigger; |
| 579 |
} |
| 580 |
|
| 581 |
unsigned int ast_sip_get_norefersub(void) |
| 582 |
{ |
| 583 |
unsigned int norefersub; |
| 584 |
struct global_config *cfg; |
| 585 |
|
| 586 |
cfg = get_global_cfg(); |
| 587 |
if (!cfg) { |
| 588 |
return DEFAULT_NOREFERSUB; |
| 589 |
} |
| 590 |
|
| 591 |
norefersub = cfg->norefersub; |
| 592 |
ao2_ref(cfg, -1); |
| 593 |
return norefersub; |
| 594 |
} |
| 595 |
|
| 596 |
unsigned int ast_sip_get_all_codecs_on_empty_reinvite(void) |
| 597 |
{ |
| 598 |
unsigned int all_codecs_on_empty_reinvite; |
| 599 |
struct global_config *cfg; |
| 600 |
|
| 601 |
cfg = get_global_cfg(); |
| 602 |
if (!cfg) { |
| 603 |
return DEFAULT_ALL_CODECS_ON_EMPTY_REINVITE; |
| 604 |
} |
| 605 |
|
| 606 |
all_codecs_on_empty_reinvite = cfg->all_codecs_on_empty_reinvite; |
| 607 |
ao2_ref(cfg, -1); |
| 608 |
return all_codecs_on_empty_reinvite; |
| 609 |
} |
| 610 |
|
| 611 |
static int overload_trigger_handler(const struct aco_option *opt, |
| 612 |
struct ast_variable *var, void *obj) |
| 613 |
{ |
| 614 |
struct global_config *cfg = obj; |
| 615 |
if (!strcasecmp(var->value, "none")) { |
| 616 |
cfg->overload_trigger = TASKPROCESSOR_OVERLOAD_TRIGGER_NONE; |
| 617 |
} else if (!strcasecmp(var->value, "global")) { |
| 618 |
cfg->overload_trigger = TASKPROCESSOR_OVERLOAD_TRIGGER_GLOBAL; |
| 619 |
} else if (!strcasecmp(var->value, "pjsip_only")) { |
| 620 |
cfg->overload_trigger = TASKPROCESSOR_OVERLOAD_TRIGGER_PJSIP_ONLY; |
| 621 |
} else { |
| 622 |
ast_log(LOG_WARNING, "Unknown overload trigger '%s' specified for %s\n", |
| 623 |
var->value, var->name); |
| 624 |
return -1; |
| 625 |
} |
| 626 |
return 0; |
| 627 |
} |
| 628 |
|
| 629 |
static const char *overload_trigger_map[] = { |
| 630 |
[TASKPROCESSOR_OVERLOAD_TRIGGER_NONE] = "none", |
| 631 |
[TASKPROCESSOR_OVERLOAD_TRIGGER_GLOBAL] = "global", |
| 632 |
[TASKPROCESSOR_OVERLOAD_TRIGGER_PJSIP_ONLY] = "pjsip_only" |
| 633 |
}; |
| 634 |
|
| 635 |
const char *ast_sip_overload_trigger_to_str(enum ast_sip_taskprocessor_overload_trigger trigger) |
| 636 |
{ |
| 637 |
return ARRAY_IN_BOUNDS(trigger, overload_trigger_map) ? |
| 638 |
overload_trigger_map[trigger] : ""; |
| 639 |
} |
| 640 |
|
| 641 |
static int overload_trigger_to_str(const void *obj, const intptr_t *args, char **buf) |
| 642 |
{ |
| 643 |
const struct global_config *cfg = obj; |
| 644 |
*buf = ast_strdup(ast_sip_overload_trigger_to_str(cfg->overload_trigger)); |
| 645 |
return 0; |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
static void global_loaded_observer(const char *name, const struct ast_sorcery *sorcery, const char *object_type, int reloaded) |
| 658 |
{ |
| 659 |
struct ao2_container *globals; |
| 660 |
struct global_config *cfg; |
| 661 |
|
| 662 |
if (strcmp(object_type, "global")) { |
| 663 |
|
| 664 |
return; |
| 665 |
} |
| 666 |
|
| 667 |
globals = ast_sorcery_retrieve_by_fields(sorcery, "global", |
| 668 |
AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL); |
| 669 |
if (globals) { |
| 670 |
int count; |
| 671 |
|
| 672 |
count = ao2_container_count(globals); |
| 673 |
ao2_ref(globals, -1); |
| 674 |
|
| 675 |
if (1 < count) { |
| 676 |
ast_log(LOG_ERROR, |
| 677 |
"At most one pjsip.conf type=global object can be defined. You have %d defined.\n", |
| 678 |
count); |
| 679 |
return; |
| 680 |
} |
| 681 |
if (count) { |
| 682 |
return; |
| 683 |
} |
| 684 |
} |
| 685 |
|
| 686 |
ast_debug(1, "No pjsip.conf type=global object exists so applying defaults.\n"); |
| 687 |
cfg = ast_sorcery_alloc(sorcery, "global", NULL); |
| 688 |
if (!cfg) { |
| 689 |
return; |
| 690 |
} |
| 691 |
global_apply(sorcery, cfg); |
| 692 |
ao2_ref(cfg, -1); |
| 693 |
} |
| 694 |
|
| 695 |
static const struct ast_sorcery_instance_observer observer_callbacks_global = { |
| 696 |
.object_type_loaded = global_loaded_observer, |
| 697 |
}; |
| 698 |
|
| 699 |
int sip_cli_print_global(struct ast_sip_cli_context *context) |
| 700 |
{ |
| 701 |
struct global_config *cfg = get_global_cfg(); |
| 702 |
|
| 703 |
if (!cfg) { |
| 704 |
cfg = ast_sorcery_alloc(ast_sip_get_sorcery(), "global", NULL); |
| 705 |
if (!cfg) { |
| 706 |
return -1; |
| 707 |
} |
| 708 |
} |
| 709 |
|
| 710 |
ast_str_append(&context->output_buffer, 0, "\nGlobal Settings:\n\n"); |
| 711 |
ast_sip_cli_print_sorcery_objectset(cfg, context, 0); |
| 712 |
|
| 713 |
ao2_ref(cfg, -1); |
| 714 |
return 0; |
| 715 |
} |
| 716 |
|
| 717 |
int ast_sip_destroy_sorcery_global(void) |
| 718 |
{ |
| 719 |
struct ast_sorcery *sorcery = ast_sip_get_sorcery(); |
| 720 |
|
| 721 |
ast_sorcery_instance_observer_remove(sorcery, &observer_callbacks_global); |
| 722 |
|
| 723 |
if (previous_regcontext) { |
| 724 |
ast_context_destroy_by_name(previous_regcontext, "PJSIP"); |
| 725 |
ast_free(previous_regcontext); |
| 726 |
} |
| 727 |
|
| 728 |
ao2_t_global_obj_release(global_cfg, "Module is unloading"); |
| 729 |
|
| 730 |
return 0; |
| 731 |
} |
| 732 |
|
| 733 |
|
| 734 |
int ast_sip_initialize_sorcery_global(void) |
| 735 |
{ |
| 736 |
struct ast_sorcery *sorcery = ast_sip_get_sorcery(); |
| 737 |
|
| 738 |
snprintf(default_useragent, sizeof(default_useragent), "%s %s", |
| 739 |
DEFAULT_USERAGENT_PREFIX, ast_get_version()); |
| 740 |
|
| 741 |
ast_sorcery_apply_default(sorcery, "global", "config", "pjsip.conf,criteria=type=global,single_object=yes,explicit_name=global"); |
| 742 |
|
| 743 |
if (ast_sorcery_object_register(sorcery, "global", global_alloc, NULL, global_apply)) { |
| 744 |
return -1; |
| 745 |
} |
| 746 |
|
| 747 |
ast_sorcery_object_field_register(sorcery, "global", "type", "", OPT_NOOP_T, 0, 0); |
| 748 |
ast_sorcery_object_field_register(sorcery, "global", "max_forwards", |
| 749 |
__stringify(DEFAULT_MAX_FORWARDS), |
| 750 |
OPT_UINT_T, 0, FLDSET(struct global_config, max_forwards)); |
| 751 |
ast_sorcery_object_field_register(sorcery, "global", "user_agent", default_useragent, |
| 752 |
OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, useragent)); |
| 753 |
ast_sorcery_object_field_register(sorcery, "global", "default_outbound_endpoint", |
| 754 |
DEFAULT_OUTBOUND_ENDPOINT, |
| 755 |
OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, default_outbound_endpoint)); |
| 756 |
ast_sorcery_object_field_register(sorcery, "global", "debug", DEFAULT_DEBUG, |
| 757 |
OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, debug)); |
| 758 |
ast_sorcery_object_field_register(sorcery, "global", "endpoint_identifier_order", |
| 759 |
DEFAULT_ENDPOINT_IDENTIFIER_ORDER, |
| 760 |
OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, endpoint_identifier_order)); |
| 761 |
ast_sorcery_object_field_register(sorcery, "global", "keep_alive_interval", |
| 762 |
__stringify(DEFAULT_KEEPALIVE_INTERVAL), |
| 763 |
OPT_UINT_T, 0, FLDSET(struct global_config, keep_alive_interval)); |
| 764 |
ast_sorcery_object_field_register(sorcery, "global", "max_initial_qualify_time", |
| 765 |
__stringify(DEFAULT_MAX_INITIAL_QUALIFY_TIME), |
| 766 |
OPT_UINT_T, 0, FLDSET(struct global_config, max_initial_qualify_time)); |
| 767 |
ast_sorcery_object_field_register(sorcery, "global", "default_from_user", DEFAULT_FROM_USER, |
| 768 |
OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, default_from_user)); |
| 769 |
ast_sorcery_object_field_register(sorcery, "global", "default_voicemail_extension", |
| 770 |
DEFAULT_VOICEMAIL_EXTENSION, OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, |
| 771 |
default_voicemail_extension)); |
| 772 |
ast_sorcery_object_field_register(sorcery, "global", "regcontext", DEFAULT_REGCONTEXT, |
| 773 |
OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, regcontext)); |
| 774 |
ast_sorcery_object_field_register(sorcery, "global", "contact_expiration_check_interval", |
| 775 |
__stringify(DEFAULT_CONTACT_EXPIRATION_CHECK_INTERVAL), |
| 776 |
OPT_UINT_T, 0, FLDSET(struct global_config, contact_expiration_check_interval)); |
| 777 |
ast_sorcery_object_field_register(sorcery, "global", "disable_multi_domain", |
| 778 |
DEFAULT_DISABLE_MULTI_DOMAIN ? "yes" : "no", |
| 779 |
OPT_BOOL_T, 1, FLDSET(struct global_config, disable_multi_domain)); |
| 780 |
ast_sorcery_object_field_register(sorcery, "global", "unidentified_request_count", |
| 781 |
__stringify(DEFAULT_UNIDENTIFIED_REQUEST_COUNT), |
| 782 |
OPT_UINT_T, 0, FLDSET(struct global_config, unidentified_request_count)); |
| 783 |
ast_sorcery_object_field_register(sorcery, "global", "unidentified_request_period", |
| 784 |
__stringify(DEFAULT_UNIDENTIFIED_REQUEST_PERIOD), |
| 785 |
OPT_UINT_T, 0, FLDSET(struct global_config, unidentified_request_period)); |
| 786 |
ast_sorcery_object_field_register(sorcery, "global", "unidentified_request_prune_interval", |
| 787 |
__stringify(DEFAULT_UNIDENTIFIED_REQUEST_PRUNE_INTERVAL), |
| 788 |
OPT_UINT_T, 0, FLDSET(struct global_config, unidentified_request_prune_interval)); |
| 789 |
ast_sorcery_object_field_register(sorcery, "global", "default_realm", DEFAULT_REALM, |
| 790 |
OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, default_realm)); |
| 791 |
ast_sorcery_object_field_register(sorcery, "global", "mwi_tps_queue_high", |
| 792 |
__stringify(DEFAULT_MWI_TPS_QUEUE_HIGH), |
| 793 |
OPT_UINT_T, 0, FLDSET(struct global_config, mwi.tps_queue_high)); |
| 794 |
ast_sorcery_object_field_register(sorcery, "global", "mwi_tps_queue_low", |
| 795 |
__stringify(DEFAULT_MWI_TPS_QUEUE_LOW), |
| 796 |
OPT_INT_T, 0, FLDSET(struct global_config, mwi.tps_queue_low)); |
| 797 |
ast_sorcery_object_field_register(sorcery, "global", "mwi_disable_initial_unsolicited", |
| 798 |
DEFAULT_MWI_DISABLE_INITIAL_UNSOLICITED ? "yes" : "no", |
| 799 |
OPT_BOOL_T, 1, FLDSET(struct global_config, mwi.disable_initial_unsolicited)); |
| 800 |
ast_sorcery_object_field_register(sorcery, "global", "allow_sending_180_after_183", |
| 801 |
DEFAULT_ALLOW_SENDING_180_AFTER_183 ? "yes" : "no", |
| 802 |
OPT_BOOL_T, 1, FLDSET(struct global_config, allow_sending_180_after_183)); |
| 803 |
ast_sorcery_object_field_register(sorcery, "global", "ignore_uri_user_options", |
| 804 |
DEFAULT_IGNORE_URI_USER_OPTIONS ? "yes" : "no", |
| 805 |
OPT_BOOL_T, 1, FLDSET(struct global_config, ignore_uri_user_options)); |
| 806 |
ast_sorcery_object_field_register(sorcery, "global", "use_callerid_contact", |
| 807 |
DEFAULT_USE_CALLERID_CONTACT ? "yes" : "no", |
| 808 |
OPT_YESNO_T, 1, FLDSET(struct global_config, use_callerid_contact)); |
| 809 |
ast_sorcery_object_field_register(sorcery, "global", "send_contact_status_on_update_registration", |
| 810 |
DEFAULT_SEND_CONTACT_STATUS_ON_UPDATE_REGISTRATION ? "yes" : "no", |
| 811 |
OPT_YESNO_T, 1, FLDSET(struct global_config, send_contact_status_on_update_registration)); |
| 812 |
ast_sorcery_object_field_register_custom(sorcery, "global", "taskprocessor_overload_trigger", |
| 813 |
overload_trigger_map[DEFAULT_TASKPROCESSOR_OVERLOAD_TRIGGER], |
| 814 |
overload_trigger_handler, overload_trigger_to_str, NULL, 0, 0); |
| 815 |
ast_sorcery_object_field_register(sorcery, "global", "norefersub", |
| 816 |
DEFAULT_NOREFERSUB ? "yes" : "no", |
| 817 |
OPT_YESNO_T, 1, FLDSET(struct global_config, norefersub)); |
| 818 |
ast_sorcery_object_field_register(sorcery, "global", "all_codecs_on_empty_reinvite", |
| 819 |
DEFAULT_ALL_CODECS_ON_EMPTY_REINVITE ? "yes" : "no", |
| 820 |
OPT_BOOL_T, 1, FLDSET(struct global_config, all_codecs_on_empty_reinvite)); |
| 821 |
ast_sorcery_object_field_register(sorcery, "global", "default_auth_algorithms_uas", |
| 822 |
DEFAULT_AUTH_ALGORITHMS_UAS, OPT_STRINGFIELD_T, 0, |
| 823 |
STRFLDSET(struct global_config, default_auth_algorithms_uas)); |
| 824 |
ast_sorcery_object_field_register(sorcery, "global", "default_auth_algorithms_uac", |
| 825 |
DEFAULT_AUTH_ALGORITHMS_UAC, OPT_STRINGFIELD_T, 0, |
| 826 |
STRFLDSET(struct global_config, default_auth_algorithms_uac)); |
| 827 |
|
| 828 |
if (ast_sorcery_instance_observer_add(sorcery, &observer_callbacks_global)) { |
| 829 |
return -1; |
| 830 |
} |
| 831 |
ast_sorcery_load_object(ast_sip_get_sorcery(), "global"); |
| 832 |
|
| 833 |
return 0; |
| 834 |
} |