source: lib/http_client.h @ b38d399

Last change on this file since b38d399 was ca8037e, checked in by Wilmer van der Gaast <wilmer@…>, at 2013-06-09T21:17:45Z

Add better handling of HTTP/1.1 and/or keepalive connections. This should
let me close #641, and more importantly, prepares the Twitter module for
an upcoming API change. https://dev.twitter.com/blog/deprecating-http-1.0-streaming-api

  • Property mode set to 100644
File size: 3.8 KB
Line 
1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2002-2012 Wilmer van der Gaast and others                *
5  \********************************************************************/
6
7/* HTTP(S) module                                                       */
8
9/*
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License with
21  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
22  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23  Suite 330, Boston, MA  02111-1307  USA
24*/
25
26/* http_client allows you to talk (asynchronously, again) to HTTP servers.
27   In the "background" it will send the whole query and wait for a complete
28   response to come back. Initially written for MS Passport authentication,
29   but used for many other things now like OAuth and Twitter.
30   
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. */
34
35#include <glib.h>
36#include "ssl_client.h"
37
38struct http_request;
39
40typedef enum http_client_flags
41{
42        HTTPC_STREAMING = 1,
43        HTTPC_EOF = 2,
44        HTTPC_CHUNKED = 4,
45       
46        /* Let's reserve 0x1000000+ for lib users. */
47} http_client_flags_t;
48
49/* Your callback function should look like this: */
50typedef void (*http_input_function)( struct http_request * );
51
52/* This structure will be filled in by the http_dorequest* functions, and
53   it will be passed to the callback function. Use the data field to add
54   your own data. */
55struct http_request
56{
57        char *request;          /* The request to send to the server. */
58        int request_length;     /* Its size. */
59        short status_code;      /* The numeric HTTP status code. (Or -1
60                                   if something really went wrong) */
61        char *status_string;    /* The error text. */
62        char *reply_headers;
63        char *reply_body;
64        int body_size;          /* The number of bytes in reply_body. */
65        short redir_ttl;        /* You can set it to 0 if you don't want
66                                   http_client to follow them. */
67       
68        http_client_flags_t flags;
69       
70        http_input_function func;
71        gpointer data;
72       
73        /* Please don't touch the things down here, you shouldn't need them. */
74        void *ssl;
75        int fd;
76       
77        int inpa;
78        int bytes_written;
79        int bytes_read;
80        int content_length;     /* "Content-Length:" header or -1 */
81       
82        /* Used in streaming mode. Caller should read from reply_body. */
83        char *sbuf;
84        size_t sblen;
85       
86        /* Chunked encoding only. Raw chunked stream is decoded from here. */
87        char *cbuf;
88        size_t cblen;
89};
90
91/* The _url variant is probably more useful than the raw version. The raw
92   version is probably only useful if you want to do POST requests or if
93   you want to add some extra headers. As you can see, HTTPS connections
94   are also supported (using ssl_client). */
95struct http_request *http_dorequest( char *host, int port, int ssl, char *request, http_input_function func, gpointer data );
96struct http_request *http_dorequest_url( char *url_string, http_input_function func, gpointer data );
97
98/* For streaming connections only; flushes len bytes at the start of the buffer. */
99void http_flush_bytes( struct http_request *req, size_t len );
100void http_close( struct http_request *req );
Note: See TracBrowser for help on using the repository browser.