summaryrefslogtreecommitdiffstats
path: root/axiom/include/axiom_xml_reader.h
blob: c9450a86bbbe800e58673717f4e6dbe8869b454f (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
/*
 *   Copyright 2004,2005 The Apache Software Foundation.
 *
 *   Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */

#ifndef AXIOM_XML_READER_H
#define AXIOM_XML_READER_H

/**
 *@file axiom_xml_reader.h
 *@brief this is the parser abstraction layer for axis2
 */

#include <axutil_env.h>
#include <axutil_utils.h>
#include <axiom_defines.h>

#ifdef __cplusplus
extern "C"
{
#endif

    typedef struct axiom_xml_reader_ops axiom_xml_reader_ops_t;
    typedef struct axiom_xml_reader axiom_xml_reader_t;

    /**
      * @defgroup axiom_parser parser
      * @ingroup axiom
      * @{
      * @}
      */

    /**
     * @defgroup axiom_xml_reader XML reader
     * @ingroup axiom_parser
     * @{
     */

    typedef enum axiom_xml_reader_event_types
    {
        AXIOM_XML_READER_START_DOCUMENT = 0,        /* <?xml version="1.0" encoding="utf-8"?> */
        AXIOM_XML_READER_START_ELEMENT,             /* <element>  */
        AXIOM_XML_READER_END_ELEMENT,               /* </element> */
        AXIOM_XML_READER_SPACE,                     /* <x>  </x>*//*event is for value, not for x*/
        AXIOM_XML_READER_EMPTY_ELEMENT,             /* <element/> */
        AXIOM_XML_READER_CHARACTER,                 /* <x>text</x>*//*event is for text, not for x*/
        AXIOM_XML_READER_ENTITY_REFERENCE,
        AXIOM_XML_READER_COMMENT,                   /* <!--comment--> */
        AXIOM_XML_READER_PROCESSING_INSTRUCTION,
        AXIOM_XML_READER_CDATA,
        AXIOM_XML_READER_DOCUMENT_TYPE
    } axiom_xml_reader_event_types;

    /**
      * \brief AXIOM_XML_READER ops
      * Encapsulator struct for ops of axiom_xml_reader
      */

    struct axiom_xml_reader_ops
    {

        /**
         * causes the reader to read the next parse event. 
         * returns the event just read
         * @param parser axiom_xml_reader struct 
         * @param env    axutil_environment, MUST NOT be NULL
         * @returns one of the events defined in 
         *          axiom_xml_reader_event_types
         */

        int(
            AXIS2_CALL
            * next)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env);

        /**
        * free pull_parser
        * @param parser axiom_xml_reader struct 
        * @param env    axutil_environment MUST NOT be NULL 
        * @returns axis2_status_code
        */

        void(
            AXIS2_CALL
            * free)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env);

        /**
         * Get the Number of attributes in the current element 
         * @param parser axiom_xml_reader  
         * @param env    axutil_environment, MUST NOT be NULL.
         * @returns Number of attributes , AXIS2_FAILURE on error 
         */

        int(
            AXIS2_CALL
            * get_attribute_count)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env);

        /** This is used to get an attribute's localname using an index relative to
          * current element.The iterations are not zero based. 
          * To access the first attribute use 1 for parameter i
          * @param parser parser struct 
          * @param env environment struct
          * @param i attribute index
          * @returns the attribute localname 
          *          caller must free the value using axiom_xml_reader_xml_free macro       
          */
        axis2_char_t *(
            AXIS2_CALL
            * get_attribute_name_by_number)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env,
                int i);

        /** This is used to get an attribute's prefix using an index relative to
          * current element. The iterations are not zero based. 
          * To access the first attribute use 1 for parameter i
          * @param parser parser struct 
          * @param env environment, MUST NOT be NULL
          * @param i attribute index.
          * @returns the attribute prefix, returns NULL on error,  
          *          caller must free the value using axiom_xml_reader_xml_free macro       
          */

        axis2_char_t *(
            AXIS2_CALL
            * get_attribute_prefix_by_number)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env,
                int i);

        /** Gets an attribute's value using an index relative to
         * current element. The iterations are not zero based. 
         * To access the first attribute use 1 for parameter i
         * @param parser parser struct 
         * @param env environment, MUST NOT be NULL.
         * @param i attribute index
         * @returns the attribute value, returns NULL on error,
         *          caller must free the value using axiom_xml_reader_xml_free macro        
         */

        axis2_char_t *(
            AXIS2_CALL
            * get_attribute_value_by_number)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env,
                int i);

        /** Gets an attribute's namespace uri using an index relative to
         * current element. The iterations are not zero based. 
         * To access the first attribute use 1 for parameter i
         * @param parser parser struct 
         * @param env environment struct
         * @param i attribute index
         * @returns the attribute value, returns NULL on error  
         *          caller must free the value using axiom_xml_reader_xml_free macro        
         */

        axis2_char_t *(
            AXIS2_CALL
            * get_attribute_namespace_by_number)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env,
                int i);

        /** Returns the text value of current element
          * @param parser pointer to parser
          * @param env environment, MUST not be NULL
          * @returns Text Value, NULL on error 
          *          caller must free the value using axiom_xml_reader_xml_free macro 
          */
        axis2_char_t *(
            AXIS2_CALL
            * get_value)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env);

        /**
         * Returns the namespace count of current element 
         * @param parser parser struct 
         * @param env environment
         * @returns namespace count of current element,
         */
        int(
            AXIS2_CALL
            * get_namespace_count)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env);

        /**
         * Accesses the namespace uri of the namespaces declared in current element 
         * using an index 
         * @param parser parser struct 
         * @param env environment 
         * @param i index
         * @returns namespace uri of corresponding namespace
         * caller must free the value using axiom_xml_reader_xml_free macro        
         */
        axis2_char_t *(
            AXIS2_CALL
            * get_namespace_uri_by_number)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env,
                int i);

        /**
         * Accesses the namespace prefix of the namespaces declared in current element 
         * using an index 
         * @param parser parser struct 
         * @param env environment 
         * @param i index
         * @returns namespace prefix of corresponding namespace 
         * caller must free the value using axiom_xml_reader_xml_free macro        
         */
        axis2_char_t *(
            AXIS2_CALL
            * get_namespace_prefix_by_number)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env,
                int i);

        /**
         * Used to obtain the current element prefix
         * @param parser parser struct 
         * @param env environment struct
         * @returns prefix , NULL on error 
         * caller must free the value using axiom_xml_reader_xml_free macro
         */
        axis2_char_t *(
            AXIS2_CALL
            * get_prefix)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env);

        /**
         * Used to obtain the current element localname
         * @param parser parser struct 
         * @param env environment struct
         * @returns localname , NULL on error 
         *          caller must free the value using axiom_xml_reader_xml_free macro
         */
        axis2_char_t *(
            AXIS2_CALL
            * get_name)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env);

        /**
         * Used to get the processingInstruction target
         * @param parser parser struct
         * @param env environment, MUST NOT be NULL.
         * @returns target value of processingInstruction
         * caller must free the value using axiom_xml_reader_xml_free macro
         */
        axis2_char_t *(
            AXIS2_CALL
            * get_pi_target)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env);

        /**
         * Gets the processingInstruction data
         * @param parser parser struct
         * @param env environment, MUST NOT be NULL.
         * @returns data of processingInstruction
         * caller must free the value using axiom_xml_reader_xml_free macro
         */
        axis2_char_t *(
            AXIS2_CALL
            * get_pi_data)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env);

        /**
         * Used to get the DTD 
         * @param parser pointer to pull parser struct
         * @param env environment, MUST NOT be NULL.
         * @return text of doctype declaration. NULL is returns of no data 
         * exists.
         */
        axis2_char_t *(
            AXIS2_CALL
            * get_dtd)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env);

        /**
         *  Free function , this function wraps the underlying parser's 
         *  xml free function. For freeing values obatined by calling
         *  pull parser api methods, This function must be used.
         * @param parser pointer to axiom_xml_reader
         * @param env environment, MUST NOT be NULL.
         * @param data data values to be destroyed
         * @return status of the op, AXIS2_SUCCESS on success,
         * AXIS2_FAILURE on error.
         */
        void(
            AXIS2_CALL
            * xml_free)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env,
                void *data);

        /**
         * Gets the char set encoding of the parser 
         * @param parser xml parser
         * @param env environment
         * @returns char set encoding string or NULL in failure
         */

        axis2_char_t *(
            AXIS2_CALL
            * get_char_set_encoding)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env);

        /** Returns the namespace uri associated with current node */
        axis2_char_t *(
            AXIS2_CALL
            * get_namespace_uri)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env);

        axis2_char_t *(
            AXIS2_CALL
            * get_namespace_uri_by_prefix)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env,
                axis2_char_t * prefix);
        
        void *(
            AXIS2_CALL
            * get_context)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env);
        
            axis2_char_t *(
            AXIS2_CALL
            * get_current_buffer)(
                axiom_xml_reader_t * parser,
                const axutil_env_t * env);
    };

    /**
     * @brief axiom_xml_reader struct
      *   Axis2 OM pull_parser
     */
    struct axiom_xml_reader
    {
        const axiom_xml_reader_ops_t *ops;
    };

    /**
     * Creates an instance of axiom_xml_reader to parse
     * a file using an xml document in a file system
     * @param env environment struct, must not be null
     * @param filename url of an xml document
     * @returns a pointer to xml_pull_parser_t struct
     * NULL on error with error code set in the environment's error
     */
    AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL
    axiom_xml_reader_create_for_file(
        const axutil_env_t * env,
        char *filename,
        const axis2_char_t * encoding);

    /**
     * This create an instance of axiom_xml_reader to
     * parse a xml document in a buffer. It takes a callback
     * function that takes a buffer and the size of the buffer
     * The user must implement a function that takes in buffer
     * and size and fill the buffer with specified size
     * with xml stream, parser will call this function to fill the
     * buffer on the fly while parsing.
     * @param env environment MUST NOT be NULL.
     * @param read_input_callback() callback function that fills
     * a char buffer.
     * @param close_input_callback() callback function that closes
     * the input stream.
     * @param ctx, context can be any data that needs to be passed
     * to the callback method.
     * @param encoding encoding scheme of the xml stream
     */
    AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL
    axiom_xml_reader_create_for_io(
        const axutil_env_t * env,
        AXIS2_READ_INPUT_CALLBACK,
        AXIS2_CLOSE_INPUT_CALLBACK,
        void *ctx,
        const axis2_char_t * encoding);

    /**
     * Create an axiom_xml_reader_t using a buffer, which is the xml input
     * @param env environment, MUST not be NULL
     * @param container any data that needs to passed to the corresponding
     * parser's create_for_memory method. The reader does not take ownership
     * of this data.
     * @param size size of the buffer
     * @param encoding encoding of the xml
     * @return pointer to axiom_xml_reader_t struct on success , NULL otherwise
     */
    AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL
    axiom_xml_reader_create_for_memory(
        const axutil_env_t * env,
        void *container,
        int size,
        const axis2_char_t * encoding,
        int type);

    /**
     * init function initializes the parser. When using libxml2 parser, this function 
     * is needed to initialize libxml2. 
     */
    AXIS2_EXTERN axis2_status_t AXIS2_CALL
    axiom_xml_reader_init(void
    );

    /**
     * parser cleanup function. This function is used to clean up the globals of libxml2
     * parser.
     */
    AXIS2_EXTERN axis2_status_t AXIS2_CALL
    axiom_xml_reader_cleanup(void
    );

    /**
     * while parsing through this method is calling for each and every
     * time it parse a charactor.This is the atomic method which parse charactors.
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return 
     */
    AXIS2_EXTERN int AXIS2_CALL
    axiom_xml_reader_next(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env);

    /**
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return 
     */
    AXIS2_EXTERN void AXIS2_CALL
    axiom_xml_reader_free(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env);

    /**
     * free method for xml reader
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return 
     */
    AXIS2_EXTERN int AXIS2_CALL
    axiom_xml_reader_get_attribute_count(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env);

    /**
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return number of attributes in an element
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_xml_reader_get_attribute_name_by_number(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env,
        int i);

    /**
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return the attribute name by number
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_xml_reader_get_attribute_prefix_by_number(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env,
        int i);

    /**
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return the attribute prefix by number
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_xml_reader_get_attribute_value_by_number(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env,
        int i);

    /**
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return attribute value by number
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_xml_reader_get_attribute_namespace_by_number(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env,
        int i);

    /**
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return attribute namespace by number
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_xml_reader_get_value(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env);

    /**
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return value of the element
     */
    AXIS2_EXTERN int AXIS2_CALL
    axiom_xml_reader_get_namespace_count(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env);

    /**
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return the number of namespaces in an element
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_xml_reader_get_namespace_uri_by_number(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env,
        int i);

    /**
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return uri or the namespace by number
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_xml_reader_get_namespace_prefix_by_number(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env,
        int i);

    /**
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return prefix of the namespace by number
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_xml_reader_get_prefix(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env);

    /**
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return namespace prefix
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_xml_reader_get_name(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env);

    /**
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return name of the element
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_xml_reader_get_pi_target(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env);

    /**
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return 
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_xml_reader_get_pi_data(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env);

    /**
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return 
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_xml_reader_get_dtd(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env);

    /**
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return 
     */
    AXIS2_EXTERN void AXIS2_CALL
    axiom_xml_reader_xml_free(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env,
        void *data);

    /**
     * free method for xml 
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return 
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_xml_reader_get_char_set_encoding(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env);

    /**
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return charactor encoding
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_xml_reader_get_namespace_uri(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env);

    /**
     * 
     * @param parser pointer to the OM XML Reader struct
     * @param env environment struct, must not be null
     *
     * @return 
     */
    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_xml_reader_get_namespace_uri_by_prefix(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env,
        axis2_char_t * prefix);
    
    AXIS2_EXTERN void *AXIS2_CALL
    axiom_xml_reader_get_context(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env);

    AXIS2_EXTERN axis2_char_t *AXIS2_CALL
    axiom_xml_reader_get_current_buffer(
        axiom_xml_reader_t * parser,
        const axutil_env_t * env);

    /** @} */

#ifdef __cplusplus
}
#endif

#endif                          /* AXIOM_XML_READER_H */