[d7b7f5e] | 1 | /*
|
---|
| 2 | * Copyright (c) 2013 Martin Sucha
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup http
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #ifndef HTTP_HTTP_H_
|
---|
| 37 | #define HTTP_HTTP_H_
|
---|
| 38 |
|
---|
| 39 | #include <net/socket.h>
|
---|
| 40 | #include <adt/list.h>
|
---|
| 41 | #include <inet/addr.h>
|
---|
| 42 |
|
---|
| 43 | typedef struct {
|
---|
| 44 | char *host;
|
---|
| 45 | uint16_t port;
|
---|
| 46 | inet_addr_t addr;
|
---|
| 47 |
|
---|
| 48 | bool connected;
|
---|
| 49 | int conn_sd;
|
---|
| 50 |
|
---|
| 51 | size_t buffer_size;
|
---|
| 52 | char *recv_buffer;
|
---|
| 53 | size_t recv_buffer_in;
|
---|
| 54 | size_t recv_buffer_out;
|
---|
| 55 | } http_t;
|
---|
| 56 |
|
---|
| 57 | typedef struct {
|
---|
| 58 | uint8_t minor;
|
---|
| 59 | uint8_t major;
|
---|
| 60 | } http_version_t;
|
---|
| 61 |
|
---|
| 62 | typedef struct {
|
---|
| 63 | link_t link;
|
---|
| 64 | char *name;
|
---|
| 65 | char *value;
|
---|
| 66 | } http_header_t;
|
---|
| 67 |
|
---|
| 68 | typedef struct {
|
---|
| 69 | char *method;
|
---|
| 70 | char *path;
|
---|
| 71 | list_t headers;
|
---|
| 72 | } http_request_t;
|
---|
| 73 |
|
---|
| 74 | typedef struct {
|
---|
| 75 | http_version_t version;
|
---|
| 76 | uint16_t status;
|
---|
| 77 | char *message;
|
---|
| 78 | list_t headers;
|
---|
| 79 | } http_response_t;
|
---|
| 80 |
|
---|
| 81 | extern http_t *http_create(const char *, uint16_t);
|
---|
| 82 | extern int http_connect(http_t *);
|
---|
| 83 | extern http_header_t *http_header_create(const char *, const char *);
|
---|
| 84 | extern http_header_t *http_header_create_no_copy(char *, char *);
|
---|
| 85 | extern void http_header_destroy(http_header_t *);
|
---|
| 86 | extern http_request_t *http_request_create(const char *, const char *);
|
---|
| 87 | extern void http_request_destroy(http_request_t *);
|
---|
| 88 | extern int http_request_format(http_request_t *, char **, size_t *);
|
---|
| 89 | extern int http_send_request(http_t *, http_request_t *);
|
---|
| 90 | extern int http_parse_status(const char *, http_version_t *, uint16_t *,
|
---|
| 91 | char **);
|
---|
| 92 | extern int http_parse_header(const char *, char **, char **);
|
---|
| 93 | extern int http_receive_response(http_t *, http_response_t **);
|
---|
| 94 | extern int http_receive_body(http_t *, void *, size_t);
|
---|
| 95 | extern void http_response_destroy(http_response_t *);
|
---|
| 96 | extern int http_close(http_t *);
|
---|
| 97 | extern void http_destroy(http_t *);
|
---|
| 98 |
|
---|
| 99 | #endif
|
---|
| 100 |
|
---|
| 101 | /** @}
|
---|
| 102 | */
|
---|