Great and cool ! Thanks, Andre :)

Le 9 mars 04, à 02:38, Andre Garzia a écrit :

Hi Folks,

I've been fiddling with HTTP and Rev for some time, now and them I posted some news here. Many people visited the server and got interested in the project. Now it's time to release the code. For those that do not know what this project is or what it is able to do, I'll do a quick and dirty resume here. but the best way to learn about it is thru it's about page. Try http://home.soapdog.org:8081/about?card=1

This will take you to a server and possibilities tour, much better and well written than this quick hack here. The stacks are available from http://public.soapdog.org The demo server is running here at http://home.soapdog.org:8081/

Cheers
Andre

--- What is ServerWorkz/RevHTTPd Project? ----------------------------------------------------------------------- -------------------------

It's the implementation of a fully functional web server/framework in Revolution. While we do not plan to overtake Apache, we've got some UberCool features that will impresse everyone. This stack is a heavy modified version of old Metacard HTTPd Stack. I stripped out many things but added tons of code too, so You might not recognize it. The server is able to serve local files from the HTML folder and to serve stacks as dynamic pages (lot's of stunts here). Local files may interface to revolution using special Inform2 Tags. Dynamic files might be substacks of the server, local .Rev files inside the Modules folder or any stack that is loaded in runtime (like everything in the IDE...). The server is very advanced and it's even able to transport data from HTML to Stacks automatically.


Any stack can be served this way. You can set the server to any port you want and you can even embedd it in your own app (it's just a button to be placed in the back). You can allow it to serve local files or use it only for dynamic content. Server default to port 8081. Sou you can try to access my home server by pointing your browser to http://home.soapdog.org:8081/


--- How To Flush things to the browser ----------------------------------------------------------------------- -----------------------------------

To echo content to the browser you use the http_flush handler, it's like this:

http_flush "text/html", "hello world"

first parameter is the mime type, the second is the content. Other good function is http_redirect that accepts one parameter and forces a redirection. Use it like:

http_redirect "http://www.yahoo.com";


That will force browser to redirect to Yahoo! Page.


--- Understanding what happens inside the server when browser asks for a stack. -----------------------------------------------


When user connect to the server, it asks for a document. This document might be a local stored file or a stack. In the case of a file it is just flushed to the browser. In case of a stack it's more complex. For your stack to be served it must implement (well, it should implement) the default handler "default_html". So suppose you want a helloworld stack, just add this to a stack

on default_html
        http_flush "text/html", "Hello World!"
end default_html

you'll be able to access this exact script from http://home.soapdog.org:8081/helloworld
But that's not all, we've got a cool URL mapping scheme. Let's talk about it.


--- About URL Mapping scheme ----------------------------------------------------------------------- -----------------------------------------------

/Stack ---> Send default_html to the stack.
/Stack/Message ---> Send message to the Stack
/Stack/Card/Message ---> Send message to card of stack.
/Stack/Card/Button/Message ---> Send message to button of card of stack (this is like a design decision, messages default to button if no object type is present)
/Stack/Card/ObjectType/ObjectName/Msg ---> Send msg to obj of card of stack like: /MainStack/1/field/email/clearText (would send "clearText" to field email)


This way I can for example access a URL a button like this http://home.soapdog.org:8081/quotes/2/button/refreshquotes/mouseUp, this would trigger the mouseUp of button adduote on card 2 of stack quotes. Pretty easy! Enought for URLs.

The server is now supporting the POST method and GET method, it will look for POST Data and look inside document request URL for GET data... it will map HTML/URL Field names to Revolution Field names, so if I access http://home.soapdog.org:8081/about?card=1 it will look for stack "about" and for a text field named card in it, if it find one it will fill it with "1", Thats automatic. It fills the fields before sending the message (so that you can proccess them). This way you can write whole web apps just by using our familiar ways of stacks, cards, fields and messages.

We created a Revolution Field to Web Engine called Inform2. Inform2 can take any card of any stack and will parse it taking all fields and making a nice HTML form of it. It will fill the form with the currrent fields values, and since the server do the map back automatically, you can focus on the "processPost" message that is sent to your stack for the rest is taken care.

For you all to wonder, with this framework I was able to create a Blog engine in 10 lines, was able to create a Fotolog engine in also 10 lines. I created a Instant Message in some 30 lines.

--- More on Inform2 ----------------------------------------------------------------------- -----------------------------------------------------------------

Inform2 is a frontscript used to make the server even better. It was created after reading Mr Dar Scott message primer and looking inside LibCGI code.
Inform2 adds the following


* New ways to access server data.
In previous version, revHTTPd would match field names to the field names acquired from POST or GET Methods, thus if you used a form with a field named email or a url like http://yourhost/[EMAIL PROTECTED] it would get the email value and fill the email field of the desired stack with it. Now you also have the option to access it in a nice global array called gDataA (This is inspired by LibCGI, thats how it handles), this way, you can access non expected fields and also you will be able to access the data without creating fields for everything.


* Cookies!
After seeing the code from libCGI, I finally understood how HTTP handles cookies (it's not covered with HTTP Made Easy - my main learning book), so I put cookie support with a function called "http_flush_with_cookies" that will flush a response and also set cookies based on a array parameter. The current browser cookies will be inside gDataA array.(it's not working in RC1)


* New packaging! :D
revHTTPd was first a stack, then a button, now... now it still a button, but since I learned much from message primer by Mr Dar Scott and from message path article at Fourth World Embassy, I figured out that inserting button "httpd" into back would be very good, this way we can guarantee that it always receive the message and that the handlers are available everywhere.


* Brand new and improved and over-powerfull template engine.
We created Inform2, our new template engine. This is a frontscript that overdrive normal http_flush, this way, besides the normal template tags %BODY%, %STACKNAME%, %TITLE%, we've got some ubercool tags like:

Inform-field tag: This one will insert a field from any card or stack, to be used like [inform-field: passwordField stack: User Database card: andre garzia] this would insert the content of field "passwordField" of card "andre garzia" of stack "User Database". You can omit the card: parameter and it will act on current card.


Inform-property tag: the same as above but insert a custom property. Used like [inform-property: cHits stack: serverworkz card: 1] where card parameter is optional.

Inform-throw tag: will send a message thru message path, like [inform-throw: closeStack stack: about], when inform2 engine find this tag it sends a message, this is good for using static html to send messages and stuff. For example, inform-field is proccessed before inform-throw, so you can make voodoo things like [inform-throw: [inform-field: messageField stack: messageSelector] stack: messageDestination], can you guess what this one will do... that's evil!!! :D

Must say that it was after seeing WebMerge from Fourth World that I thought of custom tags thru Regular Expressions, I thought: "They did that with metacard, so there must be a way". After couple minutes search I found matchText command and a primer on Regular Expressions on the net.

--- More? Licensing and the like ----------------------------------------------------------------------- ----------------------------------------------------------------------- -------------

Well this was a copy & paste from previous messages with some new words in it. What you should have in mind is that ServerWorkz is not a simple webserver nor is a CGI lib. It's something very different. It's a conduit between Revolution and the HTTP speaking world. You can use it to serve pages, sure. You can use it for CGI, yes. But you can use it as a networking lib for interapplication communication for example. You can make two apps talk to each other with no fuss. Just add the server to both, use something like zeroconf to discover each other and use http_flush to send text and actions.

Simple apps like address books, simple user databases, are pretty easy. You can check the modules folder for the RegisterUser.rev stack and you'll see what I am talking about. It's a dozen lines for all the code you need to make that user database you see on the page. By inspecting the modules you'll see how I did everything for I am too lazy to document all the aspects of the server. This will be done in the future. It's enought to say that everything goes inside the code of button "httpd" and in it's custom properties (that's where templates and configurations are stored), the button "inform2" will take care of all that RegEx template stuff and the automatic field to web generator.

I am always here to answer about everything. My machine is running 24/7 and the server is always up (unless when I break it by adding new features). The server is running at http://home.soapdog.org:8081/ and you can grab it as serverworkzbeta.zip inside http://public.soapdog.org

This code is being made public, fiddle with it as you like it but giving me credit will attract good karma for you, and donating to this project will attract good karma to you and you familly. Bear in mind that I am 23, living in Brazil coursing film school. Life here is very very hard, my salary is R$220 (U$75), it's hard to have time to code when you need to fill your time with freelance work so that you got the means to take your girl to the movies and eat every day. my paypal account is [EMAIL PROTECTED]

I can do custom work using this framework (I understand it better than anyone ;-) ) This is the base of some solutions I am working, and I am releasing it for I feel that everyone can benefit from it, and that this can be a killer thing for Revolution. Please send feedback to me at [EMAIL PROTECTED] and if you feel like helping me just send code, suggestions, bug reports, advise and the like.

Well, cheers, fiddle with the code!

Andre Garzia

--
Andre Alves Garzia  2004
Soap Dog Studios - BRAZIL
http://studio.soapdog.org
_______________________________________________
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution


--
Bien cordialement, Pierre Sahores

100, rue de Paris
F - 77140 Nemours

psahores (at) easynet.fr

GSM:   +33 6 03 95 77 70
Pro:      +33 1 41 60 52 68
Dom:    +33 1 64 45 05 33
Fax:      +33 1 64 45 05 33

Inspection académique de Seine-Saint-Denis
Applications et SGBD ACID SQL (WEB et PGI)
Penser et produire "delta de productivité"

_______________________________________________
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to