[Refdb-cvs] CVS: refdb/src refdbdnote.c,1.25.2.3,1.25.2.4
Status: Beta
Brought to you by:
mhoenicka
From: Markus H. <mho...@us...> - 2005-05-03 20:31:48
|
Update of /cvsroot/refdb/refdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12088 Modified Files: Tag: Release_0_9_5_stable refdbdnote.c Log Message: fixed hang when getnote returns zero datasets Index: refdbdnote.c =================================================================== RCS file: /cvsroot/refdb/refdb/src/refdbdnote.c,v retrieving revision 1.25.2.3 retrieving revision 1.25.2.4 diff -u -U2 -r1.25.2.3 -r1.25.2.4 --- refdbdnote.c 17 Apr 2005 00:09:10 -0000 1.25.2.3 +++ refdbdnote.c 3 May 2005 20:31:39 -0000 1.25.2.4 @@ -2161,121 +2161,128 @@ } - /* fetch all notes we're interested in */ - while (dbi_result_next_row(rendinfo.dbires) != 0) { - nref_counter++; - - /* fill in variable elements of structure */ - rendinfo.ptr_ref = &sql_command; - rendinfo.ptr_ref_len = &sql_command_len; - rendinfo.nref_counter = nref_counter; - - /* recycle sql_command */ - if ((render_res = render_note(&rendinfo)) != 0) { - if (render_res == 801) { - retval = 1; - tiwrite(ptr_clrequest->fd, "", TERM_YES); - read_status(ptr_clrequest->fd); - send_status(ptr_clrequest->fd, 801, TERM_NO); - LOG_PRINT(LOG_CRIT, get_status_msg(801)); - dbi_result_free(rendinfo.dbires); - dbi_conn_close(conn); - delete_all_lilimem(&sentinel); - if (conv_descriptor) { - iconv_close(conv_descriptor); + if (dbi_result_get_numrows(rendinfo.dbires)) { + /* fetch all notes we're interested in */ + while (dbi_result_next_row(rendinfo.dbires) != 0) { + nref_counter++; + + /* fill in variable elements of structure */ + rendinfo.ptr_ref = &sql_command; + rendinfo.ptr_ref_len = &sql_command_len; + rendinfo.nref_counter = nref_counter; + + /* recycle sql_command */ + if ((render_res = render_note(&rendinfo)) != 0) { + if (render_res == 801) { + retval = 1; + tiwrite(ptr_clrequest->fd, "", TERM_YES); + read_status(ptr_clrequest->fd); + send_status(ptr_clrequest->fd, 801, TERM_NO); + LOG_PRINT(LOG_CRIT, get_status_msg(801)); + dbi_result_free(rendinfo.dbires); + dbi_conn_close(conn); + delete_all_lilimem(&sentinel); + if (conv_descriptor) { + iconv_close(conv_descriptor); + } + return 0; + } + else { + ptr_addresult->failure++; } - return 0; - } - else { - ptr_addresult->failure++; } - } - - /* run a character encoding conversion if required */ - if (conv_descriptor && *sql_command) { - size_t inlength; - size_t outlength; - char* my_sql_command = NULL; /* this ptr will be modified by iconv() */ - char* my_sql_command_start = NULL; /* records initial state of my_elvalue */ - const char* my_instring = NULL; /* this ptr will be modified by iconv() */ - inlength = strlen(sql_command)/* + 1 */; - /* with the encodings supported by our database engines, the converted - string can't be longer than six times the input string */ - outlength = 6*inlength; - if ((my_sql_command = (char*)malloc(outlength)) == NULL) { - retval = 1; - tiwrite(ptr_clrequest->fd, "", TERM_YES); - read_status(ptr_clrequest->fd); - send_status(ptr_clrequest->fd, 801, TERM_NO); - LOG_PRINT(LOG_CRIT, get_status_msg(801)); - dbi_result_free(rendinfo.dbires); - dbi_conn_close(conn); - delete_all_lilimem(&sentinel); - if (conv_descriptor) { - iconv_close(conv_descriptor); - } - return 0; - } - - /* keep start of the converted string */ - my_sql_command_start = my_sql_command; - - /* variable will be modified by iconv, so don't use original */ - my_instring = (const char*)sql_command; - - /* now actually do the conversion */ - if (iconv(conv_descriptor, &my_instring, &inlength, &my_sql_command, &outlength) == (size_t)(-1)) { - if (errno == EILSEQ) { - sprintf(sql_command, "iconv: invalid input character sequence\n"); - LOG_PRINT(LOG_WARNING, "iconv: invalid input character sequence"); - } - else if (errno == E2BIG) { - sprintf(sql_command, "iconv: output buffer too small\n"); - LOG_PRINT(LOG_WARNING, "iconv: output buffer too small"); - } - else if (errno == EINVAL) { - sprintf(sql_command, "iconv: incomplete input character\n"); - LOG_PRINT(LOG_WARNING, "iconv: incomplete input character"); + /* run a character encoding conversion if required */ + if (conv_descriptor && *sql_command) { + size_t inlength; + size_t outlength; + char* my_sql_command = NULL; /* this ptr will be modified by iconv() */ + char* my_sql_command_start = NULL; /* records initial state of my_elvalue */ + const char* my_instring = NULL; /* this ptr will be modified by iconv() */ + inlength = strlen(sql_command)/* + 1 */; + /* with the encodings supported by our database engines, the converted + string can't be longer than six times the input string */ + outlength = 6*inlength; + + if ((my_sql_command = (char*)malloc(outlength)) == NULL) { + retval = 1; + tiwrite(ptr_clrequest->fd, "", TERM_YES); + read_status(ptr_clrequest->fd); + send_status(ptr_clrequest->fd, 801, TERM_NO); + LOG_PRINT(LOG_CRIT, get_status_msg(801)); + dbi_result_free(rendinfo.dbires); + dbi_conn_close(conn); + delete_all_lilimem(&sentinel); + if (conv_descriptor) { + iconv_close(conv_descriptor); + } + return 0; } - - tiwrite(ptr_clrequest->fd, "", TERM_YES); - read_status(ptr_clrequest->fd); - send_status(ptr_clrequest->fd, 702, TERM_NO); - dbi_result_free(rendinfo.dbires); - dbi_conn_close(conn); - delete_all_lilimem(&sentinel); - if (conv_descriptor) { - iconv_close(conv_descriptor); - } - return 0; - } - /* else: conversion went ok. We free the original string and replace - it with the converted copy */ - if (sql_command) { - free(sql_command); - } - sql_command = my_sql_command_start; - sql_command_len = outlength; - result_len = (size_t)(my_sql_command - my_sql_command_start - 1); - } - else { /* no conversion required */ - result_len = strlen(sql_command); - } - - /* send ok status, then the terminated result string */ - send_status(ptr_clrequest->fd, 404, TERM_NO); - iwrite(ptr_clrequest->fd, sql_command, result_len); - iwrite(ptr_clrequest->fd, cs_term, TERM_LEN); - ptr_addresult->success++; - - /* reset buffer string */ - sql_command[0] = '\0'; - /* read client response */ - cs_status = read_status(ptr_clrequest->fd); + /* keep start of the converted string */ + my_sql_command_start = my_sql_command; - if (cs_status) { - break; - } + /* variable will be modified by iconv, so don't use original */ + my_instring = (const char*)sql_command; + + /* now actually do the conversion */ + if (iconv(conv_descriptor, &my_instring, &inlength, &my_sql_command, &outlength) == (size_t)(-1)) { + if (errno == EILSEQ) { + sprintf(sql_command, "iconv: invalid input character sequence\n"); + LOG_PRINT(LOG_WARNING, "iconv: invalid input character sequence"); + } + else if (errno == E2BIG) { + sprintf(sql_command, "iconv: output buffer too small\n"); + LOG_PRINT(LOG_WARNING, "iconv: output buffer too small"); + } + else if (errno == EINVAL) { + sprintf(sql_command, "iconv: incomplete input character\n"); + LOG_PRINT(LOG_WARNING, "iconv: incomplete input character"); + } + + tiwrite(ptr_clrequest->fd, "", TERM_YES); + read_status(ptr_clrequest->fd); + send_status(ptr_clrequest->fd, 702, TERM_NO); + dbi_result_free(rendinfo.dbires); + dbi_conn_close(conn); + delete_all_lilimem(&sentinel); + if (conv_descriptor) { + iconv_close(conv_descriptor); + } + return 0; + } + /* else: conversion went ok. We free the original string and replace + it with the converted copy */ + if (sql_command) { + free(sql_command); + } + sql_command = my_sql_command_start; + sql_command_len = outlength; + result_len = (size_t)(my_sql_command - my_sql_command_start - 1); + } + else { /* no conversion required */ + result_len = strlen(sql_command); + } + + /* send ok status, then the terminated result string */ + send_status(ptr_clrequest->fd, 404, TERM_NO); + iwrite(ptr_clrequest->fd, sql_command, result_len); + iwrite(ptr_clrequest->fd, cs_term, TERM_LEN); + ptr_addresult->success++; + + /* reset buffer string */ + sql_command[0] = '\0'; + + /* read client response */ + cs_status = read_status(ptr_clrequest->fd); + + if (cs_status) { + break; + } + } /* end while */ + } + else { + /* no notes found, send an empty body */ + send_status(ptr_clrequest->fd, 402, TERM_NO); + iwrite(ptr_clrequest->fd, cs_term, TERM_LEN); } |