summaryrefslogtreecommitdiffstats
path: root/database/sqlite
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2008-12-18 01:31:15 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2008-12-18 01:31:15 +0100
commit98cb5d203fa6a0cfde0c56e840d693526ba219cf (patch)
treed4682195f4a622c7e331d8d7a2f69ccbd07342c0 /database/sqlite
parent7b41f88947712f584b50dc240289ec74eeb26a3e (diff)
downloadeurephia-98cb5d203fa6a0cfde0c56e840d693526ba219cf.tar.gz
eurephia-98cb5d203fa6a0cfde0c56e840d693526ba219cf.tar.xz
eurephia-98cb5d203fa6a0cfde0c56e840d693526ba219cf.zip
Rewrote eDBadminUpdateUser(...) to use XML instead of eurephiaUSERINFO
Diffstat (limited to 'database/sqlite')
-rw-r--r--database/sqlite/administration.c45
1 files changed, 32 insertions, 13 deletions
diff --git a/database/sqlite/administration.c b/database/sqlite/administration.c
index 576ddb2..bf228ce 100644
--- a/database/sqlite/administration.c
+++ b/database/sqlite/administration.c
@@ -546,21 +546,41 @@ int eDBadminAddUser(eurephiaCTX *ctx, eurephiaUSERINFO *usrinf) {
return 0;
}
-int eDBadminUpdateUser(eurephiaCTX *ctx, const int uid, eurephiaUSERINFO *usrinf) {
- /*
+
+int eDBadminUpdateUser(eurephiaCTX *ctx, const int uid, xmlDoc *usrinf) {
dbresult *uinf = NULL;
- eurephiaUSERINFO *srch = NULL;
- eDBfieldMap *data_map = NULL, *srch_map = NULL;
+ xmlDoc *srch_xml = NULL;
+ xmlNode *root_n = NULL, *srch_n = NULL, *values_n = NULL;
+ eDBfieldMap *value_map = NULL, *srch_map = NULL;
+ xmlChar *xmluid = 0;
+ assert( (ctx != NULL) && (usrinf != NULL) );
+
+ root_n = eurephiaXML_getRoot(ctx, usrinf, "update_user", 1);
+ if( root_n == NULL ) {
+ eurephia_log(ctx, LOG_ERROR, 0, "Could not find proper XML element for user update");
+ return 0;
+ }
- assert( (ctx != NULL) && (uid == usrinf->uid) );
+ // Double check that we are going to update the right user
+ xmluid = (xmlChar *)xmlGetAttrValue(root_n->properties, "uid");
+ if( atoi_nullsafe((char *)xmluid) != uid ) {
+ eurephia_log(ctx, LOG_ERROR, 0, "Mismatch between uid given as parameter and uid in XML");
+ return 0;
+ }
- srch = eAdminPopulateUSERINFO(uid, NULL, NULL, NULL, NULL, NULL);
- srch_map = eDBmkMapping_USERINFO(ctx, tbl_sqlite_users, NULL, srch);
+ // Grab the fieldMapping node and create a eDBfieldMap structure for it
+ values_n = xmlFindNode(root_n, "fieldMapping");
+ value_map = eDBxmlMapping(ctx, tbl_sqlite_users, NULL, values_n);
- data_map = eDBmkMapping_USERINFO(ctx, tbl_sqlite_users, NULL, usrinf);
+ // Create an eDBfieldMap structure for the srch_map (used for WHERE clause)
+ eurephiaXML_CreateDoc(ctx, 1, "fieldMapping", &srch_xml, &srch_n);
+ xmlNewProp(srch_n, (xmlChar *) "table", (xmlChar *) "users");
+ xmlNewChild(srch_n, NULL, (xmlChar *) "uid", xmluid);
+ srch_map = eDBxmlMapping(ctx, tbl_sqlite_users, NULL, srch_n);
+ assert( srch_map != NULL );
- // Query the database, find the user defined in the user map
- uinf = sqlite_query_mapped(ctx, SQL_UPDATE, "UPDATE openvpn_users", data_map, srch_map);
+ // UPDATE the database
+ uinf = sqlite_query_mapped(ctx, SQL_UPDATE, "UPDATE openvpn_users", value_map, srch_map);
if( uinf == NULL ) {
eurephia_log(ctx, LOG_ERROR, 0, "Error querying the database for a user");
@@ -569,10 +589,9 @@ int eDBadminUpdateUser(eurephiaCTX *ctx, const int uid, eurephiaUSERINFO *usrinf
sqlite_free_results(uinf);
eDBfreeMapping(srch_map);
- eAdminFreeUSERINFO(srch);
+ eDBfreeMapping(value_map);
+ xmlFreeDoc(srch_xml);
- eDBfreeMapping(data_map);
- */
return 1;
}