Ejemplo n.º 1
0
        /// <summary>
        /// Generates an appropriate ResponseData object for this message, filled with supplied data
        /// </summary>
        /// <param name="ResponseType">The Type of the Response message</param>
        /// <param name="ResponseMessage">The HTTP response reason phrase</param>
        /// <param name="ResponseInfo">The session response information</param>
        /// <param name="Content">The response data</param>
        /// <returns>A filled ResponseData object</returns>
        protected override ResponseData BuildResponse(Type ResponseType, string ResponseMessage, ISessionResponseInfo ResponseInfo, byte[] Content)
        {
            StringBuilder sb = new StringBuilder();
            bool appendContent = false;
            string requestedNonce = service.Authenticator.GetNewChallenge();

            if (ResponseType == typeof(OKResponse))
            {
                OKResponse.AppendResponse(sb, ResponseMessage, service.ASPNETVersion, cnonce, clientDigest);
            }
            else if (ResponseType == typeof(UnauthorizedResponse))
            {
                UnauthorizedResponse.AppendResponse(sb, ResponseMessage, null, service.ASPNETVersion, requestedNonce, service.Authenticator.Realm, service.Authenticator.HashAlgorithmName);

            }
            else if (ResponseType == typeof(BadRequestResponse))
            {
                BadRequestResponse.AppendResponse(sb, ResponseMessage, service.ASPNETVersion);
            }
            else
            {
                Diags.Fail("ASSERTION Failed -- unexpected response type: " + ResponseType.Name + " at " + new System.Diagnostics.StackTrace().ToString() + "\r\n");
                BadRequestResponse.AppendResponse(sb, ResponseMessage, service.ASPNETVersion);

            }

            return new ResponseData(MergeResponseData(sb, Content, appendContent, socket.IsAuthenticated && service.Settings.EncryptPeerData,service.Authenticator,socket.SessionKey ), ResponseType);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates an appropriate ResponseData object for this message, filled with supplied data
        /// </summary>
        /// <param name="ResponseType">The Type of the Response message</param>
        /// <param name="ResponseMessage">The HTTP response reason phrase</param>
        /// <param name="ResponseInfo">The session response information</param>
        /// <param name="Content">The response data</param>
        /// <returns>A filled ResponseData object</returns>
        protected override ResponseData BuildResponse(Type ResponseType, string ResponseMessage, ISessionResponseInfo ResponseInfo, byte[] Content)
        {
            StringBuilder sb = new StringBuilder();
            bool appendContent = false;

            if(ResponseType == typeof(OKResponse))
            {
                OKResponse.AppendResponse(sb, ResponseMessage, service.ASPNETVersion, ResponseInfo);
                appendContent = true;
            }
            else if(ResponseType == typeof(NotFoundResponse))
            {
                NotFoundResponse.AppendResponse(sb, ResponseMessage, service.ASPNETVersion);
            }
            else if (ResponseType == typeof(LockedResponse))
            {
                LockedResponse.AppendResponse(sb, ResponseMessage, service.ASPNETVersion, ResponseInfo);
            }
            else if (ResponseType == typeof(BadRequestResponse))
            {
                BadRequestResponse.AppendResponse(sb, ResponseMessage, service.ASPNETVersion);
            }
            else
            {
                Diags.Fail("ASSERTION Failed -- unexpected response type: " + ResponseType.Name + " at " + new System.Diagnostics.StackTrace().ToString() + "\r\n");
                BadRequestResponse.AppendResponse(sb, ResponseMessage, service.ASPNETVersion);
            }

            return new ResponseData(MergeResponseData(sb, Content, appendContent, socket.IsAuthenticated && service.Settings.EncryptPeerData,service.Authenticator,socket.SessionKey ), ResponseType);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Generates an appropriate ResponseData object for this message, filled with supplied data
 /// </summary>
 /// <param name="ResponseType">The Type of the Response message</param>
 /// <param name="ResponseMessage">The HTTP response reason phrase</param>
 /// <param name="ResponseInfo">The session response information</param>
 /// <param name="Content">The response data</param>
 /// <returns>A filled ResponseData object</returns>
 protected override ResponseData BuildResponse(Type ResponseType, string ResponseMessage, ISessionResponseInfo ResponseInfo, byte[] Content)
 {
     throw new NotImplementedException("The UnknownRequest.BuildResponse method is not implemented.");
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Sends a SetTransferRequest message to a specified ServiceSocket
        /// </summary>
        /// <param name="connectedMsg">AsyncMessageTracker holding connected socket</param>
        /// <param name="Service">The state server instance</param>
        /// <param name="Resource">The URI associated with the message</param>
        /// <param name="SessionInfo">The Session information used to populate fields in the message</param>
        /// <param name="Data">The message data</param>
        /// <param name="SuccessAction">The Action to call if the message was accepted</param>
        /// <param name="FailAction">The Action to call if the message transmission failed or was refused</param>
        /// <param name="AlreadyExistsAction">The Action to call if the recipient peer already has the URI</param>
        /// <param name="PeerShuttingDownAction">The Action to call if the recipient peer is shutting down</param>
        /// <param name="TimeoutAction">The Action to call if the transfer timed out. This Action's processing time should be very short because a long list of Timeout actions can be daisy-chained and called one after the other</param>
        /// <param name="Timeout">The timeout time span</param>
        public static void Send(AsyncMessageTracker connectedMsg, StateServer Service, string Resource, ISessionResponseInfo SessionInfo,
            byte[] Data, Action<AsyncMessageTracker> SuccessAction, Action<AsyncMessageTracker> FailAction, Action<AsyncMessageTracker> AlreadyExistsAction, Action<AsyncMessageTracker> PeerShuttingDownAction, System.Threading.WaitCallback TimeoutAction, TimeSpan Timeout)
        {
            StringBuilder headers = new StringBuilder();

            headers.AppendFormat("PUT {0} HTTP/1.1\r\nHost: {1}\r\nX-ID: {2}\r\n", Resource, Service.ServerIP ?? connectedMsg.Socket.LocalIP,  connectedMsg.ID.ToString("N"));

            if (SessionInfo.LockDateInTicks != DateTime.MinValue.Ticks)
            {
                headers.AppendFormat("LockDate: {0}\r\nLockAge: {1}\r\nLockCookie: {2}\r\n", SessionInfo.LockDateInTicks, SessionInfo.LockAgeInSeconds, SessionInfo.LockCookie);
            }

            headers.AppendFormat("X-If-None-Exists: true\r\nExclusive: transfer\r\nTimeout: {0}\r\nExtraFlags: {1}\r\nLast-Modified: {2}\r\n", SessionInfo.Timeout, SessionInfo.ActionFlags, SessionInfo.UpdateDateInTicks);

            ResponseData rdata = new ResponseData(
                MergeResponseData(headers, Data, true, Service.Settings.EncryptPeerData, Service.Authenticator, connectedMsg.Socket.SessionKey),
                typeof(SetTransferRequest)
            );

            //Create new AsyncResultActions object to hold delegates for actions based on the outcome of the call
            AsyncResultActions<AsyncMessageTracker> asyncResults = new AsyncResultActions<AsyncMessageTracker>(connectedMsg);
            asyncResults.Result1Action = SuccessAction;
            asyncResults.Result2Action = FailAction;
            asyncResults.Result3Action = AlreadyExistsAction;
            asyncResults.Result4Action = PeerShuttingDownAction;
            asyncResults.TimeoutAction = TimeoutAction;

            Service.AsyncMessageRequests.Add(DateTime.UtcNow + Timeout, connectedMsg.ID, asyncResults);

            connectedMsg.Socket.Send(rdata);

            Diags.LogSend(connectedMsg.Socket, rdata);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// When overriden in a derived class, Generates an appropriate ResponseData object for this message, filled with supplied data
 /// </summary>
 /// <param name="ResponseType">The Type of the Response message</param>
 /// <param name="ResponseMessage">The HTTP response reason phrase</param>
 /// <param name="ResponseInfo">The session response information</param>
 /// <param name="Content">The response data</param>
 /// <returns>A filled ResponseData object</returns>
 protected abstract ResponseData BuildResponse(Type ResponseType, string ResponseMessage, ISessionResponseInfo ResponseInfo, byte[] Content);
Ejemplo n.º 6
0
        /// <summary>
        /// Appends the raw response data to a string builder.
        /// Used to reply to GetExclusiveRequest and GetRequest messages
        /// </summary>
        /// <param name="sb">The StringBuilder to append data to</param>
        /// <param name="Message">The response reason phrase</param>
        /// <param name="ASPNETVersion">The state server version</param>
        /// <param name="ResponseInfo">The session response info</param>
        internal static void AppendResponse(StringBuilder sb, string Message, string ASPNETVersion, ISessionResponseInfo ResponseInfo)
        {
            if (ResponseInfo == null)
            {
                AppendResponse(sb, Message, null, ASPNETVersion, ResponseInfo == null ? 0 : ResponseInfo.ActionFlags);
                return;
            }

            sb.AppendFormat("{0} {1}\r\nX-AspNet-Version: {2}\r\n", Code.ToString(), Message == string.Empty ? DefaultMessage : Message ?? DefaultMessage, ASPNETVersion);
            if (ResponseInfo.ActionFlags > 0)
            {
                sb.AppendFormat("ActionFlags: {0}\r\n", ResponseInfo.ActionFlags);
            }

            if (ResponseInfo.LockDateInTicks != DateTime.MinValue.Ticks)
            {
                //this session was locked
                sb.AppendFormat("LockCookie: {0}\r\n", ResponseInfo.LockCookie);
            }

            sb.AppendFormat("Timeout: {0}\r\nCache-Control: private\r\n", ResponseInfo.Timeout);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Appends the raw response data to a string builder
 /// </summary>
 /// <param name="sb">The StringBuilder to append data to</param>
 /// <param name="Message">The response reason phrase</param>
 /// <param name="ASPNETVersion">The state server version</param>
 /// <param name="ResponseInfo">The session response information</param>
 internal static void AppendResponse(StringBuilder sb, string Message, string ASPNETVersion, ISessionResponseInfo ResponseInfo)
 {
     sb.AppendFormat("{0} {1}\r\nX-AspNet-Version: {2}\r\n", Code.ToString(), Message == string.Empty ? DefaultMessage : Message ?? DefaultMessage, ASPNETVersion);
     sb.AppendFormat("LockDate: {0}\r\nLockAge: {1}\r\nLockCookie: {2}\r\nCache-Control: private\r\n", ResponseInfo.LockDateInTicks, ResponseInfo.LockAgeInSeconds, ResponseInfo.LockCookie);
 }