{"commit":"c06418176b5c2971bc6be2a8c9a9e28012c231b7","subject":"Revert \"Resolve conflict\"","message":"Revert \"Resolve conflict\"\n\nThis reverts commit 58740171f4b5f40819b69972297295e7cf9330d4.\n","repos":"Dyalog\/MiServer,Dyalog\/MiServer,Dyalog\/MiServer","old_file":"MS3\/Documentation\/DyalogAPIs\/WidgetDoc.dyalog","new_file":"MS3\/Documentation\/DyalogAPIs\/WidgetDoc.dyalog","new_contents":"\ufeff:Class WidgetDoc : MiPageTemplate\n\n \u2207 Compose;ns;widget;doc\n :Access public\n (ns widget)\u2190Get'namespace widget'\n Add _.StyleSheet'\/Styles\/widgetDoc.css'\n doc\u2190ns Document widget\n :Select doc\n :Case \u00af1\n (Add _.h3('Namespace \"',ns,'\" not found.')).Style'color' 'red'\n :Case \u00af2\n (Add _.h3('Widget \"',widget,'\" not found in namespace ',ns)).Style'color' 'red'\n :Else\n Add _.h3 ns,'.',widget\n :If 0\u220a\u2374doc\n Add _.h4'No documentation found.'\n :Else\n doc[;2]\u2190{New _.pre \u2375}\u00a8doc[;2]\n (Add #._.Table doc).CellAttr\u2190'class=\"widgetDoc\"' 'class=\"widgetDocContent\"'\n :EndIf\n :EndSelect\n \u2207\n\n \u2207 r\u2190ns Document widget;ref;wref;src;mask;chunk;pv;c;c1;c2;samples;files\n :Access public shared\n r\u2190\u00af1\n :If 9.1=#.\u2395NC\u2282ns\n ref\u2190#.\u234ens\n r\u2190\u00af2\n :If 9=ref.\u2395NC widget\n wref\u2190ref\u234ewidget\n src\u21901\u2193\u2395SRC wref\n src\u2193\u2368\u2190+\/\u2227\\''\u2218\u2261\u00a8src\n src\u2190#.Strings.dlb\u00a8src\n src\u2190src\/\u2368\u2227\\'\u235d'=\u2283\u00a8src\n src\u2190HtmlSafeText\u00a8#.Strings.dlb\u00a81\u2193\u00a8src\n pv\u2190\u2228\/\u00a8'::'\u2218\u2377\u00a8src\n r\u21900 2\u2374\u2282''\n :For chunk :In pv\u2282src\n c\u2190\u2283chunk\n (c1 c2)\u2190{\u2375{(1,1\u2193<\\\u2375)\u2282\u237a}'::'\u2377\u2375}c\n c2\u2190#.Strings.deb 2\u2193c2\n c2\u2190c2{0\u220a\u2374\u237a:\u2375 \u22c4 0\u220a\u2374\u2375:\u2282\u237a \u22c4 (\u2282\u237a),\u2375}1\u2193chunk\n c2\u2190\u00af2\u2193\u220ac2,\u00a8\u2282\u2395UCS 13 10\n r\u236a\u2190c1 c2\n :EndFor\n :If 0\u2260wref.\u2395NC\u2282'DocBase'\n r\u236a\u2190'Documentation'('target=_blank'New _.A(2\u2374\u2282wref.DocBase))\n :EndIf\n samples\u2190'\/Examples\/',(ns~'_'),'\/'\n :If ~0\u220a\u2374files\u21901\u2337[2]#.Files.List #.Boot.ms.Config.AppRoot,samples\n files\/\u2368\u2190\u2228\/files\u2218.#.Strings.(beginsWith nocase)widget\u2218,\u00a8'Simp' 'Adv'\n :AndIf ~0\u220a\u2374files\n r\u236a\u2190'Sample Pages'({'target=_blank'New _.A(2\u2374\u2282\u2375)}\u00a8samples\u2218,\u00a8files)\n :EndIf\n :EndIf\n :EndIf\n \u2207\n\n\n:EndClass","old_contents":"\ufeff:Class WidgetDoc : MiPageTemplate\n\n \u2207 Compose;ns;widget;doc;t;opts;og\n :Access public\n Add _.StyleSheet'\/Styles\/widgetDoc.css'\n (ns widget)\u2190Get'namespace widget'\n :If 0\u220a\u2374widget\n Add _.h3'Select widget'\n opts\u2190'onchange=\"window.open(this.value,''this'');this.selectedIndex=0\"'Add _.select\n 'disabled=' 'value='opts.Add _.option'[Select widget]'\n :For ns :In '_DC' '_SF' '_JQ' '_html'\n og\u2190('label'ns)opts.Add _.optgroup\n :For widget :In (\u234ens).\u2395NL \u00af9\n ('value=?namespace=',ns,'&widget=',widget)og.Add _.option widget\n :EndFor\n :EndFor\n :Else\n doc\u2190ns Document widget\n doc[;2]\u2190{New _.pre \u2375}\u00a8doc[;2]\n Add _.h3 ns,'.',widget\n (Add #._.Table doc).CellAttr\u2190'class=\"widgetDoc\"' 'class=\"widgetDocContent\"'\n :EndIf\n \u2207\n\n \u2207 r\u2190ns Document widget;ref;wref;src;mask;chunk;pv;c;c1;c2;samples;files\n :Access public shared\n r\u2190''\n :If 9.1=#.\u2395NC\u2282ns\n ref\u2190#.\u234ens\n :If 9=ref.\u2395NC widget\n wref\u2190ref\u234ewidget\n src\u21901\u2193\u2395SRC wref\n src\u2193\u2368\u2190+\/\u2227\\''\u2218\u2261\u00a8src\n src\u2190#.Strings.dlb\u00a8src\n src\u2190src\/\u2368\u2227\\'\u235d'=\u2283\u00a8src\n src\u2190HtmlSafeText\u00a8#.Strings.dlb\u00a81\u2193\u00a8src\n pv\u2190\u2228\/\u00a8'::'\u2218\u2377\u00a8src\n r\u21900 2\u2374\u2282''\n :For chunk :In pv\u2282src\n c\u2190\u2283chunk\n (c1 c2)\u2190{\u2375{(1,1\u2193<\\\u2375)\u2282\u237a}'::'\u2377\u2375}c\n c2\u2190#.Strings.deb 2\u2193c2\n c2\u2190c2{0\u220a\u2374\u237a:\u2375 \u22c4 0\u220a\u2374\u2375:\u2282\u237a \u22c4 (\u2282\u237a),\u2375}1\u2193chunk\n c2\u2190\u00af2\u2193\u220ac2,\u00a8\u2282\u2395UCS 13 10\n r\u236a\u2190c1 c2\n :EndFor\n :If 0\u2260wref.\u2395NC\u2282'DocBase'\n r\u236a\u2190'Documentation'('target=_blank'New _.A(2\u2374\u2282wref.DocBase))\n :EndIf\n samples\u2190'\/Examples\/',(ns~'_'),'\/'\n :If ~0\u220a\u2374files\u21901\u2337[2]#.Files.List #.Boot.ms.Config.AppRoot,samples\n :AndIf ~0\u220a\u2374files\/\u2368\u2190\u2228\/files\u2218.#.Strings.(beginsWith nocase)widget\u2218,\u00a8'Simp' 'Adv'\n r\u236a\u2190'Sample Pages'({'target=_blank'New _.A(2\u2374\u2282\u2375)}\u00a8samples\u2218,\u00a8files)\n :EndIf\n :EndIf\n :EndIf\n \u2207\n\n\n:EndClass","returncode":0,"stderr":"","license":"mit","lang":"APL"} {"commit":"c6a7bc71d9a4c5257aa536258292d3ddd05ae660","subject":"Add Public Field StartTime to MiServer","message":"Add Public Field StartTime to MiServer\n","repos":"Dyalog\/MiServer,Dyalog\/MiServer,Dyalog\/MiServer","old_file":"Core\/MiServer.dyalog","new_file":"Core\/MiServer.dyalog","new_contents":"\ufeff:Class MiServer\n\n :Field Public Config\n\n :Field Public TID\u2190\u00af1 \u235d Thread ID Server is running under\n :Field Public BlockSize\u2190640000 \u235d Blocksize when returning files\n\n :Field Public SessionHandler\u2190\u2395NS ''\n :Field Public Authentication\u2190\u2395NS ''\n :Field Public Logger\u2190\u2395NS ''\n :Field Public Application\u2190\u2395NS ''\n :Field Public PageTemplates\u2190\u236c\n :Field Public Encoders\u2190\u236c \u235d pointers to instances of content encoders\n :Field Public Datasources\u2190\u236c\n :Field Public StartTime\u2190\u236c\n\n \u2395TRAP\u21900\/\u2395TRAP \u22c4 (\u2395ML \u2395IO)\u21901 1\n\n unicode\u219080=\u2395DR 'A'\n NL\u2190(CR LF)\u2190\u2395UCS 13 10\n FindFirst\u2190{(\u237a\u2377\u2375)\u23731}\n enlist\u2190{\u2395ML\u21901 \u22c4 \u220a\u2375}\n fromutf8\u2190{0::(\u2395AV,'?')[\u2395AVU\u2373\u2375] \u22c4 'UTF-8' \u2395UCS \u2375} \u235d Turn raw UTF-8 input into text\n toutf8\u2190{'UTF-8' \u2395UCS \u2375} \u235d Turn text into UTF-8 byte stream\n setting\u2190{0=\u2395NC \u2375:\u237a \u22c4 \u234e\u2375}\n endswith\u2190{(,\u237a){\u2375\u2261\u237a\u2191\u2368-\u2374\u2375},\u2375}\n I85\u2190{}\n\n bit\u2190{\u2395IO\u21900 \u235d used by Log\n 0=\u237a:0 \u235d all bits turned off\n \u00af1=\u237a:1 \u235d all bits turned on\n (\u23082\u235f\u2375)\u2283\u233d((1+\u2375)\u23742)\u22a4\u237a}\n\n :section Override\n\u235d \u2193\u2193\u2193--- Methods which are usually overridden ---\n\n \u2207 onServerLoad\n :Access Public Overridable\n \u235d Handle any server initialization prior to starting\n \u2207\n\n \u2207 onServerStart\n :Access Public Overridable\n \u235d Handle any server startup processing\n \u2207\n\n \u2207 onSessionStart req\n :Access Public Overridable\n \u235d Process a new session\n \u2207\n\n \u2207 onSessionEnd session\n :Access Public Overridable\n \u235d Handle the end of a session\n \u2207\n\n \u2207 onIdle\n :Access Public Overridable\n \u235d Idle time handler - called when the server has gone idle for a period of time\n \u2207\n\n \u2207 Error req\n :Access Public Overridable\n \u235d Handle trapped errors\n req.Response.HTML\u2190'',(\u2283,\/\u2395DM,\u00a8\u2282''),'<\/font>'\n req.Fail 500 \u235d Internal Server Error\n 1 Log \u2395DM\n \u2207\n\n \u2207 level Log msg\n :Access Public overridable\n \u235d Logs server messages\n \u235d levels implemented in MildServer are:\n \u235d 1-error\/important, 2-warning, 4-informational, 8-transaction (GET\/POST)\n :If Config.LogMessageLevel bit level \u235d if set to display this level of message\n \u2395\u2190msg \u235d display it\n :EndIf\n \u2207\n\n \u2207 Cleanup\n :Access Public overridable\n \u235d Perform any site specific cleanup\n \u2207\n\n\u235d \u2191\u2191\u2191--- End of Overridable methods ---\n :endsection\n\n\n\u235d \u2193\u2193\u2193--- Begin MildServer Core Code\n :section Start\/Stop\n \u2207 Run\n :Access Public\n ('Already Running on Thread',\u2355TID)\u2395SIGNAL(TID\u220a\u2395TNUMS)\/11\n onServerLoad\n TID\u2190RunServer&\u236c\n \u2207\n\n \u2207 End;tempfiles\n \u235d Called by destructor\n :Access Public\n Logger.Stop \u236c\n :If 0=\u2395NC'ServerName'\n \u235d!!! {}1 #.DRC.Init''\n :Else\n 'Not running'\u2395SIGNAL(#.DRC.Exists ServerName)\u219311\n {}#.DRC.Close ServerName\n :Trap 6 \u235d \u2395TSYNC may not return a value if the thread doesn't, so handle the possible VALUE ERROR\n {}\u2395TSYNC \u2395TID~\u2368TID\u2229\u2395TNUMS\n :EndTrap\n :EndIf\n :If ~0\u220a\u2374Config.TempFolder\n tempfiles\u2190{(~\u2375[;4])\/\u2375[;1]}#.Files.List Config.TempFolder\n :If 0\u2260\u2374tempfiles\u2190(tempfiles\u2228.\u2260\u00a8'.')\/tempfiles\n {}{0::'' \u22c4 #.Files.Delete Config.TempFolder,\u2375}\u00a8tempfiles\n :EndIf\n :EndIf\n Cleanup \u235d overridable\n TID\u2190\u00af1\n \u2207\n :endsection\n\n \u2207 r\u2190RunServer arg;RESUME;\u2395TRAP;Common;cmd;name;port;wres;ref;nspc;sink;Stop;secure;certpath;flags;z;rc;rate;ErrorCount;idletime;msg;uid;ts;CMTid\n \u235d Simple HTTP (Web) Server framework\n \u235d Assumes Conga available in #.DRC and uses #.HTTPRequest\n \u235d arg: dummy\n \u235d certs: RootCertDir, ServerCert, ServerKey (optional: runs Secure server)\n \n Common\u2190\u2395NS'' \u22c4 Stop\u21900 \u22c4 WAITING\u21900\n CMTid\u2190ConnectionMonitor&ServerName\n StartTime\u2190\u2395TS\n \n :If Config.TrapErrors>0\n \u2395TRAP\u2190#.DrA.TrapServer\n #.DrA.NoUser\u21901+#.DrA.MailRecipient\u2228.\u2260' '\n :EndIf \u235d Trap MiServer Errors. See HandleMSP for Page Errors.\n \n onServerStart \u235d meant to be overridden\n \n idletime\u2190#.Dates.DateToIDN \u2395TS\n :While ~Stop\n wres\u2190#.DRC.Wait ServerName 20000 \u235d Tick every 20 secs\n \u235d wres: (return code) (object name) (command) (data)\n \n :Select 1\u2283wres\n :Case 0 \u235d Good data from RPC.Wait\n :Select 3\u2283wres\n \n :Case 'Error'\n :If ServerName\u22612\u2283wres\n Stop\u21901\n :EndIf\n (1+(4\u2283wres)\u220a1008 1105 1119)Log'RunServer: DRC.Wait reported error ',(\u2355#.DRC.Error 4\u2283wres),' on ',2\u2283wres\n \n \u2395EX SpaceName 2\u2283wres\n \n :CaseList 'Block' 'BlockLast'\n nspc\u2190SpaceName 2\u2283wres\n :If 0=\u2395NC nspc\n :Trap 6 \u235d VALUE ERROR - nspc could be erased if page goes away\n nspc \u2395NS''\n (\u234enspc).(Pos Buffer ContentLength Req)\u21900 '' 0 ''\n :If 0=1\u2283z\u2190#.DRC.GetProp(2\u2283wres)'PeerAddr' \u22c4 (\u234enspc).PeerAddr\u21902\u2283z\n :Else \u22c4 (\u234enspc).PeerAddr\u2190'Unknown'\n :EndIf\n :If Config.Secure\n rc z\u2190#.DRC.GetProp(2\u2283wres)'PeerCert'\n :If rc=0 \u22c4 (\u234enspc).PeerCert\u2190z\n :Else\n 1 Log'Unable to obtain peer certificate over secure connection - request ignored'\n \u2395EX nspc\n :EndIf\n :EndIf\n :EndTrap\n :EndIf\n \n :If 0\u2260\u2395NC nspc\n {}(\u234enspc){\u2395EX nspc\/\u2368('BlockLast'\u22613\u2283\u2375)\u2227\u237a HandleRequest(2\u2191\u2375)}&wres[2 4 3] \u235d Run page handler in new thread\n :EndIf\n :Case 'Connect' \u235d Ignore\n \n :Else\n 2 Log'Error ',\u2355wres\n :EndSelect\n \n :Case 100 \u235d Time out - put \"housekeeping\" code here\n SessionHandler.HouseKeeping \u2395THIS\n :If 0CongaVersion\n 'MiServer 3.0 requires Conga 2.2 or later'\u2395SIGNAL 11\n :EndIf\n \n PageTemplates\u2190#.Pages.\u2395NL \u00af9.4\n \n ('Unable to allocate TCP\/IP port ',\u2355Config.Port)\u2395SIGNAL(0\u22601\u2283,AllocatePort)\/11\n \u2207\n\n \u2207 UnMake\n :Implements Destructor\n :Trap 0 \u22c4 End \u22c4 :EndTrap\n \u2207\n\n \u2207 r\u2190AllocatePort;ipv;server\n \u235d Starts Conga, allocates TCP\/IP port\n ipv\u2190'Protocol'Config.IPVersion\n :If Config.Secure\n :If \u2227\/(~0\u220a\u2374)\u00a8Config.(CertFile KeyFile)\n :AndIf \u2283\u2227\/#.Files.Exists\u00a8Config.(CertFile KeyFile)\n {}#.DRC.SetProp'.' 'RootCertDir'Config.RootCertDir\n server\u2190#.DRC.X509Cert.ReadCertFromFile Config.CertFile\n server.KeyOrigin\u2190'DER'Config.KeyFile\n \u2192(0\u22601\u2283r\u2190#.DRC.Srv'' ''Config.Port'Raw' 10000('X509'server)('SSLValidation'Config.SSLFlags)ipv)\u23740 \u235d Must have Conga v2.1\n 1 Log'Starting secure server using certificate ',Config.CertFile\n :Else\n 1 Log'Invalid certificate parameters'\n r\u21901\n \u21920\n :EndIf\n :Else\n \u2192(0\u22601\u2283r\u2190#.DRC.Srv'' ''Config.Port'Raw' 10000 ipv)\u23740\n :EndIf\n \n ServerName\u21902\u2283r\n \n \u235d If running Linux, we may want to switch users (only root can allocate a port less than 1024)\n \n :If ~isWin\n :AndIf 0<\u2374uid\u2190''setting'Config.UserID'\n msg\u2190'4001\u2336''',uid,''' '\n :Trap 0\n {}4001\u2336uid\n :Else\n 1 Log msg,'failed.'\n :Return\n :EndTrap\n 4 Log msg,'succeeded.'\n :EndIf\n \n 4 Log'Web server ''',ServerName,''' started on port ',\u2355Config.Port\n 4 Log'Root folder: ',Config.Root\n \u2207\n\n :endsection\n\n :section RequestHandling\n\n \u2207 names\u2190pagedata PrepareJSONTargets names;p;m;i;nss;z\n \u235d See if names contain JSON indexed names like editcell[Name]\n \u235d and if so convert them to editcell.Name and make sure editcell exists\n \u235d \/\/\/ Hack by Morten awaiting cleanup or approval by Brian\n \n :If 0\u2260\u2374i\u2190(\u00af1=\u2395NC names)\/\u2373\u2374names \u235d all invalid APL names\n names[i]\u2190('%5B' '%5D'\u2395R(,\u00a8'[]'))\u00a8names[i]\n :AndIf 0\u2260\u2374i\u2190i\/\u2368m\u2190(p\u2190names[i]\u2373\u00a8'[')\u2260\u2218\u2283\u2218\u2374\u00a8names[i] \u235d ... which contain '['\n nss\u2190\u222az\u2190(m\/p-1)\u2191\u00a8names[i] \u235d all namespaces mentions\n nss pagedata.\u2395NS\u00a8\u2282\u236c \u235d prepare empty nss\n names[i]\u2190\u00af1\u2193\u00a8names[i] \u235d drop trailing ']'\n names[i,\u00a8p]\u2190'.' \u235d replace '[' by '.'\n :EndIf\n \u2207\n\n \u2207 r\u2190conns HandleRequest arg;buf;m;Answer;obj;CMD;pos;req;Data;z;r;hdr;REQ;status;file;tn;length;done;offset;res;closed;sess;chartype;raw;enc;which;html;encoderc;encodeMe;startsize;cacheMe;root;page;filename;eoh;n;i;ext;enctype\n \u235d Handle a Web Server Request\n r\u21900\n obj buf\u2190arg\n conns.Buffer,\u2190buf\n conns.Handler\u2190{6::conns.Handler\u2190(\u2395UCS'')\u22615\u2191conns.Buffer \u22c4 conns.Handler}\u236c \u235d are we serving as a mapping handler?\n \n :If 0=conns.Pos \u235d is we haven't found the end of the header yet...\n eoh\u2190\u2395UCS(1+conns.Handler)\u2283(NL,NL)('<\/env>') \u235d end of header marker\n pos\u2190(\u00af1+\u2374eoh)+eoh FindFirst conns.Buffer\n :If pos\u2264\u2374conns.Buffer \u235d found the end of header\n conns.Pos\u2190pos\n conns.Req\u2190fromutf8 conns.(Pos\u2191Buffer)\n :Else\n :Return \u235d haven't found end of header yet, go back for more\n :EndIf\n :EndIf\n \n :If 0<\u2374conns.Req\n :If conns.Pos>i\u2190(z\u2190LF,'content-length:')FindFirst hdr\u2190#.Strings.lc conns.Req\n :AndIf (\u2374conns.Buffer) go back for more\n :EndIf\n :EndIf\n \n conns.Buffer\u2190conns.(Pos\u2193Buffer)\n \n :If conns.Handler \u235d if we're running as a mapping handler\n conns.(Req Buffer)\u2190MakeHTTPRequest conns.Req \u235d fake MiServer out by building an HTTP request from what we've got\n :EndIf\n \n\u235d :Hold 'Request'\n \n REQ\u2190\u2395NEW #.HTTPRequest conns.(Req Buffer)\n REQ.Server\u2190\u2395THIS \u235d Request will also contain reference to the Server\n \n :If 2=conns.\u2395NC'PeerAddr' \u22c4 REQ.PeerAddr\u2190conns.PeerAddr \u22c4 :EndIf \u235d Add Client Address Information\n 8 Log REQ.(PeerAddr Command Page)\n \n :If 2=conns.\u2395NC'PeerCert' \u22c4 REQ.PeerCert\u2190conns.PeerCert \u22c4 :EndIf \u235d Add Client Cert Information\n \n :If Config.RESTful \u235d if running RESTful web service...\n n\u2190+\/\u2227\\2>+\\REQ.Page\u220a'\/\\'\n REQ.RESTfulReq\u2190n\u2193REQ.Page\n REQ.Page\u2190n\u2191REQ.Page\n :EndIf\n \n REQ.Page\u2190Config.DefaultPage{\u2227\/\u2375\u220a'\/\\':'\/',\u237a \u22c4 '\/\\'\u220a\u2368\u00af1\u2191\u2375:\u2375,\u237a \u22c4 \u2375}REQ.Page \u235d no page specified? use the default\n REQ.Page,\u2190(~'.'\u220a{\u2375\/\u2368\u233d~\u2228\\'\/'=\u233d\u2375}REQ.Page)\/Config.DefaultExtension \u235d no extension specified? use the default\n \n SessionHandler.GetSession REQ\n Authentication.Authenticate REQ\n \n :If REQ.Response.Status\u2260401 \u235d Authentication did not fail\n \n ext\u2190\u2283\u00af1\u2191#.Files.SplitFilename filename\u2190Config Virtual REQ.Page\n :If Config.AllowedHttpCommands\u220a\u2368\u2282REQ.Command\n \n :If REQ.Page endswith Config.DefaultExtension \u235d MiPage?\n filename HandleMSP REQ\n :Else\n :If REQ.Command\u2261'get'\n REQ.ReturnFile filename\n :Else\n REQ.Fail 501 \u235d Service Not Implemented\n :EndIf\n :EndIf\n :Else\n REQ.Fail 501 \u235d Service Not Implemented\n :EndIf\n :EndIf\n \n res\u2190REQ.Response\n \n enc\u2190','#.Utils.penclose' '~\u2368REQ.GetHeader'accept-encoding' \u235d check if client supports encoding\n encodeMe\u2190(0<\u2374enc)\u2227conns.Handler\u2190(\u2282ext)\u220a'png' 'gif' 'jpg' \u235d don't try to compress compressed graphics, should probably add zip files, etc\n cacheMe\u21900\n \n :If 1=res.File \u235d See HTTPRequest.ReturnFile\n :If 83=\u2395DR file\u2190res.HTML \u235d if we returned a byte stream, just use it\n length\u2190\u2374file \u22c4 tn\u21900\n :Else\n :Trap 22\n tn\u2190file \u2395NTIE 0\n :If encodeMe \u22c4 length\u2190\u2395NSIZE tn \u235d if using compression, read the entire file\n :Else \u22c4 length\u2190BlockSize \u235d otherwise send it a block at a time\n :EndIf\n res.HTML\u2190\u2395NREAD tn 83 length 0\n cacheMe\u21900\u2260Config.HttpCacheTime \u235d for now, cache all files if set to use caching\n :Else\n REQ.Fail 404\n length\u2190\u2374res.HTML\n res.File\u21900\n :EndTrap\n :EndIf\n startsize\u2190length\n :EndIf\n \n :If (200=res.Status)\u2227encodeMe \u235d if our HTTP status is 200 (OK) and we're okay to encode\n :AndIf 1024<\u2374res.HTML \u235d don't bother compressing less than 1K\n :AndIf 0\u2260which\u2190\u2283Encoders.Encoding{(\u2374\u237a){(\u237a\u2265\u2375)\/\u2375}\u237a\u2373\u2375}enc \u235d try to match what encodings they accept to those we provide\n (encoderc html)\u2190Encoders[which].Compress res.HTML\n :If 0=encoderc\n length\u2190startsize\u2190\u2374res.HTML\n :If startsize>\u2374html \u235d did we save anything by compressing\n length\u2190\u2374res.HTML\u2190html \u235d use it\n res.Headers\u236a\u2190'Content-Encoding'(enctype\u2190Encoders[which].Encoding)\n 4 Log'Used ',enctype,' compression on \"',REQ.Page,'\", transmitted% = ',2\u2355length{\u2395DIV\u21901 \u22c4 \u237a\u00f7\u2375}startsize\n :Else\n 4 Log'Compression not used on \"',REQ.Page,'\", startsize = ',(\u2355startsize),', compressed length = ',\u2355length\n :If 83\u2260\u2395DR res.HTML\n res.HTML\u2190toutf8 res.HTML\n :EndIf\n :EndIf\n :ElseIf 0=res.File\n 2 Log'Compression failed'\n length\u2190\u2374res.HTML\u2190toutf8 res.HTML \u235d otherwise, send uncompressed\n :EndIf\n :ElseIf 0=res.File\n startsize\u2190length\u2190\u2374res.HTML\u2190toutf8\u220ares.HTML\n :EndIf\n \n :If (200=res.Status)\u2227cacheMe \u235d if cacheable, set expires\n :AndIf 0\u2374Answer\u2190\u2395NREAD tn 83,BlockSize,offset\n offset+\u2190\u2374Answer\n :EndIf\n :Until closed \u235d Everything sent\n :EndIf\n \n :If res.File \u22c4 \u2395NUNTIE tn \u22c4 :EndIf\n 8 Log REQ.PeerAddr status\n Logger.Log REQ\n r\u21901\n \u235d :EndHold\n \u2207\n\n \u2207 file HandleMSP REQ;\u2395TRAP;inst;class;z;props;lcp;args;i;ts;date;n;expired;data;m;oldinst;names;html;sessioned;page;root;fn;MS3;token;cb;mask;resp;t;RESTful;APLJax;flag;orig;path;name;ext;list\n \u235d Handle a \"MiServer Page\" request\n \n path name ext\u2190#.Files.SplitFilename file\n \n RETRY:\n :If 0=n\u2190\u2283\u2374list\u2190''#.Files.List orig\u2190file \u235d does the file exist?\n :AndIf Config.DefaultExtension\u2262'.dyalog' \u235d temporary measure to ease the transition to the .mipage extension\n :If 1\u2260\u2283\u2374list\u2190''#.Files.List\u220apath name'.dyalog'\n REQ.Fail 404 \u22c4 \u21920\n :Else\n 1 Log'File not found: \"',orig,'\" using \"',file,'\" instead.'\n :EndIf\n :ElseIf 1\u2260n\n REQ.Fail 404 \u22c4 \u21920\n :EndIf\n \n date\u2190\u220alist[1;3]\n \n MS3\u2190RESTful\u2190expired\u21900\n APLJax\u2190REQ.isAPLJax\n \n :If sessioned\u2190326=\u2395DR REQ.Session \u235d do we think we have a session handler active?\n :AndIf 0\u2260\u2374REQ.Session.Pages \u235d Look for existing Page in Session\n :AndIf (n\u2190\u2374REQ.Session.Pages)\u2265i\u2190REQ.Session.Pages._PageName\u2373\u2282REQ.Page\n inst\u2190i\u2283REQ.Session.Pages \u235d Get existing instance\n :If expired\u2190inst._PageDate\u2262date \u235d Timestamp unchanged?\n\u235dBPB :AndIf expired\u2190(\u2395SRC\u2283\u2283\u2395CLASS inst)\u2262#.UnicodeFile.ReadNestedText file \u235dBPB commented out because it's wasteful\n oldinst\u2190inst\n REQ.Session.Pages~\u2190inst\n 4 Log'Page: ',REQ.Page,' ... has been updated ...'\n :EndIf\n :AndIf ~expired\n 4 Log'Using existing instance of page: ',REQ.Page\n :If 9=\u2395NC'#.HtmlPage'\n :If MS3\u2190\u2228\/(\u220a\u2395CLASS inst)\u220a#.HtmlPage \u22c4 inst._Request\u2190REQ \u22c4 :EndIf\n :EndIf\n :If 9=\u2395NC'#.RESTful'\n :If RESTful\u2190\u2228\/(\u220a\u2395CLASS inst)\u220a#.RESTful \u22c4 inst._Request\u2190REQ \u22c4 :EndIf\n :EndIf\n :Else \u235d First use of Page in this Session, or page expired\n\u235d :If 0\u2260\u2374z\u2190#.Files.GetText file\n :Trap 11 22 92\n inst\u2190Config.AppRoot LoadMSP file \u235d \u2395NEW \u2395SE.SALT.Load file,' -target=#.Pages'\n :Case 11 \u22c4 REQ.Fail 500 \u22c4 1 Log'Domain Error trying to load \"',file,'\"' \u22c4 \u21920 \u235d Domain Error: HTTP Internal Error\n :Case 22 \u22c4 REQ.Fail 404 \u22c4 1 Log'File not found - \"',file,'\"' \u22c4 \u21920 \u235d File Name Error: HTTP Page not found\n :Case 92 \u22c4 REQ.Response.HTML,\u2190'

Unable to load page ',REQ.Page,' due to a translation error.This is typically caused by trying to load a page containing Unicode characters when running MiServer under a Classic (not Unicode) version of Dyalog APL.<\/p>'\n REQ.Fail 500 \u22c4 \u21920\n :EndTrap\n 4 Log'Creating new instance of page: ',REQ.Page\n inst._PageName\u2190REQ.Page\n inst._PageDate\u2190date\n MS3\u2190RESTful\u21900\n :If 9=\u2395NC'#.HtmlPage'\n :If MS3\u2190\u2228\/(\u220a\u2395CLASS inst)\u220a#.HtmlPage\n :OrIf RESTful\u2190\u2228\/(\u220a\u2395CLASS inst)\u220a#.RESTful\n inst.(_Request _PageRef)\u2190REQ inst\n :EndIf\n :EndIf\n \n \u235d ======= TIMEOUT Logic =======\n \u235d If RESTful or not sessioned, let anything through\n \u235d If sessioned and expired, let it though\n \u235d If sessioned but not expired, check if GET\n :If RESTfulexpired\n :AndIf ~REQ.isGet\n inst._TimedOut\u21901\n :EndIf\n \n :If sessioned \u22c4 REQ.Session.Pages,\u2190inst \u22c4 inst.Session\u2190REQ.Session.ID \u22c4 :EndIf\n\u235d :Else \u235d empty file or file not found\n\u235d REQ.Fail 404 \u22c4 \u21920\n\u235d :EndIf\n :EndIf\n \n :If sessioned \u22c4 token\u2190REQ.(Page,\u2355Session.ID)\n :ElseIf ~0\u220a\u2374REQ.PeerAddr \u22c4 token\u2190REQ.(Page,PeerAddr)\n :Else \u22c4 token\u2190\u2355\u2395TID\n :EndIf\n \n :Hold token\n \n \u235d Move arguments \/ parameters into Public Properties\n inst._PageData\u2190\u2395NS''\n :If 0\u22601\u2191\u2374data\u2190{\u2375[\u234b\u2191\u2375[;1];]}REQ.Arguments\u236aREQ.Data\n m\u21901,2\u2262\/data[;1]\n data\u2190(m\/data[;1]),[1.5]m\u2282data[;2]\n i\u2190{\u2375\/\u2373\u2374\u2375}1=\u2283\u2218\u2374\u00a8data[;2]\n data[i;2]\u2190\u2283\u00a8data[i;2]\n :If 0\u2260\u2374lcp\u2190props\u2190('_'\u22601\u2283\u00a8props)\/props\u2190(inst.\u2395NL-2) \u235d Get list of public properties (those beginning with '_' are excluded)\n :AndIf 0\u22601\u2191\u2374args\u2190(data[;1]\u220alcp)\u233fdata\n args\u2190(2\u2308\u2374args)\u2374args\n i\u2190lcp\u2373args[;1]\n \u234e'inst.(',(\u2355props[i]),')\u2190args[;2]'\n :EndIf\n :If \u2228\/mask\u2190'_'\u22601\u2283\u00a8data[;1]\n args\u2190mask\u233fdata\n :Trap 0\n args[;1]\u2190inst._PageData PrepareJSONTargets args[;1]\n \u234e'inst._PageData.(',(\u2355args[;1]),')\u2190args[;2]'\n :EndTrap\n :EndIf\n :EndIf\n \n fn\u2190cb\u2190'Render'\n :If APLJax>RESTful \u235d if it's an APLJax (XmlHttpRequest) request (but not web service)\n REQ.Response.NoWrap\u21901\n fn\u2190cb\u2190'APLJax' \u235d default callback function name\n :If MS3\n inst._what\u2190REQ.GetData'_what'\n inst._event\u2190REQ.GetData'_event'\n inst._value\u2190REQ.GetData'_value'\n inst._selector\u2190REQ.GetData'_selector'\n inst._callback\u2190REQ.GetData'_callback'\n :If ~0\u220a\u2374inst._callback \u235d does the request specify a callback function\n fn\u2190cb\u2190inst._callback\n :EndIf\n :EndIf\n :ElseIf RESTful\n fn\u2190cb\u2190'Respond'\n :ElseIf MS3\n cb\u2190cb inst.{3=\u230a|\u2395NC\u2282\u2375:\u2375 \u22c4 \u237a}fn\u2190'Compose' \u235d default function to call\n :EndIf\n \n :If 3\u2260\u230a|inst.\u2395NC\u2282cb \u235d and is it a public method?\n 1 Log'Method \"',fn,'\" not found (or not public) in page \"',REQ.Page,'\"'\n REQ.Fail 500\n \u21920\n :EndIf\n \n :If MS3\n :If APLJax\n inst._resetAjax\n :Else\n inst._init \u235d reset instance's content\n :EndIf\n :EndIf\n \n :If (1=Config.TrapErrors)\u22279=\u2395NC'#.DrA' \u22c4 \u2395TRAP\u2190#.DrA.TrapServer\n :ElseIf (0=Config.Production) \u22c4 \u2395TRAP\u2190(800 'C' '\u2192FAIL')(811 'E' '\u2395SIGNAL 801')(813 'E' '\u2395SIGNAL 803')(812 'S')(85 'N')(0 'E' '\u234e#.Boot.Oops') \u235d enable development debug framework\n :EndIf\n \n :If flag\u2190APLJax\n :AndIf flag\u2190inst.{6::0 \u22c4 _DebugCallbacks}\u236c\n :EndIf\n \n :Trap 85 \u235d we use 85\u2336 because \"old\" MiPages use REQ.Return internally (and don't return a result)...\n resp\u2190flag Debugger'inst.',cb,(MS3\u2371RESTful)\/' REQ' \u235d ... whereas \"new\" MiPages return the HTML they generate\n resp\u2190(#.JSON.toAPLJAX\u2363APLJax)resp\n inst._TimedOut\u21900\n :If RESTful\n :AndIf ~\u2228\/(\u2282'content-type')(\u2261#.Strings.nocase)\u00a8REQ.Response.Headers[;1]\n resp\u21901 #.JSON.fromAPL resp\n 'Content-Type'REQ.SetHeader'application\/json'\n :EndIf\n REQ.Return resp\n :Else\n :If APLJax\n 1 Log'No result returned by callback method \"',cb,'\" in page \"',REQ.Page,'\"'\n REQ.Return''\n :EndIf\n :EndTrap\n \n :If ~REQ.Response.NoWrap\n :If MS3\u2228RESTful\n inst.Wrap\n :Else\n inst.Wrap REQ\n :EndIf\n :EndIf\n :EndHold\n \u21920\n \n FAIL:\n \u2395\u2190'* Carrying on...'\n \u2395TRAP\u21900\u2374\u2395TRAP\n REQ.Fail 500 \u22c4 \u21920\n \n RESUME: \u235d RESUME is used by DrA\n \u2395TRAP\u21900\/\u2395TRAP \u235d Let framework trapping take over\n \n :If #.DrA.UseHTTP \u22c4 REQ.Fail 500 \u22c4 \u21920 \u22c4 :EndIf\n \n REQ.Title'Unhandled Execution Error'\n REQ.Style'Styles\/error.css'\n html\u2190'h1'#.HTMLInput.Enclose'Server Error in ''',REQ.Page,'''.


'\n html,\u2190'

Unhandled Exception Error<\/i><\/h2>'\n html,\u2190'Description:<\/b> An unhandled exception occurred during the execution of the current web request.'\n :If #.DrA.Mode=2 \u235d Allows editing\n html,\u2190'

Edit page: ',REQ.Page,'<\/a>
'\n :EndIf\n html,\u2190'

Exception Details:<\/b>

'\n :If (#.DrA.Mode>0)\u22270\u2260\u2374#.DrA.LastFile \u22c4 html,\u2190#.DrA.(GenHTML LastFile)\n :Else \u22c4 html,\u2190'code'#.HTMLInput.Enclose'',(\u2283,\/#.DrA.LastError,\u00a8\u2282'
'),'<\/font>'\n :EndIf\n REQ.Return html\n \u2207\n\n \u2207 inst\u2190root LoadMSP file;path;name;ext;rpath;ns;tree;class;level;n;created;node;mask\n path name ext\u2190#.Files.SplitFilename file\n rpath\u2190(\u2374root)\u2193path\n ns\u2190#.Pages\n tree\u2190'\/'#.Utils.penclose rpath\n created\u2190(n\u2190\u2374tree)\u23740\n \n :For level :In \u2373n\n :Select \u2283ns.\u2395NC\u2282node\u2190level\u2283tree\n :Case 0\n :Trap 11\n ns\u2190\u234enode ns.\u2395NS''\n :Else\n 1 Log'Unable to create namespace in #.Pages for page in file \"',file,'\"'\n \u2395SIGNAL 11\n :EndTrap\n ns\u234e'(',(\u2355PageTemplates),')\u2190',\u220a'##.'\u2218,\u2218\u2355\u00a8PageTemplates\n created[level]\u21901\n :Case 9.1\n ns\u2190ns\u234enode\n :Else\n 1 Log'Unable to create namespace in #.Pages for page in file \"',file,'\" due to name conflict'\n :While \u2228\/created \u235d clean up any created nodes\n ns\u2190ns.##\n ns.\u2395EX\u2283(mask\u2190\u233d<\\\u233dcreated)\/tree\n created\u2227\/\u2190~mask\n :EndWhile\n \u2395SIGNAL 11\n :EndSelect\n :EndFor\n \n inst\u2190\u2395NEW class\u2190\u2395SE.SALT.Load file,' -target=',\u2355ns\n \n :If ~name(\u2261#.Strings.nocase)class\u2190\u2283\u00af1\u2191'.'#.Utils.penclose\u2355class\n 1 Log'Filename\/Classname mismatch: ',file,' \u2262 ',class\n :EndIf\n \u2207\n\n \u2207 (req buffer)\u2190MakeHTTPRequest req;x;v;s;p;l;m;n;i;c;h\n\u235d kludge to get by ampersands in a POST - will be fixed when we build proper requests from MiServerCGI\n buffer\u2190c\u2190''\n :If (\u2374req)\u2265i\u21901\u2373\u2368'>tsop<'\u2377\u233dreq\n i\u2190(\u2374req)-i+5\n c\u2190\u00af13\u2193(i+6)\u2193req\n req\u2190(i\u2191req),'<\/env>'\n :EndIf\n \n :Trap 11\n x\u2190\u2395XML req\n :Else\n \u2218\u2218\u2218\n :EndTrap\n v\u2190'var'\u2218\u2261\u00a8x[;2]\n v\u2190{\u2395ML\u21903 \u22c4 (~<\\'='=\u2375)\u2282\u2375}\u00a8v\/x[;3]\n v\u2190(\u220a2=\u2374\u00a8v)\/v\n h\u2190\u220a{0\u220a\u2374\u2375:'' \u22c4 (#.Strings.lc{'HTTP_'\u22615\u2191\u2375:5\u2193\u2375 \u22c4 'HTTPS_'\u22616\u2191\u2375:6\u2193\u2375 \u22c4 \u2375}\u237a){('-',\u237a)[('_',\u237a)\u2373\u237a],': ',\u2375,NL}\u2375}\/\u00a8v\n \u235d pull out special fields\n m p s n\u2190(\u2191v)\u2218{3::2\u2283\u2375 \u22c4 \u237a[;2]\u2283\u2368\u237a[;1]\u2373\u22821\u2283\u2375}\u00a8\u2193'REQUEST_METHOD' 'PATH_INFO' 'SERVER_PROTOCOL' 'SERVER_NAME',[1.1]'GET' '' 'HTTP\/1.0' 'localhost'\n (req buffer)\u2190(m,' ',p,' ',s,NL,'Host: ',n,h,NL)c\n \u2207\n\n :endsection\n\n :section Misc\n\n \u2207 ConnectionMonitor server\n \u235d Because AJAX calls don't send a \"BlockLast\" packet, we need to clean up connection namespaces that didn't get erased\n :While 1\n \u2395DL 30\n :Trap 6\n {}Common.{\u2395EX(\u2395NL \u00af9)~'C',\u00a8#.DRC.Names \u2375}server\n :Else\n \u21920\n :EndTrap\n :EndWhile\n \u2207\n\n \u2207 r\u2190flag Debugger w\n :If flag\n \u2395\u2190'* Callback debugging active on this page, press Ctrl-Enter to trace into Callback function'\n Debug \u2395STOP'Debugger'\n :EndIf\n :Trap 85\n Debug:r\u2190I85 w\n :Else\n :If flag \u22c4 \u236c \u2395STOP'Debugger' \u22c4 :EndIf\n \u2395SIGNAL 85\n :EndTrap\n :If flag \u22c4 \u236c \u2395STOP'Debugger' \u22c4 :EndIf\n \u2207\n\n \u2207 r\u2190SpaceName cmd\n \u235d Generate namespace name from command name\n r\u2190'Common.C',Subst(2\u2283{1\u2193\u00a8('.'=\u2375)\u2282\u2375}'.',cmd)'-=' '_\u2206'\n \u2207\n\n \u2207 r\u2190Subst arg;i;m;str;c;rep\n \u235d Substitute character c in str with rep\n str c rep\u2190arg\n i\u2190c\u2373str\n m\u2190i\u2264\u2374c\n (m\/str)\u2190rep[m\/i]\n r\u2190str\n \u2207\n\n \u2207 file\u2190Config Virtual page;mask;f;ind;t;path;root\n :Access public shared\n \u235d checks for virtual directory\n root\u2190(-'\/\\'\u220a\u2368\u00af1\u2191root)\u2193root\u2190Config.Root\n page\u2190('\/\\'\u220a\u23681\u2191page)\u2193page\n file\u2190root,'\/',page\n :If 0<\u2374Config.Virtual\n ind\u2190Config.Virtual.alias\u2373\u2282t\u2190{(\u00af1+\u2375\u2373'\/')\u2374\u2375}page\n :If ind\u2264\u2374Config.Virtual.alias\n path\u2190ind\u2283Config.Virtual.path\n file\u2190#.Files.unixfix path,('\/\\'\u220a\u2368\u00af1\u2191path)\u2193(\u2374t)\u2193page\n :EndIf\n :EndIf\n \u2207\n\n \u2207 r\u2190isWin\n r\u2190'Win'\u22613\u21911\u2283'.'\u2395WG'APLVersion'\n \u2207\n\n :endsection\n\n:EndClass","old_contents":"\ufeff:Class MiServer\n\n :Field Public Config\n\n :Field Public TID\u2190\u00af1 \u235d Thread ID Server is running under\n :Field Public BlockSize\u2190640000 \u235d Blocksize when returning files\n\n :Field Public SessionHandler\u2190\u2395NS ''\n :Field Public Authentication\u2190\u2395NS ''\n :Field Public Logger\u2190\u2395NS ''\n :Field Public Application\u2190\u2395NS ''\n :field Public PageTemplates\u2190\u236c\n :field Public Encoders\u2190\u236c \u235d pointers to instances of content encoders\n :field Public Datasources\u2190\u236c\n\n \u2395TRAP\u21900\/\u2395TRAP \u22c4 (\u2395ML \u2395IO)\u21901 1\n\n unicode\u219080=\u2395DR 'A'\n NL\u2190(CR LF)\u2190\u2395UCS 13 10\n FindFirst\u2190{(\u237a\u2377\u2375)\u23731}\n enlist\u2190{\u2395ML\u21901 \u22c4 \u220a\u2375}\n fromutf8\u2190{0::(\u2395AV,'?')[\u2395AVU\u2373\u2375] \u22c4 'UTF-8' \u2395UCS \u2375} \u235d Turn raw UTF-8 input into text\n toutf8\u2190{'UTF-8' \u2395UCS \u2375} \u235d Turn text into UTF-8 byte stream\n setting\u2190{0=\u2395NC \u2375:\u237a \u22c4 \u234e\u2375}\n endswith\u2190{(,\u237a){\u2375\u2261\u237a\u2191\u2368-\u2374\u2375},\u2375}\n I85\u2190{}\n\n bit\u2190{\u2395IO\u21900 \u235d used by Log\n 0=\u237a:0 \u235d all bits turned off\n \u00af1=\u237a:1 \u235d all bits turned on\n (\u23082\u235f\u2375)\u2283\u233d((1+\u2375)\u23742)\u22a4\u237a}\n\n :section Override\n\u235d \u2193\u2193\u2193--- Methods which are usually overridden ---\n\n \u2207 onServerLoad\n :Access Public Overridable\n \u235d Handle any server initialization prior to starting\n \u2207\n\n \u2207 onServerStart\n :Access Public Overridable\n \u235d Handle any server startup processing\n \u2207\n\n \u2207 onSessionStart req\n :Access Public Overridable\n \u235d Process a new session\n \u2207\n\n \u2207 onSessionEnd session\n :Access Public Overridable\n \u235d Handle the end of a session\n \u2207\n\n \u2207 onIdle\n :Access Public Overridable\n \u235d Idle time handler - called when the server has gone idle for a period of time\n \u2207\n\n \u2207 Error req\n :Access Public Overridable\n \u235d Handle trapped errors\n req.Response.HTML\u2190'',(\u2283,\/\u2395DM,\u00a8\u2282''),'<\/font>'\n req.Fail 500 \u235d Internal Server Error\n 1 Log \u2395DM\n \u2207\n\n \u2207 level Log msg\n :Access Public overridable\n \u235d Logs server messages\n \u235d levels implemented in MildServer are:\n \u235d 1-error\/important, 2-warning, 4-informational, 8-transaction (GET\/POST)\n :If Config.LogMessageLevel bit level \u235d if set to display this level of message\n \u2395\u2190msg \u235d display it\n :EndIf\n \u2207\n\n \u2207 Cleanup\n :Access Public overridable\n \u235d Perform any site specific cleanup\n \u2207\n\n\u235d \u2191\u2191\u2191--- End of Overridable methods ---\n :endsection\n\n\n\u235d \u2193\u2193\u2193--- Begin MildServer Core Code\n :section Start\/Stop\n \u2207 Run\n :Access Public\n ('Already Running on Thread',\u2355TID)\u2395SIGNAL(TID\u220a\u2395TNUMS)\/11\n onServerLoad\n TID\u2190RunServer&\u236c\n \u2207\n\n \u2207 End;tempfiles\n \u235d Called by destructor\n :Access Public\n Logger.Stop \u236c\n :If 0=\u2395NC'ServerName'\n \u235d!!! {}1 #.DRC.Init''\n :Else\n 'Not running'\u2395SIGNAL(#.DRC.Exists ServerName)\u219311\n {}#.DRC.Close ServerName\n :Trap 6 \u235d \u2395TSYNC may not return a value if the thread doesn't, so handle the possible VALUE ERROR\n {}\u2395TSYNC \u2395TID~\u2368TID\u2229\u2395TNUMS\n :EndTrap\n :EndIf\n :If ~0\u220a\u2374Config.TempFolder\n tempfiles\u2190{(~\u2375[;4])\/\u2375[;1]}#.Files.List Config.TempFolder\n :If 0\u2260\u2374tempfiles\u2190(tempfiles\u2228.\u2260\u00a8'.')\/tempfiles\n {}{0::'' \u22c4 #.Files.Delete Config.TempFolder,\u2375}\u00a8tempfiles\n :EndIf\n :EndIf\n Cleanup \u235d overridable\n TID\u2190\u00af1\n \u2207\n :endsection\n\n \u2207 r\u2190RunServer arg;RESUME;\u2395TRAP;Common;cmd;name;port;wres;ref;nspc;sink;Stop;secure;certpath;flags;z;rc;rate;ErrorCount;idletime;msg;uid;ts;CMTid\n \u235d Simple HTTP (Web) Server framework\n \u235d Assumes Conga available in #.DRC and uses #.HTTPRequest\n \u235d arg: dummy\n \u235d certs: RootCertDir, ServerCert, ServerKey (optional: runs Secure server)\n \n Common\u2190\u2395NS'' \u22c4 Stop\u21900 \u22c4 WAITING\u21900\n CMTid\u2190ConnectionMonitor&ServerName\n \n :If Config.TrapErrors>0\n \u2395TRAP\u2190#.DrA.TrapServer\n #.DrA.NoUser\u21901+#.DrA.MailRecipient\u2228.\u2260' '\n :EndIf \u235d Trap MiServer Errors. See HandleMSP for Page Errors.\n \n onServerStart \u235d meant to be overridden\n \n idletime\u2190#.Dates.DateToIDN \u2395TS\n :While ~Stop\n wres\u2190#.DRC.Wait ServerName 20000 \u235d Tick every 20 secs\n \u235d wres: (return code) (object name) (command) (data)\n \n :Select 1\u2283wres\n :Case 0 \u235d Good data from RPC.Wait\n :Select 3\u2283wres\n \n :Case 'Error'\n :If ServerName\u22612\u2283wres\n Stop\u21901\n :EndIf\n (1+(4\u2283wres)\u220a1008 1105 1119)Log'RunServer: DRC.Wait reported error ',(\u2355#.DRC.Error 4\u2283wres),' on ',2\u2283wres\n \n \u2395EX SpaceName 2\u2283wres\n \n :CaseList 'Block' 'BlockLast'\n nspc\u2190SpaceName 2\u2283wres\n :If 0=\u2395NC nspc\n :Trap 6 \u235d VALUE ERROR - nspc could be erased if page goes away\n nspc \u2395NS''\n (\u234enspc).(Pos Buffer ContentLength Req)\u21900 '' 0 ''\n :If 0=1\u2283z\u2190#.DRC.GetProp(2\u2283wres)'PeerAddr' \u22c4 (\u234enspc).PeerAddr\u21902\u2283z\n :Else \u22c4 (\u234enspc).PeerAddr\u2190'Unknown'\n :EndIf\n :If Config.Secure\n rc z\u2190#.DRC.GetProp(2\u2283wres)'PeerCert'\n :If rc=0 \u22c4 (\u234enspc).PeerCert\u2190z\n :Else\n 1 Log'Unable to obtain peer certificate over secure connection - request ignored'\n \u2395EX nspc\n :EndIf\n :EndIf\n :EndTrap\n :EndIf\n \n :If 0\u2260\u2395NC nspc\n {}(\u234enspc){\u2395EX nspc\/\u2368('BlockLast'\u22613\u2283\u2375)\u2227\u237a HandleRequest(2\u2191\u2375)}&wres[2 4 3] \u235d Run page handler in new thread\n :EndIf\n :Case 'Connect' \u235d Ignore\n \n :Else\n 2 Log'Error ',\u2355wres\n :EndSelect\n \n :Case 100 \u235d Time out - put \"housekeeping\" code here\n SessionHandler.HouseKeeping \u2395THIS\n :If 0CongaVersion\n 'MiServer 3.0 requires Conga 2.2 or later'\u2395SIGNAL 11\n :EndIf\n \n PageTemplates\u2190#.Pages.\u2395NL \u00af9.4\n \n ('Unable to allocate TCP\/IP port ',\u2355Config.Port)\u2395SIGNAL(0\u22601\u2283,AllocatePort)\/11\n \u2207\n\n \u2207 UnMake\n :Implements Destructor\n :Trap 0 \u22c4 End \u22c4 :EndTrap\n \u2207\n\n \u2207 r\u2190AllocatePort;ipv;server\n \u235d Starts Conga, allocates TCP\/IP port\n ipv\u2190'Protocol'Config.IPVersion\n :If Config.Secure\n :If \u2227\/(~0\u220a\u2374)\u00a8Config.(CertFile KeyFile)\n :AndIf \u2283\u2227\/#.Files.Exists\u00a8Config.(CertFile KeyFile)\n {}#.DRC.SetProp'.' 'RootCertDir'Config.RootCertDir\n server\u2190#.DRC.X509Cert.ReadCertFromFile Config.CertFile\n server.KeyOrigin\u2190'DER'Config.KeyFile\n \u2192(0\u22601\u2283r\u2190#.DRC.Srv'' ''Config.Port'Raw' 10000('X509'server)('SSLValidation'Config.SSLFlags)ipv)\u23740 \u235d Must have Conga v2.1\n 1 Log'Starting secure server using certificate ',Config.CertFile\n :Else\n 1 Log'Invalid certificate parameters'\n r\u21901\n \u21920\n :EndIf\n :Else\n \u2192(0\u22601\u2283r\u2190#.DRC.Srv'' ''Config.Port'Raw' 10000 ipv)\u23740\n :EndIf\n \n ServerName\u21902\u2283r\n \n \u235d If running Linux, we may want to switch users (only root can allocate a port less than 1024)\n \n :If ~isWin\n :AndIf 0<\u2374uid\u2190''setting'Config.UserID'\n msg\u2190'4001\u2336''',uid,''' '\n :Trap 0\n {}4001\u2336uid\n :Else\n 1 Log msg,'failed.'\n :Return\n :EndTrap\n 4 Log msg,'succeeded.'\n :EndIf\n \n 4 Log'Web server ''',ServerName,''' started on port ',\u2355Config.Port\n 4 Log'Root folder: ',Config.Root\n \u2207\n\n :endsection\n\n :section RequestHandling\n\n \u2207 names\u2190pagedata PrepareJSONTargets names;p;m;i;nss;z\n \u235d See if names contain JSON indexed names like editcell[Name]\n \u235d and if so convert them to editcell.Name and make sure editcell exists\n \u235d \/\/\/ Hack by Morten awaiting cleanup or approval by Brian\n \n :If 0\u2260\u2374i\u2190(\u00af1=\u2395NC names)\/\u2373\u2374names \u235d all invalid APL names\n names[i]\u2190('%5B' '%5D'\u2395R(,\u00a8'[]'))\u00a8names[i]\n :AndIf 0\u2260\u2374i\u2190i\/\u2368m\u2190(p\u2190names[i]\u2373\u00a8'[')\u2260\u2218\u2283\u2218\u2374\u00a8names[i] \u235d ... which contain '['\n nss\u2190\u222az\u2190(m\/p-1)\u2191\u00a8names[i] \u235d all namespaces mentions\n nss pagedata.\u2395NS\u00a8\u2282\u236c \u235d prepare empty nss\n names[i]\u2190\u00af1\u2193\u00a8names[i] \u235d drop trailing ']'\n names[i,\u00a8p]\u2190'.' \u235d replace '[' by '.'\n :EndIf\n \u2207\n\n \u2207 r\u2190conns HandleRequest arg;buf;m;Answer;obj;CMD;pos;req;Data;z;r;hdr;REQ;status;file;tn;length;done;offset;res;closed;sess;chartype;raw;enc;which;html;encoderc;encodeMe;startsize;cacheMe;root;page;filename;eoh;n;i;ext;enctype\n \u235d Handle a Web Server Request\n r\u21900\n obj buf\u2190arg\n conns.Buffer,\u2190buf\n conns.Handler\u2190{6::conns.Handler\u2190(\u2395UCS'')\u22615\u2191conns.Buffer \u22c4 conns.Handler}\u236c \u235d are we serving as a mapping handler?\n \n :If 0=conns.Pos \u235d is we haven't found the end of the header yet...\n eoh\u2190\u2395UCS(1+conns.Handler)\u2283(NL,NL)('<\/env>') \u235d end of header marker\n pos\u2190(\u00af1+\u2374eoh)+eoh FindFirst conns.Buffer\n :If pos\u2264\u2374conns.Buffer \u235d found the end of header\n conns.Pos\u2190pos\n conns.Req\u2190fromutf8 conns.(Pos\u2191Buffer)\n :Else\n :Return \u235d haven't found end of header yet, go back for more\n :EndIf\n :EndIf\n \n :If 0<\u2374conns.Req\n :If conns.Pos>i\u2190(z\u2190LF,'content-length:')FindFirst hdr\u2190#.Strings.lc conns.Req\n :AndIf (\u2374conns.Buffer) go back for more\n :EndIf\n :EndIf\n \n conns.Buffer\u2190conns.(Pos\u2193Buffer)\n \n :If conns.Handler \u235d if we're running as a mapping handler\n conns.(Req Buffer)\u2190MakeHTTPRequest conns.Req \u235d fake MiServer out by building an HTTP request from what we've got\n :EndIf\n \n\u235d :Hold 'Request'\n \n REQ\u2190\u2395NEW #.HTTPRequest conns.(Req Buffer)\n REQ.Server\u2190\u2395THIS \u235d Request will also contain reference to the Server\n \n :If 2=conns.\u2395NC'PeerAddr' \u22c4 REQ.PeerAddr\u2190conns.PeerAddr \u22c4 :EndIf \u235d Add Client Address Information\n 8 Log REQ.(PeerAddr Command Page)\n \n :If 2=conns.\u2395NC'PeerCert' \u22c4 REQ.PeerCert\u2190conns.PeerCert \u22c4 :EndIf \u235d Add Client Cert Information\n \n :If Config.RESTful \u235d if running RESTful web service...\n n\u2190+\/\u2227\\2>+\\REQ.Page\u220a'\/\\'\n REQ.RESTfulReq\u2190n\u2193REQ.Page\n REQ.Page\u2190n\u2191REQ.Page\n :EndIf\n \n REQ.Page\u2190Config.DefaultPage{\u2227\/\u2375\u220a'\/\\':'\/',\u237a \u22c4 '\/\\'\u220a\u2368\u00af1\u2191\u2375:\u2375,\u237a \u22c4 \u2375}REQ.Page \u235d no page specified? use the default\n REQ.Page,\u2190(~'.'\u220a{\u2375\/\u2368\u233d~\u2228\\'\/'=\u233d\u2375}REQ.Page)\/Config.DefaultExtension \u235d no extension specified? use the default\n \n SessionHandler.GetSession REQ\n Authentication.Authenticate REQ\n \n :If REQ.Response.Status\u2260401 \u235d Authentication did not fail\n \n ext\u2190\u2283\u00af1\u2191#.Files.SplitFilename filename\u2190Config Virtual REQ.Page\n :If Config.AllowedHttpCommands\u220a\u2368\u2282REQ.Command\n \n :If REQ.Page endswith Config.DefaultExtension \u235d MiPage?\n filename HandleMSP REQ\n :Else\n :If REQ.Command\u2261'get'\n REQ.ReturnFile filename\n :Else\n REQ.Fail 501 \u235d Service Not Implemented\n :EndIf\n :EndIf\n :Else\n REQ.Fail 501 \u235d Service Not Implemented\n :EndIf\n :EndIf\n \n res\u2190REQ.Response\n \n enc\u2190','#.Utils.penclose' '~\u2368REQ.GetHeader'accept-encoding' \u235d check if client supports encoding\n encodeMe\u2190(0<\u2374enc)\u2227conns.Handler\u2190(\u2282ext)\u220a'png' 'gif' 'jpg' \u235d don't try to compress compressed graphics, should probably add zip files, etc\n cacheMe\u21900\n \n :If 1=res.File \u235d See HTTPRequest.ReturnFile\n :If 83=\u2395DR file\u2190res.HTML \u235d if we returned a byte stream, just use it\n length\u2190\u2374file \u22c4 tn\u21900\n :Else\n :Trap 22\n tn\u2190file \u2395NTIE 0\n :If encodeMe \u22c4 length\u2190\u2395NSIZE tn \u235d if using compression, read the entire file\n :Else \u22c4 length\u2190BlockSize \u235d otherwise send it a block at a time\n :EndIf\n res.HTML\u2190\u2395NREAD tn 83 length 0\n cacheMe\u21900\u2260Config.HttpCacheTime \u235d for now, cache all files if set to use caching\n :Else\n REQ.Fail 404\n length\u2190\u2374res.HTML\n res.File\u21900\n :EndTrap\n :EndIf\n startsize\u2190length\n :EndIf\n \n :If (200=res.Status)\u2227encodeMe \u235d if our HTTP status is 200 (OK) and we're okay to encode\n :AndIf 1024<\u2374res.HTML \u235d don't bother compressing less than 1K\n :AndIf 0\u2260which\u2190\u2283Encoders.Encoding{(\u2374\u237a){(\u237a\u2265\u2375)\/\u2375}\u237a\u2373\u2375}enc \u235d try to match what encodings they accept to those we provide\n (encoderc html)\u2190Encoders[which].Compress res.HTML\n :If 0=encoderc\n length\u2190startsize\u2190\u2374res.HTML\n :If startsize>\u2374html \u235d did we save anything by compressing\n length\u2190\u2374res.HTML\u2190html \u235d use it\n res.Headers\u236a\u2190'Content-Encoding'(enctype\u2190Encoders[which].Encoding)\n 4 Log'Used ',enctype,' compression on \"',REQ.Page,'\", transmitted% = ',2\u2355length{\u2395DIV\u21901 \u22c4 \u237a\u00f7\u2375}startsize\n :Else\n 4 Log'Compression not used on \"',REQ.Page,'\", startsize = ',(\u2355startsize),', compressed length = ',\u2355length\n :If 83\u2260\u2395DR res.HTML\n res.HTML\u2190toutf8 res.HTML\n :EndIf\n :EndIf\n :ElseIf 0=res.File\n 2 Log'Compression failed'\n length\u2190\u2374res.HTML\u2190toutf8 res.HTML \u235d otherwise, send uncompressed\n :EndIf\n :ElseIf 0=res.File\n startsize\u2190length\u2190\u2374res.HTML\u2190toutf8\u220ares.HTML\n :EndIf\n \n :If (200=res.Status)\u2227cacheMe \u235d if cacheable, set expires\n :AndIf 0\u2374Answer\u2190\u2395NREAD tn 83,BlockSize,offset\n offset+\u2190\u2374Answer\n :EndIf\n :Until closed \u235d Everything sent\n :EndIf\n \n :If res.File \u22c4 \u2395NUNTIE tn \u22c4 :EndIf\n 8 Log REQ.PeerAddr status\n Logger.Log REQ\n r\u21901\n \u235d :EndHold\n \u2207\n\n \u2207 file HandleMSP REQ;\u2395TRAP;inst;class;z;props;lcp;args;i;ts;date;n;expired;data;m;oldinst;names;html;sessioned;page;root;fn;MS3;token;cb;mask;resp;t;RESTful;APLJax;flag;orig;path;name;ext;list\n \u235d Handle a \"MiServer Page\" request\n \n path name ext\u2190#.Files.SplitFilename file\n \n RETRY:\n :If 0=n\u2190\u2283\u2374list\u2190''#.Files.List orig\u2190file \u235d does the file exist?\n :AndIf Config.DefaultExtension\u2262'.dyalog' \u235d temporary measure to ease the transition to the .mipage extension\n :If 1\u2260\u2283\u2374list\u2190''#.Files.List\u220apath name'.dyalog'\n REQ.Fail 404 \u22c4 \u21920\n :Else\n 1 Log'File not found: \"',orig,'\" using \"',file,'\" instead.'\n :EndIf\n :ElseIf 1\u2260n\n REQ.Fail 404 \u22c4 \u21920\n :EndIf\n \n date\u2190\u220alist[1;3]\n \n MS3\u2190RESTful\u2190expired\u21900\n APLJax\u2190REQ.isAPLJax\n \n :If sessioned\u2190326=\u2395DR REQ.Session \u235d do we think we have a session handler active?\n :AndIf 0\u2260\u2374REQ.Session.Pages \u235d Look for existing Page in Session\n :AndIf (n\u2190\u2374REQ.Session.Pages)\u2265i\u2190REQ.Session.Pages._PageName\u2373\u2282REQ.Page\n inst\u2190i\u2283REQ.Session.Pages \u235d Get existing instance\n :If expired\u2190inst._PageDate\u2262date \u235d Timestamp unchanged?\n\u235dBPB :AndIf expired\u2190(\u2395SRC\u2283\u2283\u2395CLASS inst)\u2262#.UnicodeFile.ReadNestedText file \u235dBPB commented out because it's wasteful\n oldinst\u2190inst\n REQ.Session.Pages~\u2190inst\n 4 Log'Page: ',REQ.Page,' ... has been updated ...'\n :EndIf\n :AndIf ~expired\n 4 Log'Using existing instance of page: ',REQ.Page\n :If 9=\u2395NC'#.HtmlPage'\n :If MS3\u2190\u2228\/(\u220a\u2395CLASS inst)\u220a#.HtmlPage \u22c4 inst._Request\u2190REQ \u22c4 :EndIf\n :EndIf\n :If 9=\u2395NC'#.RESTful'\n :If RESTful\u2190\u2228\/(\u220a\u2395CLASS inst)\u220a#.RESTful \u22c4 inst._Request\u2190REQ \u22c4 :EndIf\n :EndIf\n :Else \u235d First use of Page in this Session, or page expired\n\u235d :If 0\u2260\u2374z\u2190#.Files.GetText file\n :Trap 11 22 92\n inst\u2190Config.AppRoot LoadMSP file \u235d \u2395NEW \u2395SE.SALT.Load file,' -target=#.Pages'\n :Case 11 \u22c4 REQ.Fail 500 \u22c4 1 Log'Domain Error trying to load \"',file,'\"' \u22c4 \u21920 \u235d Domain Error: HTTP Internal Error\n :Case 22 \u22c4 REQ.Fail 404 \u22c4 1 Log'File not found - \"',file,'\"' \u22c4 \u21920 \u235d File Name Error: HTTP Page not found\n :Case 92 \u22c4 REQ.Response.HTML,\u2190'

Unable to load page ',REQ.Page,' due to a translation error.This is typically caused by trying to load a page containing Unicode characters when running MiServer under a Classic (not Unicode) version of Dyalog APL.<\/p>'\n REQ.Fail 500 \u22c4 \u21920\n :EndTrap\n 4 Log'Creating new instance of page: ',REQ.Page\n inst._PageName\u2190REQ.Page\n inst._PageDate\u2190date\n MS3\u2190RESTful\u21900\n :If 9=\u2395NC'#.HtmlPage'\n :If MS3\u2190\u2228\/(\u220a\u2395CLASS inst)\u220a#.HtmlPage\n :OrIf RESTful\u2190\u2228\/(\u220a\u2395CLASS inst)\u220a#.RESTful\n inst.(_Request _PageRef)\u2190REQ inst\n :EndIf\n :EndIf\n \n \u235d ======= TIMEOUT Logic =======\n \u235d If RESTful or not sessioned, let anything through\n \u235d If sessioned and expired, let it though\n \u235d If sessioned but not expired, check if GET\n :If RESTfulexpired\n :AndIf ~REQ.isGet\n inst._TimedOut\u21901\n :EndIf\n \n :If sessioned \u22c4 REQ.Session.Pages,\u2190inst \u22c4 inst.Session\u2190REQ.Session.ID \u22c4 :EndIf\n\u235d :Else \u235d empty file or file not found\n\u235d REQ.Fail 404 \u22c4 \u21920\n\u235d :EndIf\n :EndIf\n \n :If sessioned \u22c4 token\u2190REQ.(Page,\u2355Session.ID)\n :ElseIf ~0\u220a\u2374REQ.PeerAddr \u22c4 token\u2190REQ.(Page,PeerAddr)\n :Else \u22c4 token\u2190\u2355\u2395TID\n :EndIf\n \n :Hold token\n \n \u235d Move arguments \/ parameters into Public Properties\n inst._PageData\u2190\u2395NS''\n :If 0\u22601\u2191\u2374data\u2190{\u2375[\u234b\u2191\u2375[;1];]}REQ.Arguments\u236aREQ.Data\n m\u21901,2\u2262\/data[;1]\n data\u2190(m\/data[;1]),[1.5]m\u2282data[;2]\n i\u2190{\u2375\/\u2373\u2374\u2375}1=\u2283\u2218\u2374\u00a8data[;2]\n data[i;2]\u2190\u2283\u00a8data[i;2]\n :If 0\u2260\u2374lcp\u2190props\u2190('_'\u22601\u2283\u00a8props)\/props\u2190(inst.\u2395NL-2) \u235d Get list of public properties (those beginning with '_' are excluded)\n :AndIf 0\u22601\u2191\u2374args\u2190(data[;1]\u220alcp)\u233fdata\n args\u2190(2\u2308\u2374args)\u2374args\n i\u2190lcp\u2373args[;1]\n \u234e'inst.(',(\u2355props[i]),')\u2190args[;2]'\n :EndIf\n :If \u2228\/mask\u2190'_'\u22601\u2283\u00a8data[;1]\n args\u2190mask\u233fdata\n :Trap 0\n args[;1]\u2190inst._PageData PrepareJSONTargets args[;1]\n \u234e'inst._PageData.(',(\u2355args[;1]),')\u2190args[;2]'\n :EndTrap\n :EndIf\n :EndIf\n \n fn\u2190cb\u2190'Render'\n :If APLJax>RESTful \u235d if it's an APLJax (XmlHttpRequest) request (but not web service)\n REQ.Response.NoWrap\u21901\n fn\u2190cb\u2190'APLJax' \u235d default callback function name\n :If MS3\n inst._what\u2190REQ.GetData'_what'\n inst._event\u2190REQ.GetData'_event'\n inst._value\u2190REQ.GetData'_value'\n inst._selector\u2190REQ.GetData'_selector'\n inst._callback\u2190REQ.GetData'_callback'\n :If ~0\u220a\u2374inst._callback \u235d does the request specify a callback function\n fn\u2190cb\u2190inst._callback\n :EndIf\n :EndIf\n :ElseIf RESTful\n fn\u2190cb\u2190'Respond'\n :ElseIf MS3\n cb\u2190cb inst.{3=\u230a|\u2395NC\u2282\u2375:\u2375 \u22c4 \u237a}fn\u2190'Compose' \u235d default function to call\n :EndIf\n \n :If 3\u2260\u230a|inst.\u2395NC\u2282cb \u235d and is it a public method?\n 1 Log'Method \"',fn,'\" not found (or not public) in page \"',REQ.Page,'\"'\n REQ.Fail 500\n \u21920\n :EndIf\n \n :If MS3\n :If APLJax\n inst._resetAjax\n :Else\n inst._init \u235d reset instance's content\n :EndIf\n :EndIf\n \n :If (1=Config.TrapErrors)\u22279=\u2395NC'#.DrA' \u22c4 \u2395TRAP\u2190#.DrA.TrapServer\n :ElseIf (0=Config.Production) \u22c4 \u2395TRAP\u2190(800 'C' '\u2192FAIL')(811 'E' '\u2395SIGNAL 801')(813 'E' '\u2395SIGNAL 803')(812 'S')(85 'N')(0 'E' '\u234e#.Boot.Oops') \u235d enable development debug framework\n :EndIf\n \n :If flag\u2190APLJax\n :AndIf flag\u2190inst.{6::0 \u22c4 _DebugCallbacks}\u236c\n :EndIf\n \n :Trap 85 \u235d we use 85\u2336 because \"old\" MiPages use REQ.Return internally (and don't return a result)...\n resp\u2190flag Debugger'inst.',cb,(MS3\u2371RESTful)\/' REQ' \u235d ... whereas \"new\" MiPages return the HTML they generate\n resp\u2190(#.JSON.toAPLJAX\u2363APLJax)resp\n inst._TimedOut\u21900\n :If RESTful\n :AndIf ~\u2228\/(\u2282'content-type')(\u2261#.Strings.nocase)\u00a8REQ.Response.Headers[;1]\n resp\u21901 #.JSON.fromAPL resp\n 'Content-Type'REQ.SetHeader'application\/json'\n :EndIf\n REQ.Return resp\n :Else\n :If APLJax\n 1 Log'No result returned by callback method \"',cb,'\" in page \"',REQ.Page,'\"'\n REQ.Return''\n :EndIf\n :EndTrap\n \n :If ~REQ.Response.NoWrap\n :If MS3\u2228RESTful\n inst.Wrap\n :Else\n inst.Wrap REQ\n :EndIf\n :EndIf\n :EndHold\n \u21920\n \n FAIL:\n \u2395\u2190'* Carrying on...'\n \u2395TRAP\u21900\u2374\u2395TRAP\n REQ.Fail 500 \u22c4 \u21920\n \n RESUME: \u235d RESUME is used by DrA\n \u2395TRAP\u21900\/\u2395TRAP \u235d Let framework trapping take over\n \n :If #.DrA.UseHTTP \u22c4 REQ.Fail 500 \u22c4 \u21920 \u22c4 :EndIf\n \n REQ.Title'Unhandled Execution Error'\n REQ.Style'Styles\/error.css'\n html\u2190'h1'#.HTMLInput.Enclose'Server Error in ''',REQ.Page,'''.


'\n html,\u2190'

Unhandled Exception Error<\/i><\/h2>'\n html,\u2190'Description:<\/b> An unhandled exception occurred during the execution of the current web request.'\n :If #.DrA.Mode=2 \u235d Allows editing\n html,\u2190'

Edit page:
',REQ.Page,'<\/a>
'\n :EndIf\n html,\u2190'

Exception Details:<\/b>

'\n :If (#.DrA.Mode>0)\u22270\u2260\u2374#.DrA.LastFile \u22c4 html,\u2190#.DrA.(GenHTML LastFile)\n :Else \u22c4 html,\u2190'code'#.HTMLInput.Enclose'',(\u2283,\/#.DrA.LastError,\u00a8\u2282'
'),'<\/font>'\n :EndIf\n REQ.Return html\n \u2207\n\n \u2207 inst\u2190root LoadMSP file;path;name;ext;rpath;ns;tree;class;level;n;created;node;mask\n path name ext\u2190#.Files.SplitFilename file\n rpath\u2190(\u2374root)\u2193path\n ns\u2190#.Pages\n tree\u2190'\/'#.Utils.penclose rpath\n created\u2190(n\u2190\u2374tree)\u23740\n \n :For level :In \u2373n\n :Select \u2283ns.\u2395NC\u2282node\u2190level\u2283tree\n :Case 0\n :Trap 11\n ns\u2190\u234enode ns.\u2395NS''\n :Else\n 1 Log'Unable to create namespace in #.Pages for page in file \"',file,'\"'\n \u2395SIGNAL 11\n :EndTrap\n ns\u234e'(',(\u2355PageTemplates),')\u2190',\u220a'##.'\u2218,\u2218\u2355\u00a8PageTemplates\n created[level]\u21901\n :Case 9.1\n ns\u2190ns\u234enode\n :Else\n 1 Log'Unable to create namespace in #.Pages for page in file \"',file,'\" due to name conflict'\n :While \u2228\/created \u235d clean up any created nodes\n ns\u2190ns.##\n ns.\u2395EX\u2283(mask\u2190\u233d<\\\u233dcreated)\/tree\n created\u2227\/\u2190~mask\n :EndWhile\n \u2395SIGNAL 11\n :EndSelect\n :EndFor\n \n inst\u2190\u2395NEW class\u2190\u2395SE.SALT.Load file,' -target=',\u2355ns\n \n :If ~name(\u2261#.Strings.nocase)class\u2190\u2283\u00af1\u2191'.'#.Utils.penclose\u2355class\n 1 Log'Filename\/Classname mismatch: ',file,' \u2262 ',class\n :EndIf\n \u2207\n\n \u2207 (req buffer)\u2190MakeHTTPRequest req;x;v;s;p;l;m;n;i;c;h\n\u235d kludge to get by ampersands in a POST - will be fixed when we build proper requests from MiServerCGI\n buffer\u2190c\u2190''\n :If (\u2374req)\u2265i\u21901\u2373\u2368'>tsop<'\u2377\u233dreq\n i\u2190(\u2374req)-i+5\n c\u2190\u00af13\u2193(i+6)\u2193req\n req\u2190(i\u2191req),'<\/env>'\n :EndIf\n \n :Trap 11\n x\u2190\u2395XML req\n :Else\n \u2218\u2218\u2218\n :EndTrap\n v\u2190'var'\u2218\u2261\u00a8x[;2]\n v\u2190{\u2395ML\u21903 \u22c4 (~<\\'='=\u2375)\u2282\u2375}\u00a8v\/x[;3]\n v\u2190(\u220a2=\u2374\u00a8v)\/v\n h\u2190\u220a{0\u220a\u2374\u2375:'' \u22c4 (#.Strings.lc{'HTTP_'\u22615\u2191\u2375:5\u2193\u2375 \u22c4 'HTTPS_'\u22616\u2191\u2375:6\u2193\u2375 \u22c4 \u2375}\u237a){('-',\u237a)[('_',\u237a)\u2373\u237a],': ',\u2375,NL}\u2375}\/\u00a8v\n \u235d pull out special fields\n m p s n\u2190(\u2191v)\u2218{3::2\u2283\u2375 \u22c4 \u237a[;2]\u2283\u2368\u237a[;1]\u2373\u22821\u2283\u2375}\u00a8\u2193'REQUEST_METHOD' 'PATH_INFO' 'SERVER_PROTOCOL' 'SERVER_NAME',[1.1]'GET' '' 'HTTP\/1.0' 'localhost'\n (req buffer)\u2190(m,' ',p,' ',s,NL,'Host: ',n,h,NL)c\n \u2207\n\n :endsection\n\n :section Misc\n\n \u2207 ConnectionMonitor server\n \u235d Because AJAX calls don't send a \"BlockLast\" packet, we need to clean up connection namespaces that didn't get erased\n :While 1\n \u2395DL 30\n :Trap 6\n {}Common.{\u2395EX(\u2395NL \u00af9)~'C',\u00a8#.DRC.Names \u2375}server\n :Else\n \u21920\n :EndTrap\n :EndWhile\n \u2207\n\n \u2207 r\u2190flag Debugger w\n :If flag\n \u2395\u2190'* Callback debugging active on this page, press Ctrl-Enter to trace into Callback function'\n Debug \u2395STOP'Debugger'\n :EndIf\n :Trap 85\n Debug:r\u2190I85 w\n :Else\n :If flag \u22c4 \u236c \u2395STOP'Debugger' \u22c4 :EndIf\n \u2395SIGNAL 85\n :EndTrap\n :If flag \u22c4 \u236c \u2395STOP'Debugger' \u22c4 :EndIf\n \u2207\n\n \u2207 r\u2190SpaceName cmd\n \u235d Generate namespace name from command name\n r\u2190'Common.C',Subst(2\u2283{1\u2193\u00a8('.'=\u2375)\u2282\u2375}'.',cmd)'-=' '_\u2206'\n \u2207\n\n \u2207 r\u2190Subst arg;i;m;str;c;rep\n \u235d Substitute character c in str with rep\n str c rep\u2190arg\n i\u2190c\u2373str\n m\u2190i\u2264\u2374c\n (m\/str)\u2190rep[m\/i]\n r\u2190str\n \u2207\n\n \u2207 file\u2190Config Virtual page;mask;f;ind;t;path;root\n :Access public shared\n \u235d checks for virtual directory\n root\u2190(-'\/\\'\u220a\u2368\u00af1\u2191root)\u2193root\u2190Config.Root\n page\u2190('\/\\'\u220a\u23681\u2191page)\u2193page\n file\u2190root,'\/',page\n :If 0<\u2374Config.Virtual\n ind\u2190Config.Virtual.alias\u2373\u2282t\u2190{(\u00af1+\u2375\u2373'\/')\u2374\u2375}page\n :If ind\u2264\u2374Config.Virtual.alias\n path\u2190ind\u2283Config.Virtual.path\n file\u2190#.Files.unixfix path,('\/\\'\u220a\u2368\u00af1\u2191path)\u2193(\u2374t)\u2193page\n :EndIf\n :EndIf\n \u2207\n\n \u2207 r\u2190isWin\n r\u2190'Win'\u22613\u21911\u2283'.'\u2395WG'APLVersion'\n \u2207\n\n :endsection\n\n:EndClass","returncode":0,"stderr":"","license":"mit","lang":"APL"} {"commit":"fba23f3f8938c39b9bf01693c7b4d94bd870865d","subject":"wrong error guard in dfn","message":"wrong error guard in dfn\n\nError 6 is used to detect a division by 0 but this is incorrect. \u2395DIV is\nused instead.\n","repos":"Dyalog\/MiServer,Dyalog\/MiServer,Dyalog\/MiServer","old_file":"Core\/MiServer.dyalog","new_file":"Core\/MiServer.dyalog","new_contents":"\ufeff:Class MiServer\n\n :Field Public Config\n\n :Field Public TID\u2190\u00af1 \u235d Thread ID Server is running under\n :Field Public BlockSize\u2190640000 \u235d Blocksize when returning files\n\n :Field Public SessionHandler\u2190\u2395NS ''\n :Field Public Authentication\u2190\u2395NS ''\n :Field Public Logger\u2190\u2395NS ''\n :Field Public Application\u2190\u2395NS ''\n\n :field Public Encoders\u2190\u236c \u235d pointers to instances of content encoders\n :field Public Datasources\u2190\u236c\n\n \u2395TRAP\u21900\/\u2395TRAP \u22c4 (\u2395ML \u2395IO)\u21901 1\n\n unicode\u219080=\u2395DR 'A'\n NL\u2190(CR LF)\u2190\u2395UCS 13 10\n FindFirst\u2190{(\u237a\u2377\u2375)\u23731}\n enlist\u2190{\u2395ML\u21901 \u22c4 \u220a\u2375}\n fromutf8\u2190{0::(\u2395AV,'?')[\u2395AVU\u2373\u2375] \u22c4 'UTF-8' \u2395UCS \u2375} \u235d Turn raw UTF-8 input into text\n toutf8\u2190{'UTF-8' \u2395UCS \u2375} \u235d Turn text into UTF-8 byte stream\n setting\u2190{0=\u2395NC \u2375:\u237a \u22c4 \u234e\u2375}\n endswith\u2190{(,\u237a){\u2375\u2261\u237a\u2191\u2368-\u2374\u2375},\u2375}\n I85\u2190{}\n\n bit\u2190{\u2395IO\u21900 \u235d used by Log\n 0=\u237a:0 \u235d all bits turned off\n \u00af1=\u237a:1 \u235d all bits turned on\n (\u23082\u235f\u2375)\u2283\u233d((1+\u2375)\u23742)\u22a4\u237a}\n\n :section Override\n\u235d \u2193\u2193\u2193--- Methods which are usually overridden ---\n\n \u2207 onServerStart\n :Access Public Overridable\n \u235d Handle any server startup processing\n \u2207\n\n \u2207 onSessionStart req\n :Access Public Overridable\n \u235d Process a new session\n \u2207\n\n \u2207 onSessionEnd session\n :Access Public Overridable\n \u235d Handle the end of a session\n \u2207\n\n \u2207 onIdle\n :Access Public Overridable\n \u235d Idle time handler - called when the server has gone idle for a period of time\n \u2207\n\n \u2207 Error req\n :Access Public Overridable\n \u235d Handle trapped errors\n req.Response.HTML\u2190'',(\u2283,\/\u2395DM,\u00a8\u2282''),'<\/font>'\n req.Fail 500 \u235d Internal Server Error\n 1 Log \u2395DM\n \u2207\n\n \u2207 level Log msg\n :Access Public overridable\n \u235d Logs server messages\n \u235d levels implemented in MildServer are:\n \u235d 1-error\/important, 2-warning, 4-informational, 8-transaction (GET\/POST)\n :If Config.LogMessageLevel bit level \u235d if set to display this level of message\n \u2395\u2190msg \u235d display it\n :EndIf\n \u2207\n\n \u2207 Cleanup\n :Access Public overridable\n \u235d Perform any site specific cleanup\n \u2207\n\n\u235d \u2191\u2191\u2191--- End of Overridable methods ---\n :endsection\n\n\n\u235d \u2193\u2193\u2193--- Begin MildServer Core Code\n :section Start\/Stop\n \u2207 Run\n :Access Public\n ('Already Running on Thread',\u2355TID)\u2395SIGNAL(TID\u220a\u2395TNUMS)\/11\n TID\u2190RunServer&\u236c\n \u2207\n\n \u2207 End;tempfiles\n \u235d Called by destructor\n :Access Public\n Logger.Stop \u236c\n :If 0=\u2395NC'ServerName'\n \u235d!!! {}1 #.DRC.Init''\n :Else\n 'Not running'\u2395SIGNAL(#.DRC.Exists ServerName)\u219311\n {}#.DRC.Close ServerName\n :Trap 6 \u235d \u2395TSYNC may not return a value if the thread doesn't, so handle the possible VALUE ERROR\n {}\u2395TSYNC \u2395TID~\u2368TID\u2229\u2395TNUMS\n :EndTrap\n :EndIf\n :If ~0\u220a\u2374Config.TempFolder\n tempfiles\u2190{(~\u2375[;4])\/\u2375[;1]}#.Files.List Config.TempFolder\n :If 0\u2260\u2374tempfiles\u2190(tempfiles\u2228.\u2260\u00a8'.')\/tempfiles\n {}{0::'' \u22c4 #.Files.Delete Config.TempFolder,\u2375}\u00a8tempfiles\n :EndIf\n :EndIf\n Cleanup \u235d overridable\n TID\u2190\u00af1\n \u2207\n :endsection\n\n \u2207 r\u2190RunServer arg;RESUME;\u2395TRAP;Common;cmd;name;port;wres;ref;nspc;sink;Stop;secure;certpath;flags;z;rc;rate;ErrorCount;idletime;msg;uid;ts\n \u235d Simple HTTP (Web) Server framework\n \u235d Assumes Conga available in #.DRC and uses #.HTTPRequest\n \u235d arg: dummy\n \u235d certs: RootCertDir, ServerCert, ServerKey (optional: runs Secure server)\n \n Common\u2190\u2395NS'' \u22c4 Stop\u21900 \u22c4 WAITING\u21900\n \n \n :If Config.TrapErrors>0\n \u2395TRAP\u2190#.DrA.TrapServer\n #.DrA.NoUser\u21901+#.DrA.MailRecipient\u2228.\u2260' '\n :EndIf \u235d Trap MiServer Errors. See HandleMSP for Page Errors.\n \n onServerStart \u235d meant to be overridden\n \n idletime\u2190#.Dates.DateToIDN \u2395TS\n :While ~Stop\n \n wres\u2190#.DRC.Wait ServerName 20000 \u235d Tick every 20 secs\n \u235d wres: (return code) (object name) (command) (data)\n \n :Select 1\u2283wres\n :Case 0 \u235d Good data from RPC.Wait\n :Select 3\u2283wres\n \n :Case 'Error'\n :If ServerName\u22612\u2283wres\n Stop\u21901\n :EndIf\n (1+(4\u2283wres)\u220a1008 1105 1119)Log'RunServer: DRC.Wait reported error ',(\u2355#.DRC.Error 4\u2283wres),' on ',2\u2283wres\n \n \u2395EX SpaceName 2\u2283wres\n \n :CaseList 'Block' 'BlockLast'\n :If 0=\u2395NC nspc\u2190SpaceName 2\u2283wres\n nspc \u2395NS''\n :If 0=1\u2283z\u2190#.DRC.GetProp(2\u2283wres)'PeerAddr' \u22c4 (\u234enspc).PeerAddr\u21902\u2283z\n :Else \u22c4 (\u234enspc).PeerAddr\u2190'Unknown'\n :EndIf\n :If Config.Secure\n rc z\u2190#.DRC.GetProp(2\u2283wres)'PeerCert'\n :If rc=0 \u22c4 (\u234enspc).PeerCert\u2190z\n :Else\n \u2218\n :EndIf\n :EndIf\n :EndIf\n {}(\u234enspc)HandleRequest&wres[2 4] \u235d Run page handler in new thread\n :If 'BlockLast'\u22613\u2283wres\n \u2395EX nspc\n :EndIf\n \n :Case 'Connect' \u235d Ignore\n \n :Else\n 2 Log'Error ',\u2355wres\n :EndSelect\n \n :Case 100 \u235d Time out - put \"housekeeping\" code here\n SessionHandler.HouseKeeping \u2395THIS\n :If 0CongaVersion\n 'MiServer 3.0 requires Conga 2.2 or later'\u2395SIGNAL 11\n :EndIf\n \n 'Unable to allocate TCP\/IP port'\u2395SIGNAL(0\u22601\u2283,AllocatePort)\/11\n \u2207\n\n \u2207 UnMake\n :Implements Destructor\n :Trap 0 \u22c4 End \u22c4 :EndTrap\n \u2207\n\n \u2207 r\u2190AllocatePort;ipv;server\n \u235d Starts Conga, allocates TCP\/IP port\n ipv\u2190'Protocol'Config.IPVersion\n :If Config.Secure\n :If \u2227\/(~0\u220a\u2374)\u00a8Config.(CertFile KeyFile)\n :AndIf \u2283\u2227\/#.Files.Exists\u00a8Config.(CertFile KeyFile)\n {}#.DRC.SetProp'.' 'RootCertDir'Config.RootCertDir\n server\u2190#.DRC.X509Cert.ReadCertFromFile Config.CertFile\n server.KeyOrigin\u2190'DER'Config.KeyFile\n \u2192(0\u22601\u2283r\u2190#.DRC.Srv'' ''Config.Port'Raw' 10000('X509'server)('SSLValidation'Config.SSLFlags)ipv)\u23740 \u235d Must have Conga v2.1\n 1 Log'Starting secure server using certificate ',Config.CertFile\n :Else\n 1 Log'Invalid certificate parameters'\n r\u21901\n \u21920\n :EndIf\n :Else\n \u2192(0\u22601\u2283r\u2190#.DRC.Srv'' ''Config.Port'Raw' 10000 ipv)\u23740\n :EndIf\n \n ServerName\u21902\u2283r\n \n \u235d If running Linux, we may want to switch users (only root can allocate a port less than 1024)\n \n :If ~IsWin\n :AndIf 0<\u2374uid\u2190''setting'Config.UserID'\n msg\u2190'4001\u2336''',uid,''' '\n :Trap 0\n {}4001\u2336uid\n :Else\n 1 Log msg,'failed.'\n :Return\n :EndTrap\n 4 Log msg,'succeeded.'\n :EndIf\n \n 4 Log'Web server ''',ServerName,''' started on port ',\u2355Config.Port\n 4 Log'Root folder: ',Config.Root\n \u2207\n\n :endsection\n\n :section RequestHandling\n\n \u2207 conns HandleRequest arg;buf;m;Answer;obj;CMD;pos;req;Data;z;r;hdr;I;REQ;status;file;tn;length;done;offset;res;closed;sess;chartype;raw;enc;which;html;encoderc;encodeMe;startsize;cacheMe;root;page;filename;eoh;n\n \u235d Handle a Web Server Request\n \n obj buf\u2190arg\n :If 0=conns.\u2395NC'Buffer'\n conns.Buffer\u2190''\n :EndIf\n conns.Buffer,\u2190buf\n conns.Handler\u2190{6::conns.Handler\u2190(\u2395UCS'')\u22615\u2191conns.Buffer \u22c4 conns.Handler}\u236c \u235d are we serving as a mapping handler?\n eoh\u2190\u2395UCS(1+conns.Handler)\u2283(NL,NL)('<\/env>') \u235d end of header marker\n pos\u2190(\u00af1+\u2374eoh)+eoh FindFirst conns.Buffer\n req\u2190fromutf8 pos\u2191conns.Buffer\n \n :If pos>\u2374conns.Buffer \u235d Have we got everything ?\n :Return\n :ElseIf pos>I\u2190(z\u2190LF,'content-length:')FindFirst hdr\u2190#.Strings.lc req\n :AndIf (\u2374conns.Buffer) go back for more\n :EndIf\n conns.Buffer\u2190fromutf8 pos\u2193conns.Buffer\n :If conns.Handler \u235d if we're running as a mapping handler\n (req conns.Buffer)\u2190MakeHTTPRequest req \u235d fake MiServer out by building an HTTP request from what we've got\n :EndIf\n :Hold 'Request'\n \n REQ\u2190\u2395NEW #.HTTPRequest(req conns.Buffer)\n REQ.Server\u2190\u2395THIS \u235d Request will also contain reference to the Server\n \n :If 2=conns.\u2395NC'PeerAddr' \u22c4 REQ.PeerAddr\u2190conns.PeerAddr \u22c4 :EndIf \u235d Add Client Address Information\n 8 Log REQ.(PeerAddr Command Page)\n \n :If 2=conns.\u2395NC'PeerCert' \u22c4 REQ.PeerCert\u2190conns.PeerCert \u22c4 :EndIf \u235d Add Client Cert Information\n \n :If Config.Rest \u235d if running RESTful web service...\n n\u2190+\/\u2227\\2>+\\REQ.Page\u220a'\/\\'\n REQ.RestReq\u2190n\u2193REQ.Page\n REQ.Page\u2190n\u2191REQ.Page\n :EndIf\n \n REQ.Page\u2190Config.DefaultPage{\u2227\/\u2375\u220a'\/\\':'\/',\u237a \u22c4 '\/\\'\u220a\u2368\u00af1\u2191\u2375:\u2375,\u237a \u22c4 \u2375}REQ.Page\n REQ.Page,\u2190(~'.'\u220a{\u2375\/\u2368\u233d~\u2228\\'\/'=\u233d\u2375}REQ.Page)\/Config.DefaultExtension\n \n SessionHandler.GetSession REQ\n Authentication.Authenticate REQ\n \n :If REQ.Response.Status\u2260401 \u235d Authentication did not fail\n \n filename\u2190Config Virtual REQ.Page\n :If Config.AllowedHttpCommands\u220a\u2368\u2282REQ.Command\n \n :If REQ.Page endswith Config.DefaultExtension \u235d MiPage?\n filename HandleMSP REQ\n :Else\n :If REQ.Command\u2261'get'\n REQ.ReturnFile filename\n :Else\n REQ.Fail 501 \u235d Service Not Implemented\n :EndIf\n :EndIf\n :Else\n REQ.Fail 501 \u235d Service Not Implemented\n :EndIf\n :EndIf\n \n res\u2190REQ.Response\n \n encodeMe\u2190conns.Handler\u2190(\u2282\u00af4\u2191file)\u220a'.png' '.gif' '.jpg' \u235d don't try to compress compressed graphics, should probably add zip files, etc\n :EndIf\n :Else\n REQ.Fail 404\n length\u2190\u2374res.HTML\n res.File\u21900\n :EndTrap\n :EndIf\n startsize\u2190length\n :EndIf\n \n :If (200=res.Status)\u2227encodeMe \u235d if our HTTP status is 200 (OK) and we're okay to encode\n :AndIf 1024<\u2374res.HTML \u235d BPB used to be 0\n :AndIf 0\u2260\u2374enc\u2190{(\u2282'')~\u23681\u2193\u00a8(\u2375=\u2283\u2375)\u2282\u2375}' '~\u2368',',REQ.GetHeader'accept-encoding' \u235d check if client supports encoding\n :AndIf 0\u2260which\u2190\u2283Encoders.Encoding{(\u2374\u237a){(\u237a\u2265\u2375)\/\u2375}\u237a\u2373\u2375}enc \u235d try to match what encodings they accept to those we provide\n (encoderc html)\u2190Encoders[which].Compress res.HTML\n :If 0=encoderc\n length\u2190startsize\u2190\u2374res.HTML\n :If startsize>\u2374html \u235d did we save anything by compressing\n length\u2190\u2374res.HTML\u2190html \u235d use it\n res.Headers\u236a\u2190'Content-Encoding'(Encoders[which].Encoding)\n 4 Log'Used compression, transmitted% = ',2\u2355length{\u2395DIV\u21901 \u22c4 \u237a\u00f7\u2375}startsize\n :Else\n 4 Log'Compression not used on \"',REQ.Page,'\", startsize = ',(\u2355startsize),', compressed length = ',\u2355length\n :If 83\u2260\u2395DR res.HTML\n res.HTML\u2190toutf8 res.HTML\n :EndIf\n :EndIf\n :ElseIf 0=res.File\n 2 Log'Compression failed'\n length\u2190\u2374res.HTML\u2190toutf8 res.HTML \u235d otherwise, send uncompressed\n :EndIf\n :ElseIf 0=res.File\n startsize\u2190length\u2190\u2374res.HTML\u2190toutf8 res.HTML\n :EndIf\n \n :If (200=res.Status)\u2227cacheMe \u235d if cacheable, set expires\n res.Headers\u236a\u2190'Expires'(Config.HttpCacheTime #.Dates.HttpDate \u2395TS)\n :EndIf\n res.Headers\u236a\u2190{0\u220a\u2374\u2375:'' '' \u22c4 'Server'\u2375}Config.Server\n status\u2190res.((\u2355Status),' ',StatusText)\n hdr\u2190enlist{\u237a,': ',\u2375,NL}\/res.Headers\n Answer\u2190(toutf8((1+conns.Handler)\u2283'HTTP\/1.0 ' 'Status: '),status,NL,'Content-Length: ',(\u2355length),NL,hdr,NL),res.HTML\n done\u2190length\u2264offset\u2190\u2374res.HTML\n REQ.MSec-\u2368\u2190\u2395AI[3]\n res.Bytes\u2190startsize length\n :Repeat\n :If 0\u22601\u2283z\u2190#.DRC.Send obj Answer done \u235d Send response and\n (1+(1\u2283z)\u220a1008 1119)Log'\"Handlerequest\" closed socket ',obj,' due to error: ',(\u2355z),' sending response'\n done\u21901\n :EndIf\n closed\u2190done\n :If ~done\n done\u2190BlockSize>\u2374Answer\u2190\u2395NREAD tn 83,BlockSize,offset\n offset+\u2190\u2374Answer\n :EndIf\n :Until closed \u235d Everything sent\n \n :If res.File \u22c4 \u2395NUNTIE tn \u22c4 :EndIf\n 8 Log REQ.PeerAddr status\n Logger.Log REQ\n :EndHold\n \u2207\n\n \u2207 file HandleMSP REQ;\u2395TRAP;inst;class;z;props;lcp;args;i;ts;date;n;expired;data;m;oldinst;names;html;sessioned;page;root;fn;MS3;token;cb;mask;resp;t;RESTful;APLJax\n \u235d Handle a \"Mildserver Page\" request\n \n :If 0\u2261date\u21903\u2283(,''#.Files.List file),0 0 0\n REQ.Fail 404 \u22c4 \u21920\n :EndIf\n \n MS3\u2190RESTful\u21900\n \n :If sessioned\u2190326=\u2395DR REQ.Session \u235d do we think we have a session handler active?\n :AndIf 0\u2260\u2374REQ.Session.Pages \u235d Look for existing Page in Session\n :AndIf (n\u2190\u2374REQ.Session.Pages)\u2265i\u2190REQ.Session.Pages._PageName\u2373\u2282REQ.Page\n inst\u2190i\u2283REQ.Session.Pages \u235d Get existing instance\n :If expired\u2190inst._PageDate\u2262date \u235d Timestamp unchanged?\n oldinst\u2190inst\n REQ.Session.Pages~\u2190inst\n 4 Log'Page: ',REQ.Page,' ... has been updated ...'\n :EndIf\n :AndIf ~expired\n 4 Log'Using existing instance of page: ',REQ.Page\n :If 9=\u2395NC'#.HtmlPage'\n :If MS3\u2190\u2228\/(\u220a\u2395CLASS inst)\u220a#.HtmlPage \u22c4 inst._Request\u2190REQ \u22c4 :EndIf\n :EndIf\n :If 9=\u2395NC'#.RESTful'\n :If RESTful\u2190\u2228\/(\u220a\u2395CLASS inst)\u220a#.RESTful \u22c4 inst._Request\u2190REQ \u22c4 :EndIf\n :EndIf\n :Else \u235d First use of Page in this Session, or page expired\n :If 0\u2260\u2374z\u2190#.Files.GetText file\n class\u2190\u2395SE.SALT.Load file,' -target=#.Pages'\n :Trap 11\n inst\u2190\u2395NEW class\n :Else\n REQ.Fail 500 \u22c4 \u21920\n :EndTrap\n 4 Log'Creating new instance of page: ',REQ.Page\n inst._PageName\u2190REQ.Page\n inst._PageDate\u2190date\n :If 9=\u2395NC'#.HtmlPage'\n :If MS3\u2190\u2228\/(\u220a\u2395CLASS inst)\u220a#.HtmlPage\n inst.(_Request _PageRef)\u2190REQ inst\n :EndIf\n :EndIf\n :If 9=\u2395NC'#.HtmlPage'\n :If RESTful\u2190\u2228\/(\u220a\u2395CLASS inst)\u220a#.RESTful\n inst.(_Request _PageRef)\u2190REQ inst\n :EndIf\n :EndIf\n :If sessioned \u22c4 REQ.Session.Pages,\u2190inst \u22c4 :EndIf\n :If 0\u2260\u2395NC'oldinst'\n :AndIf (names\u2190oldinst.\u2395NL-2.2)\u2261inst.\u2395NL-2.2 \u235d Interface is indentical\n :AndIf 0\u2260\u2374names\u2190('_'\u22601\u2283\u00a8names)\/names\n :Trap 6\n \u234e'inst.(',names,')\u2190oldinst.(',(names\u2190\u2355names),')' \u235d Transfer values\n 4 Log' (interface is identical: data transferred)'\n :Else\n 4 Log' (interface is identical: but undefined)'\n :EndTrap\n :EndIf\n :Else\n REQ.Fail 404 \u22c4 \u21920\n :EndIf\n :EndIf\n \n :If sessioned \u22c4 token\u2190REQ.(Page,\u2355Session.ID)\n :ElseIf ~0\u220a\u2374REQ.PeerAddr \u22c4 token\u2190REQ.(Page,PeerAddr)\n :Else \u22c4 token\u2190\u2355\u2395TID\n :EndIf\n \n :Hold token\n \n \u235d Move arguments \/ parameters into Public Properties\n inst._PageData\u2190\u2395NS''\n :If 0\u22601\u2191\u2374data\u2190{\u2375[\u234b\u2191\u2375[;1];]}REQ.Arguments\u236aREQ.Data\n m\u21901,2\u2262\/data[;1]\n data\u2190(m\/data[;1]),[1.5]m\u2282data[;2]\n i\u2190{\u2375\/\u2373\u2374\u2375}1=\u2283\u2218\u2374\u00a8data[;2]\n data[i;2]\u2190\u2283\u00a8data[i;2]\n :If 0\u2260\u2374lcp\u2190props\u2190('_'\u22601\u2283\u00a8props)\/props\u2190(inst.\u2395NL-2) \u235d Get list of public properties (those beginning with '_' are excluded)\n :AndIf 0\u22601\u2191\u2374args\u2190(data[;1]\u220alcp)\u233fdata\n args\u2190(2\u2308\u2374args)\u2374args\n i\u2190lcp\u2373args[;1]\n \u234e'inst.(',(\u2355props[i]),')\u2190args[;2]'\n :EndIf\n :If \u2228\/mask\u2190'_'\u22601\u2283\u00a8data[;1]\n args\u2190mask\u233fdata\n \u234e'inst._PageData.(',(\u2355args[;1]),')\u2190args[;2]'\n :EndIf\n :EndIf\n :If (1=Config.TrapErrors)\u22279=\u2395NC'#.DrA' \u22c4 \u2395TRAP\u2190#.DrA.TrapServer\n :Else \u22c4 \u2395TRAP\u21900 'S'\n :EndIf\n \n fn\u2190''\n cb\u2190'Render' \u235d default function to call\n APLJax\u2190REQ.IsAPLJax>RESTful \u235d if it's an APLJax (XmlHttpRequest) request (but not web service)\n :If APLJax\n REQ.Response.NoWrap\u21901\n cb\u2190'APLJax' \u235d default callback function name\n :If MS3\n inst._what\u2190REQ.GetData'_what'\n inst._event\u2190REQ.GetData'_event'\n :If ~0\u220a\u2374t\u2190REQ.GetData'_callback' \u235d does the request specify a callback function\n cb\u2190t\n :EndIf\n :EndIf\n :EndIf\n \n :If 3=\u230a|inst.\u2395NC\u2282cb \u235d and is it a public method?\n fn\u2190cb\n :Else\n 1 Log'Method \"',cb,'\" not found (or not public) in page \"',REQ.Page,'\"'\n REQ.Fail 500\n :EndIf\n \n :If ~0\u220a\u2374fn\n :If MS3\u2227fn\u2261'Render'\n inst._init \u235d reset instance's content\n :EndIf\n \n :Trap 85 \u235d we use 85\u2336 because \"old\" MiPages use REQ.Return internally (and don't return a result)...\n EXEC: resp\u2190I85'inst.',fn,(MS3\u2371RESTful)\/' REQ' \u235d ... whereas \"new\" MiPages return the HTML they generate\n resp\u2190(#.JSON.toAPLJAX\u2363APLJax)resp\n REQ.Return resp\n :Else\n :If APLJax\n 1 Log'No result returned by callback method \"',cb,'\" in page \"',REQ.Page,'\"'\n REQ.Return''\n :EndIf\n :EndTrap\n \n :If MS3\u2228RESTful\n :If ~REQ.Response.NoWrap\n inst.Wrap\n :EndIf\n :Else\n :If ~REQ.Response.NoWrap\n inst.Wrap REQ\n :EndIf\n :EndIf\n :EndIf\n :EndHold\n \u21920\n \n RESUME: \u235d RESUME is used by DrA\n \u2395TRAP\u21900\/\u2395TRAP \u235d Let framework trapping take over\n \n :If #.DrA.UseHTTP \u22c4 REQ.Fail 500 \u22c4 \u21920 \u22c4 :EndIf\n \n REQ.Title'Unhandled Execution Error'\n REQ.Style'Styles\/error.css'\n html\u2190'h1'#.HTMLInput.Enclose'Server Error in ''',REQ.Page,'''.
'\n html,\u2190'

Unhandled Exception Error<\/i><\/h2>'\n html,\u2190'Description:<\/b> An unhandled exception occurred during the execution of the current web request.'\n :If #.DrA.Mode=2 \u235d Allows editing\n html,\u2190'

Edit page:
',REQ.Page,'<\/a>
'\n :EndIf\n html,\u2190'

Exception Details:<\/b>

'\n :If (#.DrA.Mode>0)\u22270\u2260\u2374#.DrA.LastFile \u22c4 html,\u2190#.DrA.(GenHTML LastFile)\n :Else \u22c4 html,\u2190'code'#.HTMLInput.Enclose'',(\u2283,\/#.DrA.LastError,\u00a8\u2282'
'),'<\/font>'\n :EndIf\n REQ.Return html\n \u2207\n\n \u2207 (req buffer)\u2190MakeHTTPRequest req;x;v;s;p;l;m;n;i;c;h\n\u235d kludge to get by ampersands in a POST - will be fixed when we build proper requests from MiServerCGI\n buffer\u2190c\u2190''\n :If (\u2374req)\u2265i\u21901\u2373\u2368'>tsop<'\u2377\u233dreq\n i\u2190(\u2374req)-i+5\n c\u2190\u00af13\u2193(i+6)\u2193req\n req\u2190(i\u2191req),'<\/env>'\n :EndIf\n \n :Trap 11\n x\u2190\u2395XML req\n :Else\n \u2218\u2218\u2218\n :EndTrap\n v\u2190'var'\u2218\u2261\u00a8x[;2]\n v\u2190{\u2395ML\u21903 \u22c4 (~<\\'='=\u2375)\u2282\u2375}\u00a8v\/x[;3]\n v\u2190(\u220a2=\u2374\u00a8v)\/v\n h\u2190\u220a{0\u220a\u2374\u2375:'' \u22c4 (#.Strings.lc{'HTTP_'\u22615\u2191\u2375:5\u2193\u2375 \u22c4 'HTTPS_'\u22616\u2191\u2375:6\u2193\u2375 \u22c4 \u2375}\u237a){('-',\u237a)[('_',\u237a)\u2373\u237a],': ',\u2375,NL}\u2375}\/\u00a8v\n \u235d pull out special fields\n m p s n\u2190(\u2191v)\u2218{3::2\u2283\u2375 \u22c4 \u237a[;2]\u2283\u2368\u237a[;1]\u2373\u22821\u2283\u2375}\u00a8\u2193'REQUEST_METHOD' 'PATH_INFO' 'SERVER_PROTOCOL' 'SERVER_NAME',[1.1]'GET' '' 'HTTP\/1.0' 'localhost'\n (req buffer)\u2190(m,' ',p,' ',s,NL,'Host: ',n,h,NL)c\n \u2207\n\n :endsection\n\n :section Misc\n\n \u2207 r\u2190SpaceName cmd\n \u235d Generate namespace name from command name\n r\u2190'Common.C',Subst(2\u2283{1\u2193\u00a8('.'=\u2375)\u2282\u2375}'.',cmd)'-=' '_\u2206'\n \u2207\n\n \u2207 r\u2190Subst arg;i;m;str;c;rep\n \u235d Substitute character c in str with rep\n str c rep\u2190arg\n i\u2190c\u2373str\n m\u2190i\u2264\u2374c\n (m\/str)\u2190rep[m\/i]\n r\u2190str\n \u2207\n\n \u2207 file\u2190Config Virtual page;mask;f;ind;t;path;root\n :Access public shared\n \u235d checks for virtual directory\n root\u2190(-'\/\\'\u220a\u2368\u00af1\u2191root)\u2193root\u2190Config.Root\n page\u2190('\/\\'\u220a\u23681\u2191page)\u2193page\n file\u2190root,'\/',page\n :If 0<\u2374Config.Virtual\n ind\u2190Config.Virtual.alias\u2373\u2282t\u2190{(\u00af1+\u2375\u2373'\/')\u2374\u2375}page\n :If ind\u2264\u2374Config.Virtual.alias\n path\u2190ind\u2283Config.Virtual.path\n file\u2190#.Files.unixfix path,('\/\\'\u220a\u2368\u00af1\u2191path)\u2193(\u2374t)\u2193page\n :EndIf\n :EndIf\n \u2207\n\n \u2207 r\u2190IsWin\n r\u2190'Win'\u22613\u21911\u2283'.'\u2395WG'APLVersion'\n \u2207\n :endsection\n\n:EndClass","old_contents":"\ufeff:Class MiServer\n\n :Field Public Config\n\n :Field Public TID\u2190\u00af1 \u235d Thread ID Server is running under\n :Field Public BlockSize\u2190640000 \u235d Blocksize when returning files\n\n :Field Public SessionHandler\u2190\u2395NS ''\n :Field Public Authentication\u2190\u2395NS ''\n :Field Public Logger\u2190\u2395NS ''\n :Field Public Application\u2190\u2395NS ''\n\n :field Public Encoders\u2190\u236c \u235d pointers to instances of content encoders\n :field Public Datasources\u2190\u236c\n\n \u2395TRAP\u21900\/\u2395TRAP \u22c4 (\u2395ML \u2395IO)\u21901 1\n\n unicode\u219080=\u2395DR 'A'\n NL\u2190(CR LF)\u2190\u2395UCS 13 10\n FindFirst\u2190{(\u237a\u2377\u2375)\u23731}\n enlist\u2190{\u2395ML\u21901 \u22c4 \u220a\u2375}\n fromutf8\u2190{0::(\u2395AV,'?')[\u2395AVU\u2373\u2375] \u22c4 'UTF-8' \u2395UCS \u2375} \u235d Turn raw UTF-8 input into text\n toutf8\u2190{'UTF-8' \u2395UCS \u2375} \u235d Turn text into UTF-8 byte stream\n setting\u2190{0=\u2395NC \u2375:\u237a \u22c4 \u234e\u2375}\n endswith\u2190{(,\u237a){\u2375\u2261\u237a\u2191\u2368-\u2374\u2375},\u2375}\n I85\u2190{}\n\n bit\u2190{\u2395IO\u21900 \u235d used by Log\n 0=\u237a:0 \u235d all bits turned off\n \u00af1=\u237a:1 \u235d all bits turned on\n (\u23082\u235f\u2375)\u2283\u233d((1+\u2375)\u23742)\u22a4\u237a}\n\n :section Override\n\u235d \u2193\u2193\u2193--- Methods which are usually overridden ---\n\n \u2207 onServerStart\n :Access Public Overridable\n \u235d Handle any server startup processing\n \u2207\n\n \u2207 onSessionStart req\n :Access Public Overridable\n \u235d Process a new session\n \u2207\n\n \u2207 onSessionEnd session\n :Access Public Overridable\n \u235d Handle the end of a session\n \u2207\n\n \u2207 onIdle\n :Access Public Overridable\n \u235d Idle time handler - called when the server has gone idle for a period of time\n \u2207\n\n \u2207 Error req\n :Access Public Overridable\n \u235d Handle trapped errors\n req.Response.HTML\u2190'',(\u2283,\/\u2395DM,\u00a8\u2282''),'<\/font>'\n req.Fail 500 \u235d Internal Server Error\n 1 Log \u2395DM\n \u2207\n\n \u2207 level Log msg\n :Access Public overridable\n \u235d Logs server messages\n \u235d levels implemented in MildServer are:\n \u235d 1-error\/important, 2-warning, 4-informational, 8-transaction (GET\/POST)\n :If Config.LogMessageLevel bit level \u235d if set to display this level of message\n \u2395\u2190msg \u235d display it\n :EndIf\n \u2207\n\n \u2207 Cleanup\n :Access Public overridable\n \u235d Perform any site specific cleanup\n \u2207\n\n\u235d \u2191\u2191\u2191--- End of Overridable methods ---\n :endsection\n\n\n\u235d \u2193\u2193\u2193--- Begin MildServer Core Code\n :section Start\/Stop\n \u2207 Run\n :Access Public\n ('Already Running on Thread',\u2355TID)\u2395SIGNAL(TID\u220a\u2395TNUMS)\/11\n TID\u2190RunServer&\u236c\n \u2207\n\n \u2207 End;tempfiles\n \u235d Called by destructor\n :Access Public\n Logger.Stop \u236c\n :If 0=\u2395NC'ServerName'\n \u235d!!! {}1 #.DRC.Init''\n :Else\n 'Not running'\u2395SIGNAL(#.DRC.Exists ServerName)\u219311\n {}#.DRC.Close ServerName\n :Trap 6 \u235d \u2395TSYNC may not return a value if the thread doesn't, so handle the possible VALUE ERROR\n {}\u2395TSYNC \u2395TID~\u2368TID\u2229\u2395TNUMS\n :EndTrap\n :EndIf\n :If ~0\u220a\u2374Config.TempFolder\n tempfiles\u2190{(~\u2375[;4])\/\u2375[;1]}#.Files.List Config.TempFolder\n :If 0\u2260\u2374tempfiles\u2190(tempfiles\u2228.\u2260\u00a8'.')\/tempfiles\n {}{0::'' \u22c4 #.Files.Delete Config.TempFolder,\u2375}\u00a8tempfiles\n :EndIf\n :EndIf\n Cleanup \u235d overridable\n TID\u2190\u00af1\n \u2207\n :endsection\n\n \u2207 r\u2190RunServer arg;RESUME;\u2395TRAP;Common;cmd;name;port;wres;ref;nspc;sink;Stop;secure;certpath;flags;z;rc;rate;ErrorCount;idletime;msg;uid;ts\n \u235d Simple HTTP (Web) Server framework\n \u235d Assumes Conga available in #.DRC and uses #.HTTPRequest\n \u235d arg: dummy\n \u235d certs: RootCertDir, ServerCert, ServerKey (optional: runs Secure server)\n \n Common\u2190\u2395NS'' \u22c4 Stop\u21900 \u22c4 WAITING\u21900\n \n \n :If Config.TrapErrors>0\n \u2395TRAP\u2190#.DrA.TrapServer\n #.DrA.NoUser\u21901+#.DrA.MailRecipient\u2228.\u2260' '\n :EndIf \u235d Trap MiServer Errors. See HandleMSP for Page Errors.\n \n onServerStart \u235d meant to be overridden\n \n idletime\u2190#.Dates.DateToIDN \u2395TS\n :While ~Stop\n \n wres\u2190#.DRC.Wait ServerName 20000 \u235d Tick every 20 secs\n \u235d wres: (return code) (object name) (command) (data)\n \n :Select 1\u2283wres\n :Case 0 \u235d Good data from RPC.Wait\n :Select 3\u2283wres\n \n :Case 'Error'\n :If ServerName\u22612\u2283wres\n Stop\u21901\n :EndIf\n (1+(4\u2283wres)\u220a1008 1105 1119)Log'RunServer: DRC.Wait reported error ',(\u2355#.DRC.Error 4\u2283wres),' on ',2\u2283wres\n \n \u2395EX SpaceName 2\u2283wres\n \n :CaseList 'Block' 'BlockLast'\n :If 0=\u2395NC nspc\u2190SpaceName 2\u2283wres\n nspc \u2395NS''\n :If 0=1\u2283z\u2190#.DRC.GetProp(2\u2283wres)'PeerAddr' \u22c4 (\u234enspc).PeerAddr\u21902\u2283z\n :Else \u22c4 (\u234enspc).PeerAddr\u2190'Unknown'\n :EndIf\n :If Config.Secure\n rc z\u2190#.DRC.GetProp(2\u2283wres)'PeerCert'\n :If rc=0 \u22c4 (\u234enspc).PeerCert\u2190z\n :Else\n \u2218\n :EndIf\n :EndIf\n :EndIf\n {}(\u234enspc)HandleRequest&wres[2 4] \u235d Run page handler in new thread\n :If 'BlockLast'\u22613\u2283wres\n \u2395EX nspc\n :EndIf\n \n :Case 'Connect' \u235d Ignore\n \n :Else\n 2 Log'Error ',\u2355wres\n :EndSelect\n \n :Case 100 \u235d Time out - put \"housekeeping\" code here\n SessionHandler.HouseKeeping \u2395THIS\n :If 0CongaVersion\n 'MiServer 3.0 requires Conga 2.2 or later'\u2395SIGNAL 11\n :EndIf\n \n 'Unable to allocate TCP\/IP port'\u2395SIGNAL(0\u22601\u2283,AllocatePort)\/11\n \u2207\n\n \u2207 UnMake\n :Implements Destructor\n :Trap 0 \u22c4 End \u22c4 :EndTrap\n \u2207\n\n \u2207 r\u2190AllocatePort;ipv;server\n \u235d Starts Conga, allocates TCP\/IP port\n ipv\u2190'Protocol'Config.IPVersion\n :If Config.Secure\n :If \u2227\/(~0\u220a\u2374)\u00a8Config.(CertFile KeyFile)\n :AndIf \u2283\u2227\/#.Files.Exists\u00a8Config.(CertFile KeyFile)\n {}#.DRC.SetProp'.' 'RootCertDir'Config.RootCertDir\n server\u2190#.DRC.X509Cert.ReadCertFromFile Config.CertFile\n server.KeyOrigin\u2190'DER'Config.KeyFile\n \u2192(0\u22601\u2283r\u2190#.DRC.Srv'' ''Config.Port'Raw' 10000('X509'server)('SSLValidation'Config.SSLFlags)ipv)\u23740 \u235d Must have Conga v2.1\n 1 Log'Starting secure server using certificate ',Config.CertFile\n :Else\n 1 Log'Invalid certificate parameters'\n r\u21901\n \u21920\n :EndIf\n :Else\n \u2192(0\u22601\u2283r\u2190#.DRC.Srv'' ''Config.Port'Raw' 10000 ipv)\u23740\n :EndIf\n \n ServerName\u21902\u2283r\n \n \u235d If running Linux, we may want to switch users (only root can allocate a port less than 1024)\n \n :If ~IsWin\n :AndIf 0<\u2374uid\u2190''setting'Config.UserID'\n msg\u2190'4001\u2336''',uid,''' '\n :Trap 0\n {}4001\u2336uid\n :Else\n 1 Log msg,'failed.'\n :Return\n :EndTrap\n 4 Log msg,'succeeded.'\n :EndIf\n \n 4 Log'Web server ''',ServerName,''' started on port ',\u2355Config.Port\n 4 Log'Root folder: ',Config.Root\n \u2207\n\n :endsection\n\n :section RequestHandling\n\n \u2207 conns HandleRequest arg;buf;m;Answer;obj;CMD;pos;req;Data;z;r;hdr;I;REQ;status;file;tn;length;done;offset;res;closed;sess;chartype;raw;enc;which;html;encoderc;encodeMe;startsize;cacheMe;root;page;filename;eoh;n\n \u235d Handle a Web Server Request\n \n obj buf\u2190arg\n :If 0=conns.\u2395NC'Buffer'\n conns.Buffer\u2190''\n :EndIf\n conns.Buffer,\u2190buf\n conns.Handler\u2190{6::conns.Handler\u2190(\u2395UCS'')\u22615\u2191conns.Buffer \u22c4 conns.Handler}\u236c \u235d are we serving as a mapping handler?\n eoh\u2190\u2395UCS(1+conns.Handler)\u2283(NL,NL)('<\/env>') \u235d end of header marker\n pos\u2190(\u00af1+\u2374eoh)+eoh FindFirst conns.Buffer\n req\u2190fromutf8 pos\u2191conns.Buffer\n \n :If pos>\u2374conns.Buffer \u235d Have we got everything ?\n :Return\n :ElseIf pos>I\u2190(z\u2190LF,'content-length:')FindFirst hdr\u2190#.Strings.lc req\n :AndIf (\u2374conns.Buffer) go back for more\n :EndIf\n conns.Buffer\u2190fromutf8 pos\u2193conns.Buffer\n :If conns.Handler \u235d if we're running as a mapping handler\n (req conns.Buffer)\u2190MakeHTTPRequest req \u235d fake MiServer out by building an HTTP request from what we've got\n :EndIf\n :Hold 'Request'\n \n REQ\u2190\u2395NEW #.HTTPRequest(req conns.Buffer)\n REQ.Server\u2190\u2395THIS \u235d Request will also contain reference to the Server\n \n :If 2=conns.\u2395NC'PeerAddr' \u22c4 REQ.PeerAddr\u2190conns.PeerAddr \u22c4 :EndIf \u235d Add Client Address Information\n 8 Log REQ.(PeerAddr Command Page)\n \n :If 2=conns.\u2395NC'PeerCert' \u22c4 REQ.PeerCert\u2190conns.PeerCert \u22c4 :EndIf \u235d Add Client Cert Information\n \n :If Config.Rest \u235d if running RESTful web service...\n n\u2190+\/\u2227\\2>+\\REQ.Page\u220a'\/\\'\n REQ.RestReq\u2190n\u2193REQ.Page\n REQ.Page\u2190n\u2191REQ.Page\n :EndIf\n \n REQ.Page\u2190Config.DefaultPage{\u2227\/\u2375\u220a'\/\\':'\/',\u237a \u22c4 '\/\\'\u220a\u2368\u00af1\u2191\u2375:\u2375,\u237a \u22c4 \u2375}REQ.Page\n REQ.Page,\u2190(~'.'\u220a{\u2375\/\u2368\u233d~\u2228\\'\/'=\u233d\u2375}REQ.Page)\/Config.DefaultExtension\n \n SessionHandler.GetSession REQ\n Authentication.Authenticate REQ\n \n :If REQ.Response.Status\u2260401 \u235d Authentication did not fail\n \n filename\u2190Config Virtual REQ.Page\n :If Config.AllowedHttpCommands\u220a\u2368\u2282REQ.Command\n \n :If REQ.Page endswith Config.DefaultExtension \u235d MiPage?\n filename HandleMSP REQ\n :Else\n :If REQ.Command\u2261'get'\n REQ.ReturnFile filename\n :Else\n REQ.Fail 501 \u235d Service Not Implemented\n :EndIf\n :EndIf\n :Else\n REQ.Fail 501 \u235d Service Not Implemented\n :EndIf\n :EndIf\n \n res\u2190REQ.Response\n \n encodeMe\u2190conns.Handler\u2190(\u2282\u00af4\u2191file)\u220a'.png' '.gif' '.jpg' \u235d don't try to compress compressed graphics, should probably add zip files, etc\n :EndIf\n :Else\n REQ.Fail 404\n length\u2190\u2374res.HTML\n res.File\u21900\n :EndTrap\n :EndIf\n startsize\u2190length\n :EndIf\n \n :If (200=res.Status)\u2227encodeMe \u235d if our HTTP status is 200 (OK) and we're okay to encode\n :AndIf 1024<\u2374res.HTML \u235d BPB used to be 0\n :AndIf 0\u2260\u2374enc\u2190{(\u2282'')~\u23681\u2193\u00a8(\u2375=\u2283\u2375)\u2282\u2375}' '~\u2368',',REQ.GetHeader'accept-encoding' \u235d check if client supports encoding\n :AndIf 0\u2260which\u2190\u2283Encoders.Encoding{(\u2374\u237a){(\u237a\u2265\u2375)\/\u2375}\u237a\u2373\u2375}enc \u235d try to match what encodings they accept to those we provide\n (encoderc html)\u2190Encoders[which].Compress res.HTML\n :If 0=encoderc\n length\u2190startsize\u2190\u2374res.HTML\n :If startsize>\u2374html \u235d did we save anything by compressing\n length\u2190\u2374res.HTML\u2190html \u235d use it\n res.Headers\u236a\u2190'Content-Encoding'(Encoders[which].Encoding)\n 4 Log'Used compression, transmitted% = ',2\u2355length{6::0 \u22c4 \u237a\u00f7\u2375}startsize\n :Else\n 4 Log'Compression not used on \"',REQ.Page,'\", startsize = ',(\u2355startsize),', compressed length = ',\u2355length\n :If 83\u2260\u2395DR res.HTML\n res.HTML\u2190toutf8 res.HTML\n :EndIf\n :EndIf\n :ElseIf 0=res.File\n 2 Log'Compression failed'\n length\u2190\u2374res.HTML\u2190toutf8 res.HTML \u235d otherwise, send uncompressed\n :EndIf\n :ElseIf 0=res.File\n startsize\u2190length\u2190\u2374res.HTML\u2190toutf8 res.HTML\n :EndIf\n \n :If (200=res.Status)\u2227cacheMe \u235d if cacheable, set expires\n res.Headers\u236a\u2190'Expires'(Config.HttpCacheTime #.Dates.HttpDate \u2395TS)\n :EndIf\n res.Headers\u236a\u2190{0\u220a\u2374\u2375:'' '' \u22c4 'Server'\u2375}Config.Server\n status\u2190res.((\u2355Status),' ',StatusText)\n hdr\u2190enlist{\u237a,': ',\u2375,NL}\/res.Headers\n Answer\u2190(toutf8((1+conns.Handler)\u2283'HTTP\/1.0 ' 'Status: '),status,NL,'Content-Length: ',(\u2355length),NL,hdr,NL),res.HTML\n done\u2190length\u2264offset\u2190\u2374res.HTML\n REQ.MSec-\u2368\u2190\u2395AI[3]\n res.Bytes\u2190startsize length\n :Repeat\n :If 0\u22601\u2283z\u2190#.DRC.Send obj Answer done \u235d Send response and\n (1+(1\u2283z)\u220a1008 1119)Log'\"Handlerequest\" closed socket ',obj,' due to error: ',(\u2355z),' sending response'\n done\u21901\n :EndIf\n closed\u2190done\n :If ~done\n done\u2190BlockSize>\u2374Answer\u2190\u2395NREAD tn 83,BlockSize,offset\n offset+\u2190\u2374Answer\n :EndIf\n :Until closed \u235d Everything sent\n \n :If res.File \u22c4 \u2395NUNTIE tn \u22c4 :EndIf\n 8 Log REQ.PeerAddr status\n Logger.Log REQ\n :EndHold\n \u2207\n\n \u2207 file HandleMSP REQ;\u2395TRAP;inst;class;z;props;lcp;args;i;ts;date;n;expired;data;m;oldinst;names;html;sessioned;page;root;fn;MS3;token;cb;mask;resp;t;RESTful;APLJax\n \u235d Handle a \"Mildserver Page\" request\n \n :If 0\u2261date\u21903\u2283(,''#.Files.List file),0 0 0\n REQ.Fail 404 \u22c4 \u21920\n :EndIf\n \n MS3\u2190RESTful\u21900\n \n :If sessioned\u2190326=\u2395DR REQ.Session \u235d do we think we have a session handler active?\n :AndIf 0\u2260\u2374REQ.Session.Pages \u235d Look for existing Page in Session\n :AndIf (n\u2190\u2374REQ.Session.Pages)\u2265i\u2190REQ.Session.Pages._PageName\u2373\u2282REQ.Page\n inst\u2190i\u2283REQ.Session.Pages \u235d Get existing instance\n :If expired\u2190inst._PageDate\u2262date \u235d Timestamp unchanged?\n oldinst\u2190inst\n REQ.Session.Pages~\u2190inst\n 4 Log'Page: ',REQ.Page,' ... has been updated ...'\n :EndIf\n :AndIf ~expired\n 4 Log'Using existing instance of page: ',REQ.Page\n :If 9=\u2395NC'#.HtmlPage'\n :If MS3\u2190\u2228\/(\u220a\u2395CLASS inst)\u220a#.HtmlPage \u22c4 inst._Request\u2190REQ \u22c4 :EndIf\n :EndIf\n :If 9=\u2395NC'#.RESTful'\n :If RESTful\u2190\u2228\/(\u220a\u2395CLASS inst)\u220a#.RESTful \u22c4 inst._Request\u2190REQ \u22c4 :EndIf\n :EndIf\n :Else \u235d First use of Page in this Session, or page expired\n :If 0\u2260\u2374z\u2190#.Files.GetText file\n class\u2190\u2395SE.SALT.Load file,' -target=#.Pages'\n :Trap 11\n inst\u2190\u2395NEW class\n :Else\n REQ.Fail 500 \u22c4 \u21920\n :EndTrap\n 4 Log'Creating new instance of page: ',REQ.Page\n inst._PageName\u2190REQ.Page\n inst._PageDate\u2190date\n :If 9=\u2395NC'#.HtmlPage'\n :If MS3\u2190\u2228\/(\u220a\u2395CLASS inst)\u220a#.HtmlPage\n inst.(_Request _PageRef)\u2190REQ inst\n :EndIf\n :EndIf\n :If 9=\u2395NC'#.HtmlPage'\n :If RESTful\u2190\u2228\/(\u220a\u2395CLASS inst)\u220a#.RESTful\n inst.(_Request _PageRef)\u2190REQ inst\n :EndIf\n :EndIf\n :If sessioned \u22c4 REQ.Session.Pages,\u2190inst \u22c4 :EndIf\n :If 0\u2260\u2395NC'oldinst'\n :AndIf (names\u2190oldinst.\u2395NL-2.2)\u2261inst.\u2395NL-2.2 \u235d Interface is indentical\n :AndIf 0\u2260\u2374names\u2190('_'\u22601\u2283\u00a8names)\/names\n :Trap 6\n \u234e'inst.(',names,')\u2190oldinst.(',(names\u2190\u2355names),')' \u235d Transfer values\n 4 Log' (interface is identical: data transferred)'\n :Else\n 4 Log' (interface is identical: but undefined)'\n :EndTrap\n :EndIf\n :Else\n REQ.Fail 404 \u22c4 \u21920\n :EndIf\n :EndIf\n \n :If sessioned \u22c4 token\u2190REQ.(Page,\u2355Session.ID)\n :ElseIf ~0\u220a\u2374REQ.PeerAddr \u22c4 token\u2190REQ.(Page,PeerAddr)\n :Else \u22c4 token\u2190\u2355\u2395TID\n :EndIf\n \n :Hold token\n \n \u235d Move arguments \/ parameters into Public Properties\n inst._PageData\u2190\u2395NS''\n :If 0\u22601\u2191\u2374data\u2190{\u2375[\u234b\u2191\u2375[;1];]}REQ.Arguments\u236aREQ.Data\n m\u21901,2\u2262\/data[;1]\n data\u2190(m\/data[;1]),[1.5]m\u2282data[;2]\n i\u2190{\u2375\/\u2373\u2374\u2375}1=\u2283\u2218\u2374\u00a8data[;2]\n data[i;2]\u2190\u2283\u00a8data[i;2]\n :If 0\u2260\u2374lcp\u2190props\u2190('_'\u22601\u2283\u00a8props)\/props\u2190(inst.\u2395NL-2) \u235d Get list of public properties (those beginning with '_' are excluded)\n :AndIf 0\u22601\u2191\u2374args\u2190(data[;1]\u220alcp)\u233fdata\n args\u2190(2\u2308\u2374args)\u2374args\n i\u2190lcp\u2373args[;1]\n \u234e'inst.(',(\u2355props[i]),')\u2190args[;2]'\n :EndIf\n :If \u2228\/mask\u2190'_'\u22601\u2283\u00a8data[;1]\n args\u2190mask\u233fdata\n \u234e'inst._PageData.(',(\u2355args[;1]),')\u2190args[;2]'\n :EndIf\n :EndIf\n :If (1=Config.TrapErrors)\u22279=\u2395NC'#.DrA' \u22c4 \u2395TRAP\u2190#.DrA.TrapServer\n :Else \u22c4 \u2395TRAP\u21900 'S'\n :EndIf\n \n fn\u2190''\n cb\u2190'Render' \u235d default function to call\n APLJax\u2190REQ.IsAPLJax>RESTful \u235d if it's an APLJax (XmlHttpRequest) request (but not web service)\n :If APLJax\n REQ.Response.NoWrap\u21901\n cb\u2190'APLJax' \u235d default callback function name\n :If MS3\n inst._what\u2190REQ.GetData'_what'\n inst._event\u2190REQ.GetData'_event'\n :If ~0\u220a\u2374t\u2190REQ.GetData'_callback' \u235d does the request specify a callback function\n cb\u2190t\n :EndIf\n :EndIf\n :EndIf\n \n :If 3=\u230a|inst.\u2395NC\u2282cb \u235d and is it a public method?\n fn\u2190cb\n :Else\n 1 Log'Method \"',cb,'\" not found (or not public) in page \"',REQ.Page,'\"'\n REQ.Fail 500\n :EndIf\n \n :If ~0\u220a\u2374fn\n :If MS3\u2227fn\u2261'Render'\n inst._init \u235d reset instance's content\n :EndIf\n \n :Trap 85 \u235d we use 85\u2336 because \"old\" MiPages use REQ.Return internally (and don't return a result)...\n EXEC: resp\u2190I85'inst.',fn,(MS3\u2371RESTful)\/' REQ' \u235d ... whereas \"new\" MiPages return the HTML they generate\n resp\u2190(#.JSON.toAPLJAX\u2363APLJax)resp\n REQ.Return resp\n :Else\n :If APLJax\n 1 Log'No result returned by callback method \"',cb,'\" in page \"',REQ.Page,'\"'\n REQ.Return''\n :EndIf\n :EndTrap\n \n :If MS3\u2228RESTful\n :If ~REQ.Response.NoWrap\n inst.Wrap\n :EndIf\n :Else\n :If ~REQ.Response.NoWrap\n inst.Wrap REQ\n :EndIf\n :EndIf\n :EndIf\n :EndHold\n \u21920\n \n RESUME: \u235d RESUME is used by DrA\n \u2395TRAP\u21900\/\u2395TRAP \u235d Let framework trapping take over\n \n :If #.DrA.UseHTTP \u22c4 REQ.Fail 500 \u22c4 \u21920 \u22c4 :EndIf\n \n REQ.Title'Unhandled Execution Error'\n REQ.Style'Styles\/error.css'\n html\u2190'h1'#.HTMLInput.Enclose'Server Error in ''',REQ.Page,'''.
'\n html,\u2190'

Unhandled Exception Error<\/i><\/h2>'\n html,\u2190'Description:<\/b> An unhandled exception occurred during the execution of the current web request.'\n :If #.DrA.Mode=2 \u235d Allows editing\n html,\u2190'

Edit page:
',REQ.Page,'<\/a>
'\n :EndIf\n html,\u2190'

Exception Details:<\/b>

'\n :If (#.DrA.Mode>0)\u22270\u2260\u2374#.DrA.LastFile \u22c4 html,\u2190#.DrA.(GenHTML LastFile)\n :Else \u22c4 html,\u2190'code'#.HTMLInput.Enclose'',(\u2283,\/#.DrA.LastError,\u00a8\u2282'
'),'<\/font>'\n :EndIf\n REQ.Return html\n \u2207\n\n \u2207 (req buffer)\u2190MakeHTTPRequest req;x;v;s;p;l;m;n;i;c;h\n\u235d kludge to get by ampersands in a POST - will be fixed when we build proper requests from MiServerCGI\n buffer\u2190c\u2190''\n :If (\u2374req)\u2265i\u21901\u2373\u2368'>tsop<'\u2377\u233dreq\n i\u2190(\u2374req)-i+5\n c\u2190\u00af13\u2193(i+6)\u2193req\n req\u2190(i\u2191req),'<\/env>'\n :EndIf\n \n :Trap 11\n x\u2190\u2395XML req\n :Else\n \u2218\u2218\u2218\n :EndTrap\n v\u2190'var'\u2218\u2261\u00a8x[;2]\n v\u2190{\u2395ML\u21903 \u22c4 (~<\\'='=\u2375)\u2282\u2375}\u00a8v\/x[;3]\n v\u2190(\u220a2=\u2374\u00a8v)\/v\n h\u2190\u220a{0\u220a\u2374\u2375:'' \u22c4 (#.Strings.lc{'HTTP_'\u22615\u2191\u2375:5\u2193\u2375 \u22c4 'HTTPS_'\u22616\u2191\u2375:6\u2193\u2375 \u22c4 \u2375}\u237a){('-',\u237a)[('_',\u237a)\u2373\u237a],': ',\u2375,NL}\u2375}\/\u00a8v\n \u235d pull out special fields\n m p s n\u2190(\u2191v)\u2218{3::2\u2283\u2375 \u22c4 \u237a[;2]\u2283\u2368\u237a[;1]\u2373\u22821\u2283\u2375}\u00a8\u2193'REQUEST_METHOD' 'PATH_INFO' 'SERVER_PROTOCOL' 'SERVER_NAME',[1.1]'GET' '' 'HTTP\/1.0' 'localhost'\n (req buffer)\u2190(m,' ',p,' ',s,NL,'Host: ',n,h,NL)c\n \u2207\n\n :endsection\n\n :section Misc\n\n \u2207 r\u2190SpaceName cmd\n \u235d Generate namespace name from command name\n r\u2190'Common.C',Subst(2\u2283{1\u2193\u00a8('.'=\u2375)\u2282\u2375}'.',cmd)'-=' '_\u2206'\n \u2207\n\n \u2207 r\u2190Subst arg;i;m;str;c;rep\n \u235d Substitute character c in str with rep\n str c rep\u2190arg\n i\u2190c\u2373str\n m\u2190i\u2264\u2374c\n (m\/str)\u2190rep[m\/i]\n r\u2190str\n \u2207\n\n \u2207 file\u2190Config Virtual page;mask;f;ind;t;path;root\n :Access public shared\n \u235d checks for virtual directory\n root\u2190(-'\/\\'\u220a\u2368\u00af1\u2191root)\u2193root\u2190Config.Root\n page\u2190('\/\\'\u220a\u23681\u2191page)\u2193page\n file\u2190root,'\/',page\n :If 0<\u2374Config.Virtual\n ind\u2190Config.Virtual.alias\u2373\u2282t\u2190{(\u00af1+\u2375\u2373'\/')\u2374\u2375}page\n :If ind\u2264\u2374Config.Virtual.alias\n path\u2190ind\u2283Config.Virtual.path\n file\u2190#.Files.unixfix path,('\/\\'\u220a\u2368\u00af1\u2191path)\u2193(\u2374t)\u2193page\n :EndIf\n :EndIf\n \u2207\n\n \u2207 r\u2190IsWin\n r\u2190'Win'\u22613\u21911\u2283'.'\u2395WG'APLVersion'\n \u2207\n :endsection\n\n:EndClass","returncode":0,"stderr":"","license":"mit","lang":"APL"} {"commit":"4973d69366cb8e7347c329fd432ca48b96624977","subject":"Added 7161\u2336 to isTrue and isFalse, and commented everything","message":"Added 7161\u2336 to isTrue and isFalse, and commented everything\n","repos":"Dyalog\/MiServer,Dyalog\/MiServer,Dyalog\/MiServer","old_file":"Core\/HtmlElement.dyalog","new_file":"Core\/HtmlElement.dyalog","new_contents":"\ufeff:class HtmlElement \u235d this is the most basic element of a page\n\n\u235d\u2207:require =\\JSON.dyalog\n\n \u2395io\u2190\u2395ml\u21901\n\n :field public shared _version\u21901\n :field public NL\u2190\u2395ucs 13 \u235d 10\n\n :field public Tag\u2190'' \u235d this is the element name\n :field public Content\u2190\u236c \u235d content of the element - a series of strings\/instances\/class+parms\n :field public Handlers\u2190'' \u235d array of event handlers\n :field public _PageRef\u2190'' \u235d reference back to the page instance containing this element\n :field public NoEndTag\u21900 \u235d set to 1 if this singleton element (does not have a closing tag)\n :field public Position \u235d has position information for this element (if position is set)\n :field public Uses\u2190'' \u235d resources that will be used by this object (can be overridden by derived classes)\n\n :field public shared readonly _true\u2190#.JSON.true \u235d same definition as in #.JSON\n :field public shared readonly _false\u2190#.JSON.false \u235d same definition as in #.JSON\n\n\n\u235d define shortcuts to namespaces (initialized later)\n :field public _html \u235d reference to base HTML elements namespace\n :field public _JQ \u235d reference to JQuery\/JQueryUI widgets namespace\n :field public _SF \u235d reference to SyncFusion widgets namespace\n :field public _JSS \u235d reference to JavaScript Snippets namespace\n :field public _DC \u235d reference to Dyalog Controls namespace\n :field public _ \u235d reference to namespace that refers to all elements\/widgets\n\n \u235d make shortcuts for some common HTML attributes\n :field public shared readonly UNDEF\u2190\u2395NULL \u235d setting for undefined attributes\n :field public id\u2190UNDEF \u235d id attribute for the element\n :field public value\u2190UNDEF \u235d value attribute for the element\n :field public name\u2190UNDEF \u235d name attribute for the element\n :field public class\u2190UNDEF \u235d class attribute for the element\n :field public style\u2190UNDEF \u235d style attribute for the element\n :field public title\u2190UNDEF \u235d title attribute for the element\n :field public type\u2190UNDEF \u235d type attribute for the element\n\n :field public readonly CommonAttributes\u2190'id' 'value' 'name' 'class' 'style' 'title' 'type' \u235d element attributes that are directly accessible\n\n _names\u2190_values\u21900\u2374\u2282'' \u235d used for attributes\n\n :field public _styles\u2190''\n\n rand\u2190{t\u219016807\u23362 \u22c4r\u2190?\u2375 \u22c4 t\u219016807\u2336t \u22c4 r }\n\n \u2207 r\u2190Version\n :Access public\n r\u2190{\u2375,[1.1]{0::\u00af1 \u22c4 \u2375._version}\u00a8\u2375}\u2395CLASS \u2395THIS\n \u2207\n\n \u2207 r\u2190context name\n :Access public shared\n :If 326=\u2395DR name \u235d ref?\n r\u2190\u2395RSI{0\u220a\u2374\u237a:'' \u22c4 16::''\n \u2228\/\u2228\/\u00a8(\u2282\u2375)\u220a\u00a8(\u2283\u237a).(\u2395CLASS \u2395THIS):\u2283\u237a\n (1\u2193\u237a)\u2207 \u2375}name\n :Else\n r\u2190\u2395RSI{0\u220a\u2374\u237a:''\n \u22c4 (\u2283\u237a){0=\u237a.\u2395NC\u2282\u2375:0\n \u22c4 ''\u2261t\u2190\u237a\u234e\u2375:0\n \u22c4 1}\u2375:\u2283\u237a\n \u22c4 (1\u2193\u237a)\u2207 \u2375}name\n :EndIf\n \u2207\n\n \u2207 r\u2190isChar w\n :Access public shared\n r\u21900 2\u220a\u236810|\u2395DR w\n \u2207\n\n \u2207 r\u2190isString w\n :Access public shared\n :Select \u2261w\n :Case 2\n :If 1=\u2374,w\n r\u2190{(isChar \u2375)\u22271\u220a\u2374\u23741\/\u2375}\u2283w\n :Else\n r\u21900\n :EndIf\n :CaseList 0 1\n r\u2190{(isChar \u2375)\u22271\u220a\u2374\u23741\/\u2375}w\n :Else\n r\u21900\n :EndSelect\n \u2207\n\n \u2207 r\u2190quote w\n :Access public\n r\u2190{'\"'\u220a\u2375:\u2375 \u22c4 '\"',\u2375,'\"'}w\n \u2207\n\n \u2207 r\u2190isTrue a\n :Access public shared\n \u21920\u2374\u2368r\u2190(,1)\u2261,a \u235d boolean\n \u21920\u2374\u2368r\u2190#.JSON.true\u2261a \u235d namespace\n \u21920\u2374\u2368r\u2190'true'\u2261a \u235d string\n \u21920\u2374\u2368r\u2190a\u2261\u2282'true' \u235d 7161\u23361\n \u2207\n\n \u2207 r\u2190isFalse a\n :Access public shared\n \u21920\u2374\u2368r\u2190(,0)\u2261,a \u235d boolean\n \u21920\u2374\u2368r\u2190#.JSON.false\u2261a \u235d namespace\n \u21920\u2374\u2368r\u2190'false'\u2261a \u235d string\n \u21920\u2374\u2368r\u2190a\u2261\u2282'false' \u235d 7161\u23360\n \u2207\n\n \u2207 r\u2190a ine w\n :Access public shared\n r\u2190a{0\u220a\u2374\u237a:'' \u22c4 \u2375}w \u235d if not empty\n \u2207\n errorIf\u2190{\u237a\u2190\u22a2 \u22c4 0\u2260\u2375:\u237a \u2395SIGNAL \u2375 \u22c4 ''}\n\n :section Attribute Handling\n\n \u2207 r\u2190fixkeys w\n :Access public shared\n r\u2190{2>|\u2261\u2375:,\u2282\u2375 \u22c4 \u2375}w \u235d Enclose if simple\n \u2207\n\n \u2207 SyncAttrs arg\n :Implements Trigger id,name,class,style,title,type,value\n :If \u2283\u2262\/arg.(NewValue OldValue)\n arg.Name Set arg.NewValue\n :EndIf\n \u2207\n\n :property keyed Attrs \u235d element attributes\n :access public\n\n \u2207 set ra;i;new;there;names;ind\n there\u2190~new\u2190(\u2374_names) id=\"foo\"\n\u235d\n\u235d In all other positions, a string of this type is treated as a singleton attribute\n\u235d 'foo' 'goo' 'moo' > id=\"foo\" goo=\"goo\" moo=\"moo\"\n\u235d\n\u235d 2) Single simple string beginning with '#' is an id\n\u235d '#foo' > id=\"foo\"\n\u235d 'goo=moo' '#foo' > goo=\"moo\" id=\"foo\"\n\u235d\n\u235d 3) Single simple string beginning with '.' is treated as a class\n\u235d '.foo' > class=\"foo\"\n\u235d 'foo' '.goo' 'moo' > id=\"foo\" class=\"goo\" moo=\"moo\"\n\u235d\n\u235d 4) Attributes must be paired either as in 'foo=goo' or ('foo' 'goo'), if there is a single pair, it must be enclosed\n\u235d \u2282'href' '#top' > href=\"#top\"\n\u235d\n\u235d The value portion of an attribute pair may begin with '#' or '.' without special interpretation\n\u235d ('href' '#top') '#foo' > href=\"#top\" id=\"foo\"\n \n :If 0=\u2395NC'plain' \u22c4 plain\u21900 \u22c4 :EndIf\n arg\u2190eis,arg\n attr\u2190\u236c\n split\u2190{0=\u22a2\/v\u2190\u2228\\(\u2260\\'\"'=\u2375)<'='=\u2375:\u2375 \u22c4 ((~v)\/\u2375)({'\"'\u2227.=\u220a1 \u00af1\u2191\u00a8\u2282\u2375:\u00af1\u21931\u2193\u2375 \u22c4 \u2375}1\u2193v\/\u2375)}\n :For i :In \u2373\u2374arg\n :Select |\u2261item\u2190,i\u2283arg\n :Case 1\n :If ~0\u220a\u2374item\n :If \u2228\/eq\u2190'='=item \u235d any '=' (i.e.\n :AndIf 0\u2260n\u2190eq+.\u2227nq\u2190~\u2260\\'\"'=item\n :If n=1\n attr,\u2190\u2282split item\n :Else\n attr,\u2190\u2283,\/1 ParseAttr\u00a8item{\u2395ML\u21903 \u22c4 \u2375\u2282\u237a}nq\u2372item=' '\n :EndIf\n :ElseIf 3>f\u2190'#.'\u23731\u2191item\n attr,\u2190\u2282((f\u2283'id' 'class')(1\u2193item))\n :ElseIf plain<\/tag>).\n\n\u235d area base basefont br col frame hr img input isindex link meta param\n\n fmtAttr\u2190{' ',\u237a,'=',Quote HtmlSafeText,\u2355\u2375}\n\n \u2207 r\u2190Render;av;t;vs;e;h;c;p\n :Access public\n \u235d Render by first constructing the Tag, complete with attributes, if any\n r\u2190RenderCore Content\n :If ~0\u220a\u2374av\u2190Tag\n h\u2190RenderHandlers\n p\u2190RenderPosition\n :If 0<\u2374vs\u2190Attrs[]\n av,\u2190\u220afmtAttr\/\u00a8vs\n :EndIf\n av,\u2190RenderStyles\n r\u2190(av Enclose r),h,p\n :EndIf\n \u2207\n\n \u2207 r\u2190Postrender r\n :Access overridable\n \u2207\n\n \u2207 r\u2190RenderCore list;e;t\n :Access public\n \u235d do the bulk of the rendering work\n r\u2190''\n :For e :In eis list\n :If isInstance\u2283e\n r,\u2190e.Render\n :ElseIf isClass\u2283e\n r,\u2190(\u2395NEW e).Render\n :Else\n :If 1<\u2374\u2374t\u2190\u2355e\n t\u2190\u220a(\u2193t),\u00a8\u2282''\n :EndIf\n r,\u2190t\n :EndIf\n :EndFor\n \u2207\n\n \u2207 r\u2190HtmlSafeText txt;i;m;u;ucs\n :Access public shared\n \u235d make text HTML \"safe\"\n r\u2190,\u2395FMT txt\n i\u2190'&<>\"#'\u2373r\n i-\u2190(i=1)\u22271\u2193(i=5),0 \u235d mark & that aren't &#\n m\u2190i\u220a\u23734\n u\u2190127'\u2395FMT u\/ucs\n r\u2190\u220ar\n \u2207\n\n \u2207 r\u2190RenderPosition\n :Access public\n r\u2190''\n :If 9=\u2395NC'Position'\n :AndIf ~0\u220a\u2374Position.\u2395NL-2\n Uses,\u2190\u2282'JQueryUI'\n r\u2190#.JQ.JQueryfn'position'('#',SetId)Position\n Use\n :EndIf\n \u2207\n\n :endsection\n\n :section Utilities\n\n Bracket\u2190{'<',\u2375,'>'}\n\n \u2207 SetInputName\n :Access public\n \u235d for input element widgets, this will set the name to the id if not already set\n \u235d or the id to the name if not already set\n :If (\u2282name)\u220aUNDEF''\n :If (\u2282id)\u220aUNDEF''\n SetId\n :EndIf\n name\u2190id\n :ElseIf UNDEF\u2261id\n id\u2190name\n :EndIf\n \u2207\n\n \u2207 r\u2190tag Enclose txt;nl\n :Access public shared\n tag\u2190,tag\n r\u2190(tag{NoEndTag\u22270\u220a\u2374\u2375:Bracket \u237a,'\/' \u22c4 (Bracket \u237a),\u2375,Bracket'\/',\u237a\u2191\u2368\u00af1+\u237a\u2373' '}txt),NL\n \u2207\n\n \u2207 r\u2190{a}eis w\n :Access public shared\n r\u2190((,\u2218\u2282)\u2363((isString w)\u22272>|\u2261w))w \u235d enclose if simple character\n \u2207\n\n \u2207 da\u2190args defaultArgs defaultvalues\n :Access public shared\n da\u2190da,(\u2374,da\u2190eis args)\u2193defaultvalues\n \u2207\n\n \u2207 r\u2190Quote a;b\n :Access public shared\n b\u21901\u2193<\u233f\u00af1 0\u233d'\\\"'\u2218.=';',a \u235d keep \\\" as is\n (b\/a)\u2190\u2282'"'\n r\u21901\u233d'\"\"',\u220aa\n \u2207\n\n \u2207 r\u2190attr ParseArgs args\n :Access public\n :If ~0\u220a\u2374r\u2190args\n :If isClass\u2283args\n r\u2190\u2395NEW\u2218{2<\u2374,\u2375:(\u2283\u2375)({eis \u2375}(1\u2193\u2375)) \u22c4 \u2375}args\n :If 0\u2260\u2395NC\u2282'_PageRef'\n r._PageRef\u2190_PageRef\n :EndIf\n :If ~0\u220a\u2374attr\n r.SetAttr attr\n :EndIf\n :Else \u235dIf isInstance\u2283args\n r\u2190args\n :EndIf\n :EndIf\n \u2207\n\n \u2207 {r}\u2190Push args;c;cl;attr;elm\n :Access public\n :If ~0\u220a\u2374r\u2190args\n (cl attr)\u2190{2\u2191\u2375,(\u2374\u2375)\u2193'' ''}eis args\n c\u2190Content\n :If isClass cl\n elm\u2190\u2395NEW cl\n elm.Content\u2190c\n :If ~0\u220a\u2374attr\n elm.SetAttr attr\n :EndIf\n r\u2190Content\u2190elm\n :ElseIf 0\u220a\u2374attr\n r\u2190Content,\u2368\u2190\u2282cl\n :Else\n 'Invalid Push arguments'\u2395SIGNAL 11\n :EndIf\n :EndIf\n \u2207\n\n \u2207 {r}\u2190{attr}Add args;cl\n \u235d add \"something\" to the Content\n \u235d args can be an instance, a class, or just html\/text\n :Access public\n r\u2190''\n :If ~0\u220a\u2374\u220aargs\n :If 0=\u2395NC'attr' \u22c4 attr\u2190'' \u22c4 :EndIf\n r\u2190attr ParseArgs args\n :Trap 4 5 \u235d rank and length error\n Content,\u2190r\n :Else\n Content,\u2190\u2282r\n :EndTrap\n :EndIf\n \u2207\n\n \u2207 {r}\u2190{attr}New args;cl\n \u235d create a new instance\n \u235d args can be an instance, a class, or just html\/text\n :Access public shared\n r\u2190''\n :If ~0\u220a\u2374\u220aargs\n :If 0=\u2395NC'attr' \u22c4 attr\u2190'' \u22c4 :EndIf\n r\u2190attr ParseArgs args\n :EndIf\n \u2207\n\n \u2207 {r}\u2190{attr}Insert args;cl\n \u235d add \"something\" to the beginning of Content\n \u235d args can be an instance, a class, or just html\/text\n :Access public\n r\u2190''\n :If ~0\u220a\u2374\u220aargs\n :If 0=\u2395NC'attr' \u22c4 attr\u2190'' \u22c4 :EndIf\n r\u2190attr ParseArgs args\n :Trap 4 5 \u235d rank and length error\n Content,\u2368\u2190r\n :Else\n Content,\u2368\u2190\u2282r\n :EndTrap\n :EndIf\n \u2207\n\n \u2207 {r}\u2190Last\n :Access public\n r\u2190\u2283\u233dContent\n \u2207\n\n \u2207 r\u2190isClass ao\n :Access public shared\n r\u21909.4\u220a\u2395NC\u2282'ao'\n \u2207\n\n \u2207 r\u2190isInstance ao\n :Access public shared\n r\u21909.2\u220a\u2395NC\u2282'ao'\n \u2207\n\n \u2207 r\u2190isRef obj\n :Access public shared\n r\u21909\u220a\u2395NC'obj'\n \u2207\n\n isattr\u2190{isString \u2375:1 \u22c4 isRef \u2375:0 \u22c4 \u2227\/\u2207\u00a8\u2375}\n\n \u2207 r\u2190isAttr obj\n :Access public shared\n r\u2190isattr obj\n \u2207\n\n \u2207 r\u2190renderIt It\n :Access public shared\n r\u2190{326=\u2395DR\u2283\u2375:{isInstance\u2283\u2375:(\u2283\u2375).Render\n isClass\u2283\u2375:(\u2395NEW(\u2283\u2375)((\u2283\u2363(2=\u2283\u2374\u2375))1\u2193\u2375)).Render\n ,\u2355\u2375}\u2375 \u22c4 ,\u2355\u2375}It\n \u2207\n\n \u2207 r\u2190isHtmlElement ao\n :Access public shared\n :Trap r\u21900\n r\u2190\u2283\u2228\/#.HtmlElement=\u2395CLASS ao\n :EndTrap\n \u2207\n\n \u2207 r\u2190Parse string;b;s\n \u235d Separate each section of name=\"...\"\n :Access public\n string\u2190(b\u23721\u233db\u2190' '=s)\/s\u2190' ',string\n b\u2190(' '=string)>\u2260\\'\"'=string\n r\u21901\u2193\u00a8b\u2282string \u235d each pair\n s\u2190r\u2373\u00a8'=' \u235d each is separated by =\n r\u2190s{(\u00af1\u2193\u237a\u2191\u2375)(1\u2193\u00af1\u2193\u237a\u2193\u2375)}\u00a8r\n \u2207\n\n \u2207 r\u2190GenId\n :Access public shared\n r\u2190'id',\u2355rand \u00af1+2*31\n \u2207\n\n \u2207 {myid}\u2190SetId\n :Access public\n :If UNDEF\u2261myid\u2190id\n :If ''\u2261myid\u2190\u2283Attrs[\u2282'id']\n id\u2190myid\u2190GenId\n :Else\n id\u2190myid\n :EndIf\n :EndIf\n \u2207\n\n dtlb\u2190{\u2375{((\u2228\\\u2375)\u2227\u233d\u2228\\\u233d\u2375)\/\u237a}' '\u2260\u2375}\n\n \u2207 r\u2190ScriptFollows\n :Access public shared\n r\u2190\u220a(\u2395UCS 13 10)\u2218,\u00a8{\u2375\/\u2368'\u235d'\u2260\u2283\u00a8\u2375}{1\u2193\u00a8\u2375\/\u2368\u2227\\'\u235d'=\u2283\u00a8\u2375}{\u2375{((\u2228\\\u2375)\u2227\u233d\u2228\\\u233d\u2375)\/\u237a}' '\u2260\u2375}\u00a8(1+2\u2283\u2395LC)\u2193\u2193(\u2283\u2283\u2395CLASS 1\u2283\u2395RSI).(180\u2336)2\u2283\u2395SI\n \u2207\n\n \u2207 r\u2190WrapFollowing tag;text;SplitOnSpaceLines;Trim;FirstCommentBlock\n :Access public shared\n \n \u235d USAGE:\n \u235d\n \u235d Add WrapFollowing 'p class=\"bodytext\"'\n \u235d \u235d paragraph may span\n \u235d \u235d several lines\n \u235d \u235d\n \u235d \u235d they are separated by empty comment lines\n \u235d\n \u235d RESULT:\n \u235d\n \u235d

paragraph may span several lines<\/p>\n \u235d

they are separated by empty comment lines<\/p>\n \u235d\n \n Trim\u2190{(\u2228\\' '\u2260\u2375)\/\u2375}\u00a8\n FirstCommentBlock\u2190{1\u2193\u00a8\u2375\/\u2368\u2227\\'\u235d'=\u2283\u00a8\u2375}\n SplitOnSpaceLines\u2190{1\u2193\u00a8\u2375\u2282\u2368\u2375\u2227.=\u00a8' '}\n text\u2190(1+2\u2283\u2395LC)\u2193\u2193(\u2283\u2283\u2395CLASS 1\u2283\u2395RSI).(180\u2336)2\u2283\u2395SI\n \n r\u2190tag\u2218#.HTMLUtils.Enclose\u00a8\u220a\u00a8SplitOnSpaceLines' ',\u00a8\u2368' ',\u233d\u00a8Trim\u233d\u00a8FirstCommentBlock Trim text\n \u2207\n\n \u2207 r\u2190what Subst text;names;gv;i;repl;fixL;fixR\n :Access public shared\n r\u2190text\n fixL\u2190'[][{}()?*.+\\\\^$|]'\u2395R'\\\\\\0' \u235d precede regex metacharacters by \\\n fixR\u2190'&' '%' '\\\\'\u2395R'\\\\\\0' \u235d add \\ to & % \\\n :Select \u2395NC\u2282'what'\n :Case 9.1 \u235d namespace\n gv\u2190\u2352\u220a\u2374\u00a8names\u2190what.\u2395NL \u00af2 3 \u235d variables and functions only, sort so that 'foo' matches before 'fo'\n r\u2190(names[gv]\u2395R(fixR\u00a8\u2355\u00a8what\u234e\u2355names[gv]))r\n :Case 2.1 \u235d substitution pairs\n :If 2=|\u2261what \u22c4 what\u2190,\u2282what \u22c4 :EndIf\n :If 2\u2260\u2374\u2374what \u22c4 what\u2190\u2191what \u22c4 :EndIf\n what\u2190,\u00a8what\n r\u2190(fixL\u00a8what[;1])\u2395R(fixR\u00a8what[;2])\u22a2r\n :EndSelect\n \u2207\n\n :endsection\n\n:endclass \u235d HtmlElement","old_contents":"\ufeff:class HtmlElement \u235d this is the most basic element of a page\n\n\u235d\u2207:require =\\JSON.dyalog\n\n \u2395io\u2190\u2395ml\u21901\n\n :field public shared _version\u21901\n :field public NL\u2190\u2395ucs 13 \u235d 10\n\n :field public Tag\u2190'' \u235d this is the element name\n :field public Content\u2190\u236c \u235d content of the element - a series of strings\/instances\/class+parms\n :field public Handlers\u2190'' \u235d array of event handlers\n :field public _PageRef\u2190'' \u235d reference back to the page instance containing this element\n :field public NoEndTag\u21900 \u235d set to 1 if this singleton element (does not have a closing tag)\n :field public Position \u235d has position information for this element (if position is set)\n :field public Uses\u2190'' \u235d resources that will be used by this object (can be overridden by derived classes)\n\n :field public shared readonly _true\u2190#.JSON.true \u235d same definition as in #.JSON\n :field public shared readonly _false\u2190#.JSON.false \u235d same definition as in #.JSON\n\n\n\u235d define shortcuts to namespaces (initialized later)\n :field public _html \u235d reference to base HTML elements namespace\n :field public _JQ \u235d reference to JQuery\/JQueryUI widgets namespace\n :field public _SF \u235d reference to SyncFusion widgets namespace\n :field public _JSS \u235d reference to JavaScript Snippets namespace\n :field public _DC \u235d reference to Dyalog Controls namespace\n :field public _ \u235d reference to namespace that refers to all elements\/widgets\n\n \u235d make shortcuts for some common HTML attributes\n :field public shared readonly UNDEF\u2190\u2395NULL \u235d setting for undefined attributes\n :field public id\u2190UNDEF \u235d id attribute for the element\n :field public value\u2190UNDEF \u235d value attribute for the element\n :field public name\u2190UNDEF \u235d name attribute for the element\n :field public class\u2190UNDEF \u235d class attribute for the element\n :field public style\u2190UNDEF \u235d style attribute for the element\n :field public title\u2190UNDEF \u235d title attribute for the element\n :field public type\u2190UNDEF \u235d type attribute for the element\n\n :field public readonly CommonAttributes\u2190'id' 'value' 'name' 'class' 'style' 'title' 'type' \u235d element attributes that are directly accessible\n\n _names\u2190_values\u21900\u2374\u2282'' \u235d used for attributes\n\n :field public _styles\u2190''\n\n rand\u2190{t\u219016807\u23362 \u22c4r\u2190?\u2375 \u22c4 t\u219016807\u2336t \u22c4 r }\n\n \u2207 r\u2190Version\n :Access public\n r\u2190{\u2375,[1.1]{0::\u00af1 \u22c4 \u2375._version}\u00a8\u2375}\u2395CLASS \u2395THIS\n \u2207\n\n \u2207 r\u2190context name\n :Access public shared\n :If 326=\u2395DR name \u235d ref?\n r\u2190\u2395RSI{0\u220a\u2374\u237a:'' \u22c4 16::''\n \u2228\/\u2228\/\u00a8(\u2282\u2375)\u220a\u00a8(\u2283\u237a).(\u2395CLASS \u2395THIS):\u2283\u237a\n (1\u2193\u237a)\u2207 \u2375}name\n :Else\n r\u2190\u2395RSI{0\u220a\u2374\u237a:''\n \u22c4 (\u2283\u237a){0=\u237a.\u2395NC\u2282\u2375:0\n \u22c4 ''\u2261t\u2190\u237a\u234e\u2375:0\n \u22c4 1}\u2375:\u2283\u237a\n \u22c4 (1\u2193\u237a)\u2207 \u2375}name\n :EndIf\n \u2207\n\n \u2207 r\u2190isChar w\n :Access public shared\n r\u21900 2\u220a\u236810|\u2395DR w\n \u2207\n\n \u2207 r\u2190isString w\n :Access public shared\n :Select \u2261w\n :Case 2\n :If 1=\u2374,w\n r\u2190{(isChar \u2375)\u22271\u220a\u2374\u23741\/\u2375}\u2283w\n :Else\n r\u21900\n :EndIf\n :CaseList 0 1\n r\u2190{(isChar \u2375)\u22271\u220a\u2374\u23741\/\u2375}w\n :Else\n r\u21900\n :EndSelect\n \u2207\n\n \u2207 r\u2190quote w\n :Access public\n r\u2190{'\"'\u220a\u2375:\u2375 \u22c4 '\"',\u2375,'\"'}w\n \u2207\n\n \u2207 r\u2190isTrue a\n :Access public shared\n \u21920\u2374\u2368r\u2190(,1)\u2261,a\n \u21920\u2374\u2368r\u2190#.JSON.true\u2261a\n \u21920\u2374\u2368r\u2190'true'\u2261a\n \u2207\n\n \u2207 r\u2190isFalse a\n :Access public shared\n \u21920\u2374\u2368r\u2190(,0)\u2261,a\n \u21920\u2374\u2368r\u2190#.JSON.false\u2261a\n \u21920\u2374\u2368r\u2190'false'\u2261a\n \u2207\n\n \u2207 r\u2190a ine w\n :Access public shared\n r\u2190a{0\u220a\u2374\u237a:'' \u22c4 \u2375}w \u235d if not empty\n \u2207\n errorIf\u2190{\u237a\u2190\u22a2 \u22c4 0\u2260\u2375:\u237a \u2395SIGNAL \u2375 \u22c4 ''}\n\n :section Attribute Handling\n\n \u2207 r\u2190fixkeys w\n :Access public shared\n r\u2190{2>|\u2261\u2375:,\u2282\u2375 \u22c4 \u2375}w \u235d Enclose if simple\n \u2207\n\n \u2207 SyncAttrs arg\n :Implements Trigger id,name,class,style,title,type,value\n :If \u2283\u2262\/arg.(NewValue OldValue)\n arg.Name Set arg.NewValue\n :EndIf\n \u2207\n\n :property keyed Attrs \u235d element attributes\n :access public\n\n \u2207 set ra;i;new;there;names;ind\n there\u2190~new\u2190(\u2374_names) id=\"foo\"\n\u235d\n\u235d In all other positions, a string of this type is treated as a singleton attribute\n\u235d 'foo' 'goo' 'moo' > id=\"foo\" goo=\"goo\" moo=\"moo\"\n\u235d\n\u235d 2) Single simple string beginning with '#' is an id\n\u235d '#foo' > id=\"foo\"\n\u235d 'goo=moo' '#foo' > goo=\"moo\" id=\"foo\"\n\u235d\n\u235d 3) Single simple string beginning with '.' is treated as a class\n\u235d '.foo' > class=\"foo\"\n\u235d 'foo' '.goo' 'moo' > id=\"foo\" class=\"goo\" moo=\"moo\"\n\u235d\n\u235d 4) Attributes must be paired either as in 'foo=goo' or ('foo' 'goo'), if there is a single pair, it must be enclosed\n\u235d \u2282'href' '#top' > href=\"#top\"\n\u235d\n\u235d The value portion of an attribute pair may begin with '#' or '.' without special interpretation\n\u235d ('href' '#top') '#foo' > href=\"#top\" id=\"foo\"\n \n :If 0=\u2395NC'plain' \u22c4 plain\u21900 \u22c4 :EndIf\n arg\u2190eis,arg\n attr\u2190\u236c\n split\u2190{0=\u22a2\/v\u2190\u2228\\(\u2260\\'\"'=\u2375)<'='=\u2375:\u2375 \u22c4 ((~v)\/\u2375)({'\"'\u2227.=\u220a1 \u00af1\u2191\u00a8\u2282\u2375:\u00af1\u21931\u2193\u2375 \u22c4 \u2375}1\u2193v\/\u2375)}\n :For i :In \u2373\u2374arg\n :Select |\u2261item\u2190,i\u2283arg\n :Case 1\n :If ~0\u220a\u2374item\n :If \u2228\/eq\u2190'='=item \u235d any '=' (i.e.\n :AndIf 0\u2260n\u2190eq+.\u2227nq\u2190~\u2260\\'\"'=item\n :If n=1\n attr,\u2190\u2282split item\n :Else\n attr,\u2190\u2283,\/1 ParseAttr\u00a8item{\u2395ML\u21903 \u22c4 \u2375\u2282\u237a}nq\u2372item=' '\n :EndIf\n :ElseIf 3>f\u2190'#.'\u23731\u2191item\n attr,\u2190\u2282((f\u2283'id' 'class')(1\u2193item))\n :ElseIf plain<\/tag>).\n\n\u235d area base basefont br col frame hr img input isindex link meta param\n\n fmtAttr\u2190{' ',\u237a,'=',Quote HtmlSafeText,\u2355\u2375}\n\n \u2207 r\u2190Render;av;t;vs;e;h;c;p\n :Access public\n \u235d Render by first constructing the Tag, complete with attributes, if any\n r\u2190RenderCore Content\n :If ~0\u220a\u2374av\u2190Tag\n h\u2190RenderHandlers\n p\u2190RenderPosition\n :If 0<\u2374vs\u2190Attrs[]\n av,\u2190\u220afmtAttr\/\u00a8vs\n :EndIf\n av,\u2190RenderStyles\n r\u2190(av Enclose r),h,p\n :EndIf\n \u2207\n\n \u2207 r\u2190Postrender r\n :Access overridable\n \u2207\n\n \u2207 r\u2190RenderCore list;e;t\n :Access public\n \u235d do the bulk of the rendering work\n r\u2190''\n :For e :In eis list\n :If isInstance\u2283e\n r,\u2190e.Render\n :ElseIf isClass\u2283e\n r,\u2190(\u2395NEW e).Render\n :Else\n :If 1<\u2374\u2374t\u2190\u2355e\n t\u2190\u220a(\u2193t),\u00a8\u2282''\n :EndIf\n r,\u2190t\n :EndIf\n :EndFor\n \u2207\n\n \u2207 r\u2190HtmlSafeText txt;i;m;u;ucs\n :Access public shared\n \u235d make text HTML \"safe\"\n r\u2190,\u2395FMT txt\n i\u2190'&<>\"#'\u2373r\n i-\u2190(i=1)\u22271\u2193(i=5),0 \u235d mark & that aren't &#\n m\u2190i\u220a\u23734\n u\u2190127'\u2395FMT u\/ucs\n r\u2190\u220ar\n \u2207\n\n \u2207 r\u2190RenderPosition\n :Access public\n r\u2190''\n :If 9=\u2395NC'Position'\n :AndIf ~0\u220a\u2374Position.\u2395NL-2\n Uses,\u2190\u2282'JQueryUI'\n r\u2190#.JQ.JQueryfn'position'('#',SetId)Position\n Use\n :EndIf\n \u2207\n\n :endsection\n\n :section Utilities\n\n Bracket\u2190{'<',\u2375,'>'}\n\n \u2207 SetInputName\n :Access public\n \u235d for input element widgets, this will set the name to the id if not already set\n \u235d or the id to the name if not already set\n :If (\u2282name)\u220aUNDEF''\n :If (\u2282id)\u220aUNDEF''\n SetId\n :EndIf\n name\u2190id\n :ElseIf UNDEF\u2261id\n id\u2190name\n :EndIf\n \u2207\n\n \u2207 r\u2190tag Enclose txt;nl\n :Access public shared\n tag\u2190,tag\n r\u2190(tag{NoEndTag\u22270\u220a\u2374\u2375:Bracket \u237a,'\/' \u22c4 (Bracket \u237a),\u2375,Bracket'\/',\u237a\u2191\u2368\u00af1+\u237a\u2373' '}txt),NL\n \u2207\n\n \u2207 r\u2190{a}eis w\n :Access public shared\n r\u2190((,\u2218\u2282)\u2363((isString w)\u22272>|\u2261w))w \u235d enclose if simple character\n \u2207\n\n \u2207 da\u2190args defaultArgs defaultvalues\n :Access public shared\n da\u2190da,(\u2374,da\u2190eis args)\u2193defaultvalues\n \u2207\n\n \u2207 r\u2190Quote a;b\n :Access public shared\n b\u21901\u2193<\u233f\u00af1 0\u233d'\\\"'\u2218.=';',a \u235d keep \\\" as is\n (b\/a)\u2190\u2282'"'\n r\u21901\u233d'\"\"',\u220aa\n \u2207\n\n \u2207 r\u2190attr ParseArgs args\n :Access public\n :If ~0\u220a\u2374r\u2190args\n :If isClass\u2283args\n r\u2190\u2395NEW\u2218{2<\u2374,\u2375:(\u2283\u2375)({eis \u2375}(1\u2193\u2375)) \u22c4 \u2375}args\n :If 0\u2260\u2395NC\u2282'_PageRef'\n r._PageRef\u2190_PageRef\n :EndIf\n :If ~0\u220a\u2374attr\n r.SetAttr attr\n :EndIf\n :Else \u235dIf isInstance\u2283args\n r\u2190args\n :EndIf\n :EndIf\n \u2207\n\n \u2207 {r}\u2190Push args;c;cl;attr;elm\n :Access public\n :If ~0\u220a\u2374r\u2190args\n (cl attr)\u2190{2\u2191\u2375,(\u2374\u2375)\u2193'' ''}eis args\n c\u2190Content\n :If isClass cl\n elm\u2190\u2395NEW cl\n elm.Content\u2190c\n :If ~0\u220a\u2374attr\n elm.SetAttr attr\n :EndIf\n r\u2190Content\u2190elm\n :ElseIf 0\u220a\u2374attr\n r\u2190Content,\u2368\u2190\u2282cl\n :Else\n 'Invalid Push arguments'\u2395SIGNAL 11\n :EndIf\n :EndIf\n \u2207\n\n \u2207 {r}\u2190{attr}Add args;cl\n \u235d add \"something\" to the Content\n \u235d args can be an instance, a class, or just html\/text\n :Access public\n r\u2190''\n :If ~0\u220a\u2374\u220aargs\n :If 0=\u2395NC'attr' \u22c4 attr\u2190'' \u22c4 :EndIf\n r\u2190attr ParseArgs args\n :Trap 4 5 \u235d rank and length error\n Content,\u2190r\n :Else\n Content,\u2190\u2282r\n :EndTrap\n :EndIf\n \u2207\n\n \u2207 {r}\u2190{attr}New args;cl\n \u235d create a new instance\n \u235d args can be an instance, a class, or just html\/text\n :Access public shared\n r\u2190''\n :If ~0\u220a\u2374\u220aargs\n :If 0=\u2395NC'attr' \u22c4 attr\u2190'' \u22c4 :EndIf\n r\u2190attr ParseArgs args\n :EndIf\n \u2207\n\n \u2207 {r}\u2190{attr}Insert args;cl\n \u235d add \"something\" to the beginning of Content\n \u235d args can be an instance, a class, or just html\/text\n :Access public\n r\u2190''\n :If ~0\u220a\u2374\u220aargs\n :If 0=\u2395NC'attr' \u22c4 attr\u2190'' \u22c4 :EndIf\n r\u2190attr ParseArgs args\n :Trap 4 5 \u235d rank and length error\n Content,\u2368\u2190r\n :Else\n Content,\u2368\u2190\u2282r\n :EndTrap\n :EndIf\n \u2207\n\n \u2207 {r}\u2190Last\n :Access public\n r\u2190\u2283\u233dContent\n \u2207\n\n \u2207 r\u2190isClass ao\n :Access public shared\n r\u21909.4\u220a\u2395NC\u2282'ao'\n \u2207\n\n \u2207 r\u2190isInstance ao\n :Access public shared\n r\u21909.2\u220a\u2395NC\u2282'ao'\n \u2207\n\n \u2207 r\u2190isRef obj\n :Access public shared\n r\u21909\u220a\u2395NC'obj'\n \u2207\n\n isattr\u2190{isString \u2375:1 \u22c4 isRef \u2375:0 \u22c4 \u2227\/\u2207\u00a8\u2375}\n\n \u2207 r\u2190isAttr obj\n :Access public shared\n r\u2190isattr obj\n \u2207\n\n \u2207 r\u2190renderIt It\n :Access public shared\n r\u2190{326=\u2395DR\u2283\u2375:{isInstance\u2283\u2375:(\u2283\u2375).Render\n isClass\u2283\u2375:(\u2395NEW(\u2283\u2375)((\u2283\u2363(2=\u2283\u2374\u2375))1\u2193\u2375)).Render\n ,\u2355\u2375}\u2375 \u22c4 ,\u2355\u2375}It\n \u2207\n\n \u2207 r\u2190isHtmlElement ao\n :Access public shared\n :Trap r\u21900\n r\u2190\u2283\u2228\/#.HtmlElement=\u2395CLASS ao\n :EndTrap\n \u2207\n\n \u2207 r\u2190Parse string;b;s\n \u235d Separate each section of name=\"...\"\n :Access public\n string\u2190(b\u23721\u233db\u2190' '=s)\/s\u2190' ',string\n b\u2190(' '=string)>\u2260\\'\"'=string\n r\u21901\u2193\u00a8b\u2282string \u235d each pair\n s\u2190r\u2373\u00a8'=' \u235d each is separated by =\n r\u2190s{(\u00af1\u2193\u237a\u2191\u2375)(1\u2193\u00af1\u2193\u237a\u2193\u2375)}\u00a8r\n \u2207\n\n \u2207 r\u2190GenId\n :Access public shared\n r\u2190'id',\u2355rand \u00af1+2*31\n \u2207\n\n \u2207 {myid}\u2190SetId\n :Access public\n :If UNDEF\u2261myid\u2190id\n :If ''\u2261myid\u2190\u2283Attrs[\u2282'id']\n id\u2190myid\u2190GenId\n :Else\n id\u2190myid\n :EndIf\n :EndIf\n \u2207\n\n dtlb\u2190{\u2375{((\u2228\\\u2375)\u2227\u233d\u2228\\\u233d\u2375)\/\u237a}' '\u2260\u2375}\n\n \u2207 r\u2190ScriptFollows\n :Access public shared\n r\u2190\u220a(\u2395UCS 13 10)\u2218,\u00a8{\u2375\/\u2368'\u235d'\u2260\u2283\u00a8\u2375}{1\u2193\u00a8\u2375\/\u2368\u2227\\'\u235d'=\u2283\u00a8\u2375}{\u2375{((\u2228\\\u2375)\u2227\u233d\u2228\\\u233d\u2375)\/\u237a}' '\u2260\u2375}\u00a8(1+2\u2283\u2395LC)\u2193\u2193(\u2283\u2283\u2395CLASS 1\u2283\u2395RSI).(180\u2336)2\u2283\u2395SI\n \u2207\n\n \u2207 r\u2190WrapFollowing tag;text;SplitOnSpaceLines;Trim;FirstCommentBlock\n :Access public shared\n \n \u235d USAGE:\n \u235d\n \u235d Add WrapFollowing 'p class=\"bodytext\"'\n \u235d \u235d paragraph may span\n \u235d \u235d several lines\n \u235d \u235d\n \u235d \u235d they are separated by empty comment lines\n \u235d\n \u235d RESULT:\n \u235d\n \u235d

paragraph may span several lines<\/p>\n \u235d

they are separated by empty comment lines<\/p>\n \u235d\n \n Trim\u2190{(\u2228\\' '\u2260\u2375)\/\u2375}\u00a8\n FirstCommentBlock\u2190{1\u2193\u00a8\u2375\/\u2368\u2227\\'\u235d'=\u2283\u00a8\u2375}\n SplitOnSpaceLines\u2190{1\u2193\u00a8\u2375\u2282\u2368\u2375\u2227.=\u00a8' '}\n text\u2190(1+2\u2283\u2395LC)\u2193\u2193(\u2283\u2283\u2395CLASS 1\u2283\u2395RSI).(180\u2336)2\u2283\u2395SI\n \n r\u2190tag\u2218#.HTMLUtils.Enclose\u00a8\u220a\u00a8SplitOnSpaceLines' ',\u00a8\u2368' ',\u233d\u00a8Trim\u233d\u00a8FirstCommentBlock Trim text\n \u2207\n\n \u2207 r\u2190what Subst text;names;gv;i;repl;fixL;fixR\n :Access public shared\n r\u2190text\n fixL\u2190'[][{}()?*.+\\\\^$|]'\u2395R'\\\\\\0' \u235d precede regex metacharacters by \\\n fixR\u2190'&' '%' '\\\\'\u2395R'\\\\\\0' \u235d add \\ to & % \\\n :Select \u2395NC\u2282'what'\n :Case 9.1 \u235d namespace\n gv\u2190\u2352\u220a\u2374\u00a8names\u2190what.\u2395NL \u00af2 3 \u235d variables and functions only, sort so that 'foo' matches before 'fo'\n r\u2190(names[gv]\u2395R(fixR\u00a8\u2355\u00a8what\u234e\u2355names[gv]))r\n :Case 2.1 \u235d substitution pairs\n :If 2=|\u2261what \u22c4 what\u2190,\u2282what \u22c4 :EndIf\n :If 2\u2260\u2374\u2374what \u22c4 what\u2190\u2191what \u22c4 :EndIf\n what\u2190,\u00a8what\n r\u2190(fixL\u00a8what[;1])\u2395R(fixR\u00a8what[;2])\u22a2r\n :EndSelect\n \u2207\n\n :endsection\n\n:endclass \u235d HtmlElement","returncode":0,"stderr":"","license":"mit","lang":"APL"} {"commit":"52d4389064c9af7687c4a5012f72696a21e5d3a3","subject":"HTTPRequest - remove query string arguments with no name","message":"HTTPRequest - remove query string arguments with no name\n","repos":"Dyalog\/MiServer,Dyalog\/MiServer,Dyalog\/MiServer","old_file":"Core\/HTTPRequest.dyalog","new_file":"Core\/HTTPRequest.dyalog","new_contents":"\ufeff:Class HTTPRequest\n\n (\u2395IO \u2395ML)\u21901 1\n (CR LF)\u2190NL\u2190\u2395UCS 13 10\n\n\u235d Common Status Codes\n SC\u2190(200 'OK')(201 'Created')(204 'No Content')(301 'Moved Permanently')(302 'Found')(303 'See Other')(304 'Not Modified')(305 'Use Proxy')(307 'Temporary Redirect')\n SC,\u2190(400 'Bad Request')(401 'Unauthorized')(403 'Forbidden')(404 'Not Found')(405 'Method Not Allowed')(406 'Not Acceptable')(408 'Request Timeout')(409 'Conflict')\n SC,\u2190(410 'Gone')(411 'Length Required')(412 'Precondition Failed')(413 'Request Entity Too Large')(414 'Request-URI Too Long')(415 'Unsupported Media Type')\n SC,\u2190(500 'Internal Server Error')(501 'Not Implemented')(503 'Service Unavailable')\n SC\u2190\u2191SC\n\n\u235d Shared Fields\n\n :Field Public Shared DecodeBuffers\u21901 \u235d have Conga decode HTTP message buffers by default (MiServer sets this on initialization)\n :Field Public Shared Server \u235d reference back to the server\n\n\u235d Fields related to the Request\n\n :Field Public Instance Complete\u21900 \u235d do we have a complete request?\n :Field Public Instance URI\u2190'' \u235d the complete URI (page + query string)\n :Field Public Instance Headers\u21900 2\u2374\u2282'' \u235d HTTPRequest header fields (plus any supplied from HTTPTrailer event)\n :Field Public Instance Method\u2190'' \u235d HTTP method (GET, POST, PUT, etc)\n :Field Public Instance Page\u2190'' \u235d Requested URI\n :Field Public Instance Body\u2190'' \u235d body of the request\n :Field Public Instance Host\u2190'' \u235d host header field\n :Field Public Instance Filename\u2190'' \u235d upload file name\n :Field Public Instance RESTfulReq\u21900 \u235d RESTful Request (set to charvec if request is RESTful)\n :Field Public Instance Arguments\u21900 2\u2374\u2282'' \u235d arguments provided in the URI\n :Field Public Instance PeerAddr\u2190'' \u235d client IP address\n :Field Public Instance PeerCert\u21900 0\u2374\u2282'' \u235d client certificate\n :Field Public Instance Data\u21900 2\u2374\u2282'' \u235d form data\n :Field Public Instance HTTPVersion\u2190''\n :Field Public Instance Cookies\u21900 2\u2374\u2282''\n :Field Public Instance Session\u2190''\n :Field Public Instance CloseConnection\u21900\n\n\u235d Fields related to the Response\n\n :Field Public Instance Response\n\n GetFromTableCS\u2190{{0\u220a\u2374\u2375:'' \u22c4 1=\u2374\u2375:\u2283\u2375 \u22c4 \u2375}\u2375[;2]\/\u2368\u2375[;1]\u220a\u2282\u237a} \u235d Case Sensitive\n GetFromTable\u2190{(#.Strings.lc \u237a)GetFromTableCS \u2375}\n GetFromTableDefault\u2190{\u237a\u2190'' \u22c4 \u237a{0\u220a\u2374\u2375:\u237a \u22c4 \u2375}\u2375 GetFromTable \u237a\u237a} \u235d default_value (table \u2207) value\n\n ine\u2190{0\u220a\u2374\u237a:'' \u22c4 \u2375} \u235d if not empty\n inf\u2190{\u2228\/\u2375\u2377\u237a:'' \u22c4 \u2375} \u235d if not found\n begins\u2190{\u237a\u2261(\u2374\u237a)\u2191\u2375}\n split\u2190{p\u2190(\u237a\u2377\u2375)\u23731 \u22c4 ((p-\u2262\u237a)\u2191\u2375)(p\u2193\u2375)} \u235d Split \u2375 on first occurrence of \u237a\n\n \u2207 r\u2190eis w\n :Access public shared\n r\u2190{(,\u2218\u2282)\u2363((326\u220a\u2395DR \u2375)<2>|\u2261\u2375),\u2375}w \u235d Enclose if simple\n \u2207\n\n \u2207 Make args;query;cookies\n :Access Public Instance\n :Implements Constructor\n \u235d args is either:\n \u235d [1] HTTP method [2] URI [3] HTTP version [4] 2-column headers\n \u235d character vector if Conga could not parse the HTTP header or if DecodeBuffers is turned off\n\n args\u2190eis args\n :If 1=\u2262args \u235d single arg means Conga did not or could not decode\n :Trap 999\n :If DecodeBuffers \u235d this is a header that Conga failed to parse\n 1 Server.Log'Bad HTTP header received:',\u2283args \u235d may want to improve this if bad header is very long\n :EndIf\n (Method URI HTTPVersion Headers)\u2190ParseHead\u2283args\n :Else\n 1 Fail 400\n \u21920\n :EndTrap\n :Else\n (Method URI HTTPVersion Headers)\u2190args\n :EndIf\n\n Headers[;1]\u2190#.Strings.lc Headers[;1] \u235d header names are case insensitive\n Headers\u2190CombineHeaders Headers \u235d combine any multiple header entries\n Method\u2190#.Strings.lc Method\n\n Response\u2190\u2395NS''\n Response.(Status StatusText Headers File HTML HTMLHead PeerAddr NoWrap Bytes MSec)\u2190200 'OK'(0 2\u2374\u2282'')0 '' '' '' 0(0 0)(\u2395AI[3])\n\n Host\u2190GetHeader'host'\n Page query\u2190'?'split URI\n Page\u2190PercentDecode Page\n\n :If '\/'\u2260\u2283Page \u235d!!! need to update this to deal with absolute URI's, see https:\/\/tools.ietf.org\/html\/rfc7230#section-5.3.2\n 1 Fail 400\n \u21920\n :EndIf\n\n Arguments\u2190URLDecodeArgs query\n\n :If ~0\u220a\u2374cookies\u2190GetHeader'cookie'\n cookies\u2190CookieSplit cookies\n :If ~0\u220a\u2374cookies\u2190(2=\u2283\u2218\u2374\u00a8cookies)\/cookies\n Cookies\u2190\u2191{(' '~\u23681\u2283\u2375)(2\u2283\u2375)}\u00a8cookies\n :EndIf\n :EndIf\n :If 'get'\u2261Method\n :OrIf \u2227\/0\u2218\u220a\u2218\u2374\u00a8GetHeader\u00a8'content-length' 'transfer-encoding'\n FinalizeRequest\n :EndIf\n \u2207\n\n \u2207 (method uri version headers)\u2190ParseHead head;start;ind;header;t\n \u235d manually parse HTTP head\n (start header)\u21901(\u2191{\u237a \u2375}\u2193)(\u2282'')~\u2368{2\u2193\u00a8\u2375\u2282\u2368NL\u2377\u2375}NL,head \u235d split start line from headers\n \u2395SIGNAL 999\/\u23683\u2260\u2262t\u2190start\u2286\u2368' '\u2260start\u2190\u220astart \u235d start line should be method uri httpversion\n (method uri version)\u2190t\n \u2395SIGNAL 999\/\u2368~\u2227\/':'\u220a\u00a8header \u235d a valid header must have a ':'\n headers\u2190\u2191{dltb\u00a8':'split \u2375}\u00a8header\n \u2207\n\n \u2207 ProcessBody args\n :Access public\n Body\u2190args\n FinalizeRequest\n \u2207\n\n \u2207 ProcessChunk args;len;chunk\n :Access public\n \u235d args is either\n \u235d [1] chunk content [2] chunk-extension name\/value pairs (which we don't expect and won't process)\n \u235d or a character vector if either DecodeBuffers=0 or Conga failed to parse the chunk\n :If DecodeBuffers=1=\u2261,args \u235d if we're Decoding buffers, we expect a nested arg, if not, we expect a simple vector\n 1 Fail 400\n \u21920\n :EndIf\n\n :If DecodeBuffers\n Body,\u21901\u2283args\n :Else\n :Trap 0\n (len chunk)\u2190NL split args\n Body,\u2190(hex len)\u2191chunk\n :Else\n 1 Fail 400\n :EndTrap\n :EndIf\n \u2207\n\n \u2207 ProcessTrailer args;inds;mask;len;trailer;forbidden\n :Access public\n \u235d args is either\n \u235d 2-column matrix of\n \u235d or a character vector if either DecodeBuffers=0 or Conga failed to parse the chunk\n :If 1=\u2262\u2374args\n (len trailer)\u2190NL split args\n :If len\u2262,'0'\n 1 Fail 400\n \u21920\n :EndIf\n args\u21900 2\u2374\u2282''\n :If ~0\u220a\u2374trailer\n args\u2190\u2191{dltb\u00a8':'split \u2375}\u00a8(\u2282'')~\u2368{2\u2193\u00a8\u2375\u2282\u2368NL\u2377\u2375}NL,trailer\n :EndIf\n :EndIf\n :If ~0\u220a\u2374args\n args[;1]\u2190#.Strings.lc args[;1]\n \u235d The following is an attempt to comply with https:\/\/tools.ietf.org\/html\/rfc7230#section-4.1.2\n \u235d However, there doesn't seem to be a definitive list of the forbidden trailer fields, so, we do our best...\n forbidden\u2190'age' 'authorization' 'cache-control' 'content-encoding' 'content-length' 'content-range' 'content-type' 'date' 'expect' 'expires' 'host' 'location' 'max-forwards' 'pragma' 'proxy-authenticate' 'proxy-authorization' 'range' 'retry-after' 'set-cookie' 'te' 'trailer' 'transfer-encoding' 'vary' 'warning' 'www-authenticate'\n args\u233f\u2190~args[;1]\u220aforbidden\n mask\u2190(\u2262Headers)\u2265inds\u2190Headers[;1]\u2373args[;1]\n Headers[mask\/inds;2]\u2190mask\/args[;2]\n Headers\u236a\u2190(~mask)\u233fargs\n :EndIf\n FinalizeRequest\n \u2207\n\n \u2207 FinalizeRequest;contentType;boundary;mask;new;s\n :If ~0\u220a\u2374contentType\u2190GetHeader'content-type'\n :AndIf 'multipart\/form-data'begins contentType\n boundary\u2190'--',(8+('boundary='\u2377contentType)\u23731)\u2193contentType \u235d boundary string\n Data\u2190\u2191DecodeMultiPart\u00a8\u00af1\u2193boundary{(\u2374\u237a)\u2193\u00a8(\u237a\u2377\u2375)\u2282\u2375}Body \u235d \u00af1\u2193 because last boundary has '--' appended\n :ElseIf 'application\/x-www-form-urlencoded'begins contentType\n Data\u2190URLDecodeArgs Body\n :EndIf\n :If \u2228\/mask\u2190Data[;1]#.Strings.beginsWith\u00a8\u2282'_serialized_' \u235d do we have any serialized form data from AJAX?\n new\u21900 2\u2374\u2282''\n :For s :In mask\/Data[;2]\n new\u236a\u2190URLDecodeArgs s\n :EndFor\n Data\u2190((~(\u2283\u2374Data)\u2191mask)\u233fData)\u236anew\n Data\u2190{0 1\u220a\u2368\u2283\u2374\u2375:\u2283\u2375 \u22c4 \u2375}\u00a8\u2283{\u237a \u2375}\u2338\/\u2193[1]Data\n :EndIf\n\n :If \u2228\/mask\u2190Data[;1]#.Strings.beginsWith\u00a8\u2282'_json_' \u235d do we have any Syncfusion model data?\n :For s :In mask\/\u2373\u2374mask\n Data[s;1]\u2193\u2368\u21906\n Data[s;2]\u2190eis #.JSON.toAPL\u2283Data[s;2]\n :EndFor\n :EndIf\n Complete\u21901\n CloseConnection\u2190'close'\u2261GetHeader'connection'\n \u2207\n\n \u2207 headers\u2190CombineHeaders headers;inds;hdrs;hdr;i\n :Access public shared\n \u235d combines any headers that may occur more than once\n :If ~0\u220a\u2374inds\u2190\u23781<\u2262\u00a82\u2337[2]hdrs\u2190{\u237a \u2375}\u2338headers[;1]\n :For (hdr i) :In \u2193hdrs[inds;]\n headers[\u2283i;2]\u2190\u2282\u00af1\u2193\u220aheaders[i;2],\u00a8',;'[1+'cookie'\u2261\u220ahdr]\n :EndFor\n headers\u2190headers[\u2283\u00a8hdrs[;2];]\n :EndIf\n \u2207\n\n\n \u2207 Wipe\n :Access public\n \u235d clear out all request data\n URI\u2190''\n Headers\u2190''\n Method\u2190''\n Page\u2190''\n Filename\u2190''\n RESTfulReq\u21900\n Arguments\u2190''\n PeerAddr\u2190''\n PeerCert\u2190\u236c\n Data\u2190\u236c\n Cookies\u2190''\n Session\u2190''\n Response\u2190\u2395NS''\n \u2207\n\n\n :Section Argument and Data Handling\n\n \u2207 r\u2190PercentDecode r;rgx;rgxu;i;j;z;t;m;\u2395IO;lens;fill\n :Access public shared\n \u235d Decode a Percent Encoded string https:\/\/en.wikipedia.org\/wiki\/Percent-encoding\n \u2395IO\u21900\n ((r='+')\/r)\u2190' '\n rgx\u2190'[0-9a-fA-F]'\n rgxu\u2190'%[uU]',(4\u00d7\u2374rgx)\u2374rgx \u235d 4 characters\n r\u2190(rgxu \u2395R{{\u2395UCS 16\u22a5\u234916|'0123456789ABCDEF0123456789abcdef'\u2373\u2375}2\u2193\u2375.Match})r\n :If 0\u2260\u2374i\u2190(r='%')\/\u2373\u2374r\n :AndIf 0\u2260\u2374i\u2190(i\u2264\u00af2+\u2374r)\/i\n z\u2190r[j\u2190i\u2218.+1 2]\n t\u2190'UTF-8'\u2395UCS 16\u22a5\u234916|'0123456789ABCDEF0123456789abcdef'\u2373z\n lens\u2190\u2283\u2218\u2374\u00a8'UTF-8'\u2218\u2395UCS\u00a8t \u235d UTF-8 is variable length encoding\n fill\u2190i[\u00af1\u2193+\\0,lens]\n r[fill]\u2190t\n m\u2190(\u2374r)\u23741 \u22c4 m[(,j),i~fill]\u21900\n r\u2190m\/r\n :EndIf\n \u2207\n\n \u2207 r\u2190GetArgument name\n :Access Public Instance\n r\u2190name GetFromTable Arguments\n \u2207\n\n \u2207 r\u2190GetData name\n :Access Public Instance\n r\u2190name GetFromTableCS Data\n \u2207\n\n \u2207 r\u2190GetHeader name\n :Access Public Instance\n r\u2190(#.Strings.lc name)GetFromTable Headers\n \u2207\n\n \u2207 r\u2190{cs}URLDecodeArgs args\n :Access Public Shared\n \u235d Decode arguments passed in the URI\n cs\u2190{6::\u2375 \u22c4 cs}1 \u235d default to case sensitive\n r\u2190(args\u2228.\u2260' ')\u233f\u2191'='\u2218split\u00a8{1\u2193\u00a8(\u2375='&')\u2282\u2375}'&',args \u235d Cut on '&'\n r[;1]\u2190{\u2375\u2193\u2368\u00af6\u00d7'%5B%5D'\u2261\u00af6\u2191\u2375}\u00a8r[;1] \u235d remove [] from array args\n r[;2]\u2190PercentDecode\u00a8r[;2]\n :If ~cs \u22c4 r[;1]\u2190#.Strings.lc\u00a8r[;1] \u22c4 :EndIf\n r\u233f\u2368\u21900<\u2262\u00a8r[;1]\n \u2207\n\n \u2207 r\u2190URLEncode data;\u2395IO;z;ok;nul;m\n :Access Public Shared\n nul\u2190\u2395UCS \u2395IO\u21900\n ok\u2190nul,\u220a\u2395UCS\u00a8(\u2395UCS'aA0')+\u2373\u00a826 26 10\n\n z\u2190\u2395UCS'UTF-8'\u2395UCS\u220anul,\u00a8,data\n :If \u2228\/m\u2190~z\u220aok\n (m\/z)\u2190\u2193'%',(\u2395D,\u2395A)[\u234916 16\u22a4\u2395UCS m\/z]\n data\u2190(\u2374data)\u23741\u2193\u00a8{(\u2375=nul)\u2282\u2375}\u220az\n :EndIf\n\n r\u2190\u00af1\u2193\u220adata,\u00a8(\u2374data)\u2374'=&'\n \u2207\n\n \u2207 r\u2190DecodeHeader buf;len;d;i\n \u235d Decode HTML Header\n :Access public shared\n len\u2190(\u00af1+\u2374NL,NL)+\u2283{((NL,NL)\u2377\u2375)\/\u2373\u2374\u2375}buf\n :If len>0\n d\u2190(\u2374NL)\u2193\u00a8{(NL\u2377\u2375)\u2282\u2375}NL,len\u2191buf\n d\u2190\u2191{((p-1)\u2191\u2375)({(' '=1\u2191\u2375)\u2193\u2375}(p\u2190\u2375\u2373':')\u2193\u2375)}\u00a8d\n d[i;1]\u2190#.Strings.lc\u00a8d[i\u21901\u2193\u23731\u2191\u2374d;1]\n :Else\n d\u2190\u236c\n :EndIf\n r\u2190len d\n \u2207\n\n \u2207 r\u2190DecodeMultiPart data;ind;hdr;d;name;filename;i;upload\n hdr\u2190data\u2191\u2368ind\u21901+1\u2373\u2368(NL,NL)\u2377data\n d\u2190#.Strings.dlb'Content-Disposition:'GetParam hdr\n\n name\u2190filename\u2190''\n :If (\u2374d)\u2265i\u21905+('name=\"'\u2377d)\u23731\n name\u2190(\u00af1+name\u2373'\"')\u2191name\u2190i\u2193d\n :EndIf\n\n :If upload\u2190(\u2374d)\u2265i\u21909+('filename=\"'\u2377d)\u23731\n filename\u2190(\u00af1+filename\u2373'\"')\u2191filename\u2190i\u2193d\n :EndIf\n\n data\u2190(2+ind)\u2193data \u235d Drop up to 1st doubleCR\n data\u2190(\u00af1+\u00af1\u2191{\u2375\/\u2373\u2374\u2375}NL\u2377data)\u2191data \u235d Drop from last CR\n\n :If upload>0\u220a\u2374filename\n r\u2190name(filename data)\n :Else\n r\u2190name('UTF-8'\u2395UCS \u2395UCS data)\n :EndIf\n \u2207\n\n \u2207 r\u2190header GetValue(name type);i;h\n \u235d Extract value from HTTP Header structure returned by DecodeHeader\n\n :If (1\u2191\u2374header)'\n Response.Headers\u236a\u2190'content-type' 'text\/html; charset=utf-8'\n :EndIf\n :Leave\n :EndIf\n :EndFor\n :If ~gotFile\n Response.HTML,\u2368\u2190'Request for \"',URI,'\" Failed: ',\u2355Response.(Status StatusText)\n Response.Headers\u236a\u2190'content-type' 'text\/html; charset=utf-8'\n :EndIf\n :EndIf\n Complete\u2190CloseConnection\u21901\n \u2207\n\n \u2207 {code}Redirect location\n :Access public\n :If 0=\u2395NC'code' \u22c4 code\u2190301 \u22c4 :EndIf \u235d default to permanent redirection\n Response.(Status StatusText)\u2190code((SC[;1]\u2373code)\u2283SC[;2],\u2282'')\n 'Location'SetHeader location\n \u2207\n\n\n \u2207 r\u2190isDesktop;cis;desktop;mobile;bot;user_agent \u235d Detect if we think this is a desktop platform\n\u235d Rationale: mobile device detection is a messy subject, therefore it's easier and perhaps safer to detect\n\u235d desktop platforms (or bots) and assume that anything else is a mobile platform\n\n :Access public instance\n cis\u2190{~0\u220a\u2374(\u237a \u2395S 0 \u2395OPT'IC' 1)\u2375} \u235d Case Insensitive Search\n\n r\u21900\n\n\u235d Some mobile browsers which look like desktop browsers.\n mobile\u2190'(iphone|ipod|ipad|blackberry|android|palm|windows\\s+ce)'\n desktop\u2190'(windows|linux|os\\s+[x9]|solaris|bsd)'\n bot\u2190'(spider|crawl|slurp|bot)'\n\n \u21920\u2374\u23680\u220a\u2374user_agent\u2190GetUserAgent\n \u21920\u2374\u2368mobile cis user_agent \u235d Anything that looks like a phone isn't a desktop.\n \u21920\u2374\u2368r\u2190desktop cis user_agent \u235d Anything that looks like a desktop probably is.\n r\u2190bot cis user_agent \u235d Anything that looks like a bot should default to desktop.\n \u2207\n\n \u2207 r\u2190GetUserAgent\n :Access public instance\n \u235d Some mobile browsers put the User-Agent in a HTTP-X header\n \u21920\u2193\u23680\u220a\u2374r\u2190GetHeader'X-OPERAMINI-PHONE-UA'\n \u21920\u2193\u23680\u220a\u2374r\u2190GetHeader'X-SKYFIRE-PHONE'\n r\u2190GetHeader'USER-AGENT'\n \u2207\n\n \u2207 r\u2190isAPLJax\n :Access public instance\n r\u2190'true'\u2261GetHeader'isAPLJax'\n \u2207\n\n \u2207 r\u2190isPost\n :Access public instance\n r\u2190Method\u2261'post'\n \u2207\n\n \u2207 r\u2190isGet\n :Access public instance\n r\u2190Method\u2261'get'\n \u2207\n\n \u2207 r\u2190JSPlugIn file;root \u235d Retrieve a JavaScript PlugIn\n :Access Public Instance\n root\u2190{(1-\u230a\/'\/\\'\u2373\u2368\u233d\u2375)\u2193\u2375}\u2395WSID\n r\u2190#.Files.ReadText root,'PlugIns\\',file\n \u2207\n\n \u2207 Meta attrs \u235d add a meta tag to the head element\n :Access public instance\n Response.HTMLHead,\u2190''\n \u2207\n\n \u2207 {hdrs}Return x;type\n :Access Public Instance\n\n :If 2=\u2374\u2374x \u22c4 :AndIf 2=\u00af1\u2191\u2374x \u22c4 x\u2190URLEncode x \u22c4 type\u2190'text\/plain' \u235d 2-column matrix is name\/value pairs\n :Else \u22c4 type\u2190'text\/html'\n :EndIf\n Response.HTML\u2190\u220ax\n :If 2=\u2395NC'hdrs'\n Response.Headers\u236a\u2190hdrs\n :ElseIf ~\u2228\/Response.Headers[;1](\u2261#.Strings.nocase)\u00a8\u2282'content-type'\n Response.Headers\u236a\u2190'content-type'(type,'; charset=utf-8') \u235d set content-type if not already set\n :EndIf\n \u2207\n\n \u2207 {hdrs}ReturnFile filename\n \u235d Queues a file to be returned to client\n \u235d filename - physical name of the file\n \u235d {hdrs} - optional 2-column header name\/value pairs\n \u235d if hdrs is not supplied, we attempt to set the content type of file response based on the file extension\n :Access Public Instance\n :If #.Files.Exists filename\n Response.(HTML File)\u2190filename 1\n :If 2=\u2395NC'hdrs'\n Response.Headers\u236a\u2190hdrs\n :Else\n SetContentType filename\n :EndIf\n :Else\n Fail 404 \u235d file not found\n :EndIf\n \u2207\n\n \u2207 SetContentType x;ct\n :Access public instance\n \u235d Sets response content-type header\n \u235d x is either a file name or extension (if it contains a period), in which case we attempt to look up the appropriate content-type\n \u235d or the actual setting for content-type\n :If '.'\u220ax \u235d contains file extension?\n ct\u2190'application\/binary'(Server.Config.ContentTypes GetFromTableDefault)#.Strings.lc{(1-(\u233d\u2375)\u2373'.')\u2191\u2375}x \u235d attempt to look it up\n :Else\n ct\u2190x\n :EndIf\n 'content-type'SetHeader ct\n \u2207\n\n \u2207 {hdr}SetHeaderIfNotSet value;val;mask\n :Access public instance\n \u235d accepts value in forms\n \u235d ('hdr1' 'val1')[('hdr2' 'val2')]\n \u235d 'hdr1:val1' ['hdr2:val2']\n \u235d 'hdr1' 'val1' ['hdr2' 'val2']\n :If 0=\u2395NC'hdr'\n :If 3\u2261|\u2261value \u235d pairs of strings\n val\u2190\u2191value\n :ElseIf 2\u2261|\u2261value\n :If \u2227\/':'\u220a\u00a8value\n val\u2190\u2191':'split\u00a8value\n :Else\n val\u2190((0.5\u00d7\u2374value),2)\u2374value\n :EndIf\n :Else\n val\u21901 2\u2374':'split value\n :EndIf\n :Else\n (hdr value)\u2190eis\u00a8hdr value\n val\u2190hdr,\u236avalue\n :EndIf\n :If \u2228\/mask\u2190~hdr(\u220a#.Strings.nocase)Response.Headers[;1]\n Response.Headers\u236a\u2190mask\u233fval\n :EndIf\n \u2207\n\n \u2207 {hdr}SetHeader value;val;mask\n :Access public instance\n \u235d accepts value in forms\n \u235d ('hdr1' 'val1')[('hdr2' 'val2')]\n \u235d 'hdr1:val1' ['hdr2:val2']\n \u235d 'hdr1' 'val1' ['hdr2' 'val2']\n :If 0=\u2395NC'hdr'\n :If 3\u2261|\u2261value \u235d pairs of strings\n val\u2190\u2191value\n :ElseIf 2\u2261|\u2261value\n :If \u2227\/':'\u220a\u00a8value\n val\u2190\u2191':'split\u00a8value\n :Else\n val\u2190((0.5\u00d7\u2374value),2)\u2374value\n :EndIf\n :Else\n val\u21901 2\u2374':'split value\n :EndIf\n :Else\n (hdr value)\u2190eis\u00a8hdr value\n val\u2190hdr,\u236avalue\n :EndIf\n Response.Headers\u236a\u2190val\n \u2207\n\n \u2207 {tags}Script x\n :Access Public Instance\n :If 0=\u2395NC'tags' \u22c4 tags\u2190'type=\"text\/javascript\"'\n :ElseIf ~\u2228\/'type='\u2377tags \u22c4 tags,\u2190' type=\"text\/javascript\"'\n :EndIf\n Response.HTMLHead,\u2190Response.HTMLHead inf'