diff --git a/LICENSE b/LICENSE index c1808387..653a6893 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2013 Maxim Sokhatsky, Synrc Research Center +Copyright (c) 2013—2015 Maxim Sokhatsky, Synrc Research Center Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/include/wf.hrl b/include/wf.hrl index 6240921f..06d7b885 100644 --- a/include/wf.hrl +++ b/include/wf.hrl @@ -1,15 +1,13 @@ -ifndef(N2O_HRL). -define(N2O_HRL, true). --define(CTX, (wf_context:context())). --define(REQ, (wf_context:context())#cx.req). +-record(handler, { name, module, config, state}). +-record(cx, { handlers, actions, req, module, lang, path, session, params, form, state=[] }). --define(ACTION(Module), ancestor=action, trigger, target, module=Module, actions, source=[]). +-define(CTX, (get(context))). +-define(REQ, (get(context))#cx.req). -% Actions --record(wire, {?ACTION(action_wire)}). --record(event, {?ACTION(action_event)}). --record(jq, {?ACTION(action_jq), property, method, args=[], right, format="~s"}). +% API -define(HANDLER_API, [init/2, finish/2]). -define(FAULTER_API, [error_page/2]). @@ -19,20 +17,25 @@ -define(PICKLES_API, [pickle/1, depickle/1]). -define(MESSAGE_API, [send/2, reg/1, reg/2, unreg/1]). --record(handler, {name, module, config, state}). --record(cx, {handlers, actions, req, module, lang, path, session, params, form, state=[]}). --record(ev, {module, msg, trigger, name :: api_event | control_event | event | atom() }). - -%Binary messaging to browser --record(binary, { - id = 0 :: integer(), % 4 bytes unsigned - type = 0 :: integer(), % 1 byte unsigned - app = 0 :: integer(), % 1 byte unsigned - version = 0 :: integer(), % 1 byte unsigned - from = 0 :: integer(), % 4 bytes unsigned - to = 0 :: integer(), % 4 bytes unsigned - user1 = 0 :: integer(), % 8 bytes signed float, user defined, e.g.: -define(TIMESTAMP, user1). - user2 = 0 :: integer(), % 8 bytes signed float, user defined, e.g.: -define(EXPIRES, user2). - meta = <<>> :: binary(), % binary - data = <<>> :: binary() }). % binary +% IO protocol + +-record(io, { eval, data }). +-record(bin, { meta, data }). + +% Client/Server protocol + +-record(client, { data }). +-record(server, { data }). + +% Nitrogen Protocol + +-record(pickle, { source, pickled, args }). +-record(flush, { data }). +-record(direct, { data }). +-record(ev, { module, msg, trigger, name }). + +% File Transfer Protocol + +-record(ftp, { id, type, app, version, from, to, meta, data }). + -endif. diff --git a/rebar.config b/rebar.config index 05f53667..372539e7 100644 --- a/rebar.config +++ b/rebar.config @@ -1,6 +1,7 @@ {lib_dirs,[".."]}. {deps_dir,["deps"]}. {deps,[ + {nitro, ".*", {git, "git://github.com/synrc/nitro.git", {tag,"master"}}}, {jsone, ".*", {git, "git://github.com/sile/jsone.git", {tag,"v0.3.3"}}}, {cowboy, ".*", {git, "git://github.com/extend/cowboy", {tag,"1.0.1"}}}, {gproc, ".*", {git, "git://github.com/uwiger/gproc.git", {tag,"0.3"}}} diff --git a/src/n2o.app.src b/src/n2o.app.src index 65822e8c..ebfefd81 100644 --- a/src/n2o.app.src +++ b/src/n2o.app.src @@ -1,7 +1,7 @@ {application, n2o, [ {description, "N2O WebSocket Application Server"}, {vsn, "2.9"}, - {applications, [kernel, stdlib, cowboy, ranch, gproc]}, + {applications, [kernel, stdlib, cowboy, gproc]}, {modules, []}, {registered, []}, {mod, { n2o_app, []}}, diff --git a/src/protocols/n2o_binary.erl b/src/protocols/n2o_file.erl similarity index 78% rename from src/protocols/n2o_binary.erl rename to src/protocols/n2o_file.erl index 44d2d45d..c109b547 100644 --- a/src/protocols/n2o_binary.erl +++ b/src/protocols/n2o_file.erl @@ -1,4 +1,4 @@ --module(n2o_binary). +-module(n2o_file). -author('Andrey Martemyanov'). -include_lib("n2o/include/wf.hrl"). -compile(export_all). @@ -14,13 +14,12 @@ info({bin,Message}, Req, State) -> Term = try Module:event({bin,DpkldMessage}) catch E:R -> wf:error(?MODULE,"Catch: ~p:~p~n~p", wf:stack(E, R)), <<>> end, wf:info(?MODULE,"Raw Binary Message: ~p Result: ~p",[Message,Term]), Res = case Term of - #binary{ + #ftp{ id=Id, type=Type, app=App, version=Version, - from=From, to=To, user1=User1, user2=User2, meta=Meta, data=Data } -> + from=From, to=To, meta=Meta, data=Data } -> MetaSize = byte_size(Meta), <<132,Id:32,Type:8,App:8,Version:8, - From:32,To:32,User1:64/float,User2:64/float, - MetaSize:32,Meta/binary,Data/binary>>; + From:32,To:32,MetaSize:32,Meta/binary,Data/binary>>; _ when is_binary(Term) -> Term; _ -> term_to_binary(Term) end, {reply,{binary,Res},Req,State};