Changeset cc6fdf8 for lib/http_client.h


Ignore:
Timestamp:
2012-12-22T00:14:26Z (11 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
7d5afa6
Parents:
92d3044 (diff), 573e274 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merging JSON branch. It's very stable by now, and I want more testers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/http_client.h

    r92d3044 rcc6fdf8  
    2626/* http_client allows you to talk (asynchronously, again) to HTTP servers.
    2727   In the "background" it will send the whole query and wait for a complete
    28    response to come back. Right now it's only used by the MSN Passport
    29    authentication code, but it might be useful for other things too (for
    30    example the AIM usericon patch uses this so icons can be stored on
    31    webservers instead of the local filesystem).
     28   response to come back. Initially written for MS Passport authentication,
     29   but used for many other things now like OAuth and Twitter.
    3230   
    33    Didn't test this too much, but it seems to work well. Just don't look
    34    at the code that handles HTTP 30x redirects. ;-) The function is
    35    probably not very useful for downloading lots of data since it keeps
    36    everything in a memory buffer until the download is completed (and
    37    can't pass any data or whatever before then). It's very useful for
    38    doing quick requests without blocking the whole program, though. */
     31   It's very useful for doing quick requests without blocking the whole
     32   program. Unfortunately it doesn't support fancy stuff like HTTP keep-
     33   alives. */
    3934
    4035#include <glib.h>
     
    4237
    4338struct http_request;
     39
     40typedef enum http_client_flags
     41{
     42        HTTPC_STREAMING = 1,
     43        HTTPC_EOF = 2,
     44       
     45        /* Let's reserve 0x1000000+ for lib users. */
     46} http_client_flags_t;
    4447
    4548/* Your callback function should look like this: */
     
    5356        char *request;          /* The request to send to the server. */
    5457        int request_length;     /* Its size. */
    55         int status_code;        /* The numeric HTTP status code. (Or -1
     58        short status_code;      /* The numeric HTTP status code. (Or -1
    5659                                   if something really went wrong) */
    5760        char *status_string;    /* The error text. */
     
    5962        char *reply_body;
    6063        int body_size;          /* The number of bytes in reply_body. */
    61         /* int finished;           Set to non-0 if the request was completed
    62                                    successfully. */
    63         int redir_ttl;          /* You can set it to 0 if you don't want
     64        short redir_ttl;        /* You can set it to 0 if you don't want
    6465                                   http_client to follow them. */
     66       
     67        http_client_flags_t flags;
    6568       
    6669        http_input_function func;
     
    6871       
    6972        /* Please don't touch the things down here, you shouldn't need them. */
    70        
    7173        void *ssl;
    7274        int fd;
     
    7577        int bytes_written;
    7678        int bytes_read;
     79       
     80        /* Used in streaming mode. Caller should read from reply_body. */
     81        char *sbuf;
     82        size_t sblen;
    7783};
    7884
     
    8389struct http_request *http_dorequest( char *host, int port, int ssl, char *request, http_input_function func, gpointer data );
    8490struct http_request *http_dorequest_url( char *url_string, http_input_function func, gpointer data );
     91
     92/* For streaming connections only; flushes len bytes at the start of the buffer. */
     93void http_flush_bytes( struct http_request *req, size_t len );
     94void http_close( struct http_request *req );
Note: See TracChangeset for help on using the changeset viewer.