summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2008-12-17 09:43:13 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2008-12-17 09:43:13 +0100
commit4f5bcdbd99fe9bfb3af5bdfa2a8bd973aa9a5bad (patch)
treeeffcb477ccbd429ec12951dda70b6ed03fe08242
parent58619e09c5d554e66cad768a9abd6b2fff7f5a62 (diff)
downloadeurephia-4f5bcdbd99fe9bfb3af5bdfa2a8bd973aa9a5bad.tar.gz
eurephia-4f5bcdbd99fe9bfb3af5bdfa2a8bd973aa9a5bad.tar.xz
eurephia-4f5bcdbd99fe9bfb3af5bdfa2a8bd973aa9a5bad.zip
Using the new eurephiaXML_* functions for creating and parsing XML
Also rebased the XML file to always have a document root which is <eurephia/>. This tag must contain a "format" attribute, which should be 1 for the moment. When parsing the XML, the eurephiaXML_getRoot(...) function will return a pointer to the requested XML node inside the <eurephia/> document root. The format version in the root element will also be checked automatically.
-rw-r--r--database/sqlite/administration.c8
-rw-r--r--eurephiadm/commands/users.c23
2 files changed, 19 insertions, 12 deletions
diff --git a/database/sqlite/administration.c b/database/sqlite/administration.c
index a538adf..7e1855f 100644
--- a/database/sqlite/administration.c
+++ b/database/sqlite/administration.c
@@ -382,11 +382,9 @@ xmlDoc *eDBadminGetUserList(eurephiaCTX *ctx, const char *sortkeys) {
// Prepare a list with all users
memset(&tmp, 0, 34);
- userlist = xmlNewDoc((xmlChar *)"1.0");
- root_n = xmlNewNode(NULL, (xmlChar *)"userlist");
+ eurephiaXML_CreateDoc(ctx, 1, "userlist", &userlist, &root_n);
snprintf(tmp, 32, "%i", sqlite_get_numtuples(res));
xmlNewProp(root_n, (xmlChar *)"usercount", (xmlChar *)tmp);
- xmlDocSetRootElement(userlist, root_n);
// Register all records
for( i = 0; i < sqlite_get_numtuples(res); i++ ) {
@@ -457,11 +455,9 @@ xmlDoc *eDBadminGetUserInfo(eurephiaCTX *ctx, int getInfo, xmlDoc *srch) {
case 1:
uid = atoi_nullsafe(sqlite_get_value(uinf, 0, 4));
- doc = xmlNewDoc((xmlChar *) "1.0");
- root_n = xmlNewNode(NULL, (xmlChar *) "user");
+ eurephiaXML_CreateDoc(ctx, 1, "user", &doc, &root_n);
sqlite_xml_value(root_n, XML_ATTR, "uid", uinf, 0, 4);
sqlite_xml_value(root_n, XML_NODE, "username", uinf, 0, 0);
- xmlDocSetRootElement(doc, root_n);
info_n = xmlNewChild(root_n, NULL, (xmlChar *) "flags", NULL);
diff --git a/eurephiadm/commands/users.c b/eurephiadm/commands/users.c
index e2cf3f2..3a949d0 100644
--- a/eurephiadm/commands/users.c
+++ b/eurephiadm/commands/users.c
@@ -175,7 +175,12 @@ int list_users(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int
"ID", "Username", "Activated","Deactivated","Last access");
fprintf(stdout, "---------------------------------------------------------------------------\n");
- users_n = xmlDocGetRootElement(userlist);
+ users_n = eurephiaXML_getRoot(ctx, userlist, "userlist", 1);
+ if( users_n == NULL ) {
+ fprintf(stderr, "Could not retrieve valid data\n");
+ xmlFreeDoc(userlist);
+ return 1;
+ }
users_n = users_n->children;
for( ; users_n != NULL; users_n = users_n->next ) {
@@ -288,7 +293,7 @@ int show_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int
int i, crit_set = 0;
long int show_info = USERINFO_user | USERINFO_certs;
xmlDoc *user = NULL, *srch = NULL;
- xmlNode *srch_root = NULL;
+ xmlNode *srch_root = NULL, *user_n = NULL;
e_options activargs[] = {
{"--uid", "-i", 1},
@@ -367,6 +372,13 @@ int show_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int
}
xmlFreeDoc(srch);
+ user_n = eurephiaXML_getRoot(ctx, user, "user", 1);
+ if( user_n == NULL ) {
+ fprintf(stderr, "Could not retrieve valid data\n");
+ xmlFreeDoc(user);
+ return 1;
+ }
+
// Create a XPath context for functions which users XPath to locate info
user_XP = xmlXPathNewContext(user);
if( user_XP == NULL ) {
@@ -374,9 +386,8 @@ int show_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int
return 1;
}
-
if( show_info & USERINFO_user ) {
- xmlNode *lastacc = NULL, *user_n = xmlDocGetRootElement(user);
+ xmlNode *lastacc = NULL;
lastacc = xmlFindNode(user_n, "last_accessed");
@@ -386,13 +397,13 @@ int show_user(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int
field_print_str("Last accessed", xmlExtractContent(lastacc));
field_print_str("Activated", xmlGetNodeContent(user_n, "activated"));
field_print_str("Dectivated", xmlGetNodeContent(user_n, "deactivated"));
- field_print_str("Flags", xmlFlags2str(user_XP, "/user/flags/flag"));
+ field_print_str("Flags", xmlFlags2str(user_XP, "/eurephia/user/flags/flag"));
printf("\n");
}
// Show associated certificates if we was asked to show this info
if( show_info & USERINFO_certs ) {
- xmlPrint_certs(user_XP, "/user/certificates/certificate");
+ xmlPrint_certs(user_XP, "/eurephia/user/certificates/certificate");
}
// Clean up