mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-27 06:51:04 +08:00
Added MG_INIT_LUA event
This commit is contained in:
parent
6205e69ab2
commit
b437d56736
@ -49,6 +49,8 @@ WEBSOCKET_CONNECT = 5
|
||||
WEBSOCKET_READY = 6
|
||||
WEBSOCKET_MESSAGE = 7
|
||||
WEBSOCKET_CLOSE = 8
|
||||
OPEN_FILE = 9
|
||||
INIT_LUA = 10
|
||||
|
||||
|
||||
class mg_header(ctypes.Structure):
|
||||
|
@ -4005,7 +4005,6 @@ static void prepare_lua_environment(struct mg_connection *conn, lua_State *L) {
|
||||
static void handle_lsp_request(struct mg_connection *conn, const char *path,
|
||||
struct file *filep) {
|
||||
void *p = NULL;
|
||||
FILE *fp = NULL;
|
||||
lua_State *L = NULL;
|
||||
|
||||
if (!mg_fopen(conn, path, "r", filep)) {
|
||||
@ -4020,13 +4019,14 @@ static void handle_lsp_request(struct mg_connection *conn, const char *path,
|
||||
mg_printf(conn, "%s", "HTTP/1.1 200 OK\r\n"
|
||||
"Content-Type: text/html\r\nConnection: close\r\n\r\n");
|
||||
prepare_lua_environment(conn, L);
|
||||
conn->request_info.ev_data = L;
|
||||
call_user(conn, MG_INIT_LUA);
|
||||
lsp(conn, filep->membuf == NULL ? p : filep->membuf, filep->size, L);
|
||||
}
|
||||
|
||||
if (L) lua_close(L);
|
||||
if (p) munmap(p, st->size);
|
||||
if (fp) fclose(fp);
|
||||
|
||||
if (p) munmap(p, filep->size);
|
||||
mg_fclose(filep);
|
||||
}
|
||||
#endif // USE_LUA
|
||||
|
||||
|
35
mongoose.h
35
mongoose.h
@ -82,21 +82,6 @@ enum mg_event {
|
||||
// SSL_CTX *ssl_context = request_info->ev_data;
|
||||
MG_INIT_SSL,
|
||||
|
||||
// Mongoose tries to open file.
|
||||
// If callback returns non-NULL, Mongoose will not try to open it, but
|
||||
// will use the returned value as a pointer to the file data. This allows
|
||||
// for example to serve files from memory.
|
||||
// ev_data contains file path, including document root path.
|
||||
// Upon return, ev_data should return file size, which should be a long int.
|
||||
//
|
||||
// const char *file_name = request_info->ev_data;
|
||||
// if (strcmp(file_name, "foo.txt") == 0) {
|
||||
// request_info->ev_data = (void *) (long) 4;
|
||||
// return "data";
|
||||
// }
|
||||
// return NULL;
|
||||
MG_OPEN_FILE,
|
||||
|
||||
// Sent on HTTP connect, before websocket handshake.
|
||||
// If user callback returns NULL, then mongoose proceeds
|
||||
// with handshake, otherwise it closes the connection.
|
||||
@ -117,6 +102,26 @@ enum mg_event {
|
||||
// Callback's return value is ignored.
|
||||
// ev_data contains NULL.
|
||||
MG_WEBSOCKET_CLOSE,
|
||||
|
||||
// Mongoose tries to open file.
|
||||
// If callback returns non-NULL, Mongoose will not try to open it, but
|
||||
// will use the returned value as a pointer to the file data. This allows
|
||||
// for example to serve files from memory.
|
||||
// ev_data contains file path, including document root path.
|
||||
// Upon return, ev_data should return file size, which should be a long int.
|
||||
//
|
||||
// const char *file_name = request_info->ev_data;
|
||||
// if (strcmp(file_name, "foo.txt") == 0) {
|
||||
// request_info->ev_data = (void *) (long) 4;
|
||||
// return "data";
|
||||
// }
|
||||
// return NULL;
|
||||
MG_OPEN_FILE,
|
||||
|
||||
// Mongoose initializes Lua server page. Sent only if Lua support is enabled.
|
||||
// Callback's return value is ignored.
|
||||
// ev_data contains lua_State pointer.
|
||||
MG_INIT_LUA,
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user