Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added attribute record definition from erlsom. Fixed minor mod bugs.

  • Loading branch information...
commit 80eca158a5197534e761801ec7ebede4e4d6c8d8 1 parent e4a8ca7
@kaos authored
View
7 include/yaxs.hrl
@@ -21,6 +21,13 @@
body=[]
}).
+-record(attribute, {
+ name,
+ prefix,
+ uri,
+ value
+ }).
+
-record(stanza, {
type,
to,
View
20 src/core/yaxs_core_bind.erl
@@ -39,12 +39,24 @@ handle(stream_features,
ok
end;
-handle(#tag{ name="bind" },
- #yaxs_client{ response=_R } = _Client ) ->
-
- {tag, {bind, was_here}}.
+handle(#tag{ name="bind", body=Body },
+ #yaxs_client{ response=_R, tags=Tags } = Client ) ->
+ case proplists:get_value(bind, Tags) of
+ undefined ->
+ bind_to_resource(Body, Client);
+ Res ->
+ {tag, {already_bound, Res}}
+ end.
%%====================================================================
%% Internal functions
%%====================================================================
+
+bind_to_resource([#tag{ name="resource",
+ body=[Resource] }],
+ _Client) ->
+ {tag, {bind, Resource}};
+bind_to_resource(_, _Client) ->
+ {tag, {bind, "generated-resource-name"}}.
+
View
10 src/core/yaxs_core_sasl.erl
@@ -37,15 +37,15 @@ handle(stream_features,
ok;
_ ->
R("<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>"),
- NewTags = yaxs_event:publish(sasl_mechanisms, Client),
+ Res = yaxs_event:publish(sasl_mechanisms, Client),
R("</mechanisms>"),
- {tag, NewTags}
+ Res
end;
handle(#tag{ name="auth", attrs=Attrs } = Event, Client) ->
- [Mechanism] = [list_to_atom(
- "SASL/" ++ Val) || {attribute, Key, _, _, Val} <- Attrs,
- Key == "mechanism"],
+ [Mechanism] = [list_to_atom("SASL/" ++ Val)
+ || #attribute{ name=Key, value=Val } <- Attrs,
+ Key == "mechanism"],
Res = yaxs_event:publish({Mechanism, Event}, Client),
[{tag, {mechanism, Mechanism}}|Res].
View
57 src/test/yaxs_SUITE.erl
@@ -179,34 +179,25 @@ test_stream(_Config) ->
{ok, Sock} = gen_tcp:connect("localhost", 5222, [list, {active, false}]),
open_stream(Sock, "initial"),
- ok = gen_tcp:send(Sock, "
-<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
- ),
+ ok = gen_tcp:send(Sock,
+ "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"
+ ),
{ok, Tls} = gen_tcp:recv(Sock, 0, 1000),
ct:pal("TLS Response:~n~s~n", [Tls]),
open_stream(Sock, "secured (fake)"),
- ok = gen_tcp:send(Sock, "
-<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/>"
+ ok = gen_tcp:send(Sock,
+ "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'/>"
),
{ok, Auth} = gen_tcp:recv(Sock, 0, 1000),
ct:pal("Auth Response:~n~s~n", [Auth]),
open_stream(Sock, "authenticated (fake)"),
- ok = gen_tcp:send(Sock, "
-<iq type='set' id='bind_2'>
- <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>
- <resource>someresource</resource>
- </bind>
-</iq>
-"),
-%% <iq type='set' id='bind_1'>
-%% <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
-%% </iq>
-%% "),
-
+ bind(Sock, 2),
+ bind(Sock, 1),
+
{error, timeout} = gen_tcp:recv(Sock, 0, 500),
ok = gen_tcp:close(Sock).
@@ -215,14 +206,30 @@ test_stream(_Config) ->
%% Utils
+bind(Sock, 1) ->
+ ok = gen_tcp:send(Sock,
+ "<iq type='set' id='bind_1'>
+ <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
+</iq>"
+ );
+bind(Sock, 2) ->
+ ok = gen_tcp:send(Sock,
+ "<iq type='set' id='bind_2'>
+ <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>
+ <resource>someresource</resource>
+ </bind>
+</iq>"
+ ).
+
open_stream(Sock, Comment) ->
- ok = gen_tcp:send(Sock, "
-<?xml version='1.0'?>
- <stream:stream
- to='example.com'
- xmlns='jabber:client'
- xmlns:stream='http://etherx.jabber.org/streams'
- version='1.0'>
-"),
+ ok = gen_tcp:send(
+ Sock,
+ "<?xml version='1.0'?>
+ <stream:stream
+ to='example.com'
+ xmlns='jabber:client'
+ xmlns:stream='http://etherx.jabber.org/streams'
+ version='1.0'>"
+ ),
{ok, Data} = gen_tcp:recv(Sock, 0, 1000),
ct:pal("Response{~s}:~n~s~n", [Comment, Data]).
View
6 src/yaxs_event.erl
@@ -142,7 +142,9 @@ list_mods(Event) ->
do_publish(Event, Client, Mods) ->
error_logger:info_msg("do publish:~nEvent:~p~nClient:~p~nMods:~p~n", [Event, Client, Mods]),
- lists:flatten(
+ Res = lists:flatten(
[Mod:handle(Event, Client) || Mod <- Mods]
- ).
+ ),
+ error_logger:info_msg("publish result: ~p~nMods: ~p~n", [Res, Mods]),
+ Res.
Please sign in to comment.
Something went wrong with that request. Please try again.