| 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 |
#include "asterisk.h" |
| 27 |
|
| 28 |
#include "res_parking.h" |
| 29 |
#include "asterisk/config.h" |
| 30 |
#include "asterisk/config_options.h" |
| 31 |
#include "asterisk/utils.h" |
| 32 |
#include "asterisk/module.h" |
| 33 |
#include "asterisk/cli.h" |
| 34 |
#include "asterisk/astobj2.h" |
| 35 |
#include "asterisk/features.h" |
| 36 |
#include "asterisk/manager.h" |
| 37 |
#include "asterisk/bridge.h" |
| 38 |
#include "asterisk/module.h" |
| 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 |
static struct stasis_subscription *parking_sub; |
| 206 |
|
| 207 |
static struct ast_parked_call_payload *parked_call_payload_from_failure(struct ast_channel *chan) |
| 208 |
{ |
| 209 |
RAII_VAR(struct ast_channel_snapshot *, parkee_snapshot, NULL, ao2_cleanup); |
| 210 |
|
| 211 |
ast_channel_lock(chan); |
| 212 |
parkee_snapshot = ast_channel_snapshot_create(chan); |
| 213 |
ast_channel_unlock(chan); |
| 214 |
if (!parkee_snapshot) { |
| 215 |
return NULL; |
| 216 |
} |
| 217 |
|
| 218 |
return ast_parked_call_payload_create(PARKED_CALL_FAILED, parkee_snapshot, NULL, NULL, NULL, 0, 0, 0); |
| 219 |
} |
| 220 |
|
| 221 |
static struct ast_parked_call_payload *parked_call_payload_from_parked_user(struct parked_user *pu, enum ast_parked_call_event_type event_type) |
| 222 |
{ |
| 223 |
RAII_VAR(struct ast_channel_snapshot *, parkee_snapshot, NULL, ao2_cleanup); |
| 224 |
long int timeout; |
| 225 |
long int duration; |
| 226 |
struct timeval now = ast_tvnow(); |
| 227 |
const char *lot_name = pu->lot->name; |
| 228 |
|
| 229 |
ast_channel_lock(pu->chan); |
| 230 |
parkee_snapshot = ast_channel_snapshot_create(pu->chan); |
| 231 |
ast_channel_unlock(pu->chan); |
| 232 |
if (!parkee_snapshot) { |
| 233 |
return NULL; |
| 234 |
} |
| 235 |
|
| 236 |
timeout = pu->start.tv_sec + (long) pu->time_limit - now.tv_sec; |
| 237 |
duration = now.tv_sec - pu->start.tv_sec; |
| 238 |
|
| 239 |
return ast_parked_call_payload_create(event_type, parkee_snapshot, pu->parker_dial_string, pu->retriever, lot_name, pu->parking_space, timeout, duration); |
| 240 |
|
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
static struct ast_str *manager_build_parked_call_string(const struct ast_parked_call_payload *payload) |
| 245 |
{ |
| 246 |
struct ast_str *out = ast_str_create(1024); |
| 247 |
RAII_VAR(struct ast_str *, parkee_string, NULL, ast_free); |
| 248 |
RAII_VAR(struct ast_str *, retriever_string, NULL, ast_free); |
| 249 |
|
| 250 |
if (!out) { |
| 251 |
return NULL; |
| 252 |
} |
| 253 |
|
| 254 |
parkee_string = ast_manager_build_channel_state_string_prefix(payload->parkee, "Parkee"); |
| 255 |
if (!parkee_string) { |
| 256 |
ast_free(out); |
| 257 |
return NULL; |
| 258 |
} |
| 259 |
|
| 260 |
if (payload->retriever) { |
| 261 |
retriever_string = ast_manager_build_channel_state_string_prefix(payload->retriever, "Retriever"); |
| 262 |
if (!retriever_string) { |
| 263 |
ast_free(out); |
| 264 |
return NULL; |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
ast_str_set(&out, 0, |
| 269 |
"%s" |
| 270 |
"%s" |
| 271 |
"ParkerDialString: %s\r\n" |
| 272 |
"Parkinglot: %s\r\n" |
| 273 |
"ParkingSpace: %u\r\n" |
| 274 |
"ParkingTimeout: %lu\r\n" |
| 275 |
"ParkingDuration: %lu\r\n", |
| 276 |
|
| 277 |
ast_str_buffer(parkee_string), |
| 278 |
retriever_string ? ast_str_buffer(retriever_string) : "", |
| 279 |
payload->parker_dial_string, |
| 280 |
payload->parkinglot, |
| 281 |
payload->parkingspace, |
| 282 |
payload->timeout, |
| 283 |
payload->duration); |
| 284 |
|
| 285 |
return out; |
| 286 |
} |
| 287 |
|
| 288 |
static void manager_parking_status_single_lot(struct mansession *s, const struct message *m, const char *id_text, const char *lot_name) |
| 289 |
{ |
| 290 |
RAII_VAR(struct parking_lot *, curlot, NULL, ao2_cleanup); |
| 291 |
struct parked_user *curuser; |
| 292 |
struct ao2_iterator iter_users; |
| 293 |
int total = 0; |
| 294 |
|
| 295 |
curlot = parking_lot_find_by_name(lot_name); |
| 296 |
if (!curlot) { |
| 297 |
astman_send_error(s, m, "Requested parking lot could not be found."); |
| 298 |
return; |
| 299 |
} |
| 300 |
|
| 301 |
astman_send_listack(s, m, "Parked calls will follow", "start"); |
| 302 |
|
| 303 |
iter_users = ao2_iterator_init(curlot->parked_users, 0); |
| 304 |
while ((curuser = ao2_iterator_next(&iter_users))) { |
| 305 |
RAII_VAR(struct ast_parked_call_payload *, payload, NULL, ao2_cleanup); |
| 306 |
RAII_VAR(struct ast_str *, parked_call_string, NULL, ast_free); |
| 307 |
|
| 308 |
payload = parked_call_payload_from_parked_user(curuser, PARKED_CALL); |
| 309 |
if (!payload) { |
| 310 |
ao2_ref(curuser, -1); |
| 311 |
break; |
| 312 |
} |
| 313 |
|
| 314 |
parked_call_string = manager_build_parked_call_string(payload); |
| 315 |
if (!parked_call_string) { |
| 316 |
ao2_ref(curuser, -1); |
| 317 |
break; |
| 318 |
} |
| 319 |
|
| 320 |
total++; |
| 321 |
|
| 322 |
astman_append(s, "Event: ParkedCall\r\n" |
| 323 |
"%s" |
| 324 |
"%s" |
| 325 |
"\r\n", |
| 326 |
ast_str_buffer(parked_call_string), |
| 327 |
id_text); |
| 328 |
|
| 329 |
ao2_ref(curuser, -1); |
| 330 |
} |
| 331 |
ao2_iterator_destroy(&iter_users); |
| 332 |
|
| 333 |
astman_send_list_complete_start(s, m, "ParkedCallsComplete", total); |
| 334 |
astman_append(s, "Total: %d\r\n", total); |
| 335 |
astman_send_list_complete_end(s); |
| 336 |
} |
| 337 |
|
| 338 |
static void manager_parking_status_all_lots(struct mansession *s, const struct message *m, const char *id_text) |
| 339 |
{ |
| 340 |
struct parked_user *curuser; |
| 341 |
struct ao2_container *lot_container; |
| 342 |
struct ao2_iterator iter_lots; |
| 343 |
struct ao2_iterator iter_users; |
| 344 |
struct parking_lot *curlot; |
| 345 |
int total = 0; |
| 346 |
|
| 347 |
lot_container = get_parking_lot_container(); |
| 348 |
if (!lot_container) { |
| 349 |
ast_log(LOG_ERROR, "Failed to obtain parking lot list. Action canceled.\n"); |
| 350 |
astman_send_error(s, m, "Could not create parking lot list"); |
| 351 |
return; |
| 352 |
} |
| 353 |
|
| 354 |
astman_send_listack(s, m, "Parked calls will follow", "start"); |
| 355 |
|
| 356 |
iter_lots = ao2_iterator_init(lot_container, 0); |
| 357 |
while ((curlot = ao2_iterator_next(&iter_lots))) { |
| 358 |
iter_users = ao2_iterator_init(curlot->parked_users, 0); |
| 359 |
while ((curuser = ao2_iterator_next(&iter_users))) { |
| 360 |
RAII_VAR(struct ast_parked_call_payload *, payload, NULL, ao2_cleanup); |
| 361 |
RAII_VAR(struct ast_str *, parked_call_string, NULL, ast_free); |
| 362 |
|
| 363 |
payload = parked_call_payload_from_parked_user(curuser, PARKED_CALL); |
| 364 |
if (!payload) { |
| 365 |
ao2_ref(curuser, -1); |
| 366 |
ao2_iterator_destroy(&iter_users); |
| 367 |
ao2_ref(curlot, -1); |
| 368 |
goto abort_list; |
| 369 |
} |
| 370 |
|
| 371 |
parked_call_string = manager_build_parked_call_string(payload); |
| 372 |
if (!parked_call_string) { |
| 373 |
ao2_ref(curuser, -1); |
| 374 |
ao2_iterator_destroy(&iter_users); |
| 375 |
ao2_ref(curlot, -1); |
| 376 |
goto abort_list; |
| 377 |
} |
| 378 |
|
| 379 |
total++; |
| 380 |
|
| 381 |
astman_append(s, "Event: ParkedCall\r\n" |
| 382 |
"%s" |
| 383 |
"%s" |
| 384 |
"\r\n", |
| 385 |
ast_str_buffer(parked_call_string), |
| 386 |
id_text); |
| 387 |
|
| 388 |
ao2_ref(curuser, -1); |
| 389 |
} |
| 390 |
ao2_iterator_destroy(&iter_users); |
| 391 |
ao2_ref(curlot, -1); |
| 392 |
} |
| 393 |
abort_list: |
| 394 |
ao2_iterator_destroy(&iter_lots); |
| 395 |
|
| 396 |
astman_send_list_complete_start(s, m, "ParkedCallsComplete", total); |
| 397 |
astman_append(s, "Total: %d\r\n", total); |
| 398 |
astman_send_list_complete_end(s); |
| 399 |
} |
| 400 |
|
| 401 |
static int manager_parking_status(struct mansession *s, const struct message *m) |
| 402 |
{ |
| 403 |
const char *id = astman_get_header(m, "ActionID"); |
| 404 |
const char *lot_name = astman_get_header(m, "ParkingLot"); |
| 405 |
char id_text[256]; |
| 406 |
|
| 407 |
id_text[0] = '\0'; |
| 408 |
if (!ast_strlen_zero(id)) { |
| 409 |
snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", id); |
| 410 |
} |
| 411 |
|
| 412 |
if (!ast_strlen_zero(lot_name)) { |
| 413 |
manager_parking_status_single_lot(s, m, id_text, lot_name); |
| 414 |
} else { |
| 415 |
manager_parking_status_all_lots(s, m, id_text); |
| 416 |
} |
| 417 |
|
| 418 |
return 0; |
| 419 |
} |
| 420 |
|
| 421 |
struct park_list_data { |
| 422 |
const char *id_text; |
| 423 |
int count; |
| 424 |
}; |
| 425 |
|
| 426 |
static int manager_append_event_parking_lot_data_cb(void *obj, void *arg, void *data, int flags) |
| 427 |
{ |
| 428 |
struct parking_lot *curlot = obj; |
| 429 |
struct mansession *s = arg; |
| 430 |
struct park_list_data *list_data = data; |
| 431 |
|
| 432 |
astman_append(s, "Event: Parkinglot\r\n" |
| 433 |
"%s" |
| 434 |
"Name: %s\r\n" |
| 435 |
"StartSpace: %d\r\n" |
| 436 |
"StopSpace: %d\r\n" |
| 437 |
"Timeout: %u\r\n" |
| 438 |
"\r\n", |
| 439 |
list_data->id_text, |
| 440 |
curlot->name, |
| 441 |
curlot->cfg->parking_start, |
| 442 |
curlot->cfg->parking_stop, |
| 443 |
curlot->cfg->parkingtime); |
| 444 |
++list_data->count; |
| 445 |
|
| 446 |
return 0; |
| 447 |
} |
| 448 |
|
| 449 |
static int manager_parking_lot_list(struct mansession *s, const struct message *m) |
| 450 |
{ |
| 451 |
const char *id = astman_get_header(m, "ActionID"); |
| 452 |
struct ao2_container *lot_container; |
| 453 |
char id_text[256]; |
| 454 |
struct park_list_data list_data; |
| 455 |
|
| 456 |
id_text[0] = '\0'; |
| 457 |
if (!ast_strlen_zero(id)) { |
| 458 |
snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", id); |
| 459 |
} |
| 460 |
|
| 461 |
lot_container = get_parking_lot_container(); |
| 462 |
if (!lot_container) { |
| 463 |
ast_log(LOG_ERROR, "Failed to obtain parking lot list. Action canceled.\n"); |
| 464 |
astman_send_error(s, m, "Could not create parking lot list"); |
| 465 |
return 0; |
| 466 |
} |
| 467 |
|
| 468 |
astman_send_listack(s, m, "Parking lots will follow", "start"); |
| 469 |
|
| 470 |
list_data.id_text = id_text; |
| 471 |
list_data.count = 0; |
| 472 |
ao2_callback_data(lot_container, OBJ_MULTIPLE | OBJ_NODATA, |
| 473 |
manager_append_event_parking_lot_data_cb, s, &list_data); |
| 474 |
|
| 475 |
astman_send_list_complete_start(s, m, "ParkinglotsComplete", list_data.count); |
| 476 |
astman_send_list_complete_end(s); |
| 477 |
|
| 478 |
return 0; |
| 479 |
} |
| 480 |
|
| 481 |
static void manager_park_unbridged(struct mansession *s, const struct message *m, |
| 482 |
struct ast_channel *chan, const char *parkinglot, int timeout_override) |
| 483 |
{ |
| 484 |
struct ast_bridge *parking_bridge = park_common_setup(chan, |
| 485 |
chan, parkinglot, NULL, 0, 0, timeout_override, 1); |
| 486 |
|
| 487 |
if (!parking_bridge) { |
| 488 |
astman_send_error(s, m, "Park action failed\n"); |
| 489 |
return; |
| 490 |
} |
| 491 |
|
| 492 |
if (ast_bridge_add_channel(parking_bridge, chan, NULL, 0, NULL)) { |
| 493 |
astman_send_error(s, m, "Park action failed\n"); |
| 494 |
ao2_cleanup(parking_bridge); |
| 495 |
return; |
| 496 |
} |
| 497 |
|
| 498 |
astman_send_ack(s, m, "Park successful\n"); |
| 499 |
ao2_cleanup(parking_bridge); |
| 500 |
} |
| 501 |
|
| 502 |
static void manager_park_bridged(struct mansession *s, const struct message *m, |
| 503 |
struct ast_channel *chan, struct ast_channel *parker_chan, |
| 504 |
const char *parkinglot, int timeout_override) |
| 505 |
{ |
| 506 |
struct ast_bridge_channel *bridge_channel; |
| 507 |
char *app_data; |
| 508 |
|
| 509 |
if (timeout_override != -1) { |
| 510 |
if (ast_asprintf(&app_data, "%s,t(%d)", parkinglot, timeout_override) == -1) { |
| 511 |
astman_send_error(s, m, "Park action failed\n"); |
| 512 |
return; |
| 513 |
} |
| 514 |
} else { |
| 515 |
if (ast_asprintf(&app_data, "%s", parkinglot) == -1) { |
| 516 |
astman_send_error(s, m, "Park action failed\n"); |
| 517 |
return; |
| 518 |
} |
| 519 |
} |
| 520 |
|
| 521 |
ast_channel_lock(parker_chan); |
| 522 |
bridge_channel = ast_channel_get_bridge_channel(parker_chan); |
| 523 |
ast_channel_unlock(parker_chan); |
| 524 |
|
| 525 |
if (!bridge_channel) { |
| 526 |
ast_free(app_data); |
| 527 |
astman_send_error(s, m, "Park action failed\n"); |
| 528 |
return; |
| 529 |
} |
| 530 |
|
| 531 |
|
| 532 |
if (create_parked_subscription(parker_chan, ast_channel_uniqueid(chan), 1)) { |
| 533 |
ast_free(app_data); |
| 534 |
astman_send_error(s, m, "Park action failed\n"); |
| 535 |
ao2_cleanup(bridge_channel); |
| 536 |
return; |
| 537 |
} |
| 538 |
|
| 539 |
ast_bridge_channel_write_park(bridge_channel, ast_channel_uniqueid(chan), |
| 540 |
ast_channel_uniqueid(parker_chan), app_data); |
| 541 |
|
| 542 |
ast_free(app_data); |
| 543 |
|
| 544 |
astman_send_ack(s, m, "Park successful\n"); |
| 545 |
ao2_cleanup(bridge_channel); |
| 546 |
} |
| 547 |
|
| 548 |
static int manager_park(struct mansession *s, const struct message *m) |
| 549 |
{ |
| 550 |
const char *channel = astman_get_header(m, "Channel"); |
| 551 |
const char *timeout_channel = S_OR(astman_get_header(m, "TimeoutChannel"), astman_get_header(m, "Channel2")); |
| 552 |
const char *announce_channel = astman_get_header(m, "AnnounceChannel"); |
| 553 |
const char *timeout = astman_get_header(m, "Timeout"); |
| 554 |
const char *parkinglot = astman_get_header(m, "Parkinglot"); |
| 555 |
const char *parkingspace = astman_get_header(m, "ParkingSpace"); |
| 556 |
char buf[BUFSIZ]; |
| 557 |
int timeout_override = -1; |
| 558 |
|
| 559 |
RAII_VAR(struct ast_channel *, parker_chan, NULL, ao2_cleanup); |
| 560 |
RAII_VAR(struct ast_channel *, chan, NULL, ao2_cleanup); |
| 561 |
|
| 562 |
if (ast_strlen_zero(channel)) { |
| 563 |
astman_send_error(s, m, "Channel not specified"); |
| 564 |
return 0; |
| 565 |
} |
| 566 |
|
| 567 |
if (!ast_strlen_zero(timeout)) { |
| 568 |
if (sscanf(timeout, "%30d", &timeout_override) != 1 || timeout_override < 0) { |
| 569 |
astman_send_error(s, m, "Invalid Timeout value."); |
| 570 |
return 0; |
| 571 |
} |
| 572 |
|
| 573 |
if (timeout_override) { |
| 574 |
|
| 575 |
timeout_override = MAX(1, timeout_override / 1000); |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
if (!(chan = ast_channel_get_by_name(channel))) { |
| 580 |
snprintf(buf, sizeof(buf), "Channel does not exist: %s", channel); |
| 581 |
astman_send_error(s, m, buf); |
| 582 |
return 0; |
| 583 |
} |
| 584 |
|
| 585 |
if (!ast_strlen_zero(timeout_channel)) { |
| 586 |
ast_channel_lock(chan); |
| 587 |
ast_bridge_set_transfer_variables(chan, timeout_channel, 0); |
| 588 |
ast_channel_unlock(chan); |
| 589 |
} |
| 590 |
|
| 591 |
if (!ast_strlen_zero(parkingspace)) { |
| 592 |
pbx_builtin_setvar_helper(chan, "PARKINGEXTEN", parkingspace); |
| 593 |
} |
| 594 |
|
| 595 |
parker_chan = ast_channel_bridge_peer(chan); |
| 596 |
if (!parker_chan || strcmp(ast_channel_name(parker_chan), timeout_channel)) { |
| 597 |
if (!ast_strlen_zero(announce_channel)) { |
| 598 |
struct ast_channel *announce_chan = ast_channel_get_by_name(announce_channel); |
| 599 |
if (!announce_channel) { |
| 600 |
astman_send_error(s, m, "AnnounceChannel does not exist"); |
| 601 |
return 0; |
| 602 |
} |
| 603 |
|
| 604 |
create_parked_subscription(announce_chan, ast_channel_uniqueid(chan), 0); |
| 605 |
ast_channel_cleanup(announce_chan); |
| 606 |
} |
| 607 |
|
| 608 |
manager_park_unbridged(s, m, chan, parkinglot, timeout_override); |
| 609 |
return 0; |
| 610 |
} |
| 611 |
|
| 612 |
if (!ast_strlen_zero(announce_channel) && strcmp(announce_channel, timeout_channel)) { |
| 613 |
|
| 614 |
|
| 615 |
struct ast_channel *announce_chan = ast_channel_get_by_name(announce_channel); |
| 616 |
if (!announce_channel) { |
| 617 |
astman_send_error(s, m, "AnnounceChannel does not exist"); |
| 618 |
return 0; |
| 619 |
} |
| 620 |
|
| 621 |
create_parked_subscription(announce_chan, ast_channel_uniqueid(chan), 0); |
| 622 |
ast_channel_cleanup(announce_chan); |
| 623 |
} |
| 624 |
|
| 625 |
manager_park_bridged(s, m, chan, parker_chan, parkinglot, timeout_override); |
| 626 |
return 0; |
| 627 |
} |
| 628 |
|
| 629 |
void publish_parked_call_failure(struct ast_channel *parkee) |
| 630 |
{ |
| 631 |
RAII_VAR(struct ast_parked_call_payload *, payload, NULL, ao2_cleanup); |
| 632 |
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup); |
| 633 |
|
| 634 |
if (!ast_parked_call_type()) { |
| 635 |
return; |
| 636 |
} |
| 637 |
|
| 638 |
payload = parked_call_payload_from_failure(parkee); |
| 639 |
if (!payload) { |
| 640 |
return; |
| 641 |
} |
| 642 |
|
| 643 |
msg = stasis_message_create(ast_parked_call_type(), payload); |
| 644 |
if (!msg) { |
| 645 |
return; |
| 646 |
} |
| 647 |
|
| 648 |
stasis_publish(ast_parking_topic(), msg); |
| 649 |
} |
| 650 |
|
| 651 |
void publish_parked_call(struct parked_user *pu, enum ast_parked_call_event_type event_type) |
| 652 |
{ |
| 653 |
RAII_VAR(struct ast_parked_call_payload *, payload, NULL, ao2_cleanup); |
| 654 |
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup); |
| 655 |
|
| 656 |
if (!ast_parked_call_type()) { |
| 657 |
return; |
| 658 |
} |
| 659 |
|
| 660 |
payload = parked_call_payload_from_parked_user(pu, event_type); |
| 661 |
if (!payload) { |
| 662 |
return; |
| 663 |
} |
| 664 |
|
| 665 |
msg = stasis_message_create(ast_parked_call_type(), payload); |
| 666 |
if (!msg) { |
| 667 |
return; |
| 668 |
} |
| 669 |
|
| 670 |
stasis_publish(ast_parking_topic(), msg); |
| 671 |
} |
| 672 |
|
| 673 |
static void parked_call_message_response(struct ast_parked_call_payload *parked_call) |
| 674 |
{ |
| 675 |
char *event_type = ""; |
| 676 |
RAII_VAR(struct ast_str *, parked_call_string, NULL, ast_free); |
| 677 |
|
| 678 |
switch (parked_call->event_type) { |
| 679 |
case PARKED_CALL: |
| 680 |
event_type = "ParkedCall"; |
| 681 |
break; |
| 682 |
case PARKED_CALL_TIMEOUT: |
| 683 |
event_type = "ParkedCallTimeOut"; |
| 684 |
break; |
| 685 |
case PARKED_CALL_GIVEUP: |
| 686 |
event_type = "ParkedCallGiveUp"; |
| 687 |
break; |
| 688 |
case PARKED_CALL_UNPARKED: |
| 689 |
event_type = "UnParkedCall"; |
| 690 |
break; |
| 691 |
case PARKED_CALL_SWAP: |
| 692 |
event_type = "ParkedCallSwap"; |
| 693 |
break; |
| 694 |
case PARKED_CALL_FAILED: |
| 695 |
|
| 696 |
return; |
| 697 |
} |
| 698 |
|
| 699 |
parked_call_string = manager_build_parked_call_string(parked_call); |
| 700 |
if (!parked_call_string) { |
| 701 |
ast_log(LOG_ERROR, "Failed to issue an AMI event of '%s' in response to a stasis message.\n", event_type); |
| 702 |
return; |
| 703 |
} |
| 704 |
|
| 705 |
manager_event(EVENT_FLAG_CALL, event_type, |
| 706 |
"%s", |
| 707 |
ast_str_buffer(parked_call_string) |
| 708 |
); |
| 709 |
} |
| 710 |
|
| 711 |
static void parking_event_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message) |
| 712 |
{ |
| 713 |
if (stasis_message_type(message) == ast_parked_call_type()) { |
| 714 |
struct ast_parked_call_payload *parked_call_message = stasis_message_data(message); |
| 715 |
parked_call_message_response(parked_call_message); |
| 716 |
} |
| 717 |
} |
| 718 |
|
| 719 |
static void parking_manager_enable_stasis(void) |
| 720 |
{ |
| 721 |
if (!parking_sub) { |
| 722 |
parking_sub = stasis_subscribe(ast_parking_topic(), parking_event_cb, NULL); |
| 723 |
stasis_subscription_accept_message_type(parking_sub, ast_parked_call_type()); |
| 724 |
stasis_subscription_set_filter(parking_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE); |
| 725 |
} |
| 726 |
} |
| 727 |
|
| 728 |
int load_parking_manager(void) |
| 729 |
{ |
| 730 |
int res; |
| 731 |
|
| 732 |
res = ast_manager_register_xml("Parkinglots", EVENT_FLAG_CALL, manager_parking_lot_list); |
| 733 |
res |= ast_manager_register_xml("ParkedCalls", EVENT_FLAG_CALL, manager_parking_status); |
| 734 |
res |= ast_manager_register_xml("Park", EVENT_FLAG_CALL, manager_park); |
| 735 |
parking_manager_enable_stasis(); |
| 736 |
return res ? -1 : 0; |
| 737 |
} |
| 738 |
|
| 739 |
static void parking_manager_disable_stasis(void) |
| 740 |
{ |
| 741 |
parking_sub = stasis_unsubscribe_and_join(parking_sub); |
| 742 |
} |
| 743 |
|
| 744 |
void unload_parking_manager(void) |
| 745 |
{ |
| 746 |
ast_manager_unregister("Parkinglots"); |
| 747 |
ast_manager_unregister("ParkedCalls"); |
| 748 |
ast_manager_unregister("Park"); |
| 749 |
parking_manager_disable_stasis(); |
| 750 |
} |