source: lib/http_client.h @ 098b430

Last change on this file since 098b430 was 5ebff60, checked in by dequis <dx@…>, at 2015-02-20T22:50:54Z

Reindent everything to K&R style with tabs

Used uncrustify, with the configuration file in ./doc/uncrustify.cfg

Commit author set to "Indent <please@…>" so that it's easier to
skip while doing git blame.

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[5ebff60]1/********************************************************************\
[8a9afe4]2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
[0e788f5]4  * Copyright 2002-2012 Wilmer van der Gaast and others                *
[8a9afe4]5  \********************************************************************/
6
[7c0a497]7/* HTTP(S) module                                                       */
[8a9afe4]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;
[6f10697]22  if not, write to the Free Software Foundation, Inc., 51 Franklin St.,
23  Fifth Floor, Boston, MA  02110-1301  USA
[8a9afe4]24*/
25
[0aaca60]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
[8bd866f]28   response to come back. Initially written for MS Passport authentication,
29   but used for many other things now like OAuth and Twitter.
[5ebff60]30
[8bd866f]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. */
[8a9afe4]34
[0aaca60]35#include <glib.h>
[8a9afe4]36#include "ssl_client.h"
37
38struct http_request;
39
[5ebff60]40typedef enum http_client_flags {
[8bd866f]41        HTTPC_STREAMING = 1,
[dd672e2]42        HTTPC_EOF = 2,
[ca8037e]43        HTTPC_CHUNKED = 4,
[5ebff60]44
[b235228]45        /* Let's reserve 0x1000000+ for lib users. */
[8bd866f]46} http_client_flags_t;
47
[0aaca60]48/* Your callback function should look like this: */
[5ebff60]49typedef void (*http_input_function)(struct http_request *);
[8a9afe4]50
[0aaca60]51/* This structure will be filled in by the http_dorequest* functions, and
52   it will be passed to the callback function. Use the data field to add
53   your own data. */
[5ebff60]54struct http_request {
[0aaca60]55        char *request;          /* The request to send to the server. */
56        int request_length;     /* Its size. */
[8bd866f]57        short status_code;      /* The numeric HTTP status code. (Or -1
[0aaca60]58                                   if something really went wrong) */
59        char *status_string;    /* The error text. */
[8a9afe4]60        char *reply_headers;
61        char *reply_body;
[0aaca60]62        int body_size;          /* The number of bytes in reply_body. */
[8bd866f]63        short redir_ttl;        /* You can set it to 0 if you don't want
[7885d0f]64                                   http_client to follow them. */
[5ebff60]65
[8bd866f]66        http_client_flags_t flags;
[5ebff60]67
[0aaca60]68        http_input_function func;
69        gpointer data;
[5ebff60]70
[0aaca60]71        /* Please don't touch the things down here, you shouldn't need them. */
[8a9afe4]72        void *ssl;
73        int fd;
[5ebff60]74
[8a9afe4]75        int inpa;
76        int bytes_written;
77        int bytes_read;
[ca8037e]78        int content_length;     /* "Content-Length:" header or -1 */
[5ebff60]79
[8bd866f]80        /* Used in streaming mode. Caller should read from reply_body. */
81        char *sbuf;
82        size_t sblen;
[5ebff60]83
[ca8037e]84        /* Chunked encoding only. Raw chunked stream is decoded from here. */
85        char *cbuf;
86        size_t cblen;
[8a9afe4]87};
88
[0aaca60]89/* The _url variant is probably more useful than the raw version. The raw
90   version is probably only useful if you want to do POST requests or if
91   you want to add some extra headers. As you can see, HTTPS connections
92   are also supported (using ssl_client). */
[5ebff60]93struct http_request *http_dorequest(char *host, int port, int ssl, char *request, http_input_function func,
94                                    gpointer data);
95struct http_request *http_dorequest_url(char *url_string, http_input_function func, gpointer data);
[8bd866f]96
97/* For streaming connections only; flushes len bytes at the start of the buffer. */
[5ebff60]98void http_flush_bytes(struct http_request *req, size_t len);
99void http_close(struct http_request *req);
Note: See TracBrowser for help on using the repository browser.