| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
#include "asterisk.h" |
| 292 |
|
| 293 |
#include "parking/res_parking.h" |
| 294 |
#include "asterisk/config.h" |
| 295 |
#include "asterisk/config_options.h" |
| 296 |
#include "asterisk/utils.h" |
| 297 |
#include "asterisk/module.h" |
| 298 |
#include "asterisk/cli.h" |
| 299 |
#include "asterisk/astobj2.h" |
| 300 |
#include "asterisk/features.h" |
| 301 |
#include "asterisk/manager.h" |
| 302 |
#include "asterisk/pbx.h" |
| 303 |
|
| 304 |
static int parking_lot_sort_fn(const void *obj_left, const void *obj_right, int flags) |
| 305 |
{ |
| 306 |
const struct parking_lot *left = obj_left; |
| 307 |
const struct parking_lot *right = obj_right; |
| 308 |
const char *right_key = obj_right; |
| 309 |
int cmp; |
| 310 |
|
| 311 |
switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) { |
| 312 |
default: |
| 313 |
case OBJ_POINTER: |
| 314 |
right_key = right->name; |
| 315 |
|
| 316 |
case OBJ_KEY: |
| 317 |
cmp = strcmp(left->name, right_key); |
| 318 |
break; |
| 319 |
case OBJ_PARTIAL_KEY: |
| 320 |
cmp = strncmp(left->name, right_key, strlen(right_key)); |
| 321 |
} |
| 322 |
return cmp; |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
static struct ao2_container *parking_lot_container; |
| 327 |
|
| 328 |
static void *parking_config_alloc(void); |
| 329 |
|
| 330 |
static void *parking_lot_cfg_alloc(const char *cat); |
| 331 |
static void *named_item_find(struct ao2_container *container, const char *name); |
| 332 |
|
| 333 |
static int config_parking_preapply(void); |
| 334 |
static void link_configured_disable_marked_lots(void); |
| 335 |
|
| 336 |
struct parking_global_config { |
| 337 |
int parkeddynamic; |
| 338 |
}; |
| 339 |
|
| 340 |
struct parking_config { |
| 341 |
struct parking_global_config *global; |
| 342 |
struct ao2_container *parking_lots; |
| 343 |
}; |
| 344 |
|
| 345 |
static struct aco_type global_option = { |
| 346 |
.type = ACO_GLOBAL, |
| 347 |
.name = "globals", |
| 348 |
.item_offset = offsetof(struct parking_config, global), |
| 349 |
.category_match = ACO_WHITELIST_EXACT, |
| 350 |
.category = "general", |
| 351 |
}; |
| 352 |
|
| 353 |
struct aco_type *global_options[] = ACO_TYPES(&global_option); |
| 354 |
|
| 355 |
static struct aco_type parking_lot_type = { |
| 356 |
.type = ACO_ITEM, |
| 357 |
.name = "parking_lot", |
| 358 |
.category_match = ACO_BLACKLIST_EXACT, |
| 359 |
.category = "general", |
| 360 |
.item_alloc = parking_lot_cfg_alloc, |
| 361 |
.item_find = named_item_find, |
| 362 |
.item_offset = offsetof(struct parking_config, parking_lots), |
| 363 |
}; |
| 364 |
|
| 365 |
struct aco_type *parking_lot_types[] = ACO_TYPES(&parking_lot_type); |
| 366 |
|
| 367 |
struct aco_file parking_lot_conf = { |
| 368 |
.filename = "res_parking.conf", |
| 369 |
.types = ACO_TYPES(&global_option, &parking_lot_type), |
| 370 |
}; |
| 371 |
|
| 372 |
static AO2_GLOBAL_OBJ_STATIC(globals); |
| 373 |
|
| 374 |
CONFIG_INFO_STANDARD(cfg_info, globals, parking_config_alloc, |
| 375 |
.files = ACO_FILES(&parking_lot_conf), |
| 376 |
.pre_apply_config = config_parking_preapply, |
| 377 |
.post_apply_config = link_configured_disable_marked_lots, |
| 378 |
); |
| 379 |
|
| 380 |
static int parking_lot_cfg_hash_fn(const void *obj, const int flags) |
| 381 |
{ |
| 382 |
const struct parking_lot_cfg *entry; |
| 383 |
const char *key; |
| 384 |
|
| 385 |
switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) { |
| 386 |
case OBJ_KEY: |
| 387 |
key = obj; |
| 388 |
return ast_str_hash(key); |
| 389 |
case OBJ_PARTIAL_KEY: |
| 390 |
ast_assert(0); |
| 391 |
return 0; |
| 392 |
default: |
| 393 |
entry = obj; |
| 394 |
return ast_str_hash(entry->name); |
| 395 |
} |
| 396 |
} |
| 397 |
|
| 398 |
static int parking_lot_cfg_cmp_fn(void *obj, void *arg, const int flags) |
| 399 |
{ |
| 400 |
struct parking_lot_cfg *entry1 = obj; |
| 401 |
|
| 402 |
char *key; |
| 403 |
size_t key_size; |
| 404 |
struct parking_lot_cfg *entry2; |
| 405 |
|
| 406 |
switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) { |
| 407 |
case OBJ_KEY: |
| 408 |
key = arg; |
| 409 |
return (!strcmp(entry1->name, key)) ? CMP_MATCH : 0; |
| 410 |
case OBJ_PARTIAL_KEY: |
| 411 |
key = arg; |
| 412 |
key_size = strlen(key); |
| 413 |
return (!strncmp(entry1->name, key, key_size)) ? CMP_MATCH : 0; |
| 414 |
case OBJ_POINTER: |
| 415 |
entry2 = arg; |
| 416 |
return (!strcmp(entry1->name, entry2->name)) ? CMP_MATCH : 0; |
| 417 |
default: |
| 418 |
return CMP_STOP; |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
static void parking_config_destructor(void *obj) |
| 424 |
{ |
| 425 |
struct parking_config *cfg = obj; |
| 426 |
ao2_cleanup(cfg->parking_lots); |
| 427 |
ao2_cleanup(cfg->global); |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
static void parking_global_config_destructor(void *obj) |
| 432 |
{ |
| 433 |
|
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
static void *parking_config_alloc(void) |
| 438 |
{ |
| 439 |
RAII_VAR(struct parking_config *, cfg, NULL, ao2_cleanup); |
| 440 |
|
| 441 |
if (!(cfg = ao2_alloc(sizeof(*cfg), parking_config_destructor))) { |
| 442 |
return NULL; |
| 443 |
} |
| 444 |
|
| 445 |
cfg->parking_lots = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 37, |
| 446 |
parking_lot_cfg_hash_fn, NULL, parking_lot_cfg_cmp_fn); |
| 447 |
if (!cfg->parking_lots) { |
| 448 |
return NULL; |
| 449 |
} |
| 450 |
|
| 451 |
if (!(cfg->global = ao2_alloc(sizeof(*cfg->global), parking_global_config_destructor))) { |
| 452 |
return NULL; |
| 453 |
} |
| 454 |
|
| 455 |
|
| 456 |
ao2_ref(cfg, +1); |
| 457 |
return cfg; |
| 458 |
} |
| 459 |
|
| 460 |
int parking_lot_remove_if_unused(struct parking_lot *lot) |
| 461 |
{ |
| 462 |
if (lot->mode != PARKINGLOT_DISABLED) { |
| 463 |
return -1; |
| 464 |
} |
| 465 |
|
| 466 |
if (!ao2_container_count(lot->parked_users)) { |
| 467 |
ao2_unlink(parking_lot_container, lot); |
| 468 |
return 0; |
| 469 |
} |
| 470 |
|
| 471 |
return -1; |
| 472 |
} |
| 473 |
|
| 474 |
static void parking_lot_disable(struct parking_lot *lot) |
| 475 |
{ |
| 476 |
|
| 477 |
int was_dynamic = (lot->mode == PARKINGLOT_DYNAMIC); |
| 478 |
|
| 479 |
lot->mode = PARKINGLOT_DISABLED; |
| 480 |
if (parking_lot_remove_if_unused(lot) && was_dynamic) { |
| 481 |
lot->mode = PARKINGLOT_DYNAMIC; |
| 482 |
lot->disable_mark = 0; |
| 483 |
} |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
static void parking_lot_cfg_destructor(void *obj) |
| 488 |
{ |
| 489 |
struct parking_lot_cfg *lot_cfg = obj; |
| 490 |
parking_lot_cfg_remove_extensions(lot_cfg); |
| 491 |
ast_string_field_free_memory(lot_cfg); |
| 492 |
} |
| 493 |
|
| 494 |
|
| 495 |
static int parked_user_cmp_fn(void *obj, void *arg, int flags) |
| 496 |
{ |
| 497 |
int *search_space = arg; |
| 498 |
struct parked_user *user = obj; |
| 499 |
int object_space = user->parking_space; |
| 500 |
|
| 501 |
if (*search_space == object_space) { |
| 502 |
return CMP_MATCH; |
| 503 |
} |
| 504 |
return 0; |
| 505 |
} |
| 506 |
|
| 507 |
static int parked_user_sort_fn(const void *obj_left, const void *obj_right, int flags) |
| 508 |
{ |
| 509 |
const struct parked_user *left = obj_left; |
| 510 |
const struct parked_user *right = obj_right; |
| 511 |
|
| 512 |
return left->parking_space - right->parking_space; |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
static void *parking_lot_cfg_alloc(const char *cat) |
| 522 |
{ |
| 523 |
struct parking_lot_cfg *lot_cfg; |
| 524 |
|
| 525 |
lot_cfg = ao2_alloc(sizeof(*lot_cfg), parking_lot_cfg_destructor); |
| 526 |
if (!lot_cfg) { |
| 527 |
return NULL; |
| 528 |
} |
| 529 |
|
| 530 |
if (ast_string_field_init(lot_cfg, 32)) { |
| 531 |
ao2_cleanup(lot_cfg); |
| 532 |
return NULL; |
| 533 |
} |
| 534 |
|
| 535 |
ast_string_field_set(lot_cfg, name, cat); |
| 536 |
|
| 537 |
return lot_cfg; |
| 538 |
} |
| 539 |
|
| 540 |
#if defined(TEST_FRAMEWORK) |
| 541 |
struct parking_lot_cfg *parking_lot_cfg_create(const char *cat) |
| 542 |
{ |
| 543 |
return parking_lot_cfg_alloc(cat); |
| 544 |
} |
| 545 |
#endif |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
static void *named_item_find(struct ao2_container *container, const char *name) |
| 558 |
{ |
| 559 |
return ao2_find(container, name, OBJ_KEY); |
| 560 |
} |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
static int option_handler_parkpos(const struct aco_option *opt, struct ast_variable *var, void *obj) |
| 566 |
{ |
| 567 |
struct parking_lot_cfg *lot_cfg = obj; |
| 568 |
int low; |
| 569 |
int high; |
| 570 |
|
| 571 |
if (sscanf(var->value, "%30d-%30d", &low, &high) != 2) { |
| 572 |
ast_log(LOG_WARNING, "Format for parking positions is a-b, where a and b are numbers\n"); |
| 573 |
} else if (high < low || low <= 0 || high <= 0) { |
| 574 |
ast_log(LOG_WARNING, "Format for parking positions is a-b, where a <= b\n"); |
| 575 |
} else { |
| 576 |
lot_cfg->parking_start = low; |
| 577 |
lot_cfg->parking_stop = high; |
| 578 |
return 0; |
| 579 |
} |
| 580 |
return -1; |
| 581 |
} |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
static int option_handler_findslot(const struct aco_option *opt, struct ast_variable *var, void *obj) |
| 587 |
{ |
| 588 |
struct parking_lot_cfg *lot_cfg = obj; |
| 589 |
|
| 590 |
if (!strcmp(var->value, "first")) { |
| 591 |
lot_cfg->parkfindnext = 0; |
| 592 |
} else if (!strcmp(var->value, "next")) { |
| 593 |
lot_cfg->parkfindnext = 1; |
| 594 |
} else { |
| 595 |
ast_log(LOG_WARNING, "value '%s' is not valid for findslot option.\n", var->value); |
| 596 |
return -1; |
| 597 |
} |
| 598 |
|
| 599 |
return 0; |
| 600 |
} |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
static int parking_feature_flag_cfg(int *param, const char *var) |
| 606 |
{ |
| 607 |
if (ast_false(var)) { |
| 608 |
*param = 0; |
| 609 |
} else if (!strcasecmp(var, "both")) { |
| 610 |
*param = AST_FEATURE_FLAG_BYBOTH; |
| 611 |
} else if (!strcasecmp(var, "caller")) { |
| 612 |
*param = AST_FEATURE_FLAG_BYCALLER; |
| 613 |
} else if (!strcasecmp(var, "callee")) { |
| 614 |
*param = AST_FEATURE_FLAG_BYCALLEE; |
| 615 |
} else { |
| 616 |
return -1; |
| 617 |
} |
| 618 |
|
| 619 |
return 0; |
| 620 |
} |
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
static int option_handler_parkedfeature(const struct aco_option *opt, struct ast_variable *var, void *obj) |
| 626 |
{ |
| 627 |
struct parking_lot_cfg *cfg = obj; |
| 628 |
enum parked_call_feature_options option = aco_option_get_flags(opt); |
| 629 |
int *parameter = NULL; |
| 630 |
|
| 631 |
switch (option) { |
| 632 |
case OPT_PARKEDPLAY: |
| 633 |
parameter = &cfg->parkedplay; |
| 634 |
break; |
| 635 |
case OPT_PARKEDTRANSFERS: |
| 636 |
parameter = &cfg->parkedcalltransfers; |
| 637 |
break; |
| 638 |
case OPT_PARKEDREPARKING: |
| 639 |
parameter = &cfg->parkedcallreparking; |
| 640 |
break; |
| 641 |
case OPT_PARKEDHANGUP: |
| 642 |
parameter = &cfg->parkedcallhangup; |
| 643 |
break; |
| 644 |
case OPT_PARKEDRECORDING: |
| 645 |
parameter = &cfg->parkedcallrecording; |
| 646 |
break; |
| 647 |
} |
| 648 |
|
| 649 |
ast_assert(parameter != NULL); |
| 650 |
if (!parameter || parking_feature_flag_cfg(parameter, var->value)) { |
| 651 |
return -1; |
| 652 |
} |
| 653 |
|
| 654 |
return 0; |
| 655 |
} |
| 656 |
|
| 657 |
struct ao2_container *get_parking_lot_container(void) |
| 658 |
{ |
| 659 |
return parking_lot_container; |
| 660 |
} |
| 661 |
|
| 662 |
struct parking_lot *parking_lot_find_by_name(const char *lot_name) |
| 663 |
{ |
| 664 |
struct parking_lot *lot = named_item_find(parking_lot_container, lot_name); |
| 665 |
return lot; |
| 666 |
} |
| 667 |
|
| 668 |
const char *find_channel_parking_lot_name(struct ast_channel *chan) |
| 669 |
{ |
| 670 |
const char *name; |
| 671 |
|
| 672 |
|
| 673 |
name = pbx_builtin_getvar_helper(chan, "PARKINGLOT"); |
| 674 |
if (ast_strlen_zero(name)) { |
| 675 |
|
| 676 |
name = ast_channel_parkinglot(chan); |
| 677 |
if (ast_strlen_zero(name)) { |
| 678 |
|
| 679 |
name = DEFAULT_PARKING_LOT; |
| 680 |
} |
| 681 |
} |
| 682 |
|
| 683 |
return name; |
| 684 |
} |
| 685 |
|
| 686 |
static void parking_lot_destructor(void *obj) |
| 687 |
{ |
| 688 |
struct parking_lot *lot = obj; |
| 689 |
|
| 690 |
if (lot->parking_bridge) { |
| 691 |
ast_bridge_destroy(lot->parking_bridge, 0); |
| 692 |
} |
| 693 |
ao2_cleanup(lot->parked_users); |
| 694 |
ao2_cleanup(lot->cfg); |
| 695 |
ast_string_field_free_memory(lot); |
| 696 |
} |
| 697 |
|
| 698 |
static struct parking_lot *alloc_new_parking_lot(struct parking_lot_cfg *lot_cfg) |
| 699 |
{ |
| 700 |
struct parking_lot *lot; |
| 701 |
if (!(lot = ao2_alloc(sizeof(*lot), parking_lot_destructor))) { |
| 702 |
return NULL; |
| 703 |
} |
| 704 |
|
| 705 |
if (ast_string_field_init(lot, 32)) { |
| 706 |
return NULL; |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
lot->parked_users = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_RWLOCK, |
| 711 |
AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, |
| 712 |
parked_user_sort_fn, |
| 713 |
parked_user_cmp_fn); |
| 714 |
|
| 715 |
if (!lot->parked_users) { |
| 716 |
ao2_cleanup(lot); |
| 717 |
return NULL; |
| 718 |
} |
| 719 |
|
| 720 |
ast_string_field_set(lot, name, lot_cfg->name); |
| 721 |
return lot; |
| 722 |
} |
| 723 |
|
| 724 |
void parking_lot_cfg_remove_extensions(struct parking_lot_cfg *lot_cfg) |
| 725 |
{ |
| 726 |
if (!ast_strlen_zero(lot_cfg->registrar)) { |
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
ast_context_destroy(NULL, lot_cfg->registrar); |
| 733 |
} |
| 734 |
|
| 735 |
|
| 736 |
ast_string_field_set(lot_cfg, registrar, ""); |
| 737 |
} |
| 738 |
|
| 739 |
static void remove_all_configured_parking_lot_extensions(void) |
| 740 |
{ |
| 741 |
RAII_VAR(struct parking_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup); |
| 742 |
struct parking_lot_cfg *lot_cfg; |
| 743 |
struct ao2_iterator iter; |
| 744 |
|
| 745 |
if (!cfg) { |
| 746 |
return; |
| 747 |
} |
| 748 |
|
| 749 |
for (iter = ao2_iterator_init(cfg->parking_lots, 0); (lot_cfg = ao2_iterator_next(&iter)); ao2_ref(lot_cfg, -1)) { |
| 750 |
parking_lot_cfg_remove_extensions(lot_cfg); |
| 751 |
} |
| 752 |
|
| 753 |
ast_context_destroy(NULL, BASE_REGISTRAR); |
| 754 |
|
| 755 |
ao2_iterator_destroy(&iter); |
| 756 |
} |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
static int parking_add_extension(struct ast_context *context, int replace, const char *extension, |
| 775 |
int priority, const char *application, const char *data, const char *registrar) |
| 776 |
{ |
| 777 |
char *data_duplicate = ast_strdup(data); |
| 778 |
|
| 779 |
if (!data_duplicate) { |
| 780 |
return -1; |
| 781 |
} |
| 782 |
|
| 783 |
if (ast_add_extension2_nolock(context, replace, extension, priority, NULL, NULL, |
| 784 |
application, data_duplicate, ast_free_ptr, registrar, NULL, 0)) { |
| 785 |
return -1; |
| 786 |
} |
| 787 |
|
| 788 |
return 0; |
| 789 |
} |
| 790 |
|
| 791 |
static int extension_is_compatible(struct parking_lot_cfg *lot_cfg, const char *app_type, struct ast_exten *extension) |
| 792 |
{ |
| 793 |
const char *extension_registrar = ast_get_extension_registrar(extension); |
| 794 |
const char *extension_context = ast_get_context_name(ast_get_extension_context(extension)); |
| 795 |
const char *extension_name = ast_get_extension_name(extension); |
| 796 |
const char *extension_application = ast_get_extension_app(extension); |
| 797 |
|
| 798 |
ast_assert(extension_registrar && extension_context && extension_name && extension_application); |
| 799 |
|
| 800 |
if (strcmp(extension_registrar, BASE_REGISTRAR)) { |
| 801 |
ast_log(LOG_ERROR, "Parking lot '%s' -- Needs an extension '%s@%s', but that extension is already owned by %s.\n", |
| 802 |
lot_cfg->name, extension_name, extension_context, extension_registrar); |
| 803 |
return 0; |
| 804 |
} |
| 805 |
|
| 806 |
if (strcmp(extension_application, app_type)) { |
| 807 |
ast_log(LOG_ERROR, "Parking lot '%s' -- Needs an extension '%s@%s' with a non-exclusive %s application, " |
| 808 |
"but a/an %s application is already registered to that extension by %s.\n", |
| 809 |
lot_cfg->name, extension_name, extension_context, app_type, |
| 810 |
extension_application, BASE_REGISTRAR); |
| 811 |
return 0; |
| 812 |
} |
| 813 |
|
| 814 |
ast_debug(3, "Parking lot '%s' -- extension '%s@%s' with application %s is compatible.\n", |
| 815 |
lot_cfg->name, extension_name, extension_context, app_type); |
| 816 |
return 1; |
| 817 |
} |
| 818 |
|
| 819 |
int parking_lot_cfg_create_extensions(struct parking_lot_cfg *lot_cfg) |
| 820 |
{ |
| 821 |
int parkingspace; |
| 822 |
struct ast_exten *existing_exten; |
| 823 |
struct ast_context *lot_context; |
| 824 |
struct pbx_find_info find_info = { .stacklen = 0 }; |
| 825 |
const char *parkext_registrar_pointer; |
| 826 |
const char *parkedcall_registrar_pointer; |
| 827 |
|
| 828 |
if (ast_strlen_zero(lot_cfg->parkext)) { |
| 829 |
return 0; |
| 830 |
} |
| 831 |
|
| 832 |
ast_string_field_build(lot_cfg, registrar, "%s/%s", BASE_REGISTRAR, lot_cfg->name); |
| 833 |
parkedcall_registrar_pointer = lot_cfg->registrar; |
| 834 |
|
| 835 |
if (lot_cfg->parkext_exclusive) { |
| 836 |
parkext_registrar_pointer = lot_cfg->registrar; |
| 837 |
} else { |
| 838 |
parkext_registrar_pointer = BASE_REGISTRAR; |
| 839 |
} |
| 840 |
|
| 841 |
|
| 842 |
ast_wrlock_contexts(); |
| 843 |
|
| 844 |
if (!(lot_context = ast_context_find_or_create(NULL, NULL, lot_cfg->parking_con, parkext_registrar_pointer))) { |
| 845 |
ast_log(LOG_ERROR, "Parking lot '%s' -- Needs a context '%s' which does not exist and Asterisk was unable to create\n", |
| 846 |
lot_cfg->name, lot_cfg->parking_con); |
| 847 |
ast_unlock_contexts(); |
| 848 |
return -1; |
| 849 |
} |
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
ast_wrlock_context(lot_context); |
| 855 |
|
| 856 |
ast_unlock_contexts(); |
| 857 |
|
| 858 |
|
| 859 |
if ((existing_exten = pbx_find_extension(NULL, NULL, &find_info, lot_cfg->parking_con, lot_cfg->parkext, 1, NULL, NULL, E_MATCH))) { |
| 860 |
if (lot_cfg->parkext_exclusive || !extension_is_compatible(lot_cfg, PARK_APPLICATION, existing_exten)) { |
| 861 |
ast_unlock_context(lot_context); |
| 862 |
return -1; |
| 863 |
} |
| 864 |
} else if (parking_add_extension(lot_context, 0, lot_cfg->parkext, 1, PARK_APPLICATION, |
| 865 |
lot_cfg->parkext_exclusive ? lot_cfg->name : "", parkext_registrar_pointer)) { |
| 866 |
ast_log(LOG_ERROR, "Parking lot '%s' -- Failed to add %s extension '%s@%s' to the PBX.\n", |
| 867 |
lot_cfg->name, PARK_APPLICATION, lot_cfg->parkext, lot_cfg->parking_con); |
| 868 |
ast_unlock_context(lot_context); |
| 869 |
return -1; |
| 870 |
} |
| 871 |
|
| 872 |
|
| 873 |
for (parkingspace = lot_cfg->parking_start; parkingspace <= lot_cfg->parking_stop; parkingspace++) { |
| 874 |
char space[AST_MAX_EXTENSION]; |
| 875 |
RAII_VAR(struct ast_str *, arguments_string, NULL, ast_free); |
| 876 |
find_info.stacklen = 0; |
| 877 |
|
| 878 |
snprintf(space, sizeof(space), "%d", parkingspace); |
| 879 |
|
| 880 |
|
| 881 |
if ((existing_exten = pbx_find_extension(NULL, NULL, &find_info, lot_cfg->parking_con, space, 1, NULL, NULL, E_MATCH))) { |
| 882 |
ast_unlock_context(lot_context); |
| 883 |
return -1; |
| 884 |
} |
| 885 |
|
| 886 |
arguments_string = ast_str_create(32); |
| 887 |
if (!arguments_string) { |
| 888 |
ast_unlock_context(lot_context); |
| 889 |
return -1; |
| 890 |
} |
| 891 |
|
| 892 |
ast_str_set(&arguments_string, 0, "%s,%s", lot_cfg->name, space); |
| 893 |
if (parking_add_extension(lot_context, 0, space, 1, PARKED_CALL_APPLICATION, |
| 894 |
ast_str_buffer(arguments_string), parkedcall_registrar_pointer)) { |
| 895 |
ast_log(LOG_ERROR, "Parking lot '%s' -- Failed to add %s extension '%s@%s' to the PBX.\n", |
| 896 |
lot_cfg->name, PARKED_CALL_APPLICATION, space, lot_cfg->parking_con); |
| 897 |
ast_unlock_context(lot_context); |
| 898 |
return -1; |
| 899 |
} |
| 900 |
|
| 901 |
find_info.stacklen = 0; |
| 902 |
|
| 903 |
if (lot_cfg->parkaddhints) { |
| 904 |
char hint_device[AST_MAX_EXTENSION]; |
| 905 |
|
| 906 |
snprintf(hint_device, sizeof(hint_device), "park:%s@%s", space, lot_cfg->parking_con); |
| 907 |
|
| 908 |
if ((existing_exten = pbx_find_extension(NULL, NULL, &find_info, lot_cfg->parking_con, space, PRIORITY_HINT, NULL, NULL, E_MATCH))) { |
| 909 |
ast_log(LOG_ERROR, "Parking lot '%s' -- Needs to add a hint '%s' at '%s@%s' but one already exists owned by %s\n", |
| 910 |
lot_cfg->name, hint_device, space, lot_cfg->parking_con, ast_get_extension_registrar(existing_exten)); |
| 911 |
ast_unlock_context(lot_context); |
| 912 |
return -1; |
| 913 |
} |
| 914 |
|
| 915 |
if (parking_add_extension(lot_context, 0, space, PRIORITY_HINT, hint_device, "", parkedcall_registrar_pointer)) { |
| 916 |
ast_log(LOG_ERROR, "Parking lot '%s' -- Failed to add hint '%s@%s' to the PBX.\n", |
| 917 |
lot_cfg->name, space, lot_cfg->parking_con); |
| 918 |
ast_unlock_context(lot_context); |
| 919 |
return -1; |
| 920 |
} |
| 921 |
} |
| 922 |
} |
| 923 |
|
| 924 |
ast_unlock_context(lot_context); |
| 925 |
|
| 926 |
return 0; |
| 927 |
} |
| 928 |
|
| 929 |
struct parking_lot *parking_lot_build_or_update(struct parking_lot_cfg *lot_cfg, int dynamic) |
| 930 |
{ |
| 931 |
struct parking_lot *lot; |
| 932 |
struct parking_lot_cfg *replaced_cfg = NULL; |
| 933 |
int found = 0; |
| 934 |
|
| 935 |
|
| 936 |
lot = named_item_find(parking_lot_container, lot_cfg->name); |
| 937 |
if (!lot) { |
| 938 |
lot = alloc_new_parking_lot(lot_cfg); |
| 939 |
|
| 940 |
|
| 941 |
if (!lot) { |
| 942 |
return NULL; |
| 943 |
} |
| 944 |
} else { |
| 945 |
found = 1; |
| 946 |
|
| 947 |
if (dynamic) { |
| 948 |
ast_log(LOG_ERROR, "Tried to create dynamic parking lot with name '%s' but a lot with that name already exists.\n", lot_cfg->name); |
| 949 |
ao2_cleanup(lot); |
| 950 |
return NULL; |
| 951 |
} |
| 952 |
} |
| 953 |
|
| 954 |
|
| 955 |
if (lot->cfg) { |
| 956 |
replaced_cfg = lot->cfg; |
| 957 |
} |
| 958 |
|
| 959 |
ao2_ref(lot_cfg, +1); |
| 960 |
lot->cfg = lot_cfg; |
| 961 |
|
| 962 |
ao2_cleanup(replaced_cfg); |
| 963 |
|
| 964 |
|
| 965 |
lot->disable_mark = 0; |
| 966 |
lot->mode = dynamic ? PARKINGLOT_DYNAMIC : PARKINGLOT_NORMAL; |
| 967 |
|
| 968 |
if (!found) { |
| 969 |
|
| 970 |
ao2_link(parking_lot_container, lot); |
| 971 |
}; |
| 972 |
|
| 973 |
return lot; |
| 974 |
} |
| 975 |
|
| 976 |
static void generate_or_link_lots_to_configs(void) |
| 977 |
{ |
| 978 |
RAII_VAR(struct parking_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup); |
| 979 |
struct parking_lot_cfg *lot_cfg; |
| 980 |
struct ao2_iterator iter; |
| 981 |
|
| 982 |
iter = ao2_iterator_init(cfg->parking_lots, 0); |
| 983 |
for (; (lot_cfg = ao2_iterator_next(&iter)); ao2_ref(lot_cfg, -1)) { |
| 984 |
ao2_cleanup(parking_lot_build_or_update(lot_cfg, 0)); |
| 985 |
} |
| 986 |
ao2_iterator_destroy(&iter); |
| 987 |
} |
| 988 |
|
| 989 |
int parking_dynamic_lots_enabled(void) |
| 990 |
{ |
| 991 |
RAII_VAR(struct parking_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup); |
| 992 |
|
| 993 |
if (!cfg) { |
| 994 |
return 0; |
| 995 |
} |
| 996 |
|
| 997 |
return cfg->global->parkeddynamic; |
| 998 |
} |
| 999 |
|
| 1000 |
static struct parking_lot_cfg *clone_parkinglot_cfg(struct parking_lot_cfg *source, const char *name) |
| 1001 |
{ |
| 1002 |
struct parking_lot_cfg *cfg = parking_lot_cfg_alloc(name); |
| 1003 |
|
| 1004 |
if (!cfg) { |
| 1005 |
return NULL; |
| 1006 |
} |
| 1007 |
|
| 1008 |
ast_string_fields_copy(cfg, source); |
| 1009 |
|
| 1010 |
|
| 1011 |
ast_string_field_set(cfg, name, name); |
| 1012 |
|
| 1013 |
|
| 1014 |
cfg->parking_start = source->parking_start; |
| 1015 |
cfg->parking_stop = source->parking_stop; |
| 1016 |
cfg->parkingtime = source->parkingtime; |
| 1017 |
cfg->comebackdialtime = source->comebackdialtime; |
| 1018 |
cfg->parkfindnext = source->parkfindnext; |
| 1019 |
cfg->parkext_exclusive = source->parkext_exclusive; |
| 1020 |
cfg->parkaddhints = source->parkaddhints; |
| 1021 |
cfg->comebacktoorigin = source->comebacktoorigin; |
| 1022 |
cfg->parkedplay = source->parkedplay; |
| 1023 |
cfg->parkedcalltransfers = source->parkedcalltransfers; |
| 1024 |
cfg->parkedcallreparking = source->parkedcallreparking; |
| 1025 |
cfg->parkedcallhangup = source->parkedcallhangup; |
| 1026 |
cfg->parkedcallrecording = source->parkedcallrecording; |
| 1027 |
|
| 1028 |
return cfg; |
| 1029 |
} |
| 1030 |
|
| 1031 |
static struct parking_lot *create_dynamic_lot_full(const char *name, struct ast_channel *chan, int forced) |
| 1032 |
{ |
| 1033 |
RAII_VAR(struct parking_lot_cfg *, cfg, NULL, ao2_cleanup); |
| 1034 |
RAII_VAR(struct parking_lot *, template_lot, NULL, ao2_cleanup); |
| 1035 |
|
| 1036 |
struct parking_lot *lot; |
| 1037 |
const char *dyn_context; |
| 1038 |
const char *dyn_exten; |
| 1039 |
const char *dyn_range; |
| 1040 |
const char *template_name; |
| 1041 |
const char *chan_template_name; |
| 1042 |
int dyn_start; |
| 1043 |
int dyn_end; |
| 1044 |
|
| 1045 |
if (!forced && !parking_dynamic_lots_enabled()) { |
| 1046 |
return NULL; |
| 1047 |
} |
| 1048 |
|
| 1049 |
ast_channel_lock(chan); |
| 1050 |
chan_template_name = ast_strdupa(S_OR(pbx_builtin_getvar_helper(chan, "PARKINGDYNAMIC"), "")); |
| 1051 |
dyn_context = ast_strdupa(S_OR(pbx_builtin_getvar_helper(chan, "PARKINGDYNCONTEXT"), "")); |
| 1052 |
dyn_exten = ast_strdupa(S_OR(pbx_builtin_getvar_helper(chan, "PARKINGDYNEXTEN"), "")); |
| 1053 |
dyn_range = ast_strdupa(S_OR(pbx_builtin_getvar_helper(chan, "PARKINGDYNPOS"), "")); |
| 1054 |
ast_channel_unlock(chan); |
| 1055 |
|
| 1056 |
template_name = S_OR(chan_template_name, DEFAULT_PARKING_LOT); |
| 1057 |
|
| 1058 |
template_lot = parking_lot_find_by_name(template_name); |
| 1059 |
if (!template_lot) { |
| 1060 |
ast_log(LOG_ERROR, "Lot %s does not exist. Can not use it as a dynamic parking lot template.\n", |
| 1061 |
template_name); |
| 1062 |
return NULL; |
| 1063 |
} |
| 1064 |
|
| 1065 |
cfg = clone_parkinglot_cfg(template_lot->cfg, name); |
| 1066 |
|
| 1067 |
if (!cfg) { |
| 1068 |
ast_log(LOG_ERROR, "Failed to allocate dynamic parking lot configuration.\n"); |
| 1069 |
return NULL; |
| 1070 |
} |
| 1071 |
|
| 1072 |
if (!ast_strlen_zero(dyn_exten)) { |
| 1073 |
ast_string_field_set(cfg, parkext, dyn_exten); |
| 1074 |
} |
| 1075 |
|
| 1076 |
if (!ast_strlen_zero(dyn_context)) { |
| 1077 |
ast_string_field_set(cfg, parking_con, dyn_context); |
| 1078 |
} |
| 1079 |
|
| 1080 |
if (!ast_strlen_zero(dyn_range)) { |
| 1081 |
if (sscanf(dyn_range, "%30d-%30d", &dyn_start, &dyn_end) != 2) { |
| 1082 |
ast_log(LOG_ERROR, |
| 1083 |
"Invalid parking range %s specified in PARKINGDYNPOS: could not parse minimum/maximum parking space range\n", dyn_range); |
| 1084 |
return NULL; |
| 1085 |
} |
| 1086 |
if (dyn_end < dyn_start || dyn_start < 0) { |
| 1087 |
ast_log(LOG_ERROR, |
| 1088 |
"Invalid parking range %s specified for PARKINGDYNPOS: end parking space must be greater than starting parking space.\n", dyn_range); |
| 1089 |
return NULL; |
| 1090 |
} |
| 1091 |
|
| 1092 |
cfg->parking_start = dyn_start; |
| 1093 |
cfg->parking_stop = dyn_end; |
| 1094 |
} |
| 1095 |
|
| 1096 |
if (parking_lot_cfg_create_extensions(cfg)) { |
| 1097 |
ast_log(LOG_ERROR, "Extensions for dynamic parking lot '%s' could not be registered. Dynamic lot creation failed.\n", name); |
| 1098 |
return NULL; |
| 1099 |
} |
| 1100 |
|
| 1101 |
ao2_lock(parking_lot_container); |
| 1102 |
|
| 1103 |
if ((lot = parking_lot_find_by_name(name))) { |
| 1104 |
ao2_unlock(parking_lot_container); |
| 1105 |
ast_log(LOG_ERROR, "Started creating dynamic parking lot '%s', but a parking lot with that name already exists.\n", name); |
| 1106 |
ao2_ref(lot, -1); |
| 1107 |
return NULL; |
| 1108 |
} |
| 1109 |
|
| 1110 |
lot = parking_lot_build_or_update(cfg, 1); |
| 1111 |
ao2_unlock(parking_lot_container); |
| 1112 |
|
| 1113 |
if (!lot) { |
| 1114 |
ast_log(LOG_NOTICE, "Failed to build dynamic parking lot '%s'\n", name); |
| 1115 |
} |
| 1116 |
|
| 1117 |
return lot; |
| 1118 |
} |
| 1119 |
|
| 1120 |
struct parking_lot *parking_create_dynamic_lot(const char *name, struct ast_channel *chan){ |
| 1121 |
return create_dynamic_lot_full(name, chan, 0); |
| 1122 |
} |
| 1123 |
|
| 1124 |
#if defined(TEST_FRAMEWORK) |
| 1125 |
struct parking_lot *parking_create_dynamic_lot_forced(const char *name, struct ast_channel *chan) { |
| 1126 |
return create_dynamic_lot_full(name, chan, 1); |
| 1127 |
} |
| 1128 |
#endif |
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
static int verify_default_parking_lot(void) |
| 1133 |
{ |
| 1134 |
struct parking_config *cfg = aco_pending_config(&cfg_info); |
| 1135 |
RAII_VAR(struct parking_lot_cfg *, lot_cfg, NULL, ao2_cleanup); |
| 1136 |
|
| 1137 |
if (!cfg) { |
| 1138 |
return 0; |
| 1139 |
} |
| 1140 |
|
| 1141 |
lot_cfg = ao2_find(cfg->parking_lots, DEFAULT_PARKING_LOT, OBJ_KEY); |
| 1142 |
if (!lot_cfg) { |
| 1143 |
lot_cfg = parking_lot_cfg_alloc(DEFAULT_PARKING_LOT); |
| 1144 |
if (!lot_cfg) { |
| 1145 |
return -1; |
| 1146 |
} |
| 1147 |
ast_log(AST_LOG_NOTICE, "Adding %s profile to res_parking\n", DEFAULT_PARKING_LOT); |
| 1148 |
aco_set_defaults(&parking_lot_type, DEFAULT_PARKING_LOT, lot_cfg); |
| 1149 |
ast_string_field_set(lot_cfg, parkext, DEFAULT_PARKING_EXTEN); |
| 1150 |
ao2_link(cfg->parking_lots, lot_cfg); |
| 1151 |
} |
| 1152 |
|
| 1153 |
return 0; |
| 1154 |
} |
| 1155 |
|
| 1156 |
static void remove_pending_parking_lot_extensions(struct parking_config *cfg_pending) |
| 1157 |
{ |
| 1158 |
struct parking_lot_cfg *lot_cfg; |
| 1159 |
struct ao2_iterator iter; |
| 1160 |
|
| 1161 |
for (iter = ao2_iterator_init(cfg_pending->parking_lots, 0); (lot_cfg = ao2_iterator_next(&iter)); ao2_ref(lot_cfg, -1)) { |
| 1162 |
parking_lot_cfg_remove_extensions(lot_cfg); |
| 1163 |
} |
| 1164 |
|
| 1165 |
ao2_iterator_destroy(&iter); |
| 1166 |
|
| 1167 |
ast_context_destroy(NULL, BASE_REGISTRAR); |
| 1168 |
|
| 1169 |
} |
| 1170 |
|
| 1171 |
static int configure_parking_extensions(void) |
| 1172 |
{ |
| 1173 |
struct parking_config *cfg = aco_pending_config(&cfg_info); |
| 1174 |
struct ao2_iterator iter; |
| 1175 |
RAII_VAR(struct parking_lot_cfg *, lot_cfg, NULL, ao2_cleanup); |
| 1176 |
int res = 0; |
| 1177 |
|
| 1178 |
if (!cfg) { |
| 1179 |
return 0; |
| 1180 |
} |
| 1181 |
|
| 1182 |
|
| 1183 |
remove_all_configured_parking_lot_extensions(); |
| 1184 |
|
| 1185 |
|
| 1186 |
for (iter = ao2_iterator_init(cfg->parking_lots, 0); (lot_cfg = ao2_iterator_next(&iter)); ao2_ref(lot_cfg, -1)) { |
| 1187 |
if (parking_lot_cfg_create_extensions(lot_cfg)) { |
| 1188 |
ao2_cleanup(lot_cfg); |
| 1189 |
lot_cfg = NULL; |
| 1190 |
res = -1; |
| 1191 |
break; |
| 1192 |
} |
| 1193 |
} |
| 1194 |
ao2_iterator_destroy(&iter); |
| 1195 |
|
| 1196 |
if (res) { |
| 1197 |
remove_pending_parking_lot_extensions(cfg); |
| 1198 |
ast_log(LOG_ERROR, "Extension registration failed. Previously configured lot extensions were removed and can not be safely restored.\n"); |
| 1199 |
} |
| 1200 |
|
| 1201 |
return res; |
| 1202 |
} |
| 1203 |
|
| 1204 |
static void mark_lots_as_disabled(void) |
| 1205 |
{ |
| 1206 |
struct ao2_iterator iter; |
| 1207 |
struct parking_lot *lot; |
| 1208 |
|
| 1209 |
for (iter = ao2_iterator_init(parking_lot_container, 0); (lot = ao2_iterator_next(&iter)); ao2_ref(lot, -1)) { |
| 1210 |
lot->disable_mark = 1; |
| 1211 |
} |
| 1212 |
|
| 1213 |
ao2_iterator_destroy(&iter); |
| 1214 |
} |
| 1215 |
|
| 1216 |
static int config_parking_preapply(void) |
| 1217 |
{ |
| 1218 |
mark_lots_as_disabled(); |
| 1219 |
|
| 1220 |
if (verify_default_parking_lot()) { |
| 1221 |
return -1; |
| 1222 |
} |
| 1223 |
|
| 1224 |
if (configure_parking_extensions()) { |
| 1225 |
return -1; |
| 1226 |
} |
| 1227 |
|
| 1228 |
return 0; |
| 1229 |
} |
| 1230 |
|
| 1231 |
static void disable_marked_lots(void) |
| 1232 |
{ |
| 1233 |
struct ao2_iterator iter; |
| 1234 |
struct parking_lot *lot; |
| 1235 |
|
| 1236 |
for (iter = ao2_iterator_init(parking_lot_container, 0); (lot = ao2_iterator_next(&iter)); ao2_ref(lot, -1)) { |
| 1237 |
if (lot->disable_mark) { |
| 1238 |
parking_lot_disable(lot); |
| 1239 |
} |
| 1240 |
} |
| 1241 |
|
| 1242 |
ao2_iterator_destroy(&iter); |
| 1243 |
} |
| 1244 |
|
| 1245 |
static void link_configured_disable_marked_lots(void) |
| 1246 |
{ |
| 1247 |
generate_or_link_lots_to_configs(); |
| 1248 |
disable_marked_lots(); |
| 1249 |
} |
| 1250 |
|
| 1251 |
static int unload_module(void) |
| 1252 |
{ |
| 1253 |
unload_parking_bridge_features(); |
| 1254 |
remove_all_configured_parking_lot_extensions(); |
| 1255 |
unload_parking_applications(); |
| 1256 |
unload_parking_manager(); |
| 1257 |
unload_parking_ui(); |
| 1258 |
unload_parking_devstate(); |
| 1259 |
unload_parking_tests(); |
| 1260 |
ao2_cleanup(parking_lot_container); |
| 1261 |
parking_lot_container = NULL; |
| 1262 |
aco_info_destroy(&cfg_info); |
| 1263 |
ao2_global_obj_release(globals); |
| 1264 |
|
| 1265 |
return 0; |
| 1266 |
} |
| 1267 |
|
| 1268 |
static int load_module(void) |
| 1269 |
{ |
| 1270 |
parking_lot_container = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, |
| 1271 |
AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, |
| 1272 |
parking_lot_sort_fn, |
| 1273 |
NULL); |
| 1274 |
if (!parking_lot_container) { |
| 1275 |
goto error; |
| 1276 |
} |
| 1277 |
|
| 1278 |
if (aco_info_init(&cfg_info)) { |
| 1279 |
goto error; |
| 1280 |
} |
| 1281 |
|
| 1282 |
|
| 1283 |
aco_option_register(&cfg_info, "parkeddynamic", ACO_EXACT, global_options, "no", OPT_BOOL_T, 1, FLDSET(struct parking_global_config, parkeddynamic)); |
| 1284 |
|
| 1285 |
|
| 1286 |
aco_option_register(&cfg_info, "parkext", ACO_EXACT, parking_lot_types, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct parking_lot_cfg, parkext)); |
| 1287 |
aco_option_register(&cfg_info, "context", ACO_EXACT, parking_lot_types, "parkedcalls", OPT_STRINGFIELD_T, 0, STRFLDSET(struct parking_lot_cfg, parking_con)); |
| 1288 |
aco_option_register(&cfg_info, "parkingtime", ACO_EXACT, parking_lot_types, "45", OPT_UINT_T, 0, FLDSET(struct parking_lot_cfg, parkingtime)); |
| 1289 |
aco_option_register(&cfg_info, "comebacktoorigin", ACO_EXACT, parking_lot_types, "yes", OPT_BOOL_T, 1, FLDSET(struct parking_lot_cfg, comebacktoorigin)); |
| 1290 |
aco_option_register(&cfg_info, "comebackcontext", ACO_EXACT, parking_lot_types, "parkedcallstimeout", OPT_STRINGFIELD_T, 0, STRFLDSET(struct parking_lot_cfg, comebackcontext)); |
| 1291 |
aco_option_register(&cfg_info, "comebackdialtime", ACO_EXACT, parking_lot_types, "30", OPT_UINT_T, 0, FLDSET(struct parking_lot_cfg, comebackdialtime)); |
| 1292 |
aco_option_register(&cfg_info, "parkedmusicclass", ACO_EXACT, parking_lot_types, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct parking_lot_cfg, mohclass)); |
| 1293 |
aco_option_register(&cfg_info, "parkext_exclusive", ACO_EXACT, parking_lot_types, "no", OPT_BOOL_T, 1, FLDSET(struct parking_lot_cfg, parkext_exclusive)); |
| 1294 |
aco_option_register(&cfg_info, "parkinghints", ACO_EXACT, parking_lot_types, "no", OPT_BOOL_T, 1, FLDSET(struct parking_lot_cfg, parkaddhints)); |
| 1295 |
aco_option_register(&cfg_info, "courtesytone", ACO_EXACT, parking_lot_types, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct parking_lot_cfg, courtesytone)); |
| 1296 |
|
| 1297 |
|
| 1298 |
aco_option_register_custom(&cfg_info, "parkpos", ACO_EXACT, parking_lot_types, "701-750", option_handler_parkpos, 0); |
| 1299 |
aco_option_register_custom(&cfg_info, "findslot", ACO_EXACT, parking_lot_types, "first", option_handler_findslot, 0); |
| 1300 |
aco_option_register_custom(&cfg_info, "parkedplay", ACO_EXACT, parking_lot_types, "caller", option_handler_parkedfeature, OPT_PARKEDPLAY); |
| 1301 |
aco_option_register_custom(&cfg_info, "parkedcalltransfers", ACO_EXACT, parking_lot_types, "no", option_handler_parkedfeature, OPT_PARKEDTRANSFERS); |
| 1302 |
aco_option_register_custom(&cfg_info, "parkedcallreparking", ACO_EXACT, parking_lot_types, "no", option_handler_parkedfeature, OPT_PARKEDREPARKING); |
| 1303 |
aco_option_register_custom(&cfg_info, "parkedcallhangup", ACO_EXACT, parking_lot_types, "no", option_handler_parkedfeature, OPT_PARKEDHANGUP); |
| 1304 |
aco_option_register_custom(&cfg_info, "parkedcallrecording", ACO_EXACT, parking_lot_types, "no", option_handler_parkedfeature, OPT_PARKEDRECORDING); |
| 1305 |
|
| 1306 |
if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) { |
| 1307 |
goto error; |
| 1308 |
} |
| 1309 |
|
| 1310 |
if (load_parking_applications()) { |
| 1311 |
goto error; |
| 1312 |
} |
| 1313 |
|
| 1314 |
if (load_parking_ui()) { |
| 1315 |
goto error; |
| 1316 |
} |
| 1317 |
|
| 1318 |
if (load_parking_manager()) { |
| 1319 |
goto error; |
| 1320 |
} |
| 1321 |
|
| 1322 |
if (load_parking_bridge_features()) { |
| 1323 |
goto error; |
| 1324 |
} |
| 1325 |
|
| 1326 |
if (load_parking_devstate()) { |
| 1327 |
goto error; |
| 1328 |
} |
| 1329 |
|
| 1330 |
if (load_parking_tests()) { |
| 1331 |
goto error; |
| 1332 |
} |
| 1333 |
|
| 1334 |
return AST_MODULE_LOAD_SUCCESS; |
| 1335 |
|
| 1336 |
error: |
| 1337 |
unload_module(); |
| 1338 |
return AST_MODULE_LOAD_DECLINE; |
| 1339 |
} |
| 1340 |
|
| 1341 |
static int reload_module(void) |
| 1342 |
{ |
| 1343 |
if (aco_process_config(&cfg_info, 1) == ACO_PROCESS_ERROR) { |
| 1344 |
return AST_MODULE_LOAD_DECLINE; |
| 1345 |
} |
| 1346 |
|
| 1347 |
return 0; |
| 1348 |
} |
| 1349 |
|
| 1350 |
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Call Parking Resource", |
| 1351 |
.support_level = AST_MODULE_SUPPORT_CORE, |
| 1352 |
.load = load_module, |
| 1353 |
.unload = unload_module, |
| 1354 |
.reload = reload_module, |
| 1355 |
.load_pri = AST_MODPRI_DEVSTATE_PROVIDER, |
| 1356 |
); |