#1 libreJS patch

Open
bill-auger wants to merge 1 commits from bill-auger/librejs into bill-auger/master

+ 16 - 0
INSTALL

@@ -5,6 +5,7 @@
      * [1]Requirements
      * [2]Building and installing the library
      * [3]Trying the examples (or your own Wt application)
+     * [4]LibreJS Compliance
 
 Requirements
 
@@ -331,6 +332,21 @@ HTTPS server options:
   --ssl-tmp-dh arg        File for temporary Diffie-Hellman parameters
                           e.g. "/etc/ssl/dh512.pem"
 
+LibreJS Compliance
+
+To make your website to be LibreJS compliant, simply copy
+src/web/skeleton/libreJS_sources.example.txt into the directory
+containing the *.wt executable as libreJS_sources.txt; then edit it
+to include one or more @source lines with URLs at which your
+non-minified javascript sources can be downloaded.  One such line
+should point to the entire Wt sources because some of the inline
+scripts have no other corresponding source.
+e.g.
+$ cp src/web/skeleton/libreJS_sources.example.txt /path/to/my-site/libreJS_sources.txt
+$ cat /path/to/my-site/libreJS_sources.txt
+  @source - https://your-site.net/sources/wt/
+  @source - https://your-site.net/sources/your-custom.js
+
 References
 
    1. file:///home/roel/project/wt/git/wt/INSTALL.html#requirements

+ 20 - 0
INSTALL.html

@@ -14,6 +14,7 @@ organized in 3 sections:
 <li><a href="#build">Building and installing</a> the library</li>
 <li><a href="#examples">Trying the examples</a> (or your own Wt
   application)</li>
+<li><a href="#librejs">LibreJS Compliance</a></li>
 </ul>
 
 <a name="requirements"></a><h2>Requirements</h2>
@@ -418,5 +419,24 @@ HTTPS server options:
 </pre>
 </p>
 
+<hr />
+
+<a name="librejs"></a><h2>LibreJS Compliance</h2>
+
+<p>To make your website to be LibreJS compliant, simply copy
+src/web/skeleton/libreJS_sources.example.txt into the directory
+containing the *.wt executable as libreJS_sources.txt; then edit it
+to include one or more @source lines with URLs at which your
+non-minified javascript sources can be downloaded.  One such line
+should point to the entire Wt sources because some of the inline
+scripts have no other corresponding source.</p>
+e.g.
+<code>
+$ cp src/web/skeleton/libreJS_sources.example.txt /path/to/my-site/libreJS_sources.txt
+$ cat /path/to/my-site/libreJS_sources.txt
+  @source - https://your-site.net/sources/wt/
+  @source - https://your-site.net/sources/your-custom.js
+</code>
+
 </body>
 </html>

+ 20 - 0
INSTALL.win32.html

@@ -12,6 +12,7 @@ It is organized in 3 sections:
 <li>Requirements</li>
 <li>Building and installing the library</li>
 <li>Trying the examples (or your own Wt application)</li>
+<li>LibreJS Compliance</li>
 </ul>
 
 <h2>Requirements</h2>
@@ -122,5 +123,24 @@ HTTPS server options:
 </pre>
 </p>
 
+<hr />
+
+<h2>LibreJS Compliance</h2>
+
+<p>To make your website to be LibreJS compliant, simply copy
+src/web/skeleton/libreJS_sources.example.txt into the directory
+containing the *.wt executable as libreJS_sources.txt; then edit it
+to include one or more @source lines with URLs at which your
+non-minified javascript sources can be downloaded.  One such line
+should point to the entire Wt sources because some of the inline
+scripts have no other corresponding source.</p>
+e.g.
+<code>
+$ cp src/web/skeleton/libreJS_sources.example.txt /path/to/my-site/libreJS_sources.txt
+$ cat /path/to/my-site/libreJS_sources.txt
+  @source - https://your-site.net/sources/wt/
+  @source - https://your-site.net/sources/your-custom.js
+</code>
+
 </body>
 </html>

+ 2 - 0
src/CMakeLists.txt

@@ -39,6 +39,7 @@ ELSE(CMAKE_BUILD_TYPE STREQUAL "Debug")
 ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
 
 FILE_TO_STRING(web/skeleton/jquery.min.js JQuery_js.C JQuery_js)
+FILE_TO_STRING(web/skeleton/libreJS.js LibreJS_js.C LibreJS_js)
 
 FILE_TO_STRING(xml/wt.xml Wt_xml.C Wt_xml)
 FILE_TO_STRING(xml/auth_strings.xml AuthStrings_xml.C AuthStrings_xml)
@@ -372,6 +373,7 @@ BootstrapTheme_xml.C
 Bootstrap3Theme_xml.C
 AuthCssTheme_xml.C
 JQuery_js.C
+LibreJS_js.C
 )
 
 ADD_DEFINITIONS(-DWT_BUILDING)

+ 30 - 0
src/web/WebRenderer.C

@@ -21,6 +21,7 @@
 #include "DomElement.h"
 #include "EscapeOStream.h"
 #include "FileServe.h"
+#include "FileUtils.h"
 #include "WebController.h"
 #include "WebRenderer.h"
 #include "WebRequest.h"
@@ -72,9 +73,34 @@ namespace skeletons {
   extern const char *Wt_js1;
   extern const char *Boot_js1;
   extern const char *JQuery_js1;
+  extern const char *LibreJS_js1;
 
   extern std::vector<const char *> JQuery_js();
   extern std::vector<const char *> Wt_js();
+
+  const std::string* ParseJsSources()
+  {
+    // libreJS header is used only if the server admin supplies a URL for
+    // at least one @source line in LIBREJS_FILENAME - e.g.
+    //     @source - https://example.net/wt-sources
+    const std::string LIBREJS_FILENAME = "libreJS_sources.txt";
+    const std::string* LIBREJS_SOURCES = Wt::FileUtils::fileToString(LIBREJS_FILENAME);
+    if (!LIBREJS_SOURCES) return nullptr;
+
+    std::string librejs_sources = *LIBREJS_SOURCES;
+    std::size_t sources_start = librejs_sources.find("@source ");
+    bool has_sources_line = sources_start != std::string::npos;
+    librejs_sources = (has_sources_line) ? librejs_sources.substr(sources_start + 8) : "";
+    bool has_http_source = librejs_sources.find(" http://") != std::string::npos;
+    bool has_https_source = librejs_sources.find(" https://") != std::string::npos;
+    bool has_ftp_source = librejs_sources.find(" ftp://") != std::string::npos;
+
+    return (has_http_source || has_https_source || has_ftp_source)? LIBREJS_SOURCES: nullptr;
+  }
+
+  const std::string* JS_SOURCES = ParseJsSources();
+  const std::string LIBREJS_HEADER = (!!JS_SOURCES) ? "/*\n" + *JS_SOURCES + LibreJS_js1 + "\n*/\n" : "";
+  const std::string LIBREJS_SCRIPT = (!!JS_SOURCES) ? "<script>\n" + LIBREJS_HEADER + "</script>\n" : "";
 }
 
 namespace Wt {
@@ -433,6 +459,8 @@ void WebRenderer::serveBootstrap(WebResponse& response)
     (noJsRedirectUrl,
      session_.bootstrapUrl(response, WebSession::KeepInternalPath) + "&js=no");
 
+  boot.setVar("LIBREJS_HEADER", skeletons::LIBREJS_SCRIPT);
+
   boot.setVar("REDIRECT_URL", noJsRedirectUrl.str());
   boot.setVar("AUTO_REDIRECT",
 	      "<noscript><meta http-equiv=\"refresh\" content=\"0; url="
@@ -944,6 +972,8 @@ void WebRenderer::serveMainscript(WebResponse& response)
 
   const bool innerHtml = true;
 
+  out << skeletons::LIBREJS_HEADER;
+
   if (serveSkeletons) {
     bool haveJQuery = app->customJQuery();
 

+ 1 - 0
src/web/skeleton/Boot.html

@@ -10,6 +10,7 @@ v\:* { behavior:url(#default#VML); position:absolute }
 </style>
 <script id="ie-deferred-loader" defer="defer" src="//:"></script>
 <![endif]-->
+_$_LIBREJS_HEADER_$_
 <script>
 /*<![CDATA[*/
 _$_BOOT_JS_$_

+ 30 - 0
src/web/skeleton/libreJS.js

@@ -0,0 +1,30 @@
+  @licstart - The following is the entire license notice for the
+  JavaScript code in this page.
+
+  Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  The code is distributed WITHOUT ANY WARRANTY;
+  without even the implied warranty of MERCHANTABILITY or FITNESS
+  FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.
+
+  As additional permission under GNU GPL version 3 section 7, you
+  may distribute non-source (e.g., minimized or compacted) forms of
+  that code without the copy of the GNU GPL normally required by
+  section 4, provided you include this license notice and a URL
+  through which recipients can access the Corresponding Source.
+
+  IMPORTANT:
+  The paragraphs above are slightly incorrect; but the current wording is
+  necessary in order to satisfy the LibreJS parser.  The actual license
+  of this javascript is the same as that of the greater WT framework,
+  which is currently GNU General Public License version 2 only, without
+  the option of any later version.  The full license text can be found in
+  the LICENSE file of the WT source code published at the @source URL above.
+
+  @licend - The above is the entire license notice
+  for the JavaScript code in this page.

+ 1 - 0
src/web/skeleton/libreJS_sources.example.txt

@@ -0,0 +1 @@
+  @source - https://example.org/wt-sources