diff options
| author | David Sommerseth <dazo@users.sourceforge.net> | 2009-04-02 01:35:35 +0200 |
|---|---|---|
| committer | David Sommerseth <dazo@users.sourceforge.net> | 2009-04-02 01:35:35 +0200 |
| commit | 2077aa6897fd9d0828b13cec29a9ca7135a48dca (patch) | |
| tree | 87b4a4b4026f5513a1456c47c0ed6f3b43158752 /database/sqlite | |
| parent | 6ae1db7f381066253976bdfa2ee5554d5700d805 (diff) | |
| download | eurephia-2077aa6897fd9d0828b13cec29a9ca7135a48dca.tar.gz eurephia-2077aa6897fd9d0828b13cec29a9ca7135a48dca.tar.xz eurephia-2077aa6897fd9d0828b13cec29a9ca7135a48dca.zip | |
Completed eDBadminFirewallProfiles(...) with add and delete in db driver
Diffstat (limited to 'database/sqlite')
| -rw-r--r-- | database/sqlite/firewalladmin.c | 69 |
1 files changed, 60 insertions, 9 deletions
diff --git a/database/sqlite/firewalladmin.c b/database/sqlite/firewalladmin.c index 6f0cf44..920f1af 100644 --- a/database/sqlite/firewalladmin.c +++ b/database/sqlite/firewalladmin.c @@ -127,10 +127,56 @@ xmlDoc *fwadmin_search(eurephiaCTX *ctx, eDBfieldMap *fmap) { } +xmlDoc *fwadmin_add(eurephiaCTX *ctx, eDBfieldMap *fmap) { + dbresult *res = NULL; + xmlDoc *ret = NULL; + + // Check if we have the needed fields, and only the needed fields + if( eDBmappingFieldsPresent(fmap) != (FIELD_DESCR | FIELD_FWPROFILE) ) { + return eurephiaXML_ResultMsg(ctx, exmlERROR, "Adding firewall profile only accepts " + "description and firewall profile fields"); + } + + res = sqlite_query_mapped(ctx, SQL_INSERT, "INSERT INTO openvpn_accesses", fmap, NULL, NULL); + if( res == NULL ) { + eurephia_log(ctx, LOG_FATAL, 0, "Could not register the new firewall profile"); + ret = eurephiaXML_ResultMsg(ctx, exmlERROR, "Could not register the new firewall profile"); + } else { + ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, "Firewall profile registered with id %i", + res->last_insert_id); + } + sqlite_free_results(res); + return ret; +} + + +xmlDoc *fwadmin_delete(eurephiaCTX *ctx, eDBfieldMap *fmap) { + dbresult *res = NULL; + xmlDoc *ret = NULL; + long int fields; + + // Check if we have the needed fields, and only the needed fields + fields = eDBmappingFieldsPresent(fmap); + if( !(fields & FIELD_FWPROFILE) && !(fields & FIELD_RECID) ) { + return eurephiaXML_ResultMsg(ctx, exmlERROR, "Deleting firewall profile only accepts " + "firewall profile and destination fields"); + } + + res = sqlite_query_mapped(ctx, SQL_DELETE, "DELETE FROM openvpn_accesses", NULL, fmap, NULL); + if( res == NULL ) { + eurephia_log(ctx, LOG_FATAL, 0, "Could not delete the firewall profile"); + ret = eurephiaXML_ResultMsg(ctx, exmlERROR, "Could not delete the firewall profile"); + } else { + ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, "Firewall profile deleted"); + } + sqlite_free_results(res); + return ret; +} + // The search XML document format is: // <eurephia format="1"> -// <firewall_profiles mode="search"> +// <firewall_profiles mode="{search|add|delete}"> // <fieldMapping table="fwprofiles"> // <{search field}>{search value}</{search field}> // </fieldMapping> @@ -165,18 +211,23 @@ xmlDoc *eDBadminFirewallProfiles(eurephiaCTX *ctx, xmlDoc *srch) { return NULL; } + fieldmap_n = xmlFindNode(root_n, "fieldMapping"); + if( fieldmap_n == NULL ) { + eurephia_log(ctx, LOG_ERROR, 0, "Missing fieldMapping"); + } + fmap = eDBxmlMapping(ctx, tbl_sqlite_openvpnaccesses, NULL, fieldmap_n); + if( strcmp(mode, "search") == 0 ) { - fieldmap_n = xmlFindNode(root_n, "fieldMapping"); - if( fieldmap_n == NULL ) { - eurephia_log(ctx, LOG_ERROR, 0, "Missing fieldMapping"); - } - fmap = eDBxmlMapping(ctx, tbl_sqlite_openvpnaccesses, NULL, fieldmap_n); resxml = fwadmin_search(ctx, fmap); - eDBfreeMapping(fmap); + } else if( strcmp(mode, "add") == 0 ) { + resxml = fwadmin_add(ctx, fmap); + } else if( strcmp(mode, "delete") == 0 ) { + resxml = fwadmin_delete(ctx, fmap); } else { - eurephia_log(ctx, LOG_ERROR, 0, "Unknown mode: '%s'", mode); - resxml = NULL; + eurephia_log(ctx, LOG_ERROR, 0, "FirewallProfiles - Unknown mode: '%s'", mode); + resxml = eurephiaXML_ResultMsg(ctx, exmlERROR, "Unknown mode '%s'", mode); } + eDBfreeMapping(fmap); return resxml; } |
