annotate src/protocols/sametime/meanwhile/srvc_resolve.c @ 12323:fc464a0abccc

[gaim-migrate @ 14627] Function prototypes need to be of the form foo(void); instead of foo(); for function that don't take any arguments. This allows the compiler to detect mistakes were someone passes arguments to such a function. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Sun, 04 Dec 2005 18:19:56 +0000
parents 0110fc7c6a8a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10969
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
1
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
2 /*
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
3 Meanwhile - Unofficial Lotus Sametime Community Client Library
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
4 Copyright (C) 2004 Christopher (siege) O'Brien
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
5
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
6 This library is free software; you can redistribute it and/or
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
7 modify it under the terms of the GNU Library General Public
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
8 License as published by the Free Software Foundation; either
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
9 version 2 of the License, or (at your option) any later version.
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
10
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
11 This library is distributed in the hope that it will be useful,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
14 Library General Public License for more details.
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
15
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
16 You should have received a copy of the GNU Library General Public
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
17 License along with this library; if not, write to the Free
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
19 */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
20
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
21 #include <glib/ghash.h>
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
22
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
23 #include "mw_channel.h"
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
24 #include "mw_common.h"
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
25 #include "mw_debug.h"
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
26 #include "mw_error.h"
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
27 #include "mw_service.h"
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
28 #include "mw_session.h"
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
29 #include "mw_srvc_resolve.h"
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
30
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
31
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
32 #define PROTOCOL_TYPE 0x00000015
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
33 #define PROTOCOL_VER 0x00000000
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
34
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
35
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
36 /** oddly, there is only one message type in this service */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
37 #define RESOLVE_ACTION 0x02
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
38
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
39
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
40 struct mwServiceResolve {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
41 struct mwService service;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
42
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
43 struct mwChannel *channel; /**< channel for this service */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
44 GHashTable *searches; /**< guint32:struct mw_search */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
45 guint32 counter; /**< incremented to provide searche IDs */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
46 };
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
47
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
48
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
49 /** structure representing an active search. keeps track of the ID,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
50 the handler, and the optional user data and cleanup */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
51 struct mw_search {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
52 struct mwServiceResolve *service;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
53 guint32 id;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
54 mwResolveHandler handler;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
55 gpointer data;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
56 GDestroyNotify cleanup;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
57 };
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
58
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
59
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
60 static struct mw_search *search_new(struct mwServiceResolve *srvc,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
61 mwResolveHandler handler,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
62 gpointer data, GDestroyNotify cleanup) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
63
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
64 struct mw_search *search = g_new0(struct mw_search, 1);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
65
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
66 search->service = srvc;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
67 search->handler = handler;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
68
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
69 /* we want search IDs that aren't SEARCH_ERROR */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
70 do {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
71 search->id = srvc->counter++;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
72 } while(search->id == SEARCH_ERROR);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
73
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
74 search->data = data;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
75 search->cleanup = cleanup;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
76
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
77 return search;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
78 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
79
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
80
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
81 /** called whenever a mw_search is removed from the searches table of
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
82 the service */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
83 static void search_free(struct mw_search *search) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
84 g_return_if_fail(search != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
85
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
86 if(search->cleanup)
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
87 search->cleanup(search->data);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
88
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
89 g_free(search);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
90 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
91
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
92
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
93 static const char *get_name(struct mwService *srvc) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
94 return "Identity Resolution";
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
95 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
96
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
97
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
98 static const char *get_desc(struct mwService *srvc) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
99 return "Resolves short IDs to full IDs";
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
100 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
101
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
102
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
103 static struct mwChannel *make_channel(struct mwServiceResolve *srvc) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
104 struct mwSession *session;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
105 struct mwChannelSet *cs;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
106 struct mwChannel *chan;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
107
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
108 session = mwService_getSession(MW_SERVICE(srvc));
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
109 cs = mwSession_getChannels(session);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
110 chan = mwChannel_newOutgoing(cs);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
111
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
112 mwChannel_setService(chan, MW_SERVICE(srvc));
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
113 mwChannel_setProtoType(chan, PROTOCOL_TYPE);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
114 mwChannel_setProtoVer(chan, PROTOCOL_VER);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
115
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
116 return mwChannel_create(chan)? NULL: chan;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
117 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
118
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
119
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
120 static void start(struct mwServiceResolve *srvc) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
121 struct mwChannel *chan;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
122
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
123 g_return_if_fail(srvc != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
124
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
125 chan = make_channel(srvc);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
126 if(chan) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
127 srvc->channel = chan;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
128 } else {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
129 mwService_stopped(MW_SERVICE(srvc));
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
130 return;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
131 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
132
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
133 /* semi-lazily create the searches table */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
134 srvc->searches = g_hash_table_new_full(g_direct_hash, g_direct_equal,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
135 NULL, (GDestroyNotify) search_free);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
136 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
137
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
138
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
139 static void stop(struct mwServiceResolve *srvc) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
140 g_return_if_fail(srvc != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
141
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
142 if(srvc->channel) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
143 mwChannel_destroy(srvc->channel, ERR_SUCCESS, NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
144 srvc->channel = NULL;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
145 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
146
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
147 /* destroy all the pending requests. */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
148 g_hash_table_destroy(srvc->searches);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
149 srvc->searches = NULL;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
150
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
151 mwService_stopped(MW_SERVICE(srvc));
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
152 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
153
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
154
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
155 static void clear(struct mwServiceResolve *srvc) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
156 if(srvc->searches) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
157 g_hash_table_destroy(srvc->searches);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
158 srvc->searches = NULL;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
159 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
160 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
161
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
162
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
163 static void recv_create(struct mwServiceResolve *srvc,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
164 struct mwChannel *chan,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
165 struct mwMsgChannelCreate *msg) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
166
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
167 /* you serve me, not the other way around */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
168 mwChannel_destroy(chan, ERR_FAILURE, NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
169 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
170
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
171
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
172 static void recv_accept(struct mwServiceResolve *srvc,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
173 struct mwChannel *chan,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
174 struct mwMsgChannelAccept *msg) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
175
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
176 g_return_if_fail(srvc != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
177 g_return_if_fail(chan != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
178 g_return_if_fail(chan == srvc->channel);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
179
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
180 mwService_started(MW_SERVICE(srvc));
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
181 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
182
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
183
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
184 static void recv_destroy(struct mwServiceResolve *srvc,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
185 struct mwChannel *chan,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
186 struct mwMsgChannelDestroy *msg) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
187
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
188 struct mwSession *session;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
189
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
190 g_return_if_fail(srvc != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
191 g_return_if_fail(chan != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
192 g_return_if_fail(chan == srvc->channel);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
193
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
194 srvc->channel = NULL;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
195 mwService_stop(MW_SERVICE(srvc));
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
196
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
197 session = mwService_getSession(MW_SERVICE(srvc));
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
198 g_return_if_fail(session != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
199
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
200 mwSession_senseService(session, mwService_getType(MW_SERVICE(srvc)));
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
201 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
202
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
203
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
204 static GList *load_matches(struct mwGetBuffer *b, guint32 count) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
205 GList *matches = NULL;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
206
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
207 while(count--) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
208 struct mwResolveMatch *m = g_new0(struct mwResolveMatch, 1);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
209
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
210 mwString_get(b, &m->id);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
211 mwString_get(b, &m->name);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
212 mwString_get(b, &m->desc);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
213 guint32_get(b, &m->type);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
214
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
215 matches = g_list_append(matches, m);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
216 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
217
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
218 return matches;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
219 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
220
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
221
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
222 static GList *load_results(struct mwGetBuffer *b, guint32 count) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
223 GList *results = NULL;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
224
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
225 while(count--) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
226 struct mwResolveResult *r = g_new0(struct mwResolveResult, 1);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
227 guint32 junk, matches;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
228
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
229 guint32_get(b, &junk);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
230 guint32_get(b, &r->code);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
231 mwString_get(b, &r->name);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
232
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
233 guint32_get(b, &matches);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
234 r->matches = load_matches(b, matches);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
235
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
236 results = g_list_append(results, r);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
237 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
238
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
239 return results;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
240 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
241
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
242
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
243 static void free_matches(GList *matches) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
244 for(; matches; matches = g_list_delete_link(matches, matches)) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
245 struct mwResolveMatch *m = matches->data;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
246 g_free(m->id);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
247 g_free(m->name);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
248 g_free(m->desc);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
249 g_free(m);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
250 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
251 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
252
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
253
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
254 static void free_results(GList *results) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
255 for(; results; results = g_list_delete_link(results, results)) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
256 struct mwResolveResult *r = results->data;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
257 g_free(r->name);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
258 free_matches(r->matches);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
259 g_free(r);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
260 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
261 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
262
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
263
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
264 static void recv(struct mwServiceResolve *srvc,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
265 struct mwChannel *chan,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
266 guint16 type, struct mwOpaque *data) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
267
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
268 struct mwGetBuffer *b;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
269 guint32 junk, id, code, count;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
270 struct mw_search *search;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
271
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
272 g_return_if_fail(srvc != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
273 g_return_if_fail(chan != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
274 g_return_if_fail(chan == srvc->channel);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
275 g_return_if_fail(data != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
276
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
277 if(type != RESOLVE_ACTION) {
11943
0110fc7c6a8a [gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents: 10969
diff changeset
278 mw_mailme_opaque(data, "unknown message in resolve service: 0x%04x", type);
10969
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
279 return;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
280 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
281
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
282 b = mwGetBuffer_wrap(data);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
283 guint32_get(b, &junk);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
284 guint32_get(b, &id);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
285 guint32_get(b, &code);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
286 guint32_get(b, &count);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
287
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
288 if(mwGetBuffer_error(b)) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
289 g_warning("error parsing search result");
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
290 mwGetBuffer_free(b);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
291 return;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
292 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
293
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
294 search = g_hash_table_lookup(srvc->searches, GUINT_TO_POINTER(id));
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
295
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
296 if(search) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
297 GList *results = load_results(b, count);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
298 if(mwGetBuffer_error(b)) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
299 g_warning("error parsing search results");
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
300 } else {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
301 g_debug("triggering handler");
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
302 search->handler(srvc, id, code, results, search->data);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
303 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
304 free_results(results);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
305 g_hash_table_remove(srvc->searches, GUINT_TO_POINTER(id));
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
306
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
307 } else {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
308 g_debug("no search found: 0x%x", id);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
309 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
310
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
311 mwGetBuffer_free(b);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
312 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
313
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
314
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
315 struct mwServiceResolve *mwServiceResolve_new(struct mwSession *session) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
316 struct mwServiceResolve *srvc_resolve;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
317 struct mwService *srvc;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
318
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
319 g_return_val_if_fail(session != NULL, NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
320
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
321 srvc_resolve = g_new0(struct mwServiceResolve, 1);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
322
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
323 srvc = MW_SERVICE(srvc_resolve);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
324
11943
0110fc7c6a8a [gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents: 10969
diff changeset
325 mwService_init(srvc, session, mwService_RESOLVE);
10969
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
326 srvc->get_name = get_name;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
327 srvc->get_desc = get_desc;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
328 srvc->recv_create = (mwService_funcRecvCreate) recv_create;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
329 srvc->recv_accept = (mwService_funcRecvAccept) recv_accept;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
330 srvc->recv_destroy = (mwService_funcRecvDestroy) recv_destroy;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
331 srvc->recv = (mwService_funcRecv) recv;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
332 srvc->start = (mwService_funcStart) start;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
333 srvc->stop = (mwService_funcStop) stop;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
334 srvc->clear = (mwService_funcClear) clear;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
335
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
336 return srvc_resolve;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
337 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
338
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
339
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
340 guint32 mwServiceResolve_resolve(struct mwServiceResolve *srvc,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
341 GList *queries, enum mwResolveFlag flags,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
342 mwResolveHandler handler,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
343 gpointer data, GDestroyNotify cleanup) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
344
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
345 struct mw_search *search;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
346 struct mwPutBuffer *b;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
347 struct mwOpaque o = { 0, 0 };
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
348 int ret, count = 0;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
349
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
350 g_return_val_if_fail(srvc != NULL, SEARCH_ERROR);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
351 g_return_val_if_fail(handler != NULL, SEARCH_ERROR);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
352
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
353 count = g_list_length(queries);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
354 g_return_val_if_fail(count > 0, SEARCH_ERROR);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
355
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
356 search = search_new(srvc, handler, data, cleanup);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
357
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
358 b = mwPutBuffer_new();
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
359 guint32_put(b, 0x00); /* to be overwritten */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
360 guint32_put(b, search->id);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
361 guint32_put(b, count);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
362 for(; queries; queries = queries->next)
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
363 mwString_put(b, queries->data);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
364 guint32_put(b, flags);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
365
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
366 mwPutBuffer_finalize(&o, b);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
367
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
368 ret = mwChannel_send(srvc->channel, RESOLVE_ACTION, &o);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
369 if(ret) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
370 search_free(search);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
371 return SEARCH_ERROR;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
372
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
373 } else {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
374 g_hash_table_insert(srvc->searches,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
375 GUINT_TO_POINTER(search->id), search);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
376 return search->id;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
377 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
378 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
379
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
380
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
381 void mwServiceResolve_cancelResolve(struct mwServiceResolve *srvc,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
382 guint32 id) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
383
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
384 g_return_if_fail(srvc != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
385 g_return_if_fail(srvc->searches != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
386
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
387 g_hash_table_remove(srvc->searches, GUINT_TO_POINTER(id));
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
388 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
389