int chise_ccst_close (CHISE_CCS_Table *table);
+CHISE_Property_Table*
+chise_ds_open_property_table (CHISE_DS *ds, const char *property);
+
+int chise_pt_close (CHISE_Property_Table *table);
+
+
typedef DB CHISE_Attribute_Table;
CHISE_Attribute_Table*
unsigned char *location;
CHISE_NAME_TABLE* feature_names;
CHISE_NAME_TABLE* ccs_names;
+ CHISE_NAME_TABLE* property_names;
DBTYPE subtype;
int modemask;
};
free (ds->location);
free (ds);
}
+
+ ds->property_names = chise_make_name_table ();
+ if (ds->property_names == NULL)
+ {
+ free (ds->ccs_names);
+ free (ds->feature_names);
+ free (ds->location);
+ free (ds);
+ }
return ds;
}
chise_destroy_name_table (ds->feature_names);
if (ds->ccs_names != NULL)
chise_destroy_name_table (ds->ccs_names);
+ if (ds->property_names != NULL)
+ chise_destroy_name_table (ds->property_names);
free (ds);
return 0;
}
+unsigned char*
+chise_ds_location (CHISE_DS *ds)
+{
+ return ds->location;
+}
+
CHISE_Feature_Table*
chise_ds_get_feature (CHISE_DS *ds, const unsigned char *feature)
{
return ct;
}
+CHISE_Property_Table*
+chise_ds_get_property (CHISE_DS *ds, const unsigned char *property)
+{
+ CHISE_Property_Table* pt;
+
+ pt = chise_name_table_get (ds->property_names, property);
+ if (pt != NULL)
+ return pt;
+
+ pt = chise_ds_open_property_table (ds, property);
+ if (pt == NULL)
+ return NULL;
+
+ if (chise_name_table_put (ds->property_names, property, pt))
+ {
+ chise_pt_close (pt);
+ return NULL;
+ }
+ return pt;
+}
+
int
chise_ds_foreach_char_feature_name (CHISE_DS *ds,
int (*func) (CHISE_DS *ds,
}
+struct CHISE_Property_Table
+{
+ CHISE_DS *ds;
+ unsigned char *name;
+ CHISE_Attribute_Table *db;
+ u_int32_t access;
+};
+
+CHISE_Property_Table*
+chise_ds_open_property_table (CHISE_DS *ds, const char *property)
+{
+ CHISE_Property_Table* table;
+ size_t len = strlen (property);
+
+ if (ds == NULL)
+ return NULL;
+
+ table = (CHISE_Property_Table*)malloc (sizeof (CHISE_Property_Table));
+ if (table == NULL)
+ return NULL;
+
+ table->ds = ds;
+ table->db = NULL;
+ table->access = 0;
+ table->name = (unsigned char*)malloc (len + 1);
+ if (table->name == NULL)
+ {
+ free (table);
+ return NULL;
+ }
+ strcpy (table->name, property);
+ return table;
+}
+
+int
+chise_pt_close (CHISE_Property_Table *table)
+{
+ int status;
+
+ if (table == NULL)
+ return -1;
+
+ if (table->db == NULL)
+ status = -1;
+ else
+ status = CHISE_Attribute_Table_close (table->db);
+
+ if (table->name == NULL)
+ status = -1;
+ else
+ {
+ free (table->name);
+ status = 0;
+ }
+ free (table);
+ return status;
+}
+
+int
+chise_property_setup_db (CHISE_Property property, int writable)
+{
+ u_int32_t access;
+
+ if (property == NULL)
+ return -1;
+
+ if (writable)
+ {
+ if ((property->access & DB_CREATE) == 0)
+ {
+ if (property->db != NULL)
+ {
+ CHISE_Attribute_Table_close (property->db);
+ property->db = NULL;
+ }
+ property->access = 0;
+ }
+ access = DB_CREATE;
+ }
+ else
+ access = DB_RDONLY;
+
+ if (property->db == NULL)
+ {
+ CHISE_DS *ds = property->ds;
+
+ property->db
+ = CHISE_Attribute_Table_open (ds->location, "feature",
+ "property", property->name,
+ ds->subtype, access, ds->modemask);
+ if (property->db == NULL)
+ return -1;
+ property->access = access;
+ }
+ return 0;
+}
+
+int
+chise_property_sync (CHISE_Property property)
+{
+ int status;
+
+ if (property->db == NULL)
+ status = 0;
+ else
+ status = CHISE_Attribute_Table_close (property->db);
+ property->db = NULL;
+ property->access = 0;
+ return status;
+}
+
+int
+chise_feature_set_property_value (CHISE_Feature feature,
+ CHISE_Property property,
+ unsigned char *value)
+{
+ if (property == NULL)
+ return -1;
+ if (chise_property_setup_db (property, 1))
+ return -1;
+ return chise_attribute_table_put (property->db, feature->name, value);
+}
+
+int
+chise_feature_load_property_value (CHISE_Feature feature,
+ CHISE_Property_Table *table,
+ CHISE_Value *valdatum)
+{
+ if (chise_property_setup_db (table, 0))
+ return -1;
+ return chise_attribute_table_get (table->db, feature->name, valdatum);
+}
+
+unsigned char*
+chise_feature_gets_property_value (CHISE_Feature feature,
+ CHISE_Property_Table *table,
+ unsigned char *buf, size_t size)
+{
+ CHISE_Value valdatum;
+ int status;
+
+ if (chise_property_setup_db (table, 0))
+ return NULL;
+ status = chise_attribute_table_get (table->db,
+ feature->name, &valdatum);
+ if (status)
+ return NULL;
+ if (size < valdatum.size)
+ return NULL;
+ strncpy (buf, valdatum.data, valdatum.size);
+ buf[valdatum.size] = '\0';
+ return buf;
+}
+
+
CHISE_Attribute_Table*
CHISE_Attribute_Table_open (const unsigned char *db_dir,
const char *category,