Skip to content
This repository
Browse code

added mochiweb server to capture amf requests

  • Loading branch information...
commit c6b257cb5100f7ff9f771859be158b2a8009e8a7 1 parent 14203ac
Nguyen Kien Trung authored
0  ebin/.empty
No changes.
0  ebin/bash.exe.stackdump
No changes.
29  ebin/mochiweb.app
... ...
@@ -0,0 +1,29 @@
  1
+{application, mochiweb,
  2
+ [{description, "MochiMedia Web Server"},
  3
+  {vsn, "0.01"},
  4
+  {modules, [
  5
+        mochihex,
  6
+        mochijson,
  7
+        mochijson2,
  8
+        mochinum,
  9
+        mochiweb,
  10
+        mochiweb_app,
  11
+        mochiweb_charref,
  12
+        mochiweb_cookies,
  13
+        mochiweb_echo,
  14
+        mochiweb_headers,
  15
+        mochiweb_html,
  16
+        mochiweb_http,
  17
+        mochiweb_multipart,
  18
+        mochiweb_request,
  19
+        mochiweb_response,
  20
+        mochiweb_skel,
  21
+        mochiweb_socket_server,
  22
+        mochiweb_sup,
  23
+        mochiweb_util,
  24
+        reloader
  25
+	    ]},
  26
+  {registered, []},
  27
+  {mod, {mochiweb_app, []}},
  28
+  {env, []},
  29
+  {applications, [kernel, stdlib]}]}.
5  priv/www/crossdomain.xml
... ...
@@ -0,0 +1,5 @@
  1
+<!DOCTYPE cross-domain-policy
  2
+  SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"> 
  3
+<cross-domain-policy> 
  4
+  <allow-access-from domain="*.*" secure="false" /> 
  5
+</cross-domain-policy> 
8  priv/www/index.html
... ...
@@ -0,0 +1,8 @@
  1
+<html>
  2
+<head>
  3
+<title>It Worked</title>
  4
+</head>
  5
+<body>
  6
+Erling Server (based on MochiWeb) is running.
  7
+</body>
  8
+</html>
14  src/erling_server.app
... ...
@@ -0,0 +1,14 @@
  1
+{application, erling_server,
  2
+ [{description, "erling_server"},
  3
+  {vsn, "0.01"},
  4
+  {modules, [
  5
+    erling_server,
  6
+    erling_server_app,
  7
+    erling_server_sup,
  8
+    erling_server_web,
  9
+    erling_server_deps
  10
+  ]},
  11
+  {registered, []},
  12
+  {mod, {erling_server_app, []}},
  13
+  {env, []},
  14
+  {applications, [kernel, stdlib, crypto]}]}.
30  src/erling_server.erl
... ...
@@ -0,0 +1,30 @@
  1
+%% @author author <author@example.com>
  2
+%% @copyright YYYY author.
  3
+
  4
+%% @doc TEMPLATE.
  5
+
  6
+-module(erling_server).
  7
+-author('author <author@example.com>').
  8
+-export([start/0, stop/0]).
  9
+
  10
+ensure_started(App) ->
  11
+    case application:start(App) of
  12
+        ok ->
  13
+            ok;
  14
+        {error, {already_started, App}} ->
  15
+            ok
  16
+    end.
  17
+        
  18
+%% @spec start() -> ok
  19
+%% @doc Start the erling_server server.
  20
+start() ->
  21
+    erling_server_deps:ensure(),
  22
+    ensure_started(crypto),
  23
+    application:start(erling_server).
  24
+
  25
+%% @spec stop() -> ok
  26
+%% @doc Stop the erling_server server.
  27
+stop() ->
  28
+    Res = application:stop(erling_server),
  29
+    application:stop(crypto),
  30
+    Res.
1  src/erling_server.hrl
... ...
@@ -0,0 +1 @@
  1
+
22  src/erling_server_app.erl
... ...
@@ -0,0 +1,22 @@
  1
+%% @author author <author@example.com>
  2
+%% @copyright YYYY author.
  3
+
  4
+%% @doc Callbacks for the erling_server application.
  5
+
  6
+-module(erling_server_app).
  7
+-author('author <author@example.com>').
  8
+
  9
+-behaviour(application).
  10
+-export([start/2,stop/1]).
  11
+
  12
+
  13
+%% @spec start(_Type, _StartArgs) -> ServerRet
  14
+%% @doc application start callback for erling_server.
  15
+start(_Type, _StartArgs) ->
  16
+    erling_server_deps:ensure(),
  17
+    erling_server_sup:start_link().
  18
+
  19
+%% @spec stop(_State) -> ServerRet
  20
+%% @doc application stop callback for erling_server.
  21
+stop(_State) ->
  22
+    ok.
84  src/erling_server_deps.erl
... ...
@@ -0,0 +1,84 @@
  1
+%% @author author <author@example.com>
  2
+%% @copyright YYYY author.
  3
+
  4
+%% @doc Ensure that the relatively-installed dependencies are on the code
  5
+%%      loading path, and locate resources relative
  6
+%%      to this application's path.
  7
+
  8
+-module(erling_server_deps).
  9
+-author('author <author@example.com>').
  10
+
  11
+-export([ensure/0, ensure/1]).
  12
+-export([get_base_dir/0, get_base_dir/1]).
  13
+-export([local_path/1, local_path/2]).
  14
+-export([deps_on_path/0, new_siblings/1]).
  15
+
  16
+%% @spec deps_on_path() -> [ProjNameAndVers]
  17
+%% @doc List of project dependencies on the path.
  18
+deps_on_path() ->
  19
+    F = fun (X, Acc) ->
  20
+                ProjDir = filename:dirname(X),
  21
+                case {filename:basename(X),
  22
+                      filename:basename(filename:dirname(ProjDir))} of
  23
+                    {"ebin", "deps"} ->
  24
+                        [filename:basename(ProjDir) | Acc];
  25
+                    _ ->
  26
+                        Acc
  27
+                end
  28
+        end,
  29
+    ordsets:from_list(lists:foldl(F, [], code:get_path())).
  30
+    
  31
+%% @spec new_siblings(Module) -> [Dir]
  32
+%% @doc Find new siblings paths relative to Module that aren't already on the
  33
+%%      code path.
  34
+new_siblings(Module) ->
  35
+    Existing = deps_on_path(),
  36
+    SiblingEbin = filelib:wildcard(local_path(["deps", "*", "ebin"], Module)),
  37
+    Siblings = [filename:dirname(X) || X <- SiblingEbin,
  38
+                           ordsets:is_element(
  39
+                             filename:basename(filename:dirname(X)),
  40
+                             Existing) =:= false],
  41
+    lists:filter(fun filelib:is_dir/1, 
  42
+                 lists:append([[filename:join([X, "ebin"]),
  43
+                                filename:join([X, "include"])] ||
  44
+                                  X <- Siblings])).
  45
+        
  46
+
  47
+%% @spec ensure(Module) -> ok
  48
+%% @doc Ensure that all ebin and include paths for dependencies
  49
+%%      of the application for Module are on the code path.
  50
+ensure(Module) ->
  51
+    code:add_paths(new_siblings(Module)),
  52
+    code:clash(),
  53
+    ok.
  54
+
  55
+%% @spec ensure() -> ok
  56
+%% @doc Ensure that the ebin and include paths for dependencies of
  57
+%%      this application are on the code path. Equivalent to
  58
+%%      ensure(?Module).
  59
+ensure() ->
  60
+    ensure(?MODULE).
  61
+
  62
+%% @spec get_base_dir(Module) -> string()
  63
+%% @doc Return the application directory for Module. It assumes Module is in
  64
+%%      a standard OTP layout application in the ebin or src directory.
  65
+get_base_dir(Module) ->
  66
+    {file, Here} = code:is_loaded(Module),
  67
+    filename:dirname(filename:dirname(Here)).
  68
+
  69
+%% @spec get_base_dir() -> string()
  70
+%% @doc Return the application directory for this application. Equivalent to
  71
+%%      get_base_dir(?MODULE).
  72
+get_base_dir() ->
  73
+    get_base_dir(?MODULE).
  74
+
  75
+%% @spec local_path([string()], Module) -> string()
  76
+%% @doc Return an application-relative directory from Module's application.
  77
+local_path(Components, Module) ->
  78
+    filename:join([get_base_dir(Module) | Components]).
  79
+
  80
+%% @spec local_path(Components) -> string()
  81
+%% @doc Return an application-relative directory for this application.
  82
+%%      Equivalent to local_path(Components, ?MODULE).
  83
+local_path(Components) ->
  84
+    local_path(Components, ?MODULE).
54  src/erling_server_sup.erl
... ...
@@ -0,0 +1,54 @@
  1
+%% @author author <author@example.com>
  2
+%% @copyright YYYY author.
  3
+
  4
+%% @doc Supervisor for the erling_server application.
  5
+
  6
+-module(erling_server_sup).
  7
+-author('author <author@example.com>').
  8
+
  9
+-behaviour(supervisor).
  10
+
  11
+%% External exports
  12
+-export([start_link/0, upgrade/0]).
  13
+
  14
+%% supervisor callbacks
  15
+-export([init/1]).
  16
+
  17
+%% @spec start_link() -> ServerRet
  18
+%% @doc API for starting the supervisor.
  19
+start_link() ->
  20
+    supervisor:start_link({local, ?MODULE}, ?MODULE, []).
  21
+
  22
+%% @spec upgrade() -> ok
  23
+%% @doc Add processes if necessary.
  24
+upgrade() ->
  25
+    {ok, {_, Specs}} = init([]),
  26
+
  27
+    Old = sets:from_list(
  28
+            [Name || {Name, _, _, _} <- supervisor:which_children(?MODULE)]),
  29
+    New = sets:from_list([Name || {Name, _, _, _, _, _} <- Specs]),
  30
+    Kill = sets:subtract(Old, New),
  31
+
  32
+    sets:fold(fun (Id, ok) ->
  33
+                      supervisor:terminate_child(?MODULE, Id),
  34
+                      supervisor:delete_child(?MODULE, Id),
  35
+                      ok
  36
+              end, ok, Kill),
  37
+
  38
+    [supervisor:start_child(?MODULE, Spec) || Spec <- Specs],
  39
+    ok.
  40
+
  41
+%% @spec init([]) -> SupervisorTree
  42
+%% @doc supervisor callback.
  43
+init([]) ->
  44
+    Ip = case os:getenv("MOCHIWEB_IP") of false -> "0.0.0.0"; Any -> Any end,   
  45
+    WebConfig = [
  46
+         {ip, Ip},
  47
+                 {port, 8000},
  48
+                 {docroot, erling_server_deps:local_path(["priv", "www"])}],
  49
+    Web = {erling_server_web,
  50
+           {erling_server_web, start, [WebConfig]},
  51
+           permanent, 5000, worker, dynamic},
  52
+
  53
+    Processes = [Web],
  54
+    {ok, {{one_for_one, 10, 10}, Processes}}.
45  src/erling_server_web.erl
... ...
@@ -0,0 +1,45 @@
  1
+%% @author author <author@example.com>
  2
+%% @copyright YYYY author.
  3
+
  4
+%% @doc Web server for erling_server.
  5
+
  6
+-module(erling_server_web).
  7
+-author('author <author@example.com>').
  8
+
  9
+-export([start/1, stop/0, loop/2]).
  10
+
  11
+%% External API
  12
+
  13
+start(Options) ->
  14
+    {DocRoot, Options1} = get_option(docroot, Options),
  15
+    Loop = fun (Req) ->
  16
+                   ?MODULE:loop(Req, DocRoot)
  17
+           end,
  18
+    mochiweb_http:start([{name, ?MODULE}, {loop, Loop} | Options1]).
  19
+
  20
+stop() ->
  21
+    mochiweb_http:stop(?MODULE).
  22
+
  23
+loop(Req, DocRoot) ->
  24
+    "/" ++ Path = Req:get(path),
  25
+    io:format("Path = [~p]", [Path]),
  26
+    case Req:get(method) of
  27
+        Method when Method =:= 'GET'; Method =:= 'HEAD' ->
  28
+            case Path of
  29
+                _ ->
  30
+                    Req:serve_file(Path, DocRoot)
  31
+            end;
  32
+        'POST' ->
  33
+            io:format("Body = [~p]", [Req:recv_body()]),
  34
+            case Path of
  35
+                _ ->
  36
+                    Req:not_found()
  37
+            end;
  38
+        _ ->
  39
+            Req:respond({501, [], []})
  40
+    end.
  41
+
  42
+%% Internal API
  43
+
  44
+get_option(Option, Options) ->
  45
+    {proplists:get_value(Option, Options), proplists:delete(Option, Options)}.
BIN  temp/client/bin-debug/main.swf
Binary file not shown
2  temp/client/config/services-config.xml
@@ -24,7 +24,7 @@
24 24
 	
25 25
 	<channels>
26 26
 		<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
27  
-			<endpoint uri="http://localhost:8001/erling/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
  27
+			<endpoint uri="http://localhost:8000/erling/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
28 28
 		</channel-definition>
29 29
 	</channels>
30 30
 	
2  temp/client/src/vo/Address.as
... ...
@@ -1,6 +1,6 @@
1 1
 package vo
2 2
 {
3  
-	[RemoteClass(alias="org.mdkt.entity.Addres")]
  3
+	[RemoteClass(alias="org.mdkt.entity.Address")]
4 4
 	[Bindable]
5 5
 	public class Address extends BaseVO
6 6
 	{
39  test/uint29.erl
... ...
@@ -0,0 +1,39 @@
  1
+-module(uint29).
  2
+-compile(export_all).
  3
+
  4
+encode_int29(I) when I >= -16#10000000, I < 0 ->
  5
+    encode_uint29(16#20000000 + I);
  6
+encode_int29(I) when I =< 16#0FFFFFFF ->
  7
+    encode_uint29(I);
  8
+encode_int29(_) ->
  9
+    throw(badrange).
  10
+ 
  11
+encode_uint29(I) when I >= 16#00000000, I =< 16#0000007F ->
  12
+    <<I>>;
  13
+encode_uint29(I) when I >= 16#00000080, I =< 16#00003FFF ->
  14
+    X1 = 16#80 bor (I bsr 7),
  15
+    X2 = I band 16#7F,
  16
+    <<X1, X2>>;
  17
+encode_uint29(I) when I >= 16#00004000, I =< 16#001FFFFF ->
  18
+    X1 = 16#80 bor (I bsr 14),
  19
+    X2 = 16#80 bor (I bsr 7),
  20
+    X3 = I band 16#7F,
  21
+    <<X1, X2, X3>>;
  22
+encode_uint29(I) when I >= 16#00200000, I =< 16#1FFFFFFF ->
  23
+    X1 = 16#80 bor (I bsr 22),
  24
+    X2 = 16#80 bor (I bsr 15),
  25
+    X3 = 16#80 bor (I bsr 8),
  26
+    X4 = I band 16#FF,
  27
+    <<X1, X2, X3, X4>>;
  28
+encode_uint29(_) ->
  29
+    throw(badrange).
  30
+
  31
+decode_uint29(Data) ->
  32
+    decode_uint29(Data, 0, 0).
  33
+ 
  34
+decode_uint29(<<1:1, Num:7, Data/binary>>, Result, N) when N < 3 ->
  35
+    decode_uint29(Data, (Result bsl 7) bor Num, N + 1);
  36
+decode_uint29(<<0:1, Num:7, Data/binary>>, Result, N) when N < 3 ->
  37
+    {(Result bsl 7) bor Num, Data};
  38
+decode_uint29(<<Byte, Data/binary>>, Result, _N) ->
  39
+    {(Result bsl 8) bor Byte, Data}.

0 notes on commit c6b257c

Please sign in to comment.
Something went wrong with that request. Please try again.