The attached patch is a proposed solution to a problem I am having with interfacing with the mongoose httpd for which I've found no canonical (or any other) clean solution.
The problem is that some of the data structures needed for some operations, specifically writing callbacks that get invoked for some HTTP requests, are declared in mongoose.c and therefore are not available to external programs, i.e. clients of mongoose. This is the mg_connection struct & its dependencies. It is passed as an argument to callbacks, and even without referencing the object the code won't compile if the struct isn't fully known. The change is moving some declarations from mongoose.c to mongoose.h. Unfortunately this diverges from the original code, then again mongoose isn't tracked any more since the license change I take it, so perhaps that's not so bad. I've made the changes __rtems__-conditional so it's clear where the divergence is.
From 60e135fcc6ae74aa334211046b8f8cc6dd413041 Mon Sep 17 00:00:00 2001 From: Ben Gras <b...@shrike-systems.com> Date: Tue, 18 Nov 2014 17:29:36 +0100 Subject: [PATCH] mongoose.h --- cpukit/mghttpd/mongoose.c | 21 +++++++++++++++ cpukit/mghttpd/mongoose.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/cpukit/mghttpd/mongoose.c b/cpukit/mghttpd/mongoose.c index dd243d3..e1e2c1e 100644 --- a/cpukit/mghttpd/mongoose.c +++ b/cpukit/mghttpd/mongoose.c @@ -245,11 +245,22 @@ typedef struct DIR { #define ERRNO errno #define INVALID_SOCKET (-1) #define INT64_FMT PRId64 +#ifndef __rtems__ /* defined in mongoose.h for RTEMS */ typedef int SOCKET; +#endif #define WINCDECL #endif // End of Windows and UNIX specific includes +#ifdef __rtems__ + +/* For RTEMS, some definitions are moved from mongoose.c to mongoose.h. + * See mongoose.h for more info. - BJG 18/11/2014 + */ + +#include "mongoose.h" +#endif + #ifndef HAVE_POLL struct pollfd { SOCKET fd; @@ -259,7 +270,9 @@ struct pollfd { #define POLLIN 1 #endif +#ifndef __rtems__ #include "mongoose.h" +#endif #define MONGOOSE_VERSION "3.9" #define PASSWORDS_FILE_NAME ".htpasswd" @@ -327,11 +340,13 @@ static const char *http_500_error = "Internal Server Error"; #include <openssl/ssl.h> #include <openssl/err.h> #else +#if !defined(__rtems__) /* defined in mongoose.h for RTEMS */ // SSL loaded dynamically from DLL. // I put the prototypes here to be independent from OpenSSL source installation. typedef struct ssl_st SSL; typedef struct ssl_method_st SSL_METHOD; typedef struct ssl_ctx_st SSL_CTX; +#endif /* !defined(__rtems__) */ struct ssl_func { const char *name; // SSL function name @@ -419,6 +434,7 @@ static const char *month_names[] = { "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; +#if !defined(__rtems__) /* defined in mongoose.h for RTEMS */ // Unified socket address. For IPv6 support, add IPv6 address structure // in the union u. union usa { @@ -428,6 +444,7 @@ union usa { struct sockaddr_in6 sin6; #endif }; +#endif /* !defined(__rtems__) */ // Describes a string (chunk of memory). struct vec { @@ -447,6 +464,7 @@ struct file { }; #define STRUCT_FILE_INITIALIZER {0, 0, 0, NULL, NULL, 0} +#if !defined(__rtems__) /* defined in mongoose.h for RTEMS */ // Describes listening socket, or socket which was accept()-ed by the master // thread and queued for future handling by the worker thread. struct socket { @@ -456,6 +474,7 @@ struct socket { unsigned is_ssl:1; // Is port SSL-ed unsigned ssl_redir:1; // Is port supposed to redirect everything to SSL port }; +#endif /* !defined(__rtems__) */ // NOTE(lsm): this enum shoulds be in sync with the config_options below. enum { @@ -522,6 +541,7 @@ struct mg_context { pthread_cond_t sq_empty; // Signaled when socket is consumed }; +#if !defined(__rtems__) /* defined in mongoose.h for RTEMS */ struct mg_connection { struct mg_request_info request_info; struct mg_context *ctx; @@ -543,6 +563,7 @@ struct mg_connection { time_t last_throttle_time; // Last time throttled data was sent int64_t last_throttle_bytes;// Bytes sent this second }; +#endif // Directory entry struct de { diff --git a/cpukit/mghttpd/mongoose.h b/cpukit/mghttpd/mongoose.h index ad7c40f..cd09b33 100644 --- a/cpukit/mghttpd/mongoose.h +++ b/cpukit/mghttpd/mongoose.h @@ -29,8 +29,51 @@ extern "C" { #endif // __cplusplus struct mg_context; // Handle for the HTTP service itself +#ifndef __rtems__ struct mg_connection; // Handle for the individual connection +#else + +/* For RTEMS, some definitions are moved from mongoose.c to mongoose.h. + * The purpose is so that clients of the mongoose functions can get + * passed objects of type mg_connection, which is needed for callbacks. + * For RTEMS, therefore we include mg_connection and its dependencies + * in mongoose.h and remove them from mongoose.c. + * + * - BJG 18/11/2014 + */ + +#if !defined(NO_SSL_DL) +typedef struct ssl_st SSL; +typedef struct ssl_method_st SSL_METHOD; +typedef struct ssl_ctx_st SSL_CTX; +#endif +typedef int SOCKET; +struct socket; + +#include <sys/socket.h> +#include <netinet/in.h> + +// Unified socket address. For IPv6 support, add IPv6 address structure +// in the union u. +union usa { + struct sockaddr sa; + struct sockaddr_in sin; +#if defined(USE_IPV6) + struct sockaddr_in6 sin6; +#endif +}; + +// Describes listening socket, or socket which was accept()-ed by the master +// thread and queued for future handling by the worker thread. +struct socket { + SOCKET sock; // Listening socket + union usa lsa; // Local socket address + union usa rsa; // Remote socket address + unsigned is_ssl:1; // Is port SSL-ed + unsigned ssl_redir:1; // Is port supposed to redirect everything to SSL port +}; +#endif /* __rtems__ */ // This structure contains information about the HTTP request. struct mg_request_info { @@ -52,6 +95,30 @@ struct mg_request_info { } http_headers[64]; // Maximum 64 headers }; +#ifdef __rtems__ +struct mg_connection { + struct mg_request_info request_info; + struct mg_context *ctx; + SSL *ssl; // SSL descriptor + SSL_CTX *client_ssl_ctx; // SSL context for client connections + struct socket client; // Connected client + time_t birth_time; // Time when request was received + int64_t num_bytes_sent; // Total bytes sent to client + int64_t content_len; // Content-Length header value + int64_t consumed_content; // How many bytes of content have been read + char *buf; // Buffer for received data + char *path_info; // PATH_INFO part of the URL + int must_close; // 1 if connection must be closed + int buf_size; // Buffer size + int request_len; // Size of the request + headers in a buffer + int data_len; // Total size of data in a buffer + int status_code; // HTTP reply status code, e.g. 200 + int throttle; // Throttling, bytes/sec. <= 0 means no throttle + time_t last_throttle_time; // Last time throttled data was sent + int64_t last_throttle_bytes;// Bytes sent this second +}; +#endif /* __rtems__ */ + // This structure needs to be passed to mg_start(), to let mongoose know // which callbacks to invoke. For detailed description, see -- 1.9.1
_______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel