[8f243ad] | 1 | /***************************************************************************\ |
---|
| 2 | * * |
---|
| 3 | * BitlBee - An IRC to IM gateway * |
---|
| 4 | * Simple XML (stream) parse tree handling code (Jabber/XMPP, mainly) * |
---|
| 5 | * * |
---|
[0e788f5] | 6 | * Copyright 2006-2012 Wilmer van der Gaast <wilmer@gaast.net> * |
---|
[8f243ad] | 7 | * * |
---|
| 8 | * This library is free software; you can redistribute it and/or * |
---|
| 9 | * modify it under the terms of the GNU Lesser General Public * |
---|
| 10 | * License as published by the Free Software Foundation, version * |
---|
| 11 | * 2.1. * |
---|
| 12 | * * |
---|
| 13 | * This library is distributed in the hope that it will be useful, * |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
---|
| 16 | * Lesser General Public License for more details. * |
---|
| 17 | * * |
---|
| 18 | * You should have received a copy of the GNU Lesser General Public License * |
---|
| 19 | * along with this library; if not, write to the Free Software Foundation, * |
---|
| 20 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * |
---|
| 21 | * * |
---|
| 22 | ****************************************************************************/ |
---|
| 23 | |
---|
[f06894d] | 24 | #ifndef _XMLTREE_H |
---|
| 25 | #define _XMLTREE_H |
---|
| 26 | |
---|
[8f243ad] | 27 | typedef enum |
---|
| 28 | { |
---|
| 29 | XT_COMPLETE = 1, /* </tag> reached */ |
---|
| 30 | XT_SEEN = 2, /* Handler called (or not defined) */ |
---|
| 31 | } xt_flags; |
---|
| 32 | |
---|
| 33 | typedef enum |
---|
| 34 | { |
---|
| 35 | XT_ABORT, /* Abort, don't handle the rest anymore */ |
---|
| 36 | XT_HANDLED, /* Handled this tag properly, go to the next one */ |
---|
| 37 | XT_NEXT /* Try if there's another matching handler */ |
---|
| 38 | } xt_status; |
---|
| 39 | |
---|
| 40 | struct xt_attr |
---|
| 41 | { |
---|
| 42 | char *key, *value; |
---|
| 43 | }; |
---|
| 44 | |
---|
| 45 | struct xt_node |
---|
| 46 | { |
---|
| 47 | struct xt_node *parent; |
---|
| 48 | struct xt_node *children; |
---|
| 49 | |
---|
| 50 | char *name; |
---|
| 51 | struct xt_attr *attr; |
---|
| 52 | char *text; |
---|
| 53 | int text_len; |
---|
| 54 | |
---|
| 55 | struct xt_node *next; |
---|
| 56 | xt_flags flags; |
---|
| 57 | }; |
---|
| 58 | |
---|
| 59 | typedef xt_status (*xt_handler_func) ( struct xt_node *node, gpointer data ); |
---|
| 60 | |
---|
| 61 | struct xt_handler_entry |
---|
| 62 | { |
---|
| 63 | char *name, *parent; |
---|
| 64 | xt_handler_func func; |
---|
| 65 | }; |
---|
| 66 | |
---|
| 67 | struct xt_parser |
---|
| 68 | { |
---|
| 69 | GMarkupParseContext *parser; |
---|
| 70 | struct xt_node *root; |
---|
| 71 | struct xt_node *cur; |
---|
| 72 | |
---|
[4bbcba3] | 73 | const struct xt_handler_entry *handlers; |
---|
[8f243ad] | 74 | gpointer data; |
---|
| 75 | |
---|
| 76 | GError *gerr; |
---|
| 77 | }; |
---|
| 78 | |
---|
[4bbcba3] | 79 | struct xt_parser *xt_new( const struct xt_handler_entry *handlers, gpointer data ); |
---|
[8f243ad] | 80 | void xt_reset( struct xt_parser *xt ); |
---|
[d93c0eb9] | 81 | int xt_feed( struct xt_parser *xt, const char *text, int text_len ); |
---|
[101d84f] | 82 | int xt_handle( struct xt_parser *xt, struct xt_node *node, int depth ); |
---|
| 83 | void xt_cleanup( struct xt_parser *xt, struct xt_node *node, int depth ); |
---|
[d0752e8] | 84 | struct xt_node *xt_from_string( const char *in, int text_len ); |
---|
[8f243ad] | 85 | char *xt_to_string( struct xt_node *node ); |
---|
| 86 | void xt_print( struct xt_node *node ); |
---|
[022df46] | 87 | struct xt_node *xt_dup( struct xt_node *node ); |
---|
[8f243ad] | 88 | void xt_free_node( struct xt_node *node ); |
---|
| 89 | void xt_free( struct xt_parser *xt ); |
---|
[40ef702] | 90 | struct xt_node *xt_find_node( struct xt_node *node, const char *name ); |
---|
[d912fe4] | 91 | struct xt_node *xt_find_path( struct xt_node *node, const char *name ); |
---|
[40ef702] | 92 | char *xt_find_attr( struct xt_node *node, const char *key ); |
---|
[8f243ad] | 93 | |
---|
[94acdd0] | 94 | struct xt_node *xt_new_node( char *name, const char *text, struct xt_node *children ); |
---|
[8f243ad] | 95 | void xt_add_child( struct xt_node *parent, struct xt_node *child ); |
---|
[b46769d] | 96 | void xt_insert_child( struct xt_node *parent, struct xt_node *child ); |
---|
[40ef702] | 97 | void xt_add_attr( struct xt_node *node, const char *key, const char *value ); |
---|
| 98 | int xt_remove_attr( struct xt_node *node, const char *key ); |
---|
[f06894d] | 99 | |
---|
| 100 | #endif |
---|