Author: poeml Date: Sat Mar 13 01:50:36 2010 New Revision: 7995 URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=7995&view=rev Log: mod_mirrorbrain: - Inclusion of a Tracker URL into Magnet links is implemented, configurable via a new Apache config directive named MirrorBrainTrackerURL. - urn:sha1 scheme is omitted, because it seems to require Base32 encoding. - Magnet link generation was refactored for better maintainability. 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=7995&r1=7994&r2=7995&view=diff ============================================================================== --- trunk/mod_mirrorbrain/mod_mirrorbrain.c (original) +++ trunk/mod_mirrorbrain/mod_mirrorbrain.c Sat Mar 13 01:50:36 2010 _at_@ -201,6 +201,7 @@ const char *metalink_hashes_prefix; const char *metalink_publisher_name; const char *metalink_publisher_url; + const char *tracker_url; const char *metalink_broken_test_mirrors; const char *mirrorlist_stylesheet; const char *query; _at_@ -358,6 +359,7 @@ new->metalink_hashes_prefix = NULL; new->metalink_publisher_name = NULL; new->metalink_publisher_url = NULL; + new->tracker_url = NULL; new->metalink_broken_test_mirrors = NULL; new->mirrorlist_stylesheet = NULL; new->query = DEFAULT_QUERY; _at_@ -385,6 +387,7 @@ cfgMergeString(metalink_hashes_prefix); cfgMergeString(metalink_publisher_name); cfgMergeString(metalink_publisher_url); + cfgMergeString(tracker_url); cfgMergeString(metalink_broken_test_mirrors); cfgMergeString(mirrorlist_stylesheet); mrg->query = (add->query != (char *) DEFAULT_QUERY) ? add->query : base->query; _at_@ -586,6 +589,17 @@ cfg->metalink_publisher_name = arg1; cfg->metalink_publisher_url = arg2; + return NULL; +} + +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; return NULL; } _at_@ -1806,27 +1820,46 @@ switch (rep) { case META4: case METALINK: - case MIRRORLIST: - magnet = apr_psprintf(r->pool, "magnet:" - "?xl=%s" /* size */ - "&dn=%s" /* file basename */ - "&xt=urn:sha1:%s" - "&xt=urn:bith:%s" /* bittorrent information hash */ - "&xt=urn:md5:%s" /* Gnutella */ - "&as=%s", /* a HTTP link to the file */ - apr_off_t_toa(r->pool, r->finfo.size), - ap_escape_uri(r->pool, basename), - hashbag->sha1, hashbag->sha1, hashbag->md5, - apr_psprintf(r->pool, - "http://%s%s", - ap_escape_uri(r->pool, r->hostname), - ap_escape_uri(r->pool, r->uri)) - ); - - /* FIXME: including a tracker URL might be cool (&tr=<tracker-url>) - * see http://mirrorbrain.org/issues/issue38 */ - /* the URL to the file (for HTTP redirection) can also be included - * http://en.wikipedia.org/wiki/Magnet_URI_scheme#Normal_.28as.29 */ + case MIRRORLIST: { + + apr_array_header_t *m; + m = apr_array_make(r->pool, 7, sizeof(char *)); + + /* Bittorrent info hash */ + APR_ARRAY_PUSH(m, char *) = + apr_psprintf(r->pool, "magnet:?xt=urn:btih:%s", hashbag->sha1); +#if 0 + /* SHA-1 */ + /* As far as I can see, this hash would actually need to be Base32 + * encoded, not hex. But it's probably not worth adding Base32 + * encoder just for this. */ + APR_ARRAY_PUSH(m, char *) = + apr_psprintf(r->pool, "&xt=urn:sha1:%s", hashbag->sha1); +#endif + /* MD5 */ + APR_ARRAY_PUSH(m, char *) = + apr_psprintf(r->pool, "&xt=urn:md5:%s", hashbag->md5); + + /* size */ + APR_ARRAY_PUSH(m, char *) = + apr_psprintf(r->pool, "&xl=%s", apr_off_t_toa(r->pool, r->finfo.size)); + + /* file basename */ + APR_ARRAY_PUSH(m, char *) = + apr_psprintf(r->pool, "&dn=%s", ap_escape_uri(r->pool, basename)); + + /* a HTTP link to the file */ + APR_ARRAY_PUSH(m, char *) = + apr_psprintf(r->pool, "&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, "&tr=%s", ap_escape_uri(r->pool, scfg->tracker_url)); + } + + magnet = apr_array_pstrcat(r->pool, m, '\0'); + } } } _at_@ -2597,6 +2630,10 @@ RSRC_CONF, "Name and URL for the metalinks publisher elements"), + AP_INIT_TAKE1("MirrorBrainTrackerURL", mb_cmd_tracker_url, NULL, + RSRC_CONF, + "Define a Tracker URL to be included in Magnet links"), + AP_INIT_TAKE1("MirrorBrainMetalinkBrokenTestMirrors", mb_cmd_metalink_broken_test_mirrors, NULL, RSRC_CONF, "Filename with snippet to include at the top of a metalink's " _______________________________________________ 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.orgReceived on Sat Mar 13 2010 - 00:50:41 GMT
This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT