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