Commit ae611a6e authored by Sergey Lyubka's avatar Sergey Lyubka Committed by Cesanta Bot

Clean up v7 from mongoose

PUBLISHED_FROM=efa9cc3aaf0c5ae8841e029370f882b615cebf1b
parent a7a2e3de
...@@ -11,7 +11,6 @@ items: ...@@ -11,7 +11,6 @@ items:
- { name: mg_check_ip_acl.md } - { name: mg_check_ip_acl.md }
- { name: mg_connect.md } - { name: mg_connect.md }
- { name: mg_connect_opt.md } - { name: mg_connect_opt.md }
- { name: mg_enable_javascript.md }
- { name: mg_mgr_free.md } - { name: mg_mgr_free.md }
- { name: mg_mgr_init.md } - { name: mg_mgr_init.md }
- { name: mg_mgr_init_opt.md } - { name: mg_mgr_init_opt.md }
......
---
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: | ...@@ -14,9 +14,6 @@ signature: |
void *user_data; /* User data */ void *user_data; /* User data */
int num_ifaces; int num_ifaces;
struct mg_iface **ifaces; /* network interfaces */ struct mg_iface **ifaces; /* network interfaces */
#if MG_ENABLE_JAVASCRIPT
struct v7 *v7;
#endif
const char *nameserver; /* DNS server to use */ const char *nameserver; /* DNS server to use */
}; };
--- ---
......
...@@ -317,7 +317,7 @@ void cs_log_set_filter(char *str) { ...@@ -317,7 +317,7 @@ void cs_log_set_filter(char *str) {
s_filter_pattern = NULL; s_filter_pattern = NULL;
s_filter_pattern_len = 0; 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, const char *, const char *) WEAK;
int cs_log_print_prefix(enum cs_log_level level, const char *func, 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, ...@@ -2281,32 +2281,6 @@ void mg_mgr_init_opt(struct mg_mgr *m, void *user_data,
DBG(("init mgr=%p", m)); 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) { void mg_mgr_free(struct mg_mgr *m) {
struct mg_connection *conn, *tmp_conn; struct mg_connection *conn, *tmp_conn;
...@@ -5995,57 +5969,8 @@ void mg_http_handler(struct mg_connection *nc, int ev, ...@@ -5995,57 +5969,8 @@ void mg_http_handler(struct mg_connection *nc, int ev,
MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT); MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
DBG(("%p %s %.*s %.*s", nc, addr, (int) hm->method.len, hm->method.p, DBG(("%p %s %.*s %.*s", nc, addr, (int) hm->method.len, hm->method.p,
(int) hm->uri.len, hm->uri.p)); (int) hm->uri.len, hm->uri.p));
/* Whole HTTP message is fully buffered, call event handler */
/* 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
mg_http_call_endpoint_handler(nc, trigger_ev, hm); mg_http_call_endpoint_handler(nc, trigger_ev, hm);
#endif
mbuf_remove(io, hm->message.len); mbuf_remove(io, hm->message.len);
} }
} }
......
...@@ -2939,10 +2939,6 @@ struct { \ ...@@ -2939,10 +2939,6 @@ struct { \
#define MG_ENABLE_IPV6 0 #define MG_ENABLE_IPV6 0
#endif #endif
#ifndef MG_ENABLE_JAVASCRIPT
#define MG_ENABLE_JAVASCRIPT 0
#endif
#ifndef MG_ENABLE_MQTT #ifndef MG_ENABLE_MQTT
#define MG_ENABLE_MQTT 1 #define MG_ENABLE_MQTT 1
#endif #endif
...@@ -3243,11 +3239,6 @@ int mg_ssl_if_write(struct mg_connection *nc, const void *data, size_t len); ...@@ -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_ #ifndef CS_MONGOOSE_SRC_NET_H_
#define 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/common.h" */
/* Amalgamated: #include "mongoose/src/net_if.h" */ /* Amalgamated: #include "mongoose/src/net_if.h" */
/* Amalgamated: #include "common/mbuf.h" */ /* Amalgamated: #include "common/mbuf.h" */
...@@ -3310,9 +3301,6 @@ struct mg_mgr { ...@@ -3310,9 +3301,6 @@ struct mg_mgr {
void *user_data; /* User data */ void *user_data; /* User data */
int num_ifaces; int num_ifaces;
struct mg_iface **ifaces; /* network interfaces */ struct mg_iface **ifaces; /* network interfaces */
#if MG_ENABLE_JAVASCRIPT
struct v7 *v7;
#endif
const char *nameserver; /* DNS server to use */ 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); ...@@ -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); 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. * Schedules an MG_EV_TIMER event to be delivered at `timestamp` time.
* `timestamp` is UNIX time (the number of seconds since Epoch). It is * `timestamp` is UNIX time (the number of seconds since Epoch). It is
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment