[mirrorbrain-commits] r8045 - /trunk/mod_mirrorbrain/mod_mirrorbrain.c

From: <poeml_at_mirrorbrain.org>
Date: Wed, 05 May 2010 15:41:46 -0000
Author: poeml
Date: Wed May  5 17:41:44 2010
New Revision: 8045

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8045&view=rev
Log:
mod_mirrorbrain: using apr_is_empty_array(), instead of testing for the "nelts"
element of the array struct, increases code readability.

Modified:
    trunk/mod_mirrorbrain/mod_mirrorbrain.c

Modified: trunk/mod_mirrorbrain/mod_mirrorbrain.c
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mod_mirrorbrain/mod_mirrorbrain.c?rev=8045&r1=8044&r2=8045&view=diff
==============================================================================
--- trunk/mod_mirrorbrain/mod_mirrorbrain.c (original)
+++ trunk/mod_mirrorbrain/mod_mirrorbrain.c Wed May  5 17:41:44 2010
_at_@ -1272,7 +1272,7 @@
         }
 
         /* is the request originating from an ip address excluded from redirecting? */
-        if (cfg->exclude_ips->nelts) {
+        if (!apr_is_empty_array(cfg->exclude_ips)) {
             for (i = 0; i < cfg->exclude_ips->nelts; i++) {
                 char *ip = ((char **) cfg->exclude_ips->elts)[i];
                 if (strcmp(ip, clientip) == 0) {
_at_@ -1286,7 +1286,7 @@
         }
 
         /* is the request originating from a network excluded from redirecting? */
-        if (cfg->exclude_networks->nelts) {
+        if (!apr_is_empty_array(cfg->exclude_networks)) {
             for (i = 0; i < cfg->exclude_networks->nelts; i++) {
                 char *network = ((char **) cfg->exclude_networks->elts)[i];
                 if (strncmp(network, clientip, strlen(network)) == 0) {
_at_@ -1301,7 +1301,7 @@
 
 
         /* is the file in the list of mimetypes to never mirror? */
-        if ((r->content_type) && (cfg->exclude_mime->nelts)) {
+        if ((r->content_type) && !apr_is_empty_array(cfg->exclude_mime)) {
             for (i = 0; i < cfg->exclude_mime->nelts; i++) {
                 char *mimetype = ((char **) cfg->exclude_mime->elts)[i];
                 if (wild_match(mimetype, r->content_type)) {
_at_@ -1317,7 +1317,7 @@
         /* is this User-Agent excluded from redirecting? */
         const char *user_agent = 
             (const char *) apr_table_get(r->headers_in, "User-Agent");
-        if (user_agent && (cfg->exclude_agents->nelts)) {
+        if (user_agent && !apr_is_empty_array(cfg->exclude_agents)) {
             for (i = 0; i < cfg->exclude_agents->nelts; i++) {
                 char *agent = ((char **) cfg->exclude_agents->elts)[i];
                 if (wild_match(agent, user_agent)) {
_at_@ -2044,7 +2044,7 @@
                 apr_psprintf(r->pool, "&amp;as=http://%s%s", ap_escape_uri(r->pool, r->hostname), 
                                                              ap_escape_uri(r->pool, r->uri));
 
-            if (scfg->tracker_urls->nelts) {
+            if (!apr_is_empty_array(scfg->tracker_urls)) {
                 for (i = 0; i < scfg->tracker_urls->nelts; i++) {
                     char *url = ((char **) scfg->tracker_urls->elts)[i];
                     APR_ARRAY_PUSH(m, char *) = 
_at_@ -2512,7 +2512,7 @@
 
 
         /* prefix */
-        if (mirrors_same_prefix->nelts) {
+        if (!apr_is_empty_array(mirrors_same_prefix)) {
             ap_rprintf(r, "\n  <h3>Found %d mirror%s directly nearby (within the same network prefix: %s :-)</h3>\n", 
                        mirrors_same_prefix->nelts, 
                        (mirrors_same_prefix->nelts == 1) ? "" : "s",
_at_@ -2531,7 +2531,7 @@
         }
 
         /* AS */
-        if (mirrors_same_as->nelts) {
+        if (!apr_is_empty_array(mirrors_same_as)) {
             ap_rprintf(r, "\n  <h3>Found %d mirror%s very close (within the same autonomous system (AS%s):</h3>\n", 
                        mirrors_same_as->nelts, 
                        (mirrors_same_as->nelts == 1) ? "" : "s",
_at_@ -2550,7 +2550,7 @@
         }
 
         /* country */
-        if (mirrors_same_country->nelts) {
+        if (!apr_is_empty_array(mirrors_same_country)) {
             ap_rprintf(r, "\n  <h3>Found %d mirror%s which handle this country (%s):</h3>\n", 
                        mirrors_same_country->nelts, 
                        (mirrors_same_country->nelts == 1) ? "" : "s",
_at_@ -2569,7 +2569,7 @@
         }
 
         /* region */
-        if (mirrors_same_region->nelts) {
+        if (!apr_is_empty_array(mirrors_same_region)) {
             ap_rprintf(r, "\n  <h3>Found %d mirror%s in other countries, but same continent (%s):</h3>\n", 
                        mirrors_same_region->nelts,
                        (mirrors_same_region->nelts == 1) ? "" : "s",
_at_@ -2588,7 +2588,7 @@
         }
 
         /* elsewhere */
-        if (mirrors_elsewhere->nelts) {
+        if (!apr_is_empty_array(mirrors_elsewhere)) {
             ap_rprintf(r, "\n   <h3>Found %d mirror%s in other parts of the world:</h3>\n", 
                        mirrors_elsewhere->nelts,
                        (mirrors_elsewhere->nelts == 1) ? "" : "s");
_at_@ -2616,7 +2616,7 @@
             break;
         }
 
-        if (!scfg->tracker_urls->nelts) {
+        if (apr_is_empty_array(scfg->tracker_urls)) {
             debugLog(r, cfg, "Torrent requested, but at least one MirrorBrainTorrentTrackerURL must configured");
             break;
         }
_at_@ -2837,15 +2837,15 @@
     const char *found_in;
     /* choose from country, then from region, then from elsewhere */
     if (!chosen) {
-        if (mirrors_same_prefix->nelts) {
+        if (!apr_is_empty_array(mirrors_same_prefix)) {
             mirrorp = (mirror_entry_t **)mirrors_same_prefix->elts;
             chosen = mirrorp[find_lowest_rank(mirrors_same_prefix)];
             found_in = "prefix";
-        } else if (mirrors_same_as->nelts) {
+        } else if (!apr_is_empty_array(mirrors_same_as)) {
             mirrorp = (mirror_entry_t **)mirrors_same_as->elts;
             chosen = mirrorp[find_lowest_rank(mirrors_same_as)];
             found_in = "AS";
-        } else if (mirrors_same_country->nelts) {
+        } else if (!apr_is_empty_array(mirrors_same_country)) {
             mirrorp = (mirror_entry_t **)mirrors_same_country->elts;
             chosen = mirrorp[find_lowest_rank(mirrors_same_country)];
             if (strcasecmp(chosen->country_code, country_code) == 0) {
_at_@ -2853,11 +2853,11 @@
             } else {
                 found_in = "other_country";
             }
-        } else if (mirrors_same_region->nelts) {
+        } else if (!apr_is_empty_array(mirrors_same_region)) {
             mirrorp = (mirror_entry_t **)mirrors_same_region->elts;
             chosen = mirrorp[find_lowest_rank(mirrors_same_region)];
             found_in = "region";
-        } else if (mirrors_elsewhere->nelts) {
+        } else if (!apr_is_empty_array(mirrors_elsewhere)) {
             mirrorp = (mirror_entry_t **)mirrors_elsewhere->elts;
             chosen = mirrorp[find_lowest_rank(mirrors_elsewhere)];
             found_in = "other";




_______________________________________________
mirrorbrain-commits mailing list
Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/

Note: To remove yourself from this list, send a mail with the content
 	unsubscribe
to the address mirrorbrain-commits-request_at_mirrorbrain.org
Received on Wed May 05 2010 - 15:41:48 GMT

This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT