├── .gitattributes ├── .gitignore ├── ISSUE_TEMPLATE.md ├── LICENSE ├── README.md ├── bin ├── DirectCOM.dll ├── VbFcgi.debug ├── VbFcgiApp.dll ├── VbFcgiApp.fcgi ├── VbFcgiLib.dll ├── downloads │ ├── test.pdf │ └── test.png ├── nginx │ ├── conf │ │ ├── fastcgi.conf │ │ ├── fastcgi_params │ │ ├── koi-utf │ │ ├── koi-win │ │ ├── mime.types │ │ ├── nginx.conf │ │ ├── scgi_params │ │ ├── uwsgi_params │ │ └── win-utf │ ├── contrib │ │ ├── README │ │ ├── geo2nginx.pl │ │ ├── unicode2nginx │ │ │ ├── koi-utf │ │ │ ├── unicode-to-nginx.pl │ │ │ └── win-utf │ │ └── vim │ │ │ ├── ftdetect │ │ │ └── nginx.vim │ │ │ ├── ftplugin │ │ │ └── nginx.vim │ │ │ ├── indent │ │ │ └── nginx.vim │ │ │ └── syntax │ │ │ └── nginx.vim │ ├── docs │ │ ├── CHANGES │ │ ├── CHANGES.ru │ │ ├── LICENSE │ │ ├── OpenSSL.LICENSE │ │ ├── PCRE.LICENCE │ │ ├── README │ │ └── zlib.LICENSE │ ├── html │ │ ├── 404.html │ │ ├── 50x.html │ │ ├── img │ │ │ ├── bg-pattern.png │ │ │ ├── logo.png │ │ │ └── time.png │ │ └── index.html │ └── nginx.exe ├── vbFcgiHost.exe ├── vbRichClient5.dll ├── vb_cairo_sqlite.dll └── vbml │ ├── index.vbml │ └── template_demo.vbml ├── docs └── img │ ├── diagram_processes.dia │ ├── diagram_processes.png │ └── screenshot_appdemo.png └── src ├── Shared ├── MApi.bas ├── MArrays.bas ├── MCollections.bas ├── MDates.bas ├── MEnv.bas ├── MLibs.bas ├── MMath.bas ├── MMime.bas ├── MPaths.bas └── MStrings.bas ├── VbFcgiAppDemo ├── CFcgiApp.cls ├── MImage.bas ├── MTests.bas ├── README.md ├── VbFcgiApp.vbp ├── frmImages.frm └── frmImages.frx ├── VbFcgiHostExe ├── MStartup.bas └── vbFcgiHostExe.vbp └── VbFcgiLibDll ├── CBuilderFile.cls ├── CBuilderHtml.cls ├── CBuilderJson.cls ├── CBuilderTemplate.cls ├── CBuilders.cls ├── CFcgi.cls ├── CFcgiDownstream.cls ├── CFcgiParams.cls ├── CFcgiRequest.cls ├── CFcgiResponse.cls ├── CFcgiServer.cls ├── CFcgiStdIn.cls ├── CFcgiStdOut.cls ├── CHttp.cls ├── CHttpCookie.cls ├── CHttpCookies.cls ├── CHttpHeader.cls ├── CHttpHeaderField.cls ├── CHttpHeaderFieldKeyValuePairs.cls ├── CHttpQueryParamValues.cls ├── CHttpQueryParams.cls ├── CSimulator.cls ├── CSimulatorFcgiApp.cls ├── CTests.cls ├── CWebStringBase.cls ├── CWebStringTemplate.cls ├── IBuilder.cls ├── IFcgiApp.cls ├── IJson.cls ├── MConfig.bas ├── MFcgi.bas ├── MHtml.bas ├── MTests.bas └── VbFcgiLib.vbp /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text eol=auto 3 | *.bas text eol=crlf 4 | *.frm text eol=crlf 5 | *.log text eol=crlf 6 | *.vbp text eol=crlf 7 | *.cls text eol=crlf 8 | *.vbw text eol=crlf 9 | *.dsr text eol=crlf 10 | *.ini text eol=crlf 11 | *.res binary 12 | *.RES binary 13 | *.frx binary 14 | *.exe binary 15 | *.dll binary 16 | *.ico binary 17 | *.gif binary 18 | *.ocx binary 19 | *.png binary 20 | *.pdf binary 21 | *.tlb binary 22 | *.ocx.bin binary 23 | *.ism binary 24 | *.bin binary 25 | *.aps binary 26 | *.ncb binary 27 | *.exe.compat binary 28 | *.ocx.compat binary 29 | *.fcgi binary 30 | bin/nginx/* linguist-vendored -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .Trashes 3 | *.vbw 4 | *.csi 5 | *.exp 6 | *.lib 7 | *.lvw 8 | *.dca 9 | *.scc 10 | *.tmp 11 | *.pid 12 | *.log -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### EXPECTED BEHAVIOUR 2 | 3 | 4 | 5 | ### ACTUAL BEHAVIOUR 6 | 7 | 8 | 9 | ### STEPS TO REPRODUCE THE BEHAVIOUR (OR OTHER NOTES/OBSERVATIONS/COMMENTS) 10 | 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jason Peter Brown 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VbFcgi 2 | Code your web application back-end in VB6! VbFcgi makes it easy to leverage your current programming knowledge and even get your existing VB6 client/server apps on the web. 3 | 4 | 5 | 6 | # Introduction 7 | VbFcgi is an FCGI Host/Server Framework for Visual Basic 6 (VB6) ActiveX/COM DLL Web Applications. It was developed against Nginx, but should work with any web server that implements the FCGI spec. 8 | 9 | # Process Diagram 10 | 11 | 12 | # Included Binaries 13 | There are 3 main components of the VbFcgi framework: 14 | 1. **VbFcgiLib.dll** - This is the main framework library that includes all of the code for listening and responding to FCGI requests from the web server, as well as parsing out records for FCGI parameters, HTTP cookies, etc... This file should be included with every distribution of your FCGI application. 15 | 2. **VbFcgiHost.exe** - This is main executable file that will spawn FCGI listeners as a broker between your webserver and your FCGI application. It includes support for running multiple listeners on sequential ports for load balancing, and it also monitors for terminated listeners that need respawning. Lastly, it also acts as a shutdown co-ordinator for all running FCGI listener instances. This file should be included with every distribution of your FCGI application. 16 | 3. **VbFcgiApp.dll** - This is the demo FCGI Application code. The version included here is a very basic proof-of-concept that will send an HTML page upstream with a table of the FCGI parameters that were received, also demonstrates the basic usage of cookies and HTTP query parameters This file should **not** be included when distributing your own FCGI application! Instead you should create your own version as described in the *Creating your own FCGI Application* section below. 17 | 18 | While the above DLLs are COM ActiveX libraries, you do NOT need to register them with regsvr32 when deploying to users since this code uses Olaf Schmidt's registration-free DirectCOM library. You should however register the above DLLs on your development machine. 19 | 20 | Also included is a binary build of Nginx with a basic configuration to support a single FCGI host server listener on localhost:9100. This is included for the sake of convenience and to demonstrate a minimal configuration. You should have your own properly configured Nginx (or other web server) running in most cases. 21 | 22 | Lastly, I've also bundled Olaf Schmidt's excellent vbRichClient5 library (http://www.vbrichclient.com/), again for the sake of convenience. You can always get the latest version from the vbRichClient5 website. 23 | 24 | # Demo Usage 25 | 1. If you don't already have a web server running, start nginx from the command-line by going to the .\VbFcgi\bin\nginx folder and then rnning the nginx.exe command. If you already have a web server running, make sure it is configured to pass *.fcgi requests from the browser upstream to 127.0.0.1 port 9100. 26 | 2. From the command line, start VbFcgiHost.exe with the following command: vbfcgihost.exe /host 127.0.0.1 /port 9100 /spawn 1 27 | 3. Open your browser and go to http://127.0.0.1/vbfcgiapp.fcgi - you should see the HTML response from the demo FCGI application. 28 | 29 | # Creating your own FCGI Application 30 | You can use the included VbFcgiApp source code as a starting point - all the work is done in the IFcgiApp_ProcessRequest method, so give it a thorough review. 31 | 32 | In order to write your own FCGI application from scratch, you must: 33 | 34 | 1. Start a new ActiveX DLL project in VB6. 35 | 2. Change the name of the project from "Project1" to "MyFcgiApp" (or whatever name you would like it to have). 36 | 3. Change the name of "Class1" to "CFcgiApp". 37 | 4. Add a reference to VbFcgiLib from the Projects menu > References. 38 | 5. In the General section of the "CFcgiApp" class, type; Implements VbFcgiLib.IFcgiApp 39 | 6. Select "IFcgiApp" from the drop down list in code view. It will create the IFcgiApp_ProcessRequest method for you. 40 | 7. Code your app in the IFcgiApp_ProcessRequest method (the rest of the f*cking owl). 41 | 8. Build your DLL app. 42 | 9. Make a copy of the built DLL and change the extension to .fcgi. 43 | 10. Move the .fcgi file to the same folder as the VbFcgiHost.exe and VbFcgiLib.dll files. 44 | 45 | **NOTE:** You do **not** need to register your FCGI application DLL, nor VbFcgiLib.dll when distributing it as registration-free instantiation is used by this framework. 46 | 47 | When you subsequently run the VbFcgiHost.exe, it will use your .fcgi as a "plugin" (of sorts) for responding to correspondng FCGI requests. For example, typing http://localhost/myapp.fcgi will cause VbFcgiHost to create an instance of the CFcgiApp class from the myapp.fcgi DLL stored in the same folder, and then it will call IFcgiApp_ProcessRequest in that class. 48 | 49 | Enjoy! -------------------------------------------------------------------------------- /bin/DirectCOM.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/bin/DirectCOM.dll -------------------------------------------------------------------------------- /bin/VbFcgi.debug: -------------------------------------------------------------------------------- 1 | The presence of this file in the same folder as an of the VbFcgi* DLLs or EXE enables debug mode (logging messages will be sent via OutputDebugString calls). 2 | 3 | You can safely delete this file at any time. -------------------------------------------------------------------------------- /bin/VbFcgiApp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/bin/VbFcgiApp.dll -------------------------------------------------------------------------------- /bin/VbFcgiApp.fcgi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/bin/VbFcgiApp.fcgi -------------------------------------------------------------------------------- /bin/VbFcgiLib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/bin/VbFcgiLib.dll -------------------------------------------------------------------------------- /bin/downloads/test.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/bin/downloads/test.pdf -------------------------------------------------------------------------------- /bin/downloads/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/bin/downloads/test.png -------------------------------------------------------------------------------- /bin/nginx/conf/fastcgi.conf: -------------------------------------------------------------------------------- 1 | 2 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 3 | fastcgi_param QUERY_STRING $query_string; 4 | fastcgi_param REQUEST_METHOD $request_method; 5 | fastcgi_param CONTENT_TYPE $content_type; 6 | fastcgi_param CONTENT_LENGTH $content_length; 7 | 8 | fastcgi_param SCRIPT_NAME $fastcgi_script_name; 9 | fastcgi_param REQUEST_URI $request_uri; 10 | fastcgi_param DOCUMENT_URI $document_uri; 11 | fastcgi_param DOCUMENT_ROOT $document_root; 12 | fastcgi_param SERVER_PROTOCOL $server_protocol; 13 | fastcgi_param REQUEST_SCHEME $scheme; 14 | fastcgi_param HTTPS $https if_not_empty; 15 | 16 | fastcgi_param GATEWAY_INTERFACE CGI/1.1; 17 | fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; 18 | 19 | fastcgi_param REMOTE_ADDR $remote_addr; 20 | fastcgi_param REMOTE_PORT $remote_port; 21 | fastcgi_param SERVER_ADDR $server_addr; 22 | fastcgi_param SERVER_PORT $server_port; 23 | fastcgi_param SERVER_NAME $server_name; 24 | 25 | # PHP only, required if PHP was built with --enable-force-cgi-redirect 26 | fastcgi_param REDIRECT_STATUS 200; 27 | -------------------------------------------------------------------------------- /bin/nginx/conf/fastcgi_params: -------------------------------------------------------------------------------- 1 | 2 | fastcgi_param QUERY_STRING $query_string; 3 | fastcgi_param REQUEST_METHOD $request_method; 4 | fastcgi_param CONTENT_TYPE $content_type; 5 | fastcgi_param CONTENT_LENGTH $content_length; 6 | 7 | fastcgi_param SCRIPT_NAME $fastcgi_script_name; 8 | fastcgi_param REQUEST_URI $request_uri; 9 | fastcgi_param DOCUMENT_URI $document_uri; 10 | fastcgi_param DOCUMENT_ROOT $document_root; 11 | fastcgi_param SERVER_PROTOCOL $server_protocol; 12 | fastcgi_param REQUEST_SCHEME $scheme; 13 | fastcgi_param HTTPS $https if_not_empty; 14 | 15 | fastcgi_param GATEWAY_INTERFACE CGI/1.1; 16 | fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; 17 | 18 | fastcgi_param REMOTE_ADDR $remote_addr; 19 | fastcgi_param REMOTE_PORT $remote_port; 20 | fastcgi_param SERVER_ADDR $server_addr; 21 | fastcgi_param SERVER_PORT $server_port; 22 | fastcgi_param SERVER_NAME $server_name; 23 | 24 | # PHP only, required if PHP was built with --enable-force-cgi-redirect 25 | fastcgi_param REDIRECT_STATUS 200; 26 | -------------------------------------------------------------------------------- /bin/nginx/conf/koi-utf: -------------------------------------------------------------------------------- 1 | 2 | # This map is not a full koi8-r <> utf8 map: it does not contain 3 | # box-drawing and some other characters. Besides this map contains 4 | # several koi8-u and Byelorussian letters which are not in koi8-r. 5 | # If you need a full and standard map, use contrib/unicode2nginx/koi-utf 6 | # map instead. 7 | 8 | charset_map koi8-r utf-8 { 9 | 10 | 80 E282AC ; # euro 11 | 12 | 95 E280A2 ; # bullet 13 | 14 | 9A C2A0 ; #   15 | 16 | 9E C2B7 ; # · 17 | 18 | A3 D191 ; # small yo 19 | A4 D194 ; # small Ukrainian ye 20 | 21 | A6 D196 ; # small Ukrainian i 22 | A7 D197 ; # small Ukrainian yi 23 | 24 | AD D291 ; # small Ukrainian soft g 25 | AE D19E ; # small Byelorussian short u 26 | 27 | B0 C2B0 ; # ° 28 | 29 | B3 D081 ; # capital YO 30 | B4 D084 ; # capital Ukrainian YE 31 | 32 | B6 D086 ; # capital Ukrainian I 33 | B7 D087 ; # capital Ukrainian YI 34 | 35 | B9 E28496 ; # numero sign 36 | 37 | BD D290 ; # capital Ukrainian soft G 38 | BE D18E ; # capital Byelorussian short U 39 | 40 | BF C2A9 ; # (C) 41 | 42 | C0 D18E ; # small yu 43 | C1 D0B0 ; # small a 44 | C2 D0B1 ; # small b 45 | C3 D186 ; # small ts 46 | C4 D0B4 ; # small d 47 | C5 D0B5 ; # small ye 48 | C6 D184 ; # small f 49 | C7 D0B3 ; # small g 50 | C8 D185 ; # small kh 51 | C9 D0B8 ; # small i 52 | CA D0B9 ; # small j 53 | CB D0BA ; # small k 54 | CC D0BB ; # small l 55 | CD D0BC ; # small m 56 | CE D0BD ; # small n 57 | CF D0BE ; # small o 58 | 59 | D0 D0BF ; # small p 60 | D1 D18F ; # small ya 61 | D2 D180 ; # small r 62 | D3 D181 ; # small s 63 | D4 D182 ; # small t 64 | D5 D183 ; # small u 65 | D6 D0B6 ; # small zh 66 | D7 D0B2 ; # small v 67 | D8 D18C ; # small soft sign 68 | D9 D18B ; # small y 69 | DA D0B7 ; # small z 70 | DB D188 ; # small sh 71 | DC D18D ; # small e 72 | DD D189 ; # small shch 73 | DE D187 ; # small ch 74 | DF D18A ; # small hard sign 75 | 76 | E0 D0AE ; # capital YU 77 | E1 D090 ; # capital A 78 | E2 D091 ; # capital B 79 | E3 D0A6 ; # capital TS 80 | E4 D094 ; # capital D 81 | E5 D095 ; # capital YE 82 | E6 D0A4 ; # capital F 83 | E7 D093 ; # capital G 84 | E8 D0A5 ; # capital KH 85 | E9 D098 ; # capital I 86 | EA D099 ; # capital J 87 | EB D09A ; # capital K 88 | EC D09B ; # capital L 89 | ED D09C ; # capital M 90 | EE D09D ; # capital N 91 | EF D09E ; # capital O 92 | 93 | F0 D09F ; # capital P 94 | F1 D0AF ; # capital YA 95 | F2 D0A0 ; # capital R 96 | F3 D0A1 ; # capital S 97 | F4 D0A2 ; # capital T 98 | F5 D0A3 ; # capital U 99 | F6 D096 ; # capital ZH 100 | F7 D092 ; # capital V 101 | F8 D0AC ; # capital soft sign 102 | F9 D0AB ; # capital Y 103 | FA D097 ; # capital Z 104 | FB D0A8 ; # capital SH 105 | FC D0AD ; # capital E 106 | FD D0A9 ; # capital SHCH 107 | FE D0A7 ; # capital CH 108 | FF D0AA ; # capital hard sign 109 | } 110 | -------------------------------------------------------------------------------- /bin/nginx/conf/koi-win: -------------------------------------------------------------------------------- 1 | 2 | charset_map koi8-r windows-1251 { 3 | 4 | 80 88 ; # euro 5 | 6 | 95 95 ; # bullet 7 | 8 | 9A A0 ; #   9 | 10 | 9E B7 ; # · 11 | 12 | A3 B8 ; # small yo 13 | A4 BA ; # small Ukrainian ye 14 | 15 | A6 B3 ; # small Ukrainian i 16 | A7 BF ; # small Ukrainian yi 17 | 18 | AD B4 ; # small Ukrainian soft g 19 | AE A2 ; # small Byelorussian short u 20 | 21 | B0 B0 ; # ° 22 | 23 | B3 A8 ; # capital YO 24 | B4 AA ; # capital Ukrainian YE 25 | 26 | B6 B2 ; # capital Ukrainian I 27 | B7 AF ; # capital Ukrainian YI 28 | 29 | B9 B9 ; # numero sign 30 | 31 | BD A5 ; # capital Ukrainian soft G 32 | BE A1 ; # capital Byelorussian short U 33 | 34 | BF A9 ; # (C) 35 | 36 | C0 FE ; # small yu 37 | C1 E0 ; # small a 38 | C2 E1 ; # small b 39 | C3 F6 ; # small ts 40 | C4 E4 ; # small d 41 | C5 E5 ; # small ye 42 | C6 F4 ; # small f 43 | C7 E3 ; # small g 44 | C8 F5 ; # small kh 45 | C9 E8 ; # small i 46 | CA E9 ; # small j 47 | CB EA ; # small k 48 | CC EB ; # small l 49 | CD EC ; # small m 50 | CE ED ; # small n 51 | CF EE ; # small o 52 | 53 | D0 EF ; # small p 54 | D1 FF ; # small ya 55 | D2 F0 ; # small r 56 | D3 F1 ; # small s 57 | D4 F2 ; # small t 58 | D5 F3 ; # small u 59 | D6 E6 ; # small zh 60 | D7 E2 ; # small v 61 | D8 FC ; # small soft sign 62 | D9 FB ; # small y 63 | DA E7 ; # small z 64 | DB F8 ; # small sh 65 | DC FD ; # small e 66 | DD F9 ; # small shch 67 | DE F7 ; # small ch 68 | DF FA ; # small hard sign 69 | 70 | E0 DE ; # capital YU 71 | E1 C0 ; # capital A 72 | E2 C1 ; # capital B 73 | E3 D6 ; # capital TS 74 | E4 C4 ; # capital D 75 | E5 C5 ; # capital YE 76 | E6 D4 ; # capital F 77 | E7 C3 ; # capital G 78 | E8 D5 ; # capital KH 79 | E9 C8 ; # capital I 80 | EA C9 ; # capital J 81 | EB CA ; # capital K 82 | EC CB ; # capital L 83 | ED CC ; # capital M 84 | EE CD ; # capital N 85 | EF CE ; # capital O 86 | 87 | F0 CF ; # capital P 88 | F1 DF ; # capital YA 89 | F2 D0 ; # capital R 90 | F3 D1 ; # capital S 91 | F4 D2 ; # capital T 92 | F5 D3 ; # capital U 93 | F6 C6 ; # capital ZH 94 | F7 C2 ; # capital V 95 | F8 DC ; # capital soft sign 96 | F9 DB ; # capital Y 97 | FA C7 ; # capital Z 98 | FB D8 ; # capital SH 99 | FC DD ; # capital E 100 | FD D9 ; # capital SHCH 101 | FE D7 ; # capital CH 102 | FF DA ; # capital hard sign 103 | } 104 | -------------------------------------------------------------------------------- /bin/nginx/conf/mime.types: -------------------------------------------------------------------------------- 1 | 2 | types { 3 | text/html html htm shtml; 4 | text/css css; 5 | text/xml xml; 6 | image/gif gif; 7 | image/jpeg jpeg jpg; 8 | application/javascript js; 9 | application/atom+xml atom; 10 | application/rss+xml rss; 11 | 12 | text/mathml mml; 13 | text/plain txt; 14 | text/vnd.sun.j2me.app-descriptor jad; 15 | text/vnd.wap.wml wml; 16 | text/x-component htc; 17 | 18 | image/png png; 19 | image/svg+xml svg svgz; 20 | image/tiff tif tiff; 21 | image/vnd.wap.wbmp wbmp; 22 | image/webp webp; 23 | image/x-icon ico; 24 | image/x-jng jng; 25 | image/x-ms-bmp bmp; 26 | 27 | application/font-woff woff; 28 | application/java-archive jar war ear; 29 | application/json json; 30 | application/mac-binhex40 hqx; 31 | application/msword doc; 32 | application/pdf pdf; 33 | application/postscript ps eps ai; 34 | application/rtf rtf; 35 | application/vnd.apple.mpegurl m3u8; 36 | application/vnd.google-earth.kml+xml kml; 37 | application/vnd.google-earth.kmz kmz; 38 | application/vnd.ms-excel xls; 39 | application/vnd.ms-fontobject eot; 40 | application/vnd.ms-powerpoint ppt; 41 | application/vnd.oasis.opendocument.graphics odg; 42 | application/vnd.oasis.opendocument.presentation odp; 43 | application/vnd.oasis.opendocument.spreadsheet ods; 44 | application/vnd.oasis.opendocument.text odt; 45 | application/vnd.openxmlformats-officedocument.presentationml.presentation 46 | pptx; 47 | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 48 | xlsx; 49 | application/vnd.openxmlformats-officedocument.wordprocessingml.document 50 | docx; 51 | application/vnd.wap.wmlc wmlc; 52 | application/x-7z-compressed 7z; 53 | application/x-cocoa cco; 54 | application/x-java-archive-diff jardiff; 55 | application/x-java-jnlp-file jnlp; 56 | application/x-makeself run; 57 | application/x-perl pl pm; 58 | application/x-pilot prc pdb; 59 | application/x-rar-compressed rar; 60 | application/x-redhat-package-manager rpm; 61 | application/x-sea sea; 62 | application/x-shockwave-flash swf; 63 | application/x-stuffit sit; 64 | application/x-tcl tcl tk; 65 | application/x-x509-ca-cert der pem crt; 66 | application/x-xpinstall xpi; 67 | application/xhtml+xml xhtml; 68 | application/xspf+xml xspf; 69 | application/zip zip; 70 | 71 | application/octet-stream bin exe dll; 72 | application/octet-stream deb; 73 | application/octet-stream dmg; 74 | application/octet-stream iso img; 75 | application/octet-stream msi msp msm; 76 | 77 | audio/midi mid midi kar; 78 | audio/mpeg mp3; 79 | audio/ogg ogg; 80 | audio/x-m4a m4a; 81 | audio/x-realaudio ra; 82 | 83 | video/3gpp 3gpp 3gp; 84 | video/mp2t ts; 85 | video/mp4 mp4; 86 | video/mpeg mpeg mpg; 87 | video/quicktime mov; 88 | video/webm webm; 89 | video/x-flv flv; 90 | video/x-m4v m4v; 91 | video/x-mng mng; 92 | video/x-ms-asf asx asf; 93 | video/x-ms-wmv wmv; 94 | video/x-msvideo avi; 95 | } 96 | -------------------------------------------------------------------------------- /bin/nginx/conf/nginx.conf: -------------------------------------------------------------------------------- 1 | worker_processes 1; 2 | 3 | #error_log logs/error.log; 4 | #error_log logs/error.log notice; 5 | #error_log logs/error.log info; 6 | 7 | events { 8 | worker_connections 1024; 9 | } 10 | 11 | http { 12 | limit_req_zone $binary_remote_addr zone=mylimit:1m rate=4r/s; 13 | 14 | upstream backend { 15 | # Load-balancing across multiple FCGI listeners defined below 16 | server 127.0.0.1:9100; 17 | } 18 | 19 | include mime.types; 20 | default_type application/octet-stream; 21 | 22 | access_log logs/access.log; 23 | error_log logs/error.log error; 24 | 25 | sendfile on; 26 | 27 | keepalive_timeout 65; 28 | 29 | server { 30 | listen 80; 31 | server_name localhost; 32 | 33 | error_page 404 /404.html; 34 | error_page 500 502 503 504 /50x.html; 35 | 36 | location / { 37 | root html; 38 | index index.html index.htm; 39 | } 40 | 41 | # pass the FCGI scripts to FastCGI server listening on upstream "backend" 42 | location ~ \.(fcgi|vbml)$ { 43 | limit_req zone=mylimit burst=20; 44 | 45 | root html; 46 | fastcgi_keep_conn on; 47 | fastcgi_pass backend; 48 | fastcgi_index index.html; 49 | fastcgi_split_path_info ^(.*cgi)(/.*)$; 50 | fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; 51 | fastcgi_param PATH_INFO $fastcgi_path_info; 52 | fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 53 | fastcgi_intercept_errors on; 54 | include fastcgi_params; 55 | } 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /bin/nginx/conf/scgi_params: -------------------------------------------------------------------------------- 1 | 2 | scgi_param REQUEST_METHOD $request_method; 3 | scgi_param REQUEST_URI $request_uri; 4 | scgi_param QUERY_STRING $query_string; 5 | scgi_param CONTENT_TYPE $content_type; 6 | 7 | scgi_param DOCUMENT_URI $document_uri; 8 | scgi_param DOCUMENT_ROOT $document_root; 9 | scgi_param SCGI 1; 10 | scgi_param SERVER_PROTOCOL $server_protocol; 11 | scgi_param REQUEST_SCHEME $scheme; 12 | scgi_param HTTPS $https if_not_empty; 13 | 14 | scgi_param REMOTE_ADDR $remote_addr; 15 | scgi_param REMOTE_PORT $remote_port; 16 | scgi_param SERVER_PORT $server_port; 17 | scgi_param SERVER_NAME $server_name; 18 | -------------------------------------------------------------------------------- /bin/nginx/conf/uwsgi_params: -------------------------------------------------------------------------------- 1 | 2 | uwsgi_param QUERY_STRING $query_string; 3 | uwsgi_param REQUEST_METHOD $request_method; 4 | uwsgi_param CONTENT_TYPE $content_type; 5 | uwsgi_param CONTENT_LENGTH $content_length; 6 | 7 | uwsgi_param REQUEST_URI $request_uri; 8 | uwsgi_param PATH_INFO $document_uri; 9 | uwsgi_param DOCUMENT_ROOT $document_root; 10 | uwsgi_param SERVER_PROTOCOL $server_protocol; 11 | uwsgi_param REQUEST_SCHEME $scheme; 12 | uwsgi_param HTTPS $https if_not_empty; 13 | 14 | uwsgi_param REMOTE_ADDR $remote_addr; 15 | uwsgi_param REMOTE_PORT $remote_port; 16 | uwsgi_param SERVER_PORT $server_port; 17 | uwsgi_param SERVER_NAME $server_name; 18 | -------------------------------------------------------------------------------- /bin/nginx/conf/win-utf: -------------------------------------------------------------------------------- 1 | 2 | # This map is not a full windows-1251 <> utf8 map: it does not 3 | # contain Serbian and Macedonian letters. If you need a full map, 4 | # use contrib/unicode2nginx/win-utf map instead. 5 | 6 | charset_map windows-1251 utf-8 { 7 | 8 | 82 E2809A ; # single low-9 quotation mark 9 | 10 | 84 E2809E ; # double low-9 quotation mark 11 | 85 E280A6 ; # ellipsis 12 | 86 E280A0 ; # dagger 13 | 87 E280A1 ; # double dagger 14 | 88 E282AC ; # euro 15 | 89 E280B0 ; # per mille 16 | 17 | 91 E28098 ; # left single quotation mark 18 | 92 E28099 ; # right single quotation mark 19 | 93 E2809C ; # left double quotation mark 20 | 94 E2809D ; # right double quotation mark 21 | 95 E280A2 ; # bullet 22 | 96 E28093 ; # en dash 23 | 97 E28094 ; # em dash 24 | 25 | 99 E284A2 ; # trade mark sign 26 | 27 | A0 C2A0 ; #   28 | A1 D18E ; # capital Byelorussian short U 29 | A2 D19E ; # small Byelorussian short u 30 | 31 | A4 C2A4 ; # currency sign 32 | A5 D290 ; # capital Ukrainian soft G 33 | A6 C2A6 ; # borken bar 34 | A7 C2A7 ; # section sign 35 | A8 D081 ; # capital YO 36 | A9 C2A9 ; # (C) 37 | AA D084 ; # capital Ukrainian YE 38 | AB C2AB ; # left-pointing double angle quotation mark 39 | AC C2AC ; # not sign 40 | AD C2AD ; # soft hypen 41 | AE C2AE ; # (R) 42 | AF D087 ; # capital Ukrainian YI 43 | 44 | B0 C2B0 ; # ° 45 | B1 C2B1 ; # plus-minus sign 46 | B2 D086 ; # capital Ukrainian I 47 | B3 D196 ; # small Ukrainian i 48 | B4 D291 ; # small Ukrainian soft g 49 | B5 C2B5 ; # micro sign 50 | B6 C2B6 ; # pilcrow sign 51 | B7 C2B7 ; # · 52 | B8 D191 ; # small yo 53 | B9 E28496 ; # numero sign 54 | BA D194 ; # small Ukrainian ye 55 | BB C2BB ; # right-pointing double angle quotation mark 56 | 57 | BF D197 ; # small Ukrainian yi 58 | 59 | C0 D090 ; # capital A 60 | C1 D091 ; # capital B 61 | C2 D092 ; # capital V 62 | C3 D093 ; # capital G 63 | C4 D094 ; # capital D 64 | C5 D095 ; # capital YE 65 | C6 D096 ; # capital ZH 66 | C7 D097 ; # capital Z 67 | C8 D098 ; # capital I 68 | C9 D099 ; # capital J 69 | CA D09A ; # capital K 70 | CB D09B ; # capital L 71 | CC D09C ; # capital M 72 | CD D09D ; # capital N 73 | CE D09E ; # capital O 74 | CF D09F ; # capital P 75 | 76 | D0 D0A0 ; # capital R 77 | D1 D0A1 ; # capital S 78 | D2 D0A2 ; # capital T 79 | D3 D0A3 ; # capital U 80 | D4 D0A4 ; # capital F 81 | D5 D0A5 ; # capital KH 82 | D6 D0A6 ; # capital TS 83 | D7 D0A7 ; # capital CH 84 | D8 D0A8 ; # capital SH 85 | D9 D0A9 ; # capital SHCH 86 | DA D0AA ; # capital hard sign 87 | DB D0AB ; # capital Y 88 | DC D0AC ; # capital soft sign 89 | DD D0AD ; # capital E 90 | DE D0AE ; # capital YU 91 | DF D0AF ; # capital YA 92 | 93 | E0 D0B0 ; # small a 94 | E1 D0B1 ; # small b 95 | E2 D0B2 ; # small v 96 | E3 D0B3 ; # small g 97 | E4 D0B4 ; # small d 98 | E5 D0B5 ; # small ye 99 | E6 D0B6 ; # small zh 100 | E7 D0B7 ; # small z 101 | E8 D0B8 ; # small i 102 | E9 D0B9 ; # small j 103 | EA D0BA ; # small k 104 | EB D0BB ; # small l 105 | EC D0BC ; # small m 106 | ED D0BD ; # small n 107 | EE D0BE ; # small o 108 | EF D0BF ; # small p 109 | 110 | F0 D180 ; # small r 111 | F1 D181 ; # small s 112 | F2 D182 ; # small t 113 | F3 D183 ; # small u 114 | F4 D184 ; # small f 115 | F5 D185 ; # small kh 116 | F6 D186 ; # small ts 117 | F7 D187 ; # small ch 118 | F8 D188 ; # small sh 119 | F9 D189 ; # small shch 120 | FA D18A ; # small hard sign 121 | FB D18B ; # small y 122 | FC D18C ; # small soft sign 123 | FD D18D ; # small e 124 | FE D18E ; # small yu 125 | FF D18F ; # small ya 126 | } 127 | -------------------------------------------------------------------------------- /bin/nginx/contrib/README: -------------------------------------------------------------------------------- 1 | 2 | geo2nginx.pl by Andrei Nigmatulin 3 | 4 | The perl script to convert CSV geoip database ( free download 5 | at http://www.maxmind.com/app/geoip_country ) to format, suitable 6 | for use by the ngx_http_geo_module. 7 | 8 | 9 | unicode2nginx by Maxim Dounin 10 | 11 | The perl script to convert unicode mappings ( available 12 | at http://www.unicode.org/Public/MAPPINGS/ ) to the nginx 13 | configuration file format. 14 | Two generated full maps for windows-1251 and koi8-r. 15 | 16 | 17 | vim by Evan Miller 18 | 19 | Syntax highlighting of nginx configuration for vim, to be 20 | placed into ~/.vim/. 21 | 22 | -------------------------------------------------------------------------------- /bin/nginx/contrib/geo2nginx.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # (c) Andrei Nigmatulin, 2005 4 | # 5 | # this script provided "as is", without any warranties. use it at your own risk. 6 | # 7 | # special thanx to Andrew Sitnikov for perl port 8 | # 9 | # this script converts CSV geoip database (free download at http://www.maxmind.com/app/geoip_country) 10 | # to format, suitable for use with nginx_http_geo module (http://sysoev.ru/nginx) 11 | # 12 | # for example, line with ip range 13 | # 14 | # "62.16.68.0","62.16.127.255","1041253376","1041268735","RU","Russian Federation" 15 | # 16 | # will be converted to four subnetworks: 17 | # 18 | # 62.16.68.0/22 RU; 19 | # 62.16.72.0/21 RU; 20 | # 62.16.80.0/20 RU; 21 | # 62.16.96.0/19 RU; 22 | 23 | 24 | use warnings; 25 | use strict; 26 | 27 | while( ){ 28 | if (/"[^"]+","[^"]+","([^"]+)","([^"]+)","([^"]+)"/){ 29 | print_subnets($1, $2, $3); 30 | } 31 | } 32 | 33 | sub print_subnets { 34 | my ($a1, $a2, $c) = @_; 35 | my $l; 36 | while ($a1 <= $a2) { 37 | for ($l = 0; ($a1 & (1 << $l)) == 0 && ($a1 + ((1 << ($l + 1)) - 1)) <= $a2; $l++){}; 38 | print long2ip($a1) . "/" . (32 - $l) . " " . $c . ";\n"; 39 | $a1 += (1 << $l); 40 | } 41 | } 42 | 43 | sub long2ip { 44 | my $ip = shift; 45 | 46 | my $str = 0; 47 | 48 | $str = ($ip & 255); 49 | 50 | $ip >>= 8; 51 | $str = ($ip & 255).".$str"; 52 | 53 | $ip >>= 8; 54 | $str = ($ip & 255).".$str"; 55 | 56 | $ip >>= 8; 57 | $str = ($ip & 255).".$str"; 58 | } 59 | -------------------------------------------------------------------------------- /bin/nginx/contrib/unicode2nginx/koi-utf: -------------------------------------------------------------------------------- 1 | charset_map koi8-r utf-8 { 2 | 3 | 80 E29480 ; # BOX DRAWINGS LIGHT HORIZONTAL 4 | 81 E29482 ; # BOX DRAWINGS LIGHT VERTICAL 5 | 82 E2948C ; # BOX DRAWINGS LIGHT DOWN AND RIGHT 6 | 83 E29490 ; # BOX DRAWINGS LIGHT DOWN AND LEFT 7 | 84 E29494 ; # BOX DRAWINGS LIGHT UP AND RIGHT 8 | 85 E29498 ; # BOX DRAWINGS LIGHT UP AND LEFT 9 | 86 E2949C ; # BOX DRAWINGS LIGHT VERTICAL AND RIGHT 10 | 87 E294A4 ; # BOX DRAWINGS LIGHT VERTICAL AND LEFT 11 | 88 E294AC ; # BOX DRAWINGS LIGHT DOWN AND HORIZONTAL 12 | 89 E294B4 ; # BOX DRAWINGS LIGHT UP AND HORIZONTAL 13 | 8A E294BC ; # BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL 14 | 8B E29680 ; # UPPER HALF BLOCK 15 | 8C E29684 ; # LOWER HALF BLOCK 16 | 8D E29688 ; # FULL BLOCK 17 | 8E E2968C ; # LEFT HALF BLOCK 18 | 8F E29690 ; # RIGHT HALF BLOCK 19 | 90 E29691 ; # LIGHT SHADE 20 | 91 E29692 ; # MEDIUM SHADE 21 | 92 E29693 ; # DARK SHADE 22 | 93 E28CA0 ; # TOP HALF INTEGRAL 23 | 94 E296A0 ; # BLACK SQUARE 24 | 95 E28899 ; # BULLET OPERATOR 25 | 96 E2889A ; # SQUARE ROOT 26 | 97 E28988 ; # ALMOST EQUAL TO 27 | 98 E289A4 ; # LESS-THAN OR EQUAL TO 28 | 99 E289A5 ; # GREATER-THAN OR EQUAL TO 29 | 9A C2A0 ; # NO-BREAK SPACE 30 | 9B E28CA1 ; # BOTTOM HALF INTEGRAL 31 | 9C C2B0 ; # DEGREE SIGN 32 | 9D C2B2 ; # SUPERSCRIPT TWO 33 | 9E C2B7 ; # MIDDLE DOT 34 | 9F C3B7 ; # DIVISION SIGN 35 | A0 E29590 ; # BOX DRAWINGS DOUBLE HORIZONTAL 36 | A1 E29591 ; # BOX DRAWINGS DOUBLE VERTICAL 37 | A2 E29592 ; # BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE 38 | A3 D191 ; # CYRILLIC SMALL LETTER IO 39 | A4 E29593 ; # BOX DRAWINGS DOWN DOUBLE AND RIGHT SINGLE 40 | A5 E29594 ; # BOX DRAWINGS DOUBLE DOWN AND RIGHT 41 | A6 E29595 ; # BOX DRAWINGS DOWN SINGLE AND LEFT DOUBLE 42 | A7 E29596 ; # BOX DRAWINGS DOWN DOUBLE AND LEFT SINGLE 43 | A8 E29597 ; # BOX DRAWINGS DOUBLE DOWN AND LEFT 44 | A9 E29598 ; # BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE 45 | AA E29599 ; # BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE 46 | AB E2959A ; # BOX DRAWINGS DOUBLE UP AND RIGHT 47 | AC E2959B ; # BOX DRAWINGS UP SINGLE AND LEFT DOUBLE 48 | AD E2959C ; # BOX DRAWINGS UP DOUBLE AND LEFT SINGLE 49 | AE E2959D ; # BOX DRAWINGS DOUBLE UP AND LEFT 50 | AF E2959E ; # BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE 51 | B0 E2959F ; # BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE 52 | B1 E295A0 ; # BOX DRAWINGS DOUBLE VERTICAL AND RIGHT 53 | B2 E295A1 ; # BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE 54 | B3 D081 ; # CYRILLIC CAPITAL LETTER IO 55 | B4 E295A2 ; # BOX DRAWINGS VERTICAL DOUBLE AND LEFT SINGLE 56 | B5 E295A3 ; # BOX DRAWINGS DOUBLE VERTICAL AND LEFT 57 | B6 E295A4 ; # BOX DRAWINGS DOWN SINGLE AND HORIZONTAL DOUBLE 58 | B7 E295A5 ; # BOX DRAWINGS DOWN DOUBLE AND HORIZONTAL SINGLE 59 | B8 E295A6 ; # BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL 60 | B9 E295A7 ; # BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE 61 | BA E295A8 ; # BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE 62 | BB E295A9 ; # BOX DRAWINGS DOUBLE UP AND HORIZONTAL 63 | BC E295AA ; # BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE 64 | BD E295AB ; # BOX DRAWINGS VERTICAL DOUBLE AND HORIZONTAL SINGLE 65 | BE E295AC ; # BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL 66 | BF C2A9 ; # COPYRIGHT SIGN 67 | C0 D18E ; # CYRILLIC SMALL LETTER YU 68 | C1 D0B0 ; # CYRILLIC SMALL LETTER A 69 | C2 D0B1 ; # CYRILLIC SMALL LETTER BE 70 | C3 D186 ; # CYRILLIC SMALL LETTER TSE 71 | C4 D0B4 ; # CYRILLIC SMALL LETTER DE 72 | C5 D0B5 ; # CYRILLIC SMALL LETTER IE 73 | C6 D184 ; # CYRILLIC SMALL LETTER EF 74 | C7 D0B3 ; # CYRILLIC SMALL LETTER GHE 75 | C8 D185 ; # CYRILLIC SMALL LETTER HA 76 | C9 D0B8 ; # CYRILLIC SMALL LETTER I 77 | CA D0B9 ; # CYRILLIC SMALL LETTER SHORT I 78 | CB D0BA ; # CYRILLIC SMALL LETTER KA 79 | CC D0BB ; # CYRILLIC SMALL LETTER EL 80 | CD D0BC ; # CYRILLIC SMALL LETTER EM 81 | CE D0BD ; # CYRILLIC SMALL LETTER EN 82 | CF D0BE ; # CYRILLIC SMALL LETTER O 83 | D0 D0BF ; # CYRILLIC SMALL LETTER PE 84 | D1 D18F ; # CYRILLIC SMALL LETTER YA 85 | D2 D180 ; # CYRILLIC SMALL LETTER ER 86 | D3 D181 ; # CYRILLIC SMALL LETTER ES 87 | D4 D182 ; # CYRILLIC SMALL LETTER TE 88 | D5 D183 ; # CYRILLIC SMALL LETTER U 89 | D6 D0B6 ; # CYRILLIC SMALL LETTER ZHE 90 | D7 D0B2 ; # CYRILLIC SMALL LETTER VE 91 | D8 D18C ; # CYRILLIC SMALL LETTER SOFT SIGN 92 | D9 D18B ; # CYRILLIC SMALL LETTER YERU 93 | DA D0B7 ; # CYRILLIC SMALL LETTER ZE 94 | DB D188 ; # CYRILLIC SMALL LETTER SHA 95 | DC D18D ; # CYRILLIC SMALL LETTER E 96 | DD D189 ; # CYRILLIC SMALL LETTER SHCHA 97 | DE D187 ; # CYRILLIC SMALL LETTER CHE 98 | DF D18A ; # CYRILLIC SMALL LETTER HARD SIGN 99 | E0 D0AE ; # CYRILLIC CAPITAL LETTER YU 100 | E1 D090 ; # CYRILLIC CAPITAL LETTER A 101 | E2 D091 ; # CYRILLIC CAPITAL LETTER BE 102 | E3 D0A6 ; # CYRILLIC CAPITAL LETTER TSE 103 | E4 D094 ; # CYRILLIC CAPITAL LETTER DE 104 | E5 D095 ; # CYRILLIC CAPITAL LETTER IE 105 | E6 D0A4 ; # CYRILLIC CAPITAL LETTER EF 106 | E7 D093 ; # CYRILLIC CAPITAL LETTER GHE 107 | E8 D0A5 ; # CYRILLIC CAPITAL LETTER HA 108 | E9 D098 ; # CYRILLIC CAPITAL LETTER I 109 | EA D099 ; # CYRILLIC CAPITAL LETTER SHORT I 110 | EB D09A ; # CYRILLIC CAPITAL LETTER KA 111 | EC D09B ; # CYRILLIC CAPITAL LETTER EL 112 | ED D09C ; # CYRILLIC CAPITAL LETTER EM 113 | EE D09D ; # CYRILLIC CAPITAL LETTER EN 114 | EF D09E ; # CYRILLIC CAPITAL LETTER O 115 | F0 D09F ; # CYRILLIC CAPITAL LETTER PE 116 | F1 D0AF ; # CYRILLIC CAPITAL LETTER YA 117 | F2 D0A0 ; # CYRILLIC CAPITAL LETTER ER 118 | F3 D0A1 ; # CYRILLIC CAPITAL LETTER ES 119 | F4 D0A2 ; # CYRILLIC CAPITAL LETTER TE 120 | F5 D0A3 ; # CYRILLIC CAPITAL LETTER U 121 | F6 D096 ; # CYRILLIC CAPITAL LETTER ZHE 122 | F7 D092 ; # CYRILLIC CAPITAL LETTER VE 123 | F8 D0AC ; # CYRILLIC CAPITAL LETTER SOFT SIGN 124 | F9 D0AB ; # CYRILLIC CAPITAL LETTER YERU 125 | FA D097 ; # CYRILLIC CAPITAL LETTER ZE 126 | FB D0A8 ; # CYRILLIC CAPITAL LETTER SHA 127 | FC D0AD ; # CYRILLIC CAPITAL LETTER E 128 | FD D0A9 ; # CYRILLIC CAPITAL LETTER SHCHA 129 | FE D0A7 ; # CYRILLIC CAPITAL LETTER CHE 130 | FF D0AA ; # CYRILLIC CAPITAL LETTER HARD SIGN 131 | } 132 | -------------------------------------------------------------------------------- /bin/nginx/contrib/unicode2nginx/unicode-to-nginx.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # Convert unicode mappings to nginx configuration file format. 4 | 5 | # You may find useful mappings in various places, including 6 | # unicode.org official site: 7 | # 8 | # http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1251.TXT 9 | # http://www.unicode.org/Public/MAPPINGS/VENDORS/MISC/KOI8-R.TXT 10 | 11 | # Needs perl 5.6 or later. 12 | 13 | # Written by Maxim Dounin, mdounin@mdounin.ru 14 | 15 | ############################################################################### 16 | 17 | require 5.006; 18 | 19 | while (<>) { 20 | # Skip comments and empty lines 21 | 22 | next if /^#/; 23 | next if /^\s*$/; 24 | chomp; 25 | 26 | # Convert mappings 27 | 28 | if (/^\s*0x(..)\s*0x(....)\s*(#.*)/) { 29 | # Mapping "#" 30 | my $cs_code = $1; 31 | my $un_code = $2; 32 | my $un_name = $3; 33 | 34 | # Produce UTF-8 sequence from character code; 35 | 36 | my $un_utf8 = join('', 37 | map { sprintf("%02X", $_) } 38 | unpack("U0C*", pack("U", hex($un_code))) 39 | ); 40 | 41 | print " $cs_code $un_utf8 ; $un_name\n"; 42 | 43 | } else { 44 | warn "Unrecognized line: '$_'"; 45 | } 46 | } 47 | 48 | ############################################################################### 49 | -------------------------------------------------------------------------------- /bin/nginx/contrib/unicode2nginx/win-utf: -------------------------------------------------------------------------------- 1 | charset_map windows-1251 utf-8 { 2 | 3 | 80 D082 ; #CYRILLIC CAPITAL LETTER DJE 4 | 81 D083 ; #CYRILLIC CAPITAL LETTER GJE 5 | 82 E2809A ; #SINGLE LOW-9 QUOTATION MARK 6 | 83 D193 ; #CYRILLIC SMALL LETTER GJE 7 | 84 E2809E ; #DOUBLE LOW-9 QUOTATION MARK 8 | 85 E280A6 ; #HORIZONTAL ELLIPSIS 9 | 86 E280A0 ; #DAGGER 10 | 87 E280A1 ; #DOUBLE DAGGER 11 | 88 E282AC ; #EURO SIGN 12 | 89 E280B0 ; #PER MILLE SIGN 13 | 8A D089 ; #CYRILLIC CAPITAL LETTER LJE 14 | 8B E280B9 ; #SINGLE LEFT-POINTING ANGLE QUOTATION MARK 15 | 8C D08A ; #CYRILLIC CAPITAL LETTER NJE 16 | 8D D08C ; #CYRILLIC CAPITAL LETTER KJE 17 | 8E D08B ; #CYRILLIC CAPITAL LETTER TSHE 18 | 8F D08F ; #CYRILLIC CAPITAL LETTER DZHE 19 | 90 D192 ; #CYRILLIC SMALL LETTER DJE 20 | 91 E28098 ; #LEFT SINGLE QUOTATION MARK 21 | 92 E28099 ; #RIGHT SINGLE QUOTATION MARK 22 | 93 E2809C ; #LEFT DOUBLE QUOTATION MARK 23 | 94 E2809D ; #RIGHT DOUBLE QUOTATION MARK 24 | 95 E280A2 ; #BULLET 25 | 96 E28093 ; #EN DASH 26 | 97 E28094 ; #EM DASH 27 | 99 E284A2 ; #TRADE MARK SIGN 28 | 9A D199 ; #CYRILLIC SMALL LETTER LJE 29 | 9B E280BA ; #SINGLE RIGHT-POINTING ANGLE QUOTATION MARK 30 | 9C D19A ; #CYRILLIC SMALL LETTER NJE 31 | 9D D19C ; #CYRILLIC SMALL LETTER KJE 32 | 9E D19B ; #CYRILLIC SMALL LETTER TSHE 33 | 9F D19F ; #CYRILLIC SMALL LETTER DZHE 34 | A0 C2A0 ; #NO-BREAK SPACE 35 | A1 D08E ; #CYRILLIC CAPITAL LETTER SHORT U 36 | A2 D19E ; #CYRILLIC SMALL LETTER SHORT U 37 | A3 D088 ; #CYRILLIC CAPITAL LETTER JE 38 | A4 C2A4 ; #CURRENCY SIGN 39 | A5 D290 ; #CYRILLIC CAPITAL LETTER GHE WITH UPTURN 40 | A6 C2A6 ; #BROKEN BAR 41 | A7 C2A7 ; #SECTION SIGN 42 | A8 D081 ; #CYRILLIC CAPITAL LETTER IO 43 | A9 C2A9 ; #COPYRIGHT SIGN 44 | AA D084 ; #CYRILLIC CAPITAL LETTER UKRAINIAN IE 45 | AB C2AB ; #LEFT-POINTING DOUBLE ANGLE QUOTATION MARK 46 | AC C2AC ; #NOT SIGN 47 | AD C2AD ; #SOFT HYPHEN 48 | AE C2AE ; #REGISTERED SIGN 49 | AF D087 ; #CYRILLIC CAPITAL LETTER YI 50 | B0 C2B0 ; #DEGREE SIGN 51 | B1 C2B1 ; #PLUS-MINUS SIGN 52 | B2 D086 ; #CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I 53 | B3 D196 ; #CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I 54 | B4 D291 ; #CYRILLIC SMALL LETTER GHE WITH UPTURN 55 | B5 C2B5 ; #MICRO SIGN 56 | B6 C2B6 ; #PILCROW SIGN 57 | B7 C2B7 ; #MIDDLE DOT 58 | B8 D191 ; #CYRILLIC SMALL LETTER IO 59 | B9 E28496 ; #NUMERO SIGN 60 | BA D194 ; #CYRILLIC SMALL LETTER UKRAINIAN IE 61 | BB C2BB ; #RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK 62 | BC D198 ; #CYRILLIC SMALL LETTER JE 63 | BD D085 ; #CYRILLIC CAPITAL LETTER DZE 64 | BE D195 ; #CYRILLIC SMALL LETTER DZE 65 | BF D197 ; #CYRILLIC SMALL LETTER YI 66 | C0 D090 ; #CYRILLIC CAPITAL LETTER A 67 | C1 D091 ; #CYRILLIC CAPITAL LETTER BE 68 | C2 D092 ; #CYRILLIC CAPITAL LETTER VE 69 | C3 D093 ; #CYRILLIC CAPITAL LETTER GHE 70 | C4 D094 ; #CYRILLIC CAPITAL LETTER DE 71 | C5 D095 ; #CYRILLIC CAPITAL LETTER IE 72 | C6 D096 ; #CYRILLIC CAPITAL LETTER ZHE 73 | C7 D097 ; #CYRILLIC CAPITAL LETTER ZE 74 | C8 D098 ; #CYRILLIC CAPITAL LETTER I 75 | C9 D099 ; #CYRILLIC CAPITAL LETTER SHORT I 76 | CA D09A ; #CYRILLIC CAPITAL LETTER KA 77 | CB D09B ; #CYRILLIC CAPITAL LETTER EL 78 | CC D09C ; #CYRILLIC CAPITAL LETTER EM 79 | CD D09D ; #CYRILLIC CAPITAL LETTER EN 80 | CE D09E ; #CYRILLIC CAPITAL LETTER O 81 | CF D09F ; #CYRILLIC CAPITAL LETTER PE 82 | D0 D0A0 ; #CYRILLIC CAPITAL LETTER ER 83 | D1 D0A1 ; #CYRILLIC CAPITAL LETTER ES 84 | D2 D0A2 ; #CYRILLIC CAPITAL LETTER TE 85 | D3 D0A3 ; #CYRILLIC CAPITAL LETTER U 86 | D4 D0A4 ; #CYRILLIC CAPITAL LETTER EF 87 | D5 D0A5 ; #CYRILLIC CAPITAL LETTER HA 88 | D6 D0A6 ; #CYRILLIC CAPITAL LETTER TSE 89 | D7 D0A7 ; #CYRILLIC CAPITAL LETTER CHE 90 | D8 D0A8 ; #CYRILLIC CAPITAL LETTER SHA 91 | D9 D0A9 ; #CYRILLIC CAPITAL LETTER SHCHA 92 | DA D0AA ; #CYRILLIC CAPITAL LETTER HARD SIGN 93 | DB D0AB ; #CYRILLIC CAPITAL LETTER YERU 94 | DC D0AC ; #CYRILLIC CAPITAL LETTER SOFT SIGN 95 | DD D0AD ; #CYRILLIC CAPITAL LETTER E 96 | DE D0AE ; #CYRILLIC CAPITAL LETTER YU 97 | DF D0AF ; #CYRILLIC CAPITAL LETTER YA 98 | E0 D0B0 ; #CYRILLIC SMALL LETTER A 99 | E1 D0B1 ; #CYRILLIC SMALL LETTER BE 100 | E2 D0B2 ; #CYRILLIC SMALL LETTER VE 101 | E3 D0B3 ; #CYRILLIC SMALL LETTER GHE 102 | E4 D0B4 ; #CYRILLIC SMALL LETTER DE 103 | E5 D0B5 ; #CYRILLIC SMALL LETTER IE 104 | E6 D0B6 ; #CYRILLIC SMALL LETTER ZHE 105 | E7 D0B7 ; #CYRILLIC SMALL LETTER ZE 106 | E8 D0B8 ; #CYRILLIC SMALL LETTER I 107 | E9 D0B9 ; #CYRILLIC SMALL LETTER SHORT I 108 | EA D0BA ; #CYRILLIC SMALL LETTER KA 109 | EB D0BB ; #CYRILLIC SMALL LETTER EL 110 | EC D0BC ; #CYRILLIC SMALL LETTER EM 111 | ED D0BD ; #CYRILLIC SMALL LETTER EN 112 | EE D0BE ; #CYRILLIC SMALL LETTER O 113 | EF D0BF ; #CYRILLIC SMALL LETTER PE 114 | F0 D180 ; #CYRILLIC SMALL LETTER ER 115 | F1 D181 ; #CYRILLIC SMALL LETTER ES 116 | F2 D182 ; #CYRILLIC SMALL LETTER TE 117 | F3 D183 ; #CYRILLIC SMALL LETTER U 118 | F4 D184 ; #CYRILLIC SMALL LETTER EF 119 | F5 D185 ; #CYRILLIC SMALL LETTER HA 120 | F6 D186 ; #CYRILLIC SMALL LETTER TSE 121 | F7 D187 ; #CYRILLIC SMALL LETTER CHE 122 | F8 D188 ; #CYRILLIC SMALL LETTER SHA 123 | F9 D189 ; #CYRILLIC SMALL LETTER SHCHA 124 | FA D18A ; #CYRILLIC SMALL LETTER HARD SIGN 125 | FB D18B ; #CYRILLIC SMALL LETTER YERU 126 | FC D18C ; #CYRILLIC SMALL LETTER SOFT SIGN 127 | FD D18D ; #CYRILLIC SMALL LETTER E 128 | FE D18E ; #CYRILLIC SMALL LETTER YU 129 | FF D18F ; #CYRILLIC SMALL LETTER YA 130 | } 131 | -------------------------------------------------------------------------------- /bin/nginx/contrib/vim/ftdetect/nginx.vim: -------------------------------------------------------------------------------- 1 | au BufRead,BufNewFile *.nginx set ft=nginx 2 | au BufRead,BufNewFile */etc/nginx/* set ft=nginx 3 | au BufRead,BufNewFile */usr/local/nginx/conf/* set ft=nginx 4 | au BufRead,BufNewFile nginx.conf set ft=nginx 5 | -------------------------------------------------------------------------------- /bin/nginx/contrib/vim/ftplugin/nginx.vim: -------------------------------------------------------------------------------- 1 | setlocal commentstring=#\ %s 2 | -------------------------------------------------------------------------------- /bin/nginx/contrib/vim/indent/nginx.vim: -------------------------------------------------------------------------------- 1 | if exists("b:did_indent") 2 | finish 3 | endif 4 | let b:did_indent = 1 5 | 6 | setlocal indentexpr= 7 | 8 | " cindent actually works for nginx' simple file structure 9 | setlocal cindent 10 | " Just make sure that the comments are not reset as defs would be. 11 | setlocal cinkeys-=0# 12 | -------------------------------------------------------------------------------- /bin/nginx/docs/LICENSE: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002-2017 Igor Sysoev 3 | * Copyright (C) 2011-2017 Nginx, Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 | * SUCH DAMAGE. 26 | */ 27 | -------------------------------------------------------------------------------- /bin/nginx/docs/OpenSSL.LICENSE: -------------------------------------------------------------------------------- 1 | 2 | LICENSE ISSUES 3 | ============== 4 | 5 | The OpenSSL toolkit stays under a double license, i.e. both the conditions of 6 | the OpenSSL License and the original SSLeay license apply to the toolkit. 7 | See below for the actual license texts. Actually both licenses are BSD-style 8 | Open Source licenses. In case of any license issues related to OpenSSL 9 | please contact openssl-core@openssl.org. 10 | 11 | OpenSSL License 12 | --------------- 13 | 14 | /* ==================================================================== 15 | * Copyright (c) 1998-2017 The OpenSSL Project. All rights reserved. 16 | * 17 | * Redistribution and use in source and binary forms, with or without 18 | * modification, are permitted provided that the following conditions 19 | * are met: 20 | * 21 | * 1. Redistributions of source code must retain the above copyright 22 | * notice, this list of conditions and the following disclaimer. 23 | * 24 | * 2. Redistributions in binary form must reproduce the above copyright 25 | * notice, this list of conditions and the following disclaimer in 26 | * the documentation and/or other materials provided with the 27 | * distribution. 28 | * 29 | * 3. All advertising materials mentioning features or use of this 30 | * software must display the following acknowledgment: 31 | * "This product includes software developed by the OpenSSL Project 32 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 33 | * 34 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 35 | * endorse or promote products derived from this software without 36 | * prior written permission. For written permission, please contact 37 | * openssl-core@openssl.org. 38 | * 39 | * 5. Products derived from this software may not be called "OpenSSL" 40 | * nor may "OpenSSL" appear in their names without prior written 41 | * permission of the OpenSSL Project. 42 | * 43 | * 6. Redistributions of any form whatsoever must retain the following 44 | * acknowledgment: 45 | * "This product includes software developed by the OpenSSL Project 46 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 47 | * 48 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 49 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 51 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 52 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 53 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 54 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 55 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 57 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 58 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 59 | * OF THE POSSIBILITY OF SUCH DAMAGE. 60 | * ==================================================================== 61 | * 62 | * This product includes cryptographic software written by Eric Young 63 | * (eay@cryptsoft.com). This product includes software written by Tim 64 | * Hudson (tjh@cryptsoft.com). 65 | * 66 | */ 67 | 68 | Original SSLeay License 69 | ----------------------- 70 | 71 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 72 | * All rights reserved. 73 | * 74 | * This package is an SSL implementation written 75 | * by Eric Young (eay@cryptsoft.com). 76 | * The implementation was written so as to conform with Netscapes SSL. 77 | * 78 | * This library is free for commercial and non-commercial use as long as 79 | * the following conditions are aheared to. The following conditions 80 | * apply to all code found in this distribution, be it the RC4, RSA, 81 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 82 | * included with this distribution is covered by the same copyright terms 83 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 84 | * 85 | * Copyright remains Eric Young's, and as such any Copyright notices in 86 | * the code are not to be removed. 87 | * If this package is used in a product, Eric Young should be given attribution 88 | * as the author of the parts of the library used. 89 | * This can be in the form of a textual message at program startup or 90 | * in documentation (online or textual) provided with the package. 91 | * 92 | * Redistribution and use in source and binary forms, with or without 93 | * modification, are permitted provided that the following conditions 94 | * are met: 95 | * 1. Redistributions of source code must retain the copyright 96 | * notice, this list of conditions and the following disclaimer. 97 | * 2. Redistributions in binary form must reproduce the above copyright 98 | * notice, this list of conditions and the following disclaimer in the 99 | * documentation and/or other materials provided with the distribution. 100 | * 3. All advertising materials mentioning features or use of this software 101 | * must display the following acknowledgement: 102 | * "This product includes cryptographic software written by 103 | * Eric Young (eay@cryptsoft.com)" 104 | * The word 'cryptographic' can be left out if the rouines from the library 105 | * being used are not cryptographic related :-). 106 | * 4. If you include any Windows specific code (or a derivative thereof) from 107 | * the apps directory (application code) you must include an acknowledgement: 108 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 109 | * 110 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 111 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 112 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 113 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 114 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 115 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 116 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 117 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 118 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 119 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 120 | * SUCH DAMAGE. 121 | * 122 | * The licence and distribution terms for any publically available version or 123 | * derivative of this code cannot be changed. i.e. this code cannot simply be 124 | * copied and put under another distribution licence 125 | * [including the GNU Public Licence.] 126 | */ 127 | 128 | -------------------------------------------------------------------------------- /bin/nginx/docs/PCRE.LICENCE: -------------------------------------------------------------------------------- 1 | PCRE LICENCE 2 | ------------ 3 | 4 | PCRE is a library of functions to support regular expressions whose syntax 5 | and semantics are as close as possible to those of the Perl 5 language. 6 | 7 | Release 8 of PCRE is distributed under the terms of the "BSD" licence, as 8 | specified below. The documentation for PCRE, supplied in the "doc" 9 | directory, is distributed under the same terms as the software itself. The data 10 | in the testdata directory is not copyrighted and is in the public domain. 11 | 12 | The basic library functions are written in C and are freestanding. Also 13 | included in the distribution is a set of C++ wrapper functions, and a 14 | just-in-time compiler that can be used to optimize pattern matching. These 15 | are both optional features that can be omitted when the library is built. 16 | 17 | 18 | THE BASIC LIBRARY FUNCTIONS 19 | --------------------------- 20 | 21 | Written by: Philip Hazel 22 | Email local part: ph10 23 | Email domain: cam.ac.uk 24 | 25 | University of Cambridge Computing Service, 26 | Cambridge, England. 27 | 28 | Copyright (c) 1997-2017 University of Cambridge 29 | All rights reserved. 30 | 31 | 32 | PCRE JUST-IN-TIME COMPILATION SUPPORT 33 | ------------------------------------- 34 | 35 | Written by: Zoltan Herczeg 36 | Email local part: hzmester 37 | Emain domain: freemail.hu 38 | 39 | Copyright(c) 2010-2017 Zoltan Herczeg 40 | All rights reserved. 41 | 42 | 43 | STACK-LESS JUST-IN-TIME COMPILER 44 | -------------------------------- 45 | 46 | Written by: Zoltan Herczeg 47 | Email local part: hzmester 48 | Emain domain: freemail.hu 49 | 50 | Copyright(c) 2009-2017 Zoltan Herczeg 51 | All rights reserved. 52 | 53 | 54 | THE C++ WRAPPER FUNCTIONS 55 | ------------------------- 56 | 57 | Contributed by: Google Inc. 58 | 59 | Copyright (c) 2007-2012, Google Inc. 60 | All rights reserved. 61 | 62 | 63 | THE "BSD" LICENCE 64 | ----------------- 65 | 66 | Redistribution and use in source and binary forms, with or without 67 | modification, are permitted provided that the following conditions are met: 68 | 69 | * Redistributions of source code must retain the above copyright notice, 70 | this list of conditions and the following disclaimer. 71 | 72 | * Redistributions in binary form must reproduce the above copyright 73 | notice, this list of conditions and the following disclaimer in the 74 | documentation and/or other materials provided with the distribution. 75 | 76 | * Neither the name of the University of Cambridge nor the name of Google 77 | Inc. nor the names of their contributors may be used to endorse or 78 | promote products derived from this software without specific prior 79 | written permission. 80 | 81 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 82 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 83 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 84 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 85 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 86 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 87 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 88 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 89 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 90 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 91 | POSSIBILITY OF SUCH DAMAGE. 92 | 93 | End 94 | -------------------------------------------------------------------------------- /bin/nginx/docs/README: -------------------------------------------------------------------------------- 1 | 2 | Documentation is available at http://nginx.org 3 | 4 | -------------------------------------------------------------------------------- /bin/nginx/docs/zlib.LICENSE: -------------------------------------------------------------------------------- 1 | (C) 1995-2017 Jean-loup Gailly and Mark Adler 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 2. Altered source versions must be plainly marked as such, and must not be 16 | misrepresented as being the original software. 17 | 3. This notice may not be removed or altered from any source distribution. 18 | 19 | Jean-loup Gailly Mark Adler 20 | jloup@gzip.org madler@alumni.caltech.edu 21 | -------------------------------------------------------------------------------- /bin/nginx/html/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Not Found 5 | 12 | 13 | 14 |

404 Not Found

15 |

Sorry, the page you are looking for could not be found.

16 |

If you are the system administrator of this resource then you should check 17 | the error log for details.

18 |

Faithfully yours, nginx.

19 | 20 | 21 | -------------------------------------------------------------------------------- /bin/nginx/html/50x.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Error 5 | 12 | 13 | 14 |

An error occurred.

15 |

Sorry, the page you are looking for is currently unavailable.
16 | Please try again later.

17 |

If you are the system administrator of this resource then you should check 18 | the error log for details.

19 |

Faithfully yours, nginx.

20 | 21 | 22 | -------------------------------------------------------------------------------- /bin/nginx/html/img/bg-pattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/bin/nginx/html/img/bg-pattern.png -------------------------------------------------------------------------------- /bin/nginx/html/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/bin/nginx/html/img/logo.png -------------------------------------------------------------------------------- /bin/nginx/html/img/time.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/bin/nginx/html/img/time.png -------------------------------------------------------------------------------- /bin/nginx/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Welcome to nginx! 5 | 12 | 13 | 14 |

Welcome to nginx!

15 |

If you see this page, the nginx web server is successfully installed and 16 | working. Further configuration is required.

17 | 18 |

For online documentation and support please refer to 19 | nginx.org.
20 | Commercial support is available at 21 | nginx.com.

22 | 23 |

Thank you for using nginx.

24 | 25 | 26 | -------------------------------------------------------------------------------- /bin/nginx/nginx.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/bin/nginx/nginx.exe -------------------------------------------------------------------------------- /bin/vbFcgiHost.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/bin/vbFcgiHost.exe -------------------------------------------------------------------------------- /bin/vbRichClient5.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/bin/vbRichClient5.dll -------------------------------------------------------------------------------- /bin/vb_cairo_sqlite.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/bin/vb_cairo_sqlite.dll -------------------------------------------------------------------------------- /bin/vbml/template_demo.vbml: -------------------------------------------------------------------------------- 1 | 2 | 3 | [[TITLE]] 4 | 15 | 16 | 17 | 18 | 19 |

This is a table of random numbers generated dynamically in a VB6 FCGI application:

20 | 21 |

22 | 23 | [[TABLE_001]] 24 | 25 | 26 |

[[SAMPLE UNKNOWN TAG]]

27 | 28 | -------------------------------------------------------------------------------- /docs/img/diagram_processes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/docs/img/diagram_processes.png -------------------------------------------------------------------------------- /docs/img/screenshot_appdemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/docs/img/screenshot_appdemo.png -------------------------------------------------------------------------------- /src/Shared/MApi.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "MApi" 2 | Option Explicit 3 | 4 | ' Copyright (c) 2017 Jason Peter Brown 5 | ' 6 | ' MIT License 7 | ' 8 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 9 | ' of this software and associated documentation files (the "Software"), to deal 10 | ' in the Software without restriction, including without limitation the rights 11 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | ' copies of the Software, and to permit persons to whom the Software is 13 | ' furnished to do so, subject to the following conditions: 14 | ' 15 | ' The above copyright notice and this permission notice shall be included in all 16 | ' copies or substantial portions of the Software. 17 | ' 18 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | ' SOFTWARE. 25 | 26 | ' This module is for WIN API declares and wrappers 27 | 28 | Public Type SAFEARRAY1D 29 | cDims As Integer 30 | fFeatures As Integer 31 | cbElements As Long 32 | cLocks As Long 33 | pvData As Long 34 | cElements1D As Long 35 | lLbound1D As Long 36 | End Type 37 | 38 | ' API Calls for reversing order of integer and long byte content 39 | Public Declare Function apiNtohs Lib "wsock32.dll" Alias "ntohs" (ByVal a As Integer) As Integer 40 | Public Declare Function apiNtohl Lib "wsock32.dll" Alias "ntohl" (ByVal a As Long) As Long 41 | 42 | ' Debugging 43 | Private Declare Sub OutputDebugString Lib "kernel32.dll" Alias "OutputDebugStringA" (ByVal lpOutputString As String) 44 | 45 | ' Copying Bytes 46 | Public Declare Sub apiCopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long) 47 | 48 | ' Waiting 49 | Public Declare Sub apiSleep Lib "kernel32.dll" Alias "Sleep" (ByVal dwMilliseconds As Long) 50 | 51 | ' Safe Array related 52 | Public Declare Function apiSafeArrayAccessData Lib "oleaut32.dll" Alias "SafeArrayAccessData" (ByVal psa As Long, pvData As Long) As Long 53 | Public Declare Function apiSafeArrayUnaccessData Lib "oleaut32.dll" Alias "SafeArrayUnaccessData" (ByVal psa As Long) As Long 54 | 55 | ' App Path related 56 | Private Const MAX_PATH As Long = 260 57 | Private Declare Function GetModuleFileName Lib "kernel32.dll" Alias "GetModuleFileNameW" (ByVal hModule As Long, ByVal lpFileName As Long, ByVal nSize As Long) As Long 58 | 59 | ' Unicode Command Line handling 60 | Private Declare Function GetCommandLineW Lib "kernel32.dll" () As Long 61 | 62 | Public Declare Function apiWideCharToMultiByte Lib "kernel32" Alias "WideCharToMultiByte" (ByVal CodePage As Long, _ 63 | ByVal dwFlags As Long, _ 64 | ByVal lpWideCharStr As Long, _ 65 | ByVal cchWideChar As Long, _ 66 | ByVal lpMultiByteStr As Long, _ 67 | ByVal cchMultiByte As Long, _ 68 | ByVal lpDefaultChar As Long, _ 69 | lpUsedDefaultChar As Long) As Long 70 | 71 | Public Declare Function apiMultiByteToWideChar Lib "kernel32" Alias "MultiByteToWideChar" (ByVal CodePage As Long, _ 72 | ByVal dwFlags As Long, _ 73 | ByVal lpWideCharStr As Long, _ 74 | ByVal cchWideChar As Long, _ 75 | ByVal lpMultiByteStr As Long, _ 76 | ByVal cchMultiByte As Long) As Long 77 | 78 | ' Mutex API related 79 | Public Const SYNCHRONIZE As Long = &H100000 80 | Public Const ERROR_ALREADY_EXISTS As Long = 183& 81 | Public Const ERROR_ACCESS_DENIED As Long = 5& 82 | Public Const ERROR_FILE_NOT_FOUND As Long = 2& 83 | Public Declare Function apiCreateMutex Lib "kernel32.dll" Alias "CreateMutexW" (ByRef lpMutexAttributes As Any, ByVal bInitialOwner As Long, ByVal lpName As Long) As Long 84 | Public Declare Function apiOpenMutex Lib "kernel32.dll" Alias "OpenMutexW" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal lpName As Long) As Long 85 | Public Declare Function apiCloseHandle Lib "kernel32.dll" Alias "CloseHandle" (ByVal hObject As Long) As Long 86 | 87 | ' Date & Time functions 88 | Public Type SYSTEMTIME 89 | wYear As Integer 90 | wMonth As Integer 91 | wDayOfWeek As Integer 92 | wDay As Integer 93 | wHour As Integer 94 | wMinute As Integer 95 | wSecond As Integer 96 | wMilliseconds As Integer 97 | End Type 98 | 99 | Public Declare Function apiTzSpecificLocalTimeToSystemTime Lib "kernel32.dll" Alias "TzSpecificLocalTimeToSystemTime" (ByVal lpTzData As Long, ByVal lpLocalSystemTime As Long, ByVal lpUtcSystemTime As Long) As Long 100 | 101 | Public Function apiExePath() As String 102 | apiExePath = String$(MAX_PATH, 0) 103 | 104 | GetModuleFileName 0, StrPtr(apiExePath), MAX_PATH 105 | 106 | apiExePath = Left$(apiExePath, InStr(1, apiExePath, vbNullChar) - 1) 107 | End Function 108 | 109 | Public Sub apiOutputDebugString(ByVal p_Message As String) 110 | If envDebugMode Then 111 | OutputDebugString p_Message 112 | End If 113 | End Sub 114 | 115 | Public Function apiGetCommandLine() As String 116 | apiGetCommandLine = libRc5Factory.C.GetStringFromPointerW(GetCommandLineW) 117 | End Function 118 | 119 | -------------------------------------------------------------------------------- /src/Shared/MArrays.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "MArrays" 2 | Option Explicit 3 | 4 | ' Copyright (c) 2017 Jason Peter Brown 5 | ' 6 | ' MIT License 7 | ' 8 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 9 | ' of this software and associated documentation files (the "Software"), to deal 10 | ' in the Software without restriction, including without limitation the rights 11 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | ' copies of the Software, and to permit persons to whom the Software is 13 | ' furnished to do so, subject to the following conditions: 14 | ' 15 | ' The above copyright notice and this permission notice shall be included in all 16 | ' copies or substantial portions of the Software. 17 | ' 18 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | ' SOFTWARE. 25 | 26 | Public Function arrayIsDimmed(p_Array As Variant) As Boolean 27 | Dim l_Lbound As Long 28 | 29 | If Not VarType(p_Array) And vbArray Then Err.Raise 5, , "Array required." 30 | 31 | On Error Resume Next 32 | Err.Clear 33 | l_Lbound = LBound(p_Array) 34 | arrayIsDimmed = (Err.Number = 0) 35 | Err.Clear 36 | 37 | If arrayIsDimmed Then 38 | If UBound(p_Array) < l_Lbound Then 39 | arrayIsDimmed = False 40 | End If 41 | End If 42 | On Error GoTo 0 43 | End Function 44 | 45 | Public Function arraySize(p_Array As Variant, Optional p_RaiseErrorIfUndimmed As Boolean) 46 | If arrayIsDimmed(p_Array) Then 47 | arraySize = UBound(p_Array) - LBound(p_Array) + 1 48 | Else 49 | If p_RaiseErrorIfUndimmed Then 50 | Err.Raise 9, , "Array not dimensioned in arraySize method." 51 | Else 52 | arraySize = -1 53 | End If 54 | End If 55 | End Function 56 | -------------------------------------------------------------------------------- /src/Shared/MCollections.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "MCollections" 2 | Option Explicit 3 | 4 | Public Function collectionHasContent(po_Collection As vbRichClient5.cCollection) As Boolean 5 | If Not po_Collection Is Nothing Then 6 | collectionHasContent = (po_Collection.Count > 0) 7 | End If 8 | End Function 9 | 10 | Public Function collectionIsJsonArray(po_Collection As vbRichClient5.cCollection) As Boolean 11 | If Not po_Collection Is Nothing Then 12 | collectionIsJsonArray = po_Collection.IsJSONArray 13 | End If 14 | End Function 15 | 16 | Public Function collectionIsJsonObject(po_Collection As vbRichClient5.cCollection) As Boolean 17 | If Not po_Collection Is Nothing Then 18 | collectionIsJsonObject = po_Collection.IsJSONObject 19 | End If 20 | End Function 21 | 22 | -------------------------------------------------------------------------------- /src/Shared/MDates.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "MDates" 2 | Option Explicit 3 | 4 | ' Copyright (c) 2017 Jason Peter Brown 5 | ' 6 | ' MIT License 7 | ' 8 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 9 | ' of this software and associated documentation files (the "Software"), to deal 10 | ' in the Software without restriction, including without limitation the rights 11 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | ' copies of the Software, and to permit persons to whom the Software is 13 | ' furnished to do so, subject to the following conditions: 14 | ' 15 | ' The above copyright notice and this permission notice shall be included in all 16 | ' copies or substantial portions of the Software. 17 | ' 18 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | ' SOFTWARE. 25 | 26 | Public Function dateGmtToCookieDate(ByVal p_GmtDate As Date) As String 27 | dateGmtToCookieDate = "Wdy, DD Mon YYYY HH:MM:SS GMT" 28 | 29 | Mid$(dateGmtToCookieDate, 1, 3) = CookieWeekday(Weekday(p_GmtDate, vbSunday)) 30 | Mid$(dateGmtToCookieDate, 6, 2) = Format$(Day(p_GmtDate), "00") 31 | Mid$(dateGmtToCookieDate, 9, 3) = CookieMonth(Month(p_GmtDate)) 32 | Mid$(dateGmtToCookieDate, 13, 4) = Format$(Year(p_GmtDate), "0000") 33 | Mid$(dateGmtToCookieDate, 18, 2) = Format$(Hour(p_GmtDate), "00") 34 | Mid$(dateGmtToCookieDate, 21, 2) = Format$(Minute(p_GmtDate), "00") 35 | Mid$(dateGmtToCookieDate, 24, 2) = Format$(Second(p_GmtDate), "00") 36 | End Function 37 | 38 | Public Function dateVbLocalDateTimeToIso8601Utc(ByVal p_LocalDate As Date) As String 39 | Dim lt_LocalSystemTime As SYSTEMTIME 40 | Dim lt_UtcSystemTime As SYSTEMTIME 41 | 42 | With lt_LocalSystemTime 43 | .wYear = Year(p_LocalDate) 44 | .wMonth = Month(p_LocalDate) 45 | .wDay = Day(p_LocalDate) 46 | .wHour = Hour(p_LocalDate) 47 | .wMinute = Minute(p_LocalDate) 48 | .wSecond = Second(p_LocalDate) 49 | End With 50 | 51 | apiTzSpecificLocalTimeToSystemTime 0, VarPtr(lt_LocalSystemTime), VarPtr(lt_UtcSystemTime) 52 | 53 | dateVbLocalDateTimeToIso8601Utc = "0000-00-00T00:00:00Z" 54 | Mid$(dateVbLocalDateTimeToIso8601Utc, 1, 4) = Format$(lt_UtcSystemTime.wYear, "0000") 55 | Mid$(dateVbLocalDateTimeToIso8601Utc, 6, 2) = Format$(lt_UtcSystemTime.wMonth, "00") 56 | Mid$(dateVbLocalDateTimeToIso8601Utc, 9, 2) = Format$(lt_UtcSystemTime.wDay, "00") 57 | Mid$(dateVbLocalDateTimeToIso8601Utc, 12, 2) = Format$(lt_UtcSystemTime.wHour, "00") 58 | Mid$(dateVbLocalDateTimeToIso8601Utc, 15, 2) = Format$(lt_UtcSystemTime.wMinute, "00") 59 | Mid$(dateVbLocalDateTimeToIso8601Utc, 18, 2) = Format$(lt_UtcSystemTime.wSecond, "00") 60 | End Function 61 | 62 | Private Function CookieMonth(ByVal p_OneBasedMonthIndex As Long) As String 63 | ' Return English abbreviation for month 64 | Select Case p_OneBasedMonthIndex 65 | Case 1 66 | CookieMonth = "Jan" 67 | Case 2 68 | CookieMonth = "Feb" 69 | Case 3 70 | CookieMonth = "Mar" 71 | Case 4 72 | CookieMonth = "Apr" 73 | Case 5 74 | CookieMonth = "May" 75 | Case 6 76 | CookieMonth = "Jun" 77 | Case 7 78 | CookieMonth = "Jul" 79 | Case 8 80 | CookieMonth = "Aug" 81 | Case 9 82 | CookieMonth = "Sep" 83 | Case 10 84 | CookieMonth = "Oct" 85 | Case 11 86 | CookieMonth = "Nov" 87 | Case 12 88 | CookieMonth = "Dec" 89 | Case Else 90 | Err.Raise 5, , "Invalid one-based month index: " & p_OneBasedMonthIndex 91 | End Select 92 | End Function 93 | 94 | Private Function CookieWeekday(ByVal p_Weekday As VbDayOfWeek) As String 95 | ' Return English abbreviation for day of week 96 | Select Case p_Weekday 97 | Case vbSunday 98 | CookieWeekday = "Sun" 99 | Case vbMonday 100 | CookieWeekday = "Mon" 101 | Case vbTuesday 102 | CookieWeekday = "Tue" 103 | Case vbWednesday 104 | CookieWeekday = "Wed" 105 | Case vbThursday 106 | CookieWeekday = "Thu" 107 | Case vbFriday 108 | CookieWeekday = "Fri" 109 | Case vbSaturday 110 | CookieWeekday = "Sat" 111 | Case Else 112 | Err.Raise 5, , "Invalid day index: " & p_Weekday 113 | End Select 114 | End Function 115 | 116 | -------------------------------------------------------------------------------- /src/Shared/MEnv.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "MEnv" 2 | Option Explicit 3 | 4 | ' Copyright (c) 2017 Jason Peter Brown 5 | ' 6 | ' MIT License 7 | ' 8 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 9 | ' of this software and associated documentation files (the "Software"), to deal 10 | ' in the Software without restriction, including without limitation the rights 11 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | ' copies of the Software, and to permit persons to whom the Software is 13 | ' furnished to do so, subject to the following conditions: 14 | ' 15 | ' The above copyright notice and this permission notice shall be included in all 16 | ' copies or substantial portions of the Software. 17 | ' 18 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | ' SOFTWARE. 25 | 26 | Public Function envDebugMode() As Boolean 27 | Static s_DebugMode As Boolean 28 | Static s_LastChecked As Double 29 | 30 | If libRc5Factory.C.HPTimer - s_LastChecked > 30 Then 31 | ' time has passed to warrant checking if debug mode is enabled 32 | s_DebugMode = libRc5Factory.C.FSO.FileExists(pathBin & "VbFcgi.debug") 33 | s_LastChecked = libRc5Factory.C.HPTimer 34 | End If 35 | 36 | envDebugMode = s_DebugMode 37 | End Function 38 | 39 | Public Function envRunningInIde() As Boolean 40 | Static s_Checked As Boolean 41 | Static s_InIde As Boolean 42 | 43 | If Not s_Checked Then 44 | s_Checked = True 45 | 46 | On Error Resume Next 47 | Debug.Print 1 / 0 48 | s_InIde = Err.Number 49 | On Error GoTo 0 50 | End If 51 | 52 | envRunningInIde = s_InIde 53 | End Function 54 | 55 | -------------------------------------------------------------------------------- /src/Shared/MLibs.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "MLibs" 2 | Option Explicit 3 | 4 | ' Copyright (c) 2017 Jason Peter Brown 5 | ' 6 | ' MIT License 7 | ' 8 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 9 | ' of this software and associated documentation files (the "Software"), to deal 10 | ' in the Software without restriction, including without limitation the rights 11 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | ' copies of the Software, and to permit persons to whom the Software is 13 | ' furnished to do so, subject to the following conditions: 14 | ' 15 | ' The above copyright notice and this permission notice shall be included in all 16 | ' copies or substantial portions of the Software. 17 | ' 18 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | ' SOFTWARE. 25 | 26 | ' DirectCOM Stuff 27 | Private Declare Function GetInstanceEx Lib "DirectCom" (StrPtr_FName As Long, StrPtr_ClassName As Long, Optional ByVal UseAlteredSearchPath As Boolean = True) As Object 28 | Private Declare Function GetInstanceOld Lib "DirectCom" Alias "GETINSTANCE" (FName As String, ClassName As String) As Object 29 | Private Declare Function GETINSTANCELASTERROR Lib "DirectCom" () As String 30 | 'used, to preload DirectCOM.dll from a given Path, before we try our calls 31 | Private Declare Function LoadLibraryW Lib "kernel32.dll" (ByVal LibFilePath As Long) As Long 32 | 33 | 'The new GetInstance-Wrapper-Proc, which is using the new DirectCOM.dll (March 2009 and newer) 34 | 'with the new Unicode-capable GetInstanceEx-Call (which now supports the AlteredSearchPath-Flag as well) - 35 | 'If you omit that optional param or set it to True, then LoadLibraryExW is used with the appropriate 36 | 'Flag. If the Param was set to False, then the behaviour is the same as with the former 37 | 'DirectCOM.dll-GETINSTANCE-Call - only that LoadLibraryW is used instead of LoadLibraryA. 38 | 'This routine also tries a fallback to the former DirectCOM.dll-GETINSTANCE-Call, in case 39 | 'you are using it against an older version of this small regfree-helper-lib. 40 | Private Function GETINSTANCE(DllFileName As String, ClassName As String, Optional ByVal UseAlteredSearchPath As Boolean = True) As Object 41 | On Error Resume Next 42 | 43 | Set GETINSTANCE = GetInstanceEx(StrPtr(DllFileName), StrPtr(ClassName), UseAlteredSearchPath) 44 | If Err.Number = 453 Then 'GetInstanceEx not available, probably an older DirectCOM.dll... 45 | Err.Clear 46 | Set GETINSTANCE = GetInstanceOld(DllFileName, ClassName) 'so let's try the older GETINSTANCE-call 47 | End If 48 | If Err Then 49 | Dim Error As String 50 | Error = Err.Description 51 | On Error GoTo 0 52 | Err.Raise vbObjectError, , Error 53 | Else 54 | If GETINSTANCE Is Nothing Then 55 | On Error GoTo 0 56 | Err.Raise vbObjectError, , GETINSTANCELASTERROR() 57 | End If 58 | End If 59 | End Function 60 | 61 | Public Function libRc5Factory() As vbRichClient5.cFactory 62 | Static so_Lib As vbRichClient5.cFactory 63 | 64 | If so_Lib Is Nothing Then 65 | If envRunningInIde Then 66 | Set so_Lib = New vbRichClient5.cFactory 67 | Else 68 | Set so_Lib = GETINSTANCE(pathBin & "vbRichClient5.dll", "cFactory", True) 69 | End If 70 | End If 71 | 72 | Set libRc5Factory = so_Lib 73 | End Function 74 | 75 | Public Function libCrypt() As vbRichClient5.cCrypt 76 | Static so_Lib As vbRichClient5.cCrypt 77 | 78 | If so_Lib Is Nothing Then 79 | If envRunningInIde Then 80 | Set so_Lib = New vbRichClient5.cCrypt 81 | Else 82 | Set so_Lib = libRc5Factory.C.Crypt 83 | End If 84 | End If 85 | 86 | Set libCrypt = so_Lib 87 | End Function 88 | 89 | Public Function libFso() As vbRichClient5.cFSO 90 | Static so_Lib As vbRichClient5.cFSO 91 | 92 | If so_Lib Is Nothing Then 93 | Set so_Lib = libRc5Factory.C.FSO 94 | End If 95 | 96 | Set libFso = so_Lib 97 | End Function 98 | 99 | 100 | -------------------------------------------------------------------------------- /src/Shared/MMath.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "MMath" 2 | Option Explicit 3 | 4 | ' Copyright (c) 2017 Jason Peter Brown 5 | ' 6 | ' MIT License 7 | ' 8 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 9 | ' of this software and associated documentation files (the "Software"), to deal 10 | ' in the Software without restriction, including without limitation the rights 11 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | ' copies of the Software, and to permit persons to whom the Software is 13 | ' furnished to do so, subject to the following conditions: 14 | ' 15 | ' The above copyright notice and this permission notice shall be included in all 16 | ' copies or substantial portions of the Software. 17 | ' 18 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | ' SOFTWARE. 25 | 26 | Public Function mathModCurrency(ByVal p_Number As Currency, ByVal p_ModBy As Currency) As Currency 27 | mathModCurrency = p_Number - (Fix(p_Number / p_ModBy) * p_ModBy) 28 | End Function 29 | 30 | Public Function mathIntDivideCurrency(ByVal p_Numerator As Currency, ByVal p_Denominator As Currency) As Currency 31 | mathIntDivideCurrency = Fix(p_Numerator / p_Denominator) 32 | End Function 33 | 34 | -------------------------------------------------------------------------------- /src/Shared/MPaths.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "MPaths" 2 | Option Explicit 3 | 4 | ' Copyright (c) 2017 Jason Peter Brown 5 | ' 6 | ' MIT License 7 | ' 8 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 9 | ' of this software and associated documentation files (the "Software"), to deal 10 | ' in the Software without restriction, including without limitation the rights 11 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | ' copies of the Software, and to permit persons to whom the Software is 13 | ' furnished to do so, subject to the following conditions: 14 | ' 15 | ' The above copyright notice and this permission notice shall be included in all 16 | ' copies or substantial portions of the Software. 17 | ' 18 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | ' SOFTWARE. 25 | 26 | Public Function pathBin() As String 27 | Static s_Path As String 28 | 29 | Dim la_Path() As String 30 | 31 | If LenB(s_Path) = 0 Then 32 | If envRunningInIde Then 33 | la_Path = Split(App.Path, "\") 34 | ReDim Preserve la_Path(UBound(la_Path) - 2) 35 | 36 | s_Path = Join$(la_Path, "\") & "\bin\" 37 | Else 38 | s_Path = App.Path & "\" 39 | End If 40 | End If 41 | 42 | pathBin = s_Path 43 | End Function 44 | 45 | -------------------------------------------------------------------------------- /src/VbFcgiAppDemo/MImage.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "MImage" 2 | Option Explicit 3 | 4 | Public Function imageStdPictureToCairoSurface(po_StdPicture As stdole.StdPicture) As vbRichClient5.cCairoSurface 5 | ' Code by Olaf Schmidt. Found here: http://www.vbforums.com/showthread.php?857371-How-to-use-vbRichClient5-to-convert-VB-Picture-to-a-byte-array&p=5249553&viewfull=1#post5249553 6 | 7 | Dim lo_Cairo As vbRichClient5.cCairo 8 | Dim lo_CC As vbRichClient5.cCairoContext 9 | Dim lo_Dib As vbRichClient5.cDIB 10 | 11 | 10 On Error GoTo ErrorHandler 12 | 13 | 20 Set lo_Dib = libRc5Factory.C.DIB(, , po_StdPicture) 'create an RC5-DIBObj from the StdPic 14 | 15 | 30 Set lo_Cairo = libRc5Factory.C.Cairo 16 | 17 | 40 Set imageStdPictureToCairoSurface = lo_Cairo.CreateWin32Surface(lo_Dib.dx, lo_Dib.dy) 'ensure the Dest-Surface 18 | 19 | 50 lo_Dib.DrawTo imageStdPictureToCairoSurface.GetDC 'hDC-based Blitting from DIB to CairoSurface 20 | 21 | 'normally we would be finished here - but the above Blt-Op left out the Alpha-Channel, 22 | 60 Set lo_CC = imageStdPictureToCairoSurface.CreateContext 23 | 70 lo_CC.Operator = CAIRO_OPERATOR_DEST_ATOP '...so we have to ensure one with a Paint-Op, 24 | 80 lo_CC.Paint 1, lo_Cairo.CreateSolidPatternLng(0, 1) '<- which sets the Alpha-Channel to "fully opaque" 25 | 26 | 90 Exit Function 27 | 28 | ErrorHandler: 29 | 100 apiOutputDebugString "*** ERROR *** " & Err.Number & " " & Err.Description & ", Line #" & Erl 30 | End Function 31 | 32 | -------------------------------------------------------------------------------- /src/VbFcgiAppDemo/MTests.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "MTests" 2 | Option Explicit 3 | 4 | Public Sub TestForm() 5 | Dim lo_Form As New frmImages 6 | 7 | Load lo_Form 8 | 9 | lo_Form.Show 'vbModal 10 | 11 | 'Unload lo_Form 12 | End Sub 13 | 14 | Public Sub TestSimulator() 15 | Dim lo_Sim As VbFcgiLib.CSimulator 16 | 17 | Set lo_Sim = New VbFcgiLib.CSimulator 18 | 19 | lo_Sim.SimulateRequest "http://localhost/vbfcgiapp.fcgi?json_getdata=1", New VbFcgiApp.CFcgiApp 20 | End Sub 21 | -------------------------------------------------------------------------------- /src/VbFcgiAppDemo/README.md: -------------------------------------------------------------------------------- 1 | This is a demo FCGI application for the VbFcgi framework. Don't build your own DLL using this code (to avoid problems with CLSID collisions). Start a new/fresh ActiveX DLL project for your FCGI application instead! 2 | 3 | After compiling your DLL, make a copy and change the extension from ".dll" to ".fcgi". -------------------------------------------------------------------------------- /src/VbFcgiAppDemo/VbFcgiApp.vbp: -------------------------------------------------------------------------------- 1 | Type=OleDll 2 | Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\..\..\Windows\SysWOW64\stdole2.tlb#OLE Automation 3 | Reference=*\G{C79C91A4-10F5-4F71-A490-3B7915514344}#2.6#0#..\..\..\..\..\..\..\five\bin\common\vbRichClient5.dll#vbRichClient5 4 | Reference=*\G{EEAA331B-F2AF-4D88-9C28-479C240384D7}#d.0#0#..\..\bin\VbFcgiLib.dll#VbFcgiLib 5 | Class=CFcgiApp; CFcgiApp.cls 6 | Module=MLibs; ..\shared\MLibs.bas 7 | Module=MEnv; ..\shared\MEnv.bas 8 | Module=MPaths; ..\shared\MPaths.bas 9 | Module=MApi; ..\shared\MApi.bas 10 | Module=MStrings; ..\Shared\MStrings.bas 11 | Module=MArrays; ..\Shared\MArrays.bas 12 | Module=MDates; ..\Shared\MDates.bas 13 | Form=frmImages.frm 14 | Object={831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0; MSCOMCTL.OCX 15 | Module=MTests; MTests.bas 16 | Module=MImage; MImage.bas 17 | Startup="(None)" 18 | HelpFile="" 19 | Title="VbFcgiApp" 20 | ExeName32="VbFcgiApp.dll" 21 | Path32="..\..\bin" 22 | Command32="" 23 | Name="VbFcgiApp" 24 | HelpContextID="0" 25 | CompatibleMode="0" 26 | CompatibleEXE32="..\..\bin\VbFcgiApp.dll" 27 | MajorVer=1 28 | MinorVer=0 29 | RevisionVer=200 30 | AutoIncrementVer=1 31 | ServerSupportFiles=0 32 | VersionComments="Programmed by Jason Peter Brown" 33 | CompilationType=0 34 | OptimizationType=0 35 | FavorPentiumPro(tm)=0 36 | CodeViewDebugInfo=0 37 | NoAliasing=0 38 | BoundsCheck=0 39 | OverflowCheck=0 40 | FlPointCheck=0 41 | FDIVCheck=0 42 | UnroundedFP=0 43 | StartMode=1 44 | Unattended=0 45 | Retained=0 46 | ThreadPerObject=0 47 | MaxNumberOfThreads=1 48 | ThreadingModel=1 49 | DebugStartupOption=0 50 | -------------------------------------------------------------------------------- /src/VbFcgiAppDemo/frmImages.frm: -------------------------------------------------------------------------------- 1 | VERSION 5.00 2 | Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX" 3 | Begin VB.Form frmImages 4 | Caption = "Form1" 5 | ClientHeight = 3380 6 | ClientLeft = 110 7 | ClientTop = 450 8 | ClientWidth = 6810 9 | LinkTopic = "Form1" 10 | ScaleHeight = 3380 11 | ScaleWidth = 6810 12 | StartUpPosition = 3 'Windows Default 13 | Begin VB.PictureBox Picture1 14 | Height = 2320 15 | Left = 3660 16 | ScaleHeight = 2280 17 | ScaleWidth = 2850 18 | TabIndex = 1 19 | Top = 150 20 | Width = 2890 21 | End 22 | Begin MSComctlLib.ImageList ImageList1 23 | Left = 3690 24 | Top = 2490 25 | _ExtentX = 953 26 | _ExtentY = 953 27 | BackColor = -2147483643 28 | ImageWidth = 800 29 | ImageHeight = 600 30 | MaskColor = 12632256 31 | _Version = 393216 32 | BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 33 | NumListImages = 3 34 | BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 35 | Picture = "frmImages.frx":0000 36 | Key = "" 37 | EndProperty 38 | BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 39 | Picture = "frmImages.frx":6F85 40 | Key = "" 41 | EndProperty 42 | BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 43 | Picture = "frmImages.frx":185B6 44 | Key = "" 45 | EndProperty 46 | EndProperty 47 | End 48 | Begin VB.ListBox List1 49 | Height = 2840 50 | Left = 150 51 | TabIndex = 0 52 | Top = 150 53 | Width = 3370 54 | End 55 | End 56 | Attribute VB_Name = "frmImages" 57 | Attribute VB_GlobalNameSpace = False 58 | Attribute VB_Creatable = False 59 | Attribute VB_PredeclaredId = True 60 | Attribute VB_Exposed = False 61 | Option Explicit 62 | 63 | ' This form simulates part of a legacy VB6 application where all logic is programmed 64 | ' directly into the form. We can interact with a hidden copy of the form from our VBFCGI application 65 | ' and send dynamically generated data downstream to the browser. 66 | ' In the case of this demo, we will send an image whenever the browser user clicks an item in an option list. 67 | 68 | Private Sub Form_Load() 69 | With Me.List1 70 | .AddItem "Blue Hills" 71 | .AddItem "Sunset" 72 | .AddItem "Water Lilies" 73 | 74 | .ListIndex = 0 75 | End With 76 | End Sub 77 | 78 | Private Sub List1_Click() 79 | ' Change the Picture in the PictureBox when list box item is clicked 80 | Me.Picture1.AutoRedraw = True 81 | Set Me.Picture1.Picture = Me.ImageList1.ListImages.Item(Me.List1.ListIndex + 1).Picture 82 | Me.Picture1.AutoRedraw = False 83 | End Sub 84 | -------------------------------------------------------------------------------- /src/VbFcgiAppDemo/frmImages.frx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/src/VbFcgiAppDemo/frmImages.frx -------------------------------------------------------------------------------- /src/VbFcgiHostExe/vbFcgiHostExe.vbp: -------------------------------------------------------------------------------- 1 | Type=Exe 2 | Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\..\..\Windows\SysWOW64\stdole2.tlb#OLE Automation 3 | Reference=*\G{C79C91A4-10F5-4F71-A490-3B7915514344}#2.5#0#..\..\..\..\..\..\..\five\bin\common\vbRichClient5.dll#vbRichClient5 4 | Reference=*\G{EEAA331B-F2AF-4D88-9C28-479C240384D7}#2.0#0#..\..\bin\VbFcgiLib.dll#VbFcgiLib 5 | Module=MStartup; MStartup.bas 6 | Module=MLibs; ..\shared\MLibs.bas 7 | Module=MPaths; ..\shared\MPaths.bas 8 | Module=MApi; ..\shared\MApi.bas 9 | Module=MEnv; ..\shared\MEnv.bas 10 | Startup="Sub Main" 11 | HelpFile="" 12 | Title="vbFcgiHost" 13 | ExeName32="vbFcgiHost.exe" 14 | Path32="..\..\bin" 15 | Command32="" 16 | Name="vbFcgiHost" 17 | HelpContextID="0" 18 | Description="Experimental FastCGI Application Server Host" 19 | CompatibleMode="0" 20 | MajorVer=0 21 | MinorVer=0 22 | RevisionVer=48 23 | AutoIncrementVer=1 24 | ServerSupportFiles=0 25 | VersionComments="Programmed by Jason Peter Brown" 26 | CompilationType=0 27 | OptimizationType=0 28 | FavorPentiumPro(tm)=0 29 | CodeViewDebugInfo=0 30 | NoAliasing=0 31 | BoundsCheck=-1 32 | OverflowCheck=-1 33 | FlPointCheck=-1 34 | FDIVCheck=-1 35 | UnroundedFP=-1 36 | StartMode=0 37 | Unattended=-1 38 | Retained=0 39 | ThreadPerObject=0 40 | MaxNumberOfThreads=1 41 | DebugStartupOption=0 42 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CBuilders.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CBuilders" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | ' ------------------------------------------------------------------------------- 39 | ' PURPOSE 40 | ' ------------------------------------------------------------------------------- 41 | ' 42 | ' To hand out an IBuilder class to your FCGI application. IBuilder classes are 43 | ' designed to help you more easily create and transmit specific kinds of web content 44 | ' (e.g. HTML documents, templates, and binary files). 45 | ' 46 | ' ------------------------------------------------------------------------------- 47 | ' USAGE 48 | ' ------------------------------------------------------------------------------- 49 | ' 50 | ' A CBuilders class will be passed to your FCGI application as part of the 51 | ' CFcgiReponse class that is passed to the IFcgi_ProcessRequest method. 52 | ' 53 | ' Once you have determine what kind of information you want to send back 54 | ' downstream to the browser, you can select a specific IBuilder implementing 55 | ' class by calling the CBuilder.Builder() method. 56 | ' 57 | ' For example, if you want to send a completely dynamically generated HTML file 58 | ' downstream, you would call 59 | ' 60 | ' po_Response.Builders.Builder(builder_Html) ' to get a CBuilderHtml class 61 | ' 62 | ' Or to send a binary file downstream, you would call: 63 | ' 64 | ' po_response.Builders.Builder(builder_File) ' to get a CBuilderFile class 65 | ' 66 | ' Please see each CBuilder* class for more information on the purpose 67 | ' and usage of each. 68 | 69 | 70 | Public Enum e_ContentEncoding 71 | contentencoding_RecommendedDefault = -1 72 | contentencoding_Unknown 73 | 74 | contentencoding_UTF8 75 | contentencoding_UTF16_LE 76 | contentencoding_USASCII 77 | contentencoding_ISO8859_1 78 | End Enum 79 | 80 | Public Enum e_BuilderType 81 | [_builder_NotInitialized] = 0 82 | 83 | builder_Html = 1 ' HTML string builder/helper 84 | builder_File ' Byte data stored on the file system (typically) 85 | builder_Template ' Server-side VBML template parser/helper 86 | builder_Json ' JSON string builder/helper 87 | 88 | ' Not supported yet: 89 | 'builder_Xml ' XML string builder/helper 90 | 'builder_Raw ' Raw socket to write whatever you want to 91 | End Enum 92 | 93 | Private Const mc_KeyIBuilder As String = "IBuilder" 94 | 95 | Public Event Finished() 96 | 97 | Private WithEvents mo_EventCollection As vbRichClient5.cEventCollection 98 | Attribute mo_EventCollection.VB_VarHelpID = -1 99 | Private mo_Builder As VbFcgiLib.IBuilder 100 | Private m_BuilderType As VbFcgiLib.e_BuilderType 101 | 102 | Public Function Builder(Optional ByVal p_InitializeBuilderType As VbFcgiLib.e_BuilderType) As VbFcgiLib.IBuilder 103 | If mo_Builder Is Nothing Then 104 | ' Initialize a new builder 105 | 106 | Select Case p_InitializeBuilderType 107 | Case builder_Html 108 | ' Requested an HTML builder/helper 109 | Set mo_Builder = New VbFcgiLib.CBuilderHtml 110 | 111 | Case builder_File 112 | ' Requested a file builder/helper 113 | Set mo_Builder = New VbFcgiLib.CBuilderFile 114 | 115 | Case builder_Template 116 | Set mo_Builder = New VbFcgiLib.CBuilderTemplate 117 | 118 | Case builder_Json 119 | Set mo_Builder = New VbFcgiLib.CBuilderJson 120 | 121 | Case Else 122 | Err.Raise 5, , "Unknown builder type: " & p_InitializeBuilderType 123 | 124 | End Select 125 | 126 | mo_EventCollection.Add mo_Builder, mc_KeyIBuilder 127 | 128 | m_BuilderType = p_InitializeBuilderType 129 | 130 | Else 131 | If p_InitializeBuilderType <> 0 Then 132 | If p_InitializeBuilderType <> m_BuilderType Then 133 | Err.Raise 5, , "Already initialized a different builder type!" 134 | End If 135 | End If 136 | 137 | End If 138 | 139 | Set Builder = mo_Builder 140 | End Function 141 | 142 | Private Sub Class_Initialize() 143 | Set mo_EventCollection = libRc5Factory.C.EventCollection 144 | End Sub 145 | 146 | Private Sub mo_EventCollection_EventRaised(p_Key As String, p_EventName As String, ByVal p_ParamCount As Long, p_Param1 As Variant, p_Param2 As Variant, p_Param3 As Variant, p_Param4 As Variant, p_Param5 As Variant, p_Param6 As Variant, p_Param7 As Variant, p_Param8 As Variant) 147 | apiOutputDebugString "In mo_EventCollection_EventRaised for " & p_Key & "." & p_EventName 148 | 149 | Select Case p_Key 150 | Case mc_KeyIBuilder 151 | Select Case LCase$(p_EventName) 152 | Case "finished" 153 | RaiseEvent Finished 154 | End Select 155 | 156 | Case Else 157 | Debug.Assert False 158 | apiOutputDebugString "Unhandled event in EventCollection member: " & p_EventName & ". Key: " & p_Key 159 | End Select 160 | End Sub 161 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CFcgi.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CFcgi" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | Private mo_FcgiDownstream As VbFcgiLib.CFcgiDownstream 39 | 40 | Friend Property Set FcgiDownstream(po_FcgiDownstream As VbFcgiLib.CFcgiDownstream) 41 | Set mo_FcgiDownstream = po_FcgiDownstream 42 | End Property 43 | 44 | Public Property Get Stdin() As VbFcgiLib.CFcgiStdIn 45 | Set Stdin = mo_FcgiDownstream.Stdin 46 | End Property 47 | 48 | Public Property Get Params() As VbFcgiLib.CFcgiParams 49 | Set Params = mo_FcgiDownstream.Params 50 | End Property 51 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CFcgiDownstream.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CFcgiDownstream" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | ' This class holds all of the information related to an FCGI request (including the response byte stream) 39 | 40 | Public Enum e_FcgiRequestState 41 | fcgireqstate_Error = -1 ' There was an error processing the request 42 | 43 | fcgireqstate_Created = 0 ' Request object has just been created 44 | fcgireqstate_Initialized ' Request has had initial state variable set 45 | fcgireqstate_Busy ' Request is off to the application for response processing 46 | fcgireqstate_Ready ' Request is ready for flushing in whole or in part 47 | End Enum 48 | 49 | ' Initial state information 50 | Private m_State As e_FcgiRequestState ' The current state of the request object 51 | Private m_Id As Integer ' FCGI ID# of the request 52 | Private m_SocketNumber As Long ' Socket number for request/response communications with the web server 53 | 54 | ' Error information 55 | Private m_ErrorNumber As Long ' This should be sent back through STDERR request body as the ApplicationStatus member 56 | Private m_ErrorDescription As String 57 | 58 | ' FCGI Objects 59 | Private mo_Params As CFcgiParams ' Collection of Key/Value pairs received from the web server 60 | Private mo_StdIn As CFcgiStdIn ' Byte data streamed from the web server 61 | Private mo_StdOut As CFcgiStdOut ' Byte data to be streamed to the web server 62 | Private mo_FcgiResponse As CFcgiResponse 63 | 64 | Public Property Get FcgiResponse() As VbFcgiLib.CFcgiResponse 65 | Set FcgiResponse = mo_FcgiResponse 66 | End Property 67 | 68 | Public Sub Initialize(ByVal p_RequestId As Integer, ByVal p_SocketNumber As Long) 69 | If Me.State <> fcgireqstate_Created Then Err.Raise 5, , "Can't re-initialize request." 70 | 71 | m_Id = p_RequestId 72 | m_SocketNumber = p_SocketNumber 73 | 74 | Me.State = fcgireqstate_Initialized 75 | 76 | Set mo_FcgiResponse = New VbFcgiLib.CFcgiResponse 77 | mo_FcgiResponse.RequestId = p_RequestId 78 | End Sub 79 | 80 | Public Sub SetError(ByVal p_ErrorNumber As Long, ByVal p_ErrorDescription As String) 81 | apiOutputDebugString "In SetError. Error #" & p_ErrorNumber & " " & p_ErrorDescription 82 | 83 | m_ErrorNumber = p_ErrorNumber 84 | m_ErrorDescription = p_ErrorDescription 85 | 86 | Me.State = fcgireqstate_Error 87 | End Sub 88 | 89 | Public Property Get State() As e_FcgiRequestState 90 | State = m_State 91 | End Property 92 | 93 | Public Property Let State(ByVal p_State As e_FcgiRequestState) 94 | ' Check for invalid state changes 95 | If p_State = fcgireqstate_Created Then 96 | ' Illegal state change 97 | ' Can't return request to Created state - create a new object instead 98 | Err.Raise 5, , "Can't re-create request." 99 | End If 100 | 101 | If p_State <> fcgireqstate_Error Then 102 | If m_State = fcgireqstate_Error Then 103 | ' A request in an error state can not be removed from the error state 104 | ' Illegal state change 105 | Err.Raise 5, , "Can't remove request from error state." 106 | End If 107 | End If 108 | 109 | If p_State = fcgireqstate_Initialized Then 110 | ' A request can only be marked initialized if it is in the created or initialized states 111 | Select Case m_State 112 | Case fcgireqstate_Created, fcgireqstate_Initialized 113 | ' State change/status quo OK 114 | Case Else 115 | ' Illegal state change 116 | Err.Raise 5, , "Can't re-initialize request." 117 | End Select 118 | End If 119 | 120 | m_State = p_State 121 | End Property 122 | 123 | Public Property Get Params() As CFcgiParams 124 | Set Params = mo_Params 125 | End Property 126 | 127 | Public Property Get Stdin() As CFcgiStdIn 128 | Set Stdin = mo_StdIn 129 | End Property 130 | 131 | Public Property Get StdOut() As CFcgiStdOut 132 | Set StdOut = mo_StdOut 133 | End Property 134 | 135 | Public Property Get ErrorDescription() As String 136 | ErrorDescription = m_ErrorDescription 137 | End Property 138 | 139 | Public Property Get ErrorNumber() As Long 140 | ErrorNumber = m_ErrorNumber 141 | End Property 142 | 143 | Public Property Get Id() As Integer 144 | Id = m_Id 145 | End Property 146 | 147 | Public Property Get SocketNumber() As Long 148 | SocketNumber = m_SocketNumber 149 | End Property 150 | 151 | Private Sub Class_Initialize() 152 | Set mo_Params = New CFcgiParams 153 | Set mo_StdIn = New CFcgiStdIn 154 | Set mo_StdOut = New CFcgiStdOut 155 | End Sub 156 | 157 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CFcgiRequest.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CFcgiRequest" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | ' ------------------------------------------------------------------------------- 39 | ' PURPOSE 40 | ' ------------------------------------------------------------------------------- 41 | ' 42 | ' This class holds references to CFcgi and CHttp classes (which themselves 43 | ' hold information received from the downstream browser and web server. 44 | ' 45 | ' A CFcgiRequest class is passed as a parameter to your FCGI application when 46 | ' IFcgiApp_ProcessRequest is called. 47 | ' 48 | ' ------------------------------------------------------------------------------- 49 | ' USAGE 50 | ' ------------------------------------------------------------------------------- 51 | ' 52 | ' This class is useful for getting information that was sent upstream by a 53 | ' the web browser and web server. 54 | ' For things like the request method (GET, PUT, etc...), the query parameters, 55 | ' HTTP request header fields, cookies, etc... 56 | 57 | Private mo_Http As VbFcgiLib.CHttp 58 | Private mo_Fcgi As VbFcgiLib.CFcgi 59 | Private mo_Downstream As VbFcgiLib.CFcgiDownstream 60 | 61 | Friend Property Set FcgiDownstream(po_Downstream As VbFcgiLib.CFcgiDownstream) 62 | Set mo_Downstream = po_Downstream 63 | Set mo_Http.FcgiDownstream = po_Downstream 64 | Set mo_Fcgi.FcgiDownstream = po_Downstream 65 | End Property 66 | 67 | Public Property Get Fcgi() As VbFcgiLib.CFcgi 68 | Set Fcgi = mo_Fcgi 69 | End Property 70 | 71 | Public Property Get Http() As VbFcgiLib.CHttp 72 | Set Http = mo_Http 73 | End Property 74 | 75 | Private Sub Class_Initialize() 76 | Set mo_Http = New VbFcgiLib.CHttp 77 | Set mo_Fcgi = New VbFcgiLib.CFcgi 78 | End Sub 79 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CFcgiResponse.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CFcgiResponse" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | ' ------------------------------------------------------------------------------- 39 | ' PURPOSE 40 | ' ------------------------------------------------------------------------------- 41 | ' 42 | ' This class helps you respond to requests. 43 | ' 44 | ' A CFcgiResponse class instance is passed as a parameter to your FCGI 45 | ' application when IFcgiApp_ProcessRequest is called there. 46 | ' 47 | ' ------------------------------------------------------------------------------- 48 | ' USAGE 49 | ' ------------------------------------------------------------------------------- 50 | ' 51 | ' You can use the Builders method to get a builder helper suitable for the type 52 | ' of data that you want to respond with. 53 | ' 54 | ' Alternately, you can write directly downstream using the included WriteBytes, 55 | ' Error, and Finished methods. 56 | 57 | Public Event SendBytes(ByVal p_RequestId As Long, pa_Bytes() As Byte) 58 | Public Event SendError(ByVal p_RequestId As Long, ByVal p_ErrorNumber As Long, ByVal p_ErrorDescription As String) 59 | Public Event SendFinished(ByVal p_RequestId As Long) 60 | 61 | Private WithEvents mo_Builders As VbFcgiLib.CBuilders 62 | Attribute mo_Builders.VB_VarHelpID = -1 63 | 64 | Private m_RequestId As Long 65 | Private m_Finished As Boolean 66 | 67 | Friend Property Let RequestId(ByVal p_RequestId As Long) 68 | m_RequestId = p_RequestId 69 | End Property 70 | 71 | Public Property Get Builders() As VbFcgiLib.CBuilders 72 | If mo_Builders Is Nothing Then Set mo_Builders = New VbFcgiLib.CBuilders 73 | 74 | Set Builders = mo_Builders 75 | End Property 76 | 77 | Public Sub WriteBytes(pa_Bytes() As Byte) 78 | ' Call this method from your FCGI App to write bytes back to the web server. 79 | 80 | If m_Finished Then Err.Raise 5, , "FCGI application finished." 81 | 82 | apiOutputDebugString "Sending " & arraySize(pa_Bytes) & " bytes downstream." 83 | 84 | RaiseEvent SendBytes(m_RequestId, pa_Bytes) 85 | End Sub 86 | 87 | Public Sub Error(ByVal p_ErrorNumber As Long, ByVal p_ErrorDescription As String) 88 | ' Call this method from your FCGI app to send an error back to the web server 89 | 90 | apiOutputDebugString "FCGI Response error: " & p_ErrorNumber & " " & p_ErrorDescription 91 | 92 | If m_Finished Then Err.Raise 5, , "FCGI application finished." 93 | 94 | RaiseEvent SendError(m_RequestId, p_ErrorNumber, p_ErrorDescription) 95 | Me.Finished 96 | End Sub 97 | 98 | Public Sub Finished() 99 | ' Call this method when your FCGI app is finished responding to the web server. 100 | 101 | If Not m_Finished Then 102 | m_Finished = True 103 | 104 | apiOutputDebugString "Request #" & m_RequestId & " is finished." 105 | 106 | RaiseEvent SendFinished(m_RequestId) 107 | End If 108 | End Sub 109 | 110 | Public Property Get IsFinished() As Boolean 111 | IsFinished = m_Finished 112 | End Property 113 | 114 | Private Sub mo_Builders_Finished() 115 | Dim lo_Builder As VbFcgiLib.IBuilder 116 | Dim lo_File As VbFcgiLib.CBuilderFile 117 | 118 | apiOutputDebugString "In mo_Builders_Finished for " & m_RequestId 119 | 120 | Set lo_Builder = mo_Builders.Builder 121 | With lo_Builder 122 | ' Send HTTP header content for all builder types 123 | apiOutputDebugString "Sending HTTP header." 124 | 125 | Me.WriteBytes .HttpHeader.Content 126 | 127 | ' Customize sending of content based on active builder type 128 | If TypeOf lo_Builder Is VbFcgiLib.CBuilderFile Then 129 | ' CBuilderFile is active, so stream bytes downstream 130 | 131 | apiOutputDebugString "Sending file builder content." 132 | 133 | Set lo_File = lo_Builder 134 | 135 | ' Send file content or 304 NOT MODIFIED 136 | Do While Not lo_File.IsFinishedReading 137 | ' File content gets sent in chunks, hence the loop 138 | 139 | apiOutputDebugString "Sending file content chunk #" & lo_File.ChunkIndex + 1 & " of " & lo_File.ChunkCount 140 | 141 | If .Length > 0 Then 142 | Me.WriteBytes .Content 143 | End If 144 | Loop 145 | 146 | Else 147 | ' Send entire content for any other builder type 148 | 149 | apiOutputDebugString "Sending builder content." 150 | 151 | If .Length > 0 Then 152 | Me.WriteBytes .Content 153 | End If 154 | End If 155 | End With 156 | 157 | Me.Finished 158 | End Sub 159 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CFcgiStdIn.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CFcgiStdIn" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | ' This class holds the STDIN data received from the web server 39 | Public Enum e_FcgiStdinState 40 | fcgistdinstate_Error = -1 ' There was a problem with the STDIN buffer 41 | fcgistdinstate_Initialized ' The buffer is ready for data to be appended 42 | fcgistdinstate_Building ' Content has been and/or is being appended to the STDIN buffer 43 | fcgistdinstate_Built ' We've receive all the STDIN data 44 | End Enum 45 | 46 | Private mo_StdIn As cStream ' Stream of bytes received from the web server via STDIN record(s) 47 | 48 | Private m_State As e_FcgiStdinState 49 | Private m_FilePath As String ' Path if the STDIN buffer is on the physical disk 50 | 51 | Public Property Get State() As e_FcgiStdinState 52 | State = m_State 53 | End Property 54 | 55 | Public Property Let State(ByVal p_NewState As e_FcgiStdinState) 56 | If p_NewState = fcgistdinstate_Initialized Then Err.Raise 5, , "Can't re-initialize STDIN." 57 | If Me.State = fcgistdinstate_Built And p_NewState <> fcgistdinstate_Built Then Err.Raise 5, , "Can't remove STDIN from built state." 58 | If Me.State = fcgistdinstate_Error And p_NewState <> fcgistdinstate_Error Then Err.Raise 5, , "Can't remove STDIN from error state." 59 | 60 | m_State = p_NewState 61 | End Property 62 | 63 | Public Sub AppendContent(pa_Bytes() As Byte) 64 | Dim lo_DiskStream As vbRichClient5.cStream 65 | Dim l_ContentLength As Currency 66 | Dim la_Bytes() As Byte 67 | Dim l_AppendLength As Long 68 | 69 | Select Case Me.State 70 | Case fcgistdinstate_Error, fcgistdinstate_Built 71 | Err.Raise 5, , "Can not append to STDIN in the current state: " & Me.State 72 | End Select 73 | 74 | l_AppendLength = UBound(pa_Bytes) - LBound(pa_Bytes) + 1 75 | apiOutputDebugString "Appending content to STDIN. Size: " & l_AppendLength 76 | 77 | If l_AppendLength < 1 Then Exit Sub ' Nothing to append, Short-Circuit 78 | 79 | Me.State = fcgistdinstate_Building 80 | 81 | If m_FilePath = "" Then 82 | ' In memory stream - check if the existing + append length will exceed max in-memory sisze 83 | ' If so, move to temporary file on file system 84 | 85 | l_ContentLength = Me.ContentLength 86 | 87 | If l_ContentLength + l_AppendLength > gc_MaxStdinInMemorySize Then 88 | apiOutputDebugString "STDIN data exceeds maximum in-memory size of " & gc_MaxStdinInMemorySize & " bytes. Moving data to file system." 89 | apiOutputDebugString "Current ContentLength: " & l_ContentLength & ", Append Length: " & l_AppendLength 90 | 91 | ' Move to file system 92 | m_FilePath = libRc5Factory.C.FSO.GetTmpFileName("VBF") 93 | Set lo_DiskStream = libRc5Factory.C.FSO.CreateFileStream(m_FilePath, STRM_READWRITE + STRM_SHARE_EXCLUSIVE) 94 | 95 | apiOutputDebugString "STDIN file: " & m_FilePath 96 | 97 | If l_ContentLength > 0 Then 98 | apiOutputDebugString "Copying existing data from memory to disk." 99 | 100 | mo_StdIn.SetPosition 0 ' Go to beginning of stream 101 | mo_StdIn.ReadToByteArr la_Bytes 102 | lo_DiskStream.WriteFromByteArr la_Bytes 103 | Erase la_Bytes 104 | End If 105 | 106 | Set mo_StdIn = lo_DiskStream 107 | End If 108 | End If 109 | 110 | mo_StdIn.WriteFromByteArr pa_Bytes 111 | End Sub 112 | 113 | Public Function ContentLength() As Long 114 | ContentLength = mo_StdIn.GetSize 115 | End Function 116 | 117 | Public Function HasContent() As Boolean 118 | HasContent = (Me.ContentLength > 0) 119 | End Function 120 | 121 | Public Function Content() As Byte() 122 | Dim la_Bytes() As Byte 123 | Dim l_CurPos As Long 124 | 125 | ' Get all available content in STDIN 126 | 127 | If Me.HasContent Then 128 | l_CurPos = mo_StdIn.GetPosition ' Record current stream position 129 | 130 | mo_StdIn.SetPosition 0 ' Go to beginning of stream 131 | mo_StdIn.ReadToByteArr la_Bytes ' Get all bytes 132 | 133 | mo_StdIn.SetPosition l_CurPos ' Reset stream position 134 | 135 | Else 136 | la_Bytes = vbNullString ' Return empty array. LBound = 0, UBound = -1 137 | End If 138 | 139 | Content = la_Bytes 140 | End Function 141 | 142 | Public Sub SaveToFile(ByVal p_FilePath As String) 143 | libRc5Factory.C.FSO.WriteByteContent p_FilePath, Me.Content 144 | End Sub 145 | 146 | Private Sub Class_Initialize() 147 | Set mo_StdIn = libRc5Factory.C.Stream 148 | End Sub 149 | 150 | Private Sub Class_Terminate() 151 | On Error Resume Next 152 | 153 | ' Remove STDIN data if it was stored on file system 154 | If m_FilePath <> "" Then 155 | If libRc5Factory.C.FSO.FileExists(m_FilePath) Then 156 | libRc5Factory.C.FSO.DeleteFile m_FilePath 157 | End If 158 | End If 159 | End Sub 160 | 161 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CFcgiStdOut.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CFcgiStdOut" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | Public Enum e_FcgiStdoutState 39 | fcgistdoutstate_Initialized ' The buffer is ready for data to be appended 40 | fcgistdoutstate_Building ' Content has been and/or is being appended to the STDOUT buffer 41 | fcgistdoutstate_Built ' Can send FCGI_END_REQUEST after buffer flushes 42 | End Enum 43 | 44 | Private mo_StdOut As vbRichClient5.cArrayList 45 | Private m_State As e_FcgiStdoutState ' The current state of this object. 46 | Private m_ContentLength As Long ' The current unflushed content length 47 | 48 | Public Property Get State() As e_FcgiStdoutState 49 | State = m_State 50 | End Property 51 | 52 | Public Property Let State(ByVal p_State As e_FcgiStdoutState) 53 | If m_State > p_State Then Err.Raise 5, , "Can't revert state." 54 | 55 | m_State = p_State 56 | End Property 57 | 58 | Public Sub AppendContent(pa_Bytes As Variant) 59 | Dim l_Len As Long 60 | Dim l_Mod As Long 61 | Dim ii As Long 62 | Dim l_Bytes As Variant 63 | Dim la_Bytes() As Byte 64 | Dim l_DestSafeArrayPointer As Long 65 | Dim l_SafeArrayPointer As Long 66 | Dim l_SafeArray As Long 67 | Dim l_DataPointer As Long 68 | Dim lt_SafeArray As SAFEARRAY1D 69 | 70 | If Me.State = fcgistdoutstate_Built Then Err.Raise 5, , "Can't append content to built STDOUT" 71 | Me.State = fcgistdoutstate_Building 72 | 73 | apiOutputDebugString "Before queuing content. Current chunks: " & mo_StdOut.Count & ", Bytes: " & m_ContentLength 74 | 75 | l_Len = arraySize(pa_Bytes) 76 | apiOutputDebugString "Appending content to STDOUT. Length: " & l_Len 77 | 78 | m_ContentLength = m_ContentLength + l_Len 79 | 80 | If l_Len > gc_MaxStdoutBufferChunkSize Then 81 | ' Length of passed content larger than our maximum STDOUT buffer chunk size 82 | ' So split into smaller chunks and queue those chunks 83 | apiOutputDebugString "Content to append needs to be split into smaller chunks." 84 | 85 | ReDim la_Bytes(0 To gc_MaxStdoutBufferChunkSize - 1) 86 | l_Bytes = la_Bytes 87 | 88 | apiCopyMemory l_SafeArrayPointer, ByVal VarPtr(pa_Bytes) + 8, 4 89 | If l_SafeArrayPointer = 0 Then Err.Raise vbObjectError, , "Could not retrieve safe array pointer." 90 | apiCopyMemory l_SafeArray, ByVal l_SafeArrayPointer, 4 91 | apiCopyMemory lt_SafeArray, ByVal l_SafeArray, LenB(lt_SafeArray) 92 | 93 | If apiSafeArrayAccessData(l_SafeArray, l_DataPointer) = 0 Then 94 | If l_DataPointer = 0 Then Err.Raise vbObjectError, , "Could not retrieve safe array data pointer!" 95 | 96 | For ii = 0 To (l_Len \ gc_MaxStdoutBufferChunkSize) - 1 97 | apiOutputDebugString "Appending chunk #" & ii & ". Length: " & gc_MaxStdoutBufferChunkSize 98 | apiOutputDebugString "Chunk Start: " & (gc_MaxStdoutBufferChunkSize * ii) 99 | 100 | apiCopyMemory la_Bytes(0), ByVal l_DataPointer + (gc_MaxStdoutBufferChunkSize * ii), gc_MaxStdoutBufferChunkSize 101 | 102 | apiOutputDebugString "Queueing chunk #" & ii 103 | 104 | mo_StdOut.Queue la_Bytes 105 | Next ii 106 | 107 | ' Append final chunk 108 | l_Mod = l_Len Mod gc_MaxStdoutBufferChunkSize 109 | 110 | If l_Mod > 0 Then 111 | apiOutputDebugString "Appending final chunk. Length: " & l_Mod 112 | 113 | ReDim la_Bytes(0 To l_Mod - 1) 114 | apiCopyMemory la_Bytes(0), ByVal l_DataPointer + (gc_MaxStdoutBufferChunkSize * ii), l_Mod 115 | 116 | mo_StdOut.Queue la_Bytes 117 | End If 118 | 119 | ' Release array 120 | apiSafeArrayUnaccessData l_SafeArray 121 | 122 | Else 123 | ' Could not access safe array data 124 | Err.Raise vbObjectError, , "Could not access safe array data! Last DLL Error: " & Err.LastDllError 125 | End If 126 | 127 | Else 128 | ' Length of passed content smaller or equal to our max STDOUT buffer chunk size 129 | ' Queue the entire chunk 130 | 131 | mo_StdOut.Queue pa_Bytes 132 | 133 | End If 134 | 135 | apiOutputDebugString "Queued content chunks: " & mo_StdOut.Count & ", Bytes: " & m_ContentLength 136 | End Sub 137 | 138 | Public Function HasUnflushedContent() As Boolean 139 | HasUnflushedContent = (mo_StdOut.Count > 0) 140 | End Function 141 | 142 | Public Function UnflushedContentLength() As Long 143 | UnflushedContentLength = m_ContentLength 144 | End Function 145 | 146 | Public Function NextContentChunk() As Byte() 147 | If mo_StdOut.Count <= 0 Then Err.Raise vbObjectError, , "No unflushed content available." 148 | 149 | apiOutputDebugString "Getting content chunk. Total chunks: " & mo_StdOut.Count & ", bytes: " & m_ContentLength 150 | 151 | NextContentChunk = mo_StdOut.DeQueue 152 | 153 | m_ContentLength = m_ContentLength - arraySize(NextContentChunk) 154 | If m_ContentLength < 0 Then m_ContentLength = 0 155 | 156 | apiOutputDebugString "Remaining bytes to flush: " & m_ContentLength 157 | End Function 158 | 159 | Private Sub Class_Initialize() 160 | Set mo_StdOut = libRc5Factory.C.ArrayList(vbVariant) 161 | End Sub 162 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CHttp.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CHttp" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | Private mo_Cookies As VbFcgiLib.CHttpCookies 39 | Private mo_QueryParams As VbFcgiLib.CHttpQueryParams 40 | Private mo_Downstream As VbFcgiLib.CFcgiDownstream 41 | 42 | Friend Property Set FcgiDownstream(po_Downstream As VbFcgiLib.CFcgiDownstream) 43 | Set mo_Downstream = po_Downstream 44 | End Property 45 | 46 | Public Property Get Cookies(Optional pv_CookieDomain As Variant) As VbFcgiLib.CHttpCookies 47 | ' The optional pv_CookieDomain parameter must be a string if passed 48 | ' If MISSING/Not Passed, pv_CookieDomain will default to an empt string if no domain has ever been passed 49 | ' OR if a domain has been previously passed, it will default to the last passed cookie domain 50 | 51 | Static s_LastDomain As String 52 | 53 | Dim l_Domain As String 54 | Dim l_New As Boolean 55 | 56 | If mo_Downstream Is Nothing Then Err.Raise vbObjectError, , "FCGI upstream object must be set to access cookies." 57 | 58 | If mo_Cookies Is Nothing Then 59 | ' Initialize on first call 60 | Set mo_Cookies = New VbFcgiLib.CHttpCookies 61 | l_New = True ' Indicate we need to build the cookies collection on the first pass 62 | End If 63 | 64 | If IsMissing(pv_CookieDomain) Then 65 | ' No cookie domain passed, use last passed domain 66 | l_Domain = s_LastDomain 67 | 68 | Else 69 | If VarType(pv_CookieDomain) <> vbString Then Err.Raise 5, , "Cookie domain must be a string." 70 | 71 | ' Normalize the passed domain 72 | ' Domains are case insensitive and can't include whitespace 73 | l_Domain = LCase$(stringRemoveWhitespace(pv_CookieDomain)) 74 | End If 75 | 76 | If (l_Domain <> s_LastDomain) Or l_New Then 77 | ' Build cookies collection for newly created object or changed domain 78 | s_LastDomain = l_Domain 79 | 80 | mo_Cookies.ParseCookies mo_Downstream.Params, s_LastDomain 81 | End If 82 | 83 | Set Cookies = mo_Cookies 84 | End Property 85 | 86 | Public Property Get QueryParameters() As VbFcgiLib.CHttpQueryParams 87 | If mo_QueryParams Is Nothing Then 88 | ' Initialize on first call 89 | Set mo_QueryParams = New VbFcgiLib.CHttpQueryParams 90 | If Not mo_Downstream Is Nothing Then 91 | mo_QueryParams.ParseQueryParams mo_Downstream.Params, mo_Downstream.Stdin 92 | End If 93 | End If 94 | 95 | Set QueryParameters = mo_QueryParams 96 | End Property 97 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CHttpCookie.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CHttpCookie" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | Public Value As String 39 | Public Domain As String 40 | Public Path As String 41 | Public ExpiresGmt As Date 42 | Public Secure As Boolean 43 | Public HttpOnly As Boolean 44 | 45 | Public Sub ExpireCookie() 46 | ExpiresGmt = 1 47 | End Sub 48 | 49 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CHttpCookies.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CHttpCookies" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | Private mo_Cookies As vbRichClient5.cCollection 39 | 40 | Public Property Get Exists(ByVal p_Key As String) As Boolean 41 | Exists = mo_Cookies.Exists(p_Key) 42 | End Property 43 | 44 | Public Property Get CookieHeaders() As String 45 | ' Return a SetCookie line for each Cookie in the collection 46 | Dim lo_CookieHeaders As vbRichClient5.cStringBuilder 47 | Dim lo_Cookie As CHttpCookie 48 | Dim ii As Long 49 | 50 | Set lo_CookieHeaders = libRc5Factory.C.StringBuilder 51 | 52 | For ii = 0 To mo_Cookies.Count - 1 53 | Set lo_Cookie = Me.CookieByIndex(ii) 54 | 55 | With lo_CookieHeaders 56 | .Append "Set-Cookie: " 57 | .Append libCrypt.URLEncode(Me.KeyByIndex(ii)) 58 | .Append "=" 59 | .Append libCrypt.URLEncode(lo_Cookie.Value) 60 | 61 | If stringIsEmptyOrWhitespaceOnly(lo_Cookie.Domain) Then 62 | ' Empty domain 63 | Else 64 | .Append "; Domain=" 65 | .Append lo_Cookie.Domain 66 | End If 67 | 68 | If stringIsEmptyOrWhitespaceOnly(lo_Cookie.Path) Then 69 | ' Cookie path is empty. 70 | Else 71 | .Append "; Path=" 72 | .Append lo_Cookie.Path 73 | End If 74 | 75 | If lo_Cookie.ExpiresGmt > 0 Then 76 | .Append "; Expires=" 77 | .Append dateGmtToCookieDate(lo_Cookie.ExpiresGmt) 78 | End If 79 | 80 | If lo_Cookie.Secure Then 81 | .Append "; Secure" 82 | End If 83 | 84 | If lo_Cookie.HttpOnly Then 85 | .Append "; HttpOnly" 86 | End If 87 | 88 | .AppendNL "" 89 | End With 90 | Next ii 91 | 92 | CookieHeaders = lo_CookieHeaders.ToString 93 | End Property 94 | 95 | Public Sub ParseCookies(po_FcgiParams As CFcgiParams, ByVal p_CookieDomain As String) 96 | Dim l_Cookies As String 97 | Dim la_Cookies() As String 98 | Dim la_Cookie() As String 99 | Dim lo_Cookie As VbFcgiLib.CHttpCookie 100 | 101 | Dim ii As Long 102 | Dim jj As Long 103 | 104 | ' ********** Start of procedure 105 | 106 | mo_Cookies.RemoveAll 107 | 108 | If Not po_FcgiParams.ExistsByEnum(stdparam_HttpCookie) Then 109 | apiOutputDebugString "No cookie header found in request." 110 | Exit Sub 111 | End If 112 | 113 | l_Cookies = Trim$(po_FcgiParams.ValueByEnum(stdparam_HttpCookie)) 114 | 115 | If LenB(l_Cookies) = 0 Then 116 | apiOutputDebugString "Cookies parameter was found but is empty." 117 | Exit Sub 118 | End If 119 | 120 | apiOutputDebugString "Parsing Cookies: " & l_Cookies 121 | 122 | la_Cookies = Split(l_Cookies, ";") 123 | For ii = 0 To UBound(la_Cookies) 124 | la_Cookie = Split(la_Cookies(ii), "=") 125 | 126 | Select Case UBound(la_Cookie) 127 | Case 1 128 | ' Key/Value pair 129 | ' There's no definitive spec on what to do with duplicate keys. 130 | la_Cookie(0) = Trim$(libCrypt.URLDecode(la_Cookie(0))) 131 | 132 | If mo_Cookies.Exists(la_Cookie(0)) Then 133 | ' Duplicate! 134 | Debug.Assert False 135 | apiOutputDebugString "WARNING: Duplicate cookie key found! Key: " & la_Cookie(0) 136 | 137 | Else 138 | la_Cookie(1) = libCrypt.URLDecode(la_Cookie(1)) 139 | 140 | Set lo_Cookie = New VbFcgiLib.CHttpCookie 141 | With lo_Cookie 142 | .Value = la_Cookie(1) 143 | End With 144 | 145 | lo_Cookie.Domain = p_CookieDomain 146 | lo_Cookie.Path = "/" 147 | lo_Cookie.Secure = True 148 | 149 | mo_Cookies.Add lo_Cookie, la_Cookie(0) 150 | End If 151 | 152 | Case Else 153 | ' Huh? 154 | Debug.Assert False 155 | apiOutputDebugString "WARNING: Bad cookie: " & la_Cookies(ii) 156 | 157 | End Select 158 | Next ii 159 | End Sub 160 | 161 | Public Sub AddOrReplaceCookie(ByVal p_Key As String, ByVal p_Value As String, Optional ByVal p_Domain As String, Optional ByVal p_Path As String, Optional ByVal p_ExpiryDateGmt As Date = 0, Optional ByVal p_Secure As Boolean) 162 | Dim lo_Cookie As CHttpCookie 163 | 164 | Set lo_Cookie = New VbFcgiLib.CHttpCookie 165 | With lo_Cookie 166 | .Domain = p_Domain 167 | .ExpiresGmt = p_ExpiryDateGmt 168 | .Path = p_Path 169 | .Secure = p_Secure 170 | .Value = p_Value 171 | End With 172 | 173 | If mo_Cookies.Exists(p_Key) Then 174 | mo_Cookies.Remove p_Key 175 | End If 176 | 177 | mo_Cookies.Add lo_Cookie, p_Key 178 | End Sub 179 | 180 | Public Property Get CookieByKey(ByVal p_Key As String) As CHttpCookie 181 | Set CookieByKey = mo_Cookies.Item(p_Key) 182 | End Property 183 | 184 | Public Property Get CookieCount() As Long 185 | CookieCount = mo_Cookies.Count 186 | End Property 187 | 188 | Public Property Get CookieByIndex(ByVal p_ZeroBasedIndex As Long) As CHttpCookie 189 | Set CookieByIndex = mo_Cookies.ItemByIndex(p_ZeroBasedIndex) 190 | End Property 191 | 192 | Public Property Get KeyByIndex(ByVal p_ZeroBasedIndex As Long) As String 193 | KeyByIndex = mo_Cookies.KeyByIndex(p_ZeroBasedIndex) 194 | End Property 195 | 196 | Private Sub Class_Initialize() 197 | Set mo_Cookies = libRc5Factory.C.Collection(False, BinaryCompare) 198 | End Sub 199 | 200 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CHttpHeader.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CHttpHeader" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = True 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | Public Event BeforeBuildHttpHeader() ' Give host a chance to add missing headers 39 | 40 | Private mo_Headers As vbRichClient5.cCollection 41 | 42 | Public Property Get ItemByName(ByVal p_HeaderName As String) As VbFcgiLib.CHttpHeaderField 43 | Set ItemByName = mo_Headers.Item(p_HeaderName) 44 | End Property 45 | 46 | Public Property Get ItemByIndex(ByVal p_ZeroBasedIndex As Long) As VbFcgiLib.CHttpHeaderField 47 | Set ItemByIndex = mo_Headers.ItemByIndex(p_ZeroBasedIndex) 48 | End Property 49 | 50 | Public Function Exists(ByVal p_HeaderName As String) As Boolean 51 | Exists = mo_Headers.Exists(p_HeaderName) 52 | End Function 53 | 54 | Public Sub Remove(ByVal p_HeaderName As String) 55 | mo_Headers.Remove p_HeaderName 56 | End Sub 57 | 58 | Public Function AddOrReplace(ByVal p_HeaderName As String, Optional ByVal p_PrimaryValue As String = "") As VbFcgiLib.CHttpHeaderField 59 | If Me.Exists(p_HeaderName) Then Me.Remove p_HeaderName 60 | 61 | Set AddOrReplace = Me.Add(p_HeaderName, p_PrimaryValue) 62 | End Function 63 | 64 | Public Function Add(ByVal p_HeaderName As String, Optional ByVal p_PrimaryValue As String) As VbFcgiLib.CHttpHeaderField 65 | ' All HTTP headers fields accept a primary value (for example: Content-Type: text/html") 66 | ' Pass the primary value via the p_PrimaryValue parameter. 67 | ' Some HTTP header fields accept multiple subsequent ";" separated values 68 | ' Those should be added via the InitializeByKeyValuePairs method 69 | 70 | If InStr(1, p_PrimaryValue, ";") > 0 Then Err.Raise 5, , "Only pass the primary value to this method and use InitializeByKeyValuePairs to add additional key/value pairs to the field." 71 | 72 | Set Add = New VbFcgiLib.CHttpHeaderField 73 | Add.HttpHeaderFieldName = p_HeaderName 74 | 75 | mo_Headers.Add Add, p_HeaderName 76 | 77 | If Not stringIsEmptyOrWhitespaceOnly(p_PrimaryValue) Then 78 | With Add.InitializeByKeyValuePairs() 79 | .Add "", p_PrimaryValue 80 | End With 81 | End If 82 | End Function 83 | 84 | Public Sub Append(ByVal p_HttpHeaderFields As String) 85 | Dim ii As Long 86 | Dim la_Lines() As String 87 | Dim la_Header() As String 88 | 89 | la_Lines = Split(p_HttpHeaderFields, vbNewLine) 90 | 91 | For ii = LBound(la_Lines) To UBound(la_Lines) 92 | If stringIsEmptyOrWhitespaceOnly(la_Lines(ii)) Then 93 | Debug.Assert False 94 | 95 | Else 96 | 97 | la_Header = Split(la_Lines(ii), ":", 2) 98 | 99 | If arraySize(la_Header) = 2 Then 100 | With Me.Add(stringTrimWhitespace(la_Header(0))) 101 | .InitializeByCustomString stringTrimWhitespace(la_Header(1), stringtrimwhitespace_Left) 102 | End With 103 | 104 | Else 105 | Err.Raise 5, , "Bad HTTP header line: " & la_Lines(ii) 106 | End If 107 | 108 | End If 109 | Next ii 110 | End Sub 111 | 112 | Public Function Count() As Long 113 | Count = mo_Headers.Count 114 | End Function 115 | 116 | Public Function Enumerator() As IUnknown 117 | Attribute Enumerator.VB_UserMemId = -4 118 | Attribute Enumerator.VB_MemberFlags = "40" 119 | Set Enumerator = mo_Headers.Enumerator 120 | End Function 121 | 122 | Public Function Content(Optional ByVal p_Encoding As VbFcgiLib.e_ContentEncoding = contentencoding_RecommendedDefault, Optional ByVal p_IncludeTrailingDoubleNewlines As Boolean = True) As Byte() 123 | Dim lo_HttpHeader As vbRichClient5.cStringBuilder 124 | Dim lo_HttpHeaderField As VbFcgiLib.CHttpHeaderField 125 | Dim l_HttpHeaderField As String 126 | 127 | If p_Encoding = contentencoding_RecommendedDefault Then p_Encoding = contentencoding_USASCII 128 | 129 | ' Raise event to allow caller to add/replace headers 130 | RaiseEvent BeforeBuildHttpHeader 131 | 132 | ' Begin building HTTP headers 133 | Set lo_HttpHeader = libRc5Factory.C.StringBuilder 134 | 135 | For Each lo_HttpHeaderField In mo_Headers 136 | l_HttpHeaderField = stringChomp(lo_HttpHeaderField.HttpHeader) 137 | 138 | lo_HttpHeader.AppendNL l_HttpHeaderField 139 | Next lo_HttpHeaderField 140 | 141 | If p_IncludeTrailingDoubleNewlines Then 142 | lo_HttpHeader.Append vbNewLine 143 | End If 144 | 145 | Select Case p_Encoding 146 | Case contentencoding_UTF16_LE 147 | ' Return as VB6 string 148 | Content = lo_HttpHeader.ToString 149 | 150 | Case contentencoding_UTF8 151 | ' Return in UTF-8 encoding 152 | Content = lo_HttpHeader.ToUtf8 153 | 154 | Case contentencoding_ISO8859_1 155 | ' Return in ISO-8859-1 encoding 156 | Content = stringVbToIso88591(lo_HttpHeader.ToString) 157 | 158 | Case contentencoding_USASCII 159 | ' Return in US-ASCII encoding 160 | Content = stringVbToUsAscii(lo_HttpHeader.ToString) 161 | 162 | Case Else 163 | ' Unhandled encoding type 164 | Err.Raise vbObjectError, , "Unknown content encoding: " & p_Encoding 165 | 166 | End Select 167 | 168 | End Function 169 | 170 | Private Sub Class_Initialize() 171 | Set mo_Headers = libRc5Factory.C.Collection(False, TextCompare, False) 172 | End Sub 173 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CHttpHeaderField.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CHttpHeaderField" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | ' An HTTP header "field" is a single HTTP header line 39 | ' For example, "Content-Type: text/html; charset=utf-8" 40 | 41 | Private m_Initialized As Boolean 42 | 43 | Private m_HttpHeaderFieldName As String 44 | 45 | Private mo_Pairs As VbFcgiLib.CHttpHeaderFieldKeyValuePairs 46 | Private m_HttpHeaderCustomString As String 47 | 48 | Friend Property Let HttpHeaderFieldName(ByVal p_Name As String) 49 | If stringIsEmptyOrWhitespaceOnly(p_Name) Then Err.Raise 5, , "HTTP Header name required." 50 | 51 | If InStr(1, p_Name, vbLf) > 0 Then Err.Raise 5, , "Newline characters are not allowed in header field names." 52 | If InStr(1, p_Name, vbCr) > 0 Then Err.Raise 5, , "Newline characters are not allowed in header field names." 53 | 54 | m_HttpHeaderFieldName = stringRemoveWhitespace(p_Name) 55 | End Property 56 | 57 | Friend Property Get HttpHeader() As String 58 | If Not m_Initialized Then Err.Raise 5, , "CHttpHeaderField class must be initialized first!" 59 | 60 | If Not stringIsEmptyOrWhitespaceOnly(m_HttpHeaderCustomString) Then 61 | ' Use custom HTTP header string passed to InitializeByString 62 | HttpHeader = m_HttpHeaderCustomString 63 | 64 | Else 65 | ' Not using custom HTTP header string 66 | ' so build the string from the parameters collection 67 | 68 | If mo_Pairs Is Nothing Then Err.Raise 5, , "Header parameters have not been initialized!" 69 | 70 | HttpHeader = m_HttpHeaderFieldName & ": " 71 | HttpHeader = HttpHeader & stringChomp(mo_Pairs.FieldValue) & vbNewLine 72 | End If 73 | End Property 74 | 75 | Public Sub InitializeByCustomString(ByVal p_CustomHttpHeaderStringWithoutName As String) 76 | ' Use this for a completely customized HTTP header 77 | If m_Initialized Then Err.Raise 5, , "Already initialized." 78 | 79 | If InStr(1, p_CustomHttpHeaderStringWithoutName, vbLf) > 0 Then Err.Raise 5, , "Newline characters are not allowed in header fields." 80 | If InStr(1, p_CustomHttpHeaderStringWithoutName, vbCr) > 0 Then Err.Raise 5, , "Newline characters are not allowed in header fields." 81 | 82 | Set mo_Pairs = Nothing 83 | 84 | ' Make sure the HTTP header name wasn't passed 85 | If LCase$(Left$(p_CustomHttpHeaderStringWithoutName, Len(m_HttpHeaderFieldName & ":")) <> LCase$(m_HttpHeaderFieldName) & ":") Then 86 | p_CustomHttpHeaderStringWithoutName = m_HttpHeaderFieldName & ": " & LTrim$(p_CustomHttpHeaderStringWithoutName) 87 | End If 88 | 89 | m_HttpHeaderCustomString = p_CustomHttpHeaderStringWithoutName 90 | 91 | m_Initialized = True 92 | End Sub 93 | 94 | Public Function InitializeByKeyValuePairs(Optional po_PairsCollectionOrNothing As VbFcgiLib.CHttpHeaderFieldKeyValuePairs) As VbFcgiLib.CHttpHeaderFieldKeyValuePairs 95 | If m_Initialized Then Err.Raise 5, , "Already initialized." 96 | 97 | m_HttpHeaderCustomString = "" 98 | 99 | If po_PairsCollectionOrNothing Is Nothing Then 100 | Set mo_Pairs = New VbFcgiLib.CHttpHeaderFieldKeyValuePairs 101 | Else 102 | Set mo_Pairs = po_PairsCollectionOrNothing 103 | End If 104 | 105 | Set InitializeByKeyValuePairs = mo_Pairs 106 | 107 | m_Initialized = True 108 | End Function 109 | 110 | Public Function KeyValuePairs() As VbFcgiLib.CHttpHeaderFieldKeyValuePairs 111 | If m_Initialized Then 112 | Set KeyValuePairs = mo_Pairs 113 | Else 114 | Set KeyValuePairs = Me.InitializeByKeyValuePairs() 115 | End If 116 | End Function 117 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CHttpHeaderFieldKeyValuePairs.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CHttpHeaderFieldKeyValuePairs" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = True 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | Private mo_Pairs As vbRichClient5.cCollection 39 | Private m_Dirty As Boolean 40 | 41 | Public Function Exists(ByVal p_Key As String) As Boolean 42 | If mo_Pairs.Count = 0 Then Exit Function 43 | 44 | If stringIsEmptyOrWhitespaceOnly(p_Key) Then 45 | Exists = (mo_Pairs.KeyByIndex(0) = "") 46 | Else 47 | Exists = mo_Pairs.Exists(p_Key) 48 | End If 49 | End Function 50 | 51 | Public Sub Add(ByVal p_Key As String, ByVal p_Value As String) 52 | If stringIsEmptyOrWhitespaceOnly(p_Key) Then 53 | ' Empty key must be first item in collection 54 | If mo_Pairs.Count Then Err.Raise 5, , "Empty key must be first key/pair." 55 | End If 56 | 57 | If InStr(1, p_Key, vbCr) > 0 Then Err.Raise 5, , "Key can not contain new line character." 58 | If InStr(1, p_Key, vbLf) > 0 Then Err.Raise 5, , "Key can not contain new line character." 59 | If InStr(1, p_Value, vbCr) > 0 Then Err.Raise 5, , "Value can not contain new line character." 60 | If InStr(1, p_Value, vbLf) > 0 Then Err.Raise 5, , "Value can not contain new line character." 61 | 62 | m_Dirty = True 63 | 64 | If stringIsEmptyOrWhitespaceOnly(p_Key) Then 65 | mo_Pairs.Add p_Value 66 | Else 67 | mo_Pairs.Add p_Value, p_Key 68 | End If 69 | End Sub 70 | 71 | Friend Function FieldValue() As String 72 | Static s_FieldValue As String 73 | 74 | Dim ii As Long 75 | Dim jj As Long 76 | Dim l_Key As String 77 | Dim l_Value As String 78 | Dim l_QuoteValue As Boolean 79 | Dim l_Char As String 80 | 81 | If stringIsEmptyOrWhitespaceOnly(s_FieldValue) Or m_Dirty Then 82 | s_FieldValue = "" 83 | 84 | For ii = 0 To mo_Pairs.Count - 1 85 | l_Key = mo_Pairs.KeyByIndex(ii) 86 | 87 | If l_Key = "" Then 88 | If ii > 0 Then 89 | Err.Raise vbObjectError, , "Empty key must be the first parameter." 90 | End If 91 | Else 92 | l_Key = l_Key & "=" 93 | End If 94 | 95 | If ii > 0 Then 96 | l_Key = "; " & l_Key 97 | End If 98 | 99 | l_Value = mo_Pairs.ItemByIndex(ii) 100 | 101 | If Left$(l_Value, 1) <> """" Then 102 | If l_Key <> "" Then ' First parameters don't seem to require quoting? 103 | ' For example Content-Type: text/html would appear to need quoting 104 | ' as per RFC2616 since it contains a "/" character (which is on the special characters list) 105 | ' but it is never done in the wild. Dates contain ":" characters, but they too are never quoted 106 | ' when they are the first token of a header field. 107 | 108 | ' See if we need to quote this value 109 | For jj = 1 To Len(l_Value) 110 | 111 | l_Char = Mid$(l_Value, jj, 1) 112 | 113 | Select Case l_Char 114 | Case "(", ")", "<", ">", "@", _ 115 | ",", ";", ":", "\", "<", _ 116 | ">", "/", "[", "]", "?", "=", _ 117 | "{", "}", vbTab, " " 118 | 119 | ' RFC2616 says these characters must be placed in quoted strings 120 | l_QuoteValue = True 121 | 122 | Case Else 123 | Select Case AscW(l_Char) 124 | Case Is < 0, &H0 To &H8, &HA To &H1A, &H22, &H7F To &H7FFF 125 | ' Illegal character 126 | Err.Raise vbObjectError, , "Illegal character '" & Mid$(l_Value, jj, 1) & "' found in parameter for key: " & l_Key 127 | End Select 128 | End Select 129 | Next jj 130 | End If 131 | End If 132 | 133 | If l_QuoteValue Then 134 | l_QuoteValue = False 135 | l_Value = """" & Replace$(l_Value, """", "\""") & """" 136 | End If 137 | 138 | s_FieldValue = s_FieldValue & l_Key & l_Value 139 | 140 | Next ii 141 | End If 142 | 143 | FieldValue = s_FieldValue 144 | End Function 145 | 146 | Private Sub Class_Initialize() 147 | Set mo_Pairs = libRc5Factory.C.Collection(False) 148 | End Sub 149 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CHttpQueryParamValues.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CHttpQueryParamValues" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | Private mo_Values As vbRichClient5.cArrayList 39 | 40 | Public Property Get Count() As Long 41 | Count = mo_Values.Count 42 | End Property 43 | 44 | Public Sub Add(ByVal p_Value As String) 45 | mo_Values.Add p_Value 46 | End Sub 47 | 48 | Public Property Get ValueByIndex(ByVal p_ZeroBasedIndex As Long) As String 49 | ValueByIndex = mo_Values.Item(p_ZeroBasedIndex) 50 | End Property 51 | 52 | Public Property Let ValueByIndex(ByVal p_ZeroBasedIndex As Long, ByVal p_Value As String) 53 | mo_Values.Item(p_ZeroBasedIndex) = p_Value 54 | End Property 55 | 56 | Private Sub Class_Initialize() 57 | Set mo_Values = libRc5Factory.C.ArrayList(vbString) 58 | End Sub 59 | 60 | Public Property Get IsValueTrueByIndex(ByVal p_ZeroBasedIndex As Long) As Boolean 61 | Dim l_Value As String 62 | Dim l_ValueLong As Long 63 | 64 | l_Value = LCase$(Me.ValueByIndex(p_ZeroBasedIndex)) 65 | 66 | Select Case l_Value 67 | Case "1", "-1", "on", "yes", "true", "y" 68 | IsValueTrueByIndex = True 69 | Case Else 70 | If IsNumeric(l_Value) Then 71 | l_ValueLong = CLng(l_Value) 72 | End If 73 | 74 | IsValueTrueByIndex = (l_ValueLong <> 0) 75 | End Select 76 | End Property 77 | 78 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CHttpQueryParams.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CHttpQueryParams" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | Private mo_QueryParams As vbRichClient5.cCollection 39 | 40 | Public Property Get Exists(ByVal p_Key As String) As Boolean 41 | Exists = mo_QueryParams.Exists(p_Key) 42 | End Property 43 | 44 | Public Sub RemoveByKey(ByVal p_Key As String) 45 | If Me.Exists(p_Key) Then 46 | mo_QueryParams.Remove p_Key 47 | End If 48 | End Sub 49 | 50 | Public Sub AppendValue(ByVal p_Key As String, ByVal p_Value As String) 51 | Dim lo_Values As CHttpQueryParamValues 52 | Dim l_Exists As Boolean 53 | 54 | l_Exists = mo_QueryParams.Exists(p_Key) 55 | If l_Exists Then 56 | Set lo_Values = mo_QueryParams.Item(p_Key) 57 | Else 58 | Set lo_Values = New CHttpQueryParamValues 59 | End If 60 | 61 | lo_Values.Add p_Value 62 | 63 | If Not l_Exists Then 64 | mo_QueryParams.Add lo_Values, p_Key 65 | End If 66 | End Sub 67 | 68 | Public Property Get DefaultValue(p_KeyOrZeroBasedIndex As Variant) As String 69 | Attribute DefaultValue.VB_UserMemId = 0 70 | Attribute DefaultValue.VB_MemberFlags = "40" 71 | ' Shortcut for ValuesByKey("key").ValueByIndex(0) 72 | ' or ValuesByIndex(#).ValueByIndex(0) 73 | 74 | If VarType(p_KeyOrZeroBasedIndex) = vbString Then 75 | DefaultValue = Me.ValuesByKey(p_KeyOrZeroBasedIndex).ValueByIndex(0) 76 | Else 77 | DefaultValue = Me.ValuesByIndex(p_KeyOrZeroBasedIndex).ValueByIndex(0) 78 | End If 79 | End Property 80 | 81 | Public Property Get ValuesByKey(ByVal p_Key As String) As CHttpQueryParamValues 82 | Dim ii As Long 83 | 84 | If Trim$(p_Key) = "" Then 85 | ' Get default, requires loop search since cCollection raises error on empty key 86 | For ii = 0 To mo_QueryParams.Count - 1 87 | If IsEmpty(mo_QueryParams.ItemByIndex(ii)) Then 88 | Set ValuesByKey = mo_QueryParams.ItemByIndex(ii) 89 | 90 | Exit For 91 | End If 92 | Next ii 93 | 94 | Else 95 | Set ValuesByKey = mo_QueryParams.Item(p_Key) 96 | 97 | End If 98 | 99 | If ValuesByKey Is Nothing Then 100 | Err.Raise vbObjectError, , "Values could not be found for key: " & p_Key 101 | End If 102 | End Property 103 | 104 | Public Property Get KeyByIndex(ByVal p_ZeroBasedIndex As Long) As String 105 | KeyByIndex = mo_QueryParams.KeyByIndex(p_ZeroBasedIndex) 106 | End Property 107 | 108 | Public Property Get KeyCount() As Long 109 | KeyCount = mo_QueryParams.Count 110 | End Property 111 | 112 | Public Property Get ValueCountByKey(ByVal p_Key As String) As Long 113 | ValueCountByKey = ValuesByKey(p_Key).Count 114 | End Property 115 | 116 | Public Property Get ValuesByIndex(ByVal p_ZeroBasedIndex As Long) As CHttpQueryParamValues 117 | Set ValuesByIndex = mo_QueryParams.ItemByIndex(p_ZeroBasedIndex) 118 | End Property 119 | 120 | Public Sub ParseQueryParams(po_FcgiParams As CFcgiParams, po_FcgiStdin As CFcgiStdIn) 121 | Dim l_QueryString As String 122 | Dim la_QueryPairs() As String 123 | Dim la_QueryPair() As String 124 | Dim lo_Values As VbFcgiLib.CHttpQueryParamValues 125 | 126 | Dim ii As Long 127 | Dim jj As Long 128 | 129 | ' ********** Start of procedure 130 | 131 | mo_QueryParams.RemoveAll 132 | 133 | If po_FcgiParams.ExistsByEnum(stdparam_QueryString) Then 134 | l_QueryString = po_FcgiParams.ValueByEnum(stdparam_QueryString) 135 | End If 136 | 137 | Select Case UCase$(po_FcgiParams.ValueByEnum(stdparam_RequestMethod)) 138 | Case "POST" 139 | ' May have parameters in body 140 | Select Case LCase$(Left$(po_FcgiParams.ValueByEnum(stdparam_ContentType), Len("application/x-www-form-urlencoded"))) 141 | Case "application/x-www-form-urlencoded" 142 | 143 | ' Add body to querystring 144 | apiOutputDebugString "application/x-www-form-urlencoded content - will parse query parameters" 145 | apiOutputDebugString "POST body: " & StrConv(po_FcgiStdin.Content, vbUnicode) 146 | 147 | l_QueryString = l_QueryString & StrConv(po_FcgiStdin.Content, vbUnicode) 148 | End Select 149 | End Select 150 | 151 | If stringIsEmptyOrWhitespaceOnly(l_QueryString) Then Exit Sub 152 | 153 | If InStr(1, l_QueryString, ";") Then 154 | ' Accept ; or & as pair separators 155 | l_QueryString = Replace(l_QueryString, ";", "&") 156 | End If 157 | 158 | la_QueryPairs = Split(l_QueryString, "&") 159 | For ii = 0 To UBound(la_QueryPairs) 160 | 161 | Set lo_Values = Nothing 162 | la_QueryPair = Split(la_QueryPairs(ii), "=") 163 | 164 | Select Case UBound(la_QueryPair) 165 | Case 0 166 | ' Default argument, not a pair 167 | la_QueryPair(0) = libCrypt.URLDecode(la_QueryPair(0)) 168 | 169 | For jj = 0 To mo_QueryParams.Count - 1 170 | If IsEmpty(mo_QueryParams.KeyByIndex(jj)) Then 171 | Set lo_Values = mo_QueryParams.ItemByIndex(jj) 172 | 173 | mo_QueryParams.RemoveByIndex jj 174 | 175 | Exit For 176 | End If 177 | Next jj 178 | 179 | If lo_Values Is Nothing Then 180 | Set lo_Values = New CHttpQueryParamValues 181 | End If 182 | 183 | lo_Values.Add la_QueryPair(0) 184 | 185 | mo_QueryParams.Add lo_Values 186 | 187 | Case 1 188 | ' Key/Value pair 189 | ' There's no definitive spec on what to do with duplicate keys. 190 | la_QueryPair(0) = Trim$(libCrypt.URLDecode(la_QueryPair(0))) 191 | la_QueryPair(1) = libCrypt.URLDecode(la_QueryPair(1)) 192 | 193 | For jj = 0 To mo_QueryParams.Count - 1 194 | If mo_QueryParams.KeyByIndex(jj) = la_QueryPair(0) Then 195 | ' Key exists, remove it 196 | Set lo_Values = mo_QueryParams.ItemByIndex(jj) 197 | 198 | mo_QueryParams.RemoveByIndex jj 199 | 200 | Exit For 201 | End If 202 | Next jj 203 | 204 | If lo_Values Is Nothing Then 205 | Set lo_Values = New VbFcgiLib.CHttpQueryParamValues 206 | End If 207 | 208 | lo_Values.Add la_QueryPair(1) 209 | 210 | mo_QueryParams.Add lo_Values, la_QueryPair(0) 211 | 212 | Case Else 213 | ' Huh? 214 | Debug.Assert False 215 | apiOutputDebugString "WARNING: Bad query string parameter: " & la_QueryPairs(ii) 216 | End Select 217 | Next ii 218 | End Sub 219 | 220 | Private Sub Class_Initialize() 221 | Set mo_QueryParams = libRc5Factory.C.Collection(False, BinaryCompare) 222 | End Sub 223 | 224 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CSimulator.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CSimulator" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = True 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | Private mo_Downstream As VbFcgiLib.CFcgiDownstream 17 | 18 | Public Sub SimulateRequest(ByVal p_Url As String, po_FcgiApp As VbFcgiLib.IFcgiApp) 19 | Dim lo_Request As VbFcgiLib.CFcgiRequest 20 | Dim lo_Response As VbFcgiLib.CFcgiResponse 21 | Dim la_Url() As String 22 | Dim ii As Long 23 | Dim l_ChunkPos As Long 24 | 25 | Set lo_Request = New VbFcgiLib.CFcgiRequest 26 | Set lo_Response = New VbFcgiLib.CFcgiResponse 27 | 28 | ' Cleanup URL 29 | p_Url = Replace$(p_Url, " ", "%20") 30 | p_Url = Replace$(p_Url, "\", "/") 31 | 32 | l_ChunkPos = InStr(1, p_Url, "?") 33 | If l_ChunkPos > 1 Then 34 | mo_Downstream.Params.ValueByEnum(stdparam_QueryString) = Mid$(p_Url, l_ChunkPos + 1) 35 | 36 | ' Chop query 37 | p_Url = Left$(p_Url, l_ChunkPos - 1) 38 | End If 39 | 40 | l_ChunkPos = InStr(1, p_Url, "://") 41 | If l_ChunkPos < 1 Then 42 | mo_Downstream.Params.ValueByEnum(stdparam_RequestScheme) = "http" 43 | Else 44 | mo_Downstream.Params.ValueByEnum(stdparam_RequestScheme) = LCase$(Left$(p_Url, l_ChunkPos - 1)) 45 | 46 | ' Chop protocol 47 | p_Url = Mid$(p_Url, l_ChunkPos + 3) 48 | End If 49 | 50 | ' Remove trailing "/" if exists 51 | If Right$(p_Url, 1) = "/" Then p_Url = Left$(p_Url, Len(p_Url) - 1) 52 | 53 | la_Url = Split(p_Url, "\") 54 | 55 | ' Check for port 56 | l_ChunkPos = InStr(1, la_Url(0), ":") 57 | If l_ChunkPos > 0 Then 58 | mo_Downstream.Params.ValueByEnum(stdparam_ServerPort) = Mid$(la_Url(0), l_ChunkPos + 1) 59 | 60 | ' Strip port 61 | la_Url(0) = Left$(la_Url(0), l_ChunkPos - 1) 62 | Else 63 | Select Case LCase$(mo_Downstream.Params.ValueByEnum(stdparam_RequestMethod)) 64 | Case "https" 65 | mo_Downstream.Params.ValueByEnum(stdparam_ServerPort) = 443 66 | Case Else 67 | mo_Downstream.Params.ValueByEnum(stdparam_ServerPort) = 80 68 | End Select 69 | End If 70 | 71 | ' Remove user name if exists 72 | l_ChunkPos = InStr(1, la_Url(0), "@") 73 | If l_ChunkPos > 0 Then 74 | la_Url(0) = Mid$(la_Url(0), l_ChunkPos + 1) 75 | End If 76 | 77 | ' Init HTTP_HOST parameter 78 | mo_Downstream.Params.ValueByEnum(stdparam_HttpHost) = la_Url(0) 79 | 80 | ' Init DOCUMENT_URI, REQUEST_URI, SCRIPTNAME 81 | ' TODO: Make sure this works for all kinds of passed URLs...there undoubtedly issues with some 82 | ' URLS in the current for (for example, 83 | mo_Downstream.Params.ValueByEnum(stdparam_ScriptName) = "/" & la_Url(UBound(la_Url)) 84 | mo_Downstream.Params.ValueByEnum(stdparam_DocumentUri) = "/" 85 | For ii = 1 To UBound(la_Url) 86 | mo_Downstream.Params.ValueByEnum(stdparam_DocumentUri) = mo_Downstream.Params.ValueByEnum(stdparam_DocumentUri) & la_Url(ii) 87 | Next ii 88 | mo_Downstream.Params.ValueByEnum(stdparam_RequestUri) = mo_Downstream.Params.ValueByEnum(stdparam_DocumentUri) & "?" & mo_Downstream.Params.ValueByEnum(stdparam_QueryString) 89 | 90 | mo_Downstream.Params.State = paramstate_Built 91 | 92 | ' Parse HTTP query params 93 | Set lo_Request.FcgiDownstream = mo_Downstream 94 | 95 | lo_Request.Http.QueryParameters.ParseQueryParams mo_Downstream.Params, Nothing 96 | 97 | mo_Downstream.State = fcgireqstate_Ready 98 | Set lo_Request.FcgiDownstream = mo_Downstream 99 | 100 | po_FcgiApp.ProcessRequest lo_Request, lo_Response 101 | End Sub 102 | 103 | Private Sub Class_Initialize() 104 | Set mo_Downstream = New VbFcgiLib.CFcgiDownstream 105 | 106 | mo_Downstream.Initialize 0, 0 107 | 108 | With mo_Downstream.Params 109 | .State = paramstate_Building 110 | 111 | ' Set up default FCGI parameter values 112 | 113 | .ValueByEnum(stdparam_ServerSoftware) = "nginx/1.13.7" 114 | .ValueByEnum(stdparam_RequestMethod) = "GET" 115 | .ValueByEnum(stdparam_GatewayInterface) = "CGI/1.1" 116 | .ValueByEnum(stdparam_ServerProtocol) = "HTTP/1.1" 117 | .ValueByEnum(stdparam_RemoteAddr) = "127.0.0.1" 118 | .ValueByEnum(stdparam_RemotePort) = Int(Rnd * 32767) + 32767 ' Random remote port, not used for anything 119 | .ValueByEnum(stdparam_DocumentRoot) = Replace$(pathBin, "\", "/") & "nginx/html" 120 | .ValueByEnum(stdparam_RedirectStatus) = 200 121 | .ValueByEnum(stdparam_HttpUserAgent) = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0" 122 | .ValueByEnum(stdparam_HttpAccept) = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" 123 | .ValueByEnum(stdparam_HttpAcceptEncoding) = "gzip, deflate" 124 | .ValueByEnum(stdparam_HttpAcceptLanguage) = "en-US,en;q=0.5" 125 | .ValueByEnum(stdparam_HttpConnection) = "keep-alive" 126 | .ValueByEnum(stdparam_ServerName) = "localhost" 127 | .ValueByEnum(stdparam_ServerPort) = "80" 128 | End With 129 | End Sub 130 | 131 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CSimulatorFcgiApp.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CSimulatorFcgiApp" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = False 14 | Option Explicit 15 | 16 | Implements VbFcgiLib.IFcgiApp 17 | 18 | Private Sub IFcgiApp_ProcessRequest(po_Request As CFcgiRequest, po_Response As CFcgiResponse) 19 | Debug.Assert False 20 | End Sub 21 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CTests.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CTests" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = False 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | Private WithEvents mo_Template As VbFcgiLib.CBuilderTemplate 39 | Attribute mo_Template.VB_VarHelpID = -1 40 | 41 | Public Sub TestTemplateInfiniteLoopProtection() 42 | Set mo_Template = New CBuilderTemplate 43 | 44 | mo_Template.ParseFile "This is a [[TITLE]] test." 45 | mo_Template.Finish contentencoding_UTF16_LE 46 | Debug.Print mo_Template.Content 47 | End Sub 48 | 49 | Private Sub mo_Template_FoundTag(ByVal p_Tag As String, po_Replacement As VbFcgiLib.CWebStringTemplate, ByRef p_DoNotReplace As Boolean) 50 | Select Case p_Tag 51 | Case "TITLE" 52 | po_Replacement.SkipEncodeEntities = True 53 | po_Replacement.OpenTags "p" 54 | po_Replacement.Append "HELLO [[ABC]]" 55 | po_Replacement.CloseAllOpenedTags 56 | 57 | Case "ABC" 58 | po_Replacement = "XXX [[TITLE]] XXX" 59 | End Select 60 | End Sub 61 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/CWebStringTemplate.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "CWebStringTemplate" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = True 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | ' Wraps the CWebStringBase class and adds extra properties specific to CBuilderTemplate 39 | 40 | Private mo_String As VbFcgiLib.CWebStringBase 41 | 42 | Public SkipCache As Boolean ' Do not cache this content for use in other matching tags without raising an event. 43 | Public SkipEncodeEntities As Boolean ' Do not encode HTML entities. 44 | 45 | Private Sub Class_Initialize() 46 | Set mo_String = New VbFcgiLib.CWebStringBase 47 | End Sub 48 | 49 | ' The following methods wrap the corresponding methods in the CWebString class. 50 | 51 | Public Sub Append(ByVal p_Text As String) 52 | mo_String.Append p_Text 53 | End Sub 54 | 55 | Public Sub Append2(ByVal p_Text1 As String, ByVal p_Text2 As String) 56 | mo_String.Append2 p_Text1, p_Text2 57 | End Sub 58 | 59 | Public Sub Append3(ByVal p_Text1 As String, ByVal p_Text2 As String, ByVal p_Text3 As String) 60 | mo_String.Append3 p_Text1, p_Text2, p_Text3 61 | End Sub 62 | 63 | Public Sub Append4(ByVal p_Text1 As String, ByVal p_Text2 As String, ByVal p_Text3 As String, ByVal p_Text4 As String) 64 | mo_String.Append4 p_Text1, p_Text2, p_Text3, p_Text4 65 | End Sub 66 | 67 | Public Sub AppendDocType(Optional ByVal p_DocType As e_HtmlDocType = 0&, Optional ByVal p_CustomDocType As String) 68 | mo_String.AppendDocType p_DocType, p_CustomDocType 69 | End Sub 70 | 71 | Public Sub AppendImageTag(ByVal p_Source As String, Optional ByVal p_AlternateText As String, Optional ByVal p_WidthPx As Long = -1&, Optional ByVal p_HeightPx As Long = -1&, Optional ByVal p_Class As String, Optional ByVal p_Id As String, Optional ByVal p_Style As String) 72 | mo_String.AppendImageTag p_Source, p_AlternateText, p_WidthPx, p_HeightPx, p_Class, p_Id, p_Style 73 | End Sub 74 | 75 | Public Sub AppendWithTag(ByVal p_Text As String, ByVal p_Tag As String, Optional ByVal p_EncodeEntities As Boolean = True) 76 | mo_String.AppendWithTag p_Text, p_Tag, p_EncodeEntities 77 | End Sub 78 | 79 | Public Sub AppendWithTagAndAttributes(ByVal p_Text As String, ByVal p_Tag As String, Optional ByVal p_TagClass As String, Optional ByVal p_TagId As String, Optional ByVal p_TagStyle As String, Optional ByVal p_EncodeEntities As Boolean = True) 80 | mo_String.AppendWithTagAndAttributes p_Text, p_Tag, p_TagClass, p_TagId, p_TagStyle, p_EncodeEntities 81 | End Sub 82 | 83 | Public Sub Clear() 84 | mo_String.Clear 85 | End Sub 86 | 87 | Public Sub CloseAllOpenedTags() 88 | mo_String.CloseAllOpenedTags 89 | End Sub 90 | 91 | Public Sub CloseLastOpenedTag() 92 | mo_String.CloseLastOpenedTag 93 | End Sub 94 | 95 | Public Sub CloseOpenedTagsToIndex(ByVal p_Index As Long) 96 | mo_String.CloseOpenedTagsToIndex p_Index 97 | End Sub 98 | 99 | Public Property Let Content(ByVal p_Content As String) 100 | mo_String.Content = p_Content 101 | End Property 102 | 103 | Public Property Get Content() As String 104 | Attribute Content.VB_UserMemId = 0 105 | Content = mo_String.Content 106 | End Property 107 | 108 | Public Function EncodeHtmlEntities(ByVal p_Text As String) As String 109 | EncodeHtmlEntities = mo_String.EncodeHtmlEntities(p_Text) 110 | End Function 111 | 112 | Public Function Length() As Long 113 | Length = mo_String.Length 114 | End Function 115 | 116 | Public Function OpenHyperlinkTag(ByVal p_Href As String, Optional ByVal p_Target As String, Optional ByVal p_Class As String, Optional ByVal p_Id As String, Optional ByVal p_Style As String) As Long 117 | OpenHyperlinkTag = mo_String.OpenHyperlinkTag(p_Href, p_Target, p_Class, p_Id, p_Style) 118 | End Function 119 | 120 | Public Function OpenTags(ParamArray pa_Tags() As Variant) As Long 121 | ' This is an ugly solution for passing ParamArray parameter values up to another method that takes a ParamArry parameter. 122 | ' Since we can't just pass pa_Tags as a single parameter, we have to check the Ubound of pa_tags and pass each element individually. 123 | ' See converstaion here: http://www.vbforums.com/showthread.php?857003-Default-Class-Property-As-Obejct 124 | 125 | ' I don't like it for many reasons, but the worst might be that we are 126 | ' stuck at a range of X to Y parameters unless we modify the source code. 127 | ' I've set the range at 0 to 9 as of December 21, 2017 (which should be sufficient, but let's all laugh at the comment at some unspecified future time). 128 | 129 | ' A different approach is demonstrated here: http://www.vbforums.com/showthread.php?844667-VB6-VB6-tlb-Passing-a-ParamArray-without-Copying 130 | ' But I'm unsure of the licensing status of that code, plus the maintenance burden looks quite scary if there should be any bugs. 131 | 132 | Select Case UBound(pa_Tags) 133 | Case -1 134 | ' No parameters 135 | OpenTags = mo_String.OpenTags 136 | 137 | Case 0 138 | OpenTags = mo_String.OpenTags(pa_Tags(0)) 139 | 140 | Case 1 141 | OpenTags = mo_String.OpenTags(pa_Tags(0), pa_Tags(1)) 142 | 143 | Case 2 144 | OpenTags = mo_String.OpenTags(pa_Tags(0), pa_Tags(1), pa_Tags(2)) 145 | 146 | Case 3 147 | OpenTags = mo_String.OpenTags(pa_Tags(0), pa_Tags(1), pa_Tags(2), pa_Tags(3)) 148 | 149 | Case 4 150 | OpenTags = mo_String.OpenTags(pa_Tags(0), pa_Tags(1), pa_Tags(2), pa_Tags(3), pa_Tags(4)) 151 | 152 | Case 5 153 | OpenTags = mo_String.OpenTags(pa_Tags(0), pa_Tags(1), pa_Tags(2), pa_Tags(3), pa_Tags(4), pa_Tags(5)) 154 | 155 | Case 6 156 | OpenTags = mo_String.OpenTags(pa_Tags(0), pa_Tags(1), pa_Tags(2), pa_Tags(3), pa_Tags(4), pa_Tags(5), pa_Tags(6)) 157 | 158 | Case 7 159 | OpenTags = mo_String.OpenTags(pa_Tags(0), pa_Tags(1), pa_Tags(2), pa_Tags(3), pa_Tags(4), pa_Tags(5), pa_Tags(6), pa_Tags(7)) 160 | 161 | Case 8 162 | OpenTags = mo_String.OpenTags(pa_Tags(0), pa_Tags(1), pa_Tags(2), pa_Tags(3), pa_Tags(4), pa_Tags(5), pa_Tags(6), pa_Tags(7), pa_Tags(8)) 163 | 164 | Case 9 165 | OpenTags = mo_String.OpenTags(pa_Tags(0), pa_Tags(1), pa_Tags(2), pa_Tags(3), pa_Tags(4), pa_Tags(5), pa_Tags(6), pa_Tags(7), pa_Tags(8), pa_Tags(9)) 166 | 167 | Case Else 168 | ' Max tags reached - we can always extend this limit as required by adding more Cases above. 169 | Err.Raise 5, , "Maximum Tag count reached." 170 | End Select 171 | End Function 172 | 173 | Public Function OpenTagWithAttributes(ByVal p_Tag As String, Optional ByVal p_TagClass As String, Optional ByVal p_TagId As String, Optional ByVal p_TagStyle As String) As Long 174 | OpenTagWithAttributes = mo_String.OpenTagWithAttributes(p_Tag, p_TagClass, p_TagId, p_TagStyle) 175 | End Function 176 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/IBuilder.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "IBuilder" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | ' ------------------------------------------------------------------------------- 39 | ' PURPOSE 40 | ' ------------------------------------------------------------------------------- 41 | ' 42 | ' This class defines the interface that all VbFcgi CBuilder* classes implement. 43 | ' Classes that implement the IBuilder interface are designed to help you more 44 | ' easily build web content (including HTTP headers) using VB6. 45 | ' 46 | ' As of December 21, 2017, the following VbFcgiLib classes implement the 47 | ' IBuilder interface: 48 | ' 49 | ' CBuilderFile - helper class for sending locally stored files downstream. 50 | ' (for example, PDFs, images, etc...) 51 | ' 52 | ' CBuilderHtml - helper class for building HTML files completely in memory. 53 | ' 54 | ' CBuilderTemplate - helper class for reading template files (usually HTML) 55 | ' from the local file system and detecting & replacing special 56 | ' "tags" to generate dynamic page data for sending downstream. 57 | ' 58 | ' ------------------------------------------------------------------------------- 59 | ' USAGE 60 | ' ------------------------------------------------------------------------------- 61 | ' 62 | ' In general you will not implement your own IBuilder classes, so usage is 63 | ' limited to interaction with the packaged classes that implement the 64 | ' IBuilder interface. See each IBuilder implementing class for usage specific 65 | ' to those classes. 66 | 67 | Public Property Get HttpHeader() As VbFcgiLib.CHttpHeader 68 | ' Returns a IHttpHeaderFields object 69 | End Property 70 | 71 | Public Property Get IsFinished() As Boolean 72 | ' Returns TRUE if the Finish method has been called. 73 | ' Otherwise returns FALSE 74 | End Property 75 | 76 | Public Sub Finish(Optional ByVal p_ContentEncoding As VbFcgiLib.e_ContentEncoding = contentencoding_RecommendedDefault) 77 | ' Call this method to close the content buffer and convert it to the passed encoding. 78 | ' This method must be called before Length/Content properties are called. 79 | End Sub 80 | 81 | Public Property Get Length() As Long 82 | ' Returns the length of the content buffer in bytes (in the encoding passed to the Finish method) 83 | ' This property cannot be called before the Finish method has been called 84 | End Property 85 | 86 | Public Property Get Content() As Byte() 87 | ' Returns a byte array of all content in the buffer in the encoding passed to the Finish method 88 | ' This property cannot be called before the Finish method has been called 89 | End Property 90 | 91 | Public Sub Reset() 92 | ' Clear all variables and objects and/or reset them to sensible defaults 93 | End Sub 94 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/IFcgiApp.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "IFcgiApp" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | ' ------------------------------------------------------------------------------- 39 | ' PURPOSE 40 | ' ------------------------------------------------------------------------------- 41 | ' 42 | ' This class defines the interface that all upstream FCGI applications must 43 | ' implement in order to be used by the VbFcgi framework. 44 | ' 45 | ' ------------------------------------------------------------------------------- 46 | ' USAGE 47 | ' ------------------------------------------------------------------------------- 48 | ' 49 | ' To create a class that can be used by the VbFcgi framework you must: 50 | ' 51 | ' 1) Create a new ActiveX Dll project. 52 | ' 53 | ' 2) Add a reference to VbFcgiLib to your project. 54 | ' 55 | ' 3) Rename the default "Class1" class to "CFcgiApp" 56 | ' 57 | ' 4) In the "General" code section for the "CFcgiApp" class, type: 58 | ' 59 | ' Implements VbFcgiLib.IFcgiApp 60 | ' 61 | ' 5) Add the following code: 62 | ' 63 | ' Private Sub IFcgiApp_ProcessRequest(po_Request As VbFcgiLib.CFcgiRequest, po_Response As VbFcgiLib.CFcgiResponse) 64 | ' 65 | ' 6) Code your web application within the IFcgiApp_ProcessRequest sub. See comments 66 | ' in the ProcessRequest sub (below) for more details. 67 | 68 | Public Sub ProcessRequest(po_Request As VbFcgiLib.CFcgiRequest, po_Response As VbFcgiLib.CFcgiResponse) 69 | ' This sub is called when an FCGI request is received by the CFgiServer class. 70 | 71 | ' The po_Request object holds information received from 72 | ' the browser (Http) and web server (Fcgi) that can be queried to build your dynamic web pages. 73 | ' For more information, see the VbFcgiLib.CFcgiRequest class. 74 | 75 | ' The po_Response object should be used by your FCGI application 76 | ' to pass data downstream to the web server/browser. 77 | ' For more information, see the VbFcgiLib.CFcgiResponse class. 78 | End Sub 79 | 80 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/IJson.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "IJson" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = True 14 | Option Explicit 15 | 16 | ' Copyright (c) 2017 Jason Peter Brown 17 | ' 18 | ' MIT License 19 | ' 20 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 21 | ' of this software and associated documentation files (the "Software"), to deal 22 | ' in the Software without restriction, including without limitation the rights 23 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | ' copies of the Software, and to permit persons to whom the Software is 25 | ' furnished to do so, subject to the following conditions: 26 | ' 27 | ' The above copyright notice and this permission notice shall be included in all 28 | ' copies or substantial portions of the Software. 29 | ' 30 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 36 | ' SOFTWARE. 37 | 38 | Public Property Get JsonString() As String 39 | ' Get the data held in the JSON collection as a VB6 UTF16LE string 40 | End Property 41 | 42 | Public Property Let JsonString(ByVal p_JsonString As String) 43 | ' Initialize a IJson object by a JSON string (VB/UTF16LE). 44 | ' This will replace any existing JSON data 45 | End Property 46 | 47 | Public Property Get JsonUtf8() As Byte() 48 | ' Get the data held in the JSON collection as a UTF8 Byte Array 49 | End Property 50 | 51 | Public Property Let JsonUtf8(pa_JsonUtf8Bytes() As Byte) 52 | ' Initialize a IJson object by a JSON byte array (UTF8). 53 | ' This will replace any existing JSON data 54 | End Property 55 | 56 | Public Property Get JsonRc5Collection() As vbRichClient5.cCollection 57 | ' Get the JSON collection 58 | End Property 59 | 60 | Public Property Set JsonRc5Collection(po_Collection As vbRichClient5.cCollection) 61 | ' Initialize a IJson object using a vbRichClient5 cCollection class (JSONArray or JSONObject type). 62 | ' This will replace any existing JSON data 63 | End Property 64 | 65 | Public Sub AddJsonObjectByKeyValuePairs(ParamArray p_KeyAndValuePairs() As Variant) 66 | ' Add data to the JSON collection by key and value pairs. 67 | ' Existing data will be left alone. 68 | ' For example: AddJsonObjectByKeyValuePairs "status", 200, "message", "OK" 69 | ' Will produce: {"status":200,"message":"OK"} 70 | End Sub 71 | 72 | Public Sub AddJsonArrayByValues(ParamArray p_Values() As Variant) 73 | ' Add to to JSON collection by an array of values. 74 | ' Existing data will be left alone. 75 | ' For Example: AddJsonArrayByValues 1,2,3,4,5 76 | ' Will produce: [1,2,3,4,5] 77 | End Sub 78 | 79 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/MConfig.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "MConfig" 2 | Option Explicit 3 | 4 | ' Copyright (c) 2017 Jason Peter Brown 5 | ' 6 | ' MIT License 7 | ' 8 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 9 | ' of this software and associated documentation files (the "Software"), to deal 10 | ' in the Software without restriction, including without limitation the rights 11 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | ' copies of the Software, and to permit persons to whom the Software is 13 | ' furnished to do so, subject to the following conditions: 14 | ' 15 | ' The above copyright notice and this permission notice shall be included in all 16 | ' copies or substantial portions of the Software. 17 | ' 18 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | ' SOFTWARE. 25 | 26 | ' This module holds global configuration constants 27 | ' Eventually these might just become defaults, 28 | ' and the values become settable as properties 29 | 30 | ' STDOUT configuration variables 31 | ' Maximum size of individual STDOUT chunked responses if gc_SupportsChunkedResponse = TRUE 32 | Public Const gc_MaxStdoutBufferChunkSize As Long = 16384 ' Bytes 33 | 34 | 35 | ' STDIN configuration variables 36 | Public Const gc_MaxStdinInMemorySize As Long = 1024000 ' In Bytes - streams above this size will be cached on disk instead 37 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/MHtml.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpbro/VbFcgi/58f9e9ed80f8bcaccd9d7d822ef690256e95b541/src/VbFcgiLibDll/MHtml.bas -------------------------------------------------------------------------------- /src/VbFcgiLibDll/MTests.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "MTests" 2 | Option Explicit 3 | 4 | ' Copyright (c) 2017 Jason Peter Brown 5 | ' 6 | ' MIT License 7 | ' 8 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 9 | ' of this software and associated documentation files (the "Software"), to deal 10 | ' in the Software without restriction, including without limitation the rights 11 | ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | ' copies of the Software, and to permit persons to whom the Software is 13 | ' furnished to do so, subject to the following conditions: 14 | ' 15 | ' The above copyright notice and this permission notice shall be included in all 16 | ' copies or substantial portions of the Software. 17 | ' 18 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | ' SOFTWARE. 25 | 26 | Public Sub TestHtml() 27 | Dim y As New CBuilders 28 | Dim x As CBuilderHtml 29 | Dim l_TagIndex As Long 30 | 31 | Set x = y.Builder(builder_Html) 32 | 33 | x.AppendDocType htmldoctype_Html5 34 | x.OpenTags "html" 35 | l_TagIndex = x.OpenTags("head") 36 | x.AppendWithTag "Test page", "title" 37 | x.CloseOpenedTagsToIndex l_TagIndex 38 | x.Append vbNewLine 39 | 40 | x.OpenTags "body" 41 | l_TagIndex = x.OpenTags("table", "tr") 42 | x.AppendWithTag "This is a test & stuff.", "td" 43 | x.CloseLastOpenedTag 44 | x.OpenTags "tr" 45 | x.AppendWithTag "This is a test2.", "td" 46 | x.CloseOpenedTagsToIndex l_TagIndex 47 | 48 | x.OpenHyperlinkTag "http://www.statslog.com" 49 | x.CloseAllOpenedTags ' Optional, calling Finished will also take care of this. 50 | 51 | x.Finish contentencoding_UTF16_LE 52 | 53 | Debug.Print stringIso88591ToVb(x.IBuilderInterface.HttpHeader.Content(True)) 54 | Debug.Print y.Builder.Content 55 | End Sub 56 | 57 | Public Sub TestCollection() 58 | Dim x As vbRichClient5.cCollection 59 | 60 | Set x = libRc5Factory.C.Collection(False) 61 | 62 | x.Add "AD" 63 | 64 | Debug.Print x.KeyByIndex(0) = "" 65 | End Sub 66 | 67 | Public Sub TestTemplate() 68 | Dim xx As New CTests 69 | 70 | xx.TestTemplateInfiniteLoopProtection 71 | End Sub 72 | 73 | Sub TestJson() 74 | Dim lo_Json As VbFcgiLib.CBuilderJson 75 | 76 | ' Initialize to empty JSON Object collection 77 | Set lo_Json = New VbFcgiLib.CBuilderJson 78 | lo_Json.Initialize Nothing 79 | ' Add some data 80 | lo_Json.IJsonObject.AddJsonObjectByKeyValuePairs "Info", "status", 200, "message", "OK" 81 | lo_Json.IJsonObject.AddJsonObjectByKeyValuePairs "MyObject", "test", "test2" 82 | lo_Json.IJsonObject.AddJsonArrayByValues "A", "B", "C" 83 | 84 | lo_Json.Finish contentencoding_RecommendedDefault 85 | 86 | Debug.Print stringUtf8ToVb(lo_Json.Content) 87 | 88 | ' Initialize to empty JSON Array collection 89 | Set lo_Json = New VbFcgiLib.CBuilderJson 90 | lo_Json.Initialize Array() ' .AddJsonArrayByValues "" 91 | 92 | lo_Json.IJsonObject.AddJsonObjectByKeyValuePairs "status", 200, "message", "OK" 93 | lo_Json.IJsonObject.AddJsonObjectByKeyValuePairs "test", "test2" 94 | lo_Json.IJsonObject.AddJsonArrayByValues "A", "B", "C" 95 | 96 | lo_Json.Finish contentencoding_RecommendedDefault 97 | 98 | Debug.Print stringUtf8ToVb(lo_Json.Content) 99 | 100 | ' Initialize to empty JSON collection 101 | Set lo_Json = New VbFcgiLib.CBuilderJson 102 | ' Add some data 103 | lo_Json.IJsonObject.AddJsonObjectByKeyValuePairs "status", 200, "message", "OK" 104 | 105 | lo_Json.Finish contentencoding_RecommendedDefault 106 | 107 | Debug.Print stringUtf8ToVb(lo_Json.Content) 108 | End Sub 109 | 110 | Public Sub TestSimulator() 111 | Dim lo_App As New VbFcgiLib.CSimulatorFcgiApp 112 | Dim lo_Sim As New VbFcgiLib.CSimulator 113 | 114 | lo_Sim.SimulateRequest "http://localhost/vbfcgiapp.fgci?a=b&c=d", lo_App 115 | End Sub 116 | -------------------------------------------------------------------------------- /src/VbFcgiLibDll/VbFcgiLib.vbp: -------------------------------------------------------------------------------- 1 | Type=OleDll 2 | Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\..\..\Windows\SysWOW64\stdole2.tlb#OLE Automation 3 | Reference=*\G{C79C91A4-10F5-4F71-A490-3B7915514344}#2.5#0#..\..\..\..\..\..\..\five\bin\common\vbRichClient5.dll#vbRichClient5 4 | Class=IFcgiApp; IFcgiApp.cls 5 | Class=CFcgiServer; CFcgiServer.cls 6 | Class=CFcgiDownstream; CFcgiDownstream.cls 7 | Class=CFcgiParams; CFcgiParams.cls 8 | Class=CFcgiStdIn; CFcgiStdIn.cls 9 | Class=CFcgiStdOut; CFcgiStdOut.cls 10 | Module=MLibs; ..\shared\MLibs.bas 11 | Module=MPaths; ..\shared\MPaths.bas 12 | Module=MEnv; ..\shared\MEnv.bas 13 | Module=MApi; ..\shared\MApi.bas 14 | Module=MConfig; MConfig.bas 15 | Module=MFcgi; MFcgi.bas 16 | Class=CFcgiResponse; CFcgiResponse.cls 17 | Class=CHttpCookie; CHttpCookie.cls 18 | Class=CHttpCookies; CHttpCookies.cls 19 | Class=CHttpQueryParams; CHttpQueryParams.cls 20 | Class=CHttpQueryParamValues; CHttpQueryParamValues.cls 21 | Module=MStrings; ..\Shared\MStrings.bas 22 | Module=MDates; ..\Shared\MDates.bas 23 | Class=CFcgiRequest; CFcgiRequest.cls 24 | Class=CHttp; CHttp.cls 25 | Class=CFcgi; CFcgi.cls 26 | Class=CBuilders; CBuilders.cls 27 | Class=CBuilderHtml; CBuilderHtml.cls 28 | Module=MHtml; MHtml.bas 29 | Module=MTests; MTests.bas 30 | Class=IBuilder; IBuilder.cls 31 | Class=CHttpHeaderField; CHttpHeaderField.cls 32 | Class=CHttpHeader; CHttpHeader.cls 33 | Module=MArrays; ..\Shared\MArrays.bas 34 | Class=CHttpHeaderFieldKeyValuePairs; CHttpHeaderFieldKeyValuePairs.cls 35 | Class=CBuilderFile; CBuilderFile.cls 36 | Module=MMath; ..\Shared\MMath.bas 37 | Module=MMime; ..\Shared\MMime.bas 38 | Class=CBuilderTemplate; CBuilderTemplate.cls 39 | Class=CTests; CTests.cls 40 | Class=CWebStringBase; CWebStringBase.cls 41 | Class=CWebStringTemplate; CWebStringTemplate.cls 42 | Class=CBuilderJson; CBuilderJson.cls 43 | Class=IJson; IJson.cls 44 | Module=MCollections; ..\Shared\MCollections.bas 45 | Class=CSimulator; CSimulator.cls 46 | Class=CSimulatorFcgiApp; CSimulatorFcgiApp.cls 47 | Startup="(None)" 48 | HelpFile="" 49 | Title="VbFcgiLib" 50 | ExeName32="VbFcgiLib.dll" 51 | Path32="..\..\bin" 52 | Command32="" 53 | Name="VbFcgiLib" 54 | HelpContextID="0" 55 | CompatibleMode="2" 56 | CompatibleEXE32="..\..\bin\VbFcgiLib.dll" 57 | VersionCompatible32="1" 58 | MajorVer=1 59 | MinorVer=0 60 | RevisionVer=163 61 | AutoIncrementVer=1 62 | ServerSupportFiles=0 63 | VersionComments="Programmed by Jason Peter Brown" 64 | CompilationType=0 65 | OptimizationType=0 66 | FavorPentiumPro(tm)=0 67 | CodeViewDebugInfo=0 68 | NoAliasing=0 69 | BoundsCheck=0 70 | OverflowCheck=0 71 | FlPointCheck=0 72 | FDIVCheck=0 73 | UnroundedFP=0 74 | StartMode=1 75 | Unattended=-1 76 | Retained=1 77 | ThreadPerObject=0 78 | MaxNumberOfThreads=1 79 | DebugStartupOption=0 80 | --------------------------------------------------------------------------------