Ignore:
Timestamp:
2012-11-10T23:52:21Z (8 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
dff0e0b
Parents:
8bd866f
Message:

Very immature code for reading from the streaming API. It reads from a
fixed URL and tried to parse individual JSON objects. Not doing anything
useful with it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter_http.c

    r8bd866f rddc2de5  
    4747 * This is actually pretty generic function... Perhaps it should move to the lib/http_client.c
    4848 */
    49 void *twitter_http(struct im_connection *ic, char *url_string, http_input_function func,
    50                    gpointer data, int is_post, char **arguments, int arguments_len)
     49struct http_request *twitter_http(struct im_connection *ic, char *url_string, http_input_function func,
     50                                  gpointer data, int is_post, char **arguments, int arguments_len)
    5151{
    5252        struct twitter_data *td = ic->proto_data;
     
    5555        void *ret;
    5656        char *url_arguments;
     57        url_t *base_url = NULL;
    5758
    5859        url_arguments = g_strdup("");
     
    6768                }
    6869        }
     70       
     71        if (strstr(url_string, "://")) {
     72                base_url = g_new0(url_t, 1);
     73                if (!url_set(base_url, url_string)) {
     74                        g_free(base_url);
     75                        return NULL;
     76                }
     77        }
     78       
    6979        // Make the request.
    7080        g_string_printf(request, "%s %s%s%s%s HTTP/1.0\r\n"
     
    7282                        "User-Agent: BitlBee " BITLBEE_VERSION " " ARCH "/" CPU "\r\n",
    7383                        is_post ? "POST" : "GET",
    74                         td->url_path, url_string,
    75                         is_post ? "" : "?", is_post ? "" : url_arguments, td->url_host);
     84                        base_url ? base_url->file : td->url_path,
     85                        base_url ? "" : url_string,
     86                        is_post ? "" : "?", is_post ? "" : url_arguments,
     87                        base_url ? base_url->host : td->url_host);
    7688
    7789        // If a pass and user are given we append them to the request.
     
    8092                char *full_url;
    8193
    82                 full_url = g_strconcat(set_getstr(&ic->acc->set, "base_url"), url_string, NULL);
     94                if (base_url)
     95                        full_url = g_strdup(url_string);
     96                else
     97                        full_url = g_strconcat(set_getstr(&ic->acc->set, "base_url"), url_string, NULL);
    8398                full_header = oauth_http_header(td->oauth_info, is_post ? "POST" : "GET",
    8499                                                full_url, url_arguments);
     
    109124        }
    110125
    111         ret = http_dorequest(td->url_host, td->url_port, td->url_ssl, request->str, func, data);
     126        if (base_url)
     127                ret = http_dorequest(base_url->host, base_url->port, base_url->proto == PROTO_HTTPS, request->str, func, data);
     128        else
     129                ret = http_dorequest(td->url_host, td->url_port, td->url_ssl, request->str, func, data);
    112130
    113131        g_free(url_arguments);
    114132        g_string_free(request, TRUE);
     133        g_free(base_url);
    115134        return ret;
    116135}
Note: See TracChangeset for help on using the changeset viewer.