mirror of
https://github.com/cesanta/mongoose.git
synced 2025-01-14 09:48:01 +08:00
API change: added void *user_data to mg_start(). Bumped version to 3.0
This commit is contained in:
parent
7034f49276
commit
11951a57ff
@ -144,7 +144,7 @@ class Mongoose(object):
|
|||||||
args = [y for x in kwargs.items() for y in x] + [None]
|
args = [y for x in kwargs.items() for y in x] + [None]
|
||||||
options = (ctypes.c_char_p * len(args))(*args)
|
options = (ctypes.c_char_p * len(args))(*args)
|
||||||
|
|
||||||
ret = self.dll.mg_start(self.callback, options)
|
ret = self.dll.mg_start(self.callback, 0, options)
|
||||||
self.ctx = ctypes.c_void_p(ret)
|
self.ctx = ctypes.c_void_p(ret)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
|
4
main.c
4
main.c
@ -95,7 +95,7 @@ static int mg_edit_passwords(const char *fname, const char *domain,
|
|||||||
int success;
|
int success;
|
||||||
|
|
||||||
options[1] = domain;
|
options[1] = domain;
|
||||||
ctx = mg_start(NULL, options);
|
ctx = mg_start(NULL, NULL, options);
|
||||||
success = mg_modify_passwords_file(ctx, fname, user, pass);
|
success = mg_modify_passwords_file(ctx, fname, user, pass);
|
||||||
mg_stop(ctx);
|
mg_stop(ctx);
|
||||||
|
|
||||||
@ -256,7 +256,7 @@ static void start_mongoose(int argc, char *argv[]) {
|
|||||||
signal(SIGINT, signal_handler);
|
signal(SIGINT, signal_handler);
|
||||||
|
|
||||||
/* Start Mongoose */
|
/* Start Mongoose */
|
||||||
ctx = mg_start(NULL, (const char **) options);
|
ctx = mg_start(NULL, NULL, (const char **) options);
|
||||||
for (i = 0; options[i] != NULL; i++) {
|
for (i = 0; options[i] != NULL; i++) {
|
||||||
free(options[i]);
|
free(options[i]);
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,7 @@ typedef int SOCKET;
|
|||||||
|
|
||||||
#include "mongoose.h"
|
#include "mongoose.h"
|
||||||
|
|
||||||
#define MONGOOSE_VERSION "2.12"
|
#define MONGOOSE_VERSION "3.0"
|
||||||
#define PASSWORDS_FILE_NAME ".htpasswd"
|
#define PASSWORDS_FILE_NAME ".htpasswd"
|
||||||
#define CGI_ENVIRONMENT_SIZE 4096
|
#define CGI_ENVIRONMENT_SIZE 4096
|
||||||
#define MAX_CGI_ENVIR_VARS 64
|
#define MAX_CGI_ENVIR_VARS 64
|
||||||
@ -421,6 +421,7 @@ struct mg_context {
|
|||||||
SSL_CTX *ssl_ctx; // SSL context
|
SSL_CTX *ssl_ctx; // SSL context
|
||||||
char *config[NUM_OPTIONS]; // Mongoose configuration parameters
|
char *config[NUM_OPTIONS]; // Mongoose configuration parameters
|
||||||
mg_callback_t user_callback; // User-defined callback function
|
mg_callback_t user_callback; // User-defined callback function
|
||||||
|
void *user_data; // User-defined data
|
||||||
|
|
||||||
struct socket *listening_sockets;
|
struct socket *listening_sockets;
|
||||||
|
|
||||||
@ -456,6 +457,7 @@ const char **mg_get_valid_option_names(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void *call_user(struct mg_connection *conn, enum mg_event event) {
|
static void *call_user(struct mg_connection *conn, enum mg_event event) {
|
||||||
|
conn->request_info.user_data = conn->ctx->user_data;
|
||||||
return conn->ctx->user_callback == NULL ? NULL :
|
return conn->ctx->user_callback == NULL ? NULL :
|
||||||
conn->ctx->user_callback(event, conn, &conn->request_info);
|
conn->ctx->user_callback(event, conn, &conn->request_info);
|
||||||
}
|
}
|
||||||
@ -3984,7 +3986,8 @@ void mg_stop(struct mg_context *ctx) {
|
|||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mg_context *mg_start(mg_callback_t user_callback, const char **options) {
|
struct mg_context *mg_start(mg_callback_t user_callback, void *user_data,
|
||||||
|
const char **options) {
|
||||||
struct mg_context *ctx;
|
struct mg_context *ctx;
|
||||||
const char *name, *value, *default_value;
|
const char *name, *value, *default_value;
|
||||||
int i;
|
int i;
|
||||||
@ -3998,6 +4001,7 @@ struct mg_context *mg_start(mg_callback_t user_callback, const char **options) {
|
|||||||
// TODO(lsm): do proper error handling here.
|
// TODO(lsm): do proper error handling here.
|
||||||
ctx = calloc(1, sizeof(*ctx));
|
ctx = calloc(1, sizeof(*ctx));
|
||||||
ctx->user_callback = user_callback;
|
ctx->user_callback = user_callback;
|
||||||
|
ctx->user_data = user_data;
|
||||||
|
|
||||||
while (options && (name = *options++) != NULL) {
|
while (options && (name = *options++) != NULL) {
|
||||||
if ((i = get_option_index(name)) == -1) {
|
if ((i = get_option_index(name)) == -1) {
|
||||||
|
@ -31,6 +31,7 @@ struct mg_connection; // Handle for the individual connection
|
|||||||
|
|
||||||
// This structure contains information about the HTTP request.
|
// This structure contains information about the HTTP request.
|
||||||
struct mg_request_info {
|
struct mg_request_info {
|
||||||
|
void *user_data; // User-defined pointer passed to mg_start()
|
||||||
char *request_method; // "GET", "POST", etc
|
char *request_method; // "GET", "POST", etc
|
||||||
char *uri; // URL-decoded URI
|
char *uri; // URL-decoded URI
|
||||||
char *http_version; // E.g. "1.0", "1.1"
|
char *http_version; // E.g. "1.0", "1.1"
|
||||||
@ -76,7 +77,7 @@ enum mg_event {
|
|||||||
typedef void * (*mg_callback_t)(enum mg_event event,
|
typedef void * (*mg_callback_t)(enum mg_event event,
|
||||||
struct mg_connection *conn,
|
struct mg_connection *conn,
|
||||||
const struct mg_request_info *request_info);
|
const struct mg_request_info *request_info);
|
||||||
|
|
||||||
|
|
||||||
// Start web server.
|
// Start web server.
|
||||||
//
|
//
|
||||||
@ -98,7 +99,8 @@ typedef void * (*mg_callback_t)(enum mg_event event,
|
|||||||
//
|
//
|
||||||
// Return:
|
// Return:
|
||||||
// web server context, or NULL on error.
|
// web server context, or NULL on error.
|
||||||
struct mg_context *mg_start(mg_callback_t callback, const char **options);
|
struct mg_context *mg_start(mg_callback_t callback, void *user_data,
|
||||||
|
const char **options);
|
||||||
|
|
||||||
|
|
||||||
// Stop the web server.
|
// Stop the web server.
|
||||||
|
@ -167,7 +167,7 @@ int main(void) {
|
|||||||
struct mg_context *ctx;
|
struct mg_context *ctx;
|
||||||
const char *options[] = {"listening_ports", LISTENING_PORT, NULL};
|
const char *options[] = {"listening_ports", LISTENING_PORT, NULL};
|
||||||
|
|
||||||
ctx = mg_start(callback, options);
|
ctx = mg_start(callback, NULL, options);
|
||||||
pause();
|
pause();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user