Mercurial > pidgin
comparison src/protocols/yahoo/yahoo.c @ 10392:a8f9e5ce4f92
[gaim-migrate @ 11620]
a little bit of clean up and reorganization of the yahoo prpl.
I moved the packet functions to their own file, renamed a couple of them,
added a convience function and used it a lot. I plan on adding several
more convience functions.
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Thu, 16 Dec 2004 21:47:54 +0000 |
parents | 232808c6d6ab |
children | 45a0a07e8b25 |
comparison
equal
deleted
inserted
replaced
10391:38256d3e8324 | 10392:a8f9e5ce4f92 |
---|---|
37 #include "util.h" | 37 #include "util.h" |
38 #include "version.h" | 38 #include "version.h" |
39 | 39 |
40 #include "sha.h" | 40 #include "sha.h" |
41 #include "yahoo.h" | 41 #include "yahoo.h" |
42 #include "yahoo_packet.h" | |
42 #include "yahoo_friend.h" | 43 #include "yahoo_friend.h" |
43 #include "yahoochat.h" | 44 #include "yahoochat.h" |
44 #include "ycht.h" | 45 #include "ycht.h" |
45 #include "yahoo_auth.h" | 46 #include "yahoo_auth.h" |
46 #include "yahoo_filexfer.h" | 47 #include "yahoo_filexfer.h" |
52 /* #define YAHOO_DEBUG */ | 53 /* #define YAHOO_DEBUG */ |
53 | 54 |
54 static void yahoo_add_buddy(GaimConnection *gc, GaimBuddy *, GaimGroup *); | 55 static void yahoo_add_buddy(GaimConnection *gc, GaimBuddy *, GaimGroup *); |
55 static void yahoo_login_page_cb(void *user_data, const char *buf, size_t len); | 56 static void yahoo_login_page_cb(void *user_data, const char *buf, size_t len); |
56 | 57 |
57 | |
58 struct yahoo_packet *yahoo_packet_new(enum yahoo_service service, enum yahoo_status status, int id) | |
59 { | |
60 struct yahoo_packet *pkt = g_new0(struct yahoo_packet, 1); | |
61 | |
62 pkt->service = service; | |
63 pkt->status = status; | |
64 pkt->id = id; | |
65 | |
66 return pkt; | |
67 } | |
68 | |
69 void yahoo_packet_hash(struct yahoo_packet *pkt, int key, const char *value) | |
70 { | |
71 struct yahoo_pair *pair = g_new0(struct yahoo_pair, 1); | |
72 pair->key = key; | |
73 pair->value = g_strdup(value); | |
74 pkt->hash = g_slist_append(pkt->hash, pair); | |
75 } | |
76 | |
77 int yahoo_packet_length(struct yahoo_packet *pkt) | |
78 { | |
79 GSList *l; | |
80 | |
81 int len = 0; | |
82 | |
83 l = pkt->hash; | |
84 while (l) { | |
85 struct yahoo_pair *pair = l->data; | |
86 int tmp = pair->key; | |
87 do { | |
88 tmp /= 10; | |
89 len++; | |
90 } while (tmp); | |
91 len += 2; | |
92 len += strlen(pair->value); | |
93 len += 2; | |
94 l = l->next; | |
95 } | |
96 | |
97 return len; | |
98 } | |
99 | |
100 static void yahoo_packet_read(struct yahoo_packet *pkt, guchar *data, int len) | |
101 { | |
102 int pos = 0; | |
103 | |
104 while (pos + 1 < len) { | |
105 char key[64], *value = NULL, *esc; | |
106 int accept; | |
107 int x; | |
108 | |
109 struct yahoo_pair *pair = g_new0(struct yahoo_pair, 1); | |
110 | |
111 /* this is weird, and in one of the chat packets, and causes us | |
112 * think all the values are keys and all the keys are values after | |
113 * this point if we don't handle it */ | |
114 if (data[pos] == '\0') { | |
115 while (pos + 1 < len) { | |
116 if (data[pos] == 0xc0 && data[pos + 1] == 0x80) | |
117 break; | |
118 pos++; | |
119 } | |
120 pos += 2; | |
121 g_free(pair); | |
122 continue; | |
123 } | |
124 | |
125 x = 0; | |
126 while (pos + 1 < len) { | |
127 if (data[pos] == 0xc0 && data[pos + 1] == 0x80) | |
128 break; | |
129 if (x >= sizeof(key)-1) { | |
130 x++; | |
131 pos++; | |
132 continue; | |
133 } | |
134 key[x++] = data[pos++]; | |
135 } | |
136 if (x >= sizeof(key)-1) { | |
137 x = 0; | |
138 } | |
139 key[x] = 0; | |
140 pos += 2; | |
141 pair->key = strtol(key, NULL, 10); | |
142 accept = x; /* if x is 0 there was no key, so don't accept it */ | |
143 | |
144 if (len - pos + 1 <= 0) { | |
145 /* Truncated. Garbage or something. */ | |
146 accept = 0; | |
147 } | |
148 | |
149 if (accept) { | |
150 value = g_malloc(len - pos + 1); | |
151 x = 0; | |
152 while (pos + 1 < len) { | |
153 if (data[pos] == 0xc0 && data[pos + 1] == 0x80) | |
154 break; | |
155 value[x++] = data[pos++]; | |
156 } | |
157 value[x] = 0; | |
158 pair->value = g_strdup(value); | |
159 g_free(value); | |
160 pkt->hash = g_slist_append(pkt->hash, pair); | |
161 esc = g_strescape(pair->value, NULL); | |
162 gaim_debug(GAIM_DEBUG_MISC, "yahoo", | |
163 "Key: %d \tValue: %s\n", pair->key, esc); | |
164 g_free(esc); | |
165 } else { | |
166 g_free(pair); | |
167 } | |
168 pos += 2; | |
169 | |
170 /* Skip over garbage we've noticed in the mail notifications */ | |
171 if (data[0] == '9' && data[pos] == 0x01) | |
172 pos++; | |
173 } | |
174 } | |
175 | |
176 void yahoo_packet_write(struct yahoo_packet *pkt, guchar *data) | |
177 { | |
178 GSList *l = pkt->hash; | |
179 int pos = 0; | |
180 | |
181 while (l) { | |
182 struct yahoo_pair *pair = l->data; | |
183 guchar buf[100]; | |
184 | |
185 g_snprintf(buf, sizeof(buf), "%d", pair->key); | |
186 strcpy(data + pos, buf); | |
187 pos += strlen(buf); | |
188 data[pos++] = 0xc0; | |
189 data[pos++] = 0x80; | |
190 | |
191 strcpy(data + pos, pair->value); | |
192 pos += strlen(pair->value); | |
193 data[pos++] = 0xc0; | |
194 data[pos++] = 0x80; | |
195 | |
196 l = l->next; | |
197 } | |
198 } | |
199 | |
200 static void yahoo_packet_dump(guchar *data, int len) | |
201 { | |
202 #ifdef YAHOO_DEBUG | |
203 int i; | |
204 | |
205 gaim_debug(GAIM_DEBUG_MISC, "yahoo", ""); | |
206 | |
207 for (i = 0; i + 1 < len; i += 2) { | |
208 if ((i % 16 == 0) && i) { | |
209 gaim_debug(GAIM_DEBUG_MISC, NULL, "\n"); | |
210 gaim_debug(GAIM_DEBUG_MISC, "yahoo", ""); | |
211 } | |
212 | |
213 gaim_debug(GAIM_DEBUG_MISC, NULL, "%02x%02x ", data[i], data[i + 1]); | |
214 } | |
215 if (i < len) | |
216 gaim_debug(GAIM_DEBUG_MISC, NULL, "%02x", data[i]); | |
217 | |
218 gaim_debug(GAIM_DEBUG_MISC, NULL, "\n"); | |
219 gaim_debug(GAIM_DEBUG_MISC, "yahoo", ""); | |
220 | |
221 for (i = 0; i < len; i++) { | |
222 if ((i % 16 == 0) && i) { | |
223 gaim_debug(GAIM_DEBUG_MISC, NULL, "\n"); | |
224 gaim_debug(GAIM_DEBUG_MISC, "yahoo", ""); | |
225 } | |
226 | |
227 if (g_ascii_isprint(data[i])) | |
228 gaim_debug(GAIM_DEBUG_MISC, NULL, "%c ", data[i]); | |
229 else | |
230 gaim_debug(GAIM_DEBUG_MISC, NULL, ". "); | |
231 } | |
232 | |
233 gaim_debug(GAIM_DEBUG_MISC, NULL, "\n"); | |
234 #endif | |
235 } | |
236 | |
237 int yahoo_send_packet(struct yahoo_data *yd, struct yahoo_packet *pkt) | |
238 { | |
239 int pktlen = yahoo_packet_length(pkt); | |
240 int len = YAHOO_PACKET_HDRLEN + pktlen; | |
241 int ret; | |
242 | |
243 guchar *data; | |
244 int pos = 0; | |
245 | |
246 if (yd->fd < 0) | |
247 return -1; | |
248 | |
249 data = g_malloc0(len + 1); | |
250 | |
251 memcpy(data + pos, "YMSG", 4); pos += 4; | |
252 | |
253 if (yd->wm) | |
254 pos += yahoo_put16(data + pos, YAHOO_WEBMESSENGER_PROTO_VER); | |
255 else | |
256 pos += yahoo_put16(data + pos, YAHOO_PROTO_VER); | |
257 | |
258 pos += yahoo_put16(data + pos, 0x0000); | |
259 pos += yahoo_put16(data + pos, pktlen); | |
260 pos += yahoo_put16(data + pos, pkt->service); | |
261 pos += yahoo_put32(data + pos, pkt->status); | |
262 pos += yahoo_put32(data + pos, pkt->id); | |
263 | |
264 yahoo_packet_write(pkt, data + pos); | |
265 | |
266 yahoo_packet_dump(data, len); | |
267 ret = write(yd->fd, data, len); | |
268 if (ret != len) | |
269 gaim_debug_warning("yahoo", "Only wrote %d of %d bytes!", ret, len); | |
270 g_free(data); | |
271 | |
272 return ret; | |
273 } | |
274 | |
275 int yahoo_send_packet_special(int fd, struct yahoo_packet *pkt, int pad) | |
276 { | |
277 int pktlen = yahoo_packet_length(pkt); | |
278 int len = YAHOO_PACKET_HDRLEN + pktlen; | |
279 int ret; | |
280 | |
281 guchar *data; | |
282 int pos = 0; | |
283 | |
284 if (fd < 0) | |
285 return -1; | |
286 | |
287 data = g_malloc0(len + 1); | |
288 | |
289 memcpy(data + pos, "YMSG", 4); pos += 4; | |
290 | |
291 pos += yahoo_put16(data + pos, YAHOO_PROTO_VER); | |
292 | |
293 pos += yahoo_put16(data + pos, 0x0000); | |
294 pos += yahoo_put16(data + pos, pktlen + pad); | |
295 pos += yahoo_put16(data + pos, pkt->service); | |
296 pos += yahoo_put32(data + pos, pkt->status); | |
297 pos += yahoo_put32(data + pos, pkt->id); | |
298 | |
299 yahoo_packet_write(pkt, data + pos); | |
300 | |
301 ret = write(fd, data, len); | |
302 g_free(data); | |
303 | |
304 return ret; | |
305 } | |
306 | |
307 void yahoo_packet_free(struct yahoo_packet *pkt) | |
308 { | |
309 while (pkt->hash) { | |
310 struct yahoo_pair *pair = pkt->hash->data; | |
311 g_free(pair->value); | |
312 g_free(pair); | |
313 pkt->hash = g_slist_remove(pkt->hash, pair); | |
314 } | |
315 g_free(pkt); | |
316 } | |
317 | 58 |
318 static void yahoo_update_status(GaimConnection *gc, const char *name, YahooFriend *f) | 59 static void yahoo_update_status(GaimConnection *gc, const char *name, YahooFriend *f) |
319 { | 60 { |
320 gboolean online = TRUE; | 61 gboolean online = TRUE; |
321 char *status = NULL; | 62 char *status = NULL; |
423 * scs.yahoo.com sends you the list before this packet without it being | 164 * scs.yahoo.com sends you the list before this packet without it being |
424 * requested | 165 * requested |
425 * | 166 * |
426 * do_import(gc, NULL); | 167 * do_import(gc, NULL); |
427 * newpkt = yahoo_packet_new(YAHOO_SERVICE_LIST, YAHOO_STATUS_OFFLINE, 0); | 168 * newpkt = yahoo_packet_new(YAHOO_SERVICE_LIST, YAHOO_STATUS_OFFLINE, 0); |
428 * yahoo_send_packet(yd, newpkt); | 169 * yahoo_packet_send_and_free(newpkt, yd); |
429 * yahoo_packet_free(newpkt); | |
430 */ | 170 */ |
431 | 171 |
432 } | 172 } |
433 break; | 173 break; |
434 case 8: /* how many online buddies we have */ | 174 case 8: /* how many online buddies we have */ |
1278 yahoo_packet_hash(pack, 0, name); | 1018 yahoo_packet_hash(pack, 0, name); |
1279 yahoo_packet_hash(pack, 6, result6); | 1019 yahoo_packet_hash(pack, 6, result6); |
1280 yahoo_packet_hash(pack, 96, result96); | 1020 yahoo_packet_hash(pack, 96, result96); |
1281 yahoo_packet_hash(pack, 1, name); | 1021 yahoo_packet_hash(pack, 1, name); |
1282 | 1022 |
1283 yahoo_send_packet(yd, pack); | 1023 yahoo_packet_send_and_free(pack, yd); |
1284 | 1024 |
1285 g_free(hash_string_p); | 1025 g_free(hash_string_p); |
1286 g_free(hash_string_c); | 1026 g_free(hash_string_c); |
1287 | |
1288 yahoo_packet_free(pack); | |
1289 | |
1290 } | 1027 } |
1291 | 1028 |
1292 /* I'm dishing out some uber-mad props to Cerulean Studios for cracking this | 1029 /* I'm dishing out some uber-mad props to Cerulean Studios for cracking this |
1293 * and sending the fix! Thanks guys. */ | 1030 * and sending the fix! Thanks guys. */ |
1294 | 1031 |
1741 if (yd->picture_checksum) { | 1478 if (yd->picture_checksum) { |
1742 char *cksum = g_strdup_printf("%d", yd->picture_checksum); | 1479 char *cksum = g_strdup_printf("%d", yd->picture_checksum); |
1743 yahoo_packet_hash(pack, 192, cksum); | 1480 yahoo_packet_hash(pack, 192, cksum); |
1744 g_free(cksum); | 1481 g_free(cksum); |
1745 } | 1482 } |
1746 yahoo_send_packet(yd, pack); | 1483 yahoo_packet_send_and_free(pack, yd); |
1747 yahoo_packet_free(pack); | |
1748 | 1484 |
1749 g_free(password_hash); | 1485 g_free(password_hash); |
1750 g_free(crypt_hash); | 1486 g_free(crypt_hash); |
1751 } | 1487 } |
1752 | 1488 |
2285 yd->fd = source; | 2021 yd->fd = source; |
2286 | 2022 |
2287 pkt = yahoo_packet_new(YAHOO_SERVICE_AUTH, YAHOO_STATUS_AVAILABLE, 0); | 2023 pkt = yahoo_packet_new(YAHOO_SERVICE_AUTH, YAHOO_STATUS_AVAILABLE, 0); |
2288 | 2024 |
2289 yahoo_packet_hash(pkt, 1, gaim_normalize(gc->account, gaim_account_get_username(gaim_connection_get_account(gc)))); | 2025 yahoo_packet_hash(pkt, 1, gaim_normalize(gc->account, gaim_account_get_username(gaim_connection_get_account(gc)))); |
2290 yahoo_send_packet(yd, pkt); | 2026 yahoo_packet_send_and_free(pkt, yd); |
2291 | |
2292 yahoo_packet_free(pkt); | |
2293 | 2027 |
2294 gc->inpa = gaim_input_add(yd->fd, GAIM_INPUT_READ, yahoo_pending, gc); | 2028 gc->inpa = gaim_input_add(yd->fd, GAIM_INPUT_READ, yahoo_pending, gc); |
2295 } | 2029 } |
2296 | 2030 |
2297 static void yahoo_got_web_connected(gpointer data, gint source, GaimInputCondition cond) | 2031 static void yahoo_got_web_connected(gpointer data, gint source, GaimInputCondition cond) |
2316 pkt = yahoo_packet_new(YAHOO_SERVICE_WEBLOGIN, YAHOO_STATUS_WEBLOGIN, 0); | 2050 pkt = yahoo_packet_new(YAHOO_SERVICE_WEBLOGIN, YAHOO_STATUS_WEBLOGIN, 0); |
2317 | 2051 |
2318 yahoo_packet_hash(pkt, 0, gaim_normalize(gc->account, gaim_account_get_username(gaim_connection_get_account(gc)))); | 2052 yahoo_packet_hash(pkt, 0, gaim_normalize(gc->account, gaim_account_get_username(gaim_connection_get_account(gc)))); |
2319 yahoo_packet_hash(pkt, 1, gaim_normalize(gc->account, gaim_account_get_username(gaim_connection_get_account(gc)))); | 2053 yahoo_packet_hash(pkt, 1, gaim_normalize(gc->account, gaim_account_get_username(gaim_connection_get_account(gc)))); |
2320 yahoo_packet_hash(pkt, 6, yd->auth); | 2054 yahoo_packet_hash(pkt, 6, yd->auth); |
2321 yahoo_send_packet(yd, pkt); | 2055 yahoo_packet_send_and_free(pkt, yd); |
2322 | 2056 |
2323 yahoo_packet_free(pkt); | |
2324 g_free(yd->auth); | 2057 g_free(yd->auth); |
2325 gc->inpa = gaim_input_add(yd->fd, GAIM_INPUT_READ, yahoo_pending, gc); | 2058 gc->inpa = gaim_input_add(yd->fd, GAIM_INPUT_READ, yahoo_pending, gc); |
2326 } | 2059 } |
2327 | 2060 |
2328 static void yahoo_web_pending(gpointer data, gint source, GaimInputCondition cond) | 2061 static void yahoo_web_pending(gpointer data, gint source, GaimInputCondition cond) |
2876 { | 2609 { |
2877 struct yahoo_data *yd = gc->proto_data; | 2610 struct yahoo_data *yd = gc->proto_data; |
2878 | 2611 |
2879 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_IDACT, YAHOO_STATUS_AVAILABLE, 0); | 2612 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_IDACT, YAHOO_STATUS_AVAILABLE, 0); |
2880 yahoo_packet_hash(pkt, 3, entry); | 2613 yahoo_packet_hash(pkt, 3, entry); |
2881 yahoo_send_packet(yd, pkt); | 2614 yahoo_packet_send_and_free(pkt, yd); |
2882 yahoo_packet_free(pkt); | |
2883 | 2615 |
2884 gaim_connection_set_display_name(gc, entry); | 2616 gaim_connection_set_display_name(gc, entry); |
2885 } | 2617 } |
2886 | 2618 |
2887 static void yahoo_show_act_id(GaimPluginAction *action) | 2619 static void yahoo_show_act_id(GaimPluginAction *action) |
2942 else | 2674 else |
2943 yahoo_packet_hash(pkt, 206, "2"); | 2675 yahoo_packet_hash(pkt, 206, "2"); |
2944 | 2676 |
2945 /* We may need to not send any packets over 2000 bytes, but I'm not sure yet. */ | 2677 /* We may need to not send any packets over 2000 bytes, but I'm not sure yet. */ |
2946 if ((YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt)) <= 2000) | 2678 if ((YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt)) <= 2000) |
2947 yahoo_send_packet(yd, pkt); | 2679 yahoo_packet_send(pkt, yd); |
2948 else | 2680 else |
2949 ret = -E2BIG; | 2681 ret = -E2BIG; |
2950 | 2682 |
2951 yahoo_packet_free(pkt); | 2683 yahoo_packet_free(pkt); |
2952 | 2684 |
2965 yahoo_packet_hash(pkt, 14, " "); | 2697 yahoo_packet_hash(pkt, 14, " "); |
2966 yahoo_packet_hash(pkt, 13, typ == GAIM_TYPING ? "1" : "0"); | 2698 yahoo_packet_hash(pkt, 13, typ == GAIM_TYPING ? "1" : "0"); |
2967 yahoo_packet_hash(pkt, 5, who); | 2699 yahoo_packet_hash(pkt, 5, who); |
2968 yahoo_packet_hash(pkt, 1002, "1"); | 2700 yahoo_packet_hash(pkt, 1002, "1"); |
2969 | 2701 |
2970 yahoo_send_packet(yd, pkt); | 2702 yahoo_packet_send_and_free(pkt, yd); |
2971 | |
2972 yahoo_packet_free(pkt); | |
2973 | 2703 |
2974 return 0; | 2704 return 0; |
2975 } | 2705 } |
2976 | 2706 |
2977 static void yahoo_set_status(GaimAccount *account, GaimStatus *status) | 2707 static void yahoo_set_status(GaimAccount *account, GaimStatus *status) |
3021 } | 2751 } |
3022 | 2752 |
3023 if (yd->current_status == YAHOO_STATUS_INVISIBLE) { | 2753 if (yd->current_status == YAHOO_STATUS_INVISIBLE) { |
3024 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, YAHOO_STATUS_AVAILABLE, 0); | 2754 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, YAHOO_STATUS_AVAILABLE, 0); |
3025 yahoo_packet_hash(pkt, 13, "2"); | 2755 yahoo_packet_hash(pkt, 13, "2"); |
3026 yahoo_send_packet(yd, pkt); | 2756 yahoo_packet_send_and_free(pkt, yd); |
3027 yahoo_packet_free(pkt); | |
3028 | 2757 |
3029 return; | 2758 return; |
3030 } | 2759 } |
3031 | 2760 |
3032 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_STATUS_UPDATE, YAHOO_STATUS_AVAILABLE, 0); | 2761 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_STATUS_UPDATE, YAHOO_STATUS_AVAILABLE, 0); |
3052 if (gc->is_idle) | 2781 if (gc->is_idle) |
3053 yahoo_packet_hash(pkt, 47, "2"); | 2782 yahoo_packet_hash(pkt, 47, "2"); |
3054 else if (!gaim_status_type_is_available(gaim_status_get_type(status))) | 2783 else if (!gaim_status_type_is_available(gaim_status_get_type(status))) |
3055 yahoo_packet_hash(pkt, 47, "1"); | 2784 yahoo_packet_hash(pkt, 47, "1"); |
3056 | 2785 |
3057 yahoo_send_packet(yd, pkt); | 2786 yahoo_packet_send_and_free(pkt, yd); |
3058 yahoo_packet_free(pkt); | |
3059 | 2787 |
3060 g_free(conv_msg); | 2788 g_free(conv_msg); |
3061 g_free(conv_msg2); | 2789 g_free(conv_msg2); |
3062 | 2790 |
3063 if (old_status == YAHOO_STATUS_INVISIBLE) { | 2791 if (old_status == YAHOO_STATUS_INVISIBLE) { |
3064 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, YAHOO_STATUS_AVAILABLE, 0); | 2792 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, YAHOO_STATUS_AVAILABLE, 0); |
3065 yahoo_packet_hash(pkt, 13, "1"); | 2793 yahoo_packet_hash(pkt, 13, "1"); |
3066 yahoo_send_packet(yd, pkt); | 2794 yahoo_packet_send_and_free(pkt, yd); |
3067 yahoo_packet_free(pkt); | |
3068 } | 2795 } |
3069 } | 2796 } |
3070 | 2797 |
3071 static void yahoo_set_idle(GaimConnection *gc, int idle) | 2798 static void yahoo_set_idle(GaimConnection *gc, int idle) |
3072 { | 2799 { |
3099 yahoo_packet_hash(pkt, 47, "2"); | 2826 yahoo_packet_hash(pkt, 47, "2"); |
3100 else if (!gaim_presence_is_available(gaim_account_get_presence(gaim_connection_get_account(gc)))) | 2827 else if (!gaim_presence_is_available(gaim_account_get_presence(gaim_connection_get_account(gc)))) |
3101 yahoo_packet_hash(pkt, 47, "1"); | 2828 yahoo_packet_hash(pkt, 47, "1"); |
3102 | 2829 |
3103 | 2830 |
3104 yahoo_send_packet(yd, pkt); | 2831 yahoo_packet_send_and_free(pkt, yd); |
3105 yahoo_packet_free(pkt); | |
3106 | 2832 |
3107 g_free(msg); | 2833 g_free(msg); |
3108 g_free(msg2); | 2834 g_free(msg2); |
3109 } | 2835 } |
3110 | 2836 |
3177 | 2903 |
3178 static void yahoo_keepalive(GaimConnection *gc) | 2904 static void yahoo_keepalive(GaimConnection *gc) |
3179 { | 2905 { |
3180 struct yahoo_data *yd = gc->proto_data; | 2906 struct yahoo_data *yd = gc->proto_data; |
3181 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_PING, YAHOO_STATUS_AVAILABLE, 0); | 2907 struct yahoo_packet *pkt = yahoo_packet_new(YAHOO_SERVICE_PING, YAHOO_STATUS_AVAILABLE, 0); |
3182 yahoo_send_packet(yd, pkt); | 2908 yahoo_packet_send_and_free(pkt, yd); |
3183 yahoo_packet_free(pkt); | |
3184 | 2909 |
3185 if (!yd->chat_online) | 2910 if (!yd->chat_online) |
3186 return; | 2911 return; |
3187 | 2912 |
3188 if (yd->wm) { | 2913 if (yd->wm) { |
3190 return; | 2915 return; |
3191 } | 2916 } |
3192 | 2917 |
3193 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATPING, YAHOO_STATUS_AVAILABLE, 0); | 2918 pkt = yahoo_packet_new(YAHOO_SERVICE_CHATPING, YAHOO_STATUS_AVAILABLE, 0); |
3194 yahoo_packet_hash(pkt, 109, gaim_connection_get_display_name(gc)); | 2919 yahoo_packet_hash(pkt, 109, gaim_connection_get_display_name(gc)); |
3195 yahoo_send_packet(yd, pkt); | 2920 yahoo_packet_send_and_free(yd, pkt); |
3196 yahoo_packet_free(pkt); | |
3197 } | 2921 } |
3198 | 2922 |
3199 /* XXX - What's the deal with GaimGroup *foo? */ | 2923 /* XXX - What's the deal with GaimGroup *foo? */ |
3200 static void yahoo_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *foo) | 2924 static void yahoo_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *foo) |
3201 { | 2925 { |
3222 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0); | 2946 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0); |
3223 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | 2947 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
3224 yahoo_packet_hash(pkt, 7, buddy->name); | 2948 yahoo_packet_hash(pkt, 7, buddy->name); |
3225 yahoo_packet_hash(pkt, 65, group2); | 2949 yahoo_packet_hash(pkt, 65, group2); |
3226 yahoo_packet_hash(pkt, 14, ""); | 2950 yahoo_packet_hash(pkt, 14, ""); |
3227 yahoo_send_packet(yd, pkt); | 2951 yahoo_packet_send_and_free(pkt, yd); |
3228 yahoo_packet_free(pkt); | |
3229 g_free(group2); | 2952 g_free(group2); |
3230 } | 2953 } |
3231 | 2954 |
3232 static void yahoo_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) | 2955 static void yahoo_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) |
3233 { | 2956 { |
3259 cg = yahoo_string_encode(gc, group->name, NULL); | 2982 cg = yahoo_string_encode(gc, group->name, NULL); |
3260 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0); | 2983 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0); |
3261 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | 2984 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
3262 yahoo_packet_hash(pkt, 7, buddy->name); | 2985 yahoo_packet_hash(pkt, 7, buddy->name); |
3263 yahoo_packet_hash(pkt, 65, cg); | 2986 yahoo_packet_hash(pkt, 65, cg); |
3264 yahoo_send_packet(yd, pkt); | 2987 yahoo_packet_send_and_free(pkt, yd); |
3265 yahoo_packet_free(pkt); | |
3266 g_free(cg); | 2988 g_free(cg); |
3267 } | 2989 } |
3268 | 2990 |
3269 static void yahoo_add_deny(GaimConnection *gc, const char *who) { | 2991 static void yahoo_add_deny(GaimConnection *gc, const char *who) { |
3270 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | 2992 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; |
3282 | 3004 |
3283 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, YAHOO_STATUS_AVAILABLE, 0); | 3005 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, YAHOO_STATUS_AVAILABLE, 0); |
3284 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | 3006 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
3285 yahoo_packet_hash(pkt, 7, who); | 3007 yahoo_packet_hash(pkt, 7, who); |
3286 yahoo_packet_hash(pkt, 13, "1"); | 3008 yahoo_packet_hash(pkt, 13, "1"); |
3287 yahoo_send_packet(yd, pkt); | 3009 yahoo_packet_send_and_free(pkt, yd); |
3288 yahoo_packet_free(pkt); | |
3289 } | 3010 } |
3290 | 3011 |
3291 static void yahoo_rem_deny(GaimConnection *gc, const char *who) { | 3012 static void yahoo_rem_deny(GaimConnection *gc, const char *who) { |
3292 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | 3013 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; |
3293 struct yahoo_packet *pkt; | 3014 struct yahoo_packet *pkt; |
3300 | 3021 |
3301 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, YAHOO_STATUS_AVAILABLE, 0); | 3022 pkt = yahoo_packet_new(YAHOO_SERVICE_IGNORECONTACT, YAHOO_STATUS_AVAILABLE, 0); |
3302 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | 3023 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
3303 yahoo_packet_hash(pkt, 7, who); | 3024 yahoo_packet_hash(pkt, 7, who); |
3304 yahoo_packet_hash(pkt, 13, "2"); | 3025 yahoo_packet_hash(pkt, 13, "2"); |
3305 yahoo_send_packet(yd, pkt); | 3026 yahoo_packet_send_and_free(pkt, yd); |
3306 yahoo_packet_free(pkt); | |
3307 } | 3027 } |
3308 | 3028 |
3309 static void yahoo_set_permit_deny(GaimConnection *gc) { | 3029 static void yahoo_set_permit_deny(GaimConnection *gc) { |
3310 GaimAccount *acct; | 3030 GaimAccount *acct; |
3311 GSList *deny; | 3031 GSList *deny; |
3372 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0); | 3092 pkt = yahoo_packet_new(YAHOO_SERVICE_ADDBUDDY, YAHOO_STATUS_AVAILABLE, 0); |
3373 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | 3093 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
3374 yahoo_packet_hash(pkt, 7, who); | 3094 yahoo_packet_hash(pkt, 7, who); |
3375 yahoo_packet_hash(pkt, 65, gpn); | 3095 yahoo_packet_hash(pkt, 65, gpn); |
3376 yahoo_packet_hash(pkt, 14, ""); | 3096 yahoo_packet_hash(pkt, 14, ""); |
3377 yahoo_send_packet(yd, pkt); | 3097 yahoo_packet_send_and_free(pkt, yd); |
3378 yahoo_packet_free(pkt); | |
3379 | 3098 |
3380 /* Step 2: Remove buddy from old group */ | 3099 /* Step 2: Remove buddy from old group */ |
3381 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0); | 3100 pkt = yahoo_packet_new(YAHOO_SERVICE_REMBUDDY, YAHOO_STATUS_AVAILABLE, 0); |
3382 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | 3101 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
3383 yahoo_packet_hash(pkt, 7, who); | 3102 yahoo_packet_hash(pkt, 7, who); |
3384 yahoo_packet_hash(pkt, 65, gpo); | 3103 yahoo_packet_hash(pkt, 65, gpo); |
3385 yahoo_send_packet(yd, pkt); | 3104 yahoo_packet_send_and_free(pkt, yd); |
3386 yahoo_packet_free(pkt); | |
3387 g_free(gpn); | 3105 g_free(gpn); |
3388 g_free(gpo); | 3106 g_free(gpo); |
3389 } | 3107 } |
3390 | 3108 |
3391 static void yahoo_rename_group(GaimConnection *gc, const char *old_name, | 3109 static void yahoo_rename_group(GaimConnection *gc, const char *old_name, |
3405 | 3123 |
3406 pkt = yahoo_packet_new(YAHOO_SERVICE_GROUPRENAME, YAHOO_STATUS_AVAILABLE, 0); | 3124 pkt = yahoo_packet_new(YAHOO_SERVICE_GROUPRENAME, YAHOO_STATUS_AVAILABLE, 0); |
3407 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); | 3125 yahoo_packet_hash(pkt, 1, gaim_connection_get_display_name(gc)); |
3408 yahoo_packet_hash(pkt, 65, gpo); | 3126 yahoo_packet_hash(pkt, 65, gpo); |
3409 yahoo_packet_hash(pkt, 67, gpn); | 3127 yahoo_packet_hash(pkt, 67, gpn); |
3410 yahoo_send_packet(yd, pkt); | 3128 yahoo_packet_send_and_free(pkt, yd); |
3411 yahoo_packet_free(pkt); | |
3412 g_free(gpn); | 3129 g_free(gpn); |
3413 g_free(gpo); | 3130 g_free(gpo); |
3414 } | 3131 } |
3415 | 3132 |
3416 static GaimCmdRet | 3133 static GaimCmdRet |