Refactor to avoid more static variables
[pazpar2-moved-to-github.git] / src / http_command.c
index f88e296..73a8b1f 100644 (file)
@@ -237,12 +237,7 @@ static int process_settings(struct session *se, struct http_request *rq,
 static void cmd_exit(struct http_channel *c)
 {
     yaz_log(YLOG_WARN, "exit");
-    http_close_server();
-}
-
-static struct conf_service *locate_service(const char *service_name)
-{
-    return global_parameters.server->service;
+    http_close_server(c->server);
 }
 
 static void cmd_init(struct http_channel *c)
@@ -251,9 +246,17 @@ static void cmd_init(struct http_channel *c)
     char buf[1024];
     const char *clear = http_argbyname(c->request, "clear");
     const char *service_name = http_argbyname(c->request, "service");
-    struct http_session *s = http_session_create(locate_service(service_name));
+    struct conf_service *service = locate_service(c->server,
+                                                  service_name);
+    struct http_session *s = http_session_create(service);
     struct http_response *rs = c->response;
 
+    if (!service)
+    {
+        error(rs, PAZPAR2_MALFORMED_PARAMETER_VALUE, "service");
+        return;
+    }
+
     yaz_log(YLOG_DEBUG, "HTTP Session init");
     if (!clear || *clear == '0')
         session_init_databases(s->psession);