diff options
| author | David Sommerseth <dazo@users.sourceforge.net> | 2011-01-09 23:39:08 +0100 |
|---|---|---|
| committer | David Sommerseth <davids@redhat.com> | 2011-12-19 11:05:38 +0100 |
| commit | 8d2f8d68e6ae9726fdd2d941e55a7377e3cdf927 (patch) | |
| tree | a778cb9ee6f06b41f256a22450af8fd7916a3ed8 /database/sqlite/administration/certificates.c | |
| parent | f0434a3ad51bf1159a78003a020eeb82a26dfc7f (diff) | |
| download | eurephia-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/certificates.c')
| -rw-r--r-- | database/sqlite/administration/certificates.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/database/sqlite/administration/certificates.c b/database/sqlite/administration/certificates.c index 78be97e..8db12ff 100644 --- a/database/sqlite/administration/certificates.c +++ b/database/sqlite/administration/certificates.c @@ -89,10 +89,13 @@ static xmlDoc *certificate_list(eurephiaCTX *ctx, eDBfieldMap *srch_map, const c "SELECT depth, lower(digest), common_name, organisation, email, " " registered, certid" " FROM openvpn_certificates", NULL, srch_map, sortkeys); - if( res == NULL ) { + if( sqlite_query_status(res) != dbSUCCESS ) { eurephia_log(ctx, LOG_ERROR, 0, "Could not query the certificate table"); - return eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, + tmp_n = sqlite_log_error_xml(ctx, res); + certlist = eurephiaXML_ResultMsg(ctx, exmlERROR, tmp_n, "Could not query the database for certificate info"); + xmlFreeNode(tmp_n); + goto exit; } memset(&tmp, 0, 2050); @@ -118,8 +121,9 @@ static xmlDoc *certificate_list(eurephiaCTX *ctx, eDBfieldMap *srch_map, const c sqlite_xml_value(tmp_n, XML_NODE, "email", res, i, 4); } - sqlite_free_results(res); + exit: + sqlite_free_results(res); return certlist; } @@ -159,9 +163,11 @@ static xmlDoc *certificate_add(eurephiaCTX *ctx, eDBfieldMap *crtinf_map) { // Register the certificate res = sqlite_query_mapped(ctx, SQL_INSERT, "INSERT INTO openvpn_certificates", crtinf_map, NULL, NULL); - if( res == NULL ) { + if( sqlite_query_status(res) != dbSUCCESS ) { eurephia_log(ctx, LOG_FATAL, 0, "Could not register the certificate"); - res_d = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Could not register the certificate"); + info_n = sqlite_log_error_xml(ctx, res); + res_d = eurephiaXML_ResultMsg(ctx, exmlERROR, info_n, "Could not register the certificate"); + xmlFreeNode(info_n); } else { xmlChar *certid = malloc_nullsafe(ctx, 34); assert( certid != NULL ); @@ -216,9 +222,13 @@ static xmlDoc *certificate_delete(eurephiaCTX *ctx, eDBfieldMap *crtinf_map) { // Register the certificate res = sqlite_query_mapped(ctx, SQL_DELETE, "DELETE FROM openvpn_certificates", NULL, crtinf_map, NULL); - if( res == NULL ) { + if( sqlite_query_status(res) != dbSUCCESS ) { + xmlNode *err_n = NULL; + eurephia_log(ctx, LOG_FATAL, 0, "Could not complete the delete certificate request"); - res_d = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Could not delete the certificate(s)"); + err_n = sqlite_log_error_xml(ctx, res); + res_d = eurephiaXML_ResultMsg(ctx, exmlERROR, err_n, "Could not delete the certificate(s)"); + xmlFreeNode(err_n); } else { res_d = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL, "%i %s deleted", sqlite_get_affected_rows(res), |
