source: mainline/uspace/lib/http/http.h@ d7b7f5e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d7b7f5e was d7b7f5e, checked in by Martin Sucha <sucha14@…>, 12 years ago

Add a basic HTTP download tool

  • Property mode set to 100644
File size: 3.0 KB
Line 
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
43typedef 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
57typedef struct {
58 uint8_t minor;
59 uint8_t major;
60} http_version_t;
61
62typedef struct {
63 link_t link;
64 char *name;
65 char *value;
66} http_header_t;
67
68typedef struct {
69 char *method;
70 char *path;
71 list_t headers;
72} http_request_t;
73
74typedef struct {
75 http_version_t version;
76 uint16_t status;
77 char *message;
78 list_t headers;
79} http_response_t;
80
81extern http_t *http_create(const char *, uint16_t);
82extern int http_connect(http_t *);
83extern http_header_t *http_header_create(const char *, const char *);
84extern http_header_t *http_header_create_no_copy(char *, char *);
85extern void http_header_destroy(http_header_t *);
86extern http_request_t *http_request_create(const char *, const char *);
87extern void http_request_destroy(http_request_t *);
88extern int http_request_format(http_request_t *, char **, size_t *);
89extern int http_send_request(http_t *, http_request_t *);
90extern int http_parse_status(const char *, http_version_t *, uint16_t *,
91 char **);
92extern int http_parse_header(const char *, char **, char **);
93extern int http_receive_response(http_t *, http_response_t **);
94extern int http_receive_body(http_t *, void *, size_t);
95extern void http_response_destroy(http_response_t *);
96extern int http_close(http_t *);
97extern void http_destroy(http_t *);
98
99#endif
100
101/** @}
102 */
Note: See TracBrowser for help on using the repository browser.