Update of /cvsroot/refdb/refdb/src
In directory sc8-pr-cvs1:/tmp/cvs-serv12453
Modified Files:
refdbdref.c
Log Message:
do character conversion for RIS data if required
Index: refdbdref.c
===================================================================
RCS file: /cvsroot/refdb/refdb/src/refdbdref.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -U2 -r1.51 -r1.52
--- refdbdref.c 17 Jan 2004 23:07:41 -0000 1.51
+++ refdbdref.c 18 Jan 2004 01:01:02 -0000 1.52
@@ -336,12 +336,14 @@
/* 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 (db_encoding && strcmp(db_encoding, !strcmp(reftype, "risx") ? "UTF-8" : input_encoding)) {
+ ardata.conv_descriptor = iconv_open(!strcmp(db_encoding, "US-ASCII") ? "ASCII" : db_encoding, !strcmp(reftype, "risx") ? "UTF-8" : input_encoding);
if (ardata.conv_descriptor == (iconv_t)(-1)) {
ardata.conv_descriptor = NULL;
- LOG_PRINT(LOG_WARNING, "cannot set output encoding");
+ LOG_PRINT(LOG_WARNING, "cannot set conversion descriptor");
}
else {
- LOG_PRINT(LOG_DEBUG, "encoding is now:");
+ LOG_PRINT(LOG_DEBUG, "input encoding is:");
+ LOG_PRINT(LOG_DEBUG, input_encoding);
+ LOG_PRINT(LOG_DEBUG, "output encoding is:");
LOG_PRINT(LOG_DEBUG, db_encoding);
}
@@ -349,5 +351,5 @@
else {
ardata.conv_descriptor = NULL;
- LOG_PRINT(LOG_DEBUG, "encoding is UTF-8, no conversion required");
+ LOG_PRINT(LOG_DEBUG, "no character encoding conversion required");
}
@@ -590,4 +592,10 @@
/* read the data proper unless size was zero (= end of transmission) */
if (n_requested_bufsize) {
+ size_t inlength;
+ size_t outlength;
+ char* my_ris_set = NULL; /* this ptr will be modified by iconv() */
+ char* my_ris_set_start = NULL; /* records initial state of my_elvalue */
+ const char* my_instring = NULL; /* this ptr will be modified by iconv() */
+
/* acknowledge that we have a buffer ready, let them data come... */
numbyte = iwrite(ptr_clrequest->fd, positive.text, positive.length+1);
@@ -609,4 +617,60 @@
/* ToDo: run iconv here */
+ if (conv_descriptor && *ris_set) {
+ inlength = strlen(ris_set) + 1;
+ /* with the encodings supported by our database engines, the converted
+ string can't be longer than the input string */
+ outlength = inlength;
+
+ if ((my_ris_set = (char*)malloc(outlength)) == NULL) {
+ ptr_addresult->failure++;
+ sprintf(return_msg, "out of memory\n");
+ LOG_PRINT(LOG_WARNING, "failed processing dataset");
+ numbyte = iwrite(ptr_clrequest->fd, return_msg, strlen(return_msg)+1);
+ if (numbyte == -1) {
+ LOG_PRINT(LOG_INFO, "timeout while writing");
+ free(ris_set);
+ return 0;
+ }
+ }
+
+ /* keep start of the converted string */
+ my_ris_set_start = my_ris_set;
+
+ /* variable will be modified by iconv, so don't use original */
+ my_instring = (const char*)ris_set;
+
+ /* now actually do the conversion */
+ if (iconv(conv_descriptor, &my_instring, &inlength, &my_ris_set, &outlength) == (size_t)(-1)) {
+ if (errno == EILSEQ) {
+ sprintf(return_msg, "iconv: invalid input character sequence\n");
+ LOG_PRINT(LOG_WARNING, "iconv: invalid input character sequence");
+ }
+ else if (errno == E2BIG) {
+ sprintf(return_msg, "iconv: output buffer too small\n");
+ LOG_PRINT(LOG_WARNING, "iconv: output buffer too small");
+ }
+ else if (errno == EINVAL) {
+ sprintf(return_msg, "iconv: incomplete input character\n");
+ LOG_PRINT(LOG_WARNING, "iconv: incomplete input character");
+ }
+
+ numbyte = iwrite(ptr_clrequest->fd, return_msg, strlen(return_msg)+1);
+ if (numbyte == -1) {
+ LOG_PRINT(LOG_INFO, "timeout while writing");
+ free(ris_set);
+ return 0;
+ }
+ return 0;
+ }
+ /* else: conversion went ok. We free the original string and replace
+ it with the converted copy */
+ if (ris_set) {
+ free(ris_set);
+ }
+ ris_set = my_ris_set_start;
+ }
+ /* else: no conversion required */
+
/* 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);
|