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
18 #include "gateway_controller.h"
19 #include "../manager.h"
20 #include "../gateway.h"
25 typedef struct private_gateway_controller_t private_gateway_controller_t
;
28 * private data of the gateway_controller
30 struct private_gateway_controller_t
{
35 gateway_controller_t
public;
44 static void list(private_gateway_controller_t
*this, request_t
*request
)
46 enumerator_t
*enumerator
;
50 enumerator
= this->manager
->create_gateway_enumerator(this->manager
);
51 while (enumerator
->enumerate(enumerator
, &id
, &name
, &port
, &address
))
53 request
->setf(request
, "gateways.%d.name=%s", id
, name
);
56 request
->setf(request
, "gateways.%d.address=tcp://%s:%d",
61 request
->setf(request
, "gateways.%d.address=unix://%s",
62 id
, IPSEC_PIDDIR
"/charon.xml");
65 enumerator
->destroy(enumerator
);
66 request
->set(request
, "action", "select");
67 request
->set(request
, "title", "Choose gateway");
68 request
->render(request
, "templates/gateway/list.cs");
71 static void _select(private_gateway_controller_t
*this, request_t
*request
)
75 id
= request
->get_query_data(request
, "gateway");
78 if (this->manager
->select_gateway(this->manager
, atoi(id
)))
80 request
->redirect(request
, "ikesa/list");
84 request
->redirect(request
, "gateway/list");
88 * Implementation of controller_t.get_name
90 static char* get_name(private_gateway_controller_t
*this)
96 * Implementation of controller_t.handle
98 static void handle(private_gateway_controller_t
*this,
99 request_t
*request
, char *action
)
101 if (!this->manager
->logged_in(this->manager
))
103 return request
->redirect(request
, "auth/login");
107 if (streq(action
, "list"))
109 return list(this, request
);
111 else if (streq(action
, "select"))
113 return _select(this, request
);
116 request
->redirect(request
, "gateway/list");
121 * Implementation of controller_t.destroy
123 static void destroy(private_gateway_controller_t
*this)
131 controller_t
*gateway_controller_create(context_t
*context
, void *param
)
133 private_gateway_controller_t
*this = malloc_thing(private_gateway_controller_t
);
135 this->public.controller
.get_name
= (char*(*)(controller_t
*))get_name
;
136 this->public.controller
.handle
= (void(*)(controller_t
*,request_t
*,char*,char*,char*,char*,char*))handle
;
137 this->public.controller
.destroy
= (void(*)(controller_t
*))destroy
;
139 this->manager
= (manager_t
*)context
;
141 return &this->public.controller
;