* http://cs.unibo.it/helm/.
*)
-let debug = true;;
+let debug = false;;
let debug_print s = if debug then prerr_endline s;;
Http_common.debug := debug;;
open Printf;;
let daemon_name = "Search Engine";;
-let default_port = 48085;;
+let default_port = 58085;;
let port_env_var = "SEARCH_ENGINE_PORT";;
let port =
(sprintf "<html><body><pre>%s</pre></body></html>" result_string)
in
let pp_error = sprintf "<html><body><h1>Error: %s</h1></body></html>" in
+let bad_request body outchan =
+ Http_daemon.respond_error ~status:(`Client_error `Bad_request) ~body outchan
+in
let callback req outchan =
try
- (* TODO catch exceptions *)
(match req#path with
| "/execute" ->
let query_string = req#param "query" in
let result_string = MQueryUtil.text_of_result result "\n" in
Http_daemon.respond
~body:
- (sprintf
- "<html><body><pre>%s</pre></body></html>"
- result_string)
+ (sprintf "<html><body><pre>%s</pre></body></html>" result_string)
outchan
| "/locate" ->
let id = req#param "id" in
(match dom with
| [] -> (* no free variables *)
let term = mkterm (fun _ -> None) in
+ prerr_endline (CicPp.ppterm term);
let result = MQueryGenerator.searchPattern [] [] term precision in
Http_daemon.respond ~body:(pp_result result) outchan
| _ ->
Http_daemon.respond_error ~status:(`Client_error `Bad_request) outchan)
with
| Http_request.Param_not_found attr_name ->
- Http_daemon.respond_error
- ~status:(`Client_error `Bad_request)
- ~body:(sprintf "Parameter '%s' is missing" attr_name)
- outchan
+ bad_request (sprintf "Parameter '%s' is missing" attr_name) outchan
+ | Failure "int_of_string" ->
+ bad_request "Invalid 'precision' value, must be an integer" outchan
+ | exc ->
+ Http_daemon.respond
+ ~body:(pp_error ("Uncaught exception: " ^ (Printexc.to_string exc)))
+ outchan
in
printf "%s started and listening on port %d\n" daemon_name port;
printf "current directory is %s\n" (Sys.getcwd ());
flush stdout;
+Mqint.set_database Mqint.postgres_db;
+Mqint.init "host=mowgli.cs.unibo.it dbname=helm_mowgli user=helm";
Http_daemon.start' ~port callback;
+Mqint.close ();
printf "%s is terminating, bye!\n" daemon_name