static struct acl_data* parse_config(const char* line) { struct acl_data* data = (struct acl_data*) hub_malloc_zero(sizeof(struct acl_data)); struct cfg_tokens* tokens = cfg_tokenize(line); char* token = cfg_token_get_first(tokens); if (!data) return 0; // set defaults data->readonly = 1; data->exclusive = 0; data->users = list_create(); while (token) { char* split = strchr(token, '='); size_t len = strlen(token); size_t key = split ? (split - token) : len; if (key == 4 && strncmp(token, "file", 4) == 0) { if (data->file) hub_free(data->file); data->file = strdup(split + 1); } else if (key == 8 && strncmp(token, "readonly", 8) == 0) { if (!string_to_boolean(split + 1, &data->readonly)) data->readonly = 1; } else if (key == 9 && strncmp(token, "exclusive", 9) == 0) { if (!string_to_boolean(split + 1, &data->exclusive)) data->exclusive = 1; } else { cfg_tokens_free(tokens); free_acl(data); return 0; } token = cfg_token_get_next(tokens); } cfg_tokens_free(tokens); return data; }
static gboolean g_value_set_boolean_from_string( GValue * val, char * str) { int b = string_to_boolean(str); if (b == -1) return FALSE; g_value_set_boolean(val, b); return TRUE; }
static struct sql_data* parse_config(const char* line, struct plugin_handle* plugin) { struct sql_data* data = (struct sql_data*) hub_malloc_zero(sizeof(struct sql_data)); struct cfg_tokens* tokens = cfg_tokenize(line); char* token = cfg_token_get_first(tokens); if (!data) return 0; while (token) { char* split = strchr(token, '='); size_t len = strlen(token); size_t key = split ? (split - token) : len; if (key == 4 && strncmp(token, "file", 4) == 0 && data->db == 0) { if (sqlite3_open(split + 1, &data->db)) { cfg_tokens_free(tokens); hub_free(data); set_error_message(plugin, "Unable to open database file"); return 0; } } else if (key == 9 && strncmp(token, "exclusive", 9) == 0) { if (!string_to_boolean(split + 1, &data->exclusive)) data->exclusive = 1; } else { set_error_message(plugin, "Unable to parse startup parameters"); cfg_tokens_free(tokens); hub_free(data); return 0; } token = cfg_token_get_next(tokens); } cfg_tokens_free(tokens); if (!data->db) { set_error_message(plugin, "No database file is given, use file=<database>"); hub_free(data); return 0; } return data; }
/*! \brief Converts Config to dmz::Boolean. \details Defined in dmzRuntimeConfigToTypesBase.h. This function uses dmz::config_to_sring to retrieve the value and then uses dmz::string_to_boolean to convert the returned String to a dmz::Boolean. \param[in] Name String containing name of the attribute in the config context to convert. \param[in] Source Config containing config context to convert. \param[in] DefaultValue dmz::Boolean containing default value that is returned if the config context is not found. \return Returns dmz::Boolean containing value. \sa dmz::config_to_string(const String &Name, const Config &Source, const String &DefaultValue) */ dmz::Boolean dmz::config_to_boolean ( const String &Name, const Config &Source, const Boolean DefaultValue) { Boolean result (DefaultValue); String str; if (local_config_to_string (Name, Source, str)) { result = string_to_boolean (str); } return result; }
static int apply_boolean(const char* key, const char* data, int* target) { return string_to_boolean(data, target); }
static struct sql_data* parse_config(const char* line, struct plugin_handle* plugin) { struct sql_data* data = (struct sql_data*) hub_malloc_zero(sizeof(struct sql_data)); struct cfg_tokens* tokens = cfg_tokenize(line); char* token = cfg_token_get_first(tokens); if (!data) return 0; while (token) { struct cfg_settings* setting = cfg_settings_split(token); if (!setting) { set_error_message(plugin, "Unable to parse startup parameters"); cfg_tokens_free(tokens); hub_free(data); return 0; } if (strcmp(cfg_settings_get_key(setting), "file") == 0) { if (!data->db) { if (sqlite3_open(cfg_settings_get_value(setting), &data->db)) { cfg_tokens_free(tokens); cfg_settings_free(setting); hub_free(data); set_error_message(plugin, "Unable to open database file"); return 0; } } } else if (strcmp(cfg_settings_get_key(setting), "exclusive") == 0) { if (!string_to_boolean(cfg_settings_get_value(setting), &data->exclusive)) data->exclusive = 1; } else { set_error_message(plugin, "Unknown startup parameters given"); cfg_tokens_free(tokens); cfg_settings_free(setting); hub_free(data); return 0; } cfg_settings_free(setting); token = cfg_token_get_next(tokens); } cfg_tokens_free(tokens); if (!data->db) { set_error_message(plugin, "No database file is given, use file=<database>"); hub_free(data); return 0; } return data; }
static void load_in_memory (Ontology *ontology, const gchar *turtle_subject, const gchar *turtle_predicate, const gchar *turtle_object) { g_return_if_fail (ontology != NULL); if (!g_strcmp0 (turtle_predicate, RDFS_TYPE)) { /* It is a definition of class or property */ if (!g_strcmp0 (turtle_object, RDFS_CLASS)) { g_hash_table_insert (ontology->classes, g_strdup (turtle_subject), ttl_model_class_new (turtle_subject)); } else if (!g_strcmp0 (turtle_object, RDF_PROPERTY)) { g_hash_table_insert (ontology->properties, g_strdup (turtle_subject), ttl_model_property_new (turtle_subject)); } else { /* xxx:a-default-instance a xxx:Class */ OntologyClass *def; def = g_hash_table_lookup (ontology->classes, turtle_object); if (def) { def->instances = g_list_prepend (def->instances, g_strdup (turtle_subject)); } /* g_print ("FIXME Ignoring %s %s %s\n", turtle_subject, turtle_predicate, turtle_object); */ } } else if (!g_strcmp0 (turtle_predicate, RDFS_SUBCLASSOF)) { /* * A subclass of B: * - Add B in A->superclasses list * - Add A in B->subclasses list (if B is in this ontology!) */ OntologyClass *def; def = g_hash_table_lookup (ontology->classes, turtle_subject); if (!def) { g_error ("Something wrong"); } def->superclasses = g_list_prepend (def->superclasses, g_strdup (turtle_object)); def = g_hash_table_lookup (ontology->classes, turtle_object); if (def) { def->subclasses = g_list_prepend (def->subclasses, g_strdup (turtle_subject)); } } else if (!g_strcmp0 (turtle_predicate, TRACKER_NOTIFY)) { /* * A tracker:notify TRUE */ OntologyClass *def; def = g_hash_table_lookup (ontology->classes, turtle_subject); if (!def) { g_error ("Something wrong"); } def->notify = string_to_boolean (turtle_object); } else if (!g_strcmp0 (turtle_predicate, TRACKER_FTS_INDEXED)) { /* * A tracker:fulltextIndexed TRUE */ OntologyProperty *prop; prop = g_hash_table_lookup (ontology->properties, turtle_subject); if (!prop) { g_error ("Something wrong"); } prop->fulltextIndexed = string_to_boolean (turtle_object); } else if (!g_strcmp0 (turtle_predicate, TRACKER_FTS_WEIGHT)) { /* * A tracker:weight X */ OntologyProperty *prop; prop = g_hash_table_lookup (ontology->properties, turtle_subject); if (!prop) { g_error ("Something wrong"); } prop->weight = g_strdup (turtle_object); } else if (!g_strcmp0 (turtle_predicate, RDFS_COMMENT)) { OntologyClass *klass; OntologyProperty *prop; klass = g_hash_table_lookup (ontology->classes, turtle_subject); if (klass) { klass->description = g_strdup (turtle_object); } else { prop = g_hash_table_lookup (ontology->properties, turtle_subject); if (prop) { prop->description = g_strdup (turtle_object); } else { g_error ("UHUMMM %s", turtle_subject); } } } else if (!g_strcmp0 (turtle_predicate, RDFS_DOMAIN)) { /* * (prop A) has domain (class B) * -> add B in A->domain * -> add A in B->in_domain_of (if B is defined in this ontology!) */ OntologyProperty *prop; OntologyClass *klass; prop = g_hash_table_lookup (ontology->properties, turtle_subject); if (!prop) { g_error ("Strange error in domain (%s doesnt exist!)", turtle_subject); } prop->domain = g_list_prepend (prop->domain, g_strdup (turtle_object)); klass = g_hash_table_lookup (ontology->classes, turtle_object); if (klass) { klass->in_domain_of = g_list_prepend (klass->in_domain_of, g_strdup (turtle_subject)); } } else if (!g_strcmp0 (turtle_predicate, RDFS_RANGE)) { /* * (prop A) has range (class B) * -> add B in A->range * -> add A in B->in_range_of (if B is defined in this ontology!) */ OntologyProperty *prop; OntologyClass *klass; prop = g_hash_table_lookup (ontology->properties, turtle_subject); if (!prop) { g_error ("Strange error in domain (%s doesnt exist!)", turtle_subject); } prop->range = g_list_prepend (prop->range, g_strdup (turtle_object)); klass = g_hash_table_lookup (ontology->classes, turtle_object); if (klass) { klass->in_range_of = g_list_prepend (klass->in_range_of, g_strdup (turtle_subject)); } } else if (!g_strcmp0 (turtle_predicate, NRL_MAX_CARDINALITY)) { OntologyProperty *prop; prop = g_hash_table_lookup (ontology->properties, turtle_subject); if (!prop) { g_error ("Strange error in max cardinality (%s doesnt exist!)", turtle_subject); } prop->max_cardinality = g_strdup (turtle_object); } else if (!g_strcmp0 (turtle_predicate, RDFS_SUBPROPERTYOF)) { /* * (prop A) is subproperty of (prop B) * -> add B in A->superproperties * -> add A in B->subproperties (if B is in this ontology) */ OntologyProperty *propA, *propB; propA = g_hash_table_lookup (ontology->properties, turtle_subject); if (!propA) { g_error ("Strange error in subpropertyof (%s doesnt exist!)", turtle_subject); } propA->superproperties = g_list_prepend (propA->superproperties, g_strdup (turtle_object)); propB = g_hash_table_lookup (ontology->properties, turtle_object); if (propB) { propB->subproperties = g_list_prepend (propB->subproperties, g_strdup (turtle_subject)); } } else if (!g_strcmp0 (turtle_predicate, NAO_DEPRECATED)) { /* * X nao:deprecated true * * This can apply to classes OR properties OR * namespaces! * * NOTE: there is no way to check if we're dealing * with a namespace or not, so we don't error here if * we can't verify the property of class. */ OntologyProperty *prop; OntologyClass *klass; prop = g_hash_table_lookup (ontology->properties, turtle_subject); if (prop) { prop->deprecated = string_to_boolean (turtle_object); } else { /* Try with a class */ klass = g_hash_table_lookup (ontology->classes, turtle_subject); if (klass) { klass->deprecated = string_to_boolean (turtle_object); } } } else if (!g_strcmp0 (turtle_predicate, RDFS_LABEL)) { /* Intentionaly ignored */ } else { /* DEBUG g_print ("UNHANDLED %s %s %s\n", turtle_subject, turtle_predicate, turtle_object); */ } }