X-Git-Url: http://git.chise.org/gitweb/?p=chise%2Fconcord.git;a=blobdiff_plain;f=concord.c;h=71d5d4dca68173e60985bb8ce3d2dcfa56e9618b;hp=c08f10c6a48590a97a8aa114caf92b3ef22d716e;hb=2a9f3267270e17def505e553192d7a3f74add9d3;hpb=6f38c2f25fc3ae71203bf5f3d03a71fd13ac07dd diff --git a/concord.c b/concord.c index c08f10c..71d5d4d 100644 --- a/concord.c +++ b/concord.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2003,2004,2005 MORIOKA Tomohiko +/* Copyright (C) 2003, 2004, 2005, 2006, 2011, 2013 MORIOKA Tomohiko This file is part of the CONCORD Library. The CONCORD Library is free software; you can redistribute it and/or @@ -21,11 +21,9 @@ #include #include #include -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif #include "sysdep.h" #include "concord.h" +#include "cos-i.h" #include "concord-name.h" #include "concord-bdb.h" @@ -42,32 +40,29 @@ CONCORD_String_data (const CONCORD_String s) return s->data; } -CONCORD_Genre -concord_ds_open_genre (CONCORD_DS ds, const unsigned char* name); - -int concord_close_genre (CONCORD_Genre genre); +CONCORD_Genre concord_ds_open_genre (CONCORD_DS ds, const char* name); CONCORD_Feature -concord_genre_open_feature (CONCORD_Genre genre, const unsigned char* name); - -int concord_close_feature (CONCORD_Feature feature); +concord_genre_open_feature (CONCORD_Genre genre, const char* name); CONCORD_INDEX -concord_genre_open_index (CONCORD_Genre genre, const unsigned char* index); +concord_genre_open_index (CONCORD_Genre genre, const char* index); -int concord_close_index (CONCORD_INDEX table); +CONCORD_Feature +concord_genre_get_feature_0 (CONCORD_Genre genre, const char* name); CONCORD_Object concord_default_read_object (const unsigned char* string, size_t length); -struct CONCORD_DS_Table +struct COS_DS_ent { + COS_Object_Header header; CONCORD_Backend_Type type; - unsigned char *location; + char *location; CONCORD_NAME_TABLE* genre_names; DBTYPE subtype; int modemask; @@ -83,16 +78,16 @@ concord_default_read_object (const unsigned char* str, size_t length) if (buf == NULL) return NULL; - strncpy (buf, str, length); + strncpy ((char*)buf, (char*)str, length); buf[length] = '\0'; - return buf; + return (CONCORD_Object)buf; } CONCORD_DS -concord_open_ds (CONCORD_Backend_Type type, const unsigned char* location, +concord_open_ds (CONCORD_Backend_Type type, const char* location, int subtype, int modemask) { - CONCORD_DS ds = (CONCORD_DS)malloc (sizeof (CONCORD_DS_Table)); + CONCORD_DS ds = COS_ALLOCATE_OBJECT (DS); size_t len = strlen (location); if (ds == NULL) @@ -101,7 +96,7 @@ concord_open_ds (CONCORD_Backend_Type type, const unsigned char* location, ds->type = type; ds->subtype = ( (subtype != 0) ? subtype : DB_HASH ); ds->modemask = modemask; - ds->location = (unsigned char*)malloc (len + 1); + ds->location = (char*)malloc (len + 1); if (ds->location == NULL) goto location_failure; @@ -133,14 +128,14 @@ concord_close_ds (CONCORD_DS ds) return 0; } -unsigned char* +char* concord_ds_location (CONCORD_DS ds) { return ds->location; } int -concord_ds_set_object_nil (CONCORD_DS ds, CONCORD_Object object_nil) +concord_ds_set_object_failure (CONCORD_DS ds, CONCORD_Object object_nil) { ds->object_nil = object_nil; return 0; @@ -157,7 +152,7 @@ concord_ds_set_read_object_function (CONCORD_DS ds, } CONCORD_Genre -concord_ds_get_genre (CONCORD_DS ds, const unsigned char* name) +concord_ds_get_genre (CONCORD_DS ds, const char* name) { CONCORD_Genre genre; @@ -179,10 +174,9 @@ concord_ds_get_genre (CONCORD_DS ds, const unsigned char* name) int concord_ds_foreach_genre_name (CONCORD_DS ds, - int (*func) (CONCORD_DS ds, - unsigned char* name)) + int (*func) (CONCORD_DS ds, char* name)) { - unsigned char* dname = ds->location; + char* dname = ds->location; DIR *dir; struct dirent *de; @@ -196,10 +190,10 @@ concord_ds_foreach_genre_name (CONCORD_DS ds, { int i, need_to_decode = 0; unsigned char *cp; - unsigned char *name; + char *name; unsigned char *np; - for (cp = de->d_name, i = 0; *cp != '\0'; i++) + for (cp = (unsigned char*)de->d_name, i = 0; *cp != '\0'; i++) { if (*cp++ == '%') need_to_decode = 1; @@ -210,9 +204,9 @@ concord_ds_foreach_genre_name (CONCORD_DS ds, int ch, c[2]; int hex[2]; - name = (unsigned char *) alloca (i); - cp = de->d_name; - np = name; + name = (char*) alloca (i); + cp = (unsigned char*)de->d_name; + np = (unsigned char*)name; while ( (ch = *cp++) != '\0') { @@ -268,16 +262,17 @@ concord_ds_foreach_genre_name (CONCORD_DS ds, } -struct CONCORD_Genre_Table +struct COS_Genre_ent { + COS_Object_Header header; CONCORD_DS ds; - unsigned char *name; + char *name; CONCORD_NAME_TABLE* feature_names; CONCORD_NAME_TABLE* index_names; }; CONCORD_Genre -concord_ds_open_genre (CONCORD_DS ds, const unsigned char* name) +concord_ds_open_genre (CONCORD_DS ds, const char* name) { CONCORD_Genre genre; size_t len = strlen (name); @@ -285,12 +280,12 @@ concord_ds_open_genre (CONCORD_DS ds, const unsigned char* name) if (ds == NULL) return NULL; - genre = (CONCORD_Genre)malloc (sizeof (CONCORD_Genre_Table)); + genre = COS_ALLOCATE_OBJECT (Genre); if (genre == NULL) return NULL; genre->ds = ds; - genre->name = (unsigned char*)malloc (len + 1); + genre->name = (char*)malloc (len + 1); if (genre->name == NULL) { free (genre); @@ -343,6 +338,12 @@ concord_close_genre (CONCORD_Genre genre) return status; } +char* +concord_genre_get_name (CONCORD_Genre genre) +{ + return genre->name; +} + CONCORD_DS concord_genre_get_data_source (CONCORD_Genre genre) { @@ -352,9 +353,9 @@ concord_genre_get_data_source (CONCORD_Genre genre) int concord_genre_foreach_feature_name (CONCORD_Genre genre, int (*func) (CONCORD_Genre genre, - unsigned char* name)) + char* name)) { - unsigned char *dname + char *dname = alloca (strlen (genre->ds->location) + 1 + strlen (genre->name) + sizeof ("/feature") + 1); DIR *dir; @@ -375,10 +376,10 @@ concord_genre_foreach_feature_name (CONCORD_Genre genre, { int i, need_to_decode = 0; unsigned char *cp; - unsigned char *name; + char *name; unsigned char *np; - for (cp = de->d_name, i = 0; *cp != '\0'; i++) + for (cp = (unsigned char*)de->d_name, i = 0; *cp != '\0'; i++) { if (*cp++ == '%') need_to_decode = 1; @@ -389,9 +390,9 @@ concord_genre_foreach_feature_name (CONCORD_Genre genre, int ch, c[2]; int hex[2]; - name = (unsigned char *) alloca (i); - cp = de->d_name; - np = name; + name = (char*) alloca (i); + cp = (unsigned char*)de->d_name; + np = (unsigned char*)name; while ( (ch = *cp++) != '\0') { @@ -447,7 +448,7 @@ concord_genre_foreach_feature_name (CONCORD_Genre genre, } CONCORD_Feature -concord_genre_get_feature (CONCORD_Genre genre, const unsigned char* name) +concord_genre_get_feature_0 (CONCORD_Genre genre, const char* name) { CONCORD_Feature feature; @@ -467,8 +468,39 @@ concord_genre_get_feature (CONCORD_Genre genre, const unsigned char* name) return feature; } +CONCORD_Feature +concord_genre_get_feature (CONCORD_Genre genre, const char* name) +{ + CONCORD_Genre g_feature + = concord_ds_get_genre (genre->ds, "feature"); + + if (g_feature != NULL) + { + CONCORD_Feature p_true_name + = concord_genre_get_feature_0 (g_feature, "true-name"); + + if (g_feature != NULL) + { + CONCORD_String_Tank s_true_name; + int status + = concord_obj_get_feature_value_string (name, + p_true_name, + &s_true_name); + if (status == 0) + { + char* t_name = alloca (s_true_name.size + 1); + + strncpy (t_name, s_true_name.data, s_true_name.size); + t_name[s_true_name.size] = '\0'; + return concord_genre_get_feature_0 (genre, t_name); + } + } + } + return concord_genre_get_feature_0 (genre, name); +} + CONCORD_INDEX -concord_genre_get_index (CONCORD_Genre genre, const unsigned char* name) +concord_genre_get_index (CONCORD_Genre genre, const char* name) { CONCORD_INDEX index; @@ -489,16 +521,17 @@ concord_genre_get_index (CONCORD_Genre genre, const unsigned char* name) } -struct CONCORD_Feature_Table +struct COS_Feature_ent { + COS_Object_Header header; CONCORD_Genre genre; - unsigned char* name; + char* name; DB* db; u_int32_t access; }; CONCORD_Feature -concord_genre_open_feature (CONCORD_Genre genre, const unsigned char* feature) +concord_genre_open_feature (CONCORD_Genre genre, const char* feature) { CONCORD_Feature table; size_t len = strlen (feature); @@ -506,14 +539,14 @@ concord_genre_open_feature (CONCORD_Genre genre, const unsigned char* feature) if (genre == NULL) return NULL; - table = (CONCORD_Feature)malloc (sizeof (CONCORD_Feature_Table)); + table = COS_ALLOCATE_OBJECT (Feature); if (table == NULL) return NULL; table->genre = genre; table->db = NULL; table->access = 0; - table->name = (unsigned char*)malloc (len + 1); + table->name = (char*)malloc (len + 1); if (table->name == NULL) { free (table); @@ -547,12 +580,18 @@ concord_close_feature (CONCORD_Feature feature) return status; } -unsigned char* +char* concord_feature_get_name (CONCORD_Feature feature) { return feature->name; } +CONCORD_Genre +concord_feature_get_genre (CONCORD_Feature feature) +{ + return feature->genre; +} + int concord_feature_setup_db (CONCORD_Feature feature, int writable) { @@ -608,7 +647,7 @@ concord_feature_sync (CONCORD_Feature feature) } int -concord_obj_put_feature_value_str (const unsigned char* object_id, +concord_obj_put_feature_value_str (const char* object_id, CONCORD_Feature feature, unsigned char* value) { @@ -620,7 +659,7 @@ concord_obj_put_feature_value_str (const unsigned char* object_id, } int -concord_obj_get_feature_value_string (const unsigned char* object_id, +concord_obj_get_feature_value_string (const char* object_id, CONCORD_Feature feature, CONCORD_String value) { @@ -633,7 +672,7 @@ concord_obj_get_feature_value_string (const unsigned char* object_id, } CONCORD_Object -concord_obj_get_feature_value (const unsigned char* object_id, +concord_obj_get_feature_value (const char* object_id, CONCORD_Feature feature) { DBT valdatum; @@ -648,7 +687,7 @@ concord_obj_get_feature_value (const unsigned char* object_id, } unsigned char* -concord_obj_gets_feature_value (const unsigned char* object_id, +concord_obj_gets_feature_value (const char* object_id, CONCORD_Feature feature, unsigned char* dst, size_t size) { @@ -662,7 +701,7 @@ concord_obj_gets_feature_value (const unsigned char* object_id, return NULL; if (size < valdatum.size) return NULL; - strncpy (dst, valdatum.data, valdatum.size); + strncpy ((char*)dst, valdatum.data, valdatum.size); dst[valdatum.size] = '\0'; return dst; } @@ -697,16 +736,17 @@ concord_feature_foreach_obj_string (CONCORD_Feature feature, } -struct CONCORD_INDEX_Table +struct COS_Feature_INDEX_ent { + COS_Object_Header header; CONCORD_Genre genre; - unsigned char *name; + char *name; DB* db; u_int32_t access; }; CONCORD_INDEX -concord_genre_open_index (CONCORD_Genre genre, const unsigned char* index) +concord_genre_open_index (CONCORD_Genre genre, const char* index) { CONCORD_INDEX table; size_t len = strlen (index); @@ -714,14 +754,14 @@ concord_genre_open_index (CONCORD_Genre genre, const unsigned char* index) if (genre == NULL) return NULL; - table = (CONCORD_INDEX)malloc (sizeof (CONCORD_INDEX_Table)); + table = COS_ALLOCATE_OBJECT (Feature_INDEX); if (table == NULL) return NULL; table->genre = genre; table->db = NULL; table->access = 0; - table->name = (unsigned char*)malloc (len + 1); + table->name = (char*)malloc (len + 1); if (table->name == NULL) { free (table); @@ -755,6 +795,18 @@ concord_close_index (CONCORD_INDEX table) return status; } +char* +concord_index_get_name (CONCORD_INDEX index) +{ + return index->name; +} + +CONCORD_Genre +concord_index_get_genre (CONCORD_INDEX index) +{ + return index->genre; +} + int concord_index_setup_db (CONCORD_INDEX index, int writable) { @@ -811,8 +863,7 @@ concord_index_sync (CONCORD_INDEX index) int concord_index_strid_put_obj (CONCORD_INDEX index, - const unsigned char* strid, - unsigned char* object_id) + const char* strid, char* object_id) { if (index == NULL) return -1; @@ -820,12 +871,12 @@ concord_index_strid_put_obj (CONCORD_INDEX index, if (concord_index_setup_db (index, 1)) return -1; - return CONCORD_BDB_put (index->db, strid, object_id); + return CONCORD_BDB_put (index->db, strid, (unsigned char*)object_id); } int concord_index_strid_get_obj_string (CONCORD_INDEX index, - const unsigned char* strid, + const char* strid, CONCORD_String object_id) { if (index == NULL)