Minnow

Check-in [0ee2537d2f]
Login

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

Overview
Comment:Allow non-REST operation [28bcb55998]
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:0ee2537d2f782847147c2d184e584313490e89fa
User & Date: jim 2012-01-29 13:36:32
References
2012-01-29
13:37 Tested ticket [28bcb55998]: Change to allow non-REST operation plus 4 other changes artifact: c3745e3c25 user: jim
Context
2012-01-29
16:23
Initial Web version check-in: 9fcc7495af user: jim tags: trunk
13:36
Allow non-REST operation [28bcb55998] check-in: 0ee2537d2f user: jim tags: trunk
10:03
Initial Commit check-in: 3be052056d user: jim tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Docs/Minnow.bib.

1
2
3
4
5
6
7
8
9
10
11











12
13
14
15
16
17
18
%% This BibTeX bibliography file was created using BibDesk.
%% http://bibdesk.sourceforge.net/


%% Created for Jim at 2012-01-28 06:26:07 -0500 


%% Saved with string encoding Western (ASCII) 














@url{AJAX,
	Author = {Wikipedia},
	Date-Added = {2012-01-28 06:24:48 -0500},
	Date-Modified = {2012-01-28 06:26:07 -0500},
	Keywords = {AJAX JSON XMLHttpRequest},
	Lastchecked = {28-Jan-2012},
	Title = {Ajax (programming)},




|






>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
%% This BibTeX bibliography file was created using BibDesk.
%% http://bibdesk.sourceforge.net/


%% Created for Jim at 2012-01-29 05:39:44 -0500 


%% Saved with string encoding Western (ASCII) 



@url{JQuery,
	Author = {JQuery},
	Date-Added = {2012-01-29 05:38:48 -0500},
	Date-Modified = {2012-01-29 05:39:44 -0500},
	Keywords = {javascriptm,JQuery},
	Lastchecked = {29-Jan-2012},
	Local-Url = {http://jquery.com/},
	Title = {JQuery},
	Url = {http://jquery.com/},
	Urldate = {29-Jan-2012}}

@url{AJAX,
	Author = {Wikipedia},
	Date-Added = {2012-01-28 06:24:48 -0500},
	Date-Modified = {2012-01-28 06:26:07 -0500},
	Keywords = {AJAX JSON XMLHttpRequest},
	Lastchecked = {28-Jan-2012},
	Title = {Ajax (programming)},

Changes to Docs/Minnow.lyx.

553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568







































































































































569
570

571
572
573
574
575
576
577
578
579






580
581
582
583
584
585
586
587
588







589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
...
621
622
623
624
625
626
627





































































































































































628
629
630
631
632
633
634

\begin_layout Standard
Now start Minnow with the command line (I'm assuming you are in the Minnow
 directory and the executable is there):
\end_layout

\begin_layout LyX-Code
./Minnow -c Site/rest/main.lua -http Site/Site -rest Site/rest -port 8080
\end_layout

\begin_layout Standard
At this point you have a web server running on your machine (i.e.
 http://localhost:8080) that you can open with your browser.
 You should get this:
\end_layout








































































































































\begin_layout Subsubsection
REST use

\end_layout

\begin_layout Standard
In the system used here we restrict ourselves to just two commands GET and
 POST.
 The HTTP get command is used to query the system for information and the
 POST command is used cause the system to do some action.
 There is a wide latitude in how RESTful commands are done, you can either
 put command parameters (in a POST) in a JSON






\begin_inset CommandInset citation
LatexCommand cite
key "JSON"

\end_inset

 encoded data block sent with the POST or encode it into the URL of the
 command.
 







\end_layout

\begin_layout Standard
\begin_inset Float figure
placement H
wide false
sideways false
status open

\begin_layout Plain Layout
\noindent
\align center
\begin_inset Graphics
	filename Images/rest_cmds.eps
	scale 30

\end_inset


\end_layout

................................................................................

\end_layout

\end_inset


\end_layout






































































































































































\begin_layout Standard
In the FIRENET system we have encoded most of the command syntax into the
 URI.
 As you can see from the base node (which is programmable see: 
\begin_inset CommandInset ref
LatexCommand vref







|




|



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

<
>



<
<
<
<
<
<
>
>
>
>
>
>


|



|
|
|
>
>
>
>
>
>
>













|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704

705
706
707
708






709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
...
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941

\begin_layout Standard
Now start Minnow with the command line (I'm assuming you are in the Minnow
 directory and the executable is there):
\end_layout

\begin_layout LyX-Code
./Minnow -c Site/rest/main.lua -http Site/Site -rest Site/rest -port 8081
\end_layout

\begin_layout Standard
At this point you have a web server running on your machine (i.e.
 http://localhost:8081) that you can open with your browser.
 You should get this:
\end_layout

\begin_layout Standard
\begin_inset Float figure
placement H
wide false
sideways false
status open

\begin_layout Plain Layout
\begin_inset Graphics
	filename Images/initial.png
	scale 30

\end_inset


\end_layout

\begin_layout Plain Layout
\begin_inset Caption

\begin_layout Plain Layout
Initial Screen
\end_layout

\end_inset


\end_layout

\begin_layout Plain Layout

\end_layout

\end_inset


\end_layout

\begin_layout Standard
You can now Login to the system by clicking on the Login control on the
 Left.
 This gets you the challenge response screen:
\end_layout

\begin_layout Standard
\begin_inset Float figure
placement H
wide false
sideways false
status open

\begin_layout Plain Layout
\begin_inset Graphics
	filename Images/challenge.png
	scale 30

\end_inset


\end_layout

\begin_layout Plain Layout
\begin_inset Caption

\begin_layout Plain Layout
Challenge/Response Screen
\end_layout

\end_inset


\end_layout

\begin_layout Plain Layout

\end_layout

\end_inset


\end_layout

\begin_layout Standard
The challenge has been made very simple, just type in the challenge value
 into the Response field and hit Submit and you will get:
\end_layout

\begin_layout Standard
\begin_inset Float figure
placement H
wide false
sideways false
status open

\begin_layout Plain Layout
\begin_inset Graphics
	filename Images/run.png
	scale 30

\end_inset


\end_layout

\begin_layout Plain Layout
\begin_inset Caption

\begin_layout Plain Layout
Run Mode
\end_layout

\end_inset


\end_layout

\begin_layout Plain Layout

\end_layout

\end_inset


\end_layout

\begin_layout Standard
At tbis point you can click on Debug or Logout.
 Logout will take you back to the initial screen while debug will let you
 issue RESTful commands and see the responses.
\end_layout

\begin_layout Subsection
Site Operation
\end_layout

\begin_layout Subsubsection

Introduction
\end_layout

\begin_layout Standard






How did all of the above work and what do you have to write to make Minnow
 do what you want on your web site ? In this case it is done with a combination
 of server and client side scripting.
 The client side code used Javascript and the server scripting is in Lua
 supported by Minnow.
 In addition the client side scripting uses JQuery
\begin_inset CommandInset citation
LatexCommand cite
key "JQuery"

\end_inset

as a support library.
\end_layout

\begin_layout Standard
The interaction that occurs is RESTful, in that the client sends in GET
 or POST requests and the server via the Lua scripts builds responses in
 JSON.
 The script in the client then parses the JSON and changes the screen in
 the appropriate fashion.
 The full set of RESTful commands is show in the figure.
\end_layout

\begin_layout Standard
\begin_inset Float figure
placement H
wide false
sideways false
status open

\begin_layout Plain Layout
\noindent
\align center
\begin_inset Graphics
	filename /Users/jschimpf/Public/Minnow/Docs/Images/rest_cmds.eps
	scale 30

\end_inset


\end_layout

................................................................................

\end_layout

\end_inset


\end_layout

\begin_layout Standard
The client would issue a command in a RESTful fashion by building a URI
 string like 
\series bold
HTTP://localhost:8081/rest/admin/login/request
\series default
 and doing a GET to the server.
 The server the returns the challenge value and the client puts that value
 on the page and waits for the user to input the response.
 When the user presses submit it sends another RESTful command with the
 response value and if that checks out, the response allows the client script
 to show the RUN page.
\end_layout

\begin_layout Subsubsection
Server Code
\end_layout

\begin_layout Standard
If you go to the Site directory in Minnow and then go to the rest folder
 in there, that is the server scripting code.
 In the command line that started the server:
\end_layout

\begin_layout LyX-Code
./Minnow 
\series bold
-c Site/rest/main.lua
\series default
 -http Site/Site -rest Site/rest -port 8081
\end_layout

\begin_layout Standard
The highlighted portion is the initial server server script this 
\series bold
main.lua
\series default
 reads the command line for the subsequent parameters and uses them to start
 the web server.
 The RESTful operation is supported by code that turns each incomming request
 URI into a Lua list.
 It's important to note that this script does not get all the requests only
 those that start with 
\series bold
http://localhost:8081/rest .
 
\series default
The non-RESTful requests, i.e.
 regular page requests are handled automatically by the libmicrohttp code.
 On receipt of a RESTful request the Lua list is passed to a routine that
 looks at the element following rest, which in 
\series bold
HTTP://localhost:8081/rest/admin/login/request 
\series default
is 
\series bold
admin.
 
\series default
A handler has been assigned to this node:
\end_layout

\begin_layout LyX-Code
-- Build the site structure list
\end_layout

\begin_layout LyX-Code
site = {}
\end_layout

\begin_layout LyX-Code
site.ADMIN = admin_handler
\end_layout

\begin_layout Standard
So that any request with 
\series bold
admin
\series default
 will be passed in this case to admin_handler.
 If you look at the file 
\series bold
admin.lua
\series default
 in Site/rest you will see at the bottom it then assigns handlers to subsequent
 parts of the admin command.
 
\end_layout

\begin_layout LyX-Code
----------------------------------------------------------------
\end_layout

\begin_layout LyX-Code
-- STRUCTURE
\end_layout

\begin_layout LyX-Code
----------------------------------------------------------------
\end_layout

\begin_layout LyX-Code
-- Build action list for admin actions
\end_layout

\begin_layout LyX-Code
admin_actions = {}
\end_layout

\begin_layout LyX-Code
admin_actions.POWER = stop_handler
\end_layout

\begin_layout LyX-Code
admin_actions.TIME = time_handler
\end_layout

\begin_layout LyX-Code
admin_actions.LOGIN = login_handler
\end_layout

\begin_layout Standard
In 
\series bold
rest_sup.lua 
\series default
there is a handler routine that is used to call the proper handler given
 the URI list and position.
 This is called at the entrance to each section of the command structure
 and automatically calls the proper handler or returns and error.
\end_layout

\begin_layout Standard
Inside each handler routine the actions are usually rather simple, at this
 point the handler has the URI list and knows what data it needs from that
 list.
 The handler builds a response as a Lua list which has elements which will
 the JSON key's in a key value JSON response.
 Filling out those fields a support routine (in Lua) can be called to convert
 a Lua list to a JSON string.
 This is then returned to the server and we are done.
\end_layout

\begin_layout Subsubsection
REST use
\end_layout

\begin_layout Standard
In the system used here we restrict ourselves to just two commands GET and
 POST.
 The HTTP get command is used to query the system for information and the
 POST command is used cause the system to do some action.
 There is a wide latitude in how RESTful commands are done, you can either
 put command parameters (in a POST) in a JSON
\begin_inset CommandInset citation
LatexCommand cite
key "JSON"

\end_inset

 encoded data block sent with the POST or encode it into the URL of the
 command.
 
\end_layout

\begin_layout Standard
In the FIRENET system we have encoded most of the command syntax into the
 URI.
 As you can see from the base node (which is programmable see: 
\begin_inset CommandInset ref
LatexCommand vref

Changes to Docs/Minnow.lyx~.

541
542
543
544
545
546
547
548

549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570







































































































































571
572

573
574
575
576
577
578
579
580
581






582
583
584
585
586
587
588
589
590







591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
...
623
624
625
626
627
628
629


























































































































































630
631
632
633
634
635
636
\begin_layout Subsubsection
Running the example
\end_layout

\begin_layout Standard
On OS X use the project to build Minnow then put the executable in your
 path or in the top level of your Minnow directory.
 In Linux use the make file to build Minnow and do the same with the executable.

 (On OS X the executable will be in build
\backslash
Release
\backslash
Minnow and in Linux the shipped build will put Minnow in the Minnow directory.
\end_layout

\begin_layout Standard
Now start Minnow with the command line (I'm assuming you are in the Minnow
 directory and the executable is there):
\end_layout

\begin_layout LyX-Code
./Minnow -c Site/rest/main.lua -http Site/Site -rest Site/rest -port 8080
\end_layout

\begin_layout Standard
At this point you have a web server running on your machine (i.e.
 localhost:8080) that you can open with your browser.
 You should get this:
\end_layout








































































































































\begin_layout Subsubsection
REST use

\end_layout

\begin_layout Standard
In the system used here we restrict ourselves to just two commands GET and
 POST.
 The HTTP get command is used to query the system for information and the
 POST command is used cause the system to do some action.
 There is a wide latitude in how RESTful commands are done, you can either
 put command parameters (in a POST) in a JSON






\begin_inset CommandInset citation
LatexCommand cite
key "JSON"

\end_inset

 encoded data block sent with the POST or encode it into the URL of the
 command.
 







\end_layout

\begin_layout Standard
\begin_inset Float figure
placement H
wide false
sideways false
status open

\begin_layout Plain Layout
\noindent
\align center
\begin_inset Graphics
	filename Images/rest_cmds.eps
	scale 30

\end_inset


\end_layout

................................................................................

\end_layout

\end_inset


\end_layout



























































































































































\begin_layout Standard
In the FIRENET system we have encoded most of the command syntax into the
 URI.
 As you can see from the base node (which is programmable see: 
\begin_inset CommandInset ref
LatexCommand vref







|
>
|
<
<
<
|








|




|



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

<
>



<
<
<
<
<
<
>
>
>
>
>
>


|



|
|
|
>
>
>
>
>
>
>













|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







541
542
543
544
545
546
547
548
549
550



551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704

705
706
707
708






709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
...
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
\begin_layout Subsubsection
Running the example
\end_layout

\begin_layout Standard
On OS X use the project to build Minnow then put the executable in your
 path or in the top level of your Minnow directory.
 In Linux use the included make file to build Minnow and do the same with
 the executable.
 (On OS X the executable will be in build/Release/Minnow and in Linux the



 shipped build will put Minnow in the Minnow directory.
\end_layout

\begin_layout Standard
Now start Minnow with the command line (I'm assuming you are in the Minnow
 directory and the executable is there):
\end_layout

\begin_layout LyX-Code
./Minnow -c Site/rest/main.lua -http Site/Site -rest Site/rest -port 8081
\end_layout

\begin_layout Standard
At this point you have a web server running on your machine (i.e.
 http://localhost:8081) that you can open with your browser.
 You should get this:
\end_layout

\begin_layout Standard
\begin_inset Float figure
placement H
wide false
sideways false
status open

\begin_layout Plain Layout
\begin_inset Graphics
	filename Images/initial.png
	scale 30

\end_inset


\end_layout

\begin_layout Plain Layout
\begin_inset Caption

\begin_layout Plain Layout
Initial Screen
\end_layout

\end_inset


\end_layout

\begin_layout Plain Layout

\end_layout

\end_inset


\end_layout

\begin_layout Standard
You can now Login to the system by clicking on the Login control on the
 Left.
 This gets you the challenge response screen:
\end_layout

\begin_layout Standard
\begin_inset Float figure
placement H
wide false
sideways false
status open

\begin_layout Plain Layout
\begin_inset Graphics
	filename Images/challenge.png
	scale 30

\end_inset


\end_layout

\begin_layout Plain Layout
\begin_inset Caption

\begin_layout Plain Layout
Challenge/Response Screen
\end_layout

\end_inset


\end_layout

\begin_layout Plain Layout

\end_layout

\end_inset


\end_layout

\begin_layout Standard
The challenge has been made very simple, just type in the challenge value
 into the Response field and hit Submit and you will get:
\end_layout

\begin_layout Standard
\begin_inset Float figure
placement H
wide false
sideways false
status open

\begin_layout Plain Layout
\begin_inset Graphics
	filename Images/run.png
	scale 30

\end_inset


\end_layout

\begin_layout Plain Layout
\begin_inset Caption

\begin_layout Plain Layout
Run Mode
\end_layout

\end_inset


\end_layout

\begin_layout Plain Layout

\end_layout

\end_inset


\end_layout

\begin_layout Standard
At tbis point you can click on Debug or Logout.
 Logout will take you back to the initial screen while debug will let you
 issue RESTful commands and see the responses.
\end_layout

\begin_layout Subsection
Site Operation
\end_layout

\begin_layout Subsubsection

Introduction
\end_layout

\begin_layout Standard






How did all of the above work and what do you have to write to make Minnow
 do what you want on your web site ? In this case it is done with a combination
 of server and client side scripting.
 The client side code used Javascript and the server scripting is in Lua
 supported by Minnow.
 In addition the client side scripting uses JQuery
\begin_inset CommandInset citation
LatexCommand cite
key "JQuery"

\end_inset

as a support library.
\end_layout

\begin_layout Standard
The interaction that occurs is RESTful, in that the client sends in GET
 or POST requests and the server via the Lua scripts builds responses in
 JSON.
 The script in the client then parses the JSON and changes the screen in
 the appropriate fashion.
 The full set of RESTful commands is show in the figure.
\end_layout

\begin_layout Standard
\begin_inset Float figure
placement H
wide false
sideways false
status open

\begin_layout Plain Layout
\noindent
\align center
\begin_inset Graphics
	filename /Users/jschimpf/Public/Minnow/Docs/Images/rest_cmds.eps
	scale 30

\end_inset


\end_layout

................................................................................

\end_layout

\end_inset


\end_layout

\begin_layout Standard
The client would issue a command in a RESTful fashion by building a URI
 string like 
\series bold
HTTP://localhost:8081/rest/admin/login/request
\series default
 and doing a GET to the server.
 The server the returns the challenge value and the client puts that value
 on the page and waits for the user to input the response.
 When the user presses submit it sends another RESTful command with the
 response value and if that checks out, the response allows the client script
 to show the RUN page.
\end_layout

\begin_layout Subsubsection
Server Code
\end_layout

\begin_layout Standard
If you go to the Site directory in Minnow and then go to the rest folder
 in there, that is the server scripting code.
 In the command line that started the server:
\end_layout

\begin_layout LyX-Code
./Minnow 
\series bold
-c Site/rest/main.lua
\series default
 -http Site/Site -rest Site/rest -port 8081
\end_layout

\begin_layout Standard
The highlighted portion is the initial server server script this 
\series bold
main.lua
\series default
 reads the command line for the subsequent parameters and uses them to start
 the web server.
 The RESTful operation is supported by code that turns each incomming request
 URI into a Lua list.
 It's important to note that this script does not get all the requests only
 those that start with 
\series bold
http://localhost:8081/rest .
 
\series default
The non-RESTful requests, i.e.
 regular page requests are handled automatically by the libmicrohttp code.
 On receipt of a RESTful request the Lua list is passed to a routine that
 looks at the element following rest, which in 
\series bold
HTTP://localhost:8081/rest/admin/login/request 
\series default
is 
\series bold
admin.
 
\series default
A handler has been assigned to this node:
\end_layout

\begin_layout LyX-Code
-- Build the site structure list
\end_layout

\begin_layout LyX-Code
site = {}
\end_layout

\begin_layout LyX-Code
site.ADMIN = admin_handler
\end_layout

\begin_layout Standard
So that any request with 
\series bold
admin
\series default
 will be passed in this case to admin_handler.
 If you look at the file 
\series bold
admin.lua
\series default
 in Site/rest you will see at the bottom it then assigns handlers to subsequent
 parts of the admin command.
 
\end_layout

\begin_layout LyX-Code
----------------------------------------------------------------
\end_layout

\begin_layout LyX-Code
-- STRUCTURE
\end_layout

\begin_layout LyX-Code
----------------------------------------------------------------
\end_layout

\begin_layout LyX-Code
-- Build action list for admin actions
\end_layout

\begin_layout LyX-Code
admin_actions = {}
\end_layout

\begin_layout LyX-Code
admin_actions.POWER = stop_handler
\end_layout

\begin_layout LyX-Code
admin_actions.TIME = time_handler
\end_layout

\begin_layout LyX-Code
admin_actions.LOGIN = login_handler
\end_layout

\begin_layout Standard
In 
\series bold
rest_sup.lua 
\series default
there is a handler routine that is used to call the proper handler given
 the URI list and position.
 This is called at the entrance to each section of the command structure
 and automatically calls the proper handler or returns and error.
\end_layout

\begin_layout Subsubsection
REST use
\end_layout

\begin_layout Standard
In the system used here we restrict ourselves to just two commands GET and
 POST.
 The HTTP get command is used to query the system for information and the
 POST command is used cause the system to do some action.
 There is a wide latitude in how RESTful commands are done, you can either
 put command parameters (in a POST) in a JSON
\begin_inset CommandInset citation
LatexCommand cite
key "JSON"

\end_inset

 encoded data block sent with the POST or encode it into the URL of the
 command.
 
\end_layout

\begin_layout Standard
In the FIRENET system we have encoded most of the command syntax into the
 URI.
 As you can see from the base node (which is programmable see: 
\begin_inset CommandInset ref
LatexCommand vref

Added Docs/Minnow.pdf.

cannot compute difference between binary files

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
            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>
      </CommandLineArguments>
      <AdditionalOptions>
      </AdditionalOptions>
   </LaunchAction>
   <ProfileAction







>
>
>
>







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
            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

Changes to Site/rest/main.lua.

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
require "admin"


-- Build the site structure list

site = {}
site.ADMIN = admin_handler
site.FIRENET = firenet_handler

state = {}
state.RUN = 1

-- Site operation

-- (1) Open channel and start HTTP







<







102
103
104
105
106
107
108

109
110
111
112
113
114
115
require "admin"


-- Build the site structure list

site = {}
site.ADMIN = admin_handler


state = {}
state.RUN = 1

-- Site operation

-- (1) Open channel and start HTTP

Added Site_Simple/index.html.













































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xthml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
	<head>
		<meta http-equiv="Content-Type" 
		content="text/html; charset=utf-8" />
		<title>Minnow</title>
		
	</head>                                                                 
 	<body>
 		<!-- HTML AREA ----------------------------- -->
 		<h1><center>Minnow Simple Test Page</center></h1>
 		
 		This is a simple test page showing that Minnow can server up simple
 		pages
 		<p>
 			<a href="otherpage.html">Other Page</a>
 		<p>
 			<a href="thirdpage.html">More Pages</a>
 		
 	</body>                                                                 
 </html>

Added Site_Simple/main.lua.









































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
95
96
97
98
99
100
------------------------------------------------------------------------------------
--
-- Simple Minnow Startup script for Non-Rest serving
--
--	29-Jan-2012	Converted to Minnow use
--
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
--                  SUPPORT FUNCTIONS
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
--
--  flag_srch( argv,flag,data )   - Find the port in the argument list
--
--  INPUT:      argv    - Program argument list
--              flag    - Look for this string (i.e. -flag) in list
--              data    - If non-nil get the field following flag slot
--
--  OUTPUT      If data = nil return nil if flag not found and 1 if found
--              If data <> nil return nil if flag not found or next field if found
--
-------------------------------------------------------------------------------

function flag_srch( argv,flag,data )
    local rtnval = nil
    
    -- Loop over the list and check each item for match
    
    for i=1,table.getn(argv) 
    do
        if( flag == argv[i] )
        then
            -- Found so two cases 
            -- (a) If data == nil then return 1
            -- (b) If data != nil then return argv[i+1]
            
            if( data == nil  )
            then
                rtnval = 1
            else
                rtnval = argv[i+1]
            end
            
            -- In either case just break out
            
            break
        end
    end
    
    return( rtnval )
end

-------------------------------------------------------------------------------
--                 MAIN PROGRAM
-------------------------------------------------------------------------------

-- Pull up items from command line
-- NOTE THESE ARE GLOBALS FOR THE REST
-- OF THE SYSTEM

HTTP_LCN = flag_srch(arg,"-http",1)
PORT_NUM = flag_srch(arg,"-port",1)

if( HTTP_LCN == nil )
then
	print("SYNTAX ERROR: -http <HTTP file lcn> NOT GIVEN")
	print("Shutting down")
	os.exit(-1)
end

if( PORT_NUM == nil )
then
	print("WARNING: Server Port # not given")
	print("Server Port = 8080")
	PORT_NUM = 8080
end

-- Site operation

-- (1) Open channel and start HTTP

val = http.start(PORT_NUM,HTTP_LCN,nil)
if( val ~= nil )
then
	-- Loop in server till shutdown
	
	while( 1 )
	do
		-- Wait for shutdown
		
		timer.sleep( 1000 );	-- Just sleep
	end
else
	print("** Failed to open HTTP Server **")
end

print("-- END RUN -- ")
	
http.stop()

Added Site_Simple/otherpage.html.





































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xthml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
	<head>
		<meta http-equiv="Content-Type" 
		content="text/html; charset=utf-8" />
		<title>Second Page</title>
		
	</head>                                                                 
 	<body>
 		<!-- HTML AREA ----------------------------- -->
 		<h1><center>Minnow Next Page</center></h1>
 		
 		This is a linked page showing how that works
 		<p>
 			<a href="index.html">Home</a>
 	</body>                                                                 
 </html>

Added Site_Simple/thirdpage.html.





































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xthml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
	<head>
		<meta http-equiv="Content-Type" 
		content="text/html; charset=utf-8" />
		<title>Third Page</title>
		
	</head>                                                                 
 	<body>
 		<!-- HTML AREA ----------------------------- -->
 		<h1><center>Minnow Third Page</center></h1>
 		
 		This is a linked page showing how that works
 		<p>
 			<a href="index.html">Home</a>
 	</body>                                                                 
 </html>

Changes to luasupport/HTTP/httplib.c.

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
..
37
38
39
40
41
42
43



44
45
46
47
48
49
50
...
201
202
203
204
205
206
207



208

209


210

211
212
213
214
215
216
217
218
219

220
221


222
223

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
	IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
	CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
	TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
	SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
//*****************************************************************************
/*
	Module Name:         HTTP interface for Firenet

	Description:        This uses libmicrohttpd to build a RESTful
						interface to Firenet.  

	Library Extensions	rest_start()			- Start HTTP interface
						rest_stop()				- Stop HTTP interface
						rest_close()			- Close current connection & return data
................................................................................
	Revision History:	
		24 Oct 2010	Initial version
		20 Nov 2010 UC both http & rest base
		16 Dec 2010	Add client lock to lock the webserver to one client
		 7-Mar-2011 Dropping POST data reader, as post data does not work...
		23-Dec-2011 [7b5a95ed75] Update to get rest  base 
					size in structure



*/
//****************************************************************************

#include <ctype.h>
#include <time.h>
#include "lauxlib.h"
#include "lua.h"
................................................................................
		
		if(  lua_isstring(L,2 ) )
		{
			ptr = (char *)luaL_checklstring(L,2,&llen);
			rsrv->http_site = (char *)MEMALLOC(llen+1);
			if( rsrv->http_site != NULL )
			{



				memcpy(rsrv->http_site,ptr,llen);

				


				// (3) Get the path to the RESTful location

				
				if(  lua_isstring(L,3 ) )
				{
					ptr = (char *)luaL_checklstring(L,3,&llen);
					rsrv->rest_base = (char *)MEMALLOC(llen+1);
					rsrv->len_rest_base = llen;
					if( rsrv->rest_base != NULL )
					{
						memcpy(rsrv->rest_base,ptr,llen);

						
						// (4) Calculate HTTP site value


						
						if( get_http_base( rsrv ) )

						{
							// (4a) UC both rest & HTTP base

							

							uppercase_it(rsrv->rest_base);
							uppercase_it(rsrv->http_base);
							

							// (5) Start server
							
							if( rest_server() == 0 )
							{
								// (6) Start client
								
								if( rest_support_open() == 0 )
								{
									dval = 1.0;
									lua_pushnumber( L,dval );	// Return true
									rtnval = 1;
								}
							}
						}
					}
				}
			}
		}
	}
	







|







 







>
>
>







 







>
>
>

>
|
>
>
|
>
|
|
|
|
|
|
|
|
|
>
|
<
>
>
|
<
>
|
<
>
|
>
|
<
|
>
|
|
|
|
|
|
|
|
|
|
|
<
<







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
..
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
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
258
259
260
	IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
	CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
	TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
	SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
//*****************************************************************************
/*
	Module Name:         HTTP interface for Minnow

	Description:        This uses libmicrohttpd to build a RESTful
						interface to Firenet.  

	Library Extensions	rest_start()			- Start HTTP interface
						rest_stop()				- Stop HTTP interface
						rest_close()			- Close current connection & return data
................................................................................
	Revision History:	
		24 Oct 2010	Initial version
		20 Nov 2010 UC both http & rest base
		16 Dec 2010	Add client lock to lock the webserver to one client
		 7-Mar-2011 Dropping POST data reader, as post data does not work...
		23-Dec-2011 [7b5a95ed75] Update to get rest  base 
					size in structure
		29-Jan-2012 [28bcb55998] Change Minnow so that it can work as a regular
					web server
					
*/
//****************************************************************************

#include <ctype.h>
#include <time.h>
#include "lauxlib.h"
#include "lua.h"
................................................................................
		
		if(  lua_isstring(L,2 ) )
		{
			ptr = (char *)luaL_checklstring(L,2,&llen);
			rsrv->http_site = (char *)MEMALLOC(llen+1);
			if( rsrv->http_site != NULL )
			{
				// 3 Copy and set up http_base value
				// if OK continue
				
				memcpy(rsrv->http_site,ptr,llen);
				if( get_http_base(rsrv) )
				{
					uppercase_it(rsrv->http_base);

					// (3) Get the path to the RESTful location
					// if present
					
					if(  lua_isstring(L,3 ) )
					{
						ptr = (char *)luaL_checklstring(L,3,&llen);
						rsrv->rest_base = (char *)MEMALLOC(llen+1);
						rsrv->len_rest_base = llen;
						if( rsrv->rest_base != NULL )
						{
							memcpy(rsrv->rest_base,ptr,llen);
							uppercase_it(rsrv->rest_base);
						}

						else
							rsrv->len_rest_base = 0;	// No rest base
					}

					else
					{

						// (3a) There is no REST input so handle that
						
						rsrv->len_rest_base = 0;
						rsrv->rest_base = NULL;

					}
					
					// (5) Start server
					
					if( rest_server() == 0 )
					{
						// (6) Start client
						
						if( rest_support_open() == 0 )
						{
							dval = 1.0;
							lua_pushnumber( L,dval );	// Return true
							rtnval = 1;


						}
					}
				}
			}
		}
	}
	

Changes to luasupport/HTTP/rest/rest.c.

395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
		if( strncmp(lurl_buffer,data->http_base,data->len_http_base) == 0 )
		{
			*type = HTTP_SITE;
			lurl = (char *)url;
		}
		else
		{
			if( strncmp(lurl_buffer,data->rest_base,data->len_rest_base) == 0 )
			{
				*type = REST_SITE;
				lurl = (char *)url;
			}
		}
		
		// (3) If it's still NO site then stack on /http_base on the front







|







395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
		if( strncmp(lurl_buffer,data->http_base,data->len_http_base) == 0 )
		{
			*type = HTTP_SITE;
			lurl = (char *)url;
		}
		else
		{
			if( data->len_rest_base > 0 && strncmp(lurl_buffer,data->rest_base,data->len_rest_base) == 0 )
			{
				*type = REST_SITE;
				lurl = (char *)url;
			}
		}
		
		// (3) If it's still NO site then stack on /http_base on the front