EncodeDecode.dcl 2.34 KB
Newer Older
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
1
2
3
4
5
6
7
definition module EncodeDecode

// provides the encoding and decoding of information between browser and the executable
// (c) 2005 - MJP

import StdMaybe
import GenParse, GenPrint
8
import htmlFormData
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
9
10
11
12
13
14

:: HtmlState  		:== (!Formid,!Lifespan,!StorageFormat,!SerializedState)
:: Formid			:== String		// uniquely named !
:: SerializedState 	:== String 		// not encoded !

:: ServerKind
15
16
17
	= External						// An external Server has call to this executable (currently via a PhP script)
	| JustTesting					// No Server attached at all, intended for testing (in collaboration with Gast)
	| Internal						// No external server needed: a Clean Server is atached to this executable
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
18

19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Triplet handling

:: Triplet			:== (String,Int,UpdValue)
:: TripletUpdate	:== (Triplet,String)
:: Triplets			:== [TripletUpdate]

:: UpdValue 													// the updates that can take place	
	= UpdI Int													// new integer value
	| UpdR Real													// new real value
	| UpdB Bool													// new boolean value
	| UpdC String												// choose indicated constructor 
	| UpdS String												// new piece of text

encodeTriplet		:: !Triplet -> String						// encoding of triplets
33
34
35
encodeString 		:: !String  -> String						// encoding of string 
urlEncode 			:: !String ->  String
urlDecode 			:: !String -> *String
36
37
38

// Form submission handling

39
40
41
callClean 					:: !(Script -> ElementEvents) !Mode !String -> [ElementEvents]
submitscript 				::  BodyTag
globalstateform 			:: !Value -> BodyTag
42

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
43
44
45
// serializing, de-serializing of iData states to strings stored in the html page

EncodeHtmlStates 			:: ![HtmlState] -> String
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
46
DecodeHtmlStatesAndUpdate 	:: !ServerKind (Maybe [(String, String)]) -> (![HtmlState],!Triplets) // hidden state stored in Client + triplets
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
47
48
49

// serializing, de-serializing of iData state stored in files

50
51
writeState		 			:: !String !String !String !*NWorld -> *NWorld 
readState				 	:: !String !String !*NWorld -> (!String,!*NWorld) 
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
52
53
54

// constants that maybe useful

55
56
57
ThisExe						:: !ServerKind -> String			// name of this executable
MyPhP 						:: !ServerKind -> String			// name of php script interface between server and this executable
MyDir 						:: !ServerKind -> String			// name of directory in which persistent form info is stored
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
58

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
59
traceHtmlInput				:: !ServerKind !(Maybe [(String, String)]) -> BodyTag					// for debugging showing the information received from browser
60