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

From: <poeml_at_mirrorbrain.org>
Date: Thu, 05 Aug 2010 02:04:51 -0000
Author: poeml
Date: Thu Aug  5 04:04:51 2010
New Revision: 8075

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8075&view=rev
Log:
mod_mirrorbrain:
- fix creation of magnet links by using the (now available) BitTorrent
  information hash from the database
- make the hash available also by requesting <file>.btih (appending .btih to an URL)

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=8075&r1=8074&r2=8075&view=diff
==============================================================================
--- trunk/mod_mirrorbrain/mod_mirrorbrain.c (original)
+++ trunk/mod_mirrorbrain/mod_mirrorbrain.c Thu Aug  5 04:04:51 2010
_at_@ -135,7 +135,7 @@
                            "WHERE path = %s)::smallint[]) " \
                       "AND enabled AND status_baseurl AND score > 0"
 #define DEFAULT_QUERY_HASH "SELECT file_id, md5hex, sha1hex, sha256hex, " \
-                                  "sha1piecesize, sha1pieceshex, pgp, " \
+                                  "sha1piecesize, sha1pieceshex, btihhex, pgp, " \
                                   "zblocksize, zhashlens, zsumshex " \
                            "FROM hexhash " \
                            "WHERE file_id = (SELECT id " \
_at_@ -156,7 +156,7 @@
 
 /* (meta) representations of a requested file */
 enum { REDIRECT, META4, METALINK, MIRRORLIST, TORRENT, 
-       ZSYNC, MAGNET, MD5, SHA1, SHA256, UNKNOWN };
+       ZSYNC, MAGNET, MD5, SHA1, SHA256, BTIH, UNKNOWN };
 static struct {
         int     id;
         char    *ext;
_at_@ -171,6 +171,7 @@
         { MD5,           "md5" },
         { SHA1,          "sha1" },
         { SHA256,        "sha256" },
+        { BTIH,          "btih" },
         { UNKNOWN,       NULL }
 };
 
_at_@ -207,6 +208,7 @@
     const char *sha256hex;
     int sha1piecesize;
     apr_array_header_t *sha1pieceshex;
+    const char *btihhex;
     const char *pgp;
     int zblocksize;
     const char *zhashlens;
_at_@ -898,6 +900,7 @@
     h->sha256hex = NULL;
     h->sha1piecesize = 0;
     h->sha1pieceshex = NULL;
+    h->btihhex = NULL;
     h->pgp = NULL;
     h->zblocksize = 0;
     h->zhashlens = NULL;
_at_@ -988,6 +991,13 @@
                         val + (i * SHA1_DIGESTSIZE * 2), (SHA1_DIGESTSIZE * 2));
             }
         }
+    }
+
+    if ((val = apr_dbd_get_entry(dbd->driver, row, col++)) == NULL) {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "[mod_mirrorbrain] dbd: got NULL for btih");
+    } else {
+        if (val[0])
+            h->btihhex = apr_pstrdup(r->pool, val);
     }
 
     if ((val = apr_dbd_get_entry(dbd->driver, row, col++)) == NULL) {
_at_@ -1154,6 +1164,7 @@
         if (form_lookup(r, "md5"))     { rep = MD5;     rep_ext = reps[MD5].ext; };
         if (form_lookup(r, "sha1"))    { rep = SHA1;    rep_ext = reps[SHA1].ext; };
         if (form_lookup(r, "sha256"))  { rep = SHA256;  rep_ext = reps[SHA256].ext; };
+        if (form_lookup(r, "btih"))    { rep = BTIH;    rep_ext = reps[BTIH].ext; };
     }
     
     if (!query_country 
_at_@ -1250,6 +1261,7 @@
                 case MD5:
                 case SHA1:
                 case SHA256:
+                case BTIH:
                     debugLog(r, cfg, "Representation chosen by .%s extension", rep_ext);
                     /* note this actually modifies r->filename. */
                     ext[0] = '\0';
_at_@ -1476,6 +1488,7 @@
     case MD5:
     case SHA1:
     case SHA256:
+    case BTIH:
     case TORRENT:
     case ZSYNC:
     case MAGNET:
_at_@ -1490,12 +1503,14 @@
     switch (rep) {
     case MD5:
     case SHA1:
-    case SHA256: {
+    case SHA256:
+    case BTIH: {
         const char *h = NULL;
         switch (rep) {
         case MD5: h = hashbag->md5hex; break;
         case SHA1: h = hashbag->sha1hex; break;
         case SHA256: h = hashbag->sha256hex; break;
+        case BTIH: h = hashbag->btihhex; break;
         }
 
         if (h && h[0]) {
_at_@ -2048,9 +2063,7 @@
 
             /* Bittorrent info hash */
             APR_ARRAY_PUSH(m, char *) = 
-                apr_psprintf(r->pool, "magnet:?xt=urn:btih:%s", hashbag->sha1hex);
-                                                /* FIXME this is wrong. See
-                                                 * http://mirrorbrain.org/issues/issue56 */
+                apr_psprintf(r->pool, "magnet:?xt=urn:btih:%s", hashbag->btihhex);
 #if 0
             /* SHA-1 */
             /* As far as I can see, this hash would actually need to be Base32
_at_@ -2502,6 +2515,9 @@
             if (hashbag->md5hex)
                 ap_rprintf(r, "  <li><a href=\"http://%s%s.md5\">MD5 Hash</a>: <tt>%s</tt> "
                               "</li>\n", r->hostname, r->uri, hashbag->md5hex);
+            if (hashbag->btihhex)
+                ap_rprintf(r, "  <li><a href=\"http://%s%s.btih\">BitTorrent Information Hash</a>: <tt>%s</tt> "
+                              "</li>\n", r->hostname, r->uri, hashbag->btihhex);
 
             if (hashbag->pgp) {
                 /* contrary to the hashes, we don't have a handler for .asc files, because




_______________________________________________
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 Aug 05 2010 - 02:04:52 GMT

This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT