Aurora.ScriptEngine.AuroraDotNetEngine.APIs.LSL_Api.llHTTPRequest C# (CSharp) Method

llHTTPRequest() public method

public llHTTPRequest ( string url, Aurora.ScriptEngine.AuroraDotNetEngine.LSL_Types.list parameters, string body ) : Aurora.ScriptEngine.AuroraDotNetEngine.LSL_Types.LSLString
url string
parameters Aurora.ScriptEngine.AuroraDotNetEngine.LSL_Types.list
body string
return Aurora.ScriptEngine.AuroraDotNetEngine.LSL_Types.LSLString
        public LSL_String llHTTPRequest(string url, LSL_List parameters, string body)
        {
            // Partial implementation: support for parameter flags needed
            //   see http://wiki.secondlife.com/wiki/LlHTTPRequest
            // parameter flags support are implemented in ScriptsHttpRequests.cs
            //   in StartHttpRequest

            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID)) return "";

            IHttpRequestModule httpScriptMod =
                World.RequestModuleInterface<IHttpRequestModule>();
#if (!ISWIN)
            List<string> param = new List<string>();
            foreach (object o in parameters.Data)
                param.Add(o.ToString());
#else
            List<string> param = parameters.Data.Select(o => o.ToString()).ToList();
#endif

            Vector3 position = m_host.AbsolutePosition;
            Vector3 velocity = m_host.Velocity;
            Quaternion rotation = m_host.RotationOffset;
            string ownerName = String.Empty;
            IScenePresence scenePresence = World.GetScenePresence(m_host.OwnerID);
            ownerName = scenePresence == null ? resolveName(m_host.OwnerID) : scenePresence.Name;

            RegionInfo regionInfo = World.RegionInfo;

            Dictionary<string, string> httpHeaders = new Dictionary<string, string>();

            string shard = "OpenSim";
            IConfigSource config = m_ScriptEngine.ConfigSource;
            if (config.Configs["LSLRemoting"] != null)
                shard = config.Configs["LSLRemoting"].GetString("shard", shard);

            httpHeaders["X-SecondLife-Shard"] = shard;
            httpHeaders["X-SecondLife-Object-Name"] = m_host.Name;
            httpHeaders["X-SecondLife-Object-Key"] = m_host.UUID.ToString();
            httpHeaders["X-SecondLife-Region"] = string.Format("{0} ({1}, {2})", regionInfo.RegionName, regionInfo.RegionLocX, regionInfo.RegionLocY);
            httpHeaders["X-SecondLife-Local-Position"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", position.X, position.Y, position.Z);
            httpHeaders["X-SecondLife-Local-Velocity"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000})", velocity.X, velocity.Y, velocity.Z);
            httpHeaders["X-SecondLife-Local-Rotation"] = string.Format("({0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000})", rotation.X, rotation.Y, rotation.Z, rotation.W);
            httpHeaders["X-SecondLife-Owner-Name"] = ownerName;
            httpHeaders["X-SecondLife-Owner-Key"] = m_host.OwnerID.ToString();
            string userAgent = "";
            if (config.Configs["LSLRemoting"] != null)
                userAgent = config.Configs["LSLRemoting"].GetString("user_agent", null);

            if (userAgent != null)
                httpHeaders["User-Agent"] = userAgent;

            const string authregex = @"^(https?:\/\/)(\w+):(\w+)@(.*)$";
            Regex r = new Regex(authregex);
            Match m = r.Match(url);
            if (m.Success)
            {
                //for (int i = 1; i < gnums.Length; i++) {
                //    //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
                //    //CaptureCollection cc = g.Captures;
                //}
                if (m.Groups.Count == 5)
                {
                    httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
                    url = m.Groups[1].ToString() + m.Groups[4];
                }
            }

            UUID reqID = httpScriptMod.
                StartHttpRequest(m_host.UUID, m_itemID, url, param, httpHeaders, body);

            if (reqID != UUID.Zero)
                return reqID.ToString();
            else
                return new LSL_String("");
        }
LSL_Api