Lines Matching +full:- +full:- +full:no +full:- +full:check +full:- +full:certificate
19 * No one should expect a full mmap for Windows here.
81 lua_rawset(L, -3);
95 lua_rawset(L, -3);
108 lua_rawset(L, -3);
118 lua_rawset(L, -3);
132 lua_rawset(L, -3);
142 lua_rawset(L, -3);
164 lua_tostring(L, -1));
171 lua_tostring(L, -1));
190 lua_tostring(L, -1));
206 if ((num_args == 1) && lua_istable(L, -1)) {
207 lua_getfield(L, -1, "sock");
208 psock = (SOCKET *)lua_tolstring(L, -1, &s);
229 if ((num_args == 1) && lua_istable(L, -1)) {
230 lua_getfield(L, -1, "sock");
231 psock = (SOCKET *)lua_tolstring(L, -1, &s);
257 if ((num_args == 2) && lua_istable(L, -2) && lua_isstring(L, -1)) {
258 buf = lua_tolstring(L, -1, &len);
259 lua_getfield(L, -2, "sock");
260 psock = (SOCKET *)lua_tolstring(L, -1, &s);
266 if ((n = send(*psock, buf + sent, (int)(len - sent), 0)) <= 0) {
285 if ((num_args == 1) && lua_istable(L, -1)) {
286 lua_getfield(L, -1, "sock");
287 psock = (SOCKET *)lua_tolstring(L, -1, &s);
300 /* Methods and meta-methods supported by the object returned by connect.
301 * For meta-methods, see http://lua-users.org/wiki/MetatableEvents */
317 if ((num_args == 3) && lua_isstring(L, -3) && lua_isnumber(L, -2)
318 && lua_isnumber(L, -1)) {
320 lua_tostring(L, -3),
321 (int)lua_tonumber(L, -2),
322 (int)lua_tonumber(L, -1),
333 reg_string(L, "host", lua_tostring(L, -4));
335 lua_setmetatable(L, -2);
349 lua_getfield(L, -1, "onerror");
350 lua_pushvalue(L, -3);
363 lua_setfield(L, -2, "onerror");
388 switch (reader->state) {
391 reader->consumed = 0;
397 ret = reader->begin;
398 *sz = (size_t)reader->len;
399 reader->consumed += reader->len;
413 reader->state++;
430 if (reader->state == 0) {
431 /* First call: Send opening tag - what function to call */
434 reader->state = 1;
435 reader->consumed = 0;
439 if (reader->state == 4) {
445 left = reader->len - reader->consumed;
451 reader->state = 4; /* Next will be the final call */
459 if (reader->state == 1) {
460 /* State 1: plain text - put inside mg.write(...) */
463 while ((i < left) && (reader->begin[i + reader->consumed] != '<')) {
468 int64_t j = reader->consumed;
469 reader->consumed += i;
471 return reader->begin + j;
474 /* assert (reader->begin[reader->state] == '<') */
476 if (0 == memcmp(reader->begin + reader->consumed, "<?lua", 5)) {
479 reader->tag = '?';
481 } else if (0 == memcmp(reader->begin + reader->consumed, "<%", 2)) {
484 reader->tag = '%';
486 } else if (0 == memcmp(reader->begin + reader->consumed, "<?", 2)) {
489 reader->tag = '?';
497 if (reader->begin[reader->consumed + i] == '=') {
498 /* Lua= tag - Lua expression to print */
500 reader->state = 3;
503 /* Normal Lua tag - Lua chunk */
505 reader->state = 2;
508 reader->consumed += i; /* length of <?lua or <% tag */
512 if ((reader->state == 2) || (reader->state == 3)) {
513 /* State 2: Lua chunkg - keep outside mg.write(...) */
514 /* State 3: Lua expression - inside mg.write(...) */
521 && (reader->begin[i + reader->consumed] != reader->tag)) {
526 int64_t j = reader->consumed;
527 reader->consumed += i;
530 return reader->begin + j;
536 && (reader->begin[i + 1 + reader->consumed] == '>'));
540 reader->consumed += 2;
542 if (reader->state == 2) {
549 reader->state = 1;
584 conn->must_close = 1;
595 "Content-Type: text/html; charset=utf-8\r\n\r\n",
637 conn->must_close = 1;
661 /* no additional letters to skip, only "<?" */
665 /* Check for '=' in "<?= ..." or "<%= ..." or "<?lua= ..." */
682 /* Check for closing tag. */
688 mg_write(conn, p + pos, i - pos);
710 data.len = j - (i + 3 + s);
720 j - (i + 2 + s),
735 i = pos - 1;
751 mg_write(conn, p + pos, i - pos);
801 /* mg.keep_alive: Allow Lua pages to use the http keep-alive mechanism */
813 conn->must_close = !lua_toboolean(L, 1);
854 include_history = (struct lsp_include_history *)lua_touserdata(L, -1);
856 if (include_history->depth >= ((int)(LSP_INCLUDE_MAX_DEPTH))) {
877 conn->dom_ctx->config[DOCUMENT_ROOT],
901 include_history->script[include_history->depth]);
911 sizeof(file_name_path) - len,
925 * non-zero.
951 mg_cry_internal(conn, "%s", lua_tostring(L, -1));
970 conn->request_info.local_uri = target;
1032 d = (double)ts.tv_sec + ((double)ts.tv_nsec * 1.0E-9);
1050 ctx = (struct mg_context *)lua_touserdata(L, -1);
1058 /* Allocate dynamically, so there is no internal limit for get_var */
1126 ctx = (struct mg_context *)lua_touserdata(L, -1);
1206 ctx = (struct mg_context *)lua_touserdata(L, -1);
1246 ctx = (struct mg_context *)lua_touserdata(L, -1);
1285 ctx = (struct mg_context *)lua_touserdata(L, -1);
1322 ctx = (struct mg_context *)lua_touserdata(L, -1);
1333 if (ret != -1) {
1372 if (text) { /* <-- should be always true */
1384 /* mg.random - might be better than math.random on some systems */
1394 * https://en.wikipedia.org/wiki/Double-precision_floating-point_format
1395 * Thus, mask with 2^53-1 to get an integer with the maximum
1397 r &= ((((uint64_t)1) << 53) - 1);
1444 ctx = (struct mg_context *)lua_touserdata(L, -1);
1496 ctx = (struct mg_context *)lua_touserdata(L, -1);
1502 idx--;
1551 if (!opts) { /* <-- should be always false */
1556 while (opts->name) {
1557 optidx = get_option_index(opts->name);
1559 data = conn->dom_ctx->config[optidx];
1561 reg_string(L, opts->name, data);
1577 data = conn->dom_ctx->config[optidx];
1624 "{%08lX-%04X-%04X-%02X%02X-"
1667 int opcode = -1;
1673 ws = (struct lua_websock_data *)lua_touserdata(L, -1);
1675 (void)pthread_mutex_lock(&(ws->ws_mutex));
1734 for (i = 0; i < ws->references; i++) {
1735 if (client == ws->conn[i]) {
1736 mg_lock_connection(ws->conn[i]);
1737 mg_websocket_write(ws->conn[i], opcode, str, size);
1738 mg_unlock_connection(ws->conn[i]);
1742 for (i = 0; i < ws->references; i++) {
1743 mg_lock_connection(ws->conn[i]);
1744 mg_websocket_write(ws->conn[i], opcode, str, size);
1745 mg_unlock_connection(ws->conn[i]);
1749 (void)pthread_mutex_unlock(&(ws->ws_mutex));
1753 (void)pthread_mutex_unlock(&(ws->ws_mutex));
1776 (void)pthread_mutex_lock(arg->pmutex);
1778 lua_pushlightuserdata(arg->state, (void *)&lua_regkey_ctx);
1779 lua_gettable(arg->state, LUA_REGISTRYINDEX);
1780 ctx = (struct mg_context *)lua_touserdata(arg->state, -1);
1781 lua_pop(arg->state, 1);
1783 err = luaL_loadstring(arg->state, arg->txt);
1787 fake_connection(&fc, ctx), err, arg->state, arg->script, "timer");
1788 (void)pthread_mutex_unlock(arg->pmutex);
1792 err = lua_pcall(arg->state, 0, 1, 0);
1796 fake_connection(&fc, ctx), err, arg->state, arg->script, "timer");
1797 (void)pthread_mutex_unlock(arg->pmutex);
1802 ok = lua_type(arg->state, -1);
1803 if (lua_isboolean(arg->state, -1)) {
1804 ok = lua_toboolean(arg->state, -1);
1808 lua_pop(arg->state, 1);
1810 (void)pthread_mutex_unlock(arg->pmutex);
1844 ctx = (struct mg_context *)lua_touserdata(L, -1);
1848 ws = (struct lua_websock_data *)lua_touserdata(L, -1);
1869 arg->state = L;
1870 arg->script = ws->script;
1871 arg->pmutex = &(ws->ws_mutex);
1872 memcpy(arg->txt, "return(", 7);
1873 memcpy(arg->txt + 7, txt, txt_len);
1874 arg->txt[txt_len + 7] = ')';
1875 arg->txt[txt_len + 8] = 0;
1927 if (ar->event == LUA_HOOKCALL) {
1929 } else if (ar->event == LUA_HOOKRET) {
1932 } else if (ar->event == LUA_HOOKTAILRET) {
1936 } else if (ar->event == LUA_HOOKTAILCALL) {
1939 } else if (ar->event == LUA_HOOKLINE) {
1941 } else if (ar->event == LUA_HOOKCOUNT) {
1944 printf("unknown (%i)\n", ar->event);
1947 if (ar->currentline >= 0) {
1948 printf("%s:%i\n", ar->source, ar->currentline);
1951 printf("%s (%s)\n", ar->name, ar->namewhat);
2013 reg_string(L, "request_method", conn->request_info.request_method);
2014 reg_string(L, "request_uri", conn->request_info.request_uri);
2015 reg_string(L, "uri", conn->request_info.local_uri);
2016 reg_string(L, "http_version", conn->request_info.http_version);
2017 reg_string(L, "query_string", conn->request_info.query_string);
2018 reg_string(L, "remote_addr", conn->request_info.remote_addr);
2020 reg_int(L, "remote_port", conn->request_info.remote_port);
2021 reg_int(L, "num_headers", conn->request_info.num_headers);
2022 reg_int(L, "server_port", ntohs(conn->client.lsa.sin.sin_port));
2024 if (conn->path_info != NULL) {
2025 reg_string(L, "path_info", conn->path_info);
2028 if (conn->request_info.content_length >= 0) {
2033 (lua_Number)conn->request_info
2035 lua_rawset(L, -3);
2037 if ((s = mg_get_header(conn, "Content-Type")) != NULL) {
2041 if (conn->request_info.remote_user != NULL) {
2042 reg_string(L, "remote_user", conn->request_info.remote_user);
2046 reg_boolean(L, "https", conn->ssl != NULL);
2048 if (conn->status_code > 0) {
2050 reg_int(L, "status", conn->status_code);
2056 for (i = 0; i < conn->request_info.num_headers; i++) {
2058 conn->request_info.http_headers[i].name,
2059 conn->request_info.http_headers[i].value);
2061 lua_rawset(L, -3);
2063 /* Table "Client Certificate" */
2064 if (conn->request_info.client_cert) {
2067 reg_string(L, "subject", conn->request_info.client_cert->subject);
2068 reg_string(L, "issuer", conn->request_info.client_cert->issuer);
2069 reg_string(L, "serial", conn->request_info.client_cert->serial);
2070 reg_string(L, "finger", conn->request_info.client_cert->finger);
2071 lua_rawset(L, -3);
2075 lua_rawset(L, -3);
2092 /* In CivetWeb, Lua-Shared is used as *.inl file */
2140 /* Check if debugging should be enabled */
2141 if ((conn != NULL) && (conn->dom_ctx != NULL)) {
2142 debug_params = conn->dom_ctx->config[LUA_DEBUG_PARAMS];
2153 lua_pushvalue(L, -1);
2154 lua_setfield(L, -2, "__index");
2244 if ((conn != NULL) && (conn->dom_ctx != NULL)) {
2245 reg_string(L, "document_root", conn->dom_ctx->config[DOCUMENT_ROOT]);
2248 conn->dom_ctx->config[AUTHENTICATION_DOMAIN]);
2250 if (conn->dom_ctx->config[WEBSOCKET_ROOT]) {
2253 conn->dom_ctx->config[WEBSOCKET_ROOT]);
2257 conn->dom_ctx->config[DOCUMENT_ROOT]);
2261 if ((ctx != NULL) && (ctx->systemName != NULL)) {
2262 reg_string(L, "system", ctx->systemName);
2283 /* Check if a preload file is available */
2284 if ((conn != NULL) && (conn->dom_ctx != NULL)) {
2285 preload_file_name = conn->dom_ctx->config[LUA_PRELOAD_FILE];
2295 if (ctx->callbacks.init_lua != NULL) {
2296 ctx->callbacks.init_lua(conn, L);
2320 const char *error_msg = lua_isstring(L, -1) ? lua_tostring(L, -1) : "?\n";
2323 if (!lua_isnil(L, -1)) {
2324 lua_getfield(L, -1, "write"); /* call mg.write() */
2351 conn->must_close = 1;
2355 && (L = lua_newstate(lua_allocator, (void *)(conn->phys_ctx)))
2358 conn->phys_ctx, conn, NULL, L, path, LUA_ENV_TYPE_PLAIN_LUA_PAGE);
2369 lua_rawset(L, -3);
2384 lua_pcall(L, 0, 0, -2);
2428 file_in_memory = filep->access.membuf;
2436 (size_t)filep->stat.size,
2439 fileno(filep->access.fp),
2444 * Since wi have no data, show an error. */
2446 /* No open Lua state - use generic error function */
2453 /* Lua state exists - use Lua error function */
2457 (size_t)filep->stat.size,
2458 fileno(filep->access.fp),
2475 L = lua_newstate(lua_allocator, (void *)(conn->phys_ctx));
2491 conn->phys_ctx, conn, NULL, L, path, LUA_ENV_TYPE_LUA_SERVER_PAGE);
2497 include_history = (struct lsp_include_history *)lua_touserdata(L, -1);
2500 include_history->depth++;
2501 include_history->script[include_history->depth] = path;
2516 * - In the "classic" CivetWeb syntax, the Lua Page had to send the HTTP
2519 * Content-Type: text/html
2523 * Page, but starts directly with <html> code - so it cannot influence
2527 * - The "Kepler Syntax" used to allow mixtures of Lua and HTML inside an
2533 * than for "classic" CivetWeb syntax - TODO: check timing/performance.
2548 run_lsp(conn, path, addr, filep->stat.size, L, include_history->depth);
2555 munmap(p, filep->stat.size);
2556 (void)mg_fclose(&filep->access);
2573 &(conn->dom_ctx->shared_lua_websockets);
2577 DEBUG_ASSERT(conn->lua_websocket_state == NULL);
2580 mg_lock_context(conn->phys_ctx);
2582 /* check if ws already in list */
2583 if (0 == strcmp(script, (*shared_websock_list)->ws.script)) {
2586 shared_websock_list = &((*shared_websock_list)->next);
2593 sizeof(struct mg_shared_lua_websocket_list), 1, conn->phys_ctx);
2595 conn->must_close = 1;
2596 mg_unlock_context(conn->phys_ctx);
2603 ws = &(*shared_websock_list)->ws;
2604 ws->script = mg_strdup_ctx(script, conn->phys_ctx);
2605 if (!ws->script) {
2606 conn->must_close = 1;
2607 mg_unlock_context(conn->phys_ctx);
2613 pthread_mutex_init(&(ws->ws_mutex), &pthread_mutex_attr);
2614 (void)pthread_mutex_lock(&(ws->ws_mutex));
2615 ws->state = lua_newstate(lua_allocator, (void *)(conn->phys_ctx));
2616 ws->conn[0] = conn;
2617 ws->references = 1;
2618 prepare_lua_environment(conn->phys_ctx,
2621 ws->state,
2624 err = luaL_loadfile(ws->state, script);
2626 lua_cry(conn, err, ws->state, script, "load");
2628 err = lua_pcall(ws->state, 0, 0, 0);
2630 lua_cry(conn, err, ws->state, script, "init");
2634 ws = &(*shared_websock_list)->ws;
2635 (void)pthread_mutex_lock(&(ws->ws_mutex));
2636 (*shared_websock_list)->ws.conn[(ws->references)++] = conn;
2638 mg_unlock_context(conn->phys_ctx);
2641 lua_getglobal(ws->state, "open");
2642 lua_newtable(ws->state);
2643 prepare_lua_request_info(conn, ws->state);
2644 lua_pushstring(ws->state, "client");
2645 lua_pushlightuserdata(ws->state, (void *)conn);
2646 lua_rawset(ws->state, -3);
2648 err = lua_pcall(ws->state, 1, 1, 0);
2650 lua_cry(conn, err, ws->state, script, "open handler");
2652 if (lua_isboolean(ws->state, -1)) {
2653 ok = lua_toboolean(ws->state, -1);
2655 lua_pop(ws->state, 1);
2659 /* TODO (mid): Check if list entry and Lua state needs to be deleted
2661 (*shared_websock_list)->ws.conn[--(ws->references)] = 0;
2664 (void)pthread_mutex_unlock(&(ws->ws_mutex));
2681 DEBUG_ASSERT(ws->state != NULL);
2683 (void)pthread_mutex_lock(&(ws->ws_mutex));
2685 lua_getglobal(ws->state, "data");
2686 lua_newtable(ws->state);
2687 lua_pushstring(ws->state, "client");
2688 lua_pushlightuserdata(ws->state, (void *)conn);
2689 lua_rawset(ws->state, -3);
2690 lua_pushstring(ws->state, "bits"); /* TODO: dont use "bits" but fields with
2694 lua_pushnumber(ws->state, bits);
2695 lua_rawset(ws->state, -3);
2696 lua_pushstring(ws->state, "data");
2697 lua_pushlstring(ws->state, data, data_len);
2698 lua_rawset(ws->state, -3);
2700 err = lua_pcall(ws->state, 1, 1, 0);
2702 lua_cry(conn, err, ws->state, ws->script, "data handler");
2704 if (lua_isboolean(ws->state, -1)) {
2705 ok = lua_toboolean(ws->state, -1);
2707 lua_pop(ws->state, 1);
2709 (void)pthread_mutex_unlock(&(ws->ws_mutex));
2722 DEBUG_ASSERT(ws->state != NULL);
2724 (void)pthread_mutex_lock(&(ws->ws_mutex));
2726 lua_getglobal(ws->state, "ready");
2727 lua_newtable(ws->state);
2728 lua_pushstring(ws->state, "client");
2729 lua_pushlightuserdata(ws->state, (void *)conn);
2730 lua_rawset(ws->state, -3);
2731 err = lua_pcall(ws->state, 1, 1, 0);
2733 lua_cry(conn, err, ws->state, ws->script, "ready handler");
2735 if (lua_isboolean(ws->state, -1)) {
2736 ok = lua_toboolean(ws->state, -1);
2738 lua_pop(ws->state, 1);
2741 (void)pthread_mutex_unlock(&(ws->ws_mutex));
2752 &(conn->dom_ctx->shared_lua_websockets);
2757 DEBUG_ASSERT(ws->state != NULL);
2759 (void)pthread_mutex_lock(&(ws->ws_mutex));
2761 lua_getglobal(ws->state, "close");
2762 lua_newtable(ws->state);
2763 lua_pushstring(ws->state, "client");
2764 lua_pushlightuserdata(ws->state, (void *)conn);
2765 lua_rawset(ws->state, -3);
2767 err = lua_pcall(ws->state, 1, 0, 0);
2769 lua_cry(conn, err, ws->state, ws->script, "close handler");
2771 for (i = 0; i < ws->references; i++) {
2772 if (ws->conn[i] == conn) {
2773 ws->references--;
2774 ws->conn[i] = ws->conn[ws->references];
2782 (void)pthread_mutex_unlock(&(ws->ws_mutex));
2802 NULL, /* No truncation check for ebuf */
2816 lua_err_txt = lua_tostring(L, -1);
2818 NULL, /* No truncation check for ebuf */
2829 /* no arguments */ 0,
2835 lua_err_txt = lua_tostring(L, -1);
2837 NULL, /* No truncation check for ebuf */
2860 if (lua_type(L, -1) == LUA_TNUMBER) {
2861 func_ret = (int)lua_tonumber(L, -1);