summaryrefslogtreecommitdiff
path: root/indra/lscript
diff options
context:
space:
mode:
Diffstat (limited to 'indra/lscript')
-rw-r--r--indra/lscript/CMakeLists.txt3
-rw-r--r--indra/lscript/llscriptresource.h64
-rw-r--r--indra/lscript/llscriptresourceconsumer.h56
-rw-r--r--indra/lscript/llscriptresourcepool.h46
-rw-r--r--indra/lscript/lscript_byteformat.h9
-rw-r--r--indra/lscript/lscript_compile/indra.l24
-rw-r--r--indra/lscript/lscript_compile/indra.y21
-rw-r--r--indra/lscript/lscript_compile/lscript_tree.cpp109
-rw-r--r--indra/lscript/lscript_compile/lscript_tree.h30
-rw-r--r--indra/lscript/lscript_execute/CMakeLists.txt6
-rw-r--r--indra/lscript/lscript_execute/llscriptresource.cpp86
-rw-r--r--indra/lscript/lscript_execute/llscriptresourceconsumer.cpp101
-rw-r--r--indra/lscript/lscript_execute/llscriptresourcepool.cpp39
-rw-r--r--indra/lscript/lscript_execute/lscript_execute.cpp6
-rw-r--r--indra/lscript/lscript_execute/lscript_readlso.cpp10
-rw-r--r--indra/lscript/lscript_library/lscript_library.cpp6
16 files changed, 603 insertions, 13 deletions
diff --git a/indra/lscript/CMakeLists.txt b/indra/lscript/CMakeLists.txt
index c655aef4d9..937e2ec0dc 100644
--- a/indra/lscript/CMakeLists.txt
+++ b/indra/lscript/CMakeLists.txt
@@ -1,6 +1,9 @@
# -*- cmake -*-
set(lscript_HEADER_FILES
+ llscriptresource.h
+ llscriptresourceconsumer.h
+ llscriptresourcepool.h
lscript_alloc.h
lscript_byteconvert.h
lscript_byteformat.h
diff --git a/indra/lscript/llscriptresource.h b/indra/lscript/llscriptresource.h
new file mode 100644
index 0000000000..2aa0af882d
--- /dev/null
+++ b/indra/lscript/llscriptresource.h
@@ -0,0 +1,64 @@
+/**
+ * @file llscriptresource.h
+ * @brief LLScriptResource class definition
+ *
+ * $LicenseInfo:firstyear=2008&license=internal$
+ *
+ * Copyright (c) 2008, Linden Research, Inc.
+ *
+ * The following source code is PROPRIETARY AND CONFIDENTIAL. Use of
+ * this source code is governed by the Linden Lab Source Code Disclosure
+ * Agreement ("Agreement") previously entered between you and Linden
+ * Lab. By accessing, using, copying, modifying or distributing this
+ * software, you acknowledge that you have been informed of your
+ * obligations under the Agreement and agree to abide by those obligations.
+ *
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#ifndef LL_LLSCRIPTRESOURCE_H
+#define LL_LLSCRIPTRESOURCE_H
+
+#include "stdtypes.h"
+
+// An LLScriptResource is a limited resource per ID.
+class LLScriptResource
+{
+public:
+ LLScriptResource();
+
+ // If amount resources are available will mark amount resouces
+ // used and returns true
+ // Otherwise returns false and doesn't mark any resources used.
+ bool request(S32 amount = 1);
+
+ // Release amount resources from use if at least amount resources are used and return true
+ // If amount is more than currently used no resources are released and return false
+ bool release(S32 amount = 1);
+
+ // Returns how many resources are available
+ S32 getAvailable() const;
+
+ // Sets the total amount of available resources
+ // It is possible to set the amount to less than currently used
+ // Most likely to happen on parcel ownership change
+ void setTotal(S32 amount);
+
+ // Get the total amount of available resources
+ S32 getTotal() const;
+
+ // Get the number of resources used
+ S32 getUsed() const;
+
+ // true if more resources used than total available
+ bool isOverLimit() const;
+
+private:
+ S32 mTotal; // How many resources have been set aside
+ S32 mUsed; // How many resources are currently in use
+};
+
+#endif // LL_LLSCRIPTRESOURCE_H
diff --git a/indra/lscript/llscriptresourceconsumer.h b/indra/lscript/llscriptresourceconsumer.h
new file mode 100644
index 0000000000..1ec0026996
--- /dev/null
+++ b/indra/lscript/llscriptresourceconsumer.h
@@ -0,0 +1,56 @@
+/**
+ * @file llscriptresourceconsumer.h
+ * @brief An interface for a script resource consumer.
+ *
+ * $LicenseInfo:firstyear=2008&license=internal$
+ *
+ * Copyright (c) 2008, Linden Research, Inc.
+ *
+ * The following source code is PROPRIETARY AND CONFIDENTIAL. Use of
+ * this source code is governed by the Linden Lab Source Code Disclosure
+ * Agreement ("Agreement") previously entered between you and Linden
+ * Lab. By accessing, using, copying, modifying or distributing this
+ * software, you acknowledge that you have been informed of your
+ * obligations under the Agreement and agree to abide by those obligations.
+ *
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#ifndef LL_LLSCRIPTRESOURCECONSUMER_H
+#define LL_LLSCRIPTRESOURCECONSUMER_H
+
+#include "linden_common.h"
+
+class LLScriptResourcePool;
+
+// Entities that use limited script resources
+// should implement this interface
+
+class LLScriptResourceConsumer
+{
+public:
+ LLScriptResourceConsumer();
+
+ virtual ~LLScriptResourceConsumer() { }
+
+ // Get the number of public urls used by this consumer.
+ virtual S32 getUsedPublicURLs() const = 0;
+
+ // Get the resource pool this consumer is currently using.
+ LLScriptResourcePool& getScriptResourcePool();
+ const LLScriptResourcePool& getScriptResourcePool() const;
+
+ bool switchScriptResourcePools(LLScriptResourcePool& new_pool);
+ bool canUseScriptResourcePool(const LLScriptResourcePool& resource_pool);
+ bool isInPool(const LLScriptResourcePool& resource_pool);
+
+protected:
+ virtual void setScriptResourcePool(LLScriptResourcePool& pool);
+
+ LLScriptResourcePool* mScriptResourcePool;
+};
+
+#endif // LL_LLSCRIPTRESOURCECONSUMER_H
diff --git a/indra/lscript/llscriptresourcepool.h b/indra/lscript/llscriptresourcepool.h
new file mode 100644
index 0000000000..ca4afeb3c6
--- /dev/null
+++ b/indra/lscript/llscriptresourcepool.h
@@ -0,0 +1,46 @@
+/**
+ * @file llscriptresourcepool.h
+ * @brief A collection of LLScriptResources
+ *
+ * $LicenseInfo:firstyear=2008&license=internal$
+ *
+ * Copyright (c) 2008, Linden Research, Inc.
+ *
+ * The following source code is PROPRIETARY AND CONFIDENTIAL. Use of
+ * this source code is governed by the Linden Lab Source Code Disclosure
+ * Agreement ("Agreement") previously entered between you and Linden
+ * Lab. By accessing, using, copying, modifying or distributing this
+ * software, you acknowledge that you have been informed of your
+ * obligations under the Agreement and agree to abide by those obligations.
+ *
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#ifndef LL_LLSCRIPTRESOURCEPOOL_H
+#define LL_LLSCRIPTRESOURCEPOOL_H
+
+#include "llscriptresource.h"
+
+// This is just a holder for LLSimResources
+class LLScriptResourcePool
+{
+public:
+ LLScriptResourcePool();
+ // ~LLSimResourceMgr();
+
+ LLScriptResource& getPublicURLResource();
+ const LLScriptResource& getPublicURLResource() const;
+
+ // An empty resource pool.
+ static LLScriptResourcePool null;
+
+private:
+ LLScriptResource mLSLPublicURLs;
+};
+
+
+
+#endif
diff --git a/indra/lscript/lscript_byteformat.h b/indra/lscript/lscript_byteformat.h
index 7333d47f15..ba2c46bef2 100644
--- a/indra/lscript/lscript_byteformat.h
+++ b/indra/lscript/lscript_byteformat.h
@@ -360,6 +360,7 @@ typedef enum e_lscript_state_event_type
LSTT_OBJECT_REZ,
LSTT_REMOTE_DATA,
LSTT_HTTP_RESPONSE,
+ LSTT_HTTP_REQUEST,
LSTT_EOF,
LSTT_STATE_BEGIN = LSTT_STATE_ENTRY,
@@ -401,7 +402,8 @@ const U64 LSCRIPTStateBitField[LSTT_EOF] =
0x0000000020000000, // LSTT_MOVING_END
0x0000000040000000, // LSTT_OBJECT_REZ
0x0000000080000000, // LSTT_REMOTE_DATA
- 0x0000000100000000LL // LSTT_HTTP_RESPOSE
+ 0x0000000100000000LL, // LSTT_HTTP_RESPOSE
+ 0x0000000200000000LL // LSTT_HTTP_REQUEST
};
inline S32 get_event_handler_jump_position(U64 bit_field, LSCRIPTStateEventType type)
@@ -551,5 +553,10 @@ const U32 LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_EOF] =
(0x1 << 11),// SCRIPT_PERMISSION_CONTROL_CAMERA
};
+// http_request string constants
+extern const char* URL_REQUEST_GRANTED;
+extern const char* URL_REQUEST_DENIED;
+extern const U64 LSL_HTTP_REQUEST_TIMEOUT;
+
#endif
diff --git a/indra/lscript/lscript_compile/indra.l b/indra/lscript/lscript_compile/indra.l
index 2616b47c73..ac524326fc 100644
--- a/indra/lscript/lscript_compile/indra.l
+++ b/indra/lscript/lscript_compile/indra.l
@@ -118,6 +118,7 @@ extern "C" { int yyerror(const char *fmt, ...); }
"object_rez" { count(); return(OBJECT_REZ); }
"remote_data" { count(); return(REMOTE_DATA); }
"http_response" { count(); return(HTTP_RESPONSE); }
+"http_request" { count(); return(HTTP_REQUEST); }
"." { count(); return(PERIOD); }
@@ -221,16 +222,17 @@ extern "C" { int yyerror(const char *fmt, ...); }
"INVENTORY_ALL" { count(); yylval.ival = LLAssetType::AT_NONE; return(INTEGER_CONSTANT); }
"INVENTORY_NONE" { count(); yylval.ival = LLAssetType::AT_NONE; return(INTEGER_CONSTANT); }
-"CHANGED_INVENTORY" { count(); yylval.ival = 0x1; return(INTEGER_CONSTANT); }
-"CHANGED_COLOR" { count(); yylval.ival = 0x2; return(INTEGER_CONSTANT); }
-"CHANGED_SHAPE" { count(); yylval.ival = 0x4; return(INTEGER_CONSTANT); }
-"CHANGED_SCALE" { count(); yylval.ival = 0x8; return(INTEGER_CONSTANT); }
-"CHANGED_TEXTURE" { count(); yylval.ival = 0x10; return(INTEGER_CONSTANT); }
-"CHANGED_LINK" { count(); yylval.ival = 0x20; return(INTEGER_CONSTANT); }
-"CHANGED_ALLOWED_DROP" { count(); yylval.ival = 0x40; return(INTEGER_CONSTANT); }
-"CHANGED_OWNER" { count(); yylval.ival = 0x80; return(INTEGER_CONSTANT); }
-"CHANGED_REGION" { count(); yylval.ival = 0x100; return(INTEGER_CONSTANT); }
-"CHANGED_TELEPORT" { count(); yylval.ival = 0x200; return(INTEGER_CONSTANT); }
+"CHANGED_INVENTORY" { count(); yylval.ival = CHANGED_INVENTORY; return(INTEGER_CONSTANT); }
+"CHANGED_COLOR" { count(); yylval.ival = CHANGED_COLOR; return(INTEGER_CONSTANT); }
+"CHANGED_SHAPE" { count(); yylval.ival = CHANGED_SHAPE; return(INTEGER_CONSTANT); }
+"CHANGED_SCALE" { count(); yylval.ival = CHANGED_SCALE; return(INTEGER_CONSTANT); }
+"CHANGED_TEXTURE" { count(); yylval.ival = CHANGED_TEXTURE; return(INTEGER_CONSTANT); }
+"CHANGED_LINK" { count(); yylval.ival = CHANGED_LINK; return(INTEGER_CONSTANT); }
+"CHANGED_ALLOWED_DROP" { count(); yylval.ival = CHANGED_ALLOWED_DROP; return(INTEGER_CONSTANT); }
+"CHANGED_OWNER" { count(); yylval.ival = CHANGED_OWNER; return(INTEGER_CONSTANT); }
+"CHANGED_REGION" { count(); yylval.ival = CHANGED_REGION; return(INTEGER_CONSTANT); }
+"CHANGED_TELEPORT" { count(); yylval.ival = CHANGED_TELEPORT; return(INTEGER_CONSTANT); }
+"CHANGED_REGION_START" { count(); yylval.ival = CHANGED_REGION_START; return(INTEGER_CONSTANT); }
"OBJECT_UNKNOWN_DETAIL" { count(); yylval.ival = OBJECT_UNKNOWN_DETAIL; return(INTEGER_CONSTANT); }
"OBJECT_NAME" { count(); yylval.ival = OBJECT_NAME; return(INTEGER_CONSTANT); }
@@ -252,6 +254,8 @@ extern "C" { int yyerror(const char *fmt, ...); }
"NULL_KEY" { yylval.sval = new char[UUID_STR_LENGTH]; strcpy(yylval.sval, "00000000-0000-0000-0000-000000000000"); return(STRING_CONSTANT); }
"EOF" { yylval.sval = new char[UUID_STR_LENGTH]; strcpy(yylval.sval, "\n\n\n"); return(STRING_CONSTANT); }
+"URL_REQUEST_GRANTED" { yylval.sval = new char[UUID_STR_LENGTH]; strcpy(yylval.sval, URL_REQUEST_GRANTED); return(STRING_CONSTANT); }
+"URL_REQUEST_DENIED" { yylval.sval = new char[UUID_STR_LENGTH]; strcpy(yylval.sval, URL_REQUEST_DENIED); return(STRING_CONSTANT); }
"PI" { count(); yylval.fval = F_PI; return(FP_CONSTANT); }
"TWO_PI" { count(); yylval.fval = F_TWO_PI; return(FP_CONSTANT); }
diff --git a/indra/lscript/lscript_compile/indra.y b/indra/lscript/lscript_compile/indra.y
index fdc240c772..e4b10ffdd9 100644
--- a/indra/lscript/lscript_compile/indra.y
+++ b/indra/lscript/lscript_compile/indra.y
@@ -92,6 +92,7 @@
%token LINK_MESSAGE
%token REMOTE_DATA
%token HTTP_RESPONSE
+%token HTTP_REQUEST
%token <sval> IDENTIFIER
%token <sval> STATE_DEFAULT
@@ -195,6 +196,7 @@
%type <event> object_rez
%type <event> remote_data
%type <event> http_response
+%type <event> http_request
%type <event> link_message
%type <event> timer
%type <event> chat
@@ -848,6 +850,11 @@ event
$$ = new LLScriptEventHandler(gLine, gColumn, $1, $2);
gAllocationManager->addAllocation($$);
}
+ | http_request compound_statement
+ {
+ $$ = new LLScriptEventHandler(gLine, gColumn, $1, $2);
+ gAllocationManager->addAllocation($$);
+ }
;
state_entry
@@ -1216,6 +1223,20 @@ http_response
}
;
+http_request
+ : HTTP_REQUEST '(' LLKEY IDENTIFIER ',' STRING IDENTIFIER ',' STRING IDENTIFIER ')'
+ {
+ LLScriptIdentifier *id1 = new LLScriptIdentifier(gLine, gColumn, $4);
+ gAllocationManager->addAllocation(id1);
+ LLScriptIdentifier *id2 = new LLScriptIdentifier(gLine, gColumn, $7);
+ gAllocationManager->addAllocation(id2);
+ LLScriptIdentifier *id3 = new LLScriptIdentifier(gLine, gColumn, $10);
+ gAllocationManager->addAllocation(id3);
+ $$ = new LLScriptHTTPRequestEvent(gLine, gColumn, id1, id2, id3);
+ gAllocationManager->addAllocation($$);
+ }
+ ;
+
compound_statement
: '{' '}'
{
diff --git a/indra/lscript/lscript_compile/lscript_tree.cpp b/indra/lscript/lscript_compile/lscript_tree.cpp
index 51983bb41b..e291d4c6f8 100644
--- a/indra/lscript/lscript_compile/lscript_tree.cpp
+++ b/indra/lscript/lscript_compile/lscript_tree.cpp
@@ -3291,6 +3291,110 @@ S32 LLScriptHTTPResponseEvent::getSize()
return 16;
}
+void LLScriptHTTPRequestEvent::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
+{
+ if (gErrorToText.getErrors())
+ {
+ return;
+ }
+ switch(pass)
+ {
+ case LSCP_PRETTY_PRINT:
+ case LSCP_EMIT_ASSEMBLY:
+ fdotabs(fp, tabs, tabsize);
+ fprintf(fp, "http_request( key ");
+ mRequestId->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
+ fprintf(fp, ", string ");
+ mMethod->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
+ fprintf(fp, ", string ");
+ mBody->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
+ fprintf(fp, " )\n");
+ break;
+
+ case LSCP_SCOPE_PASS1:
+ checkForDuplicateHandler(fp, this, scope, "http_request");
+ if (scope->checkEntry(mRequestId->mName))
+ {
+ gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME);
+ }
+ else
+ {
+ mRequestId->mScopeEntry = scope->addEntry(mRequestId->mName, LIT_VARIABLE, LST_KEY);
+ }
+
+ if (scope->checkEntry(mMethod->mName))
+ {
+ gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME);
+ }
+ else
+ {
+ mMethod->mScopeEntry = scope->addEntry(mMethod->mName, LIT_VARIABLE, LST_STRING);
+ }
+
+ if (scope->checkEntry(mBody->mName))
+ {
+ gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME);
+ }
+ else
+ {
+ mBody->mScopeEntry = scope->addEntry(mBody->mName, LIT_VARIABLE, LST_STRING);
+ }
+ break;
+
+ case LSCP_RESOURCE:
+ {
+ // we're just tryng to determine how much space the variable needs
+ if (mRequestId->mScopeEntry)
+ {
+ mRequestId->mScopeEntry->mOffset = (S32)count;
+ mRequestId->mScopeEntry->mSize = 4;
+ count += mRequestId->mScopeEntry->mSize;
+
+ mMethod->mScopeEntry->mOffset = (S32)count;
+ mMethod->mScopeEntry->mSize = 4;
+ count += mMethod->mScopeEntry->mSize;
+
+ mBody->mScopeEntry->mOffset = (S32)count;
+ mBody->mScopeEntry->mSize = 4;
+ count += mBody->mScopeEntry->mSize;
+ }
+ }
+ break;
+
+ case LSCP_EMIT_BYTE_CODE:
+ {
+#ifdef LSL_INCLUDE_DEBUG_INFO
+ char name[] = "http_request";
+ chunk->addBytes(name, strlen(name) + 1); /*Flawfinder: ignore*/
+ chunk->addBytes(mRequestId->mName, strlen(mRequestId->mName) + 1); /*Flawfinder: ignore*/
+ chunk->addBytes(mMethod->mName, strlen(mMethod->mName) + 1); /*Flawfinder: ignore*/
+ chunk->addBytes(mBody->mName, strlen(mBody->mName) + 1); /*Flawfinder: ignore*/
+#endif
+ }
+ break;
+ case LSCP_EMIT_CIL_ASSEMBLY:
+ fdotabs(fp, tabs, tabsize);
+ fprintf(fp, "http_request( valuetype [ScriptTypes]LindenLab.SecondLife.Key ");
+ mRequestId->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
+ fprintf(fp, ", string ");
+ mMethod->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
+ fprintf(fp, ", string ");
+ mBody->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
+ fprintf(fp, " )\n");
+ break;
+ default:
+ mRequestId->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
+ mMethod->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
+ mBody->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
+ break;
+ }
+}
+
+S32 LLScriptHTTPRequestEvent::getSize()
+{
+ // key + string + string = 12
+ return 12;
+}
void LLScriptMoneyEvent::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
{
@@ -9658,6 +9762,11 @@ void LLScriptEventHandler::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCom
mScopeEntry->mFunctionArgs.addType(LST_LIST);
mScopeEntry->mFunctionArgs.addType(LST_STRING);
break;
+ case LSTT_HTTP_REQUEST:
+ mScopeEntry->mFunctionArgs.addType(LST_KEY);
+ mScopeEntry->mFunctionArgs.addType(LST_STRING);
+ mScopeEntry->mFunctionArgs.addType(LST_STRING);
+ break;
default:
break;
diff --git a/indra/lscript/lscript_compile/lscript_tree.h b/indra/lscript/lscript_compile/lscript_tree.h
index 369d775e5d..12c16908af 100644
--- a/indra/lscript/lscript_compile/lscript_tree.h
+++ b/indra/lscript/lscript_compile/lscript_tree.h
@@ -759,12 +759,12 @@ class LLScriptHTTPResponseEvent : public LLScriptEvent
{
public:
LLScriptHTTPResponseEvent(S32 line, S32 col,
- LLScriptIdentifier *reqeust_id,
+ LLScriptIdentifier *request_id,
LLScriptIdentifier *status,
LLScriptIdentifier *metadata,
LLScriptIdentifier *body)
: LLScriptEvent(line, col, LSTT_HTTP_RESPONSE),
- mRequestId(reqeust_id), mStatus(status), mMetadata(metadata), mBody(body)
+ mRequestId(request_id), mStatus(status), mMetadata(metadata), mBody(body)
{
}
@@ -783,6 +783,32 @@ public:
LLScriptIdentifier *mBody;
};
+class LLScriptHTTPRequestEvent : public LLScriptEvent
+{
+public:
+ LLScriptHTTPRequestEvent(S32 line, S32 col,
+ LLScriptIdentifier *request_id,
+ LLScriptIdentifier *method,
+ LLScriptIdentifier *body)
+ : LLScriptEvent(line, col, LSTT_HTTP_REQUEST),
+ mRequestId(request_id), mMethod(method), mBody(body)
+ {
+ }
+
+ void recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass,
+ LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope,
+ LSCRIPTType &type, LSCRIPTType basetype, U64 &count,
+ LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap,
+ S32 stacksize, LLScriptScopeEntry *entry,
+ S32 entrycount, LLScriptLibData **ldata);
+
+ S32 getSize();
+
+ LLScriptIdentifier *mRequestId;
+ LLScriptIdentifier *mMethod;
+ LLScriptIdentifier *mBody;
+};
+
class LLScriptRezEvent : public LLScriptEvent
{
public:
diff --git a/indra/lscript/lscript_execute/CMakeLists.txt b/indra/lscript/lscript_execute/CMakeLists.txt
index f30915bab0..3a16ffdc01 100644
--- a/indra/lscript/lscript_execute/CMakeLists.txt
+++ b/indra/lscript/lscript_execute/CMakeLists.txt
@@ -12,6 +12,9 @@ include_directories(
)
set(lscript_execute_SOURCE_FILES
+ llscriptresource.cpp
+ llscriptresourceconsumer.cpp
+ llscriptresourcepool.cpp
lscript_execute.cpp
lscript_heapruntime.cpp
lscript_readlso.cpp
@@ -20,6 +23,9 @@ set(lscript_execute_SOURCE_FILES
set(lscript_execute_HEADER_FILES
CMakeLists.txt
+ ../llscriptresource.h
+ ../llscriptresourceconsumer.h
+ ../llscriptresourcepool.h
../lscript_execute.h
../lscript_rt_interface.h
lscript_heapruntime.h
diff --git a/indra/lscript/lscript_execute/llscriptresource.cpp b/indra/lscript/lscript_execute/llscriptresource.cpp
new file mode 100644
index 0000000000..cc802987b9
--- /dev/null
+++ b/indra/lscript/lscript_execute/llscriptresource.cpp
@@ -0,0 +1,86 @@
+/**
+ * @file llscriptresource.cpp
+ * @brief LLScriptResource class implementation for managing limited resources
+ *
+ * $LicenseInfo:firstyear=2008&license=internal$
+ *
+ * Copyright (c) 2008, Linden Research, Inc.
+ *
+ * The following source code is PROPRIETARY AND CONFIDENTIAL. Use of
+ * this source code is governed by the Linden Lab Source Code Disclosure
+ * Agreement ("Agreement") previously entered between you and Linden
+ * Lab. By accessing, using, copying, modifying or distributing this
+ * software, you acknowledge that you have been informed of your
+ * obligations under the Agreement and agree to abide by those obligations.
+ *
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#include "llscriptresource.h"
+#include "llerror.h"
+
+LLScriptResource::LLScriptResource()
+: mTotal(0),
+ mUsed(0)
+{
+}
+
+bool LLScriptResource::request(S32 amount /* = 1 */)
+{
+ if (mUsed + amount <= mTotal)
+ {
+ mUsed += amount;
+ return true;
+ }
+
+ return false;
+}
+
+bool LLScriptResource::release(S32 amount /* = 1 */)
+{
+ if (mUsed >= amount)
+ {
+ mUsed -= amount;
+ return true;
+ }
+
+ return false;
+}
+
+S32 LLScriptResource::getAvailable() const
+{
+ if (mUsed > mTotal)
+ {
+ // It is possible after a parcel ownership change for more than total to be used
+ // In this case the user of this class just wants to know
+ // whether or not they can use a resource
+ return 0;
+ }
+ return (mTotal - mUsed);
+}
+
+void LLScriptResource::setTotal(S32 amount)
+{
+ // This may cause this resource to be over spent
+ // such that more are in use than total allowed
+ // Until those resources are released getAvailable will return 0.
+ mTotal = amount;
+}
+
+S32 LLScriptResource::getTotal() const
+{
+ return mTotal;
+}
+
+S32 LLScriptResource::getUsed() const
+{
+ return mUsed;
+}
+
+bool LLScriptResource::isOverLimit() const
+{
+ return (mUsed > mTotal);
+}
diff --git a/indra/lscript/lscript_execute/llscriptresourceconsumer.cpp b/indra/lscript/lscript_execute/llscriptresourceconsumer.cpp
new file mode 100644
index 0000000000..6a5b28e257
--- /dev/null
+++ b/indra/lscript/lscript_execute/llscriptresourceconsumer.cpp
@@ -0,0 +1,101 @@
+/**
+ * @file llscriptresourceconsumer.cpp
+ * @brief An interface for a script resource consumer.
+ *
+ * $LicenseInfo:firstyear=2008&license=internal$
+ *
+ * Copyright (c) 2008, Linden Research, Inc.
+ *
+ * The following source code is PROPRIETARY AND CONFIDENTIAL. Use of
+ * this source code is governed by the Linden Lab Source Code Disclosure
+ * Agreement ("Agreement") previously entered between you and Linden
+ * Lab. By accessing, using, copying, modifying or distributing this
+ * software, you acknowledge that you have been informed of your
+ * obligations under the Agreement and agree to abide by those obligations.
+ *
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#include "llscriptresourceconsumer.h"
+
+#include "llscriptresourcepool.h"
+
+LLScriptResourceConsumer::LLScriptResourceConsumer()
+ : mScriptResourcePool(&LLScriptResourcePool::null)
+{ }
+
+// Get the resource pool this consumer is currently using.
+// virtual
+LLScriptResourcePool& LLScriptResourceConsumer::getScriptResourcePool()
+{
+ return *mScriptResourcePool;
+}
+
+// Get the resource pool this consumer is currently using.
+// virtual
+const LLScriptResourcePool& LLScriptResourceConsumer::getScriptResourcePool() const
+{
+ return *mScriptResourcePool;
+}
+
+// virtual
+void LLScriptResourceConsumer::setScriptResourcePool(LLScriptResourcePool& new_pool)
+{
+ mScriptResourcePool = &new_pool;
+}
+
+bool LLScriptResourceConsumer::switchScriptResourcePools(LLScriptResourcePool& new_pool)
+{
+ if (&new_pool == &LLScriptResourcePool::null)
+ {
+ llwarns << "New pool is null" << llendl;
+ }
+
+ if (isInPool(new_pool))
+ {
+ return true;
+ }
+
+ if (!canUseScriptResourcePool(new_pool))
+ {
+ return false;
+ }
+
+ S32 used_urls = getUsedPublicURLs();
+
+ getScriptResourcePool().getPublicURLResource().release( used_urls );
+ setScriptResourcePool(new_pool);
+ getScriptResourcePool().getPublicURLResource().request( used_urls );
+
+ return true;
+}
+
+bool LLScriptResourceConsumer::canUseScriptResourcePool(const LLScriptResourcePool& resource_pool)
+{
+ if (isInPool(resource_pool))
+ {
+ return true;
+ }
+
+ if (resource_pool.getPublicURLResource().getAvailable() < getUsedPublicURLs())
+ {
+ return false;
+ }
+
+ return true;
+}
+
+bool LLScriptResourceConsumer::isInPool(const LLScriptResourcePool& resource_pool)
+{
+ const LLScriptResourcePool& current_pool = getScriptResourcePool();
+ if ( &resource_pool == &current_pool )
+ {
+ // This consumer is already in this pool
+ return true;
+ }
+ return false;
+}
+
diff --git a/indra/lscript/lscript_execute/llscriptresourcepool.cpp b/indra/lscript/lscript_execute/llscriptresourcepool.cpp
new file mode 100644
index 0000000000..2ec67c87dd
--- /dev/null
+++ b/indra/lscript/lscript_execute/llscriptresourcepool.cpp
@@ -0,0 +1,39 @@
+/**
+ * @file llscriptresourcepool.cpp
+ * @brief Collection of limited script resources
+ *
+ * $LicenseInfo:firstyear=2002&license=internal$
+ *
+ * Copyright (c) 2002-2007, Linden Research, Inc.
+ *
+ * The following source code is PROPRIETARY AND CONFIDENTIAL. Use of
+ * this source code is governed by the Linden Lab Source Code Disclosure
+ * Agreement ("Agreement") previously entered between you and Linden
+ * Lab. By accessing, using, copying, modifying or distributing this
+ * software, you acknowledge that you have been informed of your
+ * obligations under the Agreement and agree to abide by those obligations.
+ *
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#include "llscriptresourcepool.h"
+
+LLScriptResourcePool LLScriptResourcePool::null;
+
+LLScriptResourcePool::LLScriptResourcePool()
+{
+
+}
+
+LLScriptResource& LLScriptResourcePool::getPublicURLResource()
+{
+ return mLSLPublicURLs;
+}
+
+const LLScriptResource& LLScriptResourcePool::getPublicURLResource() const
+{
+ return mLSLPublicURLs;
+}
diff --git a/indra/lscript/lscript_execute/lscript_execute.cpp b/indra/lscript/lscript_execute/lscript_execute.cpp
index daa17f371c..b2b54cdd7a 100644
--- a/indra/lscript/lscript_execute/lscript_execute.cpp
+++ b/indra/lscript/lscript_execute/lscript_execute.cpp
@@ -68,6 +68,12 @@ const char* LSCRIPTRunTimeFaultStrings[LSRF_EOF] = /*Flawfinder: ignore*/
void LLScriptExecuteLSL2::startRunning() {}
void LLScriptExecuteLSL2::stopRunning() {}
+const char* URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED";
+const char* URL_REQUEST_DENIED = "URL_REQUEST_DENIED";
+
+// HTTP Requests to LSL scripts will time out after 25 seconds.
+const U64 LSL_HTTP_REQUEST_TIMEOUT = 25 * USEC_PER_SEC;
+
LLScriptExecuteLSL2::LLScriptExecuteLSL2(LLFILE *fp)
{
U8 sizearray[4];
diff --git a/indra/lscript/lscript_execute/lscript_readlso.cpp b/indra/lscript/lscript_execute/lscript_readlso.cpp
index f45e64e5de..3b10cc67c1 100644
--- a/indra/lscript/lscript_execute/lscript_readlso.cpp
+++ b/indra/lscript/lscript_execute/lscript_readlso.cpp
@@ -625,6 +625,16 @@ void LLScriptLSOParse::printStates(LLFILE *fp)
bytestream2char(name, mRawData, event_offset, sizeof(name));
fprintf(fp, "\t\tstring %s\n", name);
break;
+ case LSTT_HTTP_REQUEST: // LSTT_HTTP_REQUEST
+ bytestream2char(name, mRawData, event_offset, sizeof(name));
+ fprintf(fp, "%s\n", name);
+ bytestream2char(name, mRawData, event_offset, sizeof(name));
+ fprintf(fp, "\t\tkey %s\n", name);
+ bytestream2char(name, mRawData, event_offset, sizeof(name));
+ fprintf(fp, "\t\tstring %s\n", name);
+ bytestream2char(name, mRawData, event_offset, sizeof(name));
+ fprintf(fp, "\t\tstring %s\n", name);
+ break;
default:
break;
}
diff --git a/indra/lscript/lscript_library/lscript_library.cpp b/indra/lscript/lscript_library/lscript_library.cpp
index 55ecbcf2a1..0342c97429 100644
--- a/indra/lscript/lscript_library/lscript_library.cpp
+++ b/indra/lscript/lscript_library/lscript_library.cpp
@@ -451,6 +451,12 @@ void LLScriptLibrary::init()
addFunction(new LLScriptLibraryFunction(10.f, 0.f, dummy_func, "llSHA1String", "s", "s", "string llSHA1String(string sr)\nPerforms a SHA1 security Hash. Returns a 40 character hex string."));
+ addFunction(new LLScriptLibraryFunction(10.f, 0.f, dummy_func, "llGetFreeURLs", "i", NULL, "integer llGetFreeURLs()\nreturns the available urls for the current script"));
+ addFunction(new LLScriptLibraryFunction(10.f, 0.f, dummy_func, "llRequestURL", "k", NULL, "key llRequestURL()\nRequests one HTTP:// url for use by this object\nTriggers an http_server event with results."));
+ addFunction(new LLScriptLibraryFunction(10.f, 0.f, dummy_func, "llRequestSecureURL", "k", NULL, "key llRequestSecureURL()\nRequests one HTTPS:// (SSL) url for use by this object\nTriggers an http_server event with results."));
+ addFunction(new LLScriptLibraryFunction(10.f, 0.f, dummy_func, "llReleaseURL", NULL, "s", "llReleaseURL(string url)\nReleases the specified URL, it will no longer be usable."));
+ addFunction(new LLScriptLibraryFunction(10.f, 0.f, dummy_func, "llHTTPResponse", NULL, "kis", "llHTTPResponse(key id, integer status, string body)\nResponds to request id with status and body."));
+ addFunction(new LLScriptLibraryFunction(10.f, 0.f, dummy_func, "llGetHTTPHeader", "s", "ks", "string llGetHTTPHeader(key id, string header)\nGet the value for header for request id."));
// energy, sleep, dummy_func, name, return type, parameters, help text, gods-only