Git Product home page Git Product logo

rocketamf's Introduction

DESCRIPTION:

RubyAMF is a full-featured AMF gateway based off of Rack and supporting advanced integration with Rails and other Rack-based frameworks. It includes advanced class mapping functionality, like camel to underscore case translation, parameter mapping to convert function calls to parameter hashes for actions, hooks for processing AMF authentication credentials, and many more features.

UPGRADE FROM rubyamf_plugin:

  1. Delete RAILS_ROOT/vendor/plugins/rubyamf or comment out every line in RAILS_ROOT/vendor/plugins/rubyamf/init.rb.

  2. Add gems to application:

    Bundler:

    gem "RocketAMF", :git => "git://github.com/rubyamf/rocketamf.git"
    gem 'rubyamf', :git => 'git://github.com/rubyamf/rubyamf.git'
    

    environment.rb:

    config.gem "RocketAMF"
    config.gem "rubyamf"
    
  3. Configure the endpoint path by adding the following to the end of your environment.rb file:

    RubyAMF.configure do |config|
      config.gateway_path = "/rubyamf/gateway"
    end
    

    The gateway path is no longer specified in routes.rb, so you can remove it and rubyamf_controller.rb if you want.

  4. Try out your application!

    RubyAMF should load your legacy rubyamf_config.rb file and you should be on your way.

If you want to learn more about the new features, please check out the demo app at github.com/rubyamf/rubyamf-demo or the RDoc at (SOMEWHERE).

RAILS 2 INSTALL:

  1. Add gems to application:

    Bundler:

    gem "RocketAMF", :git => "git://github.com/rubyamf/rocketamf.git"
    gem 'rubyamf', :git => 'git://github.com/rubyamf/rubyamf.git'
    

    environment.rb:

    config.gem "RocketAMF"
    config.gem "rubyamf"
    
  2. Configure the endpoint path by adding the following to the end of your environment.rb file:

    RubyAMF.configure do |config|
      config.gateway_path = "/rubyamf/gateway"
    end
    

Check out the demo app at (SOMEWHERE) or the RDoc at (SOMEWHERE) for information about configuration and use.

RAILS 3 INSTALL:

  1. Add the gems to your Gemfile:

    gem "RocketAMF", :git => "git://github.com/rubyamf/rocketamf.git"
    gem 'rubyamf', :git => 'git://github.com/rubyamf/rubyamf.git'
    
  2. Configure the endpoint path by adding the following to your application.rb:

    config.rubyamf.gateway_path = "/amf"
    

Check out the demo app at github.com/rubyamf/rubyamf-demo or the RDoc at (SOMEWHERE) for information about configuration and use.

OTHER RACK FRAMEWORK INSTALL:

TODO: Write up instructions

Running Tests

Unless a command-line Rails ‘major.minor’ version is specified both bundle install, rspec, and rake spec will default to Rails 4.0. To run tests against different versions of Rails, use:

$ RAILS_VERSION=major.minor bundle install
$ RAILS_VERSION=major.minor rspec

LICENSE:

(The MIT License)

Copyright © 2011 Stephen Augenstein

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

rocketamf's People

Contributors

doubledare avatar qqshfox avatar robertabcd avatar warhammerkid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rocketamf's Issues

Can't dereference cached objects, strings and traits

Objects, Traits and Strings aren't cached properly as they're deserialized, and the parser chokes when trying to dereference said elements

deserializer.rb:

36,38c36,38
<           @string_cache = []
<           @object_cache = []
<           @trait_cache = []

---
>           @string_cache = [] unless @string_cache
>           @object_cache = [] unless @object_cache
>           @trait_cache = [] unless @trait_cache

RocketAMF native chokes on proxy array (commonly used in rails)

Using RocketAMF native

class ProxyArray
  instance_methods.each { |m| undef_method m unless m =~ /(^__|^send$|^object_id$)/ }

  def proxy_method
     puts "you just called the proxy method!"
  end

  protected

  def method_missing(name, *args, &block)
    target.send(name, *args, &block)
  end

  def target
    @target ||= []
  end
end

baz = ProxyArray.new
=> []
baz << 1
=> [1]
baz << 2
=> [1, 2]
baz << 3
=> [1, 2, 3]
baz << 4
=> [1, 2, 3, 4]
baz.class
=> Array
RocketAMF.serialize baz, 3
ArgumentError: wrong number of arguments (0 for 1..4)
from /home/justinsharp/.rvm/gems/ruby-1.9.3-p194@cr2rails/bundler/gems/rocketamf-71f372747536/lib/rocketamf/class_mapping.rb:232:in `select'
RocketAMF.serialize baz + [], 3
=> "\n\aCflex.messaging.io.ArrayCollection\t\t\x01\x04\x01\x04\x02\x04\x03\x04\x04"

The second call works because adding [] to the proxy object produces a new true Array object.

Using RocketAMF pure

class ProxyArray
 instance_methods.each { |m| undef_method m unless m =~ /(^__|^send$|^object_id$)/ }

 def proxy_method
   puts "you just called the proxy method!"
 end

 protected

 def method_missing(name, *args, &block)
   target.send(name, *args, &block)
 end

 def target
   @target ||= []
 end
end
=> nil

baz = ProxyArray.new
=> []
baz << 1
=> [1]
baz << 2
=> [1, 2]
baz << 3
=> [1, 2, 3]
baz << 4
=> [1, 2, 3, 4]
baz.class
=> Array
RocketAMF.serialize baz, 3
=> "\n\aCflex.messaging.io.ArrayCollection\t\t\x01\x04\x01\x04\x02\x04\x03\x04\x04"

The common use case for this would be if you were trying to serialize something like this code

class User < ActiveRecord::Base
  has_many :pets
end
class Pet < ActiveRecord::Base
  belongs_to :user
end

user = User.first
RocketAMF.serialize(user.pets, 3)

I trounced around in the C code a bit, but it's not immediately obvious to me what the problem is, as I don't have a lot of experience in native ruby C api. If I have some time I will put together a spec for this.

Support JRuby

RocketAMF can't be installed under JRuby because it tries to install the native extension and fails.

abused to_sym can get server easily attacked when deserializing data from client

We are using rocketamf on our server to serialize data from remote client, which is the most case, but have found it could be easily attack by abused String::to_sym.
File:
lib/rocketamf/pure/deserializer.rb => to_sym
ext/rocketamf_ext/deserializer.c => rb_str_intern
As it is, rocketamf will convert every key in an object to sym, but in Ruby, the memory of a symbol will never be released. So, when a client transfer malicious data to server, our server will certainly get DoS attacked.

Maybe solutions:

  1. no more use to_sym, only string as key. Some old code use rocketamf will not work.
  2. to_sym only if the special symbol already exists. This maybe a good solution, but sometimes make something unexpected.
  3. give an extra argument for deserializing amf object.

RuntimeError: Not supported: 47

Consider the following AMF message received from AMFPHP on Neopets.com: https://dl.dropboxusercontent.com/u/803129/glitched.amf

Flash is able to read this response properly, as is SabreAMF: https://dl.dropboxusercontent.com/u/803129/glitched.txt

RocketAMF, however, fails to read the response:

> response = File.open('glitched.amf', 'rb') { |f| f.read }
> RocketAMF::Envelope.new.populate_from_stream(response)
RuntimeError: Not supported: 47

I suspect the issue is at messages[0]['custom_pet']['biology_by_zone']: note that the hash contains a null key. This really shouldn't be a part of the message and is almost certainly a bug on their part, but it still oughta be deserialized correctly, anyway—especially since it's just so hard to get those guys to fix bugs :P

Add support for serializing Numeric subclasses

@kirillian:

Infinite loop when serializing BigDecimal (SystemStackError Exception: stack level too deep)

I kept getting an infinite loop issue on some of my models and after quite a lot of frustration and tracing, finally noticed that I was seeing a BigDecimal class in my variables...after doing some checking and not finding support, I checked out how these had previously been handled in other AMF serializers and saw them being converted to Floats, so I forked and added in a fix.

For people trying to troubleshoot, the errors I was seeing looked like this:
SystemStackError Exception: stack level too deep

Upon tracing through callstacks, I saw repetition through these methods on the serializer:
serialize
write_prop_list
write_object
serialize

Unable to install and/or start

Thanks for working on this. I'm using

  • ruby 1.9.3p0 (2011-10-30) [i386-mingw32] on Win 7 x64

When I did an initial bundle install using

  • gem "RocketAMF", :git => "git://github.com/rubyamf/rocketamf.git"

I got a false native extension building error as if DevKit wasn't installed, similar to the one Stephen reported here:

So I tried

  • gem "RocketAMF"

That installs fine but then on server startup gives this error:

  • Uncaught exception: uninitialized constant RocketAMF::MappingSet

Is there a version that works with Ruby 1.9.3 or would I have to go back to 1.9.2 or what?

Thanks for any tips!

  • Sanford

NoMethodError: undefined method `call_flex'

When I type these code in irb:

req = RocketAMF::Envelope.new :amf_version => 3
req.call_flex 'Controller.action', "arg_1", ["args", "args"]

it reports:

NoMethodError: undefined method `call_flex' for #<RocketAMF::Envelope:0x007fa464376aa8>

Serializer discards a class name in TypedHash

Hi,

When I deserialize AMF3 data, modify it, and then serialize it, I noticed class names in AMF3 Objects is discarded.
For example:

require 'rocketamf'⏎
amf3_object_with_classname = "\x0a\x0b\x13ClassName\x01\x01"⏎
data = RocketAMF.deserialize( amf3_object_with_classname, 3 )⏎
p data.type # => "ClassName"⏎
data = RocketAMF.deserialize( RocketAMF.serialize( data, 3 ), 3 )⏎
p data.type # => ""⏎

I expect the class name "ClassName" is kept on serialization, but RocketAMF.serialize discards the class name and it will be an empty string instead. I know it can be avoided by mapping the class names, but it would be very convenient if class names in AMF3 Object is kept out-of-the-box. Especially, a class name stored in TypedHash should be kept because TypedHash is used to store the AMF3 Object and its class name.

I hope the following spec to be passed.

diff --git a/spec/class_mapping_spec.rb b/spec/class_mapping_spec.rb
index 16ff524..1a674b7 100644
--- a/spec/class_mapping_spec.rb
+++ b/spec/class_mapping_spec.rb
@@ -25,6 +25,10 @@ describe RocketAMF::ClassMapping do
       @mapper.get_as_class_name('BadClass').should be_nil
     end

+    it "should return the same AS class as of TypedHash" do
+      @mapper.get_as_class_name(RocketAMF::Values::TypedHash.new("UnmappedClass")).should == 'UnmappedClass'
+    end
+
     it "should instantiate a ruby class" do
       @mapper.get_ruby_obj('ASClass').should be_a(ClassMappingTest)
     end

Regards,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.