lib/dav4rack/controller.rb
# Lock current resource
# NOTE: This will pass an argument hash to Resource#lock and
# wait for a success/failure response.
Lock current resource
NOTE: This will pass an argument hash to Resource#lock and
wait for a success/failure response.
Lock current resource NOTE : This will pass an argument hash to Resource#lock and wait for a success / failure response .
def lock
      lockinfo = request_document.xpath("//#{ns}lockinfo")
      asked = {}
      asked[:timeout] = request.env['Timeout'].split(',').map{|x|x.strip} if request.env['Timeout']
      asked[:depth] = depth
      unless([0, :infinity].include?(asked[:depth]))
        BadRequest
      else
        asked[:scope] = lockinfo.xpath("//#{ns}lockscope").children.find_all{|n|n.element?}.map{|n|n.name}.first
        asked[:type] = lockinfo.xpath("#{ns}locktype").children.find_all{|n|n.element?}.map{|n|n.name}.first
        asked[:owner] = lockinfo.xpath("//#{ns}owner/#{ns}href").children.map{|n|n.text}.first
        begin
          lock_time, locktoken = resource.lock(asked)
          render_xml(:prop) do |xml|
            xml.lockdiscovery do
              xml.activelock do
                if(asked[:scope])
                  xml.lockscope do
                    xml.send(asked[:scope])
                  end
                end
                if(asked[:type])
                  xml.locktype do
                    xml.send(asked[:type])
                  end
                end
                xml.depth asked[:depth].to_s
                xml.timeout lock_time ? "Second-#{lock_time}" : 'infinity'
                xml.locktoken do
                  xml.href locktoken
                end
                if(asked[:owner])
                  xml.owner asked[:owner]
                end
              end
            end
          end
          response.headers['Lock-Token'] = locktoken
          response.status = resource.exist? ? OK : Created
        rescue LockFailure => e
          multistatus do |xml|
            e.path_status.each_pair do |path, status|
              xml.response do
                xml.href path
                xml.status "#{http_version} #{status.status_line}"
              end
            end
          end
        end
      end
    end
def lock lockinfo = request_document . xpath ( "//#{ns}lockinfo" ) asked = { } asked [ :timeout ] = request . env [ 'Timeout' ] . split ( ',' ) . map { | x | x . strip } if request . env [ 'Timeout' ] asked [ :depth ] = depth unless ( [ 0 , :infinity ] . include? ( asked [ :depth ] ) ) BadRequest else asked [ :scope ] = lockinfo . xpath ( "//#{ns}lockscope" ) . children . find_all { | n | n . element? } . map { | n | n . name } . first asked [ :type ] = lockinfo . xpath ( "#{ns}locktype" ) . children . find_all { | n | n . element? } . map { | n | n . name } . first asked [ :owner ] = lockinfo . xpath ( "//#{ns}owner/#{ns}href" ) . children . map { | n | n . text } . first begin lock_time , locktoken = resource . lock ( asked ) render_xml ( :prop ) do | xml | xml . lockdiscovery do xml . activelock do if ( asked [ :scope ] ) xml . lockscope do xml . send ( asked [ :scope ] ) end end if ( asked [ :type ] ) xml . locktype do xml . send ( asked [ :type ] ) end end xml . depth asked [ :depth ] . to_s xml . timeout lock_time ? "Second-#{lock_time}" : 'infinity' xml . locktoken do xml . href locktoken end if ( asked [ :owner ] ) xml . owner asked [ :owner ] end end end end response . headers [ 'Lock-Token' ] = locktoken response . status = resource . exist? ? OK : Created rescue LockFailure => e multistatus do | xml | e . path_status . each_pair do | path , status | xml . response do xml . href path xml . status "#{http_version} #{status.status_line}" end end end end end end
Lock current resource
NOTE: This will pass an argument hash to Resource#lock and
wait for a success/failure response.
Lock current resource NOTE : This will pass an argument hash to Resource#lock and wait for a success / failure response .