2016-04-15 14:01:29 +08:00
|
|
|
/*
|
|
|
|
* libwebsockets-test-server - libwebsockets test implementation
|
|
|
|
*
|
2019-05-01 07:57:56 +01:00
|
|
|
* Written in 2010-2019 by Andy Green <andy@warmcat.com>
|
2016-04-15 14:01:29 +08:00
|
|
|
*
|
|
|
|
* This file is made available under the Creative Commons CC0 1.0
|
|
|
|
* Universal Public Domain Dedication.
|
|
|
|
*
|
|
|
|
* The person who associated a work with this deed has dedicated
|
|
|
|
* the work to the public domain by waiving all of his or her rights
|
|
|
|
* to the work worldwide under copyright law, including all related
|
|
|
|
* and neighboring rights, to the extent allowed by law. You can copy,
|
|
|
|
* modify, distribute and perform the work, even for commercial purposes,
|
|
|
|
* all without asking permission.
|
|
|
|
*
|
|
|
|
* The test apps are intended to be adapted for use in your code, which
|
|
|
|
* may be proprietary. So unlike the library itself, they are licensed
|
|
|
|
* Public Domain.
|
|
|
|
*/
|
2016-05-26 07:51:58 +08:00
|
|
|
|
|
|
|
#define LWS_DLL
|
|
|
|
#define LWS_INTERNAL
|
2018-08-23 09:46:01 +08:00
|
|
|
#include <libwebsockets.h>
|
2016-04-15 14:01:29 +08:00
|
|
|
#include <string.h>
|
2016-04-17 11:28:43 +08:00
|
|
|
#include <stdlib.h>
|
2017-10-13 10:33:02 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2017-07-15 19:02:04 +08:00
|
|
|
#include <fcntl.h>
|
2019-03-07 18:31:59 +08:00
|
|
|
#include <stdio.h>
|
2016-04-15 14:01:29 +08:00
|
|
|
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
struct lws_ss_filepath {
|
|
|
|
struct lws_ss_filepath *next;
|
|
|
|
char filepath[128];
|
|
|
|
};
|
|
|
|
|
2016-04-15 14:01:29 +08:00
|
|
|
struct lws_ss_dumps {
|
|
|
|
char buf[32768];
|
|
|
|
int length;
|
|
|
|
};
|
|
|
|
|
2019-02-18 09:02:33 +08:00
|
|
|
struct pss {
|
2016-04-15 14:01:29 +08:00
|
|
|
int ver;
|
|
|
|
int pos;
|
|
|
|
};
|
|
|
|
|
2019-02-18 09:02:33 +08:00
|
|
|
struct vhd {
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
struct lws_context *context;
|
2019-02-18 09:02:33 +08:00
|
|
|
struct lws_vhost *vhost;
|
|
|
|
const struct lws_protocols *protocol;
|
2020-05-28 12:48:17 +01:00
|
|
|
lws_sorted_usec_list_t sul;
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
int hide_vhosts;
|
|
|
|
int tow_flag;
|
2019-02-18 09:02:33 +08:00
|
|
|
int period_s;
|
|
|
|
int clients;
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
struct lws_ss_dumps d;
|
|
|
|
struct lws_ss_filepath *fp;
|
|
|
|
};
|
|
|
|
|
2016-05-13 08:20:12 +08:00
|
|
|
static const struct lws_protocols protocols[1];
|
2016-04-15 14:01:29 +08:00
|
|
|
|
|
|
|
static void
|
2020-05-28 12:48:17 +01:00
|
|
|
update(struct lws_sorted_usec_list *sul)
|
2016-04-15 14:01:29 +08:00
|
|
|
{
|
2020-05-28 12:48:17 +01:00
|
|
|
struct vhd *v = lws_container_of(sul, struct vhd, sul);
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
struct lws_ss_filepath *fp;
|
2019-02-18 09:02:33 +08:00
|
|
|
char contents[256], pure[256], *p = v->d.buf + LWS_PRE,
|
|
|
|
*end = v->d.buf + sizeof(v->d.buf) - LWS_PRE - 1;
|
|
|
|
int n, first = 1, fd;
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
|
2019-02-18 09:02:33 +08:00
|
|
|
p += lws_snprintf(p, lws_ptr_diff(end, p), "{\"i\":");
|
|
|
|
p += lws_json_dump_context(v->context, p, lws_ptr_diff(end, p),
|
|
|
|
v->hide_vhosts);
|
|
|
|
p += lws_snprintf(p, lws_ptr_diff(end, p), ", \"files\": [");
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
|
|
|
|
fp = v->fp;
|
|
|
|
while (fp) {
|
2019-02-18 09:02:33 +08:00
|
|
|
if (!first)
|
|
|
|
p += lws_snprintf(p, lws_ptr_diff(end, p), ",");
|
|
|
|
|
2019-09-13 05:31:28 +01:00
|
|
|
strcpy(pure, "(unknown)");
|
2018-06-23 12:56:21 +08:00
|
|
|
fd = lws_open(fp->filepath, LWS_O_RDONLY);
|
2017-04-28 11:54:27 +08:00
|
|
|
if (fd >= 0) {
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
n = read(fd, contents, sizeof(contents) - 1);
|
2019-09-13 05:31:28 +01:00
|
|
|
close(fd);
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
if (n >= 0) {
|
|
|
|
contents[n] = '\0';
|
2020-02-21 07:52:45 +00:00
|
|
|
lws_json_purify(pure, contents, sizeof(pure), NULL);
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
}
|
|
|
|
}
|
2019-02-18 09:02:33 +08:00
|
|
|
|
2019-09-13 05:31:28 +01:00
|
|
|
p += lws_snprintf(p, lws_ptr_diff(end, p),
|
|
|
|
"{\"path\":\"%s\",\"val\":\"%s\"}",
|
|
|
|
fp->filepath, pure);
|
|
|
|
first = 0;
|
|
|
|
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
fp = fp->next;
|
2016-07-13 11:35:16 +08:00
|
|
|
}
|
2019-02-18 09:02:33 +08:00
|
|
|
p += lws_snprintf(p, lws_ptr_diff(end, p), "]}");
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
v->d.length = p - (v->d.buf + LWS_PRE);
|
2016-04-15 14:01:29 +08:00
|
|
|
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
lws_callback_on_writable_all_protocol(v->context, &protocols[0]);
|
2020-05-28 12:48:17 +01:00
|
|
|
|
|
|
|
lws_sul_schedule(v->context, 0, &v->sul, update, v->period_s * LWS_US_PER_SEC);
|
2016-04-15 14:01:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
callback_lws_server_status(struct lws *wsi, enum lws_callback_reasons reason,
|
|
|
|
void *user, void *in, size_t len)
|
|
|
|
{
|
2016-05-02 06:01:59 +08:00
|
|
|
const struct lws_protocol_vhost_options *pvo =
|
|
|
|
(const struct lws_protocol_vhost_options *)in;
|
2019-02-18 09:02:33 +08:00
|
|
|
struct vhd *v = (struct vhd *)
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
lws_protocol_vh_priv_get(lws_get_vhost(wsi),
|
|
|
|
lws_get_protocol(wsi));
|
|
|
|
struct lws_ss_filepath *fp, *fp1, **fp_old;
|
2018-04-29 10:44:36 +08:00
|
|
|
int m;
|
2016-04-15 14:01:29 +08:00
|
|
|
|
|
|
|
switch (reason) {
|
|
|
|
|
|
|
|
case LWS_CALLBACK_ESTABLISHED:
|
|
|
|
lwsl_info("%s: LWS_CALLBACK_ESTABLISHED\n", __func__);
|
2019-02-18 09:02:33 +08:00
|
|
|
if (!v->clients++) {
|
2020-05-28 12:48:17 +01:00
|
|
|
lws_sul_schedule(lws_get_context(wsi), 0, &v->sul, update, 1);
|
2019-02-18 09:02:33 +08:00
|
|
|
lwsl_info("%s: starting updates\n", __func__);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LWS_CALLBACK_CLOSED:
|
|
|
|
if (!--v->clients)
|
|
|
|
lwsl_notice("%s: stopping updates\n", __func__);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2016-04-15 14:01:29 +08:00
|
|
|
case LWS_CALLBACK_PROTOCOL_INIT: /* per vhost */
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
if (v)
|
2016-04-15 14:01:29 +08:00
|
|
|
break;
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
|
|
|
|
lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi),
|
2019-02-18 09:02:33 +08:00
|
|
|
lws_get_protocol(wsi),
|
|
|
|
sizeof(struct vhd));
|
|
|
|
v = (struct vhd *)lws_protocol_vh_priv_get(lws_get_vhost(wsi),
|
|
|
|
lws_get_protocol(wsi));
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
|
|
|
|
fp_old = &v->fp;
|
|
|
|
|
2016-04-15 14:01:29 +08:00
|
|
|
while (pvo) {
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
if (!strcmp(pvo->name, "hide-vhosts"))
|
|
|
|
v->hide_vhosts = atoi(pvo->value);
|
2016-04-15 14:01:29 +08:00
|
|
|
if (!strcmp(pvo->name, "update-ms"))
|
2019-02-18 09:02:33 +08:00
|
|
|
v->period_s = (atoi(pvo->value) + 500) / 1000;
|
2018-04-29 10:44:36 +08:00
|
|
|
else
|
2019-02-18 09:02:33 +08:00
|
|
|
v->period_s = 5;
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
if (!strcmp(pvo->name, "filepath")) {
|
|
|
|
fp = malloc(sizeof(*fp));
|
|
|
|
fp->next = NULL;
|
2017-10-13 10:33:02 +08:00
|
|
|
lws_snprintf(&fp->filepath[0],
|
|
|
|
sizeof(fp->filepath), "%s",
|
|
|
|
pvo->value);
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
*fp_old = fp;
|
|
|
|
fp_old = &fp->next;
|
|
|
|
}
|
2016-04-15 14:01:29 +08:00
|
|
|
pvo = pvo->next;
|
|
|
|
}
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
v->context = lws_get_context(wsi);
|
2019-02-18 09:02:33 +08:00
|
|
|
v->vhost = lws_get_vhost(wsi);
|
|
|
|
v->protocol = lws_get_protocol(wsi);
|
2018-04-29 10:44:36 +08:00
|
|
|
|
2020-05-28 12:48:17 +01:00
|
|
|
lws_sul_schedule(lws_get_context(wsi), 0, &v->sul, update, 1);
|
2016-04-15 14:01:29 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LWS_CALLBACK_PROTOCOL_DESTROY: /* per vhost */
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
if (!v)
|
2016-04-15 14:01:29 +08:00
|
|
|
break;
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
fp = v->fp;
|
|
|
|
while (fp) {
|
|
|
|
fp1= fp->next;
|
|
|
|
free(fp);
|
|
|
|
fp = fp1;
|
|
|
|
}
|
2016-04-15 14:01:29 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LWS_CALLBACK_SERVER_WRITEABLE:
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
m = lws_write(wsi, (unsigned char *)v->d.buf + LWS_PRE,
|
|
|
|
v->d.length, LWS_WRITE_TEXT);
|
2016-04-15 14:01:29 +08:00
|
|
|
if (m < 0)
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct lws_protocols protocols[] = {
|
|
|
|
{
|
|
|
|
"lws-server-status",
|
|
|
|
callback_lws_server_status,
|
2019-02-18 09:02:33 +08:00
|
|
|
sizeof(struct pss),
|
2016-04-15 14:01:29 +08:00
|
|
|
1024,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-01-02 08:32:23 +00:00
|
|
|
LWS_VISIBLE int
|
2016-04-15 14:01:29 +08:00
|
|
|
init_protocol_lws_server_status(struct lws_context *context,
|
2017-10-13 10:33:02 +08:00
|
|
|
struct lws_plugin_capability *c)
|
2016-04-15 14:01:29 +08:00
|
|
|
{
|
|
|
|
if (c->api_magic != LWS_PLUGIN_API_MAGIC) {
|
|
|
|
lwsl_err("Plugin API %d, library API %d",
|
|
|
|
LWS_PLUGIN_API_MAGIC, c->api_magic);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
c->protocols = protocols;
|
2018-08-16 19:10:32 +08:00
|
|
|
c->count_protocols = LWS_ARRAY_SIZE(protocols);
|
2016-04-15 14:01:29 +08:00
|
|
|
c->extensions = NULL;
|
|
|
|
c->count_extensions = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-02 08:32:23 +00:00
|
|
|
LWS_VISIBLE int
|
2016-04-15 14:01:29 +08:00
|
|
|
destroy_protocol_lws_server_status(struct lws_context *context)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|