1
0
mirror of https://github.com/lammertb/libhttp.git synced 2026-01-03 16:02:30 +03:00

Normallized coding style in a predictable way.

Uses astyle program which is freely avaiable on all platforms.
This commit is contained in:
Thomas Davis
2013-09-01 12:55:53 -04:00
parent 3f9ded0d6d
commit b745f22107
17 changed files with 5871 additions and 5482 deletions

View File

@@ -17,7 +17,8 @@ class CivetServer; // forward declaration
* Basic interface for a URI request handler. Handlers implementations
* must be reentrant.
*/
class CivetHandler {
class CivetHandler
{
public:
/**
@@ -69,7 +70,8 @@ public:
*
* Basic class for embedded web server. This has a URL mapping built-in.
*/
class CivetServer {
class CivetServer
{
public:
/**
@@ -133,7 +135,7 @@ public:
/**
* getCookie(struct mg_connection *conn, const std::string &cookieName, std::string &cookieValue)
* @param conn - the connection information
* @param conn - the connection information
* @param cookieName - cookie name to get the value from
* @param cookieValue - cookie value is returned using thiis reference
* @puts the cookie value string that matches the cookie name in the _cookieValue string.
@@ -143,7 +145,7 @@ public:
/**
* getHeader(struct mg_connection *conn, const std::string &headerName)
* @param conn - the connection information
* @param conn - the connection information
* @param headerName - header name to get the value from
* @returns a char array whcih contains the header value as string
*/
@@ -163,7 +165,7 @@ public:
* @return true of key was found
*/
static bool getParam(struct mg_connection *conn, const char *name,
std::string &dst, size_t occurrence=0);
std::string &dst, size_t occurrence=0);
/**
* getParam(const std::string &, const char *, std::string &, size_t)
@@ -179,7 +181,7 @@ public:
* @return true of key was found
*/
static bool getParam(const std::string &data, const char *name,
std::string &dst, size_t occurrence=0) {
std::string &dst, size_t occurrence=0) {
return getParam(data.c_str(), data.length(), name, dst, occurrence);
}
@@ -198,7 +200,7 @@ public:
* @return true of key was found
*/
static bool getParam(const char *data, size_t data_len, const char *name,
std::string &dst, size_t occurrence=0);
std::string &dst, size_t occurrence=0);
/**

View File

@@ -34,22 +34,22 @@ struct mg_connection; // Handle for the individual connection
// This structure contains information about the HTTP request.
struct mg_request_info {
const char *request_method; // "GET", "POST", etc
const char *uri; // URL-decoded URI
const char *http_version; // E.g. "1.0", "1.1"
const char *query_string; // URL part after '?', not including '?', or NULL
const char *remote_user; // Authenticated user, or NULL if no auth used
long remote_ip; // Client's IP address
int remote_port; // Client's port
int is_ssl; // 1 if SSL-ed, 0 if not
void *user_data; // User data pointer passed to mg_start()
void *conn_data; // Connection-specific user data
const char *request_method; // "GET", "POST", etc
const char *uri; // URL-decoded URI
const char *http_version; // E.g. "1.0", "1.1"
const char *query_string; // URL part after '?', not including '?', or NULL
const char *remote_user; // Authenticated user, or NULL if no auth used
long remote_ip; // Client's IP address
int remote_port; // Client's port
int is_ssl; // 1 if SSL-ed, 0 if not
void *user_data; // User data pointer passed to mg_start()
void *conn_data; // Connection-specific user data
int num_headers; // Number of HTTP headers
struct mg_header {
const char *name; // HTTP header name
const char *value; // HTTP header value
} http_headers[64]; // Maximum 64 headers
int num_headers; // Number of HTTP headers
struct mg_header {
const char *name; // HTTP header name
const char *value; // HTTP header value
} http_headers[64]; // Maximum 64 headers
};
@@ -57,78 +57,78 @@ struct mg_request_info {
// which callbacks to invoke. For detailed description, see
// https://github.com/sunsetbrew/civetweb/blob/master/docs/UserManual.md
struct mg_callbacks {
// Called when civetweb has received new HTTP request.
// If callback returns non-zero,
// callback must process the request by sending valid HTTP headers and body,
// and civetweb will not do any further processing.
// If callback returns 0, civetweb processes the request itself. In this case,
// callback must not send any data to the client.
int (*begin_request)(struct mg_connection *);
// Called when civetweb has received new HTTP request.
// If callback returns non-zero,
// callback must process the request by sending valid HTTP headers and body,
// and civetweb will not do any further processing.
// If callback returns 0, civetweb processes the request itself. In this case,
// callback must not send any data to the client.
int (*begin_request)(struct mg_connection *);
// Called when civetweb has finished processing request.
void (*end_request)(const struct mg_connection *, int reply_status_code);
// Called when civetweb has finished processing request.
void (*end_request)(const struct mg_connection *, int reply_status_code);
// Called when civetweb is about to log a message. If callback returns
// non-zero, civetweb does not log anything.
int (*log_message)(const struct mg_connection *, const char *message);
// Called when civetweb is about to log a message. If callback returns
// non-zero, civetweb does not log anything.
int (*log_message)(const struct mg_connection *, const char *message);
// Called when civetweb initializes SSL library.
int (*init_ssl)(void *ssl_context, void *user_data);
// Called when civetweb initializes SSL library.
int (*init_ssl)(void *ssl_context, void *user_data);
// Called when websocket request is received, before websocket handshake.
// If callback returns 0, civetweb proceeds with handshake, otherwise
// cinnection is closed immediately.
int (*websocket_connect)(const struct mg_connection *);
// Called when websocket request is received, before websocket handshake.
// If callback returns 0, civetweb proceeds with handshake, otherwise
// cinnection is closed immediately.
int (*websocket_connect)(const struct mg_connection *);
// Called when websocket handshake is successfully completed, and
// connection is ready for data exchange.
void (*websocket_ready)(struct mg_connection *);
// Called when websocket handshake is successfully completed, and
// connection is ready for data exchange.
void (*websocket_ready)(struct mg_connection *);
// Called when data frame has been received from the client.
// Parameters:
// bits: first byte of the websocket frame, see websocket RFC at
// http://tools.ietf.org/html/rfc6455, section 5.2
// data, data_len: payload, with mask (if any) already applied.
// Return value:
// non-0: keep this websocket connection opened.
// 0: close this websocket connection.
int (*websocket_data)(struct mg_connection *, int bits,
char *data, size_t data_len);
// Called when data frame has been received from the client.
// Parameters:
// bits: first byte of the websocket frame, see websocket RFC at
// http://tools.ietf.org/html/rfc6455, section 5.2
// data, data_len: payload, with mask (if any) already applied.
// Return value:
// non-0: keep this websocket connection opened.
// 0: close this websocket connection.
int (*websocket_data)(struct mg_connection *, int bits,
char *data, size_t data_len);
// Called when civetweb is closing a connection. The per-context mutex is locked when this
// is invoked. This is primarily useful for noting when a websocket is closing and removing it
// from any application-maintained list of clients.
void (*connection_close)(struct mg_connection *);
// Called when civetweb is closing a connection. The per-context mutex is locked when this
// is invoked. This is primarily useful for noting when a websocket is closing and removing it
// from any application-maintained list of clients.
void (*connection_close)(struct mg_connection *);
// Called when civetweb tries to open a file. Used to intercept file open
// calls, and serve file data from memory instead.
// Parameters:
// path: Full path to the file to open.
// data_len: Placeholder for the file size, if file is served from memory.
// Return value:
// NULL: do not serve file from memory, proceed with normal file open.
// non-NULL: pointer to the file contents in memory. data_len must be
// initilized with the size of the memory block.
const char * (*open_file)(const struct mg_connection *,
const char *path, size_t *data_len);
// Called when civetweb tries to open a file. Used to intercept file open
// calls, and serve file data from memory instead.
// Parameters:
// path: Full path to the file to open.
// data_len: Placeholder for the file size, if file is served from memory.
// Return value:
// NULL: do not serve file from memory, proceed with normal file open.
// non-NULL: pointer to the file contents in memory. data_len must be
// initilized with the size of the memory block.
const char * (*open_file)(const struct mg_connection *,
const char *path, size_t *data_len);
// Called when civetweb is about to serve Lua server page (.lp file), if
// Lua support is enabled.
// Parameters:
// lua_context: "lua_State *" pointer.
void (*init_lua)(struct mg_connection *, void *lua_context);
// Called when civetweb is about to serve Lua server page (.lp file), if
// Lua support is enabled.
// Parameters:
// lua_context: "lua_State *" pointer.
void (*init_lua)(struct mg_connection *, void *lua_context);
// Called when civetweb has uploaded a file to a temporary directory as a
// result of mg_upload() call.
// Parameters:
// file_file: full path name to the uploaded file.
void (*upload)(struct mg_connection *, const char *file_name);
// Called when civetweb has uploaded a file to a temporary directory as a
// result of mg_upload() call.
// Parameters:
// file_file: full path name to the uploaded file.
void (*upload)(struct mg_connection *, const char *file_name);
// Called when civetweb is about to send HTTP error to the client.
// Implementing this callback allows to create custom error pages.
// Parameters:
// status: HTTP error status code.
int (*http_error)(struct mg_connection *, int status);
// Called when civetweb is about to send HTTP error to the client.
// Implementing this callback allows to create custom error pages.
// Parameters:
// status: HTTP error status code.
int (*http_error)(struct mg_connection *, int status);
};
// Start web server.
@@ -187,9 +187,9 @@ typedef int (* mg_request_handler)(struct mg_connection *conn, void *cbdata);
//
// URI's are ordered and prefixed URI's are supported. For example,
// consider two URIs: /a/b and /a
// /a matches /a
// /a matches /a
// /a/b matches /a/b
// /a/c matches /a
// /a/c matches /a
//
// Parameters:
// ctx: server context
@@ -268,12 +268,12 @@ void mg_unlock(struct mg_connection* conn);
// Opcodes, from http://tools.ietf.org/html/rfc6455
enum {
WEBSOCKET_OPCODE_CONTINUATION = 0x0,
WEBSOCKET_OPCODE_TEXT = 0x1,
WEBSOCKET_OPCODE_BINARY = 0x2,
WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
WEBSOCKET_OPCODE_PING = 0x9,
WEBSOCKET_OPCODE_PONG = 0xa
WEBSOCKET_OPCODE_CONTINUATION = 0x0,
WEBSOCKET_OPCODE_TEXT = 0x1,
WEBSOCKET_OPCODE_BINARY = 0x2,
WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
WEBSOCKET_OPCODE_PING = 0x9,
WEBSOCKET_OPCODE_PONG = 0xa
};
@@ -368,7 +368,7 @@ int mg_get_var(const char *data, size_t data_len,
// Destination buffer is guaranteed to be '\0' - terminated if it is not
// NULL or zero length.
int mg_get_var2(const char *data, size_t data_len,
const char *var_name, char *dst, size_t dst_len, size_t occurrence);
const char *var_name, char *dst, size_t dst_len, size_t occurrence);
// Fetch value of certain cookie variable into the destination buffer.
//
@@ -462,7 +462,7 @@ char *mg_md5(char buf[33], ...);
// Example:
// mg_cry(conn,"i like %s", "logging");
void mg_cry(struct mg_connection *conn,
PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(2, 3);
PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(2, 3);
// utility method to compare two buffers, case incensitive.
int mg_strncasecmp(const char *s1, const char *s2, size_t len);