]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip: ami: Fix error in AMI output when an endpoint has no transport
authorGeorge Joseph <george.joseph@fairview5.com>
Thu, 18 Sep 2014 15:01:11 +0000 (15:01 +0000)
committerGeorge Joseph <george.joseph@fairview5.com>
Thu, 18 Sep 2014 15:01:11 +0000 (15:01 +0000)
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
res/res_pjsip/config_auth.c
res/res_pjsip/config_transport.c
res/res_pjsip/location.c
res/res_pjsip/pjsip_configuration.c
res/res_pjsip_endpoint_identifier_ip.c

index e009ec6acb7efedba2f20acd1863a2cb4ec175bb..05c78b0a14f7671fd3684c6814dbdd1328d6b128 100644 (file)
@@ -1732,6 +1732,8 @@ struct ast_sip_ami {
        const char *action_id;
        /*! user specified argument data */
        void *arg;
+       /*! count of objects */
+       int count;
 };
 
 /*!
index bb5aa6682dd5cc53089d501ed3c1049af3e6bf12..e105e7492a7ddbee3eedd6800cdb993f5a15e089 100644 (file)
@@ -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;
 }
 
index 785fcc5ac57c7646d78e607c03b96c8e7210c871..0a56b926345107be2c9ef14b691ba85f6d34e27d 100644 (file)
@@ -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;
 }
 
index b0a49cdf770c6ca3dac7c6553dddefa0b8a5db83..d6015c7582ae346092e48b6b95f56f557acffa00 100644 (file)
@@ -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;
 }
 
index 2e2824388936ac4bcf0ee86f6269955e60b0cb05..c7b23e9d48458744e2c0656109b59c6259a9a864 100644 (file)
@@ -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;
 }
 
index f52b4447d580bc0e7784f70a88626e2ace012ff6..f497e32ebfc8e8fd4863dd522b6f296ef812711e 100644 (file)
@@ -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;
 }