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

From: <poeml_at_mirrorbrain.org>
Date: Sun, 28 Mar 2010 23:11:47 -0000
Author: poeml
Date: Mon Mar 29 01:11:45 2010
New Revision: 8026

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8026&view=rev
Log:
mod_mirrorbrain:
- Now more than one Bittorrent tracker can be configured. Multiple trackers are
  included in magnet links, and as "announce-list" in torrents.
- Apache directive renamed to MirrorBrainTorrentTrackerURL.

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=8026&r1=8025&r2=8026&view=diff
==============================================================================
--- trunk/mod_mirrorbrain/mod_mirrorbrain.c (original)
+++ trunk/mod_mirrorbrain/mod_mirrorbrain.c Mon Mar 29 01:11:45 2010
_at_@ -238,7 +238,7 @@
     const char *metalink_hashes_prefix;
     const char *metalink_publisher_name;
     const char *metalink_publisher_url;
-    const char *tracker_url;
+    apr_array_header_t *tracker_urls;
     const char *metalink_broken_test_mirrors;
     const char *mirrorlist_stylesheet;
     const char *query;
_at_@ -396,7 +396,7 @@
     new->metalink_hashes_prefix = NULL;
     new->metalink_publisher_name = NULL;
     new->metalink_publisher_url = NULL;
-    new->tracker_url = NULL;
+    new->tracker_urls = apr_array_make(p, 5, sizeof (char *));
     new->metalink_broken_test_mirrors = NULL;
     new->mirrorlist_stylesheet = NULL;
     new->query = DEFAULT_QUERY;
_at_@ -424,7 +424,7 @@
     cfgMergeString(metalink_hashes_prefix);
     cfgMergeString(metalink_publisher_name);
     cfgMergeString(metalink_publisher_url);
-    cfgMergeString(tracker_url);
+    mrg->tracker_urls = apr_array_append(p, base->tracker_urls, add->tracker_urls);
     cfgMergeString(metalink_broken_test_mirrors);
     cfgMergeString(mirrorlist_stylesheet);
     mrg->query = (add->query != (char *) DEFAULT_QUERY) ? add->query : base->query;
_at_@ -629,14 +629,15 @@
     return NULL;
 }
 
-static const char *mb_cmd_tracker_url(cmd_parms *cmd, void *config, 
-                                      const char *arg1)
+static const char *mb_cmd_tracker_url(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->tracker_url = arg1;
+    char **url = (char **) apr_array_push(cfg->tracker_urls);
+    *url = apr_pstrdup(cmd->pool, arg1);
     return NULL;
 }
 
_at_@ -2014,9 +2015,12 @@
                 apr_psprintf(r->pool, "&amp;as=http://%s%s", ap_escape_uri(r->pool, r->hostname), 
                                                              ap_escape_uri(r->pool, r->uri));
 
-            if (scfg->tracker_url) {
-                APR_ARRAY_PUSH(m, char *) = 
-                    apr_psprintf(r->pool, "&amp;tr=%s", ap_escape_uri(r->pool, scfg->tracker_url));
+            if (scfg->tracker_urls->nelts) {
+                for (i = 0; i < scfg->tracker_urls->nelts; i++) {
+                    char *url = ((char **) scfg->tracker_urls->elts)[i];
+                    APR_ARRAY_PUSH(m, char *) = 
+                        apr_psprintf(r->pool, "&amp;tr=%s", ap_escape_uri(r->pool, url));
+                }
             }
 
             magnet = apr_array_pstrcat(r->pool, m, '\0');
_at_@ -2568,17 +2572,30 @@
 
     case TORRENT:
 
-        if (!hashbag || (hashbag->sha1piecesize <= 0) || apr_is_empty_array(hashbag->sha1pieceshex) || !scfg->tracker_url) {
-            debugLog(r, cfg, "Torrent requested, but required data is missing");
+        if (!hashbag || (hashbag->sha1piecesize <= 0) || apr_is_empty_array(hashbag->sha1pieceshex)) {
+            debugLog(r, cfg, "Torrent requested, but no hashes found");
+            break;
+        }
+
+        if (!scfg->tracker_urls->nelts) {
+            debugLog(r, cfg, "Torrent requested, but at least one MirrorBrainTorrentTrackerURL must configured");
             break;
         }
 
         debugLog(r, cfg, "Sending torrent");
         ap_set_content_type(r, "application/x-bittorrent");
 
+        char *tracker = ((char **) scfg->tracker_urls->elts)[0];
         ap_rprintf(r, "d"
                           "8:announce"
-                          "%d:%s", strlen(scfg->tracker_url), scfg->tracker_url);
+                          "%d:%s", strlen(tracker), tracker);
+
+        ap_rputs(         "13:announce-listll", r);
+        for (i = 0; i < scfg->tracker_urls->nelts; i++) {
+            tracker = ((char **) scfg->tracker_urls->elts)[i];
+            ap_rprintf(r, "%d:%s", strlen(tracker), tracker);
+        }
+        ap_rputs(         "e", r);
 
         ap_rprintf(r,     "7:comment"
                           "%d:%s", strlen(basename), basename);
_at_@ -2929,9 +2946,10 @@
                   RSRC_CONF, 
                   "Name and URL for the metalinks publisher elements"),
 
-    AP_INIT_TAKE1("MirrorBrainTrackerURL", mb_cmd_tracker_url, NULL, 
+    AP_INIT_TAKE1("MirrorBrainTorrentTrackerURL", mb_cmd_tracker_url, NULL, 
                   RSRC_CONF, 
-                  "Define a Tracker URL to be included in Magnet links"),
+                  "Define the URL a Bittorrent Tracker be included in Torrents and in Magnet "
+                  "links. Directive can be repeated to specify multiple URLs."),
 
     AP_INIT_TAKE1("MirrorBrainMetalinkBrokenTestMirrors", mb_cmd_metalink_broken_test_mirrors, NULL, 
                   RSRC_CONF, 




_______________________________________________
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 Sun Mar 28 2010 - 23:11:51 GMT

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