SpriteHTTPD - embedded HTTP server with read-only filesystem and templating, originally developed for ESP8266, now stand-alone and POSIX compatible.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
spritehttpd/spritehttpd/include/httpd-types.h

102 lines
3.4 KiB

/**
* Type definitions used in the http server
*/
#pragma once
#include <stdint.h>
#include <stddef.h>
// opaque conn type struct
struct HttpdConnType;
typedef struct HttpdConnType HttpdConnType;
typedef HttpdConnType* ConnTypePtr;
struct httpd_thread_handle;
typedef struct httpd_thread_handle httpd_thread_handle_t;
struct httpd_options;
/**
* CGI handler state / return value
*/
typedef enum {
/// Some work was done and the CGI wants to be called again at a later time.
/// Splitting long-running jobs allows other requests to be handled.
HTTPD_CGI_MORE = 0,
/// The CGI handled the request and is now done with it
HTTPD_CGI_DONE = 1,
/// This CGI did not handle the request, fall through to following ones
HTTPD_CGI_NOTFOUND = 2,
/// This is, in effect, identical to NOTFOUND, it's returned by auth functions when a fall-through is allowed.
/// The next route in the route list will be attempted.
HTTPD_CGI_AUTHENTICATED = 3,
} httpd_cgi_state;
/**
* HTTP method (verb) used for the request
*/
typedef enum {
HTTPD_METHOD_GET = 1,
HTTPD_METHOD_POST = 2,
HTTPD_METHOD_OPTIONS = 3,
HTTPD_METHOD_PUT = 4,
HTTPD_METHOD_DELETE = 5,
HTTPD_METHOD_PATCH = 6,
HTTPD_METHOD_HEAD = 7,
} httpd_method;
/**
* Transfer mode
*/
typedef enum {
HTTPD_TRANSFER_CLOSE = 0,
HTTPD_TRANSFER_CHUNKED = 1,
HTTPD_TRANSFER_NONE = 2,
} httpd_transfer_opt;
typedef struct HttpdPriv HttpdPriv;
typedef struct HttpdConnData HttpdConnData;
typedef struct HttpdPostData HttpdPostData;
typedef httpd_cgi_state (* cgiSendCallback)(HttpdConnData *connData);
typedef httpd_cgi_state (* cgiRecvHandler)(HttpdConnData *connData, uint8_t *data, size_t len);
struct httpd_options {
uint16_t port;
};
//A struct describing a http connection. This gets passed to cgi functions.
struct HttpdConnData {
ConnTypePtr conn; // The TCP connection. Exact type depends on the platform.
HttpdPriv *priv; // Opaque pointer to data for internal httpd housekeeping
httpd_method requestType; // One of the HTTPD_METHOD_* values
char *hostName; // Host name field of request
char *url; // The URL requested, without hostname or GET arguments
char *getArgs; // The GET arguments for this request, if any.
HttpdPostData *post; // POST data structure
cgiSendCallback cgi; // CGI function pointer
cgiRecvHandler recvHdl; // Handler for data received after headers, if any
const void *cgiArg; // Argument to the CGI function, as stated as the 3rd argument of
// the builtInUrls entry that referred to the CGI function.
const void *cgiArg2; // 4th argument of the builtInUrls entries, used to pass template file to the tpl handler.
void *cgiData; // Opaque data pointer for the CGI function
// this should be at the end because of padding
uint16_t remote_port; // Remote TCP port
uint8_t remote_ip[4]; // IP address of client
uint8_t slot; // Slot ID
};
//A struct describing the POST data sent inside the http connection. This is used by the CGI functions
struct HttpdPostData {
// FIXME len can be negative due to a stupid hack at `src/httpd.c:923`
int len; // POST Content-Length
size_t buffSize; // The maximum length of the post buffer
size_t buffLen; // The amount of bytes in the current post buffer
size_t received; // The total amount of bytes received so far
char *buff; // Actual POST data buffer
char *multipartBoundary; //Text of the multipart boundary, if any
};