mongoose.h
Go to the documentation of this file.
00001 // Copyright (c) 2004-2013 Sergey Lyubka <valenok@gmail.com>
00002 // Copyright (c) 2013-2014 Cesanta Software Limited
00003 // All rights reserved
00004 //
00005 // This software is dual-licensed: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License version 2 as
00007 // published by the Free Software Foundation. For the terms of this
00008 // license, see <http://www.gnu.org/licenses/>.
00009 //
00010 // You are free to use this software under the terms of the GNU General
00011 // Public License, but WITHOUT ANY WARRANTY; without even the implied
00012 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00013 // See the GNU General Public License for more details.
00014 //
00015 // Alternatively, you can license this software under a commercial
00016 // license, as set out in <http://cesanta.com/>.
00017 
00018 #ifndef MONGOOSE_HEADER_INCLUDED
00019 #define  MONGOOSE_HEADER_INCLUDED
00020 
00021 #define MONGOOSE_VERSION "5.6"
00022 
00023 #include <stdio.h>      // required for FILE
00024 #include <stddef.h>     // required for size_t
00025 #include <sys/types.h>  // required for time_t
00026 
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif // __cplusplus
00030 
00031 // This structure contains information about HTTP request.
00032 struct mg_connection {
00033   const char *request_method; // "GET", "POST", etc
00034   const char *uri;            // URL-decoded URI
00035   const char *http_version;   // E.g. "1.0", "1.1"
00036   const char *query_string;   // URL part after '?', not including '?', or NULL
00037 
00038   char remote_ip[48];         // Max IPv6 string length is 45 characters
00039   char local_ip[48];          // Local IP address
00040   unsigned short remote_port; // Client's port
00041   unsigned short local_port;  // Local port number
00042 
00043   int num_headers;            // Number of HTTP headers
00044   struct mg_header {
00045     const char *name;         // HTTP header name
00046     const char *value;        // HTTP header value
00047   } http_headers[30];
00048 
00049   char *content;              // POST (or websocket message) data, or NULL
00050   size_t content_len;         // Data length
00051 
00052   int is_websocket;           // Connection is a websocket connection
00053   int status_code;            // HTTP status code for HTTP error handler
00054   int wsbits;                 // First byte of the websocket frame
00055   void *server_param;         // Parameter passed to mg_create_server()
00056   void *connection_param;     // Placeholder for connection-specific data
00057   void *callback_param;
00058 };
00059 
00060 struct mg_server; // Opaque structure describing server instance
00061 enum mg_result { MG_FALSE, MG_TRUE, MG_MORE };
00062 enum mg_event {
00063   MG_POLL = 100,  // Callback return value is ignored
00064   MG_CONNECT,     // If callback returns MG_FALSE, connect fails
00065   MG_AUTH,        // If callback returns MG_FALSE, authentication fails
00066   MG_REQUEST,     // If callback returns MG_FALSE, Mongoose continues with req
00067   MG_REPLY,       // If callback returns MG_FALSE, Mongoose closes connection
00068   MG_RECV,        // Mongoose has received POST data chunk.
00069                   // Callback should return a number of bytes to discard from
00070                   // the receive buffer, or -1 to close the connection.
00071   MG_CLOSE,       // Connection is closed, callback return value is ignored
00072   MG_WS_HANDSHAKE,  // New websocket connection, handshake request
00073   MG_WS_CONNECT,  // New websocket connection established
00074   MG_HTTP_ERROR   // If callback returns MG_FALSE, Mongoose continues with err
00075 };
00076 typedef int (*mg_handler_t)(struct mg_connection *, enum mg_event);
00077 
00078 // Websocket opcodes, from http://tools.ietf.org/html/rfc6455
00079 enum {
00080   WEBSOCKET_OPCODE_CONTINUATION = 0x0,
00081   WEBSOCKET_OPCODE_TEXT = 0x1,
00082   WEBSOCKET_OPCODE_BINARY = 0x2,
00083   WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
00084   WEBSOCKET_OPCODE_PING = 0x9,
00085   WEBSOCKET_OPCODE_PONG = 0xa
00086 };
00087 
00088 // Server management functions
00089 struct mg_server *mg_create_server(void *server_param, mg_handler_t handler);
00090 void mg_destroy_server(struct mg_server **);
00091 const char *mg_set_option(struct mg_server *, const char *opt, const char *val);
00092 time_t mg_poll_server(struct mg_server *, int milliseconds);
00093 const char **mg_get_valid_option_names(void);
00094 const char *mg_get_option(const struct mg_server *server, const char *name);
00095 void mg_copy_listeners(struct mg_server *from, struct mg_server *to);
00096 struct mg_connection *mg_next(struct mg_server *, struct mg_connection *);
00097 void mg_wakeup_server(struct mg_server *);
00098 void mg_wakeup_server_ex(struct mg_server *, mg_handler_t, const char *, ...);
00099 struct mg_connection *mg_connect(struct mg_server *, const char *);
00100 
00101 // Connection management functions
00102 void mg_send_status(struct mg_connection *, int status_code);
00103 void mg_send_header(struct mg_connection *, const char *name, const char *val);
00104 size_t mg_send_data(struct mg_connection *, const void *data, int data_len);
00105 size_t mg_printf_data(struct mg_connection *, const char *format, ...);
00106 size_t mg_write(struct mg_connection *, const void *buf, size_t len);
00107 size_t mg_printf(struct mg_connection *conn, const char *fmt, ...);
00108 
00109 size_t mg_websocket_write(struct mg_connection *, int opcode,
00110                           const char *data, size_t data_len);
00111 size_t mg_websocket_printf(struct mg_connection* conn, int opcode,
00112                            const char *fmt, ...);
00113 
00114 void mg_send_file(struct mg_connection *, const char *path, const char *);
00115 void mg_send_file_data(struct mg_connection *, int fd);
00116 
00117 const char *mg_get_header(const struct mg_connection *, const char *name);
00118 const char *mg_get_mime_type(const char *name, const char *default_mime_type);
00119 int mg_get_var(const struct mg_connection *conn, const char *var_name,
00120                char *buf, size_t buf_len);
00121 int mg_parse_header(const char *hdr, const char *var_name, char *buf, size_t);
00122 int mg_parse_multipart(const char *buf, int buf_len,
00123                        char *var_name, int var_name_len,
00124                        char *file_name, int file_name_len,
00125                        const char **data, int *data_len);
00126 
00127 
00128 // Utility functions
00129 void *mg_start_thread(void *(*func)(void *), void *param);
00130 char *mg_md5(char buf[33], ...);
00131 int mg_authorize_digest(struct mg_connection *c, FILE *fp);
00132 size_t mg_url_encode(const char *src, size_t s_len, char *dst, size_t dst_len);
00133 int mg_url_decode(const char *src, size_t src_len, char *dst, size_t dst_len, int);
00134 int mg_terminate_ssl(struct mg_connection *c, const char *cert);
00135 int mg_forward(struct mg_connection *c, const char *addr);
00136 void *mg_mmap(FILE *fp, size_t size);
00137 void mg_munmap(void *p, size_t size);
00138 
00139 
00140 // Templates support
00141 struct mg_expansion {
00142   const char *keyword;
00143   void (*handler)(struct mg_connection *);
00144 };
00145 void mg_template(struct mg_connection *, const char *text,
00146                  struct mg_expansion *expansions);
00147 
00148 #ifdef __cplusplus
00149 }
00150 #endif // __cplusplus
00151 
00152 #endif // MONGOOSE_HEADER_INCLUDED


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05