[Refdb-cvs] CVS: refdb/src refdbdnote.c,1.13,1.14 refdbdref.c,1.50,1.51
Status: Beta
Brought to you by:
mhoenicka
|
From: Markus H. <mho...@us...> - 2004-01-17 23:07:44
|
Update of /cvsroot/refdb/refdb/src
In directory sc8-pr-cvs1:/tmp/cvs-serv25105
Modified Files:
refdbdnote.c refdbdref.c
Log Message:
retrieve database encoding for XML import
Index: refdbdnote.c
===================================================================
RCS file: /cvsroot/refdb/refdb/src/refdbdnote.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -U2 -r1.13 -r1.14
--- refdbdnote.c 4 Jan 2004 01:57:31 -0000 1.13
+++ refdbdnote.c 17 Jan 2004 23:07:41 -0000 1.14
@@ -25,4 +25,5 @@
#include <dbi/dbi.h>
#include <expat.h> /* the xml parser header file */
+#include <iconv.h>
#include "refdb.h"
@@ -68,6 +69,8 @@
added ID values
+ char* input_encoding encoding of the input data
+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
-int addnote(struct CLIENT_REQUEST* ptr_clrequest, char* set_owner, struct ADDRESULT* ptr_addresult, int replace_note, Lilid* ptr_sentinel) {
+int addnote(struct CLIENT_REQUEST* ptr_clrequest, char* set_owner, struct ADDRESULT* ptr_addresult, int replace_note, Lilid* ptr_sentinel, char* input_encoding) {
dbi_conn conn;
dbi_conn conn_refdb = NULL;
@@ -79,4 +82,5 @@
char *the_user; /* name (either set_owner or username) */
char *return_msg; /* string to hold a return message for the client */
+ const char *db_encoding; /* encoding of database */
const char *drivername; /* name of the libdbi driver */
char old_db[DBNAME_LENGTH+1];
@@ -119,4 +123,24 @@
}
+ /* get the database encoding */
+ db_encoding = dbi_conn_get_encoding(conn);
+
+ /* if we need to convert, create a conversion descriptor for iconv() */
+ if (db_encoding && strcmp(db_encoding, "UTF-8")) {
+ andata.conv_descriptor = iconv_open(!strcmp(db_encoding, "US-ASCII") ? "ASCII" : db_encoding, "UTF-8");
+ if (andata.conv_descriptor == (iconv_t)(-1)) {
+ andata.conv_descriptor = NULL;
+ LOG_PRINT(LOG_WARNING, "cannot set output encoding");
+ }
+ else {
+ LOG_PRINT(LOG_DEBUG, "encoding is now:");
+ LOG_PRINT(LOG_DEBUG, db_encoding);
+ }
+ }
+ else {
+ andata.conv_descriptor = NULL;
+ LOG_PRINT(LOG_DEBUG, "encoding is UTF-8, no conversion required");
+ }
+
while (1) { /* leave with break */
/* create the parser instance */
@@ -217,4 +241,8 @@
delete_all_lilimem(&sentinel);
+ if (andata.conv_descriptor) {
+ iconv_close(andata.conv_descriptor);
+ }
+
return success;
}
Index: refdbdref.c
===================================================================
RCS file: /cvsroot/refdb/refdb/src/refdbdref.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -U2 -r1.50 -r1.51
--- refdbdref.c 10 Jan 2004 01:26:39 -0000 1.50
+++ refdbdref.c 17 Jan 2004 23:07:41 -0000 1.51
@@ -27,4 +27,5 @@
#include <time.h>
#include <expat.h> /* the xml parser header file */
+#include <iconv.h>
#include <dbi/dbi.h>
@@ -59,5 +60,5 @@
/* forward declaration of local functions */
-static unsigned long long read_ris_data(struct CLIENT_REQUEST* ptr_clrequest, struct ADDRESULT* ptr_addresult, dbi_conn conn, dbi_conn conn_refdb, int replace_ref, int n_keep_id, const char* the_user, Lilid* ptr_sentinel);
+static unsigned long long read_ris_data(struct CLIENT_REQUEST* ptr_clrequest, struct ADDRESULT* ptr_addresult, dbi_conn conn, dbi_conn conn_refdb, int replace_ref, int n_keep_id, const char* the_user, Lilid* ptr_sentinel, iconv_t conv_descriptor);
static int real_run_keyword_scan(struct CLIENT_REQUEST* ptr_clrequest, Lilid* ptr_sentinel, int mode, int* ptr_insert);
@@ -270,6 +271,8 @@
added ID values
+ char* input_encoding encoding of the input data
+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
-int addref(struct CLIENT_REQUEST* ptr_clrequest, char* set_owner, struct ADDRESULT* ptr_addresult, int replace_ref, int n_keep_id, const char* reftype, Lilid* ptr_sentinel) {
+int addref(struct CLIENT_REQUEST* ptr_clrequest, char* set_owner, struct ADDRESULT* ptr_addresult, int replace_ref, int n_keep_id, const char* reftype, Lilid* ptr_sentinel, char* input_encoding) {
dbi_conn conn;
dbi_conn conn_refdb = NULL;
@@ -281,4 +284,5 @@
char *the_user; /* name (either set_owner or username) */
char *return_msg; /* string to hold a return message for the client */
+ const char *db_encoding; /* encoding of database */
const char *drivername; /* name of the libdbi driver */
char old_db[DBNAME_LENGTH+1];
@@ -328,4 +332,24 @@
}
+ /* get the database encoding */
+ db_encoding = dbi_conn_get_encoding(conn);
+
+ /* if we need to convert, create a conversion descriptor for iconv() */
+ if (db_encoding && strcmp(db_encoding, "UTF-8")) {
+ ardata.conv_descriptor = iconv_open(!strcmp(db_encoding, "US-ASCII") ? "ASCII" : db_encoding, "UTF-8");
+ if (ardata.conv_descriptor == (iconv_t)(-1)) {
+ ardata.conv_descriptor = NULL;
+ LOG_PRINT(LOG_WARNING, "cannot set output encoding");
+ }
+ else {
+ LOG_PRINT(LOG_DEBUG, "encoding is now:");
+ LOG_PRINT(LOG_DEBUG, db_encoding);
+ }
+ }
+ else {
+ ardata.conv_descriptor = NULL;
+ LOG_PRINT(LOG_DEBUG, "encoding is UTF-8, no conversion required");
+ }
+
if (!strcmp(my_dbi_conn_get_cap(conn, "multiple_db"), "f")) {
/* pgsql, sqlite need another connection to retrieve values from
@@ -341,4 +365,7 @@
dbi_conn_close(conn);
delete_all_lilimem(&sentinel);
+ if (ardata.conv_descriptor) {
+ iconv_close(ardata.conv_descriptor);
+ }
LOG_PRINT(LOG_ERR, connerr.text);
return 0;
@@ -450,5 +477,5 @@
}
- ullresult = read_ris_data(ptr_clrequest, ptr_addresult, conn, conn_refdb, replace_ref, n_keep_id, the_user, ptr_sentinel);
+ ullresult = read_ris_data(ptr_clrequest, ptr_addresult, conn, conn_refdb, replace_ref, n_keep_id, the_user, ptr_sentinel, ardata.conv_descriptor);
}
@@ -466,4 +493,8 @@
free_authorinfo(ardata.ptr_ainfo);
+ if (ardata.conv_descriptor) {
+ iconv_close(ardata.conv_descriptor);
+ }
+
return success;
}
@@ -496,6 +527,8 @@
added ID values
+ iconv_t conv_descriptor conversion descriptor for iconv()
+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
-static unsigned long long read_ris_data(struct CLIENT_REQUEST* ptr_clrequest, struct ADDRESULT* ptr_addresult, dbi_conn conn, dbi_conn conn_refdb, int replace_ref, int n_keep_id, const char* the_user, Lilid* ptr_sentinel) {
+static unsigned long long read_ris_data(struct CLIENT_REQUEST* ptr_clrequest, struct ADDRESULT* ptr_addresult, dbi_conn conn, dbi_conn conn_refdb, int replace_ref, int n_keep_id, const char* the_user, Lilid* ptr_sentinel, iconv_t conv_descriptor) {
int numbyte;
int success = 1; /* be optimistic */
@@ -574,4 +607,6 @@
}
+ /* ToDo: run iconv here */
+
/* split reference into lines and squeeze contents into database */
result = process_ris_set(ris_set, conn, conn_refdb, replace_ref, (char*)the_user, ptr_clrequest, n_keep_id, ptr_sentinel);
|