mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
codacy: minor fixes
This commit is contained in:
parent
546a2800c7
commit
33a6034875
72 changed files with 555 additions and 2270 deletions
|
@ -1772,14 +1772,6 @@ if ((LWS_ROLE_H1 OR LWS_ROLE_H2) AND NOT LWS_WITHOUT_TESTAPPS)
|
|||
|
||||
endif()
|
||||
|
||||
if (UNIX)
|
||||
create_test_app(test-fuzxy "test-apps/fuzxy.c"
|
||||
""
|
||||
""
|
||||
""
|
||||
""
|
||||
"")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[](https://travis-ci.org/warmcat/libwebsockets) [](https://ci.appveyor.com/project/lws-team/libwebsockets) [](https://scan.coverity.com/projects/3576) [](https://bestpractices.coreinfrastructure.org/projects/2266)
|
||||
[](https://travis-ci.org/warmcat/libwebsockets) [](https://ci.appveyor.com/project/lws-team/libwebsockets) [](https://scan.coverity.com/projects/3576) [](https://bestpractices.coreinfrastructure.org/projects/2266) [](https://www.codacy.com/app/lws-team/libwebsockets?utm_source=github.com&utm_medium=referral&utm_content=warmcat/libwebsockets&utm_campaign=Badge_Grade)
|
||||
|
||||

|
||||
|
||||
|
|
|
@ -1,192 +0,0 @@
|
|||
# lws-meta protocol
|
||||
|
||||
lws-meta is a lightweight ws subprotocol that accepts other ws connections
|
||||
to the same server inside it and multiplexes their access to the connection.
|
||||
|
||||
```
|
||||
Client Server
|
||||
|
||||
conn1: \ / :conn1
|
||||
conn2: = mux ------ lws-meta ws protocol ----- mux = :conn2
|
||||
conn3: / \ :conn3
|
||||
```
|
||||
|
||||
You may have n client ws connections back to the server, but you now
|
||||
only have one tcp connection (and one SSL wrapper if using SSL) instead
|
||||
of n of those.
|
||||
|
||||
If you currently make multiple ws connections back to the server, so you
|
||||
can have different protocols active in one webpage, this if for you.
|
||||
|
||||
- The subprotocol code for the connections inside a lws-meta connection
|
||||
need zero changes from being a normal ws connection. It is unaware
|
||||
it is inside an lws-meta parent connection.
|
||||
|
||||
- The traffic on the lws-meta connection is indistinguishable from
|
||||
standard ws traffic, so intermediaries won't object to it
|
||||
|
||||
- The multiplexing is done in the protocol, **not by an extension**. So
|
||||
it's compatible with all browsers.
|
||||
|
||||
- Javascript helper code is provided to very simply use lws-meta
|
||||
protocol instead of direct connections. The lws test server has
|
||||
been converted to use this by default.
|
||||
|
||||
# Converting your server
|
||||
|
||||
1) include the provided lws-meta plugin (plugins/protocl_lws_meta.c) as an
|
||||
active protocol for your server. You can do that using runtime plugins, or
|
||||
include the plugin sources into your server at build-time. The lws test
|
||||
server uses the latter approach.
|
||||
|
||||
That's all you need to do on the server side.
|
||||
|
||||
# Converting your browser JS
|
||||
|
||||
1) import lws-common.js
|
||||
|
||||
2) Instantiate a parent lws-meta connection object
|
||||
|
||||
```
|
||||
var lws_meta = new lws_meta_ws();
|
||||
```
|
||||
|
||||
3) Connect the lws-meta object to your server
|
||||
|
||||
```
|
||||
lws_meta.new_parent(get_appropriate_ws_url("?mirror=" + mirror_name));
|
||||
```
|
||||
|
||||
4) Convert your actual ws connections to go via the lws_meta object
|
||||
|
||||
```
|
||||
var my_ws = lws_meta.new_ws("", "dumb-increment-protocol");
|
||||
```
|
||||
|
||||
The first arg is the URL path, the second arg is the ws protocol you want.
|
||||
|
||||
That's it. my_ws will get `onopen()`, `onmessage()` etc calls as before.
|
||||
|
||||
# lws-meta wire protocol
|
||||
|
||||
lws-meta works by adding some bytes at the start of a message indicating
|
||||
which channel the message applies to.
|
||||
|
||||
Channel messages are atomic on the wire. The reason is if we tried to
|
||||
intersperse other channel fragments between one channels message fragments,
|
||||
an intermediary would observe violations of the ws framing rule about
|
||||
having to start a message with TEXT or BINARY, and use only CONTINUATION
|
||||
for the subsequent fragments. Eg
|
||||
|
||||
```
|
||||
[ ch1 TEXT NOFIN ] [ ch2 BINARY FIN ] [ ch1 CONTINUATION FIN ]
|
||||
```
|
||||
|
||||
is illegal to an observer that doesn't understand lws-meta headers in the
|
||||
packet payloads. So to avoid this situation, only complete messages may
|
||||
be sent from one subchannel in each direction at a time.
|
||||
|
||||
Consequently, only the first fragment of each message is modified to
|
||||
have the extra two bytes identifying the subchannel it is aimed at, since
|
||||
the rest of the message from the same subchannel is defined to follow.
|
||||
|
||||
If it makes latencies, modify the protocol sending large messages to
|
||||
send smaller messages, so the transmission of messages from other channels
|
||||
can be sent inbetween the smaller messages.
|
||||
|
||||
## lws-meta commands
|
||||
|
||||
1) CSTRING indicates a string terminated by 0x00 byte
|
||||
|
||||
2) Channel IDs are sent with 0x20 added to them, to guarantee valid UTF-8
|
||||
|
||||
### 0x41: RX: LWS_META_CMD_OPEN_SUBCHANNEL
|
||||
|
||||
- CSTRING: protocol name
|
||||
- CSTRING: url
|
||||
- CSTRING: cookie (7 bytes max)
|
||||
|
||||
Client is requesting to open a new channel with the given protocol name,
|
||||
at the given url. The cookie (eg, channel name) is only used in
|
||||
LWS_META_CMD_OPEN_RESULT, when the channel id is assigned, so it is
|
||||
applied to the right channel.
|
||||
|
||||
### 0x42: TX: LWS_META_CMD_OPEN_RESULT
|
||||
|
||||
- CSTRING cookie
|
||||
- BYTE channel id (0 indicates failed)
|
||||
- CSTRING: selected protocol name
|
||||
|
||||
The server is informing the client of the results of a previous
|
||||
open request. The cookie the client sent to identify the request
|
||||
is returned along with a channel id to be used subsequently. If
|
||||
the channel ID is 0 (after subtracting the transport offset of
|
||||
0x20) then the open request has failed.
|
||||
|
||||
### 0x43: TX: LWS_META_CMD_CLOSE_NOTIFY
|
||||
|
||||
- BYTE channel id
|
||||
- BYTE: payload length + 0x20
|
||||
- BYTE: close code MSB
|
||||
- BYTE: close code LSB
|
||||
- PAYLOAD: payload (< 123 bytes)
|
||||
|
||||
Server notifies the client that a child has closed, for whatever reason.
|
||||
|
||||
### 0x44: RX: LWS_META_CMD_CLOSE_RQ
|
||||
- BYTE: channel id
|
||||
- BYTE: payload length + 0x20
|
||||
- BYTE: close code MSB
|
||||
- BYTE: close code LSB
|
||||
- PAYLOAD: payload (< 123 bytes)
|
||||
|
||||
The client requests to close a child connection
|
||||
|
||||
### 0x45: TX: LWS_META_CMD_WRITE
|
||||
|
||||
- BYTE: channel id
|
||||
|
||||
Normal write of payload n from lws-meta perspective is actually
|
||||
LWS_META_CMD_WRITE, channel id, then (n - 2) bytes of payload
|
||||
|
||||
The command only appears at the start of a message, continuations do
|
||||
not have the command.
|
||||
|
||||
## Protocol Notes
|
||||
|
||||
- Once the subchannel is up, overhead is only +2 bytes per message
|
||||
|
||||
- Close reasons are supported in both directions
|
||||
|
||||
- Ping and Pong are only supported at the lws-meta level, using normal ws ping and pong packets.
|
||||
|
||||
- Only the final close of the tcp lws-meta connection itself goes out as
|
||||
a normal ws close frame. Subchannels close is done in a normal TEXT
|
||||
message using LWS_META_CMD_CLOSE_RQ and then the close packet payload.
|
||||
This is so intermediaries do not mistake subchannel closures for the
|
||||
tcp / ws link going down.
|
||||
|
||||
Messages that start with LWS_META_CMD_OPEN_SUBCHANNEL only contain those
|
||||
commands but may contain any number of them for the whole duration of the
|
||||
message. The lws-meta js support collects child open requests made before
|
||||
the parent lws-meta connection is open, and dumps them all in a single
|
||||
message when it does open.
|
||||
|
||||
Messages that start with LWS_META_CMD_OPEN_RESULT or LWS_META_CMD_CLOSE_NOTIFY
|
||||
only contain those two commands, but they may contain any number of them
|
||||
for the whole duration of the message.
|
||||
|
||||
|
||||
# Current Implemention Limitations
|
||||
|
||||
- only server side is supported in lws. The client side JS for
|
||||
a browser is supported.
|
||||
|
||||
- max number of child connections per parent at the moment is 8
|
||||
|
||||
- child connection URL paramter when opening the connection is
|
||||
ignored
|
||||
|
||||
- there is no ah attached when the child connections are
|
||||
established inside the lws-meta parent. So header access
|
||||
functions will fail.
|
|
@ -138,7 +138,7 @@ lws_client_connect_via_info(const struct lws_client_connect_info *i)
|
|||
* role finalization
|
||||
*/
|
||||
|
||||
if (wsi && !wsi->user_space && i->userdata) {
|
||||
if (!wsi->user_space && i->userdata) {
|
||||
wsi->user_space_externally_allocated = 1;
|
||||
wsi->user_space = i->userdata;
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ lws_client_connect_via_info(const struct lws_client_connect_info *i)
|
|||
* role finalization
|
||||
*/
|
||||
|
||||
if (wsi && !wsi->user_space && i->userdata) {
|
||||
if (!wsi->user_space && i->userdata) {
|
||||
wsi->user_space_externally_allocated = 1;
|
||||
wsi->user_space = i->userdata;
|
||||
}
|
||||
|
|
|
@ -832,9 +832,6 @@ lws_create_context(const struct lws_context_creation_info *info)
|
|||
|
||||
lwsl_info("Initial logging level %d\n", log_level);
|
||||
lwsl_info("Libwebsockets version: %s\n", library_version);
|
||||
#if defined(GCC_VER)
|
||||
lwsl_info("Compiled with %s\n", GCC_VER);
|
||||
#endif
|
||||
|
||||
#ifdef LWS_WITH_IPV6
|
||||
if (!lws_check_opt(info->options, LWS_SERVER_OPTION_DISABLE_IPV6))
|
||||
|
@ -1241,7 +1238,6 @@ LWS_VISIBLE LWS_EXTERN void
|
|||
lws_context_deprecate(struct lws_context *context, lws_reload_func cb)
|
||||
{
|
||||
struct lws_vhost *vh = context->vhost_list, *vh1;
|
||||
struct lws *wsi;
|
||||
|
||||
/*
|
||||
* "deprecation" means disable the context from accepting any new
|
||||
|
@ -1255,7 +1251,8 @@ lws_context_deprecate(struct lws_context *context, lws_reload_func cb)
|
|||
/* for each vhost, close his listen socket */
|
||||
|
||||
while (vh) {
|
||||
wsi = vh->lserv_wsi;
|
||||
struct lws *wsi = vh->lserv_wsi;
|
||||
|
||||
if (wsi) {
|
||||
wsi->socket_is_permanently_unusable = 1;
|
||||
lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "ctx deprecate");
|
||||
|
@ -1631,11 +1628,12 @@ static void
|
|||
lws_context_destroy3(struct lws_context *context)
|
||||
{
|
||||
struct lws_context **pcontext_finalize = context->pcontext_finalize;
|
||||
struct lws_context_per_thread *pt;
|
||||
int n;
|
||||
|
||||
for (n = 0; n < context->count_threads; n++) {
|
||||
pt = &context->pt[n];
|
||||
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
||||
struct lws_context_per_thread *pt = &context->pt[n];
|
||||
#endif
|
||||
|
||||
if (context->event_loop_ops->destroy_pt)
|
||||
context->event_loop_ops->destroy_pt(context, n);
|
||||
|
@ -1666,7 +1664,6 @@ lws_context_destroy2(struct lws_context *context)
|
|||
#if defined(LWS_WITH_PEER_LIMITS)
|
||||
uint32_t nu;
|
||||
#endif
|
||||
int n;
|
||||
|
||||
lwsl_info("%s: ctx %p\n", __func__, context);
|
||||
|
||||
|
@ -1729,12 +1726,14 @@ lws_context_destroy2(struct lws_context *context)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!context->pt[0].event_loop_foreign)
|
||||
if (!context->pt[0].event_loop_foreign) {
|
||||
int n;
|
||||
for (n = 0; n < context->count_threads; n++)
|
||||
if (context->pt[n].inside_service) {
|
||||
lws_context_unlock(context); /* } context --- */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
lws_context_unlock(context); /* } context ------------------- */
|
||||
|
||||
|
@ -1750,7 +1749,6 @@ lws_context_destroy(struct lws_context *context)
|
|||
{
|
||||
volatile struct lws_foreign_thread_pollfd *ftp, *next;
|
||||
volatile struct lws_context_per_thread *vpt;
|
||||
struct lws_context_per_thread *pt;
|
||||
struct lws_vhost *vh = NULL;
|
||||
struct lws wsi;
|
||||
int n, m;
|
||||
|
@ -1796,7 +1794,7 @@ lws_context_destroy(struct lws_context *context)
|
|||
#endif
|
||||
|
||||
while (m--) {
|
||||
pt = &context->pt[m];
|
||||
struct lws_context_per_thread *pt = &context->pt[m];
|
||||
vpt = (volatile struct lws_context_per_thread *)pt;
|
||||
|
||||
ftp = vpt->foreign_pfd_list;
|
||||
|
|
|
@ -1709,7 +1709,8 @@ lws_rx_flow_control(struct lws *wsi, int _enable)
|
|||
wsi->rxflow_change_to)
|
||||
goto skip;
|
||||
|
||||
wsi->rxflow_change_to = LWS_RXFLOW_PENDING_CHANGE | !wsi->rxflow_bitmap;
|
||||
wsi->rxflow_change_to = LWS_RXFLOW_PENDING_CHANGE |
|
||||
(!wsi->rxflow_bitmap);
|
||||
|
||||
lwsl_info("%s: %p: bitmap 0x%x: en 0x%x, ch 0x%x\n", __func__, wsi,
|
||||
wsi->rxflow_bitmap, en, wsi->rxflow_change_to);
|
||||
|
@ -1850,7 +1851,9 @@ lws_set_proxy(struct lws_vhost *vhost, const char *proxy)
|
|||
|
||||
lwsl_info(" Proxy auth in use\n");
|
||||
|
||||
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
||||
proxy = p + 1;
|
||||
#endif
|
||||
} else
|
||||
vhost->proxy_basic_auth_token[0] = '\0';
|
||||
|
||||
|
@ -1997,7 +2000,9 @@ LWS_VISIBLE int
|
|||
lwsl_timestamp(int level, char *p, int len)
|
||||
{
|
||||
#ifndef LWS_PLAT_OPTEE
|
||||
#ifndef _WIN32_WCE
|
||||
time_t o_now = time(NULL);
|
||||
#endif
|
||||
unsigned long long now;
|
||||
struct tm *ptm = NULL;
|
||||
#ifndef WIN32
|
||||
|
@ -2132,9 +2137,7 @@ LWS_VISIBLE void
|
|||
lwsl_hexdump_level(int hexdump_level, const void *vbuf, size_t len)
|
||||
{
|
||||
unsigned char *buf = (unsigned char *)vbuf;
|
||||
unsigned int n, m, start;
|
||||
char line[80];
|
||||
char *p;
|
||||
unsigned int n;
|
||||
|
||||
if (!lwsl_visible(hexdump_level))
|
||||
return;
|
||||
|
@ -2148,8 +2151,8 @@ lwsl_hexdump_level(int hexdump_level, const void *vbuf, size_t len)
|
|||
_lws_log(hexdump_level, "\n");
|
||||
|
||||
for (n = 0; n < len;) {
|
||||
start = n;
|
||||
p = line;
|
||||
unsigned int start = n, m;
|
||||
char line[80], *p = line;
|
||||
|
||||
p += sprintf(p, "%04X: ", start);
|
||||
|
||||
|
@ -2558,6 +2561,8 @@ lws_socket_bind(struct lws_vhost *vhost, lws_sockfd_type sockfd, int port,
|
|||
struct sockaddr_storage sin;
|
||||
struct sockaddr *v;
|
||||
|
||||
memset(&sin, 0, sizeof(sin));
|
||||
|
||||
#if defined(LWS_WITH_UNIX_SOCK)
|
||||
if (LWS_UNIX_SOCK_ENABLED(vhost)) {
|
||||
v = (struct sockaddr *)&serv_unix;
|
||||
|
@ -3659,9 +3664,10 @@ LWS_VISIBLE LWS_EXTERN void
|
|||
lws_stats_log_dump(struct lws_context *context)
|
||||
{
|
||||
struct lws_vhost *v = context->vhost_list;
|
||||
int n, m;
|
||||
|
||||
(void)m;
|
||||
int n;
|
||||
#if defined(LWS_WITH_PEER_LIMITS)
|
||||
int m;
|
||||
#endif
|
||||
|
||||
if (!context->updated)
|
||||
return;
|
||||
|
|
|
@ -232,7 +232,9 @@ static int
|
|||
__lws_service_timeout_check(struct lws *wsi, time_t sec)
|
||||
{
|
||||
struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi];
|
||||
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
||||
int n = 0;
|
||||
#endif
|
||||
|
||||
(void)n;
|
||||
|
||||
|
@ -244,9 +246,11 @@ __lws_service_timeout_check(struct lws *wsi, time_t sec)
|
|||
lws_compare_time_t(wsi->context, sec, wsi->pending_timeout_set) >
|
||||
wsi->pending_timeout_limit) {
|
||||
|
||||
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
||||
if (wsi->desc.sockfd != LWS_SOCK_INVALID &&
|
||||
wsi->position_in_fds_table >= 0)
|
||||
n = pt->fds[wsi->position_in_fds_table].events;
|
||||
#endif
|
||||
|
||||
lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_TIMEOUTS, 1);
|
||||
|
||||
|
|
|
@ -55,12 +55,11 @@ _lws_b64_encode_string(const char *encode, const char *in, int in_len,
|
|||
{
|
||||
unsigned char triple[3];
|
||||
int i;
|
||||
int len;
|
||||
int line = 0;
|
||||
int done = 0;
|
||||
|
||||
while (in_len) {
|
||||
len = 0;
|
||||
int len = 0;
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (in_len) {
|
||||
triple[i] = *in++;
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include "core/private.h"
|
||||
|
||||
int pid_daemon;
|
||||
unsigned int pid_daemon;
|
||||
static char *lock_path;
|
||||
|
||||
int get_daemonize_pid()
|
||||
|
@ -35,9 +35,6 @@ int get_daemonize_pid()
|
|||
static void
|
||||
child_handler(int signum)
|
||||
{
|
||||
int fd, len, sent;
|
||||
char sz[20];
|
||||
|
||||
switch (signum) {
|
||||
|
||||
case SIGALRM: /* timed out daemonizing */
|
||||
|
@ -47,9 +44,12 @@ child_handler(int signum)
|
|||
case SIGUSR1: /* positive confirmation we daemonized well */
|
||||
|
||||
if (lock_path) {
|
||||
char sz[20];
|
||||
int len, sent;
|
||||
|
||||
/* Create the lock file as the current user */
|
||||
|
||||
fd = lws_open(lock_path, O_TRUNC | O_RDWR | O_CREAT, 0640);
|
||||
int fd = lws_open(lock_path, O_TRUNC | O_RDWR | O_CREAT, 0640);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr,
|
||||
"unable to create lock file %s, code=%d (%s)\n",
|
||||
|
@ -98,19 +98,22 @@ lws_daemonize(const char *_lock_path)
|
|||
{
|
||||
struct sigaction act;
|
||||
pid_t sid, parent;
|
||||
int n, fd, ret;
|
||||
char buf[10];
|
||||
|
||||
/* already a daemon */
|
||||
// if (getppid() == 1)
|
||||
// return 1;
|
||||
|
||||
if (_lock_path) {
|
||||
fd = lws_open(_lock_path, O_RDONLY);
|
||||
int n;
|
||||
|
||||
int fd = lws_open(_lock_path, O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
char buf[10];
|
||||
|
||||
n = read(fd, buf, sizeof(buf));
|
||||
close(fd);
|
||||
if (n) {
|
||||
int ret;
|
||||
n = atoi(buf);
|
||||
ret = kill(n, 0);
|
||||
if (ret >= 0) {
|
||||
|
@ -141,7 +144,7 @@ lws_daemonize(const char *_lock_path)
|
|||
|
||||
/* Fork off the parent process */
|
||||
pid_daemon = fork();
|
||||
if (pid_daemon < 0) {
|
||||
if ((int)pid_daemon < 0) {
|
||||
fprintf(stderr, "unable to fork daemon, code=%d (%s)",
|
||||
errno, strerror(errno));
|
||||
exit(9);
|
||||
|
|
|
@ -158,7 +158,7 @@ LWS_VISIBLE int
|
|||
lws_jwk_export(struct lws_jwk *s, int private, char *p, size_t len)
|
||||
{
|
||||
char *start = p, *end = &p[len - 1];
|
||||
int n, m, limit = LWS_COUNT_RSA_ELEMENTS;
|
||||
int n, limit = LWS_COUNT_RSA_ELEMENTS;
|
||||
|
||||
/* RFC7638 lexicographic order requires
|
||||
* RSA: e -> kty -> n
|
||||
|
@ -202,6 +202,8 @@ lws_jwk_export(struct lws_jwk *s, int private, char *p, size_t len)
|
|||
limit = JWK_KEY_N + 1;
|
||||
|
||||
for (n = 0; n < limit; n++) {
|
||||
int m;
|
||||
|
||||
if (!s->el.e[n].buf)
|
||||
continue;
|
||||
lwsl_info("%d: len %d\n", n, s->el.e[n].len);
|
||||
|
|
|
@ -255,7 +255,7 @@ lws_jws_confirm_sig(const char *in, size_t len, struct lws_jwk *jwk)
|
|||
|
||||
/* 2) find length of first, hdr, block */
|
||||
|
||||
while (in[pos] != '.' && pos < (int)len)
|
||||
while (pos < (int)len && in[pos] != '.')
|
||||
pos++;
|
||||
if (pos == (int)len)
|
||||
return -1;
|
||||
|
|
|
@ -119,15 +119,16 @@ static romfs_inode_t
|
|||
romfs_lookup(romfs_t romfs, romfs_inode_t start, const char *path)
|
||||
{
|
||||
romfs_inode_t level, i = start, i_in;
|
||||
const char *p, *n, *cp;
|
||||
const char *p, *cp;
|
||||
uint32_t next_be;
|
||||
|
||||
if (start == (romfs_inode_t)romfs)
|
||||
i = skip_and_pad((romfs_inode_t)romfs);
|
||||
level = i;
|
||||
while (i != (romfs_inode_t)romfs) {
|
||||
const char *n = ((const char *)i) + sizeof(*i);
|
||||
|
||||
p = path;
|
||||
n = ((const char *)i) + sizeof(*i);
|
||||
i_in = i;
|
||||
|
||||
set_cache(i, sizeof(*i));
|
||||
|
@ -142,7 +143,7 @@ romfs_lookup(romfs_t romfs, romfs_inode_t start, const char *path)
|
|||
cp++;
|
||||
}
|
||||
|
||||
while (*p && *p == '/' && p[1] == '/')
|
||||
while (*p == '/' && p[1] == '/')
|
||||
p++;
|
||||
|
||||
if (!*cp && (!*p || *p == '/') &&
|
||||
|
@ -165,7 +166,7 @@ romfs_lookup(romfs_t romfs, romfs_inode_t start, const char *path)
|
|||
if (!*p && *cp == '/')
|
||||
return NULL;
|
||||
|
||||
while (*p && *p == '/' && p[1] == '/')
|
||||
while (*p == '/' && p[1] == '/')
|
||||
p++;
|
||||
|
||||
if (*p == '/' && !*cp) {
|
||||
|
|
|
@ -236,18 +236,14 @@ sha1_pad(struct sha1_ctxt *ctxt)
|
|||
void
|
||||
sha1_loop(struct sha1_ctxt *ctxt, const unsigned char *input, size_t len)
|
||||
{
|
||||
size_t gaplen;
|
||||
size_t gapstart;
|
||||
size_t off;
|
||||
size_t copysiz;
|
||||
|
||||
off = 0;
|
||||
|
||||
while (off < len) {
|
||||
gapstart = COUNT % 64;
|
||||
gaplen = 64 - gapstart;
|
||||
size_t gapstart = COUNT % 64, gaplen = 64 - gapstart,
|
||||
copysiz = (gaplen < len - off) ? gaplen : len - off;
|
||||
|
||||
copysiz = (gaplen < len - off) ? gaplen : len - off;
|
||||
memcpy(&ctxt->m.b8[gapstart], &input[off], copysiz);
|
||||
COUNT += (unsigned char)copysiz;
|
||||
COUNT %= 64;
|
||||
|
|
|
@ -966,7 +966,6 @@ lws_threadpool_task_status_wsi(struct lws *wsi,
|
|||
{
|
||||
enum lws_threadpool_task_status status;
|
||||
struct lws_threadpool *tp;
|
||||
char buf[160];
|
||||
|
||||
*task = wsi->tp_task;
|
||||
if (!*task)
|
||||
|
@ -978,6 +977,7 @@ lws_threadpool_task_status_wsi(struct lws *wsi,
|
|||
|
||||
if (status == LWS_TP_STATUS_FINISHED ||
|
||||
status == LWS_TP_STATUS_STOPPED) {
|
||||
char buf[160];
|
||||
|
||||
pthread_mutex_lock(&tp->lock); /* ================ tpool lock */
|
||||
__lws_threadpool_task_dump(*task, buf, sizeof(buf));
|
||||
|
|
|
@ -543,7 +543,6 @@ esp_err_t lws_esp32_event_passthru(void *ctx, system_event_t *event)
|
|||
struct lws_group_member *mem;
|
||||
int n;
|
||||
#endif
|
||||
char slot[8];
|
||||
nvs_handle nvh;
|
||||
uint32_t use;
|
||||
|
||||
|
@ -587,6 +586,8 @@ esp_err_t lws_esp32_event_passthru(void *ctx, system_event_t *event)
|
|||
(uint8_t *)&event->event_info.got_ip.ip_info.gw);
|
||||
|
||||
if (!nvs_open("lws-station", NVS_READWRITE, &nvh)) {
|
||||
char slot[8];
|
||||
|
||||
lws_snprintf(slot, sizeof(slot) - 1, "%duse", try_slot);
|
||||
use = 0;
|
||||
nvs_get_u32(nvh, slot, &use);
|
||||
|
@ -1154,6 +1155,7 @@ lws_esp32_selfsigned(struct lws_vhost *vhost)
|
|||
nvs_close(nvh);
|
||||
if (n == 3) {
|
||||
lwsl_notice("%s: certs exist\n", __func__);
|
||||
free(buf);
|
||||
return 0; /* certs already exist */
|
||||
}
|
||||
|
||||
|
|
|
@ -44,10 +44,12 @@ lws_get_random(struct lws_context *context, void *buf, int len)
|
|||
LWS_VISIBLE int
|
||||
lws_send_pipe_choked(struct lws *wsi)
|
||||
{
|
||||
struct lws *wsi_eff = wsi;
|
||||
struct lws *wsi_eff;
|
||||
|
||||
#if defined(LWS_WITH_HTTP2)
|
||||
wsi_eff = lws_get_network_wsi(wsi);
|
||||
#else
|
||||
wsi_eff = wsi;
|
||||
#endif
|
||||
|
||||
/* the fact we checked implies we avoided back-to-back writes */
|
||||
|
|
|
@ -46,10 +46,6 @@ _lws_plat_apply_caps(int mode, const cap_value_t *cv, int count)
|
|||
void
|
||||
lws_plat_drop_app_privileges(const struct lws_context_creation_info *info)
|
||||
{
|
||||
#if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP)
|
||||
int n;
|
||||
#endif
|
||||
|
||||
if (info->gid && info->gid != -1)
|
||||
if (setgid(info->gid))
|
||||
lwsl_warn("setgid: %s\n", strerror(LWS_ERRNO));
|
||||
|
@ -75,10 +71,12 @@ lws_plat_drop_app_privileges(const struct lws_context_creation_info *info)
|
|||
_lws_plat_apply_caps(CAP_EFFECTIVE, info->caps,
|
||||
info->count_caps);
|
||||
|
||||
if (info->count_caps)
|
||||
if (info->count_caps) {
|
||||
int n;
|
||||
for (n = 0; n < info->count_caps; n++)
|
||||
lwsl_notice(" RETAINING CAPABILITY %d\n",
|
||||
(int)info->caps[n]);
|
||||
}
|
||||
#endif
|
||||
|
||||
} else
|
||||
|
|
|
@ -31,10 +31,12 @@ int
|
|||
lws_send_pipe_choked(struct lws *wsi)
|
||||
{
|
||||
struct lws_pollfd fds;
|
||||
struct lws *wsi_eff = wsi;
|
||||
struct lws *wsi_eff;
|
||||
|
||||
#if defined(LWS_WITH_HTTP2)
|
||||
wsi_eff = lws_get_network_wsi(wsi);
|
||||
#else
|
||||
wsi_eff = wsi;
|
||||
#endif
|
||||
|
||||
/* the fact we checked implies we avoided back-to-back writes */
|
||||
|
|
|
@ -34,7 +34,7 @@ _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi)
|
|||
struct lws *wsi;
|
||||
unsigned int i;
|
||||
DWORD ev;
|
||||
int n, m;
|
||||
int n;
|
||||
|
||||
/* stay dead once we are dead */
|
||||
if (context == NULL || !context->vhost_list)
|
||||
|
@ -58,6 +58,7 @@ _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi)
|
|||
if (lws_service_flag_pending(context, tsi)) {
|
||||
/* any socket with events to service? */
|
||||
for (n = 0; n < (int)pt->fds_count; n++) {
|
||||
int m;
|
||||
if (!pt->fds[n].revents)
|
||||
continue;
|
||||
|
||||
|
@ -125,7 +126,7 @@ _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi)
|
|||
|
||||
ev = WSAWaitForMultipleEvents(1, &pt->events, FALSE, timeout_ms, FALSE);
|
||||
if (ev == WSA_WAIT_EVENT_0) {
|
||||
unsigned int eIdx, err;
|
||||
unsigned int eIdx;
|
||||
|
||||
WSAResetEvent(pt->events);
|
||||
|
||||
|
@ -134,6 +135,8 @@ _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi)
|
|||
pt->context->tls_ops->fake_POLLIN_for_buffered(pt);
|
||||
|
||||
for (eIdx = 0; eIdx < pt->fds_count; ++eIdx) {
|
||||
unsigned int err;
|
||||
|
||||
if (WSAEnumNetworkEvents(pt->fds[eIdx].fd, 0,
|
||||
&networkevents) == SOCKET_ERROR) {
|
||||
lwsl_err("WSAEnumNetworkEvents() failed "
|
||||
|
|
|
@ -6,10 +6,12 @@
|
|||
|
||||
LWS_VISIBLE int
|
||||
lws_send_pipe_choked(struct lws *wsi)
|
||||
{ struct lws *wsi_eff = wsi;
|
||||
{ struct lws *wsi_eff;
|
||||
|
||||
#if defined(LWS_WITH_HTTP2)
|
||||
wsi_eff = lws_get_network_wsi(wsi);
|
||||
#else
|
||||
wsi_eff = wsi;
|
||||
#endif
|
||||
/* the fact we checked implies we avoided back-to-back writes */
|
||||
wsi_eff->could_have_pending = 0;
|
||||
|
|
|
@ -677,7 +677,6 @@ rops_write_role_protocol_h1(struct lws *wsi, unsigned char *buf, size_t len,
|
|||
size_t o = sizeof(mtubuf) - LWS_PRE -
|
||||
LWS_HTTP_CHUNK_HDR_MAX_SIZE -
|
||||
LWS_HTTP_CHUNK_TRL_MAX_SIZE;
|
||||
char c[LWS_HTTP_CHUNK_HDR_MAX_SIZE + 2];
|
||||
|
||||
n = lws_http_compression_transform(wsi, buf, len, wp, &out, &o);
|
||||
if (n)
|
||||
|
@ -691,6 +690,7 @@ rops_write_role_protocol_h1(struct lws *wsi, unsigned char *buf, size_t len,
|
|||
return olen;
|
||||
|
||||
if (wsi->http.comp_ctx.chunking) {
|
||||
char c[LWS_HTTP_CHUNK_HDR_MAX_SIZE + 2];
|
||||
/*
|
||||
* this only needs dealing with on http/1.1 to allow
|
||||
* pipelining
|
||||
|
@ -798,7 +798,7 @@ rops_adoption_bind_h1(struct lws *wsi, int type, const char *vh_prot_name)
|
|||
return 1;
|
||||
}
|
||||
|
||||
lws_role_transition(wsi, LWSIFR_SERVER, type & LWS_ADOPT_ALLOW_SSL ?
|
||||
lws_role_transition(wsi, LWSIFR_SERVER, (type & LWS_ADOPT_ALLOW_SSL) ?
|
||||
LRS_SSL_INIT : LRS_HEADERS, &role_ops_h1);
|
||||
|
||||
if (!vh_prot_name)
|
||||
|
|
|
@ -489,7 +489,7 @@ lws_dynamic_token_insert(struct lws *wsi, int hdr_len,
|
|||
int lws_hdr_index, char *arg, int len)
|
||||
{
|
||||
struct hpack_dynamic_table *dyn;
|
||||
int new_index, n;
|
||||
int new_index;
|
||||
|
||||
/* dynamic table only belongs to network wsi */
|
||||
wsi = lws_get_network_wsi(wsi);
|
||||
|
@ -522,7 +522,7 @@ lws_dynamic_token_insert(struct lws *wsi, int hdr_len,
|
|||
dyn->used_entries &&
|
||||
dyn->virtual_payload_usage + hdr_len + len >
|
||||
dyn->virtual_payload_max + 1024) {
|
||||
n = (dyn->pos - dyn->used_entries) % dyn->num_entries;
|
||||
int n = (dyn->pos - dyn->used_entries) % dyn->num_entries;
|
||||
if (n < 0)
|
||||
n += dyn->num_entries;
|
||||
lws_dynamic_free(dyn, n);
|
||||
|
|
|
@ -1181,7 +1181,6 @@ static int
|
|||
lws_h2_parse_end_of_frame(struct lws *wsi)
|
||||
{
|
||||
struct lws_h2_netconn *h2n = wsi->h2.h2n;
|
||||
struct lws_h2_protocol_send *pps;
|
||||
struct lws *eff_wsi = wsi;
|
||||
const char *p;
|
||||
int n;
|
||||
|
@ -1215,6 +1214,7 @@ lws_h2_parse_end_of_frame(struct lws *wsi)
|
|||
#if !defined(LWS_NO_CLIENT)
|
||||
if (wsi->client_h2_alpn &&
|
||||
!(h2n->flags & LWS_H2_FLAG_SETTINGS_ACK)) {
|
||||
struct lws_h2_protocol_send *pps;
|
||||
|
||||
/* migrate original client ask on to substream 1 */
|
||||
|
||||
|
@ -1499,10 +1499,13 @@ lws_h2_parse_end_of_frame(struct lws *wsi)
|
|||
case LWS_H2_FRAME_TYPE_PING:
|
||||
if (h2n->flags & LWS_H2_FLAG_SETTINGS_ACK) { // ack
|
||||
} else {/* they're sending us a ping request */
|
||||
lwsl_info("rx ping, preparing pong\n");
|
||||
pps = lws_h2_new_pps(LWS_H2_PPS_PONG);
|
||||
struct lws_h2_protocol_send *pps =
|
||||
lws_h2_new_pps(LWS_H2_PPS_PONG);
|
||||
if (!pps)
|
||||
return 1;
|
||||
|
||||
lwsl_info("rx ping, preparing pong\n");
|
||||
|
||||
memcpy(pps->u.ping.ping_payload, h2n->ping_payload, 8);
|
||||
lws_pps_schedule(wsi, pps);
|
||||
}
|
||||
|
@ -2193,7 +2196,6 @@ lws_read_h2(struct lws *wsi, unsigned char *buf, lws_filepos_t len)
|
|||
{
|
||||
unsigned char *oldbuf = buf;
|
||||
lws_filepos_t body_chunk_len;
|
||||
int m;
|
||||
|
||||
// lwsl_notice("%s: h2 path: wsistate 0x%x len %d\n", __func__,
|
||||
// wsi->wsistate, (int)len);
|
||||
|
@ -2209,6 +2211,8 @@ lws_read_h2(struct lws *wsi, unsigned char *buf, lws_filepos_t len)
|
|||
* case.
|
||||
*/
|
||||
while (len) {
|
||||
int m;
|
||||
|
||||
/*
|
||||
* we were accepting input but now we stopped doing so
|
||||
*/
|
||||
|
|
|
@ -511,12 +511,13 @@ static int
|
|||
rops_init_vhost_h2(struct lws_vhost *vh,
|
||||
const struct lws_context_creation_info *info)
|
||||
{
|
||||
int n;
|
||||
|
||||
vh->h2.set = vh->context->set;
|
||||
if (info->http2_settings[0])
|
||||
if (info->http2_settings[0]) {
|
||||
int n;
|
||||
|
||||
for (n = 1; n < LWS_H2_SETTINGS_LEN; n++)
|
||||
vh->h2.set.s[n] = info->http2_settings[n];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -766,8 +767,6 @@ lws_h2_bind_for_post_before_action(struct lws *wsi)
|
|||
|
||||
p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD);
|
||||
if (p && !strcmp(p, "POST")) {
|
||||
const struct lws_protocols *pp;
|
||||
const char *name;
|
||||
const struct lws_http_mount *hit =
|
||||
lws_find_mount(wsi,
|
||||
lws_hdr_simple_ptr(wsi,
|
||||
|
@ -779,7 +778,9 @@ lws_h2_bind_for_post_before_action(struct lws *wsi)
|
|||
lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_PATH),
|
||||
hit, hit ? hit->origin : "null");
|
||||
if (hit) {
|
||||
name = hit->origin;
|
||||
const struct lws_protocols *pp;
|
||||
const char *name = hit->origin;
|
||||
|
||||
if (hit->protocol)
|
||||
name = hit->protocol;
|
||||
|
||||
|
@ -871,6 +872,11 @@ rops_perform_user_POLLOUT_h2(struct lws *wsi)
|
|||
w = w->h2.sibling_list;
|
||||
}
|
||||
|
||||
if (!w) {
|
||||
wa = &wsi->h2.child_list;
|
||||
goto next_child;
|
||||
}
|
||||
|
||||
w->h2.requested_POLLOUT = 0;
|
||||
lwsl_info("%s: child %p (wsistate 0x%x)\n", __func__, w,
|
||||
w->wsistate);
|
||||
|
|
|
@ -673,7 +673,7 @@ lws_client_interpret_server_handshake(struct lws *wsi)
|
|||
int n, port = 0, ssl = 0;
|
||||
int close_reason = LWS_CLOSE_STATUS_PROTOCOL_ERR;
|
||||
const char *prot, *ads = NULL, *path, *cce = NULL;
|
||||
struct allocated_headers *ah = NULL;
|
||||
struct allocated_headers *ah;
|
||||
struct lws *w = lws_client_wsi_effective(wsi);
|
||||
char *p, *q;
|
||||
char new_path[300];
|
||||
|
|
|
@ -40,16 +40,16 @@ static const char * const hver[] = {
|
|||
void
|
||||
lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int uri_len, int meth)
|
||||
{
|
||||
char da[64], uri[256];
|
||||
const char *pa, *me;
|
||||
time_t t = time(NULL);
|
||||
int l = 256, m;
|
||||
#ifdef LWS_WITH_IPV6
|
||||
char ads[INET6_ADDRSTRLEN];
|
||||
#else
|
||||
char ads[INET_ADDRSTRLEN];
|
||||
#endif
|
||||
char da[64], uri[256];
|
||||
const char *pa, *me;
|
||||
struct tm *tmp;
|
||||
time_t t = time(NULL);
|
||||
int l = 256, m;
|
||||
|
||||
if (!wsi->vhost)
|
||||
return;
|
||||
|
@ -62,73 +62,72 @@ lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int uri_len, int met
|
|||
lws_access_log(wsi);
|
||||
|
||||
wsi->http.access_log.header_log = lws_malloc(l, "access log");
|
||||
if (wsi->http.access_log.header_log) {
|
||||
if (!wsi->http.access_log.header_log)
|
||||
return;
|
||||
|
||||
tmp = localtime(&t);
|
||||
if (tmp)
|
||||
strftime(da, sizeof(da), "%d/%b/%Y:%H:%M:%S %z", tmp);
|
||||
else
|
||||
strcpy(da, "01/Jan/1970:00:00:00 +0000");
|
||||
tmp = localtime(&t);
|
||||
if (tmp)
|
||||
strftime(da, sizeof(da), "%d/%b/%Y:%H:%M:%S %z", tmp);
|
||||
else
|
||||
strcpy(da, "01/Jan/1970:00:00:00 +0000");
|
||||
|
||||
pa = lws_get_peer_simple(wsi, ads, sizeof(ads));
|
||||
if (!pa)
|
||||
pa = "(unknown)";
|
||||
pa = lws_get_peer_simple(wsi, ads, sizeof(ads));
|
||||
if (!pa)
|
||||
pa = "(unknown)";
|
||||
|
||||
if (wsi->http2_substream)
|
||||
me = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD);
|
||||
else
|
||||
me = method_names[meth];
|
||||
if (!me)
|
||||
me = "(null)";
|
||||
if (wsi->http2_substream)
|
||||
me = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD);
|
||||
else
|
||||
me = method_names[meth];
|
||||
if (!me)
|
||||
me = "(null)";
|
||||
|
||||
m = uri_len;
|
||||
if (m > (int)sizeof(uri) - 1)
|
||||
m = sizeof(uri) - 1;
|
||||
m = uri_len;
|
||||
if (m > (int)sizeof(uri) - 1)
|
||||
m = sizeof(uri) - 1;
|
||||
|
||||
strncpy(uri, uri_ptr, m);
|
||||
uri[m] = '\0';
|
||||
strncpy(uri, uri_ptr, m);
|
||||
uri[m] = '\0';
|
||||
|
||||
lws_snprintf(wsi->http.access_log.header_log, l,
|
||||
"%s - - [%s] \"%s %s %s\"",
|
||||
pa, da, me, uri,
|
||||
hver[wsi->http.request_version]);
|
||||
lws_snprintf(wsi->http.access_log.header_log, l,
|
||||
"%s - - [%s] \"%s %s %s\"",
|
||||
pa, da, me, uri, hver[wsi->http.request_version]);
|
||||
|
||||
//lwsl_notice("%s\n", wsi->http.access_log.header_log);
|
||||
//lwsl_notice("%s\n", wsi->http.access_log.header_log);
|
||||
|
||||
l = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_USER_AGENT);
|
||||
if (l) {
|
||||
wsi->http.access_log.user_agent = lws_malloc(l + 2, "access log");
|
||||
if (!wsi->http.access_log.user_agent) {
|
||||
lwsl_err("OOM getting user agent\n");
|
||||
lws_free_set_NULL(wsi->http.access_log.header_log);
|
||||
return;
|
||||
}
|
||||
|
||||
lws_hdr_copy(wsi, wsi->http.access_log.user_agent,
|
||||
l + 1, WSI_TOKEN_HTTP_USER_AGENT);
|
||||
|
||||
for (m = 0; m < l; m++)
|
||||
if (wsi->http.access_log.user_agent[m] == '\"')
|
||||
wsi->http.access_log.user_agent[m] = '\'';
|
||||
l = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_USER_AGENT);
|
||||
if (l) {
|
||||
wsi->http.access_log.user_agent = lws_malloc(l + 2, "access log");
|
||||
if (!wsi->http.access_log.user_agent) {
|
||||
lwsl_err("OOM getting user agent\n");
|
||||
lws_free_set_NULL(wsi->http.access_log.header_log);
|
||||
return;
|
||||
}
|
||||
l = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_REFERER);
|
||||
if (l) {
|
||||
wsi->http.access_log.referrer = lws_malloc(l + 2, "referrer");
|
||||
if (!wsi->http.access_log.referrer) {
|
||||
lwsl_err("OOM getting user agent\n");
|
||||
lws_free_set_NULL(wsi->http.access_log.user_agent);
|
||||
lws_free_set_NULL(wsi->http.access_log.header_log);
|
||||
return;
|
||||
}
|
||||
lws_hdr_copy(wsi, wsi->http.access_log.referrer,
|
||||
l + 1, WSI_TOKEN_HTTP_REFERER);
|
||||
|
||||
for (m = 0; m < l; m++)
|
||||
if (wsi->http.access_log.referrer[m] == '\"')
|
||||
wsi->http.access_log.referrer[m] = '\'';
|
||||
}
|
||||
wsi->access_log_pending = 1;
|
||||
lws_hdr_copy(wsi, wsi->http.access_log.user_agent,
|
||||
l + 1, WSI_TOKEN_HTTP_USER_AGENT);
|
||||
|
||||
for (m = 0; m < l; m++)
|
||||
if (wsi->http.access_log.user_agent[m] == '\"')
|
||||
wsi->http.access_log.user_agent[m] = '\'';
|
||||
}
|
||||
l = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_REFERER);
|
||||
if (l) {
|
||||
wsi->http.access_log.referrer = lws_malloc(l + 2, "referrer");
|
||||
if (!wsi->http.access_log.referrer) {
|
||||
lwsl_err("OOM getting user agent\n");
|
||||
lws_free_set_NULL(wsi->http.access_log.user_agent);
|
||||
lws_free_set_NULL(wsi->http.access_log.header_log);
|
||||
return;
|
||||
}
|
||||
lws_hdr_copy(wsi, wsi->http.access_log.referrer,
|
||||
l + 1, WSI_TOKEN_HTTP_REFERER);
|
||||
|
||||
for (m = 0; m < l; m++)
|
||||
if (wsi->http.access_log.referrer[m] == '\"')
|
||||
wsi->http.access_log.referrer[m] = '\'';
|
||||
}
|
||||
wsi->access_log_pending = 1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -67,11 +67,10 @@ int
|
|||
lws_ranges_next(struct lws_range_parsing *rp)
|
||||
{
|
||||
static const char * const beq = "bytes=";
|
||||
char c;
|
||||
|
||||
while (1) {
|
||||
|
||||
c = rp->buf[rp->pos];
|
||||
char c = rp->buf[rp->pos];
|
||||
|
||||
switch (rp->state) {
|
||||
case LWSRS_SYNTAX:
|
||||
|
|
|
@ -307,7 +307,7 @@ lws_select_vhost(struct lws_context *context, int port, const char *servername)
|
|||
{
|
||||
struct lws_vhost *vhost = context->vhost_list;
|
||||
const char *p;
|
||||
int n, m, colon;
|
||||
int n, colon;
|
||||
|
||||
n = (int)strlen(servername);
|
||||
colon = n;
|
||||
|
@ -335,7 +335,7 @@ lws_select_vhost(struct lws_context *context, int port, const char *servername)
|
|||
*/
|
||||
vhost = context->vhost_list;
|
||||
while (vhost) {
|
||||
m = (int)strlen(vhost->name);
|
||||
int m = (int)strlen(vhost->name);
|
||||
if (port && port == vhost->listen_port &&
|
||||
m <= (colon - 2) &&
|
||||
servername[colon - m - 1] == '.' &&
|
||||
|
@ -1202,7 +1202,7 @@ lws_http_action(struct lws *wsi)
|
|||
hit->origin_protocol == LWSMPRO_HTTP) {
|
||||
struct lws_client_connect_info i;
|
||||
struct lws *cwsi;
|
||||
char ads[96], rpath[256], *pcolon, *pslash, *p, unix_skt = 0;
|
||||
char ads[96], rpath[256], *pcolon, *pslash, unix_skt = 0;
|
||||
int n, na;
|
||||
|
||||
memset(&i, 0, sizeof(i));
|
||||
|
@ -1258,7 +1258,7 @@ lws_http_action(struct lws *wsi)
|
|||
lws_clean_url(rpath);
|
||||
na = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_URI_ARGS);
|
||||
if (na) {
|
||||
p = rpath + strlen(rpath);
|
||||
char *p = rpath + strlen(rpath);
|
||||
*p++ = '?';
|
||||
lws_hdr_copy(wsi, p, &rpath[sizeof(rpath) - 1] - p,
|
||||
WSI_TOKEN_HTTP_URI_ARGS);
|
||||
|
@ -1485,8 +1485,6 @@ deal_body:
|
|||
}
|
||||
|
||||
if (wsi->http.rx_content_length > 0) {
|
||||
struct lws_tokens ebuf;
|
||||
int m;
|
||||
|
||||
lwsi_set_state(wsi, LRS_BODY);
|
||||
lwsl_info("%s: %p: LRS_BODY state set (0x%x)\n",
|
||||
|
@ -1502,12 +1500,18 @@ deal_body:
|
|||
*/
|
||||
|
||||
while (1) {
|
||||
struct lws_tokens ebuf;
|
||||
int m;
|
||||
|
||||
ebuf.len = (int)lws_buflist_next_segment_len(
|
||||
&wsi->buflist, (uint8_t **)&ebuf.token);
|
||||
&wsi->buflist,
|
||||
(uint8_t **)&ebuf.token);
|
||||
if (!ebuf.len)
|
||||
break;
|
||||
lwsl_notice("%s: consuming %d\n", __func__, (int)ebuf.len);
|
||||
m = lws_read_h1(wsi, (uint8_t *)ebuf.token, ebuf.len);
|
||||
lwsl_notice("%s: consuming %d\n", __func__,
|
||||
(int)ebuf.len);
|
||||
m = lws_read_h1(wsi, (uint8_t *)ebuf.token,
|
||||
ebuf.len);
|
||||
if (m < 0)
|
||||
return -1;
|
||||
|
||||
|
@ -1588,7 +1592,7 @@ raw_transition:
|
|||
&role_ops_raw_skt);
|
||||
lws_header_table_detach(wsi, 1);
|
||||
|
||||
if (m == 2 && (wsi->protocol->callback)(wsi,
|
||||
if (wsi->protocol->callback(wsi,
|
||||
LWS_CALLBACK_RAW_RX,
|
||||
wsi->user_space, obuf, olen))
|
||||
return 1;
|
||||
|
|
|
@ -152,7 +152,7 @@ rops_adoption_bind_raw_skt(struct lws *wsi, int type, const char *vh_prot_name)
|
|||
wsi->udp = lws_malloc(sizeof(*wsi->udp), "udp struct");
|
||||
#endif
|
||||
|
||||
lws_role_transition(wsi, 0, type & LWS_ADOPT_ALLOW_SSL ? LRS_SSL_INIT :
|
||||
lws_role_transition(wsi, 0, (type & LWS_ADOPT_ALLOW_SSL) ? LRS_SSL_INIT :
|
||||
LRS_ESTABLISHED, &role_ops_raw_skt);
|
||||
|
||||
if (vh_prot_name)
|
||||
|
|
|
@ -309,7 +309,7 @@ lws_client_ws_upgrade(struct lws *wsi, const char **cce)
|
|||
}
|
||||
while (*pc && *pc++ != ',')
|
||||
;
|
||||
while (*pc && *pc == ' ')
|
||||
while (*pc == ' ')
|
||||
pc++;
|
||||
}
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ lws_extension_server_handshake(struct lws *wsi, char **p, int budget)
|
|||
continue;
|
||||
}
|
||||
|
||||
while (args && *args && *args == ' ')
|
||||
while (args && *args == ' ')
|
||||
args++;
|
||||
|
||||
/* check a client's extension against our support */
|
||||
|
@ -643,7 +643,7 @@ lws_ws_frame_rest_is_payload(struct lws *wsi, uint8_t **buf, size_t len)
|
|||
if (avail > len)
|
||||
avail = (unsigned int)len;
|
||||
|
||||
if (avail <= 0)
|
||||
if (!avail)
|
||||
return 0;
|
||||
|
||||
ebuf.token = (char *)buffer;
|
||||
|
|
|
@ -36,8 +36,6 @@ lws_jwk_destroy_genrsa_elements(struct lws_genrsa_elements *el)
|
|||
LWS_VISIBLE int
|
||||
lws_genrsa_create(struct lws_genrsa_ctx *ctx, struct lws_genrsa_elements *el)
|
||||
{
|
||||
int n;
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
ctx->ctx = lws_zalloc(sizeof(*ctx->ctx), "genrsa");
|
||||
if (!ctx->ctx)
|
||||
|
@ -46,6 +44,8 @@ lws_genrsa_create(struct lws_genrsa_ctx *ctx, struct lws_genrsa_elements *el)
|
|||
mbedtls_rsa_init(ctx->ctx, MBEDTLS_RSA_PKCS_V15, 0);
|
||||
|
||||
{
|
||||
int n;
|
||||
|
||||
mbedtls_mpi *mpi[LWS_COUNT_RSA_ELEMENTS] = {
|
||||
&ctx->ctx->E, &ctx->ctx->N, &ctx->ctx->D, &ctx->ctx->P,
|
||||
&ctx->ctx->Q, &ctx->ctx->DP, &ctx->ctx->DQ,
|
||||
|
|
|
@ -30,7 +30,6 @@ OpenSSL_client_verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx)
|
|||
int
|
||||
lws_ssl_client_bio_create(struct lws *wsi)
|
||||
{
|
||||
X509_VERIFY_PARAM *param;
|
||||
char hostname[128], *p;
|
||||
const char *alpn_comma = wsi->context->tls.alpn_default;
|
||||
struct alpn_ctx protos;
|
||||
|
@ -63,7 +62,7 @@ lws_ssl_client_bio_create(struct lws *wsi)
|
|||
SSL_set_info_callback(wsi->tls.ssl, lws_ssl_info_callback);
|
||||
|
||||
if (!(wsi->tls.use_ssl & LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK)) {
|
||||
param = SSL_get0_param(wsi->tls.ssl);
|
||||
X509_VERIFY_PARAM *param = SSL_get0_param(wsi->tls.ssl);
|
||||
/* Enable automatic hostname checks */
|
||||
// X509_VERIFY_PARAM_set_hostflags(param,
|
||||
// X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
|
||||
|
|
|
@ -90,9 +90,6 @@ OpenSSL_client_verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx)
|
|||
int
|
||||
lws_ssl_client_bio_create(struct lws *wsi)
|
||||
{
|
||||
#if defined LWS_HAVE_X509_VERIFY_PARAM_set1_host
|
||||
X509_VERIFY_PARAM *param;
|
||||
#endif
|
||||
char hostname[128], *p;
|
||||
#if defined(LWS_HAVE_SSL_set_alpn_protos) && \
|
||||
defined(LWS_HAVE_SSL_get0_alpn_selected)
|
||||
|
@ -139,7 +136,8 @@ lws_ssl_client_bio_create(struct lws *wsi)
|
|||
|
||||
#if defined LWS_HAVE_X509_VERIFY_PARAM_set1_host
|
||||
if (!(wsi->tls.use_ssl & LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK)) {
|
||||
param = SSL_get0_param(wsi->tls.ssl);
|
||||
X509_VERIFY_PARAM *param = SSL_get0_param(wsi->tls.ssl);
|
||||
|
||||
/* Enable automatic hostname checks */
|
||||
X509_VERIFY_PARAM_set_hostflags(param,
|
||||
X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
|
||||
|
|
|
@ -644,7 +644,7 @@ lws_tls_openssl_cert_info(X509 *x509, enum lws_tls_cert_info type,
|
|||
size_t klen = i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x509), NULL);
|
||||
uint8_t *tmp, *ptmp;
|
||||
|
||||
if (klen <= 0 || klen > len)
|
||||
if (!klen || klen > len)
|
||||
return -1;
|
||||
|
||||
tmp = (uint8_t *)OPENSSL_malloc(klen);
|
||||
|
|
|
@ -140,8 +140,8 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
break;
|
||||
|
||||
/* notice we allowed for LWS_PRE in the payload already */
|
||||
m = lws_write(wsi, pmsg->payload + LWS_PRE, pmsg->len,
|
||||
LWS_WRITE_TEXT);
|
||||
m = lws_write(wsi, ((unsigned char *)pmsg->payload) + LWS_PRE,
|
||||
pmsg->len, LWS_WRITE_TEXT);
|
||||
if (m < (int)pmsg->len) {
|
||||
lwsl_err("ERROR %d writing to ws socket\n", m);
|
||||
return -1;
|
||||
|
|
|
@ -5,7 +5,7 @@ This is a test client used to test `./minimal-examples/dbus-server/minimal-dbus-
|
|||
It asks the minimal dbus ws proxy application to connect to libwebsockets.org
|
||||
over the mirror protocol. And it proxies back the ASCII packets used to
|
||||
communicate the mirror sample drawing vectors over dbus to this test client
|
||||
if you draw on the mirror example app at https://libwebsockets.org/testserver/
|
||||
if you draw on the [mirror example app](https://libwebsockets.org/testserver/)
|
||||
in a browser.
|
||||
|
||||
## build
|
||||
|
|
|
@ -488,7 +488,7 @@ new_conn(DBusServer *server, DBusConnection *conn, void *d)
|
|||
|
||||
memset(conn_wspctx, 0, sizeof(*conn_wspctx));
|
||||
|
||||
conn_wspctx->ctx.tsi = conn_wspctx->ctx.tsi;
|
||||
conn_wspctx->ctx.tsi = wspctx->ctx.tsi;
|
||||
conn_wspctx->ctx.vh = wspctx->ctx.vh;
|
||||
conn_wspctx->ctx.conn = conn;
|
||||
conn_wspctx->vhd = vhd; /* let accepted connections also know the vhd */
|
||||
|
@ -708,7 +708,8 @@ callback_minimal_dbus_wsproxy(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
pmsg->first, pmsg->final);
|
||||
|
||||
/* notice we allowed for LWS_PRE in the payload already */
|
||||
m = lws_write(wsi, pmsg->payload + LWS_PRE, pmsg->len, flags);
|
||||
m = lws_write(wsi, ((unsigned char *)pmsg->payload) + LWS_PRE,
|
||||
pmsg->len, flags);
|
||||
if (m < (int)pmsg->len) {
|
||||
lwsl_err("ERROR %d writing to ws socket\n", m);
|
||||
return -1;
|
||||
|
|
|
@ -79,7 +79,7 @@ callback_dynamic_http(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
return 1;
|
||||
|
||||
pss->times = 0;
|
||||
pss->budget = atoi(in + 1);
|
||||
pss->budget = atoi((char *)in + 1);
|
||||
pss->content_lines = 0;
|
||||
if (!pss->budget)
|
||||
pss->budget = 10;
|
||||
|
|
|
@ -13,26 +13,73 @@
|
|||
*
|
||||
*/
|
||||
|
||||
function lws_gray_out(vis, options) {
|
||||
function gsize(ptype)
|
||||
{
|
||||
var h = document.compatMode === "CSS1Compat" &&
|
||||
!window.opera ?
|
||||
document.documentElement.clientHeight :
|
||||
document.body.clientHeight;
|
||||
var w = document.compatMode === "CSS1Compat" &&
|
||||
!window.opera ?
|
||||
document.documentElement.clientWidth :
|
||||
document.body.clientWidth;
|
||||
var pageWidth, pageHeight, t;
|
||||
|
||||
var options = options || {};
|
||||
if (document.body &&
|
||||
(document.body.scrollWidth || document.body.scrollHeight)) {
|
||||
t = document.body.scrollWidth;
|
||||
pageWidth = (w > t) ? ("" + w + "px") : ("" + (t) + "px");
|
||||
t = document.body.scrollHeight;
|
||||
pageHeight = (h > t) ? ("" + h + "px") : ("" + (t) + "px");
|
||||
} else if (document.body.offsetWidth) {
|
||||
t = document.body.offsetWidth;
|
||||
pageWidth = (w > t) ? ("" + w + "px") : ("" + (t) + "px");
|
||||
t = document.body.offsetHeight;
|
||||
pageHeight =(h > t) ? ("" + h + "px") : ("" + (t) + "px");
|
||||
} else {
|
||||
pageWidth = "100%";
|
||||
pageHeight = "100%";
|
||||
}
|
||||
return (ptype === 1) ? pageWidth : pageHeight;
|
||||
}
|
||||
|
||||
function addEvent( obj, type, fn ) {
|
||||
if ( obj.attachEvent ) {
|
||||
obj["e" + type + fn] = fn;
|
||||
obj[type+fn] = function() { obj["e" + type + fn]( window.event );};
|
||||
obj.attachEvent("on" + type, obj[type + fn]);
|
||||
} else
|
||||
obj.addEventListener(type, fn, false);
|
||||
}
|
||||
|
||||
function removeEvent( obj, type, fn ) {
|
||||
if ( obj.detachEvent ) {
|
||||
obj.detachEvent("on" + type, obj[type + fn]);
|
||||
obj[type + fn] = null;
|
||||
} else
|
||||
obj.removeEventListener(type, fn, false);
|
||||
}
|
||||
|
||||
function lws_gray_out(vis, _options) {
|
||||
|
||||
var options = _options || {};
|
||||
var zindex = options.zindex || 50;
|
||||
var opacity = options.opacity || 70;
|
||||
var opaque = (opacity / 100);
|
||||
var bgcolor = options.bgcolor || '#000000';
|
||||
var dark = document.getElementById('darkenScreenObject');
|
||||
var bgcolor = options.bgcolor || "#000000";
|
||||
var dark = document.getElementById("darkenScreenObject");
|
||||
|
||||
if (!dark) {
|
||||
var tbody = document.getElementsByTagName("body")[0];
|
||||
var tnode = document.createElement('div');
|
||||
tnode.style.position = 'absolute';
|
||||
tnode.style.top = '0px';
|
||||
tnode.style.left = '0px';
|
||||
tnode.style.overflow = 'hidden';
|
||||
tnode.style.display ='none';
|
||||
tnode.id = 'darkenScreenObject';
|
||||
var tnode = document.createElement("div");
|
||||
tnode.style.position = "absolute";
|
||||
tnode.style.top = "0px";
|
||||
tnode.style.left = "0px";
|
||||
tnode.style.overflow = "hidden";
|
||||
tnode.style.display ="none";
|
||||
tnode.id = "darkenScreenObject";
|
||||
tbody.appendChild(tnode);
|
||||
dark = document.getElementById('darkenScreenObject');
|
||||
dark = document.getElementById("darkenScreenObject");
|
||||
}
|
||||
if (vis) {
|
||||
dark.style.opacity = opaque;
|
||||
|
@ -42,7 +89,7 @@ function lws_gray_out(vis, options) {
|
|||
dark.style.backgroundColor = bgcolor;
|
||||
dark.style.width = gsize(1);
|
||||
dark.style.height = gsize(0);
|
||||
dark.style.display ='block';
|
||||
dark.style.display = "block";
|
||||
addEvent(window, "resize",
|
||||
function() {
|
||||
dark.style.height = gsize(0);
|
||||
|
@ -50,7 +97,7 @@ function lws_gray_out(vis, options) {
|
|||
}
|
||||
);
|
||||
} else {
|
||||
dark.style.display = 'none';
|
||||
dark.style.display = "none";
|
||||
removeEvent(window, "resize",
|
||||
function() {
|
||||
dark.style.height = gsize(0);
|
||||
|
@ -60,338 +107,13 @@ function lws_gray_out(vis, options) {
|
|||
}
|
||||
}
|
||||
|
||||
function gsize(ptype)
|
||||
{
|
||||
var h = document.compatMode == 'CSS1Compat' &&
|
||||
!window.opera ?
|
||||
document.documentElement.clientHeight :
|
||||
document.body.clientHeight;
|
||||
var w = document.compatMode == 'CSS1Compat' &&
|
||||
!window.opera ?
|
||||
document.documentElement.clientWidth :
|
||||
document.body.clientWidth;
|
||||
if (document.body &&
|
||||
(document.body.scrollWidth || document.body.scrollHeight)) {
|
||||
var pageWidth = (w > (t = document.body.scrollWidth)) ?
|
||||
("" + w + "px") : ("" + (t) + "px");
|
||||
var pageHeight = (h > (t = document.body.scrollHeight)) ?
|
||||
("" + h + "px") : ("" + (t) + "px");
|
||||
} else if (document.body.offsetWidth) {
|
||||
var pageWidth = (w > (t = document.body.offsetWidth)) ?
|
||||
("" + w + "px") : ("" + (t) + "px");
|
||||
var pageHeight =(h > (t = document.body.offsetHeight)) ?
|
||||
("" + h + "px") : ("" + (t) + "px");
|
||||
} else {
|
||||
var pageWidth = '100%';
|
||||
var pageHeight = '100%';
|
||||
}
|
||||
return (ptype == 1) ? pageWidth : pageHeight;
|
||||
}
|
||||
|
||||
function addEvent( obj, type, fn ) {
|
||||
if ( obj.attachEvent ) {
|
||||
obj['e' + type + fn] = fn;
|
||||
obj[type+fn] = function() { obj['e' + type+fn]( window.event );}
|
||||
obj.attachEvent('on' + type, obj[type + fn]);
|
||||
} else
|
||||
obj.addEventListener(type, fn, false);
|
||||
}
|
||||
|
||||
function removeEvent( obj, type, fn ) {
|
||||
if ( obj.detachEvent ) {
|
||||
obj.detachEvent('on' + type, obj[type + fn]);
|
||||
obj[type + fn] = null;
|
||||
} else
|
||||
obj.removeEventListener(type, fn, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* end of grayOut related stuff
|
||||
*/
|
||||
|
||||
/*
|
||||
* lws-meta helpers
|
||||
*/
|
||||
|
||||
var lws_meta_cmd = {
|
||||
OPEN_SUBCHANNEL: 0x41,
|
||||
/**< Client requests to open new subchannel
|
||||
*/
|
||||
OPEN_RESULT: 0x42,
|
||||
/**< Result of client request to open new subchannel */
|
||||
CLOSE_NOT: 0x43,
|
||||
CLOSE_RQ: 0x44,
|
||||
/**< client requests to close a subchannel */
|
||||
WRITE: 0x45,
|
||||
/**< connection writes something to specific channel index */
|
||||
RX: 0x46,
|
||||
};
|
||||
|
||||
function new_ws(urlpath, protocol)
|
||||
{
|
||||
if (typeof MozWebSocket != "undefined")
|
||||
return new MozWebSocket(urlpath, protocol);
|
||||
|
||||
return new WebSocket(urlpath, protocol);
|
||||
}
|
||||
|
||||
function lws_meta_ws() {
|
||||
var real;
|
||||
|
||||
var channel_id_to_child;
|
||||
var pending_children;
|
||||
var active_children;
|
||||
}
|
||||
|
||||
function lws_meta_ws_child() {
|
||||
var onopen;
|
||||
var onmessage;
|
||||
var onclose;
|
||||
|
||||
var channel_id;
|
||||
|
||||
var subprotocol;
|
||||
var suburl;
|
||||
var cookie;
|
||||
|
||||
var extensions;
|
||||
|
||||
var parent;
|
||||
}
|
||||
|
||||
lws_meta_ws_child.prototype.send = function(data)
|
||||
{
|
||||
|
||||
if (typeof data == "string") {
|
||||
data = String.fromCharCode(lws_meta_cmd.WRITE) +
|
||||
String.fromCharCode(this.channel_id) +
|
||||
data;
|
||||
|
||||
return this.parent.real.send(data);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
var ab = new Uint8Array(data.length + 2);
|
||||
|
||||
ab[0] = lws_meta_cmd.WRITE;
|
||||
ab[1] = this.channel_id;
|
||||
ab.set(data, 2);
|
||||
|
||||
return this.parent.real.send(ab);
|
||||
}
|
||||
}
|
||||
|
||||
lws_meta_ws_child.prototype.close = function(close_code, close_string)
|
||||
{
|
||||
var pkt = new Uint8Array(129), m = 0, pkt1;
|
||||
|
||||
pkt[m++] = lws_meta_cmd.CLOSE_RQ;
|
||||
pkt[m++] = this.channel_id;
|
||||
|
||||
pkt[m++] = close_string.length + 0x20;
|
||||
|
||||
pkt[m++] = close_code / 256;
|
||||
pkt[m++] = close_code % 256;
|
||||
|
||||
for (i = 0; i < close_string.length; i++)
|
||||
pkt[m++] = close_string.charCodeAt(i);
|
||||
|
||||
pkt1 = new Uint8Array(m);
|
||||
for (n = 0; n < m; n++)
|
||||
pkt1[n] = pkt[n];
|
||||
|
||||
this.parent.real.send(pkt1.buffer);
|
||||
}
|
||||
|
||||
/* make a real ws connection using lws_meta*/
|
||||
lws_meta_ws.prototype.new_parent = function(urlpath)
|
||||
{
|
||||
var n, i, m = 0, pkt1;
|
||||
|
||||
this.ordinal = 1;
|
||||
this.pending_children = [];
|
||||
this.active_children = [];
|
||||
this.real = new_ws(urlpath, "lws-meta");
|
||||
|
||||
this.real.binaryType = 'arraybuffer';
|
||||
this.real.myparent = this;
|
||||
|
||||
this.real.onopen = function() {
|
||||
pkt = new Uint8Array(1024);
|
||||
var n, i, m = 0, pkt1;
|
||||
console.log("real open - pending children " + this.myparent.pending_children.length);
|
||||
for (n = 0; n < this.myparent.pending_children.length; n++) {
|
||||
|
||||
var p = this.myparent.pending_children[n];
|
||||
|
||||
pkt[m++] = lws_meta_cmd.OPEN_SUBCHANNEL;
|
||||
for (i = 0; i < p.subprotocol.length; i++)
|
||||
pkt[m++] = p.subprotocol.charCodeAt(i);
|
||||
pkt[m++] = 0;
|
||||
for (i = 0; i < p.suburl.length; i++)
|
||||
pkt[m++] = p.suburl.charCodeAt(i);
|
||||
pkt[m++] = 0;
|
||||
for (i = 0; i < p.cookie.length; i++)
|
||||
pkt[m++] = p.cookie.charCodeAt(i);
|
||||
pkt[m++] = 0;
|
||||
}
|
||||
|
||||
pkt1 = new Uint8Array(m);
|
||||
for (n = 0; n < m; n++)
|
||||
pkt1[n] = pkt[n];
|
||||
|
||||
console.log(this.myparent.pending_children[0].subprotocol);
|
||||
console.log(pkt1);
|
||||
|
||||
this.send(pkt1.buffer);
|
||||
}
|
||||
|
||||
|
||||
this.real.onmessage = function(msg) {
|
||||
|
||||
if (typeof msg.data != "string") {
|
||||
var ba = new Uint8Array(msg.data), n = 0;
|
||||
|
||||
while (n < ba.length) {
|
||||
|
||||
switch (ba[n++]) {
|
||||
case lws_meta_cmd.OPEN_RESULT:
|
||||
{
|
||||
var m = 0, cookie = "", protocol = "", ch = 0;
|
||||
var ws = this.myparent;
|
||||
/* cookie NUL
|
||||
* channel index + 0x20
|
||||
* protocol NUL
|
||||
*/
|
||||
while (ba[n])
|
||||
cookie = cookie + String.fromCharCode(ba[n++]);
|
||||
n++;
|
||||
ch = ba[n++];
|
||||
|
||||
while (ba[n])
|
||||
protocol = protocol + String.fromCharCode(ba[n++]);
|
||||
|
||||
console.log("open result " + cookie + " " + protocol + " " + ch + " pending len " + ws.pending_children.length);
|
||||
|
||||
for (m = 0; m < ws.pending_children.length; m++) {
|
||||
if (ws.pending_children[m].cookie == cookie) {
|
||||
var newchild = ws.pending_children[m];
|
||||
|
||||
/* found it */
|
||||
ws.pending_children[m].channel_id = ch;
|
||||
/* add to active children array */
|
||||
ws.active_children.push(ws.pending_children[m]);
|
||||
/* remove from pending children array */
|
||||
ws.pending_children.splice(m, 1);
|
||||
|
||||
newchild.parent = ws;
|
||||
newchild.extensions = this.extensions;
|
||||
|
||||
newchild.onopen();
|
||||
|
||||
console.log("made active " + cookie);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case lws_meta_cmd.CLOSE_NOT:
|
||||
{
|
||||
var code = 0, str = "", ch = 0, m, le;
|
||||
var ba = new Uint8Array(msg.data);
|
||||
/*
|
||||
* BYTE: channel
|
||||
* BYTE: MSB status code
|
||||
* BYTE: LSB status code
|
||||
* BYTES: rest of message is close status string
|
||||
*/
|
||||
|
||||
ch = ba[n++];
|
||||
le = ba[n++] - 0x20;
|
||||
code = ba[n++] * 256;
|
||||
code += ba[n++];
|
||||
|
||||
while (le--)
|
||||
str += String.fromCharCode(ba[n++]);
|
||||
|
||||
console.log("channel id " + ch + " code " + code + " str " + str + " len " + str.length);
|
||||
|
||||
for (m = 0; m < this.myparent.active_children.length; m++)
|
||||
if (this.myparent.active_children[m].channel_id == ch) {
|
||||
var child = this.myparent.active_children[m];
|
||||
var ms = new CloseEvent("close", { code:code, reason:str } );
|
||||
|
||||
/* reply with close ack */
|
||||
this.send(msg.data);
|
||||
|
||||
if (child.onclose)
|
||||
child.onclose(ms);
|
||||
|
||||
this.myparent.active_children.splice(m, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
} // switch
|
||||
}
|
||||
} else {
|
||||
if (msg.data.charCodeAt(0) == lws_meta_cmd.WRITE ) {
|
||||
var ch = msg.data.charCodeAt(1), m, ms;
|
||||
var ws = this.myparent, ms;
|
||||
|
||||
for (m = 0; m < ws.active_children.length; m++) {
|
||||
if (ws.active_children[m].channel_id == ch) {
|
||||
ms = new MessageEvent("WebSocket", { data: msg.data.substr(2, msg.data.length - 2) } );
|
||||
if (ws.active_children[m].onmessage)
|
||||
ws.active_children[m].onmessage(ms);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.real.onclose = function() {
|
||||
var ws = this.myparent, m;
|
||||
for (m = 0; m < ws.active_children.length; m++) {
|
||||
var child = ws.active_children[m];
|
||||
var ms = new CloseEvent("close", { code:1000, reason:"parent closed" } );
|
||||
|
||||
if (child.onclose)
|
||||
child.onclose(ms);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* make a child connection using existing lws_meta real ws connection */
|
||||
lws_meta_ws.prototype.new_ws = function(suburl, protocol)
|
||||
{
|
||||
var ch = new lws_meta_ws_child();
|
||||
|
||||
ch.suburl = suburl;
|
||||
ch.subprotocol = protocol;
|
||||
ch.cookie = "C" + this.ordinal++;
|
||||
|
||||
this.pending_children.push(ch);
|
||||
|
||||
if (this.real.readyState == 1)
|
||||
this.real.onopen();
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* end of lws-meta helpers
|
||||
*/
|
||||
|
||||
function lws_san(s)
|
||||
{
|
||||
if (s.search("<") != -1)
|
||||
if (s.search("<") !== -1)
|
||||
return "invalid string";
|
||||
|
||||
return s;
|
||||
|
|
|
@ -555,37 +555,13 @@ if (params.mirror)
|
|||
console.log(mirror_name);
|
||||
|
||||
|
||||
/*
|
||||
* if using lws-meta to carry the other ws connections, declare the
|
||||
* parent connection object and start its connection to the server.
|
||||
*
|
||||
* These helpers are defined in lws-common.js
|
||||
*/
|
||||
|
||||
var use_lws_meta = 0, lws_meta;
|
||||
|
||||
if (use_lws_meta) {
|
||||
lws_meta = new lws_meta_ws();
|
||||
lws_meta.new_parent(get_appropriate_ws_url("?mirror=" + mirror_name));
|
||||
}
|
||||
|
||||
|
||||
document.getElementById("number").textContent = get_appropriate_ws_url(mirror_name);
|
||||
|
||||
/* dumb increment protocol */
|
||||
|
||||
/*
|
||||
* to connect via an lws-meta connection, start the connection using
|
||||
* lws_meta.new_ws(). To connect by independent connection, start
|
||||
* the connection using just new_ws()
|
||||
*/
|
||||
|
||||
var socket_di;
|
||||
|
||||
if (use_lws_meta)
|
||||
socket_di = lws_meta.new_ws("", "dumb-increment-protocol");
|
||||
else
|
||||
socket_di = new_ws(get_appropriate_ws_url(""), "dumb-increment-protocol");
|
||||
socket_di = new_ws(get_appropriate_ws_url(""), "dumb-increment-protocol");
|
||||
|
||||
try {
|
||||
socket_di.onopen = function() {
|
||||
|
@ -609,10 +585,7 @@ document.getElementById("number").textContent = get_appropriate_ws_url(mirror_na
|
|||
|
||||
var socket_status, jso, s;
|
||||
|
||||
if (use_lws_meta)
|
||||
socket_status = lws_meta.new_ws("", "lws-status");
|
||||
else
|
||||
socket_status = new_ws(get_appropriate_ws_url(""), "lws-status");
|
||||
socket_status = new_ws(get_appropriate_ws_url(""), "lws-status");
|
||||
|
||||
try {
|
||||
socket_status.onopen = function() {
|
||||
|
@ -681,10 +654,7 @@ function on_pmd() {
|
|||
var socket_ot;
|
||||
|
||||
function ot_open() {
|
||||
if (use_lws_meta)
|
||||
socket_ot = lws_meta.new_ws(get_appropriate_ws_url(""), "dumb-increment-protocol");
|
||||
else
|
||||
socket_ot = new_ws(get_appropriate_ws_url(""), "dumb-increment-protocol");
|
||||
socket_ot = new_ws(get_appropriate_ws_url(""), "dumb-increment-protocol");
|
||||
|
||||
console.log("ot_open");
|
||||
|
||||
|
@ -732,11 +702,7 @@ function ot_req_close() {
|
|||
var pending = "";
|
||||
var lm_timer;
|
||||
|
||||
if (use_lws_meta)
|
||||
socket_lm = lws_meta.new_ws(get_appropriate_ws_url("?mirror=" + mirror_name),
|
||||
"lws-mirror-protocol");
|
||||
else
|
||||
socket_lm = new_ws(get_appropriate_ws_url("?mirror=" + mirror_name),
|
||||
socket_lm = new_ws(get_appropriate_ws_url("?mirror=" + mirror_name),
|
||||
"lws-mirror-protocol");
|
||||
try {
|
||||
socket_lm.onopen = function() {
|
||||
|
|
|
@ -49,7 +49,6 @@ file_upload_cb(void *data, const char *name, const char *filename,
|
|||
char *buf, int len, enum lws_spa_fileupload_states state)
|
||||
{
|
||||
struct pss *pss = (struct pss *)data;
|
||||
int n;
|
||||
|
||||
switch (state) {
|
||||
case LWS_UFS_OPEN:
|
||||
|
@ -68,6 +67,8 @@ file_upload_cb(void *data, const char *name, const char *filename,
|
|||
case LWS_UFS_FINAL_CONTENT:
|
||||
case LWS_UFS_CONTENT:
|
||||
if (len) {
|
||||
int n;
|
||||
|
||||
pss->file_length += len;
|
||||
|
||||
n = write(pss->fd, buf, len);
|
||||
|
|
|
@ -37,6 +37,7 @@ static int
|
|||
callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason,
|
||||
void *user, void *in, size_t len)
|
||||
{
|
||||
const char *cp = (const char *)in;
|
||||
|
||||
switch (reason) {
|
||||
|
||||
|
@ -93,7 +94,7 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
case LWS_CALLBACK_RAW_RX:
|
||||
lwsl_user("LWS_CALLBACK_RAW_RX (%d)\n", (int)len);
|
||||
while (len--)
|
||||
putchar(*((const char *)in++));
|
||||
putchar(*cp++);
|
||||
fflush(stdout);
|
||||
break;
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ -z "$1" -o -z "$2" ] ; then
|
||||
echo "required args missing"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#/bin/bash
|
||||
#!/bin/bash
|
||||
#
|
||||
# run this from your build dir having configured
|
||||
# -DLWS_WITH_MINIMAL_EXAMPLES=1 to get all the examples
|
||||
|
|
|
@ -161,7 +161,8 @@ callback_minimal_client_echo(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
pmsg->first, pmsg->final);
|
||||
|
||||
/* notice we allowed for LWS_PRE in the payload already */
|
||||
m = lws_write(wsi, pmsg->payload + LWS_PRE, pmsg->len, flags);
|
||||
m = lws_write(wsi, ((unsigned char *)pmsg->payload) +
|
||||
LWS_PRE, pmsg->len, flags);
|
||||
if (m < (int)pmsg->len) {
|
||||
lwsl_err("ERROR %d writing to ws socket\n", m);
|
||||
return -1;
|
||||
|
|
|
@ -228,7 +228,7 @@ callback_minimal_pmd_bulk(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
return -1;
|
||||
}
|
||||
pss->position_rx += s;
|
||||
in += s;
|
||||
in = ((unsigned char *)in) + s;
|
||||
len -= s;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -214,8 +214,8 @@ init_fail:
|
|||
goto skip;
|
||||
|
||||
/* notice we allowed for LWS_PRE in the payload already */
|
||||
m = lws_write(wsi, pmsg->payload + LWS_PRE, pmsg->len,
|
||||
LWS_WRITE_TEXT);
|
||||
m = lws_write(wsi, ((unsigned char *)pmsg->payload) + LWS_PRE,
|
||||
pmsg->len, LWS_WRITE_TEXT);
|
||||
if (m < (int)pmsg->len) {
|
||||
pthread_mutex_unlock(&vhd->lock_ring); /* } ring lock */
|
||||
lwsl_err("ERROR %d writing to ws socket\n", m);
|
||||
|
|
|
@ -133,8 +133,8 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
break;
|
||||
|
||||
/* notice we allowed for LWS_PRE in the payload already */
|
||||
m = lws_write(wsi, pmsg->payload + LWS_PRE, pmsg->len,
|
||||
LWS_WRITE_TEXT);
|
||||
m = lws_write(wsi, ((unsigned char *)pmsg->payload) + LWS_PRE,
|
||||
pmsg->len, LWS_WRITE_TEXT);
|
||||
if (m < (int)pmsg->len) {
|
||||
lwsl_err("ERROR %d writing to ws socket\n", m);
|
||||
return -1;
|
||||
|
|
|
@ -67,7 +67,7 @@ callback_minimal_server_echo(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
lws_get_protocol(wsi));
|
||||
const struct msg *pmsg;
|
||||
struct msg amsg;
|
||||
int n, m, flags;
|
||||
int n, flags;
|
||||
|
||||
switch (reason) {
|
||||
|
||||
|
@ -104,6 +104,8 @@ callback_minimal_server_echo(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
|
||||
lwsl_user("LWS_CALLBACK_SERVER_WRITEABLE\n");
|
||||
do {
|
||||
int m;
|
||||
|
||||
pmsg = lws_ring_get_element(pss->ring, &pss->tail);
|
||||
if (!pmsg) {
|
||||
lwsl_user(" (nothing in ring)\n");
|
||||
|
@ -115,7 +117,8 @@ callback_minimal_server_echo(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
pmsg->first, pmsg->final);
|
||||
|
||||
/* notice we allowed for LWS_PRE in the payload already */
|
||||
m = lws_write(wsi, pmsg->payload + LWS_PRE, pmsg->len, flags);
|
||||
m = lws_write(wsi, ((unsigned char *)pmsg->payload) +
|
||||
LWS_PRE, pmsg->len, flags);
|
||||
if (m < (int)pmsg->len) {
|
||||
lwsl_err("ERROR %d writing to ws socket\n", m);
|
||||
return -1;
|
||||
|
|
|
@ -186,7 +186,7 @@ callback_minimal_pmd_bulk(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
return -1;
|
||||
}
|
||||
pss->position_rx += s;
|
||||
in += s;
|
||||
in = ((char *)in) + s;
|
||||
len -= s;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -108,8 +108,8 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
break;
|
||||
|
||||
/* notice we allowed for LWS_PRE in the payload already */
|
||||
m = lws_write(wsi, vhd->amsg.payload + LWS_PRE, vhd->amsg.len,
|
||||
LWS_WRITE_TEXT);
|
||||
m = lws_write(wsi, ((unsigned char *)vhd->amsg.payload) +
|
||||
LWS_PRE, vhd->amsg.len, LWS_WRITE_TEXT);
|
||||
if (m < (int)vhd->amsg.len) {
|
||||
lwsl_err("ERROR %d writing to ws socket\n", m);
|
||||
return -1;
|
||||
|
|
|
@ -203,8 +203,8 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
break;
|
||||
|
||||
/* notice we allowed for LWS_PRE in the payload already */
|
||||
m = lws_write(wsi, pmsg->payload + LWS_PRE, pmsg->len,
|
||||
LWS_WRITE_TEXT);
|
||||
m = lws_write(wsi, ((unsigned char *)pmsg->payload) +
|
||||
LWS_PRE, pmsg->len, LWS_WRITE_TEXT);
|
||||
if (m < (int)pmsg->len) {
|
||||
lwsl_err("ERROR %d writing to ws socket\n", m);
|
||||
return -1;
|
||||
|
|
|
@ -224,8 +224,8 @@ init_fail:
|
|||
}
|
||||
|
||||
/* notice we allowed for LWS_PRE in the payload already */
|
||||
m = lws_write(wsi, pmsg->payload + LWS_PRE, pmsg->len,
|
||||
LWS_WRITE_TEXT);
|
||||
m = lws_write(wsi, ((unsigned char *)pmsg->payload) + LWS_PRE,
|
||||
pmsg->len, LWS_WRITE_TEXT);
|
||||
if (m < (int)pmsg->len) {
|
||||
pthread_mutex_unlock(&vhd->lock_ring); /* } ring lock ------- */
|
||||
lwsl_err("ERROR %d writing to ws socket\n", m);
|
||||
|
|
|
@ -102,8 +102,8 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
break;
|
||||
|
||||
/* notice we allowed for LWS_PRE in the payload already */
|
||||
m = lws_write(wsi, vhd->amsg.payload + LWS_PRE, vhd->amsg.len,
|
||||
LWS_WRITE_TEXT);
|
||||
m = lws_write(wsi, ((unsigned char *)vhd->amsg.payload) +
|
||||
LWS_PRE, vhd->amsg.len, LWS_WRITE_TEXT);
|
||||
if (m < (int)vhd->amsg.len) {
|
||||
lwsl_err("ERROR %d writing to ws\n", m);
|
||||
return -1;
|
||||
|
|
|
@ -126,7 +126,7 @@ span.bad {
|
|||
}
|
||||
|
||||
span.small {
|
||||
style=\"font-size:8pt;
|
||||
font-size:8pt;
|
||||
}
|
||||
|
||||
.green {
|
||||
|
|
|
@ -390,7 +390,7 @@ function lwsgs_cupdate()
|
|||
|
||||
if (!document.getElementById('cpassword').value ||
|
||||
!document.getElementById('cpassword2').value ||
|
||||
pwok == 0)
|
||||
pwok === 0)
|
||||
en_change = 0;
|
||||
|
||||
if (document.getElementById('showdel').checked)
|
||||
|
@ -432,7 +432,7 @@ function lwsgs_cupdate()
|
|||
else
|
||||
document.getElementById('cforgot').style.display = "none";
|
||||
|
||||
if (pwok == 0)
|
||||
if (pwok === 0)
|
||||
op = '0.5';
|
||||
else
|
||||
op = '1.0';
|
||||
|
@ -445,7 +445,7 @@ function lwsgs_check_user()
|
|||
{
|
||||
var xmlHttp = new XMLHttpRequest();
|
||||
xmlHttp.onreadystatechange = function() {
|
||||
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
|
||||
if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
|
||||
lwsgs_user_check = xmlHttp.responseText;
|
||||
lwsgs_rupdate();
|
||||
}
|
||||
|
@ -458,7 +458,7 @@ function lwsgs_check_email(id)
|
|||
{
|
||||
var xmlHttp = new XMLHttpRequest();
|
||||
xmlHttp.onreadystatechange = function() {
|
||||
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
|
||||
if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
|
||||
lwsgs_email_check = xmlHttp.responseText;
|
||||
lwsgs_rupdate();
|
||||
}
|
||||
|
@ -547,7 +547,7 @@ window.addEventListener("load", function() {
|
|||
wos = 0;
|
||||
else {
|
||||
wos++;
|
||||
if (wos == 40) {
|
||||
if (wos === 40) {
|
||||
wos = 0;
|
||||
r = r + ' ';
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@ function lwsgt_get_appropriate_ws_url()
|
|||
var pcol;
|
||||
var u = document.URL;
|
||||
|
||||
if (u.substring(0, 5) == "https") {
|
||||
if (u.substring(0, 5) === "https") {
|
||||
pcol = "wss://";
|
||||
u = u.substr(8);
|
||||
} else {
|
||||
pcol = "ws://";
|
||||
if (u.substring(0, 4) == "http")
|
||||
if (u.substring(0, 4) === "http")
|
||||
u = u.substr(7);
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,8 @@ function lwsgt_app_hdr(j, bc, ws)
|
|||
if (!j.cols[n].hide)
|
||||
m++;
|
||||
|
||||
s = "<tr><td colspan=\"" + m + "\" class=\"lwsgt_title\">" + ws.lwsgt_title + "</td></tr>"
|
||||
s = "<tr><td colspan=\"" + m + "\" class=\"lwsgt_title\">" +
|
||||
ws.lwsgt_title + "</td></tr>";
|
||||
|
||||
if (!!bc) {
|
||||
s += "<tr><td colspan=\"" + m + "\" class=\"lwsgt_breadcrumbs\">";
|
||||
|
@ -34,7 +35,8 @@ function lwsgt_app_hdr(j, bc, ws)
|
|||
if (!bc[n].url && bc[n].url !== "")
|
||||
s += " " + lws_san(bc[n].name) + " ";
|
||||
else {
|
||||
s = s + "<a href=# id=\"bc_"+ ws.divname + ws.bcq + "\" h=\"" + ws.lwsgt_cb + "\" p=\""+ws.lwsgt_parent+"\" aa=\"="+
|
||||
s += "<a href=# id=\"bc_"+ ws.divname + ws.bcq + "\" h=\"" +
|
||||
ws.lwsgt_cb + "\" p=\""+ws.lwsgt_parent+"\" aa=\"="+
|
||||
lws_san(encodeURI(bc[n].url))+"\" m=\"-1\" n=\"-1\">" +
|
||||
lws_san(bc[n].name) + "</a> ";
|
||||
ws.bcq++;
|
||||
|
@ -45,18 +47,25 @@ function lwsgt_app_hdr(j, bc, ws)
|
|||
s += "<tr>";
|
||||
for (n = 0; n < j.cols.length; n++)
|
||||
if (!j.cols[n].hide)
|
||||
s = s + "<td class=\"lwsgt_hdr\">" + lws_san(j.cols[n].name) + "</td>";
|
||||
s = s + "<td class=\"lwsgt_hdr\">" + lws_san(j.cols[n].name) +
|
||||
"</td>";
|
||||
|
||||
s += "</tr>";
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
function lwsgt_click_callthru()
|
||||
{
|
||||
window[this.getAttribute("h")](this.getAttribute("p"), this.getAttribute("aa"), this.getAttribute("m"), this.getAttribute("n"));
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
function lwsgt_initial(title, pcol, divname, cb, gname)
|
||||
{
|
||||
this.divname = divname;
|
||||
|
||||
lws_gray_out(true,{'zindex':'499'});
|
||||
lws_gray_out(true,{"zindex":"499"});
|
||||
|
||||
if (typeof MozWebSocket != "undefined")
|
||||
this.lwsgt_ws = new MozWebSocket(lwsgt_get_appropriate_ws_url(), pcol);
|
||||
|
@ -71,7 +80,7 @@ function lwsgt_initial(title, pcol, divname, cb, gname)
|
|||
lws_gray_out(false);
|
||||
// document.getElementById("debug").textContent =
|
||||
// "ws opened " + lwsgt_get_appropriate_ws_url();
|
||||
}
|
||||
};
|
||||
this.lwsgt_ws.onmessage = function got_packet(msg) {
|
||||
var s, m, n, j = JSON.parse(msg.data);
|
||||
document.getElementById("debug").textContent = msg.data;
|
||||
|
@ -114,24 +123,20 @@ function lwsgt_initial(title, pcol, divname, cb, gname)
|
|||
s = s + "</table>";
|
||||
document.getElementById(this.divname).innerHTML = s;
|
||||
for (n = 0; n < q; n++)
|
||||
document.getElementById(this.divname + n).onclick = lwsgt_click_callthru;
|
||||
document.getElementById(this.divname + n).onclick =
|
||||
lwsgt_click_callthru;
|
||||
|
||||
for (n = 0; n < this.bcq; n++)
|
||||
document.getElementById("bc_" + this.divname + n).onclick = lwsgt_click_callthru;
|
||||
document.getElementById("bc_" + this.divname + n).onclick =
|
||||
lwsgt_click_callthru;
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
this.lwsgt_ws.onclose = function(){
|
||||
lws_gray_out(true,{'zindex':'499'});
|
||||
}
|
||||
lws_gray_out(true,{"zindex":"499"});
|
||||
};
|
||||
} catch(exception) {
|
||||
alert('<p>Error' + exception);
|
||||
alert("<p>Error" + exception);
|
||||
}
|
||||
}
|
||||
|
||||
function lwsgt_click_callthru()
|
||||
{
|
||||
window[this.getAttribute("h")](this.getAttribute("p"), this.getAttribute("aa"), this.getAttribute("m"), this.getAttribute("n"));
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
|
|
|
@ -27,11 +27,6 @@
|
|||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
struct lws_ss_load_sample {
|
||||
time_t t;
|
||||
int load_x100;
|
||||
};
|
||||
|
||||
struct lws_ss_filepath {
|
||||
struct lws_ss_filepath *next;
|
||||
char filepath[128];
|
||||
|
@ -40,10 +35,6 @@ struct lws_ss_filepath {
|
|||
struct lws_ss_dumps {
|
||||
char buf[32768];
|
||||
int length;
|
||||
|
||||
struct lws_ss_load_sample load[64];
|
||||
int load_head;
|
||||
int load_tail;
|
||||
};
|
||||
|
||||
struct per_session_data__server_status {
|
||||
|
@ -110,7 +101,6 @@ update(struct per_vhost_data__lws_server_status *v)
|
|||
}
|
||||
n = lws_snprintf(p, l, "]}");
|
||||
p += n;
|
||||
l -= n;
|
||||
|
||||
v->d.length = p - (v->d.buf + LWS_PRE);
|
||||
|
||||
|
|
|
@ -242,7 +242,7 @@ static int
|
|||
ssh_ops_is_pubkey_authorized(const char *username, const char *type,
|
||||
const uint8_t *peer, int peer_len)
|
||||
{
|
||||
char *aps = NULL, *p, *ps;
|
||||
char *aps, *p, *ps;
|
||||
int n = (int)strlen(type), alen = 2048, ret = 2, len;
|
||||
size_t s = 0;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(function () {
|
||||
(function() {
|
||||
|
||||
/*
|
||||
* We display untrusted stuff in html context... reject anything
|
||||
|
@ -7,7 +7,7 @@
|
|||
|
||||
function san(s)
|
||||
{
|
||||
if (s.search("<") != -1)
|
||||
if (s.search("<") !== -1)
|
||||
return "invalid string";
|
||||
|
||||
return s;
|
||||
|
@ -15,7 +15,7 @@ function san(s)
|
|||
|
||||
function humanize(s)
|
||||
{
|
||||
i = parseInt(s);
|
||||
var i = parseInt(s, 10);
|
||||
|
||||
if (i > 1000000000)
|
||||
return (i / 1000000000).toFixed(3) + "G";
|
||||
|
@ -41,16 +41,16 @@ function get_appropriate_ws_url()
|
|||
* https:// url itself, otherwise unencrypted
|
||||
*/
|
||||
|
||||
if (u.substring(0, 5) == "https") {
|
||||
if (u.substring(0, 5) === "https") {
|
||||
pcol = "wss://";
|
||||
u = u.substr(8);
|
||||
} else {
|
||||
pcol = "ws://";
|
||||
if (u.substring(0, 4) == "http")
|
||||
if (u.substring(0, 4) === "http")
|
||||
u = u.substr(7);
|
||||
}
|
||||
|
||||
u = u.split('/');
|
||||
u = u.split("/");
|
||||
|
||||
/* + "/xxx" bit is for IE10 workaround */
|
||||
|
||||
|
@ -69,7 +69,7 @@ function ws_open_server_status()
|
|||
socket_status.onopen = function() {
|
||||
document.getElementById("title").innerHTML = "Server Status (Active)";
|
||||
lws_gray_out(false);
|
||||
}
|
||||
};
|
||||
|
||||
socket_status.onmessage =function got_packet(msg) {
|
||||
var u, ci, n;
|
||||
|
@ -77,9 +77,9 @@ function ws_open_server_status()
|
|||
if (msg.data.length < 100)
|
||||
return;
|
||||
jso = JSON.parse(msg.data);
|
||||
u = parseInt(san(jso.i.uptime));
|
||||
u = parseInt(san(jso.i.uptime), 10);
|
||||
|
||||
if (parseInt(jso.i.contexts[0].deprecated) == 0)
|
||||
if (parseInt(jso.i.contexts[0].deprecated, 10) === 0)
|
||||
s = "<table><tr><td></td><td class=\"c0\">";
|
||||
else
|
||||
s = "<table><tr><td></td><td class=\"dc0\">";
|
||||
|
@ -107,14 +107,14 @@ function ws_open_server_status()
|
|||
|
||||
for (ci = 0; ci < jso.i.contexts.length; ci++) {
|
||||
|
||||
if (parseInt(jso.i.contexts[ci].deprecated) == 0)
|
||||
if (parseInt(jso.i.contexts[ci].deprecated, 10) === 0)
|
||||
s += "<tr><td></td><td class=\"c\">" +
|
||||
"Active Context</td><td>";
|
||||
else
|
||||
s += "<tr><td></td><td class=\"c1\">" +
|
||||
"Deprecated Context " + ci + "</td><td>";
|
||||
|
||||
u = parseInt(san(jso.i.contexts[ci].context_uptime));
|
||||
u = parseInt(san(jso.i.contexts[ci].context_uptime), 10);
|
||||
s += "<span class=n>Uptime:</span> <span class=v>" +
|
||||
((u / (24 * 3600)) | 0) + "d " +
|
||||
(((u % (24 * 3600)) / 3600) | 0) + "h " +
|
||||
|
@ -123,8 +123,8 @@ function ws_open_server_status()
|
|||
s = s +
|
||||
"<br>" +
|
||||
"<span class=n>Listening wsi:</span> <span class=v>" + san(jso.i.contexts[ci].listen_wsi) + "</span>, " +
|
||||
"<span class=n>Current wsi alive:</span> <span class=v>" + (parseInt(san(jso.i.contexts[ci].wsi_alive)) -
|
||||
parseInt(san(jso.i.contexts[ci].listen_wsi))) + "</span><br>" +
|
||||
"<span class=n>Current wsi alive:</span> <span class=v>" + (parseInt(san(jso.i.contexts[ci].wsi_alive), 10) -
|
||||
parseInt(san(jso.i.contexts[ci].listen_wsi), 10)) + "</span><br>" +
|
||||
"<span class=n>Total Rx:</span> <span class=v>" + humanize(san(jso.i.contexts[ci].rx)) +"</span>, " +
|
||||
"<span class=n>Total Tx:</span> <span class=v>" + humanize(san(jso.i.contexts[ci].tx)) +"</span><br>" +
|
||||
|
||||
|
@ -144,7 +144,7 @@ function ws_open_server_status()
|
|||
|
||||
for (n = 0; n < jso.i.contexts[ci].pt.length; n++) {
|
||||
|
||||
if (parseInt(jso.i.contexts[ci].deprecated) == 0)
|
||||
if (parseInt(jso.i.contexts[ci].deprecated, 10) === 0)
|
||||
s += "<tr><td> </td><td class=\"l\">service thread " + (n + 1);
|
||||
else
|
||||
s += "<tr><td> </td><td class=\"dl\">service thread " + (n + 1);
|
||||
|
@ -159,18 +159,18 @@ function ws_open_server_status()
|
|||
|
||||
}
|
||||
for (n = 0; n < jso.i.contexts[ci].vhosts.length; n++) {
|
||||
if (parseInt(jso.i.contexts[ci].deprecated) == 0)
|
||||
if (parseInt(jso.i.contexts[ci].deprecated, 10) === 0)
|
||||
s += "<tr><td> </td><td class=\"l\">vhost " + (n + 1);
|
||||
else
|
||||
s += "<tr><td> </td><td class=\"dl\">vhost " + (n + 1);
|
||||
s += "</td><td><span class=\"mountname\">";
|
||||
if (jso.i.contexts[ci].vhosts[n].use_ssl == '1')
|
||||
if (jso.i.contexts[ci].vhosts[n].use_ssl === "1")
|
||||
s = s + "https://";
|
||||
else
|
||||
s = s + "http://";
|
||||
s = s + san(jso.i.contexts[ci].vhosts[n].name) + ":" +
|
||||
san(jso.i.contexts[ci].vhosts[n].port) + "</span>";
|
||||
if (jso.i.contexts[ci].vhosts[n].sts == '1')
|
||||
if (jso.i.contexts[ci].vhosts[n].sts === "1")
|
||||
s = s + " (STS)";
|
||||
s = s +"<br>" +
|
||||
|
||||
|
@ -196,7 +196,7 @@ function ws_open_server_status()
|
|||
"</span></td><td><span class=\"m2\">" +
|
||||
san(jso.i.contexts[ci].vhosts[n].mounts[m].origin) +
|
||||
"</span></td><td>";
|
||||
if (parseInt(san(jso.i.contexts[ci].vhosts[n].mounts[m].cache_max_age)))
|
||||
if (parseInt(san(jso.i.contexts[ci].vhosts[n].mounts[m].cache_max_age), 10))
|
||||
s = s + "<span class=n>max-age:</span> <span class=v>" +
|
||||
san(jso.i.contexts[ci].vhosts[n].mounts[m].cache_max_age) +
|
||||
"</span>, <span class=n>reuse:</span> <span class=v>" +
|
||||
|
@ -205,7 +205,7 @@ function ws_open_server_status()
|
|||
san(jso.i.contexts[ci].vhosts[n].mounts[m].cache_revalidate) +
|
||||
"</span>, <span class=n>inter:</span> <span class=v>" +
|
||||
san(jso.i.contexts[ci].vhosts[n].mounts[m].cache_intermediaries);
|
||||
s = s + "</span></td></tr>"
|
||||
s = s + "</span></td></tr>";
|
||||
}
|
||||
s = s + "</table>";
|
||||
s = s + "</td></tr>";
|
||||
|
@ -217,14 +217,14 @@ function ws_open_server_status()
|
|||
s = s + "</table>";
|
||||
|
||||
document.getElementById("conninfo").innerHTML = s;
|
||||
}
|
||||
};
|
||||
|
||||
socket_status.onclose = function(){
|
||||
document.getElementById("title").innerHTML = "Server Status (Disconnected)";
|
||||
lws_gray_out(true,{'zindex':'499'});
|
||||
}
|
||||
lws_gray_out(true,{"zindex":"499"});
|
||||
};
|
||||
} catch(exception) {
|
||||
alert('<p>Error' + exception);
|
||||
alert("<p>Error" + exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,10 +232,11 @@ function ws_open_server_status()
|
|||
|
||||
window.addEventListener("load", function() {
|
||||
|
||||
lws_gray_out(true,{'zindex':'499'});
|
||||
lws_gray_out(true,{"zindex":"499"});
|
||||
|
||||
ws_open_server_status();
|
||||
|
||||
}, false);
|
||||
|
||||
})();
|
||||
}());
|
||||
|
||||
|
|
|
@ -180,11 +180,10 @@ void sc25519_add(sc25519 *r, const sc25519 *x, const sc25519 *y)
|
|||
void sc25519_sub_nored(sc25519 *r, const sc25519 *x, const sc25519 *y)
|
||||
{
|
||||
uint32_t b = 0;
|
||||
uint32_t t;
|
||||
int i;
|
||||
for(i=0;i<32;i++)
|
||||
{
|
||||
t = x->v[i] - y->v[i] - b;
|
||||
uint32_t t = x->v[i] - y->v[i] - b;
|
||||
r->v[i] = t & 255;
|
||||
b = (t >> 8) & 1;
|
||||
}
|
||||
|
|
|
@ -60,10 +60,10 @@ static void freeze(unsigned int a[32])
|
|||
static void mult(unsigned int out[32],const unsigned int a[32],const unsigned int b[32])
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
unsigned int u;
|
||||
|
||||
for (i = 0;i < 32;++i) {
|
||||
unsigned int j;
|
||||
unsigned int u;
|
||||
u = 0;
|
||||
for (j = 0;j <= i;++j) u += a[j] * b[i - j];
|
||||
for (j = i + 1;j < 32;++j) u += 38 * a[j] * b[i + 32 - j];
|
||||
|
|
|
@ -50,7 +50,6 @@ rm -rf $RPM_BUILD_ROOT
|
|||
/usr/bin/libwebsockets-test-server
|
||||
/usr/bin/libwebsockets-test-client
|
||||
/usr/bin/libwebsockets-test-sshd
|
||||
/usr/bin/libwebsockets-test-fuzxy
|
||||
/usr/bin/libwebsockets-test-lejp
|
||||
/usr/bin/libwebsockets-test-server-extpoll
|
||||
/usr/bin/lwsws
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#/bin/bash
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$COVERITY_SCAN_BRANCH" != 1 -a "$TRAVIS_OS_NAME" = "osx" ]; then
|
||||
if [ "$LWS_METHOD" != "mbedtls" ] ; then
|
||||
|
|
|
@ -10,9 +10,9 @@ then
|
|||
then
|
||||
sudo apt-get install -y -qq realpath libjemalloc1 libev4 libuv-dev libdbus-1-dev
|
||||
sudo apt-get remove python-six
|
||||
sudo pip install six>=1.9
|
||||
sudo pip install Twisted==16.0.0
|
||||
sudo pip install pyopenssl>=0.14
|
||||
sudo pip install "six>=1.9"
|
||||
sudo pip install "Twisted==16.0.0"
|
||||
sudo pip install "pyopenssl>=0.14"
|
||||
sudo pip install autobahntestsuite
|
||||
wget https://libwebsockets.org/openssl-1.1.0-trusty.tar.bz2 -O/tmp/openssl.tar.bz2
|
||||
cd /
|
||||
|
|
|
@ -1,967 +0,0 @@
|
|||
/*
|
||||
* fuzzing proxy - network-level fuzzing injection proxy
|
||||
*
|
||||
* Copyright (C) 2016 Andy Green <andy@warmcat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation:
|
||||
* version 2.1 of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
*
|
||||
* fuzxy is designed to go on the client path
|
||||
*
|
||||
* [ client <-> fuzxy ] <-> server
|
||||
*
|
||||
* you can arrange that with, eg,
|
||||
*
|
||||
* http_proxy=localhost:8880
|
||||
*
|
||||
* env var before starting the client.
|
||||
*
|
||||
* Even though he is on the client side, he is able to see and change traffic
|
||||
* in both directions, and so fuzz both the client and the server.
|
||||
*/
|
||||
|
||||
#if defined(_WIN32) && defined(EXTERNAL_POLL)
|
||||
#define WINVER 0x0600
|
||||
#define _WIN32_WINNT 0x0600
|
||||
#define poll(fdArray, fds, timeout) WSAPoll((LPWSAPOLLFD)(fdArray), (ULONG)(fds), (INT)(timeout))
|
||||
#endif
|
||||
|
||||
#include "lws_config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#include "gettimeofday.h"
|
||||
#else
|
||||
#include <syslog.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#if defined(__sun)
|
||||
#include <strings.h> /* bzero */
|
||||
#endif
|
||||
|
||||
#define MAX_FUZZ_BUF (1024 * 1024)
|
||||
|
||||
enum types {
|
||||
FZY_S_DEAD = 0,
|
||||
FZY_S_LISTENING = 1,
|
||||
FZY_S_ACCEPTED = 2,
|
||||
FZY_S_PROXIED = 3,
|
||||
FZY_S_ONWARD = 4,
|
||||
};
|
||||
|
||||
enum proxy_parser_states {
|
||||
FZY_PP_CONNECT = 0,
|
||||
FZY_PP_ADDRESS = 1,
|
||||
FZY_PP_PORT = 2,
|
||||
FZY_PP_CRLFS = 3,
|
||||
};
|
||||
|
||||
enum fuzzer_parser_states {
|
||||
FZY_FP_SEARCH = 0,
|
||||
FZY_FP_SEARCH2 = 1,
|
||||
FZY_FP_INJECT_PREPARE = 2,
|
||||
FZY_FP_INJECT = 3,
|
||||
FZY_FP_PENDING = 4,
|
||||
};
|
||||
|
||||
struct ring {
|
||||
char buf[4096];
|
||||
int head;
|
||||
int tail;
|
||||
};
|
||||
|
||||
struct state {
|
||||
enum types type;
|
||||
enum proxy_parser_states pp;
|
||||
int ppc;
|
||||
|
||||
struct ring in;
|
||||
|
||||
char address[256];
|
||||
int port;
|
||||
|
||||
enum fuzzer_parser_states fp;
|
||||
int fuzc;
|
||||
int pending;
|
||||
|
||||
int twin; /* must be fixed up when arrays lose guys */
|
||||
unsigned int outbound:1; /* from local -> remote */
|
||||
unsigned int is_pending:1;
|
||||
|
||||
unsigned char buf[MAX_FUZZ_BUF];
|
||||
unsigned int inject_len;
|
||||
};
|
||||
|
||||
struct test {
|
||||
const char *s[3];
|
||||
int len[2];
|
||||
unsigned int swallow:1;
|
||||
};
|
||||
|
||||
int force_exit = 0;
|
||||
int which = 5;
|
||||
|
||||
static const struct test tests[] = {
|
||||
{ { NULL, "\x0d\x0a\x0d\x0a",
|
||||
"{ 0xd9, 0x87, 0xd2, 0x88, 0xd2, (248){ 0x89, 0xd2 }, 0x0d, 0x0a },"
|
||||
}, { 0, 4 }, 1 },
|
||||
{ { NULL, "\x0d\x0a\x0d\x0a",
|
||||
"{ 0xd9, 0x87, 0xd2, 0x88, 0xd2, (1373){ 0x89, 0xd2 }, 0x0d, 0x0a },"
|
||||
}, { 0, 4 }, 1 },
|
||||
{ { NULL, "\x0d\x0a\x0d\x0a",
|
||||
"{ 0xd9, 0x87, 0xd2, 0x88, 0xd2, (16967){ 0x89, 0xd2 }, (87){ 0xe2, 0x82, 0xac }, 0x0d, 0x0a },"
|
||||
}, { 0, 4 }, 1 },
|
||||
{ { NULL, "\x0d\x0a\x0d\x0a",
|
||||
"0x47, 0x45, 0x54, 0x20, 0x2f, 0x65, 0x63, 0x68, 0x6f, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, "
|
||||
"0x2e, 0x31, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, "
|
||||
"0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x3a, 0x20, 0x77, 0x65, "
|
||||
"0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, "
|
||||
"0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x0d, 0x0a, 0x53, 0x65, "
|
||||
"0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2d, 0x4b, 0x65, 0x79, 0x3a, "
|
||||
"0x20, 0x64, 0x47, 0x68, 0x6c, 0x49, 0x48, 0x4e, 0x68, 0x62, 0x58, 0x42, 0x73, 0x5a, 0x53, 0x42, "
|
||||
"0x75, 0x62, 0x32, 0x35, 0x6a, 0x5a, 0x51, 0x3d, 0x3d, 0x0d, 0x0a, 0x4f, 0x72, 0x69, 0x67, 0x69, "
|
||||
"0x6e, 0x3a, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, "
|
||||
"0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x53, 0x65, 0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, "
|
||||
"0x65, 0x74, 0x2d, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x31, 0x33, 0x0d, 0x0a, "
|
||||
"0xef, 0xbb, 0xbf, 0xc2, 0x47, 0x45, 0x54, 0x20, 0x2f, 0x65, 0x63, 0x68, 0x6f, 0x20, 0x48, 0x54, "
|
||||
"0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x31, 0x32, "
|
||||
"0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, "
|
||||
"0x3a, 0x20, 0x77, 0x65, 0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, "
|
||||
"0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x0d, 0x0a, "
|
||||
}, { 0, 4 }, 1 },
|
||||
{ { NULL, "\x0d\x0a\x0d\x0a",
|
||||
"(20){0x47, 0x45, 0x54, 0x20, 0x2f, 0x65, 0x63, 0x68, 0x6f, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, "
|
||||
"0x2e, 0x31, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, "
|
||||
"0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x3a, 0x20, 0x77, 0x65, "
|
||||
"0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, "
|
||||
"0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x0d, 0x0a, 0x53, 0x65, "
|
||||
"0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2d, 0x4b, 0x65, 0x79, 0x3a, "
|
||||
"0x20, 0x64, 0x47, 0x68, 0x6c, 0x49, 0x48, 0x4e, 0x68, 0x62, 0x58, 0x42, 0x73, 0x5a, 0x53, 0x42, "
|
||||
"0x75, 0x62, 0x32, 0x35, 0x6a, 0x5a, 0x51, 0x3d, 0x3d, 0x0d, 0x0a, 0x4f, 0x72, 0x69, 0x67, 0x69, "
|
||||
"0x6e, 0x3a, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, "
|
||||
"0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x53, 0x65, 0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, "
|
||||
"0x65, 0x74, 0x2d, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x31, 0x33, 0x0d, 0x0a, "
|
||||
"0x47, 0x45, 0x54, 0x20, 0x2f, 0x65, 0x63, 0x68, 0x6f, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, "
|
||||
"0x2e, 0x31, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, "
|
||||
"0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x3a, 0x20, 0x77, 0x65, "
|
||||
"0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, "
|
||||
"0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x0d, 0x0a, 0x53, 0x65, "
|
||||
"0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2d, 0x4b, 0x65, 0x79, 0x3a, "
|
||||
"0x20, 0x64, 0x47, 0x68, 0x6c, 0x49, 0x48, 0x4e, 0x68, 0x62, 0x58, 0x42, 0x73, 0x5a, 0x53, 0x42, "
|
||||
"0x75, 0x62, 0x32, 0x35, 0x6a, 0x5a, 0x51, 0x3d, 0x3d, 0x0d, 0x0a, 0x4f, 0x72, 0x69, 0x67, 0x69, "
|
||||
"0x6e, 0x3a, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, "
|
||||
"0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x53, 0x65, 0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, "
|
||||
"0x65, 0x74, 0x2d, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x31, 0x33, 0x0d, 0x0a, "
|
||||
"0xc2, 0x47, 0x45, 0x54, 0x20, 0x2f, 0x65, 0x63, 0x68, 0x6f, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, "
|
||||
"0x31, 0x2e, 0x31, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x31, 0x32, 0x37, 0x2e, 0x30, "
|
||||
"0x2e, 0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x3a, 0x20, 0x77, "
|
||||
"0x65, 0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, "
|
||||
"0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x0d, 0x0a, 0x53, "
|
||||
"0x65, 0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2d, 0x4b, 0x65, 0x79, "
|
||||
"0x3a, 0x20, 0x64, 0x47, 0x68, 0x6c, 0x49, 0x48, 0x4e, 0x68, 0x62, 0x58, 0x42, 0x73, 0x5a, 0x53, "
|
||||
"0x42, 0x75, 0x62, 0x32, 0x35, 0x6a, 0x5a, 0x51, 0x3d, 0x3d, 0x0d, 0x0a, 0x4f, 0x72, 0x69, 0x67, "
|
||||
"0x69, 0x6e, 0x3a, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x32, 0x37, 0x2e, 0x30, "
|
||||
"0x2e, 0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x53, 0x65, 0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, "
|
||||
"0x6b, 0x65, 0x74, 0x2d, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x31, 0x33, 0x0d, "
|
||||
"0x0a, 0x47, 0x45, 0x54, 0x20, 0x2f, 0x65, 0x63, 0x68, 0x6f, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, "
|
||||
"0x31, 0x2e, 0x31, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x31, 0x32, 0x37, 0x2e, 0x30, "
|
||||
"0x2e, 0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x3a, 0x20, 0x77, "
|
||||
"0x65, 0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, "
|
||||
"0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x0d, 0x0a, 0x53, "
|
||||
"0x65, 0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2d, 0x4b, 0x65, 0x79, "
|
||||
"0x3a, 0x20, 0x64, 0x47, 0x68, 0x6c, 0x49, 0x48, 0x4e, 0x68, 0x62, 0x58, 0x42, 0x73, 0x5a, 0x53, "
|
||||
"0x42, 0x75, 0x62, 0x32, 0x35, 0x6a, 0x5a, 0x51, 0x3d, 0x3d, 0x0d, 0x0a, 0x4f, 0x72, 0x69, 0x67, "
|
||||
"0x69, 0x6e, 0x3a, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x32, 0x37, 0x2e, 0x30, "
|
||||
"0x2e, 0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x53, 0x65, 0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, "
|
||||
"0x6b, 0x65, 0x74, 0x2d, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x31, 0x33, 0x0d, "
|
||||
"0x0a, 0x47, 0x45, 0x54, 0x20, 0x2f, 0x65, 0x63, 0x68, 0x6f, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, "
|
||||
"0x31, 0x2e, 0x31, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x31, 0x32, 0x37, 0x2e, 0x30, "
|
||||
"0x2e, 0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x3a, 0x20, 0x77, "
|
||||
"0x65, 0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, "
|
||||
"0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x0d, 0x0a, 0x53, "
|
||||
"0x65, 0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2d, 0x4b, 0x65, 0x79, "
|
||||
"0x3a, 0x20, 0x64, 0x47, 0x68, 0x6c, 0x49, 0x48, 0x4e, 0x68, 0x62, 0x58, 0x42, 0x73, 0x5a, 0x53, "
|
||||
"0x42, 0x75, 0x62, 0x32, 0x35, 0x6a, 0x5a, 0x51, 0x3d, 0x3d, 0x0d, 0x0a, 0x4f, 0x72, 0x69, 0x67, "
|
||||
"0x69, 0x6e, 0x3a, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x32, 0x37, 0x2e, 0x30, "
|
||||
"0x2e, 0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x53, 0x65, 0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, "
|
||||
"0x6b, 0x65, 0x74, 0x2d, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x31, 0x33, 0x0d, "
|
||||
"0x0a, 0xc0, 0x80, 0xef, 0xb7, 0x90, 0x47, 0x45, 0x54, 0x20, 0x2f, 0x65, 0x63, 0x68, 0x6f, 0x20, "
|
||||
"0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, "
|
||||
"0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x55, 0x70, 0x67, 0x72, 0x61, "
|
||||
"0x64, 0x65, 0x3a, 0x20, 0x77, 0x65, 0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x0d, 0x0a, 0x43, "
|
||||
"0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x55, 0x70, 0x67, 0x72, 0x61, "
|
||||
"0x64, 0x65, 0x0d, 0x0a, 0x53, 0x65, 0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, "
|
||||
"0x74, 0x2d, 0x4b, 0x65, 0x79, 0x3a, 0x20, 0x64, 0x47, 0x68, 0x6c, 0x49, 0x48, 0x4e, 0x68, 0x62, "
|
||||
"0x58, 0x42, 0x73, 0x5a, 0x53, 0x42, 0x75, 0x62, 0x32, 0x35, 0x6a, 0x5a, 0x51, 0x3d, 0x3d, 0x0d, "
|
||||
"0x0a, 0x4f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x3a, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, "
|
||||
"0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x53, 0x65, 0x63, 0x2d, 0x57, "
|
||||
"0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2d, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, "
|
||||
"0x3a, 0x20, 0x31, 0x33, 0x0d, 0x0a, 0x47, 0x45, 0x54, 0x20, 0x2f, 0x65, 0x63, 0x68, 0x6f, 0x20, "
|
||||
"0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, "
|
||||
"0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x55, 0x70, 0x67, 0x72, 0x61, "
|
||||
"0x64, 0x65, 0x3a, 0x20, 0x77, 0x65, 0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x0d, 0x0a, 0x43, "
|
||||
"0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x55, 0x70, 0x67, 0x72, 0x61, "
|
||||
"0x64, 0x65, 0x0d, 0x0a, 0x53, 0x65, 0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, "
|
||||
"0x74, 0x2d, 0x4b, 0x65, 0x79, 0x3a, 0x20, 0x64, 0x47, 0x68, 0x6c, 0x49, 0x48, 0x4e, 0x68, 0x62, "
|
||||
"0x58, 0x42, 0x73, 0x5a, 0x53, 0x42, 0x75, 0x62, 0x32, 0x35, 0x6a, 0x5a, 0x51, 0x3d, 0x3d, 0x0d, "
|
||||
"0x0a, 0x4f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x3a, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, "
|
||||
"0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x53, 0x65, 0x63, 0x2d, 0x57, "
|
||||
"0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2d, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, "
|
||||
"0x3a, 0x20, 0x31, 0x33, 0x0d, 0x0a, 0xc2, 0x47, 0x45, 0x54, 0x20, 0x2f, 0x65, 0x63, 0x68, 0x6f, "
|
||||
"0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, "
|
||||
"0x20, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x55, 0x70, 0x67, 0x72, "
|
||||
"0x61, 0x64, 0x0d, 0x0a, }"
|
||||
}, { 0, 4 }, 1 },
|
||||
{ { NULL, "\x0d\x0a\x0d\x0a",
|
||||
"0x47, 0x45, 0x54, 0x20, 0x2f, 0x65, 0x63, 0x68, 0x6f, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, "
|
||||
"0x2e, 0x31, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, "
|
||||
"0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x3a, 0x20, 0x77, 0x65, "
|
||||
"0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, "
|
||||
"0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x0d, 0x0a, 0x53, 0x65, "
|
||||
"0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2d, 0x4b, 0x65, 0x79, 0x3a, "
|
||||
"0x20, 0x64, 0x47, 0x68, 0x6c, 0x49, 0x48, 0x4e, 0x68, 0x62, 0x58, 0x42, 0x73, 0x5a, 0x53, 0x42, "
|
||||
"0x75, 0x62, 0x32, 0x35, 0x6a, 0x5a, 0x51, 0x3d, 0x3d, 0x0d, 0x0a, 0x4f, 0x72, 0x69, 0x67, 0x69, "
|
||||
"0x6e, 0x3a, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, "
|
||||
"0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x53, 0x65, 0x63, 0x2d, 0x57, 0x65, 0x62, 0x53, 0x6f, 0x63, 0x6b, "
|
||||
"0x65, 0x74, 0x2d, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x31, 0x33, 0x0d, 0x0a, "
|
||||
"0xef, 0xbb, 0xbf, 0xc2, 0x47, 0x45, 0x54, 0x20, 0x2f, 0x65, 0x63, 0x68, 0x6f, 0x20, 0x48, 0x54, "
|
||||
"0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x31, 0x32, "
|
||||
"0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0d, 0x0a, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, "
|
||||
"0x3a, 0x20, 0x77, 0x65, 0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, "
|
||||
"0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x0d, 0x0a, (2048){ 0x0d, 0x0a}"
|
||||
}, { 0, 4 }, 1 },
|
||||
};
|
||||
|
||||
static int ring_size(struct ring *r)
|
||||
{
|
||||
return sizeof(r->buf);
|
||||
}
|
||||
static int ring_used(struct ring *r)
|
||||
{
|
||||
return (r->head - r->tail) & (ring_size(r) - 1);
|
||||
}
|
||||
static int ring_free(struct ring *r)
|
||||
{
|
||||
return (ring_size(r) - 1) - ring_used(r);
|
||||
}
|
||||
static int ring_get_one(struct ring *r)
|
||||
{
|
||||
int n = r->buf[r->tail] & 255;
|
||||
|
||||
if (r->tail == r->head)
|
||||
return -1;
|
||||
|
||||
r->tail++;
|
||||
if (r->tail == ring_size(r))
|
||||
r->tail = 0;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static int hex(char c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return c -'0';
|
||||
if (c >= 'a' && c <= 'f')
|
||||
return c - 'a' + 10;
|
||||
if (c >='A' && c <= 'F')
|
||||
return c - 'A' + 10;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
fuzxy_tok(const char **src, unsigned char **buf, int *len)
|
||||
{
|
||||
unsigned char *start;
|
||||
unsigned int count, rlen;
|
||||
|
||||
while (**src) {
|
||||
|
||||
if (**src == ' ' || **src == ',' || **src == '\n') {
|
||||
(*src)++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*src)[0] == '}') {
|
||||
(*src)++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((*src)[0] == '0' && (*src)[1] == 'x') {
|
||||
if (!len) {
|
||||
lwsl_err("out of space\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
((*buf)++)[0] = (hex((*src)[2]) << 4) | hex((*src)[3]);
|
||||
*src += 4;
|
||||
(*len)--;
|
||||
}
|
||||
|
||||
if (*src[0] == '(') {
|
||||
start = *buf;
|
||||
(*src)++;
|
||||
count = atoi(*src) - 1;
|
||||
lwsl_err("count %d\n", count);
|
||||
while (**src && **src != ')')
|
||||
(*src)++;
|
||||
if (!(*src)[0]) {
|
||||
lwsl_err("unexpected end in (\n");
|
||||
return -1;
|
||||
}
|
||||
(*src)++;
|
||||
while (**src == ' ')
|
||||
(*src)++;
|
||||
if (**src != '{') {
|
||||
lwsl_err("missing {\n");
|
||||
|
||||
return -1;
|
||||
}
|
||||
(*src)++;
|
||||
if (fuzxy_tok(src, buf, len))
|
||||
return -1;
|
||||
rlen = *buf - start;
|
||||
while (count--) {
|
||||
if (*len < (int)rlen) {
|
||||
lwsl_err("out of space\n");
|
||||
return -1;
|
||||
}
|
||||
memcpy(*buf, start, rlen);
|
||||
*buf += rlen;
|
||||
*len -= rlen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
fuzxy_create_pattern(const char *src, unsigned char *buf, int len)
|
||||
{
|
||||
unsigned char *old = buf;
|
||||
int n;
|
||||
|
||||
while (*src && (*src == '{' || *src == ' '))
|
||||
src++;
|
||||
|
||||
if (!*src)
|
||||
return -1;
|
||||
|
||||
n = fuzxy_tok(&src, &buf, &len);
|
||||
if (n)
|
||||
return -1;
|
||||
|
||||
return buf - old;
|
||||
}
|
||||
|
||||
void sighandler(int sig)
|
||||
{
|
||||
force_exit = 1;
|
||||
}
|
||||
|
||||
static struct option options[] = {
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "debug", required_argument, NULL, 'd' },
|
||||
{ "port", required_argument, NULL, 'p' },
|
||||
{ "ssl", no_argument, NULL, 's' },
|
||||
{ "allow-non-ssl", no_argument, NULL, 'a' },
|
||||
{ "interface", required_argument, NULL, 'i' },
|
||||
{ "closetest", no_argument, NULL, 'c' },
|
||||
{ "libev", no_argument, NULL, 'e' },
|
||||
#ifndef LWS_NO_DAEMONIZE
|
||||
{ "daemonize", no_argument, NULL, 'D' },
|
||||
#endif
|
||||
{ "resource_path", required_argument, NULL, 'r' },
|
||||
{ NULL, 0, 0, 0 }
|
||||
};
|
||||
|
||||
static struct pollfd pfd[128];
|
||||
static struct state state[128];
|
||||
static int pfds = 0;
|
||||
|
||||
static void close_and_remove_fd(int index)
|
||||
{
|
||||
int n;
|
||||
|
||||
lwsl_notice("%s: closing index %d\n", __func__, index);
|
||||
close(pfd[index].fd);
|
||||
pfd[index].fd = -1;
|
||||
|
||||
n = state[index].twin;
|
||||
if (n) {
|
||||
assert(state[n].twin == index);
|
||||
}
|
||||
state[index].type = FZY_S_DEAD;
|
||||
|
||||
if (index == pfds - 1) {
|
||||
if (state[index].twin)
|
||||
state[state[index].twin].twin = 0;
|
||||
state[index].twin = 0;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
/* swap the end guy into the deleted guy and trim back one */
|
||||
|
||||
if (state[pfds - 1].twin) {
|
||||
state[state[pfds - 1].twin].twin = index;
|
||||
if (n && n == pfds - 1)
|
||||
n = index;
|
||||
}
|
||||
|
||||
/* swap the last guy into dead guy's place and trim by one */
|
||||
pfd[index] = pfd[pfds - 1];
|
||||
state[index] = state[pfds - 1];
|
||||
|
||||
if (n) {
|
||||
pfds--;
|
||||
state[n].twin = 0;
|
||||
close_and_remove_fd(n);
|
||||
return;
|
||||
}
|
||||
|
||||
bail:
|
||||
pfds--;
|
||||
}
|
||||
|
||||
static void construct_state(int n, enum types s, int flags)
|
||||
{
|
||||
memset(&state[n], 0, sizeof state[n]);
|
||||
state[n].type = s;
|
||||
pfd[n].events = flags | POLLHUP;
|
||||
}
|
||||
|
||||
static int
|
||||
fuzxy_listen(const char *interface_name, int port, int *sockfd)
|
||||
{
|
||||
struct sockaddr_in serv_addr4;
|
||||
socklen_t len = sizeof(struct sockaddr);
|
||||
struct sockaddr_in sin;
|
||||
int n, opt = 1;
|
||||
|
||||
*sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if (*sockfd == -1) {
|
||||
lwsl_err("ERROR opening socket\n");
|
||||
goto bail1;
|
||||
}
|
||||
|
||||
if (setsockopt(*sockfd, SOL_SOCKET, SO_REUSEADDR,
|
||||
(const void *)&opt, sizeof(opt)) < 0) {
|
||||
lwsl_err("unable to set listen socket options\n");
|
||||
goto bail2;
|
||||
}
|
||||
|
||||
bzero((char *) &serv_addr4, sizeof(serv_addr4));
|
||||
serv_addr4.sin_addr.s_addr = INADDR_ANY;
|
||||
serv_addr4.sin_family = AF_INET;
|
||||
|
||||
if (interface_name[0] &&
|
||||
lws_interface_to_sa(0, interface_name, (struct sockaddr_in *)
|
||||
(struct sockaddr *)&serv_addr4,
|
||||
sizeof(serv_addr4)) < 0) {
|
||||
lwsl_err("Unable to find interface %s\n", interface_name);
|
||||
goto bail2;
|
||||
}
|
||||
|
||||
serv_addr4.sin_port = htons(port);
|
||||
|
||||
n = bind(*sockfd, (struct sockaddr *)&serv_addr4,
|
||||
sizeof(serv_addr4));
|
||||
if (n < 0) {
|
||||
lwsl_err("ERROR on binding to port %d (%d %d)\n",
|
||||
port, n, errno);
|
||||
goto bail2;
|
||||
}
|
||||
|
||||
if (getsockname(*sockfd, (struct sockaddr *)&sin, &len) == -1)
|
||||
lwsl_warn("getsockname: %s\n", strerror(errno));
|
||||
else
|
||||
port = ntohs(sin.sin_port);
|
||||
|
||||
listen(*sockfd, SOMAXCONN);
|
||||
|
||||
return 0;
|
||||
bail2:
|
||||
close(*sockfd);
|
||||
bail1:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static int fuzz(int n, char *out, int len)
|
||||
{
|
||||
struct state *s = &state[n];
|
||||
const struct test *t = &tests[which];
|
||||
int m = 0;
|
||||
int c;
|
||||
|
||||
while (m < len) {
|
||||
switch (s->fp) {
|
||||
case FZY_FP_SEARCH:
|
||||
if (t->s[0] == NULL) {
|
||||
s->fuzc = 0;
|
||||
s->is_pending = 0;
|
||||
s->fp = FZY_FP_SEARCH2;
|
||||
goto search2;
|
||||
}
|
||||
c = ring_get_one(&state[s->twin].in);
|
||||
if (c < 0)
|
||||
return m;
|
||||
if (c == tests[which].s[0][s->fuzc++]) {
|
||||
if (s->fuzc == t->len[0]) {
|
||||
s->fuzc = 0;
|
||||
s->fp = FZY_FP_SEARCH2;
|
||||
}
|
||||
} else
|
||||
s->fuzc = 0;
|
||||
out[m++] = c;
|
||||
break;
|
||||
|
||||
case FZY_FP_SEARCH2:
|
||||
search2:
|
||||
if (tests[which].s[1] == NULL) {
|
||||
s->fuzc = 0;
|
||||
s->is_pending = 0;
|
||||
s->fp = FZY_FP_INJECT_PREPARE;
|
||||
goto inject;
|
||||
}
|
||||
c = ring_get_one(&state[s->twin].in);
|
||||
if (c < 0)
|
||||
return m;
|
||||
if (c == tests[which].s[1][s->fuzc++]) {
|
||||
if (s->fuzc == tests[which].len[1]) {
|
||||
lwsl_notice("+++++++fuzzer hit...\n");
|
||||
s->fuzc = 0;
|
||||
s->fp = FZY_FP_INJECT_PREPARE;
|
||||
s->is_pending = !t->swallow;
|
||||
s->pending = c;
|
||||
goto inject;
|
||||
}
|
||||
} else
|
||||
s->fuzc = 0;
|
||||
if (!t->swallow)
|
||||
out[m++] = c;
|
||||
break;
|
||||
|
||||
case FZY_FP_INJECT_PREPARE:
|
||||
inject:
|
||||
s->inject_len = fuzxy_create_pattern(t->s[2],
|
||||
s->buf, sizeof(s->buf));
|
||||
if (s->inject_len == (unsigned int) -1)
|
||||
return -1;
|
||||
s->fp = FZY_FP_INJECT;
|
||||
/* fallthru */
|
||||
|
||||
case FZY_FP_INJECT:
|
||||
out[m++] = s->buf[s->fuzc++];
|
||||
if (s->fuzc == (int)s->inject_len)
|
||||
s->fp = FZY_FP_PENDING;
|
||||
break;
|
||||
|
||||
case FZY_FP_PENDING:
|
||||
if (s->is_pending)
|
||||
out[m++] = s->pending;
|
||||
s->fp = FZY_FP_SEARCH;
|
||||
s->fuzc = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
static int
|
||||
handle_accept(int n)
|
||||
{
|
||||
struct addrinfo ai, *res, *result;
|
||||
struct sockaddr_in serv_addr4;
|
||||
struct state *s = &state[n];
|
||||
void *p = NULL;
|
||||
int m, sockfd;
|
||||
|
||||
while (1) {
|
||||
m = ring_get_one(&s->in);
|
||||
if (m < 0)
|
||||
return 0;
|
||||
|
||||
switch (s->pp) {
|
||||
case FZY_PP_CONNECT:
|
||||
if (m != "CONNECT "[s->ppc++]) {
|
||||
lwsl_notice("failed CONNECT match\n");
|
||||
return 1;
|
||||
}
|
||||
if (s->ppc == 8) {
|
||||
s->pp = FZY_PP_ADDRESS;
|
||||
s->ppc = 0;
|
||||
}
|
||||
break;
|
||||
case FZY_PP_ADDRESS:
|
||||
if (m == ':') {
|
||||
s->address[s->ppc++] = '\0';
|
||||
s->pp = FZY_PP_PORT;
|
||||
s->ppc = 0;
|
||||
break;
|
||||
}
|
||||
if (m == ' ') {
|
||||
s->address[s->ppc++] = '\0';
|
||||
s->pp = FZY_PP_CRLFS;
|
||||
s->ppc = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
s->address[s->ppc++] = m;
|
||||
if (s->ppc == sizeof(s->address)) {
|
||||
lwsl_notice("Failed on address length\n");
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case FZY_PP_PORT:
|
||||
if (m == ' ') {
|
||||
s->pp = FZY_PP_CRLFS;
|
||||
s->ppc = 0;
|
||||
break;
|
||||
}
|
||||
if (m >= '0' && m <= '9') {
|
||||
s->port *= 10;
|
||||
s->port += m - '0';
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
|
||||
case FZY_PP_CRLFS:
|
||||
if (m != "\x0d\x0a\x0d\x0a"[s->ppc++])
|
||||
s->ppc = 0;
|
||||
if (s->ppc != 4)
|
||||
break;
|
||||
s->type = FZY_S_PROXIED;
|
||||
|
||||
memset (&ai, 0, sizeof ai);
|
||||
ai.ai_family = PF_UNSPEC;
|
||||
ai.ai_socktype = SOCK_STREAM;
|
||||
|
||||
if (getaddrinfo(s->address, NULL, &ai, &result)) {
|
||||
lwsl_notice("failed to lookup %s\n",
|
||||
s->address);
|
||||
return 1;
|
||||
}
|
||||
|
||||
res = result;
|
||||
while (!p && res) {
|
||||
switch (res->ai_family) {
|
||||
case AF_INET:
|
||||
p = &((struct sockaddr_in *)res->
|
||||
ai_addr)->sin_addr;
|
||||
break;
|
||||
}
|
||||
|
||||
res = res->ai_next;
|
||||
}
|
||||
|
||||
if (!p) {
|
||||
lwsl_notice("Failed to get address result %s\n",
|
||||
s->address);
|
||||
freeaddrinfo(result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
serv_addr4.sin_family = AF_INET;
|
||||
serv_addr4.sin_addr = *((struct in_addr *)p);
|
||||
serv_addr4.sin_port = htons(s->port);
|
||||
bzero(&serv_addr4.sin_zero, 8);
|
||||
freeaddrinfo(result);
|
||||
|
||||
lwsl_err("Conn %d req '%s' port %d\n", n,
|
||||
s->address, s->port);
|
||||
/* we need to open the associated onward connection */
|
||||
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sockfd < 0) {
|
||||
lwsl_err("Could not get socket\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (connect(sockfd, (struct sockaddr *)&serv_addr4,
|
||||
sizeof(struct sockaddr)) == -1 ||
|
||||
errno == EISCONN) {
|
||||
close(sockfd);
|
||||
lwsl_err("proxied onward connection failed\n");
|
||||
return 1;
|
||||
}
|
||||
s->twin = pfds;
|
||||
construct_state(pfds, FZY_S_ONWARD,
|
||||
POLLOUT | POLLIN | POLLERR);
|
||||
state[pfds].twin = n;
|
||||
lwsl_notice("binding conns %d and %d\n", n, pfds);
|
||||
state[pfds].outbound = s->outbound;
|
||||
state[pfds].ppc = 0;
|
||||
pfd[pfds++].fd = sockfd;
|
||||
|
||||
lwsl_notice("onward connection in progress\n");
|
||||
if (ring_used(&s->in))
|
||||
pfd[s->twin].events |= POLLOUT;
|
||||
if (write(pfd[n].fd,
|
||||
"HTTP/1.0 200 \x0d\x0a\x0d\x0a", 17) < 17)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void sigpipe_handler(int x)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char interface_name[128] = "", interface_name_local[128] = "lo";
|
||||
int port_local = 8880, accept_fd;
|
||||
struct sockaddr_in cli_addr;
|
||||
int debug_level = 7;
|
||||
socklen_t clilen;
|
||||
struct state *s;
|
||||
char out[4096];
|
||||
int opts = 0;
|
||||
int n = 0, m;
|
||||
|
||||
#ifndef _WIN32
|
||||
/* LOG_PERROR is not POSIX standard, and may not be portable */
|
||||
#ifdef __sun
|
||||
int syslog_options = LOG_PID;
|
||||
#else
|
||||
int syslog_options = LOG_PID | LOG_PERROR;
|
||||
#endif
|
||||
#endif
|
||||
#ifndef LWS_NO_DAEMONIZE
|
||||
int daemonize = 0;
|
||||
#endif
|
||||
signal(SIGPIPE, sigpipe_handler);
|
||||
|
||||
while (n >= 0) {
|
||||
n = getopt_long(argc, argv, "eci:hsap:d:Dr:", options, NULL);
|
||||
if (n < 0)
|
||||
continue;
|
||||
switch (n) {
|
||||
case 'e':
|
||||
opts |= LWS_SERVER_OPTION_LIBEV;
|
||||
break;
|
||||
#ifndef LWS_NO_DAEMONIZE
|
||||
case 'D':
|
||||
daemonize = 1;
|
||||
#if !defined(_WIN32) && !defined(__sun)
|
||||
syslog_options &= ~LOG_PERROR;
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
case 'd':
|
||||
debug_level = atoi(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
port_local = atoi(optarg);
|
||||
break;
|
||||
case 'i':
|
||||
lws_strncpy(interface_name, optarg, sizeof interface_name);
|
||||
break;
|
||||
case 'h':
|
||||
fprintf(stderr, "Usage: libwebsockets-test-fuzxy "
|
||||
"[--port=<p>] [--ssl] "
|
||||
"[-d <log bitfield>] "
|
||||
"[--resource_path <path>]\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(LWS_NO_DAEMONIZE) && !defined(WIN32)
|
||||
/*
|
||||
* normally lock path would be /var/lock/lwsts or similar, to
|
||||
* simplify getting started without having to take care about
|
||||
* permissions or running as root, set to /tmp/.lwsts-lock
|
||||
*/
|
||||
if (daemonize && lws_daemonize("/tmp/.lwsts-lock")) {
|
||||
fprintf(stderr, "Failed to daemonize\n");
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
signal(SIGINT, sighandler);
|
||||
|
||||
#ifndef _WIN32
|
||||
/* we will only try to log things according to our debug_level */
|
||||
setlogmask(LOG_UPTO (LOG_DEBUG));
|
||||
openlog("fuzxy", syslog_options, LOG_DAEMON);
|
||||
#endif
|
||||
|
||||
/* tell the library what debug level to emit and to send it to syslog */
|
||||
lws_set_log_level(debug_level, lwsl_emit_syslog);
|
||||
|
||||
lwsl_notice("libwebsockets fuzzing proxy - license LGPL2.1+SLE\n");
|
||||
lwsl_notice("(C) Copyright 2016 Andy Green <andy@warmcat.com>\n");
|
||||
|
||||
/* listen on local side */
|
||||
|
||||
if (fuzxy_listen(interface_name, port_local, &pfd[pfds].fd)) {
|
||||
lwsl_err("Failed to listen on local side\n");
|
||||
goto bail1;
|
||||
}
|
||||
construct_state(pfds, FZY_S_LISTENING, POLLIN | POLLERR);
|
||||
pfds++;
|
||||
|
||||
(void)interface_name_local;
|
||||
lwsl_notice("Local side listening on %s:%u\n",
|
||||
interface_name_local, port_local);
|
||||
|
||||
while (!force_exit) {
|
||||
|
||||
m = poll(pfd, pfds, 50);
|
||||
if (m < 0)
|
||||
continue;
|
||||
for (n = 0; n < pfds; n++) {
|
||||
s = &state[n];
|
||||
if (s->type == FZY_S_LISTENING &&
|
||||
(pfd[n].revents & POLLIN)) {
|
||||
/* first do the accept entry */
|
||||
|
||||
clilen = sizeof(cli_addr);
|
||||
accept_fd = accept(pfd[0].fd,
|
||||
(struct sockaddr *)&cli_addr, &clilen);
|
||||
if (accept_fd < 0) {
|
||||
if (errno == EAGAIN ||
|
||||
errno == EWOULDBLOCK)
|
||||
continue;
|
||||
|
||||
lwsl_warn("ERROR on accept: %s\n",
|
||||
strerror(errno));
|
||||
continue;
|
||||
}
|
||||
construct_state(pfds, FZY_S_ACCEPTED,
|
||||
POLLIN | POLLERR);
|
||||
state[pfds].outbound = n == 0;
|
||||
state[pfds].pp = FZY_PP_CONNECT;
|
||||
state[pfds].ppc = 0;
|
||||
pfd[pfds++].fd = accept_fd;
|
||||
lwsl_notice("new connect accepted\n");
|
||||
continue;
|
||||
}
|
||||
if (pfd[n].revents & POLLIN) {
|
||||
assert(ring_free(&s->in));
|
||||
m = (ring_size(&s->in) - 1) -
|
||||
s->in.head;
|
||||
if (s->in.head == ring_size(&s->in) - 1 &&
|
||||
s->in.tail)
|
||||
m = 1;
|
||||
m = read(pfd[n].fd, s->in.buf + s->in.head, m);
|
||||
// lwsl_notice("read %d\n", m);
|
||||
if (m <= 0) {
|
||||
lwsl_err("Error on read\n");
|
||||
goto drop;
|
||||
}
|
||||
s->in.head += m;
|
||||
if (s->in.head == ring_size(&s->in))
|
||||
s->in.head = 0;
|
||||
|
||||
switch (s->type) {
|
||||
case FZY_S_ACCEPTED: /* parse proxy CONNECT */
|
||||
if (handle_accept(n))
|
||||
goto drop;
|
||||
break;
|
||||
case FZY_S_PROXIED:
|
||||
case FZY_S_ONWARD:
|
||||
if (ring_used(&s->in))
|
||||
pfd[s->twin].events |= POLLOUT;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
if (s->in.head == s->in.tail) {
|
||||
s->in.head = s->in.tail = 0;
|
||||
pfd[n].events |= POLLIN;
|
||||
}
|
||||
if (!ring_free(&s->in))
|
||||
pfd[n].events &= ~POLLIN;
|
||||
}
|
||||
if (pfd[n].revents & POLLOUT) {
|
||||
switch (s->type) {
|
||||
case FZY_S_PROXIED:
|
||||
case FZY_S_ONWARD:
|
||||
/*
|
||||
* draw down enough of the partner's
|
||||
* in ring to either exhaust it
|
||||
* or fill an output buffer
|
||||
*/
|
||||
m = fuzz(n, out, sizeof(out));
|
||||
if (m < 0) {
|
||||
lwsl_err("Error on fuzz\n");
|
||||
goto drop;
|
||||
}
|
||||
lwsl_notice("got block %d\n", m);
|
||||
if (m) {
|
||||
m = write(pfd[n].fd, out, m);
|
||||
if (m <= 0) {
|
||||
lwsl_err("Error on write\n");
|
||||
goto drop;
|
||||
} else
|
||||
pfd[s->twin].events &= ~POLLIN;
|
||||
} else {
|
||||
pfd[n].events &= ~POLLOUT;
|
||||
|
||||
if (ring_free(&state[s->twin].in))
|
||||
pfd[s->twin].events |= POLLIN;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
drop:
|
||||
close_and_remove_fd(n);
|
||||
n--; /* redo this slot */
|
||||
}
|
||||
}
|
||||
|
||||
bail1:
|
||||
lwsl_notice("%s exited cleanly\n", argv[0]);
|
||||
|
||||
#ifndef _WIN32
|
||||
closelog();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -13,26 +13,73 @@
|
|||
*
|
||||
*/
|
||||
|
||||
function lws_gray_out(vis, options) {
|
||||
function gsize(ptype)
|
||||
{
|
||||
var h = document.compatMode === "CSS1Compat" &&
|
||||
!window.opera ?
|
||||
document.documentElement.clientHeight :
|
||||
document.body.clientHeight;
|
||||
var w = document.compatMode === "CSS1Compat" &&
|
||||
!window.opera ?
|
||||
document.documentElement.clientWidth :
|
||||
document.body.clientWidth;
|
||||
var pageWidth, pageHeight, t;
|
||||
|
||||
var options = options || {};
|
||||
if (document.body &&
|
||||
(document.body.scrollWidth || document.body.scrollHeight)) {
|
||||
t = document.body.scrollWidth;
|
||||
pageWidth = (w > t) ? ("" + w + "px") : ("" + (t) + "px");
|
||||
t = document.body.scrollHeight;
|
||||
pageHeight = (h > t) ? ("" + h + "px") : ("" + (t) + "px");
|
||||
} else if (document.body.offsetWidth) {
|
||||
t = document.body.offsetWidth;
|
||||
pageWidth = (w > t) ? ("" + w + "px") : ("" + (t) + "px");
|
||||
t = document.body.offsetHeight;
|
||||
pageHeight =(h > t) ? ("" + h + "px") : ("" + (t) + "px");
|
||||
} else {
|
||||
pageWidth = "100%";
|
||||
pageHeight = "100%";
|
||||
}
|
||||
return (ptype === 1) ? pageWidth : pageHeight;
|
||||
}
|
||||
|
||||
function addEvent( obj, type, fn ) {
|
||||
if ( obj.attachEvent ) {
|
||||
obj["e" + type + fn] = fn;
|
||||
obj[type+fn] = function() { obj["e" + type + fn]( window.event );};
|
||||
obj.attachEvent("on" + type, obj[type + fn]);
|
||||
} else
|
||||
obj.addEventListener(type, fn, false);
|
||||
}
|
||||
|
||||
function removeEvent( obj, type, fn ) {
|
||||
if ( obj.detachEvent ) {
|
||||
obj.detachEvent("on" + type, obj[type + fn]);
|
||||
obj[type + fn] = null;
|
||||
} else
|
||||
obj.removeEventListener(type, fn, false);
|
||||
}
|
||||
|
||||
function lws_gray_out(vis, _options) {
|
||||
|
||||
var options = _options || {};
|
||||
var zindex = options.zindex || 50;
|
||||
var opacity = options.opacity || 70;
|
||||
var opaque = (opacity / 100);
|
||||
var bgcolor = options.bgcolor || '#000000';
|
||||
var dark = document.getElementById('darkenScreenObject');
|
||||
var bgcolor = options.bgcolor || "#000000";
|
||||
var dark = document.getElementById("darkenScreenObject");
|
||||
|
||||
if (!dark) {
|
||||
var tbody = document.getElementsByTagName("body")[0];
|
||||
var tnode = document.createElement('div');
|
||||
tnode.style.position = 'absolute';
|
||||
tnode.style.top = '0px';
|
||||
tnode.style.left = '0px';
|
||||
tnode.style.overflow = 'hidden';
|
||||
tnode.style.display ='none';
|
||||
tnode.id = 'darkenScreenObject';
|
||||
var tnode = document.createElement("div");
|
||||
tnode.style.position = "absolute";
|
||||
tnode.style.top = "0px";
|
||||
tnode.style.left = "0px";
|
||||
tnode.style.overflow = "hidden";
|
||||
tnode.style.display ="none";
|
||||
tnode.id = "darkenScreenObject";
|
||||
tbody.appendChild(tnode);
|
||||
dark = document.getElementById('darkenScreenObject');
|
||||
dark = document.getElementById("darkenScreenObject");
|
||||
}
|
||||
if (vis) {
|
||||
dark.style.opacity = opaque;
|
||||
|
@ -42,7 +89,7 @@ function lws_gray_out(vis, options) {
|
|||
dark.style.backgroundColor = bgcolor;
|
||||
dark.style.width = gsize(1);
|
||||
dark.style.height = gsize(0);
|
||||
dark.style.display ='block';
|
||||
dark.style.display = "block";
|
||||
addEvent(window, "resize",
|
||||
function() {
|
||||
dark.style.height = gsize(0);
|
||||
|
@ -50,7 +97,7 @@ function lws_gray_out(vis, options) {
|
|||
}
|
||||
);
|
||||
} else {
|
||||
dark.style.display = 'none';
|
||||
dark.style.display = "none";
|
||||
removeEvent(window, "resize",
|
||||
function() {
|
||||
dark.style.height = gsize(0);
|
||||
|
@ -60,72 +107,9 @@ function lws_gray_out(vis, options) {
|
|||
}
|
||||
}
|
||||
|
||||
function gsize(ptype)
|
||||
{
|
||||
var h = document.compatMode == 'CSS1Compat' &&
|
||||
!window.opera ?
|
||||
document.documentElement.clientHeight :
|
||||
document.body.clientHeight;
|
||||
var w = document.compatMode == 'CSS1Compat' &&
|
||||
!window.opera ?
|
||||
document.documentElement.clientWidth :
|
||||
document.body.clientWidth;
|
||||
if (document.body &&
|
||||
(document.body.scrollWidth || document.body.scrollHeight)) {
|
||||
var pageWidth = (w > (t = document.body.scrollWidth)) ?
|
||||
("" + w + "px") : ("" + (t) + "px");
|
||||
var pageHeight = (h > (t = document.body.scrollHeight)) ?
|
||||
("" + h + "px") : ("" + (t) + "px");
|
||||
} else if (document.body.offsetWidth) {
|
||||
var pageWidth = (w > (t = document.body.offsetWidth)) ?
|
||||
("" + w + "px") : ("" + (t) + "px");
|
||||
var pageHeight =(h > (t = document.body.offsetHeight)) ?
|
||||
("" + h + "px") : ("" + (t) + "px");
|
||||
} else {
|
||||
var pageWidth = '100%';
|
||||
var pageHeight = '100%';
|
||||
}
|
||||
return (ptype == 1) ? pageWidth : pageHeight;
|
||||
}
|
||||
|
||||
function addEvent( obj, type, fn ) {
|
||||
if ( obj.attachEvent ) {
|
||||
obj['e' + type + fn] = fn;
|
||||
obj[type+fn] = function() { obj['e' + type+fn]( window.event );}
|
||||
obj.attachEvent('on' + type, obj[type + fn]);
|
||||
} else
|
||||
obj.addEventListener(type, fn, false);
|
||||
}
|
||||
|
||||
function removeEvent( obj, type, fn ) {
|
||||
if ( obj.detachEvent ) {
|
||||
obj.detachEvent('on' + type, obj[type + fn]);
|
||||
obj[type + fn] = null;
|
||||
} else
|
||||
obj.removeEventListener(type, fn, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* end of grayOut related stuff
|
||||
*/
|
||||
|
||||
/*
|
||||
* lws-meta helpers
|
||||
*/
|
||||
|
||||
var lws_meta_cmd = {
|
||||
OPEN_SUBCHANNEL: 0x41,
|
||||
/**< Client requests to open new subchannel
|
||||
*/
|
||||
OPEN_RESULT: 0x42,
|
||||
/**< Result of client request to open new subchannel */
|
||||
CLOSE_NOT: 0x43,
|
||||
CLOSE_RQ: 0x44,
|
||||
/**< client requests to close a subchannel */
|
||||
WRITE: 0x45,
|
||||
/**< connection writes something to specific channel index */
|
||||
RX: 0x46,
|
||||
};
|
||||
|
||||
function new_ws(urlpath, protocol)
|
||||
{
|
||||
|
@ -134,264 +118,10 @@ function new_ws(urlpath, protocol)
|
|||
|
||||
return new WebSocket(urlpath, protocol);
|
||||
}
|
||||
|
||||
function lws_meta_ws() {
|
||||
var real;
|
||||
|
||||
var channel_id_to_child;
|
||||
var pending_children;
|
||||
var active_children;
|
||||
}
|
||||
|
||||
function lws_meta_ws_child() {
|
||||
var onopen;
|
||||
var onmessage;
|
||||
var onclose;
|
||||
|
||||
var channel_id;
|
||||
|
||||
var subprotocol;
|
||||
var suburl;
|
||||
var cookie;
|
||||
|
||||
var extensions;
|
||||
|
||||
var parent;
|
||||
}
|
||||
|
||||
lws_meta_ws_child.prototype.send = function(data)
|
||||
{
|
||||
|
||||
if (typeof data == "string") {
|
||||
data = String.fromCharCode(lws_meta_cmd.WRITE) +
|
||||
String.fromCharCode(this.channel_id) +
|
||||
data;
|
||||
|
||||
return this.parent.real.send(data);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
var ab = new Uint8Array(data.length + 2);
|
||||
|
||||
ab[0] = lws_meta_cmd.WRITE;
|
||||
ab[1] = this.channel_id;
|
||||
ab.set(data, 2);
|
||||
|
||||
return this.parent.real.send(ab);
|
||||
}
|
||||
}
|
||||
|
||||
lws_meta_ws_child.prototype.close = function(close_code, close_string)
|
||||
{
|
||||
var pkt = new Uint8Array(129), m = 0, pkt1;
|
||||
|
||||
pkt[m++] = lws_meta_cmd.CLOSE_RQ;
|
||||
pkt[m++] = this.channel_id;
|
||||
|
||||
pkt[m++] = close_string.length + 0x20;
|
||||
|
||||
pkt[m++] = close_code / 256;
|
||||
pkt[m++] = close_code % 256;
|
||||
|
||||
for (i = 0; i < close_string.length; i++)
|
||||
pkt[m++] = close_string.charCodeAt(i);
|
||||
|
||||
pkt1 = new Uint8Array(m);
|
||||
for (n = 0; n < m; n++)
|
||||
pkt1[n] = pkt[n];
|
||||
|
||||
this.parent.real.send(pkt1.buffer);
|
||||
}
|
||||
|
||||
/* make a real ws connection using lws_meta*/
|
||||
lws_meta_ws.prototype.new_parent = function(urlpath)
|
||||
{
|
||||
var n, i, m = 0, pkt1;
|
||||
|
||||
this.ordinal = 1;
|
||||
this.pending_children = [];
|
||||
this.active_children = [];
|
||||
this.real = new_ws(urlpath, "lws-meta");
|
||||
|
||||
this.real.binaryType = 'arraybuffer';
|
||||
this.real.myparent = this;
|
||||
|
||||
this.real.onopen = function() {
|
||||
pkt = new Uint8Array(1024);
|
||||
var n, i, m = 0, pkt1;
|
||||
console.log("real open - pending children " + this.myparent.pending_children.length);
|
||||
for (n = 0; n < this.myparent.pending_children.length; n++) {
|
||||
|
||||
var p = this.myparent.pending_children[n];
|
||||
|
||||
pkt[m++] = lws_meta_cmd.OPEN_SUBCHANNEL;
|
||||
for (i = 0; i < p.subprotocol.length; i++)
|
||||
pkt[m++] = p.subprotocol.charCodeAt(i);
|
||||
pkt[m++] = 0;
|
||||
for (i = 0; i < p.suburl.length; i++)
|
||||
pkt[m++] = p.suburl.charCodeAt(i);
|
||||
pkt[m++] = 0;
|
||||
for (i = 0; i < p.cookie.length; i++)
|
||||
pkt[m++] = p.cookie.charCodeAt(i);
|
||||
pkt[m++] = 0;
|
||||
}
|
||||
|
||||
pkt1 = new Uint8Array(m);
|
||||
for (n = 0; n < m; n++)
|
||||
pkt1[n] = pkt[n];
|
||||
|
||||
console.log(this.myparent.pending_children[0].subprotocol);
|
||||
console.log(pkt1);
|
||||
|
||||
this.send(pkt1.buffer);
|
||||
}
|
||||
|
||||
|
||||
this.real.onmessage = function(msg) {
|
||||
|
||||
if (typeof msg.data != "string") {
|
||||
var ba = new Uint8Array(msg.data), n = 0;
|
||||
|
||||
while (n < ba.length) {
|
||||
|
||||
switch (ba[n++]) {
|
||||
case lws_meta_cmd.OPEN_RESULT:
|
||||
{
|
||||
var m = 0, cookie = "", protocol = "", ch = 0;
|
||||
var ws = this.myparent;
|
||||
/* cookie NUL
|
||||
* channel index + 0x20
|
||||
* protocol NUL
|
||||
*/
|
||||
while (ba[n])
|
||||
cookie = cookie + String.fromCharCode(ba[n++]);
|
||||
n++;
|
||||
ch = ba[n++];
|
||||
|
||||
while (ba[n])
|
||||
protocol = protocol + String.fromCharCode(ba[n++]);
|
||||
|
||||
console.log("open result " + cookie + " " + protocol + " " + ch + " pending len " + ws.pending_children.length);
|
||||
|
||||
for (m = 0; m < ws.pending_children.length; m++) {
|
||||
if (ws.pending_children[m].cookie == cookie) {
|
||||
var newchild = ws.pending_children[m];
|
||||
|
||||
/* found it */
|
||||
ws.pending_children[m].channel_id = ch;
|
||||
/* add to active children array */
|
||||
ws.active_children.push(ws.pending_children[m]);
|
||||
/* remove from pending children array */
|
||||
ws.pending_children.splice(m, 1);
|
||||
|
||||
newchild.parent = ws;
|
||||
newchild.extensions = this.extensions;
|
||||
|
||||
newchild.onopen();
|
||||
|
||||
console.log("made active " + cookie);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case lws_meta_cmd.CLOSE_NOT:
|
||||
{
|
||||
var code = 0, str = "", ch = 0, m, le;
|
||||
var ba = new Uint8Array(msg.data);
|
||||
/*
|
||||
* BYTE: channel
|
||||
* BYTE: MSB status code
|
||||
* BYTE: LSB status code
|
||||
* BYTES: rest of message is close status string
|
||||
*/
|
||||
|
||||
ch = ba[n++];
|
||||
le = ba[n++] - 0x20;
|
||||
code = ba[n++] * 256;
|
||||
code += ba[n++];
|
||||
|
||||
while (le--)
|
||||
str += String.fromCharCode(ba[n++]);
|
||||
|
||||
console.log("channel id " + ch + " code " + code + " str " + str + " len " + str.length);
|
||||
|
||||
for (m = 0; m < this.myparent.active_children.length; m++)
|
||||
if (this.myparent.active_children[m].channel_id == ch) {
|
||||
var child = this.myparent.active_children[m];
|
||||
var ms = new CloseEvent("close", { code:code, reason:str } );
|
||||
|
||||
/* reply with close ack */
|
||||
this.send(msg.data);
|
||||
|
||||
if (child.onclose)
|
||||
child.onclose(ms);
|
||||
|
||||
this.myparent.active_children.splice(m, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
} // switch
|
||||
}
|
||||
} else {
|
||||
if (msg.data.charCodeAt(0) == lws_meta_cmd.WRITE ) {
|
||||
var ch = msg.data.charCodeAt(1), m, ms;
|
||||
var ws = this.myparent, ms;
|
||||
|
||||
for (m = 0; m < ws.active_children.length; m++) {
|
||||
if (ws.active_children[m].channel_id == ch) {
|
||||
ms = new MessageEvent("WebSocket", { data: msg.data.substr(2, msg.data.length - 2) } );
|
||||
if (ws.active_children[m].onmessage)
|
||||
ws.active_children[m].onmessage(ms);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.real.onclose = function() {
|
||||
var ws = this.myparent, m;
|
||||
for (m = 0; m < ws.active_children.length; m++) {
|
||||
var child = ws.active_children[m];
|
||||
var ms = new CloseEvent("close", { code:1000, reason:"parent closed" } );
|
||||
|
||||
if (child.onclose)
|
||||
child.onclose(ms);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* make a child connection using existing lws_meta real ws connection */
|
||||
lws_meta_ws.prototype.new_ws = function(suburl, protocol)
|
||||
{
|
||||
var ch = new lws_meta_ws_child();
|
||||
|
||||
ch.suburl = suburl;
|
||||
ch.subprotocol = protocol;
|
||||
ch.cookie = "C" + this.ordinal++;
|
||||
|
||||
this.pending_children.push(ch);
|
||||
|
||||
if (this.real.readyState == 1)
|
||||
this.real.onopen();
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* end of lws-meta helpers
|
||||
*/
|
||||
|
||||
function lws_san(s)
|
||||
{
|
||||
if (s.search("<") != -1)
|
||||
if (s.search("<") !== -1)
|
||||
return "invalid string";
|
||||
|
||||
return s;
|
||||
|
|
|
@ -83,12 +83,12 @@ enum demo_protocols {
|
|||
static uint8_t
|
||||
lws_poly_rand(struct lws_poly_gen *p)
|
||||
{
|
||||
p->cyc[0] = p->cyc[0] & 1 ? (p->cyc[0] >> 1) ^ 0xb4bcd35c :
|
||||
p->cyc[0] >> 1;
|
||||
p->cyc[0] = p->cyc[0] & 1 ? (p->cyc[0] >> 1) ^ 0xb4bcd35c :
|
||||
p->cyc[0] >> 1;
|
||||
p->cyc[1] = p->cyc[1] & 1 ? (p->cyc[1] >> 1) ^ 0x7a5bc2e3 :
|
||||
p->cyc[1] >> 1;
|
||||
p->cyc[0] = (p->cyc[0] & 1) ? (p->cyc[0] >> 1) ^ 0xb4bcd35c :
|
||||
p->cyc[0] >> 1;
|
||||
p->cyc[0] = (p->cyc[0] & 1) ? (p->cyc[0] >> 1) ^ 0xb4bcd35c :
|
||||
p->cyc[0] >> 1;
|
||||
p->cyc[1] = (p->cyc[1] & 1) ? (p->cyc[1] >> 1) ^ 0x7a5bc2e3 :
|
||||
p->cyc[1] >> 1;
|
||||
|
||||
return p->cyc[0] ^ p->cyc[1];
|
||||
}
|
||||
|
|
|
@ -52,11 +52,12 @@ static signed char
|
|||
cb(struct lejp_ctx *ctx, char reason)
|
||||
{
|
||||
char buf[1024], *p = buf, *end = &buf[sizeof(buf)];
|
||||
int n;
|
||||
|
||||
if (reason & LEJP_FLAG_CB_IS_VALUE) {
|
||||
p += lws_snprintf(p, p - end, " value '%s' ", ctx->buf);
|
||||
if (ctx->ipos) {
|
||||
int n;
|
||||
|
||||
p += lws_snprintf(p, p - end, "(array indexes: ");
|
||||
for (n = 0; n < ctx->ipos; n++)
|
||||
p += lws_snprintf(p, p - end, "%d ", ctx->i[n]);
|
||||
|
|
|
@ -283,7 +283,7 @@ static int
|
|||
ssh_ops_is_pubkey_authorized(const char *username, const char *type,
|
||||
const uint8_t *peer, int peer_len)
|
||||
{
|
||||
char *aps = NULL, *p, *ps;
|
||||
char *aps, *p, *ps;
|
||||
int n = strlen(type), alen = 2048, ret = 2, len;
|
||||
size_t s = 0;
|
||||
|
||||
|
@ -458,7 +458,6 @@ ssh_ops_child_process_io(void *_priv, struct lws *wsi,
|
|||
struct sshd_instance_priv *priv = _priv;
|
||||
struct lws_ring *r = priv->ring_stdout;
|
||||
void *rp;
|
||||
uint8_t buf[256], *p, *d;
|
||||
size_t bytes;
|
||||
int n, m;
|
||||
|
||||
|
@ -481,6 +480,8 @@ ssh_ops_child_process_io(void *_priv, struct lws *wsi,
|
|||
break;
|
||||
}
|
||||
if (priv->pty_in_bloat_nl_to_crnl) {
|
||||
uint8_t buf[256], *p, *d;
|
||||
|
||||
if (bytes != 1)
|
||||
n = bytes / 2;
|
||||
else
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue