2 ** Copyright (C) 2006 Thadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU General Public License for more details.
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "iksemel_extra.h"
30 struct _iks_extra_stream_t
38 void iks_extra_insert_attrib (iks* node, char** atts)
44 iks_insert_attrib (node, atts[0], atts[1]);
49 int tagHook (void* user_data, char* name, char** atts, int type)
51 struct _iks_extra_stream_t* pdata;
52 pdata = (struct _iks_extra_stream_t*) user_data;
56 if (pdata->top == FALSE || g_str_equal (name, "stream:stream"))
59 pdata->node = iks_new (name);
60 iks_extra_insert_attrib (pdata->node, atts);
61 pdata->hook (pdata->data, IKS_NODE_START, pdata->node);
64 else if (pdata->node == NULL)
66 pdata->node = iks_new (name);
67 iks_extra_insert_attrib (pdata->node, atts);
71 pdata->node = iks_insert (pdata->node, name);
72 iks_extra_insert_attrib (pdata->node, atts);
76 if (pdata->node == NULL)
78 pdata->node = iks_new (name);
79 pdata->hook (pdata->data, IKS_NODE_STOP, pdata->node);
83 else if (iks_parent (pdata->node) == NULL)
85 pdata->hook (pdata->data, IKS_NODE_NORMAL, pdata->node);
90 pdata->node = iks_parent (pdata->node);
94 if (pdata->top == FALSE)
98 else if (pdata->node == NULL)
100 pdata->node = iks_new (name);
101 iks_extra_insert_attrib (pdata->node, atts);
102 pdata->hook (pdata->data, IKS_NODE_NORMAL, pdata->node);
107 pdata->node = iks_insert (pdata->node, name);
108 iks_extra_insert_attrib (pdata->node, atts);
109 pdata->node = iks_parent (pdata->node);
118 int dataHook (void* user_data, char* data, size_t len)
120 struct _iks_extra_stream_t* pdata;
121 pdata = (struct _iks_extra_stream_t*) user_data;
122 iks_insert_cdata (pdata->node, data, len);
126 void deleteHook (void* user_data)
128 iks_free (user_data);
131 iksparser* iks_extra_stream_new (void* data, iksStreamHook* hook)
134 struct _iks_extra_stream_t* pdata;
135 pdata = iks_malloc (sizeof (struct _iks_extra_stream_t));
140 parser = iks_sax_extend (iks_stack_new (256, 0),
141 pdata, tagHook, dataHook, deleteHook);