Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
HTTP Permanent_HTTPIN_URL_persister  

Permanent_HTTPIN_URL_persister

When you need to pass data into SL from ...

Category: HTTP
By : donjr Spiegelblatt
Created: 2012-06-16 Edited: 2012-06-16
Worlds: Second Life

the Zip file

Download all files for Permanent_HTTPIN_URL_persister
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Permanent_HTTPIN_URL_persister_1.lsl
Get file # 2. Permanent_HTTPIN_URL_persister_2.lsl
1 //////////////////////////////////////////////////////////
2 // [K] Kira Komarov - 2011, License: GPLv3 //
3 // Please see: http://www.gnu.org/licenses/gpl.html //
4 // for legal details, rights of fair usage and //
5 // the disclaimer and warranty conditions. //
6 //////////////////////////////////////////////////////////
7
8 // With modification by: Donjr Spiegelblatt
9
10 //////////////////////////////////////////////////////////
11 // CONFIGURATION //
12 //////////////////////////////////////////////////////////
13 // This is the url extension, ie http://tiny.cc/biose.
14 string CUSTOM_URL = "hotrod";
15 // Set this to the username you signed up with on
16 // http://tiny.cc.
17 string USER_NAME = "hotrod";
18 // Set this to the API key generatred by tiny.cc. To
19 // generate one, visit: http://tiny.cc/api-docs and you
20 // will see Your "API Key:" followed by a key.
21 string API_KEY = "0000000-0000-0000-0000-000000000";
22 //////////////////////////////////////////////////////////
23 // INTERNALS //
24 //////////////////////////////////////////////////////////
25
26 key rlReq = NULL_KEY;
27 key glReq = NULL_KEY;
28 string smURL = "";
29
30 key TinyRequest(integer type)
31 {
32 string url = "http://tiny.cc/"
33 + "?c=rest_api"
34 + "&format=json"
35 + "&version=2.0.3";
36 if(type) // this was the minor difference between the two two calls
37 url += "&m=shorten";
38 else
39 {
40 url += "&m=edit"
41 + "&hash=" + CUSTOM_URL;
42 }
43 url += "&login=" + USER_NAME
44 + "&apiKey=" + API_KEY
45 + "&shortUrl=" + CUSTOM_URL
46 + "&longUrl=" + llEscapeURL(smURL + "/get_url");
47 return llHTTPRequest( url, [HTTP_METHOD, "GET"], "");
48 }
49
50 default
51 {
53 {
55 }
56 on_rez(integer param)
57 {
59 }
60
61 http_request(key id, string method, string body)
62 {
63 if(method == URL_REQUEST_GRANTED)
64 {
65 smURL = body;
66 rlReq = TinyRequest(TRUE); // tiny request first goes here and not in a timer event
67 }
68 else if(method == URL_REQUEST_DENIED)
69 {
70 llOwnerSay("ERROR: URL REQUEST was DENIED "+body);
71 llSleep(5);
73 }
74 else if(method == "GET")
75 {
76 string resp = "GET";
77 llSay(0, "x-path-info ="+llGetHTTPHeader(id, "x-path-info"));
78 llSay(0, "x-query-string ="+llGetHTTPHeader(id, "x-query-string"));
79 if(llGetHTTPHeader(id, "x-path-info") == "/get_url")
80 llHTTPResponse(id, 200,"URL="+smURL+"/cmd");
81 else if(llGetHTTPHeader(id, "x-path-info") == "/cmd")
82 {
83 // example of handling a parameter
84 if(llGetHTTPHeader(id, "x-query-string") == "name" )
85 resp = llGetObjectName();
86 if(llGetHTTPHeader(id, "x-query-string") == "sim" )
87 resp = llGetRegionName();
88 llHTTPResponse(id, 200, resp);
89 }
90 else
91 llHTTPResponse(id, 501, "Unknown call");
92 }
93 else if(method == "POST")
94 {
95 string resp = "POST";
96 llHTTPResponse(id, 200, resp);
97 }
98 else
99 {
100 // \/ 501 Not Implemented (not real sure if this is even possible)
101 llHTTPResponse(id, 501, "Not Implemented "+method);
102 }
103 }
104 http_response(key request_id, integer status, list metadata, string body)
105 {
106 if(glReq == request_id)
107 {
108 if(status != 200)
109 llOwnerSay("TinyRequest(FALSE) failed status="+(string)status+" "+body);
110 glReq = NULL_KEY; // the same event sometimes shows up more then once
111 }
112 else if(rlReq == request_id)
113 {
114 rlReq = NULL_KEY; // the same event sometimes shows up more then once
115 if(status != 200)
116 llOwnerSay("TinyRequest(TRUE) failed status="+(string)status+" "+body);
117 if(~llSubStringIndex(body, "1215"))
118 glReq = TinyRequest(FALSE);
119 }
120 // llHTTPResponse(request_id, 200, ""); Not require and in fact invalid in this event
121 }
122 }

Permanent_HTTPIN_URL_persister

This is a simple example of using an LSL-script to query the other script and get results.

Category: HTTP
By : donjr Spiegelblatt
Created: 2012-06-16 Edited: 2012-06-16
Worlds: Second Life

1 key rlReq;
2 key fReq = NULL_KEY;
3 string newpath = "";
4
5 key Request(string cmd)
6 {
7 llSay(0, "sending="+newpath+"?"+cmd);
8 return llHTTPRequest( newpath+"?"+cmd, [HTTP_METHOD, "GET"], "");
9 }
10
11 default
12 {
14 {
15 }
16 on_rez(integer param)
17 {
19 }
20
22 {
23 rlReq = llHTTPRequest( "http://tiny.cc/hotrod", [HTTP_METHOD, "GET"], ""); // find the other object/script
24 // llSay(0, "MyKey="+(string)llGetKey());
25 }
26
27 http_response(key request_id, integer status, list metadata, string body)
28 {
29 if(rlReq == request_id)
30 {
31 rlReq = NULL_KEY; // the same event sometimes shows up more then once
32 if(status != 200)
33 llOwnerSay("request failed status="+(string)status+" "+body);
34 else
35 {
36 llSay(0, "body["+body+"]"); // report what was returned
37 if(newpath == "")
38 {
39 list t = llParseString2List(body,["="],[]); // break it into two parts
40 if(llList2String(t,0) == "URL") // test that the first par matched
41 {
42 newpath=llList2String(t,1); // set newpath to the second part
43 rlReq = Request("name"); // request the object name
44 }
45 }
46 else if(fReq == NULL_KEY)
47 fReq = Request("unknown"); // make an unknown parameter test
48 }
49 }
50 else if(fReq == request_id)
51 {
52 fReq = llGetKey(); // the same event sometimes shows up more then once
53 if(status != 200)
54 llOwnerSay("request failed status="+(string)status+" "+body);
55 else
56 {
57 llSay(0, "body["+body+"]"); // report what was returned from unknow request
58 rlReq = Request("sim"); // request the 'sim' parameter
59 }
60 }
61 }
62 }

Back to the Best Free Tools in Second Life and OpenSim.