summaryrefslogtreecommitdiffstats
path: root/database/eurephiadb_mapping.c
diff options
context:
space:
mode:
Diffstat (limited to 'database/eurephiadb_mapping.c')
-rw-r--r--database/eurephiadb_mapping.c75
1 files changed, 68 insertions, 7 deletions
diff --git a/database/eurephiadb_mapping.c b/database/eurephiadb_mapping.c
index 52c2909..6ae289d 100644
--- a/database/eurephiadb_mapping.c
+++ b/database/eurephiadb_mapping.c
@@ -58,6 +58,7 @@ const char *TABLE_NAME[] = {
"blacklist", // TABLE_BLACKLIST
"eurephia_adminaccess", // TABLE_EUREPHIAADMACC
"firewall_profiles", // TABLE_FWPROFILES
+ "plugins", // TABLE_PLUGINS
NULL};
/**
@@ -146,6 +147,10 @@ eDBfieldMap *eDBgetTableFieldMapping(int table) {
srcmap = eTblMap_fwprofiles;
break;
+ case TABLE_PLUGINS:
+ srcmap = eTblMap_plugins;
+ break;
+
default:
return NULL;
}
@@ -307,6 +312,29 @@ eDBfieldMap *eDBxmlMapping(eurephiaCTX *ctx, eDBfieldMap *dbmap, const char *tbl
NULL)
: strdup(""));
}
+
+ case ft_BOOL:
+ // Normalise boolean values.
+ //
+ // A boolean value will be either 't' (true) or 'f' (false)
+ // Unknonw/invalid values will be interpreted as false.
+ //
+ if( nptr->children != NULL ) {
+ switch (nptr->children->content[0]) {
+ case '1':
+ case 't':
+ case 'T':
+ case 'y':
+ case 'Y':
+ ptr->value = strdup("t");
+ break;
+ default:
+ ptr->value = strdup("f");
+ break;
+ }
+ } else {
+ ptr->value = strdup("f");
+ }
break;
default:
@@ -407,8 +435,8 @@ const char *eDBmkSortKeyString(eDBfieldMap *tfmap, const char *skeys_str) {
* @return Returns a bit-wise OR'ed value of all fields in an eDBfieldMap which have their values
* set to something else than NULL.
*/
-long int eDBmappingFieldsPresent(eDBfieldMap *map) {
- long int ret = 0;
+unsigned long long eDBmappingFieldsPresent(eDBfieldMap *map) {
+ long long int ret = 0;
eDBfieldMap *p = NULL;
// Loops through all elements and flags those
@@ -423,15 +451,15 @@ long int eDBmappingFieldsPresent(eDBfieldMap *map) {
/**
- * Retrieves the value of a field in a eDBfieldMap pointer chain.
+ * Looks up a given fieldMap entry to a given field
*
* @param map eDBfieldMap with the values
* @param field_id The field ID to retrieve the value from
*
- * @return Returns const char * to the value in the eDBfieldMap on success, or NULL if either the
- * value is not found or if the value is not set.
+ * @returns the pointer to the fieldMap entry on success, otherwise NULL
*/
-const char *eDBmappingGetValue(eDBfieldMap *map, long field_id) {
+static eDBfieldMap *_eDBmappingGetFieldMapEntry(eDBfieldMap *map, long long field_id)
+{
eDBfieldMap *ptr = NULL;
if( map == NULL ) {
@@ -440,9 +468,42 @@ const char *eDBmappingGetValue(eDBfieldMap *map, long field_id) {
for( ptr = map; ptr != NULL; ptr = ptr->next ) {
if( ptr->field_id == field_id ) {
- return ptr->value;
+ return ptr;
}
}
return NULL;
}
+/**
+ * Retrieves the value of a field in a eDBfieldMap pointer chain.
+ *
+ * @param map eDBfieldMap with the values
+ * @param field_id The field ID to retrieve the value from
+ *
+ * @return Returns const char * to the value in the eDBfieldMap on success, or NULL if either the
+ * value is not found or if the value is not set.
+ */
+const char *eDBmappingGetValue(eDBfieldMap *map, long long field_id) {
+ eDBfieldMap *ptr = _eDBmappingGetFieldMapEntry(map, field_id);
+ return (ptr != NULL ? ptr->value : NULL);
+}
+
+
+/**
+ * Sets the value of a field in a eDBfieldMap pointer chain.
+ *
+ * @param map eDBfieldMap with the values
+ * @param field_id The field ID to modify
+ * @param value String pointer to the value to use
+ *
+ * @return Returns 1 on success, otherwise 0
+ */
+int eDBmappingSetValue(eDBfieldMap *map, long long field_id, char *value) {
+ eDBfieldMap *ptr = _eDBmappingGetFieldMapEntry(map, field_id);
+ if( ptr != NULL ) {
+ ptr->value = strdup_nullsafe(value);
+ return 1;
+ }
+ return 0;
+}
+