764 lines
115 KiB
HTML
764 lines
115 KiB
HTML
<?xml version="1.0" encoding="utf-8" ?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="generator" content="Docutils 0.12: http://docutils.sourceforge.net/" />
|
|
<title>libtorrent Examples</title>
|
|
<meta name="author" content="Arvid Norberg, arvid@libtorrent.org" />
|
|
<meta name=viewport content="width=device-width, initial-scale=1">
|
|
<script type="text/javascript">
|
|
/* <![CDATA[ */
|
|
(function() {
|
|
var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];
|
|
s.type = 'text/javascript';
|
|
s.async = true;
|
|
s.src = 'http://api.flattr.com/js/0.6/load.js?mode=auto';
|
|
t.parentNode.insertBefore(s, t);
|
|
})();
|
|
/* ]]> */
|
|
</script>
|
|
<link rel="stylesheet" href="style.css" type="text/css" />
|
|
<link rel="stylesheet" type="text/css" href="rst.css" />
|
|
<style type="text/css">
|
|
/* Hides from IE-mac \*/
|
|
* html pre { height: 1%; }
|
|
/* End hide from IE-mac */
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="document" id="libtorrent-examples">
|
|
<div id="container">
|
|
<table id="header">
|
|
<tr><td id="orange"></td>
|
|
<td id="logo">libtorrent</td></tr>
|
|
</table>
|
|
<div id="main">
|
|
<h1 class="title">libtorrent Examples</h1>
|
|
<table class="docinfo" frame="void" rules="none">
|
|
<col class="docinfo-name" />
|
|
<col class="docinfo-content" />
|
|
<tbody valign="top">
|
|
<tr><th class="docinfo-name">Author:</th>
|
|
<td>Arvid Norberg, <a class="last reference external" href="mailto:arvid@libtorrent.org">arvid@libtorrent.org</a></td></tr>
|
|
<tr><th class="docinfo-name">Version:</th>
|
|
<td>1.1.0</td></tr>
|
|
</tbody>
|
|
</table>
|
|
<div class="contents topic" id="table-of-contents">
|
|
<p class="topic-title first">Table of contents</p>
|
|
<ul class="simple">
|
|
<li><a class="reference internal" href="#examples" id="id2">examples</a><ul>
|
|
<li><a class="reference internal" href="#simple-client" id="id3">simple client</a></li>
|
|
<li><a class="reference internal" href="#make-torrent" id="id4">make_torrent</a></li>
|
|
<li><a class="reference internal" href="#dump-torrent" id="id5">dump_torrent</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div class="section" id="examples">
|
|
<h1>examples</h1>
|
|
<p>Except for the example programs in this manual, there's also a bigger example
|
|
of a (little bit) more complete client, <tt class="docutils literal">client_test</tt>. There are separate
|
|
instructions for how to use it <a class="reference external" href="client_test.html">here</a> if you'd like to try it. Note that building
|
|
<tt class="docutils literal">client_test</tt> also requires boost.regex and boost.program_options library.</p>
|
|
<div class="section" id="simple-client">
|
|
<h2>simple client</h2>
|
|
<p>This is a simple client. It doesn't have much output to keep it simple:</p>
|
|
<pre class="code c++ literal-block">
|
|
<span class="comment preproc">#include <stdlib.h>
|
|
#include <boost/make_shared.hpp>
|
|
#include "libtorrent/entry.hpp"
|
|
#include "libtorrent/bencode.hpp"
|
|
#include "libtorrent/session.hpp"
|
|
#include "libtorrent/torrent_info.hpp"
|
|
</span>
|
|
<span class="keyword type">int</span> <span class="name function">main</span><span class="punctuation">(</span><span class="keyword type">int</span> <span class="name">argc</span><span class="punctuation">,</span> <span class="keyword type">char</span><span class="operator">*</span> <span class="name">argv</span><span class="punctuation">[])</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="name">libtorrent</span><span class="punctuation">;</span>
|
|
<span class="keyword">namespace</span> <span class="name">lt</span> <span class="operator">=</span> <span class="name">libtorrent</span><span class="punctuation">;</span>
|
|
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">argc</span> <span class="operator">!=</span> <span class="literal number integer">2</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fputs</span><span class="punctuation">(</span><span class="literal string">"usage: ./simple_client torrent-file</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"to stop the client, press return.</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">stderr</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="name">settings_pack</span> <span class="name">sett</span><span class="punctuation">;</span>
|
|
<span class="name">sett</span><span class="punctuation">.</span><span class="name">set_str</span><span class="punctuation">(</span><span class="name">settings_pack</span><span class="operator">::</span><span class="name">listen_interfaces</span><span class="punctuation">,</span> <span class="literal string">"0.0.0.0:6881"</span><span class="punctuation">);</span>
|
|
<span class="name">lt</span><span class="operator">::</span><span class="name">session</span> <span class="name">s</span><span class="punctuation">(</span><span class="name">sett</span><span class="punctuation">);</span>
|
|
<span class="name">error_code</span> <span class="name">ec</span><span class="punctuation">;</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">ec</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"failed to open listen socket: %s</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">ec</span><span class="punctuation">.</span><span class="name">message</span><span class="punctuation">().</span><span class="name">c_str</span><span class="punctuation">());</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="name">add_torrent_params</span> <span class="name">p</span><span class="punctuation">;</span>
|
|
<span class="name">p</span><span class="punctuation">.</span><span class="name">save_path</span> <span class="operator">=</span> <span class="literal string">"./"</span><span class="punctuation">;</span>
|
|
<span class="name">p</span><span class="punctuation">.</span><span class="name">ti</span> <span class="operator">=</span> <span class="name">boost</span><span class="operator">::</span><span class="name">make_shared</span><span class="operator"><</span><span class="name">torrent_info</span><span class="operator">></span><span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">string</span><span class="punctuation">(</span><span class="name">argv</span><span class="punctuation">[</span><span class="literal number integer">1</span><span class="punctuation">]),</span> <span class="name">boost</span><span class="operator">::</span><span class="name">ref</span><span class="punctuation">(</span><span class="name">ec</span><span class="punctuation">),</span> <span class="literal number integer">0</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">ec</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"%s</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">ec</span><span class="punctuation">.</span><span class="name">message</span><span class="punctuation">().</span><span class="name">c_str</span><span class="punctuation">());</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="name">s</span><span class="punctuation">.</span><span class="name">add_torrent</span><span class="punctuation">(</span><span class="name">p</span><span class="punctuation">,</span> <span class="name">ec</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">ec</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"%s</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">ec</span><span class="punctuation">.</span><span class="name">message</span><span class="punctuation">().</span><span class="name">c_str</span><span class="punctuation">());</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="comment single">// wait for the user to end
|
|
</span> <span class="keyword type">char</span> <span class="name">a</span><span class="punctuation">;</span>
|
|
<span class="name">scanf</span><span class="punctuation">(</span><span class="literal string">"%c</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="operator">&</span><span class="name">a</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">0</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
</pre>
|
|
</div>
|
|
<div class="section" id="make-torrent">
|
|
<h2>make_torrent</h2>
|
|
<p>Shows how to create a torrent from a directory tree:</p>
|
|
<pre class="code c++ literal-block">
|
|
<span class="comment preproc">#include "libtorrent/entry.hpp"
|
|
#include "libtorrent/bencode.hpp"
|
|
#include "libtorrent/torrent_info.hpp"
|
|
#include "libtorrent/file.hpp"
|
|
#include "libtorrent/storage.hpp"
|
|
#include "libtorrent/hasher.hpp"
|
|
#include "libtorrent/create_torrent.hpp"
|
|
#include "libtorrent/file.hpp"
|
|
#include "libtorrent/file_pool.hpp"
|
|
#include "libtorrent/hex.hpp" </span><span class="comment single">// for from_hex
|
|
</span>
|
|
<span class="comment preproc">#include <boost/bind.hpp>
|
|
</span>
|
|
<span class="comment preproc">#ifdef TORRENT_WINDOWS
|
|
#include <direct.h> </span><span class="comment single">// for _getcwd
|
|
</span><span class="comment preproc">#endif
|
|
</span>
|
|
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="name">libtorrent</span><span class="punctuation">;</span>
|
|
|
|
<span class="keyword type">int</span> <span class="name function">load_file</span><span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">string</span> <span class="keyword">const</span><span class="operator">&</span> <span class="name">filename</span><span class="punctuation">,</span> <span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator"><</span><span class="keyword type">char</span><span class="operator">>&</span> <span class="name">v</span><span class="punctuation">,</span> <span class="name">libtorrent</span><span class="operator">::</span><span class="name">error_code</span><span class="operator">&</span> <span class="name">ec</span><span class="punctuation">,</span> <span class="keyword type">int</span> <span class="name">limit</span> <span class="operator">=</span> <span class="literal number integer">8000000</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">ec</span><span class="punctuation">.</span><span class="name">clear</span><span class="punctuation">();</span>
|
|
<span class="keyword type">FILE</span><span class="operator">*</span> <span class="name">f</span> <span class="operator">=</span> <span class="name">fopen</span><span class="punctuation">(</span><span class="name">filename</span><span class="punctuation">.</span><span class="name">c_str</span><span class="punctuation">(),</span> <span class="literal string">"rb"</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">f</span> <span class="operator">==</span> <span class="name builtin">NULL</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">ec</span><span class="punctuation">.</span><span class="name">assign</span><span class="punctuation">(</span><span class="name">errno</span><span class="punctuation">,</span> <span class="name">boost</span><span class="operator">::</span><span class="name">system</span><span class="operator">::</span><span class="name">generic_category</span><span class="punctuation">());</span>
|
|
<span class="keyword">return</span> <span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="keyword type">int</span> <span class="name">r</span> <span class="operator">=</span> <span class="name">fseek</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">,</span> <span class="literal number integer">0</span><span class="punctuation">,</span> <span class="name">SEEK_END</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">r</span> <span class="operator">!=</span> <span class="literal number integer">0</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">ec</span><span class="punctuation">.</span><span class="name">assign</span><span class="punctuation">(</span><span class="name">errno</span><span class="punctuation">,</span> <span class="name">boost</span><span class="operator">::</span><span class="name">system</span><span class="operator">::</span><span class="name">generic_category</span><span class="punctuation">());</span>
|
|
<span class="name">fclose</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="keyword type">long</span> <span class="name">s</span> <span class="operator">=</span> <span class="name">ftell</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">s</span> <span class="operator"><</span> <span class="literal number integer">0</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">ec</span><span class="punctuation">.</span><span class="name">assign</span><span class="punctuation">(</span><span class="name">errno</span><span class="punctuation">,</span> <span class="name">boost</span><span class="operator">::</span><span class="name">system</span><span class="operator">::</span><span class="name">generic_category</span><span class="punctuation">());</span>
|
|
<span class="name">fclose</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">s</span> <span class="operator">></span> <span class="name">limit</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fclose</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="operator">-</span><span class="literal number integer">2</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="name">r</span> <span class="operator">=</span> <span class="name">fseek</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">,</span> <span class="literal number integer">0</span><span class="punctuation">,</span> <span class="name">SEEK_SET</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">r</span> <span class="operator">!=</span> <span class="literal number integer">0</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">ec</span><span class="punctuation">.</span><span class="name">assign</span><span class="punctuation">(</span><span class="name">errno</span><span class="punctuation">,</span> <span class="name">boost</span><span class="operator">::</span><span class="name">system</span><span class="operator">::</span><span class="name">generic_category</span><span class="punctuation">());</span>
|
|
<span class="name">fclose</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="name">v</span><span class="punctuation">.</span><span class="name">resize</span><span class="punctuation">(</span><span class="name">s</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">s</span> <span class="operator">==</span> <span class="literal number integer">0</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fclose</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">0</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="name">r</span> <span class="operator">=</span> <span class="name">fread</span><span class="punctuation">(</span><span class="operator">&</span><span class="name">v</span><span class="punctuation">[</span><span class="literal number integer">0</span><span class="punctuation">],</span> <span class="literal number integer">1</span><span class="punctuation">,</span> <span class="name">v</span><span class="punctuation">.</span><span class="name">size</span><span class="punctuation">(),</span> <span class="name">f</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">r</span> <span class="operator"><</span> <span class="literal number integer">0</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">ec</span><span class="punctuation">.</span><span class="name">assign</span><span class="punctuation">(</span><span class="name">errno</span><span class="punctuation">,</span> <span class="name">boost</span><span class="operator">::</span><span class="name">system</span><span class="operator">::</span><span class="name">generic_category</span><span class="punctuation">());</span>
|
|
<span class="name">fclose</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="name">fclose</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">);</span>
|
|
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">r</span> <span class="operator">!=</span> <span class="name">s</span><span class="punctuation">)</span> <span class="keyword">return</span> <span class="operator">-</span><span class="literal number integer">3</span><span class="punctuation">;</span>
|
|
|
|
<span class="keyword">return</span> <span class="literal number integer">0</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="name">std</span><span class="operator">::</span><span class="name">string</span> <span class="name">branch_path</span><span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">string</span> <span class="keyword">const</span><span class="operator">&</span> <span class="name">f</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">f</span><span class="punctuation">.</span><span class="name">empty</span><span class="punctuation">())</span> <span class="keyword">return</span> <span class="name">f</span><span class="punctuation">;</span>
|
|
|
|
<span class="comment preproc">#ifdef TORRENT_WINDOWS
|
|
</span> <span class="keyword">if</span> <span class="punctuation">(</span><span class="name">f</span> <span class="operator">==</span> <span class="literal string">"</span><span class="literal string escape">\\\\</span><span class="literal string">"</span><span class="punctuation">)</span> <span class="keyword">return</span> <span class="literal string">""</span><span class="punctuation">;</span>
|
|
<span class="comment preproc">#endif
|
|
</span> <span class="keyword">if</span> <span class="punctuation">(</span><span class="name">f</span> <span class="operator">==</span> <span class="literal string">"/"</span><span class="punctuation">)</span> <span class="keyword">return</span> <span class="literal string">""</span><span class="punctuation">;</span>
|
|
|
|
<span class="keyword type">int</span> <span class="name">len</span> <span class="operator">=</span> <span class="name">f</span><span class="punctuation">.</span><span class="name">size</span><span class="punctuation">();</span>
|
|
<span class="comment single">// if the last character is / or \ ignore it
|
|
</span> <span class="keyword">if</span> <span class="punctuation">(</span><span class="name">f</span><span class="punctuation">[</span><span class="name">len</span><span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">]</span> <span class="operator">==</span> <span class="literal string char">'/'</span> <span class="operator">||</span> <span class="name">f</span><span class="punctuation">[</span><span class="name">len</span><span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">]</span> <span class="operator">==</span> <span class="literal string char">'\\'</span><span class="punctuation">)</span> <span class="operator">--</span><span class="name">len</span><span class="punctuation">;</span>
|
|
<span class="keyword">while</span> <span class="punctuation">(</span><span class="name">len</span> <span class="operator">></span> <span class="literal number integer">0</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="operator">--</span><span class="name">len</span><span class="punctuation">;</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">f</span><span class="punctuation">[</span><span class="name">len</span><span class="punctuation">]</span> <span class="operator">==</span> <span class="literal string char">'/'</span> <span class="operator">||</span> <span class="name">f</span><span class="punctuation">[</span><span class="name">len</span><span class="punctuation">]</span> <span class="operator">==</span> <span class="literal string char">'\\'</span><span class="punctuation">)</span>
|
|
<span class="keyword">break</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">f</span><span class="punctuation">[</span><span class="name">len</span><span class="punctuation">]</span> <span class="operator">==</span> <span class="literal string char">'/'</span> <span class="operator">||</span> <span class="name">f</span><span class="punctuation">[</span><span class="name">len</span><span class="punctuation">]</span> <span class="operator">==</span> <span class="literal string char">'\\'</span><span class="punctuation">)</span> <span class="operator">++</span><span class="name">len</span><span class="punctuation">;</span>
|
|
<span class="keyword">return</span> <span class="name">std</span><span class="operator">::</span><span class="name">string</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">.</span><span class="name">c_str</span><span class="punctuation">(),</span> <span class="name">len</span><span class="punctuation">);</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="comment single">// do not include files and folders whose
|
|
// name starts with a .
|
|
</span><span class="keyword type">bool</span> <span class="name">file_filter</span><span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">string</span> <span class="keyword">const</span><span class="operator">&</span> <span class="name">f</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">f</span><span class="punctuation">.</span><span class="name">empty</span><span class="punctuation">())</span> <span class="keyword">return</span> <span class="name builtin">false</span><span class="punctuation">;</span>
|
|
|
|
<span class="keyword type">char</span> <span class="keyword">const</span><span class="operator">*</span> <span class="name">first</span> <span class="operator">=</span> <span class="name">f</span><span class="punctuation">.</span><span class="name">c_str</span><span class="punctuation">();</span>
|
|
<span class="keyword type">char</span> <span class="keyword">const</span><span class="operator">*</span> <span class="name">sep</span> <span class="operator">=</span> <span class="name">strrchr</span><span class="punctuation">(</span><span class="name">first</span><span class="punctuation">,</span> <span class="literal string char">'/'</span><span class="punctuation">);</span>
|
|
<span class="comment preproc">#if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2)
|
|
</span> <span class="keyword type">char</span> <span class="keyword">const</span><span class="operator">*</span> <span class="name">altsep</span> <span class="operator">=</span> <span class="name">strrchr</span><span class="punctuation">(</span><span class="name">first</span><span class="punctuation">,</span> <span class="literal string char">'\\'</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">sep</span> <span class="operator">==</span> <span class="name builtin">NULL</span> <span class="operator">||</span> <span class="name">altsep</span> <span class="operator">></span> <span class="name">sep</span><span class="punctuation">)</span> <span class="name">sep</span> <span class="operator">=</span> <span class="name">altsep</span><span class="punctuation">;</span>
|
|
<span class="comment preproc">#endif
|
|
</span> <span class="comment single">// if there is no parent path, just set 'sep'
|
|
</span> <span class="comment single">// to point to the filename.
|
|
</span> <span class="comment single">// if there is a parent path, skip the '/' character
|
|
</span> <span class="keyword">if</span> <span class="punctuation">(</span><span class="name">sep</span> <span class="operator">==</span> <span class="name builtin">NULL</span><span class="punctuation">)</span> <span class="name">sep</span> <span class="operator">=</span> <span class="name">first</span><span class="punctuation">;</span>
|
|
<span class="keyword">else</span> <span class="operator">++</span><span class="name">sep</span><span class="punctuation">;</span>
|
|
|
|
<span class="comment single">// return false if the first character of the filename is a .
|
|
</span> <span class="keyword">if</span> <span class="punctuation">(</span><span class="name">sep</span><span class="punctuation">[</span><span class="literal number integer">0</span><span class="punctuation">]</span> <span class="operator">==</span> <span class="literal string char">'.'</span><span class="punctuation">)</span> <span class="keyword">return</span> <span class="name builtin">false</span><span class="punctuation">;</span>
|
|
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"%s</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">f</span><span class="punctuation">.</span><span class="name">c_str</span><span class="punctuation">());</span>
|
|
<span class="keyword">return</span> <span class="name builtin">true</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="keyword type">void</span> <span class="name">print_progress</span><span class="punctuation">(</span><span class="keyword type">int</span> <span class="name">i</span><span class="punctuation">,</span> <span class="keyword type">int</span> <span class="name">num</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"</span><span class="literal string escape">\r</span><span class="literal string">%d/%d"</span><span class="punctuation">,</span> <span class="name">i</span><span class="operator">+</span><span class="literal number integer">1</span><span class="punctuation">,</span> <span class="name">num</span><span class="punctuation">);</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="keyword type">void</span> <span class="name">print_usage</span><span class="punctuation">()</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fputs</span><span class="punctuation">(</span><span class="literal string">"usage: make_torrent FILE [OPTIONS]</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"Generates a torrent file from the specified file</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"or directory and writes it to standard out</span><span class="literal string escape">\n\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"OPTIONS:</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"-m file generate a merkle hash tree torrent.</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" merkle torrents require client support</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" the resulting full merkle tree is written to</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" the specified file</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"-w url adds a web seed to the torrent with</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" the specified url</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"-t url adds the specified tracker to the</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" torrent. For multiple trackers, specify more</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" -t options</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"-c comment sets the comment to the specified string</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"-C creator sets the created-by field to the specified string</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"-p bytes enables padding files. Files larger</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" than bytes will be piece-aligned</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"-s bytes specifies a piece size for the torrent</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" This has to be a multiple of 16 kiB</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"-l Don't follow symlinks, instead encode them as</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" links in the torrent file</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"-o file specifies the output filename of the torrent file</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" If this is not specified, the torrent file is</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" printed to the standard out, except on windows</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" where the filename defaults to a.torrent</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"-r file add root certificate to the torrent, to verify</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" the HTTPS tracker</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"-S info-hash add a similar torrent by info-hash. The similar</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" torrent is expected to share some files with this one</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"-L collection add a collection name to this torrent. Other torrents</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" in the same collection is expected to share files</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" with this one.</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"-M make the torrent compatible with mutable torrents</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" this means aligning large files and pad them in order</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" for piece hashes to uniquely indentify a file without</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">" overlap</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="punctuation">,</span> <span class="name">stderr</span><span class="punctuation">);</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="keyword type">int</span> <span class="name">main</span><span class="punctuation">(</span><span class="keyword type">int</span> <span class="name">argc</span><span class="punctuation">,</span> <span class="keyword type">char</span><span class="operator">*</span> <span class="name">argv</span><span class="punctuation">[])</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="name">libtorrent</span><span class="punctuation">;</span>
|
|
|
|
<span class="name">std</span><span class="operator">::</span><span class="name">string</span> <span class="name">creator_str</span> <span class="operator">=</span> <span class="literal string">"libtorrent"</span><span class="punctuation">;</span>
|
|
<span class="name">std</span><span class="operator">::</span><span class="name">string</span> <span class="name">comment_str</span><span class="punctuation">;</span>
|
|
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">argc</span> <span class="operator"><</span> <span class="literal number integer">2</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">print_usage</span><span class="punctuation">();</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="comment preproc">#ifndef BOOST_NO_EXCEPTIONS
|
|
</span> <span class="name">try</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="comment preproc">#endif
|
|
</span> <span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator"><</span><span class="name">std</span><span class="operator">::</span><span class="name">string</span><span class="operator">></span> <span class="name">web_seeds</span><span class="punctuation">;</span>
|
|
<span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator"><</span><span class="name">std</span><span class="operator">::</span><span class="name">string</span><span class="operator">></span> <span class="name">trackers</span><span class="punctuation">;</span>
|
|
<span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator"><</span><span class="name">std</span><span class="operator">::</span><span class="name">string</span><span class="operator">></span> <span class="name">collections</span><span class="punctuation">;</span>
|
|
<span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator"><</span><span class="name">sha1_hash</span><span class="operator">></span> <span class="name">similar</span><span class="punctuation">;</span>
|
|
<span class="keyword type">int</span> <span class="name">pad_file_limit</span> <span class="operator">=</span> <span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="keyword type">int</span> <span class="name">piece_size</span> <span class="operator">=</span> <span class="literal number integer">0</span><span class="punctuation">;</span>
|
|
<span class="keyword type">int</span> <span class="name">flags</span> <span class="operator">=</span> <span class="literal number integer">0</span><span class="punctuation">;</span>
|
|
<span class="name">std</span><span class="operator">::</span><span class="name">string</span> <span class="name">root_cert</span><span class="punctuation">;</span>
|
|
|
|
<span class="name">std</span><span class="operator">::</span><span class="name">string</span> <span class="name">outfile</span><span class="punctuation">;</span>
|
|
<span class="name">std</span><span class="operator">::</span><span class="name">string</span> <span class="name">merklefile</span><span class="punctuation">;</span>
|
|
<span class="comment preproc">#ifdef TORRENT_WINDOWS
|
|
</span> <span class="comment single">// don't ever write binary data to the console on windows
|
|
</span> <span class="comment single">// it will just be interpreted as text and corrupted
|
|
</span> <span class="name">outfile</span> <span class="operator">=</span> <span class="literal string">"a.torrent"</span><span class="punctuation">;</span>
|
|
<span class="comment preproc">#endif
|
|
</span>
|
|
<span class="keyword">for</span> <span class="punctuation">(</span><span class="keyword type">int</span> <span class="name">i</span> <span class="operator">=</span> <span class="literal number integer">2</span><span class="punctuation">;</span> <span class="name">i</span> <span class="operator"><</span> <span class="name">argc</span><span class="punctuation">;</span> <span class="operator">++</span><span class="name">i</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">argv</span><span class="punctuation">[</span><span class="name">i</span><span class="punctuation">][</span><span class="literal number integer">0</span><span class="punctuation">]</span> <span class="operator">!=</span> <span class="literal string char">'-'</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">print_usage</span><span class="punctuation">();</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="keyword">switch</span> <span class="punctuation">(</span><span class="name">argv</span><span class="punctuation">[</span><span class="name">i</span><span class="punctuation">][</span><span class="literal number integer">1</span><span class="punctuation">])</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="keyword">case</span> <span class="literal string char">'w'</span><span class="operator">:</span>
|
|
<span class="operator">++</span><span class="name">i</span><span class="punctuation">;</span>
|
|
<span class="name">web_seeds</span><span class="punctuation">.</span><span class="name">push_back</span><span class="punctuation">(</span><span class="name">argv</span><span class="punctuation">[</span><span class="name">i</span><span class="punctuation">]);</span>
|
|
<span class="keyword">break</span><span class="punctuation">;</span>
|
|
<span class="keyword">case</span> <span class="literal string char">'t'</span><span class="operator">:</span>
|
|
<span class="operator">++</span><span class="name">i</span><span class="punctuation">;</span>
|
|
<span class="name">trackers</span><span class="punctuation">.</span><span class="name">push_back</span><span class="punctuation">(</span><span class="name">argv</span><span class="punctuation">[</span><span class="name">i</span><span class="punctuation">]);</span>
|
|
<span class="keyword">break</span><span class="punctuation">;</span>
|
|
<span class="keyword">case</span> <span class="literal string char">'M'</span><span class="operator">:</span>
|
|
<span class="name">flags</span> <span class="operator">|=</span> <span class="name">create_torrent</span><span class="operator">::</span><span class="name">mutable_torrent_support</span><span class="punctuation">;</span>
|
|
<span class="name">pad_file_limit</span> <span class="operator">=</span> <span class="literal number hex">0x4000</span><span class="punctuation">;</span>
|
|
<span class="keyword">break</span><span class="punctuation">;</span>
|
|
<span class="keyword">case</span> <span class="literal string char">'p'</span><span class="operator">:</span>
|
|
<span class="operator">++</span><span class="name">i</span><span class="punctuation">;</span>
|
|
<span class="name">pad_file_limit</span> <span class="operator">=</span> <span class="name">atoi</span><span class="punctuation">(</span><span class="name">argv</span><span class="punctuation">[</span><span class="name">i</span><span class="punctuation">]);</span>
|
|
<span class="name">flags</span> <span class="operator">|=</span> <span class="name">create_torrent</span><span class="operator">::</span><span class="name">optimize</span><span class="punctuation">;</span>
|
|
<span class="keyword">break</span><span class="punctuation">;</span>
|
|
<span class="keyword">case</span> <span class="literal string char">'s'</span><span class="operator">:</span>
|
|
<span class="operator">++</span><span class="name">i</span><span class="punctuation">;</span>
|
|
<span class="name">piece_size</span> <span class="operator">=</span> <span class="name">atoi</span><span class="punctuation">(</span><span class="name">argv</span><span class="punctuation">[</span><span class="name">i</span><span class="punctuation">]);</span>
|
|
<span class="keyword">break</span><span class="punctuation">;</span>
|
|
<span class="keyword">case</span> <span class="literal string char">'m'</span><span class="operator">:</span>
|
|
<span class="operator">++</span><span class="name">i</span><span class="punctuation">;</span>
|
|
<span class="name">merklefile</span> <span class="operator">=</span> <span class="name">argv</span><span class="punctuation">[</span><span class="name">i</span><span class="punctuation">];</span>
|
|
<span class="name">flags</span> <span class="operator">|=</span> <span class="name">create_torrent</span><span class="operator">::</span><span class="name">merkle</span><span class="punctuation">;</span>
|
|
<span class="keyword">break</span><span class="punctuation">;</span>
|
|
<span class="keyword">case</span> <span class="literal string char">'o'</span><span class="operator">:</span>
|
|
<span class="operator">++</span><span class="name">i</span><span class="punctuation">;</span>
|
|
<span class="name">outfile</span> <span class="operator">=</span> <span class="name">argv</span><span class="punctuation">[</span><span class="name">i</span><span class="punctuation">];</span>
|
|
<span class="keyword">break</span><span class="punctuation">;</span>
|
|
<span class="keyword">case</span> <span class="literal string char">'l'</span><span class="operator">:</span>
|
|
<span class="name">flags</span> <span class="operator">|=</span> <span class="name">create_torrent</span><span class="operator">::</span><span class="name">symlinks</span><span class="punctuation">;</span>
|
|
<span class="keyword">break</span><span class="punctuation">;</span>
|
|
<span class="keyword">case</span> <span class="literal string char">'C'</span><span class="operator">:</span>
|
|
<span class="operator">++</span><span class="name">i</span><span class="punctuation">;</span>
|
|
<span class="name">creator_str</span> <span class="operator">=</span> <span class="name">argv</span><span class="punctuation">[</span><span class="name">i</span><span class="punctuation">];</span>
|
|
<span class="keyword">break</span><span class="punctuation">;</span>
|
|
<span class="keyword">case</span> <span class="literal string char">'c'</span><span class="operator">:</span>
|
|
<span class="operator">++</span><span class="name">i</span><span class="punctuation">;</span>
|
|
<span class="name">comment_str</span> <span class="operator">=</span> <span class="name">argv</span><span class="punctuation">[</span><span class="name">i</span><span class="punctuation">];</span>
|
|
<span class="keyword">break</span><span class="punctuation">;</span>
|
|
<span class="keyword">case</span> <span class="literal string char">'r'</span><span class="operator">:</span>
|
|
<span class="operator">++</span><span class="name">i</span><span class="punctuation">;</span>
|
|
<span class="name">root_cert</span> <span class="operator">=</span> <span class="name">argv</span><span class="punctuation">[</span><span class="name">i</span><span class="punctuation">];</span>
|
|
<span class="keyword">break</span><span class="punctuation">;</span>
|
|
<span class="keyword">case</span> <span class="literal string char">'S'</span><span class="operator">:</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="operator">++</span><span class="name">i</span><span class="punctuation">;</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">strlen</span><span class="punctuation">(</span><span class="name">argv</span><span class="punctuation">[</span><span class="name">i</span><span class="punctuation">])</span> <span class="operator">!=</span> <span class="literal number integer">40</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"invalid info-hash for -S. "</span>
|
|
<span class="literal string">"Expected 40 hex characters</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">);</span>
|
|
<span class="name">print_usage</span><span class="punctuation">();</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="name">sha1_hash</span> <span class="name">ih</span><span class="punctuation">;</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="operator">!</span><span class="name">from_hex</span><span class="punctuation">(</span><span class="name">argv</span><span class="punctuation">[</span><span class="name">i</span><span class="punctuation">],</span> <span class="literal number integer">40</span><span class="punctuation">,</span> <span class="punctuation">(</span><span class="keyword type">char</span><span class="operator">*</span><span class="punctuation">)</span><span class="operator">&</span><span class="name">ih</span><span class="punctuation">[</span><span class="literal number integer">0</span><span class="punctuation">]))</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"invalid info-hash for -S</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">);</span>
|
|
<span class="name">print_usage</span><span class="punctuation">();</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="name">similar</span><span class="punctuation">.</span><span class="name">push_back</span><span class="punctuation">(</span><span class="name">ih</span><span class="punctuation">);</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="keyword">break</span><span class="punctuation">;</span>
|
|
<span class="keyword">case</span> <span class="literal string char">'L'</span><span class="operator">:</span>
|
|
<span class="operator">++</span><span class="name">i</span><span class="punctuation">;</span>
|
|
<span class="name">collections</span><span class="punctuation">.</span><span class="name">push_back</span><span class="punctuation">(</span><span class="name">argv</span><span class="punctuation">[</span><span class="name">i</span><span class="punctuation">]);</span>
|
|
<span class="keyword">break</span><span class="punctuation">;</span>
|
|
<span class="keyword">default</span><span class="operator">:</span>
|
|
<span class="name">print_usage</span><span class="punctuation">();</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="name">file_storage</span> <span class="name">fs</span><span class="punctuation">;</span>
|
|
<span class="name">std</span><span class="operator">::</span><span class="name">string</span> <span class="name">full_path</span> <span class="operator">=</span> <span class="name">argv</span><span class="punctuation">[</span><span class="literal number integer">1</span><span class="punctuation">];</span>
|
|
<span class="comment preproc">#ifdef TORRENT_WINDOWS
|
|
</span> <span class="keyword">if</span> <span class="punctuation">(</span><span class="name">full_path</span><span class="punctuation">[</span><span class="literal number integer">1</span><span class="punctuation">]</span> <span class="operator">!=</span> <span class="literal string char">':'</span><span class="punctuation">)</span>
|
|
<span class="comment preproc">#else
|
|
</span> <span class="keyword">if</span> <span class="punctuation">(</span><span class="name">full_path</span><span class="punctuation">[</span><span class="literal number integer">0</span><span class="punctuation">]</span> <span class="operator">!=</span> <span class="literal string char">'/'</span><span class="punctuation">)</span>
|
|
<span class="comment preproc">#endif
|
|
</span> <span class="punctuation">{</span>
|
|
<span class="keyword type">char</span> <span class="name">cwd</span><span class="punctuation">[</span><span class="name">TORRENT_MAX_PATH</span><span class="punctuation">];</span>
|
|
<span class="comment preproc">#ifdef TORRENT_WINDOWS
|
|
</span> <span class="name">_getcwd</span><span class="punctuation">(</span><span class="name">cwd</span><span class="punctuation">,</span> <span class="keyword">sizeof</span><span class="punctuation">(</span><span class="name">cwd</span><span class="punctuation">));</span>
|
|
<span class="name">full_path</span> <span class="operator">=</span> <span class="name">cwd</span> <span class="operator">+</span> <span class="punctuation">(</span><span class="literal string">"</span><span class="literal string escape">\\</span><span class="literal string">"</span> <span class="operator">+</span> <span class="name">full_path</span><span class="punctuation">);</span>
|
|
<span class="comment preproc">#else
|
|
</span> <span class="name">getcwd</span><span class="punctuation">(</span><span class="name">cwd</span><span class="punctuation">,</span> <span class="keyword">sizeof</span><span class="punctuation">(</span><span class="name">cwd</span><span class="punctuation">));</span>
|
|
<span class="name">full_path</span> <span class="operator">=</span> <span class="name">cwd</span> <span class="operator">+</span> <span class="punctuation">(</span><span class="literal string">"/"</span> <span class="operator">+</span> <span class="name">full_path</span><span class="punctuation">);</span>
|
|
<span class="comment preproc">#endif
|
|
</span> <span class="punctuation">}</span>
|
|
|
|
<span class="name">add_files</span><span class="punctuation">(</span><span class="name">fs</span><span class="punctuation">,</span> <span class="name">full_path</span><span class="punctuation">,</span> <span class="name">file_filter</span><span class="punctuation">,</span> <span class="name">flags</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">fs</span><span class="punctuation">.</span><span class="name">num_files</span><span class="punctuation">()</span> <span class="operator">==</span> <span class="literal number integer">0</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fputs</span><span class="punctuation">(</span><span class="literal string">"no files specified.</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">stderr</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="name">create_torrent</span> <span class="name">t</span><span class="punctuation">(</span><span class="name">fs</span><span class="punctuation">,</span> <span class="name">piece_size</span><span class="punctuation">,</span> <span class="name">pad_file_limit</span><span class="punctuation">,</span> <span class="name">flags</span><span class="punctuation">);</span>
|
|
<span class="keyword type">int</span> <span class="name">tier</span> <span class="operator">=</span> <span class="literal number integer">0</span><span class="punctuation">;</span>
|
|
<span class="keyword">for</span> <span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator"><</span><span class="name">std</span><span class="operator">::</span><span class="name">string</span><span class="operator">>::</span><span class="name">iterator</span> <span class="name">i</span> <span class="operator">=</span> <span class="name">trackers</span><span class="punctuation">.</span><span class="name">begin</span><span class="punctuation">()</span>
|
|
<span class="punctuation">,</span> <span class="name">end</span><span class="punctuation">(</span><span class="name">trackers</span><span class="punctuation">.</span><span class="name">end</span><span class="punctuation">());</span> <span class="name">i</span> <span class="operator">!=</span> <span class="name">end</span><span class="punctuation">;</span> <span class="operator">++</span><span class="name">i</span><span class="punctuation">,</span> <span class="operator">++</span><span class="name">tier</span><span class="punctuation">)</span>
|
|
<span class="name">t</span><span class="punctuation">.</span><span class="name">add_tracker</span><span class="punctuation">(</span><span class="operator">*</span><span class="name">i</span><span class="punctuation">,</span> <span class="name">tier</span><span class="punctuation">);</span>
|
|
|
|
<span class="keyword">for</span> <span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator"><</span><span class="name">std</span><span class="operator">::</span><span class="name">string</span><span class="operator">>::</span><span class="name">iterator</span> <span class="name">i</span> <span class="operator">=</span> <span class="name">web_seeds</span><span class="punctuation">.</span><span class="name">begin</span><span class="punctuation">()</span>
|
|
<span class="punctuation">,</span> <span class="name">end</span><span class="punctuation">(</span><span class="name">web_seeds</span><span class="punctuation">.</span><span class="name">end</span><span class="punctuation">());</span> <span class="name">i</span> <span class="operator">!=</span> <span class="name">end</span><span class="punctuation">;</span> <span class="operator">++</span><span class="name">i</span><span class="punctuation">)</span>
|
|
<span class="name">t</span><span class="punctuation">.</span><span class="name">add_url_seed</span><span class="punctuation">(</span><span class="operator">*</span><span class="name">i</span><span class="punctuation">);</span>
|
|
|
|
<span class="keyword">for</span> <span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator"><</span><span class="name">std</span><span class="operator">::</span><span class="name">string</span><span class="operator">>::</span><span class="name">iterator</span> <span class="name">i</span> <span class="operator">=</span> <span class="name">collections</span><span class="punctuation">.</span><span class="name">begin</span><span class="punctuation">()</span>
|
|
<span class="punctuation">,</span> <span class="name">end</span><span class="punctuation">(</span><span class="name">collections</span><span class="punctuation">.</span><span class="name">end</span><span class="punctuation">());</span> <span class="name">i</span> <span class="operator">!=</span> <span class="name">end</span><span class="punctuation">;</span> <span class="operator">++</span><span class="name">i</span><span class="punctuation">)</span>
|
|
<span class="name">t</span><span class="punctuation">.</span><span class="name">add_collection</span><span class="punctuation">(</span><span class="operator">*</span><span class="name">i</span><span class="punctuation">);</span>
|
|
|
|
<span class="keyword">for</span> <span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator"><</span><span class="name">sha1_hash</span><span class="operator">>::</span><span class="name">iterator</span> <span class="name">i</span> <span class="operator">=</span> <span class="name">similar</span><span class="punctuation">.</span><span class="name">begin</span><span class="punctuation">()</span>
|
|
<span class="punctuation">,</span> <span class="name">end</span><span class="punctuation">(</span><span class="name">similar</span><span class="punctuation">.</span><span class="name">end</span><span class="punctuation">());</span> <span class="name">i</span> <span class="operator">!=</span> <span class="name">end</span><span class="punctuation">;</span> <span class="operator">++</span><span class="name">i</span><span class="punctuation">)</span>
|
|
<span class="name">t</span><span class="punctuation">.</span><span class="name">add_similar_torrent</span><span class="punctuation">(</span><span class="operator">*</span><span class="name">i</span><span class="punctuation">);</span>
|
|
|
|
<span class="name">error_code</span> <span class="name">ec</span><span class="punctuation">;</span>
|
|
<span class="name">set_piece_hashes</span><span class="punctuation">(</span><span class="name">t</span><span class="punctuation">,</span> <span class="name">branch_path</span><span class="punctuation">(</span><span class="name">full_path</span><span class="punctuation">)</span>
|
|
<span class="punctuation">,</span> <span class="name">boost</span><span class="operator">::</span><span class="name">bind</span><span class="punctuation">(</span><span class="operator">&</span><span class="name">print_progress</span><span class="punctuation">,</span> <span class="name">_1</span><span class="punctuation">,</span> <span class="name">t</span><span class="punctuation">.</span><span class="name">num_pieces</span><span class="punctuation">()),</span> <span class="name">ec</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">ec</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"%s</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">ec</span><span class="punctuation">.</span><span class="name">message</span><span class="punctuation">().</span><span class="name">c_str</span><span class="punctuation">());</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">);</span>
|
|
<span class="name">t</span><span class="punctuation">.</span><span class="name">set_creator</span><span class="punctuation">(</span><span class="name">creator_str</span><span class="punctuation">.</span><span class="name">c_str</span><span class="punctuation">());</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="operator">!</span><span class="name">comment_str</span><span class="punctuation">.</span><span class="name">empty</span><span class="punctuation">())</span>
|
|
<span class="name">t</span><span class="punctuation">.</span><span class="name">set_comment</span><span class="punctuation">(</span><span class="name">comment_str</span><span class="punctuation">.</span><span class="name">c_str</span><span class="punctuation">());</span>
|
|
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="operator">!</span><span class="name">root_cert</span><span class="punctuation">.</span><span class="name">empty</span><span class="punctuation">())</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator"><</span><span class="keyword type">char</span><span class="operator">></span> <span class="name">pem</span><span class="punctuation">;</span>
|
|
<span class="name">load_file</span><span class="punctuation">(</span><span class="name">root_cert</span><span class="punctuation">,</span> <span class="name">pem</span><span class="punctuation">,</span> <span class="name">ec</span><span class="punctuation">,</span> <span class="literal number integer">10000</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">ec</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"failed to load root certificate for tracker: %s</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">ec</span><span class="punctuation">.</span><span class="name">message</span><span class="punctuation">().</span><span class="name">c_str</span><span class="punctuation">());</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="keyword">else</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">t</span><span class="punctuation">.</span><span class="name">set_root_cert</span><span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">string</span><span class="punctuation">(</span><span class="operator">&</span><span class="name">pem</span><span class="punctuation">[</span><span class="literal number integer">0</span><span class="punctuation">],</span> <span class="name">pem</span><span class="punctuation">.</span><span class="name">size</span><span class="punctuation">()));</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="comment single">// create the torrent and print it to stdout
|
|
</span> <span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator"><</span><span class="keyword type">char</span><span class="operator">></span> <span class="name">torrent</span><span class="punctuation">;</span>
|
|
<span class="name">bencode</span><span class="punctuation">(</span><span class="name">back_inserter</span><span class="punctuation">(</span><span class="name">torrent</span><span class="punctuation">),</span> <span class="name">t</span><span class="punctuation">.</span><span class="name">generate</span><span class="punctuation">());</span>
|
|
<span class="keyword type">FILE</span><span class="operator">*</span> <span class="name">output</span> <span class="operator">=</span> <span class="name">stdout</span><span class="punctuation">;</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="operator">!</span><span class="name">outfile</span><span class="punctuation">.</span><span class="name">empty</span><span class="punctuation">())</span>
|
|
<span class="name">output</span> <span class="operator">=</span> <span class="name">fopen</span><span class="punctuation">(</span><span class="name">outfile</span><span class="punctuation">.</span><span class="name">c_str</span><span class="punctuation">(),</span> <span class="literal string">"wb+"</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">output</span> <span class="operator">==</span> <span class="name builtin">NULL</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"failed to open file </span><span class="literal string escape">\"</span><span class="literal string">%s</span><span class="literal string escape">\"</span><span class="literal string">: (%d) %s</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="punctuation">,</span> <span class="name">outfile</span><span class="punctuation">.</span><span class="name">c_str</span><span class="punctuation">(),</span> <span class="name">errno</span><span class="punctuation">,</span> <span class="name">strerror</span><span class="punctuation">(</span><span class="name">errno</span><span class="punctuation">));</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="name">fwrite</span><span class="punctuation">(</span><span class="operator">&</span><span class="name">torrent</span><span class="punctuation">[</span><span class="literal number integer">0</span><span class="punctuation">],</span> <span class="literal number integer">1</span><span class="punctuation">,</span> <span class="name">torrent</span><span class="punctuation">.</span><span class="name">size</span><span class="punctuation">(),</span> <span class="name">output</span><span class="punctuation">);</span>
|
|
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">output</span> <span class="operator">!=</span> <span class="name">stdout</span><span class="punctuation">)</span>
|
|
<span class="name">fclose</span><span class="punctuation">(</span><span class="name">output</span><span class="punctuation">);</span>
|
|
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="operator">!</span><span class="name">merklefile</span><span class="punctuation">.</span><span class="name">empty</span><span class="punctuation">())</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">output</span> <span class="operator">=</span> <span class="name">fopen</span><span class="punctuation">(</span><span class="name">merklefile</span><span class="punctuation">.</span><span class="name">c_str</span><span class="punctuation">(),</span> <span class="literal string">"wb+"</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">output</span> <span class="operator">==</span> <span class="name builtin">NULL</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"failed to open file </span><span class="literal string escape">\"</span><span class="literal string">%s</span><span class="literal string escape">\"</span><span class="literal string">: (%d) %s</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="punctuation">,</span> <span class="name">merklefile</span><span class="punctuation">.</span><span class="name">c_str</span><span class="punctuation">(),</span> <span class="name">errno</span><span class="punctuation">,</span> <span class="name">strerror</span><span class="punctuation">(</span><span class="name">errno</span><span class="punctuation">));</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="keyword type">int</span> <span class="name">ret</span> <span class="operator">=</span> <span class="name">fwrite</span><span class="punctuation">(</span><span class="operator">&</span><span class="name">t</span><span class="punctuation">.</span><span class="name">merkle_tree</span><span class="punctuation">()[</span><span class="literal number integer">0</span><span class="punctuation">],</span> <span class="literal number integer">20</span><span class="punctuation">,</span> <span class="name">t</span><span class="punctuation">.</span><span class="name">merkle_tree</span><span class="punctuation">().</span><span class="name">size</span><span class="punctuation">(),</span> <span class="name">output</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">ret</span> <span class="operator">!=</span> <span class="keyword type">int</span><span class="punctuation">(</span><span class="name">t</span><span class="punctuation">.</span><span class="name">merkle_tree</span><span class="punctuation">().</span><span class="name">size</span><span class="punctuation">()))</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"failed to write %s: (%d) %s</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="punctuation">,</span> <span class="name">merklefile</span><span class="punctuation">.</span><span class="name">c_str</span><span class="punctuation">(),</span> <span class="name">errno</span><span class="punctuation">,</span> <span class="name">strerror</span><span class="punctuation">(</span><span class="name">errno</span><span class="punctuation">));</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="name">fclose</span><span class="punctuation">(</span><span class="name">output</span><span class="punctuation">);</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="comment preproc">#ifndef BOOST_NO_EXCEPTIONS
|
|
</span> <span class="punctuation">}</span>
|
|
<span class="keyword">catch</span> <span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">exception</span><span class="operator">&</span> <span class="name">e</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"%s</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">e</span><span class="punctuation">.</span><span class="name">what</span><span class="punctuation">());</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="comment preproc">#endif
|
|
</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">0</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
</pre>
|
|
</div>
|
|
<div class="section" id="dump-torrent">
|
|
<h2>dump_torrent</h2>
|
|
<p>This is an example of a program that will take a torrent-file as a parameter and
|
|
print information about it to std out:</p>
|
|
<pre class="code c++ literal-block">
|
|
<span class="comment preproc">#include "libtorrent/entry.hpp"
|
|
#include "libtorrent/bencode.hpp"
|
|
#include "libtorrent/torrent_info.hpp"
|
|
#include "libtorrent/announce_entry.hpp"
|
|
#include "libtorrent/bdecode.hpp"
|
|
#include "libtorrent/magnet_uri.hpp"
|
|
</span>
|
|
<span class="keyword type">int</span> <span class="name function">load_file</span><span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">string</span> <span class="keyword">const</span><span class="operator">&</span> <span class="name">filename</span><span class="punctuation">,</span> <span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator"><</span><span class="keyword type">char</span><span class="operator">>&</span> <span class="name">v</span>
|
|
<span class="punctuation">,</span> <span class="name">libtorrent</span><span class="operator">::</span><span class="name">error_code</span><span class="operator">&</span> <span class="name">ec</span><span class="punctuation">,</span> <span class="keyword type">int</span> <span class="name">limit</span> <span class="operator">=</span> <span class="literal number integer">8000000</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">ec</span><span class="punctuation">.</span><span class="name">clear</span><span class="punctuation">();</span>
|
|
<span class="keyword type">FILE</span><span class="operator">*</span> <span class="name">f</span> <span class="operator">=</span> <span class="name">fopen</span><span class="punctuation">(</span><span class="name">filename</span><span class="punctuation">.</span><span class="name">c_str</span><span class="punctuation">(),</span> <span class="literal string">"rb"</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">f</span> <span class="operator">==</span> <span class="name builtin">NULL</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">ec</span><span class="punctuation">.</span><span class="name">assign</span><span class="punctuation">(</span><span class="name">errno</span><span class="punctuation">,</span> <span class="name">boost</span><span class="operator">::</span><span class="name">system</span><span class="operator">::</span><span class="name">generic_category</span><span class="punctuation">());</span>
|
|
<span class="keyword">return</span> <span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="keyword type">int</span> <span class="name">r</span> <span class="operator">=</span> <span class="name">fseek</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">,</span> <span class="literal number integer">0</span><span class="punctuation">,</span> <span class="name">SEEK_END</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">r</span> <span class="operator">!=</span> <span class="literal number integer">0</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">ec</span><span class="punctuation">.</span><span class="name">assign</span><span class="punctuation">(</span><span class="name">errno</span><span class="punctuation">,</span> <span class="name">boost</span><span class="operator">::</span><span class="name">system</span><span class="operator">::</span><span class="name">generic_category</span><span class="punctuation">());</span>
|
|
<span class="name">fclose</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="keyword type">long</span> <span class="name">s</span> <span class="operator">=</span> <span class="name">ftell</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">s</span> <span class="operator"><</span> <span class="literal number integer">0</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">ec</span><span class="punctuation">.</span><span class="name">assign</span><span class="punctuation">(</span><span class="name">errno</span><span class="punctuation">,</span> <span class="name">boost</span><span class="operator">::</span><span class="name">system</span><span class="operator">::</span><span class="name">generic_category</span><span class="punctuation">());</span>
|
|
<span class="name">fclose</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">s</span> <span class="operator">></span> <span class="name">limit</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fclose</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="operator">-</span><span class="literal number integer">2</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="name">r</span> <span class="operator">=</span> <span class="name">fseek</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">,</span> <span class="literal number integer">0</span><span class="punctuation">,</span> <span class="name">SEEK_SET</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">r</span> <span class="operator">!=</span> <span class="literal number integer">0</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">ec</span><span class="punctuation">.</span><span class="name">assign</span><span class="punctuation">(</span><span class="name">errno</span><span class="punctuation">,</span> <span class="name">boost</span><span class="operator">::</span><span class="name">system</span><span class="operator">::</span><span class="name">generic_category</span><span class="punctuation">());</span>
|
|
<span class="name">fclose</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="name">v</span><span class="punctuation">.</span><span class="name">resize</span><span class="punctuation">(</span><span class="name">s</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">s</span> <span class="operator">==</span> <span class="literal number integer">0</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fclose</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">0</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="name">r</span> <span class="operator">=</span> <span class="name">fread</span><span class="punctuation">(</span><span class="operator">&</span><span class="name">v</span><span class="punctuation">[</span><span class="literal number integer">0</span><span class="punctuation">],</span> <span class="literal number integer">1</span><span class="punctuation">,</span> <span class="name">v</span><span class="punctuation">.</span><span class="name">size</span><span class="punctuation">(),</span> <span class="name">f</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">r</span> <span class="operator"><</span> <span class="literal number integer">0</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">ec</span><span class="punctuation">.</span><span class="name">assign</span><span class="punctuation">(</span><span class="name">errno</span><span class="punctuation">,</span> <span class="name">boost</span><span class="operator">::</span><span class="name">system</span><span class="operator">::</span><span class="name">generic_category</span><span class="punctuation">());</span>
|
|
<span class="name">fclose</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="name">fclose</span><span class="punctuation">(</span><span class="name">f</span><span class="punctuation">);</span>
|
|
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">r</span> <span class="operator">!=</span> <span class="name">s</span><span class="punctuation">)</span> <span class="keyword">return</span> <span class="operator">-</span><span class="literal number integer">3</span><span class="punctuation">;</span>
|
|
|
|
<span class="keyword">return</span> <span class="literal number integer">0</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="keyword type">int</span> <span class="name function">main</span><span class="punctuation">(</span><span class="keyword type">int</span> <span class="name">argc</span><span class="punctuation">,</span> <span class="keyword type">char</span><span class="operator">*</span> <span class="name">argv</span><span class="punctuation">[])</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="name">libtorrent</span><span class="punctuation">;</span>
|
|
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">argc</span> <span class="operator"><</span> <span class="literal number integer">2</span> <span class="operator">||</span> <span class="name">argc</span> <span class="operator">></span> <span class="literal number integer">4</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fputs</span><span class="punctuation">(</span><span class="literal string">"usage: dump_torrent torrent-file [total-items-limit] [recursion-limit]</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">stderr</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="keyword type">int</span> <span class="name">item_limit</span> <span class="operator">=</span> <span class="literal number integer">1000000</span><span class="punctuation">;</span>
|
|
<span class="keyword type">int</span> <span class="name">depth_limit</span> <span class="operator">=</span> <span class="literal number integer">1000</span><span class="punctuation">;</span>
|
|
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">argc</span> <span class="operator">></span> <span class="literal number integer">2</span><span class="punctuation">)</span> <span class="name">item_limit</span> <span class="operator">=</span> <span class="name">atoi</span><span class="punctuation">(</span><span class="name">argv</span><span class="punctuation">[</span><span class="literal number integer">2</span><span class="punctuation">]);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">argc</span> <span class="operator">></span> <span class="literal number integer">3</span><span class="punctuation">)</span> <span class="name">depth_limit</span> <span class="operator">=</span> <span class="name">atoi</span><span class="punctuation">(</span><span class="name">argv</span><span class="punctuation">[</span><span class="literal number integer">3</span><span class="punctuation">]);</span>
|
|
|
|
<span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator"><</span><span class="keyword type">char</span><span class="operator">></span> <span class="name">buf</span><span class="punctuation">;</span>
|
|
<span class="name">error_code</span> <span class="name">ec</span><span class="punctuation">;</span>
|
|
<span class="keyword type">int</span> <span class="name">ret</span> <span class="operator">=</span> <span class="name">load_file</span><span class="punctuation">(</span><span class="name">argv</span><span class="punctuation">[</span><span class="literal number integer">1</span><span class="punctuation">],</span> <span class="name">buf</span><span class="punctuation">,</span> <span class="name">ec</span><span class="punctuation">,</span> <span class="literal number integer">40</span> <span class="operator">*</span> <span class="literal number integer">1000000</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">ret</span> <span class="operator">==</span> <span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"file too big, aborting</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">ret</span> <span class="operator">!=</span> <span class="literal number integer">0</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"failed to load file: %s</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">ec</span><span class="punctuation">.</span><span class="name">message</span><span class="punctuation">().</span><span class="name">c_str</span><span class="punctuation">());</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="name">bdecode_node</span> <span class="name">e</span><span class="punctuation">;</span>
|
|
<span class="keyword type">int</span> <span class="name">pos</span> <span class="operator">=</span> <span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="name">printf</span><span class="punctuation">(</span><span class="literal string">"decoding. recursion limit: %d total item count limit: %d</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="punctuation">,</span> <span class="name">depth_limit</span><span class="punctuation">,</span> <span class="name">item_limit</span><span class="punctuation">);</span>
|
|
<span class="name">ret</span> <span class="operator">=</span> <span class="name">bdecode</span><span class="punctuation">(</span><span class="operator">&</span><span class="name">buf</span><span class="punctuation">[</span><span class="literal number integer">0</span><span class="punctuation">],</span> <span class="operator">&</span><span class="name">buf</span><span class="punctuation">[</span><span class="literal number integer">0</span><span class="punctuation">]</span> <span class="operator">+</span> <span class="name">buf</span><span class="punctuation">.</span><span class="name">size</span><span class="punctuation">(),</span> <span class="name">e</span><span class="punctuation">,</span> <span class="name">ec</span><span class="punctuation">,</span> <span class="operator">&</span><span class="name">pos</span>
|
|
<span class="punctuation">,</span> <span class="name">depth_limit</span><span class="punctuation">,</span> <span class="name">item_limit</span><span class="punctuation">);</span>
|
|
|
|
<span class="name">printf</span><span class="punctuation">(</span><span class="literal string">"</span><span class="literal string escape">\n\n</span><span class="literal string">----- raw info -----</span><span class="literal string escape">\n\n</span><span class="literal string">%s</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">print_entry</span><span class="punctuation">(</span><span class="name">e</span><span class="punctuation">).</span><span class="name">c_str</span><span class="punctuation">());</span>
|
|
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">ret</span> <span class="operator">!=</span> <span class="literal number integer">0</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"failed to decode: '%s' at character: %d</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">ec</span><span class="punctuation">.</span><span class="name">message</span><span class="punctuation">().</span><span class="name">c_str</span><span class="punctuation">(),</span> <span class="name">pos</span><span class="punctuation">);</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="name">torrent_info</span> <span class="name">t</span><span class="punctuation">(</span><span class="name">e</span><span class="punctuation">,</span> <span class="name">ec</span><span class="punctuation">);</span>
|
|
<span class="keyword">if</span> <span class="punctuation">(</span><span class="name">ec</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">fprintf</span><span class="punctuation">(</span><span class="name">stderr</span><span class="punctuation">,</span> <span class="literal string">"%s</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">ec</span><span class="punctuation">.</span><span class="name">message</span><span class="punctuation">().</span><span class="name">c_str</span><span class="punctuation">());</span>
|
|
<span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="name">e</span><span class="punctuation">.</span><span class="name">clear</span><span class="punctuation">();</span>
|
|
<span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator"><</span><span class="keyword type">char</span><span class="operator">></span><span class="punctuation">().</span><span class="name">swap</span><span class="punctuation">(</span><span class="name">buf</span><span class="punctuation">);</span>
|
|
|
|
<span class="comment single">// print info about torrent
|
|
</span> <span class="name">printf</span><span class="punctuation">(</span><span class="literal string">"</span><span class="literal string escape">\n\n</span><span class="literal string">----- torrent file info -----</span><span class="literal string escape">\n\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"nodes:</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">);</span>
|
|
|
|
<span class="keyword">typedef</span> <span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator"><</span><span class="name">std</span><span class="operator">::</span><span class="name">pair</span><span class="operator"><</span><span class="name">std</span><span class="operator">::</span><span class="name">string</span><span class="punctuation">,</span> <span class="keyword type">int</span><span class="operator">></span> <span class="operator">></span> <span class="name">node_vec</span><span class="punctuation">;</span>
|
|
<span class="name">node_vec</span> <span class="keyword">const</span><span class="operator">&</span> <span class="name">nodes</span> <span class="operator">=</span> <span class="name">t</span><span class="punctuation">.</span><span class="name">nodes</span><span class="punctuation">();</span>
|
|
<span class="keyword">for</span> <span class="punctuation">(</span><span class="name">node_vec</span><span class="operator">::</span><span class="name">const_iterator</span> <span class="name">i</span> <span class="operator">=</span> <span class="name">nodes</span><span class="punctuation">.</span><span class="name">begin</span><span class="punctuation">(),</span> <span class="name">end</span><span class="punctuation">(</span><span class="name">nodes</span><span class="punctuation">.</span><span class="name">end</span><span class="punctuation">());</span>
|
|
<span class="name">i</span> <span class="operator">!=</span> <span class="name">end</span><span class="punctuation">;</span> <span class="operator">++</span><span class="name">i</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">printf</span><span class="punctuation">(</span><span class="literal string">"%s: %d</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">i</span><span class="operator">-></span><span class="name">first</span><span class="punctuation">.</span><span class="name">c_str</span><span class="punctuation">(),</span> <span class="name">i</span><span class="operator">-></span><span class="name">second</span><span class="punctuation">);</span>
|
|
<span class="punctuation">}</span>
|
|
<span class="name">puts</span><span class="punctuation">(</span><span class="literal string">"trackers:</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">);</span>
|
|
<span class="keyword">for</span> <span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">vector</span><span class="operator"><</span><span class="name">announce_entry</span><span class="operator">>::</span><span class="name">const_iterator</span> <span class="name">i</span> <span class="operator">=</span> <span class="name">t</span><span class="punctuation">.</span><span class="name">trackers</span><span class="punctuation">().</span><span class="name">begin</span><span class="punctuation">();</span>
|
|
<span class="name">i</span> <span class="operator">!=</span> <span class="name">t</span><span class="punctuation">.</span><span class="name">trackers</span><span class="punctuation">().</span><span class="name">end</span><span class="punctuation">();</span> <span class="operator">++</span><span class="name">i</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="name">printf</span><span class="punctuation">(</span><span class="literal string">"%2d: %s</span><span class="literal string escape">\n</span><span class="literal string">"</span><span class="punctuation">,</span> <span class="name">i</span><span class="operator">-></span><span class="name">tier</span><span class="punctuation">,</span> <span class="name">i</span><span class="operator">-></span><span class="name">url</span><span class="punctuation">.</span><span class="name">c_str</span><span class="punctuation">());</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="keyword type">char</span> <span class="name">ih</span><span class="punctuation">[</span><span class="literal number integer">41</span><span class="punctuation">];</span>
|
|
<span class="name">to_hex</span><span class="punctuation">((</span><span class="keyword type">char</span> <span class="keyword">const</span><span class="operator">*</span><span class="punctuation">)</span><span class="operator">&</span><span class="name">t</span><span class="punctuation">.</span><span class="name">info_hash</span><span class="punctuation">()[</span><span class="literal number integer">0</span><span class="punctuation">],</span> <span class="literal number integer">20</span><span class="punctuation">,</span> <span class="name">ih</span><span class="punctuation">);</span>
|
|
<span class="name">printf</span><span class="punctuation">(</span><span class="literal string">"number of pieces: %d</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"piece length: %d</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"info hash: %s</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"comment: %s</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"created by: %s</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"magnet link: %s</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"name: %s</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"number of files: %d</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="literal string">"files:</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="punctuation">,</span> <span class="name">t</span><span class="punctuation">.</span><span class="name">num_pieces</span><span class="punctuation">()</span>
|
|
<span class="punctuation">,</span> <span class="name">t</span><span class="punctuation">.</span><span class="name">piece_length</span><span class="punctuation">()</span>
|
|
<span class="punctuation">,</span> <span class="name">ih</span>
|
|
<span class="punctuation">,</span> <span class="name">t</span><span class="punctuation">.</span><span class="name">comment</span><span class="punctuation">().</span><span class="name">c_str</span><span class="punctuation">()</span>
|
|
<span class="punctuation">,</span> <span class="name">t</span><span class="punctuation">.</span><span class="name">creator</span><span class="punctuation">().</span><span class="name">c_str</span><span class="punctuation">()</span>
|
|
<span class="punctuation">,</span> <span class="name">make_magnet_uri</span><span class="punctuation">(</span><span class="name">t</span><span class="punctuation">).</span><span class="name">c_str</span><span class="punctuation">()</span>
|
|
<span class="punctuation">,</span> <span class="name">t</span><span class="punctuation">.</span><span class="name">name</span><span class="punctuation">().</span><span class="name">c_str</span><span class="punctuation">()</span>
|
|
<span class="punctuation">,</span> <span class="name">t</span><span class="punctuation">.</span><span class="name">num_files</span><span class="punctuation">());</span>
|
|
<span class="name">file_storage</span> <span class="keyword">const</span><span class="operator">&</span> <span class="name">st</span> <span class="operator">=</span> <span class="name">t</span><span class="punctuation">.</span><span class="name">files</span><span class="punctuation">();</span>
|
|
<span class="keyword">for</span> <span class="punctuation">(</span><span class="keyword type">int</span> <span class="name">i</span> <span class="operator">=</span> <span class="literal number integer">0</span><span class="punctuation">;</span> <span class="name">i</span> <span class="operator"><</span> <span class="name">st</span><span class="punctuation">.</span><span class="name">num_files</span><span class="punctuation">();</span> <span class="operator">++</span><span class="name">i</span><span class="punctuation">)</span>
|
|
<span class="punctuation">{</span>
|
|
<span class="keyword type">int</span> <span class="name">first</span> <span class="operator">=</span> <span class="name">st</span><span class="punctuation">.</span><span class="name">map_file</span><span class="punctuation">(</span><span class="name">i</span><span class="punctuation">,</span> <span class="literal number integer">0</span><span class="punctuation">,</span> <span class="literal number integer">0</span><span class="punctuation">).</span><span class="name">piece</span><span class="punctuation">;</span>
|
|
<span class="keyword type">int</span> <span class="name">last</span> <span class="operator">=</span> <span class="name">st</span><span class="punctuation">.</span><span class="name">map_file</span><span class="punctuation">(</span><span class="name">i</span><span class="punctuation">,</span> <span class="punctuation">(</span><span class="name">std</span><span class="operator">::</span><span class="name">max</span><span class="punctuation">)(</span><span class="name">boost</span><span class="operator">::</span><span class="keyword type">int64_t</span><span class="punctuation">(</span><span class="name">st</span><span class="punctuation">.</span><span class="name">file_size</span><span class="punctuation">(</span><span class="name">i</span><span class="punctuation">))</span><span class="operator">-</span><span class="literal number integer">1</span><span class="punctuation">,</span> <span class="name">boost</span><span class="operator">::</span><span class="keyword type">int64_t</span><span class="punctuation">(</span><span class="literal number integer">0</span><span class="punctuation">)),</span> <span class="literal number integer">0</span><span class="punctuation">).</span><span class="name">piece</span><span class="punctuation">;</span>
|
|
<span class="keyword type">int</span> <span class="name">flags</span> <span class="operator">=</span> <span class="name">st</span><span class="punctuation">.</span><span class="name">file_flags</span><span class="punctuation">(</span><span class="name">i</span><span class="punctuation">);</span>
|
|
<span class="name">printf</span><span class="punctuation">(</span><span class="literal string">" %8"</span> <span class="name">PRIx64</span> <span class="literal string">" %11"</span> <span class="name">PRId64</span> <span class="literal string">" %c%c%c%c [ %5d, %5d ] %7u %s %s %s%s</span><span class="literal string escape">\n</span><span class="literal string">"</span>
|
|
<span class="punctuation">,</span> <span class="name">st</span><span class="punctuation">.</span><span class="name">file_offset</span><span class="punctuation">(</span><span class="name">i</span><span class="punctuation">)</span>
|
|
<span class="punctuation">,</span> <span class="name">st</span><span class="punctuation">.</span><span class="name">file_size</span><span class="punctuation">(</span><span class="name">i</span><span class="punctuation">)</span>
|
|
<span class="punctuation">,</span> <span class="punctuation">((</span><span class="name">flags</span> <span class="operator">&</span> <span class="name">file_storage</span><span class="operator">::</span><span class="name">flag_pad_file</span><span class="punctuation">)</span><span class="operator">?</span><span class="literal string char">'p'</span><span class="operator">:</span><span class="literal string char">'-'</span><span class="punctuation">)</span>
|
|
<span class="punctuation">,</span> <span class="punctuation">((</span><span class="name">flags</span> <span class="operator">&</span> <span class="name">file_storage</span><span class="operator">::</span><span class="name">flag_executable</span><span class="punctuation">)</span><span class="operator">?</span><span class="literal string char">'x'</span><span class="operator">:</span><span class="literal string char">'-'</span><span class="punctuation">)</span>
|
|
<span class="punctuation">,</span> <span class="punctuation">((</span><span class="name">flags</span> <span class="operator">&</span> <span class="name">file_storage</span><span class="operator">::</span><span class="name">flag_hidden</span><span class="punctuation">)</span><span class="operator">?</span><span class="literal string char">'h'</span><span class="operator">:</span><span class="literal string char">'-'</span><span class="punctuation">)</span>
|
|
<span class="punctuation">,</span> <span class="punctuation">((</span><span class="name">flags</span> <span class="operator">&</span> <span class="name">file_storage</span><span class="operator">::</span><span class="name">flag_symlink</span><span class="punctuation">)</span><span class="operator">?</span><span class="literal string char">'l'</span><span class="operator">:</span><span class="literal string char">'-'</span><span class="punctuation">)</span>
|
|
<span class="punctuation">,</span> <span class="name">first</span><span class="punctuation">,</span> <span class="name">last</span>
|
|
<span class="punctuation">,</span> <span class="name">boost</span><span class="operator">::</span><span class="keyword type">uint32_t</span><span class="punctuation">(</span><span class="name">st</span><span class="punctuation">.</span><span class="name">mtime</span><span class="punctuation">(</span><span class="name">i</span><span class="punctuation">))</span>
|
|
<span class="punctuation">,</span> <span class="name">st</span><span class="punctuation">.</span><span class="name">hash</span><span class="punctuation">(</span><span class="name">i</span><span class="punctuation">)</span> <span class="operator">!=</span> <span class="name">sha1_hash</span><span class="punctuation">(</span><span class="literal number integer">0</span><span class="punctuation">)</span> <span class="operator">?</span> <span class="name">to_hex</span><span class="punctuation">(</span><span class="name">st</span><span class="punctuation">.</span><span class="name">hash</span><span class="punctuation">(</span><span class="name">i</span><span class="punctuation">).</span><span class="name">to_string</span><span class="punctuation">()).</span><span class="name">c_str</span><span class="punctuation">()</span> <span class="operator">:</span> <span class="literal string">""</span>
|
|
<span class="punctuation">,</span> <span class="name">st</span><span class="punctuation">.</span><span class="name">file_path</span><span class="punctuation">(</span><span class="name">i</span><span class="punctuation">).</span><span class="name">c_str</span><span class="punctuation">()</span>
|
|
<span class="punctuation">,</span> <span class="punctuation">(</span><span class="name">flags</span> <span class="operator">&</span> <span class="name">file_storage</span><span class="operator">::</span><span class="name">flag_symlink</span><span class="punctuation">)</span> <span class="operator">?</span> <span class="literal string">"-> "</span> <span class="operator">:</span> <span class="literal string">""</span>
|
|
<span class="punctuation">,</span> <span class="punctuation">(</span><span class="name">flags</span> <span class="operator">&</span> <span class="name">file_storage</span><span class="operator">::</span><span class="name">flag_symlink</span><span class="punctuation">)</span> <span class="operator">?</span> <span class="name">st</span><span class="punctuation">.</span><span class="name">symlink</span><span class="punctuation">(</span><span class="name">i</span><span class="punctuation">).</span><span class="name">c_str</span><span class="punctuation">()</span> <span class="operator">:</span> <span class="literal string">""</span><span class="punctuation">);</span>
|
|
<span class="punctuation">}</span>
|
|
|
|
<span class="keyword">return</span> <span class="literal number integer">0</span><span class="punctuation">;</span>
|
|
<span class="punctuation">}</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<div id="gradient"></div>
|
|
<div id="footer">
|
|
<table>
|
|
<tr>
|
|
<td><a href="index.html">home</a></td>
|
|
<td><a href="http://blog.libtorrent.org">blog</a></td>
|
|
<td><a href="utp.html">uTP</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a href="https://sourceforge.net/projects/libtorrent/files/libtorrent/">download</a></td>
|
|
<td><a href="reference.html">documentation</a></td>
|
|
<td><a href="dht_store.html">DHT put extension</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a href="https://sourceforge.net/projects/libtorrent/files/py-libtorrent/">python bindings</a></td>
|
|
<td><a href="features.html">features</a></td>
|
|
<td><a href="dht_sec.html">DHT security extension</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a href="http://dir.gmane.org/gmane.network.bit-torrent.libtorrent">mailing list archive</a></td>
|
|
<td><a href="contributing.html">contributing</a></td>
|
|
<td><a href="streaming.html">streaming</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td><a href="http://code.google.com/p/libtorrent/issues/entry">report a bug</a></td>
|
|
<td><a href="building.html">building</a></td>
|
|
<td><a href="bittorrent.pdf">bittorrent slides</a></td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div id="filler"></div>
|
|
|
|
</div>
|
|
</body>
|
|
</html>
|