static int manager_parking_status_single_lot(struct mansession *s, const struct message *m, const char *id_text, const char *lot_name) { RAII_VAR(struct parking_lot *, curlot, NULL, ao2_cleanup); struct parked_user *curuser; struct ao2_iterator iter_users; int total = 0; curlot = parking_lot_find_by_name(lot_name); if (!curlot) { astman_send_error(s, m, "Requested parking lot could not be found."); return RESULT_SUCCESS; } astman_send_ack(s, m, "Parked calls will follow"); iter_users = ao2_iterator_init(curlot->parked_users, 0); while ((curuser = ao2_iterator_next(&iter_users))) { RAII_VAR(struct ast_parked_call_payload *, payload, NULL, ao2_cleanup); RAII_VAR(struct ast_str *, parked_call_string, NULL, ast_free); payload = parked_call_payload_from_parked_user(curuser, PARKED_CALL); if (!payload) { astman_send_error(s, m, "Failed to retrieve parking data about a parked user."); return RESULT_FAILURE; } parked_call_string = manager_build_parked_call_string(payload); if (!parked_call_string) { astman_send_error(s, m, "Failed to retrieve parkingd ata about a parked user."); return RESULT_FAILURE; } total++; astman_append(s, "Event: ParkedCall\r\n" "%s" /* The parked call string */ "%s" /* The action ID */ "\r\n", ast_str_buffer(parked_call_string), id_text); ao2_ref(curuser, -1); } ao2_iterator_destroy(&iter_users); astman_append(s, "Event: ParkedCallsComplete\r\n" "Total: %d\r\n" "%s" "\r\n", total, id_text); return RESULT_SUCCESS; }
void publish_parked_call(struct parked_user *pu, enum ast_parked_call_event_type event_type) { RAII_VAR(struct ast_parked_call_payload *, payload, NULL, ao2_cleanup); RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup); payload = parked_call_payload_from_parked_user(pu, event_type); if (!payload) { return; } msg = stasis_message_create(ast_parked_call_type(), payload); if (!msg) { return; } stasis_publish(ast_parking_topic(), msg); }
static void manager_parking_status_all_lots(struct mansession *s, const struct message *m, const char *id_text) { struct parked_user *curuser; struct ao2_container *lot_container; struct ao2_iterator iter_lots; struct ao2_iterator iter_users; struct parking_lot *curlot; int total = 0; lot_container = get_parking_lot_container(); if (!lot_container) { ast_log(LOG_ERROR, "Failed to obtain parking lot list. Action canceled.\n"); astman_send_error(s, m, "Could not create parking lot list"); return; } astman_send_listack(s, m, "Parked calls will follow", "start"); iter_lots = ao2_iterator_init(lot_container, 0); while ((curlot = ao2_iterator_next(&iter_lots))) { iter_users = ao2_iterator_init(curlot->parked_users, 0); while ((curuser = ao2_iterator_next(&iter_users))) { RAII_VAR(struct ast_parked_call_payload *, payload, NULL, ao2_cleanup); RAII_VAR(struct ast_str *, parked_call_string, NULL, ast_free); payload = parked_call_payload_from_parked_user(curuser, PARKED_CALL); if (!payload) { ao2_ref(curuser, -1); ao2_iterator_destroy(&iter_users); ao2_ref(curlot, -1); goto abort_list; } parked_call_string = manager_build_parked_call_string(payload); if (!parked_call_string) { ao2_ref(curuser, -1); ao2_iterator_destroy(&iter_users); ao2_ref(curlot, -1); goto abort_list; } total++; astman_append(s, "Event: ParkedCall\r\n" "%s" /* The parked call string */ "%s" /* The action ID */ "\r\n", ast_str_buffer(parked_call_string), id_text); ao2_ref(curuser, -1); } ao2_iterator_destroy(&iter_users); ao2_ref(curlot, -1); } abort_list: ao2_iterator_destroy(&iter_lots); astman_send_list_complete_start(s, m, "ParkedCallsComplete", total); astman_append(s, "Total: %d\r\n", total); astman_send_list_complete_end(s); }