11 * |
11 * |
12 * You should have received a copy of the GNU General Public License |
12 * You should have received a copy of the GNU General Public License |
13 * along with this program; if not, write to the Free Software |
13 * along with this program; if not, write to the Free Software |
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
15 * |
15 * |
16 * Jabber |
16 * Copyrights |
17 * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ |
17 * |
|
18 * Portions created by or assigned to Jabber.com, Inc. are |
|
19 * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact |
|
20 * information for Jabber.com, Inc. is available at http://www.jabber.com/. |
|
21 * |
|
22 * Portions Copyright (c) 1998-1999 Jeremie Miller. |
|
23 * |
|
24 * Acknowledgements |
|
25 * |
|
26 * Special thanks to the Jabber Open Source Contributors for their |
|
27 * suggestions and support of Jabber. |
|
28 * |
|
29 * |
|
30 */ |
|
31 |
|
32 /** |
|
33 * @file pproxy.c |
|
34 * @brief presence proxy database - DEPRECATED |
|
35 * |
|
36 * @deprecated these functions are not used by jabberd itself (but aim-t uses them), they will be removed from jabberd |
|
37 * |
|
38 * The presence proxy database is used to store presences for different resources of a JID. |
|
39 * |
|
40 * these aren't the most efficient things in the world, a hash optimized for tiny spaces would be far better |
18 */ |
41 */ |
19 |
42 |
20 #include "jabber.h" |
43 #include "jabber.h" |
21 |
44 |
22 /* these aren't the most efficient things in the world, a hash optimized for tiny spaces would be far better */ |
45 /* these aren't the most efficient things in the world, a hash optimized for tiny spaces would be far better */ |
40 ppdb cur; |
63 ppdb cur; |
41 |
64 |
42 if(db == NULL || id == NULL) return NULL; |
65 if(db == NULL || id == NULL) return NULL; |
43 |
66 |
44 for(cur = db->next; cur != NULL; cur = cur->next) |
67 for(cur = db->next; cur != NULL; cur = cur->next) |
45 if(jid_cmp(cur->id,id) == 0) return cur; |
68 if(jid_cmp(cur->id,id) == 0) return cur; |
46 |
69 |
47 return NULL; |
70 return NULL; |
48 } |
71 } |
49 |
72 |
50 ppdb ppdb_insert(ppdb db, jid id, xmlnode x) |
73 ppdb ppdb_insert(ppdb db, jid id, xmlnode x) |
51 { |
74 { |
52 char *res; |
|
53 ppdb cur, curu; |
75 ppdb cur, curu; |
54 pool p; |
76 pool p; |
55 |
77 |
56 if(id == NULL || id->server == NULL || x == NULL) |
78 if(id == NULL || id->server == NULL || x == NULL) |
57 return db; |
79 return db; |
58 |
80 |
59 /* new ppdb list dummy holder */ |
81 /* new ppdb list dummy holder */ |
60 if(db == NULL) |
82 if(db == NULL) |
61 { |
83 { |
62 p = pool_heap(1024); |
84 p = pool_heap(1024); |
63 db = _ppdb_new(p,id); |
85 db = _ppdb_new(p,NULL); |
64 } |
86 } |
65 |
87 |
66 cur = _ppdb_get(db,id); |
88 cur = _ppdb_get(db,id); |
67 |
89 |
68 /* just update it */ |
90 /* just update it */ |
69 if(cur != NULL) |
91 if(cur != NULL) |
70 { |
92 { |
71 xmlnode_free(cur->x); |
93 xmlnode_free(cur->x); |
72 cur->x = xmlnode_dup(x); |
94 cur->x = xmlnode_dup(x); |
73 cur->pri = jutil_priority(x); |
95 cur->pri = jutil_priority(x); |
74 return db; |
96 return db; |
75 } |
97 } |
76 |
98 |
77 /* make an entry for it */ |
99 /* make an entry for it */ |
78 cur = _ppdb_new(db->p,id); |
100 cur = _ppdb_new(db->p,id); |
79 cur->x = xmlnode_dup(x); |
101 cur->x = xmlnode_dup(x); |
80 cur->pri = jutil_priority(x); |
102 cur->pri = jutil_priority(x); |
81 cur->next = db->next; |
103 cur->next = db->next; |
82 db->next = cur; |
104 db->next = cur; |
83 |
105 |
84 /* this is a presence from a resource, make an entry for just the user */ |
106 /* if this is a user's resource presence, get the the user entry */ |
85 if(id->user != NULL && id->resource != NULL) |
107 if(id->user != NULL && (curu = _ppdb_get(db,jid_user(id))) != cur) |
86 { |
108 { |
87 /* modify the id to just user@host */ |
109 /* no user entry, make one */ |
88 res = id->resource; |
110 if(curu == NULL) |
89 jid_set(id,NULL,JID_RESOURCE); |
111 { |
90 curu = _ppdb_get(db,id); |
112 curu = _ppdb_new(db->p,jid_user(id)); |
91 |
113 curu->next = db->next; |
92 /* no user entry, make one */ |
114 db->next = curu; |
93 if(curu == NULL) |
115 } |
94 { |
116 |
95 curu = _ppdb_new(db->p,id); |
117 /* insert this resource into the user list */ |
96 curu->next = db->next; |
118 cur->user = curu->user; |
97 db->next = curu; |
119 curu->user = cur; |
98 } |
|
99 |
|
100 /* restore the id */ |
|
101 jid_set(id,res,JID_RESOURCE); |
|
102 |
|
103 /* insert this resource into the user list */ |
|
104 cur->user = curu->user; |
|
105 curu->user = cur; |
|
106 } |
120 } |
107 |
121 |
108 return db; |
122 return db; |
109 } |
123 } |
110 |
124 |
121 /* not user@host check, just return */ |
135 /* not user@host check, just return */ |
122 if(id->user == NULL || id->resource != NULL) return cur->x; |
136 if(id->user == NULL || id->resource != NULL) return cur->x; |
123 |
137 |
124 top = cur; |
138 top = cur; |
125 for(cur = cur->user; cur != NULL; cur = cur->user) |
139 for(cur = cur->user; cur != NULL; cur = cur->user) |
126 if(cur->pri >= top->pri) top = cur; |
140 if(cur->pri >= top->pri) top = cur; |
127 |
141 |
128 if(top != NULL && top->pri >= 0) return top->x; |
142 if(top != NULL && top->pri >= 0) return top->x; |
129 |
143 |
130 return NULL; |
144 return NULL; |
131 } |
145 } |
139 if(db == NULL || id == NULL) return NULL; |
153 if(db == NULL || id == NULL) return NULL; |
140 |
154 |
141 /* MODE: if this is NOT just user@host addy, return just the single entry */ |
155 /* MODE: if this is NOT just user@host addy, return just the single entry */ |
142 if(id->user == NULL || id->resource != NULL) |
156 if(id->user == NULL || id->resource != NULL) |
143 { |
157 { |
144 /* we were just here, return now */ |
158 /* we were just here, return now */ |
145 if(last != NULL) |
159 if(last != NULL) |
146 { |
160 { |
147 last = NULL; |
161 last = NULL; |
148 return NULL; |
162 return NULL; |
149 } |
163 } |
150 |
164 |
151 last = _ppdb_get(db,id); |
165 last = _ppdb_get(db,id); |
152 if(last != NULL) |
166 if(last != NULL) |
153 return last->x; |
167 return last->x; |
154 else |
168 else |
155 return NULL; |
169 return NULL; |
156 } |
170 } |
157 |
171 |
158 /* handle looping for user@host */ |
172 /* handle looping for user@host */ |
159 |
173 |
160 /* we're already in the loop */ |
174 /* we're already in the loop */ |
161 if(last != NULL) |
175 if(last != NULL) |
162 { |
176 { |
163 /* this is the last entry in the list */ |
177 /* this is the last entry in the list */ |
164 if(last->user == NULL) |
178 if(last->user == NULL) |
165 { |
179 { |
166 last = NULL; |
180 last = NULL; |
167 return NULL; |
181 return NULL; |
168 } |
182 } |
169 |
183 |
170 last = last->user; |
184 last = last->user; |
171 return last->x; |
185 return last->x; |
172 } |
186 } |
173 |
187 |
174 /* start a new loop */ |
188 /* start a new loop */ |
175 cur = _ppdb_get(db,id); |
189 cur = _ppdb_get(db,id); |
176 |
190 |
177 if(cur == NULL) return NULL; |
191 if(cur == NULL) return NULL; |
178 |
192 |
179 last = cur->user; |
193 last = cur->user; |
180 if(last != NULL) |
194 if(last != NULL) |
181 return last->x; |
195 return last->x; |
182 else |
196 else |
183 return NULL; |
197 return NULL; |
184 } |
198 } |
185 |
199 |
186 |
200 |
187 void ppdb_free(ppdb db) |
201 void ppdb_free(ppdb db) |
188 { |
202 { |
189 ppdb cur; |
203 ppdb cur; |
190 |
204 |
191 if(db == NULL) return; |
205 if(db == NULL) return; |
192 |
206 |
193 for(cur = db; cur != NULL; cur = cur->next) |
207 for(cur = db; cur != NULL; cur = cur->next) |
194 xmlnode_free(cur->x); |
208 xmlnode_free(cur->x); |
195 |
209 |
196 pool_free(db->p); |
210 pool_free(db->p); |
197 } |
211 } |
198 |
212 |