From b436f387cc1bbb667df996158cb9e5dce6d7c662 Mon Sep 17 00:00:00 2001 From: George Joseph Date: Thu, 18 Sep 2014 15:01:11 +0000 Subject: [PATCH] res_pjsip: ami: Fix error in AMI output when an endpoint has no transport When no transport is associated to an endpoint, the AMI output for PJSIPShowEndpoint indicates an error instead of silently ignoring the missing transport. This patch causes the error to appear only if a transport was specified on the endpoint and the transport doesn't exist. It also fixes an issue with counting the objects that were actually found. ASTERISK-24161 #close ASTERISK-24331 #close Tested by: George Joseph Review: https://reviewboard.asterisk.org/r/3998/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@423282 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- include/asterisk/res_pjsip.h | 2 ++ res/res_pjsip/config_auth.c | 2 ++ res/res_pjsip/config_transport.c | 18 ++++++++++++------ res/res_pjsip/location.c | 2 ++ res/res_pjsip/pjsip_configuration.c | 6 ++++-- res/res_pjsip_endpoint_identifier_ip.c | 2 ++ 6 files changed, 24 insertions(+), 8 deletions(-) diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h index e009ec6acb..05c78b0a14 100644 --- a/include/asterisk/res_pjsip.h +++ b/include/asterisk/res_pjsip.h @@ -1732,6 +1732,8 @@ struct ast_sip_ami { const char *action_id; /*! user specified argument data */ void *arg; + /*! count of objects */ + int count; }; /*! diff --git a/res/res_pjsip/config_auth.c b/res/res_pjsip/config_auth.c index bb5aa6682d..e105e7492a 100644 --- a/res/res_pjsip/config_auth.c +++ b/res/res_pjsip/config_auth.c @@ -174,6 +174,8 @@ static int format_ami_auth_handler(void *obj, void *arg, int flags) } astman_append(ami->s, "%s\r\n", ast_str_buffer(buf)); + ami->count++; + return 0; } diff --git a/res/res_pjsip/config_transport.c b/res/res_pjsip/config_transport.c index 785fcc5ac5..0a56b92634 100644 --- a/res/res_pjsip/config_transport.c +++ b/res/res_pjsip/config_transport.c @@ -39,16 +39,20 @@ static int sip_transport_to_ami(const struct ast_sip_transport *transport, static int format_ami_endpoint_transport(const struct ast_sip_endpoint *endpoint, struct ast_sip_ami *ami) { - RAII_VAR(struct ast_str *, buf, - ast_sip_create_ami_event("TransportDetail", ami), ast_free); - RAII_VAR(struct ast_sip_transport *, - transport, ast_sorcery_retrieve_by_id( - ast_sip_get_sorcery(), "transport", - endpoint->transport), ao2_cleanup); + RAII_VAR(struct ast_str *, buf, NULL, ast_free); + RAII_VAR(struct ast_sip_transport *, transport, NULL, ao2_cleanup); + + if (ast_strlen_zero(endpoint->transport)) { + return 0; + } + + buf = ast_sip_create_ami_event("TransportDetail", ami); if (!buf) { return -1; } + transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", + endpoint->transport); if (!transport) { astman_send_error_va(ami->s, ami->m, "Unable to retrieve " "transport %s\n", endpoint->transport); @@ -61,6 +65,8 @@ static int format_ami_endpoint_transport(const struct ast_sip_endpoint *endpoint ast_sorcery_object_get_id(endpoint)); astman_append(ami->s, "%s\r\n", ast_str_buffer(buf)); + ami->count++; + return 0; } diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c index b0a49cdf77..d6015c7582 100644 --- a/res/res_pjsip/location.c +++ b/res/res_pjsip/location.c @@ -506,6 +506,8 @@ static int format_ami_aor_handler(void *obj, void *arg, int flags) ast_sorcery_object_get_id(endpoint)); astman_append(ami->s, "%s\r\n", ast_str_buffer(buf)); + ami->count++; + return 0; } diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c index 2e28243889..c7b23e9d48 100644 --- a/res/res_pjsip/pjsip_configuration.c +++ b/res/res_pjsip/pjsip_configuration.c @@ -1112,7 +1112,8 @@ static int format_ami_endpoint(const struct ast_sip_endpoint *endpoint, static int ami_show_endpoint(struct mansession *s, const struct message *m) { - struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"), }; + struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"), + .count = 0, }; RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup); const char *endpoint_name = astman_get_header(m, "Endpoint"); int count = 0; @@ -1149,7 +1150,8 @@ static int ami_show_endpoint(struct mansession *s, const struct message *m) astman_append(s, "ActionID: %s\r\n", ami.action_id); } astman_append(s, "EventList: Complete\r\n" - "ListItems: %d\r\n\r\n", count + 1); + "ListItems: %d\r\n\r\n", ami.count + 1); + return 0; } diff --git a/res/res_pjsip_endpoint_identifier_ip.c b/res/res_pjsip_endpoint_identifier_ip.c index f52b4447d5..f497e32ebf 100644 --- a/res/res_pjsip_endpoint_identifier_ip.c +++ b/res/res_pjsip_endpoint_identifier_ip.c @@ -263,6 +263,8 @@ static int format_ami_endpoint_identify(const struct ast_sip_endpoint *endpoint, ast_sorcery_object_get_id(endpoint)); astman_append(ami->s, "%s\r\n", ast_str_buffer(buf)); + ami->count++; + return 0; } -- 2.47.3