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