summaryrefslogtreecommitdiff
path: root/win32/sablot/include/shandler.h
blob: bf4f3faed1702910ad09a9af38f09295da8ff78a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
/*

 * The contents of this file are subject to the Mozilla Public

 * License Version 1.1 (the "License"); you may not use this file

 * except in compliance with the License. You may obtain a copy of

 * the License at http://www.mozilla.org/MPL/

 *

 * Software distributed under the License is distributed on an "AS

 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or

 * implied. See the License for the specific language governing

 * rights and limitations under the License.

 *

 * The Original Code is the Sablotron XSLT Processor.

 *

 * The Initial Developer of the Original Code is Ginger Alliance Ltd.

 * Portions created by Ginger Alliance are Copyright (C) 2000-2002

 * Ginger Alliance Ltd. All Rights Reserved.

 *

 * Contributor(s):

 *

 * Alternatively, the contents of this file may be used under the

 * terms of the GNU General Public License Version 2 or later (the

 * "GPL"), in which case the provisions of the GPL are applicable

 * instead of those above.  If you wish to allow use of your

 * version of this file only under the terms of the GPL and not to

 * allow others to use your version of this file under the MPL,

 * indicate your decision by deleting the provisions above and

 * replace them with the notice and other provisions required by

 * the GPL.  If you do not delete the provisions above, a recipient

 * may use your version of this file under either the MPL or the

 * GPL.

 */



#ifndef ShandlerHIncl

#define ShandlerHIncl



/* we have to deal with the size_t type, sys/types.h;

   is needed on some platforms */

#if !defined(_MSC_VER) && !defined(__BORLANDC__)

#include <sabcfg.h>

#endif



#include <stddef.h>



/* GP: clean */



/*****************************************************************



  handler types



*****************************************************************/



typedef enum

{

    HLR_MESSAGE = 0,

    HLR_SCHEME,

    HLR_SAX,

    HLR_MISC,

    HLR_ENC

} HandlerType;



extern const char* hlrTypeNames[]; /* found in base.cpp */



typedef enum

{

    SH_ERR_OK = 0,

    SH_ERR_NOT_OK = 1,

    SH_ERR_UNSUPPORTED_SCHEME

} SchemeHandlerErrors;



/*****************************************************************

SchemeHandler



  is a structure for a scheme handler. It contains pointers to

  the following functions of the handler:

        open(), get(), put(), close().

  All of these function return an error flag (0=OK, 1=not).

  open() may also return SH_ERR_UNSUPPORTED_SCHEME.

*****************************************************************/



/*  getAll: open the URI and return the whole string

        scheme = URI scheme (e.g. "http")

        rest = the rest of the URI (without colon)

        the document is returned in a handler-allocated buffer

        byteCount holds the byte count on return

        return *buffer = NULL if not processed

*/

typedef int SchemeHandlerGetAll(void *userData, SablotHandle processor_,

    const char *scheme, const char *rest,

    char **buffer, int *byteCount);



/*  freeMemory: free the buffer allocated by getAll

*/



typedef int SchemeHandlerFreeMemory(void *userData, SablotHandle processor_,

    char *buffer);



/*  open: open the URI and return a handle

        scheme = URI scheme (e.g. "http")

        rest = the rest of the URI (without colon)

        the resulting handle is returned in '*handle'

*/

typedef int SchemeHandlerOpen(void *userData, SablotHandle processor_,

    const char *scheme, const char *rest, int *handle);



/*  get: retrieve data from the URI

        handle = the handle assigned on open

        buffer = pointer to the data

        *byteCount = number of bytes to read

            (the number actually read is returned here)

*/

typedef int SchemeHandlerGet(void *userData, SablotHandle processor_,

    int handle, char *buffer, int *byteCount);



/*  put: save data to the URI (if possible)

        handle = the handle assigned on open

        buffer = pointer to the data

        *byteCount = number of bytes to write

            (the number actually written is returned here)

*/

typedef int SchemeHandlerPut(void *userData, SablotHandle processor_,

    int handle, const char *buffer, int *byteCount);



/*  close: close the URI with the given handle

        handle = the handle assigned on open

*/

typedef int SchemeHandlerClose(void *userData, SablotHandle processor_,

    int handle);



typedef struct

{

    SchemeHandlerGetAll *getAll;

    SchemeHandlerFreeMemory *freeMemory;

    SchemeHandlerOpen *open;

    SchemeHandlerGet *get;

    SchemeHandlerPut *put;

    SchemeHandlerClose *close;

} SchemeHandler;



/*****************************************************************

MessageHandler



  a structure for external message handlers. Such a handler, if set,

  receives all error reports, displays them, keeps the log, the

  error trace, etc.

*****************************************************************/



/*

   define the "facility number" for Sablotron. This does not mean much

   nowadays.

*/



#define MH_FACILITY_SABLOTRON 2



/* type for the error codes used by the message handler */



typedef unsigned long MH_ERROR;



/* logging levels for the message handler */



typedef enum

{

    MH_LEVEL_DEBUG,

    MH_LEVEL_INFO,

    MH_LEVEL_WARN,

    MH_LEVEL_ERROR,

    MH_LEVEL_CRITICAL

} MH_LEVEL;



/*

   makeCode()

   makes the "external" error code to report with log() or error()

   call with facility = module id; severity = 1 iff critical.

   'code' is the error code internal to Sablotron.

*/



typedef MH_ERROR

MessageHandlerMakeCode(

    void *userData, SablotHandle processor_,

    int severity, unsigned short facility, unsigned short code);



/*

   log()

   pass code created by makeCode, level as necessary

   fields is a NULL-terminated list of strings in form "field:contents"

   distinguished fields include: msg, file, line, token

*/



typedef MH_ERROR

MessageHandlerLog(

    void *userData, SablotHandle processor_,

    MH_ERROR code, MH_LEVEL level, char **fields);



/*

   error()

   for reporting errors, meaning as with log()

*/



typedef MH_ERROR

MessageHandlerError(void *userData, SablotHandle processor_,

    MH_ERROR code, MH_LEVEL level, char **fields);



/* the message handler structure. Use SablotRegMessageHandler() to register. */



typedef struct

{

    MessageHandlerMakeCode *makeCode;

    MessageHandlerLog *log;

    MessageHandlerError *error;

} MessageHandler;











/*



                SAXHandler

    a SAX-like, streaming interface for access to XML docs



*/





#define SAX_RETURN void



typedef SAX_RETURN

SAXHandlerStartDocument(void* userData, SablotHandle processor_);



typedef SAX_RETURN

SAXHandlerStartElement(void* userData, SablotHandle processor_,

    const char* name, const char** atts);



typedef SAX_RETURN

SAXHandlerEndElement(void* userData, SablotHandle processor_,

    const char* name);



typedef SAX_RETURN

SAXHandlerStartNamespace(void* userData, SablotHandle processor_,

    const char* prefix, const char* uri);



typedef SAX_RETURN

SAXHandlerEndNamespace(void* userData, SablotHandle processor_,

    const char* prefix);



typedef SAX_RETURN

SAXHandlerComment(void* userData, SablotHandle processor_,

    const char* contents);



typedef SAX_RETURN

SAXHandlerPI(void* userData, SablotHandle processor_,

    const char* target, const char* contents);



typedef SAX_RETURN

SAXHandlerCharacters(void* userData, SablotHandle processor_,

    const char* contents, int length);



typedef SAX_RETURN

SAXHandlerEndDocument(void* userData, SablotHandle processor_);





/*

    The SAX handler structure. Use SablotRegSAXHandler() to register.

*/





typedef struct

{

    SAXHandlerStartDocument     *startDocument;

    SAXHandlerStartElement      *startElement;

    SAXHandlerEndElement        *endElement;

    SAXHandlerStartNamespace    *startNamespace;

    SAXHandlerEndNamespace      *endNamespace;

    SAXHandlerComment           *comment;

    SAXHandlerPI                *processingInstruction;

    SAXHandlerCharacters        *characters;

    SAXHandlerEndDocument       *endDocument;

} SAXHandler;





/*****************************************************************

MiscHandler



  Collects miscellaneous callbacks.

*****************************************************************/



/*

    documentInfo()

    If set, this callback gets called after the output of a result

    document is finished, giving information about its content type

    and encoding.

*/



typedef void

MiscHandlerDocumentInfo(void* userData, SablotHandle processor_,

    const char *contentType, const char *encoding);



/*

    The Misc handler structure.

    Use SablotRegHandler(HLR_MISC, ...) to register.

*/



typedef struct

{

    MiscHandlerDocumentInfo     *documentInfo;

} MiscHandler;



/*****************************************************************

EncHandler



  Handler for recoding requests in absence of iconv.

*****************************************************************/



#define EH_FROM_UTF8 1

#define EH_TO_UTF8 0



/*

    the conversion descriptor like iconv_t

*/



typedef void* EHDescriptor;



typedef enum

{

    EH_OK,

    EH_EINVAL,

    EH_E2BIG,

    EH_EILSEQ

} EHResult;



/*

    open()

    direction is either EH_FROM_UTF8 or EH_TO_UTF8

    encoding is the other encoding

    RETURN the descriptor, or -1 if the encoding is not supported

*/



typedef EHDescriptor EncHandlerOpen(void* userData, SablotHandle processor_,

    int direction, const char *encoding);



/*

    conv()

    arguments 3 through 7 are just like for iconv, see the manpage

    RETURN -1 on error (set errno), a different value (e.g. 0) if OK

*/



typedef EHResult EncHandlerConv(void* userData, SablotHandle processor_,

    EHDescriptor cd, const char** inbuf, size_t *inbytesleft,

    char ** outbuf, size_t *outbytesleft);



/*

    close()

    cd is the descriptor to close. Return 0 if OK, -1 on error.

*/



typedef int EncHandlerClose(void* userData, SablotHandle processor_,

    EHDescriptor cd);



/*

    The EncHandler structure.

    Use SablotRegHandler(HLR_ENC, ...) to register.

*/



typedef struct

{

    EncHandlerOpen      *open;

    EncHandlerConv      *conv;

    EncHandlerClose     *close;

} EncHandler;



#endif