2014-09-16 18:12:26 +04:00
/*
Unix SMB / CIFS implementation .
HTTP library
Copyright ( C ) 2013 Samuel Cabrero < samuelcabrero @ kernevil . me >
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# ifndef _HTTP_H_
# define _HTTP_H_
# include <limits.h>
# include <sys/uio.h>
# include <tevent.h>
# include "lib/tsocket/tsocket.h"
/* Response codes */
# define HTTP_OK 200 /* request completed ok */
# define HTTP_NOCONTENT 204 /* request does not have content */
# define HTTP_MOVEPERM 301 /* uri moved permanently */
# define HTTP_MOVETEMP 302 /* uri moved temporarily */
# define HTTP_NOTMODIFIED 304 /* page was not modified from last */
# define HTTP_BADREQUEST 400 /* invalid http request was made */
# define HTTP_NOTFOUND 404 /* could not find content for uri */
# define HTTP_BADMETHOD 405 /* method not allowed for this uri */
# define HTTP_ENTITYTOOLARGE 413 /* */
# define HTTP_EXPECTATIONFAILED 417 /* can't handle this expectation */
# define HTTP_INTERNAL 500 /* internal error */
# define HTTP_NOTIMPLEMENTED 501 /* not implemented */
# define HTTP_SERVUNAVAIL 503 /* server is not available */
2017-07-20 19:13:28 +03:00
# define HTTP_MAX_HEADER_SIZE 0x1FFFF
2014-09-16 18:12:26 +04:00
struct cli_credentials ;
enum http_cmd_type {
HTTP_REQ_GET = 1 < < 0 ,
HTTP_REQ_POST = 1 < < 1 ,
HTTP_REQ_HEAD = 1 < < 2 ,
HTTP_REQ_PUT = 1 < < 3 ,
HTTP_REQ_DELETE = 1 < < 4 ,
HTTP_REQ_OPTIONS = 1 < < 5 ,
HTTP_REQ_TRACE = 1 < < 6 ,
HTTP_REQ_CONNECT = 1 < < 7 ,
HTTP_REQ_PATCH = 1 < < 8 ,
HTTP_REQ_RPC_IN_DATA = 1 < < 9 ,
HTTP_REQ_RPC_OUT_DATA = 1 < < 10 ,
} ;
enum http_auth_method {
2014-09-16 20:05:53 +04:00
HTTP_AUTH_BASIC = 1 ,
2014-09-16 18:12:26 +04:00
HTTP_AUTH_NTLM ,
2017-07-20 14:03:40 +03:00
HTTP_AUTH_NEGOTIATE ,
2014-09-16 18:12:26 +04:00
} ;
struct http_header {
struct http_header * next , * prev ;
char * key ;
char * value ;
} ;
struct http_request {
enum http_cmd_type type ; /* HTTP command type */
char major ; /* HTTP version major number */
char minor ; /* HTTP version minor number */
char * uri ; /* URI after HTTP request was parsed */
struct http_header * headers ;
size_t headers_size ;
unsigned int response_code ; /* HTTP response code */
char * response_code_line ; /* Readable response */
2017-07-20 19:12:27 +03:00
uint64_t remaining_content_length ; /* data not represent in body */
2014-09-16 18:12:26 +04:00
DATA_BLOB body ;
} ;
/* HTTP header handling functions */
int http_remove_header ( struct http_header * * , const char * ) ;
int http_add_header ( TALLOC_CTX * , struct http_header * * , const char * , const char * ) ;
int http_replace_header ( TALLOC_CTX * , struct http_header * * , const char * , const char * ) ;
2019-03-25 16:39:59 +03:00
/* HTTP(s) connect */
struct http_conn ;
struct tstream_tls_params ;
struct tevent_req * http_connect_send ( TALLOC_CTX * mem_ctx ,
struct tevent_context * ev ,
const char * http_server ,
uint16_t http_port ,
struct cli_credentials * credentials ,
struct tstream_tls_params * tls_params ) ;
int http_connect_recv ( struct tevent_req * req ,
TALLOC_CTX * mem_ctx ,
struct http_conn * * http_conn ) ;
struct tevent_req * http_disconnect_send ( TALLOC_CTX * mem_ctx ,
struct tevent_context * ev ,
struct http_conn * http_conn ) ;
int http_disconnect_recv ( struct tevent_req * req ) ;
struct tevent_queue * http_conn_send_queue ( struct http_conn * http_conn ) ;
struct tstream_context * http_conn_tstream ( struct http_conn * http_conn ) ;
2014-09-16 18:12:26 +04:00
/* HTTP request */
struct tevent_req * http_send_request_send ( TALLOC_CTX * ,
struct tevent_context * ,
2019-08-06 13:33:40 +03:00
struct http_conn * ,
2014-09-16 18:12:26 +04:00
struct http_request * ) ;
NTSTATUS http_send_request_recv ( struct tevent_req * ) ;
/* HTTP response */
struct tevent_req * http_read_response_send ( TALLOC_CTX * ,
struct tevent_context * ,
2019-08-06 13:33:40 +03:00
struct http_conn * ,
2017-07-20 19:12:27 +03:00
size_t max_content_length ) ;
2014-09-16 18:12:26 +04:00
NTSTATUS http_read_response_recv ( struct tevent_req * ,
TALLOC_CTX * ,
struct http_request * * ) ;
2014-09-16 20:05:53 +04:00
/* HTTP authenticated request */
struct tevent_req * http_send_auth_request_send ( TALLOC_CTX * ,
struct tevent_context * ,
2019-08-06 13:33:40 +03:00
struct http_conn * ,
2017-05-11 16:34:08 +03:00
const struct http_request * ,
2014-09-16 20:05:53 +04:00
struct cli_credentials * ,
struct loadparm_context * ,
enum http_auth_method ) ;
NTSTATUS http_send_auth_request_recv ( struct tevent_req * ) ;
2014-09-16 18:12:26 +04:00
# endif /* _HTTP_H_ */