Beispiel #1
0
size_t writebts( void *buf, size_t size, size_t nmemb, void* stream ) {
    btStream *bts=stream;
    int len=size*nmemb;
    if (bts_write(bts, buf, len) != 0) {
	return 0;
    }
    return len;
}
Beispiel #2
0
int bts_printf( btStream* bts, char *fmt, ...) {
    static char buf[8192];
    int res;
    int osize;
    va_list va;
    va_start(va, fmt);
    osize=vsnprintf(buf, sizeof(buf), fmt, va);
    DIE_UNLESS(osize < sizeof(buf));
    res = bts_write( bts, buf, osize);
    va_end(va);
    return res;
}
Beispiel #3
0
void CTorrent::init( const void* data, size_t size ) {
       int res;
       int optseed = 0;
       char* optignore = NULL;
       m_pMetaData = data;
       m_nMetaSize = size;
       btStream *io;
       io = bts_create_strstream( BTS_OUTPUT );
       bt_assert( io );
       res = bts_write( io, (char*)data, size );
       bt_assert( res == 0 );
       res = ctx_loadfile( io, &m_Context, (char*)m_szDownloadDir, optseed, optignore);
       bts_destroy( io );
       if (res < 0) {
            notify("Bad torrent");
            return;
       }
       m_nState = STATE_STOPPED;
       notify("Torrent loaded");
}
Beispiel #4
0
/**	\brief	The benc_put_string function serializes a btString to
                the stream 'bts' in BEncoded format.

	\param	bts	a parameter of type struct btStream*
	\param	s	a parameter of type btString *

	\return	int	0 - sucess, 1 - error


*/
int benc_put_string( struct btStream* bts, btString *s) {
    int res;
    res = bts_printf(bts, "%d:", btString_len(s));
    res |= bts_write( bts, btString_buf(s), btString_len(s));
    return res;
}