>>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