X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=data1%2Fd1_read.c;h=8247e6255502eaf30c8f42f49c32e6eefc2ba362;hb=46d18b14e7af411cd9b9a4614e6bb0cb1a99069c;hp=1c50d0607d6bb0e4bebef1ca535a60abcc3a681d;hpb=d1e1a6a2a574e8019e700abb9d8a9d03ba41aab5;p=idzebra-moved-to-github.git diff --git a/data1/d1_read.c b/data1/d1_read.c index 1c50d06..8247e62 100644 --- a/data1/d1_read.c +++ b/data1/d1_read.c @@ -1,5 +1,5 @@ -/* $Id: d1_read.c,v 1.20 2006-07-06 11:40:23 adam Exp $ - Copyright (C) 1995-2005 +/* $Id: d1_read.c,v 1.24 2007-03-20 22:07:35 adam Exp $ + Copyright (C) 1995-2007 Index Data ApS This file is part of the Zebra server. @@ -15,9 +15,9 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with Zebra; see the file LICENSE.zebra. If not, write to the -Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ @@ -592,7 +592,6 @@ data1_xattr *data1_read_xattr (data1_handle dh, NMEM m, for (;;) { data1_xattr *p; - int len; while (*amp || (c && d1_isspace(c))) c = ampr (get_byte, fh, amp); if (*amp == 0 && (c == 0 || c == '>' || c == '/')) @@ -609,10 +608,7 @@ data1_xattr *data1_read_xattr (data1_handle dh, NMEM m, wrbuf_putc (wrbuf, c); c = ampr (get_byte, fh, amp); } - wrbuf_putc (wrbuf, '\0'); - len = wrbuf_len(wrbuf); - p->name = (char*) nmem_malloc (m, len); - strcpy (p->name, wrbuf_buf(wrbuf)); + p->name = nmem_strdup (m, wrbuf_cstr(wrbuf)); if (c == '=') { c = ampr (get_byte, fh, amp); @@ -649,10 +645,7 @@ data1_xattr *data1_read_xattr (data1_handle dh, NMEM m, c = ampr (get_byte, fh, amp); } } - wrbuf_putc (wrbuf, '\0'); - len = wrbuf_len(wrbuf); - p->value = (char*) nmem_malloc (m, len); - strcpy (p->value, wrbuf_buf(wrbuf)); + p->value = nmem_strdup(m, wrbuf_cstr(wrbuf)); } } *ch = c; @@ -965,7 +958,7 @@ data1_node *data1_read_node (data1_handle dh, const char **buf, NMEM m) data1_node *node; node = data1_read_nodex(dh, m, getc_mem, (void *) (buf), wrbuf); - wrbuf_free (wrbuf, 1); + wrbuf_destroy(wrbuf); return node; } @@ -1020,14 +1013,15 @@ static int conv_item (NMEM m, yaz_iconv_t t, { char *outbuf = wrbuf->buf + wrbuf->pos; size_t outlen = wrbuf->size - wrbuf->pos; - if (yaz_iconv (t, &inbuf, &inlen, &outbuf, &outlen) == + if (yaz_iconv(t, &inbuf, &inlen, &outbuf, &outlen) == (size_t)(-1) && yaz_iconv_error(t) != YAZ_ICONV_E2BIG) { /* bad data. stop and skip conversion entirely */ return -1; } else if (inlen == 0) - { /* finished converting */ + { /* finished converting, flush it */ + yaz_iconv(t, 0, 0, &outbuf, &outlen); wrbuf->pos = wrbuf->size - outlen; break; } @@ -1075,8 +1069,7 @@ static void data1_iconv_s (data1_handle dh, NMEM m, data1_node *n, conv_item(m, t, wrbuf, p->value, strlen(p->value)) == 0) { - wrbuf_puts (wrbuf, ""); - p->value = nmem_strdup (m, wrbuf->buf); + p->value = nmem_strdup(m, wrbuf_cstr(wrbuf)); } } } @@ -1124,12 +1117,12 @@ int data1_iconv (data1_handle dh, NMEM m, data1_node *n, yaz_iconv_t t = yaz_iconv_open(tocode, fromcode); if (!t) { - wrbuf_free(wrbuf, 1); + wrbuf_destroy(wrbuf); return -1; } data1_iconv_s(dh, m, n, t, wrbuf, tocode); yaz_iconv_close(t); - wrbuf_free(wrbuf, 1); + wrbuf_destroy(wrbuf); } return 0; }