httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r1226487 - in /httpd/mod_mbox/trunk/module-2.0: mod_mbox.c mod_mbox.h mod_mbox_out.c
Date Mon, 02 Jan 2012 17:33:26 GMT
Author: sf
Date: Mon Jan  2 17:33:26 2012
New Revision: 1226487

URL: http://svn.apache.org/viewvc?rev=1226487&view=rev
Log:
cache get_base_* results in request config

add get_base_name(), fix some warnings

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

Modified: httpd/mod_mbox/trunk/module-2.0/mod_mbox.c
URL: http://svn.apache.org/viewvc/httpd/mod_mbox/trunk/module-2.0/mod_mbox.c?rev=1226487&r1=1226486&r2=1226487&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mod_mbox.c (original)
+++ httpd/mod_mbox/trunk/module-2.0/mod_mbox.c Mon Jan  2 17:33:26 2012
@@ -44,6 +44,12 @@
 APLOG_USE_MODULE(mbox);
 #endif
 
+typedef struct {
+    const char *base_uri;
+    const char *base_path;
+    const char *base_name;
+} mbox_req_cfg_t;
+
 /* Register module hooks.
  */
 static void mbox_register_hooks(apr_pool_t *p)
@@ -198,34 +204,52 @@ char *mbox_ascii_escape(apr_pool_t *p, c
     return x;
 }
 
-/* Returns the archives base path */
-char *get_base_path(request_rec *r)
+static mbox_req_cfg_t *get_req_conf(request_rec *r)
 {
-    char *baseURI, *temp;
+    mbox_req_cfg_t *conf = ap_get_module_config(r->request_config, &mbox_module);
+    const char *temp;
+    if (conf)
+        return conf;
+
+    conf = apr_pcalloc(r->pool, sizeof(*conf));
+
+    temp = ap_strstr_c(r->uri, r->path_info);
+    if (temp)
+        conf->base_uri = apr_pstrmemdup(r->pool, r->uri, temp - r->uri);
+    else
+        conf->base_uri = r->uri;
+
+    temp = ap_strstr_c(conf->base_uri, ".mbox");
+    /* 7 is length of "/yyyymm" */
+    if (temp && temp >= conf->base_uri + 7) {
+        conf->base_path = apr_pstrmemdup(r->pool, conf->base_uri,
+                                         temp - 7 - conf->base_uri);
 
-    baseURI = get_base_uri(r);
-    temp = strstr(baseURI, ".mbox");
-    if (!temp) {
-        return NULL;
+        conf->base_name = ap_strrchr_c(conf->base_path, '/') + 1;
     }
+    ap_set_module_config(r->request_config, &mbox_module, conf);
+    return conf;
+}
 
-    temp = temp - 7;
-    *temp = 0;
-
-    return baseURI;
+/* Returns the archives base path */
+const char *get_base_path(request_rec *r)
+{
+    mbox_req_cfg_t *conf = get_req_conf(r);
+    return conf->base_path;
 }
 
 /* Returns the base URI, stripping the path_info */
-char *get_base_uri(request_rec *r)
+const char *get_base_uri(request_rec *r)
 {
-    char *baseURI, *temp;
+    mbox_req_cfg_t *conf = get_req_conf(r);
+    return conf->base_uri;
+}
 
-    baseURI = apr_pstrdup(r->pool, r->uri);
-    temp = strstr(baseURI, r->path_info);
-    if (temp) {
-        *temp = '\0';
-    }
-    return baseURI;
+/* Returns the base name, stripping the path */
+const char *get_base_name(request_rec *r)
+{
+    mbox_req_cfg_t *conf = get_req_conf(r);
+    return conf->base_name;
 }
 
 static const command_rec mbox_cmds[] = {

Modified: httpd/mod_mbox/trunk/module-2.0/mod_mbox.h
URL: http://svn.apache.org/viewvc/httpd/mod_mbox/trunk/module-2.0/mod_mbox.h?rev=1226487&r1=1226486&r2=1226487&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mod_mbox.h (original)
+++ httpd/mod_mbox/trunk/module-2.0/mod_mbox.h Mon Jan  2 17:33:26 2012
@@ -140,8 +140,9 @@ void mbox_mime_display_xml_structure(req
 /* Utility functions */
 char *mbox_wrap_text(char *str);
 char *mbox_ascii_escape(apr_pool_t *p, const char *s);
-char *get_base_path(request_rec *r);
-char *get_base_uri(request_rec *r);
+const char *get_base_path(request_rec *r);
+const char *get_base_uri(request_rec *r);
+const char *get_base_name(request_rec *r);
 
 #if AP_MODULE_MAGIC_AT_LEAST(20081231,0)
 #define ESCAPE_OR_BLANK(pool, s) \

Modified: httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c
URL: http://svn.apache.org/viewvc/httpd/mod_mbox/trunk/module-2.0/mod_mbox_out.c?rev=1226487&r1=1226486&r2=1226487&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 Mon Jan  2 17:33:26 2012
@@ -224,7 +224,7 @@ apr_status_t mbox_static_boxlist(request
     apr_array_header_t *files;
 
     int i;
-    char *base_path;
+    const char *base_path;
     char *path, *k;
 
     conf = ap_get_module_config(r->per_dir_config, &mbox_module);
@@ -545,7 +545,6 @@ apr_status_t mbox_xml_msglist(request_re
 {
     apr_finfo_t fi;
 
-    mbox_dir_cfg_t *conf;
     MBOX_LIST *head;
     Message *m;
     Container *threads = NULL, *c;
@@ -555,8 +554,6 @@ apr_status_t mbox_xml_msglist(request_re
     int count = 0;              /* Message count */
     int i = 0;
 
-    conf = ap_get_module_config(r->per_dir_config, &mbox_module);
-
     /* Fetch page number if present. Otherwise, assume page #1 */
     if (r->args && strcmp(r->args, ""))
         current_page = atoi(r->args);
@@ -644,7 +641,7 @@ apr_status_t mbox_xml_msglist(request_re
  *
  * FIXME: improve the algorithm in order to handle long pages list.
  */
-static void mbox_static_msglist_page_selector(request_rec *r, char *baseURI,
+static void mbox_static_msglist_page_selector(request_rec *r, const char *baseURI,
                                               int pages, int current_page)
 {
     int i;
@@ -680,7 +677,7 @@ static void mbox_static_msglist_page_sel
     }
 }
 
-static void mbox_static_msglist_nav(request_rec *r, char *baseURI,
+static void mbox_static_msglist_nav(request_rec *r, const char *baseURI,
                                     int pages, int current_page,
                                     int sortFlags)
 {
@@ -727,10 +724,10 @@ apr_status_t mbox_static_msglist(request
     int count = 0;              /* Message count */
     int i = 0;
 
-    char *baseURI;
+    const char *baseURI;
     char *filename;
     const char *month;
-    char *year;
+    const char *year;
 
     conf = ap_get_module_config(r->per_dir_config, &mbox_module);
     baseURI = get_base_uri(r);
@@ -885,7 +882,7 @@ apr_status_t mbox_static_msglist(request
 apr_status_t mbox_ajax_browser(request_rec *r)
 {
     mbox_dir_cfg_t *conf;
-    char *baseURI;
+    const char *baseURI;
 
     conf = ap_get_module_config(r->per_dir_config, &mbox_module);
     baseURI = get_base_uri(r);
@@ -1060,7 +1057,7 @@ int mbox_raw_message(request_rec *r, apr
 }
 
 static void mbox_static_message_nav(request_rec *r, char **context,
-                                    char *baseURI, char *msgID)
+                                    const char *baseURI, char *msgID)
 {
     ap_rputs("    <th class=\"nav\">", r);
 
@@ -1121,7 +1118,8 @@ int mbox_static_message(request_rec *r, 
     mbox_dir_cfg_t *conf;
     Message *m;
 
-    char *baseURI, *from, **context, *msgID, *escaped_msgID;
+    const char *baseURI;
+    char *from, **context, *msgID, *escaped_msgID;
 
     conf = ap_get_module_config(r->per_dir_config, &mbox_module);
     baseURI = get_base_uri(r);
@@ -1255,10 +1253,9 @@ apr_status_t mbox_xml_message(request_re
     mbox_dir_cfg_t *conf;
     Message *m;
 
-    char *baseURI, *from, *msgID;
+    char *from, *msgID;
 
     conf = ap_get_module_config(r->per_dir_config, &mbox_module);
-    baseURI = get_base_uri(r);
 
     /* Here, we skip 6 chars (/ajax/). */
     msgID = r->path_info + 6;



Mime
View raw message