]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/amf_controller.rb
Remove bogus trailing slash from GPX namespace URL
[rails.git] / app / controllers / amf_controller.rb
index 2aac00d5ed81326736671c0c3bb2073afe97b695..0b04f0f3569b2610c143409f5feb2ca0f6c130ec 100644 (file)
@@ -133,12 +133,12 @@ class AmfController < ApplicationController
               when 'putway';         orn=renumberednodes.dup
                                      r=putway(renumberednodes,*args)
                                      r[4]=renumberednodes.reject { |k,v| orn.has_key?(k) }
-                                     if r[2] != r[3] then renumberedways[r[2]] = r[3] end
+                                     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[2] != r[3] then renumberednodes[r[2]] = r[3] end
+                                     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
@@ -156,6 +156,8 @@ class AmfController < ApplicationController
 
   def amf_handle_error(call,rootobj,rootid)
     yield
+  rescue OSM::APIAlreadyDeletedError => ex
+    return [-4, ex.object, ex.object_id]
   rescue OSM::APIVersionMismatchError => ex
     return [-3, [rootobj, rootid], [ex.type.downcase, ex.id, ex.latest]]
   rescue OSM::APIUserChangesetMismatchError => ex
@@ -170,7 +172,7 @@ class AmfController < ApplicationController
 
   def amf_handle_error_with_timeout(call,rootobj,rootid)
     amf_handle_error(call,rootobj,rootid) do
-      Timeout::timeout(APP_CONFIG['api_timeout'], OSM::APITimeoutError) do
+      Timeout::timeout(API_TIMEOUT, OSM::APITimeoutError) do
         yield
       end
     end
@@ -185,9 +187,14 @@ class AmfController < ApplicationController
       if !user then return -1,"You are not logged in, so Potlatch can't write any changes to the database." end
       unless user.active_blocks.empty? then return -1,t('application.setup_user_auth.blocked') end
 
+      if cstags
+        if !tags_ok(cstags) then return -1,"One of the tags is invalid. Linux users may need to upgrade to Flash Player 10.1." end
+        cstags = strip_non_xml_chars cstags
+      end
+
       # close previous changeset and add comment
       if closeid
-        cs = Changeset.find(closeid)
+        cs = Changeset.find(closeid.to_i)
         cs.set_closed_time_now
         if cs.user_id!=user.id
           raise OSM::APIUserChangesetMismatchError.new
@@ -195,6 +202,8 @@ class AmfController < ApplicationController
           cs.save!
         else
           cs.tags['comment']=closecomment
+          # in case closecomment has chars not allowed in xml
+          cs.tags = strip_non_xml_chars cs.tags
           cs.save_with_tags!
         end
       end
@@ -204,7 +213,11 @@ class AmfController < ApplicationController
         cs = Changeset.new
         cs.tags = cstags
         cs.user_id = user.id
-        if !closecomment.empty? then cs.tags['comment']=closecomment end
+        if !closecomment.empty? 
+          cs.tags['comment']=closecomment 
+          # in case closecomment has chars not allowed in xml
+          cs.tags = strip_non_xml_chars cs.tags
+        end
         # smsm1 doesn't like the next two lines and thinks they need to be abstracted to the model more/better
         cs.created_at = Time.now.getutc
         cs.closed_at = cs.created_at + Changeset::IDLE_TIMEOUT
@@ -358,7 +371,7 @@ class AmfController < ApplicationController
         way = Way.find(:first, :conditions => { :id => wayid }, :include => { :nodes => :node_tags })
 
         # check case where way has been deleted or doesn't exist
-        return [-4, 'way', wayid, [], {}, nil] if way.nil? or !way.visible
+        return [-4, 'way', wayid] if way.nil? or !way.visible
 
         points = way.nodes.collect do |node|
           nodetags=node.tags
@@ -403,7 +416,7 @@ class AmfController < ApplicationController
           unless old_way.nil?
             points = old_way.get_nodes_revert(timestamp)
             if !old_way.visible
-              return [-1, "Sorry, the way was deleted at that time - please revert to a previous version.", id, [], {}, nil, false]
+              return [-1, "Sorry, the way was deleted at that time - please revert to a previous version.", id]
             end
           end
         rescue ArgumentError
@@ -413,7 +426,7 @@ class AmfController < ApplicationController
       end
 
       if old_way.nil?
-        return [-1, "Sorry, the server could not find a way at that time.", id, [], {}, nil, false]
+        return [-1, "Sorry, the server could not find a way at that time.", id]
       else
         curway=Way.find(id)
         old_way.tags['history'] = "Retrieved from v#{old_way.version}"
@@ -492,8 +505,8 @@ class AmfController < ApplicationController
   def findgpx(searchterm, usertoken)
     amf_handle_error_with_timeout("'findgpx'" ,nil,nil) do
       user = getuser(usertoken)
-      if !user then return -1,"You must be logged in to search for GPX traces.",[] end
-      unless user.active_blocks.empty? then return -1,t('application.setup_user_auth.blocked'),[] end
+      if !user then return -1,"You must be logged in to search for GPX traces." end
+      unless user.active_blocks.empty? then return -1,t('application.setup_user_auth.blocked') end
 
       gpxs = []
       if searchterm.to_i>0 then
@@ -523,7 +536,7 @@ class AmfController < ApplicationController
     amf_handle_error("'getrelation' #{relid}" ,'relation',relid) do
       rel = Relation.find(:first, :conditions => { :id => relid })
 
-      return [-4, 'relation', relid, {}, [], nil] if rel.nil? or !rel.visible
+      return [-4, 'relation', relid] if rel.nil? or !rel.visible
       [0, '', relid, rel.tags, rel.members, rel.version]
     end
   end
@@ -560,7 +573,7 @@ class AmfController < ApplicationController
       user = getuser(usertoken)
       if !user then return -1,"You are not logged in, so the relation could not be saved." end
       unless user.active_blocks.empty? then return -1,t('application.setup_user_auth.blocked') end
-      if !tags_ok(tags) then return -1,"One of the tags is invalid. Please pester Adobe to fix Flash on Linux." end
+      if !tags_ok(tags) then return -1,"One of the tags is invalid. Linux users may need to upgrade to Flash Player 10.1." end
       tags = strip_non_xml_chars tags
 
       relid = relid.to_i
@@ -649,7 +662,7 @@ class AmfController < ApplicationController
       if !user then return -1,"You are not logged in, so the way could not be saved." end
       unless user.active_blocks.empty? then return -1,t('application.setup_user_auth.blocked') end
       if pointlist.length < 2 then return -2,"Server error - way is only #{points.length} points long." end
-      if !tags_ok(attributes) then return -1,"One of the tags is invalid. Please pester Adobe to fix Flash on Linux." end
+      if !tags_ok(attributes) then return -1,"One of the tags is invalid. Linux users may need to upgrade to Flash Player 10.1." end
       attributes = strip_non_xml_chars attributes
 
       originalway = originalway.to_i
@@ -666,6 +679,7 @@ class AmfController < ApplicationController
           lat = a[1].to_f
           id = a[2].to_i
           version = a[3].to_i
+
           if id == 0  then return -2,"Server error - node with id 0 found in way #{originalway}." end
           if lat== 90 then return -2,"Server error - node with latitude -90 found in way #{originalway}." end
           if renumberednodes[id] then id = renumberednodes[id] end
@@ -677,7 +691,7 @@ class AmfController < ApplicationController
           node.tags = a[4]
 
           # fixup node tags in a way as well
-          if !tags_ok(node.tags) then return -1,"One of the tags is invalid. Please pester Adobe to fix Flash on Linux." end
+          if !tags_ok(node.tags) then return -1,"One of the tags is invalid. Linux users may need to upgrade to Flash Player 10.1." end
           node.tags = strip_non_xml_chars node.tags
 
           node.tags.delete('created_by')
@@ -753,7 +767,7 @@ class AmfController < ApplicationController
       user = getuser(usertoken)
       if !user then return -1,"You are not logged in, so the point could not be saved." end
       unless user.active_blocks.empty? then return -1,t('application.setup_user_auth.blocked') end
-      if !tags_ok(tags) then return -1,"One of the tags is invalid. Please pester Adobe to fix Flash on Linux." end
+      if !tags_ok(tags) then return -1,"One of the tags is invalid. Linux users may need to upgrade to Flash Player 10.1." end
       tags = strip_non_xml_chars tags
 
       id = id.to_i
@@ -765,7 +779,7 @@ class AmfController < ApplicationController
           node = Node.find(id)
 
           if !visible then
-            unless node.ways.empty? then return -1,"The point has since become part of a way, so you cannot save it as a POI.",id,id,version end
+            unless node.ways.empty? then return -1,"Point #{id} has since become part of a way, so you cannot save it as a POI.",id,id,version end
           end
         end
         # We always need a new node, based on the data that has been sent to us
@@ -816,7 +830,7 @@ class AmfController < ApplicationController
       if n
         return [0, '', n.id, n.lon, n.lat, n.tags, v]
       else
-        return [-4, 'node', id, nil, nil, {}, nil]
+        return [-4, 'node', id]
       end
     end
   end
@@ -832,7 +846,7 @@ class AmfController < ApplicationController
   # Returns 0 (success), unchanged way id, new way version, new node versions.
 
   def deleteway(usertoken, changeset_id, way_id, way_version, deletednodes) #:doc:
-    amf_handle_error("'deleteway' #{way_id}" ,'way',id) do
+    amf_handle_error("'deleteway' #{way_id}" ,'way', way_id) do
       user = getuser(usertoken)
       unless user then return -1,"You are not logged in, so the way could not be deleted." end
       unless user.active_blocks.empty? then return -1,t('application.setup_user_auth.blocked') end