httpdb

httpdb provides free, persistant, off-site storage for Second Life LSL Scripts via llHTTPRequest. You can store up to 250kb of data in the form of key/value pairs, and read or write the data from any script. You can share your data with other users, protect it with passwords, browse and manage your data on the web, and download backups.

Web Interface
DO NOT USE YOUR SECOND LIFE ACCOUNT PASSWORD!

Registering

There is no need to register to use httpdb, you can just start saving and retrieving data at any time. There are some advanced features that require you to set an admin password; see Advanced Use.

Quickstart

  string HTTPDB = "http://w-hat.com/httpdb/"; // httpdb url
  key    reqid_load;                          // request id

  // Save a value to httpdb with the specified name.
  httpdb_save( string name, string value ) {
    llHTTPRequest( HTTPDB + name, [HTTP_METHOD, "PUT"], value );
  }

  // Load named data from httpdb.
  httpdb_load( string name ) {
    reqid_load = llHTTPRequest( HTTPDB + name, [HTTP_METHOD, "GET"], "" );
  }

  default {
    http_response( key reqid, integer status, list meta, string body ) {
      if ( reqid == reqid_load ) {
        // do something with body
      }
    }
  }

For more complete library code, see libhttpdb.lsl.

Usage

Requests

All httpdb requests are composed of three parts: a path, a method, and a body. These correspond directly to the three parameters of llHTTPRequest

Paths

A path is a "name" or "key" that identifies a value. You specify the path you want to access by adding it on to the httpdb URL, and using it as the first parameter of llHTTPRequest. For example, the URL for a value called myproject/data1.txt would be http://w-hat.com/httpdb/myproject/data1.txt.

Methods

httpdb uses the HTTP Request Method to determine what action you want to perform. GET is for retrieving data, PUT is for saving data, DELETE is for removing data, and POST is used for updating metadata. You specify the method by passing [HTTP_METHOD, "(method)"] as the second parameter of llHTTPRequest.

Body

The body of the request is the third parameter of llHTTPRequest. It should be blank for GET and DELETE requests, but for PUT requests it should contain the actual data that you want to store.

Responses

httpdb uses a subset of the standard HTTP 1.1 responses, with slightly adapted semantics:

For quick checking, a code < 300 means success, and a code >= 400 means error.

Advanced Usage

Options

You can add options to a request in the normal HTTP way: append a question mark (?) to the URL, and then a list of "key=value" pairs separated by "and" symbols (&). Each option has a shorthand version displayed after it in parenthesis that you can use instead of the full name. For example: http://w-hat.com/httpdb/secret?m=read&password=hello

Special Paths

Paths beginning with two underscores are reserved for system use.

POST

You can use POST to change the metadata associated with a record without changing the record itself. You pass a list of options in the normal format, but as the body of the request instead of after a question mark in the URL. You must provide your admin password as the password parameter. For example, to change the password on 'top/secret.txt' you would do:

  llHTTPRequest(
    "http://w-hat.com/top/secret.txt", [HTTP_METHOD, "POST"], "password=" +
    admin_pass + "&wp=sekrit"); 

Backups

After logging into the Web Interface, you can download CSV dumps of all your data. The dump contains the following information for each record (in this order): path, creator, created_at, updater, updated_at, read_password, write_password, data. The passwords are salted MD5 hashes, the same way they are stored in the database.

External Access

You can access any part of the Web Interface from scripts outside of SL. The username parameter is called login and the password parameter is called password. You can use this to set up a cronjob on your computer to download backups, or whatever you want.

Misc

Space

There are about 250 bytes of overhead for each record, used for metadata, paths, and indexing. This means that even if you only store one byte, it will be counted as much more. This also means it is more economical to use a few large records, rather than many small records.

The space limit is per SL account, so you can use any alternate accounts you have for more space. Additional storage can be arranged; send an IM to Masakazu Kojima in world for more information.

Why not use SQL?

Similar Services

Carl Omlet offers free, unlimited(?) storage through llHTTPRequest().

Some Jerk offers a bad attitude and a false sense of security.

Zero Linden created Silo, "a simple, general purpose file system for LSL via HTTP" written in PHP. It is similar to httpdb and you host it yourself. (link fixed 2006-11-04)

Example Uses

These examples use libhttpdb.lsl.

Visitor Logger

 float SCAN_RANGE    = 32.0;
 float SCAN_INTERVAL = 30.0;

 httpdb_success( integer type, string name, integer status ) {
     if ( status == 201 ) { // new record created, first visit
         list l = llParseString2List( name, "/" ); // [ "visitors", key ]
         key  id = llList2String( l, 1 );
         // greet them
         llInstantMessage( id, "WELCOME TO THE INTERNET!" );
     }
 }

 default {

     state_entry() {
         llSensorRepeat("", NULL_KEY, AGENT, SCAN_RANGE, PI, SCAN_INTERVAL);
     }

     sensor(integer num) {
         integer i = num;
         while (i--) {
             httpdb_save(
               "visitors/" + (string)llDetectedKey(i),
               llGetTimestamp()
             );
         }
     }

 }                        

Log File

log(string message) {
    string logstr = "[" + llGetTimestamp() + "] " + message;
    llOwnerSay(logstr);
    httpdb_save( "logs/example.log?mode=prepend", logstr + "\n" );
}

High Score List

Customer List

Name2key Database

Server Tracker (objdns)

XML-RPC Key Tracker