httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pque...@apache.org
Subject svn commit: r307262 - in /httpd/mod_mbox/trunk/module-2.0: mod_mbox.h mod_mbox_index.c mod_mbox_out.c
Date Sat, 08 Oct 2005 05:18:37 GMT
Author: pquerna
Date: Fri Oct  7 22:18:34 2005
New Revision: 307262

URL: http://svn.apache.org/viewcvs?rev=307262&view=rev
Log:
- Remove MAX_MBOX_FILES Hack
- Use apr_array_header_t instead of a static-sized array for the list of mbox files

Modified:
    httpd/mod_mbox/trunk/module-2.0/mod_mbox.h
    httpd/mod_mbox/trunk/module-2.0/mod_mbox_index.c
    httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c

Modified: httpd/mod_mbox/trunk/module-2.0/mod_mbox.h
URL: http://svn.apache.org/viewcvs/httpd/mod_mbox/trunk/module-2.0/mod_mbox.h?rev=307262&r1=307261&r2=307262&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mod_mbox.h (original)
+++ httpd/mod_mbox/trunk/module-2.0/mod_mbox.h Fri Oct  7 22:18:34 2005
@@ -57,12 +57,6 @@
 #define MBOX_PREV_THREAD 2
 #define MBOX_NEXT_THREAD 3
 
-/* FIXME: MAX_MBOX_FILES is set to 240 (20 years of 12 months), but
-   this is not a really clean mechanism. I've used that because there
-   is not easy way of sorting a chained list, and because there is no
-   realloc function in the APR, so I use a static array */
-#define MAX_MBOX_FILES 240
-
 #define MBOX_OUTPUT_STATIC 0
 #define MBOX_OUTPUT_AJAX   1
 
@@ -141,8 +135,8 @@
 char *get_base_uri(request_rec *r);
 
 /* Backend functions */
-mbox_file_t *mbox_fetch_boxes_list(request_rec *r, mbox_cache_info *mli,
-				   char *path, int *count);
+apr_array_header_t *mbox_fetch_boxes_list(request_rec *r, mbox_cache_info *mli,
+                                          char *path);
 Message *fetch_message(request_rec *r, apr_file_t *f, char *msgID);
 char **fetch_context_msgids(request_rec *r, apr_file_t *f, char*msgID);
 

Modified: httpd/mod_mbox/trunk/module-2.0/mod_mbox_index.c
URL: http://svn.apache.org/viewcvs/httpd/mod_mbox/trunk/module-2.0/mod_mbox_index.c?rev=307262&r1=307261&r2=307262&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mod_mbox_index.c (original)
+++ httpd/mod_mbox/trunk/module-2.0/mod_mbox_index.c Fri Oct  7 22:18:34 2005
@@ -39,14 +39,14 @@
  * list of mbox_files_t containing all the information we need to
  * output a complete box listing.
  */
-mbox_file_t *mbox_fetch_boxes_list(request_rec *r, mbox_cache_info *mli,
-				   char *path, int *count)
+apr_array_header_t *mbox_fetch_boxes_list(request_rec *r, mbox_cache_info *mli,
+                                          char *path)
 {
     apr_status_t rv = APR_SUCCESS;
     apr_finfo_t finfo;
     apr_dir_t *dir;
-
-    mbox_file_t *files;
+    mbox_file_t *fi;
+    apr_array_header_t *files;
 
     rv = apr_dir_open(&dir, path, r->pool);
 
@@ -63,26 +63,28 @@
         return NULL;
     }
 
-    *count = 0;
-    files = apr_pcalloc(r->pool, MAX_MBOX_FILES * sizeof(mbox_file_t));
+    /* 15 Years of Mail Archives */
+    files = apr_array_make(r->pool, 15 * 12, sizeof(mbox_file_t));
 
     /* Foreach file in the directory, add its name and the message
        count to our array */
-    while ((apr_dir_read(&finfo, APR_FINFO_NAME, dir) == APR_SUCCESS) &&
-	   (*count < MAX_MBOX_FILES)) {
+    while (apr_dir_read(&finfo, APR_FINFO_NAME, dir) == APR_SUCCESS) {
         if ((apr_fnmatch("*.mbox", finfo.name, 0) == APR_SUCCESS) &&
             (strstr(finfo.name, "incomplete") == NULL)) {
-	    files[*count].filename = apr_pstrdup(r->pool, finfo.name);
-	    mbox_cache_get_count(mli, &(files[*count].count), (char *)finfo.name);
-
-	    (*count)++;
+            fi = (mbox_file_t*)apr_array_push(files);
+            fi->filename = apr_pstrdup(r->pool, finfo.name);
+	    mbox_cache_get_count(mli, &(fi->count), (char *)finfo.name);
 	}
     }
 
     apr_dir_close(dir);
 
+    if (files->nelts == 0) {
+        return NULL;
+    }
+
     /* Sort by reverse filename order */
-    qsort((void *) files, *count, sizeof(mbox_file_t), filename_rsort);
+    qsort((void *)files->elts, files->nelts, sizeof(mbox_file_t), filename_rsort);
 
     return files;
 }

Modified: httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c
URL: http://svn.apache.org/viewcvs/httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c?rev=307262&r1=307261&r2=307262&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c (original)
+++ httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c Fri Oct  7 22:18:34 2005
@@ -41,9 +41,9 @@
 
     mbox_dir_cfg_t *conf;
     mbox_cache_info *mli;
-    mbox_file_t *files;
-
-    int i, count = 0;
+    mbox_file_t *fi;
+    apr_array_header_t *files;
+    int i;
     char *path, *k;
 
     conf = ap_get_module_config(r->per_dir_config, &mbox_module);
@@ -67,7 +67,7 @@
         return HTTP_FORBIDDEN;
     }
 
-    files = mbox_fetch_boxes_list(r, mli, path, &count);
+    files = mbox_fetch_boxes_list(r, mli, path);
     if (!files) {
         return HTTP_FORBIDDEN;
     }
@@ -75,10 +75,12 @@
     ap_rputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", r);
     ap_rputs("<boxlist>\n", r);
 
-    for (i=0 ; i<count ; i++) {
-        if (files[i].count || !conf->hide_empty) {
-	    ap_rprintf(r, "<mbox id=\"%s\" count=\"%d\" />\n",
-		       files[i].filename, files[i].count);
+    fi = (mbox_file_t *)files->elts;
+
+    for (i = 0; i < files->nelts; i++) {
+        if (fi[i].count || !conf->hide_empty) {
+	    ap_rprintf(r, "<mbox id=\"%s\" count=\"%d\" />\n", 
+                       fi[i].filename, fi[i].count);
 	}
     }
 
@@ -94,9 +96,10 @@
 
     mbox_dir_cfg_t *conf;
     mbox_cache_info *mli;
-    mbox_file_t *files;
+    mbox_file_t *fi;
+    apr_array_header_t *files;
 
-    int i, count = 0;
+    int i;
     char *base_path;
     char *path, *k;
 
@@ -122,7 +125,7 @@
         return HTTP_FORBIDDEN;
     }
 
-    files = mbox_fetch_boxes_list(r, mli, path, &count);
+    files = mbox_fetch_boxes_list(r, mli, path);
     if (!files) {
         return HTTP_FORBIDDEN;
     }
@@ -131,9 +134,11 @@
     ap_rputs("   <thead><tr><th colspan=\"2\">Box list</th></tr></thead>\n",
r);
     ap_rputs("   <tbody>\n", r);
 
-    for (i=0 ; i<count ; i++) {
-        if (files[i].count || !conf->hide_empty) {
-	    if (strcmp(k+1, files[i].filename) == 0) {
+    fi = (mbox_file_t *)files->elts;
+
+    for (i=0 ; i < files->nelts; i++) {
+        if (fi[i].count || !conf->hide_empty) {
+	    if (strcmp(k+1, fi[i].filename) == 0) {
 	        ap_rputs("   <tr id=\"boxactive\">", r);
 	    }
 	    else {
@@ -142,13 +147,13 @@
 
 	    ap_rprintf(r, "    <td class=\"box\"><a href=\"%s/%s%s\" title=\"Browse %s
%.4s archives\">"
 		       "%s %.4s</a></td><td class=\"msgcount\">%d</td>\n",
-		       base_path, files[i].filename, r->path_info,
+		       base_path, fi[i].filename, r->path_info,
 		       mbox_months[atoi(apr_pstrndup(r->pool,
-						     files[i].filename+4, 2)) - 1][1],
-		       files[i].filename,
+						     fi[i].filename+4, 2)) - 1][1],
+		       fi[i].filename,
  		       mbox_months[atoi(apr_pstrndup(r->pool,
-						     files[i].filename+4, 2)) - 1][0],
-		       files[i].filename, files[i].count);
+						     fi[i].filename+4, 2)) - 1][0],
+		       fi[i].filename, fi[i].count);
 
 	    ap_rputs("   </tr>\n", r);
 	}
@@ -164,24 +169,23 @@
 apr_status_t mbox_static_index_boxlist(request_rec *r, mbox_dir_cfg_t *conf,
 				       mbox_cache_info *mli)
 {
-    mbox_file_t *files;
-    int side = 0, year_hdr = 0, count = 0, i;
+    mbox_file_t *fi;
+    apr_array_header_t *files;
+    int side = 0, year_hdr = 0, i;
 
-    files = mbox_fetch_boxes_list(r, mli, r->filename, &count);
+    files = mbox_fetch_boxes_list(r, mli, r->filename);
     if (!files) {
         return HTTP_FORBIDDEN;
     }
 
-    if (!count) {
-        return APR_SUCCESS;
-    }
-
     ap_rputs("  <table id=\"grid\">\n", r);
 
-    for (i=0 ; i<count ; i++) {
+    fi = (mbox_file_t *)files->elts;
+
+    for (i=0; i < files->nelts; i++) {
         /* Only display an entry if it has messages or if we don't
 	   hide empty mailboxes */
-        if (files[i].count || !conf->hide_empty) {
+        if (fi[i].count || !conf->hide_empty) {
 	    if (!year_hdr) {
 	        if (!side) {
 		    ap_rputs("  <tr><td class=\"left\">\n", r);
@@ -195,7 +199,7 @@
 		ap_rputs("   <table class=\"year\">\n", r);
 		ap_rputs("    <thead><tr>\n", r);
 		ap_rprintf(r, "     <th colspan=\"3\">Year %.4s</th>\n",
-			   files[i].filename);
+			   fi[i].filename);
 		ap_rputs("    </tr></thead>\n", r);
 		ap_rputs("    <tbody>\n", r);
 
@@ -204,24 +208,25 @@
 
 	    ap_rputs("    <tr>\n", r);
 	    ap_rprintf(r, "     <td class=\"date\">%s %.4s</td>\n",
-		       mbox_months[atoi(apr_pstrndup(r->pool,
-						     files[i].filename+4, 2)) - 1][0],
-		       files[i].filename);
+		       mbox_months[atoi(apr_pstrndup(r->pool, 
+                                                     fi[i].filename+4, 2)) - 1][0],
+		       fi[i].filename);
 	    ap_rprintf(r, "     <td class=\"links\"><span class=\"links\" id=\"%.4s%.2s\">"
 		       "<a href=\"%.4s%.2s.mbox/thread\">Thread</a>"
 		       " &middot; <a href=\"%.4s%.2s.mbox/date\">Date</a>"
 		       " &middot; <a href=\"%.4s%.2s.mbox/author\">Author</a></span></td>\n",
-		       files[i].filename, files[i].filename+4,
-		       files[i].filename, files[i].filename+4,
-		       files[i].filename, files[i].filename+4,
-		       files[i].filename, files[i].filename+4);
-	    ap_rprintf(r, "     <td class=\"msgcount\">%d</td>\n", files[i].count);
+		       fi[i].filename, fi[i].filename+4,
+		       fi[i].filename, fi[i].filename+4,
+		       fi[i].filename, fi[i].filename+4,
+		       fi[i].filename, fi[i].filename+4);
+	    ap_rprintf(r, "     <td class=\"msgcount\">%d</td>\n", fi[i].count);
 	    ap_rputs("    </tr>\n", r);
 	}
 
 	/* Year separation */
-	if ((files[i+1].filename && year_hdr) &&
-	    (files[i].filename[3] != files[i+1].filename[3])) {
+     
+	if ((fi[i+1].filename && year_hdr) &&
+	    (fi[i].filename[3] != fi[i+1].filename[3])) {
 	    ap_rputs("    </tbody>\n", r);
 	    ap_rputs("   </table>\n", r);
 	    if (side) {



Mime
View raw message