Exemple #1
0
        /// <summary>
        /// Handles the <see cref="NotifyReceived"/> event
        /// </summary>
        /// <param name="notification">The <see cref="Notification"/> that was received</param>
        /// <param name="callbackInfo">The <see cref="CallbackInfo"/> for the notification</param>
        /// <param name="requestInfo">The <see cref="RequestInfo"/> associated with the request</param>
        /// <returns><see cref="Response"/></returns>
        protected virtual Response OnNotifyReceived(Notification notification, CallbackInfo callbackInfo, RequestInfo requestInfo)
        {
            LogInfo("NOTIFICATION RECEIVED: {0}", notification.Name);

            Response response = new Response(ErrorCode.INTERNAL_SERVER_ERROR, ErrorDescription.INTERNAL_SERVER_ERROR);

            if (this.NotifyReceived != null)
            {
                response = this.NotifyReceived(notification, callbackInfo, requestInfo);
            }
            return(response);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MessageHandler"/> class.
        /// </summary>
        /// <param name="serverName">Name of the server</param>
        /// <param name="passwordManager">A list of valid passwords</param>
        /// <param name="passwordRequired">Indicates if the request must contain a password</param>
        /// <param name="logFolder">The path to the folder where log files are written</param>
        /// <param name="loggingEnabled">Indicates if logging is enabled or not</param>
        /// <param name="allowNetworkNotifications">Indicates if notifications from remote machines are allowed</param>
        /// <param name="allowBrowserConnections">Indicates if notifications from browsers are allowed</param>
        /// <param name="allowSubscriptions">Indicates if clients are allowed to subscribe to notifications from this server</param>
        public MessageHandler(string serverName, PasswordManager passwordManager, bool passwordRequired, string logFolder, bool loggingEnabled, bool allowNetworkNotifications, bool allowBrowserConnections, bool allowSubscriptions)
        {
            this.serverName                = serverName;
            this.passwordManager           = passwordManager;
            this.passwordRequired          = passwordRequired;
            this.logFolder                 = logFolder;
            this.loggingEnabled            = loggingEnabled;
            this.allowNetworkNotifications = allowNetworkNotifications;
            this.allowBrowserConnections   = allowBrowserConnections;
            this.allowSubscriptions        = allowSubscriptions;

            this.serverName   = serverName;
            this.callbackInfo = new CallbackInfo();
            this.requestInfo  = new RequestInfo();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GNTPParser"/> class.
        /// </summary>
        /// <param name="passwordManager">The <see cref="PasswordManager"/> containing a list of allowed passwords</param>
        /// <param name="passwordRequired">Indicates if a password is required</param>
        /// <param name="allowNetworkNotifications">Indicates if network requests are allowed</param>
        /// <param name="allowBrowserConnections">Indicates if browser requests are allowed</param>
        /// <param name="allowSubscriptions">Indicates if SUBSCRIPTION requests are allowed</param>
        /// <param name="requestInfo">The <see cref="RequestInfo"/> associated with this request</param>
        public GNTPParser(PasswordManager passwordManager, bool passwordRequired, bool allowNetworkNotifications, bool allowBrowserConnections, bool allowSubscriptions, RequestInfo requestInfo)
        {
            this.passwordManager           = passwordManager;
            this.passwordRequired          = passwordRequired;
            this.allowNetworkNotifications = allowNetworkNotifications;
            this.allowBrowserConnections   = allowBrowserConnections;
            this.allowSubscriptions        = allowSubscriptions;
            this.requestInfo = requestInfo;

            this.alreadyReceived             = new StringBuilder();
            this.headers                     = new HeaderCollection();
            this.notificationsToBeRegistered = new List <HeaderCollection>();
            this.pointers                    = new List <Pointer>();
            this.callbackInfo                = new CallbackInfo();
        }
Exemple #4
0
        /// <summary>
        /// Writes back the GNTP response to the requesting application
        /// </summary>
        /// <param name="cbInfo">The <see cref="CallbackInfo"/> associated with the response</param>
        /// <param name="response">The <see cref="Response"/> to be written back</param>
        public void WriteResponse(CallbackInfo cbInfo, Response response)
        {
            if (!cbInfo.AlreadyResponded)
            {
                cbInfo.AlreadyResponded = true;
                MessageHandler mh           = cbInfo.MessageHandler;
                GNTPRequest    request      = mh.Request;
                ResponseType   responseType = ResponseType.ERROR;
                if (response != null)
                {
                    if (response.IsCallback)
                    {
                        responseType = ResponseType.CALLBACK;
                    }
                    else if (response.IsOK)
                    {
                        responseType = ResponseType.OK;
                    }
                }
                else
                {
                    response = new Response(ErrorCode.INTERNAL_SERVER_ERROR, ErrorDescription.INTERNAL_SERVER_ERROR);
                }

                if (cbInfo.AdditionalInfo != null)
                {
                    foreach (KeyValuePair <string, string> item in cbInfo.AdditionalInfo)
                    {
                        response.CustomTextAttributes.Add(item.Key, item.Value);
                    }
                }

                AddServerHeaders(response);
                MessageBuilder   mb = new MessageBuilder(responseType);
                HeaderCollection responseHeaders = response.ToHeaders();
                foreach (Header header in responseHeaders)
                {
                    mb.AddHeader(header);
                }
                // return any application-specific data headers that were received
                RequestData rd = RequestData.FromHeaders(request.Headers);
                AddRequestData(mb, rd);

                mh.WriteResponse(mb, true);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GNTPParser"/> class.
        /// </summary>
        /// <param name="passwordManager">The <see cref="PasswordManager"/> containing a list of allowed passwords</param>
        /// <param name="passwordRequired">Indicates if a password is required</param>
        /// <param name="allowNetworkNotifications">Indicates if network requests are allowed</param>
        /// <param name="allowBrowserConnections">Indicates if browser requests are allowed</param>
        /// <param name="allowSubscriptions">Indicates if SUBSCRIPTION requests are allowed</param>
        /// <param name="requestInfo">The <see cref="RequestInfo"/> associated with this request</param>
        public GNTPParser2(PasswordManager passwordManager, bool passwordRequired, bool allowNetworkNotifications, bool allowBrowserConnections, bool allowSubscriptions, RequestInfo requestInfo)
        {
            this.passwordManager           = passwordManager;
            this.passwordRequired          = passwordRequired;
            this.allowNetworkNotifications = allowNetworkNotifications;
            this.allowBrowserConnections   = allowBrowserConnections;
            this.allowSubscriptions        = allowSubscriptions;
            this.requestInfo = requestInfo;

            this.alreadyReceived             = new StringBuilder();
            this.headers                     = new HeaderCollection();
            this.notificationsToBeRegistered = new List <HeaderCollection>();
            this.pointers                    = new List <Pointer>();
            this.callbackInfo                = new CallbackInfo();

            ms            = new MemoryStream();
            gntpReader    = new GNTPStreamReader(ms);
            buffer        = new List <byte>();
            nextIndicator = AsyncSocket.CRLFData;
            tag           = GNTP_IDENTIFIER_TAG;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GNTPParser"/> class.
        /// </summary>
        /// <param name="passwordManager">The <see cref="PasswordManager"/> containing a list of allowed passwords</param>
        /// <param name="passwordRequired">Indicates if a password is required</param>
        /// <param name="allowNetworkNotifications">Indicates if network requests are allowed</param>
        /// <param name="allowBrowserConnections">Indicates if browser requests are allowed</param>
        /// <param name="allowSubscriptions">Indicates if SUBSCRIPTION requests are allowed</param>
        /// <param name="requestInfo">The <see cref="RequestInfo"/> associated with this request</param>
        public GNTPParser2(PasswordManager passwordManager, bool passwordRequired, bool allowNetworkNotifications, bool allowBrowserConnections, bool allowSubscriptions, RequestInfo requestInfo)
        {
            this.passwordManager = passwordManager;
            this.passwordRequired = passwordRequired;
            this.allowNetworkNotifications = allowNetworkNotifications;
            this.allowBrowserConnections = allowBrowserConnections;
            this.allowSubscriptions = allowSubscriptions;
            this.requestInfo = requestInfo;

            this.alreadyReceived = new StringBuilder();
            this.headers = new HeaderCollection();
            this.notificationsToBeRegistered = new List<HeaderCollection>();
            this.pointers = new List<Pointer>();
            this.callbackInfo = new CallbackInfo();

            ms = new MemoryStream();
            gntpReader = new GNTPStreamReader(ms);
            buffer = new List<byte>();
            nextIndicator = AsyncSocket.CRLFData;
            tag = GNTP_IDENTIFIER_TAG;
        }
        /// <summary>
        /// Handles the <see cref="NotifyReceived"/> event
        /// </summary>
        /// <param name="notification">The <see cref="Notification"/> that was received</param>
        /// <param name="callbackInfo">The <see cref="CallbackInfo"/> for the notification</param>
        /// <param name="requestInfo">The <see cref="RequestInfo"/> associated with the request</param>
        /// <returns><see cref="Response"/></returns>
        protected virtual Response OnNotifyReceived(Notification notification, CallbackInfo callbackInfo, RequestInfo requestInfo)
        {
            LogInfo("NOTIFICATION RECEIVED: {0}", notification.Name);

            Response response = new Response(ErrorCode.INTERNAL_SERVER_ERROR, ErrorDescription.INTERNAL_SERVER_ERROR);
            if (this.NotifyReceived != null)
            {
                response = this.NotifyReceived(notification, callbackInfo, requestInfo);
            }
            return response;
        }
        /// <summary>
        /// Writes back the GNTP response to the requesting application
        /// </summary>
        /// <param name="cbInfo">The <see cref="CallbackInfo"/> associated with the response</param>
        /// <param name="response">The <see cref="Response"/> to be written back</param>
        public void WriteResponse(CallbackInfo cbInfo, Response response)
        {
            if (!cbInfo.AlreadyResponded)
            {
                cbInfo.AlreadyResponded = true;
                MessageHandler mh = cbInfo.MessageHandler;
                GNTPRequest request = mh.Request;
                ResponseType responseType = ResponseType.ERROR;
                if (response != null)
                {
                    if (response.IsCallback) responseType = ResponseType.CALLBACK;
                    else if (response.IsOK) responseType = ResponseType.OK;
                }
                else
                {
                    response = new Response(ErrorCode.INTERNAL_SERVER_ERROR, ErrorDescription.INTERNAL_SERVER_ERROR);
                }

                if (cbInfo.AdditionalInfo != null)
                {
                    foreach (KeyValuePair<string, string> item in cbInfo.AdditionalInfo)
                    {
                        response.CustomTextAttributes.Add(item.Key, item.Value);
                    }
                }

                AddServerHeaders(response);
                MessageBuilder mb = new MessageBuilder(responseType);
                HeaderCollection responseHeaders = response.ToHeaders();
                foreach (Header header in responseHeaders)
                {
                    mb.AddHeader(header);
                }
                // return any application-specific data headers that were received
                RequestData rd = RequestData.FromHeaders(request.Headers);
                AddRequestData(mb, rd);

                mh.WriteResponse(mb, true);
            }
         }
        /// <summary>
        /// Initializes a new instance of the <see cref="MessageHandler"/> class.
        /// </summary>
        /// <param name="serverName">Name of the server</param>
        /// <param name="passwordManager">A list of valid passwords</param>
        /// <param name="passwordRequired">Indicates if the request must contain a password</param>
        /// <param name="logFolder">The path to the folder where log files are written</param>
        /// <param name="loggingEnabled">Indicates if logging is enabled or not</param>
        /// <param name="allowNetworkNotifications">Indicates if notifications from remote machines are allowed</param>
        /// <param name="allowBrowserConnections">Indicates if notifications from browsers are allowed</param>
        /// <param name="allowSubscriptions">Indicates if clients are allowed to subscribe to notifications from this server</param>
        public MessageHandler(string serverName, PasswordManager passwordManager, bool passwordRequired, string logFolder, bool loggingEnabled, bool allowNetworkNotifications, bool allowBrowserConnections, bool allowSubscriptions)
        {
            this.serverName = serverName;
            this.passwordManager = passwordManager;
            this.passwordRequired = passwordRequired;
            this.logFolder = logFolder;
            this.loggingEnabled = loggingEnabled;
            this.allowNetworkNotifications = allowNetworkNotifications;
            this.allowBrowserConnections = allowBrowserConnections;
            this.allowSubscriptions = allowSubscriptions;

            this.serverName = serverName;
            this.callbackInfo = new CallbackInfo();
            this.requestInfo = new RequestInfo();
        }
Exemple #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GNTPParser"/> class.
        /// </summary>
        /// <param name="passwordManager">The <see cref="PasswordManager"/> containing a list of allowed passwords</param>
        /// <param name="passwordRequired">Indicates if a password is required</param>
        /// <param name="allowNetworkNotifications">Indicates if network requests are allowed</param>
        /// <param name="allowBrowserConnections">Indicates if browser requests are allowed</param>
        /// <param name="allowSubscriptions">Indicates if SUBSCRIPTION requests are allowed</param>
        /// <param name="requestInfo">The <see cref="RequestInfo"/> associated with this request</param>
        public GNTPParser(PasswordManager passwordManager, bool passwordRequired, bool allowNetworkNotifications, bool allowBrowserConnections, bool allowSubscriptions, RequestInfo requestInfo)
        {
            this.passwordManager = passwordManager;
            this.passwordRequired = passwordRequired;
            this.allowNetworkNotifications = allowNetworkNotifications;
            this.allowBrowserConnections = allowBrowserConnections;
            this.allowSubscriptions = allowSubscriptions;
            this.requestInfo = requestInfo;

            this.alreadyReceived = new StringBuilder();
            this.headers = new HeaderCollection();
            this.notificationsToBeRegistered = new List<HeaderCollection>();
            this.pointers = new List<Pointer>();
            this.callbackInfo = new CallbackInfo();
        }