Mercurial > pidgin.yaz
annotate plugins/yay/libyahoo.c @ 1362:3cea00ca7a34
[gaim-migrate @ 1372]
yay.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 22 Dec 2000 10:48:19 +0000 |
parents | 903a6d0938c7 |
children | b167222b5c93 |
rev | line source |
---|---|
1135
903a6d0938c7
[gaim-migrate @ 1145]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1099
diff
changeset
|
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ |
1054 | 2 /* |
3 Yahoo Pager Client Library | |
4 | |
5 This code is based on code by Douglas Winslow. The original info from | |
6 his code is listed below. This code has taken his code and has been | |
7 altered to my naming and coding conventions and has been made more | |
8 usable as a library of routines. | |
9 | |
10 -- Nathan Neulinger <nneul@umr.edu> | |
11 */ | |
12 | |
13 /* | |
14 Yahoo Pager Client Emulator Pro - yppro.c | |
15 A basic reference implementation | |
16 Douglas Winslow <douglas@min.net> | |
17 Tue Sep 1 02:28:21 EDT 1998 | |
18 Version 2, Revision 2 | |
19 Known to compile on Linux 2.0, FreeBSD 2.2, and BSDi 3.0. | |
20 hi to aap bdc drw jfn jrc mm mcd [cejn]b #cz and rootshell | |
21 | |
22 Finally! | |
23 Yahoo finally patched their server-side, and things will be getting | |
24 back to "normal". I will continue to maintain this code as long as | |
25 there is interest for it. Since Yahoo will be discontinuing YPNS1.1 | |
26 login support shortly, I've upgraded this client to do YPNS1.2. You | |
27 *must* have a password to pass authentication to the pager server. | |
28 This authentication is done by a weird HTTP cookie method. | |
29 | |
30 This code is distributed under the GNU General Public License (GPL) | |
31 */ | |
32 | |
33 #include "config.h" | |
34 #include <stdio.h> | |
35 #include <netdb.h> | |
36 #include <fcntl.h> | |
37 #include <errno.h> | |
38 #include <sys/socket.h> | |
39 #include <netinet/in.h> | |
40 #if defined(WITH_GTK) | |
41 #include <gtk/gtk.h> | |
42 #endif | |
43 #include <unistd.h> | |
44 #if defined(HAVE_STRINGS_H) | |
45 #include <strings.h> | |
46 #endif | |
47 #if defined(HAVE_STRING_H) | |
48 #include <string.h> | |
49 #endif | |
50 #include <ctype.h> | |
51 #include "libyahoo.h" | |
52 #ifdef HAVE_DMALLOC | |
53 #include "dmalloc.h" | |
54 #else | |
55 #include <stdlib.h> | |
56 #endif | |
57 | |
58 #include "memtok.h" | |
59 | |
60 /* allow libyahoo to be used without gtkyahoo's debug support */ | |
61 #ifdef ENABLE_LIBYAHOO_DEBUG | |
62 #include "libyahoo-debug.h" | |
63 #else | |
64 static void yahoo_dbg_Print(char *tmp, ...) | |
65 { | |
66 } | |
67 | |
68 #define yahoo_dbg_NullCheck(x) ((x)?(x):("[NULL]")) | |
69 #endif | |
70 | |
71 /* remap functions to gtk versions */ | |
72 #if defined(WITH_GTK) | |
73 #define malloc g_malloc | |
74 #define free g_free | |
75 #define calloc(x,y) g_malloc0((x)*(y)) | |
76 #endif | |
77 | |
78 #if (!defined(TRUE) || !defined(FALSE)) | |
79 # define TRUE 1 | |
80 # define FALSE 0 | |
81 #endif | |
82 | |
83 /* Define a quick shortcut function to free a pointer and set it to null */ | |
84 #define FREE(x) if (x) { free(x); x=NULL; } | |
85 | |
86 #if defined(WITH_SOCKS4) | |
87 void SOCKSinit(char *argv0); | |
88 #endif | |
89 | |
90 /* pager server host */ | |
91 #define YAHOO_PAGER_HOST "cs.yahoo.com" | |
92 #define YAHOO_PAGER_PORT 5050 | |
93 /* pager server host for http connections */ | |
94 #define YAHOO_PAGER_HTTP_HOST "http.pager.yahoo.com" | |
95 #define YAHOO_PAGER_HTTP_PORT 80 | |
96 /* authentication/login host */ | |
97 #define YAHOO_AUTH_HOST "msg.edit.yahoo.com" | |
98 #define YAHOO_AUTH_PORT 80 | |
99 /* buddy/identity/config host */ | |
100 #define YAHOO_DATA_HOST YAHOO_AUTH_HOST | |
101 #define YAHOO_DATA_PORT 80 | |
102 /* Address book host */ | |
103 #define YAHOO_ADDRESS_HOST "uk.address.yahoo.com" | |
104 #define YAHOO_ADDRESS_PORT 80 | |
105 | |
106 /* User agent to use for HTTP connections */ | |
107 /* It needs to have Mozilla/4 in it, otherwise it fails */ | |
108 #ifndef VERSION | |
109 #define VERSION "1.0" | |
110 #endif | |
111 #define YAHOO_USER_AGENT "Mozilla/4.6 (libyahoo/" VERSION ")" | |
112 | |
113 #define YAHOO_PROTOCOL_HEADER "YPNS2.0" | |
114 | |
115 /* | |
116 * Routines and data private to this library, should not be directly | |
117 * accessed outside of these routines. | |
118 */ | |
119 | |
120 /* Service code labels for debugging output */ | |
121 static struct yahoo_idlabel yahoo_service_codes[] = { | |
122 {YAHOO_SERVICE_LOGON, "Pager Logon"}, | |
123 {YAHOO_SERVICE_LOGOFF, "Pager Logoff"}, | |
124 {YAHOO_SERVICE_ISAWAY, "Is Away"}, | |
125 {YAHOO_SERVICE_ISBACK, "Is Back"}, | |
126 {YAHOO_SERVICE_IDLE, "Idle"}, | |
127 {YAHOO_SERVICE_MESSAGE, "Message"}, | |
128 {YAHOO_SERVICE_IDACT, "Activate Identity"}, | |
129 {YAHOO_SERVICE_IDDEACT, "Deactivate Identity"}, | |
130 {YAHOO_SERVICE_MAILSTAT, "Mail Status"}, | |
131 {YAHOO_SERVICE_USERSTAT, "User Status"}, | |
132 {YAHOO_SERVICE_NEWMAIL, "New Mail"}, | |
133 {YAHOO_SERVICE_CHATINVITE, "Chat Invitation"}, | |
134 {YAHOO_SERVICE_CALENDAR, "Calendar Reminder"}, | |
135 {YAHOO_SERVICE_NEWPERSONALMAIL, "New Personals Mail"}, | |
136 {YAHOO_SERVICE_NEWCONTACT, "New Friend"}, | |
137 {YAHOO_SERVICE_GROUPRENAME, "Group Renamed"}, | |
138 {YAHOO_SERVICE_ADDIDENT, "Add Identity"}, | |
139 {YAHOO_SERVICE_ADDIGNORE, "Add Ignore"}, | |
140 {YAHOO_SERVICE_PING, "Ping"}, | |
141 {YAHOO_SERVICE_SYSMESSAGE, "System Message"}, | |
142 {YAHOO_SERVICE_CONFINVITE, "Conference Invitation"}, | |
143 {YAHOO_SERVICE_CONFLOGON, "Conference Logon"}, | |
144 {YAHOO_SERVICE_CONFDECLINE, "Conference Decline"}, | |
145 {YAHOO_SERVICE_CONFLOGOFF, "Conference Logoff"}, | |
146 {YAHOO_SERVICE_CONFMSG, "Conference Message"}, | |
147 {YAHOO_SERVICE_CONFADDINVITE, "Conference Additional Invitation"}, | |
148 {YAHOO_SERVICE_CHATLOGON, "Chat Logon"}, | |
149 {YAHOO_SERVICE_CHATLOGOFF, "Chat Logoff"}, | |
150 {YAHOO_SERVICE_CHATMSG, "Chat Message"}, | |
151 {YAHOO_SERVICE_GAMELOGON, "Game Logon"}, | |
152 {YAHOO_SERVICE_GAMELOGOFF, "Game Logoff"}, | |
153 {YAHOO_SERVICE_FILETRANSFER, "File Transfer"}, | |
154 {YAHOO_SERVICE_PASSTHROUGH2, "Passthrough 2"}, | |
155 {0, NULL} | |
156 }; | |
157 | |
158 /* Status codes */ | |
159 static struct yahoo_idlabel yahoo_status_codes[] = { | |
160 {YAHOO_STATUS_AVAILABLE, "I'm Available"}, | |
161 {YAHOO_STATUS_BRB, "Be Right Back"}, | |
162 {YAHOO_STATUS_BUSY, "Busy"}, | |
163 {YAHOO_STATUS_NOTATHOME, "Not at Home"}, | |
164 {YAHOO_STATUS_NOTATDESK, "Not at my Desk"}, | |
165 {YAHOO_STATUS_NOTINOFFICE, "Not in the Office"}, | |
166 {YAHOO_STATUS_ONPHONE, "On the Phone"}, | |
167 {YAHOO_STATUS_ONVACATION, "On Vacation"}, | |
168 {YAHOO_STATUS_OUTTOLUNCH, "Out to Lunch"}, | |
169 {YAHOO_STATUS_STEPPEDOUT, "Stepped Out"}, | |
170 {YAHOO_STATUS_INVISIBLE, "Invisible"}, | |
171 {YAHOO_STATUS_IDLE, "Idle"}, | |
172 {YAHOO_STATUS_CUSTOM, "Custom Message"}, | |
173 {0, NULL} | |
174 }; | |
175 | |
176 /* Status codes */ | |
177 static struct yahoo_idlabel yahoo_status_append[] = { | |
178 {YAHOO_STATUS_AVAILABLE, "is now available"}, | |
179 {YAHOO_STATUS_BRB, "will be right back"}, | |
180 {YAHOO_STATUS_BUSY, "is now busy"}, | |
181 {YAHOO_STATUS_NOTATHOME, "is not at home"}, | |
182 {YAHOO_STATUS_NOTATDESK, "is not at their desk"}, | |
183 {YAHOO_STATUS_NOTINOFFICE, "is not in the office"}, | |
184 {YAHOO_STATUS_ONPHONE, "is on the phone"}, | |
185 {YAHOO_STATUS_ONVACATION, "is on vacation"}, | |
186 {YAHOO_STATUS_OUTTOLUNCH, "is out to lunch"}, | |
187 {YAHOO_STATUS_STEPPEDOUT, "has stepped out"}, | |
188 {YAHOO_STATUS_INVISIBLE, "is now invisible"}, | |
189 {YAHOO_STATUS_IDLE, "is now idle"}, | |
190 {YAHOO_STATUS_CUSTOM, ""}, | |
191 {0, NULL} | |
192 }; | |
193 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
194 static int readall(int fd, void *buf, size_t count) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
195 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
196 int left, ret, cur = 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
197 |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
198 left = count; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
199 |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
200 while (left) { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
201 ret = read(fd, ((unsigned char *)buf)+cur, left); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
202 if ((ret == -1) && (errno != EINTR)) { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
203 return -1; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
204 } |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
205 if (ret == 0) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
206 return cur; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
207 |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
208 if (ret != -1) { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
209 cur += ret; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
210 left -= ret; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
211 } |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
212 } |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
213 return cur; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
214 } |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
215 |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
216 static int writeall(int fd, void *buf, size_t count) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
217 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
218 int left, ret, cur = 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
219 |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
220 left = count; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
221 |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
222 while (left) { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
223 ret = write(fd, ((unsigned char *)buf)+cur, left); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
224 if ((ret == -1) && (errno != EINTR)) { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
225 return -1; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
226 } |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
227 if (ret == 0) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
228 return cur; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
229 if (ret != -1) { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
230 cur += ret; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
231 left -= ret; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
232 } |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
233 } |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
234 |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
235 return cur; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
236 } |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
237 |
1054 | 238 /* Take a 4-byte character string in little-endian format and return |
239 a unsigned integer */ | |
240 unsigned int yahoo_makeint(unsigned char *data) | |
241 { | |
242 if (data) | |
243 { | |
244 return ((data[3] << 24) + (data[2] << 16) + (data[1] << 8) + | |
245 (data[0])); | |
246 } | |
247 return 0; | |
248 } | |
249 | |
250 /* Take an integer and store it into a 4 character little-endian string */ | |
251 static void yahoo_storeint(unsigned char *data, unsigned int val) | |
252 { | |
253 unsigned int tmp = val; | |
254 int i; | |
255 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
256 if (!data) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
257 return; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
258 |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
259 for (i = 0; i < 4; i++) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
260 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
261 data[i] = tmp % 256; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
262 tmp >>= 8; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
263 } |
1054 | 264 } |
265 | |
266 /* | |
267 converts a comma seperated list to an array of strings | |
268 used primarily in conference code | |
269 | |
270 allocates a string in here -- caller needs to free it | |
271 */ | |
272 char **yahoo_list2array(char *buff) | |
273 { | |
274 char **tmp_array = NULL; | |
275 char *array_elem = NULL; | |
276 char *tmp = NULL; | |
277 | |
278 char *buffer = 0; | |
279 char *ptr_buffer = 0; | |
280 | |
281 int sublen = 0; | |
282 int cnt = 0; | |
283 int nxtelem = 0; | |
284 unsigned int i = 0; | |
285 unsigned int len = 0; | |
286 | |
287 if (0 == buff) | |
288 return 0; | |
289 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
290 if (!(ptr_buffer = buffer = strdup(buff))) /* play with a copy */ |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
291 return NULL; |
1054 | 292 |
293 /* count the number of users (commas + 1) */ | |
294 for (i = 0; i < strlen(buffer); i++) | |
295 { | |
296 if (buffer[i] == ',') | |
297 { | |
298 /* | |
299 if not looking at end of list | |
300 ( ignore extra pesky comma at end of list) | |
301 */ | |
302 if (i != (strlen(buffer) - 1)) | |
303 cnt++; | |
304 } | |
305 } | |
306 | |
307 /* add one more name than comma .. */ | |
308 cnt++; | |
309 | |
310 /* allocate the array to hold the list of buddys */ | |
311 /* null terminated array of pointers */ | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
312 if (!(tmp_array = (char **) malloc(sizeof(char *) * (cnt + 1)))) { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
313 FREE(buffer); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
314 return NULL; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
315 } |
1054 | 316 |
317 memset(tmp_array, 0, (sizeof(char *) * (cnt + 1))); | |
318 | |
319 /* Parse through the list and get all the entries */ | |
320 while ((ptr_buffer[sublen] != ',') && (ptr_buffer[sublen] != '\0')) | |
321 sublen++; | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
322 if (!(tmp = (char *) malloc(sizeof(char) * (sublen + 1)))) { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
323 FREE(buffer); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
324 FREE(tmp_array); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
325 return NULL; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
326 } |
1054 | 327 |
328 memcpy(tmp, ptr_buffer, sublen); | |
329 tmp[sublen] = '\0'; | |
330 | |
331 if (ptr_buffer[sublen] != '\0') | |
332 ptr_buffer = &(ptr_buffer[sublen + 1]); | |
333 else | |
334 ptr_buffer = &(ptr_buffer[sublen]); /* stay at the null char */ | |
335 sublen = 0; | |
336 | |
337 while (tmp && (strcmp(tmp, "") != 0)) | |
338 { | |
339 len = strlen(tmp); | |
340 array_elem = (char *) malloc(sizeof(char) * (len + 1)); | |
341 | |
342 strncpy(array_elem, tmp, (len + 1)); | |
343 array_elem[len] = '\0'; | |
344 | |
345 tmp_array[nxtelem++] = array_elem; | |
346 array_elem = NULL; | |
347 | |
348 FREE(tmp); | |
349 | |
350 while ((ptr_buffer[sublen] != ',') && (ptr_buffer[sublen] != '\0')) | |
351 sublen++; | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
352 if (!(tmp = (char *) malloc(sizeof(char) * (sublen + 1)))) { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
353 FREE(buffer); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
354 FREE(tmp_array); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
355 return NULL; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
356 } |
1054 | 357 |
358 memcpy(tmp, ptr_buffer, sublen); | |
359 tmp[sublen] = '\0'; | |
360 | |
361 if (ptr_buffer[sublen] != '\0') | |
362 ptr_buffer = &(ptr_buffer[sublen + 1]); | |
363 else | |
364 ptr_buffer = &(ptr_buffer[sublen]); /* stay at the null char */ | |
365 | |
366 sublen = 0; | |
367 } | |
368 tmp_array[nxtelem] = NULL; | |
369 | |
370 FREE(tmp); | |
371 FREE(buffer); | |
372 return (tmp_array); | |
373 | |
374 } /* yahoo_list2array() */ | |
375 | |
376 /* | |
377 Free's the memory associated with an array generated bu yahoo_list2array | |
378 */ | |
379 void yahoo_arraykill(char **array) | |
380 { | |
381 int nxtelem = 0; | |
382 | |
383 if (NULL == array) | |
384 return; | |
385 | |
386 while (array[nxtelem] != NULL) | |
387 { | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
388 FREE(array[nxtelem++]); |
1054 | 389 } |
390 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
391 FREE(array); |
1054 | 392 } /* yahoo_arraykill() */ |
393 | |
394 /* | |
395 converts an array of strings to a comma seperated list | |
396 used primarily in conference code | |
397 | |
398 allocates a string in here.. needs to be freed by caller program | |
399 */ | |
400 char *yahoo_array2list(char **array) | |
401 { | |
402 char *list = NULL; | |
403 int nxtelem = 0; | |
404 int arraylength = 0; | |
405 | |
406 if (NULL == array) | |
407 return NULL; | |
408 | |
409 while (array[nxtelem] != NULL) | |
410 { | |
411 arraylength += strlen(array[nxtelem++]); | |
412 arraylength++; /* comma */ | |
413 } | |
414 | |
415 nxtelem = 0; /* reset array counter */ | |
416 | |
417 /* allocate at least one - for NULL list - and to | |
418 allow my strcat to write past the end for the | |
419 last comma which gets converted to NULL */ | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
420 if (!(list = (char *) malloc(sizeof(char) * (arraylength + 1)))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
421 return NULL; |
1054 | 422 |
423 memset(list, 0, (arraylength + 1)); | |
424 | |
425 while (array[nxtelem] != NULL) | |
426 { | |
427 strcat(list, array[nxtelem++]); | |
428 strcat(list, ","); | |
429 } | |
430 /* | |
431 overwrite last ',' with a NULL | |
432 makes the string end with two null characters, but this way | |
433 handles empty lists gracefully | |
434 */ | |
435 list[arraylength - 1] = '\0'; | |
436 | |
437 return (list); | |
438 } /* yahoo_array2list() */ | |
439 | |
440 /* Free a buddy list */ | |
441 static void yahoo_free_buddies(struct yahoo_context *ctx) | |
442 { | |
443 int i; | |
444 | |
445 if (!ctx->buddies) | |
446 { | |
447 return; | |
448 } | |
449 | |
450 i = 0; | |
451 while (ctx->buddies[i]) | |
452 { | |
453 FREE(ctx->buddies[i]->group); | |
454 FREE(ctx->buddies[i]->id); | |
455 i++; | |
456 } | |
457 | |
458 FREE(ctx->buddies); | |
459 } | |
460 | |
461 /* Free a identities list */ | |
462 static void yahoo_free_identities(struct yahoo_context *ctx) | |
463 { | |
464 int i; | |
465 | |
466 if (!ctx->identities) | |
467 { | |
468 return; | |
469 } | |
470 | |
471 i = 0; | |
472 while (ctx->identities[i]) | |
473 { | |
474 FREE(ctx->identities[i]); | |
475 i++; | |
476 } | |
477 | |
478 FREE(ctx->identities); | |
479 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_free_identities: done\n"); | |
480 } | |
481 | |
482 #if 0 /* not used at the moment */ | |
483 static void yahoo_hexdump(char *label, unsigned char *data, int datalen) | |
484 { | |
485 int i, j; | |
486 int val, skipped_last; | |
487 char current[100]; | |
488 char last[100]; | |
489 char tmp[15]; | |
490 char outline[100]; | |
491 static int last_datalen = 0; | |
492 static unsigned char *last_data = NULL; | |
493 | |
494 if (last_data) | |
495 { | |
496 if (last_datalen == datalen && !memcmp(data, last_data, datalen)) | |
497 { | |
498 printf("\n%s: <same as last dump>\n", label); | |
499 return; | |
500 } | |
501 FREE(last_data); | |
502 } | |
503 | |
504 /* Copy the packet so we can don't duplicate it next time. */ | |
505 last_datalen = datalen; | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
506 if (!(last_data = (unsigned char *) malloc(datalen))) { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
507 FREE(last_data); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
508 return; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
509 } |
1054 | 510 memcpy(last_data, data, datalen); |
511 | |
512 /* Handle printing the full entry out */ | |
513 printf("\n"); | |
514 printf("%s:\n", label); | |
515 | |
516 skipped_last = 0; | |
517 last[0] = 0; | |
518 for (j = 0; j * 16 < datalen; j++) | |
519 { | |
520 current[0] = 0; | |
521 | |
522 /* Print out in hex */ | |
523 for (i = j * 16; i < (j * 16 + 16); i++) | |
524 { | |
525 if (i < datalen) | |
526 { | |
527 val = data[i]; | |
528 sprintf(tmp, "%.2X ", val); | |
529 } | |
530 else | |
531 { | |
532 sprintf(tmp, " "); | |
533 } | |
534 strcat(current, tmp); | |
535 } | |
536 | |
537 /* Print out in ascii */ | |
538 strcat(current, " "); | |
539 for (i = j * 16; i < (j * 16) + 16; i++) | |
540 { | |
541 if (i < datalen) | |
542 { | |
543 if (isprint(data[i])) | |
544 { | |
545 sprintf(tmp, "%c", data[i]); | |
546 } | |
547 else | |
548 { | |
549 sprintf(tmp, "."); | |
550 } | |
551 } | |
552 else | |
553 { | |
554 sprintf(tmp, " "); | |
555 } | |
556 strcat(current, tmp); | |
557 } | |
558 | |
559 outline[0] = 0; | |
560 if (!strcmp(current, last)) | |
561 { | |
562 if (!skipped_last) | |
563 { | |
564 strcpy(outline, " ....:\n"); | |
565 } | |
566 skipped_last = 1; | |
567 } | |
568 else | |
569 { | |
570 sprintf(outline, " %.4d: %s\n", j * 16, current); | |
571 skipped_last = 0; | |
572 } | |
573 printf("%s", outline); | |
574 strcpy(last, current); | |
575 } | |
576 | |
577 if (skipped_last) | |
578 { | |
579 printf("%s", outline); | |
580 } | |
581 printf("\n"); | |
582 } | |
583 #endif | |
584 | |
585 static int yahoo_socket_connect(struct yahoo_context *ctx, char *host, | |
586 int port) | |
587 { | |
588 struct sockaddr_in serv_addr; | |
589 struct hostent *server; | |
590 int servfd; | |
591 int res; | |
592 | |
593 yahoo_dbg_Print("libyahoo", | |
594 "[libyahoo] yahoo_socket_connect - starting [%s:%d]\n", host, port); | |
595 | |
596 if (!ctx || !host || !port) | |
597 { | |
598 yahoo_dbg_Print("libyahoo", | |
599 "[libyahoo] yahoo_socket_connect - nulls\n"); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
600 return -1; |
1054 | 601 } |
602 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
603 if (!(server = gethostbyname(host))) |
1054 | 604 { |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
605 printf("[libyahoo] failed to look up server (%s:%d): %s\n", host, port, hstrerror(h_errno)); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
606 return -1; |
1054 | 607 } |
608 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
609 if ((servfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
610 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
611 return -1; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
612 } |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
613 |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
614 memset(&serv_addr, 0, sizeof(serv_addr)); |
1054 | 615 serv_addr.sin_family = AF_INET; |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
616 memcpy(&serv_addr.sin_addr.s_addr, server->h_addr, server->h_length); |
1054 | 617 serv_addr.sin_port = htons(port); |
618 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
619 /* XXX should put timeouts on the connect()'s -mid */ |
1054 | 620 res = -1; |
621 if (ctx->connect_mode == YAHOO_CONNECT_SOCKS4) | |
622 { | |
623 #if defined(WITH_SOCKS4) | |
624 res = | |
625 Rconnect(servfd, (struct sockaddr *) &serv_addr, | |
626 sizeof(serv_addr)); | |
627 #endif | |
628 } | |
629 else if (ctx->connect_mode == YAHOO_CONNECT_SOCKS5) | |
630 { | |
631 #if defined(WITH_SOCKS5) | |
632 #endif | |
633 } | |
634 else if (ctx->connect_mode == YAHOO_CONNECT_NORMAL || | |
635 ctx->connect_mode == YAHOO_CONNECT_HTTP || | |
636 ctx->connect_mode == YAHOO_CONNECT_HTTPPROXY) | |
637 { | |
638 res = | |
639 connect(servfd, (struct sockaddr *) &serv_addr, | |
640 sizeof(serv_addr)); | |
641 } | |
642 else | |
643 { | |
644 printf("[libyahoo] unhandled connect mode (%d).\n", | |
645 ctx->connect_mode); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
646 close(servfd); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
647 return -1; |
1054 | 648 } |
649 | |
650 if (res < 0) | |
651 { | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
652 printf("[libyahoo] failed to connect to server (%s:%d): %s\n", |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
653 host, port, strerror(errno)); |
1054 | 654 close(servfd); |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
655 return -1; |
1054 | 656 } |
657 | |
658 yahoo_dbg_Print("libyahoo", | |
659 "[libyahoo] yahoo_socket_connect - finished\n"); | |
660 return servfd; | |
661 } | |
662 | |
663 /* really ugly brute force approach - someone find a GPL'd/free | |
664 equivalent and replace this p.o.s. */ | |
665 static char *yahoo_urlencode(char *data) | |
666 { | |
667 static char *tmp = NULL; | |
668 char buf[4]; | |
669 int i, len; | |
670 | |
671 len = 3 * strlen(data) + 1; | |
672 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
673 if (tmp) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
674 FREE(tmp); |
1054 | 675 |
676 if (!data) | |
677 return NULL; | |
678 | |
679 /* change this at some point to re-use the buffer, no sense | |
680 allocating repeatedly */ | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
681 if (!(tmp = (char *) malloc(len))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
682 return NULL; |
1054 | 683 tmp[0] = 0; |
684 | |
685 for (i = 0; i < strlen(data); i++) | |
686 { | |
687 if (isdigit((int) (data[i])) || | |
688 isalpha((int) data[i]) || data[i] == '_') | |
689 { | |
690 buf[0] = data[i]; | |
691 buf[1] = 0; | |
692 strcat(tmp, buf); | |
693 } | |
694 else | |
695 { | |
696 sprintf(buf, "%%%.2X", data[i]); | |
697 strcat(tmp, buf); | |
698 } | |
699 } | |
700 | |
701 return tmp; | |
702 } | |
703 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
704 static int yahoo_addtobuffer(struct yahoo_context *ctx, char *data, |
1054 | 705 int datalen) |
706 { | |
707 //yahoo_hexdump("yahoo_addtobuffer", data, datalen); | |
708 | |
709 /* Check buffer, increase size if necessary */ | |
710 if (!ctx->io_buf | |
711 || ((ctx->io_buf_maxlen - ctx->io_buf_curlen) < (datalen + 100))) | |
712 { | |
713 char *new_io_buf; | |
714 | |
715 if (datalen < 10240) | |
716 { | |
717 ctx->io_buf_maxlen += 10240; | |
718 } | |
719 else | |
720 { | |
721 ctx->io_buf_maxlen += datalen; | |
722 } | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
723 if (!(new_io_buf = (char *) malloc(ctx->io_buf_maxlen))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
724 return 0; |
1054 | 725 |
726 if (ctx->io_buf) | |
727 { | |
728 memcpy(new_io_buf, ctx->io_buf, ctx->io_buf_curlen); | |
729 FREE(ctx->io_buf); | |
730 } | |
731 | |
732 ctx->io_buf = new_io_buf; | |
733 } | |
734 | |
735 memcpy(ctx->io_buf + ctx->io_buf_curlen, data, datalen); | |
736 ctx->io_buf_curlen += datalen; | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
737 |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
738 return 1; |
1054 | 739 } |
740 | |
741 static int yahoo_tcp_readline(char *ptr, int maxlen, int fd) | |
742 { | |
743 int n, rc; | |
744 char c; | |
745 | |
746 for (n = 1; n < maxlen; n++) | |
747 { | |
748 again: | |
749 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
750 if ((rc = readall(fd, &c, 1)) == 1) |
1054 | 751 { |
752 *ptr++ = c; | |
753 if (c == '\n') | |
754 break; | |
755 } | |
756 else if (rc == 0) | |
757 { | |
758 if (n == 1) | |
759 return (0); /* EOF, no data */ | |
760 else | |
761 break; /* EOF, w/ data */ | |
762 } | |
763 else | |
764 { | |
765 if (errno == EINTR) | |
766 goto again; | |
767 printf | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
768 ("Yahoo: Error reading from socket in yahoo_tcp_readline: %s.\n", strerror(errno)); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
769 return -1; |
1054 | 770 } |
771 } | |
772 | |
773 *ptr = 0; | |
774 return (n); | |
775 } | |
776 | |
777 /* | |
778 * Published library interfaces | |
779 */ | |
780 | |
781 /* Initialize interface to yahoo library, sortof like a class object | |
782 creation routine. */ | |
783 struct yahoo_context *yahoo_init(char *user, char *password, | |
784 struct yahoo_options *options) | |
785 { | |
786 struct yahoo_context *tmp; | |
787 | |
788 if (!user || !password) | |
789 { | |
790 return NULL; | |
791 } | |
792 | |
793 /* Allocate a new context */ | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
794 if (!(tmp = (struct yahoo_context *) calloc(1, sizeof(*tmp)))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
795 return NULL; |
1054 | 796 |
797 /* Fill in any available info */ | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
798 if (!(tmp->user = strdup(user))) { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
799 yahoo_free_context(tmp); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
800 return NULL; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
801 } |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
802 if (!(tmp->password = strdup(password))) { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
803 yahoo_free_context(tmp); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
804 return NULL; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
805 } |
1054 | 806 if (options->proxy_host) |
807 { | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
808 if (!(tmp->proxy_host = strdup(options->proxy_host))) { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
809 yahoo_free_context(tmp); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
810 return NULL; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
811 } |
1054 | 812 } |
813 tmp->proxy_port = options->proxy_port; | |
814 tmp->connect_mode = options->connect_mode; | |
815 | |
816 #if defined(WITH_SOCKS4) | |
817 if (connect_mode == YAHOO_CONNECT_SOCKS4) | |
818 { | |
819 static int did_socks_init = 0; | |
820 | |
821 if (did_socks_init == 0) | |
822 { | |
823 SOCKSinit("libyahoo"); | |
824 did_socks_init = 1; | |
825 } | |
826 } | |
827 #endif | |
828 | |
829 /* Fetch the cookies */ | |
830 if (!yahoo_fetchcookies(tmp)) | |
831 { | |
832 yahoo_free_context(tmp); | |
833 return NULL; | |
834 } | |
835 | |
836 return tmp; | |
837 } | |
838 | |
839 /* Free a yahoo context */ | |
840 void yahoo_free_context(struct yahoo_context *ctx) | |
841 { | |
842 FREE(ctx->user); | |
843 FREE(ctx->password); | |
844 FREE(ctx->proxy_host); | |
845 FREE(ctx->io_buf); | |
846 FREE(ctx->cookie); | |
847 FREE(ctx->login_cookie); | |
848 FREE(ctx->login_id); | |
849 | |
850 yahoo_free_buddies(ctx); | |
851 yahoo_free_identities(ctx); | |
852 | |
853 FREE(ctx); | |
854 } | |
855 | |
856 /* Turn a status code into it's corresponding string */ | |
857 char *yahoo_get_status_string(int statuscode) | |
858 { | |
859 int i; | |
860 | |
861 for (i = 0; yahoo_status_codes[i].label; i++) | |
862 { | |
863 if (yahoo_status_codes[i].id == statuscode) | |
864 { | |
865 return yahoo_status_codes[i].label; | |
866 } | |
867 } | |
868 return NULL; | |
869 } | |
870 | |
871 /* Turn a status code into it's corresponding string */ | |
872 char *yahoo_get_status_append(int statuscode) | |
873 { | |
874 int i; | |
875 | |
876 for (i = 0; yahoo_status_append[i].label; i++) | |
877 { | |
878 if (yahoo_status_append[i].id == statuscode) | |
879 { | |
880 return yahoo_status_append[i].label; | |
881 } | |
882 } | |
883 return NULL; | |
884 } | |
885 | |
886 /* Turn a service code into it's corresponding string */ | |
887 char *yahoo_get_service_string(int servicecode) | |
888 { | |
889 int i; | |
890 char *name = "Unknown Service"; | |
891 static char tmp[50]; | |
892 | |
893 for (i = 0; yahoo_service_codes[i].label; i++) | |
894 { | |
895 if (yahoo_service_codes[i].id == servicecode) | |
896 { | |
897 name = yahoo_service_codes[i].label; | |
898 break; | |
899 } | |
900 } | |
901 | |
902 snprintf(tmp, 50, "(%d) %s", servicecode, name); | |
903 return tmp; | |
904 } | |
905 | |
906 /* Return a malloc()'d copy of the users cookie */ | |
907 int yahoo_fetchcookies(struct yahoo_context *ctx) | |
908 { | |
909 char buffer[5000]; | |
910 int servfd; | |
911 int i; | |
912 int res; | |
913 char *tmpstr; | |
914 | |
915 if (!ctx) | |
916 { | |
917 return 0; | |
918 } | |
919 | |
920 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_fetchcookies: starting\n"); | |
921 | |
922 /* Check for cached cookie */ | |
923 if (ctx->cookie) | |
924 { | |
925 FREE(ctx->cookie); | |
926 } | |
927 if (ctx->login_cookie) | |
928 { | |
929 FREE(ctx->login_cookie); | |
930 } | |
931 | |
932 if (ctx->connect_mode == YAHOO_CONNECT_HTTPPROXY) | |
933 { | |
934 servfd = yahoo_socket_connect(ctx, ctx->proxy_host, ctx->proxy_port); | |
935 } | |
936 else | |
937 { | |
938 servfd = yahoo_socket_connect(ctx, YAHOO_AUTH_HOST, YAHOO_AUTH_PORT); | |
939 } | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
940 if (servfd < 0) |
1054 | 941 { |
942 printf("[libyahoo] failed to connect to pager auth server.\n"); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
943 return 0; |
1054 | 944 } |
945 | |
946 strcpy(buffer, "GET "); | |
947 if (ctx->connect_mode == YAHOO_CONNECT_HTTPPROXY) | |
948 { | |
949 strcat(buffer, "http://" YAHOO_AUTH_HOST); | |
950 } | |
951 strcat(buffer, "/config/ncclogin?login="); | |
952 if (ctx->login_id) | |
953 { | |
954 strcat(buffer, yahoo_urlencode(ctx->login_id)); | |
955 } | |
956 else | |
957 { | |
958 strcat(buffer, yahoo_urlencode(ctx->user)); | |
959 } | |
960 strcat(buffer, "&passwd="); | |
961 strcat(buffer, yahoo_urlencode(ctx->password)); | |
962 strcat(buffer, "&n=1 HTTP/1.0\r\n"); | |
963 strcat(buffer, "User-Agent: " YAHOO_USER_AGENT "\r\n"); | |
964 strcat(buffer, "Host: " YAHOO_AUTH_HOST "\r\n"); | |
965 strcat(buffer, "\r\n"); | |
966 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
967 if (writeall(servfd, buffer, strlen(buffer)) < strlen(buffer)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
968 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
969 close(servfd); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
970 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
971 } |
1054 | 972 |
973 yahoo_dbg_Print("libyahoo", | |
974 "[libyahoo] yahoo_fetchcookies: writing buffer '%s'\n", buffer); | |
975 | |
976 ctx->cookie = NULL; | |
977 while ((res = yahoo_tcp_readline(buffer, 5000, servfd)) > 0) | |
978 { | |
979 /* strip out any non-alphas */ | |
980 for (i = 0; i < strlen(buffer); i++) | |
981 { | |
982 if (!isprint((int) buffer[i])) | |
983 { | |
984 buffer[i] = 0; | |
985 } | |
986 } | |
987 | |
988 yahoo_dbg_Print("libyahoo", | |
989 "[libyahoo] yahoo_fetchcookies: read buffer '%s'\n", buffer); | |
990 | |
991 if (!strcasecmp(buffer, "ERROR: Invalid NCC Login")) | |
992 { | |
993 yahoo_dbg_Print("libyahoo", | |
994 "[libyahoo] yahoo_fetchcookies: password was invalid\n"); | |
995 return (0); | |
996 } | |
997 | |
998 if (!strncasecmp(buffer, "Set-Cookie: Y=", 14)) | |
999 { | |
1000 FREE(ctx->cookie); | |
1001 ctx->cookie = strdup(buffer + 12); | |
1002 | |
1003 tmpstr = strchr(ctx->cookie, ';'); | |
1004 if (tmpstr) | |
1005 { | |
1006 *tmpstr = '\0'; | |
1007 } | |
1008 } | |
1009 } | |
1010 yahoo_dbg_Print("libyahoo", | |
1011 "[libyahoo] yahoo_fetchcookies: closing server connection\n"); | |
1012 close(servfd); | |
1013 servfd = 0; | |
1014 yahoo_dbg_Print("libyahoo", | |
1015 "[libyahoo] yahoo_fetchcookies: closed server connection\n"); | |
1016 | |
1017 if (ctx->cookie) | |
1018 { | |
1019 tmpstr = strstr(ctx->cookie, "n="); | |
1020 if (tmpstr) | |
1021 { | |
1022 ctx->login_cookie = strdup(tmpstr + 2); | |
1023 } | |
1024 | |
1025 tmpstr = strchr(ctx->login_cookie, '&'); | |
1026 if (tmpstr) | |
1027 { | |
1028 *tmpstr = '\0'; | |
1029 } | |
1030 } | |
1031 | |
1032 if (ctx->cookie) | |
1033 yahoo_dbg_Print("libyahoo", | |
1034 "[libyahoo] yahoo_fetchcookies: cookie (%s)\n", ctx->cookie); | |
1035 if (ctx->login_cookie) | |
1036 yahoo_dbg_Print("libyahoo", | |
1037 "[libyahoo] yahoo_fetchcookies: login cookie (%s)\n", | |
1038 ctx->login_cookie); | |
1039 | |
1040 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_fetchcookies: done\n"); | |
1041 | |
1042 return 1; | |
1043 } | |
1044 | |
1045 /* Add a buddy to your buddy list */ | |
1046 int yahoo_add_buddy(struct yahoo_context *ctx, char *addid, | |
1047 char *active_id, char *group, char *msg) | |
1048 { | |
1049 char buffer[5000]; | |
1050 int servfd; | |
1051 | |
1052 if (!ctx) | |
1053 { | |
1054 return 0; | |
1055 } | |
1056 | |
1057 if (ctx->connect_mode == YAHOO_CONNECT_HTTPPROXY) | |
1058 { | |
1059 yahoo_dbg_Print("libyahoo", | |
1060 "[libyahoo] yahoo_add_buddy - connecting via proxy\n"); | |
1061 servfd = yahoo_socket_connect(ctx, ctx->proxy_host, ctx->proxy_port); | |
1062 } | |
1063 else | |
1064 { | |
1065 yahoo_dbg_Print("libyahoo", | |
1066 "[libyahoo] yahoo_add_buddy - connecting\n"); | |
1067 servfd = yahoo_socket_connect(ctx, YAHOO_DATA_HOST, YAHOO_DATA_PORT); | |
1068 } | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1069 if (servfd < 0) |
1054 | 1070 { |
1071 yahoo_dbg_Print("libyahoo", | |
1072 "[libyahoo] yahoo_add_buddy: failed to connect\n"); | |
1073 return (0); | |
1074 } | |
1075 | |
1076 strcpy(buffer, "GET "); | |
1077 if (ctx->connect_mode == YAHOO_CONNECT_HTTPPROXY) | |
1078 { | |
1079 strcat(buffer, "http://" YAHOO_DATA_HOST); | |
1080 } | |
1081 strcat(buffer, "/config/set_buddygrp?.bg="); | |
1082 strcat(buffer, yahoo_urlencode(group)); | |
1083 strcat(buffer, "&.src=bl&.cmd=a&.bdl="); | |
1084 strcat(buffer, yahoo_urlencode(addid)); | |
1085 strcat(buffer, "&.id="); | |
1086 strcat(buffer, yahoo_urlencode(active_id)); | |
1087 strcat(buffer, "&.l="); | |
1088 strcat(buffer, yahoo_urlencode(ctx->user)); | |
1089 strcat(buffer, "&.amsg="); | |
1090 strcat(buffer, yahoo_urlencode(msg)); | |
1091 strcat(buffer, " HTTP/1.0\r\n"); | |
1092 | |
1093 strcat(buffer, "User-Agent: " YAHOO_USER_AGENT "\r\n"); | |
1094 strcat(buffer, "Host: " YAHOO_DATA_HOST "\r\n"); | |
1095 strcat(buffer, "Cookie: "); | |
1096 strcat(buffer, ctx->cookie); | |
1097 strcat(buffer, "\r\n"); | |
1098 strcat(buffer, "\r\n"); | |
1099 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1100 if (writeall(servfd, buffer, strlen(buffer)) < strlen(buffer)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1101 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1102 close(servfd); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1103 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1104 } |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1105 |
1054 | 1106 while (yahoo_tcp_readline(buffer, 5000, servfd) > 0) |
1107 { | |
1108 /* just dump the output, I don't care about errors at the moment */ | |
1109 } | |
1110 close(servfd); | |
1111 servfd = 0; | |
1112 | |
1113 /* indicate success for now with 0 */ | |
1114 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_add_buddy: finished\n"); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1115 return 1; |
1054 | 1116 } |
1117 | |
1118 /* Remove a buddy from your buddy list */ | |
1119 int yahoo_remove_buddy(struct yahoo_context *ctx, char *addid, | |
1120 char *active_id, char *group, char *msg) | |
1121 { | |
1122 char buffer[5000]; | |
1123 int servfd; | |
1124 | |
1125 if (!ctx) | |
1126 { | |
1127 return 0; | |
1128 } | |
1129 | |
1130 if (ctx->connect_mode == YAHOO_CONNECT_HTTPPROXY) | |
1131 { | |
1132 yahoo_dbg_Print("libyahoo", | |
1133 "[libyahoo] yahoo_add_buddy - connecting via proxy\n"); | |
1134 servfd = yahoo_socket_connect(ctx, ctx->proxy_host, ctx->proxy_port); | |
1135 } | |
1136 else | |
1137 { | |
1138 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_add_buddy - connecting\n"); | |
1139 servfd = yahoo_socket_connect(ctx, YAHOO_DATA_HOST, YAHOO_DATA_PORT); | |
1140 } | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1141 if (servfd < 0) |
1054 | 1142 { |
1143 yahoo_dbg_Print("libyahoo", | |
1144 "[libyahoo] yahoo_add_buddy: failed to connect\n"); | |
1145 return (0); | |
1146 } | |
1147 | |
1148 strcpy(buffer, "GET "); | |
1149 if (ctx->connect_mode == YAHOO_CONNECT_HTTPPROXY) | |
1150 { | |
1151 strcat(buffer, "http://" YAHOO_DATA_HOST); | |
1152 } | |
1153 strcat(buffer, "/config/set_buddygrp?.bg="); | |
1154 strcat(buffer, yahoo_urlencode(group)); | |
1155 strcat(buffer, "&.src=bl&.cmd=d&.bdl="); | |
1156 strcat(buffer, yahoo_urlencode(addid)); | |
1157 strcat(buffer, "&.id="); | |
1158 strcat(buffer, yahoo_urlencode(active_id)); | |
1159 strcat(buffer, "&.l="); | |
1160 strcat(buffer, yahoo_urlencode(ctx->user)); | |
1161 strcat(buffer, "&.amsg="); | |
1162 strcat(buffer, yahoo_urlencode(msg)); | |
1163 strcat(buffer, " HTTP/1.0\r\n"); | |
1164 | |
1165 strcat(buffer, "User-Agent: " YAHOO_USER_AGENT "\r\n"); | |
1166 strcat(buffer, "Host: " YAHOO_DATA_HOST "\r\n"); | |
1167 strcat(buffer, "Cookie: "); | |
1168 strcat(buffer, ctx->cookie); | |
1169 strcat(buffer, "\r\n"); | |
1170 strcat(buffer, "\r\n"); | |
1171 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1172 if (writeall(servfd, buffer, strlen(buffer)) < strlen(buffer)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1173 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1174 close(servfd); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1175 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1176 } |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1177 |
1054 | 1178 while (yahoo_tcp_readline(buffer, 5000, servfd) > 0) |
1179 { | |
1180 /* just dump the output, I don't care about errors at the moment */ | |
1181 } | |
1182 close(servfd); | |
1183 servfd = 0; | |
1184 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1185 /* indicate success for now with 1 */ |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1186 return 1; |
1054 | 1187 } |
1188 | |
1189 /* Retrieve the configuration from the server */ | |
1190 int yahoo_get_config(struct yahoo_context *ctx) | |
1191 { | |
1192 char buffer[5000]; | |
1193 int i, j; | |
1194 int servfd; | |
1195 int commas; | |
1196 int in_section; | |
1197 struct yahoo_buddy **buddylist = NULL; | |
1198 int buddycnt = 0; | |
1199 int nextbuddy = 0; | |
1200 | |
1201 /* Check for cached cookie */ | |
1202 if (!ctx || !ctx->cookie) | |
1203 { | |
1204 return 0; | |
1205 } | |
1206 | |
1207 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_get_config: starting\n"); | |
1208 | |
1209 if (ctx->connect_mode == YAHOO_CONNECT_HTTPPROXY) | |
1210 { | |
1211 servfd = yahoo_socket_connect(ctx, ctx->proxy_host, ctx->proxy_port); | |
1212 } | |
1213 else | |
1214 { | |
1215 servfd = yahoo_socket_connect(ctx, YAHOO_DATA_HOST, YAHOO_DATA_PORT); | |
1216 } | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1217 if (servfd < 0) |
1054 | 1218 { |
1219 yahoo_dbg_Print("libyahoo", | |
1220 "[libyahoo] yahoo_get_config: failed to connect\n"); | |
1221 return (0); | |
1222 } | |
1223 | |
1224 strcpy(buffer, "GET "); | |
1225 if (ctx->connect_mode == YAHOO_CONNECT_HTTPPROXY) | |
1226 { | |
1227 strcat(buffer, "http://" YAHOO_DATA_HOST); | |
1228 } | |
1229 strcat(buffer, "/config/get_buddylist?.src=bl HTTP/1.0\r\n"); | |
1230 strcat(buffer, "Cookie: "); | |
1231 strcat(buffer, ctx->cookie); | |
1232 strcat(buffer, "\r\n"); | |
1233 strcat(buffer, "\r\n"); | |
1234 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1235 if (writeall(servfd, buffer, strlen(buffer)) < strlen(buffer)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1236 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1237 close(servfd); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1238 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1239 } |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1240 |
1054 | 1241 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_get_config: sending '%s'\n", |
1242 buffer); | |
1243 | |
1244 in_section = 0; | |
1245 while (yahoo_tcp_readline(buffer, 5000, servfd) > 0) | |
1246 { | |
1247 /* strip out any non-alphas */ | |
1248 for (i = 0; i < strlen(buffer); i++) | |
1249 { | |
1250 if (!isprint((int) buffer[i])) | |
1251 { | |
1252 for (j = i; j < strlen(buffer); j++) | |
1253 { | |
1254 buffer[j] = buffer[j + 1]; | |
1255 } | |
1256 } | |
1257 } | |
1258 | |
1259 yahoo_dbg_Print("libyahoo", | |
1260 "[libyahoo] yahoo_get_config: read '%s'\n", buffer); | |
1261 | |
1262 if (!strcasecmp(buffer, "BEGIN IDENTITIES")) | |
1263 { | |
1264 in_section = 1; | |
1265 } | |
1266 else if (!strcasecmp(buffer, "END IDENTITIES")) | |
1267 { | |
1268 in_section = 0; | |
1269 } | |
1270 else if (!strcasecmp(buffer, "BEGIN BUDDYLIST")) | |
1271 { | |
1272 in_section = 2; | |
1273 } | |
1274 else if (!strcasecmp(buffer, "END BUDDYLIST")) | |
1275 { | |
1276 in_section = 0; | |
1277 } | |
1278 else if (in_section == 1) | |
1279 { | |
1280 char *tmp; | |
1281 | |
1282 /* count the commas */ | |
1283 commas = 0; | |
1284 for (i = 0; i < strlen(buffer); i++) | |
1285 { | |
1286 if (buffer[i] == ',') | |
1287 { | |
1288 commas++; | |
1289 } | |
1290 } | |
1291 | |
1292 /* make sure we've gotten rid of any previous identities array */ | |
1293 yahoo_free_identities(ctx); | |
1294 | |
1295 /* allocate the array to hold the list of identities */ | |
1296 ctx->identities = (char **) calloc(commas + 2, sizeof(char *)); | |
1297 | |
1298 /* Parse through the list and get all the entries */ | |
1299 i = 0; | |
1300 tmp = strtok(buffer, ","); | |
1301 while (tmp) | |
1302 { | |
1303 yahoo_dbg_Print("libyahoo", | |
1304 "[libyahoo] yahoo_get_config: retrieved " | |
1305 "identity '%s'\n", tmp); | |
1306 ctx->identities[i++] = strdup(tmp); | |
1307 tmp = strtok(NULL, ","); | |
1308 } | |
1309 ctx->identities[i] = 0; | |
1310 } | |
1311 else if (in_section == 2) | |
1312 { | |
1313 char *group; | |
1314 char *tmp; | |
1315 struct yahoo_buddy **tmp_buddylist; | |
1316 struct yahoo_buddy *tmpbuddy; | |
1317 int tmp_buddycnt; | |
1318 | |
1319 /* count the buddies on this line */ | |
1320 tmp_buddycnt = buddycnt; | |
1321 for (i = 0; i < strlen(buffer); i++) | |
1322 { | |
1323 if (buffer[i] == ',') | |
1324 { | |
1325 buddycnt++; | |
1326 } | |
1327 } | |
1328 buddycnt++; /* always one more than comma count */ | |
1329 | |
1330 /* allocate the array to hold the list of buddy */ | |
1331 tmp_buddylist = (struct yahoo_buddy **) | |
1332 malloc(sizeof(struct yahoo_buddy *) * (buddycnt + 1)); | |
1333 | |
1334 /* Free and copy the old one if necessary */ | |
1335 if (buddylist) | |
1336 { | |
1337 memcpy(tmp_buddylist, buddylist, | |
1338 | |
1339 (tmp_buddycnt + 1) * sizeof(struct yahoo_buddy *)); | |
1340 | |
1341 FREE(buddylist); | |
1342 } | |
1343 buddylist = tmp_buddylist; | |
1344 | |
1345 /* Parse through the list and get all the entries */ | |
1346 tmp = strtok(buffer, ",:"); | |
1347 group = NULL; | |
1348 while (tmp) | |
1349 { | |
1350 if (tmp == buffer) /* group name */ | |
1351 { | |
1352 group = tmp; | |
1353 } | |
1354 else | |
1355 { | |
1356 tmpbuddy = (struct yahoo_buddy *) | |
1357 | |
1358 malloc(sizeof(struct yahoo_buddy)); | |
1359 | |
1360 tmpbuddy->id = strdup(tmp); | |
1361 tmpbuddy->group = strdup(group); | |
1362 yahoo_dbg_Print("libyahoo", | |
1363 "[libyahoo] yahoo_get_config: retrieved buddy '%s:%s'\n", | |
1364 group, tmp); | |
1365 buddylist[nextbuddy++] = tmpbuddy; | |
1366 } | |
1367 tmp = strtok(NULL, ","); | |
1368 } | |
1369 buddylist[nextbuddy] = 0; | |
1370 } | |
1371 else if (!strncasecmp(buffer, "Mail=", strlen("Mail="))) | |
1372 { | |
1373 ctx->mail = atoi(buffer + strlen("Mail=")); | |
1374 yahoo_dbg_Print("libyahoo", | |
1375 "[libyahoo] yahoo_get_config: retrieved mail flag '%d'\n", | |
1376 ctx->mail); | |
1377 } | |
1378 else if (!strncasecmp(buffer, "Login=", strlen("Login="))) | |
1379 { | |
1380 FREE(ctx->login_id); | |
1381 ctx->login_id = strdup(buffer + strlen("Login=")); | |
1382 yahoo_dbg_Print("libyahoo", | |
1383 "[libyahoo] yahoo_get_config: retrieved login id '%s'\n", | |
1384 ctx->login_id); | |
1385 } | |
1386 } | |
1387 close(servfd); | |
1388 servfd = 0; | |
1389 | |
1390 yahoo_free_buddies(ctx); | |
1391 ctx->buddies = buddylist; | |
1392 | |
1393 /* fill in a bogus login_in, just in case */ | |
1394 if (!ctx->login_id) | |
1395 { | |
1396 ctx->login_id = strdup(ctx->user); | |
1397 } | |
1398 | |
1399 /* refetch the cookie if the login_id is different so that | |
1400 it will have the correct info in it */ | |
1401 if (strcmp(ctx->login_id, ctx->user)) | |
1402 { | |
1403 yahoo_dbg_Print("libyahoo", | |
1404 "[libyahoo] yahoo_get_config - refetching cookies\n"); | |
1405 yahoo_fetchcookies(ctx); | |
1406 } | |
1407 | |
1408 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_get_config - finished\n"); | |
1409 | |
1410 return 1; | |
1411 } | |
1412 | |
1413 /* Log in, optionally activating other secondary identities */ | |
1414 int yahoo_cmd_logon(struct yahoo_context *ctx, unsigned int initial_status) | |
1415 { | |
1416 char login_string[5000]; /* need to change to malloc ASAP */ | |
1417 char *tmpid; | |
1418 char **identities = ctx->identities; | |
1419 int i; | |
1420 | |
1421 if (!ctx || !ctx->login_cookie) | |
1422 { | |
1423 yahoo_dbg_Print("libyahoo", | |
1424 "[libyahoo] yahoo_cmd_logon: logon called without " | |
1425 "context and/or cookie.\n"); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1426 return 0; |
1054 | 1427 } |
1428 | |
1429 strcpy(login_string, ctx->login_cookie); | |
1430 /* testing with new logon code */ | |
1431 // strcpy(login_string, "$1$_2S43d5f$XXXXXXXXWtRKNclLWyy8C."); | |
1432 | |
1433 login_string[strlen(login_string) + 1] = 0; | |
1434 login_string[strlen(login_string)] = 1; /* control-A */ | |
1435 | |
1436 strcat(login_string, ctx->user); | |
1437 | |
1438 /* Send all identities */ | |
1439 if (identities) | |
1440 { | |
1441 i = 0; | |
1442 tmpid = identities[i]; | |
1443 while (tmpid) | |
1444 { | |
1445 if (strcasecmp(tmpid, ctx->user)) | |
1446 { | |
1447 strcat(login_string, ","); | |
1448 strcat(login_string, tmpid); | |
1449 } | |
1450 tmpid = identities[i++]; | |
1451 } | |
1452 } | |
1453 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1454 if(!yahoo_sendcmd(ctx, YAHOO_SERVICE_LOGON, ctx->user, login_string, |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1455 initial_status)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1456 return 0; |
1054 | 1457 |
1458 /* something that the windows one sends, not sure what it is */ | |
1459 #if 0 | |
1460 login_string[0] = 0; | |
1461 strcat(login_string, "C=0\002"); | |
1462 strcat(login_string, "F=0,P=0,H=0,S=0,W=0,O=0\002"); | |
1463 strcat(login_string, "M=0,P=0,C=0,S=0"); | |
1464 yahoo_sendcmd(ctx, YAHOO_SERVICE_PASSTHROUGH2, ctx->user, login_string, | |
1465 0); | |
1466 #endif | |
1467 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1468 return 1; |
1054 | 1469 } |
1470 | |
1471 int yahoo_connect(struct yahoo_context *ctx) | |
1472 { | |
1473 int res; | |
1474 | |
1475 res = 0; | |
1476 ctx->sockfd = 0; | |
1477 | |
1478 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_connect - starting\n"); | |
1479 | |
1480 switch (ctx->connect_mode) | |
1481 { | |
1482 case YAHOO_CONNECT_SOCKS4: | |
1483 case YAHOO_CONNECT_SOCKS5: | |
1484 case YAHOO_CONNECT_NORMAL: | |
1485 yahoo_dbg_Print("libyahoo", | |
1486 "[libyahoo] yahoo_connect - establishing socket connection\n"); | |
1487 ctx->sockfd = | |
1488 yahoo_socket_connect(ctx, YAHOO_PAGER_HOST, YAHOO_PAGER_PORT); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1489 if (ctx->sockfd < 0) |
1054 | 1490 { |
1491 printf("[libyahoo] couldn't connect to pager host\n"); | |
1492 return (0); | |
1493 } | |
1494 break; | |
1495 | |
1496 case YAHOO_CONNECT_HTTP: | |
1497 case YAHOO_CONNECT_HTTPPROXY: | |
1498 yahoo_dbg_Print("libyahoo", | |
1499 "[libyahoo] yahoo_connect - no connect for HTTP\n"); | |
1500 /* no pager connection will be established for this */ | |
1501 break; | |
1502 | |
1503 default: | |
1504 printf("[libyahoo] unhandled connect mode (%d)\n", | |
1505 ctx->connect_mode); | |
1506 } | |
1507 | |
1508 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_connect - finished\n"); | |
1509 return (1); | |
1510 } | |
1511 | |
1512 /* Send a packet to the server via http connection method */ | |
1513 /* at moment only handles regular http connection, once I have that | |
1514 working, this code needs to also do http proxy connections as well */ | |
1515 int yahoo_sendcmd_http(struct yahoo_context *ctx, struct yahoo_rawpacket *pkt) | |
1516 { | |
1517 int sockfd; | |
1518 char buffer[5000]; | |
1519 char tmpbuf[1000]; | |
1520 int size; | |
1521 int res; | |
1522 | |
1523 if (!ctx || !pkt) | |
1524 { | |
1525 return (0); | |
1526 } | |
1527 | |
1528 size = YAHOO_PACKET_HEADER_SIZE + strlen(pkt->content) + 1; | |
1529 | |
1530 if (ctx->connect_mode == YAHOO_CONNECT_HTTPPROXY) | |
1531 { | |
1532 sockfd = yahoo_socket_connect(ctx, ctx->proxy_host, ctx->proxy_port); | |
1533 } | |
1534 else | |
1535 { | |
1536 sockfd = yahoo_socket_connect(ctx, YAHOO_PAGER_HTTP_HOST, | |
1537 YAHOO_PAGER_HTTP_PORT); | |
1538 } | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1539 if (sockfd < 0) |
1054 | 1540 { |
1541 printf("[libyahoo] failed to connect to pager http server.\n"); | |
1542 return (0); | |
1543 } | |
1544 | |
1545 strcpy(buffer, "POST "); | |
1546 if (ctx->connect_mode == YAHOO_CONNECT_HTTPPROXY) | |
1547 { | |
1548 strcat(buffer, "http://" YAHOO_PAGER_HTTP_HOST); | |
1549 } | |
1550 strcat(buffer, "/notify HTTP/1.0\r\n"); | |
1551 | |
1552 strcat(buffer, "User-Agent: " YAHOO_USER_AGENT "\r\n"); | |
1553 strcat(buffer, "Host: " YAHOO_PAGER_HTTP_HOST "\r\n"); | |
1554 snprintf(tmpbuf, 1000, "Content-Length: %d\r\n", size); | |
1555 strcat(buffer, tmpbuf); | |
1556 | |
1557 strcat(buffer, "Pragma: No-Cache\r\n"); | |
1558 | |
1559 strcat(buffer, "Cookie: "); | |
1560 strcat(buffer, ctx->cookie); | |
1561 strcat(buffer, "\r\n"); | |
1562 strcat(buffer, "\r\n"); | |
1563 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1564 if ((writeall(sockfd, buffer, strlen(buffer)) < strlen(buffer)) || |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1565 (writeall(sockfd, pkt, size) < size) || |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1566 (writeall(sockfd, "\r\n", 2) < 2)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1567 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1568 close(sockfd); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1569 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1570 } |
1054 | 1571 |
1572 /* now we need to read the results */ | |
1573 /* I'm taking the cheat approach and just dumping them onto the | |
1574 buffer, headers and all, the _skip_to_YHOO_ code will handle it | |
1575 for now */ | |
1576 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1577 while ((res = readall(sockfd, buffer, sizeof(buffer))) > 0) |
1054 | 1578 { |
1579 if (res == -1) | |
1580 { | |
1581 printf("[libyahoo] Error reading data from server.\n"); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1582 return 0; |
1054 | 1583 } |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1584 if (!yahoo_addtobuffer(ctx, buffer, res)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1585 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1586 close(sockfd); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1587 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1588 } |
1054 | 1589 } |
1590 close(sockfd); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1591 |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1592 return (1); |
1054 | 1593 } |
1594 | |
1595 /* Send a packet to the server, called by all routines that want to issue | |
1596 a command. */ | |
1597 int yahoo_sendcmd(struct yahoo_context *ctx, int service, char *active_nick, | |
1598 char *content, unsigned int msgtype) | |
1599 { | |
1600 int size; | |
1601 struct yahoo_rawpacket *pkt; | |
1602 int maxcontentsize; | |
1603 | |
1604 /* why the )&*@#$( did they hardwire the packet size that gets sent | |
1605 when the size of the packet is included in what is sent, bizarre */ | |
1606 size = 4 * 256 + YAHOO_PACKET_HEADER_SIZE; | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1607 if (!(pkt = (struct yahoo_rawpacket *) calloc(1, size))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1608 return 0; |
1054 | 1609 |
1610 /* figure out max content length, including trailing null */ | |
1611 maxcontentsize = size - sizeof(struct yahoo_rawpacket); | |
1612 | |
1613 /* Build the packet */ | |
1614 strcpy(pkt->version, YAHOO_PROTOCOL_HEADER); | |
1615 yahoo_storeint(pkt->len, size); | |
1616 yahoo_storeint(pkt->service, service); | |
1617 | |
1618 /* not sure if this is valid with YPNS1.4 or if it needs 2.0 */ | |
1619 yahoo_storeint(pkt->msgtype, msgtype); | |
1620 | |
1621 /* Not sure, but might as well send for regular connections as well. */ | |
1622 yahoo_storeint(pkt->magic_id, ctx->magic_id); | |
1623 strcpy(pkt->nick1, ctx->login_id); | |
1624 strcpy(pkt->nick2, active_nick); | |
1625 strncpy(pkt->content, content, maxcontentsize); | |
1626 | |
1627 // yahoo_hexdump("send_cmd", (char *) pkt, size); | |
1628 | |
1629 switch (ctx->connect_mode) | |
1630 { | |
1631 case YAHOO_CONNECT_SOCKS4: | |
1632 case YAHOO_CONNECT_SOCKS5: | |
1633 case YAHOO_CONNECT_NORMAL: | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1634 if (writeall(ctx->sockfd, pkt, size) < size) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1635 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1636 printf("sendcmd: writeall failed\n"); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1637 close(ctx->sockfd); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1638 FREE(pkt); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1639 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1640 } |
1054 | 1641 break; |
1642 case YAHOO_CONNECT_HTTP: | |
1643 case YAHOO_CONNECT_HTTPPROXY: | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1644 if (!yahoo_sendcmd_http(ctx, pkt)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1645 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1646 printf("sendcmd_http failed\n"); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1647 FREE(pkt); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1648 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1649 } |
1054 | 1650 break; |
1651 } | |
1652 | |
1653 FREE(pkt); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1654 return (1); |
1054 | 1655 } |
1656 | |
1657 int yahoo_cmd_ping(struct yahoo_context *ctx) | |
1658 { | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1659 return yahoo_sendcmd(ctx, YAHOO_SERVICE_PING, ctx->user, "", 0); |
1054 | 1660 } |
1661 | |
1662 int yahoo_cmd_idle(struct yahoo_context *ctx) | |
1663 { | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1664 return yahoo_sendcmd(ctx, YAHOO_SERVICE_IDLE, ctx->user, "", 0); |
1054 | 1665 } |
1666 | |
1667 int yahoo_cmd_sendfile(struct yahoo_context *ctx, char *active_user, | |
1668 char *touser, char *msg, char *filename) | |
1669 { | |
1670 yahoo_dbg_Print("libyahoo", "yahoo_cmd_sendfile not implemented yet!"); | |
1671 return (0); | |
1672 } | |
1673 | |
1674 int yahoo_cmd_msg(struct yahoo_context *ctx, char *active_user, | |
1675 char *touser, char *msg) | |
1676 { | |
1677 char *content; | |
1678 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1679 if (!(content = (char *) malloc(strlen(touser) + strlen(msg) + 5))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1680 return 0; |
1054 | 1681 |
1682 if (strlen(touser)) | |
1683 { | |
1684 sprintf(content, "%s,%s", touser, msg); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1685 if (!yahoo_sendcmd(ctx, YAHOO_SERVICE_MESSAGE, active_user, content, 0)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1686 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1687 FREE(content); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1688 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1689 } |
1054 | 1690 } |
1691 | |
1692 FREE(content); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1693 return (1); |
1054 | 1694 } |
1695 | |
1696 int yahoo_cmd_msg_offline(struct yahoo_context *ctx, char *active_user, | |
1697 char *touser, char *msg) | |
1698 { | |
1699 char *content; | |
1700 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1701 if (!(content = (char *) malloc(strlen(touser) + strlen(msg) + 5))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1702 return 0; |
1054 | 1703 |
1704 if (strlen(touser)) | |
1705 { | |
1706 sprintf(content, "%s,%s", touser, msg); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1707 if (!yahoo_sendcmd(ctx, YAHOO_SERVICE_MESSAGE, active_user, |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1708 content, YAHOO_MSGTYPE_KNOWN_USER)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1709 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1710 FREE(content); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1711 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1712 } |
1054 | 1713 } |
1714 | |
1715 FREE(content); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1716 return (1); |
1054 | 1717 } |
1718 | |
1719 /* appended the " " so that won't trigger yahoo bug - hack for the moment */ | |
1720 int yahoo_cmd_set_away_mode(struct yahoo_context *ctx, int status, char *msg) | |
1721 { | |
1722 char statusstring[500]; | |
1723 | |
1724 yahoo_dbg_Print("libyahoo", | |
1725 "[libyahoo] yahoo_cmd_set_away_mode: set status (%d), msg(%s)\n", | |
1726 status, yahoo_dbg_NullCheck(msg)); | |
1727 | |
1728 if (status == YAHOO_STATUS_CUSTOM) | |
1729 { | |
1730 if (msg && msg[0] != 0) | |
1731 { | |
1732 snprintf(statusstring, 500, "%d%c%s", status, 1, msg); | |
1733 } | |
1734 else | |
1735 { | |
1736 snprintf(statusstring, 500, "%d%c---", status, 1); | |
1737 } | |
1738 } | |
1739 else | |
1740 { | |
1741 snprintf(statusstring, 500, "%d", status); | |
1742 } | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1743 return yahoo_sendcmd(ctx, YAHOO_SERVICE_ISAWAY, ctx->user, statusstring, 0); |
1054 | 1744 } |
1745 | |
1746 int yahoo_cmd_set_back_mode(struct yahoo_context *ctx, int status, char *msg) | |
1747 { | |
1748 char statusstring[500]; | |
1749 | |
1750 yahoo_dbg_Print("libyahoo", | |
1751 "[libyahoo] yahoo_cmd_set_back_mode: set status (%d), msg(%s)\n", | |
1752 status, yahoo_dbg_NullCheck(msg)); | |
1753 | |
1754 snprintf(statusstring, 500, "%d%c%s ", status, 1, msg ? msg : ""); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1755 return yahoo_sendcmd(ctx, YAHOO_SERVICE_ISBACK, ctx->user, statusstring, 0); |
1054 | 1756 } |
1757 | |
1758 int yahoo_cmd_activate_id(struct yahoo_context *ctx, char *newid) | |
1759 { | |
1760 if (strlen(newid)) | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1761 return yahoo_sendcmd(ctx, YAHOO_SERVICE_IDACT, newid, newid, 0); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1762 return 0; |
1054 | 1763 } |
1764 | |
1765 int yahoo_cmd_user_status(struct yahoo_context *ctx) | |
1766 { | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1767 return yahoo_sendcmd(ctx, YAHOO_SERVICE_USERSTAT, ctx->user, "", 0); |
1054 | 1768 } |
1769 | |
1770 int yahoo_cmd_logoff(struct yahoo_context *ctx) | |
1771 { | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1772 return yahoo_sendcmd(ctx, YAHOO_SERVICE_LOGOFF, ctx->user, ctx->user, 0); |
1054 | 1773 } |
1774 | |
1775 /* | |
1776 | |
1777 yahoo_cmd_start_conf() | |
1778 | |
1779 Starts a conference. (You create the conference) | |
1780 | |
1781 Arguments: | |
1782 char *conf_id == The conference id -- usually of the form name-number, | |
1783 though it doesn't seem to matter much. ex: jaylubo-123 | |
1784 You create this id to start the conference, but pass it | |
1785 along after that. | |
1786 char **userlist == Users to invite. Null terminated array of strings. | |
1787 car *msg == Invitiation message. | |
1788 int type == 0 - normal, 1 - voice (not supported yet) | |
1789 | |
1790 Packet format: | |
1791 id^invited-users^msg^0or1 | |
1792 */ | |
1793 int yahoo_cmd_start_conf(struct yahoo_context *ctx, char *conf_id, | |
1794 char **userlist, char *msg, int type) | |
1795 { | |
1796 char ctrlb = 2; | |
1797 char *content; | |
1798 char *new_userlist = yahoo_array2list(userlist); | |
1799 int cont_len = 0; | |
1800 | |
1801 #ifdef ENABLE_LIBYAHOO_DEBUG | |
1802 char *unraw_msg = NULL; | |
1803 #endif /* def ENABLE_LIBYAHOO_DEBUG */ | |
1804 | |
1805 int size = strlen(conf_id) + strlen(msg) + 8 + strlen(new_userlist); | |
1806 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1807 if (!(content = (char *) malloc(size))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1808 return 0; |
1054 | 1809 memset(content, 0, size); |
1810 | |
1811 cont_len = snprintf(content, | |
1812 size - 1, | |
1813 "%s%c%s%c%s%c%d", | |
1814 conf_id, ctrlb, new_userlist, ctrlb, msg, ctrlb, type); | |
1815 | |
1816 #ifdef ENABLE_LIBYAHOO_DEBUG | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1817 if ((unraw_msg = yahoo_unraw_buffer(content, cont_len))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1818 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1819 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_cmd_start_conf: %s\n", |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1820 unraw_msg); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1821 FREE(unraw_msg); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1822 } |
1054 | 1823 #endif /* def ENABLE_LIBYAHOO_DEBUG */ |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1824 if (!yahoo_sendcmd(ctx, YAHOO_SERVICE_CONFINVITE, ctx->user, content, 0)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1825 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1826 FREE(new_userlist); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1827 FREE(content); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1828 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1829 } |
1054 | 1830 |
1831 FREE(new_userlist); | |
1832 FREE(content); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1833 return 1; |
1054 | 1834 } |
1835 | |
1836 /* | |
1837 yahoo_cmd_conf_logon() | |
1838 | |
1839 Reply to a conference invitation, logs you into conference. | |
1840 | |
1841 Arguments: | |
1842 char *conf_id == The conference id -- usually of the form name-number, | |
1843 though it doesn't seem to matter much. ex: jaylubo-123 | |
1844 This comes from the invitiation. | |
1845 char *host == The person that sent you the invitation. | |
1846 char **userlist == Everyone else invited. This comes from the invitiation. | |
1847 Null terminated array of strings. | |
1848 | |
1849 Packet format: | |
1850 id^all-invited-users-and-host | |
1851 | |
1852 */ | |
1853 int yahoo_cmd_conf_logon(struct yahoo_context *ctx, char *conf_id, | |
1854 char *host, char **userlist) | |
1855 { | |
1856 char ctrlb = 2; | |
1857 char *content; | |
1858 char *new_userlist = yahoo_array2list(userlist); | |
1859 int cont_len = 0; | |
1860 | |
1861 #ifdef ENABLE_LIBYAHOO_DEBUG | |
1862 char *unraw_msg = NULL; | |
1863 #endif /* def ENABLE_LIBYAHOO_DEBUG */ | |
1864 | |
1865 int size = strlen(conf_id) + strlen(host) + 8 + strlen(new_userlist); | |
1866 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1867 if (!(content = (char *) malloc(size))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1868 return 0; |
1054 | 1869 memset(content, 0, size); |
1870 | |
1871 cont_len = | |
1872 sprintf(content, "%s%c%s,%s", conf_id, ctrlb, host, new_userlist); | |
1873 | |
1874 #ifdef ENABLE_LIBYAHOO_DEBUG | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1875 if ((unraw_msg = yahoo_unraw_buffer(content, cont_len))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1876 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1877 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_cmd_conf_logon: %s\n", |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1878 unraw_msg); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1879 FREE(unraw_msg); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1880 } |
1054 | 1881 #endif /* def ENABLE_LIBYAHOO_DEBUG */ |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1882 if (!yahoo_sendcmd(ctx, YAHOO_SERVICE_CONFLOGON, ctx->user, content, 0)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1883 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1884 FREE(new_userlist); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1885 FREE(content); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1886 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1887 } |
1054 | 1888 |
1889 FREE(new_userlist); | |
1890 FREE(content); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1891 return 1; |
1054 | 1892 } |
1893 | |
1894 /* | |
1895 | |
1896 yahoo_cmd_decline_conf() | |
1897 | |
1898 Reply to a conference invitation, decline offer. | |
1899 | |
1900 Arguments: | |
1901 char *conf_id == The conference id -- usually of the form name-number, | |
1902 though it doesn't seem to matter much. ex: jaylubo-123 | |
1903 This comes from the invitiation. | |
1904 char *host == The person that sent you the invitation. | |
1905 char **userlist == Everyone else invited. This comes from the invitiation. | |
1906 Null terminated array of strings. | |
1907 (Null if replying to a conference additional invite ) | |
1908 char *msg == Reason for declining. | |
1909 | |
1910 Packet format: | |
1911 id^all-invited-users-and-host^msg | |
1912 | |
1913 */ | |
1914 int yahoo_cmd_decline_conf(struct yahoo_context *ctx, char *conf_id, | |
1915 char *host, char **userlist, char *msg) | |
1916 { | |
1917 char ctrlb = 2; | |
1918 char *content; | |
1919 char *new_userlist = yahoo_array2list(userlist); | |
1920 | |
1921 int size = | |
1922 strlen(conf_id) + strlen(host) + strlen(msg) + 8 + | |
1923 strlen(new_userlist); | |
1924 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1925 if (!(content = (char *) malloc(size))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1926 return 0; |
1054 | 1927 memset(content, 0, size); |
1928 | |
1929 sprintf(content, "%s%c%s,%s%c%s", conf_id, ctrlb, host, new_userlist, | |
1930 ctrlb, msg); | |
1931 | |
1932 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_cmd_decline_conf: %s\n", | |
1933 content); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1934 if (!yahoo_sendcmd(ctx, YAHOO_SERVICE_CONFDECLINE, ctx->user, content, 0)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1935 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1936 FREE(new_userlist); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1937 FREE(content); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1938 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1939 } |
1054 | 1940 |
1941 FREE(new_userlist); | |
1942 FREE(content); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1943 return 1; |
1054 | 1944 } |
1945 | |
1946 /* | |
1947 | |
1948 yahoo_cmd_conf_logoff() | |
1949 | |
1950 Logoff of a conference. | |
1951 | |
1952 Arguments: | |
1953 char *conf_id == The conference id -- usually of the form name-number, | |
1954 though it doesn't seem to matter much. ex: jaylubo-123 | |
1955 This comes from the invitiation. | |
1956 char **userlist == Everyone in conference. | |
1957 Null terminated array of strings. | |
1958 | |
1959 Packet format: | |
1960 id^all-invited-users | |
1961 | |
1962 */ | |
1963 | |
1964 int yahoo_cmd_conf_logoff(struct yahoo_context *ctx, char *conf_id, | |
1965 char **userlist) | |
1966 { | |
1967 char ctrlb = 2; | |
1968 char *content; | |
1969 int cont_len = 0; | |
1970 | |
1971 #ifdef ENABLE_LIBYAHOO_DEBUG | |
1972 char *unraw_msg = NULL; | |
1973 #endif /* def ENABLE_LIBYAHOO_DEBUG */ | |
1974 char *new_userlist = yahoo_array2list(userlist); | |
1975 | |
1976 int size = strlen(conf_id) + strlen(new_userlist) + 8; | |
1977 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1978 if (!(content = (char *) malloc(size))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1979 return 0; |
1054 | 1980 memset(content, 0, size); |
1981 | |
1982 cont_len = | |
1983 snprintf(content, size, "%s%c%s", conf_id, ctrlb, new_userlist); | |
1984 #ifdef ENABLE_LIBYAHOO_DEBUG | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1985 if ((unraw_msg = yahoo_unraw_buffer(content, cont_len))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1986 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1987 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_cmd_conf_logoff: %s\n", |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1988 unraw_msg); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1989 FREE(unraw_msg); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1990 } |
1054 | 1991 #endif /* def ENABLE_LIBYAHOO_DEBUG */ |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1992 if (!yahoo_sendcmd(ctx, YAHOO_SERVICE_CONFLOGOFF, ctx->user, content, 0)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1993 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1994 FREE(new_userlist); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1995 FREE(content); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1996 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
1997 } |
1054 | 1998 |
1999 FREE(new_userlist); | |
2000 FREE(content); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2001 return 1; |
1054 | 2002 } |
2003 | |
2004 /* | |
2005 | |
2006 yahoo_cmd_conf_invite() | |
2007 | |
2008 Invite another user to an already running conference. | |
2009 | |
2010 Arguments: | |
2011 char *conf_id == The conference id -- usually of the form name-number, | |
2012 though it doesn't seem to matter much. ex: jaylubo-123 | |
2013 This comes from the invitiation. | |
2014 char *invited_user == The person being invited to conference. | |
2015 char **userlist == Everyone else in conference. | |
2016 Null terminated array of strings. | |
2017 char *msg == Invitation message. | |
2018 | |
2019 Packet format: | |
2020 id^invited-user^who-else-in-conf^who-else-in-conf^msg^0 | |
2021 | |
2022 */ | |
2023 | |
2024 int yahoo_cmd_conf_invite(struct yahoo_context *ctx, char *conf_id, | |
2025 char **userlist, char *invited_user, char *msg) | |
2026 { | |
2027 char ctrlb = 2; | |
2028 char *content; | |
2029 char *new_userlist = yahoo_array2list(userlist); | |
2030 | |
2031 int size = strlen(conf_id) + strlen(invited_user) | |
2032 + (2 * strlen(new_userlist)) + strlen(msg) + 7; | |
2033 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2034 if (!(content = (char *) malloc(size))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2035 return 0; |
1054 | 2036 memset(content, 0, size); |
2037 | |
2038 sprintf(content, "%s%c%s%c%s%c%s%c%s%c0", conf_id, ctrlb, | |
2039 invited_user, ctrlb, new_userlist, ctrlb, | |
2040 new_userlist, ctrlb, msg, ctrlb); | |
2041 yahoo_dbg_Print("libyahoo", "[libyahoo] yahoo_cmd_conf_invite: %s\n", | |
2042 content); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2043 if (!yahoo_sendcmd(ctx, YAHOO_SERVICE_CONFADDINVITE, ctx->user, content, 0)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2044 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2045 FREE(new_userlist); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2046 FREE(content); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2047 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2048 } |
1054 | 2049 |
2050 FREE(new_userlist); | |
2051 FREE(content); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2052 return 1; |
1054 | 2053 } |
2054 | |
2055 /* | |
2056 | |
2057 yahoo_cmd_conf_msg() | |
2058 | |
2059 Send a message to everyone in conference. | |
2060 | |
2061 Arguments: | |
2062 char *conf_id == The conference id -- usually of the form name-number, | |
2063 though it doesn't seem to matter much. ex: jaylubo-123 | |
2064 This comes from the invitiation. | |
2065 char **userlist == Everyone in conference. | |
2066 Null terminated array of strings. | |
2067 char *msg == Message to send. | |
2068 | |
2069 Packet format: | |
2070 id^all-invited-users^msg | |
2071 | |
2072 */ | |
2073 int yahoo_cmd_conf_msg(struct yahoo_context *ctx, char *conf_id, | |
2074 char **userlist, char *msg) | |
2075 { | |
2076 char ctrlb = 2; | |
2077 char *content; | |
2078 int cont_len = 0; | |
2079 | |
2080 #ifdef ENABLE_LIBYAHOO_DEBUG | |
2081 char *unraw_msg = NULL; | |
2082 #endif /* def ENABLE_LIBYAHOO_DEBUG */ | |
2083 char *new_userlist = yahoo_array2list(userlist); | |
2084 | |
2085 int size = strlen(conf_id) + strlen(new_userlist) + strlen(msg) + 8; | |
2086 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2087 if (!(content = (char *) malloc(size))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2088 return 0; |
1054 | 2089 memset(content, 0, size); |
2090 | |
2091 cont_len = | |
2092 snprintf(content, size, "%s%c%s%c%s", conf_id, ctrlb, new_userlist, | |
2093 ctrlb, msg); | |
2094 #ifdef ENABLE_LIBYAHOO_DEBUG | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2095 if ((unraw_msg = yahoo_unraw_buffer(content, cont_len))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2096 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2097 yahoo_dbg_Print("libyahoo", "yahoo_cmd_conf_msg: %s\n", unraw_msg); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2098 FREE(unraw_msg); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2099 } |
1054 | 2100 #endif /* def ENABLE_LIBYAHOO_DEBUG */ |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2101 if (!yahoo_sendcmd(ctx, YAHOO_SERVICE_CONFMSG, ctx->user, content, 0)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2102 { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2103 FREE(new_userlist); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2104 FREE(content); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2105 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2106 } |
1054 | 2107 |
2108 FREE(new_userlist); | |
2109 FREE(content); | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2110 return 1; |
1054 | 2111 } |
2112 | |
2113 /* | |
2114 * Free the rawpacket structure - primarily a placeholder | |
2115 * since all static elements at the moment | |
2116 */ | |
2117 void yahoo_free_rawpacket(struct yahoo_rawpacket *pkt) | |
2118 { | |
2119 FREE(pkt); | |
2120 } | |
2121 | |
2122 /* | |
2123 * Free entire packet structure including string elements | |
2124 */ | |
2125 void yahoo_free_packet(struct yahoo_packet *pkt) | |
2126 { | |
2127 int i; | |
2128 | |
2129 if (pkt) | |
2130 { | |
2131 FREE(pkt->real_id); | |
2132 FREE(pkt->active_id); | |
2133 FREE(pkt->conf_id); | |
2134 FREE(pkt->conf_host); | |
2135 FREE(pkt->conf_user); | |
2136 FREE(pkt->conf_msg); | |
2137 FREE(pkt->cal_url); | |
2138 FREE(pkt->cal_timestamp); | |
2139 FREE(pkt->cal_title); | |
2140 FREE(pkt->cal_description); | |
2141 FREE(pkt->chat_invite_content); | |
2142 FREE(pkt->msg_id); | |
2143 FREE(pkt->msg_timestamp); | |
2144 FREE(pkt->msg); | |
2145 FREE(pkt->file_from); | |
2146 FREE(pkt->file_flag); | |
2147 FREE(pkt->file_url); | |
2148 FREE(pkt->file_description); | |
2149 FREE(pkt->group_old); | |
2150 FREE(pkt->group_new); | |
2151 if (pkt->idstatus) | |
2152 { | |
2153 for (i = 0; i < pkt->idstatus_count; i++) | |
2154 { | |
2155 yahoo_free_idstatus(pkt->idstatus[i]); | |
2156 } | |
2157 free(pkt->idstatus); | |
2158 } | |
2159 free(pkt); | |
2160 } | |
2161 } | |
2162 | |
2163 void yahoo_free_idstatus(struct yahoo_idstatus *idstatus) | |
2164 { | |
2165 if (!idstatus) | |
2166 return; | |
2167 | |
2168 FREE(idstatus->id); | |
2169 FREE(idstatus->connection_id); | |
2170 FREE(idstatus->status_msg); | |
2171 FREE(idstatus); | |
2172 } | |
2173 | |
2174 struct yahoo_packet *yahoo_parsepacket(struct yahoo_context *ctx, | |
2175 struct yahoo_rawpacket *inpkt) | |
2176 { | |
2177 struct yahoo_packet *pkt; | |
2178 | |
2179 /* If no valid inpkt passed, return */ | |
2180 if (!inpkt) | |
2181 return NULL; | |
2182 | |
2183 /* Allocate the packet structure, zeroed out */ | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2184 if (!(pkt = (struct yahoo_packet *) calloc(sizeof(*pkt), 1))) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
2185 return NULL; |
1054 | 2186 |
2187 /* Pull out the standard data */ | |
2188 pkt->service = yahoo_makeint(inpkt->service); | |
2189 pkt->connection_id = yahoo_makeint(inpkt->connection_id); | |
2190 pkt->real_id = strdup(inpkt->nick1); | |
2191 pkt->active_id = strdup(inpkt->nick2); | |
2192 | |
2193 pkt->magic_id = yahoo_makeint(inpkt->magic_id); | |
2194 pkt->unknown1 = yahoo_makeint(inpkt->unknown1); | |
2195 pkt->msgtype = yahoo_makeint(inpkt->msgtype); | |
2196 | |
2197 /* doing this seems like a cleaner approach, but am not sure if it is | |
2198 a valid one */ | |
2199 if (pkt->magic_id != 0) | |
2200 { | |
2201 ctx->magic_id = pkt->magic_id; | |
2202 } | |
2203 if (pkt->connection_id != 0) | |
2204 { | |
2205 ctx->connection_id = pkt->connection_id; | |
2206 } | |
2207 | |
2208 /* Call a particular parse routine to pull out the content */ | |
2209 switch (pkt->service) | |
2210 { | |
2211 case YAHOO_SERVICE_LOGON: | |
2212 case YAHOO_SERVICE_LOGOFF: | |
2213 case YAHOO_SERVICE_ISAWAY: | |
2214 case YAHOO_SERVICE_ISBACK: | |
2215 case YAHOO_SERVICE_USERSTAT: | |
2216 case YAHOO_SERVICE_CHATLOGON: | |
2217 case YAHOO_SERVICE_CHATLOGOFF: | |
2218 case YAHOO_SERVICE_GAMELOGON: | |
2219 case YAHOO_SERVICE_GAMELOGOFF: | |
2220 yahoo_parsepacket_status(ctx, pkt, inpkt); | |
2221 break; | |
2222 case YAHOO_SERVICE_IDACT: | |
2223 case YAHOO_SERVICE_IDDEACT: | |
2224 /* nothing needs done, only has main fields */ | |
2225 break; | |
2226 case YAHOO_SERVICE_MESSAGE: | |
2227 case YAHOO_SERVICE_SYSMESSAGE: | |
2228 case YAHOO_SERVICE_CHATMSG: | |
2229 yahoo_parsepacket_message(ctx, pkt, inpkt); | |
2230 break; | |
2231 case YAHOO_SERVICE_NEWMAIL: | |
2232 case YAHOO_SERVICE_NEWPERSONALMAIL: | |
2233 yahoo_parsepacket_newmail(ctx, pkt, inpkt); | |
2234 break; | |
2235 case YAHOO_SERVICE_CALENDAR: | |
2236 yahoo_parsepacket_calendar(ctx, pkt, inpkt); | |
2237 break; | |
2238 case YAHOO_SERVICE_CHATINVITE: | |
2239 yahoo_parsepacket_chatinvite(ctx, pkt, inpkt); | |
2240 break; | |
2241 case YAHOO_SERVICE_NEWCONTACT: | |
2242 yahoo_parsepacket_newcontact(ctx, pkt, inpkt); | |
2243 break; | |
2244 case YAHOO_SERVICE_GROUPRENAME: | |
2245 yahoo_parsepacket_grouprename(ctx, pkt, inpkt); | |
2246 break; | |
2247 case YAHOO_SERVICE_CONFINVITE: | |
2248 yahoo_parsepacket_conference_invite(ctx, pkt, inpkt); | |
2249 break; | |
2250 case YAHOO_SERVICE_CONFLOGON: | |
2251 case YAHOO_SERVICE_CONFLOGOFF: | |
2252 yahoo_parsepacket_conference_user(ctx, pkt, inpkt); | |
2253 break; | |
2254 case YAHOO_SERVICE_CONFDECLINE: | |
2255 yahoo_parsepacket_conference_decline(ctx, pkt, inpkt); | |
2256 break; | |
2257 case YAHOO_SERVICE_CONFADDINVITE: | |
2258 yahoo_parsepacket_conference_addinvite(ctx, pkt, inpkt); | |
2259 break; | |
2260 case YAHOO_SERVICE_CONFMSG: | |
2261 yahoo_parsepacket_conference_msg(ctx, pkt, inpkt); | |
2262 break; | |
2263 case YAHOO_SERVICE_PING: | |
2264 yahoo_parsepacket_ping(ctx, pkt, inpkt); | |
2265 break; | |
2266 case YAHOO_SERVICE_FILETRANSFER: | |
2267 yahoo_parsepacket_filetransfer(ctx, pkt, inpkt); | |
2268 break; | |
2269 default: | |
2270 yahoo_dbg_Print("libyahoo", | |
2271 "yahoo_parsepacket: can't parse packet type (%d)\n", | |
2272 pkt->service); | |
2273 break; | |
2274 } | |
2275 | |
2276 return pkt; | |
2277 } | |
2278 | |
2279 int yahoo_parsepacket_ping(struct yahoo_context *ctx, | |
2280 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt) | |
2281 { | |
2282 char *content; | |
2283 | |
2284 /* Make working copy of content */ | |
2285 content = inpkt->content; | |
2286 | |
2287 pkt->msg = NULL; | |
2288 if (content) | |
2289 pkt->msg = strdup(content); | |
2290 | |
2291 return 0; | |
2292 } | |
2293 | |
2294 int yahoo_parsepacket_newmail(struct yahoo_context *ctx, | |
2295 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt) | |
2296 { | |
2297 char *content; | |
2298 int len; | |
2299 | |
2300 /* Make working copy of content */ | |
2301 content = inpkt->content; | |
2302 len = strlen(content); | |
2303 | |
2304 if (pkt->service == YAHOO_SERVICE_NEWMAIL) | |
2305 { | |
2306 pkt->mail_status = 0; | |
2307 if (len > 0) | |
2308 { | |
2309 pkt->mail_status = atoi(content); | |
2310 } | |
2311 } | |
2312 else if (pkt->service == YAHOO_SERVICE_NEWPERSONALMAIL) | |
2313 { | |
2314 pkt->mail_status = 0; | |
2315 if (len > 0) | |
2316 { | |
2317 pkt->mail_status = atoi(content); | |
2318 } | |
2319 } | |
2320 | |
2321 return 0; | |
2322 } | |
2323 | |
2324 int yahoo_parsepacket_grouprename(struct yahoo_context *ctx, | |
2325 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt) | |
2326 { | |
2327 char *content; | |
2328 char *tmp, delim[5]; | |
2329 | |
2330 /* Make working copy of content */ | |
2331 content = strdup(inpkt->content); | |
2332 | |
2333 /* init elements to all null */ | |
2334 pkt->group_old = NULL; | |
2335 pkt->group_new = NULL; | |
2336 | |
2337 tmp = NULL; | |
2338 delim[0] = 1; /* control-a */ | |
2339 delim[1] = 0; | |
2340 | |
2341 if (content) | |
2342 { | |
2343 tmp = strtok(content, delim); | |
2344 } | |
2345 | |
2346 if (tmp) /* got the conference id */ | |
2347 { | |
2348 pkt->group_old = strdup(tmp); | |
2349 tmp = strtok(NULL, delim); | |
2350 } | |
2351 | |
2352 if (tmp) /* conference host */ | |
2353 { | |
2354 pkt->group_new = strdup(tmp); | |
2355 tmp = strtok(NULL, delim); | |
2356 } | |
2357 | |
2358 FREE(content); | |
2359 return (0); | |
2360 } | |
2361 | |
2362 /* | |
2363 | |
2364 yahoo_parsepacket_conference_invite() | |
2365 | |
2366 Packet format: | |
2367 id^host^invited-users^msg^0or1 | |
2368 | |
2369 Parses Arguments: | |
2370 char *conf_id == The conference id -- usually of the form name-number, | |
2371 though it doesn't seem to matter much. ex: jaylubo-123 | |
2372 char *conf_host == The person inviting you to conference. | |
2373 char **userlist == Everyone else invited to conference. | |
2374 Null terminated array of strings. | |
2375 char *msg == Invitation message. | |
2376 int conf_type == Type of conference ( 0 = text, 1 = voice ) | |
2377 | |
2378 */ | |
2379 int yahoo_parsepacket_conference_invite(struct yahoo_context *ctx, | |
2380 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt) | |
2381 { | |
2382 char *content; | |
2383 char *tmp = 0; | |
2384 size_t found = 0, len = yahoo_makeint(inpkt->len); | |
2385 | |
2386 /* Make working copy of content */ | |
2387 content = memdup(inpkt->content, len); | |
2388 | |
2389 /* init elements to all null */ | |
2390 pkt->conf_id = NULL; | |
2391 pkt->conf_host = NULL; | |
2392 pkt->conf_user = pkt->active_id; | |
2393 pkt->conf_userlist = NULL; | |
2394 pkt->conf_inviter = NULL; | |
2395 pkt->conf_msg = NULL; | |
2396 | |
2397 if (content) | |
2398 { | |
2399 tmp = memtok(content, len, "\002", 2, &found); | |
2400 } | |
2401 | |
2402 if (tmp) /* got the conference id */ | |
2403 { | |
2404 pkt->conf_id = memdupasstr(tmp, found); | |
2405 tmp = memtok(0, 0, "\002", 2, &found); | |
2406 } | |
2407 | |
2408 if (tmp) /* conference host */ | |
2409 { | |
2410 pkt->conf_host = memdupasstr(tmp, found); | |
2411 tmp = memtok(0, 0, "\002", 2, &found); | |
2412 } | |
2413 | |
2414 if (tmp) /* who else is invited */ | |
2415 { | |
2416 char *userlist = memdupasstr(tmp, found); | |
2417 | |
2418 pkt->conf_userlist = yahoo_list2array(userlist); | |
2419 FREE(userlist); | |
2420 tmp = memtok(0, 0, "\002", 2, &found); | |
2421 } | |
2422 | |
2423 if (tmp) /* msg */ | |
2424 { | |
2425 pkt->conf_msg = memdupasstr(tmp, found); | |
2426 tmp = memtok(0, 0, "\002", 2, &found); | |
2427 } | |
2428 | |
2429 if (tmp) /* 0 == text chat 1 == voice chat */ | |
2430 { | |
2431 char *conftype = memdupasstr(tmp, found); | |
2432 | |
2433 if (0 != conftype) | |
2434 pkt->conf_type = atoi(conftype); | |
2435 FREE(conftype); | |
2436 tmp = memtok(0, 0, "\002", 2, &found); | |
2437 } | |
2438 | |
2439 FREE(content); | |
2440 return 0; | |
2441 } | |
2442 | |
2443 /* | |
2444 | |
2445 yahoo_parsepacket_conference_decline() | |
2446 | |
2447 Packet format: | |
2448 id^user-who-declined^msg | |
2449 | |
2450 Parses Arguments: | |
2451 char *conf_id == The conference id -- usually of the form name-number, | |
2452 though it doesn't seem to matter much. ex: jaylubo-123 | |
2453 char *conf_user == User who declined. | |
2454 char *msg == Reason for declining. | |
2455 | |
2456 */ | |
2457 int yahoo_parsepacket_conference_decline(struct yahoo_context *ctx, | |
2458 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt) | |
2459 { | |
2460 char *content; | |
2461 char *tmp, delim[2]; | |
2462 | |
2463 /* Make working copy of content */ | |
2464 content = strdup(inpkt->content); | |
2465 | |
2466 /* init elements to all null */ | |
2467 pkt->conf_id = NULL; | |
2468 pkt->conf_host = NULL; | |
2469 pkt->conf_user = NULL; | |
2470 pkt->conf_userlist = NULL; | |
2471 pkt->conf_inviter = NULL; | |
2472 pkt->conf_msg = NULL; | |
2473 | |
2474 tmp = NULL; | |
2475 delim[0] = 2; /* control-b */ | |
2476 delim[1] = 0; | |
2477 | |
2478 if (content) | |
2479 { | |
2480 tmp = strtok(content, delim); | |
2481 } | |
2482 | |
2483 if (tmp) /* got the conference id */ | |
2484 { | |
2485 pkt->conf_id = strdup(tmp); | |
2486 tmp = strtok(NULL, delim); | |
2487 } | |
2488 if (tmp) /* got the user who declined */ | |
2489 { | |
2490 pkt->conf_user = strdup(tmp); | |
2491 tmp = strtok(NULL, delim); | |
2492 } | |
2493 if (tmp) /* msg */ | |
2494 { | |
2495 pkt->conf_msg = strdup(tmp); | |
2496 tmp = strtok(NULL, delim); | |
2497 } | |
2498 | |
2499 FREE(content); | |
2500 return 0; | |
2501 | |
2502 } | |
2503 | |
2504 /* | |
2505 | |
2506 yahoo_parsepacket_conference_addinvite() | |
2507 | |
2508 Packet format: | |
2509 Msgtype == 1 | |
2510 id^inviter^who-else-invited^who-else-in-conf^msg^0or1 | |
2511 Msgtype == 11 | |
2512 id^inviter^invited-user | |
2513 | |
2514 Parses Arguments: | |
2515 char *conf_id == The conference id -- usually of the form name-number, | |
2516 though it doesn't seem to matter much. ex: jaylubo-123 | |
2517 char *conf_inviter == The person inviting you to conference. | |
2518 char **userlist == Everyone else in conference. | |
2519 Null terminated array of strings. | |
2520 char *msg == Invitation message. | |
2521 int conf_type == Type of conference ( 0 = text, 1 = voice ) | |
2522 | |
2523 char *conf_user == User invited to conference (msgtype == 11) | |
2524 */ | |
2525 int yahoo_parsepacket_conference_addinvite(struct yahoo_context *ctx, | |
2526 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt) | |
2527 { | |
2528 char *content = 0, *tmp = 0; | |
2529 size_t found = 0, len = yahoo_makeint(inpkt->len); | |
2530 | |
2531 /* Make working copy of content */ | |
2532 content = memdup(inpkt->content, len); | |
2533 | |
2534 /* init elements to all null */ | |
2535 pkt->conf_id = NULL; | |
2536 pkt->conf_host = NULL; | |
2537 pkt->conf_user = NULL; | |
2538 pkt->conf_userlist = NULL; | |
2539 pkt->conf_inviter = NULL; | |
2540 pkt->conf_msg = NULL; | |
2541 | |
2542 if (pkt->msgtype == 1) | |
2543 { | |
2544 if (content) | |
2545 { | |
2546 tmp = memtok(content, len, "\002", 2, &found); | |
2547 } | |
2548 | |
2549 if (tmp) /* got the conference id */ | |
2550 { | |
2551 pkt->conf_id = memdupasstr(tmp, found); | |
2552 tmp = memtok(0, 0, "\002", 2, &found); | |
2553 } | |
2554 if (tmp) /* got the inviter */ | |
2555 { | |
2556 pkt->conf_inviter = memdupasstr(tmp, found); | |
2557 tmp = memtok(0, 0, "\002", 2, &found); | |
2558 } | |
2559 if (tmp) /* got who-else-invited */ | |
2560 { | |
2561 /* don't use this field, its the same as the next one | |
2562 so I'm going to use the second field */ | |
2563 /* pkt->conf_userlist = yahoo_list2array(tmp); */ | |
2564 tmp = memtok(0, 0, "\002", 2, &found); | |
2565 } | |
2566 if (tmp) /* got the people in conference | |
2567 not counting the inviter */ | |
2568 { | |
2569 char *userlist = memdupasstr(tmp, found); | |
2570 | |
2571 pkt->conf_userlist = yahoo_list2array(userlist); | |
2572 FREE(userlist); | |
2573 tmp = memtok(0, 0, "\002", 2, &found); | |
2574 } | |
2575 if (tmp) /* got the message */ | |
2576 { | |
2577 pkt->conf_msg = memdupasstr(tmp, found); | |
2578 tmp = memtok(0, 0, "\002", 2, &found); | |
2579 } | |
2580 if (tmp) /* 0 at the end */ | |
2581 { | |
2582 char *conftype = memdupasstr(tmp, found); | |
2583 | |
2584 if (0 != conftype) | |
2585 pkt->conf_type = atoi(conftype); | |
2586 FREE(conftype); | |
2587 /* tmp = memtok (0, 0, "\002", 2, &found); */ | |
2588 } | |
2589 } | |
2590 else | |
2591 /* msgid == 11 (someone else is being invited) */ | |
2592 { | |
2593 if (content) | |
2594 { | |
2595 tmp = memtok(content, len, "\002", 2, &found); | |
2596 } | |
2597 | |
2598 if (tmp) /* got the conference id */ | |
2599 { | |
2600 pkt->conf_id = memdupasstr(tmp, found); | |
2601 tmp = memtok(0, 0, "\002", 2, &found); | |
2602 } | |
2603 | |
2604 if (tmp) /* got the inviter */ | |
2605 { | |
2606 pkt->conf_inviter = memdupasstr(tmp, found); | |
2607 tmp = memtok(0, 0, "\002", 2, &found); | |
2608 } | |
2609 | |
2610 if (tmp) /* got the invited-user */ | |
2611 { | |
2612 pkt->conf_user = memdupasstr(tmp, found); | |
2613 /* tmp = memtok (0, 0, "\002", 2, &found); */ | |
2614 } | |
2615 } | |
2616 | |
2617 FREE(content); | |
2618 return 0; | |
2619 } | |
2620 | |
2621 /* | |
2622 | |
2623 yahoo_parsepacket_conference_msg() | |
2624 | |
2625 Packet format: | |
2626 id^who-from^msg | |
2627 | |
2628 Parses Arguments: | |
2629 char *conf_id == The conference id -- usually of the form name-number, | |
2630 though it doesn't seem to matter much. ex: jaylubo-123 | |
2631 char *conf_user == User who sent message. | |
2632 char *msg == Message. | |
2633 | |
2634 */ | |
2635 int yahoo_parsepacket_conference_msg(struct yahoo_context *ctx, | |
2636 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt) | |
2637 { | |
2638 char *content; | |
2639 char *tmp, delim[5]; | |
2640 | |
2641 /* Make working copy of content */ | |
2642 content = strdup(inpkt->content); | |
2643 | |
2644 /* init elements to all null */ | |
2645 pkt->conf_id = NULL; | |
2646 pkt->conf_host = NULL; | |
2647 pkt->conf_user = NULL; | |
2648 pkt->conf_userlist = NULL; | |
2649 pkt->conf_inviter = NULL; | |
2650 pkt->conf_msg = NULL; | |
2651 | |
2652 tmp = NULL; | |
2653 delim[0] = 2; /* control-b */ | |
2654 delim[1] = 0; | |
2655 | |
2656 /* parse error messages first */ | |
2657 if (pkt->msgtype == YAHOO_MSGTYPE_ERROR) | |
2658 { | |
2659 FREE(content); | |
2660 return 0; | |
2661 } | |
2662 | |
2663 if (content) | |
2664 { | |
2665 tmp = strtok(content, delim); | |
2666 } | |
2667 | |
2668 if (tmp) /* got the conference id */ | |
2669 { | |
2670 pkt->conf_id = strdup(tmp); | |
2671 tmp = strtok(NULL, delim); | |
2672 } | |
2673 | |
2674 if (tmp) /* conference user */ | |
2675 { | |
2676 pkt->conf_user = strdup(tmp); | |
2677 tmp = strtok(NULL, delim); | |
2678 } | |
2679 | |
2680 if (tmp) /* msg */ | |
2681 { | |
2682 pkt->conf_msg = strdup(tmp); | |
2683 tmp = strtok(NULL, delim); | |
2684 } | |
2685 | |
2686 FREE(content); | |
2687 return 0; | |
2688 } | |
2689 | |
2690 /* | |
2691 | |
2692 yahoo_parsepacket_conference_user() | |
2693 (User logged on/off to conference) | |
2694 Packet format: | |
2695 id^user_who_logged_on/off | |
2696 | |
2697 Parses Arguments: | |
2698 char *conf_id == The conference id -- usually of the form name-number, | |
2699 though it doesn't seem to matter much. ex: jaylubo-123 | |
2700 char *conf_user == User who logged on to conference. | |
2701 | |
2702 */ | |
2703 int yahoo_parsepacket_conference_user(struct yahoo_context *ctx, | |
2704 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt) | |
2705 { | |
2706 char *content; | |
2707 char *tmp, delim[5]; | |
2708 | |
2709 /* Make working copy of content */ | |
2710 content = strdup(inpkt->content); | |
2711 | |
2712 /* init elements to all null */ | |
2713 pkt->conf_id = NULL; | |
2714 pkt->conf_host = NULL; | |
2715 pkt->conf_user = NULL; | |
2716 pkt->conf_userlist = NULL; | |
2717 pkt->conf_inviter = NULL; | |
2718 pkt->conf_msg = NULL; | |
2719 | |
2720 tmp = NULL; | |
2721 delim[0] = 2; /* control-b */ | |
2722 delim[1] = 0; | |
2723 | |
2724 if (content) | |
2725 { | |
2726 tmp = strtok(content, delim); | |
2727 } | |
2728 | |
2729 if (tmp) /* got the conference id */ | |
2730 { | |
2731 pkt->conf_id = strdup(tmp); | |
2732 tmp = strtok(NULL, delim); | |
2733 } | |
2734 | |
2735 if (tmp) /* conference user */ | |
2736 { | |
2737 pkt->conf_user = strdup(tmp); | |
2738 tmp = strtok(NULL, delim); | |
2739 } | |
2740 | |
2741 FREE(content); | |
2742 return 0; | |
2743 } | |
2744 | |
2745 int yahoo_parsepacket_filetransfer(struct yahoo_context *ctx, | |
2746 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt) | |
2747 { | |
2748 char *content; | |
2749 char *tmp[5]; | |
2750 int i, j, section; | |
2751 | |
2752 /* Make working copy of content */ | |
2753 content = strdup(inpkt->content); | |
2754 | |
2755 /* init elements to all null */ | |
2756 pkt->file_from = NULL; | |
2757 pkt->file_flag = NULL; | |
2758 pkt->file_url = NULL; | |
2759 pkt->file_expires = 0; | |
2760 pkt->file_description = NULL; | |
2761 | |
2762 /* overkill allocation, but simple since only temporary use */ | |
2763 tmp[0] = strdup(content); | |
2764 tmp[1] = strdup(content); | |
2765 tmp[2] = strdup(content); | |
2766 tmp[3] = strdup(content); | |
2767 tmp[4] = strdup(content); | |
2768 | |
2769 /* raw data format: from,flag,url,timestamp,description */ | |
2770 | |
2771 i = 0; | |
2772 j = 0; | |
2773 section = 0; | |
2774 tmp[0][0] = 0; | |
2775 tmp[1][0] = 0; | |
2776 tmp[2][0] = 0; | |
2777 tmp[3][0] = 0; | |
2778 tmp[4][0] = 0; | |
2779 | |
2780 while (i < strlen(content)) | |
2781 { | |
2782 char ch = content[i]; | |
2783 | |
2784 if (ch == ',' && section < 4) | |
2785 { | |
2786 j = 0; | |
2787 section++; | |
2788 } | |
2789 else | |
2790 { | |
2791 tmp[section][j++] = ch; | |
2792 tmp[section][j] = 0; | |
2793 } | |
2794 i++; | |
2795 } | |
2796 | |
2797 /* do stuff with extracted parts */ | |
2798 pkt->file_from = strdup(tmp[0]); | |
2799 pkt->file_flag = strdup(tmp[1]); | |
2800 pkt->file_url = strdup(tmp[2]); | |
2801 pkt->file_expires = atoi(tmp[3]); | |
2802 pkt->file_description = strdup(tmp[4]); | |
2803 | |
2804 /* free working variables */ | |
2805 FREE(tmp[0]); | |
2806 FREE(tmp[1]); | |
2807 FREE(tmp[2]); | |
2808 FREE(tmp[3]); | |
2809 FREE(tmp[4]); | |
2810 FREE(content); | |
2811 return 0; | |
2812 } | |
2813 | |
2814 int yahoo_parsepacket_calendar(struct yahoo_context *ctx, | |
2815 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt) | |
2816 { | |
2817 char *content; | |
2818 char *tmp, delim[5]; | |
2819 | |
2820 /* Make working copy of content */ | |
2821 content = strdup(inpkt->content); | |
2822 | |
2823 /* init elements to all null */ | |
2824 pkt->cal_url = NULL; | |
2825 pkt->cal_timestamp = NULL; | |
2826 pkt->cal_type = 0; | |
2827 pkt->cal_title = NULL; | |
2828 pkt->cal_description = NULL; | |
2829 | |
2830 tmp = NULL; | |
2831 delim[0] = 2; /* control-b */ | |
2832 delim[1] = 0; | |
2833 | |
2834 if (content) | |
2835 { | |
2836 tmp = strtok(content, delim); | |
2837 } | |
2838 | |
2839 if (tmp) /* got the url */ | |
2840 { | |
2841 pkt->cal_url = strdup(tmp); | |
2842 tmp = strtok(NULL, delim); | |
2843 | |
2844 /* | |
2845 v= is not the type code | |
2846 i= doesn't look like it either | |
2847 tmp2 = strstr(pkt->cal_url, "v="); | |
2848 if ( tmp2 ) | |
2849 { | |
2850 pkt->cal_type = atoi(tmp2); | |
2851 } | |
2852 */ | |
2853 | |
2854 } | |
2855 | |
2856 if (tmp) /* unknown (type code?) */ | |
2857 { | |
2858 /* appears this isn't it either, I don't see where it is */ | |
2859 /* pkt->cal_type = atoi(tmp); */ | |
2860 tmp = strtok(NULL, "\r\n"); | |
2861 } | |
2862 | |
2863 if (tmp) /* timestamp */ | |
2864 { | |
2865 pkt->cal_timestamp = strdup(tmp); | |
2866 tmp = strtok(NULL, "\r\n"); | |
2867 } | |
2868 | |
2869 if (tmp) /* title */ | |
2870 { | |
2871 pkt->cal_title = strdup(tmp); | |
2872 tmp = strtok(NULL, delim); /* use delim since it won't occur again */ | |
2873 } | |
2874 | |
2875 if (tmp) | |
2876 { | |
2877 pkt->cal_description = strdup(tmp); | |
2878 } | |
2879 | |
2880 FREE(content); | |
2881 return 0; | |
2882 } | |
2883 | |
2884 int yahoo_parsepacket_chatinvite(struct yahoo_context *ctx, | |
2885 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt) | |
2886 { | |
2887 char *content; | |
2888 int len; | |
2889 | |
2890 /* Make working copy of content */ | |
2891 content = strdup(inpkt->content); | |
2892 len = strlen(content); | |
2893 | |
2894 /* do special parsing for invite later on */ | |
2895 pkt->chat_invite_content = strdup(content); | |
2896 | |
2897 return 0; | |
2898 } | |
2899 | |
2900 int yahoo_parsepacket_newcontact(struct yahoo_context *ctx, | |
2901 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt) | |
2902 { | |
2903 char *content; | |
2904 int len; | |
2905 | |
2906 /* Make working copy of content */ | |
2907 content = strdup(inpkt->content); | |
2908 len = strlen(content); | |
2909 | |
2910 /* cheat for now, say if first digit is number */ | |
2911 if (len > 0) | |
2912 { | |
2913 if (isdigit((int) content[0])) | |
2914 { | |
2915 return yahoo_parsepacket_status(ctx, pkt, inpkt); | |
2916 } | |
2917 else | |
2918 { | |
2919 return yahoo_parsepacket_message(ctx, pkt, inpkt); | |
2920 } | |
2921 } | |
2922 | |
2923 return 0; | |
2924 } | |
2925 | |
2926 int yahoo_parsepacket_status(struct yahoo_context *ctx, | |
2927 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt) | |
2928 { | |
2929 char *content; | |
2930 char *tmpc; | |
2931 char *tmp1; | |
2932 int i; | |
2933 int len; | |
2934 int index; | |
2935 int realcount; | |
2936 | |
2937 /* Make working copy of content */ | |
2938 content = strdup(inpkt->content); | |
2939 len = strlen(content); | |
2940 | |
2941 /* Pull off the flag from the initial part of the content */ | |
2942 /* this flag indicates the number of buddy that're online */ | |
2943 pkt->flag = 0; | |
2944 tmpc = content; | |
2945 while (tmpc[0] && isdigit((int) tmpc[0])) | |
2946 { | |
2947 pkt->flag = pkt->flag * 10 + (content[0] - '0'); | |
2948 tmpc++; | |
2949 } | |
2950 if (tmpc[0] && tmpc[0] == ',') | |
2951 { | |
2952 tmpc++; | |
2953 } | |
2954 | |
2955 /* | |
2956 We're receiving either this: | |
2957 2,buddy1(0,728EE9FB,0,1,0,0),buddy2(0,7AC00000,0,1,0,0) | |
2958 or this: | |
2959 buddy1(0,728EE9FB,0,1,0,0) | |
2960 hence: | |
2961 */ | |
2962 | |
2963 if (pkt->flag == 0) | |
2964 { | |
2965 pkt->idstatus_count = 1; | |
2966 } | |
2967 else | |
2968 { | |
2969 pkt->idstatus_count = pkt->flag; | |
2970 } | |
2971 | |
2972 /* print an error if I get the was not AWAY */ | |
2973 if (strstr(tmpc, "was not AWAY")) | |
2974 { | |
2975 pkt->idstatus_count = 0; | |
2976 yahoo_dbg_Print("libyahoo", "yahoo_parsepacket_status: " | |
2977 "got a 'was not AWAY' message\n"); | |
2978 } | |
2979 | |
2980 if (pkt->idstatus_count == 0) | |
2981 { | |
2982 /* No entries, so no array needed */ | |
2983 pkt->idstatus = NULL; | |
2984 } | |
2985 else | |
2986 { | |
2987 /* Allocate the array */ | |
2988 pkt->idstatus = (struct yahoo_idstatus **) | |
2989 calloc(sizeof(struct yahoo_idstatus), pkt->idstatus_count); | |
2990 | |
2991 for (i = 0; i < pkt->idstatus_count; i++) | |
2992 { | |
2993 pkt->idstatus[i] = (struct yahoo_idstatus *) | |
2994 | |
2995 calloc(1, sizeof(struct yahoo_idstatus)); | |
2996 } | |
2997 } | |
2998 | |
2999 index = 0; | |
3000 tmp1 = NULL; | |
3001 realcount = 0; | |
3002 while (tmpc && tmpc[0] && pkt->idstatus) | |
3003 { | |
3004 struct yahoo_idstatus *tmpid; | |
3005 | |
3006 /* Get pointer to allocated structure to hold status data */ | |
3007 tmpid = pkt->idstatus[index++]; | |
3008 if (!tmpid) | |
3009 { | |
3010 /* shortcut, we know there can't be any more status entries | |
3011 at this point */ | |
3012 /* yahoo_dbg_Print("status", "null tmpid"); */ | |
3013 break; | |
3014 } | |
3015 | |
3016 /* YPNS2.0 nick(status,msg,connection_id,UNK,in_pager,in_chat,in_game) */ | |
3017 /* tnneul(99,test,message^A,6AD68325,0,1,0,0) */ | |
3018 /* 0 1 2 3 4 5 6 */ | |
3019 | |
3020 /* YPNS1.0 nick(status,connection_id,UNK,in_pager,in_chat,in_game) */ | |
3021 /* nneul(0,7081F531,0,1,0,0) */ | |
3022 /* 0 2 3 4 5 6 */ | |
3023 | |
3024 /* rewrite this whole section in a less ugly fashion */ | |
3025 /* first pull off the id */ | |
3026 | |
3027 /* YUCK - YPNS2.0 has variable format status records, if type is 99, | |
3028 it has 7 fields, second is msg */ | |
3029 | |
3030 #if 0 | |
3031 yahoo_dbg_Print("status", "whole string = '%s'\n", | |
3032 yahoo_dbg_NullCheck(tmpc)); | |
3033 #endif | |
3034 | |
3035 if (tmp1) | |
3036 { | |
3037 tmp1 = strtok(NULL, "("); | |
3038 } | |
3039 else | |
3040 { | |
3041 tmp1 = strtok(tmpc, "("); | |
3042 } | |
3043 if (tmp1 && tmp1[0] == ',') | |
3044 { | |
3045 tmp1++; | |
3046 } | |
3047 | |
3048 if (tmp1) | |
3049 { | |
3050 tmpid->id = strdup(tmp1); | |
3051 realcount++; | |
3052 | |
3053 for (i = 0; i <= 6 && tmp1; i++) | |
3054 { | |
3055 #if 0 | |
3056 yahoo_dbg_Print("status", "i==%d\n", i); | |
3057 #endif | |
3058 | |
3059 if (i == 6) /* end of status area */ | |
3060 { | |
3061 tmp1 = strtok(NULL, "),"); | |
3062 } | |
3063 else if (i == 1) | |
3064 { | |
3065 char delim[3]; | |
3066 | |
3067 if (tmpid->status == YAHOO_STATUS_CUSTOM) | |
3068 { | |
3069 delim[0] = 1; | |
3070 delim[1] = ','; | |
1135
903a6d0938c7
[gaim-migrate @ 1145]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1099
diff
changeset
|
3071 delim[2] = 0; |
1054 | 3072 tmp1 = strtok(NULL, delim); |
3073 } | |
3074 else | |
3075 { | |
3076 i = 2; | |
3077 tmp1 = strtok(NULL, ","); | |
3078 } | |
3079 } | |
3080 else | |
3081 { | |
3082 | |
3083 tmp1 = strtok(NULL, ","); | |
3084 } | |
3085 | |
3086 /* then pull off the particular element of the list */ | |
3087 if (tmp1) | |
3088 { | |
3089 switch (i) | |
3090 { | |
3091 case 0: /* status */ | |
3092 tmpid->status = atoi(tmp1); | |
3093 break; | |
3094 case 1: /* msg */ | |
3095 if (tmpid->status == YAHOO_STATUS_CUSTOM) | |
3096 { | |
3097 tmpid->status_msg = strdup(tmp1); | |
3098 } | |
3099 break; | |
3100 case 2: /* session id */ | |
3101 tmpid->connection_id = strdup(tmp1); | |
3102 break; | |
3103 case 3: /* dunno what this is */ | |
3104 break; | |
3105 case 4: | |
3106 tmpid->in_pager = atoi(tmp1); | |
3107 break; | |
3108 case 5: | |
3109 tmpid->in_chat = atoi(tmp1); | |
3110 break; | |
3111 case 6: | |
3112 tmpid->in_game = atoi(tmp1); | |
3113 break; | |
3114 } | |
3115 } | |
3116 } | |
3117 } | |
3118 } | |
3119 | |
3120 for (i = realcount; i <= pkt->idstatus_count; i++) | |
3121 { | |
3122 if (pkt->idstatus && pkt->idstatus[i]) | |
3123 { | |
3124 FREE(pkt->idstatus[i]); | |
3125 } | |
3126 } | |
3127 pkt->idstatus_count = realcount; | |
3128 | |
3129 /* Free working copy of content */ | |
3130 FREE(content); | |
3131 | |
3132 /* Return ok for success */ | |
3133 return (0); | |
3134 } | |
3135 | |
3136 int yahoo_parsepacket_message(struct yahoo_context *ctx, | |
3137 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt) | |
3138 { | |
3139 char *content; | |
3140 char *tmp_id; | |
3141 int i, j, section; | |
3142 | |
3143 if (pkt->msgtype == YAHOO_MSGTYPE_OFFLINE) | |
3144 { | |
3145 return yahoo_parsepacket_message_offline(ctx, pkt, inpkt); | |
3146 } | |
3147 | |
3148 /* Make working copy of content */ | |
3149 content = strdup(inpkt->content); | |
3150 tmp_id = strdup(content); | |
3151 | |
3152 /* initialize */ | |
3153 pkt->msg_status = 0; | |
3154 | |
3155 /* possible message content formats: */ | |
3156 /* userid(#) *//* msgtype == YAHOO_MSGTYPE_STATUS */ | |
3157 /* userid,,msg */ | |
3158 | |
3159 /* this needed butchered */ | |
3160 /* YAHOO_MSGTYPE_OFFLINE */ | |
3161 /* 6,6,tnneul,nneul,Tue Mar 7 12:14:50 2000,test offline msg^A */ | |
3162 | |
3163 i = 0; | |
3164 j = 0; | |
3165 section = 0; | |
3166 tmp_id[0] = 0; | |
3167 while (i < strlen(content)) | |
3168 { | |
3169 char ch = content[i]; | |
3170 | |
3171 if (section == 0) /* parsing userid */ | |
3172 { | |
3173 if (ch == ',') | |
3174 { | |
3175 j = 0; | |
3176 section = 1; | |
3177 } | |
3178 else if (ch == '(') | |
3179 { | |
3180 j = 0; | |
3181 section = 2; | |
3182 } | |
3183 else | |
3184 { | |
3185 tmp_id[j++] = ch; | |
3186 tmp_id[j] = 0; | |
3187 } | |
3188 } | |
3189 else if (section == 1) /* parsing flag */ | |
3190 { | |
3191 if (ch == ',') | |
3192 { | |
3193 j = 0; | |
3194 section = 3; | |
3195 } | |
3196 } | |
3197 else if (section == 2) /* parsing status */ | |
3198 { | |
3199 if (ch == ')') | |
3200 { | |
3201 j = 0; | |
3202 section = 3; | |
3203 } | |
3204 else | |
3205 { | |
3206 if (isdigit((int) ch)) | |
3207 { | |
3208 pkt->msg_status *= 10; | |
3209 pkt->msg_status += ch - '0'; | |
3210 } | |
3211 } | |
3212 } | |
3213 else | |
3214 { | |
3215 pkt->msg = strdup(&content[i]); | |
3216 break; | |
3217 } | |
3218 | |
3219 i++; | |
3220 } | |
3221 | |
3222 /* do stuff with extracted parts */ | |
3223 pkt->msg_id = strdup(tmp_id); | |
3224 | |
3225 /* handle empty message case */ | |
3226 /* don't pass a message if it's just a status update */ | |
3227 if (!pkt->msg && pkt->msgtype != YAHOO_MSGTYPE_STATUS) | |
3228 { | |
3229 pkt->msg = strdup(""); | |
3230 } | |
3231 | |
3232 /* free working variables */ | |
3233 FREE(tmp_id); | |
3234 FREE(content); | |
3235 | |
3236 /* Return ok for success */ | |
3237 return (0); | |
3238 } | |
3239 | |
3240 /* This parses a special format offline message, and is only currently | |
3241 called from yahoo_parsepacket_message. */ | |
3242 int yahoo_parsepacket_message_offline(struct yahoo_context *ctx, | |
3243 struct yahoo_packet *pkt, struct yahoo_rawpacket *inpkt) | |
3244 { | |
3245 char *content; | |
3246 char *to_id; | |
3247 char *from_id; | |
3248 char *timestamp; | |
3249 int i, j, section; | |
3250 | |
3251 /* Make working copy of content */ | |
3252 content = strdup(inpkt->content); | |
3253 to_id = strdup(content); | |
3254 from_id = strdup(content); | |
3255 timestamp = strdup(content); | |
3256 | |
3257 /* initialize */ | |
3258 pkt->msg_status = 0; | |
3259 | |
3260 /* 6,6,tnneul,nneul,Tue Mar 7 12:14:50 2000,test offline msg^A */ | |
3261 /* sec0,sec1,sec2=to,sec3=from,sec4=tstamp,sec5=msg */ | |
3262 | |
3263 i = 0; | |
3264 j = 0; | |
3265 section = 0; | |
3266 to_id[0] = 0; | |
3267 from_id[0] = 0; | |
3268 timestamp[0] = 0; | |
3269 | |
3270 while (i < strlen(content)) | |
3271 { | |
3272 char ch = content[i]; | |
3273 | |
3274 if (section == 0) /* parsing first unknown number */ | |
3275 { | |
3276 if (ch == ',') | |
3277 { | |
3278 j = 0; | |
3279 section = 1; | |
3280 } | |
3281 } | |
3282 else if (section == 1) /* parsing second unknown number */ | |
3283 { | |
3284 if (ch == ',') | |
3285 { | |
3286 j = 0; | |
3287 section = 2; | |
3288 } | |
3289 } | |
3290 else if (section == 2) /* parsing to-id */ | |
3291 { | |
3292 if (ch == ',') | |
3293 { | |
3294 j = 0; | |
3295 section = 3; | |
3296 } | |
3297 else | |
3298 { | |
3299 to_id[j++] = ch; | |
3300 to_id[j] = 0; | |
3301 } | |
3302 } | |
3303 else if (section == 3) /* parsing from-id */ | |
3304 { | |
3305 if (ch == ',') | |
3306 { | |
3307 j = 0; | |
3308 section = 4; | |
3309 } | |
3310 else | |
3311 { | |
3312 from_id[j++] = ch; | |
3313 from_id[j] = 0; | |
3314 } | |
3315 } | |
3316 else if (section == 4) /* parsing timestamp */ | |
3317 { | |
3318 if (ch == ',') | |
3319 { | |
3320 j = 0; | |
3321 section = 5; | |
3322 } | |
3323 else | |
3324 { | |
3325 timestamp[j++] = ch; | |
3326 timestamp[j] = 0; | |
3327 } | |
3328 } | |
3329 else | |
3330 { | |
3331 pkt->msg = strdup(&content[i]); | |
3332 break; | |
3333 } | |
3334 | |
3335 i++; | |
3336 } | |
3337 | |
3338 /* do stuff with extracted parts */ | |
3339 pkt->msg_id = strdup(from_id); | |
3340 pkt->msg_timestamp = strdup(timestamp); | |
3341 if (pkt->active_id) | |
3342 { | |
3343 FREE(pkt->active_id); | |
3344 pkt->active_id = strdup(to_id); | |
3345 } | |
3346 | |
3347 /* free working variables */ | |
3348 FREE(timestamp); | |
3349 FREE(from_id); | |
3350 FREE(to_id) FREE(content); | |
3351 | |
3352 /* Return ok for success */ | |
3353 return (0); | |
3354 } | |
3355 | |
3356 int yahoo_getdata(struct yahoo_context *ctx) | |
3357 { | |
3358 char buf[1000]; | |
3359 int res; | |
3360 | |
3361 /* This is a http mode connection, so just send a ping to get any | |
3362 new data from the server. */ | |
3363 if (ctx->connect_mode == YAHOO_CONNECT_HTTP || | |
3364 ctx->connect_mode == YAHOO_CONNECT_HTTPPROXY) | |
3365 { | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3366 if (!yahoo_sendcmd(ctx, YAHOO_SERVICE_PING, ctx->user, "", 0)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3367 return 0; |
1054 | 3368 return (1); |
3369 } | |
3370 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3371 /* Read as much data as is available. */ |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3372 /* XXX: doesnt the protocol contain header information with lengths? */ |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3373 do { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3374 res = read(ctx->sockfd, buf, sizeof(buf)); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3375 if ((res == -1) && (errno == EINTR)) |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3376 continue; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3377 break; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3378 } while (1); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3379 |
1054 | 3380 if (res == -1) |
3381 { | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3382 printf("yahoo_getdata: error reading data from server: %s\n", |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3383 strerror(errno)); |
1054 | 3384 return (0); |
3385 } | |
3386 else if (res == 0) | |
3387 { | |
3388 yahoo_dbg_Print("io", | |
3389 "[libyahoo] yahoo_getdata: got zero length read\n", res); | |
3390 return 0; | |
3391 } | |
3392 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3393 yahoo_addtobuffer(ctx, buf, res); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3394 yahoo_dbg_Print("io", "[libyahoo] yahoo_getdata: read (%d) bytes\n", res); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3395 |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3396 return 1; |
1054 | 3397 } |
3398 | |
3399 struct yahoo_rawpacket *yahoo_getpacket(struct yahoo_context *ctx) | |
3400 { | |
3401 struct yahoo_rawpacket *pkt; | |
3402 struct yahoo_rawpacket *retpkt; | |
3403 int *buflen = &ctx->io_buf_curlen; | |
3404 char *buffer = ctx->io_buf; | |
3405 unsigned int contentlen; | |
3406 | |
3407 /* If buffer doesn't start with YHOO, skip bytes until it | |
3408 does. This is to protect against possible packet alignment | |
3409 errors if I size something wrong at any time. */ | |
3410 | |
3411 while ((*buflen >= 4) && (memcmp(buffer, "YHOO", 4))) | |
3412 { | |
3413 /* making quiet for now so I don't have to work too hard on the HTTP support */ | |
3414 #if 0 | |
3415 printf("\nskipped buffer byte (%d)\n", buffer[0]); | |
3416 #endif | |
3417 memmove(buffer, buffer + 1, *buflen - 1); | |
3418 *buflen = *buflen - 1; | |
3419 } | |
3420 | |
3421 /* Don't do anything if the buffer doesn't have at least a full | |
3422 header */ | |
3423 if (*buflen < YAHOO_PACKET_HEADER_SIZE) | |
3424 { | |
3425 // printf("returning null cause buffer is too small\n"); | |
3426 return NULL; | |
3427 } | |
3428 | |
3429 /* print out the beginning of the buffer */ | |
3430 #if 0 | |
3431 printf("Buffer (buflen = %d):\n", *buflen); | |
3432 for (i = 0; i < *buflen; i++) | |
3433 { | |
3434 if ((i) % 10 == 0) | |
3435 { | |
3436 printf("\n%.4d: ", i); | |
3437 } | |
3438 if (isprint(buffer[i])) | |
3439 { | |
3440 printf("%-3d %c ", buffer[i], buffer[i]); | |
3441 } | |
3442 else | |
3443 { | |
3444 printf("%-3d ", buffer[i]); | |
3445 } | |
3446 } | |
3447 printf("\n"); | |
3448 #endif | |
3449 /* Make pkt point to buffer for ease of use */ | |
3450 pkt = (struct yahoo_rawpacket *) buffer; | |
3451 | |
3452 /* Determine the content size specified by the header */ | |
3453 contentlen = yahoo_makeint(pkt->len) - YAHOO_PACKET_HEADER_SIZE; | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3454 #if 0 |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3455 printf("contentlen = %d\n", contentlen); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3456 #endif |
1054 | 3457 |
3458 /* Don't continue if buffer doesn't have full content in it */ | |
3459 if (*buflen < (YAHOO_PACKET_HEADER_SIZE + contentlen)) | |
3460 { | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3461 printf("buffer not big enough for contentlen\n"); |
1054 | 3462 return NULL; |
3463 } | |
3464 | |
3465 /* Copy this packet */ | |
3466 retpkt = | |
3467 (struct yahoo_rawpacket *) malloc(YAHOO_PACKET_HEADER_SIZE + | |
3468 contentlen); | |
3469 memcpy(retpkt, buffer, YAHOO_PACKET_HEADER_SIZE + contentlen); | |
3470 | |
3471 /* Shift the buffer */ | |
3472 memmove(buffer, buffer + YAHOO_PACKET_HEADER_SIZE + contentlen, | |
3473 *buflen - YAHOO_PACKET_HEADER_SIZE - contentlen); | |
3474 | |
3475 /* Adjust the buffer length */ | |
3476 *buflen -= (YAHOO_PACKET_HEADER_SIZE + contentlen); | |
3477 | |
3478 /* Return the packet */ | |
3479 return retpkt; | |
3480 } | |
3481 | |
3482 int yahoo_isbuddy(struct yahoo_context *ctx, const char *id) | |
3483 { | |
3484 int i; | |
3485 char *buddy = NULL; | |
3486 | |
3487 if (!id || !ctx || !ctx->buddies) | |
3488 { | |
3489 return FALSE; | |
3490 } | |
3491 | |
3492 for (i = 0; ctx->buddies[i]; i++) | |
3493 { | |
3494 buddy = (ctx->buddies[i])->id; | |
3495 if (!strcasecmp(id, buddy)) | |
3496 { | |
3497 return TRUE; | |
3498 } | |
3499 } | |
3500 | |
3501 return FALSE; | |
3502 } | |
3503 | |
3504 static void yahoo_free_address (struct yahoo_address *add) | |
3505 { | |
3506 yahoo_dbg_Print("addressbook", | |
3507 "[libyahoo] yahoo_free_address: record at address 0x%08p for user %s (%s %s) being free'd\n", | |
3508 add, add->id, add->firstname, add->lastname); | |
3509 | |
3510 FREE (add->firstname); | |
3511 FREE (add->lastname); | |
3512 FREE (add->emailnickname); | |
3513 FREE (add->email); | |
3514 FREE (add->workphone); | |
3515 FREE (add->homephone); | |
3516 } | |
3517 | |
3518 void yahoo_freeaddressbook(struct yahoo_context *ctx) | |
3519 { | |
3520 unsigned int count = ctx->address_count; | |
3521 struct yahoo_address *add_p = ctx->addresses; | |
3522 | |
3523 if (NULL == ctx || NULL == ctx->addresses) | |
3524 return; | |
3525 | |
3526 while (count-- > 0) | |
3527 { | |
3528 yahoo_free_address (add_p++); | |
3529 } | |
3530 | |
3531 ctx->address_count = 0; | |
3532 FREE (ctx->addresses); | |
3533 } | |
3534 | |
3535 static void yahoo_data_to_addressbook (char *block, struct yahoo_context *ctx) | |
3536 { | |
3537 char *token = NULL; | |
3538 int record = 0; | |
3539 struct yahoo_address *add = NULL; | |
3540 | |
3541 if (NULL == block || NULL == ctx) | |
3542 return; | |
3543 | |
3544 yahoo_freeaddressbook (ctx); | |
3545 | |
3546 add = ctx->addresses = calloc (ctx->address_count, sizeof (struct yahoo_address)); | |
3547 | |
3548 /* | |
3549 Okay! | |
3550 At this point we have a char * (block) that has \012 delimited records | |
3551 Each record (as a string when retreived with strtok) follows the format: | |
3552 <ID>:<FIRSTNAME>\011<LASTNAME>\011<EMAILNICKNAME>\011<EMAIL>\011<HOMEPHONE>\011<WORKPHONE>\011[01]\011<ENTRYID>\000 | |
3553 */ | |
3554 | |
3555 token = strtok (block, "\012"); | |
3556 while (NULL != token) | |
3557 { | |
3558 /* | |
3559 Here we must use memtok because we'll get some repeated tokens!!!!! | |
3560 */ | |
3561 char *field = NULL; | |
3562 size_t token_len = 0, found = 0; | |
3563 | |
3564 ++record; | |
3565 token_len = strlen (token); | |
3566 | |
3567 field = memtok(token, token_len, ":", 1, &found); | |
3568 | |
3569 if (NULL != field) | |
3570 { | |
3571 add->id = memdupasstr(field, found); | |
3572 field = memtok(0, 0, "\011", 1, &found); | |
3573 } | |
3574 | |
3575 if (NULL != field) | |
3576 { | |
3577 add->firstname = memdupasstr(field, found); | |
3578 field = memtok(0, 0, "\011", 1, &found); | |
3579 } | |
3580 | |
3581 if (NULL != field) | |
3582 { | |
3583 add->lastname = memdupasstr(field, found); | |
3584 field = memtok(0, 0, "\011", 1, &found); | |
3585 } | |
3586 | |
3587 if (NULL != field) | |
3588 { | |
3589 add->emailnickname = memdupasstr(field, found); | |
3590 field = memtok(0, 0, "\011", 1, &found); | |
3591 } | |
3592 | |
3593 if (NULL != field) | |
3594 { | |
3595 add->email = memdupasstr(field, found); | |
3596 field = memtok(0, 0, "\011", 1, &found); | |
3597 } | |
3598 | |
3599 if (NULL != field) | |
3600 { | |
3601 add->homephone = memdupasstr(field, found); | |
3602 field = memtok(0, 0, "\011", 1, &found); | |
3603 } | |
3604 | |
3605 if (NULL != field) | |
3606 { | |
3607 add->workphone = memdupasstr(field, found); | |
3608 field = memtok(0, 0, "\011", 1, &found); | |
3609 } | |
3610 | |
3611 if (NULL != field) | |
3612 { | |
3613 add->primary_phone = (*field == '0' ? home : work); | |
3614 field = memtok(0, 0, "", 1, &found); | |
3615 } | |
3616 | |
3617 if (NULL != field) | |
3618 { | |
3619 char *entryid = memdupasstr(field, found); | |
3620 if (NULL != entryid) | |
3621 { | |
3622 add->entryid = atoi (entryid); | |
3623 FREE (entryid); | |
3624 } | |
3625 } | |
3626 | |
3627 yahoo_dbg_Print("addressbook", | |
3628 "[libyahoo] yahoo_fetchaddressbook: record #%d is for user %s (%s %s)\n", | |
3629 record, add->id, add->firstname, add->lastname); | |
3630 | |
3631 ++add; | |
3632 | |
3633 token = strtok (NULL, "\012"); | |
3634 } | |
3635 } | |
3636 | |
3637 /* retreive the details of the friends in your address book that have a Yahoo! id listed */ | |
3638 int yahoo_fetchaddressbook(struct yahoo_context *ctx) | |
3639 { | |
3640 char buffer[5000]; | |
3641 int servfd; | |
3642 int res; | |
3643 int copied = 0, size = 5000; | |
3644 char *address = NULL, *copy = NULL; | |
3645 | |
3646 if (!ctx) | |
3647 { | |
3648 return 0; | |
3649 } | |
3650 | |
3651 yahoo_dbg_Print("addressbook", | |
3652 "[libyahoo] yahoo_fetchaddressbook: starting\n"); | |
3653 | |
3654 /* Check for cached addresses */ | |
3655 if (ctx->addresses) | |
3656 { | |
3657 yahoo_freeaddressbook(ctx); | |
3658 } | |
3659 | |
3660 if (ctx->connect_mode == YAHOO_CONNECT_HTTPPROXY) | |
3661 { | |
3662 servfd = yahoo_socket_connect(ctx, ctx->proxy_host, ctx->proxy_port); | |
3663 } | |
3664 else | |
3665 { | |
3666 servfd = yahoo_socket_connect(ctx, YAHOO_ADDRESS_HOST, YAHOO_ADDRESS_PORT); | |
3667 } | |
3668 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3669 if (servfd < 0) |
1054 | 3670 { |
3671 printf("[libyahoo] failed to connect to address book server.\n"); | |
3672 return (0); | |
3673 } | |
3674 | |
3675 strcpy(buffer, "GET "); | |
3676 if (ctx->connect_mode == YAHOO_CONNECT_HTTPPROXY) | |
3677 { | |
3678 strcat(buffer, YAHOO_ADDRESS_HOST); | |
3679 } | |
3680 strcat(buffer, "/yab/uk/yab?v=PG&A=s"); | |
3681 strcat(buffer, " HTTP/1.0\r\n"); | |
3682 strcat(buffer, "User-Agent: " YAHOO_USER_AGENT "\r\n"); | |
3683 strcat(buffer, "Host: " YAHOO_AUTH_HOST "\r\n"); | |
3684 strcat(buffer, "Cookie: "); | |
3685 strcat(buffer, ctx->cookie); | |
3686 strcat(buffer, "\r\n"); | |
3687 strcat(buffer, "\r\n"); | |
3688 | |
1099
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3689 if (writeall(servfd, buffer, strlen(buffer)) < strlen(buffer)) { |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3690 close(servfd); |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3691 return 0; |
4416ead31db7
[gaim-migrate @ 1109]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1054
diff
changeset
|
3692 } |
1054 | 3693 |
3694 yahoo_dbg_Print("addressbook", | |
3695 "[libyahoo] yahoo_fetchaddressbook: writing buffer '%s'\n", buffer); | |
3696 | |
3697 while ((res = yahoo_tcp_readline(buffer, 5000, servfd)) > 0) | |
3698 { | |
3699 if ('\012' == buffer[0]) | |
3700 continue; | |
3701 | |
3702 if (0 == strncmp (buffer, "1\011", 2)) | |
3703 { | |
3704 yahoo_dbg_Print("addressbook", | |
3705 "[libyahoo] yahoo_fetchaddressbook: found first line\n"); | |
3706 if (3 == res) | |
3707 { | |
3708 yahoo_dbg_Print("addressbook", | |
3709 "[libyahoo] yahoo_fetchaddressbook: however there's been a problem\n"); | |
3710 break; | |
3711 } | |
3712 | |
3713 address = &buffer[2]; | |
3714 } | |
3715 else if (NULL != address) | |
3716 { | |
3717 address = &buffer[0]; | |
3718 } | |
3719 | |
3720 if (NULL != address) | |
3721 { | |
3722 if (NULL == copy) | |
3723 { | |
3724 copy = malloc (size); | |
3725 memset (copy, 0, size); | |
3726 } | |
3727 | |
3728 if ((copied + res) > size) | |
3729 { | |
3730 char *newcopy = NULL; | |
3731 | |
3732 yahoo_dbg_Print("addressbook", | |
3733 "[libyahoo] yahoo_fetchaddressbook: resizing buffer from %d bytes to %d bytes\n", size, size * 2); | |
3734 size *= 2; | |
3735 newcopy = malloc (size); | |
3736 memset (newcopy, 0, size); | |
3737 memcpy (newcopy, copy, copied); | |
3738 free (copy); | |
3739 copy = newcopy; | |
3740 } | |
3741 | |
3742 copied += res; | |
3743 strcat (copy, address); | |
3744 ++ctx->address_count; | |
3745 } | |
3746 } | |
3747 | |
3748 yahoo_data_to_addressbook (copy, ctx); | |
3749 FREE (copy); | |
3750 | |
3751 yahoo_dbg_Print("addressbook", | |
3752 "[libyahoo] yahoo_fetchaddressbook: closing server connection\n"); | |
3753 close(servfd); | |
3754 servfd = 0; | |
3755 yahoo_dbg_Print("addressbook", | |
3756 "[libyahoo] yahoo_fetchaddressbook: closed server connection\n"); | |
3757 | |
3758 yahoo_dbg_Print("addressbook", "[libyahoo] yahoo_fetchaddressbook: done (%d addresses retreived)\n", ctx->address_count); | |
3759 | |
3760 return ctx->address_count; | |
3761 } |