[Refdb-cvs] CVS: refdb/src refdbdbib.c,1.36.2.35,1.36.2.36
Status: Beta
Brought to you by:
mhoenicka
From: Markus H. <mho...@us...> - 2006-02-22 21:00:38
|
Update of /cvsroot/refdb/refdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32102 Modified Files: Tag: Release_0_9_5_stable refdbdbib.c Log Message: run character encoding conversion on multiple citation output Index: refdbdbib.c =================================================================== RCS file: /cvsroot/refdb/refdb/src/refdbdbib.c,v retrieving revision 1.36.2.35 retrieving revision 1.36.2.36 diff -u -U2 -r1.36.2.35 -r1.36.2.36 --- refdbdbib.c 13 Feb 2006 21:30:36 -0000 1.36.2.35 +++ refdbdbib.c 22 Feb 2006 21:00:31 -0000 1.36.2.36 @@ -971,6 +971,77 @@ } + /* run a character encoding conversion if required */ + if (conv_descriptor && *outbuffer) { + size_t inlength; + size_t outlength; + size_t orig_outlength; + char* my_outbuffer = NULL; /* this ptr will be modified by iconv() */ + char* my_outbuffer_start = NULL; /* records initial state of outbuffer */ + const char* my_instring = NULL; /* this ptr will be modified by iconv() */ + inlength = strlen(outbuffer); + /* with the encodings supported by our database engines, the converted + string can't be longer than six times the input string */ + outlength = 6*inlength; + orig_outlength = outlength; + + if ((my_outbuffer = malloc(outlength)) == NULL) { + send_status(ptr_clrequest->fd, 801, TERM_NO); + append_return_msg(ptr_addresult, 801, id_string, bibconns.conn); + ptr_addresult->failure++; + dbi_result_free(dbires1); + dbi_result_free(dbires); + retval = 1; + goto Finish; + } + + /* keep start of the converted string */ + my_outbuffer_start = my_outbuffer; + + /* variable will be modified by iconv, so don't use original */ + my_instring = (const char*)outbuffer; + + /* now actually do the conversion */ + if (iconv(conv_descriptor, &my_instring, &inlength, &my_outbuffer, &outlength) == (size_t)(-1)) { + if (errno == EILSEQ) { + LOG_PRINT(LOG_WARNING, "iconv: invalid input character sequence"); + } + else if (errno == E2BIG) { + LOG_PRINT(LOG_WARNING, "iconv: output buffer too small"); + } + else if (errno == EINVAL) { + LOG_PRINT(LOG_WARNING, "iconv: incomplete input character"); + } + + send_status(ptr_clrequest->fd, 702, TERM_NO); + append_return_msg(ptr_addresult, 702, id_string, bibconns.conn); + ptr_addresult->failure++; + dbi_result_free(dbires1); + goto Finish; + } + /* else: conversion went ok. We free the original string and replace + it with the converted copy */ + if (outbuffer) { + free(outbuffer); + } + outbuffer = my_outbuffer_start; + outbuffer_len = orig_outlength; + result_len = (size_t)(my_outbuffer - my_outbuffer_start); + } + /* else: no conversion required */ + else { + result_len = strlen(outbuffer); + } + + + + /* send ok status, then the terminated result string */ send_status(ptr_clrequest->fd, 402, TERM_NO); - n_writeresult = tiwrite(ptr_clrequest->fd, outbuffer, TERM_YES); + iwrite(ptr_clrequest->fd, outbuffer, result_len); + n_writeresult = iwrite(ptr_clrequest->fd, cs_term, TERM_LEN); + + + +/* send_status(ptr_clrequest->fd, 402, TERM_NO); */ +/* n_writeresult = tiwrite(ptr_clrequest->fd, outbuffer, TERM_YES); */ /* todo: test */ /* printf("client sleeps for 5sec\n"); */ @@ -980,4 +1051,5 @@ /* todo: switch on after debugging */ + /* remove the temporary table */ sprintf(sql_command, "DROP TABLE %s", table_name); |