annotate src/protocols/sametime/meanwhile/srvc_store.c @ 12311:a2ebf585d8c6

[gaim-migrate @ 14615] should work fine, but I have to go home now. This ought to clean up all the signedness warnings, start to remove some unnecessary features (server-stored status messages), and add a useful feature (pretending to be an official client when the server is blocking unofficial clients) committer: Tailor Script <tailor@pidgin.im>
author Christopher O'Brien <siege@pidgin.im>
date Sun, 04 Dec 2005 04:09:30 +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/glist.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_debug.h"
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
25 #include "mw_error.h"
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
26 #include "mw_message.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_store.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 0x00000025
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
33 #define PROTOCOL_VER 0x00000001
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 enum storage_action {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
37 action_load = 0x0004,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
38 action_loaded = 0x0005,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
39 action_save = 0x0006,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
40 action_saved = 0x0007,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
41 };
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
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
44 struct mwStorageUnit {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
45 /** key by which data is referenced in service
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
46 @see mwStorageKey */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
47 guint32 key;
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 /** Data associated with key in service */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
50 struct mwOpaque data;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
51 };
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
52
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
53
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
54 struct mwStorageReq {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
55 guint32 id; /**< unique id for this request */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
56 guint32 result_code; /**< result code for completed request */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
57 enum storage_action action; /**< load or save */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
58 struct mwStorageUnit *item; /**< the key/data pair */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
59 mwStorageCallback cb; /**< callback to notify upon completion */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
60 gpointer data; /**< user data to pass with callback */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
61 GDestroyNotify data_free; /**< optionally frees user data */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
62 };
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
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
65 struct mwServiceStorage {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
66 struct mwService service;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
67
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
68 /** collection of mwStorageReq */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
69 GList *pending;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
70
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
71 /** current service channel */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
72 struct mwChannel *channel;
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 /** keep track of the counter */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
75 guint32 id_counter;
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
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 static void request_get(struct mwGetBuffer *b, struct mwStorageReq *req) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
80 guint32 id, count, junk;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
81
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
82 if(mwGetBuffer_error(b)) return;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
83
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
84 guint32_get(b, &id);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
85 guint32_get(b, &req->result_code);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
86
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
87 if(req->action == action_loaded) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
88 guint32_get(b, &count);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
89
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
90 if(count > 0) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
91 guint32_get(b, &junk);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
92 guint32_get(b, &req->item->key);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
93
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
94 mwOpaque_clear(&req->item->data);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
95 mwOpaque_get(b, &req->item->data);
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 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
99
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 static void request_put(struct mwPutBuffer *b, struct mwStorageReq *req) {
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 guint32_put(b, req->id);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
104 guint32_put(b, 1);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
105
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
106 if(req->action == action_save) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
107 guint32_put(b, 20 + req->item->data.len); /* ugh, offset garbage */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
108 guint32_put(b, req->item->key);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
109 mwOpaque_put(b, &req->item->data);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
110
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
111 } else {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
112 guint32_put(b, req->item->key);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
113 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
114 }
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
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
117 static int request_send(struct mwChannel *chan, struct mwStorageReq *req) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
118 struct mwPutBuffer *b;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
119 struct mwOpaque o = { 0, 0 };
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
120 int ret;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
121
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
122 b = mwPutBuffer_new();
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
123 request_put(b, req);
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 mwPutBuffer_finalize(&o, b);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
126 ret = mwChannel_send(chan, req->action, &o);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
127 mwOpaque_clear(&o);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
128
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
129 if(! ret) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
130 if(req->action == action_save) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
131 req->action = action_saved;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
132 } else if(req->action == action_load) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
133 req->action = action_loaded;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
134 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
135 }
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 return ret;
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
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
140
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
141 static struct mwStorageReq *request_find(struct mwServiceStorage *srvc,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
142 guint32 id) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
143 GList *l;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
144
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
145 for(l = srvc->pending; l; l = l->next) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
146 struct mwStorageReq *r = l->data;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
147 if(r->id == id) return r;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
148 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
149
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
150 return NULL;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
151 }
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 static const char *action_str(enum storage_action act) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
155 switch(act) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
156 case action_load: return "load";
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
157 case action_loaded: return "loaded";
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
158 case action_save: return "save";
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
159 case action_saved: return "saved";
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
160 default: return "UNKNOWN";
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
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
164
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
165 static void request_trigger(struct mwServiceStorage *srvc,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
166 struct mwStorageReq *req) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
167
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
168 struct mwStorageUnit *item = req->item;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
169
11943
0110fc7c6a8a [gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents: 11588
diff changeset
170 g_message("storage request %s: key = 0x%x, result = 0x%x, length = %u",
10969
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
171 action_str(req->action),
11943
0110fc7c6a8a [gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents: 11588
diff changeset
172 item->key, req->result_code, (guint) item->data.len);
10969
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
173
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
174 if(req->cb)
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
175 req->cb(srvc, req->result_code, item, req->data);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
176 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
177
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
178
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
179 static void request_free(struct mwStorageReq *req) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
180 if(req->data_free) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
181 req->data_free(req->data);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
182 req->data = NULL;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
183 req->data_free = NULL;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
184 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
185
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
186 mwStorageUnit_free(req->item);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
187 g_free(req);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
188 }
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
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
191 static void request_remove(struct mwServiceStorage *srvc,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
192 struct mwStorageReq *req) {
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->pending = g_list_remove_all(srvc->pending, req);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
195 request_free(req);
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
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
198
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
199 static const char *get_name(struct mwService *srvc) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
200 return "User Storage";
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 const char *get_desc(struct mwService *srvc) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
205 return "Stores user data and settings on the server";
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
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
208
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
209 static struct mwChannel *make_channel(struct mwServiceStorage *srvc) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
210 struct mwSession *session;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
211 struct mwChannelSet *cs;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
212 struct mwChannel *chan;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
213
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
214 session = mwService_getSession(MW_SERVICE(srvc));
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
215 cs = mwSession_getChannels(session);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
216 chan = mwChannel_newOutgoing(cs);
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 mwChannel_setService(chan, MW_SERVICE(srvc));
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
219 mwChannel_setProtoType(chan, PROTOCOL_TYPE);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
220 mwChannel_setProtoVer(chan, PROTOCOL_VER);
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 return mwChannel_create(chan)? NULL: chan;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
223 }
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
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
226 static void start(struct mwService *srvc) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
227 struct mwServiceStorage *srvc_store;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
228 struct mwChannel *chan;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
229
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
230 g_return_if_fail(srvc != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
231 srvc_store = (struct mwServiceStorage *) srvc;
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 chan = make_channel(srvc_store);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
234 if(chan) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
235 srvc_store->channel = chan;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
236 } else {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
237 mwService_stopped(srvc);
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 }
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 static void stop(struct mwService *srvc) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
243
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
244 struct mwServiceStorage *srvc_store;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
245 GList *l;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
246
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
247 g_return_if_fail(srvc != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
248 srvc_store = (struct mwServiceStorage *) srvc;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
249
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
250 if(srvc_store->channel) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
251 mwChannel_destroy(srvc_store->channel, ERR_SUCCESS, NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
252 srvc_store->channel = NULL;
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
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
255 #if 1
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
256 /* the new way */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
257 /* remove pending requests. Sometimes we can crash the storage
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
258 service, and when that happens, we end up resending the killer
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
259 request over and over again, and the service never stays up */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
260 for(l = srvc_store->pending; l; l = l->next)
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
261 request_free(l->data);
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 g_list_free(srvc_store->pending);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
264 srvc_store->pending = NULL;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
265
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
266 srvc_store->id_counter = 0;
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 #else
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
269 /* the old way */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
270 /* reset all of the started requests to their unstarted states */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
271 for(l = srvc_store->pending; l; l = l->next) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
272 struct mwStorageReq *req = l->data;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
273
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
274 if(req->action == action_loaded) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
275 req->action = action_load;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
276 } else if(req->action == action_saved) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
277 req->action = action_save;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
278 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
279 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
280 #endif
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 mwService_stopped(srvc);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
283 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
284
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
285
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
286 static void recv_channelAccept(struct mwService *srvc,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
287 struct mwChannel *chan,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
288 struct mwMsgChannelAccept *msg) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
289
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
290 struct mwServiceStorage *srvc_stor;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
291 GList *l;
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 g_return_if_fail(srvc != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
294 srvc_stor = (struct mwServiceStorage *) srvc;
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 g_return_if_fail(chan != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
297 g_return_if_fail(chan == srvc_stor->channel);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
298
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
299 /* send all pending requests */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
300 for(l = srvc_stor->pending; l; l = l->next) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
301 struct mwStorageReq *req = l->data;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
302
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
303 if(req->action == action_save || req->action == action_load) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
304 request_send(chan, req);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
305 }
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
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
308 mwService_started(srvc);
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
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
312 static void recv_channelDestroy(struct mwService *srvc,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
313 struct mwChannel *chan,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
314 struct mwMsgChannelDestroy *msg) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
315
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
316 struct mwSession *session;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
317 struct mwServiceStorage *srvc_stor;
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_if_fail(srvc != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
320 g_return_if_fail(chan != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
321
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
322 session = mwService_getSession(srvc);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
323 g_return_if_fail(session != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
324
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
325 srvc_stor = (struct mwServiceStorage *) srvc;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
326 srvc_stor->channel = NULL;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
327
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
328 mwService_stop(srvc);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
329 mwSession_senseService(session, mwService_getType(srvc));
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
330 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
331
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
332
11943
0110fc7c6a8a [gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents: 11588
diff changeset
333 static void recv(struct mwService *srvc, struct mwChannel *chan,
10969
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
334 guint16 type, struct mwOpaque *data) {
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 /* process into results, trigger callbacks */
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 struct mwGetBuffer *b;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
339 struct mwServiceStorage *srvc_stor;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
340 struct mwStorageReq *req;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
341 guint32 id;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
342
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
343 g_return_if_fail(srvc != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
344 srvc_stor = (struct mwServiceStorage *) srvc;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
345
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
346 g_return_if_fail(chan != NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
347 g_return_if_fail(chan == srvc_stor->channel);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
348 g_return_if_fail(data != NULL);
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 b = mwGetBuffer_wrap(data);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
351
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
352 id = guint32_peek(b);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
353 req = request_find(srvc_stor, id);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
354
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
355 if(! req) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
356 g_warning("couldn't find request 0x%x in storage service", id);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
357 mwGetBuffer_free(b);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
358 return;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
359 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
360
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
361 g_return_if_fail(req->action == type);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
362 request_get(b, req);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
363
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
364 if(mwGetBuffer_error(b)) {
11943
0110fc7c6a8a [gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents: 11588
diff changeset
365 mw_mailme_opaque(data, "storage request 0x%x, type: 0x%x", id, type);
10969
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
366
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
367 } else {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
368 request_trigger(srvc_stor, req);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
369 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
370
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
371 mwGetBuffer_free(b);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
372 request_remove(srvc_stor, req);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
373 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
374
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
375
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
376 static void clear(struct mwService *srvc) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
377 struct mwServiceStorage *srvc_stor;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
378 GList *l;
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 srvc_stor = (struct mwServiceStorage *) srvc;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
381
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
382 for(l = srvc_stor->pending; l; l = l->next)
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
383 request_free(l->data);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
384
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
385 g_list_free(srvc_stor->pending);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
386 srvc_stor->pending = NULL;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
387
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
388 srvc_stor->id_counter = 0;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
389 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
390
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
391
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
392 struct mwServiceStorage *mwServiceStorage_new(struct mwSession *session) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
393 struct mwServiceStorage *srvc_store;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
394 struct mwService *srvc;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
395
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
396 srvc_store = g_new0(struct mwServiceStorage, 1);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
397 srvc = MW_SERVICE(srvc_store);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
398
11943
0110fc7c6a8a [gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents: 11588
diff changeset
399 mwService_init(srvc, session, mwService_STORAGE);
10969
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
400 srvc->get_name = get_name;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
401 srvc->get_desc = get_desc;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
402 srvc->recv_accept = recv_channelAccept;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
403 srvc->recv_destroy = recv_channelDestroy;
11943
0110fc7c6a8a [gaim-migrate @ 14234]
Christopher O'Brien <siege@pidgin.im>
parents: 11588
diff changeset
404 srvc->recv = recv;
10969
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
405 srvc->start = start;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
406 srvc->stop = stop;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
407 srvc->clear = clear;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
408
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
409 return srvc_store;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
410 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
411
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
412
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
413 struct mwStorageUnit *mwStorageUnit_new(guint32 key) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
414 struct mwStorageUnit *u;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
415
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
416 u = g_new0(struct mwStorageUnit, 1);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
417 u->key = key;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
418
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
419 return u;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
420 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
421
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
422
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
423 struct mwStorageUnit *mwStorageUnit_newOpaque(guint32 key,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
424 struct mwOpaque *data) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
425 struct mwStorageUnit *u;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
426
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
427 u = g_new0(struct mwStorageUnit, 1);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
428 u->key = key;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
429
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
430 if(data)
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
431 mwOpaque_clone(&u->data, data);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
432
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
433 return u;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
434 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
435
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
436
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
437 struct mwStorageUnit *mwStorageUnit_newBoolean(guint32 key,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
438 gboolean val) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
439
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
440 return mwStorageUnit_newInteger(key, (guint32) val);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
441 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
442
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
443
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
444 struct mwStorageUnit *mwStorageUnit_newInteger(guint32 key,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
445 guint32 val) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
446 struct mwStorageUnit *u;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
447 struct mwPutBuffer *b;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
448
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
449 u = g_new0(struct mwStorageUnit, 1);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
450 u->key = key;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
451
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
452 b = mwPutBuffer_new();
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
453 guint32_put(b, val);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
454 mwPutBuffer_finalize(&u->data, b);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
455
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
456 return u;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
457 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
458
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
459
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
460 struct mwStorageUnit *mwStorageUnit_newString(guint32 key,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
461 const char *str) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
462 struct mwStorageUnit *u;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
463 struct mwPutBuffer *b;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
464
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
465 u = g_new0(struct mwStorageUnit, 1);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
466 u->key = key;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
467
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
468 b = mwPutBuffer_new();
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
469 mwString_put(b, str);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
470 mwPutBuffer_finalize(&u->data, b);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
471
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
472 return u;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
473 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
474
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
475
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
476 guint32 mwStorageUnit_getKey(struct mwStorageUnit *item) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
477 g_return_val_if_fail(item != NULL, 0x00); /* feh, unsafe */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
478 return item->key;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
479 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
480
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
481
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
482 gboolean mwStorageUnit_asBoolean(struct mwStorageUnit *item,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
483 gboolean val) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
484
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
485 return !! mwStorageUnit_asInteger(item, (guint32) val);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
486 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
487
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
488
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
489 guint32 mwStorageUnit_asInteger(struct mwStorageUnit *item,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
490 guint32 val) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
491 struct mwGetBuffer *b;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
492 guint32 v;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
493
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
494 g_return_val_if_fail(item != NULL, val);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
495
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
496 b = mwGetBuffer_wrap(&item->data);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
497
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
498 guint32_get(b, &v);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
499 if(! mwGetBuffer_error(b)) val = v;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
500 mwGetBuffer_free(b);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
501
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
502 return val;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
503 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
504
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
505
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
506 char *mwStorageUnit_asString(struct mwStorageUnit *item) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
507 struct mwGetBuffer *b;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
508 char *c = NULL;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
509
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
510 g_return_val_if_fail(item != NULL, NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
511
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
512 b = mwGetBuffer_wrap(&item->data);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
513
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
514 mwString_get(b, &c);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
515
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
516 if(mwGetBuffer_error(b))
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
517 g_debug("error obtaining string value from opaque");
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
518
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
519 mwGetBuffer_free(b);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
520
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
521 return c;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
522 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
523
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
524
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
525 struct mwOpaque *mwStorageUnit_asOpaque(struct mwStorageUnit *item) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
526 g_return_val_if_fail(item != NULL, NULL);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
527 return &item->data;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
528 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
529
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
530
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
531 void mwStorageUnit_free(struct mwStorageUnit *item) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
532 if(! item) return;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
533
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
534 mwOpaque_clear(&item->data);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
535 g_free(item);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
536 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
537
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
538
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
539 static struct mwStorageReq *request_new(struct mwServiceStorage *srvc,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
540 struct mwStorageUnit *item,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
541 mwStorageCallback cb,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
542 gpointer data, GDestroyNotify df) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
543
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
544 struct mwStorageReq *req = g_new0(struct mwStorageReq, 1);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
545
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
546 req->id = ++srvc->id_counter;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
547 req->item = item;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
548 req->cb = cb;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
549 req->data = data;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
550 req->data_free = df;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
551
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
552 return req;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
553 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
554
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
555
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
556 void mwServiceStorage_load(struct mwServiceStorage *srvc,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
557 struct mwStorageUnit *item,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
558 mwStorageCallback cb,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
559 gpointer data, GDestroyNotify d_free) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
560
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
561 /* - construct a request
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
562 - put request at end of pending
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
563 - if channel is open and connected
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
564 - compose the load message
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
565 - send message
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
566 - set request to sent
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
567 - else
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
568 - start service
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
569 */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
570
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
571 struct mwStorageReq *req;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
572
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
573 req = request_new(srvc, item, cb, data, d_free);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
574 req->action = action_load;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
575
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
576 srvc->pending = g_list_append(srvc->pending, req);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
577
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
578 if(MW_SERVICE_IS_STARTED(MW_SERVICE(srvc)))
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
579 request_send(srvc->channel, req);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
580 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
581
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
582
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
583 void mwServiceStorage_save(struct mwServiceStorage *srvc,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
584 struct mwStorageUnit *item,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
585 mwStorageCallback cb,
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
586 gpointer data, GDestroyNotify d_free) {
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
587
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
588 /* - construct a request
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
589 - put request at end of pending
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
590 - if channel is open and connected
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
591 - compose the save message
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
592 - send message
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
593 - set request to sent
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
594 - else
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
595 - start service
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
596 */
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
597
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
598 struct mwStorageReq *req;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
599
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
600 req = request_new(srvc, item, cb, data, d_free);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
601 req->action = action_save;
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
602
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
603 srvc->pending = g_list_append(srvc->pending, req);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
604
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
605 if(MW_SERVICE_IS_STARTED(MW_SERVICE(srvc)))
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
606 request_send(srvc->channel, req);
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
607 }
3ef77720e577 [gaim-migrate @ 12790]
Christopher O'Brien <siege@pidgin.im>
parents:
diff changeset
608