]> granicus.if.org Git - ejabberd/commitdiff
Expand parsing of json input to be able to handle update_roster command
authorPaweł Chmielowski <pchmielowski@process-one.net>
Thu, 4 Aug 2016 14:04:43 +0000 (16:04 +0200)
committerPaweł Chmielowski <pchmielowski@process-one.net>
Tue, 13 Sep 2016 09:27:59 +0000 (11:27 +0200)
src/mod_http_api.erl

index e2f6cc2400dd92649b574a242d12cf8c5fcc4426..dbca82375b51a0d355174917abd1e800e435ba41 100644 (file)
@@ -387,6 +387,20 @@ format_args(Args, ArgsFormat) ->
       L when is_list(L) -> exit({additional_unused_args, L})
     end.
 
+format_arg({Elements},
+          {list, {_ElementDefName, {tuple, [{_Tuple1N, Tuple1S}, {_Tuple2N, Tuple2S}]} = Tuple}})
+    when is_list(Elements) andalso
+        (Tuple1S == binary orelse Tuple1S == string) ->
+    lists:map(fun({F1, F2}) ->
+                     {format_arg(F1, Tuple1S), format_arg(F2, Tuple2S)};
+                ({Val}) when is_list(Val) ->
+                     format_arg({Val}, Tuple)
+             end, Elements);
+format_arg(Elements,
+          {list, {_ElementDefName, {list, _} = ElementDefFormat}})
+    when is_list(Elements) ->
+    [{format_arg(Element, ElementDefFormat)}
+     || Element <- Elements];
 format_arg(Elements,
           {list, {_ElementDefName, ElementDefFormat}})
     when is_list(Elements) ->
@@ -494,6 +508,11 @@ format_result({Code, Text}, {Name, restuple}) ->
      {[{<<"res">>, Code == true orelse Code == ok},
        {<<"text">>, iolist_to_binary(Text)}]}};
 
+format_result(Code, {Name, restuple}) ->
+    {jlib:atom_to_binary(Name),
+     {[{<<"res">>, Code == true orelse Code == ok},
+       {<<"text">>, <<"">>}]}};
+
 format_result(Els, {Name, {list, {_, {tuple, [{_, atom}, _]}} = Fmt}}) ->
     {jlib:atom_to_binary(Name), {[format_result(El, Fmt) || El <- Els]}};