summaryrefslogtreecommitdiffstats
path: root/database/sqlite/administration/usercerts.c
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2011-01-09 23:39:08 +0100
committerDavid Sommerseth <davids@redhat.com>2011-12-19 11:05:38 +0100
commit8d2f8d68e6ae9726fdd2d941e55a7377e3cdf927 (patch)
treea778cb9ee6f06b41f256a22450af8fd7916a3ed8 /database/sqlite/administration/usercerts.c
parentf0434a3ad51bf1159a78003a020eeb82a26dfc7f (diff)
downloadeurephia-8d2f8d68e6ae9726fdd2d941e55a7377e3cdf927.tar.gz
eurephia-8d2f8d68e6ae9726fdd2d941e55a7377e3cdf927.tar.xz
eurephia-8d2f8d68e6ae9726fdd2d941e55a7377e3cdf927.zip
Modified the whole edb-sqlite driver to use a better error handling
This will change the driver to use the new error routines made available in the SQLite3 framework. Some of the code is also restructured a little bit to simplify the code with these changes. The functionality should be the same as for, but better error messages are now sent back to the caller on the functions supporting XML. Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
Diffstat (limited to 'database/sqlite/administration/usercerts.c')
-rw-r--r--database/sqlite/administration/usercerts.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/database/sqlite/administration/usercerts.c b/database/sqlite/administration/usercerts.c
index 8c7e5fd..8e654ab 100644
--- a/database/sqlite/administration/usercerts.c
+++ b/database/sqlite/administration/usercerts.c
@@ -92,8 +92,10 @@ xmlDoc *usercerts_search(eurephiaCTX *ctx, eDBfieldMap *where_m, const char *sor
NULL, // values (not used for SELECT)
where_m, // fields and values for the WHERE clause
dbsort);
- if( res == NULL ) {
+ if( sqlite_query_status(res) != dbSUCCESS ) {
eurephia_log(ctx, LOG_ERROR, 0, "Could not query the usercerts table");
+ sqlite_log_error(ctx, res);
+ sqlite_free_results(res);
return NULL;
}
@@ -154,7 +156,7 @@ xmlDoc *usercerts_add_del(eurephiaCTX *ctx, const char *mode, eDBfieldMap *usrcr
if( strcmp(mode, "register") == 0 ) {
dbres = sqlite_query_mapped(ctx, SQL_INSERT,
"INSERT INTO openvpn_usercerts", usrcrt_m, NULL, NULL);
- if( dbres ) {
+ if( sqlite_query_status(dbres) == dbSUCCESS ) {
res = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL,
"Registered new user-cert link with id %i",
dbres->last_insert_id);
@@ -162,7 +164,7 @@ xmlDoc *usercerts_add_del(eurephiaCTX *ctx, const char *mode, eDBfieldMap *usrcr
} else if( strcmp(mode, "remove") == 0 ) {
dbres = sqlite_query_mapped(ctx, SQL_DELETE,
"DELETE FROM openvpn_usercerts", NULL, usrcrt_m, NULL);
- if( dbres ) {
+ if( sqlite_query_status(dbres) == dbSUCCESS ) {
int num_rows = sqlite_get_affected_rows(dbres);
if( num_rows > 0 ) {
res = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL,
@@ -175,12 +177,15 @@ xmlDoc *usercerts_add_del(eurephiaCTX *ctx, const char *mode, eDBfieldMap *usrcr
}
}
- if( dbres == NULL ) {
+ if( sqlite_query_status(dbres) != dbSUCCESS ) {
+ xmlNode *tmp_n = NULL;
+
eurephia_log(ctx, LOG_ERROR, 0, "Failed to %s user-cert link.", mode);
- res = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Failed to %s user-cert link", mode);
- } else {
- sqlite_free_results(dbres);
+ tmp_n = sqlite_log_error_xml(ctx, dbres);
+ res = eurephiaXML_ResultMsg(ctx, exmlERROR, tmp_n, "Failed to %s user-cert link", mode);
+ xmlFreeNode(tmp_n);
}
+ sqlite_free_results(dbres);
return res;
}
@@ -220,7 +225,7 @@ xmlDoc *usercerts_update(eurephiaCTX *ctx, const char *uicid, eDBfieldMap *usrcr
// Send update query to the database
dbres = sqlite_query_mapped(ctx, SQL_UPDATE, "UPDATE openvpn_usercerts",
usrcrt_m, where_m, NULL);
- if( dbres ) {
+ if( sqlite_query_status(dbres) == dbSUCCESS ) {
int num_rows = sqlite_get_affected_rows(dbres);
if( num_rows > 0 ) {
res = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL,
@@ -230,12 +235,16 @@ xmlDoc *usercerts_update(eurephiaCTX *ctx, const char *uicid, eDBfieldMap *usrcr
res = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
"No user-cert links where updated");
}
- sqlite_free_results(dbres);
} else {
+ xmlNode *err_n = NULL;
+
eurephia_log(ctx, LOG_ERROR, 0, "Failed to update user-cert link.(uicid: %s)", uicid);
- res = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
+ err_n = sqlite_log_error_xml(ctx, dbres);
+ res = eurephiaXML_ResultMsg(ctx, exmlERROR, err_n,
"Failed to update user-cert link for uicid %s", uicid);
+ xmlFreeNode(err_n);
}
+ sqlite_free_results(dbres);
eDBfreeMapping(where_m);
xmlFreeDoc(where_d);