- self.response_body = proc { |response, output|
- a,b=bodies.divmod(256)
- output.write 0.chr+0.chr+0.chr+0.chr+a.chr+b.chr
- bodies.times do # Read each body
- message=AMF.getstring(req) # | get message name
- index=AMF.getstring(req) # | get index in response sequence
- bytes=AMF.getlong(req) # | get total size in bytes
- args=AMF.getvalue(req) # | get response (probably an array)
- err=false # Abort batch on error
-
- logger.info("Executing AMF #{message}:#{index}")
- result=''
- if err
- result=[-5,nil]
- else
- case message
- when 'putway'; orn=renumberednodes.dup
- r=putway(renumberednodes,*args)
- r[4]=renumberednodes.reject { |k,v| orn.has_key?(k) }
- if r[0]==0 and r[2] != r[3] then renumberedways[r[2]] = r[3] end
- result=AMF.putdata(index,r)
- when 'putrelation'; result=AMF.putdata(index,putrelation(renumberednodes, renumberedways, *args))
- when 'deleteway'; result=AMF.putdata(index,deleteway(*args))
- when 'putpoi'; r=putpoi(*args)
- if r[0]==0 and r[2] != r[3] then renumberednodes[r[2]] = r[3] end
- result=AMF.putdata(index,r)
- when 'startchangeset'; result=AMF.putdata(index,startchangeset(*args))
- end
- if result[0]==-3 then err=true end # If a conflict is detected, don't execute any more writes
+ self.response_body = Dispatcher.new(request.raw_post) do |message,*args|
+ logger.info("Executing AMF #{message}")
+
+ if err
+ result = [-5, nil]
+ else
+ case message
+ when 'putway'; orn = renumberednodes.dup
+ result = putway(renumberednodes, *args)
+ result[4] = renumberednodes.reject { |k,v| orn.has_key?(k) }
+ if result[0] == 0 and result[2] != result[3] then renumberedways[result[2]] = result[3] end
+ when 'putrelation'; result = putrelation(renumberednodes, renumberedways, *args)
+ when 'deleteway'; result = deleteway(*args)
+ when 'putpoi'; result = putpoi(*args)
+ if result[0] == 0 and result[2] != result[3] then renumberednodes[result[2]] = result[3] end
+ when 'startchangeset'; result = startchangeset(*args)