Exemplo n.º 1
0
 internal WebDAVLockResponse OnLockConnector(WebDAVLockRequest request)
 {
     if (OnLock != null)
     {
         try { return OnLock(request); }
         catch (Exception ex)
         {
             Console.WriteLine("Caught exception in OnLock callback: " + ex);
         }
     }
     return null;
 }
Exemplo n.º 2
0
        public WebDAVLockResponse LockHandler(WebDAVLockRequest request)
        {
            WebDAVLockResponse response = new WebDAVLockResponse();
            lock (this) // make sure only one thread is locking the resource
            {
                if (!lockedResources.ContainsKey(request.Path))
                {
                    // check the resource exists
                    if (!CheckIfExists(request))
                    {
                        response.HttpStatusCode = HttpStatusCode.NotFound;
                    }
                    else
                    {
                        string[] timeouts = request.RequestedTimeout;
                        string timeout = "Infinite";
                        if (m_useTimeOuts)
                        {
                            if (timeouts != null && timeouts.Length != 0)
                            {
                                timeout = m_WebDAVTimeOutHandler.AddTimeOutLock(timeouts, request.Path);
                            }
                        }
                        //create locktoken
                        //more information how to really generate the token, see: rfc2518 section 6.4
                        string locktoken = "opaquelocktoken:" + UUID.Random().ToString();
                        response.LockToken = locktoken;
                        response.LockScope = request.LockScope;
                        response.LockType = request.LockType;
                        response.Depth = "0";
                        response.Timeout = timeout;
                        response.OwnerNamespaceUri = request.OwnerNamespaceUri;
                        response.OwnerValue = request.OwnerValue;
                        response.OwnerValues = request.OwnerValues;
                        response.HttpStatusCode = HttpStatusCode.Created;
                        lockedResources.Add(request.Path, response);
                    }
                }
                else
                {
                    if (request.IfHeaders != null && request.IfHeaders.Length!=0) // it's refresh request
                    {
                        if (CheckIfHeaders(request.IfHeaders, request.Path))
                        { // its valid request refresh lock:
                            if (!CheckIfExists(request))
                            {
                                response.HttpStatusCode = HttpStatusCode.NotFound;
                            }
                            else
                            {
                                string[] timeouts = request.RequestedTimeout;
                                string timeout = "Infinite";

                                if (m_useTimeOuts)
                                {
                                    if (timeouts != null && timeouts.Length != 0)
                                    {
                                        timeout = m_WebDAVTimeOutHandler.AddTimeOutLock(request.RequestedTimeout, request.Path);
                                    }
                                }
                                //create locktoken
                                //more information how to really generate the token, see: rfc2518 section 6.4
                                string locktoken = "opaquelocktoken:" + UUID.Random().ToString();
                                response.LockToken = locktoken;
                                response.LockScope = request.LockScope;
                                response.LockType = request.LockType;
                                response.Depth = "0";
                                response.Timeout = timeout;
                                response.OwnerNamespaceUri = request.OwnerNamespaceUri;
                                response.OwnerValue = request.OwnerValue;
                                response.OwnerValues = request.OwnerValues;
                                response.HttpStatusCode = HttpStatusCode.Created;

                            }
                        }
                    }
                    else if (lockedResources[request.Path].LockScope == LockScope.shared && request.LockScope == LockScope.shared)
                    {
                        //quite special case. no implementation yet
                        response.HttpStatusCode = HttpStatusCode.InternalServerError; //locked
                        ;
                    }
                    else
                    {
                        response.HttpStatusCode = (HttpStatusCode)423; //locked
                    }
                }
            }
            return response;
        }
Exemplo n.º 3
0
 public WebDAVLockResponse LockHandler(WebDAVLockRequest request) 
 { 
     CheckExpiringTimeOutLocks();
     return m_LockHandler.LockHandler(request);
 }
Exemplo n.º 4
0
 private bool CheckIfExists(WebDAVLockRequest request)
 {
     string localPath = "";
     UUID agentID = WebDAVServerConnector.AgentIDFromRequestPath(m_SubDomain, m_InitialLocalPath, request.Path, ref localPath);
     InventoryNodeBase invObject = m_WebDAVServerConnector.PathToInventory(agentID, localPath);
     if (invObject != null)
         return true;
     return false;
 }