9fdccb92818a81105ae98fa9a0582c2c4605d3be
[yaz-moved-to-github.git] / include / yaz / retrieval.h
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2008 Index Data.
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of Index Data nor the names of its contributors
13  *       may be used to endorse or promote products derived from this
14  *       software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 /**
29  * \file retrieval.h
30  * \brief Retrieval Utility
31  */
32
33 #ifndef YAZ_RETRIEVAL_H
34 #define YAZ_RETRIEVAL_H
35
36 #include <stddef.h>
37 #include <yaz/wrbuf.h>
38 #include <yaz/yconfig.h>
39 #include <yaz/oid_util.h>
40 #include <yaz/record_conv.h>
41
42 YAZ_BEGIN_CDECL
43
44 /** retrieval handle  */
45 typedef struct yaz_retrieval_struct *yaz_retrieval_t;
46
47 /** creates retrieval handle
48     \return retrieval handle
49 */
50 YAZ_EXPORT yaz_retrieval_t yaz_retrieval_create(void);
51
52 /** destroys retrieval handle
53     \param p retrieval handle
54 */
55 YAZ_EXPORT void yaz_retrieval_destroy(yaz_retrieval_t p);
56
57 /** configures retrieval
58     \param p retrieval handle
59     \param node xmlNode pointer (root element of XML config)
60     \retval 0 success
61     \retval -1 failure
62
63     On failure, use yaz_retrieval_get_error to get error string.
64     
65     For retrieval:
66     \verbatim
67      <retrievalinfo>
68        <retrieval syntax="usmarc" name="F"/>
69        <retrieval syntax="usmarc" name="B"/>
70        <retrieval syntax="xml" name="marcxml"
71                   identifier="info:srw/schema/1/marcxml-v1.1">
72          <backend syntax="usmarc" name="F">
73            <marc inputformat="marc" outputformat="marcxml"
74                  inputcharset="marc-8"/>
75          </backend>
76        </retrieval>
77        <retrieval syntax="xml" name="dc">
78          <backend syntax="usmarc" name="F">
79            <marc inputformat="marc" outputformat="marcxml"
80                  inputcharset="marc-8"/>
81            <xslt stylesheet="MARC21slim2DC.xsl"/>
82          </backend>
83        </retrieval>
84      </retrievalinfo>
85     \endverbatim
86 */
87 YAZ_EXPORT
88 int yaz_retrieval_configure(yaz_retrieval_t p, const xmlNode *node);
89
90
91 /** performs retrieval request based on schema and format
92     \param p retrieval handle
93     \param schema record schema (SRU) / element set name (Z39.50)
94     \param syntax record syntax (format)
95     \param match_schema matched schema (if conversion was successful)
96     \param match_syntax matced syntax OID  if conversion was successful)
97     \param rc record conversion reference (if conversion was successful)
98     \param backend_schema backend scchema (if conversion was successful)
99     \param backend_syntax backend syntax (if conversion was successful)
100     \retval 0 success, schema and syntax matches
101     \retval -1 failure, use yaz_retrieval_get_error() for reason
102     \retval 1 schema does not match
103     \retval 2 syntax does not match
104     \retval 3 both match but not together
105 */
106 YAZ_EXPORT
107 int yaz_retrieval_request(yaz_retrieval_t p,
108                           const char *schema, Odr_oid *syntax,
109                           const char **match_schema, Odr_oid **match_syntax,
110                           yaz_record_conv_t *rc,
111                           const char **backend_schema,
112                           Odr_oid **backend_syntax);
113
114 /** returns error string (for last error)
115     \param p record conversion handle
116     \return error string
117 */    
118 YAZ_EXPORT
119 const char *yaz_retrieval_get_error(yaz_retrieval_t p);
120
121
122 /** set path for opening stylesheets etc.
123     \param p record conversion handle
124     \param path file path (UNIX style with : / Windows with ;)
125 */    
126 YAZ_EXPORT
127 void yaz_retrieval_set_path(yaz_retrieval_t p, const char *path);
128
129 YAZ_END_CDECL
130
131 #endif
132 /*
133  * Local variables:
134  * c-basic-offset: 4
135  * indent-tabs-mode: nil
136  * End:
137  * vim: shiftwidth=4 tabstop=8 expandtab
138  */
139