diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2012-09-22 13:47:55 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2012-09-22 13:47:55 +0100 |
commit | 9c77fbf0850c364c31f80e30c54137252291ec91 (patch) | |
tree | dad13ba8f43346dfbb5785580e730d92ca16c367 | |
parent | c6fc24a81fa14cea4b3f497bbbb0e6e65a3cc6d4 (diff) | |
parent | 11ec07811cc41e1b244467d25772ef021be9db1b (diff) |
Merge mainline.
-rw-r--r-- | lib/http_client.c | 19 | ||||
-rw-r--r-- | lib/http_client.h | 2 | ||||
-rw-r--r-- | lib/misc.c | 4 | ||||
-rw-r--r-- | lib/misc.h | 2 | ||||
-rw-r--r-- | lib/xmltree.c | 7 | ||||
-rw-r--r-- | lib/xmltree.h | 2 | ||||
-rw-r--r-- | protocols/msn/ns.c | 4 | ||||
-rw-r--r-- | protocols/msn/soap.c | 2 | ||||
-rw-r--r-- | protocols/twitter/twitter_lib.c | 61 |
9 files changed, 57 insertions, 46 deletions
diff --git a/lib/http_client.c b/lib/http_client.c index 98a99f7c..7ed539d0 100644 --- a/lib/http_client.c +++ b/lib/http_client.c @@ -72,7 +72,7 @@ struct http_request *http_dorequest( char *host, int port, int ssl, char *reques if( getenv( "BITLBEE_DEBUG" ) ) printf( "About to send HTTP request:\n%s\n", req->request ); - return( req ); + return req; } struct http_request *http_dorequest_url( char *url_string, http_input_function func, gpointer data ) @@ -197,7 +197,8 @@ static gboolean http_incoming_data( gpointer data, int source, b_input_condition struct http_request *req = data; int evil_server = 0; char buffer[2048]; - char *end1, *end2; + char *end1, *end2, *s; + size_t content_length; int st; if( req->inpa > 0 ) @@ -480,7 +481,7 @@ got_reply: /* Assume that a closed connection means we're finished, this indeed breaks with keep-alive connections and faulty connections. */ - req->finished = 1; + /* req->finished = 1; */ cleanup: if( req->ssl ) @@ -488,6 +489,18 @@ cleanup: else closesocket( req->fd ); + if( ( s = get_rfc822_header( req->reply_headers, "Content-Length", 0 ) ) && + sscanf( s, "%zd", &content_length ) == 1 ) + { + if( content_length < req->body_size ) + { + req->status_code = -1; + g_free( req->status_string ); + req->status_string = g_strdup( "Response truncated" ); + } + } + g_free( s ); + if( getenv( "BITLBEE_DEBUG" ) && req ) printf( "Finishing HTTP request with status: %s\n", req->status_string ? req->status_string : "NULL" ); diff --git a/lib/http_client.h b/lib/http_client.h index 27c484ff..623f17a0 100644 --- a/lib/http_client.h +++ b/lib/http_client.h @@ -58,7 +58,7 @@ struct http_request char *reply_headers; char *reply_body; int body_size; /* The number of bytes in reply_body. */ - int finished; /* Set to non-0 if the request was completed + /* int finished; Set to non-0 if the request was completed successfully. */ int redir_ttl; /* You can set it to 0 if you don't want http_client to follow them. */ @@ -729,10 +729,10 @@ char **split_command_parts( char *command ) return cmd; } -char *get_rfc822_header( char *text, char *header, int len ) +char *get_rfc822_header( const char *text, const char *header, int len ) { int hlen = strlen( header ), i; - char *ret; + const char *ret; if( text == NULL ) return NULL; @@ -67,6 +67,6 @@ G_MODULE_EXPORT char *word_wrap( const char *msg, int line_len ); G_MODULE_EXPORT gboolean ssl_sockerr_again( void *ssl ); G_MODULE_EXPORT int md5_verify_password( char *password, char *hash ); G_MODULE_EXPORT char **split_command_parts( char *command ); -G_MODULE_EXPORT char *get_rfc822_header( char *text, char *header, int len ); +G_MODULE_EXPORT char *get_rfc822_header( const char *text, const char *header, int len ); #endif diff --git a/lib/xmltree.c b/lib/xmltree.c index 74292be9..91d256d2 100644 --- a/lib/xmltree.c +++ b/lib/xmltree.c @@ -262,13 +262,16 @@ void xt_cleanup( struct xt_parser *xt, struct xt_node *node, int depth ) } } -struct xt_node *xt_from_string( const char *in ) +struct xt_node *xt_from_string( const char *in, int len ) { struct xt_parser *parser; struct xt_node *ret; + if( len == 0 ) + len = strlen( in ); + parser = xt_new( NULL, NULL ); - xt_feed( parser, in, strlen( in ) ); + xt_feed( parser, in, len ); ret = parser->root; parser->root = NULL; xt_free( parser ); diff --git a/lib/xmltree.h b/lib/xmltree.h index 5a0dbc8e..ac77fada 100644 --- a/lib/xmltree.h +++ b/lib/xmltree.h @@ -81,7 +81,7 @@ void xt_reset( struct xt_parser *xt ); int xt_feed( struct xt_parser *xt, const char *text, int text_len ); int xt_handle( struct xt_parser *xt, struct xt_node *node, int depth ); void xt_cleanup( struct xt_parser *xt, struct xt_node *node, int depth ); -struct xt_node *xt_from_string( const char *in ); +struct xt_node *xt_from_string( const char *in, int text_len ); char *xt_to_string( struct xt_node *node ); void xt_print( struct xt_node *node ); struct xt_node *xt_dup( struct xt_node *node ); diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index a4785eb2..f2fc561f 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -739,7 +739,7 @@ static int msn_ns_message( struct msn_handler_data *handler, char *msg, int msgl struct xt_node *ubx, *psm; char *psm_text = NULL; - ubx = xt_from_string( msg ); + ubx = xt_from_string( msg, msglen ); if( ubx && strcmp( ubx->name, "Data" ) == 0 && ( psm = xt_find_node( ubx->children, "PSM" ) ) ) psm_text = psm->text; @@ -751,7 +751,7 @@ static int msn_ns_message( struct msn_handler_data *handler, char *msg, int msgl { struct xt_node *adl, *d, *c; - if( !( adl = xt_from_string( msg ) ) ) + if( !( adl = xt_from_string( msg, msglen ) ) ) return 1; for( d = adl->children; d; d = d->next ) diff --git a/protocols/msn/soap.c b/protocols/msn/soap.c index da32c291..50de22eb 100644 --- a/protocols/msn/soap.c +++ b/protocols/msn/soap.c @@ -228,7 +228,7 @@ static void msn_soap_debug_print( const char *headers, const char *payload ) if( payload ) { - struct xt_node *xt = xt_from_string( payload ); + struct xt_node *xt = xt_from_string( payload, 0 ); if( xt ) xt_print( xt ); xt_free_node( xt ); diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index f1483035..8e2804a5 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -167,23 +167,21 @@ static void twitter_add_buddy(struct im_connection *ic, char *name, const char * char *twitter_parse_error(struct http_request *req) { static char *ret = NULL; - struct xt_parser *xp = NULL; - struct xt_node *node, *err; + struct xt_node *root, *node, *err; g_free(ret); ret = NULL; if (req->body_size > 0) { - xp = xt_new(NULL, NULL); - xt_feed(xp, req->reply_body, req->body_size); + root = xt_from_string(req->reply_body, req->body_size); - for (node = xp->root; node; node = node->next) + for (node = root; node; node = node->next) if ((err = xt_find_node(node->children, "error")) && err->text_len > 0) { ret = g_strdup_printf("%s (%s)", req->status_string, err->text); break; } - xt_free(xp); + xt_free_node(root); } return ret ? ret : req->status_string; @@ -255,7 +253,7 @@ static void twitter_get_users_lookup(struct im_connection *ic); static void twitter_http_get_friends_ids(struct http_request *req) { struct im_connection *ic; - struct xt_parser *parser; + struct xt_node *parsed; struct twitter_xml_list *txl; struct twitter_data *td; @@ -291,10 +289,9 @@ static void twitter_http_get_friends_ids(struct http_request *req) txl->list = td->follow_ids; // Parse the data. - parser = xt_new(NULL, txl); - xt_feed(parser, req->reply_body, req->body_size); - twitter_xt_get_friends_id_list(parser->root, txl); - xt_free(parser); + parsed = xt_from_string(req->reply_body, req->body_size); + twitter_xt_get_friends_id_list(parsed, txl); + xt_free_node(parsed); td->follow_ids = txl->list; if (txl->next_cursor) @@ -351,7 +348,7 @@ static void twitter_http_get_users_lookup(struct http_request *req) { struct im_connection *ic = req->data; struct twitter_data *td; - struct xt_parser *parser; + struct xt_node *parsed; struct twitter_xml_list *txl; GSList *l = NULL; struct twitter_xml_user *user; @@ -376,12 +373,11 @@ static void twitter_http_get_users_lookup(struct http_request *req) txl->list = NULL; // Parse the data. - parser = xt_new(NULL, txl); - xt_feed(parser, req->reply_body, req->body_size); + parsed = xt_from_string(req->reply_body, req->body_size); // Get the user list from the parsed xml feed. - twitter_xt_get_users(parser->root, txl); - xt_free(parser); + twitter_xt_get_users(parsed, txl); + xt_free_node(parsed); // Add the users as buddies. for (l = txl->list; l; l = g_slist_next(l)) { @@ -738,7 +734,10 @@ void twitter_get_timeline(struct im_connection *ic, gint64 next_cursor) gboolean include_mentions = set_getbool(&ic->acc->set, "fetch_mentions"); if (td->flags & TWITTER_DOING_TIMELINE) { - return; + if (++td->http_fails >= 5) { + imcb_error(ic, "Fetch timeout (%d)", td->flags); + imc_logout(ic, TRUE); + } } td->flags |= TWITTER_DOING_TIMELINE; @@ -885,7 +884,7 @@ static void twitter_http_get_home_timeline(struct http_request *req) { struct im_connection *ic = req->data; struct twitter_data *td; - struct xt_parser *parser; + struct xt_node *parsed; struct twitter_xml_list *txl; // Check if the connection is still active. @@ -912,11 +911,10 @@ static void twitter_http_get_home_timeline(struct http_request *req) txl->list = NULL; // Parse the data. - parser = xt_new(NULL, txl); - xt_feed(parser, req->reply_body, req->body_size); + parsed = xt_from_string(req->reply_body, req->body_size); // The root <statuses> node should hold the list of statuses <status> - twitter_xt_get_status_list(ic, parser->root, txl); - xt_free(parser); + twitter_xt_get_status_list(ic, parsed, txl); + xt_free_node(parsed); td->home_timeline_obj = txl; @@ -933,7 +931,7 @@ static void twitter_http_get_mentions(struct http_request *req) { struct im_connection *ic = req->data; struct twitter_data *td; - struct xt_parser *parser; + struct xt_node *parsed; struct twitter_xml_list *txl; // Check if the connection is still active. @@ -960,11 +958,10 @@ static void twitter_http_get_mentions(struct http_request *req) txl->list = NULL; // Parse the data. - parser = xt_new(NULL, txl); - xt_feed(parser, req->reply_body, req->body_size); + parsed = xt_from_string(req->reply_body, req->body_size); // The root <statuses> node should hold the list of statuses <status> - twitter_xt_get_status_list(ic, parser->root, txl); - xt_free(parser); + twitter_xt_get_status_list(ic, parsed, txl); + xt_free_node(parsed); td->mentions_obj = txl; @@ -998,17 +995,15 @@ static void twitter_http_post(struct http_request *req) } if (req->body_size > 0) { - struct xt_parser *xp = NULL; - struct xt_node *node; + struct xt_node *parsed, *node; - xp = xt_new(NULL, NULL); - xt_feed(xp, req->reply_body, req->body_size); + parsed = xt_from_string(req->reply_body, req->body_size); - if ((node = xt_find_node(xp->root, "status")) && + if ((node = xt_find_node(parsed, "status")) && (node = xt_find_node(node->children, "id")) && node->text) td->last_status_id = g_ascii_strtoull(node->text, NULL, 10); - xt_free(xp); + xt_free_node(parsed); } } |