-/* 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
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
-#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"
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);
CONCORD_Feature
-concord_genre_get_feature_0 (CONCORD_Genre genre, const unsigned char* name);
-
-int concord_close_index (CONCORD_INDEX table);
+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;
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)
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;
return 0;
}
-unsigned char*
+char*
concord_ds_location (CONCORD_DS ds)
{
return ds->location;
}
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;
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;
{
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;
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')
{
}
-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);
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);
return status;
}
-unsigned char*
+char*
concord_genre_get_name (CONCORD_Genre genre)
{
return genre->name;
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;
{
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;
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')
{
}
CONCORD_Feature
-concord_genre_get_feature_0 (CONCORD_Genre genre, const unsigned char* name)
+concord_genre_get_feature_0 (CONCORD_Genre genre, const char* name)
{
CONCORD_Feature feature;
}
CONCORD_Feature
-concord_genre_get_feature (CONCORD_Genre genre, const unsigned char* name)
+concord_genre_get_feature (CONCORD_Genre genre, const char* name)
{
CONCORD_Genre g_feature
= concord_ds_get_genre (genre->ds, "feature");
&s_true_name);
if (status == 0)
{
- unsigned char* t_name = alloca (s_true_name.size + 1);
+ 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';
}
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;
}
-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);
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);
return status;
}
-unsigned char*
+char*
concord_feature_get_name (CONCORD_Feature feature)
{
return feature->name;
}
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)
{
}
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)
{
}
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;
}
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)
{
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;
}
}
-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);
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);
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)
{
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;
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)