diff options
Diffstat (limited to 'src/manager')
-rw-r--r-- | src/manager/Makefile.in | 7 | ||||
-rw-r--r-- | src/manager/controller/auth_controller.c | 39 | ||||
-rw-r--r-- | src/manager/controller/config_controller.c | 39 | ||||
-rw-r--r-- | src/manager/controller/control_controller.c | 39 | ||||
-rw-r--r-- | src/manager/controller/gateway_controller.c | 40 | ||||
-rw-r--r-- | src/manager/controller/ikesa_controller.c | 39 | ||||
-rw-r--r-- | src/manager/gateway.c | 65 | ||||
-rw-r--r-- | src/manager/gateway.h | 3 | ||||
-rw-r--r-- | src/manager/manager.c | 63 | ||||
-rw-r--r-- | src/manager/manager.h | 4 | ||||
-rw-r--r-- | src/manager/storage.c | 35 | ||||
-rw-r--r-- | src/manager/storage.h | 2 | ||||
-rw-r--r-- | src/manager/templates/static/jquery.js | 2 | ||||
-rw-r--r-- | src/manager/xml.c | 66 |
14 files changed, 211 insertions, 232 deletions
diff --git a/src/manager/Makefile.in b/src/manager/Makefile.in index 4b9c0ebae..8ae5ebf36 100644 --- a/src/manager/Makefile.in +++ b/src/manager/Makefile.in @@ -208,6 +208,9 @@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ +attest_plugins = @attest_plugins@ +axis2c_CFLAGS = @axis2c_CFLAGS@ +axis2c_LIBS = @axis2c_LIBS@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ @@ -216,6 +219,7 @@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ c_plugins = @c_plugins@ +clearsilver_LIBS = @clearsilver_LIBS@ datadir = @datadir@ datarootdir = @datarootdir@ dbusservicedir = @dbusservicedir@ @@ -232,11 +236,13 @@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ +imcvdir = @imcvdir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ ipsecdir = @ipsecdir@ ipsecgroup = @ipsecgroup@ +ipseclibdir = @ipseclibdir@ ipsecuser = @ipsecuser@ libcharon_plugins = @libcharon_plugins@ libdir = @libdir@ @@ -280,6 +286,7 @@ sharedstatedir = @sharedstatedir@ soup_CFLAGS = @soup_CFLAGS@ soup_LIBS = @soup_LIBS@ srcdir = @srcdir@ +starter_plugins = @starter_plugins@ strongswan_conf = @strongswan_conf@ sysconfdir = @sysconfdir@ systemdsystemunitdir = @systemdsystemunitdir@ diff --git a/src/manager/controller/auth_controller.c b/src/manager/controller/auth_controller.c index dd469cee4..c9a9b5461 100644 --- a/src/manager/controller/auth_controller.c +++ b/src/manager/controller/auth_controller.c @@ -67,19 +67,15 @@ static void logout(private_auth_controller_t *this, request_t *request) request->redirect(request, "auth/login"); } -/** - * Implementation of controller_t.get_name - */ -static char* get_name(private_auth_controller_t *this) +METHOD(controller_t, get_name, char*, + private_auth_controller_t *this) { return "auth"; } -/** - * Implementation of controller_t.handle - */ -static void handle(private_auth_controller_t *this, - request_t *request, char *action) +METHOD(controller_t, handle, void, + private_auth_controller_t *this, request_t *request, char *action, + char *p2, char *p3, char *p4, char *p5) { if (action) { @@ -99,10 +95,8 @@ static void handle(private_auth_controller_t *this, request->redirect(request, "auth/login"); } -/** - * Implementation of controller_t.destroy - */ -static void destroy(private_auth_controller_t *this) +METHOD(controller_t, destroy, void, + private_auth_controller_t *this) { free(this); } @@ -112,13 +106,18 @@ static void destroy(private_auth_controller_t *this) */ controller_t *auth_controller_create(context_t *context, void *param) { - private_auth_controller_t *this = malloc_thing(private_auth_controller_t); - - this->public.controller.get_name = (char*(*)(controller_t*))get_name; - this->public.controller.handle = (void(*)(controller_t*,request_t*,char*,char*,char*,char*,char*))handle; - this->public.controller.destroy = (void(*)(controller_t*))destroy; - - this->manager = (manager_t*)context; + private_auth_controller_t *this; + + INIT(this, + .public = { + .controller = { + .get_name = _get_name, + .handle = _handle, + .destroy = _destroy, + }, + }, + .manager = (manager_t*)context, + ); return &this->public.controller; } diff --git a/src/manager/controller/config_controller.c b/src/manager/controller/config_controller.c index 828a4ac97..154ab615e 100644 --- a/src/manager/controller/config_controller.c +++ b/src/manager/controller/config_controller.c @@ -149,19 +149,15 @@ static void list(private_config_controller_t *this, request_t *r) } } -/** - * Implementation of controller_t.get_name - */ -static char* get_name(private_config_controller_t *this) +METHOD(controller_t, get_name, char*, + private_config_controller_t *this) { return "config"; } -/** - * Implementation of controller_t.handle - */ -static void handle(private_config_controller_t *this, - request_t *request, char *action) +METHOD(controller_t, handle, void, + private_config_controller_t *this, request_t *request, char *action, + char *p2, char *p3, char *p4, char *p5) { if (!this->manager->logged_in(this->manager)) { @@ -181,10 +177,8 @@ static void handle(private_config_controller_t *this, return request->redirect(request, "config/list"); } -/** - * Implementation of controller_t.destroy - */ -static void destroy(private_config_controller_t *this) +METHOD(controller_t, destroy, void, + private_config_controller_t *this) { free(this); } @@ -194,13 +188,18 @@ static void destroy(private_config_controller_t *this) */ controller_t *config_controller_create(context_t *context, void *param) { - private_config_controller_t *this = malloc_thing(private_config_controller_t); - - this->public.controller.get_name = (char*(*)(controller_t*))get_name; - this->public.controller.handle = (void(*)(controller_t*,request_t*,char*,char*,char*,char*,char*))handle; - this->public.controller.destroy = (void(*)(controller_t*))destroy; - - this->manager = (manager_t*)context; + private_config_controller_t *this; + + INIT(this, + .public = { + .controller = { + .get_name = _get_name, + .handle = _handle, + .destroy = _destroy, + }, + }, + .manager = (manager_t*)context, + ); return &this->public.controller; } diff --git a/src/manager/controller/control_controller.c b/src/manager/controller/control_controller.c index fdf66bf14..68238d02f 100644 --- a/src/manager/controller/control_controller.c +++ b/src/manager/controller/control_controller.c @@ -120,19 +120,15 @@ static void terminate(private_control_controller_t *this, request_t *r, handle_result(this, r, e); } -/** - * Implementation of controller_t.get_name - */ -static char* get_name(private_control_controller_t *this) +METHOD(controller_t, get_name, char*, + private_control_controller_t *this) { return "control"; } -/** - * Implementation of controller_t.handle - */ -static void handle(private_control_controller_t *this, - request_t *request, char *action, char *str) +METHOD(controller_t, handle, void, + private_control_controller_t *this, request_t *request, char *action, + char *str, char *p3, char *p4, char *p5) { if (!this->manager->logged_in(this->manager)) { @@ -178,10 +174,8 @@ static void handle(private_control_controller_t *this, return request->redirect(request, "ikesa/list"); } -/** - * Implementation of controller_t.destroy - */ -static void destroy(private_control_controller_t *this) +METHOD(controller_t, destroy, void, + private_control_controller_t *this) { free(this); } @@ -191,13 +185,18 @@ static void destroy(private_control_controller_t *this) */ controller_t *control_controller_create(context_t *context, void *param) { - private_control_controller_t *this = malloc_thing(private_control_controller_t); - - this->public.controller.get_name = (char*(*)(controller_t*))get_name; - this->public.controller.handle = (void(*)(controller_t*,request_t*,char*,char*,char*,char*,char*))handle; - this->public.controller.destroy = (void(*)(controller_t*))destroy; - - this->manager = (manager_t*)context; + private_control_controller_t *this; + + INIT(this, + .public = { + .controller = { + .get_name = _get_name, + .handle = _handle, + .destroy = _destroy, + }, + }, + .manager = (manager_t*)context, + ); return &this->public.controller; } diff --git a/src/manager/controller/gateway_controller.c b/src/manager/controller/gateway_controller.c index 9fca220e9..39d344502 100644 --- a/src/manager/controller/gateway_controller.c +++ b/src/manager/controller/gateway_controller.c @@ -82,19 +82,15 @@ static void _select(private_gateway_controller_t *this, request_t *request) request->redirect(request, "gateway/list"); } -/** - * Implementation of controller_t.get_name - */ -static char* get_name(private_gateway_controller_t *this) +METHOD(controller_t, get_name, char*, + private_gateway_controller_t *this) { return "gateway"; } -/** - * Implementation of controller_t.handle - */ -static void handle(private_gateway_controller_t *this, - request_t *request, char *action) +METHOD(controller_t, handle, void, + private_gateway_controller_t *this, request_t *request, char *action, + char *p2, char *p3, char *p4, char *p5) { if (!this->manager->logged_in(this->manager)) { @@ -114,11 +110,8 @@ static void handle(private_gateway_controller_t *this, request->redirect(request, "gateway/list"); } - -/** - * Implementation of controller_t.destroy - */ -static void destroy(private_gateway_controller_t *this) +METHOD(controller_t, destroy, void, + private_gateway_controller_t *this) { free(this); } @@ -128,13 +121,18 @@ static void destroy(private_gateway_controller_t *this) */ controller_t *gateway_controller_create(context_t *context, void *param) { - private_gateway_controller_t *this = malloc_thing(private_gateway_controller_t); - - this->public.controller.get_name = (char*(*)(controller_t*))get_name; - this->public.controller.handle = (void(*)(controller_t*,request_t*,char*,char*,char*,char*,char*))handle; - this->public.controller.destroy = (void(*)(controller_t*))destroy; - - this->manager = (manager_t*)context; + private_gateway_controller_t *this; + + INIT(this, + .public = { + .controller = { + .get_name = _get_name, + .handle = _handle, + .destroy = _destroy, + }, + }, + .manager = (manager_t*)context, + ); return &this->public.controller; } diff --git a/src/manager/controller/ikesa_controller.c b/src/manager/controller/ikesa_controller.c index afa4a67f8..716d51a7a 100644 --- a/src/manager/controller/ikesa_controller.c +++ b/src/manager/controller/ikesa_controller.c @@ -173,19 +173,15 @@ static void list(private_ikesa_controller_t *this, request_t *r) } } -/** - * Implementation of controller_t.get_name - */ -static char* get_name(private_ikesa_controller_t *this) +METHOD(controller_t, get_name, char*, + private_ikesa_controller_t *this) { return "ikesa"; } -/** - * Implementation of controller_t.handle - */ -static void handle(private_ikesa_controller_t *this, - request_t *request, char *action) +METHOD(controller_t, handle, void, + private_ikesa_controller_t *this, request_t *request, char *action, + char *p2, char *p3, char *p4, char *p5) { if (!this->manager->logged_in(this->manager)) { @@ -205,10 +201,8 @@ static void handle(private_ikesa_controller_t *this, return request->redirect(request, "ikesa/list"); } -/** - * Implementation of controller_t.destroy - */ -static void destroy(private_ikesa_controller_t *this) +METHOD(controller_t, destroy, void, + private_ikesa_controller_t *this) { free(this); } @@ -218,13 +212,18 @@ static void destroy(private_ikesa_controller_t *this) */ controller_t *ikesa_controller_create(context_t *context, void *param) { - private_ikesa_controller_t *this = malloc_thing(private_ikesa_controller_t); - - this->public.controller.get_name = (char*(*)(controller_t*))get_name; - this->public.controller.handle = (void(*)(controller_t*,request_t*,char*,char*,char*,char*,char*))handle; - this->public.controller.destroy = (void(*)(controller_t*))destroy; - - this->manager = (manager_t*)context; + private_ikesa_controller_t *this; + + INIT(this, + .public = { + .controller = { + .get_name = _get_name, + .handle = _handle, + .destroy = _destroy, + }, + }, + .manager = (manager_t*)context, + ); return &this->public.controller; } diff --git a/src/manager/gateway.c b/src/manager/gateway.c index fd462afa7..8a8fbe895 100644 --- a/src/manager/gateway.c +++ b/src/manager/gateway.c @@ -98,10 +98,8 @@ static bool connect_(private_gateway_t *this) return TRUE; } -/** - * Implementation of gateway_t.request. - */ -static char* request(private_gateway_t *this, char *xml, ...) +METHOD(gateway_t, request, char*, + private_gateway_t *this, char *xml, ...) { if (this->fd < 0) { @@ -145,10 +143,8 @@ static char* request(private_gateway_t *this, char *xml, ...) } } -/** - * Implementation of gateway_t.query_ikesalist. - */ -static enumerator_t* query_ikesalist(private_gateway_t *this) +METHOD(gateway_t, query_ikesalist, enumerator_t*, + private_gateway_t *this) { char *str, *name, *value; xml_t *xml; @@ -202,11 +198,8 @@ static enumerator_t* query_ikesalist(private_gateway_t *this) return NULL; } - -/** - * Implementation of gateway_t.query_configlist. - */ -static enumerator_t* query_configlist(private_gateway_t *this) +METHOD(gateway_t, query_configlist, enumerator_t*, + private_gateway_t *this) { char *str, *name, *value; xml_t *xml; @@ -302,10 +295,8 @@ static enumerator_t* read_result(private_gateway_t *this, char *res) return NULL; } -/** - * Implementation of gateway_t.initiate. - */ -static enumerator_t* initiate(private_gateway_t *this, bool ike, char *name) +METHOD(gateway_t, initiate, enumerator_t*, + private_gateway_t *this, bool ike, char *name) { char *str, *kind; @@ -325,10 +316,8 @@ static enumerator_t* initiate(private_gateway_t *this, bool ike, char *name) return read_result(this, str); } -/** - * Implementation of gateway_t.terminate. - */ -static enumerator_t* terminate(private_gateway_t *this, bool ike, u_int32_t id) +METHOD(gateway_t, terminate, enumerator_t*, + private_gateway_t *this, bool ike, u_int32_t id) { char *str, *kind; @@ -348,10 +337,8 @@ static enumerator_t* terminate(private_gateway_t *this, bool ike, u_int32_t id) return read_result(this, str); } -/** - * Implementation of gateway_t.destroy - */ -static void destroy(private_gateway_t *this) +METHOD(gateway_t, destroy, void, + private_gateway_t *this) { if (this->fd >= 0) { @@ -367,19 +354,21 @@ static void destroy(private_gateway_t *this) */ static private_gateway_t *gateway_create(char *name) { - private_gateway_t *this = malloc_thing(private_gateway_t); - - this->public.request = (char*(*)(gateway_t*, char *xml))request; - this->public.query_ikesalist = (enumerator_t*(*)(gateway_t*))query_ikesalist; - this->public.query_configlist = (enumerator_t*(*)(gateway_t*))query_configlist; - this->public.initiate = (enumerator_t*(*)(gateway_t*, bool ike, char *name))initiate; - this->public.terminate = (enumerator_t*(*)(gateway_t*, bool ike, u_int32_t id))terminate; - this->public.destroy = (void(*)(gateway_t*))destroy; - - this->name = strdup(name); - this->host = NULL; - this->fd = -1; - this->xmlid = 1; + private_gateway_t *this; + + INIT(this, + .public = { + .request = _request, + .query_ikesalist = _query_ikesalist, + .query_configlist = _query_configlist, + .initiate = _initiate, + .terminate = _terminate, + .destroy = _destroy, + }, + .name = strdup(name), + .fd = -1, + .xmlid = 1, + ); return this; } diff --git a/src/manager/gateway.h b/src/manager/gateway.h index 54aade7b1..db44a2ffa 100644 --- a/src/manager/gateway.h +++ b/src/manager/gateway.h @@ -35,9 +35,10 @@ struct gateway_t { * Send an XML request to the gateway. * * @param xml xml request string + * @param ... printf style argument list for xml request string * @return allocated xml response string */ - char* (*request)(gateway_t *this, char *xml); + char* (*request)(gateway_t *this, char *xml, ...); /** * Query the list of IKE_SAs and all its children. diff --git a/src/manager/manager.c b/src/manager/manager.c index fb89c6b72..b6f3951c4 100644 --- a/src/manager/manager.c +++ b/src/manager/manager.c @@ -47,18 +47,14 @@ struct private_manager_t { gateway_t *gateway; }; -/** - * Implementation of manager_t.create_gateway_enumerator. - */ -static enumerator_t* create_gateway_enumerator(private_manager_t *this) +METHOD(manager_t, create_gateway_enumerator, enumerator_t*, + private_manager_t *this) { return this->store->create_gateway_enumerator(this->store, this->user); } -/** - * Implementation of manager_t.select_gateway. - */ -static gateway_t* select_gateway(private_manager_t *this, int select_id) +METHOD(manager_t, select_gateway, gateway_t*, + private_manager_t *this, int select_id) { if (select_id != 0) { @@ -95,18 +91,14 @@ static gateway_t* select_gateway(private_manager_t *this, int select_id) return this->gateway; } -/** - * Implementation of manager_t.logged_in. - */ -static bool logged_in(private_manager_t *this) +METHOD(manager_t, logged_in, bool, + private_manager_t *this) { return this->user != 0; } -/** - * Implementation of manager_t.login. - */ -static bool login(private_manager_t *this, char *username, char *password) +METHOD(manager_t, login, bool, + private_manager_t *this, char *username, char *password) { if (!this->user) { @@ -115,10 +107,8 @@ static bool login(private_manager_t *this, char *username, char *password) return this->user != 0; } -/** - * Implementation of manager_t.logout. - */ -static void logout(private_manager_t *this) +METHOD(manager_t, logout, void, + private_manager_t *this) { if (this->gateway) { @@ -128,10 +118,8 @@ static void logout(private_manager_t *this) this->user = 0; } -/** - * Implementation of manager_t.destroy - */ -static void destroy(private_manager_t *this) +METHOD(context_t, destroy, void, + private_manager_t *this) { if (this->gateway) this->gateway->destroy(this->gateway); free(this); @@ -142,18 +130,21 @@ static void destroy(private_manager_t *this) */ manager_t *manager_create(storage_t *storage) { - private_manager_t *this = malloc_thing(private_manager_t); - - this->public.login = (bool(*)(manager_t*, char *username, char *password))login; - this->public.logged_in = (bool(*)(manager_t*))logged_in; - this->public.logout = (void(*)(manager_t*))logout; - this->public.create_gateway_enumerator = (enumerator_t*(*)(manager_t*))create_gateway_enumerator; - this->public.select_gateway = (gateway_t*(*)(manager_t*, int id))select_gateway; - this->public.context.destroy = (void(*)(context_t*))destroy; - - this->user = 0; - this->store = storage; - this->gateway = NULL; + private_manager_t *this; + + INIT(this, + .public = { + .login = _login, + .logged_in = _logged_in, + .logout = _logout, + .create_gateway_enumerator = _create_gateway_enumerator, + .select_gateway = _select_gateway, + .context = { + .destroy = _destroy, + }, + }, + .store = storage, + ); return &this->public; } diff --git a/src/manager/manager.h b/src/manager/manager.h index 231b0f5f3..f7620833a 100644 --- a/src/manager/manager.h +++ b/src/manager/manager.h @@ -31,8 +31,6 @@ #include <context.h> -#include <utils/iterator.h> - typedef struct manager_t manager_t; /** @@ -46,7 +44,7 @@ struct manager_t { context_t context; /** - * Create an iterator over all configured gateways. + * Create an enumerator over all configured gateways. * * enumerate() arguments: int id, char *name, int port, char *address * If port is 0, address is a Unix socket address. diff --git a/src/manager/storage.c b/src/manager/storage.c index f7635ea71..5461a4288 100644 --- a/src/manager/storage.c +++ b/src/manager/storage.c @@ -37,10 +37,8 @@ struct private_storage_t { database_t *db; }; -/** - * Implementation of storage_t.login. - */ -static int login(private_storage_t *this, char *username, char *password) +METHOD(storage_t, login, int, + private_storage_t *this, char *username, char *password) { hasher_t *hasher; chunk_t hash, data, hex_str; @@ -77,10 +75,8 @@ static int login(private_storage_t *this, char *username, char *password) return uid; } -/** - * Implementation of storage_t.create_gateway_enumerator. - */ -static enumerator_t* create_gateway_enumerator(private_storage_t *this, int user) +METHOD(storage_t, create_gateway_enumerator, enumerator_t*, + private_storage_t *this, int user) { enumerator_t *enumerator; @@ -96,10 +92,8 @@ static enumerator_t* create_gateway_enumerator(private_storage_t *this, int user return enumerator; } -/** - * Implementation of storage_t.destroy - */ -static void destroy(private_storage_t *this) +METHOD(storage_t, destroy, void, + private_storage_t *this) { this->db->destroy(this->db); free(this); @@ -110,13 +104,16 @@ static void destroy(private_storage_t *this) */ storage_t *storage_create(char *uri) { - private_storage_t *this = malloc_thing(private_storage_t); - - this->public.login = (int(*)(storage_t*, char *username, char *password))login; - this->public.create_gateway_enumerator = (enumerator_t*(*)(storage_t*,int))create_gateway_enumerator; - this->public.destroy = (void(*)(storage_t*))destroy; - - this->db = lib->db->create(lib->db, uri); + private_storage_t *this; + + INIT(this, + .public = { + .login = _login, + .create_gateway_enumerator = _create_gateway_enumerator, + .destroy = _destroy, + }, + .db = lib->db->create(lib->db, uri), + ); if (this->db == NULL) { free(this); diff --git a/src/manager/storage.h b/src/manager/storage.h index d8e8b7479..69459e5aa 100644 --- a/src/manager/storage.h +++ b/src/manager/storage.h @@ -41,7 +41,7 @@ struct storage_t { int (*login)(storage_t *this, char *username, char *password); /** - * Create an iterator over the gateways. + * Create an enumerator over the gateways. * * enumerate() arguments: int id, char *name, int port, char *address * If port is 0, address is a Unix socket address. diff --git a/src/manager/templates/static/jquery.js b/src/manager/templates/static/jquery.js index 0728760b5..7cb68d02f 100644 --- a/src/manager/templates/static/jquery.js +++ b/src/manager/templates/static/jquery.js @@ -2110,7 +2110,7 @@ var jsc = (new Date).getTime(); jQuery.extend({ get: function( url, data, callback, type ) { - // shift arguments if data argument was ommited + // shift arguments if data argument was omitted if ( jQuery.isFunction( data ) ) { callback = data; data = null; diff --git a/src/manager/xml.c b/src/manager/xml.c index a9ef60c24..bf5bbbf05 100644 --- a/src/manager/xml.c +++ b/src/manager/xml.c @@ -66,11 +66,8 @@ typedef struct { xmlNode *node; } child_enum_t; -/** - * Implementation of xml_t.children().enumerate(). - */ -static bool child_enumerate(child_enum_t *e, private_xml_t **child, - char **name, char **value) +METHOD(enumerator_t, child_enumerate, bool, + child_enum_t *e, private_xml_t **child, char **name, char **value) { while (e->node && e->node->type != XML_ELEMENT_NODE) { @@ -100,18 +97,14 @@ static bool child_enumerate(child_enum_t *e, private_xml_t **child, return FALSE; } -/** - * Implementation of xml_t.get_attribute. - */ -static char* get_attribute(private_xml_t *this, char *name) +METHOD(xml_t, get_attribute, char*, + private_xml_t *this, char *name) { return NULL; } -/** - * destroy enumerator, and complete tree if this was the last enumerator - */ -static void child_destroy(child_enum_t *this) +METHOD(enumerator_t, child_destroy, void, + child_enum_t *this) { if (--this->child.root->enums == 0) { @@ -121,20 +114,25 @@ static void child_destroy(child_enum_t *this) free(this); } -/** - * Implementation of xml_t.children. - */ -static enumerator_t* children(private_xml_t *this) +METHOD(xml_t, children, enumerator_t*, + private_xml_t *this) { - child_enum_t *ce = malloc_thing(child_enum_t); - ce->e.enumerate = (void*)child_enumerate; - ce->e.destroy = (void*)child_destroy; - ce->node = this->node; - ce->child.public.children = (void*)children; - ce->child.public.get_attribute = (void*)get_attribute; - ce->child.node = NULL; - ce->child.doc = this->doc; - ce->child.root = this->root; + child_enum_t *ce; + INIT(ce, + .e = { + .enumerate = (void*)_child_enumerate, + .destroy = _child_destroy, + }, + .child = { + .public = { + .get_attribute = _get_attribute, + .children = _children, + }, + .doc = this->doc, + .root = this->root, + }, + .node = this->node, + ); this->root->enums++; return &ce->e; } @@ -144,20 +142,24 @@ static enumerator_t* children(private_xml_t *this) */ xml_t *xml_create(char *xml) { - private_xml_t *this = malloc_thing(private_xml_t); + private_xml_t *this; - this->public.get_attribute = (char*(*)(xml_t*,char*))get_attribute; - this->public.children = (enumerator_t*(*)(xml_t*))children; + INIT(this, + .public = { + .get_attribute = _get_attribute, + .children = _children, + }, + .doc = xmlReadMemory(xml, strlen(xml), NULL, NULL, 0), + ); - this->doc = xmlReadMemory(xml, strlen(xml), NULL, NULL, 0); - if (this->doc == NULL) + if (!this->doc) { free(this); return NULL; } + this->node = xmlDocGetRootElement(this->doc); this->root = this; - this->enums = 0; return &this->public; } |