- (Http_getter_env.reload (); (* reload servers list from servers file *)
- xml_map#clear; rdf_map#clear; xsl_map#clear;
- let log =
- List.fold_left
- update_from_server
- "" (* initial logmsg: empty *)
- (* reverse order: 1st server is the most important one *)
- (List.rev !Http_getter_env.servers)
+ Http_getter_env.reload (); (* reload servers list from servers file *)
+ let log = update_from_all_servers () in
+ return_html_msg log outchan
+ | "/list_servers" ->
+ return_html_raw
+ (sprintf "<html><body><table>\n%s\n</table></body></html>"
+ (String.concat "\n"
+ (List.map
+ (let i = ref ~-1 in
+ fun s -> incr i; sprintf "<tr><td>%d</td><td>%s</td></tr>" !i s)
+ !Http_getter_env.servers)))
+ outchan
+ | "/add_server" ->
+ let name = req#param "url" in
+ (try
+ let position =
+ try
+ let res = int_of_string (req#param "position") in
+ if res < 0 then
+ raise (Failure "int_of_string");
+ res
+ with Failure "int_of_string" ->
+ raise (Http_getter_bad_request
+ (sprintf "position must be a non negative integer (%s given)"
+ (req#param "position")))
+ in
+ if position = 0 then (* fallback to default value *)
+ raise (Http_types.Param_not_found "foo")
+ else if position > 0 then begin (* add server and update all *)
+ Http_getter_env.add_server ~position name;
+ let log = update_from_all_servers () in
+ return_html_msg
+ (sprintf "Added server %s in position %d)<br />\n%s"
+ name position log)
+ outchan
+ end else (* position < 0 *) (* error! *)
+ assert false (* already checked above *)
+ with Http_types.Param_not_found _ -> (* add as 1st server by default *)
+ Http_getter_env.add_server ~position:0 name;
+ let log = update_from_server (* quick update (new server only) *)
+ (sprintf "Added server %s in head position<br />\n" name) name
+ in
+ return_html_msg log outchan)
+ | "/remove_server" ->
+ let position =
+ try
+ let res = int_of_string (req#param "position") in
+ if res < 0 then
+ raise (Failure "int_of_string");
+ res
+ with Failure "int_of_string" ->
+ raise (Http_getter_bad_request
+ (sprintf "position must be a non negative integer (%s given)"
+ (req#param "position")))