Merge "res_pjsip_endpoint_identifier_ip.c: Remove unnecessary requirement."
[asterisk/asterisk.git] / res / res_pjsip_endpoint_identifier_ip.c
index 7cc2dc5..a672b33 100644 (file)
                                        <para>This module provides alternatives to matching inbound requests to
                                        a configured endpoint. At least one of the matching mechanisms
                                        must be provided, or the object configuration will be invalid.</para>
-                                       <para>If multiple criteria are provided, an inbound request will
-                                       be matched if it matches <emphasis>any</emphasis> of the criteria.</para>
                                        <para>The matching mechanisms are provided by the following
                                        configuration options:</para>
                                        <enumlist>
                                                <enum name="match"><para>Match by source IP address.</para></enum>
                                                <enum name="match_header"><para>Match by SIP header.</para></enum>
                                        </enumlist>
+                                       <note><para>If multiple matching criteria are provided then an inbound
+                                       request will be matched to the endpoint if it matches
+                                       <emphasis>any</emphasis> of the criteria.</para></note>
                                </description>
                                <configOption name="endpoint">
-                                       <synopsis>Name of Endpoint</synopsis>
+                                       <synopsis>Name of endpoint identified</synopsis>
                                </configOption>
                                <configOption name="match">
                                        <synopsis>IP addresses or networks to match against.</synopsis>
-                                       <description><para>
-                                               The value is a comma-delimited list of IP addresses. IP addresses may
-                                               have a subnet mask appended. The subnet mask may be written in either
-                                               CIDR or dot-decimal notation. Separate the IP address and subnet
-                                               mask with a slash ('/').
-                                       </para></description>
+                                       <description>
+                                               <para>The value is a comma-delimited list of IP addresses or
+                                               hostnames.  IP addresses may have a subnet mask appended.  The
+                                               subnet mask may be written in either CIDR or dotted-decimal
+                                               notation.  Separate the IP address and subnet mask with a slash
+                                               ('/').
+                                               </para>
+                                       </description>
                                </configOption>
                                <configOption name="srv_lookups" default="yes">
                                        <synopsis>Perform SRV lookups for provided hostnames.</synopsis>
-                                       <description><para>When enabled, <replaceable>srv_lookups</replaceable> will
-                                       perform SRV lookups for _sip._udp, _sip._tcp, and _sips._tcp of the given
-                                       hostnames to determine additional addresses that traffic may originate from.
-                                       </para></description>
+                                       <description>
+                                               <para>When enabled, <replaceable>srv_lookups</replaceable> will
+                                               perform SRV lookups for _sip._udp, _sip._tcp, and _sips._tcp of
+                                               the given hostnames to determine additional addresses that traffic
+                                               may originate from.
+                                               </para>
+                                       </description>
                                </configOption>
                                <configOption name="match_header">
                                        <synopsis>Header/value pair to match against.</synopsis>
-                                       <description><para>A SIP header who value is used to match against. SIP
-                                       requests containing the header, along with the specified value, will be
-                                       mapped to the specified endpoint. The header must be specified with a
-                                       <literal>:</literal>, as in <literal>match_header = SIPHeader: value</literal>.
-                                       </para></description>
+                                       <description>
+                                               <para>A SIP header whose value is used to match against.  SIP
+                                               requests containing the header, along with the specified value,
+                                               will be mapped to the specified endpoint.  The header must be
+                                               specified with a <literal>:</literal>, as in
+                                               <literal>match_header = SIPHeader: value</literal>.
+                                               </para>
+                                       </description>
                                </configOption>
                                <configOption name="type">
                                        <synopsis>Must be of type 'identify'.</synopsis>
@@ -477,47 +486,54 @@ static int sip_identify_to_ami(const struct ip_identify_match *identify,
        return ast_sip_sorcery_object_to_ami(identify, buf);
 }
 
-static int find_identify_by_endpoint(void *obj, void *arg, int flags)
+static int send_identify_ami_event(void *obj, void *arg, void *data, int flags)
 {
        struct ip_identify_match *identify = obj;
        const char *endpoint_name = arg;
+       struct ast_sip_ami *ami = data;
+       struct ast_str *buf;
 
-       return strcmp(identify->endpoint_name, endpoint_name) ? 0 : CMP_MATCH;
+       /* Build AMI event */
+       buf = ast_sip_create_ami_event("IdentifyDetail", ami);
+       if (!buf) {
+               return CMP_STOP;
+       }
+       if (sip_identify_to_ami(identify, &buf)) {
+               ast_free(buf);
+               return CMP_STOP;
+       }
+       ast_str_append(&buf, 0, "EndpointName: %s\r\n", endpoint_name);
+
+       /* Send AMI event */
+       astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
+       ++ami->count;
+
+       ast_free(buf);
+       return 0;
 }
 
 static int format_ami_endpoint_identify(const struct ast_sip_endpoint *endpoint,
                                        struct ast_sip_ami *ami)
 {
-       RAII_VAR(struct ao2_container *, identifies, NULL, ao2_cleanup);
-       RAII_VAR(struct ip_identify_match *, identify, NULL, ao2_cleanup);
-       RAII_VAR(struct ast_str *, buf, NULL, ast_free);
+       struct ao2_container *identifies;
+       struct ast_variable fields = {
+               .name = "endpoint",
+               .value = ast_sorcery_object_get_id(endpoint),
+       };
 
        identifies = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "identify",
-               AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
+               AST_RETRIEVE_FLAG_MULTIPLE, &fields);
        if (!identifies) {
                return -1;
        }
 
-       identify = ao2_callback(identifies, 0, find_identify_by_endpoint,
-               (void *) ast_sorcery_object_get_id(endpoint));
-       if (!identify) {
-               return 1;
-       }
-
-       if (!(buf = ast_sip_create_ami_event("IdentifyDetail", ami))) {
-               return -1;
-       }
-
-       if (sip_identify_to_ami(identify, &buf)) {
-               return -1;
-       }
-
-       ast_str_append(&buf, 0, "EndpointName: %s\r\n",
-               ast_sorcery_object_get_id(endpoint));
-
-       astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
-       ami->count++;
+       /* Build and send any found identify object's AMI IdentifyDetail event. */
+       ao2_callback_data(identifies, OBJ_MULTIPLE | OBJ_NODATA,
+               send_identify_ami_event,
+               (void *) ast_sorcery_object_get_id(endpoint),
+               ami);
 
+       ao2_ref(identifies, -1);
        return 0;
 }