YAZ  5.23.1
query-charset.c
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11 
12 #include <stdio.h>
13 #include <assert.h>
14 
15 #include <yaz/query-charset.h>
16 #include <yaz/wrbuf.h>
17 
18 static int yaz_query_charset_convert_buf(char *buf_in, int len_in,
19  char **buf_out, int *len_out,
20  ODR o, WRBUF wrbuf, yaz_iconv_t cd)
21 {
22  int r = 0;
23  wrbuf_rewind(wrbuf);
24  wrbuf_iconv_write(wrbuf, cd, buf_in, len_in);
25  wrbuf_iconv_reset(wrbuf, cd);
26 
27  *len_out = wrbuf_len(wrbuf);
28  if (*len_out == 0)
29  { /* we assume conversion failed */
30  *buf_out = buf_in;
31  *len_out = len_in;
32  r = -1;
33  }
34  else
35  {
36  /* conversion OK */
37  *buf_out = (char*) odr_malloc(o, *len_out);
38  memcpy(*buf_out, wrbuf_buf(wrbuf), *len_out);
39  }
40  return r;
41 }
42 
44  ODR o, WRBUF wrbuf, yaz_iconv_t cd)
45 {
46  int r = 0;
47  switch(q->which)
48  {
49  case Z_Term_general:
51  (char *) q->u.general->buf, q->u.general->len,
52  (char **) &q->u.general->buf, &q->u.general->len, o, wrbuf, cd);
53  break;
54  }
55  return r;
56 }
57 
59  ODR o, WRBUF wrbuf, yaz_iconv_t cd)
60 {
61  int r = 0;
62  switch(q->which)
63  {
64  case Z_Operand_APT:
66  o, wrbuf, cd);
67  break;
69  break;
71  break;
72  }
73  return r;
74 }
75 
77  ODR o, WRBUF wrbuf,
78  yaz_iconv_t cd)
79 {
80  int r = 0;
81  switch(q->which)
82  {
84  r = yaz_query_charset_convert_operand(q->u.simple, o, wrbuf, cd);
85  break;
87  r = yaz_query_charset_convert_structure(q->u.complex->s1, o, wrbuf, cd);
88  if (r == 0)
90  q->u.complex->s2, o, wrbuf, cd);
91  break;
92  }
93  return r;
94 }
95 
97  ODR o, yaz_iconv_t cd)
98 {
99  int r = 0;
100  WRBUF wrbuf = wrbuf_alloc();
102  wrbuf_destroy(wrbuf);
103  return r;
104 }
105 
107  ODR o, yaz_iconv_t cd)
108 {
109  WRBUF wrbuf = wrbuf_alloc();
111  wrbuf_destroy(wrbuf);
112 }
113 
115  ODR o, yaz_iconv_t cd)
116 {
117  WRBUF wrbuf = wrbuf_alloc();
118  yaz_query_charset_convert_term(apt->term, o, wrbuf, cd);
119  wrbuf_destroy(wrbuf);
120 }
121 
122 /*
123  * Local variables:
124  * c-basic-offset: 4
125  * c-file-style: "Stroustrup"
126  * indent-tabs-mode: nil
127  * End:
128  * vim: shiftwidth=4 tabstop=8 expandtab
129  */
130 
Z_Operand * simple
Definition: z-core.h:502
static int yaz_query_charset_convert_operand(Z_Operand *q, ODR o, WRBUF wrbuf, yaz_iconv_t cd)
Definition: query-charset.c:58
int which
Definition: z-core.h:510
char * buf
Definition: odr.h:101
#define Z_Term_general
Definition: z-core.h:547
Z_Complex * complex
Definition: z-core.h:503
#define wrbuf_buf(b)
Definition: wrbuf.h:251
Header for WRBUF (growing buffer)
Z_RPNStructure * s2
Definition: z-core.h:495
int yaz_query_charset_convert_rpnquery_check(Z_RPNQuery *q, ODR o, yaz_iconv_t cd)
Definition: query-charset.c:96
static int yaz_query_charset_convert_term(Z_Term *q, ODR o, WRBUF wrbuf, yaz_iconv_t cd)
Definition: query-charset.c:43
Z_RPNStructure * RPNStructure
Definition: z-core.h:490
string buffer
Definition: wrbuf.h:42
Z_AttributesPlusTerm * attributesPlusTerm
Definition: z-core.h:512
void * odr_malloc(ODR o, size_t size)
Definition: odr_mem.c:31
#define Z_RPNStructure_complex
Definition: z-core.h:505
Odr_oct * general
Definition: z-core.h:539
void wrbuf_rewind(WRBUF b)
empty WRBUF content (length of buffer set to 0)
Definition: wrbuf.c:47
int which
Definition: z-core.h:537
void yaz_query_charset_convert_apt(Z_AttributesPlusTerm *apt, ODR o, yaz_iconv_t cd)
Definition: z-core.h:536
static int yaz_query_charset_convert_buf(char *buf_in, int len_in, char **buf_out, int *len_out, ODR o, WRBUF wrbuf, yaz_iconv_t cd)
Definition: query-charset.c:18
Query to WRBUF (to strings)
static int yaz_query_charset_convert_structure(Z_RPNStructure *q, ODR o, WRBUF wrbuf, yaz_iconv_t cd)
Definition: query-charset.c:76
#define Z_Operand_resultSetId
Definition: z-core.h:516
void wrbuf_destroy(WRBUF b)
destroy WRBUF and its buffer
Definition: wrbuf.c:38
Definition: odr.h:124
void wrbuf_iconv_write(WRBUF b, yaz_iconv_t cd, const char *buf, size_t size)
Converts buffer using iconv and appends to WRBUF.
Definition: wrbuf.c:230
void wrbuf_iconv_reset(WRBUF b, yaz_iconv_t cd)
iconv reset(flush) to WRBUF
Definition: wrbuf.c:268
#define Z_Operand_APT
Definition: z-core.h:515
union Z_RPNStructure::@49 u
#define wrbuf_len(b)
Definition: wrbuf.h:250
void yaz_query_charset_convert_rpnquery(Z_RPNQuery *q, ODR o, yaz_iconv_t cd)
#define Z_RPNStructure_simple
Definition: z-core.h:504
union Z_Operand::@50 u
#define Z_Operand_resultAttr
Definition: z-core.h:517
WRBUF wrbuf_alloc(void)
construct WRBUF
Definition: wrbuf.c:25
Z_RPNStructure * s1
Definition: z-core.h:494
union Z_Term::@51 u
int len
Definition: odr.h:102