mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-27 15:01:03 +08:00
Clean up v7 from mongoose
PUBLISHED_FROM=efa9cc3aaf0c5ae8841e029370f882b615cebf1b
This commit is contained in:
parent
a7a2e3deb1
commit
ae611a6e55
@ -11,7 +11,6 @@ items:
|
||||
- { name: mg_check_ip_acl.md }
|
||||
- { name: mg_connect.md }
|
||||
- { name: mg_connect_opt.md }
|
||||
- { name: mg_enable_javascript.md }
|
||||
- { name: mg_mgr_free.md }
|
||||
- { name: mg_mgr_init.md }
|
||||
- { name: mg_mgr_init_opt.md }
|
||||
|
@ -1,14 +0,0 @@
|
||||
---
|
||||
title: "mg_enable_javascript()"
|
||||
decl_name: "mg_enable_javascript"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
enum v7_err mg_enable_javascript(struct mg_mgr *m, struct v7 *v7,
|
||||
const char *init_js_file_name);
|
||||
---
|
||||
|
||||
Enables server-side JavaScript scripting.
|
||||
Requires a `-DMG_ENABLE_JAVASCRIPT` compilation flag and V7 engine sources.
|
||||
V7 instance must not be destroyed during manager's lifetime.
|
||||
Returns a V7 error.
|
||||
|
@ -14,9 +14,6 @@ signature: |
|
||||
void *user_data; /* User data */
|
||||
int num_ifaces;
|
||||
struct mg_iface **ifaces; /* network interfaces */
|
||||
#if MG_ENABLE_JAVASCRIPT
|
||||
struct v7 *v7;
|
||||
#endif
|
||||
const char *nameserver; /* DNS server to use */
|
||||
};
|
||||
---
|
||||
|
79
mongoose.c
79
mongoose.c
@ -317,7 +317,7 @@ void cs_log_set_filter(char *str) {
|
||||
s_filter_pattern = NULL;
|
||||
s_filter_pattern_len = 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
int cs_log_print_prefix(enum cs_log_level, const char *, const char *) WEAK;
|
||||
int cs_log_print_prefix(enum cs_log_level level, const char *func,
|
||||
@ -2281,32 +2281,6 @@ void mg_mgr_init_opt(struct mg_mgr *m, void *user_data,
|
||||
DBG(("init mgr=%p", m));
|
||||
}
|
||||
|
||||
#if MG_ENABLE_JAVASCRIPT
|
||||
static enum v7_err mg_send_js(struct v7 *v7, v7_val_t *res) {
|
||||
v7_val_t arg0 = v7_arg(v7, 0);
|
||||
v7_val_t arg1 = v7_arg(v7, 1);
|
||||
struct mg_connection *c = (struct mg_connection *) v7_get_ptr(v7, arg0);
|
||||
size_t len = 0;
|
||||
|
||||
if (v7_is_string(arg1)) {
|
||||
const char *data = v7_get_string(v7, &arg1, &len);
|
||||
mg_send(c, data, len);
|
||||
}
|
||||
|
||||
*res = v7_mk_number(v7, len);
|
||||
|
||||
return V7_OK;
|
||||
}
|
||||
|
||||
enum v7_err mg_enable_javascript(struct mg_mgr *m, struct v7 *v7,
|
||||
const char *init_file_name) {
|
||||
v7_val_t v;
|
||||
m->v7 = v7;
|
||||
v7_set_method(v7, v7_get_global(v7), "mg_send", mg_send_js);
|
||||
return v7_exec_file(v7, init_file_name, &v);
|
||||
}
|
||||
#endif
|
||||
|
||||
void mg_mgr_free(struct mg_mgr *m) {
|
||||
struct mg_connection *conn, *tmp_conn;
|
||||
|
||||
@ -5995,57 +5969,8 @@ void mg_http_handler(struct mg_connection *nc, int ev,
|
||||
MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
|
||||
DBG(("%p %s %.*s %.*s", nc, addr, (int) hm->method.len, hm->method.p,
|
||||
(int) hm->uri.len, hm->uri.p));
|
||||
|
||||
/* Whole HTTP message is fully buffered, call event handler */
|
||||
|
||||
#if MG_ENABLE_JAVASCRIPT
|
||||
v7_val_t v1, v2, headers, req, args, res;
|
||||
struct v7 *v7 = nc->mgr->v7;
|
||||
const char *ev_name = trigger_ev == MG_EV_HTTP_REPLY ? "onsnd" : "onrcv";
|
||||
int i, js_callback_handled_request = 0;
|
||||
|
||||
if (v7 != NULL) {
|
||||
/* Lookup JS callback */
|
||||
v1 = v7_get(v7, v7_get_global(v7), "Http", ~0);
|
||||
v2 = v7_get(v7, v1, ev_name, ~0);
|
||||
|
||||
/* Create callback params. TODO(lsm): own/disown those */
|
||||
args = v7_mk_array(v7);
|
||||
req = v7_mk_object(v7);
|
||||
headers = v7_mk_object(v7);
|
||||
|
||||
/* Populate request object */
|
||||
v7_set(v7, req, "method", ~0,
|
||||
v7_mk_string(v7, hm->method.p, hm->method.len, 1));
|
||||
v7_set(v7, req, "uri", ~0, v7_mk_string(v7, hm->uri.p, hm->uri.len, 1));
|
||||
v7_set(v7, req, "body", ~0,
|
||||
v7_mk_string(v7, hm->body.p, hm->body.len, 1));
|
||||
v7_set(v7, req, "headers", ~0, headers);
|
||||
for (i = 0; hm->header_names[i].len > 0; i++) {
|
||||
const struct mg_str *name = &hm->header_names[i];
|
||||
const struct mg_str *value = &hm->header_values[i];
|
||||
v7_set(v7, headers, name->p, name->len,
|
||||
v7_mk_string(v7, value->p, value->len, 1));
|
||||
}
|
||||
|
||||
/* Invoke callback. TODO(lsm): report errors */
|
||||
v7_array_push(v7, args, v7_mk_foreign(v7, nc));
|
||||
v7_array_push(v7, args, req);
|
||||
if (v7_apply(v7, v2, V7_UNDEFINED, args, &res) == V7_OK &&
|
||||
v7_is_truthy(v7, res)) {
|
||||
js_callback_handled_request++;
|
||||
}
|
||||
}
|
||||
|
||||
/* If JS callback returns true, stop request processing */
|
||||
if (js_callback_handled_request) {
|
||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||
} else {
|
||||
mg_http_call_endpoint_handler(nc, trigger_ev, hm);
|
||||
}
|
||||
#else
|
||||
/* Whole HTTP message is fully buffered, call event handler */
|
||||
mg_http_call_endpoint_handler(nc, trigger_ev, hm);
|
||||
#endif
|
||||
mbuf_remove(io, hm->message.len);
|
||||
}
|
||||
}
|
||||
|
23
mongoose.h
23
mongoose.h
@ -2939,10 +2939,6 @@ struct { \
|
||||
#define MG_ENABLE_IPV6 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_JAVASCRIPT
|
||||
#define MG_ENABLE_JAVASCRIPT 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_MQTT
|
||||
#define MG_ENABLE_MQTT 1
|
||||
#endif
|
||||
@ -3243,11 +3239,6 @@ int mg_ssl_if_write(struct mg_connection *nc, const void *data, size_t len);
|
||||
#ifndef CS_MONGOOSE_SRC_NET_H_
|
||||
#define CS_MONGOOSE_SRC_NET_H_
|
||||
|
||||
#if MG_ENABLE_JAVASCRIPT
|
||||
#define EXCLUDE_COMMON
|
||||
#include <v7.h>
|
||||
#endif
|
||||
|
||||
/* Amalgamated: #include "mongoose/src/common.h" */
|
||||
/* Amalgamated: #include "mongoose/src/net_if.h" */
|
||||
/* Amalgamated: #include "common/mbuf.h" */
|
||||
@ -3310,9 +3301,6 @@ struct mg_mgr {
|
||||
void *user_data; /* User data */
|
||||
int num_ifaces;
|
||||
struct mg_iface **ifaces; /* network interfaces */
|
||||
#if MG_ENABLE_JAVASCRIPT
|
||||
struct v7 *v7;
|
||||
#endif
|
||||
const char *nameserver; /* DNS server to use */
|
||||
};
|
||||
|
||||
@ -3777,17 +3765,6 @@ int mg_resolve(const char *domain_name, char *ip_addr_buf, size_t buf_len);
|
||||
*/
|
||||
int mg_check_ip_acl(const char *acl, uint32_t remote_ip);
|
||||
|
||||
#if MG_ENABLE_JAVASCRIPT
|
||||
/*
|
||||
* Enables server-side JavaScript scripting.
|
||||
* Requires a `-DMG_ENABLE_JAVASCRIPT` compilation flag and V7 engine sources.
|
||||
* V7 instance must not be destroyed during manager's lifetime.
|
||||
* Returns a V7 error.
|
||||
*/
|
||||
enum v7_err mg_enable_javascript(struct mg_mgr *m, struct v7 *v7,
|
||||
const char *init_js_file_name);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Schedules an MG_EV_TIMER event to be delivered at `timestamp` time.
|
||||
* `timestamp` is UNIX time (the number of seconds since Epoch). It is
|
||||
|
Loading…
x
Reference in New Issue
Block a user