| 1 |
/* |
| 2 |
* Copyright 2008-2011 Various Authors |
| 3 |
* Copyright 2004-2005 Timo Hirvonen |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU General Public License as |
| 7 |
* published by the Free Software Foundation; either version 2 of the |
| 8 |
* License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#ifndef _HTTP_H |
| 20 |
#define _HTTP_H |
| 21 |
|
| 22 |
#include "keyval.h" |
| 23 |
|
| 24 |
#include <stddef.h> /* size_t */ |
| 25 |
|
| 26 |
/* |
| 27 |
* 1xx indicates an informational message only |
| 28 |
* 2xx indicates success of some kind |
| 29 |
* 3xx redirects the client to another URL |
| 30 |
* 4xx indicates an error on the client's part |
| 31 |
* 5xx indicates an error on the server's part |
| 32 |
*/ |
| 33 |
|
| 34 |
struct http_uri { |
| 35 |
char *uri; |
| 36 |
char *user; |
| 37 |
char *pass; |
| 38 |
char *host; |
| 39 |
char *path; |
| 40 |
int port; |
| 41 |
}; |
| 42 |
|
| 43 |
struct http_get { |
| 44 |
struct http_uri uri; |
| 45 |
struct http_uri *proxy; |
| 46 |
int fd; |
| 47 |
struct keyval *headers; |
| 48 |
char *reason; |
| 49 |
int code; |
| 50 |
}; |
| 51 |
|
| 52 |
int http_parse_uri(const char *uri, struct http_uri *u); |
| 53 |
|
| 54 |
/* frees contents of @u, not @u itself */ |
| 55 |
void http_free_uri(struct http_uri *u); |
| 56 |
|
| 57 |
int http_open(struct http_get *hg, int timeout_ms); |
| 58 |
|
| 59 |
/* |
| 60 |
* returns: 0 success |
| 61 |
* -1 check errno |
| 62 |
* -2 parse error |
| 63 |
*/ |
| 64 |
int http_get(struct http_get *hg, struct keyval *headers, int timeout_ms); |
| 65 |
void http_get_free(struct http_get *hg); |
| 66 |
|
| 67 |
char *http_read_body(int fd, size_t *size, int timeout_ms); |
| 68 |
char *base64_encode(const char *str); |
| 69 |
|
| 70 |
#endif |