[Refdb-cvs] CVS: refdb/src noteshandler.c,1.10,1.11 risxhandler.c,1.21,1.22
Status: Beta
Brought to you by:
mhoenicka
|
From: Markus H. <mho...@us...> - 2004-01-17 22:47:24
|
Update of /cvsroot/refdb/refdb/src
In directory sc8-pr-cvs1:/tmp/cvs-serv21530
Modified Files:
noteshandler.c risxhandler.c
Log Message:
added character conversion to end_handler()
Index: noteshandler.c
===================================================================
RCS file: /cvsroot/refdb/refdb/src/noteshandler.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -U2 -r1.10 -r1.11
--- noteshandler.c 3 Jan 2004 20:11:43 -0000 1.10
+++ noteshandler.c 17 Jan 2004 22:47:20 -0000 1.11
@@ -27,6 +27,8 @@
#include <string.h>
#include <time.h> /* for strftime */
+#include <errno.h>
#include <expat.h> /* header of the XML parser */
#include <syslog.h> /* priority levels of log messages */
+#include <iconv.h>
#include <dbi/dbi.h>
@@ -623,4 +625,68 @@
if (!ptr_andata->ndb_error && !ptr_andata->nmem_error) {
+ /* do a character conversion if required. expat dumps all
+ character data as UTF-8 regardless of the input encoding */
+ size_t inlength;
+ size_t outlength;
+ char* my_elvalue = NULL; /* this ptr will be modified by iconv() */
+ char* my_elvalue_start = NULL; /* records initial state of my_elvalue */
+ const char* my_instring = NULL; /* this ptr will be modified by iconv() */
+
+ if (ptr_andata->conv_descriptor && *((ptr_andata->ptr_first)->ptr_elvalue)) {
+ inlength = strlen((ptr_andata->ptr_first)->ptr_elvalue) + 1;
+ /* with the encodings supported by our database engines, the converted
+ string can't be longer than the input string */
+ outlength = inlength;
+
+ if ((my_elvalue = (char*)malloc(outlength)) == NULL) {
+ if ((new_msgpool = mstrcat(ptr_andata->msgpool, outomem_n.text, &(ptr_andata->msgpool_len), 0)) == NULL) {
+ return;
+ }
+ else {
+ ptr_andata->msgpool = new_msgpool;
+ }
+ (ptr_andata->nmem_error)++;
+ return;
+ }
+
+ /* keep start of the converted string */
+ my_elvalue_start = my_elvalue;
+
+ /* variable will be modified by iconv, so don't use original */
+ my_instring = (const char*)((ptr_andata->ptr_first)->ptr_elvalue);
+
+ /* now actually do the conversion */
+ if (iconv(ptr_andata->conv_descriptor, &my_instring, &inlength, &my_elvalue, &outlength) == (size_t)(-1)) {
+ if (errno == EILSEQ) {
+ new_msgpool = mstrcat(ptr_andata->msgpool, "iconv: invalid input character sequence\n", &(ptr_andata->msgpool_len), 0);
+ LOG_PRINT(LOG_WARNING, "iconv: invalid input character sequence");
+ }
+ else if (errno == E2BIG) {
+ new_msgpool = mstrcat(ptr_andata->msgpool, "iconv: output buffer too small\n", &(ptr_andata->msgpool_len), 0);
+ LOG_PRINT(LOG_WARNING, "iconv: output buffer too small");
+ }
+ else if (errno == EINVAL) {
+ new_msgpool = mstrcat(ptr_andata->msgpool, "iconv: incomplete input character\n", &(ptr_andata->msgpool_len), 0);
+ LOG_PRINT(LOG_WARNING, "iconv: incomplete input character");
+ }
+
+ if (new_msgpool == NULL) {
+ return;
+ }
+ else {
+ ptr_andata->msgpool = new_msgpool;
+ }
+ (ptr_andata->ndb_error)++;
+ return;
+ }
+ /* else: conversion went ok. We free the original string and replace
+ it with the converted copy */
+ if ((ptr_andata->ptr_first)->ptr_elvalue) {
+ free((ptr_andata->ptr_first)->ptr_elvalue);
+ }
+ (ptr_andata->ptr_first)->ptr_elvalue = my_elvalue_start;
+ }
+ /* else: no conversion required */
+
/* ------------------------------------------------------------ */
if (!strcmp(el, "title") && ptr_andata->replace_note != 2) {
Index: risxhandler.c
===================================================================
RCS file: /cvsroot/refdb/refdb/src/risxhandler.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -U2 -r1.21 -r1.22
--- risxhandler.c 7 Jan 2004 19:43:03 -0000 1.21
+++ risxhandler.c 17 Jan 2004 22:47:20 -0000 1.22
@@ -30,6 +30,8 @@
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <expat.h> /* header of the XML parser */
#include <syslog.h> /* priority levels of log messages */
+#include <iconv.h>
#include <dbi/dbi.h>
@@ -636,4 +638,68 @@
if (!ptr_ardata->ndb_error && !ptr_ardata->nmem_error) {
+ /* do a character conversion if required. expat dumps all
+ character data as UTF-8 regardless of the input encoding */
+ size_t inlength;
+ size_t outlength;
+ char* my_elvalue = NULL; /* this ptr will be modified by iconv() */
+ char* my_elvalue_start = NULL; /* records initial state of my_elvalue */
+ const char* my_instring = NULL; /* this ptr will be modified by iconv() */
+
+ if (ptr_ardata->conv_descriptor && *((ptr_ardata->ptr_first)->ptr_elvalue)) {
+ inlength = strlen((ptr_ardata->ptr_first)->ptr_elvalue) + 1;
+ /* with the encodings supported by our database engines, the converted
+ string can't be longer than the input string */
+ outlength = inlength;
+
+ if ((my_elvalue = (char*)malloc(outlength)) == NULL) {
+ if ((new_msgpool = mstrcat(ptr_ardata->msgpool, outomem_n.text, &(ptr_ardata->msgpool_len), 0)) == NULL) {
+ return;
+ }
+ else {
+ ptr_ardata->msgpool = new_msgpool;
+ }
+ (ptr_ardata->nmem_error)++;
+ return;
+ }
+
+ /* keep start of the converted string */
+ my_elvalue_start = my_elvalue;
+
+ /* variable will be modified by iconv, so don't use original */
+ my_instring = (const char*)((ptr_ardata->ptr_first)->ptr_elvalue);
+
+ /* now actually do the conversion */
+ if (iconv(ptr_ardata->conv_descriptor, &my_instring, &inlength, &my_elvalue, &outlength) == (size_t)(-1)) {
+ if (errno == EILSEQ) {
+ new_msgpool = mstrcat(ptr_ardata->msgpool, "iconv: invalid input character sequence\n", &(ptr_ardata->msgpool_len), 0);
+ LOG_PRINT(LOG_WARNING, "iconv: invalid input character sequence");
+ }
+ else if (errno == E2BIG) {
+ new_msgpool = mstrcat(ptr_ardata->msgpool, "iconv: output buffer too small\n", &(ptr_ardata->msgpool_len), 0);
+ LOG_PRINT(LOG_WARNING, "iconv: output buffer too small");
+ }
+ else if (errno == EINVAL) {
+ new_msgpool = mstrcat(ptr_ardata->msgpool, "iconv: incomplete input character\n", &(ptr_ardata->msgpool_len), 0);
+ LOG_PRINT(LOG_WARNING, "iconv: incomplete input character");
+ }
+
+ if (new_msgpool == NULL) {
+ return;
+ }
+ else {
+ ptr_ardata->msgpool = new_msgpool;
+ }
+ (ptr_ardata->ndb_error)++;
+ return;
+ }
+ /* else: conversion went ok. We free the original string and replace
+ it with the converted copy */
+ if ((ptr_ardata->ptr_first)->ptr_elvalue) {
+ free((ptr_ardata->ptr_first)->ptr_elvalue);
+ }
+ (ptr_ardata->ptr_first)->ptr_elvalue = my_elvalue_start;
+ }
+ /* else: no conversion required */
+
/* ------------------------------------------------------------ */
if (!strcmp(el, "title") && ptr_ardata->replace_ref != 2) {
|