mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
json dump vhost
Signed-off-by: Andy Green <andy@warmcat.com>
This commit is contained in:
parent
57f2007105
commit
f3e9c7347e
4 changed files with 89 additions and 5 deletions
|
@ -2160,3 +2160,87 @@ lws_set_extension_option(struct lws *wsi, const char *ext_name,
|
|||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
LWS_EXTERN int
|
||||
lws_json_dump_vhost(const struct lws_vhost *vh, char *buf, int len)
|
||||
{
|
||||
static const char * const prots[] = {
|
||||
"http://",
|
||||
"https://",
|
||||
"file://",
|
||||
"cgi://",
|
||||
">http://",
|
||||
">https://",
|
||||
};
|
||||
char *orig = buf, *end = buf + len - 1, first = 1;
|
||||
int n = 0;
|
||||
|
||||
if (len < 100)
|
||||
return 0;
|
||||
|
||||
buf += snprintf(buf, end - buf,
|
||||
"{\n \"name\":\"%s\",\n"
|
||||
" \"port\":\"%d\",\n"
|
||||
" \"use-ssl\":\"%d\",\n"
|
||||
" \"sts\":\"%d\",\n"
|
||||
" \"rx\":\"%lu\",\n"
|
||||
" \"tx\":\"%lu\",\n",
|
||||
vh->name, vh->listen_port,
|
||||
#ifdef LWS_OPENSSL_SUPPORT
|
||||
vh->use_ssl,
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
!!(vh->options & LWS_SERVER_OPTION_STS),
|
||||
vh->rx, vh->tx
|
||||
);
|
||||
|
||||
if (vh->mount_list) {
|
||||
struct lws_http_mount *m = vh->mount_list;
|
||||
|
||||
buf += snprintf(buf, end - buf, ",\n \"mounts\":[");
|
||||
while (m) {
|
||||
if (!first)
|
||||
buf += snprintf(buf, end - buf, ",");
|
||||
buf += snprintf(buf, end - buf,
|
||||
"\n {\n \"mountpoint\":\"%s\",\n"
|
||||
" \"origin\":\"%s%s\""
|
||||
,
|
||||
m->mountpoint,
|
||||
prots[m->origin_protocol],
|
||||
m->origin);
|
||||
if (m->def)
|
||||
buf += snprintf(buf, end - buf,
|
||||
",\n \"default\":\"%s\"",
|
||||
m->def);
|
||||
buf += snprintf(buf, end - buf, "\n }");
|
||||
first = 0;
|
||||
m = m->mount_next;
|
||||
}
|
||||
buf += snprintf(buf, end - buf, "\n ]");
|
||||
}
|
||||
|
||||
if (vh->protocols) {
|
||||
n = 0;
|
||||
first = 1;
|
||||
|
||||
buf += snprintf(buf, end - buf, ",\n \"ws-protocols\":[");
|
||||
while (n < vh->count_protocols) {
|
||||
if (!first)
|
||||
buf += snprintf(buf, end - buf, ",");
|
||||
buf += snprintf(buf, end - buf,
|
||||
"\n {\n \"%s\":\{\n"
|
||||
" \"status\":\"ok\"\n }\n }"
|
||||
,
|
||||
vh->protocols[n].name);
|
||||
first = 0;
|
||||
n++;
|
||||
}
|
||||
buf += snprintf(buf, end - buf, "\n ]");
|
||||
}
|
||||
|
||||
buf += snprintf(buf, end - buf, "\n}");
|
||||
|
||||
return buf - orig;
|
||||
}
|
||||
|
|
|
@ -1561,6 +1561,9 @@ lws_write_http_mount(struct lws_http_mount *next, struct lws_http_mount **res,
|
|||
struct lws_protocol_vhost_options *cgienv,
|
||||
int cgi_timeout);
|
||||
|
||||
LWS_EXTERN int
|
||||
lws_json_dump_vhost(const struct lws_vhost *vh, char *buf, int len);
|
||||
|
||||
LWS_VISIBLE LWS_EXTERN void
|
||||
lws_set_log_level(int level,
|
||||
void (*log_emit_function)(int level, const char *line));
|
||||
|
|
|
@ -111,6 +111,8 @@ int lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len)
|
|||
wsi->trunc_offset))) {
|
||||
lwsl_err("****** %x Sending new, pending truncated ...\n", wsi);
|
||||
assert(0);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
m = lws_ext_cb_active(wsi, LWS_EXT_CB_PACKET_TX_DO_SEND, &buf, len);
|
||||
|
|
|
@ -149,11 +149,6 @@ callback_lws_status(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
break;
|
||||
|
||||
case LWS_CALLBACK_CLOSED:
|
||||
/*
|
||||
* remove ourselves from live pss list
|
||||
*/
|
||||
lwsl_err("CLOSING pss %p ********\n", pss);
|
||||
|
||||
pp = &list;
|
||||
while (*pp) {
|
||||
if (*pp == pss) {
|
||||
|
|
Loading…
Add table
Reference in a new issue