User:Void Singer/Teacup

From Second Life Wiki
< User:Void Singer
Revision as of 02:23, 17 April 2011 by Void Singer (talk | contribs) (+notes)
Jump to navigation Jump to search

Teacup

Teacup

What is it?

Teapot is an open source webserver front end for LSL's HTTP-in MOAP functionality. It builds on the work of Several other people including but not limited to, Kelly Linden, Torley Linden, Tali Rosca, Vegas Silverweb, and special mentions to Kate and/or Edelman Linden (whoever wrote the original align for LSL). The idea is to make it easy to serve web content from within SL, with a minimum of work or understanding, in the most standards compliant and flexible way possible.

How does it work?

When Teacup Server starts, it requests a URL from the region server, and when it gets a response, sets the prim side 0 face to a "data:" URN wrapped page (limiting the use of the slow ll*PrimMedia* cotrols to once at load). If the response was "no URL", then it sets an error page. If the response was a new URL, then the server test page is set, and that also requests and loads the javascript library. The first time the javascript library loads, it attempts to load the "index.tsp" page by creating a script element container for it. The server gets the request for the new page, and asks the file server for it... if the file server doesn't have it, or isn't present, the an error code will be sent to the html page, which stays where it was and pops up an error alert. If the file was found, it's loaded to the script element. Once loaded, the javascript library grabs the contents and overwrites the body of the html page with them, then it checks each link on the new page, sets up a trap for any internal links leading to ".tsp" pages, and removes the script container from the page. If a trapped link is clicked, instead of loading directly, the javascript library catches the link, and repeats the same actions it used to load the "index.tsp" page. links to outside resources are not interfered with, and load normally. the page code is left untouched.

Format Requirments?

Teacup serves a modified html page.

  • The file name should end with ".tsp" (Teacup server page)
  • The contents are limited to what's valid inside a normal html "body" tag.
  • It also requires the following minor changes, made in order:
    1. all backslash characters must be converted to double backslashes (may be applied on a line by line basis)
    2. all single quote characters must be prefixed with a backslash (may be applied on a line by line basis)
    3. all line breaks should be converted to "\n" literals (may be applied on a line by line basis)
    4. The page should be prefixed with "vTea='" and suffixed with "';" (applies only to the whole page)

why all the tea jokes?

So why all the tea jokes? Well I happen to like steam punk stuff, and it has a sort of pseudo-victorian-era feel to it, but in all truth it was sparked by a bit of geek humor. There was an old april fool's joke passed around as an official sounding memo about creating a protocol for controlling coffee pots with http (back before they actually started making net enabled appliances) and part of that proposal was that teapots should return an error response "418 I'm a teapot" if you tried to make it brew coffee... since these servers are small, and 418 is safe to use internally because it wouldn't normally be encountered, I figured hey, Teapot --> Teacup --> Victorian Imagery --> Steam Punk --> teacup that is it's own teapot --> SIP --> many different types of tea --> Success!

... And thus was born the SIP, Teapot server, and Red Tea file system

Return to top

Code

<lsl>/*( Teacup Server v0.2 )*/

//-- stores the entire bootstrap or error page for touch handling string gStrAdr;

//-- pending request queue for pages waiting to be served //-- this (hopefully) prevents reponding after SL send a timeout. list gLstPndKey; list gLstPndTim;

default{

   state_entry(){
        //-- Request URL on start up
       llRequestURL();
   }
   
   on_rez( integer vIntBgn ){
        //-- Clear pending and request URL on rez
       gLstPndKey = gLstPndTim = [];
       llRequestURL();
   }
   
   changed( integer vBitChg ){
if ((CHANGED_REGION_START

Notes

Compatible File Systems and Extensions

Red Tea - A very simple backend file sytem for a starting point.

Known Bugs

  • inline script/style elements are not evaluated at load time (inline attributes should work normally)
    • images have their own events, and can be used to trigger page load javascript
  • document/body onload events are not triggered for .tsp pages
    • images have their own events, and can be used to trigger page load javascript

Planned Upgrades

  • Move the test page and base javascript library out of the main script and into either the File System, or a separate load handler script
    • Confirmed: will be adding a "Saucer" script to handle the base .js file, and default message pages.
  • Add support for Site wide javascript and css or make them load normally to the page
    • Confirmed: Saucer sub script will handle page availabilities from file system, and inject site js and css into the default message page.
      • May eventually lead to a new method of handling where each page can have a .js and .css page associated with it.
  • Trigger at least the normal load events manually
  • find a convenient way to set the page title... probably use the page name
    • Confirmed: Page titles will match the internal file name minus the ".tsp" extension
      • index page may eventually assume the object name, if I can cleanly inject that into the base .js file.

NOTE TO WIKI EDITORS

I have kept this page as a sub page of my user page to denote that it should NOT be edited except to correct errors, add confirmed bugs, or add related resources.
The intent is to ensure executive control is in one person's hands to retain a cohesive vision of it's development.
If you have an improvement suggestion, or request, please use the discussion page.

Return to top

Questions or Comments?

Feel free to leave me a note on the discussion page.