Minnow

Check-in [38fdf0cdec]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Better debugging update
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:38fdf0cdec1c6636d69320024d479c994cd21023
User & Date: jim 2012-01-29 22:28:54
Context
2012-02-11
11:42
Update and edit documentation check-in: 632b3461a2 user: jim tags: trunk
2012-01-29
22:28
Better debugging update check-in: 38fdf0cdec user: jim tags: trunk
16:23
Initial Web version check-in: 9fcc7495af user: jim tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Minnow.xcodeproj/project.xcworkspace/xcuserdata/jim.xcuserdatad/UserInterfaceState.xcuserstate.

cannot compute difference between binary files

Changes to Minnow.xcodeproj/xcuserdata/jim.xcuserdatad/xcschemes/Firenet.xcscheme.

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
            BlueprintName = "Minnow"
            ReferencedContainer = "container:Minnow.xcodeproj">
         </BuildableReference>
      </BuildableProductRunnable>
      <CommandLineArguments>
         <CommandLineArgument
            argument = "-c ../../Site/rest/main.lua -http ../../Site/Site -rest ../../Site/rest -port 8081"
            isEnabled = "NO">
         </CommandLineArgument>
         <CommandLineArgument
            argument = "-c ../../Site_Simple/main.lua -http ../../Site_Simple -port 8081"
            isEnabled = "YES">
         </CommandLineArgument>
      </CommandLineArguments>
      <AdditionalOptions>
      </AdditionalOptions>
   </LaunchAction>
   <ProfileAction
      shouldUseLaunchSchemeArgsEnv = "YES"







|



|







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
            BlueprintName = "Minnow"
            ReferencedContainer = "container:Minnow.xcodeproj">
         </BuildableReference>
      </BuildableProductRunnable>
      <CommandLineArguments>
         <CommandLineArgument
            argument = "-c ../../Site/rest/main.lua -http ../../Site/Site -rest ../../Site/rest -port 8081"
            isEnabled = "YES">
         </CommandLineArgument>
         <CommandLineArgument
            argument = "-c ../../Site_Simple/main.lua -http ../../Site_Simple -port 8081"
            isEnabled = "NO">
         </CommandLineArgument>
      </CommandLineArguments>
      <AdditionalOptions>
      </AdditionalOptions>
   </LaunchAction>
   <ProfileAction
      shouldUseLaunchSchemeArgsEnv = "YES"

Changes to Site/rest/admin.lua.

27
28
29
30
31
32
33

34
35
36
37
38
39
40
--	OUTPUT:	NONE
--
------------------------------------------------------------------------------------

function admin_handler(rqst,htype,url,n,al)
	local out
	

	rest_handler(rqst,htype,url,n,admin_actions)
end

------------------------------------------------------------------------------------
--
--	stop_handler(rqst,type,url,n,al)	- Shutdown system if requested
--







>







27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
--	OUTPUT:	NONE
--
------------------------------------------------------------------------------------

function admin_handler(rqst,htype,url,n,al)
	local out
	
	print("-- Admin Actions --")
	rest_handler(rqst,htype,url,n,admin_actions)
end

------------------------------------------------------------------------------------
--
--	stop_handler(rqst,type,url,n,al)	- Shutdown system if requested
--

Changes to Site/rest/login.lua.

36
37
38
39
40
41
42

43
44
45
46
47
48
49
..
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
...
224
225
226
227
228
229
230

231
232
233
234
235
236
237
...
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
--			url		- Path of request
--			n		- Position on path to consider
--			al		- Action list
--
--	OUTPUT:	NONE
--
------------------------------------------------------------------------------------


function login_handler(rqst,htype,url,n,al)
	local out
	
	print("-- Login actions --")
	rest_handler(rqst,htype,url,n,login_actions)
end
................................................................................
	local out = {}
	local data
	local i
	
	-- Is this a GET, if so look pick random value from random list
	-- Also fail if already logged in
	

	if( htype == HTTP_GET and LOGIN_OK == nil)
	then
		-- Add some randomness to our BAD random # gen
		data = os.time() % 1000		
		math.randomseed(data)
		for i=1,data
		do
			math.random()
		end	

		data = math.random(1,16)		
		LOGIN_CHAL_PSN = data			-- Get index into random # list
		-------------------------------------------
		
		-- Build response 
		
		out.CHAL = LOGIN_CHAL_LIST[LOGIN_CHAL_PSN]
................................................................................
	else
		out.LOGIN = "UNKNOWN RQST"
	end
	
	out = json_kvp(out)
	h:close(out)			-- Return message
end
		
------------------------------------------------------------------------------------
--
--	login_status_handler(rqst,type,url,n,al)	- Status of login
--
--	INPUT:	rqst	- HTTP request
--			htype	- Type of request
--			url		- Path of request, look at last link for stop
................................................................................
	local out = {}
	local data
	
	-- Is this a POST, and are we logged in ?
	-- (circularly) in the list
	-- Also fail if already logged in
	

	if( htype == HTTP_POST and LOGIN_OK)
	then
		-- Unlock and return OK
		
		h:lock(nil)
		out.LOGOUT = "OK"
		LOGIN_OK = nil		-- Change status
................................................................................
	else
		out.LOGOUT = "UNKNOWN RQST"
	end
	
	out = json_kvp(out)
	h:close(out)			-- Return message
end


----------------------------------------------------------------
-- STRUCTURE
----------------------------------------------------------------
-- Build action list for login actions

login_actions = {}
login_actions.REQUEST = login_request_handler
login_actions.RESPONSE = login_response_handler
login_actions.STATUS = login_status_handler
login_actions.LOGOUT = login_logout_handler








>







 







>









>







 







|







 







>







 







<












36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
..
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
...
242
243
244
245
246
247
248

249
250
251
252
253
254
255
256
257
258
259
260
--			url		- Path of request
--			n		- Position on path to consider
--			al		- Action list
--
--	OUTPUT:	NONE
--
------------------------------------------------------------------------------------


function login_handler(rqst,htype,url,n,al)
	local out
	
	print("-- Login actions --")
	rest_handler(rqst,htype,url,n,login_actions)
end
................................................................................
	local out = {}
	local data
	local i
	
	-- Is this a GET, if so look pick random value from random list
	-- Also fail if already logged in
	
	print("-- In Login Request handler --")
	if( htype == HTTP_GET and LOGIN_OK == nil)
	then
		-- Add some randomness to our BAD random # gen
		data = os.time() % 1000		
		math.randomseed(data)
		for i=1,data
		do
			math.random()
		end	
		
		data = math.random(1,16)		
		LOGIN_CHAL_PSN = data			-- Get index into random # list
		-------------------------------------------
		
		-- Build response 
		
		out.CHAL = LOGIN_CHAL_LIST[LOGIN_CHAL_PSN]
................................................................................
	else
		out.LOGIN = "UNKNOWN RQST"
	end
	
	out = json_kvp(out)
	h:close(out)			-- Return message
end

------------------------------------------------------------------------------------
--
--	login_status_handler(rqst,type,url,n,al)	- Status of login
--
--	INPUT:	rqst	- HTTP request
--			htype	- Type of request
--			url		- Path of request, look at last link for stop
................................................................................
	local out = {}
	local data
	
	-- Is this a POST, and are we logged in ?
	-- (circularly) in the list
	-- Also fail if already logged in
	
	print("-- In Logout Response handler --")	
	if( htype == HTTP_POST and LOGIN_OK)
	then
		-- Unlock and return OK
		
		h:lock(nil)
		out.LOGOUT = "OK"
		LOGIN_OK = nil		-- Change status
................................................................................
	else
		out.LOGOUT = "UNKNOWN RQST"
	end
	
	out = json_kvp(out)
	h:close(out)			-- Return message
end


----------------------------------------------------------------
-- STRUCTURE
----------------------------------------------------------------
-- Build action list for login actions

login_actions = {}
login_actions.REQUEST = login_request_handler
login_actions.RESPONSE = login_response_handler
login_actions.STATUS = login_status_handler
login_actions.LOGOUT = login_logout_handler

Changes to Site/rest/main.lua.

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
_G.package.path = REST_LCN .. "/?.lua;" .. _G.package.path

-- Now all modules will load with just a simple require + name

require "rest_sup"
require "login"
require "admin"


-- Build the site structure list

site = {}
site.ADMIN = admin_handler

state = {}







<







96
97
98
99
100
101
102

103
104
105
106
107
108
109
_G.package.path = REST_LCN .. "/?.lua;" .. _G.package.path

-- Now all modules will load with just a simple require + name

require "rest_sup"
require "login"
require "admin"


-- Build the site structure list

site = {}
site.ADMIN = admin_handler

state = {}