mongoose/mongoose.h

109 lines
4.6 KiB
C
Raw Normal View History

2013-08-16 11:18:16 +01:00
// Copyright (c) 2004-2013 Sergey Lyubka <valenok@gmail.com>
// Copyright (c) 2013-2014 Cesanta Software Limited
2013-08-16 11:18:16 +01:00
// All rights reserved
2010-07-06 23:15:14 +01:00
//
2013-08-16 11:18:16 +01:00
// This library is dual-licensed: you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation. For the terms of this
// license, see <http://www.gnu.org/licenses/>.
2010-07-06 23:15:14 +01:00
//
2013-08-16 11:18:16 +01:00
// You are free to use this library under the terms of the GNU General
// Public License, 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.
2010-07-06 23:15:14 +01:00
//
2013-08-16 11:18:16 +01:00
// Alternatively, you can license this library under a commercial
// license, as set out in <http://cesanta.com/products.html>.
2013-12-09 14:18:49 +00:00
//
// NOTE: Detailed API documentation is at http://cesanta.com/docs.html
#ifndef MONGOOSE_HEADER_INCLUDED
2010-07-06 23:15:14 +01:00
#define MONGOOSE_HEADER_INCLUDED
2014-01-10 22:37:26 +00:00
#define MONGOOSE_VERSION "5.2"
2013-12-09 14:18:49 +00:00
#include <stdio.h> // required for FILE
#include <stddef.h> // required for size_t
#ifdef __cplusplus
extern "C" {
2010-07-06 23:15:14 +01:00
#endif // __cplusplus
2013-12-09 14:18:49 +00:00
// This structure contains information about HTTP request.
struct mg_connection {
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
2013-12-09 14:18:49 +00:00
char remote_ip[48]; // Max IPv6 string length is 45 characters
int remote_port; // Client's port
2013-02-01 16:48:30 +00:00
int num_headers; // Number of HTTP headers
2010-07-06 23:15:14 +01:00
struct mg_header {
const char *name; // HTTP header name
const char *value; // HTTP header value
2013-12-09 14:18:49 +00:00
} http_headers[30];
2013-12-09 14:18:49 +00:00
char *content; // POST (or websocket message) data, or NULL
int content_len; // content length
2013-12-09 14:18:49 +00:00
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
void *server_param; // Parameter passed to mg_add_uri_handler()
void *connection_param; // Placeholder for connection-specific data
};
2013-12-09 14:18:49 +00:00
struct mg_server; // Opaque structure describing server instance
typedef int (*mg_handler_t)(struct mg_connection *);
// Server management functions
struct mg_server *mg_create_server(void *server_param);
void mg_destroy_server(struct mg_server **);
const char *mg_set_option(struct mg_server *, const char *opt, const char *val);
unsigned int mg_poll_server(struct mg_server *, int milliseconds);
2013-12-09 14:18:49 +00:00
void mg_add_uri_handler(struct mg_server *, const char *uri, mg_handler_t);
void mg_set_http_error_handler(struct mg_server *, mg_handler_t);
2013-10-30 23:02:15 +00:00
const char **mg_get_valid_option_names(void);
2013-12-09 14:18:49 +00:00
const char *mg_get_option(const struct mg_server *server, const char *name);
void mg_set_listening_socket(struct mg_server *, int sock);
int mg_get_listening_socket(struct mg_server *);
void mg_iterate_over_connections(struct mg_server *, mg_handler_t, void *);
2013-12-09 14:18:49 +00:00
// Connection management functions
2014-01-04 11:31:55 +00:00
void mg_send_status(struct mg_connection *, int status_code);
void mg_send_header(struct mg_connection *, const char *name, const char *val);
void mg_send_data(struct mg_connection *, const void *data, int data_len);
void mg_printf_data(struct mg_connection *, const char *format, ...);
2013-12-09 14:18:49 +00:00
int mg_websocket_write(struct mg_connection *, int opcode,
const char *data, size_t data_len);
2014-01-04 11:31:55 +00:00
// Deprecated in favor of mg_send_* interface
int mg_write(struct mg_connection *, const void *buf, int len);
2013-12-26 10:12:18 +00:00
int mg_printf(struct mg_connection *conn, const char *fmt, ...);
2014-01-04 11:31:55 +00:00
const char *mg_get_header(const struct mg_connection *, const char *name);
2013-12-09 14:18:49 +00:00
const char *mg_get_mime_type(const char *file_name);
int mg_get_var(const struct mg_connection *conn, const char *var_name,
char *buf, size_t buf_len);
int mg_parse_header(const char *hdr, const char *var_name, char *buf, size_t);
2014-01-13 16:29:12 +00:00
int mg_parse_multipart(const char *buf, int buf_len,
char *var_name, int var_name_len,
char *file_name, int file_name_len,
const char **data, int *data_len);
2013-12-09 14:18:49 +00:00
// Utility functions
void *mg_start_thread(void *(*func)(void *), void *param);
2013-03-27 01:31:12 -07:00
char *mg_md5(char buf[33], ...);
2014-01-11 16:44:37 +00:00
int mg_authorize_digest(struct mg_connection *c, FILE *fp);
void mg_send_digest_auth_request(struct mg_connection *conn);
2010-05-05 00:39:36 +01:00
#ifdef __cplusplus
}
2010-07-06 23:15:14 +01:00
#endif // __cplusplus
2010-07-06 23:15:14 +01:00
#endif // MONGOOSE_HEADER_INCLUDED