static int manager_parking_lot_list(struct mansession *s, const struct message *m) { const char *id = astman_get_header(m, "ActionID"); struct ao2_container *lot_container; char id_text[256]; struct park_list_data list_data; id_text[0] = '\0'; if (!ast_strlen_zero(id)) { snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", id); } 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 0; } astman_send_listack(s, m, "Parking lots will follow", "start"); list_data.id_text = id_text; list_data.count = 0; ao2_callback_data(lot_container, OBJ_MULTIPLE | OBJ_NODATA, manager_append_event_parking_lot_data_cb, s, &list_data); astman_send_list_complete_start(s, m, "ParkinglotsComplete", list_data.count); astman_send_list_complete_end(s); return 0; }
static int manager_parking_lot_list(struct mansession *s, const struct message *m) { const char *id = astman_get_header(m, "ActionID"); char id_text[256] = ""; struct ao2_container *lot_container; if (!ast_strlen_zero(id)) { snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", id); } 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 -1; } astman_send_ack(s, m, "Parking lots will follow"); ao2_callback_data(lot_container, OBJ_MULTIPLE | OBJ_NODATA, manager_append_event_parking_lot_data_cb, s, id_text); astman_append(s, "Event: ParkinglotsComplete\r\n" "%s" "\r\n",id_text); return RESULT_SUCCESS; }
static void cli_display_parking_lot_list(int fd) { struct ao2_container *lot_container; lot_container = get_parking_lot_container(); if (!lot_container) { ast_cli(fd, "Failed to obtain parking lot list.\n\n"); return; } ao2_callback(lot_container, OBJ_MULTIPLE | OBJ_NODATA, display_parking_lot_cb, &fd); ast_cli(fd, "\n"); }
static char *complete_parking_lot(const char *word, int seeking) { char *ret = NULL; struct parking_lot *lot; struct ao2_container *global_lots = get_parking_lot_container(); struct parking_lot_complete search = { .seeking = seeking, }; lot = ao2_callback_data(global_lots, ast_strlen_zero(word) ? 0 : OBJ_PARTIAL_KEY, complete_parking_lot_search, (char *) word, &search); if (!lot) { return NULL; } ret = ast_strdup(lot->name); ao2_ref(lot, -1); return ret; }
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); }