Пример #1
0
        /// <summary>
        /// Start a new thread that is tracked by the watchdog timer
        /// </summary>
        /// <param name="start">The method that will be executed in a new thread</param>
        /// <param name="name">A name to give to the new thread</param>
        /// <param name="priority">Priority to run the thread at</param>
        /// <param name="isBackground">True to run this thread as a background
        /// thread, otherwise false</param>
        /// <param name="alarmIfTimeout">Trigger an alarm function is we have timed out</param>
        /// <param name="alarmMethod">
        /// Alarm method to call if alarmIfTimeout is true and there is a timeout.
        /// Normally, this will just return some useful debugging information.
        /// </param>
        /// <param name="timeout">Number of milliseconds to wait until we issue a warning about timeout.</param>
        /// <returns>The newly created Thread object</returns>
        public static Thread StartThread(
            ThreadStart start, string name, ThreadPriority priority, bool isBackground,
            bool alarmIfTimeout, Func <string> alarmMethod, int timeout)
        {
            Thread thread = new Thread(start);

            thread.Name         = name;
            thread.Priority     = priority;
            thread.IsBackground = isBackground;

            ThreadWatchdogInfo twi
                = new ThreadWatchdogInfo(thread, timeout)
                {
                AlarmIfTimeout = alarmIfTimeout, AlarmMethod = alarmMethod
                };

            m_log.DebugFormat(
                "[WATCHDOG]: Started tracking thread {0}, ID {1}", twi.Thread.Name, twi.Thread.ManagedThreadId);

            m_threads.Add(twi.Thread.ManagedThreadId, twi);

            thread.Start();

            return(thread);
        }
Пример #2
0
        /**********************************************
        * OpenXMLRPCChannel
        *
        * Generate a UUID channel key and add it and
        * the prim id to dictionary <channelUUID, primUUID>
        *
        * A custom channel key can be proposed.
        * Otherwise, passing UUID.Zero will generate
        * and return a random channel
        *
        * First check if there is a channel assigned for
        * this itemID.  If there is, then someone called
        * llOpenRemoteDataChannel twice.  Just return the
        * original channel.  Other option is to delete the
        * current channel and assign a new one.
        *
        * ********************************************/

        public UUID OpenXMLRPCChannel(uint localID, UUID itemID, UUID channelID)
        {
            UUID newChannel = UUID.Zero;

            //Is a dupe?
            try
            {
                m_openChannels.ForEach(delegate(RPCChannelInfo ci)
                {
                    if (ci.GetItemID().Equals(itemID))
                    {
                        // return the original channel ID for this item
                        throw new ThreadedClasses.ReturnValueException <UUID>(ci.GetChannelID());
                    }
                });
            }
            catch (ThreadedClasses.ReturnValueException <UUID> e)
            {
                return(e.Value);
            }

            newChannel = (channelID == UUID.Zero) ? UUID.Random() : channelID;
            RPCChannelInfo rpcChanInfo = new RPCChannelInfo(localID, itemID, newChannel);

            m_openChannels.Add(newChannel, rpcChanInfo);

            return(newChannel);
        }
Пример #3
0
        // -----------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        // -----------------------------------------------------------------
        public bool CreateStore(string value, ref UUID result)
        {
            if (result == UUID.Zero)
            {
                result = UUID.Random();
            }

            JsonStore map = null;

            if (!m_enabled)
            {
                return(false);
            }


            try
            {
                map = new JsonStore(value);
            }
            catch (Exception)
            {
                m_log.ErrorFormat("[JsonStore]: Unable to initialize store from {0}", value);
                return(false);
            }

            m_JsonValueStore.Add(result, map);

            return(true);
        }
Пример #4
0
 private void CreateGroupChatSessionTracking(UUID groupID)
 {
     if (!m_groupsAgentsDroppedFromChatSession.ContainsKey(groupID))
     {
         m_groupsAgentsDroppedFromChatSession.Add(groupID, new ThreadedClasses.RwLockedList <string>());
         m_groupsAgentsInvitedToChatSession.Add(groupID, new ThreadedClasses.RwLockedList <string>());
     }
 }
Пример #5
0
        public XmlRpcResponse XmlRpcRemoteData(XmlRpcRequest request, IPEndPoint remoteClient)
        {
            XmlRpcResponse response = new XmlRpcResponse();

            Hashtable requestData = (Hashtable)request.Params[0];
            bool      GoodXML     = (requestData.Contains("Channel") && requestData.Contains("IntValue") &&
                                     requestData.Contains("StringValue"));

            if (GoodXML)
            {
                UUID           channel = new UUID((string)requestData["Channel"]);
                RPCChannelInfo rpcChanInfo;
                if (m_openChannels.TryGetValue(channel, out rpcChanInfo))
                {
                    string intVal = Convert.ToInt32(requestData["IntValue"]).ToString();
                    string strVal = (string)requestData["StringValue"];

                    RPCRequestInfo rpcInfo;

                    rpcInfo =
                        new RPCRequestInfo(rpcChanInfo.GetLocalID(), rpcChanInfo.GetItemID(), channel, strVal,
                                           intVal);
                    m_rpcPending.Add(rpcInfo.GetMessageID(), rpcInfo);

                    int timeoutCtr = 0;

                    while (!rpcInfo.IsProcessed() && (timeoutCtr < RemoteReplyScriptTimeout))
                    {
                        Thread.Sleep(RemoteReplyScriptWait);
                        timeoutCtr += RemoteReplyScriptWait;
                    }
                    if (rpcInfo.IsProcessed())
                    {
                        Hashtable param = new Hashtable();
                        param["StringValue"] = rpcInfo.GetStrRetval();
                        param["IntValue"]    = rpcInfo.GetIntRetval();

                        ArrayList parameters = new ArrayList();
                        parameters.Add(param);

                        response.Value = parameters;
                        rpcInfo        = null;
                    }
                    else
                    {
                        response.SetFault(-1, "Script timeout");
                        rpcInfo = null;
                    }
                }
                else
                {
                    response.SetFault(-1, "Invalid channel");
                }
            }

            return(response);
        }
Пример #6
0
        public void RemoveCompletedRequest(UUID id)
        {
            RPCRequestInfo tmp;

            if (m_rpcPending.Remove(id, out tmp))
            {
                m_rpcPendingResponses.Add(id, tmp);
            }
        }
Пример #7
0
        public UUID SendRemoteData(uint localID, UUID itemID, string channel, string dest, int idata, string sdata)
        {
            SendRemoteDataRequest req = new SendRemoteDataRequest(
                localID, itemID, channel, dest, idata, sdata
                );

            m_pendingSRDResponses.Add(req.GetReqID(), req);
            req.Process();
            return(req.ReqID);
        }
Пример #8
0
 /// <summary>
 /// Register an Module interface.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="iface"></param>
 public void RegisterInterface <T>(T iface)
 {
     try
     {
         m_moduleInterfaces.Add(typeof(T), iface);
     }
     catch
     {
     }
 }
Пример #9
0
 /// <summary>
 /// Can be called from other modules.
 /// </summary>
 /// <param name="scene"></param>
 public void Init(Scene scene)
 {
     try
     {
         m_scenes.Add(scene.RegionInfo.RegionID, scene);
     }
     catch
     {
         m_log.WarnFormat(
             "[LOCAL SIMULATION CONNECTOR]: Tried to add region {0} but it is already present",
             scene.RegionInfo.RegionName);
     }
 }
Пример #10
0
        // -----------------------------------------------------------------
        /// <summary>
        /// </summary>
        // -----------------------------------------------------------------
        public void AddRegion(Scene scene)
        {
            if (m_enabled)
            {
                m_scene = scene;
                m_scene.RegisterModuleInterface <IJsonStoreModule>(this);

                m_sharedStore    = UUID.Zero;
                m_JsonValueStore = new ThreadedClasses.RwLockedDictionary <UUID, JsonStore>();
                m_JsonValueStore.Add(m_sharedStore, new JsonStore(""));

                scene.EventManager.OnObjectBeingRemovedFromScene += EventManagerOnObjectBeingRemovedFromScene;
            }
        }
Пример #11
0
        private string ChannelUri(Scene scene, LandData land)
        {
            string channelUri = null;

            string landUUID;
            string landName;

            // Create parcel voice channel. If no parcel exists, then the voice channel ID is the same
            // as the directory ID. Otherwise, it reflects the parcel's ID.

            string parcelAddress;

            if (m_ParcelAddress.TryGetValue(land.GlobalID.ToString(), out parcelAddress))
            {
                m_log.DebugFormat("[FreeSwitchVoice]: parcel id {0}: using sip address {1}",
                                  land.GlobalID, parcelAddress);
                return(parcelAddress);
            }

            if (land.LocalID != 1 && (land.Flags & (uint)ParcelFlags.UseEstateVoiceChan) == 0)
            {
                landName = String.Format("{0}:{1}", scene.RegionInfo.RegionName, land.Name);
                landUUID = land.GlobalID.ToString();
                m_log.DebugFormat("[FreeSwitchVoice]: Region:Parcel \"{0}\": parcel id {1}: using channel name {2}",
                                  landName, land.LocalID, landUUID);
            }
            else
            {
                landName = String.Format("{0}:{1}", scene.RegionInfo.RegionName, scene.RegionInfo.RegionName);
                landUUID = scene.RegionInfo.RegionID.ToString();
                m_log.DebugFormat("[FreeSwitchVoice]: Region:Parcel \"{0}\": parcel id {1}: using channel name {2}",
                                  landName, land.LocalID, landUUID);
            }

            // slvoice handles the sip address differently if it begins with confctl, hiding it from the user in the friends list. however it also disables
            // the personal speech indicators as well unless some siren14-3d codec magic happens. we dont have siren143d so we'll settle for the personal speech indicator.
            channelUri = String.Format("sip:conf-{0}@{1}", "x" + Convert.ToBase64String(Encoding.ASCII.GetBytes(landUUID)), m_freeSwitchRealm);

            try
            {
                m_ParcelAddress.Add(land.GlobalID.ToString(), channelUri);
            }
            catch
            {
            }

            return(channelUri);
        }
Пример #12
0
        void IRegionModuleBase.AddRegion(Scene scene)
        {
            if (!Enabled)
            {
                return;
            }

            try
            {
                regions.Add(scene.RegionInfo.RegionID, scene);
            }
            catch
            {
                m_log.ErrorFormat("[LOCAL USERPROFILES SERVICE CONNECTOR]: simulator seems to have more than one region with the same UUID. Please correct this!");
            }
        }
Пример #13
0
        public void Cache(UUID userID, AssetType type, InventoryFolderBase folder)
        {
            ThreadedClasses.RwLockedDictionary <AssetType, InventoryFolderBase> ff = null;
            ff = m_FolderTypes.GetOrAdd(userID, delegate()
            {
                return(new ThreadedClasses.RwLockedDictionary <AssetType, InventoryFolderBase>());
            }, CACHE_EXPIRATION_SECONDS);

            try
            {
                ff.Add(type, folder);
            }
            catch
            {
            }
        }
Пример #14
0
        public void AddRegion(Scene scene)
        {
            if (!m_Enabled)
            {
                return;
            }

            // It's a go!

            // Claim the interface slot
            scene.RegisterModuleInterface <IEmailModule>(this);

            // Add to scene list
            m_Scenes.Add(scene.RegionInfo.RegionHandle, scene);

            m_log.Info("[EMAIL] Activated DefaultEmailModule");
        }
Пример #15
0
        public void CreateFromData(uint localID, UUID itemID, UUID objectID,
                                   Object[] data)
        {
            int idx = 0;

            while (idx < data.Length)
            {
                TimerInfo ts = new TimerInfo();

                ts.localID  = localID;
                ts.itemID   = itemID;
                ts.interval = (long)data[idx];
                ts.next     = DateTime.Now.Ticks + (long)data[idx + 1];
                idx        += 2;

                Timers.Add(MakeTimerKey(localID, itemID), ts);
            }
        }
Пример #16
0
        public void RegisterPollHandler(string capName, PollServiceEventArgs pollServiceHandler)
        {
//            m_log.DebugFormat(
//                "[CAPS]: Registering handler with name {0}, url {1} for {2}",
//                capName, pollServiceHandler.Url, m_agentID, m_regionName);

            m_pollServiceHandlers.Add(capName, pollServiceHandler);

            m_httpListener.AddPollServiceHTTPHandler(pollServiceHandler.Url, pollServiceHandler);

//            uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port;
//            string protocol = "http";
//            string hostName = m_httpListenerHostName;
//
//            if (MainServer.Instance.UseSSL)
//            {
//                hostName = MainServer.Instance.SSLCommonName;
//                port = MainServer.Instance.SSLPort;
//                protocol = "https";
//            }

//            RegisterHandler(
//                capName, String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, pollServiceHandler.Url));
        }
Пример #17
0
        /// <summary>
        /// Operation to for a region module to register a constant to be used
        /// by the script engine
        /// </summary>
        public void RegisterConstant(string cname, object value)
        {
//            m_log.DebugFormat("[MODULE COMMANDS] register constant <{0}> with value {1}",cname,value.ToString());
            m_constants.Add(cname, value);
        }
Пример #18
0
 /// <summary>
 /// Register an external handler. The service for this capability is somewhere else
 /// given by the URL.
 /// </summary>
 /// <param name="capsName"></param>
 /// <param name="url"></param>
 public void RegisterHandler(string capsName, string url)
 {
     m_externalCapsHandlers.Add(capsName, url);
 }
Пример #19
0
        public UUID StartHttpRequest(uint localID, UUID itemID, string url, List <string> parameters, Dictionary <string, string> headers, string body)
        {
            UUID             reqID = UUID.Random();
            HttpRequestClass htc   = new HttpRequestClass();

            // Partial implementation: support for parameter flags needed
            //   see http://wiki.secondlife.com/wiki/LlHTTPRequest
            //
            // Parameters are expected in {key, value, ... , key, value}
            if (parameters != null)
            {
                string[] parms = parameters.ToArray();
                for (int i = 0; i < parms.Length; i += 2)
                {
                    switch (Int32.Parse(parms[i]))
                    {
                    case (int)HttpRequestConstants.HTTP_METHOD:

                        htc.HttpMethod = parms[i + 1];
                        break;

                    case (int)HttpRequestConstants.HTTP_MIMETYPE:

                        htc.HttpMIMEType = parms[i + 1];
                        break;

                    case (int)HttpRequestConstants.HTTP_BODY_MAXLENGTH:

                        // TODO implement me
                        break;

                    case (int)HttpRequestConstants.HTTP_VERIFY_CERT:
                        htc.HttpVerifyCert = (int.Parse(parms[i + 1]) != 0);
                        break;

                    case (int)HttpRequestConstants.HTTP_VERBOSE_THROTTLE:

                        // TODO implement me
                        break;

                    case (int)HttpRequestConstants.HTTP_CUSTOM_HEADER:
                        //Parameters are in pairs and custom header takes
                        //arguments in pairs so adjust for header marker.
                        ++i;

                        //Maximum of 8 headers are allowed based on the
                        //Second Life documentation for llHTTPRequest.
                        for (int count = 1; count <= 8; ++count)
                        {
                            //Not enough parameters remaining for a header?
                            if (parms.Length - i < 2)
                            {
                                break;
                            }

                            //Have we reached the end of the list of headers?
                            //End is marked by a string with a single digit.
                            //We already know we have at least one parameter
                            //so it is safe to do this check at top of loop.
                            if (Char.IsDigit(parms[i][0]))
                            {
                                break;
                            }

                            if (htc.HttpCustomHeaders == null)
                            {
                                htc.HttpCustomHeaders = new List <string>();
                            }

                            htc.HttpCustomHeaders.Add(parms[i]);
                            htc.HttpCustomHeaders.Add(parms[i + 1]);

                            i += 2;
                        }
                        break;

                    case (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE:
                        htc.HttpPragmaNoCache = (int.Parse(parms[i + 1]) != 0);
                        break;
                    }
                }
            }

            htc.LocalID         = localID;
            htc.ItemID          = itemID;
            htc.Url             = url;
            htc.ReqID           = reqID;
            htc.HttpTimeout     = httpTimeout;
            htc.OutboundBody    = body;
            htc.ResponseHeaders = headers;
            htc.proxyurl        = m_proxyurl;
            htc.proxyexcepts    = m_proxyexcepts;

            m_pendingRequests.Add(reqID, htc);

            htc.Process();

            return(reqID);
        }
Пример #20
0
        public void HttpRequestHandler(UUID requestID, Hashtable request)
        {
            string uri    = request["uri"].ToString();
            bool   is_ssl = uri.Contains("lslhttps");

            try
            {
                Hashtable headers = (Hashtable)request["headers"];

//                    string uri_full = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/";

                int    pos1    = uri.IndexOf("/");           // /lslhttp
                int    pos2    = uri.IndexOf("/", pos1 + 1); // /lslhttp/
                int    pos3    = uri.IndexOf("/", pos2 + 1); // /lslhttp/<UUID>/
                string uri_tmp = uri.Substring(0, pos3 + 1);
                //HTTP server code doesn't provide us with QueryStrings
                string pathInfo;
                string queryString;
                queryString = "";

                pathInfo = uri.Substring(pos3);

                UrlData urlData = null;

                string url;

                if (is_ssl)
                {
                    url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp;
                }
                else
                {
                    url = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp;
                }

                // Avoid a race - the request URL may have been released via llRequestUrl() whilst this
                // request was being processed.
                if (!m_UrlMap.TryGetValue(url, out urlData))
                {
                    return;
                }

                //for llGetHttpHeader support we need to store original URI here
                //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers
                //as per http://wiki.secondlife.com/wiki/LlGetHTTPHeader

                RequestData requestData = new RequestData();
                requestData.requestID   = requestID;
                requestData.requestDone = false;
                requestData.startTime   = System.Environment.TickCount;
                requestData.uri         = uri;
                if (requestData.headers == null)
                {
                    requestData.headers = new Dictionary <string, string>();
                }

                foreach (DictionaryEntry header in headers)
                {
                    string key   = (string)header.Key;
                    string value = (string)header.Value;
                    requestData.headers.Add(key, value);
                }

                foreach (DictionaryEntry de in request)
                {
                    if (de.Key.ToString() == "querystringkeys")
                    {
                        System.String[] keys = (System.String[])de.Value;
                        foreach (String key in keys)
                        {
                            if (request.ContainsKey(key))
                            {
                                string val = (String)request[key];
                                queryString = queryString + key + "=" + val + "&";
                            }
                        }

                        if (queryString.Length > 1)
                        {
                            queryString = queryString.Substring(0, queryString.Length - 1);
                        }
                    }
                }

                //if this machine is behind DNAT/port forwarding, currently this is being
                //set to address of port forwarding router
                requestData.headers["x-remote-ip"]    = requestData.headers["remote_addr"];
                requestData.headers["x-path-info"]    = pathInfo;
                requestData.headers["x-query-string"] = queryString;
                requestData.headers["x-script-url"]   = urlData.url;

                urlData.requests.Add(requestID, requestData);
                m_RequestMap.Add(requestID, urlData);

                urlData.engine.PostScriptEvent(
                    urlData.itemID,
                    "http_request",
                    new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() });
            }
            catch (Exception we)
            {
                //Hashtable response = new Hashtable();
                m_log.Warn("[HttpRequestHandler]: http-in request failed");
                m_log.Warn(we.Message);
                m_log.Warn(we.StackTrace);
            }
        }
Пример #21
0
 /// <summary>
 /// Register a module commander.
 /// </summary>
 /// <param name="commander"></param>
 public void RegisterModuleCommander(ICommander commander)
 {
     m_moduleCommanders.Add(commander.Name, commander);
 }
Пример #22
0
        // -----------------------------------------------------------------
        /// <summary>
        /// </summary>
        // -----------------------------------------------------------------
        public void AddRegion(Scene scene)
        {
            if (m_enabled)
            {
                m_scene = scene;
                m_scene.RegisterModuleInterface<IJsonStoreModule>(this);

                m_sharedStore = UUID.Zero;
                m_JsonValueStore = new ThreadedClasses.RwLockedDictionary<UUID, JsonStore>();
                m_JsonValueStore.Add(m_sharedStore,new JsonStore(""));

                scene.EventManager.OnObjectBeingRemovedFromScene += EventManagerOnObjectBeingRemovedFromScene;
            }
        }
Пример #23
0
        public void Add(string ns, string objName, object dynObj)
        {
            DAMap.ValidateNamespace(ns);

            m_map.Add(objName, dynObj);
        }