\r
-include_lib("xmerl/include/xmerl.hrl").\r
-include_lib("yaws/include/yaws_api.hrl").
+
\r
-% Test du module\r
+% Test du module (TODO)\r
tester() ->
que_dal.\r
\r
-% il faut catcher toutes les exceptions possibles\r
-out(A) ->\r
+out(A) ->
+ %io:format("~p~n~n", [A]),
+ IP = case inet:peername(A#arg.clisock) of
+ {ok, {Adresse, _Port}} -> Adresse;
+ _ -> inconnue
+ end,\r
%inet:setopts(A#arg.clisock, inet:getopts(A#arg.clisock, [active])),\r
{value, {_, Contenu}} = lists:keysearch("action", 1, yaws_api:parse_post(A)),\r
- Ret = traiter_donnees(Contenu),\r
- %{content, "text/xml", Ret}.
+ Ret = traiter_donnees(Contenu, IP),
{content, "application/json", Ret}.\r
\r
-traiter_donnees(Contenu) ->
- % FIXME : ne plus encapsuler le JSON dans de l'xml... apparement yaws veux absolument de l'xml (voir post mi-avril 2008 sur la mailing list)\r
- Reponse = case xmerl_scan:string(Contenu) of
- {#xmlElement{name = json, content = [#xmlText{value = J}|_]}, _} ->
- case json:decode_string(J) of
- {ok, {struct, [{action, Action}| Reste]}} ->
- %io:format("~p~n", [euphorik_protocole:login(JSON)]),
- json:encode(traiter_action(Action, Reste));
- _ ->
- error
- end;
- _ -> error
- end,
- if Reponse =:= error ->
- euphorik_protocole:erreur("Format XML/JSON incorrect");
- true ->
- Reponse
+traiter_donnees(Contenu, IP) ->
+ case json:decode_string(Contenu) of
+ {ok, {struct, [{action, Action}| Reste]}} ->
+ json:encode(traiter_action(Action, Reste, IP));
+ _ ->
+ error
end.
% authentification d'un client
-traiter_action("authentification", JSON) ->
- euphorik_protocole:login(JSON));
+traiter_action("authentification", JSON, IP) ->
+ euphorik_protocole:login(JSON, IP);
% un client s'enregistre (pseudo + password)
-traiter_action("register", JSON) ->
- euphorik_protocole:register(JSON);
+traiter_action("register", JSON, IP) ->
+ euphorik_protocole:register(JSON, IP);
% modification du profile
-traiter_action("set_profile", JSON) ->
+traiter_action("set_profile", JSON, _) ->
euphorik_protocole:profile(JSON);
% un utilisateur attend un événement (par exemple l'arrivé d'un nouveau message)
-traiter_action("wait_event", JSON) ->
+traiter_action("wait_event", JSON, _) ->
euphorik_protocole:wait_event(JSON);
% un utilisateur envoie un message
-traiter_action("put_message", JSON) ->
- euphorik_protocole:message(JSON).\r
-
-
-
-
-traiter_action([#xmlAttribute{value="register"}], XML) ->
- euphorik_protocole:nouveau_user_login(XML);
-traiter_action([#xmlAttribute{value="login"}], XML) ->
- euphorik_protocole:login(XML);
-traiter_action([#xmlAttribute{value="profile"}], XML) ->
- euphorik_protocole:profile(XML);
-traiter_action([#xmlAttribute{value="refreshMessages"}], XML) ->
- euphorik_protocole:refreshMessage(XML);
-% un utilisateur envoie un message
-traiter_action([#xmlAttribute{value="message"}], XML) ->
- euphorik_protocole:message(XML).
+traiter_action("put_message", JSON, _) ->
+ euphorik_protocole:put_message(JSON);
+traiter_action("ban", JSON, _) ->
+ euphorik_protocole:ban(JSON).
\ No newline at end of file