char ipv6_readable[INET6_ADDRSTRLEN];
inet_ntop( AF_INET6, ipv6, ipv6_readable, INET6_ADDRSTRLEN );
evbuffer_add_printf( buf, "&ipv6=");
- tr_http_escape( buf, ipv6_readable, strlen(ipv6_readable), 0 );
+ tr_http_escape( buf, ipv6_readable, strlen(ipv6_readable), TRUE );
}
ret = tr_strndup( EVBUFFER_DATA( buf ), EVBUFFER_LENGTH( buf ) );
}
/* escapes a string to be URI-legal as per RFC 2396.
- like curl_escape() but can optionally avoid munging slashes. */
+ like curl_escape() but can optionally avoid escaping slashes. */
void
-tr_http_escape( struct evbuffer *out, const char *str, int len, int keep_slashes )
+tr_http_escape( struct evbuffer * out,
+ const char * str,
+ int len,
+ tr_bool escape_slashes )
{
int i;
+ if( ( len < 0 ) && ( str != NULL ) )
+ len = strlen( str );
+
for( i = 0; i < len; i++ ) {
switch( str[i] ) {
case ',': case '-': case '.':
evbuffer_add( out, &str[i], 1 );
break;
case '/':
- if(keep_slashes) {
+ if(!escape_slashes) {
evbuffer_add( out, &str[i], 1 );
break;
}
struct evbuffer;
-void tr_http_escape( struct evbuffer *out, const char *str, int len, int noslashes );
+void tr_http_escape( struct evbuffer *out, const char *str, int len, tr_bool escape_slashes );
char* tr_http_unescape( const char * str, int len );
/* if url ends with a '/', add the torrent name */
if( url[url_len - 1] == '/' && file->name )
- tr_http_escape( out, file->name, strlen(file->name), 1 );
+ tr_http_escape( out, file->name, strlen(file->name), FALSE );
ret = tr_strndup( EVBUFFER_DATA( out ), EVBUFFER_LENGTH( out ) );
evbuffer_free( out );