% This module responds to JSON requests via 'AJAX'.\r
% It's defined as an Yaws 'appmods' with the url '/request'.\r
% For instance in debug mode 'http://localhost:8090/request' will call the out/1 function.\r
-% @author G.Burri\r
\r
\r
-module(euphorik_requests).\r
+-author("Greg Burri <greg.burri@gmail.com>").\r
-export([out/1]).\r
-include_lib("yaws_api.hrl").\r
-include("../include/euphorik_defines.hrl").\r
end,\r
% active: to receive {tcp_closed, _} when the socket is closing.\r
% keepalive: avoid firewalls to cut the connection.\r
+\r
inet:setopts(A#arg.clisock, [{active, true}, {keepalive, true}]),\r
{value, {_, Contenu}} = lists:keysearch("action", 1, yaws_api:parse_post(A)),\r
+\r
Ret = traiter_message(Contenu, IP),\r
{content, "application/json", Ret}.\r
\r
% DĂ©code le message JSON.\r
traiter_message(Contenu, IP) ->\r
% extrait l'entĂȘte obligatoire des messages JSON\r
- {ok, {struct, [{header, {struct, [{action, Action}, {version, Version_client}]}} | Reste]}} = json:decode_string(Contenu),\r
- json:encode(\r
+ {ok, {struct, [{"header", {struct, [{"action", Action}, {"version", Version_client}]}} | Reste]}} = json2:decode_string(Contenu),\r
+\r
+ json2:encode(\r
if Version_client =:= ?VERSION_PROTOCOLE ->\r
traiter_action(Action, Reste, IP);\r
true ->\r