aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared
diff options
context:
space:
mode:
authorSignpostMarv2012-10-23 15:42:16 +0100
committerJustin Clark-Casey (justincc)2012-10-26 02:08:00 +0100
commite977761071a2d614a9a621437fbf86479b414759 (patch)
tree3d9e6a65c9462ca8f6439184887a632dc041eb27 /OpenSim/Region/ScriptEngine/Shared
parentFormatting and casing correction in WorldCommModule, trailing new line in OSS... (diff)
downloadopensim-SC-e977761071a2d614a9a621437fbf86479b414759.zip
opensim-SC-e977761071a2d614a9a621437fbf86479b414759.tar.gz
opensim-SC-e977761071a2d614a9a621437fbf86479b414759.tar.bz2
opensim-SC-e977761071a2d614a9a621437fbf86479b414759.tar.xz
adding ability for listeners to be filtered by regular expressions and a general-purpose function to see if a given string matches a given regex
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs63
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs24
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs10
4 files changed, 107 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 0650b90..828288d 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3647,5 +3647,68 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3647 3647
3648 DropAttachmentAt(false, pos, rot); 3648 DropAttachmentAt(false, pos, rot);
3649 } 3649 }
3650
3651 public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
3652 {
3653 CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
3654 m_host.AddScriptLPS(1);
3655 UUID keyID;
3656 UUID.TryParse(ID, out keyID);
3657
3658 // if we want the name to be used as a regular expression, ensure it is valid first.
3659 if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_NAME) == ScriptBaseClass.OS_LISTEN_REGEX_NAME)
3660 {
3661 try
3662 {
3663 Regex.IsMatch("", name);
3664 }
3665 catch (Exception)
3666 {
3667 OSSLShoutError("Name regex is invalid.");
3668 return -1;
3669 }
3670 }
3671
3672 // if we want the msg to be used as a regular expression, ensure it is valid first.
3673 if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) == ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE)
3674 {
3675 try
3676 {
3677 Regex.IsMatch("", msg);
3678 }
3679 catch (Exception)
3680 {
3681 OSSLShoutError("Message regex is invalid.");
3682 return -1;
3683 }
3684 }
3685
3686 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
3687 return (wComm == null) ? -1 : wComm.Listen(
3688 m_host.LocalId,
3689 m_item.ItemID,
3690 m_host.UUID,
3691 channelID,
3692 name,
3693 keyID,
3694 msg,
3695 regexBitfield
3696 );
3697 }
3698
3699 public LSL_Integer osRegexIsMatch(string input, string pattern)
3700 {
3701 CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch");
3702 m_host.AddScriptLPS(1);
3703 try
3704 {
3705 return Regex.IsMatch(input, pattern) ? 1 : 0;
3706 }
3707 catch (Exception)
3708 {
3709 OSSLShoutError("Possible invalid regular expression detected.");
3710 return 0;
3711 }
3712 }
3650 } 3713 }
3651} 3714}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 93188c9..cdd9ea8 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -418,5 +418,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
418 /// <param name="pos"></param> 418 /// <param name="pos"></param>
419 /// <param name="rot"></param> 419 /// <param name="rot"></param>
420 void osForceDropAttachmentAt(vector pos, rotation rot); 420 void osForceDropAttachmentAt(vector pos, rotation rot);
421
422 /// <summary>
423 /// Identical to llListen except for a bitfield which indicates which
424 /// string parameters should be parsed as regex patterns.
425 /// </summary>
426 /// <param name="channelID"></param>
427 /// <param name="name"></param>
428 /// <param name="ID"></param>
429 /// <param name="msg"></param>
430 /// <param name="regexBitfield">
431 /// OS_LISTEN_REGEX_NAME
432 /// OS_LISTEN_REGEX_MESSAGE
433 /// </param>
434 /// <returns></returns>
435 LSL_Integer osListenRegex(int channelID, string name, string ID,
436 string msg, int regexBitfield);
437
438 /// <summary>
439 /// Wraps to bool Regex.IsMatch(string input, string pattern)
440 /// </summary>
441 /// <param name="input">string to test for match</param>
442 /// <param name="regex">string to use as pattern</param>
443 /// <returns>boolean</returns>
444 LSL_Integer osRegexIsMatch(string input, string pattern);
421 } 445 }
422} 446}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index 62bd6b8..880841b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -716,5 +716,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
716 public static readonly LSLInteger RCERR_UNKNOWN = -1; 716 public static readonly LSLInteger RCERR_UNKNOWN = -1;
717 public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2; 717 public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2;
718 public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 3; 718 public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 3;
719
720 /// <summary>
721 /// process name parameter as regex
722 /// </summary>
723 public const int OS_LISTEN_REGEX_NAME = 0x1;
724
725 /// <summary>
726 /// process message parameter as regex
727 /// </summary>
728 public const int OS_LISTEN_REGEX_MESSAGE = 0x2;
719 } 729 }
720} 730}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index dee1b28..afa9ae0 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -992,5 +992,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
992 { 992 {
993 m_OSSL_Functions.osForceDropAttachmentAt(pos, rot); 993 m_OSSL_Functions.osForceDropAttachmentAt(pos, rot);
994 } 994 }
995
996 public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
997 {
998 return m_OSSL_Functions.osListenRegex(channelID, name, ID, msg, regexBitfield);
999 }
1000
1001 public LSL_Integer osRegexIsMatch(string input, string pattern)
1002 {
1003 return m_OSSL_Functions.osRegexIsMatch(input, pattern);
1004 }
995 } 1005 }
996} 1006}