1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 09:13:06 +00:00

a little more cleanup of the rpc server stuff.

This commit is contained in:
Charles Kerr 2008-09-26 04:41:13 +00:00
parent 4907ad1d54
commit 8903960174
5 changed files with 59 additions and 60 deletions

View file

@ -679,7 +679,6 @@ onAddressEdited( GtkCellRendererText * r UNUSED,
GtkTreeIter iter;
struct remote_page * page = gpage;
GtkTreeModel * model = GTK_TREE_MODEL( page->store );
tr_handle * session = tr_core_handle( page->core );
GtkTreePath * path = gtk_tree_path_new_from_string( path_string );
acl = g_strdup_printf( "+%s", new_text );

View file

@ -39,8 +39,7 @@ struct tr_rpc_server
{
unsigned int isEnabled : 1;
unsigned int isPasswordEnabled : 1;
int port;
time_t lastRequestTime;
uint16_t port;
struct evhttp * httpd;
tr_handle * session;
char * username;
@ -105,7 +104,9 @@ send_simple_response( struct evhttp_request * req, int code, const char * text )
{
const char * code_text = tr_webGetResponseStr( code );
struct evbuffer * body = evbuffer_new( );
evbuffer_add_printf( body, "<h1>%s</h1>", text ? text : code_text );
evbuffer_add_printf( body, "<h1>%s</h1>", code_text );
if( text )
evbuffer_add_printf( body, "<h2>%s</h2>", text );
evhttp_send_reply( req, code, code_text, body );
evbuffer_free( body );
}
@ -128,63 +129,62 @@ handle_upload( struct evhttp_request * req, struct tr_rpc_server * server )
const char * in = (const char *) EVBUFFER_DATA( req->input_buffer );
size_t inlen = EVBUFFER_LENGTH( req->input_buffer );
char * boundary =
tr_strdup_printf( "--%s", strstr( content_type,
"boundary=" ) +
strlen( "boundary=" ) );
const char * boundary_key = "boundary=";
const char * boundary_key_begin = strstr( content_type, boundary_key );
const char * boundary_val = boundary_key_begin ? boundary_key_begin + strlen( boundary_key ) : "arglebargle";
char * boundary = tr_strdup_printf( "--%s", boundary_val );
const size_t boundary_len = strlen( boundary );
const char * delim = tr_memmem( in, inlen, boundary, boundary_len );
while( delim )
{
size_t part_len;
const char * part = delim + boundary_len;
inlen -= ( part - in );
in = part;
delim = tr_memmem( in, inlen, boundary, boundary_len );
part_len = delim ? (size_t)( delim - part ) : inlen;
if( part_len )
{
size_t part_len;
const char * part = delim + boundary_len;
inlen -= ( part - in );
in = part;
delim = tr_memmem( in, inlen, boundary, boundary_len );
part_len = delim ? (size_t)( delim - part ) : inlen;
if( part_len )
char * text = tr_strndup( part, part_len );
if( strstr( text, "filename=\"" ) )
{
char * text = tr_strndup( part, part_len );
if( strstr( text, "filename=\"" ) )
const char * body = strstr( text, "\r\n\r\n" );
if( body )
{
const char * body = strstr( text, "\r\n\r\n" );
if( body )
{
char * b64, *json, *freeme;
int json_len;
size_t body_len;
tr_benc top, *args;
char * b64, *json, *freeme;
int json_len;
size_t body_len;
tr_benc top, *args;
body += 4;
body_len = part_len - ( body - text );
if( body_len >= 2
body += 4;
body_len = part_len - ( body - text );
if( body_len >= 2
&& !memcmp( &body[body_len - 2], "\r\n", 2 ) )
body_len -= 2;
tr_bencInitDict( &top, 2 );
args = tr_bencDictAddDict( &top, "arguments", 2 );
tr_bencDictAddStr( &top, "method",
"torrent-add" );
b64 = tr_base64_encode( body, body_len, NULL );
tr_bencDictAddStr( args, "metainfo", b64 );
tr_bencDictAddInt( args, "paused", paused );
json = tr_bencSaveAsJSON( &top, &json_len );
freeme =
tr_rpc_request_exec_json( server->session,
json, json_len,
NULL );
tr_bencInitDict( &top, 2 );
args = tr_bencDictAddDict( &top, "arguments", 2 );
tr_bencDictAddStr( &top, "method", "torrent-add" );
b64 = tr_base64_encode( body, body_len, NULL );
tr_bencDictAddStr( args, "metainfo", b64 );
tr_bencDictAddInt( args, "paused", paused );
json = tr_bencSaveAsJSON( &top, &json_len );
freeme = tr_rpc_request_exec_json( server->session,
json, json_len,
NULL );
tr_free( freeme );
tr_free( json );
tr_free( b64 );
tr_bencFree( &top );
}
tr_free( freeme );
tr_free( json );
tr_free( b64 );
tr_bencFree( &top );
}
tr_free( text );
}
tr_free( text );
}
}
tr_free( boundary );
@ -378,7 +378,7 @@ startServer( tr_rpc_server * server )
dbgmsg( "in startServer; current context is %p", server->httpd );
if( !server->httpd )
if( ( server->httpd = evhttp_start( "0.0.0.0", server->port ) ) )
if( ( server->httpd = evhttp_start( NULL, server->port ) ) )
evhttp_set_gencb( server->httpd, handle_request, server );
}
@ -412,7 +412,7 @@ tr_rpcIsEnabled( const tr_rpc_server * server )
void
tr_rpcSetPort( tr_rpc_server * server,
int port )
uint16_t port )
{
if( server->port != port )
{
@ -426,7 +426,7 @@ tr_rpcSetPort( tr_rpc_server * server,
}
}
int
uint16_t
tr_rpcGetPort( const tr_rpc_server * server )
{
return server->port;
@ -515,7 +515,7 @@ tr_rpcClose( tr_rpc_server ** ps )
tr_rpc_server *
tr_rpcInit( tr_handle * session,
int isEnabled,
int port,
uint16_t port,
const char * acl,
int isPasswordEnabled,
const char * username,

View file

@ -17,7 +17,7 @@ typedef struct tr_rpc_server tr_rpc_server;
tr_rpc_server * tr_rpcInit( struct tr_handle * session,
int isEnabled,
int port,
uint16_t port,
const char * acl,
int isPasswordEnabled,
const char * username,
@ -31,9 +31,9 @@ void tr_rpcSetEnabled( tr_rpc_server * server,
int tr_rpcIsEnabled( const tr_rpc_server * server );
void tr_rpcSetPort( tr_rpc_server * server,
int port );
uint16_t port );
int tr_rpcGetPort( const tr_rpc_server * server );
uint16_t tr_rpcGetPort( const tr_rpc_server * server );
int tr_rpcSetTest( const tr_rpc_server * server,
const char * acl,

View file

@ -215,7 +215,7 @@ tr_sessionInitFull( const char * configDir,
int isBlocklistEnabled,
int peerSocketTOS,
int rpcIsEnabled,
int rpcPort,
uint16_t rpcPort,
const char * rpcACL,
int rpcAuthIsEnabled,
const char * rpcUsername,
@ -982,12 +982,12 @@ tr_sessionIsRPCEnabled( const tr_session * session )
void
tr_sessionSetRPCPort( tr_session * session,
int port )
uint16_t port )
{
tr_rpcSetPort( session->rpcServer, port );
}
int
uint16_t
tr_sessionGetRPCPort( const tr_session * session )
{
return tr_rpcGetPort( session->rpcServer );

View file

@ -266,7 +266,7 @@ tr_handle * tr_sessionInitFull( const char * configDir,
int isBlocklistEnabled,
int peerSocketTOS,
int rpcIsEnabled,
int rpcPort,
uint16_t rpcPort,
const char * rpcAccessControlList,
int rpcPasswordIsEnabled,
const char * rpcUsername,
@ -337,13 +337,13 @@ int tr_sessionIsRPCEnabled( const tr_handle * handle );
/** @brief Specify which port to listen for RPC requests on.
@see tr_sessionInitFull()
@see tr_sessionGetRPCPort */
void tr_sessionSetRPCPort( tr_handle *,
int port );
void tr_sessionSetRPCPort( tr_handle * session,
uint16_t port );
/** @brief Get which port to listen for RPC requests on.
@see tr_sessionInitFull()
@see tr_sessionSetRPCPort */
int tr_sessionGetRPCPort( const tr_handle * );
uint16_t tr_sessionGetRPCPort( const tr_handle * );
/**
* @brief Specify access control list (ACL).