2 * Copyright (C) 2006,2008 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
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"
29 struct _iks_extra_stream_t
38 iks_extra_insert_attrib (iks* node, char** atts)
44 iks_insert_attrib (node, atts[0], atts[1]);
50 tagHook (void* user_data, char* name, char** atts, int type)
52 struct _iks_extra_stream_t* pdata;
53 pdata = (struct _iks_extra_stream_t*) user_data;
57 if (pdata->top == FALSE || !iks_strcmp (name, "stream:stream"))
60 pdata->node = iks_new (name);
61 iks_extra_insert_attrib (pdata->node, atts);
63 pdata->hook (pdata->data, IKS_NODE_START, pdata->node);
66 else if (pdata->node == NULL)
68 pdata->node = iks_new (name);
69 iks_extra_insert_attrib (pdata->node, atts);
73 pdata->node = iks_insert (pdata->node, name);
74 iks_extra_insert_attrib (pdata->node, atts);
78 if (pdata->node == NULL)
80 pdata->node = iks_new (name);
82 pdata->hook (pdata->data, IKS_NODE_STOP, pdata->node);
86 else if (iks_parent (pdata->node) == NULL)
89 pdata->hook (pdata->data, IKS_NODE_NORMAL, pdata->node);
94 pdata->node = iks_parent (pdata->node);
98 if (pdata->top == FALSE)
102 else if (pdata->node == NULL)
104 pdata->node = iks_new (name);
105 iks_extra_insert_attrib (pdata->node, atts);
107 pdata->hook (pdata->data, IKS_NODE_NORMAL, pdata->node);
112 pdata->node = iks_insert (pdata->node, name);
113 iks_extra_insert_attrib (pdata->node, atts);
114 pdata->node = iks_parent (pdata->node);
124 dataHook (void* user_data, char* data, size_t len)
126 struct _iks_extra_stream_t* pdata;
127 pdata = (struct _iks_extra_stream_t*) user_data;
128 iks_insert_cdata (pdata->node, data, len);
133 deleteHook (void* user_data)
135 iks_free (user_data);
139 iks_extra_stream_new (void* data, iksStreamHook* hook)
142 struct _iks_extra_stream_t* pdata;
143 pdata = iks_malloc (sizeof (struct _iks_extra_stream_t));
148 parser = iks_sax_extend (iks_stack_new (256, 0),
149 pdata, tagHook, dataHook, deleteHook);