CVE-2023-0614 ldb:tests: Ensure ldb_val data is zero-terminated
[Samba.git] / libcli / http / http.h
blobf2196031f0321a919e2cee59013e0ca386d8448a
1 /*
2 Unix SMB/CIFS implementation.
4 HTTP library
6 Copyright (C) 2013 Samuel Cabrero <samuelcabrero@kernevil.me>
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.
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.
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/>.
22 #ifndef _HTTP_H_
23 #define _HTTP_H_
25 #include <limits.h>
26 #include <sys/uio.h>
28 #include <tevent.h>
29 #include "lib/tsocket/tsocket.h"
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 */
46 #define HTTP_MAX_HEADER_SIZE 0x1FFFF
48 struct cli_credentials;
49 struct loadparm_ctx;
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,
65 enum http_auth_method {
66 HTTP_AUTH_BASIC=1,
67 HTTP_AUTH_NTLM,
68 HTTP_AUTH_NEGOTIATE,
71 struct http_header {
72 struct http_header *next, *prev;
73 char *key;
74 char *value;
77 struct http_request {
78 enum http_cmd_type type; /* HTTP command type */
79 char major; /* HTTP version major number */
80 char minor; /* HTTP version minor number */
81 char *uri; /* URI after HTTP request was parsed */
82 struct http_header *headers;
83 size_t headers_size;
84 unsigned int response_code; /* HTTP response code */
85 char *response_code_line; /* Readable response */
86 uint64_t remaining_content_length; /* data not represent in body */
87 DATA_BLOB body;
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 *);
95 /* HTTP(s) connect */
97 struct http_conn;
98 struct tstream_tls_params;
100 struct tevent_req *http_connect_send(TALLOC_CTX *mem_ctx,
101 struct tevent_context *ev,
102 const char *http_server,
103 uint16_t http_port,
104 struct cli_credentials *credentials,
105 struct tstream_tls_params *tls_params);
106 int http_connect_recv(struct tevent_req *req,
107 TALLOC_CTX *mem_ctx,
108 struct http_conn **http_conn);
110 struct tevent_req *http_disconnect_send(TALLOC_CTX *mem_ctx,
111 struct tevent_context *ev,
112 struct http_conn *http_conn);
113 int http_disconnect_recv(struct tevent_req *req);
115 struct tevent_queue *http_conn_send_queue(struct http_conn *http_conn);
116 struct tstream_context *http_conn_tstream(struct http_conn *http_conn);
118 /* HTTP request */
119 struct tevent_req *http_send_request_send(TALLOC_CTX *,
120 struct tevent_context *,
121 struct http_conn *,
122 struct http_request *);
123 NTSTATUS http_send_request_recv(struct tevent_req *);
125 /* HTTP response */
126 struct tevent_req *http_read_response_send(TALLOC_CTX *,
127 struct tevent_context *,
128 struct http_conn *,
129 size_t max_content_length);
130 NTSTATUS http_read_response_recv(struct tevent_req *,
131 TALLOC_CTX *,
132 struct http_request **);
134 /* HTTP authenticated request */
135 struct tevent_req *http_send_auth_request_send(TALLOC_CTX *,
136 struct tevent_context *,
137 struct http_conn *,
138 const struct http_request *,
139 struct cli_credentials *,
140 struct loadparm_context *,
141 enum http_auth_method);
142 NTSTATUS http_send_auth_request_recv(struct tevent_req *);
144 #endif /* _HTTP_H_ */