2009-04-22 15:25:41 -04:00
|
|
|
|
|
|
|
#ifndef __HTTPD_H__
|
|
|
|
#define __HTTPD_H__
|
|
|
|
|
2015-10-19 15:15:29 -04:00
|
|
|
#include <event2/http.h>
|
|
|
|
#include <event2/buffer.h>
|
2017-11-04 16:24:42 -04:00
|
|
|
#include <event2/keyvalq_struct.h>
|
2017-08-20 09:38:26 -04:00
|
|
|
#include <stdbool.h>
|
2009-04-25 04:40:47 -04:00
|
|
|
|
2016-10-17 08:18:13 -04:00
|
|
|
enum httpd_send_flags
|
|
|
|
{
|
|
|
|
HTTPD_SEND_NO_GZIP = (1 << 0),
|
|
|
|
};
|
|
|
|
|
2017-11-04 16:24:42 -04:00
|
|
|
/*
|
|
|
|
* Contains a parsed version of the URI httpd got. The URI may have been
|
|
|
|
* complete:
|
|
|
|
* scheme:[//[user[:password]@]host[:port]][/path][?query][#fragment]
|
|
|
|
* or relative:
|
|
|
|
* [/path][?query][#fragment]
|
|
|
|
*
|
|
|
|
* We are interested in the path and the query, so they are disassembled to
|
|
|
|
* path_parts and ev_query. If the request is http://x:3689/foo/bar?key1=val1,
|
|
|
|
* then part_parts[1] is "foo", [2] is "bar" and the rest is null (the first
|
|
|
|
* element points to the copy of the path so it can be freed).
|
|
|
|
*
|
|
|
|
* The allocated strings are URI decoded.
|
|
|
|
*/
|
|
|
|
struct httpd_uri_parsed
|
|
|
|
{
|
|
|
|
const char *uri;
|
|
|
|
struct evhttp_uri *ev_uri;
|
|
|
|
struct evkeyvalq ev_query;
|
|
|
|
char *uri_decoded;
|
|
|
|
char *path;
|
|
|
|
char *path_parts[7];
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper to free the parsed uri struct
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
httpd_uri_free(struct httpd_uri_parsed *parsed);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse an URI into the struct
|
|
|
|
*/
|
|
|
|
struct httpd_uri_parsed *
|
|
|
|
httpd_uri_parse(const char *uri);
|
|
|
|
|
|
|
|
|
2009-04-25 04:40:47 -04:00
|
|
|
void
|
|
|
|
httpd_stream_file(struct evhttp_request *req, int id);
|
|
|
|
|
2016-10-17 17:08:02 -04:00
|
|
|
/*
|
|
|
|
* Gzips an evbuffer
|
|
|
|
*
|
|
|
|
* @in in Data to be compressed
|
|
|
|
* @return Compressed data - must be freed by caller
|
|
|
|
*/
|
2016-10-17 13:35:37 -04:00
|
|
|
struct evbuffer *
|
|
|
|
httpd_gzip_deflate(struct evbuffer *in);
|
|
|
|
|
2016-10-17 17:08:02 -04:00
|
|
|
/*
|
|
|
|
* This wrapper around evhttp_send_reply should be used whenever a request may
|
|
|
|
* come from a browser. It will automatically gzip if feasible, but the caller
|
|
|
|
* may direct it not to. It will set CORS headers as appropriate. Should be
|
|
|
|
* thread safe.
|
|
|
|
*
|
|
|
|
* @in req The evhttp request struct
|
|
|
|
* @in code HTTP code, e.g. 200
|
|
|
|
* @in reason A brief explanation of the error - if NULL the standard meaning
|
|
|
|
of the error code will be used
|
|
|
|
* @in evbuf Data for the response body
|
|
|
|
* @in flags See flags above
|
|
|
|
*/
|
2010-05-03 12:19:41 -04:00
|
|
|
void
|
2016-10-17 08:18:13 -04:00
|
|
|
httpd_send_reply(struct evhttp_request *req, int code, const char *reason, struct evbuffer *evbuf, enum httpd_send_flags flags);
|
2010-05-03 12:19:41 -04:00
|
|
|
|
2016-10-17 17:08:02 -04:00
|
|
|
/*
|
|
|
|
* This is a substitute for evhttp_send_error that should be used whenever an
|
|
|
|
* error may be returned to a browser. It will set CORS headers as appropriate,
|
|
|
|
* which is not possible with evhttp_send_error, because it clears the headers.
|
|
|
|
* Should be thread safe.
|
|
|
|
*
|
|
|
|
* @in req The evhttp request struct
|
|
|
|
* @in error HTTP code, e.g. 200
|
|
|
|
* @in reason A brief explanation of the error - if NULL the standard meaning
|
|
|
|
of the error code will be used
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
httpd_send_error(struct evhttp_request *req, int error, const char *reason);
|
|
|
|
|
2009-05-01 14:58:15 -04:00
|
|
|
int
|
2017-02-11 19:19:56 -05:00
|
|
|
httpd_basic_auth(struct evhttp_request *req, const char *user, const char *passwd, const char *realm);
|
2009-05-01 14:58:15 -04:00
|
|
|
|
2017-08-20 09:38:26 -04:00
|
|
|
bool
|
|
|
|
httpd_admin_check_auth(struct evhttp_request *req);
|
|
|
|
|
2009-04-22 15:25:41 -04:00
|
|
|
int
|
|
|
|
httpd_init(void);
|
|
|
|
|
|
|
|
void
|
|
|
|
httpd_deinit(void);
|
|
|
|
|
|
|
|
#endif /* !__HTTPD_H__ */
|