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

From: <poeml_at_mirrorbrain.org>
Date: Wed, 11 Apr 2012 19:44:00 -0000
Author: poeml
Date: Wed Apr 11 21:44:00 2012
New Revision: 8270

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8270&view=rev
Log:
mod_mirrorbrain:
- add support for RFC 6249, Metalink/HTTP: Mirrors and Hashes (issue #15)

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=8270&r1=8269&r2=8270&view=diff
==============================================================================
--- trunk/mod_mirrorbrain/mod_mirrorbrain.c	(original)
+++ trunk/mod_mirrorbrain/mod_mirrorbrain.c	Wed Apr 11 21:44:00 2012
_at_@ -2403,6 +2403,7 @@
     case MIRRORLIST:
     case ZSYNC:
     case YUMLIST:
+    case REDIRECT:
         qsort(mirrors_same_prefix->elts, mirrors_same_prefix->nelts, 
               mirrors_same_prefix->elt_size, cmp_mirror_best);
         qsort(mirrors_same_as->elts, mirrors_same_as->nelts, 
_at_@ -2512,7 +2513,7 @@
 
 
 
-    if ((rep != REDIRECT) && (rep != YUMLIST) && (!hashbag)) {
+    if ((rep != YUMLIST) && (!hashbag)) {
         hashbag = hashbag_fill(r, dbd, filename);
         if (hashbag == NULL) {
             debugLog(r, cfg, "no hashes found in database");
_at_@ -3569,6 +3570,74 @@
 
     apr_table_setn(r->err_headers_out, "X-MirrorBrain-Mirror", chosen->identifier);
     apr_table_setn(r->err_headers_out, "X-MirrorBrain-Realm", found_in);
+
+
+    /* add HTTP headers according to RFC 5988 (Web Linking) 
+     * and RFC 5854/6249 (Metalink/HTTP: Mirrors and Hashes) */
+    /* rel=describedby */
+    apr_table_addn(r->err_headers_out, "Link", 
+                   apr_pstrcat(r->pool,
+                               "<http://", r->hostname, r->uri, ".meta4>; "
+                               "rel=describedby; type=\"application/metalink4+xml\"", 
+                               NULL));
+    if (hashbag && hashbag->pgp) {
+        apr_table_addn(r->err_headers_out, "Link", 
+                       apr_pstrcat(r->pool,
+                                   "<http://", r->hostname, r->uri, ".asc>; "
+                                   "rel=describedby; type=\"application/pgp-signature\"", 
+                                   NULL));
+    }
+    if (!apr_is_empty_array(scfg->tracker_urls) && hashbag && hashbag->btihhex) {
+        apr_table_addn(r->err_headers_out, "Link", 
+                       apr_pstrcat(r->pool,
+                                   "<http://", r->hostname, r->uri, ".torrent>; "
+                                   "rel=describedby; type=\"application/x-bittorrent\"", 
+                                   NULL));
+    }
+
+    /* rel=duplicate */
+    apr_array_header_t *topten = get_n_best_mirrors(r, 5, mirrors_same_prefix, mirrors_same_as, 
+                                                     mirrors_same_country, mirrors_same_region, 
+                                                     mirrors_elsewhere);
+    if (topten->nelts > 0) {
+        mirrorp = (mirror_entry_t **)topten->elts;
+        for (i = 0; i < topten->nelts; i++) {
+            mirror = mirrorp[i];
+            apr_table_addn(r->err_headers_out, "Link", 
+                           apr_pstrcat(r->pool,
+                                       "<", mirror->baseurl, filename, 
+                                       ">; rel=duplicate"
+                                       "; pri=", apr_itoa(r->pool, i+1),
+                                       "; geo=", mirror->country_code,
+                                       NULL));
+        }
+    }
+    
+    /* RFC 3230 HTTP Instance Digests (including updates from RFC 5843) */
+    if (hashbag) {
+        if (hashbag->md5hex) {
+            apr_table_addn(r->err_headers_out, "Digest", 
+                           apr_pstrcat(r->pool,
+                                       "MD5=", 
+                                       ap_pbase64encode(r->pool, hex_decode(r, hashbag->md5hex, MD5_DIGESTSIZE)),
+                                       NULL));
+        }
+        if (hashbag->sha1hex) {
+            apr_table_addn(r->err_headers_out, "Digest", 
+                           apr_pstrcat(r->pool,
+                                       "SHA=", 
+                                       ap_pbase64encode(r->pool, hex_decode(r, hashbag->sha1hex, SHA1_DIGESTSIZE)),
+                                       NULL));
+        }
+        if (hashbag->sha256hex) {
+            apr_table_addn(r->err_headers_out, "Digest", 
+                           apr_pstrcat(r->pool,
+                                       "SHA-256=", 
+                                       ap_pbase64encode(r->pool, hex_decode(r, hashbag->sha256hex, SHA256_DIGESTSIZE)),
+                                       NULL));
+        }
+    }
+
     apr_table_setn(r->headers_out, "Location", uri);
 
 #ifdef WITH_MEMCACHE




_______________________________________________
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 Wed Apr 11 2012 - 19:44:00 GMT

This archive was generated by hypermail 2.3.0 : Wed Apr 11 2012 - 19:47:02 GMT