b2a612676fdedbcf2c234a96d708585114c4c948
[yaz-moved-to-github.git] / include / yaz / retrieval.h
1 /*
2  * Copyright (c) 1995-2007, 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 /* $Id: retrieval.h,v 1.8 2007-01-03 08:42:14 adam Exp $ */
28
29 /**
30  * \file retrieval.h
31  * \brief Retrieval Utility
32  */
33
34 #ifndef YAZ_RETRIEVAL_H
35 #define YAZ_RETRIEVAL_H
36
37 #include <stddef.h>
38 #include <yaz/wrbuf.h>
39 #include <yaz/yconfig.h>
40
41 #include <yaz/record_conv.h>
42
43 YAZ_BEGIN_CDECL
44
45 /** retrieval handle  */
46 typedef struct yaz_retrieval_struct *yaz_retrieval_t;
47
48 /** creates retrieval handle
49     \return retrieval handle
50 */
51 YAZ_EXPORT yaz_retrieval_t yaz_retrieval_create(void);
52
53 /** destroys retrieval handle
54     \param p retrieval handle
55 */
56 YAZ_EXPORT void yaz_retrieval_destroy(yaz_retrieval_t p);
57
58 /** configures retrieval
59     \param p retrieval handle
60     \param node xmlNode pointer (root element of XML config)
61     \retval 0 success
62     \retval -1 failure
63
64     On failure, use yaz_retrieval_get_error to get error string.
65     
66     For retrieval:
67     \verbatim
68     <retrievalinfo>
69        <retrieval syntax="usmarc" name="marcxml"
70             identifier="info:srw/schema/1/marcxml-v1.1"
71             backendsyntax="xml" backendname="dc"
72        >
73          <title>MARCXML</title>
74          <convert>
75             <marc inputformat="marc" outputformat="marcxml"
76                          inputcharset="marc-8"/>
77             <xslt stylesheet="marcxml2mods.xsl"/>
78             <xslt stylesheet="mods2dc.xsl"/>
79          </convert>
80        </retrieval>
81     </retrievalinfo>
82     \endverbatim
83 */
84 YAZ_EXPORT
85 int yaz_retrieval_configure(yaz_retrieval_t p, const xmlNode *node);
86
87
88 /** performs retrieval request based on schema and format
89     \param p retrieval handle
90     \param schema record schema (SRU) / element set name (Z39.50)
91     \param syntax record syntax (format)
92     \param match_schema matched schema (if conversion was successful)
93     \param match_syntax matced syntax OID  if conversion was successful)
94     \param rc record conversion reference (if conversion was successful)
95     \param backend_schema backend scchema (if conversion was successful)
96     \param backend_syntax backend syntax (if conversion was successful)
97     \retval 0 success, schema and syntax matches
98     \retval -1 failure, use yaz_retrieval_get_error() for reason
99     \retval 1 schema does not match
100     \retval 2 syntax does not match
101     \retval 3 both match but not together
102 */
103 YAZ_EXPORT
104 int yaz_retrieval_request(yaz_retrieval_t p,
105                           const char *schema, int *syntax,
106                           const char **match_schema, int **match_syntax,
107                           yaz_record_conv_t *rc,
108                           const char **backend_schema,
109                           int **backend_syntax);
110
111 /** returns error string (for last error)
112     \param p record conversion handle
113     \return error string
114 */    
115 YAZ_EXPORT
116 const char *yaz_retrieval_get_error(yaz_retrieval_t p);
117
118
119 /** set path for opening stylesheets etc.
120     \param p record conversion handle
121     \param path file path (UNIX style with : / Windows with ;)
122 */    
123 YAZ_EXPORT
124 void yaz_retrieval_set_path(yaz_retrieval_t p, const char *path);
125
126 YAZ_END_CDECL
127
128 #endif
129 /*
130  * Local variables:
131  * c-basic-offset: 4
132  * indent-tabs-mode: nil
133  * End:
134  * vim: shiftwidth=4 tabstop=8 expandtab
135  */
136