source: mainline/uspace/lib/http/include/http/http.h@ 4d4f656

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

libhttp: Add higher-level API for working with headers

  • Property mode set to 100644
File size: 4.2 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
43#include "receive-buffer.h"
44
45typedef struct {
46 char *host;
47 uint16_t port;
48 inet_addr_t addr;
49
50 bool connected;
51 int conn_sd;
52
53 size_t buffer_size;
54 receive_buffer_t recv_buffer;
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 list_t list;
70} http_headers_t;
71
72typedef struct {
73 char *method;
74 char *path;
75 http_headers_t headers;
76} http_request_t;
77
78typedef struct {
79 http_version_t version;
80 uint16_t status;
81 char *message;
82 http_headers_t headers;
83} http_response_t;
84
85extern http_t *http_create(const char *, uint16_t);
86extern int http_connect(http_t *);
87
88extern void http_header_init(http_header_t *);
89extern http_header_t *http_header_create(const char *, const char *);
90extern int http_header_receive_name(receive_buffer_t *, char **);
91extern int http_header_receive_value(receive_buffer_t *, char **);
92extern int http_header_receive(receive_buffer_t *, http_header_t *);
93extern void http_header_normalize_value(char *);
94extern bool http_header_name_match(const char *, const char *);
95ssize_t http_header_encode(http_header_t *, char *, size_t);
96extern void http_header_destroy(http_header_t *);
97
98extern void http_headers_init(http_headers_t *);
99extern int http_headers_find_single(http_headers_t *, const char *,
100 http_header_t **);
101extern int http_headers_append(http_headers_t *, const char *, const char *);
102extern int http_headers_set(http_headers_t *, const char *, const char *);
103extern int http_headers_get(http_headers_t *, const char *, char **);
104extern int http_headers_receive(receive_buffer_t *, http_headers_t *);
105extern void http_headers_clear(http_headers_t *);
106
107#define http_headers_foreach(headers, iter) \
108 list_foreach((headers).list, link, http_header_t, (iter))
109
110static inline void http_headers_remove(http_headers_t *headers,
111 http_header_t *header)
112{
113 list_remove(&header->link);
114}
115
116static inline void http_headers_append_header(http_headers_t *headers,
117 http_header_t *header)
118{
119 list_append(&header->link, &headers->list);
120}
121
122extern http_request_t *http_request_create(const char *, const char *);
123extern void http_request_destroy(http_request_t *);
124extern int http_request_format(http_request_t *, char **, size_t *);
125extern int http_send_request(http_t *, http_request_t *);
126extern int http_parse_status(const char *, http_version_t *, uint16_t *,
127 char **);
128extern int http_receive_response(http_t *, http_response_t **);
129extern int http_receive_body(http_t *, void *, size_t);
130extern void http_response_destroy(http_response_t *);
131extern int http_close(http_t *);
132extern void http_destroy(http_t *);
133
134#endif
135
136/** @}
137 */
Note: See TracBrowser for help on using the repository browser.