ncacn_http: Add http library
[bbaumbach/samba-autobuild/.git] / source4 / lib / http / http.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    HTTP library
5
6    Copyright (C) 2013 Samuel Cabrero <samuelcabrero@kernevil.me>
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef _HTTP_H_
23 #define _HTTP_H_
24
25 #include <limits.h>
26 #include <sys/uio.h>
27
28 #include <tevent.h>
29 #include "lib/tsocket/tsocket.h"
30
31 /* Response codes */
32 #define HTTP_OK                 200     /* request completed ok */
33 #define HTTP_NOCONTENT          204     /* request does not have content */
34 #define HTTP_MOVEPERM           301     /* uri moved permanently */
35 #define HTTP_MOVETEMP           302     /* uri moved temporarily */
36 #define HTTP_NOTMODIFIED        304     /* page was not modified from last */
37 #define HTTP_BADREQUEST         400     /* invalid http request was made */
38 #define HTTP_NOTFOUND           404     /* could not find content for uri */
39 #define HTTP_BADMETHOD          405     /* method not allowed for this uri */
40 #define HTTP_ENTITYTOOLARGE     413     /* */
41 #define HTTP_EXPECTATIONFAILED  417     /* can't handle this expectation */
42 #define HTTP_INTERNAL           500     /* internal error */
43 #define HTTP_NOTIMPLEMENTED     501     /* not implemented */
44 #define HTTP_SERVUNAVAIL        503     /* server is not available */
45
46 #define HTTP_MAX_HEADER_SIZE    UINT_MAX
47
48 struct cli_credentials;
49 struct loadparm_ctx;
50
51 enum http_cmd_type {
52         HTTP_REQ_GET            = 1 << 0,
53         HTTP_REQ_POST           = 1 << 1,
54         HTTP_REQ_HEAD           = 1 << 2,
55         HTTP_REQ_PUT            = 1 << 3,
56         HTTP_REQ_DELETE         = 1 << 4,
57         HTTP_REQ_OPTIONS        = 1 << 5,
58         HTTP_REQ_TRACE          = 1 << 6,
59         HTTP_REQ_CONNECT        = 1 << 7,
60         HTTP_REQ_PATCH          = 1 << 8,
61         HTTP_REQ_RPC_IN_DATA    = 1 << 9,
62         HTTP_REQ_RPC_OUT_DATA   = 1 << 10,
63 };
64
65 enum http_auth_method {
66         HTTP_AUTH_AUTO,
67         HTTP_AUTH_BASIC,
68         HTTP_AUTH_NTLM,
69         HTTP_AUTH_NEGOTIATE,
70 };
71
72 struct http_header {
73         struct http_header      *next, *prev;
74         char                    *key;
75         char                    *value;
76 };
77
78 struct http_request {
79         enum http_cmd_type      type;   /* HTTP command type */
80         char                    major;  /* HTTP version major number */
81         char                    minor;  /* HTTP version minor number */
82         char                    *uri;   /* URI after HTTP request was parsed */
83         struct http_header      *headers;
84         size_t                  headers_size;
85         unsigned int            response_code;          /* HTTP response code */
86         char                    *response_code_line;    /* Readable response */
87         DATA_BLOB               body;
88 };
89
90 /* HTTP header handling functions */
91 int http_remove_header(struct http_header **, const char *);
92 int http_add_header(TALLOC_CTX *, struct http_header **, const char *, const char *);
93 int http_replace_header(TALLOC_CTX *, struct http_header **, const char *, const char *);
94
95 /* HTTP request */
96 struct tevent_req *http_send_request_send(TALLOC_CTX *,
97                                           struct tevent_context *,
98                                           struct tstream_context *,
99                                           struct tevent_queue *,
100                                           struct http_request *);
101 NTSTATUS http_send_request_recv(struct tevent_req *);
102
103 /* HTTP response */
104 struct tevent_req *http_read_response_send(TALLOC_CTX *,
105                                            struct tevent_context *,
106                                            struct tstream_context *);
107 NTSTATUS http_read_response_recv(struct tevent_req *,
108                             TALLOC_CTX *,
109                             struct http_request **);
110
111 #endif /* _HTTP_H_ */