2 * @file gateway_controller.c
4 * @brief Implementation of gateway_controller_t.
9 * Copyright (C) 2007 Martin Willi
10 * Hochschule fuer Technik Rapperswil
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 #include "gateway_controller.h"
24 #include "../manager.h"
25 #include "../gateway.h"
30 typedef struct private_gateway_controller_t private_gateway_controller_t
;
33 * private data of the gateway_controller
35 struct private_gateway_controller_t
{
40 gateway_controller_t
public;
49 static void list(private_gateway_controller_t
*this, request_t
*request
)
51 enumerator_t
*enumerator
;
55 enumerator
= this->manager
->create_gateway_enumerator(this->manager
);
56 while (enumerator
->enumerate(enumerator
, &id
, &name
, &port
, &address
))
58 request
->setf(request
, "gateways.%d.name=%s", id
, name
);
61 request
->setf(request
, "gateways.%d.address=tcp://%s:%d",
66 request
->setf(request
, "gateways.%d.address=unix://%s",
67 id
, IPSEC_PIDDIR
"/charon.xml");
70 enumerator
->destroy(enumerator
);
71 request
->set(request
, "action", "select");
72 request
->set(request
, "title", "Choose gateway");
73 request
->render(request
, "templates/gateway/list.cs");
76 static void _select(private_gateway_controller_t
*this, request_t
*request
)
80 id
= request
->get_query_data(request
, "gateway");
83 if (this->manager
->select_gateway(this->manager
, atoi(id
)))
85 request
->redirect(request
, "ikesa/list");
89 request
->redirect(request
, "gateway/list");
93 * Implementation of controller_t.get_name
95 static char* get_name(private_gateway_controller_t
*this)
101 * Implementation of controller_t.handle
103 static void handle(private_gateway_controller_t
*this,
104 request_t
*request
, char *action
)
106 if (!this->manager
->logged_in(this->manager
))
108 return request
->redirect(request
, "auth/login");
112 if (streq(action
, "list"))
114 return list(this, request
);
116 else if (streq(action
, "select"))
118 return _select(this, request
);
121 request
->redirect(request
, "gateway/list");
126 * Implementation of controller_t.destroy
128 static void destroy(private_gateway_controller_t
*this)
136 controller_t
*gateway_controller_create(context_t
*context
, void *param
)
138 private_gateway_controller_t
*this = malloc_thing(private_gateway_controller_t
);
140 this->public.controller
.get_name
= (char*(*)(controller_t
*))get_name
;
141 this->public.controller
.handle
= (void(*)(controller_t
*,request_t
*,char*,char*,char*,char*,char*))handle
;
142 this->public.controller
.destroy
= (void(*)(controller_t
*))destroy
;
144 this->manager
= (manager_t
*)context
;
146 return &this->public.controller
;