Commit 3330bca4 authored by Sergey Lyubka's avatar Sergey Lyubka

Using mg_handler_t

parent 31f0409b
...@@ -148,7 +148,7 @@ struct vec { ...@@ -148,7 +148,7 @@ struct vec {
struct uri_handler { struct uri_handler {
struct linked_list_link link; struct linked_list_link link;
char *uri; char *uri;
mg_uri_handler_t handler; mg_handler_t handler;
}; };
// NOTE(lsm): this enum shoulds be in sync with the config_options. // NOTE(lsm): this enum shoulds be in sync with the config_options.
...@@ -1942,7 +1942,7 @@ static int mg_iterate_over_connections(struct mg_server *server, ...@@ -1942,7 +1942,7 @@ static int mg_iterate_over_connections(struct mg_server *server,
} }
void mg_add_uri_handler(struct mg_server *server, const char *uri, void mg_add_uri_handler(struct mg_server *server, const char *uri,
mg_uri_handler_t handler) { mg_handler_t handler) {
struct uri_handler *p = (struct uri_handler *) malloc(sizeof(*p)); struct uri_handler *p = (struct uri_handler *) malloc(sizeof(*p));
if (p != NULL) { if (p != NULL) {
LINKED_LIST_ADD_TO_FRONT(&server->uri_handlers, &p->link); LINKED_LIST_ADD_TO_FRONT(&server->uri_handlers, &p->link);
......
...@@ -47,25 +47,23 @@ struct mg_connection { ...@@ -47,25 +47,23 @@ struct mg_connection {
int content_len; // content length int content_len; // content length
int is_websocket; // Connection is a websocket connection int is_websocket; // Connection is a websocket connection
int status_code; // HTTP status code for HTTP error handler
unsigned char wsbits; // First byte of the websocket frame unsigned char wsbits; // First byte of the websocket frame
void *server_param; // Parameter passed to mg_add_uri_handler() void *server_param; // Parameter passed to mg_add_uri_handler()
void *connection_param; // Placeholder for connection-specific data void *connection_param; // Placeholder for connection-specific data
}; };
struct mg_server; // Opaque structure describing server instance struct mg_server; // Opaque structure describing server instance
typedef int (*mg_uri_handler_t)(struct mg_connection *); typedef int (*mg_handler_t)(struct mg_connection *);
typedef int (*mg_error_handler_t)(struct mg_connection *, int http_error_code);
// Server management functions // Server management functions
struct mg_server *mg_create_server(void *server_param); struct mg_server *mg_create_server(void *server_param);
void mg_destroy_server(struct mg_server **); void mg_destroy_server(struct mg_server **);
const char *mg_set_option(struct mg_server *, const char *opt, const char *val); const char *mg_set_option(struct mg_server *, const char *opt, const char *val);
void mg_poll_server(struct mg_server *, int milliseconds); void mg_poll_server(struct mg_server *, int milliseconds);
void mg_add_uri_handler(struct mg_server *, const char *uri, mg_uri_handler_t); void mg_add_uri_handler(struct mg_server *, const char *uri, mg_handler_t);
#if 0 void mg_set_error_handler(struct mg_server *, mg_handler_t);
void mg_set_error_handler(struct mg_server *, mg_error_handler_t); void mg_set_log_handler(struct mg_server*, mg_handler_t);
void mg_set_log_handler(struct mg_server*, int (*)(struct mg_connection*, int));
#endif
const char **mg_get_valid_option_names(void); const char **mg_get_valid_option_names(void);
const char *mg_get_option(const struct mg_server *server, const char *name); const char *mg_get_option(const struct mg_server *server, const char *name);
...@@ -73,16 +71,10 @@ const char *mg_get_option(const struct mg_server *server, const char *name); ...@@ -73,16 +71,10 @@ const char *mg_get_option(const struct mg_server *server, const char *name);
int mg_write(struct mg_connection *, const void *buf, int len); int mg_write(struct mg_connection *, const void *buf, int len);
const char *mg_get_header(const struct mg_connection *, const char *name); const char *mg_get_header(const struct mg_connection *, const char *name);
const char *mg_get_mime_type(const char *file_name); const char *mg_get_mime_type(const char *file_name);
int mg_get_var(const struct mg_connection *conn,
#if 0
int mg_printf(struct mg_connection *, const char *fmt, ...);
void mg_send_file(struct mg_connection *, const char *path);
int mg_read(struct mg_connection *, void *buf, int len);
int mg_get_var(const char *data, size_t data_len,
const char *var_name, char *dst, size_t dst_len); const char *var_name, char *dst, size_t dst_len);
int mg_get_cookie(const char *cookie, const char *var_name, int mg_get_cookie(const char *cookie, const char *var_name,
char *buf, size_t buf_len); char *buf, size_t buf_len);
#endif
// Utility functions // Utility functions
int mg_start_thread(void *(*func)(void *), void *param); int mg_start_thread(void *(*func)(void *), void *param);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment