diff --git a/READMEs/README.coding.md b/READMEs/README.coding.md index 40aa50649..a14d1fa8d 100644 --- a/READMEs/README.coding.md +++ b/READMEs/README.coding.md @@ -1,7 +1,7 @@ Notes about coding with lws =========================== -@section era Old lws and lws v2.0 +@section era Old lws and lws v2.0+ Originally lws only supported the "manual" method of handling everything in the user callback found in test-server.c / test-server-http.c. diff --git a/READMEs/README.generic-sessions.md b/READMEs/README.generic-sessions.md deleted file mode 100644 index 376342a07..000000000 --- a/READMEs/README.generic-sessions.md +++ /dev/null @@ -1,373 +0,0 @@ -Notes about generic-sessions Plugin -=================================== - -@section gseb Enabling lwsgs for build - -Enable at CMake with -DLWS_WITH_GENERIC_SESSIONS=1 - -This also needs sqlite3 (libsqlite3-dev or similar package) - - -@section gsi lwsgs Introduction - -The generic-sessions protocol plugin provides cookie-based login -authentication for lws web and ws connections. - -The plugin handles everything about generic account registration, -email verification, lost password, account deletion, and other generic account -management. - -Other code, in another eg, ws protocol handler, only needs very high-level -state information from generic-sessions, ie, which user the client is -authenticated as. Everything underneath is managed in generic-sessions. - - - - random 20-byte session id managed in a cookie - - - all information related to the session held at the server, nothing managed clientside - - - sqlite3 used at the server to manage active sessions and users - - - defaults to creating anonymous sessions with no user associated - - - admin account (with user-selectable username) is defined in config with a SHA-1 of the password; rest of the accounts are in sqlite3 - - - user account passwords stored as salted SHA-1 with additional confounder - only stored in the JSON config, not the database - - - login, logout, register account + email verification built-in with examples - - - in a mount, some file suffixes (ie, .js) can be associated with a protocol for the purposes of rewriting symbolnames. These are read-only copies of logged-in server state. - - - When your page fetches .js or other rewritten files from that mount, "$lwsgs_user" and so on are rewritten on the fly using chunked transfer encoding - - - Eliminates server-side scripting with a few rewritten symbols and - javascript on client side - - - 32-bit bitfield for authentication sectoring, mounts can provide a mask on the loggin-in session's associated server-side bitfield that must be set for access. - - - No code (just config) required for, eg, private URL namespace that requires login to access. - - -@section gsin Lwsgs Integration to HTML - -Only three steps are needed to integrate lwsgs in your HTML. - -1) lwsgs HTML UI is bundled with the javascript it uses in `lwsgs.js`, so -import that script file in your head section - -2) define an empty div of id "lwsgs" somewhere - -3) Call lwsgs_initial() in your page - -That's it. An example is below - -``` - - - - - - - - - - - -
- - -
-
- - - - - - -``` - -@section gsof Lwsgs Overall Flow@ - -When the protocol is initialized, it gets per-vhost information from the config, such -as where the sqlite3 databases are to be stored. The admin username and sha-1 of the -admin password are also taken from here. - -In the mounts using protocol-generic-sessions, a cookie is maintained against any requests; if no cookie was active on the initial request a new session is -created with no attached user. - -So there should always be an active session after any transactions with the server. - -In the example html going to the mount /lwsgs loads a login / register page as the default. - -The
in the login page contains 'next url' hidden inputs that let the html 'program' where the form handler will go after a successful admin login, a successful user login and a failed login. - -After a successful login, the sqlite record at the server for the current session is updated to have the logged-in username associated with it. - - - -@section gsconf Lwsgs Configuration - -"auth-mask" defines the authorization sector bits that must be enabled on the session to gain access. - -"auth-mask" 0 is the default. - - - b0 is set if you are logged in as a user at all. - - b1 is set if you are logged in with the user configured to be admin - - b2 is set if the account has been verified (the account configured for admin is always verified) - - b3 is set if your session just did the forgot password flow successfully - -``` - { - # things in here can always be served - "mountpoint": "/lwsgs", - "origin": "file:///usr/share/libwebsockets-test-server/generic-sessions", - "origin": "callback://protocol-lws-messageboard", - "default": "generic-sessions-login-example.html", - "auth-mask": "0", - "interpret": { - ".js": "protocol-lws-messageboard" - } - }, { - # things in here can only be served if logged in as a user - "mountpoint": "/lwsgs/needauth", - "origin": "file:///usr/share/libwebsockets-test-server/generic-sessions/needauth", - "origin": "callback://protocol-lws-messageboard", - "default": "generic-sessions-login-example.html", - "auth-mask": "5", # logged in as a verified user - "interpret": { - ".js": "protocol-lws-messageboard" - } - }, { - # things in here can only be served if logged in as admin - "mountpoint": "/lwsgs/needadmin", - "origin": "file:///usr/share/libwebsockets-test-server/generic-sessions/needadmin", - "origin": "callback://protocol-lws-messageboard", - "default": "generic-sessions-login-example.html", - "auth-mask": "7", # b2 = verified (by email / or admin), b1 = admin, b0 = logged in with any user name - "interpret": { - ".js": "protocol-lws-messageboard" - } - } -``` -Note that the name of the real application protocol that uses generic-sessions -is used, not generic-sessions itself. - -The vhost configures the storage dir, admin credentials and session cookie lifetimes: - -``` - "ws-protocols": [{ - "protocol-generic-sessions": { - "status": "ok", - "admin-user": "admin", - - # create the pw hash like this (for the example pw, "jipdocesExunt" ) - # $ echo -n "jipdocesExunt" | sha1sum - # 046ce9a9cca769e85798133be06ef30c9c0122c9 - - # - # Obviously ** change this password hash to a secret one before deploying ** - # - "admin-password-sha1": "046ce9a9cca769e85798133be06ef30c9c0122c9", - "session-db": "/var/www/sessions/lws.sqlite3", - "timeout-idle-secs": "600", - "timeout-anon-idle-secs": "1200", - "timeout-absolute-secs": "6000", - # the confounder is part of the salted password hashes. If this config - # file is in a 0700 root:root dir, an attacker with apache credentials - # will have to get the confounder out of the process image to even try - # to guess the password hashes. - "confounder": "Change to <=31 chars of junk", - - "email-from": "noreply@example.com", - "email-smtp-ip": "127.0.0.1", - "email-expire": "3600", - "email-helo": "myhost.com", - "email-contact-person": "Set Me ", - "email-confirm-url-base": "http://localhost:7681/lwsgs" - } -``` - -The email- related settings control generation of automatic emails for -registration and forgotten password. - - - `email-from`: The email address automatic emails are sent from - - - `email-smtp-ip`: Normally 127.0.0.1, if you have a suitable server on port - 25 on your lan you can use this instead here. - - - `email-expire`: Seconds that links sent in email will work before being - deleted - - - `email-helo`: HELO to use when communicating with your SMTP server - - - `email-contact-person`: mentioned in the automatic emails as a human who can - answer questions - - - `email-confirm-url-base`: the URL to start links with in the emails, so the - recipient can get back to the web server - -The real protocol that makes use of generic-sessions must also be listed and -any configuration it needs given - -``` - "protocol-lws-messageboard": { - "status": "ok", - "message-db": "/var/www/sessions/messageboard.sqlite3" - }, -``` - -Notice the real application uses his own sqlite db, no details about how -generic-sessions works or how it stores data are available to it. - - -@section gspwc Lwsgs Password Confounder - -You can also define a per-vhost confounder shown in the example above, used -when aggregating the password with the salt when it is hashed. Any attacker -will also need to get the confounder along with the database, which you can -make harder by making the config dir only eneterable / readable by root. - - -@section gsprep Lwsgs Preparing the db directory - -You will have to prepare the db directory so it's suitable for the lwsws user to use, -that usually means apache, eg - -``` - # mkdir -p /var/www/sessions - # chown root:apache /var/www/sessions - # chmod 770 /var/www/sessions -``` - -@section gsrmail Lwsgs Email configuration - -lwsgs will can send emails by talking to an SMTP server on localhost:25. That -will usually be sendmail or postfix, you should confirm that works first by -itself using the `mail` application to send on it. - -lwsgs has been tested on stock Fedora sendmail and postfix. - - -@section gsap Lwsgs Integration with another protocol - -lwsgs is designed to provide sessions and accounts in a standalone and generic way. - -But it's not useful by itself, there will always be the actual application who wants -to make use of generic-sessions features. - -We provide the "messageboard" plugin as an example of how to integrate with -your actual application protocol. - -The basic approach is the 'real' protocol handler (usually a plugin itself) -subclasses the generic-sessions plugin and calls through to it by default. - -The "real" protocol handler entirely deals with ws-related stuff itself, since -generic-sessions does not use ws. But for - - - LWS_CALLBACK_HTTP - - LWS_CALLBACK_HTTP_BODY - - LWS_CALLBACK_HTTP_BODY_COMPLETION - - LWS_CALLBACK_HTTP_DROP_PROTOCOL - -the "real" protocol handler checks if it recognizes the activity (eg, his own -POST form URL) and if not, passes stuff through to the generic-sessions protocol callback to handle it. To simplify matters the real protocol can just pass -through any unhandled messages to generic-sessions. - -The "real" protocol can get a pointer to generic-sessions protocol on the -same vhost using - -``` - vhd->gsp = lws_vhost_name_to_protocol(vhd->vh, "protocol-generic-sessions"); -``` - -The "real" protocol must also arrange generic-sessions per_session_data in his -own per-session allocation. To allow keeping generic-sessions opaque, the -real protocol must allocate that space at runtime, using the pss size -the generic-sessions protocol struct exposes - -``` - struct per_session_data__myapp { - void *pss_gs; - ... - - pss->pss_gs = malloc(vhd->gsp->per_session_data_size); -``` - -The allocation reserved for generic-sessions is then used as user_space when -the real protocol calls through to the generic-sessions callback - -``` - vhd->gsp->callback(wsi, reason, &pss->pss_gs, in, len); -``` - -In that way the "real" protocol can subclass generic-sessions functionality. - - -To ease management of these secondary allocations, there are callbacks that -occur when a wsi binds to a protocol and when the binding is dropped. These -should be used to malloc and free and kind of per-connection -secondary allocations. - -``` - case LWS_CALLBACK_HTTP_BIND_PROTOCOL: - if (!pss || pss->pss_gs) - break; - - pss->pss_gs = malloc(vhd->gsp->per_session_data_size); - if (!pss->pss_gs) - return -1; - - memset(pss->pss_gs, 0, vhd->gsp->per_session_data_size); - break; - - case LWS_CALLBACK_HTTP_DROP_PROTOCOL: - if (vhd->gsp->callback(wsi, reason, pss ? pss->pss_gs : NULL, in, len)) - return -1; - - if (pss->pss_gs) { - free(pss->pss_gs); - pss->pss_gs = NULL; - } - break; -``` - - -#section gsapsib Getting session-specific information from another protocol - -At least at the time when someone tries to upgrade an http(s) connection to -ws(s) with your real protocol, it is necessary to confirm the cookie the http(s) -connection has with generic-sessions and find out his username and other info. - -Generic sessions lets another protocol check it again by calling his callback, -and lws itself provides a generic session info struct to pass the related data - -``` - struct lws_session_info { - char username[32]; - char email[100]; - char ip[72]; - unsigned int mask; - char session[42]; - }; - - struct lws_session_info sinfo; - ... - vhd->gsp->callback(wsi, LWS_CALLBACK_SESSION_INFO, - &pss->pss_gs, &sinfo, 0); -``` - -After the call to generic-sessions, the results can be - - - all the strings will be zero-length and .mask zero, there is no usable cookie - - - only .ip and .session are set: the cookie is OK but no user logged in - - - all the strings contain information about the logged-in user - -the real protocol can use this to reject attempts to open ws connections from -http connections that are not authenticated; afterwards there's no need to -check the ws connection auth status again. - diff --git a/READMEs/README.generic-table.md b/READMEs/README.generic-table.md deleted file mode 100644 index 7a8580968..000000000 --- a/READMEs/README.generic-table.md +++ /dev/null @@ -1,219 +0,0 @@ -Notes about generic-table -========================= - -@section gtint What is generic-table? - -Generic-table is a JSON schema and client-side JS file that makes it easy to -display live, table structured HTML over a ws link. - -An example plugin and index.html using it are provided, but lwsgt itself doesn't -have its own plugin, it's just a JSON schema and client-side JS that other -plugins can use to simplify displaying live, table-based data without having -to reinvent the wheel each time. - -The ws protocol sends JSON describing the table, and then JSON updating the table -contents when it chooses, the brower table is updated automatically, live. - -\image html lwsgt-overview.png - - - Example protocol plugin (displays directory contents): https://github.com/warmcat/libwebsockets/tree/master/plugins/generic-table/protocol_table_dirlisting.c - - - Example HTML: https://github.com/warmcat/libwebsockets/tree/master/plugins/generic-table/assets/index.html - - - lwsgt.js (client-side table rendering / ws link management): https://github.com/warmcat/libwebsockets/tree/master/plugins/generic-table/assets/lwsgt.js - - -@section gteb Enabling for build - -Enable the demo plugin at CMake with -DLWS_WITH_PLUGINS=1 - - -@section gtinth Integrating with your html - - - In your HEAD section, include lwsgt.js - -``` - -``` - - - Also in your HEAD section, style the lwsgt CSS, eg - -``` - -``` - -You can skip this but the result will be less beautiful until some CSS is -provided. - - - In your body section, declare a div with an id (can be whatever you want) - -``` -
-``` - -lwsgt JS will put its content there. - - - Finally in a -``` - -In the callback, you can recover the ws object by `window[gt].lwsgt_ws`. - - -@section gtc Lwsgt constructor - -To instantiate the ws link and lwsgt instance, your HTML must call a lwsgt -constructor for each region on the page managed by lwsgt. - -`var myvar = new lwsgt_initial(title, ws_protocol, div_id, click_cb, myvar);` - -All of the arguments are strings. - -| Parameter | Description | -|-----------------|---------------------------------------------------------| -| title | Title string to go above the table | -| ws_protocol | Protocol name string to use when making ws connection | -| div_id | HTML id of div to fill with content | -| click_cb | Callback function name string to handle clickable links | -| myvar | Name of var used to hold this instantiation globally | - -Note "myvar" is needed so it can be passed to the click handling callback. - - -@section gtclick Lwsgt click handling function - -When a clickable link produced by lwsgt is clicked, the function named in the -click_cb parameter to lwsgt_initial is called. - -That function is expected to take four parameters, eg - -`function lwsgt_dir_click(gt, u, col, row)` - -| Parameter | Description | -|------- ---|-----------------------------------------------------------| -| gt | Name of global var holding this lwsgt context (ie, myvar) | -| u | Link "url" string | -| col | Table column number link is from | -| row | Table row number link is from | - - - -@section gtgj Generic-table JSON - -### Column layout - -When the ws connection is established, the protocol should send a JSON message -describing the table columns. For example - -``` - "cols": [ - { "name": "Date" }, - { "name": "Size", "align": "right" }, - { "name": "Icon" }, - { "name": "Name", "href": "uri"}, - { "name": "uri", "hide": "1" } - ] - } -``` - - - This describes 5 columns - - - Only four columns (not "uri") should be visible - - - "Name" should be presented as a clickable link using "uri" as the - destination, when a "uri" field is presented. - - - "Size" field should be presented aligned to the right - - ### Breadcrumbs - - When a view is hierarchical, it's useful to provide a "path" with links back - in the "path", known as "breadcrumbs". - - Elements before the last one should provide a "url" member as well as the - displayable name, which is used to create the link destination. - - The last element, being the current displayed page should not have a url - member and be displayed without link style. - - - ``` - "breadcrumbs":[{"name":"top", "url": "/" }, {"name":"mydir"}] - ``` - - ### Table data - - The actual file data consists of an array of rows, containing the columns - mentioned in the original "cols" section. - - ``` - "data":[ - { - "Icon":" ", - "Date":"2015-Feb-06 03:08:35 +0000", - "Size":"1406", - "uri":"./serve//favicon.ico", - "Name":"favicon.ico" - } - ] - - ``` - - @section gtdirl Setting up protocol-lws-table-dirlisting - - The example protocol needs two mounts, one to provide the index.html, js and - the protocol itself - - ``` - { - "mountpoint": "/dirtest", - "origin": "file:///usr/share/libwebsockets-test-server/generic-table", - "origin": "callback://protocol-lws-table-dirlisting", - "default": "index.html", - "pmo": [{ - "dir": "/usr/share/libwebsockets-test-server" - }] - }, -``` - -The protocol wants a per-mount option (PMO) to tell it the base directory it -is serving from, named "dir". - -The other mount is there to simply serve items that get clicked on from the -table in a secure way - -``` - { - "mountpoint": "/dirtest/serve", - "origin": "file:///usr/share/libwebsockets-test-server", - "default": "index.html" - }, -``` - -This last bit is not related to using lwsgt itself. diff --git a/include/libwebsockets.h b/include/libwebsockets.h index 544a9db5d..f93bff3d6 100644 --- a/include/libwebsockets.h +++ b/include/libwebsockets.h @@ -546,7 +546,6 @@ struct lws; #include #include #include -#include #include diff --git a/include/libwebsockets/lws-plugin-generic-sessions.h b/include/libwebsockets/lws-plugin-generic-sessions.h deleted file mode 100644 index 2aa6e92a6..000000000 --- a/include/libwebsockets/lws-plugin-generic-sessions.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2019 Andy Green - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -/*! \defgroup generic-sessions plugin: generic-sessions - * \ingroup Protocols-and-Plugins - * - * ##Plugin Generic-sessions related - * - * generic-sessions plugin provides a reusable, generic session and login / - * register / forgot password framework including email verification. - */ -///@{ - -#define LWSGS_EMAIL_CONTENT_SIZE 16384 -/**< Maximum size of email we might send */ - -/* SHA-1 binary and hexified versions */ -/** typedef struct lwsgw_hash_bin */ -typedef struct { unsigned char bin[32]; /**< binary representation of hash */} lwsgw_hash_bin; -/** typedef struct lwsgw_hash */ -typedef struct { char id[65]; /**< ascii hex representation of hash */ } lwsgw_hash; - -/** enum lwsgs_auth_bits */ -enum lwsgs_auth_bits { - LWSGS_AUTH_LOGGED_IN = 1, /**< user is logged in as somebody */ - LWSGS_AUTH_ADMIN = 2, /**< logged in as the admin user */ - LWSGS_AUTH_VERIFIED = 4, /**< user has verified his email */ - LWSGS_AUTH_FORGOT_FLOW = 8, /**< just completed "forgot password" */ -}; - -/** struct lws_session_info - information about user session status */ -struct lws_session_info { - char username[32]; /**< username logged in as, or empty string */ - char email[100]; /**< email address associated with login, or empty string */ - char ip[72]; /**< ip address session was started from */ - unsigned int mask; /**< access rights mask associated with session - * see enum lwsgs_auth_bits */ - char session[42]; /**< session id string, usable as opaque uid when not logged in */ -}; - -/** enum lws_gs_event */ -enum lws_gs_event { - LWSGSE_CREATED, /**< a new user was created */ - LWSGSE_DELETED /**< an existing user was deleted */ -}; - -/** struct lws_gs_event_args */ -struct lws_gs_event_args { - enum lws_gs_event event; /**< which event happened */ - const char *username; /**< which username the event happened to */ - const char *email; /**< the email address of that user */ -}; - -///@} diff --git a/include/libwebsockets/lws-protocols-plugins.h b/include/libwebsockets/lws-protocols-plugins.h index 869c76f44..4df9a2228 100644 --- a/include/libwebsockets/lws-protocols-plugins.h +++ b/include/libwebsockets/lws-protocols-plugins.h @@ -196,34 +196,107 @@ lws_protocol_init(struct lws_context *context); #ifdef LWS_WITH_PLUGINS -/* PLUGINS implies LIBUV */ +#define LWS_PLUGIN_API_MAGIC 190 -#define LWS_PLUGIN_API_MAGIC 180 +/* + * Abstract plugin header for any kind of plugin class, always at top of + * actual class plugin export type. + * + * The export type object must be exported with the same name as the plugin + * file, eg, libmyplugin.so must export a const one of these as the symbol + * "myplugin". + * + * That is the only expected export from the plugin. + */ + +typedef struct lws_plugin_header { + const char *name; + const char *_class; + + unsigned int api_magic; + /* set to LWS_PLUGIN_API_MAGIC at plugin build time */ + + /* plugin-class specific superclass data follows */ +} lws_plugin_header_t; + +/* + * "lws_protocol_plugin" class export, for lws_protocol implementations done + * as plugins + */ +typedef struct lws_plugin_protocol { + lws_plugin_header_t hdr; -/** struct lws_plugin_capability - how a plugin introduces itself to lws */ -struct lws_plugin_capability { - unsigned int api_magic; /**< caller fills this in, plugin fills rest */ const struct lws_protocols *protocols; /**< array of supported protocols provided by plugin */ - int count_protocols; /**< how many protocols */ const struct lws_extension *extensions; /**< array of extensions provided by plugin */ + int count_protocols; /**< how many protocols */ int count_extensions; /**< how many extensions */ -}; +} lws_plugin_protocol_t; -typedef int (*lws_plugin_init_func)(struct lws_context *, - struct lws_plugin_capability *); -typedef int (*lws_plugin_destroy_func)(struct lws_context *); -/** struct lws_plugin */ +/* + * This is the dynamic, runtime created part of the plugin instantiation. + * These are kept in a linked-list and destroyed with the context. + */ + struct lws_plugin { struct lws_plugin *list; /**< linked list */ + + const lws_plugin_header_t *hdr; + + union { +#if defined(LWS_WITH_LIBUV) #if (UV_VERSION_MAJOR > 0) - uv_lib_t lib; /**< shared library pointer */ + uv_lib_t lib; /**< shared library pointer */ #endif - void *l; /**< so we can compile on ancient libuv */ - char name[64]; /**< name of the plugin */ - struct lws_plugin_capability caps; /**< plugin capabilities */ +#endif + void *l; /**< */ + } u; }; +typedef int (*each_plugin_cb_t)(struct lws_plugin *p, void *user); + +/** + * lws_plugins_init() - dynamically load plugins of matching class from dirs + * + * \param pplugin: pointer to linked-list for this kind of plugin + * \param d: array of directory paths to look in + * \param _class: class string that plugin must declare + * \param filter: NULL, or a string that must appear after the third char of the plugin filename + * \param each: NULL, or each_plugin_cb_t callback for each instantiated plugin + * \param each_user: pointer passed to each callback + * + * Allows you to instantiate a class of plugins to a specified linked-list. + * The each callback allows you to init each inistantiated callback and pass a + * pointer each_user to it. + * + * To take down the plugins, pass a pointer to the linked-list head to + * lws_plugins_destroy. + * + * This is used for lws protocol plugins but you can define your own plugin + * class name like "mypluginclass", declare it in your plugin headers, and load + * your own plugins to your own list using this api the same way. + */ +LWS_VISIBLE LWS_EXTERN int +lws_plugins_init(struct lws_plugin **pplugin, const char * const *d, + const char *_class, const char *filter, + each_plugin_cb_t each, void *each_user); + +/** + * lws_plugins_destroy() - dynamically unload list of plugins + * + * \param pplugin: pointer to linked-list for this kind of plugin + * \param each: NULL, or each_plugin_cb_t callback for each instantiated plugin + * \param each_user: pointer passed to each callback + * + * Allows you to destroy a class of plugins from a specified linked-list + * created by a call to lws_plugins_init(). + * + * The each callback allows you to deinit each inistantiated callback and pass a + * pointer each_user to it, just before its footprint is destroyed. + */ +LWS_VISIBLE LWS_EXTERN int +lws_plugins_destroy(struct lws_plugin **pplugin, each_plugin_cb_t each, + void *each_user); #endif ///@} diff --git a/lib/core-net/private-lib-core-net.h b/lib/core-net/private-lib-core-net.h index 6b122568c..a23a44772 100644 --- a/lib/core-net/private-lib-core-net.h +++ b/lib/core-net/private-lib-core-net.h @@ -1158,11 +1158,13 @@ lws_libuv_closehandle(struct lws *wsi); int lws_libuv_check_watcher_active(struct lws *wsi); -LWS_VISIBLE LWS_EXTERN int -lws_plat_plugins_init(struct lws_context * context, const char * const *d); +const lws_plugin_header_t * +lws_plat_dlopen(struct lws_plugin **pplugin, const char *libpath, + const char *sofilename, const char *_class, + each_plugin_cb_t each, void *each_user); -LWS_VISIBLE LWS_EXTERN int -lws_plat_plugins_destroy(struct lws_context * context); +int +lws_plat_destroy_dl(struct lws_plugin *p); struct lws * lws_adopt_socket_vhost(struct lws_vhost *vh, lws_sockfd_type accept_fd); diff --git a/lib/core-net/vhost.c b/lib/core-net/vhost.c index c5c0fcd50..e66eb2f4a 100644 --- a/lib/core-net/vhost.c +++ b/lib/core-net/vhost.c @@ -685,15 +685,18 @@ lws_create_vhost(struct lws_context *context, #ifdef LWS_WITH_PLUGINS if (plugin) { while (plugin) { - for (n = 0; n < plugin->caps.count_protocols; n++) { + const lws_plugin_protocol_t *plpr = + (const lws_plugin_protocol_t *)plugin->hdr; + + for (n = 0; n < plpr->count_protocols; n++) { /* * for compatibility's sake, no pvo implies * allow all protocols */ if (f || lws_vhost_protocol_options(vh, - plugin->caps.protocols[n].name)) { + plpr->protocols[n].name)) { memcpy(&lwsp[m], - &plugin->caps.protocols[n], + &plpr->protocols[n], sizeof(struct lws_protocols)); m++; vh->count_protocols++; diff --git a/lib/core/private-lib-core.h b/lib/core/private-lib-core.h index e5e11f4bc..f38b07a12 100644 --- a/lib/core/private-lib-core.h +++ b/lib/core/private-lib-core.h @@ -111,6 +111,7 @@ #define strerror(x) "" #endif + /* * * ------ private platform defines ------ diff --git a/lib/event-libs/libuv/libuv.c b/lib/event-libs/libuv/libuv.c index 26ca5046d..ff0e0cbac 100644 --- a/lib/event-libs/libuv/libuv.c +++ b/lib/event-libs/libuv/libuv.c @@ -312,170 +312,6 @@ lws_libuv_check_watcher_active(struct lws *wsi) return uv_is_active(h); } - -#if defined(LWS_WITH_PLUGINS) && (UV_VERSION_MAJOR > 0) - -int -lws_uv_plugins_init(struct lws_context *context, const char * const *d) -{ - struct lws_plugin_capability lcaps; - struct lws_plugin *plugin; - lws_plugin_init_func initfunc; - int m, ret = 0; - void *v; - uv_dirent_t dent; - uv_fs_t req; - char path[256]; - uv_lib_t lib; - int pofs = 0; - -#if defined(__MINGW32__) || !defined(WIN32) - pofs = 3; -#endif - - lib.errmsg = NULL; - lib.handle = NULL; - - uv_loop_init(&context->uv.loop); - - lwsl_notice(" Plugins:\n"); - - while (d && *d) { - - lwsl_notice(" Scanning %s\n", *d); - m =uv_fs_scandir(&context->uv.loop, &req, *d, 0, NULL); - if (m < 1) { - lwsl_err("Scandir on %s failed\n", *d); - d++; - continue; - } - - while (uv_fs_scandir_next(&req, &dent) != UV_EOF) { - if (strlen(dent.name) < 7) - continue; - - lwsl_notice(" %s\n", dent.name); - - lws_snprintf(path, sizeof(path) - 1, "%s/%s", *d, - dent.name); - if (uv_dlopen(path, &lib)) { - uv_dlerror(&lib); - lwsl_err("Error loading DSO: %s\n", lib.errmsg); - uv_dlclose(&lib); - goto bail; - } - - /* we could open it, can we get his init function? */ - -#if !defined(WIN32) && !defined(__MINGW32__) - m = lws_snprintf(path, sizeof(path) - 1, "init_%s", - dent.name + pofs /* snip lib... */); - path[m - 3] = '\0'; /* snip the .so */ -#else - m = lws_snprintf(path, sizeof(path) - 1, "init_%s", - dent.name + pofs); - path[m - 4] = '\0'; /* snip the .dll */ -#endif - if (uv_dlsym(&lib, path, &v)) { - uv_dlerror(&lib); - lwsl_err("%s: Failed to get '%s' on %s: %s\n", - __func__, path, dent.name, lib.errmsg); - uv_dlclose(&lib); - goto bail; - } - initfunc = (lws_plugin_init_func)v; - lcaps.api_magic = LWS_PLUGIN_API_MAGIC; - m = initfunc(context, &lcaps); - if (m) { - lwsl_err("Init %s failed %d\n", dent.name, m); - goto skip; - } - - plugin = lws_malloc(sizeof(*plugin), "plugin"); - if (!plugin) { - uv_dlclose(&lib); - lwsl_err("OOM\n"); - goto bail; - } - plugin->list = context->plugin_list; - context->plugin_list = plugin; - lws_strncpy(plugin->name, dent.name, sizeof(plugin->name)); - plugin->lib = lib; - plugin->caps = lcaps; - context->plugin_protocol_count += lcaps.count_protocols; - context->plugin_extension_count += lcaps.count_extensions; - - continue; - -skip: - uv_dlclose(&lib); - } -bail: - uv_fs_req_cleanup(&req); - d++; - } - - return ret; -} - -int -lws_uv_plugins_destroy(struct lws_context *context) -{ - struct lws_plugin *plugin = context->plugin_list, *p; - lws_plugin_destroy_func func; - char path[256]; - int pofs = 0; - void *v; - int m; - -#if defined(__MINGW32__) || !defined(WIN32) - pofs = 3; -#endif - - if (!plugin) - return 0; - - while (plugin) { - p = plugin; - -#if !defined(WIN32) && !defined(__MINGW32__) - m = lws_snprintf(path, sizeof(path) - 1, "destroy_%s", - plugin->name + pofs); - path[m - 3] = '\0'; -#else - m = lws_snprintf(path, sizeof(path) - 1, "destroy_%s", - plugin->name + pofs); - path[m - 4] = '\0'; -#endif - - if (uv_dlsym(&plugin->lib, path, &v)) { - uv_dlerror(&plugin->lib); - lwsl_err("Failed to get %s on %s: %s", path, - plugin->name, plugin->lib.errmsg); - } else { - func = (lws_plugin_destroy_func)v; - m = func(context); - if (m) - lwsl_err("Destroying %s failed %d\n", - plugin->name, m); - } - - uv_dlclose(&p->lib); - plugin = p->list; - p->list = NULL; - free(p); - } - - context->plugin_list = NULL; - - while (uv_loop_close(&context->uv.loop)) - ; - - return 0; -} - -#endif - static int elops_init_context_uv(struct lws_context *context, const struct lws_context_creation_info *info) diff --git a/lib/misc/dir.c b/lib/misc/dir.c index 971afa413..760c6953b 100644 --- a/lib/misc/dir.c +++ b/lib/misc/dir.c @@ -286,3 +286,76 @@ lws_dir_rm_rf_cb(const char *dirpath, void *user, struct lws_dir_entry *lde) #endif + +#if defined(LWS_WITH_PLUGINS) + +struct lws_plugins_args { + struct lws_plugin **pplugin; + const char *_class; + const char *filter; + each_plugin_cb_t each; + void *each_user; +}; + +static int +lws_plugins_dir_cb(const char *dirpath, void *user, struct lws_dir_entry *lde) +{ + struct lws_plugins_args *pa = (struct lws_plugins_args *)user; + char path[256]; + + if (strlen(lde->name) < 7) + return 0; + + /* if he's given a filter, only match if name + 3 matches it */ + if (pa->filter && strncmp(lde->name + 3, pa->filter, strlen(pa->filter))) + return 0; + + lws_snprintf(path, sizeof(path) - 1, "%s/%s", dirpath, lde->name); + lwsl_notice(" %s\n", path); + + return !lws_plat_dlopen(pa->pplugin, path, lde->name + 3, pa->_class, + pa->each, pa->each_user); +} + +int +lws_plugins_init(struct lws_plugin **pplugin, const char * const *d, + const char *_class, const char *filter, + each_plugin_cb_t each, void *each_user) +{ + struct lws_plugins_args pa; + + pa.pplugin = pplugin; + pa._class = _class; + pa.each = each; + pa.each_user = each_user; + pa.filter = filter; + + while (d && *d) { + lws_dir(*d, &pa, lws_plugins_dir_cb); + d++; + } + + return 0; +} + +int +lws_plugins_destroy(struct lws_plugin **pplugin, each_plugin_cb_t each, + void *each_user) +{ + struct lws_plugin *p = *pplugin, *p1; + + while (p) { + if (each) + each(p, each_user); + lws_plat_destroy_dl(p); + p1 = p->list; + p->list = NULL; + lws_free(p); + p = p1; + } + + *pplugin = NULL; + + return 0; +} +#endif diff --git a/lib/plat/unix/unix-init.c b/lib/plat/unix/unix-init.c index 0f78e1a0b..1a53a1c92 100644 --- a/lib/plat/unix/unix-init.c +++ b/lib/plat/unix/unix-init.c @@ -80,6 +80,19 @@ lws_sul_plat_unix(lws_sorted_usec_list_t *sul) } #endif +static int +protocol_plugin_cb(struct lws_plugin *pin, void *each_user) +{ + struct lws_context *context = (struct lws_context *)each_user; + const lws_plugin_protocol_t *plpr = + (const lws_plugin_protocol_t *)pin->hdr; + + context->plugin_protocol_count += plpr->count_protocols; + context->plugin_extension_count += plpr->count_extensions; + + return 0; +} + int lws_plat_init(struct lws_context *context, const struct lws_context_creation_info *info) @@ -134,7 +147,9 @@ lws_plat_init(struct lws_context *context, #if defined(LWS_WITH_PLUGINS) if (info->plugin_dirs) - lws_plat_plugins_init(context, info->plugin_dirs); + lws_plugins_init(&context->plugin_list, info->plugin_dirs, + "lws_protocol_plugin", NULL, + protocol_plugin_cb, context); #endif @@ -167,9 +182,9 @@ lws_plat_context_early_destroy(struct lws_context *context) void lws_plat_context_late_destroy(struct lws_context *context) { -#ifdef LWS_WITH_PLUGINS +#if defined(LWS_WITH_PLUGINS) if (context->plugin_list) - lws_plat_plugins_destroy(context); + lws_plugins_destroy(&context->plugin_list, NULL, NULL); #endif #if defined(LWS_WITH_NETWORK) if (context->lws_lookup) diff --git a/lib/plat/unix/unix-plugins.c b/lib/plat/unix/unix-plugins.c index 6875bac16..05fb79382 100644 --- a/lib/plat/unix/unix-plugins.c +++ b/lib/plat/unix/unix-plugins.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2019 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -35,149 +35,75 @@ #endif #include -static int filter(const struct dirent *ent) +const lws_plugin_header_t * +lws_plat_dlopen(struct lws_plugin **pplugin, const char *libpath, + const char *sofilename, const char *_class, + each_plugin_cb_t each, void *each_user) { - if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) - return 0; - - return 1; -} - -int -lws_plat_plugins_init(struct lws_context * context, const char * const *d) -{ - struct lws_plugin_capability lcaps; - struct lws_plugin *plugin; - lws_plugin_init_func initfunc; - struct dirent **namelist; - int n, i, m, ret = 0; - char path[256]; + const lws_plugin_header_t *hdr; + struct lws_plugin *pin; + char sym[96]; void *l; - -#if defined(LWS_WITH_PLUGINS) && (UV_VERSION_MAJOR > 0) - if (lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV)) - return lws_uv_plugins_init(context, d); -#endif - - lwsl_notice(" Plugins:\n"); - - while (d && *d) { - n = scandir(*d, &namelist, filter, alphasort); - if (n < 0) { - lwsl_err("Scandir on %s failed\n", *d); - d++; - continue; - } - - for (i = 0; i < n; i++) { - if (strlen(namelist[i]->d_name) < 7) - goto inval; - - lwsl_notice(" %s\n", namelist[i]->d_name); - - lws_snprintf(path, sizeof(path) - 1, "%s/%s", *d, - namelist[i]->d_name); - l = dlopen(path, RTLD_NOW); - if (!l) { - lwsl_err("Error loading DSO: %s\n", dlerror()); - while (i++ < n) - free(namelist[i]); - goto bail; - } - /* we could open it, can we get his init function? */ - m = lws_snprintf(path, sizeof(path) - 1, "init_%s", - namelist[i]->d_name + 3 /* snip lib... */); - path[m - 3] = '\0'; /* snip the .so */ - initfunc = dlsym(l, path); - if (!initfunc) { - lwsl_err("%s: Failed to get init '%s' on %s: %s\n", - __func__, path, namelist[i]->d_name, dlerror()); - goto skip; - } - lcaps.api_magic = LWS_PLUGIN_API_MAGIC; - m = initfunc(context, &lcaps); - if (m) { - lwsl_err("Initializing %s failed %d\n", - namelist[i]->d_name, m); - goto skip; - } - - plugin = lws_malloc(sizeof(*plugin), "plugin"); - if (!plugin) { - dlclose(l); - lwsl_err("OOM\n"); - goto bail; - } - plugin->list = context->plugin_list; - context->plugin_list = plugin; - lws_strncpy(plugin->name, namelist[i]->d_name, - sizeof(plugin->name)); - plugin->l = l; - plugin->caps = lcaps; - context->plugin_protocol_count += lcaps.count_protocols; - context->plugin_extension_count += lcaps.count_extensions; - - free(namelist[i]); - continue; - - skip: - dlclose(l); - inval: - free(namelist[i]); - } - free(namelist); - d++; - } - - return 0; - -bail: - free(namelist); - - return ret; -} - -int -lws_plat_plugins_destroy(struct lws_context * context) -{ - struct lws_plugin *plugin = context->plugin_list, *p; - lws_plugin_destroy_func func; - char path[256]; int m; -#if defined(LWS_WITH_PLUGINS) && (UV_VERSION_MAJOR > 0) - if (lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV)) - return lws_uv_plugins_destroy(context); -#endif + if (strlen(sofilename) < 6) + /* [lib]...[.so] */ + return NULL; - if (!plugin) - return 0; + l = dlopen(libpath, RTLD_NOW); + if (!l) { + lwsl_err("%s: Error loading DSO: %s\n", __func__, dlerror()); - lwsl_notice("%s\n", __func__); - - while (plugin) { - p = plugin; - m = lws_snprintf(path, sizeof(path) - 1, "destroy_%s", - plugin->name + 3); - path[m - 3] = '\0'; - func = dlsym(plugin->l, path); - if (!func) { - lwsl_err("Failed to get destroy on %s: %s", - plugin->name, dlerror()); - goto next; - } - m = func(context); - if (m) - lwsl_err("Initializing %s failed %d\n", - plugin->name, m); -next: - dlclose(p->l); - plugin = p->list; - p->list = NULL; - free(p); + return NULL; } - context->plugin_list = NULL; + /* we could open it... can we get his export struct? */ + m = lws_snprintf(sym, sizeof(sym) - 1, "%s", sofilename); + if (m < 4) + goto bail; + if (!strcmp(&sym[m - 3], ".so")) + sym[m - 3] = '\0'; /* snip the .so */ - return 0; + hdr = (const lws_plugin_header_t *)dlsym(l, sym); + if (!hdr) { + lwsl_err("%s: Failed to get export '%s' from %s: %s\n", + __func__, sym, libpath, dlerror()); + goto bail; + } + + if (hdr->api_magic != LWS_PLUGIN_API_MAGIC) { + lwsl_err("%s: plugin %s has outdated api %d (vs %d)\n", + __func__, libpath, hdr->api_magic, + LWS_PLUGIN_API_MAGIC); + goto bail; + } + + if (strcmp(hdr->_class, _class)) + goto bail; + + pin = lws_malloc(sizeof(*pin), __func__); + if (!pin) + goto bail; + + pin->list = *pplugin; + *pplugin = pin; + + pin->u.l = l; + pin->hdr = hdr; + + if (each) + each(pin, each_user); + + return hdr; + +bail: + dlclose(l); + + return NULL; +} + +int +lws_plat_destroy_dl(struct lws_plugin *p) +{ + return dlclose(p->u.l); } diff --git a/lib/plat/windows/windows-init.c b/lib/plat/windows/windows-init.c index d6139f499..1f2b39f9f 100644 --- a/lib/plat/windows/windows-init.c +++ b/lib/plat/windows/windows-init.c @@ -55,6 +55,19 @@ lws_plat_context_early_init(void) return 1; } +static int +protocol_plugin_cb(struct lws_plugin *pin, void *each_user) +{ + struct lws_context *context = (struct lws_context *)each_user; + const lws_plugin_protocol_t *plpr = + (const lws_plugin_protocol_t *)pin->hdr; + + context->plugin_protocol_count += plpr->count_protocols; + context->plugin_extension_count += plpr->count_extensions; + + return 0; +} + int lws_plat_init(struct lws_context *context, const struct lws_context_creation_info *info) @@ -81,9 +94,11 @@ lws_plat_init(struct lws_context *context, context->fd_random = 0; -#ifdef LWS_WITH_PLUGINS +#if defined(LWS_WITH_PLUGINS) if (info->plugin_dirs) - lws_plat_plugins_init(context, info->plugin_dirs); + lws_plat_plugins_init(&context->plugin_list, info->plugin_dirs, + "lws_protocol_plugin", + protocol_plugin_cb, context); #endif return 0; @@ -107,6 +122,11 @@ lws_plat_context_late_destroy(struct lws_context *context) { int n; +#ifdef LWS_WITH_PLUGINS + if (context->plugin_list) + lws_plugins_destroy(&context->plugin_list); +#endif + for (n = 0; n < FD_HASHTABLE_MODULUS; n++) { if (context->fd_hashtable[n].wsi) lws_free(context->fd_hashtable[n].wsi); diff --git a/lib/plat/windows/windows-plugins.c b/lib/plat/windows/windows-plugins.c index c30bd83ec..e55f802d3 100644 --- a/lib/plat/windows/windows-plugins.c +++ b/lib/plat/windows/windows-plugins.c @@ -27,12 +27,106 @@ #endif #include "private-lib-core.h" +#if defined(LWS_WITH_PLUGINS) && (UV_VERSION_MAJOR > 0) + +const lws_plugin_header_t * +lws_plat_dlopen(struct lws_plugin **pplugin, const char *libpath, + const char *sofilename, const char *_class, + each_plugin_cb_t each, void *each_user) +{ + const lws_plugin_header_t *hdr; + struct lws_plugin *pin; + char sym[96], *dot; + uv_lib_t lib; + void *v; + int m; + + lib.errmsg = NULL; + lib.handle = NULL; + + if (uv_dlopen(libpath, &lib)) { + uv_dlerror(&lib); + lwsl_err("Error loading DSO: %s\n", lib.errmsg); + uv_dlclose(&lib); + return NULL; + } + + /* we could open it... can we get his export struct? */ + m = lws_snprintf(sym, sizeof(sym) - 1, "%s", sofilename); + if (m < 4) + goto bail; + dot = strchr(sym, '.'); + if (dot) + *dot = '\0'; /* snip the .so or .lib or what-have-you*/ + + if (uv_dlsym(&lib, sym, &v)) { + uv_dlerror(&lib); + lwsl_err("%s: Failed to get '%s' on %s: %s\n", + __func__, path, dent.name, lib.errmsg); + goto bail; + } + + hdr = (const lws_plugin_header_t *)v; + if (hdr->api_magic != LWS_PLUGIN_API_MAGIC) { + lwsl_err("%s: plugin %s has outdated api %d (vs %d)\n", + __func__, libpath, hdr->api_magic, + LWS_PLUGIN_API_MAGIC); + goto bail; + } + + if (strcmp(hdr->_class, _class)) + goto bail; + + pin = lws_malloc(sizeof(*pin), __func__); + if (!pin) + goto bail; + + pin->list = *pplugin; + *pplugin = pin; + + pin->u.lib = lib; + pin->hdr = hdr; + + if (each) + each(pin, each_user); + + return hdr; + +bail: + uv_dlclose(&lib); + + return NULL; +} + int -lws_plat_plugins_init(struct lws_context * context, const char * const *d) +lws_plat_destroy_dl(struct lws_plugin *p) +{ + return uv_dlclose(&p->u.lib); +} + +static int +protocol_plugin_cb(struct lws_plugin *pin, void *each_user) +{ + struct lws_context *context = (struct lws_context *)each_user; + const lws_plugin_protocol_t *plpr = + (const lws_plugin_protocol_t *)pin->hdr; + + context->plugin_protocol_count += plpr->count_protocols; + context->plugin_extension_count += plpr->count_extensions; + + return 0; +} + +int +lws_plat_plugins_init(struct lws_context *context, const char * const *d) { #if defined(LWS_WITH_PLUGINS) && (UV_VERSION_MAJOR > 0) - if (lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV)) - return lws_uv_plugins_init(context, d); + if (info->plugin_dirs) { + uv_loop_init(&context->uv.loop); + lws_plugins_init(&context->plugin_list, info->plugin_dirs, + "lws_protocol_plugin", NULL, + protocol_plugin_cb, context); + } #endif return 0; @@ -42,8 +136,12 @@ int lws_plat_plugins_destroy(struct lws_context * context) { #if defined(LWS_WITH_PLUGINS) && (UV_VERSION_MAJOR > 0) - if (lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV)) - return lws_uv_plugins_destroy(context); + if (lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV) && + context->plugin_list) { + lws_plugins_destroy(&context->plugin_list, NULL, NULL); + while (uv_loop_close(&context->uv.loop)) + ; + } #endif return 0; diff --git a/lib/roles/ws/ops-ws.c b/lib/roles/ws/ops-ws.c index 17882edc7..d81e285d7 100644 --- a/lib/roles/ws/ops-ws.c +++ b/lib/roles/ws/ops-ws.c @@ -1967,11 +1967,14 @@ rops_init_vhost_ws(struct lws_vhost *vh, sizeof(struct lws_extension) * m); plugin = vh->context->plugin_list; while (plugin) { + const lws_plugin_protocol_t *plpr = + (const lws_plugin_protocol_t *)plugin->hdr; + memcpy((struct lws_extension *)&vh->ws.extensions[m], - plugin->caps.extensions, + plpr->extensions, sizeof(struct lws_extension) * - plugin->caps.count_extensions); - m += plugin->caps.count_extensions; + plpr->count_extensions); + m += plpr->count_extensions; plugin = plugin->list; } } else diff --git a/minimal-examples/client-server/minimal-ws-proxy/protocol_lws_minimal.c b/minimal-examples/client-server/minimal-ws-proxy/protocol_lws_minimal.c index 10e525c3f..428a27d71 100644 --- a/minimal-examples/client-server/minimal-ws-proxy/protocol_lws_minimal.c +++ b/minimal-examples/client-server/minimal-ws-proxy/protocol_lws_minimal.c @@ -238,37 +238,3 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, 128, \ 0, NULL, 0 \ } - - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff --git a/minimal-examples/dbus-server/minimal-dbus-ws-proxy/protocol_lws_minimal_dbus_ws_proxy.c b/minimal-examples/dbus-server/minimal-dbus-ws-proxy/protocol_lws_minimal_dbus_ws_proxy.c index e3e01c3db..e621c8e2a 100644 --- a/minimal-examples/dbus-server/minimal-dbus-ws-proxy/protocol_lws_minimal_dbus_ws_proxy.c +++ b/minimal-examples/dbus-server/minimal-dbus-ws-proxy/protocol_lws_minimal_dbus_ws_proxy.c @@ -793,36 +793,3 @@ callback_minimal_dbus_wsproxy(struct lws *wsi, enum lws_callback_reasons reason, 1024, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL_DBUS_WSPROXY -}; - -int -init_protocol_minimal_dbus_wsproxy(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -int -destroy_protocol_minimal_dbus_wsproxy(struct lws_context *context) -{ - return 0; -} -#endif diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server-generic-sessions/CMakeLists.txt deleted file mode 100644 index 6a24a7be8..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -project(lws-minimal-http-server-generic-sessions C) -cmake_minimum_required(VERSION 2.8) -find_package(libwebsockets CONFIG REQUIRED) -list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) -include(CheckCSourceCompiles) -include(LwsCheckRequirements) - -set(SAMP lws-minimal-http-server-generic-sessions) -set(SRCS minimal-http-server-generic-sessions.c) - -set(requirements 1) -require_lws_config(LWS_ROLE_H1 1 requirements) -require_lws_config(LWS_WITH_SERVER 1 requirements) -require_lws_config(LWS_WITH_TLS 1 requirements) -require_lws_config(LWS_WITH_GENERIC_SESSIONS 1 requirements) -require_lws_config(LWS_WITH_LIBUV 1 requirements) -require_lws_config(LWS_WITH_PLUGINS 1 requirements) - -if (requirements) - add_executable(${SAMP} ${SRCS}) - - if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) - add_dependencies(${SAMP} websockets_shared) - else() - target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) - endif() -endif() diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/README.md b/minimal-examples/http-server/minimal-http-server-generic-sessions/README.md deleted file mode 100644 index 976aea686..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/README.md +++ /dev/null @@ -1,26 +0,0 @@ -# lws minimal http server with generic-sessions - -## build - -``` - $ cmake . && make -``` - -## usage - -``` - $ ./lws-minimal-http-server-tls -[2018/03/20 13:23:13:0131] USER: LWS minimal http server TLS | visit https://localhost:7681 -[2018/03/20 13:23:13:0142] NOTICE: Creating Vhost 'default' port 7681, 1 protocols, IPv6 off -[2018/03/20 13:23:13:0142] NOTICE: Using SSL mode -[2018/03/20 13:23:13:0146] NOTICE: SSL ECDH curve 'prime256v1' -[2018/03/20 13:23:13:0146] NOTICE: HTTP2 / ALPN enabled -[2018/03/20 13:23:13:0195] NOTICE: lws_tls_client_create_vhost_context: doing cert filepath localhost-100y.cert -[2018/03/20 13:23:13:0195] NOTICE: Loaded client cert localhost-100y.cert -[2018/03/20 13:23:13:0195] NOTICE: lws_tls_client_create_vhost_context: doing private key filepath -[2018/03/20 13:23:13:0196] NOTICE: Loaded client cert private key localhost-100y.key -[2018/03/20 13:23:13:0196] NOTICE: created client ssl context for default -[2018/03/20 13:23:14:0207] NOTICE: vhost default: cert expiry: 730459d -``` - - diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/localhost-100y.cert b/minimal-examples/http-server/minimal-http-server-generic-sessions/localhost-100y.cert deleted file mode 100644 index 6f372db40..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/localhost-100y.cert +++ /dev/null @@ -1,34 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIF5jCCA86gAwIBAgIJANq50IuwPFKgMA0GCSqGSIb3DQEBCwUAMIGGMQswCQYD -VQQGEwJHQjEQMA4GA1UECAwHRXJld2hvbjETMBEGA1UEBwwKQWxsIGFyb3VuZDEb -MBkGA1UECgwSbGlid2Vic29ja2V0cy10ZXN0MRIwEAYDVQQDDAlsb2NhbGhvc3Qx -HzAdBgkqhkiG9w0BCQEWEG5vbmVAaW52YWxpZC5vcmcwIBcNMTgwMzIwMDQxNjA3 -WhgPMjExODAyMjQwNDE2MDdaMIGGMQswCQYDVQQGEwJHQjEQMA4GA1UECAwHRXJl -d2hvbjETMBEGA1UEBwwKQWxsIGFyb3VuZDEbMBkGA1UECgwSbGlid2Vic29ja2V0 -cy10ZXN0MRIwEAYDVQQDDAlsb2NhbGhvc3QxHzAdBgkqhkiG9w0BCQEWEG5vbmVA -aW52YWxpZC5vcmcwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCjYtuW -aICCY0tJPubxpIgIL+WWmz/fmK8IQr11Wtee6/IUyUlo5I602mq1qcLhT/kmpoR8 -Di3DAmHKnSWdPWtn1BtXLErLlUiHgZDrZWInmEBjKM1DZf+CvNGZ+EzPgBv5nTek -LWcfI5ZZtoGuIP1Dl/IkNDw8zFz4cpiMe/BFGemyxdHhLrKHSm8Eo+nT734tItnH -KT/m6DSU0xlZ13d6ehLRm7/+Nx47M3XMTRH5qKP/7TTE2s0U6+M0tsGI2zpRi+m6 -jzhNyMBTJ1u58qAe3ZW5/+YAiuZYAB6n5bhUp4oFuB5wYbcBywVR8ujInpF8buWQ -Ujy5N8pSNp7szdYsnLJpvAd0sibrNPjC0FQCNrpNjgJmIK3+mKk4kXX7ZTwefoAz -TK4l2pHNuC53QVc/EF++GBLAxmvCDq9ZpMIYi7OmzkkAKKC9Ue6Ef217LFQCFIBK -Izv9cgi9fwPMLhrKleoVRNsecBsCP569WgJXhUnwf2lon4fEZr3+vRuc9shfqnV0 -nPN1IMSnzXCast7I2fiuRXdIz96KjlGQpP4XfNVA+RGL7aMnWOFIaVrKWLzAtgzo -GMTvP/AuehKXncBJhYtW0ltTioVx+5yTYSAZWl+IssmXjefxJqYi2/7QWmv1QC9p -sNcjTMaBQLN03T1Qelbs7Y27sxdEnNUth4kI+wIDAQABo1MwUTAdBgNVHQ4EFgQU -9mYU23tW2zsomkKTAXarjr2vjuswHwYDVR0jBBgwFoAU9mYU23tW2zsomkKTAXar -jr2vjuswDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAgEANjIBMrow -YNCbhAJdP7dhlhT2RUFRdeRUJD0IxrH/hkvb6myHHnK8nOYezFPjUlmRKUgNEDuA -xbnXZzPdCRNV9V2mShbXvCyiDY7WCQE2Bn44z26O0uWVk+7DNNLH9BnkwUtOnM9P -wtmD9phWexm4q2GnTsiL6Ul6cy0QlTJWKVLEUQQ6yda582e23J1AXqtqFcpfoE34 -H3afEiGy882b+ZBiwkeV+oq6XVF8sFyr9zYrv9CvWTYlkpTQfLTZSsgPdEHYVcjv -xQ2D+XyDR0aRLRlvxUa9dHGFHLICG34Juq5Ai6lM1EsoD8HSsJpMcmrH7MWw2cKk -ujC3rMdFTtte83wF1uuF4FjUC72+SmcQN7A386BC/nk2TTsJawTDzqwOu/VdZv2g -1WpTHlumlClZeP+G/jkSyDwqNnTu1aodDmUa4xZodfhP1HWPwUKFcq8oQr148QYA -AOlbUOJQU7QwRWd1VbnwhDtQWXC92A2w1n/xkZSR1BM/NUSDhkBSUU1WjMbWg6Gg -mnIZLRerQCu1Oozr87rOQqQakPkyt8BUSNK3K42j2qcfhAONdRl8Hq8Qs5pupy+s -8sdCGDlwR3JNCMv6u48OK87F4mcIxhkSefFJUFII25pCGN5WtE4p5l+9cnO1GrIX -e2Hl/7M0c/lbZ4FvXgARlex2rkgS0Ka06HE= ------END CERTIFICATE----- diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/localhost-100y.key b/minimal-examples/http-server/minimal-http-server-generic-sessions/localhost-100y.key deleted file mode 100644 index 148f8598e..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/localhost-100y.key +++ /dev/null @@ -1,52 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQCjYtuWaICCY0tJ -PubxpIgIL+WWmz/fmK8IQr11Wtee6/IUyUlo5I602mq1qcLhT/kmpoR8Di3DAmHK -nSWdPWtn1BtXLErLlUiHgZDrZWInmEBjKM1DZf+CvNGZ+EzPgBv5nTekLWcfI5ZZ -toGuIP1Dl/IkNDw8zFz4cpiMe/BFGemyxdHhLrKHSm8Eo+nT734tItnHKT/m6DSU -0xlZ13d6ehLRm7/+Nx47M3XMTRH5qKP/7TTE2s0U6+M0tsGI2zpRi+m6jzhNyMBT -J1u58qAe3ZW5/+YAiuZYAB6n5bhUp4oFuB5wYbcBywVR8ujInpF8buWQUjy5N8pS -Np7szdYsnLJpvAd0sibrNPjC0FQCNrpNjgJmIK3+mKk4kXX7ZTwefoAzTK4l2pHN -uC53QVc/EF++GBLAxmvCDq9ZpMIYi7OmzkkAKKC9Ue6Ef217LFQCFIBKIzv9cgi9 -fwPMLhrKleoVRNsecBsCP569WgJXhUnwf2lon4fEZr3+vRuc9shfqnV0nPN1IMSn -zXCast7I2fiuRXdIz96KjlGQpP4XfNVA+RGL7aMnWOFIaVrKWLzAtgzoGMTvP/Au -ehKXncBJhYtW0ltTioVx+5yTYSAZWl+IssmXjefxJqYi2/7QWmv1QC9psNcjTMaB -QLN03T1Qelbs7Y27sxdEnNUth4kI+wIDAQABAoICAFWe8MQZb37k2gdAV3Y6aq8f -qokKQqbCNLd3giGFwYkezHXoJfg6Di7oZxNcKyw35LFEghkgtQqErQqo35VPIoH+ -vXUpWOjnCmM4muFA9/cX6mYMc8TmJsg0ewLdBCOZVw+wPABlaqz+0UOiSMMftpk9 -fz9JwGd8ERyBsT+tk3Qi6D0vPZVsC1KqxxL/cwIFd3Hf2ZBtJXe0KBn1pktWht5A -Kqx9mld2Ovl7NjgiC1Fx9r+fZw/iOabFFwQA4dr+R8mEMK/7bd4VXfQ1o/QGGbMT -G+ulFrsiDyP+rBIAaGC0i7gDjLAIBQeDhP409ZhswIEc/GBtODU372a2CQK/u4Q/ -HBQvuBtKFNkGUooLgCCbFxzgNUGc83GB/6IwbEM7R5uXqsFiE71LpmroDyjKTlQ8 -YZkpIcLNVLw0usoGYHFm2rvCyEVlfsE3Ub8cFyTFk50SeOcF2QL2xzKmmbZEpXgl -xBHR0hjgon0IKJDGfor4bHO7Nt+1Ece8u2oTEKvpz5aIn44OeC5mApRGy83/0bvs -esnWjDE/bGpoT8qFuy+0urDEPNId44XcJm1IRIlG56ErxC3l0s11wrIpTmXXckqw -zFR9s2z7f0zjeyxqZg4NTPI7wkM3M8BXlvp2GTBIeoxrWB4V3YArwu8QF80QBgVz -mgHl24nTg00UH1OjZsABAoIBAQDOxftSDbSqGytcWqPYP3SZHAWDA0O4ACEM+eCw -au9ASutl0IDlNDMJ8nC2ph25BMe5hHDWp2cGQJog7pZ/3qQogQho2gUniKDifN77 -40QdykllTzTVROqmP8+efreIvqlzHmuqaGfGs5oTkZaWj5su+B+bT+9rIwZcwfs5 -YRINhQRx17qa++xh5mfE25c+M9fiIBTiNSo4lTxWMBShnK8xrGaMEmN7W0qTMbFH -PgQz5FcxRjCCqwHilwNBeLDTp/ZECEB7y34khVh531mBE2mNzSVIQcGZP1I/DvXj -W7UUNdgFwii/GW+6M0uUDy23UVQpbFzcV8o1C2nZc4Fb4zwBAoIBAQDKSJkFwwuR -naVJS6WxOKjX8MCu9/cKPnwBv2mmI2jgGxHTw5sr3ahmF5eTb8Zo19BowytN+tr6 -2ZFoIBA9Ubc9esEAU8l3fggdfM82cuR9sGcfQVoCh8tMg6BP8IBLOmbSUhN3PG2m -39I802u0fFNVQCJKhx1m1MFFLOu7lVcDS9JN+oYVPb6MDfBLm5jOiPuYkFZ4gH79 -J7gXI0/YKhaJ7yXthYVkdrSF6Eooer4RZgma62Dd1VNzSq3JBo6rYjF7Lvd+RwDC -R1thHrmf/IXplxpNVkoMVxtzbrrbgnC25QmvRYc0rlS/kvM4yQhMH3eA7IycDZMp -Y+0xm7I7jTT7AoIBAGKzKIMDXdCxBWKhNYJ8z7hiItNl1IZZMW2TPUiY0rl6yaCh -BVXjM9W0r07QPnHZsUiByqb743adkbTUjmxdJzjaVtxN7ZXwZvOVrY7I7fPWYnCE -fXCr4+IVpZI/ZHZWpGX6CGSgT6EOjCZ5IUufIvEpqVSmtF8MqfXO9o9uIYLokrWQ -x1dBl5UnuTLDqw8bChq7O5y6yfuWaOWvL7nxI8NvSsfj4y635gIa/0dFeBYZEfHI -UlGdNVomwXwYEzgE/c19ruIowX7HU/NgxMWTMZhpazlxgesXybel+YNcfDQ4e3RM -OMz3ZFiaMaJsGGNf4++d9TmMgk4Ns6oDs6Tb9AECggEBAJYzd+SOYo26iBu3nw3L -65uEeh6xou8pXH0Tu4gQrPQTRZZ/nT3iNgOwqu1gRuxcq7TOjt41UdqIKO8vN7/A -aJavCpaKoIMowy/aGCbvAvjNPpU3unU8jdl/t08EXs79S5IKPcgAx87sTTi7KDN5 -SYt4tr2uPEe53NTXuSatilG5QCyExIELOuzWAMKzg7CAiIlNS9foWeLyVkBgCQ6S -me/L8ta+mUDy37K6vC34jh9vK9yrwF6X44ItRoOJafCaVfGI+175q/eWcqTX4q+I -G4tKls4sL4mgOJLq+ra50aYMxbcuommctPMXU6CrrYyQpPTHMNVDQy2ttFdsq9iK -TncCggEBAMmt/8yvPflS+xv3kg/ZBvR9JB1In2n3rUCYYD47ReKFqJ03Vmq5C9nY -56s9w7OUO8perBXlJYmKZQhO4293lvxZD2Iq4NcZbVSCMoHAUzhzY3brdgtSIxa2 -gGveGAezZ38qKIU26dkz7deECY4vrsRkwhpTW0LGVCpjcQoaKvymAoCmAs8V2oMr -Ziw1YQ9uOUoWwOqm1wZqmVcOXvPIS2gWAs3fQlWjH9hkcQTMsUaXQDOD0aqkSY3E -NqOvbCV1/oUpRi3076khCoAXI1bKSn/AvR3KDP14B5toHI/F5OTSEiGhhHesgRrs -fBrpEY1IATtPq1taBZZogRqI3rOkkPk= ------END PRIVATE KEY----- diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/minimal-http-server-generic-sessions.c b/minimal-examples/http-server/minimal-http-server-generic-sessions/minimal-http-server-generic-sessions.c deleted file mode 100644 index f4e11e645..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/minimal-http-server-generic-sessions.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - * lws-minimal-http-server-generic-sessions - * - * Copyright (C) 2019 Andy Green - * - * This file is made available under the Creative Commons CC0 1.0 - * Universal Public Domain Dedication. - * - * This demonstrates setting up and using generic sessions - */ - -#include -#include -#include - -static int interrupted; -struct lws_context *context; - -static const struct lws_protocol_vhost_options - pvo_mm1 = { - NULL, NULL, "message-db", (void *)"/var/www/sessions/messageboard.sqlite3" -}, pvo_m1 = { - NULL, &pvo_mm1, "protocol-lws-messageboard", "" -}, - - pvo13 = { - NULL, NULL, "email-confirm-url-base", (void *)"https://localhost:7681/" -}, pvo12 = { - &pvo13, NULL, "urlroot", (void *)"https://127.0.0.1:7681/" -}, pvo11 = { - &pvo12, NULL, "email-contact-person", (void *)"andy@warmcat.com" -}, pvo10 = { - &pvo11, NULL, "email-helo", (void *)"warmcat.com" -}, pvo9 = { - &pvo10, NULL, "email-expire", (void *)"3600" -}, pvo8 = { - &pvo9, NULL, "email-smtp-ip", (void *)"127.0.0.1" -}, pvo7 = { - &pvo8, NULL, "email-from", (void *)"noreply@warmcat.com" -}, pvo6 = { - &pvo7, NULL, "confounder", (void *)"some kind of secret confounder" -}, pvo5 = { - &pvo6, NULL, "timeout-anon-idle-secs", (void *)"1200" -}, pvo4 = { - &pvo5, NULL, "timeout-idle-secs", (void *)"6000" -}, pvo3 = { - &pvo4, NULL, "session-db", (void *)"/var/www/sessions/lws.sqlite3" -}, pvo2 = { - &pvo3, NULL, "admin-password-sha256", - (void *)"25d08521d996bad92605f5a40fe71179dc968e70f669cb1db6190dcd53258200" /* pvo value */ -}, pvo1 = { - &pvo2, NULL, "admin-user", (void *)"admin" -}, pvo = { - &pvo_m1, &pvo1, "protocol-generic-sessions", "" -}, - - interpret1 = { - NULL, NULL, ".js", "protocol-lws-messageboard" -}, - - pvo_hsbph[] = {{ - NULL, NULL, "referrer-policy:", "no-referrer" -}, { - &pvo_hsbph[0], NULL, "x-xss-protection:", "1; mode=block" -}, { - &pvo_hsbph[1], NULL, "x-content-type-options:", "nosniff" -}, { - &pvo_hsbph[2], NULL, "content-security-policy:", - "default-src 'self'; " - "img-src https://www.gravatar.com 'self' data: ; " - "script-src 'self'; " - "font-src 'self'; " - "style-src 'self'; " - "connect-src 'self'; " - "frame-ancestors 'self'; " - "base-uri 'none'; " - "form-action 'self';" -}}; - - static const struct lws_http_mount mount2 = { - /* .mount_next */ NULL, /* linked-list "next" */ - /* .mountpoint */ "/needadmin", /* mountpoint URL */ - /* .origin */ "./mount-origin/needadmin", /* serve from dir */ - /* .def */ "index.html", /* default filename */ - /* .protocol */ "protocol-lws-messageboard", - /* .cgienv */ NULL, - /* .extra_mimetypes */ NULL, - /* .interpret */ &interpret1, - /* .cgi_timeout */ 0, - /* .cache_max_age */ 0, - /* .auth_mask */ 7, - /* .cache_reusable */ 0, - /* .cache_revalidate */ 0, - /* .cache_intermediaries */ 0, - /* .origin_protocol */ LWSMPRO_FILE, /* files in a dir */ - /* .mountpoint_len */ 1, /* char count */ - /* .basic_auth_login_file */ NULL, - }; - - static const struct lws_http_mount mount1 = { - /* .mount_next */ &mount2, /* linked-list "next" */ - /* .mountpoint */ "/needauth", /* mountpoint URL */ - /* .origin */ "./mount-origin/needauth", /* serve from dir */ - /* .def */ "index.html", /* default filename */ - /* .protocol */ "protocol-lws-messageboard", - /* .cgienv */ NULL, - /* .extra_mimetypes */ NULL, - /* .interpret */ &interpret1, - /* .cgi_timeout */ 0, - /* .cache_max_age */ 0, - /* .auth_mask */ 5, - /* .cache_reusable */ 0, - /* .cache_revalidate */ 0, - /* .cache_intermediaries */ 0, - /* .origin_protocol */ LWSMPRO_FILE, /* files in a dir */ - /* .mountpoint_len */ 1, /* char count */ - /* .basic_auth_login_file */ NULL, - }; - -static const struct lws_http_mount mount = { - /* .mount_next */ &mount1, /* linked-list "next" */ - /* .mountpoint */ "/", /* mountpoint URL */ - /* .origin */ "./mount-origin", /* serve from dir */ - /* .def */ "index.html", /* default filename */ - /* .protocol */ "protocol-lws-messageboard", - /* .cgienv */ NULL, - /* .extra_mimetypes */ NULL, - /* .interpret */ &interpret1, - /* .cgi_timeout */ 0, - /* .cache_max_age */ 0, - /* .auth_mask */ 0, - /* .cache_reusable */ 0, - /* .cache_revalidate */ 0, - /* .cache_intermediaries */ 0, - /* .origin_protocol */ LWSMPRO_FILE, /* files in a dir */ - /* .mountpoint_len */ 1, /* char count */ - /* .basic_auth_login_file */ NULL, -}; - -void sigint_handler(int sig) -{ - lws_context_destroy(context); - - interrupted = 1; -} - -int main(int argc, const char **argv) -{ - struct lws_context_creation_info info; - const char *p, *plugin_dirs[] = { - "/usr/local/share/libwebsockets-test-server/plugins", - NULL }; - int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE - /* for LLL_ verbosity above NOTICE to be built into lws, - * lws must have been configured and built with - * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ - /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ - /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ - /* | LLL_DEBUG */; - - if ((p = lws_cmdline_option(argc, argv, "-d"))) - logs = atoi(p); - - lws_set_log_level(logs, NULL); - lwsl_user("LWS minimal http server TLS | visit https://localhost:7681\n"); - - signal(SIGINT, sigint_handler); - - memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ - info.port = 7681; - info.mounts = &mount; - info.error_document_404 = "/404.html"; - info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | - LWS_SERVER_OPTION_EXPLICIT_VHOSTS; - info.ssl_cert_filepath = "localhost-100y.cert"; - info.ssl_private_key_filepath = "localhost-100y.key"; - info.plugin_dirs = plugin_dirs; - info.pvo = &pvo; - - if (lws_cmdline_option(argc, argv, "-h")) - info.options |= LWS_SERVER_OPTION_VHOST_UPG_STRICT_HOST_CHECK; - - context = lws_create_context(&info); - if (!context) { - lwsl_err("lws init failed\n"); - return 1; - } - - info.headers = &pvo_hsbph[3]; - - if (!lws_create_vhost(context, &info)) { - lwsl_err("lws init failed\n"); - return 1; - } - - while (n >= 0 && !interrupted) - n = lws_service(context, 0); - - lws_context_destroy(context); - - return 0; -} diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/404.html deleted file mode 100644 index 6fdd6bf33..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/404.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - -
- -

404

- Sorry, that file doesn't exist. - - - diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/admin-login.html b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/admin-login.html deleted file mode 100644 index 113df9cd3..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/admin-login.html +++ /dev/null @@ -1,5 +0,0 @@ - -This is an example destination that will appear after successful Admin login. - -This URL cannot be served if you're not logged in as admin. - diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/example.js b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/example.js deleted file mode 100644 index 1bde61e46..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/example.js +++ /dev/null @@ -1,21 +0,0 @@ -document.addEventListener("DOMContentLoaded", function() { - - var transport_protocol = ""; - - if ( performance && performance.timing.nextHopProtocol ) { - transport_protocol = performance.timing.nextHopProtocol; - } else if ( window.chrome && window.chrome.loadTimes ) { - transport_protocol = window.chrome.loadTimes().connectionInfo; - } else { - - var p = performance.getEntriesByType("resource"); - for (var i=0; i < p.length; i++) { - var value = "nextHopProtocol" in p[i]; - if (value) - transport_protocol = p[i].nextHopProtocol; - } - } - - if (transport_protocol === "h2") - document.getElementById("transport").innerHTML = ""; -}, false); \ No newline at end of file diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/failed-login.html b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/failed-login.html deleted file mode 100644 index 9ab065b53..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/failed-login.html +++ /dev/null @@ -1,3 +0,0 @@ - -This is an example destination that will appear after a failed login - diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/favicon.ico b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/favicon.ico deleted file mode 100644 index c0cc2e3df..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/favicon.ico and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/http2.png b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/http2.png deleted file mode 100644 index 439bfa482..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/http2.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/index.html deleted file mode 100644 index 0695d5d3a..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/index.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - - - - -
-
-
- -
- - This is a demo application for lws generic-sessions.

- It's a simple messageboard.

- What's interesting about it is there is no serverside scripting,
- instead client js makes a wss:// connection back to the server
- and then reacts to JSON from the ws protocol. Sessions stuff is
- handled by lws generic sessions, making the actual
- test application
very small.

- And because it's natively websocket, it's naturally connected
- for dynamic events and easy to maintain. -

- Register / Login at the top right to see and create new messages. -
- -
- - New message
-
- - -
-
-
- -
- -
-
- - - diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/libwebsockets.org-logo.svg b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/libwebsockets.org-logo.svg deleted file mode 100644 index ef241b37c..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/libwebsockets.org-logo.svg +++ /dev/null @@ -1,66 +0,0 @@ - - - - - -image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lws-common.js b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lws-common.js deleted file mode 100644 index 096909f6f..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lws-common.js +++ /dev/null @@ -1,125 +0,0 @@ -/* - * This section around grayOut came from here: - * http://www.codingforums.com/archive/index.php/t-151720.html - * Assumed public domain - * - * Init like this in your main html script, this also reapplies the gray - * - * lws_gray_out(true,{'zindex':'499'}); - * - * To remove the gray - * - * lws_gray_out(false); - * - */ - -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; - - 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"); - - 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"; - tbody.appendChild(tnode); - dark = document.getElementById("darkenScreenObject"); - } - if (vis) { - dark.style.opacity = opaque; - dark.style.MozOpacity = opaque; - // dark.style.filter ='alpha(opacity='+opacity+')'; - dark.style.zIndex = zindex; - dark.style.backgroundColor = bgcolor; - dark.style.width = gsize(1); - dark.style.height = gsize(0); - dark.style.display = "block"; - addEvent(window, "resize", - function() { - dark.style.height = gsize(0); - dark.style.width = gsize(1); - } - ); - } else { - dark.style.display = "none"; - removeEvent(window, "resize", - function() { - dark.style.height = gsize(0); - dark.style.width = gsize(1); - } - ); - } -} - -/* - * end of grayOut related stuff - */ - -function new_ws(urlpath, protocol) -{ - return new WebSocket(urlpath, protocol); -} - -function lws_san(s) -{ - if (s.search("<") !== -1) - return "invalid string"; - - return s; -} diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs-logo.png b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs-logo.png deleted file mode 100644 index 723a12443..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs-logo.png and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs.css b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs.css deleted file mode 100644 index 907851f0e..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs.css +++ /dev/null @@ -1,144 +0,0 @@ -.body { font-size: 12px } -.gstitle { font-size: 18px } - -.group1 { - vertical-align:middle; - text-align:center; - background:#f0f0e0; - padding:12px; - border-radius:10px; -} -.group2 { - display:block; - vertical-align:middle; - font-size: 22px; - text-align:center; - margin:auto; - align:center; - background-color: rgba(255, 255, 255, 0.8); - padding:12px; - border-radius:10px; -} - -body { - background-color: rgba(205, 205, 205, 1); -} - -div.lwsgs { - z-index: 3; - text-align:right; - background-color: rgba(255, 255, 255, 0.8); -} - -table.lwsgs { - width:100%; - height:100%; - transition: max-height 2s; -} -table.c100 { - text-align:center; - width:100%; -} - -table.r { - vertical-align:top; - text-align:right; -} - -table.l { - vertical-align:top; - text-align:left; -} - -table.fixed { - table-layout: fixed; -} - -td.logo { - vertical-align:top; - text-align:left; - width:200px -} - -td.rlogo { - vertical-align:top; - text-align:right -} - -td.lwsgs { - vertical-align:top; - float:right; -} - -td.h99 { - height:99%; - vertical-align:middle; -} - -td.c { - margin:auto; - align:center -} - -td.tac { - text-align:center -} - -td.ava { - display:inline-block; - vertical-align:top; - word-wrap:break-word; -} - -iframe.hidden { - display:none; -} - -div.hidden { - display:none; -} - -div.hiddenr { - display:none; - text-align:right; -} - -input { - margin: 2px; - padding: 2px; -} - -input.em { - margin: 4px; - font-weight:bold; -} - -input.wide { - margin: 6px; - padding: 6px; -} - -input.hidden { - display: none; -} - -form.r { - text-align:right; -} - -span.bad { - color: red; -} - -span.small { - font-size:8pt; -} - -img.av { - width: 64px; - height: 64px; -} - -.green { - color: green; -} diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs.js b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs.js deleted file mode 100644 index e1204ccc4..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs.js +++ /dev/null @@ -1,634 +0,0 @@ - - -var lwsgs_user = "$lwsgs_user"; -var lwsgs_auth = "$lwsgs_auth"; -var lwsgs_email = "$lwsgs_email"; - -var lwsgs_html = '\ - \ -\ -
\ -
\ - \ - \ - \ - \ -
\ - \ -
\ - \ -
\ -\ - \ - \ - \ - \ - \ -'; - -/*-- this came from - -- https://raw.githubusercontent.com/blueimp/JavaScript-MD5/master/js/md5.min.js - -- under MIT license */ -!function(n){"use strict";function t(n,t){var r=(65535&n)+(65535&t),e=(n>>16)+(t>>16)+(r>>16);return e<<16|65535&r}function r(n,t){return n<>>32-t}function e(n,e,o,u,c,f){return t(r(t(t(e,n),t(u,f)),c),o)}function o(n,t,r,o,u,c,f){return e(t&r|~t&o,n,t,u,c,f)}function u(n,t,r,o,u,c,f){return e(t&o|r&~o,n,t,u,c,f)}function c(n,t,r,o,u,c,f){return e(t^r^o,n,t,u,c,f)}function f(n,t,r,o,u,c,f){return e(r^(t|~o),n,t,u,c,f)}function i(n,r){n[r>>5]|=128<>>9<<4)+14]=r;var e,i,a,h,d,l=1732584193,g=-271733879,v=-1732584194,m=271733878;for(e=0;e>5]>>>t%32&255);return r}function h(n){var t,r=[];for(r[(n.length>>2)-1]=void 0,t=0;t>5]|=(255&n.charCodeAt(t/8))<16&&(o=i(o,8*n.length)),r=0;16>r;r+=1)u[r]=909522486^o[r],c[r]=1549556828^o[r];return e=i(u.concat(h(t)),512+8*t.length),a(i(c.concat(e),640))}function g(n){var t,r,e="0123456789abcdef",o="";for(r=0;r>>4&15)+e.charAt(15&t);return o}function v(n){return unescape(encodeURIComponent(n))}function m(n){return d(v(n))}function p(n){return g(m(n))}function s(n,t){return l(v(n),v(t))}function C(n,t){return g(s(n,t))}function A(n,t,r){return t?r?s(t,n):C(t,n):r?m(n):p(n)}"function"==typeof define&&define.amd?define(function(){return A}):"object"==typeof module&&module.exports?module.exports=A:n.md5=A}(this); - -if (lwsgs_user.substring(0, 1) == "$") { - alert("lwsgs.js: lws generic sessions misconfigured and not providing vars"); -} -function lwsgs_san(s) -{ - if (s.search("<") != -1) - return "invalid string"; - - return s; -} - -function lwsgs_update() -{ - var en_login = 1, en_forgot = 1; - - if (document.getElementById('password').value.length && - document.getElementById('password').value.length < 8) - en_login = 0; - - if (!document.getElementById('username').value || - !document.getElementById('password').value) - en_login = 0; - - if (!document.getElementById('username').value || - document.getElementById('password').value) - en_forgot = 0; - - document.getElementById('login').disabled = !en_login; - document.getElementById('forgot').disabled = !en_forgot; - - if (lwsgs_user) - document.getElementById("curuser").innerHTML = lwsgs_san(lwsgs_user); - - if (lwsgs_user === "") - document.getElementById("dlogin").style.display = "inline"; - else - document.getElementById("dlogout").style.display = "inline"; - } - -function lwsgs_open_registration() -{ - document.getElementById("dadmin").style.display = "none"; - document.getElementById("dlogin").style.display = "none"; - document.getElementById("dlogout").style.display = "none"; - document.getElementById("dchange").style.display = "none"; - document.getElementById("dregister").style.display = "inline"; -} - -function lwsgs_cancel_registration() -{ - document.getElementById("dadmin").style.display = "none"; - document.getElementById("dregister").style.display = "none"; - document.getElementById("dchange").style.display = "none"; - - if (lwsgs_user === "") - document.getElementById("dlogin").style.display = "inline"; - else - document.getElementById("dlogout").style.display = "inline"; -} - -function lwsgs_select_change() -{ - document.getElementById("dlogin").style.display = "none"; - document.getElementById("dlogout").style.display = "none"; - document.getElementById("dregister").style.display = "none"; - if (lwsgs_auth & 2) { - document.getElementById("dadmin").style.display = "inline"; - document.getElementById("dchange").style.display = "none"; - } else { - document.getElementById("dadmin").style.display = "none"; - document.getElementById("dchange").style.display = "inline"; - } - - event.preventDefault() -} - -var lwsgs_user_check = '0'; -var lwsgs_email_check = '0'; - -function lwsgs_rupdate() -{ - var en_register = 1, en_forgot = 0, op; - - if (document.getElementById('rpassword').value == - document.getElementById('password2').value) { - if (document.getElementById('rpassword').value.length) - document.getElementById('match').innerHTML = - "\u2713"; - else - document.getElementById('match').innerHTML = ""; - document.getElementById('pw2').style = ""; - } else { - if (document.getElementById('password2').value || - document.getElementById('email').value) { // ie, he is filling in "register" path and cares - document.getElementById('match').innerHTML = - "\u2718 Passwords do not match"; - } else - document.getElementById('match').innerHTML = - "\u2718 Passwords do not match"; - - en_register = 0; - } - - if (document.getElementById('rpassword').value.length && - document.getElementById('rpassword').value.length < 8) { - en_register = 0; - document.getElementById('rpw1').innerHTML = "Need 8 chars"; - } else - if (document.getElementById('rpassword').value.length) - document.getElementById('rpw1').innerHTML = "\u2713"; - else - document.getElementById('rpw1').innerHTML = ""; - - if (!document.getElementById('rpassword').value || - !document.getElementById('password2').value || - !document.getElementById('rusername').value || - !document.getElementById('email').value || - lwsgs_email_check === '1'|| - lwsgs_user_check === '1') - en_register = 0; - - document.getElementById('register').disabled = !en_register; - document.getElementById('rpassword').disabled = lwsgs_user_check === '1'; - document.getElementById('password2').disabled = lwsgs_user_check === '1'; - document.getElementById('email').disabled = lwsgs_user_check === '1'; - - if (lwsgs_user_check === '0') { - var uc = document.getElementById('uchk'); - - if (uc) { - if (document.getElementById('rusername').value) - uc.innerHTML = "\u2713"; - else - uc.innerHTML = ""; - } - } else { - if (document.getElementById('uchk')) - ocument.getElementById('uchk').innerHTML = "\u2718 Already registered"; - en_forgot = 1; - } - - if (lwsgs_email_check === '0') { - var ec = document.getElementById('echk'); - - if (ec) { - if (document.getElementById('email').value) - ec.innerHTML = "\u2713"; - else - ec.innerHTML = ""; - } - } else { - if (document.getElementById('echk')) - document.getElementById('echk').innerHTML = "\u2718 Already registered"; - en_forgot = 1; - } - - if (en_forgot) - document.getElementById('rforgot').style.display = "inline"; - else - document.getElementById('rforgot').style.display = "none"; - - if (lwsgs_user_check === '1') - op = '0.5'; - else - op = '1.0'; - document.getElementById('rpassword').style.opacity = op; - document.getElementById('password2').style.opacity = op; - document.getElementById('email').style.opacity = op; - } - -function lwsgs_cupdate() -{ - var en_change = 1, en_forgot = 1, pwok = 1, op; - - if (lwsgs_auth & 8) { - document.getElementById('ccurpw').style.display = "none"; - document.getElementById('ccurpw_name').style.display = "none"; - } else { - if (!document.getElementById('ccurpw').value || - document.getElementById('ccurpw').value.length < 8) { - en_change = 0; - pwok = 0; - document.getElementById('cuchk').innerHTML = "\u2718"; - } else { - en_forgot = 0; - document.getElementById('cuchk').innerHTML = ""; - } - document.getElementById('ccurpw').style.display = "inline"; - document.getElementById('ccurpw_name').style.display = "inline"; - } - - if (document.getElementById('cpassword').value == - document.getElementById('cpassword2').value) { - if (document.getElementById('cpassword').value.length) - document.getElementById('cmatch').innerHTML = "\u2713"; - else - document.getElementById('cmatch').innerHTML = ""; - document.getElementById('pw2').style = ""; - } else { - if (document.getElementById('cpassword2').value //|| - //document.getElementById('cemail').value - ) { // ie, he is filling in "register" path and cares - document.getElementById('cmatch').innerHTML = - "\u2718 Passwords do not match"; - } else - document.getElementById('cmatch').innerHTML = "\u2718 Passwords do not match"; - - en_change = 0; - } - - if (document.getElementById('cpassword').value.length && - document.getElementById('cpassword').value.length < 8) { - en_change = 0; - document.getElementById('cpw1').innerHTML = "Need 8 chars"; - } else { - var cpw = document.getElementById('cpw1'); - - if (cpw) { - if (document.getElementById('cpassword').value.length) - cpw.innerHTML = "\u2713"; - else - cpw.innerHTML = ""; - } - } - - if (!document.getElementById('cpassword').value || - !document.getElementById('cpassword2').value || - pwok === 0) - en_change = 0; - - if (document.getElementById('showdel').checked) - document.getElementById('delete').style.display = "inline"; - else - document.getElementById('delete').style.display = "none"; - - document.getElementById('change').disabled = !en_change; - document.getElementById('cpassword').disabled = pwok === 0; - document.getElementById('cpassword2').disabled = pwok === 0; - document.getElementById('showdel').disabled = pwok === 0; - document.getElementById('delete').disabled = pwok === 0; - //document.getElementById('cemail').disabled = pwok === 0; - - /* - if (lwsgs_auth & 8) { - document.getElementById('cemail').style.display = "none"; - document.getElementById('cemail_name').style.display = "none"; - } else { - document.getElementById('cemail').style.display = "inline"; - document.getElementById('cemail_name').style.display = "inline"; - if (lwsgs_email_check === '0' && - document.getElementById('cemail').value != lwsgs_email) { - if (document.getElementById('cemail').value) - document.getElementById('cechk').innerHTML = "\u2713"; - else - document.getElementById('cechk').innerHTML = ""; - } else { - document.getElementById('cechk').innerHTML = "\u2718 Already registered"; - en_forgot = 1; - } - } */ - - if (lwsgs_auth & 8) - en_forgot = 0; - - if (en_forgot) - document.getElementById('cforgot').style.display = "inline"; - else - document.getElementById('cforgot').style.display = "none"; - - if (pwok === 0) - op = '0.5'; - else - op = '1.0'; - document.getElementById('cpassword').style.opacity = op; - document.getElementById('cpassword2').style.opacity = op; - // document.getElementById('cemail').style.opacity = op; - } - -function lwsgs_check_user() -{ - var xmlHttp = new XMLHttpRequest(); - xmlHttp.onreadystatechange = function() { - if (xmlHttp.readyState === 4 && xmlHttp.status === 200) { - lwsgs_user_check = xmlHttp.responseText; - lwsgs_rupdate(); - } - } - xmlHttp.open("GET", "lwsgs-check/username="+document.getElementById('rusername').value, true); - xmlHttp.send(null); -} - -function lwsgs_check_email(id) -{ - var xmlHttp = new XMLHttpRequest(); - xmlHttp.onreadystatechange = function() { - if (xmlHttp.readyState === 4 && xmlHttp.status === 200) { - lwsgs_email_check = xmlHttp.responseText; - lwsgs_rupdate(); - } - } - xmlHttp.open("GET", "lwsgs-check/email="+document.getElementById(id).value, true); - xmlHttp.send(null); -} - -function rupdate_user() -{ - lwsgs_rupdate(); - lwsgs_check_user(); -} - -function rupdate_email() -{ - lwsgs_rupdate(); - lwsgs_check_email('email'); -} - -function cupdate_email() -{ - lwsgs_cupdate(); - lwsgs_check_email('cemail'); -} - - -function lwsgs_initial() -{ - document.getElementById('lwsgs').innerHTML = lwsgs_html; - - if (lwsgs_user) { - document.getElementById("curuser").innerHTML = - "currently logged in as " + lwsgs_san(lwsgs_user) + "
"; - - document.getElementById("ccuruser").innerHTML = - "Login settings for " + - lwsgs_san(lwsgs_user) + "
"; - } - - document.getElementById('username').oninput = lwsgs_update; - document.getElementById('username').onchange = lwsgs_update; - document.getElementById('password').oninput = lwsgs_update; - document.getElementById('password').onchange = lwsgs_update; - document.getElementById('doreg').onclick = lwsgs_open_registration; - document.getElementById('clink').onclick = lwsgs_select_change; - document.getElementById('cancel').onclick =lwsgs_cancel_registration; - document.getElementById('cancel2').onclick =lwsgs_cancel_registration; - document.getElementById('rpassword').oninput = lwsgs_rupdate; - document.getElementById('password2').oninput = lwsgs_rupdate; - document.getElementById('rusername').oninput = rupdate_user; - document.getElementById('email').oninput = rupdate_email; - document.getElementById('ccurpw').oninput = lwsgs_cupdate; - document.getElementById('cpassword').oninput = lwsgs_cupdate; - document.getElementById('cpassword2').oninput = lwsgs_cupdate; - - document.getElementById('showdel').onchange = lwsgs_cupdate; - - if (lwsgs_email) - document.getElementById('grav').innerHTML = - ""; - //if (lwsgs_email) - //document.getElementById('cemail').placeholder = lwsgs_email; - document.getElementById('cusername').value = lwsgs_user; - lwsgs_update(); - lwsgs_cupdate(); -} - -window.addEventListener("load", function() { - lwsgs_initial(); - document.getElementById("nolog").style.display = !!lwsgs_user ? "none" : "inline-block"; - document.getElementById("logged").style.display = !lwsgs_user ? "none" : "inline-block"; - - document.getElementById("msg").onkeyup = mupd; - document.getElementById("msg").onchange = mupd; - - var ws; - - function mb_format(s) - { - var r = "", n, wos = 0; - - for (n = 0; n < s.length; n++) { - if (s[n] == ' ') - wos = 0; - else { - wos++; - if (wos === 40) { - wos = 0; - r = r + ' '; - } - } - if (s[n] == '<') { - r = r + "<"; - continue; - } - if (s[n] == '\n') { - r = r + "
"; - continue; - } - - r = r + s[n]; - } - - return r; - } - - function add_div(n, m) - { - var q = document.getElementById(n); - var d = new Date(m.time * 1000), s = d.toTimeString(), t; - - t = s.indexOf('('); - if (t) - s = s.substring(0, t); - - q.innerHTML = "
" + - "
" + - "" + lwsgs_san(m.username) + "
" + - "" + d.toDateString() + - "
" + s + "

" + - "IP: " + lwsgs_san(m.ip) + - "
" + - mb_format(m.content) + - "

" + q.innerHTML; - } - - function get_appropriate_ws_url() - { - var pcol; - var u = document.URL; - - if (u.substring(0, 5) == "https") { - pcol = "wss://"; - u = u.substr(8); - } else { - pcol = "ws://"; - if (u.substring(0, 4) == "http") - u = u.substr(7); - } - u = u.split('/'); - - return pcol + u[0] + "/xxx"; - } - - if (lwsgs_user) { - - ws = new WebSocket(get_appropriate_ws_url(), - "protocol-lws-messageboard"); - - try { - ws.onopen = function() { - document.getElementById("debug").textContent = "ws opened"; - } - ws.onmessage =function got_packet(msg) { - add_div("messages", JSON.parse(msg.data)); - } - ws.onclose = function(){ - } - } catch(exception) { - alert('

Error' + exception); - } - } - - function mupd() - { - document.getElementById("send").disabled = !document.getElementById("msg").value; - } -}, false); diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/md5.min.js b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/md5.min.js deleted file mode 100644 index 4bd9de1e9..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/md5.min.js +++ /dev/null @@ -1,2 +0,0 @@ -!function(n){"use strict";function t(n,t){var r=(65535&n)+(65535&t),e=(n>>16)+(t>>16)+(r>>16);return e<<16|65535&r}function r(n,t){return n<>>32-t}function e(n,e,o,u,c,f){return t(r(t(t(e,n),t(u,f)),c),o)}function o(n,t,r,o,u,c,f){return e(t&r|~t&o,n,t,u,c,f)}function u(n,t,r,o,u,c,f){return e(t&o|r&~o,n,t,u,c,f)}function c(n,t,r,o,u,c,f){return e(t^r^o,n,t,u,c,f)}function f(n,t,r,o,u,c,f){return e(r^(t|~o),n,t,u,c,f)}function i(n,r){n[r>>5]|=128<>>9<<4)+14]=r;var e,i,a,h,d,l=1732584193,g=-271733879,v=-1732584194,m=271733878;for(e=0;e>5]>>>t%32&255);return r}function h(n){var t,r=[];for(r[(n.length>>2)-1]=void 0,t=0;t>5]|=(255&n.charCodeAt(t/8))<16&&(o=i(o,8*n.length)),r=0;16>r;r+=1)u[r]=909522486^o[r],c[r]=1549556828^o[r];return e=i(u.concat(h(t)),512+8*t.length),a(i(c.concat(e),640))}function g(n){var t,r,e="0123456789abcdef",o="";for(r=0;r>>4&15)+e.charAt(15&t);return o}function v(n){return unescape(encodeURIComponent(n))}function m(n){return d(v(n))}function p(n){return g(m(n))}function s(n,t){return l(v(n),v(t))}function C(n,t){return g(s(n,t))}function A(n,t,r){return t?r?s(t,n):C(t,n):r?m(n):p(n)}"function"==typeof define&&define.amd?define(function(){return A}):"object"==typeof module&&module.exports?module.exports=A:n.md5=A}(this); -//# sourceMappingURL=md5.min.js.map \ No newline at end of file diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/needadmin/admin-login.html b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/needadmin/admin-login.html deleted file mode 100644 index 113df9cd3..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/needadmin/admin-login.html +++ /dev/null @@ -1,5 +0,0 @@ - -This is an example destination that will appear after successful Admin login. - -This URL cannot be served if you're not logged in as admin. - diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/needauth/successful-login.html b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/needauth/successful-login.html deleted file mode 100644 index dfc25cf74..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/needauth/successful-login.html +++ /dev/null @@ -1,4 +0,0 @@ - -This is an example destination that will appear after successful non-Admin login - - diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-forgot-fail.html b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-forgot-fail.html deleted file mode 100644 index ead3d13ec..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-forgot-fail.html +++ /dev/null @@ -1,5 +0,0 @@ - -Sorry, something went wrong. - -Click here to continue. - diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-forgot-ok.html b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-forgot-ok.html deleted file mode 100644 index 3e8e9cf59..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-forgot-ok.html +++ /dev/null @@ -1,6 +0,0 @@ - -This is a one-time password recovery login. - -Please click here and click your username at the top to reset your password. - - diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-register-fail.html b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-register-fail.html deleted file mode 100644 index 063c3c50f..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-register-fail.html +++ /dev/null @@ -1 +0,0 @@ -Registration failed, sorry diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-register-ok.html b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-register-ok.html deleted file mode 100644 index c00c3f3d2..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-register-ok.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - -
- -
- Your registration as is accepted,
- you will receive an email shortly with instructions
- to verify and enable the account for normal use.

- The link is only valid for an hour, after that if it has
- not been verified your account will be deleted. -
- - - - diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-verify-fail.html b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-verify-fail.html deleted file mode 100644 index d1d89ca56..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-verify-fail.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - -
- -
- Sorry, the link was invalid. -
- - - diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-verify-ok.html b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-verify-ok.html deleted file mode 100644 index ae647fc5c..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-verify-ok.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - -
- -
- Thanks for signing up, your registration as is verified.
-
- Click here to continue. -
- - - - diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/seats.jpg b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/seats.jpg deleted file mode 100644 index 5bed40d91..000000000 Binary files a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/seats.jpg and /dev/null differ diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/sent-forgot-fail.html b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/sent-forgot-fail.html deleted file mode 100644 index ead3d13ec..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/sent-forgot-fail.html +++ /dev/null @@ -1,5 +0,0 @@ - -Sorry, something went wrong. - -Click here to continue. - diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/sent-forgot-ok.html b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/sent-forgot-ok.html deleted file mode 100644 index 83df7510a..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/sent-forgot-ok.html +++ /dev/null @@ -1,4 +0,0 @@ -An email has been sent to your registered address. - -Please follow the instructions to reset your password. - diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/strict-csp.svg b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/strict-csp.svg deleted file mode 100644 index cd128f1d2..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/strict-csp.svg +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/successful-login.html b/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/successful-login.html deleted file mode 100644 index dfc25cf74..000000000 --- a/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/successful-login.html +++ /dev/null @@ -1,4 +0,0 @@ - -This is an example destination that will appear after successful non-Admin login - - diff --git a/minimal-examples/ws-client/minimal-ws-client-echo/protocol_lws_minimal_client_echo.c b/minimal-examples/ws-client/minimal-ws-client-echo/protocol_lws_minimal_client_echo.c index 2e34b7782..60014951d 100644 --- a/minimal-examples/ws-client/minimal-ws-client-echo/protocol_lws_minimal_client_echo.c +++ b/minimal-examples/ws-client/minimal-ws-client-echo/protocol_lws_minimal_client_echo.c @@ -281,36 +281,3 @@ callback_minimal_client_echo(struct lws *wsi, enum lws_callback_reasons reason, 1024, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL_CLIENT_ECHO -}; - -int -init_protocol_minimal_client_echo(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -int -destroy_protocol_minimal_client_echo(struct lws_context *context) -{ - return 0; -} -#endif diff --git a/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c b/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c index 5212c0fd9..c7564ac50 100644 --- a/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c +++ b/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c @@ -280,36 +280,3 @@ callback_minimal_pmd_bulk(struct lws *wsi, enum lws_callback_reasons reason, 4096, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL_PMD_BULK -}; - -int -init_protocol_minimal_pmd_bulk(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -int -destroy_protocol_minimal_pmd_bulk(struct lws_context *context) -{ - return 0; -} -#endif diff --git a/minimal-examples/ws-server/minimal-ws-broker/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-broker/protocol_lws_minimal.c index b13d4be0a..0ed24e6eb 100644 --- a/minimal-examples/ws-server/minimal-ws-broker/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-broker/protocol_lws_minimal.c @@ -215,36 +215,3 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, 128, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff --git a/minimal-examples/ws-server/minimal-ws-server-echo/protocol_lws_minimal_server_echo.c b/minimal-examples/ws-server/minimal-ws-server-echo/protocol_lws_minimal_server_echo.c index d6075fb07..5b5683373 100644 --- a/minimal-examples/ws-server/minimal-ws-server-echo/protocol_lws_minimal_server_echo.c +++ b/minimal-examples/ws-server/minimal-ws-server-echo/protocol_lws_minimal_server_echo.c @@ -230,36 +230,3 @@ callback_minimal_server_echo(struct lws *wsi, enum lws_callback_reasons reason, 1024, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL_SERVER_ECHO -}; - -int -init_protocol_minimal_server_echo(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -int -destroy_protocol_minimal_server_echo(struct lws_context *context) -{ - return 0; -} -#endif diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/protocol_lws_minimal_pmd_bulk.c b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/protocol_lws_minimal_pmd_bulk.c index 7c49f0ee4..301996dae 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/protocol_lws_minimal_pmd_bulk.c +++ b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/protocol_lws_minimal_pmd_bulk.c @@ -221,36 +221,3 @@ callback_minimal_pmd_bulk(struct lws *wsi, enum lws_callback_reasons reason, 4096, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL_PMD_BULK -}; - -int -init_protocol_minimal_pmd_bulk(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -int -destroy_protocol_minimal_pmd_bulk(struct lws_context *context) -{ - return 0; -} -#endif diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd-corner/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-pmd-corner/protocol_lws_minimal.c index 9f11af505..90ab25d66 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd-corner/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-pmd-corner/protocol_lws_minimal.c @@ -269,36 +269,3 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, 2048, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-pmd/protocol_lws_minimal.c index db07511f5..00287d723 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-pmd/protocol_lws_minimal.c @@ -158,36 +158,3 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, 128, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff --git a/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c index 5370d53e8..c809c5e72 100644 --- a/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c @@ -279,36 +279,3 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, 0, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff --git a/minimal-examples/ws-server/minimal-ws-server-threadpool/protocol_lws_minimal_threadpool.c b/minimal-examples/ws-server/minimal-ws-server-threadpool/protocol_lws_minimal_threadpool.c index ba8c22781..67b5049f1 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threadpool/protocol_lws_minimal_threadpool.c +++ b/minimal-examples/ws-server/minimal-ws-server-threadpool/protocol_lws_minimal_threadpool.c @@ -322,36 +322,3 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, 128, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff --git a/minimal-examples/ws-server/minimal-ws-server-threads-smp/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-threads-smp/protocol_lws_minimal.c index 1ee7ce705..2bc3284b6 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads-smp/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-threads-smp/protocol_lws_minimal.c @@ -300,36 +300,3 @@ init_fail: 128, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c index 8f230bbf3..2b9c09a51 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c @@ -295,36 +295,3 @@ init_fail: 128, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff --git a/minimal-examples/ws-server/minimal-ws-server/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server/protocol_lws_minimal.c index c1dd3f759..6e0ed9483 100644 --- a/minimal-examples/ws-server/minimal-ws-server/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server/protocol_lws_minimal.c @@ -152,36 +152,3 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, 128, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff --git a/plugin-standalone/protocol_example_standalone.c b/plugin-standalone/protocol_example_standalone.c index c33f683e8..b8ec2ef54 100644 --- a/plugin-standalone/protocol_example_standalone.c +++ b/plugin-standalone/protocol_example_standalone.c @@ -127,26 +127,15 @@ static const struct lws_protocols protocols[] = { }, }; -LWS_VISIBLE int -init_protocol_example_standalone(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - } +LWS_VISIBLE const lws_plugin_protocol_t protocol_example_standalone = { + .hdr = { + "standalone", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_VISIBLE int -destroy_protocol_example_standalone(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; diff --git a/plugins/acme-client/protocol_lws_acme_client.c b/plugins/acme-client/protocol_lws_acme_client.c index 73c9c6728..12b204778 100644 --- a/plugins/acme-client/protocol_lws_acme_client.c +++ b/plugins/acme-client/protocol_lws_acme_client.c @@ -1630,28 +1630,17 @@ static const struct lws_protocols protocols[] = { LWS_PLUGIN_PROTOCOL_LWS_ACME_CLIENT }; -LWS_VISIBLE int -init_protocol_lws_acme_client(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - } +LWS_VISIBLE const lws_plugin_protocol_t protocol_lws_acme_client = { + .hdr = { + "acme client", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_VISIBLE int -destroy_protocol_lws_acme_client(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff --git a/plugins/deaddrop/protocol_lws_deaddrop.c b/plugins/deaddrop/protocol_lws_deaddrop.c index b36532743..85d777a96 100644 --- a/plugins/deaddrop/protocol_lws_deaddrop.c +++ b/plugins/deaddrop/protocol_lws_deaddrop.c @@ -689,28 +689,17 @@ static const struct lws_protocols protocols[] = { LWS_PLUGIN_PROTOCOL_DEADDROP }; -LWS_VISIBLE int -init_protocol_deaddrop(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - } +LWS_VISIBLE const lws_plugin_protocol_t protocol_deaddrop = { + .hdr = { + "deaddrop", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_VISIBLE int -destroy_protocol_deaddrop(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff --git a/plugins/protocol_client_loopback_test.c b/plugins/protocol_client_loopback_test.c index 2ccaacdb5..49f73d865 100644 --- a/plugins/protocol_client_loopback_test.c +++ b/plugins/protocol_client_loopback_test.c @@ -173,26 +173,15 @@ static const struct lws_protocols protocols[] = { }, }; -LWS_VISIBLE int -init_protocol_client_loopback_test(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - } +LWS_VISIBLE const lws_plugin_protocol_t protocol_client_loopback_test = { + .hdr = { + "client loopback test", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_VISIBLE int -destroy_protocol_client_loopback_test(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; diff --git a/plugins/protocol_dumb_increment.c b/plugins/protocol_dumb_increment.c index 357ba9f51..1c3d785c6 100644 --- a/plugins/protocol_dumb_increment.c +++ b/plugins/protocol_dumb_increment.c @@ -121,28 +121,17 @@ static const struct lws_protocols protocols[] = { LWS_PLUGIN_PROTOCOL_DUMB_INCREMENT }; -LWS_VISIBLE int -init_protocol_dumb_increment(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - } +LWS_VISIBLE const lws_plugin_protocol_t protocol_dumb_increment = { + .hdr = { + "dumb increment", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_VISIBLE int -destroy_protocol_dumb_increment(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff --git a/plugins/protocol_esp32_lws_group.c b/plugins/protocol_esp32_lws_group.c deleted file mode 100644 index 68adc88c1..000000000 --- a/plugins/protocol_esp32_lws_group.c +++ /dev/null @@ -1,242 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2019 Andy Green - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#include -#include -#include - -typedef enum { - GROUP_STATE_NONE, - GROUP_STATE_INITIAL, - GROUP_STATE_MEMBERS, - GROUP_STATE_FINAL -} group_state; - -struct per_session_data__lws_group { - struct per_session_data__lws_group *next; - group_state group_state; - - struct lws_group_member *member; - - unsigned char subsequent:1; - unsigned char changed_partway:1; -}; - -struct per_vhost_data__lws_group { - struct per_session_data__lws_group *live_pss_list; - struct lws_context *context; - struct lws_vhost *vhost; - const struct lws_protocols *protocol; - int count_live_pss; -}; - -static void render_ip4(char *dest, int len, uint8_t *ip) -{ - snprintf(dest, len, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); -} - - - -static int -callback_lws_group(struct lws *wsi, enum lws_callback_reasons reason, - void *user, void *in, size_t len) -{ - struct per_session_data__lws_group *pss = - (struct per_session_data__lws_group *)user; - struct per_vhost_data__lws_group *vhd = - (struct per_vhost_data__lws_group *) - lws_protocol_vh_priv_get(lws_get_vhost(wsi), - lws_get_protocol(wsi)); - char buffer[1024 + LWS_PRE], ipv4[20]; - char *start = buffer + LWS_PRE - 1, *p = start, - *end = buffer + sizeof(buffer) - 1; - struct lws_group_member *mbr; - int n, m; - - switch (reason) { - - case LWS_CALLBACK_PROTOCOL_INIT: - vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), - lws_get_protocol(wsi), - sizeof(struct per_vhost_data__lws_group)); - vhd->context = lws_get_context(wsi); - vhd->protocol = lws_get_protocol(wsi); - vhd->vhost = lws_get_vhost(wsi); - break; - - case LWS_CALLBACK_PROTOCOL_DESTROY: - if (!vhd) - break; - break; - - case LWS_CALLBACK_ESTABLISHED: - lwsl_notice("%s: ESTABLISHED\n", __func__); - vhd->count_live_pss++; - pss->next = vhd->live_pss_list; - vhd->live_pss_list = pss; - pss->group_state = GROUP_STATE_INITIAL; - lws_callback_on_writable(wsi); - break; - - case LWS_CALLBACK_SERVER_WRITEABLE: - - switch (pss->group_state) { - - case GROUP_STATE_NONE: - /* fallthru */ - - case GROUP_STATE_INITIAL: - - p += snprintf((char *)p, end - p, - "{\n" - " \"group\":\"%s\"," - " \"members\":[\n", - lws_esp32.group); - - n = LWS_WRITE_TEXT | LWS_WRITE_NO_FIN; - pss->group_state = GROUP_STATE_MEMBERS; - pss->subsequent = 0; - pss->changed_partway = 0; - pss->member = lws_esp32.first; - break; - - case GROUP_STATE_MEMBERS: - - /* confirm pss->member is still in the list... */ - - mbr = lws_esp32.first; - while (mbr && mbr != pss->member) - mbr = mbr->next; - - if (!mbr) { /* no longer exists... */ - if (lws_esp32.first || pss->member) - pss->changed_partway = 1; - *p++ = ' '; - pss->member = NULL; - - /* - * finish the list where we got to, then - * immediately reissue it - */ - } - - while (end - p > 100 && pss->member) { - - if (pss->subsequent) - *p++ = ','; - - pss->subsequent = 1; - render_ip4(ipv4, sizeof(ipv4), (uint8_t *)&pss->member->addr); - - p += snprintf((char *)p, end - p, - " {\n" - " \"mac\":\"%s\",\n" - " \"model\":\"%s\",\n" - " \"role\":\"%s\",\n" - " \"width\":\"%d\",\n" - " \"height\":\"%d\",\n" - " \"ipv4\":\"%s\"\n" - " }\n", - pss->member->mac, - pss->member->model, - pss->member->role, - pss->member->width, - pss->member->height, - ipv4 - ); - pss->member = pss->member->next; - } - - lwsl_notice("%s\n", p); - - n = LWS_WRITE_CONTINUATION | LWS_WRITE_NO_FIN; - if (!pss->member) - pss->group_state = GROUP_STATE_FINAL; - break; - - case GROUP_STATE_FINAL: - n = LWS_WRITE_CONTINUATION; - p += sprintf((char *)p, "],\n \"discard\":\"%d\"}\n", - pss->changed_partway); - if (pss->changed_partway) - pss->group_state = GROUP_STATE_INITIAL; - else - pss->group_state = GROUP_STATE_NONE; - break; - default: - return 0; - } -// lwsl_notice("issue: %d (%d)\n", p - start, n); - m = lws_write(wsi, (unsigned char *)start, p - start, n); - if (m < 0) { - lwsl_err("ERROR %d writing to di socket\n", m); - return -1; - } - - if (pss->group_state != GROUP_STATE_NONE) - lws_callback_on_writable(wsi); - - break; - - case LWS_CALLBACK_RECEIVE: - { - break; - } - - case LWS_CALLBACK_CLOSED: - { - struct per_session_data__lws_group **p = &vhd->live_pss_list; - - while (*p) { - if ((*p) == pss) { - *p = pss->next; - continue; - } - - p = &((*p)->next); - } - - vhd->count_live_pss--; - } - break; - - case LWS_CALLBACK_HTTP_DROP_PROTOCOL: - /* called when our wsi user_space is going to be destroyed */ - break; - - default: - break; - } - - return 0; -} - -#define LWS_PLUGIN_PROTOCOL_LWS_GROUP \ - { \ - "lws-group", \ - callback_lws_group, \ - sizeof(struct per_session_data__lws_group), \ - 1024, 0, NULL, 900 \ - } - diff --git a/plugins/protocol_esp32_lws_ota.c b/plugins/protocol_esp32_lws_ota.c deleted file mode 100644 index f66e229a1..000000000 --- a/plugins/protocol_esp32_lws_ota.c +++ /dev/null @@ -1,291 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2019 Andy Green - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#include -#include -#include -#include - -struct per_session_data__esplws_ota { - struct lws_spa *spa; - char filename[32]; - char result[LWS_PRE + 512]; - int result_len; - int filename_length; - esp_ota_handle_t otahandle; - const esp_partition_t *part; - long file_length; - long last_rep; - nvs_handle nvh; - TimerHandle_t reboot_timer; -}; - -struct per_vhost_data__esplws_ota { - struct lws_context *context; - struct lws_vhost *vhost; - const struct lws_protocols *protocol; -}; - -static const char * const ota_param_names[] = { - "upload", -}; - -enum enum_ota_param_names { - EPN_UPLOAD, -}; - -static void ota_reboot_timer_cb(TimerHandle_t t) -{ - esp_restart(); -} - -const esp_partition_t * -ota_choose_part(void) -{ - const esp_partition_t *bootpart, *part = NULL; - esp_partition_iterator_t i; - - bootpart = lws_esp_ota_get_boot_partition(); - i = esp_partition_find(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, NULL); - while (i) { - part = esp_partition_get(i); - - /* cannot update ourselves */ - if (part == bootpart) - goto next; - - /* OTA Partition numbering is from _OTA_MIN to less than _OTA_MAX */ - if (part->subtype < ESP_PARTITION_SUBTYPE_APP_OTA_MIN || - part->subtype >= ESP_PARTITION_SUBTYPE_APP_OTA_MAX) - goto next; - - break; - -next: - i = esp_partition_next(i); - } - - if (!i) { - lwsl_err("Can't find good OTA part\n"); - return NULL; - } - lwsl_notice("Directing OTA to part type %d/%d start 0x%x\n", - part->type, part->subtype, - (uint32_t)part->address); - - return part; -} - -static int -ota_file_upload_cb(void *data, const char *name, const char *filename, - char *buf, int len, enum lws_spa_fileupload_states state) -{ - struct per_session_data__esplws_ota *pss = - (struct per_session_data__esplws_ota *)data; - - switch (state) { - case LWS_UFS_OPEN: - lwsl_notice("LWS_UFS_OPEN Filename %s\n", filename); - lws_strncpy(pss->filename, filename, sizeof(pss->filename)); - if (strcmp(name, "ota")) - return 1; - - pss->part = ota_choose_part(); - if (!pss->part) - return 1; - - if (esp_ota_begin(pss->part, OTA_SIZE_UNKNOWN, &pss->otahandle) != ESP_OK) { - lwsl_err("OTA: Failed to begin\n"); - return 1; - } - - pss->file_length = 0; - pss->last_rep = -1; - break; - - case LWS_UFS_FINAL_CONTENT: - case LWS_UFS_CONTENT: - if (pss->file_length + len > pss->part->size) { - lwsl_err("OTA: incoming file too large\n"); - return 1; - } - - if ((pss->file_length & ~0xffff) != (pss->last_rep & ~0xffff)) { - lwsl_notice("writing 0x%lx...\n", - pss->part->address + pss->file_length); - pss->last_rep = pss->file_length; - } - if (esp_ota_write(pss->otahandle, buf, len) != ESP_OK) { - lwsl_err("OTA: Failed to write\n"); - return 1; - } - pss->file_length += len; - - if (state == LWS_UFS_CONTENT) - break; - - lwsl_notice("LWS_UFS_FINAL_CONTENT\n"); - if (esp_ota_end(pss->otahandle) != ESP_OK) { - lwsl_err("OTA: end failed\n"); - return 1; - } - - if (esp_ota_set_boot_partition(pss->part) != ESP_OK) { - lwsl_err("OTA: set boot part failed\n"); - return 1; - } - - pss->reboot_timer = xTimerCreate("x", pdMS_TO_TICKS(250), 0, NULL, - ota_reboot_timer_cb); - xTimerStart(pss->reboot_timer, 0); - break; - } - - return 0; -} - -static int -callback_esplws_ota(struct lws *wsi, enum lws_callback_reasons reason, - void *user, void *in, size_t len) -{ - struct per_session_data__esplws_ota *pss = - (struct per_session_data__esplws_ota *)user; - struct per_vhost_data__esplws_ota *vhd = - (struct per_vhost_data__esplws_ota *) - lws_protocol_vh_priv_get(lws_get_vhost(wsi), - lws_get_protocol(wsi)); - unsigned char buf[LWS_PRE + 384], *start = buf + LWS_PRE - 1, *p = start, - *end = buf + sizeof(buf) - 1; - int n; - - switch (reason) { - - case LWS_CALLBACK_PROTOCOL_INIT: - vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), - lws_get_protocol(wsi), - sizeof(struct per_vhost_data__esplws_ota)); - vhd->context = lws_get_context(wsi); - vhd->protocol = lws_get_protocol(wsi); - vhd->vhost = lws_get_vhost(wsi); - break; - - case LWS_CALLBACK_PROTOCOL_DESTROY: - if (!vhd) - break; - break; - - /* OTA POST handling */ - - case LWS_CALLBACK_HTTP_BODY: - /* create the POST argument parser if not already existing */ - // lwsl_notice("LWS_CALLBACK_HTTP_BODY (ota) %d %d %p\n", (int)pss->file_length, (int)len, pss->spa); - lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, 30); - if (!pss->spa) { - pss->spa = lws_spa_create(wsi, ota_param_names, - LWS_ARRAY_SIZE(ota_param_names), 4096, - ota_file_upload_cb, pss); - if (!pss->spa) - return -1; - - pss->filename[0] = '\0'; - pss->file_length = 0; - } - lws_esp32.upload = 1; - - /* let it parse the POST data */ - if (lws_spa_process(pss->spa, in, len)) - return -1; - break; - - case LWS_CALLBACK_HTTP_BODY_COMPLETION: - lwsl_notice("LWS_CALLBACK_HTTP_BODY_COMPLETION (ota)\n"); - /* call to inform no more payload data coming */ - lws_spa_finalize(pss->spa); - - pss->result_len = snprintf(pss->result + LWS_PRE, sizeof(pss->result) - LWS_PRE - 1, - "Rebooting after OTA update"); - - if (lws_add_http_header_status(wsi, HTTP_STATUS_OK, &p, end)) - goto bail; - - if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, - (unsigned char *)"text/html", 9, &p, end)) - goto bail; - if (lws_add_http_header_content_length(wsi, pss->result_len, &p, end)) - goto bail; - if (lws_finalize_http_header(wsi, &p, end)) - goto bail; - - n = lws_write(wsi, start, p - start, LWS_WRITE_HTTP_HEADERS | LWS_WRITE_H2_STREAM_END); - if (n < 0) - goto bail; - - lws_callback_on_writable(wsi); - break; - - case LWS_CALLBACK_HTTP_WRITEABLE: - if (!pss->result_len) - break; - lwsl_debug("LWS_CALLBACK_HTTP_WRITEABLE: sending %d\n", - pss->result_len); - n = lws_write(wsi, (unsigned char *)pss->result + LWS_PRE, - pss->result_len, LWS_WRITE_HTTP); - if (n < 0) - return 1; - - if (lws_http_transaction_completed(wsi)) - return 1; - - /* stop further service so we don't serve the probe GET to see if we rebooted */ - while (1); - - break; - - case LWS_CALLBACK_HTTP_DROP_PROTOCOL: - /* called when our wsi user_space is going to be destroyed */ - if (pss->spa) { - lws_spa_destroy(pss->spa); - pss->spa = NULL; - } - lws_esp32.upload = 0; - break; - - default: - break; - } - - return 0; - -bail: - return 1; -} - -#define LWS_PLUGIN_PROTOCOL_ESPLWS_OTA \ - { \ - "esplws-ota", \ - callback_esplws_ota, \ - sizeof(struct per_session_data__esplws_ota), \ - 4096, 0, NULL, 900 \ - } - diff --git a/plugins/protocol_esp32_lws_reboot_to_factory.c b/plugins/protocol_esp32_lws_reboot_to_factory.c deleted file mode 100644 index d6cd7f5ee..000000000 --- a/plugins/protocol_esp32_lws_reboot_to_factory.c +++ /dev/null @@ -1,61 +0,0 @@ - /* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2019 Andy Green - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - * - * This is intended to be mounted somewhere in your ESP32 user app... if the - * client touched the mount, the plugin hangs up and reboots into the - * factory mode one second later. - * - * The factory mode will reassociate with the same IP with the same MAC - * shortly afterwards and be accessible by the same IP / mDNS name. - */ -#include -#include -#include -#include - -static int -callback_esplws_rtf(struct lws *wsi, enum lws_callback_reasons reason, - void *user, void *in, size_t len) -{ - switch (reason) { - - case LWS_CALLBACK_HTTP: - - lws_esp32_restart_guided(LWS_MAGIC_REBOOT_TYPE_REQ_FACTORY); - return 1; - - default: - break; - } - - return 0; -} - -#define LWS_PLUGIN_PROTOCOL_ESPLWS_RTF \ - { \ - "esplws-rtf", \ - callback_esplws_rtf, \ - 0, \ - 10, 0, NULL, 0 \ - } - diff --git a/plugins/protocol_esp32_lws_scan.c b/plugins/protocol_esp32_lws_scan.c deleted file mode 100644 index 5fcc8b4b5..000000000 --- a/plugins/protocol_esp32_lws_scan.c +++ /dev/null @@ -1,1276 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2019 Andy Green - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#include -#include -#include - -typedef enum { - SCAN_STATE_NONE, - SCAN_STATE_INITIAL, - SCAN_STATE_INITIAL_MANIFEST, - SCAN_STATE_KNOWN, - SCAN_STATE_LIST, - SCAN_STATE_FINAL -} scan_state; - -struct store_json { - const char *j; - const char *nvs; -}; - -struct per_session_data__esplws_scan { - struct per_session_data__esplws_scan *next; - scan_state scan_state; - struct timeval last_send; - - struct lws_spa *spa; - char filename[32]; - char result[LWS_PRE + 512]; - unsigned char buffer[4096]; - int result_len; - int filename_length; - long file_length; - nvs_handle nvh; - - char ap_record; - unsigned char subsequent:1; - unsigned char changed_partway:1; -}; - -#define max_aps 12 - -struct per_vhost_data__esplws_scan { - wifi_ap_record_t ap_records[10]; - TimerHandle_t timer, reboot_timer; - struct per_session_data__esplws_scan *live_pss_list; - struct lws_context *context; - struct lws_vhost *vhost; - const struct lws_protocols *protocol; - struct lws_wifi_scan *known_aps_list; - - const esp_partition_t *part; - esp_ota_handle_t otahandle; - long file_length; - long content_length; - - int cert_remaining_days; - - struct lws *cwsi; - char json[2048]; - int json_len; - - int acme_state; - char acme_msg[256]; - - uint16_t count_ap_records; - char count_live_pss; - unsigned char scan_ongoing:1; - unsigned char completed_any_scan:1; - unsigned char reboot:1; - unsigned char changed_settings:1; - unsigned char checked_updates:1; - unsigned char autonomous_update:1; - unsigned char autonomous_update_sampled:1; -}; - -static const struct store_json store_json[] = { - { "\"ssid0\":\"", "0ssid" }, - { ",\"pw0\":\"", "0password" }, - { "\"ssid1\":\"", "1ssid" }, - { ",\"pw1\":\"", "1password" }, - { "\"ssid2\":\"", "2ssid" }, - { ",\"pw2\":\"", "2password" }, - { "\"ssid3\":\"", "3ssid" }, - { ",\"pw3\":\"", "3password" }, - { ",\"access_pw\":\"", "access_pw" }, - { "{\"group\":\"", "group" }, - { "{\"role\":\"", "role" }, - { ",\"region\":\"", "region" }, -}; - -static wifi_scan_config_t scan_config = { - .ssid = 0, - .bssid = 0, - .channel = 0, - .show_hidden = true -}; - -const esp_partition_t * -ota_choose_part(void); - -static const char * const param_names[] = { - "text", - "pub", - "pri", - "serial", - "opts", - "group", - "role", - "updsettings", -}; - -enum enum_param_names { - EPN_TEXT, - EPN_PUB, - EPN_PRI, - EPN_SERIAL, - EPN_OPTS, - EPN_GROUP, - EPN_ROLE, - EPN_UPDSETTINGS, -}; - - -static void -scan_finished(uint16_t count, wifi_ap_record_t *recs, void *v); - -static int -esplws_simple_arg(char *dest, int len, const char *in, const char *match) -{ - const char *p = strstr(in, match); - int n = 0; - - if (!p) - return 1; - - p += strlen(match); - while (*p && *p != '\"' && n < len - 1) - dest[n++] = *p++; - dest[n] = '\0'; - - return 0; -} - -static void -scan_start(struct per_vhost_data__esplws_scan *vhd) -{ - int n; - - if (vhd->reboot) - esp_restart(); - - if (vhd->scan_ongoing) - return; - - if (lws_esp32.acme) - return; - - if (lws_esp32.upload) - return; - - vhd->scan_ongoing = 1; - lws_esp32.scan_consumer = scan_finished; - lws_esp32.scan_consumer_arg = vhd; - n = esp_wifi_scan_start(&scan_config, false); - if (n != ESP_OK) - lwsl_err("scan start failed %d\n", n); -} - -static int scan_defer; - -static void timer_cb(TimerHandle_t t) -{ - struct per_vhost_data__esplws_scan *vhd = pvTimerGetTimerID(t); - -// if (!lws_esp32.inet && ((scan_defer++) & 1)) -/* - * AP mode + scan does not work well on ESP32... if we didn't connect to an AP - * ourselves, just scan once at boot. Then leave us on the AP channel. - * - * Do the callback for everyone to keep the heartbeat alive. - */ - if (!lws_esp32.inet && scan_defer++) { - lws_callback_on_writable_all_protocol(vhd->context, vhd->protocol); - - return; - } - - scan_start(vhd); -} - -static void reboot_timer_cb(TimerHandle_t t) -{ - esp_restart(); -} - -static int -client_connection(struct per_vhost_data__esplws_scan *vhd, const char *file) -{ -#if defined(CONFIG_LWS_IS_FACTORY_APPLICATION) && defined(CONFIG_LWS_OTA_SERVER_BASE_URL) && \ - defined(CONFIG_LWS_OTA_SERVER_FQDN) - static struct lws_client_connect_info i; - char path[256]; - - memset(&i, 0, sizeof i); - - snprintf(path, sizeof(path) - 1, CONFIG_LWS_OTA_SERVER_BASE_URL "/" CONFIG_LWS_MODEL_NAME "/%s", file); - - lwsl_notice("Fetching %s\n", path); - - i.port = 443; - i.context = vhd->context; - i.address = CONFIG_LWS_OTA_SERVER_FQDN; - i.ssl_connection = 1; - i.host = i.address; - i.origin = i.host; - i.vhost = vhd->vhost; - i.method = "GET"; - i.path = path; - i.protocol = "esplws-scan"; - i.pwsi = &vhd->cwsi; - - vhd->cwsi = lws_client_connect_via_info(&i); - if (!vhd->cwsi) { - lwsl_notice("NULL return\n"); - return 1; /* fail */ - } -#endif - return 0; /* ongoing */ -} - -static int -lws_wifi_scan_rssi(struct lws_wifi_scan *p) -{ - if (!p->count) - return -127; - - return p->rssi / p->count; -} - -/* - * Insert new lws_wifi_scan into linkedlist in rssi-sorted order, trimming the - * list if needed to keep it at or below max_aps entries. - */ - -static int -lws_wifi_scan_insert_trim(struct lws_wifi_scan **list, struct lws_wifi_scan *ns) -{ - int count = 0, ins = 1, worst; - struct lws_wifi_scan *newlist, **pworst, *pp1; - - lws_start_foreach_llp(struct lws_wifi_scan **, pp, *list) { - /* try to find existing match */ - if (!strcmp((*pp)->ssid, ns->ssid) && - !memcmp((*pp)->bssid, ns->bssid, 6)) { - if ((*pp)->count > 127) { - (*pp)->count /= 2; - (*pp)->rssi /= 2; - } - (*pp)->rssi += ns->rssi; - (*pp)->count++; - ins = 0; - break; - } - } lws_end_foreach_llp(pp, next); - - if (ins) { - lws_start_foreach_llp(struct lws_wifi_scan **, pp, *list) { - /* trim any excess guys */ - if (count++ >= max_aps - 1) { - pp1 = *pp; - *pp = (*pp)->next; - free(pp1); - continue; /* stay where we are */ - } - } lws_end_foreach_llp(pp, next); - - /* we are inserting... so alloc a copy of him */ - pp1 = malloc(sizeof(*pp1)); - if (!pp1) - return -1; - - memcpy(pp1, ns, sizeof(*pp1)); - pp1->next = *list; - *list = pp1; - } - - /* sort the list ... worst first, but added at the newlist head */ - - newlist = NULL; - - /* while anybody left on the old list */ - while (*list) { - worst = 0; - pworst = NULL; - - /* who is the worst guy still left on the old list? */ - lws_start_foreach_llp(struct lws_wifi_scan **, pp, *list) { - if (lws_wifi_scan_rssi(*pp) <= worst) { - worst = lws_wifi_scan_rssi(*pp); - pworst = pp; - } - } lws_end_foreach_llp(pp, next); - - if (pworst) { - /* move the worst to the head of the new list */ - pp1 = *pworst; - *pworst = (*pworst)->next; - pp1->next = newlist; - newlist = pp1; - } - } - - *list = newlist; - - return 0; -} - -static void -scan_finished(uint16_t count, wifi_ap_record_t *recs, void *v) -{ - struct per_vhost_data__esplws_scan *vhd = v; - struct per_session_data__esplws_scan *p = vhd->live_pss_list; - struct lws_wifi_scan lws; - wifi_ap_record_t *r; - int m; - - lwsl_notice("%s: count %d\n", __func__, count); - - vhd->scan_ongoing = 0; - - if (count < LWS_ARRAY_SIZE(vhd->ap_records)) - vhd->count_ap_records = count; - else - vhd->count_ap_records = LWS_ARRAY_SIZE(vhd->ap_records); - - memcpy(vhd->ap_records, recs, vhd->count_ap_records * sizeof(*recs)); - - while (p) { - if (p->scan_state != SCAN_STATE_INITIAL && - p->scan_state != SCAN_STATE_NONE) - p->changed_partway = 1; - else - p->scan_state = SCAN_STATE_INITIAL; - p = p->next; - } - - /* convert to generic, cumulative scan results */ - - for (m = 0; m < vhd->count_ap_records; m++) { - - r = &vhd->ap_records[m]; - - lws.authmode = r->authmode; - lws.channel = r->primary; - lws.rssi = r->rssi; - lws.count = 1; - memcpy(&lws.bssid, r->bssid, 6); - lws_strncpy(lws.ssid, (const char *)r->ssid, sizeof(lws.ssid)); - - lws_wifi_scan_insert_trim(&vhd->known_aps_list, &lws); - } - - lws_callback_on_writable_all_protocol(vhd->context, vhd->protocol); - - if (lws_esp32.inet && !vhd->cwsi && !vhd->checked_updates) - client_connection(vhd, "manifest.json"); - - if (vhd->changed_settings) { - lws_esp32_wlan_nvs_get(1); - vhd->changed_settings = 0; - } else - esp_wifi_connect(); -} - -static const char *ssl_names[] = { "ap-cert.pem", "ap-key.pem" }; - -static int -file_upload_cb(void *data, const char *name, const char *filename, - char *buf, int len, enum lws_spa_fileupload_states state) -{ - struct per_session_data__esplws_scan *pss = - (struct per_session_data__esplws_scan *)data; - int n; - - switch (state) { - case LWS_UFS_OPEN: - if (lws_esp32_get_reboot_type() != LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON) - return -1; - - lwsl_notice("LWS_UFS_OPEN Filename %s\n", filename); - lws_strncpy(pss->filename, filename, sizeof(pss->filename)); - if (!strcmp(name, "pub") || !strcmp(name, "pri")) { - if (nvs_open("lws-station", NVS_READWRITE, &pss->nvh)) - return 1; - } else - return 1; - pss->file_length = 0; - break; - - case LWS_UFS_FINAL_CONTENT: - case LWS_UFS_CONTENT: - if (len) { - /* if the file length is too big, drop it */ - if (pss->file_length + len > sizeof(pss->buffer)) - return 1; - - memcpy(pss->buffer + pss->file_length, buf, len); - } - pss->file_length += len; - - if (state == LWS_UFS_CONTENT) - break; - - lwsl_notice("LWS_UFS_FINAL_CONTENT\n"); - n = 0; - if (!strcmp(name, "pri")) - n = 1; - lwsl_notice("writing %s\n", ssl_names[n]); - n = nvs_set_blob(pss->nvh, ssl_names[n], pss->buffer, pss->file_length); - if (n == ESP_OK) - nvs_commit(pss->nvh); - nvs_close(pss->nvh); - if (n != ESP_OK) - return 1; - break; - } - - return 0; -} - -static int -callback_esplws_scan(struct lws *wsi, enum lws_callback_reasons reason, - void *user, void *in, size_t len) -{ - struct per_session_data__esplws_scan *pss = - (struct per_session_data__esplws_scan *)user; - struct per_vhost_data__esplws_scan *vhd = - (struct per_vhost_data__esplws_scan *) - lws_protocol_vh_priv_get(lws_get_vhost(wsi), - lws_get_protocol(wsi)); - unsigned char *start = pss->buffer + LWS_PRE - 1, *p = start, - *end = pss->buffer + sizeof(pss->buffer) - 1; - union lws_tls_cert_info_results ir; - struct lws_wifi_scan *lwscan; - char subject[64]; - int n, m; - nvs_handle nvh; - size_t s; - - - switch (reason) { - - case LWS_CALLBACK_PROTOCOL_INIT: - vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), - lws_get_protocol(wsi), - sizeof(struct per_vhost_data__esplws_scan)); - vhd->context = lws_get_context(wsi); - vhd->protocol = lws_get_protocol(wsi); - vhd->vhost = lws_get_vhost(wsi); - vhd->timer = xTimerCreate("x", pdMS_TO_TICKS(10000), 1, vhd, - (TimerCallbackFunction_t)timer_cb); - vhd->scan_ongoing = 0; - strcpy(vhd->json, " { }"); - // scan_start(vhd); - break; - - case LWS_CALLBACK_PROTOCOL_DESTROY: - if (!vhd) - break; - xTimerStop(vhd->timer, 0); - xTimerDelete(vhd->timer, 0); - break; - - case LWS_CALLBACK_ESTABLISHED: - lwsl_notice("%s: ESTABLISHED\n", __func__); - if (!vhd->live_pss_list) { - // scan_start(vhd); - xTimerStart(vhd->timer, 0); - } - vhd->count_live_pss++; - pss->next = vhd->live_pss_list; - vhd->live_pss_list = pss; - /* if we have scan results, update them. Otherwise wait */ -// if (vhd->count_ap_records) { - pss->scan_state = SCAN_STATE_INITIAL; - lws_callback_on_writable(wsi); -// } - break; - - case LWS_CALLBACK_SERVER_WRITEABLE: - if (vhd->autonomous_update_sampled) { - p += snprintf((char *)p, end - p, - " {\n \"auton\":\"1\",\n \"pos\": \"%ld\",\n" - " \"len\":\"%ld\"\n}\n", - vhd->file_length, - vhd->content_length); - - n = LWS_WRITE_TEXT; - goto issue; - } - - switch (pss->scan_state) { - struct timeval t; - uint8_t mac[6]; - struct lws_esp32_image i; - char img_factory[384], img_ota[384], group[16], role[16]; - int grt; - - case SCAN_STATE_NONE: - - /* fallthru */ - - case SCAN_STATE_INITIAL: - - gettimeofday(&t, NULL); - // if (t.tv_sec - pss->last_send.tv_sec < 10) - // return 0; - - pss->last_send = t; - - if (nvs_open("lws-station", NVS_READWRITE, &nvh)) { - lwsl_err("unable to open nvs\n"); - return -1; - } - n = 0; - if (nvs_get_blob(nvh, "ap-cert.pem", NULL, &s) == ESP_OK) - n = 1; - if (nvs_get_blob(nvh, "ap-key.pem", NULL, &s) == ESP_OK) - n |= 2; - s = sizeof(group) - 1; - group[0] = '\0'; - role[0] = '\0'; - nvs_get_str(nvh, "group", group, &s); - nvs_get_str(nvh, "role", role, &s); - - nvs_close(nvh); - - ir.ns.name[0] = '\0'; - subject[0] = '\0'; - - if (t.tv_sec > 1464083026 && - !lws_tls_vhost_cert_info(vhd->vhost, - LWS_TLS_CERT_INFO_VALIDITY_TO, &ir, 0)) { - vhd->cert_remaining_days = - (ir.time - t.tv_sec) / (24 * 3600); - ir.ns.name[0] = '\0'; - lws_tls_vhost_cert_info(vhd->vhost, - LWS_TLS_CERT_INFO_COMMON_NAME, &ir, - sizeof(ir.ns.name)); - lws_strncpy(subject, ir.ns.name, sizeof(subject)); - - ir.ns.name[0] = '\0'; - lws_tls_vhost_cert_info(vhd->vhost, - LWS_TLS_CERT_INFO_ISSUER_NAME, &ir, - sizeof(ir.ns.name)); - } - - /* - * this value in the JSON is just - * used for UI indication. Each conditional feature confirms - * it itself before it allows itself to be used. - */ - - grt = lws_esp32_get_reboot_type(); - - esp_efuse_mac_get_default(mac); - strcpy(img_factory, " { \"date\": \"Empty\" }"); - strcpy(img_ota, " { \"date\": \"Empty\" }"); - - // if (grt != LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON) { - lws_esp32_get_image_info(esp_partition_find_first(ESP_PARTITION_TYPE_APP, - ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL), &i, - img_factory, sizeof(img_factory) - 1); - img_factory[sizeof(img_factory) - 1] = '\0'; - if (img_factory[0] == 0xff || strlen(img_factory) < 8) - strcpy(img_factory, " { \"date\": \"Empty\" }"); - - lws_esp32_get_image_info(esp_partition_find_first(ESP_PARTITION_TYPE_APP, - ESP_PARTITION_SUBTYPE_APP_OTA_0, NULL), &i, - img_ota, sizeof(img_ota) - 1); - img_ota[sizeof(img_ota) - 1] = '\0'; - if (img_ota[0] == 0xff || strlen(img_ota) < 8) - strcpy(img_ota, " { \"date\": \"Empty\" }"); - // } - - p += snprintf((char *)p, end - p, - "{ \"model\":\"%s\",\n" - " \"forced_button\":\"%d\",\n" - " \"serial\":\"%s\",\n" - " \"opts\":\"%s\",\n" - " \"host\":\"%s-%s\",\n" - " \"region\":\"%d\",\n" - " \"ssl_pub\":\"%d\",\n" - " \"ssl_pri\":\"%d\",\n" - " \"mac\":\"%02X%02X%02X%02X%02X%02X\",\n" - " \"ssid\":\"%s\",\n" - " \"conn_ip\":\"%s\",\n" - " \"conn_mask\":\"%s\",\n" - " \"conn_gw\":\"%s\",\n" - " \"certdays\":\"%d\",\n" - " \"unixtime\":\"%llu\",\n" - " \"certissuer\":\"%s\",\n" - " \"certsubject\":\"%s\",\n" - " \"le_dns\":\"%s\",\n" - " \"le_email\":\"%s\",\n" - " \"acme_state\":\"%d\",\n" - " \"acme_msg\":\"%s\",\n" - " \"button\":\"%d\",\n" - " \"group\":\"%s\",\n" - " \"role\":\"%s\",\n", - lws_esp32.model, - grt == LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON, - lws_esp32.serial, - lws_esp32.opts, - lws_esp32.model, lws_esp32.serial, - lws_esp32.region, - n & 1, (n >> 1) & 1, - mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] | 1, - lws_esp32.active_ssid, - lws_esp32.sta_ip, - lws_esp32.sta_mask, - lws_esp32.sta_gw, - vhd->cert_remaining_days, - (unsigned long long)t.tv_sec, - ir.ns.name, subject, - lws_esp32.le_dns, - lws_esp32.le_email, - vhd->acme_state, - vhd->acme_msg, - ((volatile struct lws_esp32 *)(&lws_esp32))->button_is_down, - group, role); - p += snprintf((char *)p, end - p, - " \"img_factory\": %s,\n" - " \"img_ota\": %s,\n", - img_factory, - img_ota - ); - - - n = LWS_WRITE_TEXT | LWS_WRITE_NO_FIN; - pss->scan_state = SCAN_STATE_INITIAL_MANIFEST; - pss->ap_record = 0; - pss->subsequent = 0; - break; - - case SCAN_STATE_INITIAL_MANIFEST: - p += snprintf((char *)p, end - p, - " \"latest\": %s,\n" - " \"inet\":\"%d\",\n", - vhd->json, - lws_esp32.inet - ); - - p += snprintf((char *)p, end - p, - " \"known\":[\n"); - - n = LWS_WRITE_CONTINUATION | LWS_WRITE_NO_FIN; - pss->scan_state = SCAN_STATE_KNOWN; - break; - - case SCAN_STATE_KNOWN: - if (nvs_open("lws-station", NVS_READONLY, &nvh)) { - lwsl_notice("unable to open nvh\n"); - return -1; - } - - for (m = 0; m < 4; m++) { - char name[10], ssid[65]; - unsigned int pp = 0, use = 0; - - if (m) - *p++ = ','; - - s = sizeof(ssid) - 1; - ssid[0] = '\0'; - lws_snprintf(name, sizeof(name) - 1, "%dssid", m); - nvs_get_str(nvh, name, ssid, &s); - lws_snprintf(name, sizeof(name) - 1, "%dpassword", m); - s = 10; - nvs_get_str(nvh, name, NULL, &s); - pp = !!s; - lws_snprintf(name, sizeof(name) - 1, "%duse", m); - nvs_get_u32(nvh, name, &use); - - p += snprintf((char *)p, end - p, - "{\"ssid\":\"%s\",\n" - " \"pp\":\"%u\",\n" - "\"use\":\"%u\"}\n", - ssid, pp, use); - } - nvs_close(nvh); - pss->ap_record = 0; - - p += snprintf((char *)p, end - p, - "], \"aps\":[\n"); - - n = LWS_WRITE_CONTINUATION | LWS_WRITE_NO_FIN; - pss->scan_state = SCAN_STATE_LIST; - break; - - case SCAN_STATE_LIST: - lwscan = vhd->known_aps_list; - - n = pss->ap_record; - while (lwscan && n--) - lwscan = lwscan->next; - - for (m = 0; m < 6; m++) { - n = LWS_WRITE_CONTINUATION | LWS_WRITE_NO_FIN; - if (!lwscan) - goto scan_state_final; - - if (pss->subsequent) - *p++ = ','; - pss->subsequent = 1; - pss->ap_record++; - - p += snprintf((char *)p, end - p, - "{\"ssid\":\"%s\",\n" - "\"bssid\":\"%02X:%02X:%02X:%02X:%02X:%02X\",\n" - "\"rssi\":\"%d\",\n" - "\"chan\":\"%d\",\n" - "\"auth\":\"%d\"}\n", - lwscan->ssid, - lwscan->bssid[0], lwscan->bssid[1], lwscan->bssid[2], - lwscan->bssid[3], lwscan->bssid[4], lwscan->bssid[5], - lws_wifi_scan_rssi(lwscan), - lwscan->channel, lwscan->authmode); - - lwscan = lwscan->next; - if (!lwscan) - pss->scan_state = SCAN_STATE_FINAL; - } - break; - - case SCAN_STATE_FINAL: -scan_state_final: - n = LWS_WRITE_CONTINUATION; - p += sprintf((char *)p, "]\n}\n"); - if (pss->changed_partway) { - pss->changed_partway = 0; - pss->subsequent = 0; - pss->scan_state = SCAN_STATE_INITIAL; - } else { - pss->scan_state = SCAN_STATE_NONE; - vhd->autonomous_update_sampled = vhd->autonomous_update; - } - break; - default: - return 0; - } -issue: - m = lws_write(wsi, (unsigned char *)start, p - start, n); - if (m < 0) { - lwsl_err("ERROR %d writing to di socket\n", m); - return -1; - } - - if (pss->scan_state != SCAN_STATE_NONE) - lws_callback_on_writable(wsi); - - break; - - case LWS_CALLBACK_VHOST_CERT_UPDATE: - lwsl_notice("LWS_CALLBACK_VHOST_CERT_UPDATE: %d\n", (int)len); - vhd->acme_state = (int)len; - if (in) { - lws_strncpy(vhd->acme_msg, in, sizeof(vhd->acme_msg)); - lwsl_notice("acme_msg: %s\n", (char *)in); - } - lws_callback_on_writable_all_protocol_vhost(vhd->vhost, vhd->protocol); - break; - - case LWS_CALLBACK_RECEIVE: - { - const char *sect = "\"app\": {", *b; - nvs_handle nvh; - char p[64], use[6]; - int n, si = -1; - - if (strstr((const char *)in, "identify")) { - lws_esp32_identify_physical_device(); - break; - } - - if (vhd->json_len && strstr((const char *)in, "update-factory")) { - sect = "\"factory\": {"; - goto auton; - } - if (vhd->json_len && strstr((const char *)in, "update-ota")) - goto auton; - - if (strstr((const char *)in, "\"reset\"")) - goto sched_reset; - - if (!strncmp((const char *)in, "{\"job\":\"start-le\"", 17)) - goto start_le; - - - if (nvs_open("lws-station", NVS_READWRITE, &nvh) != ESP_OK) { - lwsl_err("Unable to open nvs\n"); - break; - } - - if (!esplws_simple_arg(p, sizeof(p), in, ",\"slot\":\"")) - si = atoi(p); - - lwsl_notice("si %d\n", si); - - for (n = 0; n < LWS_ARRAY_SIZE(store_json); n++) { - if (esplws_simple_arg(p, sizeof(p), in, store_json[n].j)) - continue; - - /* only change access password if he has physical access to device */ - if (n == 8 && lws_esp32_get_reboot_type() != LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON) - continue; - - if (lws_nvs_set_str(nvh, store_json[n].nvs, p) != ESP_OK) { - lwsl_err("Unable to store %s in nvm\n", store_json[n].nvs); - goto bail_nvs; - } - - if (si != -1 && n < 8) { - if (!(n & 1)) { - lws_strncpy(lws_esp32.ssid[(n >> 1) & 3], p, - sizeof(lws_esp32.ssid[0])); - lws_snprintf(use, sizeof(use) - 1, "%duse", si); - lwsl_notice("resetting %s to 0\n", use); - nvs_set_u32(nvh, use, 0); - - } else - lws_strncpy(lws_esp32.password[(n >> 1) & 3], p, - sizeof(lws_esp32.password[0])); - } - - } - - nvs_commit(nvh); - nvs_close(nvh); - - if (strstr((const char *)in, "\"factory-reset\"")) { - if (lws_esp32_get_reboot_type() == - LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON) { - - lwsl_notice("Doing factory reset\n"); - ESP_ERROR_CHECK(nvs_open("lws-station", NVS_READWRITE, &nvh)); - n = nvs_erase_all(nvh); - if (n) - lwsl_notice("erase_all failed %d\n", n); - nvs_commit(nvh); - nvs_close(nvh); - - goto sched_reset; - } else - lwsl_notice("failed on factory button boot\n"); - } - - if (vhd->scan_ongoing) - vhd->changed_settings = 1; - else - lws_esp32_wlan_nvs_get(1); - - lwsl_notice("set Join AP info\n"); - break; - -bail_nvs: - nvs_close(nvh); - - return 1; - -sched_reset: - vhd->reboot_timer = xTimerCreate("x", pdMS_TO_TICKS(250), 0, vhd, - (TimerCallbackFunction_t)reboot_timer_cb); - xTimerStart(vhd->reboot_timer, 0); - - return 1; - -auton: - lwsl_notice("Autonomous upload\n"); - b = strstr(vhd->json, sect); - if (!b) { - lwsl_notice("Can't find %s in JSON\n", sect); - return 1; - } - b = strstr(b, "\"file\": \""); - if (!b) { - lwsl_notice("Can't find \"file\": JSON\n"); - return 1; - } - vhd->autonomous_update = 1; - if (pss->scan_state == SCAN_STATE_NONE) - vhd->autonomous_update_sampled = 1; - b += 9; - n = 0; - while ((*b != '\"') && n < sizeof(p) - 1) - p[n++] = *b++; - - p[n] = '\0'; - - vhd->part = ota_choose_part(); - if (!vhd->part) - return 1; - - if (client_connection(vhd, p)) - vhd->autonomous_update = 0; - - break; - -start_le: - lws_esp32.acme = 1; /* hold off scanning */ - puts(in); - /* - * {"job":"start-le","cn":"home.warmcat.com", - * "email":"andy@warmcat.com", "staging":"true"} - */ - - if (nvs_open("lws-station", NVS_READWRITE, &nvh) != ESP_OK) { - lwsl_err("Unable to open nvs\n"); - break; - } - - n = 0; - b = strstr(in, ",\"cn\":\""); - if (b) { - b += 7; - while (*b && *b != '\"' && n < sizeof(lws_esp32.le_dns) - 1) - lws_esp32.le_dns[n++] = *b++; - } - lws_esp32.le_dns[n] = '\0'; - - lws_nvs_set_str(nvh, "acme-cn", lws_esp32.le_dns); - n = 0; - b = strstr(in, ",\"email\":\""); - if (b) { - b += 10; - while (*b && *b != '\"' && n < sizeof(lws_esp32.le_email) - 1) - lws_esp32.le_email[n++] = *b++; - } - lws_esp32.le_email[n] = '\0'; - lws_nvs_set_str(nvh, "acme-email", lws_esp32.le_email); - nvs_commit(nvh); - - nvs_close(nvh); - - n = 1; - b = strstr(in, ",\"staging\":\""); - if (b) - lwsl_notice("staging: %s\n", b); - if (b && b[12] == 'f') - n = 0; - - lwsl_notice("cn: %s, email: %s, staging: %d\n", lws_esp32.le_dns, lws_esp32.le_email, n); - - { - struct lws_acme_cert_aging_args caa; - - memset(&caa, 0, sizeof(caa)); - caa.vh = vhd->vhost; - - caa.element_overrides[LWS_TLS_REQ_ELEMENT_COMMON_NAME] = lws_esp32.le_dns; - caa.element_overrides[LWS_TLS_REQ_ELEMENT_EMAIL] = lws_esp32.le_email; - - if (n) - caa.element_overrides[LWS_TLS_SET_DIR_URL] = - "https://acme-staging.api.letsencrypt.org/directory"; /* staging */ - else - caa.element_overrides[LWS_TLS_SET_DIR_URL] = - "https://acme-v01.api.letsencrypt.org/directory"; /* real */ - - lws_callback_vhost_protocols_vhost(vhd->vhost, - LWS_CALLBACK_VHOST_CERT_AGING, - (void *)&caa, 0); - } - - break; - - } - - case LWS_CALLBACK_CLOSED: - { - struct per_session_data__esplws_scan **p = &vhd->live_pss_list; - - while (*p) { - if ((*p) == pss) { - *p = pss->next; - continue; - } - - p = &((*p)->next); - } - - vhd->count_live_pss--; - } - if (!vhd->live_pss_list) - xTimerStop(vhd->timer, 0); - break; - - /* "factory" POST handling */ - - case LWS_CALLBACK_HTTP_BODY: - /* create the POST argument parser if not already existing */ - if (!pss->spa) { - pss->spa = lws_spa_create(wsi, param_names, - LWS_ARRAY_SIZE(param_names), 1024, - file_upload_cb, pss); - if (!pss->spa) - return -1; - - pss->filename[0] = '\0'; - pss->file_length = 0; - } - //puts((const char *)in); - /* let it parse the POST data */ - if (lws_spa_process(pss->spa, in, len)) - return -1; - break; - - case LWS_CALLBACK_HTTP_BODY_COMPLETION: - lwsl_notice("LWS_CALLBACK_HTTP_BODY_COMPLETION (scan)\n"); - /* call to inform no more payload data coming */ - lws_spa_finalize(pss->spa); - - for (n = 0; n < LWS_ARRAY_SIZE(param_names); n++) - if (lws_spa_get_string(pss->spa, n)) - lwsl_notice(" Param %s: %s\n", param_names[n], - lws_spa_get_string(pss->spa, n)); - else - lwsl_notice(" Param %s: (none)\n", - param_names[n]); - - if (nvs_open("lws-station", NVS_READWRITE, &nvh) != ESP_OK) { - lwsl_err("Unable to open nvs\n"); - break; - } - - if (lws_esp32_get_reboot_type() == LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON) { - - if (lws_spa_get_string(pss->spa, EPN_SERIAL)) { - if (lws_nvs_set_str(nvh, "serial", lws_spa_get_string(pss->spa, EPN_SERIAL)) != ESP_OK) { - lwsl_err("Unable to store serial in nvm\n"); - goto bail_nvs; - } - - nvs_commit(nvh); - } - - if (lws_spa_get_string(pss->spa, EPN_OPTS)) { - if (lws_nvs_set_str(nvh, "opts", lws_spa_get_string(pss->spa, EPN_OPTS)) != ESP_OK) { - lwsl_err("Unable to store options in nvm\n"); - goto bail_nvs; - } - - nvs_commit(nvh); - } - } - - if (lws_spa_get_string(pss->spa, EPN_GROUP)) { - if (lws_nvs_set_str(nvh, "group", lws_spa_get_string(pss->spa, EPN_GROUP)) != ESP_OK) { - lwsl_err("Unable to store group in nvm\n"); - goto bail_nvs; - } - - nvs_commit(nvh); - } - - if (lws_spa_get_string(pss->spa, EPN_ROLE)) { - if (lws_nvs_set_str(nvh, "role", lws_spa_get_string(pss->spa, EPN_ROLE)) != ESP_OK) { - lwsl_err("Unable to store group in nvm\n"); - goto bail_nvs; - } - - nvs_commit(nvh); - } - - nvs_close(nvh); - - pss->result_len = snprintf(pss->result + LWS_PRE, sizeof(pss->result) - LWS_PRE - 1, - "OK"); - - if (lws_add_http_header_status(wsi, HTTP_STATUS_OK, &p, end)) - goto bail; - - if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, - (unsigned char *)"text/html", 9, &p, end)) - goto bail; - if (lws_add_http_header_content_length(wsi, pss->result_len, &p, end)) - goto bail; - if (lws_finalize_http_header(wsi, &p, end)) - goto bail; - - n = lws_write(wsi, start, p - start, LWS_WRITE_HTTP_HEADERS); - goto bail; - - case LWS_CALLBACK_HTTP_WRITEABLE: - lwsl_debug("LWS_CALLBACK_HTTP_WRITEABLE: sending %d\n", - pss->result_len); - if (!pss->result_len) - break; - n = lws_write(wsi, (unsigned char *)pss->result + LWS_PRE, - pss->result_len, LWS_WRITE_HTTP); - if (n < 0) - return 1; - - vhd->reboot_timer = xTimerCreate("x", pdMS_TO_TICKS(3000), 0, vhd, - (TimerCallbackFunction_t)reboot_timer_cb); - xTimerStart(vhd->reboot_timer, 0); - - return 1; // hang up since we will reset - - /* ----- client handling ----- */ - - case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: - lwsl_notice("Client connection error %s\n", (char *)in); - vhd->cwsi = NULL; - break; - - case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: - if (!vhd->autonomous_update) - break; - - { - char pp[20]; - - if (lws_hdr_copy(wsi, pp, sizeof(pp) - 1, WSI_TOKEN_HTTP_CONTENT_LENGTH) < 0) - return -1; - - vhd->content_length = atoi(pp); - if (vhd->content_length <= 0 || - vhd->content_length > vhd->part->size) - return -1; - - if (esp_ota_begin(vhd->part, (long)-1, &vhd->otahandle) != ESP_OK) { - lwsl_err("OTA: Failed to begin\n"); - return 1; - } - - vhd->file_length = 0; - break; - } - break; - - case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: - //lwsl_notice("LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: %ld\n", - // (long)len); - - if (!vhd->autonomous_update) { - if (sizeof(vhd->json) - vhd->json_len - 1 < len) - len = sizeof(vhd->json) - vhd->json_len - 1; - memcpy(vhd->json + vhd->json_len, in, len); - vhd->json_len += len; - vhd->json[vhd->json_len] = '\0'; - break; - } - - /* autonomous download */ - - - if (vhd->file_length + len > vhd->part->size) { - lwsl_err("OTA: incoming file too large\n"); - goto abort_ota; - } - - lwsl_debug("writing 0x%lx... 0x%lx\n", - vhd->part->address + vhd->file_length, - vhd->part->address + vhd->file_length + len); - if (esp_ota_write(vhd->otahandle, in, len) != ESP_OK) { - lwsl_err("OTA: Failed to write\n"); - goto abort_ota; - } - vhd->file_length += len; - - lws_callback_on_writable_all_protocol(vhd->context, vhd->protocol); - break; - -abort_ota: - esp_ota_end(vhd->otahandle); - vhd->otahandle = 0; - vhd->autonomous_update = 0; - - return 1; - - case LWS_CALLBACK_RECEIVE_CLIENT_HTTP: - { - char *px = (char *)pss->buffer + LWS_PRE; - int lenx = sizeof(pss->buffer) - LWS_PRE - 1; - - //lwsl_notice("LWS_CALLBACK_RECEIVE_CLIENT_HTTP: %d\n", len); - - if (lws_http_client_read(wsi, &px, &lenx) < 0) - return -1; - } - break; - - case LWS_CALLBACK_COMPLETED_CLIENT_HTTP: - lwsl_notice("LWS_CALLBACK_COMPLETED_CLIENT_HTTP\n"); - vhd->cwsi = NULL; - if (!vhd->autonomous_update) { - - vhd->checked_updates = 1; - puts(vhd->json); - return -1; - } - - /* autonomous download */ - - lwsl_notice("auton complete\n"); - - if (esp_ota_end(vhd->otahandle) != ESP_OK) { - lwsl_err("OTA: end failed\n"); - return 1; - } - - if (esp_ota_set_boot_partition(vhd->part) != ESP_OK) { - lwsl_err("OTA: set boot part failed\n"); - return 1; - } - vhd->otahandle = 0; - vhd->autonomous_update = 0; - - vhd->reboot_timer = xTimerCreate("x", pdMS_TO_TICKS(250), 0, vhd, - (TimerCallbackFunction_t)reboot_timer_cb); - xTimerStart(vhd->reboot_timer, 0); - return -1; - - case LWS_CALLBACK_CLOSED_CLIENT_HTTP: - lwsl_notice("LWS_CALLBACK_CLOSED_CLIENT_HTTP\n"); - break; - - case LWS_CALLBACK_HTTP_DROP_PROTOCOL: - /* called when our wsi user_space is going to be destroyed */ - if (pss->spa) { - lws_spa_destroy(pss->spa); - pss->spa = NULL; - } - break; - - default: - break; - } - - return 0; - -bail: - return 1; -} - -#define LWS_PLUGIN_PROTOCOL_ESPLWS_SCAN \ - { \ - "esplws-scan", \ - callback_esplws_scan, \ - sizeof(struct per_session_data__esplws_scan), \ - 1024, 0, NULL, 900 \ - } - diff --git a/plugins/protocol_fulltext_demo.c b/plugins/protocol_fulltext_demo.c index be581bfa0..b15148236 100644 --- a/plugins/protocol_fulltext_demo.c +++ b/plugins/protocol_fulltext_demo.c @@ -266,28 +266,17 @@ static const struct lws_protocols protocols[] = { LWS_PLUGIN_PROTOCOL_FULLTEXT_DEMO }; -LWS_VISIBLE int -init_protocol_fulltext_demo(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - } +LWS_VISIBLE const lws_plugin_protocol_t protocol_fulltext_demo = { + .hdr = { + "fulltext demo", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_VISIBLE int -destroy_protocol_fulltext_demo(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff --git a/plugins/protocol_lws_mirror.c b/plugins/protocol_lws_mirror.c index 380d6c2e9..d5cc8e69e 100644 --- a/plugins/protocol_lws_mirror.c +++ b/plugins/protocol_lws_mirror.c @@ -482,27 +482,17 @@ static const struct lws_protocols protocols[] = { LWS_PLUGIN_PROTOCOL_MIRROR }; -LWS_VISIBLE int -init_protocol_lws_mirror(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - } +LWS_VISIBLE const lws_plugin_protocol_t protocol_lws_mirror = { + .hdr = { + "lws mirror", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; - return 0; -} - -LWS_VISIBLE int -destroy_protocol_lws_mirror(struct lws_context *context) -{ - return 0; -} #endif diff --git a/plugins/protocol_lws_raw_test.c b/plugins/protocol_lws_raw_test.c index 255de8c3a..abe29bbd6 100644 --- a/plugins/protocol_lws_raw_test.c +++ b/plugins/protocol_lws_raw_test.c @@ -278,28 +278,17 @@ static const struct lws_protocols protocols[] = { LWS_PLUGIN_PROTOCOL_RAW_TEST }; -LWS_VISIBLE int -init_protocol_lws_raw_test(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - } +LWS_VISIBLE const lws_plugin_protocol_t protocol_lws_raw_test = { + .hdr = { + "lws raw test", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_VISIBLE int -destroy_protocol_lws_raw_test(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff --git a/plugins/protocol_lws_server_status.c b/plugins/protocol_lws_server_status.c index ab9a7978d..61f81ddd9 100644 --- a/plugins/protocol_lws_server_status.c +++ b/plugins/protocol_lws_server_status.c @@ -204,26 +204,15 @@ static const struct lws_protocols protocols[] = { }, }; -LWS_VISIBLE int -init_protocol_lws_server_status(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - } +LWS_VISIBLE const lws_plugin_protocol_t protocol_lws_server_status = { + .hdr = { + "lws server status", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_VISIBLE int -destroy_protocol_lws_server_status(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; diff --git a/plugins/protocol_lws_sshd_demo.c b/plugins/protocol_lws_sshd_demo.c index e933de1b5..cddf0c16d 100644 --- a/plugins/protocol_lws_sshd_demo.c +++ b/plugins/protocol_lws_sshd_demo.c @@ -455,28 +455,17 @@ static const struct lws_protocols protocols[] = { LWS_PLUGIN_PROTOCOL_LWS_SSHD_DEMO }; -LWS_VISIBLE int -init_protocol_lws_sshd_demo(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - } +LWS_VISIBLE const lws_plugin_protocol_t protocol_lws_sshd_demo = { + .hdr = { + "lws sshd demo", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_VISIBLE int -destroy_protocol_lws_sshd_demo(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff --git a/plugins/protocol_lws_status.c b/plugins/protocol_lws_status.c index 35a6d155d..bf8b45f5b 100644 --- a/plugins/protocol_lws_status.c +++ b/plugins/protocol_lws_status.c @@ -245,29 +245,17 @@ static const struct lws_protocols protocols[] = { LWS_PLUGIN_PROTOCOL_LWS_STATUS }; +LWS_VISIBLE const lws_plugin_protocol_t protocol_lws_status = { + .hdr = { + "lws status", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, -LWS_VISIBLE int -init_protocol_lws_status(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_VISIBLE int -destroy_protocol_lws_status(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff --git a/plugins/protocol_post_demo.c b/plugins/protocol_post_demo.c index 86157c29d..a9cf83546 100644 --- a/plugins/protocol_post_demo.c +++ b/plugins/protocol_post_demo.c @@ -287,28 +287,17 @@ static const struct lws_protocols protocols[] = { LWS_PLUGIN_PROTOCOL_POST_DEMO }; -LWS_VISIBLE int -init_protocol_post_demo(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - } +LWS_VISIBLE const lws_plugin_protocol_t protocol_post_demo = { + .hdr = { + "post demo", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_VISIBLE int -destroy_protocol_post_demo(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff --git a/plugins/raw-proxy/protocol_lws_raw_proxy.c b/plugins/raw-proxy/protocol_lws_raw_proxy.c index 6c15f3241..515da3df6 100644 --- a/plugins/raw-proxy/protocol_lws_raw_proxy.c +++ b/plugins/raw-proxy/protocol_lws_raw_proxy.c @@ -562,29 +562,18 @@ static const struct lws_protocols protocols[] = { LWS_PLUGIN_PROTOCOL_RAW_PROXY }; -LWS_VISIBLE int -init_protocol_lws_raw_proxy(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - } +LWS_VISIBLE const lws_plugin_protocol_t protocol_lws_raw_proxy = { + .hdr = { + "raw proxy", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_VISIBLE int -destroy_protocol_lws_raw_proxy(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff --git a/plugins/ssh-base/sshd.c b/plugins/ssh-base/sshd.c index 1b78019d8..4ff303dd0 100644 --- a/plugins/ssh-base/sshd.c +++ b/plugins/ssh-base/sshd.c @@ -2565,27 +2565,17 @@ const struct lws_protocols protocols_sshd[] = { #if !defined (LWS_PLUGIN_STATIC) -LWS_VISIBLE int -init_protocol_lws_ssh_base(struct lws_context *context, - struct lws_plugin_capability *c) -{ - 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; - } +LWS_VISIBLE const lws_plugin_protocol_t protocol_lws_ssh_base = { + .hdr = { + "ssh base", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, - c->protocols = protocols_sshd; - c->count_protocols = LWS_ARRAY_SIZE(protocols_sshd); - c->extensions = NULL; - c->count_extensions = 0; + .protocols = protocols_sshd, + .count_protocols = LWS_ARRAY_SIZE(protocols_sshd), + .extensions = NULL, + .count_extensions = 0, +}; - return 0; -} - -LWS_VISIBLE int -destroy_protocol_lws_ssh_base(struct lws_context *context) -{ - return 0; -} #endif