annotate src/protocols/jabber/xmlnode.c @ 4878:77b04219f3e2

[gaim-migrate @ 5208] someone please let me know if this sounds better with 8-bit sounds (like the ones that come with winaim) committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Mon, 24 Mar 2003 06:58:25 +0000
parents 4e7cefc55971
children 67c4e9d39242
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
1 /* --------------------------------------------------------------------------
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
2 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
3 * License
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
4 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
5 * The contents of this file are subject to the Jabber Open Source License
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
6 * Version 1.0 (the "JOSL"). You may not copy or use this file, in either
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
7 * source code or executable form, except in compliance with the JOSL. You
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
8 * may obtain a copy of the JOSL at http://www.jabber.org/ or at
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
9 * http://www.opensource.org/.
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
10 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
11 * Software distributed under the JOSL is distributed on an "AS IS" basis,
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
13 * for the specific language governing rights and limitations under the
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
14 * JOSL.
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
15 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
16 * Copyrights
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
17 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
18 * Portions created by or assigned to Jabber.com, Inc. are
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
19 * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
20 * information for Jabber.com, Inc. is available at http://www.jabber.com/.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21 *
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
22 * Portions Copyright (c) 1998-1999 Jeremie Miller.
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
23 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
24 * Acknowledgements
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
25 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
26 * Special thanks to the Jabber Open Source Contributors for their
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
27 * suggestions and support of Jabber.
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
28 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
29 * Alternatively, the contents of this file may be used under the terms of the
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
30 * GNU General Public License Version 2 or later (the "GPL"), in which case
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
31 * the provisions of the GPL are applicable instead of those above. If you
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
32 * wish to allow use of your version of this file only under the terms of the
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
33 * GPL and not to allow others to use your version of this file under the JOSL,
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
34 * indicate your decision by deleting the provisions above and replace them
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
35 * with the notice and other provisions required by the GPL. If you do not
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
36 * delete the provisions above, a recipient may use your version of this file
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
37 * under either the JOSL or the GPL.
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
38 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
39 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
40 * --------------------------------------------------------------------------*/
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
42 #include "lib.h"
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 /* Internal routines */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 xmlnode _xmlnode_new(pool p, const char* name, unsigned int type)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 xmlnode result = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48 if (type > NTYPE_LAST)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 if (type != NTYPE_CDATA && name == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 if (p == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56 p = pool_heap(1*1024);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59 /* Allocate & zero memory */
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
60 result = (xmlnode)pmalloco(p, sizeof(_xmlnode));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 /* Initialize fields */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63 if (type != NTYPE_CDATA)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64 result->name = pstrdup(p,name);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65 result->type = type;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 result->p = p;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 return result;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70 static xmlnode _xmlnode_append_sibling(xmlnode lastsibling, const char* name, unsigned int type)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 xmlnode result;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74 result = _xmlnode_new(xmlnode_pool(lastsibling), name, type);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 if (result != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 /* Setup sibling pointers */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 result->prev = lastsibling;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 lastsibling->next = result;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81 return result;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 static xmlnode _xmlnode_insert(xmlnode parent, const char* name, unsigned int type)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 xmlnode result;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
88 if(parent == NULL || (type != NTYPE_CDATA && name == NULL)) return NULL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
90 /* If parent->firstchild is NULL, simply create a new node for the first child */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
91 if (parent->firstchild == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
92 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93 result = _xmlnode_new(parent->p, name, type);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 parent->firstchild = result;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
95 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
96 /* Otherwise, append this to the lastchild */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
97 else
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99 result= _xmlnode_append_sibling(parent->lastchild, name, type);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101 result->parent = parent;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 parent->lastchild = result;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103 return result;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
106
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107 static xmlnode _xmlnode_search(xmlnode firstsibling, const char* name, unsigned int type)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
109 xmlnode current;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
111 /* Walk the sibling list, looking for a NTYPE_TAG xmlnode with
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
112 the specified name */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
113 current = firstsibling;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
114 while (current != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
115 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
116 if ((current->type == type) && (j_strcmp(current->name, name) == 0))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
117 return current;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
118 else
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
119 current = current->next;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
120 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
121 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
123
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
124 void _xmlnode_merge(xmlnode data)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
125 {
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
126 xmlnode cur;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
127 char *merge, *scur;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
128 int imerge;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
129
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
130 /* get total size of all merged cdata */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
131 imerge = 0;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
132 for(cur = data; cur != NULL && cur->type == NTYPE_CDATA; cur = cur->next)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
133 imerge += cur->data_sz;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
135 /* copy in current data and then spin through all of them and merge */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
136 scur = merge = pmalloc(data->p,imerge + 1);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
137 for(cur = data; cur != NULL && cur->type == NTYPE_CDATA; cur = cur->next)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
138 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
139 memcpy(scur,cur->data,cur->data_sz);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
140 scur += cur->data_sz;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
141 }
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
142 *scur = '\0';
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
144 /* this effectively hides all of the merged-in chunks */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
145 data->next = cur;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
146 if(cur == NULL)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
147 data->parent->lastchild = data;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
148 else
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
149 cur->prev = data;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
150
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
151 /* reset data */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
152 data->data = merge;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
153 data->data_sz = imerge;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
154
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
155 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
156
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
157 static void _xmlnode_hide_sibling(xmlnode child)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159 if(child == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162 if(child->prev != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163 child->prev->next = child->next;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164 if(child->next != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
165 child->next->prev = child->prev;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
166 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168 void _xmlnode_tag2str(spool s, xmlnode node, int flag)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
169 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
170 xmlnode tmp;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
171
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
172 if(flag==0 || flag==1)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
173 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
174 spooler(s,"<",xmlnode_get_name(node),s);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
175 tmp = xmlnode_get_firstattrib(node);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
176 while(tmp) {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
177 spooler(s," ",xmlnode_get_name(tmp),"='",strescape(xmlnode_pool(node),xmlnode_get_data(tmp)),"'",s);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
178 tmp = xmlnode_get_nextsibling(tmp);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
179 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
180 if(flag==0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
181 spool_add(s,"/>");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
182 else
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
183 spool_add(s,">");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
184 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
185 else
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
186 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
187 spooler(s,"</",xmlnode_get_name(node),">",s);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
188 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
189 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
190
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
191 spool _xmlnode2spool(xmlnode node)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
192 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
193 spool s;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
194 int level=0,dir=0;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
195 xmlnode tmp;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
196
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
197 if(!node || xmlnode_get_type(node)!=NTYPE_TAG)
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
198 return NULL;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
199
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
200 s = spool_new(xmlnode_pool(node));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
201 if(!s) return(NULL);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
202
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
203 while(1)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
204 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
205 if(dir==0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
206 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
207 if(xmlnode_get_type(node) == NTYPE_TAG)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
208 {
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
209 if(xmlnode_has_children(node))
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
210 {
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
211 _xmlnode_tag2str(s,node,1);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
212 node = xmlnode_get_firstchild(node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
213 level++;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
214 continue;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
215 }else{
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
216 _xmlnode_tag2str(s,node,0);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
217 }
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
218 }else{
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
219 spool_add(s,strescape(xmlnode_pool(node),xmlnode_get_data(node)));
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
220 }
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
221 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
222
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
223 tmp = xmlnode_get_nextsibling(node);
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
224 if(!tmp)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
225 {
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
226 node = xmlnode_get_parent(node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
227 level--;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
228 if(level>=0) _xmlnode_tag2str(s,node,2);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
229 if(level<1) break;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
230 dir = 1;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
231 }else{
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
232 node = tmp;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
233 dir = 0;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
234 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
235 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
236
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
237 return s;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
238 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
239
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
240
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
241 /* External routines */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
242
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
243
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
244 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
245 * xmlnode_new_tag -- create a tag node
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
246 * Automatically creates a memory pool for the node.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
247 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
248 * parameters
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
249 * name -- name of the tag
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
250 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
251 * returns
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
252 * a pointer to the tag node
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
253 * or NULL if it was unsuccessfull
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
254 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
255 xmlnode xmlnode_new_tag(const char* name)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
256 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
257 return _xmlnode_new(NULL, name, NTYPE_TAG);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
258 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
259
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
260
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
261 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
262 * xmlnode_new_tag_pool -- create a tag node within given pool
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
263 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
264 * parameters
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
265 * p -- previously created memory pool
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
266 * name -- name of the tag
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
267 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
268 * returns
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
269 * a pointer to the tag node
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
270 * or NULL if it was unsuccessfull
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
271 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
272 xmlnode xmlnode_new_tag_pool(pool p, const char* name)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
273 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
274 return _xmlnode_new(p, name, NTYPE_TAG);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
275 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
276
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
277
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
278 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
279 * xmlnode_insert_tag -- append a child tag to a tag
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
280 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
281 * parameters
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
282 * parent -- pointer to the parent tag
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
283 * name -- name of the child tag
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
284 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
285 * returns
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
286 * a pointer to the child tag node
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
287 * or NULL if it was unsuccessfull
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
288 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
289 xmlnode xmlnode_insert_tag(xmlnode parent, const char* name)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
290 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
291 return _xmlnode_insert(parent, name, NTYPE_TAG);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
292 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
293
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
294
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
295 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
296 * xmlnode_insert_cdata -- append character data to a tag
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
297 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
298 * parameters
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
299 * parent -- parent tag
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
300 * CDATA -- character data
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
301 * size -- size of CDATA
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
302 * or -1 for null-terminated CDATA strings
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
303 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
304 * returns
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
305 * a pointer to the child CDATA node
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
306 * or NULL if it was unsuccessfull
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
307 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
308 xmlnode xmlnode_insert_cdata(xmlnode parent, const char* CDATA, unsigned int size)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
309 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
310 xmlnode result;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
311
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
312 if(CDATA == NULL || parent == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
313 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
314
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
315 if(size == -1)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
316 size = strlen(CDATA);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
317
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
318 result = _xmlnode_insert(parent, NULL, NTYPE_CDATA);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
319 if (result != NULL)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
320 {
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
321 result->data = (char*)pmalloc(result->p, size + 1);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
322 memcpy(result->data, CDATA, size);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
323 result->data[size] = '\0';
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
324 result->data_sz = size;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
325 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
326
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
327 return result;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
328 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
329
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
330
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
331 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
332 * xmlnode_get_tag -- find given tag in an xmlnode tree
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
333 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
334 * parameters
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
335 * parent -- pointer to the parent tag
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
336 * name -- "name" for the child tag of that name
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
337 * "name/name" for a sub child (recurses)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
338 * "?attrib" to match the first tag with that attrib defined
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
339 * "?attrib=value" to match the first tag with that attrib and value
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
340 * "=cdata" to match the cdata contents of the child
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
341 * or any combination: "name/name/?attrib", "name=cdata", etc
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
342 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
343 * results
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
344 * a pointer to the tag matching search criteria
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
345 * or NULL if search was unsuccessfull
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
346 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
347 xmlnode xmlnode_get_tag(xmlnode parent, const char* name)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
348 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
349 char *str, *slash, *qmark, *equals;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
350 xmlnode step, ret;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
351
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
352
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
353 if(parent == NULL || parent->firstchild == NULL || name == NULL || name == '\0') return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
354
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
355 if(strstr(name, "/") == NULL && strstr(name,"?") == NULL && strstr(name, "=") == NULL)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
356 return _xmlnode_search(parent->firstchild, name, NTYPE_TAG);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
357
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
358 str = strdup(name);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
359 slash = strstr(str, "/");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
360 qmark = strstr(str, "?");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
361 equals = strstr(str, "=");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
362
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
363 if(equals != NULL && (slash == NULL || equals < slash) && (qmark == NULL || equals < qmark))
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
364 { /* of type =cdata */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
365
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
366 *equals = '\0';
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
367 equals++;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
368
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
369 for(step = parent->firstchild; step != NULL; step = xmlnode_get_nextsibling(step))
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
370 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
371 if(xmlnode_get_type(step) != NTYPE_TAG)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
372 continue;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
373
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
374 if(*str != '\0')
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
375 if(j_strcmp(xmlnode_get_name(step),str) != 0)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
376 continue;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
377
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
378 if(j_strcmp(xmlnode_get_data(step),equals) != 0)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
379 continue;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
380
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
381 break;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
382 }
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
383
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
384 free(str);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
385 return step;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
386 }
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
387
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
388
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
389 if(qmark != NULL && (slash == NULL || qmark < slash))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
390 { /* of type ?attrib */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
391
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
392 *qmark = '\0';
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
393 qmark++;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
394 if(equals != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
395 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
396 *equals = '\0';
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
397 equals++;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
398 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
399
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
400 for(step = parent->firstchild; step != NULL; step = xmlnode_get_nextsibling(step))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
401 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
402 if(xmlnode_get_type(step) != NTYPE_TAG)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
403 continue;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
404
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
405 if(*str != '\0')
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
406 if(j_strcmp(xmlnode_get_name(step),str) != 0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
407 continue;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
408
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
409 if(xmlnode_get_attrib(step,qmark) == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
410 continue;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
411
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
412 if(equals != NULL && j_strcmp(xmlnode_get_attrib(step,qmark),equals) != 0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
413 continue;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
414
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
415 break;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
416 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
417
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
418 free(str);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
419 return step;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
420 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
421
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
422
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
423 *slash = '\0';
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
424 ++slash;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
425
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
426 for(step = parent->firstchild; step != NULL; step = xmlnode_get_nextsibling(step))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
427 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
428 if(xmlnode_get_type(step) != NTYPE_TAG) continue;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
429
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
430 if(j_strcmp(xmlnode_get_name(step),str) != 0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
431 continue;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
432
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
433 ret = xmlnode_get_tag(step, slash);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
434 if(ret != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
435 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
436 free(str);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
437 return ret;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
438 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
439 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
440
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
441 free(str);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
442 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
443 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
444
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
445
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
446 /* return the cdata from any tag */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
447 char *xmlnode_get_tag_data(xmlnode parent, const char *name)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
448 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
449 xmlnode tag;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
450
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
451 tag = xmlnode_get_tag(parent, name);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
452 if(tag == NULL) return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
453
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
454 return xmlnode_get_data(tag);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
455 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
456
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
457
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
458 void xmlnode_put_attrib(xmlnode owner, const char* name, const char* value)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
459 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
460 xmlnode attrib;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
461
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
462 if(owner == NULL || name == NULL || value == NULL) return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
463
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
464 /* If there are no existing attributs, allocate a new one to start
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
465 the list */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
466 if (owner->firstattrib == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
467 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
468 attrib = _xmlnode_new(owner->p, name, NTYPE_ATTRIB);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
469 owner->firstattrib = attrib;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
470 owner->lastattrib = attrib;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
471 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
472 else
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
473 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
474 attrib = _xmlnode_search(owner->firstattrib, name, NTYPE_ATTRIB);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
475 if(attrib == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
476 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
477 attrib = _xmlnode_append_sibling(owner->lastattrib, name, NTYPE_ATTRIB);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
478 owner->lastattrib = attrib;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
479 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
480 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
481 /* Update the value of the attribute */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
482 attrib->data_sz = strlen(value);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
483 attrib->data = pstrdup(owner->p, value);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
484
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
485 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
486
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
487 char* xmlnode_get_attrib(xmlnode owner, const char* name)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
488 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
489 xmlnode attrib;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
490
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
491 if (owner != NULL && owner->firstattrib != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
492 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
493 attrib = _xmlnode_search(owner->firstattrib, name, NTYPE_ATTRIB);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
494 if (attrib != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
495 return (char*)attrib->data;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
496 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
497 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
498 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
499
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
500 void xmlnode_put_vattrib(xmlnode owner, const char* name, void *value)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
501 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
502 xmlnode attrib;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
503
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
504 if (owner != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
505 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
506 attrib = _xmlnode_search(owner->firstattrib, name, NTYPE_ATTRIB);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
507 if (attrib == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
508 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
509 xmlnode_put_attrib(owner, name, "");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
510 attrib = _xmlnode_search(owner->firstattrib, name, NTYPE_ATTRIB);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
511 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
512 if (attrib != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
513 attrib->firstchild = (xmlnode)value;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
514 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
515 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
516
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
517 void* xmlnode_get_vattrib(xmlnode owner, const char* name)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
518 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
519 xmlnode attrib;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
520
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
521 if (owner != NULL && owner->firstattrib != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
522 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
523 attrib = _xmlnode_search(owner->firstattrib, name, NTYPE_ATTRIB);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
524 if (attrib != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
525 return (void*)attrib->firstchild;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
526 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
527 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
528 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
529
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
530 xmlnode xmlnode_get_firstattrib(xmlnode parent)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
531 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
532 if (parent != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
533 return parent->firstattrib;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
534 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
535 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
536
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
537 xmlnode xmlnode_get_firstchild(xmlnode parent)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
538 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
539 if (parent != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
540 return parent->firstchild;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
541 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
542 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
543
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
544 xmlnode xmlnode_get_lastchild(xmlnode parent)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
545 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
546 if (parent != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
547 return parent->lastchild;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
548 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
549 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
550
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
551 xmlnode xmlnode_get_nextsibling(xmlnode sibling)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
552 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
553 if (sibling != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
554 return sibling->next;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
555 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
556 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
557
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
558 xmlnode xmlnode_get_prevsibling(xmlnode sibling)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
559 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
560 if (sibling != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
561 return sibling->prev;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
562 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
563 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
564
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
565 xmlnode xmlnode_get_parent(xmlnode node)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
566 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
567 if (node != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
568 return node->parent;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
569 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
570 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
571
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
572 char* xmlnode_get_name(xmlnode node)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
573 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
574 if (node != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
575 return node->name;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
576 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
577 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
578
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
579 char* xmlnode_get_data(xmlnode node)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
580 {
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
581 if(xmlnode_get_type(node) == NTYPE_TAG) /* loop till we find a CDATA in the children */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
582 for(node = xmlnode_get_firstchild(node); node != NULL; node = xmlnode_get_nextsibling(node))
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
583 if(xmlnode_get_type(node) == NTYPE_CDATA) break;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
584
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
585 if(node == NULL) return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
586
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
587 /* check for a dirty node w/ unassembled cdata chunks */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
588 if(xmlnode_get_type(node->next) == NTYPE_CDATA)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
589 _xmlnode_merge(node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
590
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
591 return node->data;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
592 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
593
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
594 int xmlnode_get_datasz(xmlnode node)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
595 {
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
596 if(xmlnode_get_type(node) != NTYPE_CDATA) return 0;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
597
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
598 /* check for a dirty node w/ unassembled cdata chunks */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
599 if(xmlnode_get_type(node->next) == NTYPE_CDATA)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
600 _xmlnode_merge(node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
601 return node->data_sz;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
602 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
603
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
604 int xmlnode_get_type(xmlnode node)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
605 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
606 if (node != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
607 return node->type;
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
608 return NTYPE_UNDEF;
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
609 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
610
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
611 int xmlnode_has_children(xmlnode node)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
612 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
613 if ((node != NULL) && (node->firstchild != NULL))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
614 return 1;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
615 return 0;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
616 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
617
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
618 int xmlnode_has_attribs(xmlnode node)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
619 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
620 if ((node != NULL) && (node->firstattrib != NULL))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
621 return 1;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
622 return 0;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
623 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
624
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
625 pool xmlnode_pool(xmlnode node)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
626 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
627 if (node != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
628 return node->p;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
629 return (pool)NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
630 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
631
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
632 void xmlnode_hide(xmlnode child)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
633 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
634 xmlnode parent;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
635
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
636 if(child == NULL || child->parent == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
637 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
638
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
639 parent = child->parent;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
640
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
641 /* first fix up at the child level */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
642 _xmlnode_hide_sibling(child);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
643
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
644 /* next fix up at the parent level */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
645 if(parent->firstchild == child)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
646 parent->firstchild = child->next;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
647 if(parent->lastchild == child)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
648 parent->lastchild = child->prev;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
649 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
650
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
651 void xmlnode_hide_attrib(xmlnode parent, const char *name)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
652 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
653 xmlnode attrib;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
654
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
655 if(parent == NULL || parent->firstattrib == NULL || name == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
656 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
657
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
658 attrib = _xmlnode_search(parent->firstattrib, name, NTYPE_ATTRIB);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
659 if(attrib == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
660 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
661
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
662 /* first fix up at the child level */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
663 _xmlnode_hide_sibling(attrib);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
664
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
665 /* next fix up at the parent level */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
666 if(parent->firstattrib == attrib)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
667 parent->firstattrib = attrib->next;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
668 if(parent->lastattrib == attrib)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
669 parent->lastattrib = attrib->prev;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
670 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
671
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
672
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
673
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
674 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
675 * xmlnode2str -- convert given xmlnode tree into a string
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
676 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
677 * parameters
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
678 * node -- pointer to the xmlnode structure
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
679 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
680 * results
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
681 * a pointer to the created string
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
682 * or NULL if it was unsuccessfull
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
683 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
684 char *xmlnode2str(xmlnode node)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
685 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
686 return spool_print(_xmlnode2spool(node));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
687 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
688
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
689 /*
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
690 * xmlnode2tstr -- convert given xmlnode tree into a newline terminated string
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
691 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
692 * parameters
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
693 * node -- pointer to the xmlnode structure
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
694 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
695 * results
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
696 * a pointer to the created string
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
697 * or NULL if it was unsuccessfull
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
698 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
699 char* xmlnode2tstr(xmlnode node)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
700 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
701 spool s = _xmlnode2spool(node);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
702 if (s != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
703 spool_add(s, "\n");
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
704 return spool_print(s);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
705 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
706
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
707
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
708 /* loop through both a and b comparing everything, attribs, cdata, children, etc */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
709 int xmlnode_cmp(xmlnode a, xmlnode b)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
710 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
711 int ret = 0;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
712
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
713 while(1)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
714 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
715 if(a == NULL && b == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
716 return 0;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
717
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
718 if(a == NULL || b == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
719 return -1;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
720
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
721 if(xmlnode_get_type(a) != xmlnode_get_type(b))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
722 return -1;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
723
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
724 switch(xmlnode_get_type(a))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
725 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
726 case NTYPE_ATTRIB:
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
727 ret = j_strcmp(xmlnode_get_name(a), xmlnode_get_name(b));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
728 if(ret != 0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
729 return -1;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
730 ret = j_strcmp(xmlnode_get_data(a), xmlnode_get_data(b));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
731 if(ret != 0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
732 return -1;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
733 break;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
734 case NTYPE_TAG:
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
735 ret = j_strcmp(xmlnode_get_name(a), xmlnode_get_name(b));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
736 if(ret != 0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
737 return -1;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
738 ret = xmlnode_cmp(xmlnode_get_firstattrib(a), xmlnode_get_firstattrib(b));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
739 if(ret != 0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
740 return -1;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
741 ret = xmlnode_cmp(xmlnode_get_firstchild(a), xmlnode_get_firstchild(b));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
742 if(ret != 0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
743 return -1;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
744 break;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
745 case NTYPE_CDATA:
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
746 ret = j_strcmp(xmlnode_get_data(a), xmlnode_get_data(b));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
747 if(ret != 0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
748 return -1;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
749 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
750 a = xmlnode_get_nextsibling(a);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
751 b = xmlnode_get_nextsibling(b);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
752 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
753 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
754
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
755
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
756 xmlnode xmlnode_insert_tag_node(xmlnode parent, xmlnode node)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
757 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
758 xmlnode child;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
759
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
760 child = xmlnode_insert_tag(parent, xmlnode_get_name(node));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
761 if (xmlnode_has_attribs(node))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
762 xmlnode_insert_node(child, xmlnode_get_firstattrib(node));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
763 if (xmlnode_has_children(node))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
764 xmlnode_insert_node(child, xmlnode_get_firstchild(node));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
765
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
766 return child;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
767 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
768
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
769 /* places copy of node and node's siblings in parent */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
770 void xmlnode_insert_node(xmlnode parent, xmlnode node)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
771 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
772 if(node == NULL || parent == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
773 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
774
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
775 while(node != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
776 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
777 switch(xmlnode_get_type(node))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
778 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
779 case NTYPE_ATTRIB:
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
780 xmlnode_put_attrib(parent, xmlnode_get_name(node), xmlnode_get_data(node));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
781 break;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
782 case NTYPE_TAG:
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
783 xmlnode_insert_tag_node(parent, node);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
784 break;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
785 case NTYPE_CDATA:
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
786 xmlnode_insert_cdata(parent, xmlnode_get_data(node), xmlnode_get_datasz(node));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
787 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
788 node = xmlnode_get_nextsibling(node);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
789 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
790 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
791
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
792
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
793 /* produce full duplicate of x with a new pool, x must be a tag! */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
794 xmlnode xmlnode_dup(xmlnode x)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
795 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
796 xmlnode x2;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
797
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
798 if(x == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
799 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
800
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
801 x2 = xmlnode_new_tag(xmlnode_get_name(x));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
802
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
803 if (xmlnode_has_attribs(x))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
804 xmlnode_insert_node(x2, xmlnode_get_firstattrib(x));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
805 if (xmlnode_has_children(x))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
806 xmlnode_insert_node(x2, xmlnode_get_firstchild(x));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
807
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
808 return x2;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
809 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
810
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
811 xmlnode xmlnode_dup_pool(pool p, xmlnode x)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
812 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
813 xmlnode x2;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
814
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
815 if(x == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
816 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
817
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
818 x2 = xmlnode_new_tag_pool(p, xmlnode_get_name(x));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
819
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
820 if (xmlnode_has_attribs(x))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
821 xmlnode_insert_node(x2, xmlnode_get_firstattrib(x));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
822 if (xmlnode_has_children(x))
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
823 xmlnode_insert_node(x2, xmlnode_get_firstchild(x));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
824
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
825 return x2;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
826 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
827
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
828 xmlnode xmlnode_wrap(xmlnode x,const char *wrapper)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
829 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
830 xmlnode wrap;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
831 if(x==NULL||wrapper==NULL) return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
832 wrap=xmlnode_new_tag_pool(xmlnode_pool(x),wrapper);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
833 if(wrap==NULL) return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
834 wrap->firstchild=x;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
835 wrap->lastchild=x;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
836 x->parent=wrap;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
837 return wrap;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
838 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
839
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
840 void xmlnode_free(xmlnode node)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
841 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
842 if(node == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
843 return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
844
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
845 pool_free(node->p);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
846 }