summaryrefslogtreecommitdiff
path: root/res
diff options
context:
space:
mode:
Diffstat (limited to 'res')
-rw-r--r--res/parking/parking_manager.c76
-rw-r--r--res/res_fax.c17
-rw-r--r--res/res_manager_devicestate.c8
-rw-r--r--res/res_manager_presencestate.c8
-rw-r--r--res/res_mwi_external_ami.c8
-rw-r--r--res/res_pjsip/pjsip_configuration.c16
-rw-r--r--res/res_pjsip_outbound_registration.c33
-rw-r--r--res/res_pjsip_pubsub.c29
-rw-r--r--res/res_pjsip_registrar.c9
9 files changed, 86 insertions, 118 deletions
diff --git a/res/parking/parking_manager.c b/res/parking/parking_manager.c
index 73b5ff495..74b455928 100644
--- a/res/parking/parking_manager.c
+++ b/res/parking/parking_manager.c
@@ -210,11 +210,16 @@ static struct ast_str *manager_build_parked_call_string(const struct ast_parked_
parkee_string = ast_manager_build_channel_state_string_prefix(payload->parkee, "Parkee");
if (!parkee_string) {
+ ast_free(out);
return NULL;
}
if (payload->retriever) {
retriever_string = ast_manager_build_channel_state_string_prefix(payload->retriever, "Retriever");
+ if (!retriever_string) {
+ ast_free(out);
+ return NULL;
+ }
}
ast_str_set(&out, 0,
@@ -250,7 +255,7 @@ static void manager_parking_status_single_lot(struct mansession *s, const struct
return;
}
- astman_send_ack(s, m, "Parked calls will follow");
+ astman_send_listack(s, m, "Parked calls will follow", "start");
iter_users = ao2_iterator_init(curlot->parked_users, 0);
while ((curuser = ao2_iterator_next(&iter_users))) {
@@ -260,17 +265,13 @@ static void manager_parking_status_single_lot(struct mansession *s, const struct
payload = parked_call_payload_from_parked_user(curuser, PARKED_CALL);
if (!payload) {
ao2_ref(curuser, -1);
- ao2_iterator_destroy(&iter_users);
- astman_send_error(s, m, "Failed to retrieve parking data about a parked user.");
- return;
+ break;
}
parked_call_string = manager_build_parked_call_string(payload);
if (!parked_call_string) {
ao2_ref(curuser, -1);
- ao2_iterator_destroy(&iter_users);
- astman_send_error(s, m, "Failed to retrieve parking data about a parked user.");
- return;
+ break;
}
total++;
@@ -286,12 +287,9 @@ static void manager_parking_status_single_lot(struct mansession *s, const struct
}
ao2_iterator_destroy(&iter_users);
- astman_append(s,
- "Event: ParkedCallsComplete\r\n"
- "Total: %d\r\n"
- "%s"
- "\r\n",
- total, id_text);
+ astman_send_list_complete_start(s, m, "ParkedCallsComplete", total);
+ astman_append(s, "Total: %d\r\n", total);
+ astman_send_list_complete_end(s);
}
static void manager_parking_status_all_lots(struct mansession *s, const struct message *m, const char *id_text)
@@ -310,7 +308,7 @@ static void manager_parking_status_all_lots(struct mansession *s, const struct m
return;
}
- astman_send_ack(s, m, "Parked calls will follow");
+ 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))) {
@@ -324,8 +322,7 @@ static void manager_parking_status_all_lots(struct mansession *s, const struct m
ao2_ref(curuser, -1);
ao2_iterator_destroy(&iter_users);
ao2_ref(curlot, -1);
- ao2_iterator_destroy(&iter_lots);
- return;
+ goto abort_list;
}
parked_call_string = manager_build_parked_call_string(payload);
@@ -333,8 +330,7 @@ static void manager_parking_status_all_lots(struct mansession *s, const struct m
ao2_ref(curuser, -1);
ao2_iterator_destroy(&iter_users);
ao2_ref(curlot, -1);
- ao2_iterator_destroy(&iter_lots);
- return;
+ goto abort_list;
}
total++;
@@ -351,22 +347,21 @@ static void manager_parking_status_all_lots(struct mansession *s, const struct m
ao2_iterator_destroy(&iter_users);
ao2_ref(curlot, -1);
}
+abort_list:
ao2_iterator_destroy(&iter_lots);
- astman_append(s,
- "Event: ParkedCallsComplete\r\n"
- "Total: %d\r\n"
- "%s"
- "\r\n",
- total, id_text);
+ astman_send_list_complete_start(s, m, "ParkedCallsComplete", total);
+ astman_append(s, "Total: %d\r\n", total);
+ astman_send_list_complete_end(s);
}
static int manager_parking_status(struct mansession *s, const struct message *m)
{
const char *id = astman_get_header(m, "ActionID");
const char *lot_name = astman_get_header(m, "ParkingLot");
- char id_text[256] = "";
+ char id_text[256];
+ id_text[0] = '\0';
if (!ast_strlen_zero(id)) {
snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", id);
}
@@ -380,24 +375,30 @@ static int manager_parking_status(struct mansession *s, const struct message *m)
return 0;
}
+struct park_list_data {
+ const char *id_text;
+ int count;
+};
+
static int manager_append_event_parking_lot_data_cb(void *obj, void *arg, void *data, int flags)
{
struct parking_lot *curlot = obj;
struct mansession *s = arg;
- char *id_text = data;
+ struct park_list_data *list_data = data;
astman_append(s, "Event: Parkinglot\r\n"
+ "%s" /* The Action ID */
"Name: %s\r\n"
"StartSpace: %d\r\n"
"StopSpace: %d\r\n"
"Timeout: %u\r\n"
- "%s" /* The Action ID */
"\r\n",
+ list_data->id_text,
curlot->name,
curlot->cfg->parking_start,
curlot->cfg->parking_stop,
- curlot->cfg->parkingtime,
- id_text);
+ curlot->cfg->parkingtime);
+ ++list_data->count;
return 0;
}
@@ -405,9 +406,11 @@ static int manager_append_event_parking_lot_data_cb(void *obj, void *arg, void *
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;
+ 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);
}
@@ -419,14 +422,15 @@ static int manager_parking_lot_list(struct mansession *s, const struct message *
return 0;
}
- astman_send_ack(s, m, "Parking lots will follow");
+ astman_send_listack(s, m, "Parking lots will follow", "start");
- ao2_callback_data(lot_container, OBJ_MULTIPLE | OBJ_NODATA, manager_append_event_parking_lot_data_cb, s, id_text);
+ 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_append(s,
- "Event: ParkinglotsComplete\r\n"
- "%s"
- "\r\n",id_text);
+ astman_send_list_complete_start(s, m, "ParkinglotsComplete", list_data.count);
+ astman_send_list_complete_end(s);
return 0;
}
diff --git a/res/res_fax.c b/res/res_fax.c
index b5e5411ee..5f2798ab4 100644
--- a/res/res_fax.c
+++ b/res/res_fax.c
@@ -4190,17 +4190,18 @@ static int manager_fax_sessions_entry(struct mansession *s,
static int manager_fax_sessions(struct mansession *s, const struct message *m)
{
const char *action_id = astman_get_header(m, "ActionID");
- char id_text[256] = "";
+ char id_text[256];
struct ast_fax_session *session;
struct ao2_iterator iter;
int session_count = 0;
- astman_send_listack(s, m, "FAXSessionsEntry event list will follow", "Start");
-
+ id_text[0] = '\0';
if (!ast_strlen_zero(action_id)) {
snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", action_id);
}
+ astman_send_listack(s, m, "FAXSessionsEntry event list will follow", "Start");
+
iter = ao2_iterator_init(faxregistry.container, 0);
while ((session = ao2_iterator_next(&iter))) {
if (!manager_fax_sessions_entry(s, session, id_text)) {
@@ -4210,13 +4211,9 @@ static int manager_fax_sessions(struct mansession *s, const struct message *m)
}
ao2_iterator_destroy(&iter);
- astman_append(s, "Event: FAXSessionsComplete\r\n"
- "%s"
- "EventList: Complete\r\n"
- "Total: %d\r\n"
- "\r\n",
- id_text,
- session_count);
+ astman_send_list_complete_start(s, m, "FAXSessionsComplete", session_count);
+ astman_append(s, "Total: %d\r\n", session_count);
+ astman_send_list_complete_end(s);
return 0;
}
diff --git a/res/res_manager_devicestate.c b/res/res_manager_devicestate.c
index 25eae87d7..3d1f1ab10 100644
--- a/res/res_manager_devicestate.c
+++ b/res/res_manager_devicestate.c
@@ -106,12 +106,8 @@ static int action_devicestatelist(struct mansession *s, const struct message *m)
}
ao2_iterator_destroy(&it_states);
- astman_append(s, "Event: DeviceStateListComplete\r\n");
- if (!ast_strlen_zero(action_id)) {
- astman_append(s, "ActionID: %s\r\n", action_id);
- }
- astman_append(s, "EventList: Complete\r\n"
- "ListItems: %d\r\n\r\n", count);
+ astman_send_list_complete_start(s, m, "DeviceStateListComplete", count);
+ astman_send_list_complete_end(s);
return 0;
}
diff --git a/res/res_manager_presencestate.c b/res/res_manager_presencestate.c
index e2cfca506..bb9e63ab9 100644
--- a/res/res_manager_presencestate.c
+++ b/res/res_manager_presencestate.c
@@ -106,12 +106,8 @@ static int action_presencestatelist(struct mansession *s, const struct message *
}
ao2_iterator_destroy(&it_states);
- astman_append(s, "Event: PresenceStateListComplete\r\n");
- if (!ast_strlen_zero(action_id)) {
- astman_append(s, "ActionID: %s\r\n", action_id);
- }
- astman_append(s, "EventList: Complete\r\n"
- "ListItems: %d\r\n\r\n", count);
+ astman_send_list_complete_start(s, m, "PresenceStateListComplete", count);
+ astman_send_list_complete_end(s);
return 0;
}
diff --git a/res/res_mwi_external_ami.c b/res/res_mwi_external_ami.c
index b1360e9e3..87ce411e6 100644
--- a/res/res_mwi_external_ami.c
+++ b/res/res_mwi_external_ami.c
@@ -226,12 +226,8 @@ static int mwi_mailbox_get(struct mansession *s, const struct message *m)
ao2_iterator_destroy(&iter);
ao2_ref(mailboxes, -1);
- astman_append(s,
- "Event: MWIGetComplete\r\n"
- "EventList: Complete\r\n"
- "ListItems: %u\r\n"
- "%s"
- "\r\n", count, id_text);
+ astman_send_list_complete_start(s, m, "MWIGetComplete", count);
+ astman_send_list_complete_end(s);
return 0;
}
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index 3b58cea49..cc8674fb7 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -1172,12 +1172,8 @@ static int ami_show_endpoint(struct mansession *s, const struct message *m)
endpoint_name);
}
- astman_append(s, "Event: EndpointDetailComplete\r\n");
- if (!ast_strlen_zero(ami.action_id)) {
- astman_append(s, "ActionID: %s\r\n", ami.action_id);
- }
- astman_append(s, "EventList: Complete\r\n"
- "ListItems: %d\r\n\r\n", ami.count + 1);
+ astman_send_list_complete_start(s, m, "EndpointDetailComplete", ami.count + 1);
+ astman_send_list_complete_end(s);
return 0;
}
@@ -1255,12 +1251,8 @@ static int ami_show_endpoints(struct mansession *s, const struct message *m)
ao2_callback(endpoints, OBJ_NODATA, format_ami_endpoints, &ami);
- astman_append(s, "Event: EndpointListComplete\r\n");
- if (!ast_strlen_zero(ami.action_id)) {
- astman_append(s, "ActionID: %s\r\n", ami.action_id);
- }
- astman_append(s, "EventList: Complete\r\n"
- "ListItems: %d\r\n\r\n", num);
+ astman_send_list_complete_start(s, m, "EndpointListComplete", num);
+ astman_send_list_complete_end(s);
return 0;
}
diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c
index 75dae1f37..b06e3d33a 100644
--- a/res/res_pjsip_outbound_registration.c
+++ b/res/res_pjsip_outbound_registration.c
@@ -1286,10 +1286,10 @@ struct sip_ami_outbound {
static int ami_outbound_registration_task(void *obj)
{
struct sip_ami_outbound *ami = obj;
- RAII_VAR(struct ast_str *, buf,
- ast_sip_create_ami_event("OutboundRegistrationDetail", ami->ami), ast_free);
+ RAII_VAR(struct ast_str *, buf, NULL, ast_free);
struct sip_outbound_registration_state *state;
+ buf = ast_sip_create_ami_event("OutboundRegistrationDetail", ami->ami);
if (!buf) {
return -1;
}
@@ -1298,18 +1298,18 @@ static int ami_outbound_registration_task(void *obj)
if ((state = get_state(ast_sorcery_object_get_id(ami->registration)))) {
pjsip_regc_info info;
+
if (state->client_state->status == SIP_REGISTRATION_REGISTERED) {
++ami->registered;
} else {
++ami->not_registered;
}
- ast_str_append(&buf, 0, "Status: %s%s",
- sip_outbound_registration_status_str[
- state->client_state->status], "\r\n");
+ ast_str_append(&buf, 0, "Status: %s\r\n",
+ sip_outbound_registration_status_str[state->client_state->status]);
pjsip_regc_get_info(state->client_state->client, &info);
- ast_str_append(&buf, 0, "NextReg: %d%s", info.next_reg, "\r\n");
+ ast_str_append(&buf, 0, "NextReg: %d\r\n", info.next_reg);
ao2_ref(state, -1);
}
@@ -1339,20 +1339,19 @@ static int ami_show_outbound_registrations(struct mansession *s,
return -1;
}
- astman_send_listack(s, m, "Following are Events for each Outbound "
- "registration", "start");
+ astman_send_listack(s, m, "Following are Events for each Outbound registration",
+ "start");
ao2_callback(regs, OBJ_NODATA, ami_outbound_registration_detail, &ami_outbound);
- astman_append(s, "Event: OutboundRegistrationDetailComplete\r\n");
- if (!ast_strlen_zero(ami.action_id)) {
- astman_append(s, "ActionID: %s\r\n", ami.action_id);
- }
- astman_append(s, "EventList: Complete\r\n"
- "Registered: %d\r\n"
- "NotRegistered: %d\r\n\r\n",
- ami_outbound.registered,
- ami_outbound.not_registered);
+ astman_send_list_complete_start(s, m, "OutboundRegistrationDetailComplete",
+ ami_outbound.registered + ami_outbound.not_registered);
+ astman_append(s,
+ "Registered: %d\r\n"
+ "NotRegistered: %d\r\n",
+ ami_outbound.registered,
+ ami_outbound.not_registered);
+ astman_send_list_complete_end(s);
return 0;
}
diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c
index 23f04bb04..f143fa015 100644
--- a/res/res_pjsip_pubsub.c
+++ b/res/res_pjsip_pubsub.c
@@ -3232,15 +3232,16 @@ static int ami_subscription_detail(struct sip_subscription_tree *sub_tree,
struct ast_sip_ami *ami,
const char *event)
{
- RAII_VAR(struct ast_str *, buf,
- ast_sip_create_ami_event(event, ami), ast_free);
+ struct ast_str *buf;
+ buf = ast_sip_create_ami_event(event, ami);
if (!buf) {
return -1;
}
sip_subscription_to_ami(sub_tree, &buf);
astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
+ ast_free(buf);
return 0;
}
@@ -3266,12 +3267,8 @@ static int ami_show_subscriptions_inbound(struct mansession *s, const struct mes
num = for_each_subscription(ami_subscription_detail_inbound, &ami);
- astman_append(s, "Event: InboundSubscriptionDetailComplete\r\n");
- if (!ast_strlen_zero(ami.action_id)) {
- astman_append(s, "ActionID: %s\r\n", ami.action_id);
- }
- astman_append(s, "EventList: Complete\r\n"
- "ListItems: %d\r\n\r\n", num);
+ astman_send_list_complete_start(s, m, "InboundSubscriptionDetailComplete", num);
+ astman_send_list_complete_end(s);
return 0;
}
@@ -3285,12 +3282,8 @@ static int ami_show_subscriptions_outbound(struct mansession *s, const struct me
num = for_each_subscription(ami_subscription_detail_outbound, &ami);
- astman_append(s, "Event: OutboundSubscriptionDetailComplete\r\n");
- if (!ast_strlen_zero(ami.action_id)) {
- astman_append(s, "ActionID: %s\r\n", ami.action_id);
- }
- astman_append(s, "EventList: Complete\r\n"
- "ListItems: %d\r\n\r\n", num);
+ astman_send_list_complete_start(s, m, "OutboundSubscriptionDetailComplete", num);
+ astman_send_list_complete_end(s);
return 0;
}
@@ -3317,7 +3310,7 @@ static int format_ami_resource_lists(void *obj, void *arg, int flags)
static int ami_show_resource_lists(struct mansession *s, const struct message *m)
{
- struct ast_sip_ami ami = { .s = s, .m = m };
+ struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"), };
int num;
struct ao2_container *lists;
@@ -3334,10 +3327,8 @@ static int ami_show_resource_lists(struct mansession *s, const struct message *m
ao2_callback(lists, OBJ_NODATA, format_ami_resource_lists, &ami);
- astman_append(s,
- "Event: ResourceListDetailComplete\r\n"
- "EventList: Complete\r\n"
- "ListItems: %d\r\n\r\n", num);
+ astman_send_list_complete_start(s, m, "ResourceListDetailComplete", num);
+ astman_send_list_complete_end(s);
return 0;
}
diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c
index aad3dd4a7..2e298bd69 100644
--- a/res/res_pjsip_registrar.c
+++ b/res/res_pjsip_registrar.c
@@ -766,17 +766,14 @@ static int ami_show_registrations(struct mansession *s, const struct message *m)
{
int count = 0;
struct ast_sip_ami ami = { .s = s, .m = m, .arg = &count, .action_id = astman_get_header(m, "ActionID"), };
+
astman_send_listack(s, m, "Following are Events for each Inbound "
"registration", "start");
ami_registrations_endpoints(&ami);
- astman_append(s, "Event: InboundRegistrationDetailComplete\r\n");
- if (!ast_strlen_zero(ami.action_id)) {
- astman_append(s, "ActionID: %s\r\n", ami.action_id);
- }
- astman_append(s, "EventList: Complete\r\n"
- "ListItems: %d\r\n\r\n", count);
+ astman_send_list_complete_start(s, m, "InboundRegistrationDetailComplete", count);
+ astman_send_list_complete_end(s);
return 0;
}