<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -164,6 +164,9 @@ sub HandleHttpRequest {
 	elsif($rq-&gt;{URI} =~ /^\/history\/(.+)$/) {
 		$data = $self-&gt;_JSON_HistoryAction($1);
 	}
+	elsif($rq-&gt;{METHOD} eq 'POST' &amp;&amp; $rq-&gt;{URI} =~ /^\/new_torrent$/) {
+	  $data = $self-&gt;_JSON_NewTorrentAction($body);
+	}
 	elsif(my($xh,$xfile) = $rq-&gt;{URI} =~ /^\/getfile\/([a-z0-9]{40})\/(\d+)$/) {
 		if(my $so = $self-&gt;{super}-&gt;Storage-&gt;OpenStorage($xh)) {
 			$xfile     = abs(int($xfile-1)); # 'GUI' starts at 1 / Storage at 0
@@ -469,6 +472,30 @@ sub _HttpSendHeader {
 
 
 ##########################################################################
+# Accept a POST'ed Torrent file, and dumps it into the autoload directory
+sub _JSON_NewTorrentAction {
+  my ($self, $torrent) = @_;
+  my $ok = 0;
+  my $msg = '';
+  
+  # Create new autoload file
+  my $destfile  = sprintf(&quot;%s/%x-%x-%x.http_download&quot;, $self-&gt;{super}-&gt;Configuration-&gt;GetValue('tempdir'), $$, int(rand(0xFFFFFF)), int(time()));
+	if( open(DEST, &quot;&gt;&quot;, $destfile) ) {
+		print DEST $torrent;
+		close(DEST);
+		my $exe = $self-&gt;{super}-&gt;Admin-&gt;ExecuteCommand('load', $destfile);
+    $ok = 1 unless $exe-&gt;{FAILS};
+    $msg = $exe-&gt;{MSG}[0][1];
+	}
+	else {
+	  $msg = &quot;Could not create temp file $destfile: $!&quot;;
+	}
+	
+	$msg = $self-&gt;_sEsc($msg);
+  return qq!({ ok =&gt; $ok, msg =&gt; &quot;$msg&quot; })!;
+}
+
+##########################################################################
 # Return global statistics
 sub _JSON_GlobalStats {
 	my($self) = @_;</diff>
      <filename>plugins/Bitflu/10_AdminHTTP.pm</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>5996b07f9902e7662791b88c1f878dfc9c25a565</id>
    </parent>
  </parents>
  <author>
    <name>Pedro Melo</name>
    <email>melo@simplicidade.org</email>
  </author>
  <url>http://github.com/melo/bitflu/commit/d3057ccfdac5932f64e80ba7a98f2c73922fbb5d</url>
  <id>d3057ccfdac5932f64e80ba7a98f2c73922fbb5d</id>
  <committed-date>2008-10-29T05:57:52-07:00</committed-date>
  <authored-date>2008-10-29T05:57:52-07:00</authored-date>
  <message>Added new action, /new_torrent

You can POST a torrent file to be started.

For example:

    lwp-request -c 'application/x-bittorrent' -m POST \
      http://127.0.0.1:4081/new_torrent  &lt; my.torrent

should do the trick.

Signed-off-by: Pedro Melo &lt;melo@simplicidade.org&gt;</message>
  <tree>3dd4196d0636271017296fd8da504af4de05a38d</tree>
  <committer>
    <name>Pedro Melo</name>
    <email>melo@simplicidade.org</email>
  </committer>
</commit>
