httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pque...@apache.org
Subject svn commit: r729595 - in /httpd/sandbox/mod_mbox-3: SConstruct module-2.0/mod_mbox.h module-2.0/mod_mbox_index.c module-2.0/mod_mbox_sitemap.c
Date Sat, 27 Dec 2008 05:04:47 GMT
Author: pquerna
Date: Fri Dec 26 21:04:46 2008
New Revision: 729595

URL: http://svn.apache.org/viewvc?rev=729595&view=rev
Log:
Add support for generating Sitemaps of mail archives.

Added:
    httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox_sitemap.c   (with props)
Modified:
    httpd/sandbox/mod_mbox-3/SConstruct
    httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox.h
    httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox_index.c

Modified: httpd/sandbox/mod_mbox-3/SConstruct
URL: http://svn.apache.org/viewvc/httpd/sandbox/mod_mbox-3/SConstruct?rev=729595&r1=729594&r2=729595&view=diff
==============================================================================
--- httpd/sandbox/mod_mbox-3/SConstruct (original)
+++ httpd/sandbox/mod_mbox-3/SConstruct Fri Dec 26 21:04:46 2008
@@ -51,6 +51,7 @@
     mod_mbox_index.c
     mod_mbox_cte.c
     mod_mbox_mime.c
+    mod_mbox_sitemap.c
 """)]
 
 module = env.LoadableModule(target = "mod_mbox.so", source = [modsources, libsources])

Modified: httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox.h
URL: http://svn.apache.org/viewvc/httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox.h?rev=729595&r1=729594&r2=729595&view=diff
==============================================================================
--- httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox.h (original)
+++ httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox.h Fri Dec 26 21:04:46 2008
@@ -99,6 +99,7 @@
 
 /* Handlers */
 int mbox_atom_handler(request_rec *r, mbox_cache_info *mli);
+int mbox_sitemap_handler(request_rec *r, mbox_cache_info *mli);
 int mbox_file_handler(request_rec *r);
 int mbox_index_handler(request_rec *r);
 

Modified: httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox_index.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox_index.c?rev=729595&r1=729594&r2=729595&view=diff
==============================================================================
--- httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox_index.c (original)
+++ httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox_index.c Fri Dec 26 21:04:46 2008
@@ -176,6 +176,10 @@
         return mbox_atom_handler(r, mli);
     }
 
+    if (r->args && strstr(r->args, "format=sitemap") != NULL) {
+        return mbox_sitemap_handler(r, mli);
+    }
+    
     /* Only allow GETs */
     r->allowed |= (AP_METHOD_BIT << M_GET);
     if (r->method_number != M_GET) {

Added: httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox_sitemap.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox_sitemap.c?rev=729595&view=auto
==============================================================================
--- httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox_sitemap.c (added)
+++ httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox_sitemap.c Fri Dec 26 21:04:46 2008
@@ -0,0 +1,123 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+/**
+ * This file contains functions for generating a Sitemap, to make indexing
+ * by search engines easier on both them, and us:
+ *  <http://www.sitemaps.org/protocol.php>
+ */
+
+#include "mod_mbox.h"
+
+static void mbox2sitemap(request_rec *r, const char *mboxfile,
+                         mbox_cache_info *mli)
+{
+    char *filename;
+    char *origfilename;
+    MBOX_LIST *head;
+    Message *m;
+    apr_pool_t *tpool;
+
+    filename = apr_pstrcat(r->pool, r->filename, mboxfile, NULL);
+    origfilename = r->filename;
+    
+    r->filename = filename;
+    
+    head = mbox_load_index(r, NULL, NULL);
+
+    r->filename = origfilename;
+
+    apr_pool_create(&tpool, r->pool);
+    while (head != NULL) {
+        char dstr[100];
+        apr_size_t dlen;
+        apr_time_exp_t extime;
+
+        m = (Message *) head->value;
+        ap_rputs("<url>\n", r);
+
+        ap_rprintf(r, "<loc>%s%s/%s</loc>\n",
+                   ap_construct_url(tpool, r->uri, r),
+                   mboxfile, URI_ESCAPE_OR_BLANK(tpool, m->msgID));
+
+        apr_time_exp_gmt(&extime, m->date);
+        apr_strftime(dstr, &dlen, sizeof(dstr), "%G-%m-%d", &extime);
+        
+        ap_rprintf(r, "<lastmod>%s</lastmod>\n", dstr);
+        ap_rputs("<changefreq>never</changefreq>\n", r);
+        ap_rputs("</url>\n", r);
+        head = head->next;
+        apr_pool_clear(tpool);
+    }
+}
+
+static void mbox_sitemap_entries(request_rec *r, mbox_cache_info *mli)
+{
+    mbox_file_t *fi;
+    apr_array_header_t *files;
+    int i;
+
+    files = mbox_fetch_boxes_list(r, mli, r->filename);
+    if (!files) {
+        return;
+    }
+
+    fi = (mbox_file_t *) files->elts;
+    for (i = 0; i < files->nelts; i++) {
+        if (!fi[i].count) {
+            continue;
+        }
+        mbox2sitemap(r, fi[i].filename, mli);
+    }
+}
+
+int mbox_sitemap_handler(request_rec  *r, mbox_cache_info *mli)
+{
+    int errstatus;
+    char *etag;
+    
+    /* Only allow GETs */
+    r->allowed |= (AP_METHOD_BIT << M_GET);
+    if (r->method_number != M_GET) {
+        return HTTP_METHOD_NOT_ALLOWED;
+    }
+    
+    ap_set_content_type(r, "text/xml; charset=utf-8");
+    
+    /* Try to make the index page more cache friendly */
+    ap_update_mtime(r, mli->mtime);
+    ap_set_last_modified(r);
+    etag = ap_make_etag(r, 1);
+    apr_table_setn(r->headers_out, "ETag", etag);
+    
+    if (r->header_only) {
+        return OK;
+    }
+    
+    if ((errstatus = ap_meets_conditions(r)) != OK) {
+        r->status = errstatus;
+        return r->status;
+    }
+
+    ap_rputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", r);
+    ap_rputs("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n", r);
+    mbox_sitemap_entries(r, mli);
+    ap_rputs("</urlset>\n", r);
+
+    return OK;
+}
+

Propchange: httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox_sitemap.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox_sitemap.c
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: httpd/sandbox/mod_mbox-3/module-2.0/mod_mbox_sitemap.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message