2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is the Sablotron XSLT Processor.
14 * The Initial Developer of the Original Code is Ginger Alliance Ltd.
15 * Portions created by Ginger Alliance are Copyright (C) 2000-2002
16 * Ginger Alliance Ltd. All Rights Reserved.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU General Public License Version 2 or later (the
22 * "GPL"), in which case the provisions of the GPL are applicable
23 * instead of those above. If you wish to allow use of your
24 * version of this file only under the terms of the GPL and not to
25 * allow others to use your version of this file under the MPL,
26 * indicate your decision by deleting the provisions above and
27 * replace them with the notice and other provisions required by
28 * the GPL. If you do not delete the provisions above, a recipient
29 * may use your version of this file under either the MPL or the
36 /* we have to deal with the size_t type, sys/types.h;
37 is needed on some platforms */
38 #if !defined(_MSC_VER)
46 /*****************************************************************
50 *****************************************************************/
61 extern const char* hlrTypeNames[]; /* found in base.cpp */
67 SH_ERR_UNSUPPORTED_SCHEME
68 } SchemeHandlerErrors;
70 /*****************************************************************
73 is a structure for a scheme handler. It contains pointers to
74 the following functions of the handler:
75 open(), get(), put(), close().
76 All of these function return an error flag (0=OK, 1=not).
77 open() may also return SH_ERR_UNSUPPORTED_SCHEME.
78 *****************************************************************/
80 /* getAll: open the URI and return the whole string
81 scheme = URI scheme (e.g. "http")
82 rest = the rest of the URI (without colon)
83 the document is returned in a handler-allocated buffer
84 byteCount holds the byte count on return
85 return *buffer = NULL if not processed
87 typedef int SchemeHandlerGetAll(void *userData, SablotHandle processor_,
88 const char *scheme, const char *rest,
89 char **buffer, int *byteCount);
91 /* freeMemory: free the buffer allocated by getAll
94 typedef int SchemeHandlerFreeMemory(void *userData, SablotHandle processor_,
97 /* open: open the URI and return a handle
98 scheme = URI scheme (e.g. "http")
99 rest = the rest of the URI (without colon)
100 the resulting handle is returned in '*handle'
102 typedef int SchemeHandlerOpen(void *userData, SablotHandle processor_,
103 const char *scheme, const char *rest, int *handle);
105 /* get: retrieve data from the URI
106 handle = the handle assigned on open
107 buffer = pointer to the data
108 *byteCount = number of bytes to read
109 (the number actually read is returned here)
111 typedef int SchemeHandlerGet(void *userData, SablotHandle processor_,
112 int handle, char *buffer, int *byteCount);
114 /* put: save data to the URI (if possible)
115 handle = the handle assigned on open
116 buffer = pointer to the data
117 *byteCount = number of bytes to write
118 (the number actually written is returned here)
120 typedef int SchemeHandlerPut(void *userData, SablotHandle processor_,
121 int handle, const char *buffer, int *byteCount);
123 /* close: close the URI with the given handle
124 handle = the handle assigned on open
126 typedef int SchemeHandlerClose(void *userData, SablotHandle processor_,
131 SchemeHandlerGetAll *getAll;
132 SchemeHandlerFreeMemory *freeMemory;
133 SchemeHandlerOpen *open;
134 SchemeHandlerGet *get;
135 SchemeHandlerPut *put;
136 SchemeHandlerClose *close;
139 /*****************************************************************
142 a structure for external message handlers. Such a handler, if set,
143 receives all error reports, displays them, keeps the log, the
145 *****************************************************************/
148 define the "facility number" for Sablotron. This does not mean much
152 #define MH_FACILITY_SABLOTRON 2
154 /* type for the error codes used by the message handler */
156 typedef unsigned long MH_ERROR;
158 /* logging levels for the message handler */
171 makes the "external" error code to report with log() or error()
172 call with facility = module id; severity = 1 iff critical.
173 'code' is the error code internal to Sablotron.
177 MessageHandlerMakeCode(
178 void *userData, SablotHandle processor_,
179 int severity, unsigned short facility, unsigned short code);
183 pass code created by makeCode, level as necessary
184 fields is a NULL-terminated list of strings in form "field:contents"
185 distinguished fields include: msg, file, line, token
190 void *userData, SablotHandle processor_,
191 MH_ERROR code, MH_LEVEL level, char **fields);
195 for reporting errors, meaning as with log()
199 MessageHandlerError(void *userData, SablotHandle processor_,
200 MH_ERROR code, MH_LEVEL level, char **fields);
202 /* the message handler structure. Use SablotRegMessageHandler() to register. */
206 MessageHandlerMakeCode *makeCode;
207 MessageHandlerLog *log;
208 MessageHandlerError *error;
218 a SAX-like, streaming interface for access to XML docs
223 #define SAX_RETURN void
226 SAXHandlerStartDocument(void* userData, SablotHandle processor_);
229 SAXHandlerStartElement(void* userData, SablotHandle processor_,
230 const char* name, const char** atts);
233 SAXHandlerEndElement(void* userData, SablotHandle processor_,
237 SAXHandlerStartNamespace(void* userData, SablotHandle processor_,
238 const char* prefix, const char* uri);
241 SAXHandlerEndNamespace(void* userData, SablotHandle processor_,
245 SAXHandlerComment(void* userData, SablotHandle processor_,
246 const char* contents);
249 SAXHandlerPI(void* userData, SablotHandle processor_,
250 const char* target, const char* contents);
253 SAXHandlerCharacters(void* userData, SablotHandle processor_,
254 const char* contents, int length);
257 SAXHandlerEndDocument(void* userData, SablotHandle processor_);
261 The SAX handler structure. Use SablotRegSAXHandler() to register.
267 SAXHandlerStartDocument *startDocument;
268 SAXHandlerStartElement *startElement;
269 SAXHandlerEndElement *endElement;
270 SAXHandlerStartNamespace *startNamespace;
271 SAXHandlerEndNamespace *endNamespace;
272 SAXHandlerComment *comment;
273 SAXHandlerPI *processingInstruction;
274 SAXHandlerCharacters *characters;
275 SAXHandlerEndDocument *endDocument;
279 /*****************************************************************
282 Collects miscellaneous callbacks.
283 *****************************************************************/
287 If set, this callback gets called after the output of a result
288 document is finished, giving information about its content type
293 MiscHandlerDocumentInfo(void* userData, SablotHandle processor_,
294 const char *contentType, const char *encoding);
297 The Misc handler structure.
298 Use SablotRegHandler(HLR_MISC, ...) to register.
303 MiscHandlerDocumentInfo *documentInfo;
306 /*****************************************************************
309 Handler for recoding requests in absence of iconv.
310 *****************************************************************/
312 #define EH_FROM_UTF8 1
316 the conversion descriptor like iconv_t
319 typedef void* EHDescriptor;
331 direction is either EH_FROM_UTF8 or EH_TO_UTF8
332 encoding is the other encoding
333 RETURN the descriptor, or -1 if the encoding is not supported
336 typedef EHDescriptor EncHandlerOpen(void* userData, SablotHandle processor_,
337 int direction, const char *encoding);
341 arguments 3 through 7 are just like for iconv, see the manpage
342 RETURN -1 on error (set errno), a different value (e.g. 0) if OK
345 typedef EHResult EncHandlerConv(void* userData, SablotHandle processor_,
346 EHDescriptor cd, const char** inbuf, size_t *inbytesleft,
347 char ** outbuf, size_t *outbytesleft);
351 cd is the descriptor to close. Return 0 if OK, -1 on error.
354 typedef int EncHandlerClose(void* userData, SablotHandle processor_,
358 The EncHandler structure.
359 Use SablotRegHandler(HLR_ENC, ...) to register.
364 EncHandlerOpen *open;
365 EncHandlerConv *conv;
366 EncHandlerClose *close;