annotate src/protocols/jabber/pproxy.c @ 6695:0c5637b5462e

[gaim-migrate @ 7221] This is contact support. Really. It has a few bugs left in it, like sorting not working, and stuff like that, but it's pretty solid for the most part. I'm not in the mood to do a whole lot of typing, so just use and enjoy. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Tue, 02 Sep 2003 03:41:10 +0000
parents 4e7cefc55971
children
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 /* these aren't the most efficient things in the world, a hash optimized for tiny spaces would be far better */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 ppdb _ppdb_new(pool p, jid id)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48 ppdb ret;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 ret = pmalloc(p,sizeof(_ppdb));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 ret->p = p;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 ret->pri = -1;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 ret->next = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53 ret->user = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 ret->x = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 ret->id = jid_new(p,jid_full(id));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 return ret;
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
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60 ppdb _ppdb_get(ppdb db, jid id)
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 ppdb cur;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64 if(db == NULL || id == NULL) return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 for(cur = db->next; cur != NULL; cur = cur->next)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 if(jid_cmp(cur->id,id) == 0) return cur;
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 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70 }
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 ppdb ppdb_insert(ppdb db, jid id, xmlnode x)
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 ppdb cur, curu;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 pool p;
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 if(id == NULL || id->server == NULL || x == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 return db;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 /* new ppdb list dummy holder */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81 if(db == NULL)
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 p = pool_heap(1024);
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
84 db = _ppdb_new(p,NULL);
2086
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
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87 cur = _ppdb_get(db,id);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89 /* just update it */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
90 if(cur != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
91 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
92 xmlnode_free(cur->x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93 cur->x = xmlnode_dup(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 cur->pri = jutil_priority(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
95 return db;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
96 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
97
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98 /* make an entry for it */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99 cur = _ppdb_new(db->p,id);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 cur->x = xmlnode_dup(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101 cur->pri = jutil_priority(x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 cur->next = db->next;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103 db->next = cur;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
105 /* if this is a user's resource presence, get the the user entry */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
106 if(id->user != NULL && (curu = _ppdb_get(db,jid_user(id))) != cur)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108 /* no user entry, make one */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
109 if(curu == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110 {
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
111 curu = _ppdb_new(db->p,jid_user(id));
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
112 curu->next = db->next;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
113 db->next = curu;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
114 }
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 /* insert this resource into the user list */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
117 cur->user = curu->user;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
118 curu->user = cur;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
119 }
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 db;
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
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
124 xmlnode ppdb_primary(ppdb db, jid id)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
125 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
126 ppdb cur, top;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
128 if(db == NULL || id == NULL) return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
129
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
130 cur = _ppdb_get(db,id);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
131
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132 if(cur == NULL) return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
133
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 /* not user@host check, just return */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135 if(id->user == NULL || id->resource != NULL) return cur->x;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137 top = cur;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138 for(cur = cur->user; cur != NULL; cur = cur->user)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
139 if(cur->pri >= top->pri) top = cur;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
140
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
141 if(top != NULL && top->pri >= 0) return top->x;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
142
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
144 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
145
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
146 /* return the presence for the id, successive calls return all of the known resources for a user@host address */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
147 xmlnode ppdb_get(ppdb db, jid id)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
148 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
149 static ppdb last = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
150 ppdb cur;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
151
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
152 if(db == NULL || id == NULL) return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
153
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
154 /* MODE: if this is NOT just user@host addy, return just the single entry */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
155 if(id->user == NULL || id->resource != NULL)
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 /* we were just here, return now */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158 if(last != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 last = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164 last = _ppdb_get(db,id);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
165 if(last != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
166 return last->x;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167 else
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168 return NULL;
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
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
171 /* handle looping for user@host */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
172
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
173 /* we're already in the loop */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
174 if(last != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
175 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
176 /* this is the last entry in the list */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
177 if(last->user == NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
178 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
179 last = NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
180 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
181 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
182
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
183 last = last->user;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
184 return last->x;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
185 }
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 /* start a new loop */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
188 cur = _ppdb_get(db,id);
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 if(cur == NULL) return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
191
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
192 last = cur->user;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
193 if(last != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
194 return last->x;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
195 else
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
196 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
197 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
198
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 void ppdb_free(ppdb db)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
201 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
202 ppdb cur;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
203
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
204 if(db == NULL) return;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
205
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
206 for(cur = db; cur != NULL; cur = cur->next)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
207 xmlnode_free(cur->x);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
208
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
209 pool_free(db->p);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
210 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
211