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

From: <poeml_at_mirrorbrain.org>
Date: Thu, 11 Mar 2010 02:13:43 -0000
Author: poeml
Date: Thu Mar 11 03:13:42 2010
New Revision: 7979

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=7979&view=rev
Log:
mod_mirrorbrain:
- Prepare an SQL statement for retrieving hashes from the database
  This, for now, makes mod_mirrorbrain fail if the hash table doesn't exist yet.

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=7979&r1=7978&r2=7979&view=diff
==============================================================================
--- trunk/mod_mirrorbrain/mod_mirrorbrain.c (original)
+++ trunk/mod_mirrorbrain/mod_mirrorbrain.c Thu Mar 11 03:13:42 2010
@@ -107,6 +107,13 @@
                            "FROM filearr " \
                            "WHERE path = %s)::smallint[]) " \
                       "AND enabled AND status_baseurl AND score > 0"
+#define DEFAULT_QUERY_HASH "SELECT file_id, size, mtime, md5, sha1, sha256, " \
+                                  "sha1piecesize, substring(sha1pieces from 0 for 30), pgp " \
+                           "FROM hexhash " \
+                           "WHERE file_id = (SELECT id " \
+                                            "FROM filearr " \
+                                            "WHERE path = %s " \
+                                            "AND size = %lld AND mtime = %lld)"
 
 
 module AP_MODULE_DECLARE_DATA mirrorbrain_module;
@@ -188,6 +195,8 @@
     const char *mirrorlist_stylesheet;
     const char *query;
     const char *query_label;
+    const char *query_hash;
+    const char *query_hash_label;
 } mb_server_conf;
 
 
@@ -273,13 +282,15 @@
                                                         &mirrorbrain_module);
         /* make a label */
         cfg->query_label = apr_psprintf(pconf, "mirrorbrain_dbd_%d", ++label_num);
+        cfg->query_hash_label = apr_psprintf(pconf, "mirrorbrain_dbd_hash_%d", ++label_num);
+        ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
+                     "[mod_mirrorbrain] preparing stmt for server %s, label_num %d, label %s", 
+                     s->server_hostname, label_num, cfg->query_label);
         mb_dbd_prepare_fn(sp, cfg->query, cfg->query_label);
-
-        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
-                     "[mod_mirrorbrain] prepared: server %s, label_num %d, query_label %s", 
-                     s->server_hostname, 
-                     label_num,
-                     cfg->query_label);
+        ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
+                     "[mod_mirrorbrain] preparing stmt for server %s, label_num %d, label %s", 
+                     s->server_hostname, label_num, cfg->query_hash_label);
+        mb_dbd_prepare_fn(sp, cfg->query_hash, cfg->query_hash_label);
     }
 
     return OK;
@@ -356,6 +367,8 @@
     new->mirrorlist_stylesheet = NULL;
     new->query = DEFAULT_QUERY;
     new->query_label = NULL;
+    new->query_hash = DEFAULT_QUERY_HASH;
+    new->query_hash_label = NULL;
 
     return (void *) new;
 }
@@ -381,6 +394,9 @@
     cfgMergeString(mirrorlist_stylesheet);
     mrg->query = (add->query != (char *) DEFAULT_QUERY) ? add->query : base->query;
     cfgMergeString(query_label);
+    mrg->query_hash = (add->query_hash != (char *) DEFAULT_QUERY_HASH) 
+                      ? add->query_hash : base->query_hash;
+    cfgMergeString(query_hash_label);
 
     return (void *) mrg;
 }
@@ -525,7 +541,7 @@
 }
 #endif
 
-static const char *mb_cmd_dbdquery(cmd_parms *cmd, void *config, 
+static const char *mb_cmd_dbd_query(cmd_parms *cmd, void *config, 
                                    const char *arg1)
 {
     server_rec *s = cmd->server;
@@ -533,6 +549,17 @@
         ap_get_module_config(s->module_config, &mirrorbrain_module);
 
     cfg->query = arg1;
+    return NULL;
+}
+
+static const char *mb_cmd_dbd_query_hash(cmd_parms *cmd, void *config, 
+                                   const char *arg1)
+{
+    server_rec *s = cmd->server;
+    mb_server_conf *cfg = 
+        ap_get_module_config(s->module_config, &mirrorbrain_module);
+
+    cfg->query_hash = arg1;
     return NULL;
 }
 
@@ -1182,7 +1209,7 @@
 
     /* strip the leading directory
      * no need to escape it for the SQL query because we use a prepared 
-     * statement with bound parameter */
+     * statement with bound parameters */
 
     char *ptr = canonicalize_file_name(r->filename);
     if (ptr == NULL) {
@@ -2262,9 +2289,12 @@
                   "*all* files."),
 
     /* to be used only in server context */
-    AP_INIT_TAKE1("MirrorBrainDBDQuery", mb_cmd_dbdquery, NULL,
+    AP_INIT_TAKE1("MirrorBrainDBDQuery", mb_cmd_dbd_query, NULL,
                   RSRC_CONF,
-                  "the SQL query string to fetch the mirrors from the backend database"),
+                  "The SQL query for fetching the mirrors from the backend database"),
+    AP_INIT_TAKE1("MirrorBrainDBDQueryHash", mb_cmd_dbd_query_hash, NULL,
+                  RSRC_CONF,
+                  "The SQL query for fetching verification hashes from the backend database"),
 
 #ifdef NO_MOD_GEOIP
     AP_INIT_TAKE1("MirrorBrainGeoIPFile", mb_cmd_geoip_filename, NULL, 




_______________________________________________
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 Thu Mar 11 2010 - 02:13:48 GMT

This archive was generated by hypermail 2.2.0 : Thu Mar 11 2010 - 02:17:07 GMT