2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "gateway_controller.h"
17 #include "../manager.h"
18 #include "../gateway.h"
23 typedef struct private_gateway_controller_t private_gateway_controller_t
;
26 * private data of the gateway_controller
28 struct private_gateway_controller_t
{
33 gateway_controller_t
public;
42 static void list(private_gateway_controller_t
*this, request_t
*request
)
44 enumerator_t
*enumerator
;
48 enumerator
= this->manager
->create_gateway_enumerator(this->manager
);
49 while (enumerator
->enumerate(enumerator
, &id
, &name
, &port
, &address
))
51 request
->setf(request
, "gateways.%d.name=%s", id
, name
);
54 request
->setf(request
, "gateways.%d.address=tcp://%s:%d",
59 request
->setf(request
, "gateways.%d.address=unix://%s",
60 id
, IPSEC_PIDDIR
"/charon.xml");
63 enumerator
->destroy(enumerator
);
64 request
->set(request
, "action", "select");
65 request
->set(request
, "title", "Choose gateway");
66 request
->render(request
, "templates/gateway/list.cs");
69 static void _select(private_gateway_controller_t
*this, request_t
*request
)
73 id
= request
->get_query_data(request
, "gateway");
76 if (this->manager
->select_gateway(this->manager
, atoi(id
)))
78 request
->redirect(request
, "ikesa/list");
82 request
->redirect(request
, "gateway/list");
86 * Implementation of controller_t.get_name
88 static char* get_name(private_gateway_controller_t
*this)
94 * Implementation of controller_t.handle
96 static void handle(private_gateway_controller_t
*this,
97 request_t
*request
, char *action
)
99 if (!this->manager
->logged_in(this->manager
))
101 return request
->redirect(request
, "auth/login");
105 if (streq(action
, "list"))
107 return list(this, request
);
109 else if (streq(action
, "select"))
111 return _select(this, request
);
114 request
->redirect(request
, "gateway/list");
119 * Implementation of controller_t.destroy
121 static void destroy(private_gateway_controller_t
*this)
129 controller_t
*gateway_controller_create(context_t
*context
, void *param
)
131 private_gateway_controller_t
*this = malloc_thing(private_gateway_controller_t
);
133 this->public.controller
.get_name
= (char*(*)(controller_t
*))get_name
;
134 this->public.controller
.handle
= (void(*)(controller_t
*,request_t
*,char*,char*,char*,char*,char*))handle
;
135 this->public.controller
.destroy
= (void(*)(controller_t
*))destroy
;
137 this->manager
= (manager_t
*)context
;
139 return &this->public.controller
;