httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerenkra...@apache.org
Subject svn commit: r424680 - /httpd/mod_mbox/trunk/module-2.0/mod-mbox-util.c
Date Sun, 23 Jul 2006 05:55:59 GMT
Author: jerenkrantz
Date: Sat Jul 22 22:55:58 2006
New Revision: 424680

URL: http://svn.apache.org/viewvc?rev=424680&view=rev
Log:
Add -m option to mod-mbox-util to dump the mbox message-id cache
(replaces the load_msgid tool which was never updated when this was introduced.)

Modified:
    httpd/mod_mbox/trunk/module-2.0/mod-mbox-util.c

Modified: httpd/mod_mbox/trunk/module-2.0/mod-mbox-util.c
URL: http://svn.apache.org/viewvc/httpd/mod_mbox/trunk/module-2.0/mod-mbox-util.c?rev=424680&r1=424679&r2=424680&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mod-mbox-util.c (original)
+++ httpd/mod_mbox/trunk/module-2.0/mod-mbox-util.c Sat Jul 22 22:55:58 2006
@@ -46,6 +46,7 @@
     "%s -- Program to Create and Update mod_mbox cache files" NL
     "Usage: %s [-v] -u MBOX_PATH -s INDEX_PATH" NL
     "       %s [-v] -c MBOX_PATH -s INDEX_PATH" NL
+    "       %s [-v] -m MBOX_FILE" NL
     NL
     "Options: " NL
     " -v    More verbose output"NL
@@ -57,10 +58,13 @@
     " -c    Force creation of a new cache. If there is an existing cache, it" NL
     "       will be ignored and overwritten " NL
     NL
+    " -m    Dumps the Message-ID cache to stdout for the specified file." NL
+    NL
     " -s    Set the path to store a Full Text Index." NL
     NL,
     shortname,
     shortname,
+    shortname,
     shortname);
 }
 
@@ -280,6 +284,28 @@
     return rv;
 }
 
+static int load_msgid(request_rec* r)
+{
+    apr_status_t rv;
+    apr_file_t *f;
+    MBOX_LIST *l;
+
+    rv = apr_file_open(&f, r->filename, APR_READ, APR_OS_DEFAULT, r->pool);
+    if (rv != APR_SUCCESS)
+        return rv;
+
+    l = mbox_load_index(r, f, NULL);
+
+    while (l) {
+        Message *m;
+        m = (Message*)l->value;
+        printf("%s\n", m->msgID);
+        l = l->next;
+    }
+
+    return APR_SUCCESS;
+}
+
 int main(int argc, const char* const argv[]) {
     apr_status_t rv = APR_SUCCESS;
     request_rec r;
@@ -322,7 +348,7 @@
         return EXIT_FAILURE;
     }
 
-    while ((rv = apr_getopt(opt, "vc::u::s::", &ch, &optarg)) == APR_SUCCESS) {
+    while ((rv = apr_getopt(opt, "vc::u::s::m::", &ch, &optarg)) == APR_SUCCESS)
{
         switch (ch) {
         case 'v':
             if (verbose) {
@@ -350,6 +376,17 @@
             update_mode = 1;
             upath = apr_pstrdup(r.pool, optarg);
             break;
+        case 'm':
+            if (update_mode != -1) {
+                apr_file_printf(errfile,
+                                "Error: -m can't be used with -u and -c " NL
+                                NL);
+                usage();
+                return EXIT_FAILURE;
+            }
+            update_mode = 2;
+            upath = apr_pstrdup(r.pool, optarg);
+            break;
         case 's':
             index_path = apr_pstrdup(r.pool, optarg);
             break;
@@ -363,7 +400,7 @@
     }
 
     if (update_mode == -1) {
-        apr_file_printf(errfile, "Error: -u or -c must be passed" NL NL);
+        apr_file_printf(errfile, "Error: -u, -c, or -m must be passed" NL NL);
         usage();
         return EXIT_FAILURE;
     }
@@ -374,55 +411,61 @@
         return EXIT_FAILURE;
     }
 
-    rv = apr_filepath_merge(&r.filename, NULL, upath,
-                            APR_FILEPATH_TRUENAME,
-                            r.pool);
-
-    if (rv != APR_SUCCESS) {
-        apr_file_printf(errfile, "Error: Unable to resolve path: %s" NL,
-                        apr_strerror(rv, errbuf, sizeof(errbuf)));
-        return EXIT_FAILURE;
-    }
-
-    rv = apr_filepath_set(r.filename, r.pool);
+    if (update_mode != 2) {
+        rv = apr_filepath_merge(&r.filename, NULL, upath,
+                                APR_FILEPATH_TRUENAME, r.pool);
+        if (rv != APR_SUCCESS) {
+            apr_file_printf(errfile, "Error: Unable to resolve path: %s" NL,
+                            apr_strerror(rv, errbuf, sizeof(errbuf)));
+            return EXIT_FAILURE;
+        }
 
-    if (rv != APR_SUCCESS) {
-        apr_file_printf(errfile, "Error: Unable to resolve path: %s" NL,
-                        apr_strerror(rv, errbuf, sizeof(errbuf)));
-        return EXIT_FAILURE;
-    }
+        rv = apr_filepath_set(r.filename, r.pool);
 
-    if (index_path) {
-        if (verbose) {
-            apr_file_printf(errfile, "Opening Lucene Index at: %s" NL,
-                            index_path);
-        }
-        rv = mbox_indexer_init(&indexer, index_path, r.pool);
         if (rv != APR_SUCCESS) {
-            apr_file_printf(errfile, "Error: Unable to open Lucene Index at: "
-                                     "'%s', Error Code: %s" NL, index_path,
+            apr_file_printf(errfile, "Error: Unable to resolve path: %s" NL,
                             apr_strerror(rv, errbuf, sizeof(errbuf)));
             return EXIT_FAILURE;
         }
-    }
-    else {
+
+        if (index_path) {
+            if (verbose) {
+                apr_file_printf(errfile, "Opening Lucene Index at: %s" NL,
+                                index_path);
+            }
+            rv = mbox_indexer_init(&indexer, index_path, r.pool);
+            if (rv != APR_SUCCESS) {
+                apr_file_printf(errfile,
+                                "Error: Unable to open Lucene Index at: "
+                                "'%s', Error Code: %s" NL, index_path,
+                                apr_strerror(rv, errbuf, sizeof(errbuf)));
+                return EXIT_FAILURE;
+            }
+        }
+        else {
+            if (verbose) {
+                apr_file_printf(errfile, "No Search Path Set. "
+                                "Searching will not be available."  NL);
+            }
+            indexer = NULL;
+        }
+
         if (verbose) {
-            apr_file_printf(errfile, "No Search Path Set. "
-                                     "Searching will not be available."  NL);
+            apr_file_printf(errfile, "Base Path: %s" NL, r.filename);
         }
 
-        indexer = NULL;
-    }
+        if (r.filename[strlen(r.filename) - 1] != '/') {
+            r.filename = apr_pstrcat(r.pool, r.filename, "/", NULL);
+        }
 
-    if (verbose) {
-        apr_file_printf(errfile, "Base Path: %s" NL, r.filename);
+        rv = scan_dir(&r);
     }
+    else {
+        r.filename = (char*)upath;
 
-    if (r.filename[strlen(r.filename) - 1] != '/') {
-        r.filename = apr_pstrcat(r.pool, r.filename, "/", NULL);
+        rv = load_msgid(&r);
     }
 
-    rv = scan_dir(&r);
     if (indexer) {
         mbox_indexer_optimize(indexer);
         mbox_indexer_close(indexer);



Mime
View raw message