Update Files
This commit is contained in:
42
Kinc/Sources/kinc/libs/core/cgi/CMakeLists.txt
Normal file
42
Kinc/Sources/kinc/libs/core/cgi/CMakeLists.txt
Normal file
@ -0,0 +1,42 @@
|
||||
#
|
||||
# libwebsockets - small server side websockets and web server implementation
|
||||
#
|
||||
# Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com>
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to
|
||||
# deal in the Software without restriction, including without limitation the
|
||||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
# sell copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
#
|
||||
# The strategy is to only export to PARENT_SCOPE
|
||||
#
|
||||
# - changes to LIB_LIST
|
||||
# - changes to SOURCES
|
||||
# - includes via include_directories
|
||||
#
|
||||
# and keep everything else private
|
||||
|
||||
include_directories(.)
|
||||
|
||||
list(APPEND SOURCES
|
||||
roles/cgi/cgi-server.c
|
||||
roles/cgi/ops-cgi.c)
|
||||
|
||||
#
|
||||
# Keep explicit parent scope exports at end
|
||||
#
|
||||
|
||||
exports_to_parent_scope()
|
1110
Kinc/Sources/kinc/libs/core/cgi/cgi-server.c
Normal file
1110
Kinc/Sources/kinc/libs/core/cgi/cgi-server.c
Normal file
File diff suppressed because it is too large
Load Diff
182
Kinc/Sources/kinc/libs/core/cgi/ops-cgi.c
Normal file
182
Kinc/Sources/kinc/libs/core/cgi/ops-cgi.c
Normal file
@ -0,0 +1,182 @@
|
||||
/*
|
||||
* libwebsockets - small server side websockets and web server implementation
|
||||
*
|
||||
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <private-lib-core.h>
|
||||
|
||||
static int
|
||||
rops_handle_POLLIN_cgi(struct lws_context_per_thread *pt, struct lws *wsi,
|
||||
struct lws_pollfd *pollfd)
|
||||
{
|
||||
struct lws_cgi_args args;
|
||||
|
||||
assert(wsi->role_ops == &role_ops_cgi);
|
||||
|
||||
if (wsi->lsp_channel >= LWS_STDOUT &&
|
||||
!(pollfd->revents & pollfd->events & LWS_POLLIN))
|
||||
return LWS_HPI_RET_PLEASE_CLOSE_ME;
|
||||
|
||||
if (wsi->lsp_channel == LWS_STDIN &&
|
||||
!(pollfd->revents & pollfd->events & LWS_POLLOUT))
|
||||
return LWS_HPI_RET_PLEASE_CLOSE_ME;
|
||||
|
||||
if (wsi->lsp_channel == LWS_STDIN &&
|
||||
lws_change_pollfd(wsi, LWS_POLLOUT, 0)) {
|
||||
lwsl_wsi_info(wsi, "failed at set pollfd");
|
||||
return LWS_HPI_RET_WSI_ALREADY_DIED;
|
||||
}
|
||||
|
||||
if (!wsi->parent) {
|
||||
lwsl_wsi_debug(wsi, "stdwsi content with parent");
|
||||
|
||||
return LWS_HPI_RET_HANDLED;
|
||||
}
|
||||
|
||||
if (!wsi->parent->http.cgi) {
|
||||
lwsl_wsi_notice(wsi, "stdwsi content with deleted cgi object");
|
||||
|
||||
return LWS_HPI_RET_HANDLED;
|
||||
}
|
||||
|
||||
if (!wsi->parent->http.cgi->lsp) {
|
||||
lwsl_wsi_notice(wsi, "stdwsi content with reaped lsp");
|
||||
|
||||
return LWS_HPI_RET_HANDLED;
|
||||
}
|
||||
|
||||
args.ch = wsi->lsp_channel;
|
||||
args.stdwsi = &wsi->parent->http.cgi->lsp->stdwsi[0];
|
||||
args.hdr_state = (enum lws_cgi_hdr_state)wsi->hdr_state;
|
||||
|
||||
lwsl_wsi_debug(wsi, "CGI LWS_STDOUT %p wsistate 0x%x",
|
||||
wsi->parent, wsi->wsistate);
|
||||
|
||||
if (user_callback_handle_rxflow(wsi->parent->a.protocol->callback,
|
||||
wsi->parent, LWS_CALLBACK_CGI,
|
||||
wsi->parent->user_space,
|
||||
(void *)&args, 0))
|
||||
return 1;
|
||||
|
||||
return LWS_HPI_RET_HANDLED;
|
||||
}
|
||||
|
||||
static int
|
||||
rops_handle_POLLOUT_cgi(struct lws *wsi)
|
||||
{
|
||||
return LWS_HP_RET_USER_SERVICE;
|
||||
}
|
||||
|
||||
static int
|
||||
rops_destroy_role_cgi(struct lws *wsi)
|
||||
{
|
||||
#if defined(LWS_WITH_ZLIB)
|
||||
if (!wsi->http.cgi)
|
||||
return 0;
|
||||
if (!wsi->http.cgi->gzip_init)
|
||||
return 0;
|
||||
|
||||
inflateEnd(&wsi->http.cgi->inflate);
|
||||
wsi->http.cgi->gzip_init = 0;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
lws_cgi_sul_cb(lws_sorted_usec_list_t *sul)
|
||||
{
|
||||
struct lws_context_per_thread *pt = lws_container_of(sul,
|
||||
struct lws_context_per_thread, sul_cgi);
|
||||
|
||||
lws_cgi_kill_terminated(pt);
|
||||
|
||||
if (pt->http.cgi_list)
|
||||
lws_sul_schedule(pt->context, (int)(pt - pt->context->pt),
|
||||
&pt->sul_cgi, lws_cgi_sul_cb, 3 * LWS_US_PER_SEC);
|
||||
}
|
||||
|
||||
static int
|
||||
rops_pt_init_destroy_cgi(struct lws_context *context,
|
||||
const struct lws_context_creation_info *info,
|
||||
struct lws_context_per_thread *pt, int destroy)
|
||||
{
|
||||
|
||||
lws_sul_cancel(&pt->sul_cgi);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
rops_close_role_cgi(struct lws_context_per_thread *pt, struct lws *wsi)
|
||||
{
|
||||
if (wsi->parent && wsi->parent->http.cgi && wsi->parent->http.cgi->lsp)
|
||||
lws_spawn_stdwsi_closed(wsi->parent->http.cgi->lsp, wsi);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const lws_rops_t rops_table_cgi[] = {
|
||||
/* 1 */ { .pt_init_destroy = rops_pt_init_destroy_cgi },
|
||||
/* 2 */ { .handle_POLLIN = rops_handle_POLLIN_cgi },
|
||||
/* 3 */ { .handle_POLLOUT = rops_handle_POLLOUT_cgi },
|
||||
/* 4 */ { .close_role = rops_close_role_cgi },
|
||||
/* 5 */ { .destroy_role = rops_destroy_role_cgi },
|
||||
};
|
||||
|
||||
const struct lws_role_ops role_ops_cgi = {
|
||||
/* role name */ "cgi",
|
||||
/* alpn id */ NULL,
|
||||
|
||||
/* rops_table */ rops_table_cgi,
|
||||
/* rops_idx */ {
|
||||
/* LWS_ROPS_check_upgrades */
|
||||
/* LWS_ROPS_pt_init_destroy */ 0x01,
|
||||
/* LWS_ROPS_init_vhost */
|
||||
/* LWS_ROPS_destroy_vhost */ 0x00,
|
||||
/* LWS_ROPS_service_flag_pending */
|
||||
/* LWS_ROPS_handle_POLLIN */ 0x02,
|
||||
/* LWS_ROPS_handle_POLLOUT */
|
||||
/* LWS_ROPS_perform_user_POLLOUT */ 0x30,
|
||||
/* LWS_ROPS_callback_on_writable */
|
||||
/* LWS_ROPS_tx_credit */ 0x00,
|
||||
/* LWS_ROPS_write_role_protocol */
|
||||
/* LWS_ROPS_encapsulation_parent */ 0x00,
|
||||
/* LWS_ROPS_alpn_negotiated */
|
||||
/* LWS_ROPS_close_via_role_protocol */ 0x00,
|
||||
/* LWS_ROPS_close_role */
|
||||
/* LWS_ROPS_close_kill_connection */ 0x40,
|
||||
/* LWS_ROPS_destroy_role */
|
||||
/* LWS_ROPS_adoption_bind */ 0x50,
|
||||
/* LWS_ROPS_client_bind */
|
||||
/* LWS_ROPS_issue_keepalive */ 0x00,
|
||||
},
|
||||
|
||||
/* adoption_cb clnt, srv */ { 0, 0 },
|
||||
/* rx_cb clnt, srv */ { 0, 0 },
|
||||
/* writeable cb clnt, srv */ { 0, 0 },
|
||||
/* close cb clnt, srv */ { 0, 0 },
|
||||
/* protocol_bind_cb c,s */ { 0, 0 },
|
||||
/* protocol_unbind_cb c,s */ { 0, 0 },
|
||||
|
||||
/* file_handle */ 0,
|
||||
};
|
93
Kinc/Sources/kinc/libs/core/cgi/private-lib-roles-cgi.h
Normal file
93
Kinc/Sources/kinc/libs/core/cgi/private-lib-roles-cgi.h
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* libwebsockets - small server side websockets and web server implementation
|
||||
*
|
||||
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* This is included from private-lib-core.h if LWS_ROLE_WS
|
||||
*/
|
||||
|
||||
#if defined(LWS_WITH_ZLIB)
|
||||
#if defined(LWS_WITH_MINIZ)
|
||||
#include <miniz.h>
|
||||
#else
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern const struct lws_role_ops role_ops_cgi;
|
||||
|
||||
#define lwsi_role_cgi(wsi) (wsi->role_ops == &role_ops_cgi)
|
||||
|
||||
#define LWS_HTTP_CHUNK_HDR_SIZE 16
|
||||
|
||||
enum {
|
||||
SIGNIFICANT_HDR_CONTENT_LENGTH, /* numeric */
|
||||
SIGNIFICANT_HDR_LOCATION,
|
||||
SIGNIFICANT_HDR_STATUS, /* numeric */
|
||||
SIGNIFICANT_HDR_TRANSFER_ENCODING,
|
||||
SIGNIFICANT_HDR_CONTENT_ENCODING_GZIP,
|
||||
|
||||
SIGNIFICANT_HDR_COUNT
|
||||
};
|
||||
|
||||
struct lws;
|
||||
|
||||
/* wsi who is owns the cgi points to an lws_cgi */
|
||||
|
||||
struct lws_cgi {
|
||||
struct lws_cgi *cgi_list;
|
||||
|
||||
struct lws_spawn_piped *lsp;
|
||||
lws_sorted_usec_list_t sul_grace;
|
||||
|
||||
struct lws *wsi; /* owner */
|
||||
unsigned char *headers_buf;
|
||||
unsigned char *headers_start;
|
||||
unsigned char *headers_pos;
|
||||
unsigned char *headers_dumped;
|
||||
unsigned char *headers_end;
|
||||
|
||||
char summary[128];
|
||||
#if defined(LWS_WITH_ZLIB)
|
||||
z_stream inflate;
|
||||
uint8_t inflate_buf[1024];
|
||||
#endif
|
||||
|
||||
lws_filepos_t post_in_expected;
|
||||
lws_filepos_t content_length;
|
||||
lws_filepos_t content_length_seen;
|
||||
|
||||
pid_t pi;
|
||||
|
||||
int match[SIGNIFICANT_HDR_COUNT];
|
||||
char l[12];
|
||||
int response_code;
|
||||
int lp;
|
||||
|
||||
unsigned char being_closed:1;
|
||||
unsigned char explicitly_chunked:1;
|
||||
unsigned char cgi_transaction_over:1;
|
||||
unsigned char implied_chunked:1;
|
||||
unsigned char gzip_inflate:1;
|
||||
unsigned char gzip_init:1;
|
||||
|
||||
unsigned char chunked_grace;
|
||||
};
|
Reference in New Issue
Block a user