]> granicus.if.org Git - apache/commitdiff
giving ap_array_index a start parameter, adding ap_array_contains
authorStefan Eissing <icing@apache.org>
Thu, 27 Aug 2015 12:13:59 +0000 (12:13 +0000)
committerStefan Eissing <icing@apache.org>
Thu, 27 Aug 2015 12:13:59 +0000 (12:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1698133 13f79535-47bb-0310-9956-ffa450edef68

include/httpd.h
modules/http2/h2_switch.c
server/protocol.c
server/util.c

index 54b356cfa0008e3d7e9a9d98877f5f74705ed51c..24e1e2d9cce12fd7486edbfd20190beddf7ffc3b 100644 (file)
@@ -2403,12 +2403,26 @@ AP_DECLARE(char *) ap_get_exec_line(apr_pool_t *p,
 #define AP_NORESTART APR_OS_START_USEERR + 1
 
 /**
- * Get the index of the string in the array or -1 if not found.
- * @param array the array the check
- * @param s the string to find
+ * Get the first index of the string in the array or -1 if not found. Start
+ * searching a start. 
+ * @param array The array the check
+ * @param s The string to find
+ * @param start Start index for search. If start is greater or 
+                equal to array length, -1 will be returned.
  * @return index of string in array or -1
  */
-AP_DECLARE(int) ap_array_index(const apr_array_header_t *array, const char *s);
+AP_DECLARE(int) ap_array_index(const apr_array_header_t *array, 
+                               const char *s,
+                               apr_size_t start);
+
+/**
+ * Check if the string is member of the given array by strcmp.
+ * @param array The array the check
+ * @param s The string to find
+ * @return !=0 iff string is member of array
+ */
+AP_DECLARE(int) ap_array_contains(const apr_array_header_t *array, 
+                                  const char *s);
 
 #ifdef __cplusplus
 }
index 46790ba4052a5b4d3adcdbd39cc599ed3c490687..2b74debd3440832e4379f92c5cf8871c33fe5dc7 100644 (file)
@@ -107,7 +107,7 @@ static int h2_protocol_propose(conn_rec *c, request_rec *r,
         /* Add all protocols we know (tls or clear) and that
          * are part of the offerings (if there have been any). 
          */
-        if (!offers || ap_array_index(offers, *protos) >= 0) {
+        if (!offers || ap_array_contains(offers, *protos)) {
             ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, c,
                           "proposing protocol '%s'", *protos);
             APR_ARRAY_PUSH(proposals, const char*) = *protos;
index cc23ae176c5f0d958951dfece8d3cedd7526414b..d78408cf2bbf1474da5c8e3f8bbf2d735bd3c1ff 100644 (file)
@@ -1956,8 +1956,8 @@ static int protocol_cmp(apr_array_header_t *preferences,
                         const char *proto2)
 {
     if (preferences && preferences->nelts > 0) {
-        int index1 = ap_array_index(preferences, proto1);
-        int index2 = ap_array_index(preferences, proto2);
+        int index1 = ap_array_index(preferences, proto1, 0);
+        int index2 = ap_array_index(preferences, proto2, 0);
         if (index2 > index1) {
             return (index1 >= 0) ? 1 : -1;
         }
@@ -2006,8 +2006,8 @@ AP_DECLARE(const char *) ap_select_protocol(conn_rec *c, request_rec *r,
         /* If the existing protocol has not been proposed, but is a choice,
          * add it to the proposals implicitly.
          */
-        if (ap_array_index(proposals, existing) < 0 
-            && ap_array_index(choices, existing) >= 0) {
+        if (!ap_array_contains(proposals, existing) 
+            && ap_array_contains(choices, existing)) {
             APR_ARRAY_PUSH(proposals, const char*) = existing;
         }
         
@@ -2021,7 +2021,7 @@ AP_DECLARE(const char *) ap_select_protocol(conn_rec *c, request_rec *r,
         for (i = 0; i < proposals->nelts; ++i) {
             const char *p = APR_ARRAY_IDX(proposals, i, const char *);
             if (conf->protocols->nelts > 0 
-                && ap_array_index(conf->protocols, p) < 0) {
+                && !ap_array_contains(conf->protocols, p)) {
                 /* not a permitted protocol here */
                 continue;
             }
index c77635fe0eaaee6291019ecfcc912afd2064dd07..21a765123556c2681042581f4755dba802f349f3 100644 (file)
@@ -3149,15 +3149,23 @@ AP_DECLARE(char *) ap_get_exec_line(apr_pool_t *p,
     return apr_pstrndup(p, buf, k);
 }
 
-AP_DECLARE(int) ap_array_index(const apr_array_header_t *array, const char *s)
+AP_DECLARE(int) ap_array_index(const apr_array_header_t *array, 
+                               const char *s,
+                               apr_size_t start)
 {
-    int i;
-    for (i = 0; i < array->nelts; i++) {
+    apr_size_t i;
+    for (i = start; i < array->nelts; i++) {
         const char *p = APR_ARRAY_IDX(array, i, const char *);
         if (!strcmp(p, s)) {
-            return i;
+            return (int)i;
         }
     }
     return -1;
 }
 
+AP_DECLARE(int) ap_array_contains(const apr_array_header_t *array, 
+                                  const char *s)
+{
+    return (ap_array_index(array, s, 0) >= 0);
+}
+