Tue, 07 Mar 2006 10:33:22 +0000
[gaim-migrate @ 15826]
Fix bug 1444462 - No info displayed in tooltip for AIM contact
This was caused by unescaped entities in the available message.
| 13235 | 1 | /* |
| 2 | * Gaim's oscar protocol plugin | |
| 3 | * This file is the legal property of its developers. | |
| 4 | * Please see the AUTHORS file distributed alongside this file. | |
| 5 | * | |
| 6 | * This library is free software; you can redistribute it and/or | |
| 7 | * modify it under the terms of the GNU Lesser General Public | |
| 8 | * License as published by the Free Software Foundation; either | |
| 9 | * version 2 of the License, or (at your option) any later version. | |
| 10 | * | |
| 11 | * This library is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 | * Lesser General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU Lesser General Public | |
| 17 | * License along with this library; if not, write to the Free Software | |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 | */ | |
| 20 | ||
| 21 | /* | |
| 22 | * Oscar File transfer (OFT) and Oscar Direct Connect (ODC). | |
| 23 | * (ODC is also referred to as DirectIM and IM Image.) | |
| 24 | * | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
25 | * There are a few static helper functions at the top, then |
| 13235 | 26 | * ODC stuff, then ft stuff. |
| 27 | * | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
28 | * I feel like this is a good place to explain OFT, so I'm going to |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
29 | * do just that. Each OFT packet has a header type. I guess this |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
30 | * is pretty similar to the subtype of a SNAC packet. The type |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
31 | * basically tells the other client the meaning of the OFT packet. |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
32 | * There are two distinct types of file transfer, which I usually |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
33 | * call "sendfile" and "getfile." Sendfile is when you send a file |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
34 | * to another AIM user. Getfile is when you share a group of files, |
| 13235 | 35 | * and other users request that you send them the files. |
| 36 | * | |
| 37 | * A typical sendfile file transfer goes like this: | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
38 | * 1) Sender sends a channel 2 ICBM telling the other user that |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
39 | * we want to send them a file. At the same time, we open a |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
40 | * listener socket (this should be done before sending the |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
41 | * ICBM) on some port, and wait for them to connect to us. |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
42 | * The ICBM we sent should contain our IP address and the port |
| 13235 | 43 | * number that we're listening on. |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
44 | * 2) The receiver connects to the sender on the given IP address |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
45 | * and port. After the connection is established, the receiver |
| 13235 | 46 | * sends an ICBM signifying that we are ready and waiting. |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
47 | * 3) The sender sends an OFT PROMPT message over the OFT |
| 13235 | 48 | * connection. |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
49 | * 4) The receiver of the file sends back an exact copy of this |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
50 | * OFT packet, except the cookie is filled in with the cookie |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
51 | * from the ICBM. I think this might be an attempt to verify |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
52 | * that the user that is connected is actually the guy that |
| 13235 | 53 | * we sent the ICBM to. Oh, I've been calling this the ACK. |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
54 | * 5) The sender starts sending raw data across the connection |
| 13235 | 55 | * until the entire file has been sent. |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
56 | * 6) The receiver knows the file is finished because the sender |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
57 | * sent the file size in an earlier OFT packet. So then the |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
58 | * receiver sends the DONE thingy (after filling in the |
| 13235 | 59 | * "received" checksum and size) and closes the connection. |
| 60 | */ | |
| 61 | ||
| 62 | #ifdef HAVE_CONFIG_H | |
| 63 | #include <config.h> | |
| 64 | #endif | |
| 65 | ||
| 66 | #include "oscar.h" | |
| 67 | #include "peer.h" | |
| 68 | ||
| 69 | #ifndef _WIN32 | |
| 70 | #include <stdio.h> | |
| 71 | #include <netdb.h> | |
| 72 | #include <sys/socket.h> | |
| 73 | #include <netinet/in.h> | |
| 74 | #include <sys/utsname.h> /* for aim_odc_initiate */ | |
| 75 | #include <arpa/inet.h> /* for inet_ntoa */ | |
| 76 | #include <limits.h> /* for UINT_MAX */ | |
| 77 | #endif | |
| 78 | ||
| 79 | #ifdef _WIN32 | |
| 80 | #include "win32dep.h" | |
| 81 | #endif | |
| 82 | ||
| 83 | /* | |
| 84 | * I really want to switch all our networking code to using IPv6 only, | |
| 85 | * but that really isn't a good idea at all. Evan S. of Adium says | |
| 86 | * OS X sets all connections as "AF_INET6/PF_INET6," even if there is | |
| 87 | * nothing inherently IPv6 about them. And I feel like Linux kernel | |
| 88 | * 2.6.5 is doing the same thing. So we REALLY should accept | |
| 89 | * connections if they're showing up as IPv6. Old OSes (Solaris?) | |
| 90 | * that might not have full IPv6 support yet will fail if we try | |
| 91 | * to use PF_INET6 but it isn't defined. --Mark Doliner | |
| 92 | */ | |
| 93 | #ifndef PF_INET6 | |
| 94 | #define PF_INET6 PF_INET | |
| 95 | #endif | |
| 96 | ||
| 97 | struct aim_odc_intdata { | |
| 98 | guint8 cookie[8]; | |
| 99 | char sn[MAXSNLEN+1]; | |
| 100 | char ip[22]; | |
| 101 | }; | |
| 102 | ||
| 103 | /** | |
| 104 | * Convert the directory separator from / (0x2f) to ^A (0x01) | |
| 105 | * | |
| 106 | * @param name The filename to convert. | |
| 107 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
108 | static void |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
109 | aim_oft_dirconvert_tostupid(char *name) |
| 13235 | 110 | { |
| 111 | while (name[0]) { | |
| 112 | if (name[0] == 0x01) | |
| 113 | name[0] = G_DIR_SEPARATOR; | |
| 114 | name++; | |
| 115 | } | |
| 116 | } | |
| 117 | ||
| 118 | /** | |
| 119 | * Convert the directory separator from ^A (0x01) to / (0x2f) | |
| 120 | * | |
| 121 | * @param name The filename to convert. | |
| 122 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
123 | static void |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
124 | aim_oft_dirconvert_fromstupid(char *name) |
| 13235 | 125 | { |
| 126 | while (name[0]) { | |
| 127 | if (name[0] == G_DIR_SEPARATOR) | |
| 128 | name[0] = 0x01; | |
| 129 | name++; | |
| 130 | } | |
| 131 | } | |
| 132 | ||
| 133 | /** | |
| 134 | * Calculate oft checksum of buffer | |
| 135 | * | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
136 | * Prevcheck should be 0xFFFF0000 when starting a checksum of a file. The |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
137 | * checksum is kind of a rolling checksum thing, so each time you get bytes |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
138 | * of a file you just call this puppy and it updates the checksum. You can |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
139 | * calculate the checksum of an entire file by calling this in a while or a |
| 13235 | 140 | * for loop, or something. |
| 141 | * | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
142 | * Thanks to Graham Booker for providing this improved checksum routine, |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
143 | * which is simpler and should be more accurate than Josh Myer's original |
| 13235 | 144 | * code. -- wtm |
| 145 | * | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
146 | * This algorithm works every time I have tried it. The other fails |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
147 | * sometimes. So, AOL who thought this up? It has got to be the weirdest |
| 13235 | 148 | * checksum I have ever seen. |
| 149 | * | |
| 150 | * @param buffer Buffer of data to checksum. Man I'd like to buff her... | |
| 151 | * @param bufsize Size of buffer. | |
| 152 | * @param prevcheck Previous checksum. | |
| 153 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
154 | guint32 |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
155 | aim_oft_checksum_chunk(const guint8 *buffer, int bufferlen, guint32 prevcheck) |
| 13235 | 156 | { |
| 157 | guint32 check = (prevcheck >> 16) & 0xffff, oldcheck; | |
| 158 | int i; | |
| 159 | unsigned short val; | |
| 160 | ||
| 161 | for (i=0; i<bufferlen; i++) { | |
| 162 | oldcheck = check; | |
| 163 | if (i&1) | |
| 164 | val = buffer[i]; | |
| 165 | else | |
| 166 | val = buffer[i] << 8; | |
| 167 | check -= val; | |
| 168 | /* | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
169 | * The following appears to be necessary.... It happens |
| 13235 | 170 | * every once in a while and the checksum doesn't fail. |
| 171 | */ | |
| 172 | if (check > oldcheck) | |
| 173 | check--; | |
| 174 | } | |
| 175 | check = ((check & 0x0000ffff) + (check >> 16)); | |
| 176 | check = ((check & 0x0000ffff) + (check >> 16)); | |
| 177 | return check << 16; | |
| 178 | } | |
| 179 | ||
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
180 | guint32 |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
181 | aim_oft_checksum_file(char *filename) |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
182 | { |
| 13235 | 183 | FILE *fd; |
| 184 | guint32 checksum = 0xffff0000; | |
| 185 | ||
| 186 | if ((fd = fopen(filename, "rb"))) { | |
| 187 | int bytes; | |
| 188 | guint8 buffer[1024]; | |
| 189 | ||
| 190 | while ((bytes = fread(buffer, 1, 1024, fd))) | |
| 191 | checksum = aim_oft_checksum_chunk(buffer, bytes, checksum); | |
| 192 | fclose(fd); | |
| 193 | } | |
| 194 | ||
| 195 | return checksum; | |
| 196 | } | |
| 197 | ||
| 198 | /** | |
| 199 | * After establishing a listening socket, this is called to accept a connection. It | |
| 200 | * clones the conn used by the listener, and passes both of these to a signal handler. | |
| 201 | * The signal handler should close the listener conn and keep track of the new conn, | |
| 202 | * since this is what is used for file transfers and what not. | |
| 203 | * | |
| 204 | * @param sess The session. | |
| 205 | * @param cur The conn the incoming connection is on. | |
| 206 | * @return Return 0 if no errors, otherwise return the error number. | |
| 207 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
208 | int |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
209 | aim_handlerendconnect(OscarSession *sess, OscarConnection *cur) |
| 13235 | 210 | { |
| 211 | int acceptfd = 0; | |
| 212 | struct sockaddr addr; | |
| 213 | socklen_t addrlen = sizeof(addr); | |
| 214 | int ret = 0; | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
215 | OscarConnection *newconn; |
| 13235 | 216 | char ip[20]; |
| 217 | unsigned short port; | |
| 218 | ||
| 219 | if ((acceptfd = accept(cur->fd, &addr, &addrlen)) == -1) | |
| 220 | return 0; /* not an error */ | |
| 221 | ||
| 222 | if ((addr.sa_family != PF_INET) && (addr.sa_family != PF_INET6)) { | |
| 223 | close(acceptfd); | |
|
13255
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
224 | aim_conn_close(sess, cur); |
| 13235 | 225 | return -1; |
| 226 | } | |
| 227 | ||
| 228 | strncpy(ip, inet_ntoa(((struct sockaddr_in *)&addr)->sin_addr), sizeof(ip)); | |
| 229 | port = ntohs(((struct sockaddr_in *)&addr)->sin_port); | |
| 230 | ||
| 231 | if (!(newconn = aim_cloneconn(sess, cur))) { | |
| 232 | close(acceptfd); | |
|
13255
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
233 | aim_conn_close(sess, cur); |
| 13235 | 234 | return -ENOMEM; |
| 235 | } | |
| 236 | ||
| 237 | newconn->type = AIM_CONN_TYPE_RENDEZVOUS; | |
| 238 | newconn->fd = acceptfd; | |
| 239 | ||
| 240 | if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) { | |
| 241 | aim_rxcallback_t userfunc; | |
| 242 | struct aim_odc_intdata *priv; | |
| 243 | ||
| 244 | priv = (struct aim_odc_intdata *)(newconn->internal = cur->internal); | |
| 245 | cur->internal = NULL; | |
| 246 | snprintf(priv->ip, sizeof(priv->ip), "%s:%hu", ip, port); | |
| 247 | ||
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
248 | if ((userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, PEER_TYPE_DIRECTIM_ESTABLISHED))) |
| 13235 | 249 | ret = userfunc(sess, NULL, newconn, cur); |
| 250 | ||
| 251 | } else if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE) { | |
| 252 | } else if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_SENDFILE) { | |
| 253 | aim_rxcallback_t userfunc; | |
| 254 | ||
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
255 | if ((userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, PEER_TYPE_ESTABLISHED))) |
| 13235 | 256 | ret = userfunc(sess, NULL, newconn, cur); |
| 257 | ||
| 258 | } else { | |
| 259 | gaim_debug_warning("oscar", "Got a connection on a listener that's not rendezvous. Closing connection.\n"); | |
|
13255
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
260 | aim_conn_close(sess, newconn); |
| 13235 | 261 | ret = -1; |
| 262 | } | |
| 263 | ||
| 264 | return ret; | |
| 265 | } | |
| 266 | ||
| 267 | /** | |
| 268 | * Send client-to-client typing notification over an established direct connection. | |
| 269 | * | |
| 270 | * @param sess The session. | |
| 271 | * @param conn The already-connected ODC connection. | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
272 | * @param typing If 0x0002, sends a "typing" message, 0x0001 sends "typed," and |
| 13235 | 273 | * 0x0000 sends "stopped." |
| 274 | * @return Return 0 if no errors, otherwise return the error number. | |
| 275 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
276 | int |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
277 | aim_odc_send_typing(OscarSession *sess, OscarConnection *conn, int typing) |
| 13235 | 278 | { |
| 279 | struct aim_odc_intdata *intdata = (struct aim_odc_intdata *)conn->internal; | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
280 | FlapFrame *fr; |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
281 | ByteStream *hdrbs; |
| 13235 | 282 | guint8 *hdr; |
| 283 | int hdrlen = 0x44; | |
| 284 | ||
| 285 | if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS)) | |
| 286 | return -EINVAL; | |
| 287 | ||
|
13254
3fbb3f3efba7
[gaim-migrate @ 15619]
Mark Doliner <markdoliner@pidgin.im>
parents:
13253
diff
changeset
|
288 | if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0001, 0))) |
| 13235 | 289 | return -ENOMEM; |
| 290 | memcpy(fr->hdr.rend.magic, "ODC2", 4); | |
| 291 | fr->hdr.rend.hdrlen = hdrlen + 8; | |
| 292 | ||
| 293 | if (!(hdr = calloc(1, hdrlen))) { | |
| 294 | aim_frame_destroy(fr); | |
| 295 | return -ENOMEM; | |
| 296 | } | |
| 297 | ||
| 298 | hdrbs = &(fr->data); | |
| 299 | aim_bstream_init(hdrbs, hdr, hdrlen); | |
| 300 | ||
| 301 | aimbs_put16(hdrbs, 0x0006); | |
| 302 | aimbs_put16(hdrbs, 0x0000); | |
| 303 | aimbs_putraw(hdrbs, intdata->cookie, 8); | |
| 304 | aimbs_put16(hdrbs, 0x0000); | |
| 305 | aimbs_put16(hdrbs, 0x0000); | |
| 306 | aimbs_put16(hdrbs, 0x0000); | |
| 307 | aimbs_put16(hdrbs, 0x0000); | |
| 308 | aimbs_put32(hdrbs, 0x00000000); | |
| 309 | aimbs_put16(hdrbs, 0x0000); | |
| 310 | aimbs_put16(hdrbs, 0x0000); | |
| 311 | aimbs_put16(hdrbs, 0x0000); | |
| 312 | ||
| 313 | if (typing == 0x0002) | |
| 314 | aimbs_put16(hdrbs, 0x0002 | 0x0008); | |
| 315 | else if (typing == 0x0001) | |
| 316 | aimbs_put16(hdrbs, 0x0002 | 0x0004); | |
| 317 | else | |
| 318 | aimbs_put16(hdrbs, 0x0002); | |
| 319 | ||
| 320 | aimbs_put16(hdrbs, 0x0000); | |
| 321 | aimbs_put16(hdrbs, 0x0000); | |
| 322 | aimbs_putstr(hdrbs, sess->sn); | |
| 323 | ||
| 324 | aim_bstream_setpos(hdrbs, 52); /* bleeehh */ | |
| 325 | ||
| 326 | aimbs_put8(hdrbs, 0x00); | |
| 327 | aimbs_put16(hdrbs, 0x0000); | |
| 328 | aimbs_put16(hdrbs, 0x0000); | |
| 329 | aimbs_put16(hdrbs, 0x0000); | |
| 330 | aimbs_put16(hdrbs, 0x0000); | |
| 331 | aimbs_put16(hdrbs, 0x0000); | |
| 332 | aimbs_put16(hdrbs, 0x0000); | |
| 333 | aimbs_put16(hdrbs, 0x0000); | |
| 334 | aimbs_put8(hdrbs, 0x00); | |
| 335 | ||
| 336 | /* end of hdr */ | |
| 337 | ||
| 338 | aim_tx_enqueue(sess, fr); | |
| 339 | ||
| 340 | return 0; | |
| 341 | } | |
| 342 | ||
| 343 | /** | |
| 344 | * Send client-to-client IM over an established direct connection. | |
| 345 | * Call this just like you would aim_send_im, to send a directim. | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
346 | * |
| 13235 | 347 | * @param sess The session. |
| 348 | * @param conn The already-connected ODC connection. | |
| 349 | * @param msg Null-terminated string to send. | |
| 350 | * @param len The length of the message to send, including binary data. | |
| 351 | * @param encoding See the AIM_CHARSET_* defines in oscar.h | |
| 352 | * @param isawaymsg 0 if this is not an auto-response, 1 if it is. | |
| 353 | * @return Return 0 if no errors, otherwise return the error number. | |
| 354 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
355 | int |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
356 | aim_odc_send_im(OscarSession *sess, OscarConnection *conn, const char *msg, int len, int encoding, int isawaymsg) |
| 13235 | 357 | { |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
358 | FlapFrame *fr; |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
359 | ByteStream *hdrbs; |
| 13235 | 360 | struct aim_odc_intdata *intdata = (struct aim_odc_intdata *)conn->internal; |
| 361 | int hdrlen = 0x44; | |
| 362 | guint8 *hdr; | |
| 363 | ||
| 364 | if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS) || !msg) | |
| 365 | return -EINVAL; | |
| 366 | ||
|
13254
3fbb3f3efba7
[gaim-migrate @ 15619]
Mark Doliner <markdoliner@pidgin.im>
parents:
13253
diff
changeset
|
367 | if (!(fr = flap_frame_new(sess, conn, AIM_FRAMETYPE_OFT, 0x01, 0))) |
| 13235 | 368 | return -ENOMEM; |
| 369 | ||
| 370 | memcpy(fr->hdr.rend.magic, "ODC2", 4); | |
| 371 | fr->hdr.rend.hdrlen = hdrlen + 8; | |
| 372 | ||
| 373 | if (!(hdr = calloc(1, hdrlen + len))) { | |
| 374 | aim_frame_destroy(fr); | |
| 375 | return -ENOMEM; | |
| 376 | } | |
| 377 | ||
| 378 | hdrbs = &(fr->data); | |
| 379 | aim_bstream_init(hdrbs, hdr, hdrlen + len); | |
| 380 | ||
| 381 | aimbs_put16(hdrbs, 0x0006); | |
| 382 | aimbs_put16(hdrbs, 0x0000); | |
| 383 | aimbs_putraw(hdrbs, intdata->cookie, 8); | |
| 384 | aimbs_put16(hdrbs, 0x0000); | |
| 385 | aimbs_put16(hdrbs, 0x0000); | |
| 386 | aimbs_put16(hdrbs, 0x0000); | |
| 387 | aimbs_put16(hdrbs, 0x0000); | |
| 388 | aimbs_put32(hdrbs, len); | |
| 389 | aimbs_put16(hdrbs, encoding); | |
| 390 | aimbs_put16(hdrbs, 0x0000); | |
| 391 | aimbs_put16(hdrbs, 0x0000); | |
| 392 | ||
| 393 | /* flags - used for typing notification and to mark if this is an away message */ | |
| 394 | aimbs_put16(hdrbs, 0x0000 | isawaymsg); | |
| 395 | ||
| 396 | aimbs_put16(hdrbs, 0x0000); | |
| 397 | aimbs_put16(hdrbs, 0x0000); | |
| 398 | aimbs_putstr(hdrbs, sess->sn); | |
| 399 | ||
| 400 | aim_bstream_setpos(hdrbs, 52); /* bleeehh */ | |
| 401 | ||
| 402 | aimbs_put8(hdrbs, 0x00); | |
| 403 | aimbs_put16(hdrbs, 0x0000); | |
| 404 | aimbs_put16(hdrbs, 0x0000); | |
| 405 | aimbs_put16(hdrbs, 0x0000); | |
| 406 | aimbs_put16(hdrbs, 0x0000); | |
| 407 | aimbs_put16(hdrbs, 0x0000); | |
| 408 | aimbs_put16(hdrbs, 0x0000); | |
| 409 | aimbs_put16(hdrbs, 0x0000); | |
| 410 | aimbs_put8(hdrbs, 0x00); | |
| 411 | ||
| 412 | /* end of hdr2 */ | |
| 413 | ||
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
414 | #if 0 /* XXX - this is how you send buddy icon info... */ |
| 13235 | 415 | aimbs_put16(hdrbs, 0x0008); |
| 416 | aimbs_put16(hdrbs, 0x000c); | |
| 417 | aimbs_put16(hdrbs, 0x0000); | |
| 418 | aimbs_put16(hdrbs, 0x1466); | |
| 419 | aimbs_put16(hdrbs, 0x0001); | |
| 420 | aimbs_put16(hdrbs, 0x2e0f); | |
| 421 | aimbs_put16(hdrbs, 0x393e); | |
| 422 | aimbs_put16(hdrbs, 0xcac8); | |
| 423 | #endif | |
| 424 | aimbs_putraw(hdrbs, (guchar *)msg, len); | |
| 425 | ||
| 426 | aim_tx_enqueue(sess, fr); | |
| 427 | ||
| 428 | return 0; | |
| 429 | } | |
| 430 | ||
| 431 | /** | |
| 432 | * Get the screen name of the peer of a direct connection. | |
| 433 | * | |
| 434 | * @param conn The ODC connection. | |
| 435 | * @return The screen name of the dude, or NULL if there was an anomaly. | |
| 436 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
437 | const char * |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
438 | aim_odc_getsn(OscarConnection *conn) |
| 13235 | 439 | { |
| 440 | struct aim_odc_intdata *intdata; | |
| 441 | ||
| 442 | if (!conn || !conn->internal) | |
| 443 | return NULL; | |
| 444 | ||
| 445 | if ((conn->type != AIM_CONN_TYPE_RENDEZVOUS) || | |
| 446 | (conn->subtype != AIM_CONN_SUBTYPE_OFT_DIRECTIM)) | |
| 447 | return NULL; | |
| 448 | ||
| 449 | intdata = (struct aim_odc_intdata *)conn->internal; | |
| 450 | ||
| 451 | return intdata->sn; | |
| 452 | } | |
| 453 | ||
| 454 | /** | |
| 455 | * Get the cookie of a direct connection. | |
| 456 | * | |
| 457 | * @param conn The ODC connection. | |
| 458 | * @return The cookie, an 8 byte unterminated string, or NULL if there was an anomaly. | |
| 459 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
460 | const guchar * |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
461 | aim_odc_getcookie(OscarConnection *conn) |
| 13235 | 462 | { |
| 463 | struct aim_odc_intdata *intdata; | |
| 464 | ||
| 465 | if (!conn || !conn->internal) | |
| 466 | return NULL; | |
| 467 | ||
| 468 | intdata = (struct aim_odc_intdata *)conn->internal; | |
| 469 | ||
| 470 | return intdata->cookie; | |
| 471 | } | |
| 472 | ||
| 473 | /** | |
| 474 | * Find the conn of a direct connection with the given buddy. | |
| 475 | * | |
| 476 | * @param sess The session. | |
| 477 | * @param sn The screen name of the buddy whose direct connection you want to find. | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
478 | * @return The conn for the direct connection with the given buddy, or NULL if no |
| 13235 | 479 | * connection was found. |
| 480 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
481 | OscarConnection * |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
482 | aim_odc_getconn(OscarSession *sess, const char *sn) |
| 13235 | 483 | { |
|
13255
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
484 | GList *cur; |
| 13235 | 485 | struct aim_odc_intdata *intdata; |
| 486 | ||
| 487 | if (!sess || !sn || !strlen(sn)) | |
| 488 | return NULL; | |
| 489 | ||
|
13255
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
490 | for (cur = sess->oscar_connections; cur; cur = cur->next) |
|
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
491 | { |
|
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
492 | OscarConnection *conn; |
|
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
493 | conn = cur->data; |
|
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
494 | if ((conn->type == AIM_CONN_TYPE_RENDEZVOUS) && (conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM)) { |
|
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
495 | intdata = conn->internal; |
| 13235 | 496 | if (!aim_sncmp(intdata->sn, sn)) |
|
13255
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
497 | return conn; |
| 13235 | 498 | } |
| 499 | } | |
| 500 | ||
| 501 | return NULL; | |
| 502 | } | |
| 503 | ||
| 504 | /** | |
| 505 | * For those times when we want to open up the direct connection channel ourselves. | |
| 506 | * | |
| 507 | * You'll want to set up some kind of watcher on this socket. | |
| 508 | * When the state changes, call aim_handlerendconnection with | |
| 509 | * the connection returned by this. aim_handlerendconnection | |
| 510 | * will accept the pending connection and stop listening. | |
| 511 | * | |
| 512 | * @param sess The session | |
| 513 | * @param sn The screen name to connect to. | |
| 514 | * @return The new connection. | |
| 515 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
516 | OscarConnection * |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
517 | aim_odc_initiate(OscarSession *sess, const char *sn, int listenfd, |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
518 | const guint8 *localip, guint16 port, const guint8 *mycookie) |
| 13235 | 519 | { |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
520 | OscarConnection *newconn; |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
521 | IcbmCookie *cookie; |
| 13235 | 522 | struct aim_odc_intdata *priv; |
| 523 | guint8 ck[8]; | |
| 524 | ||
| 525 | if (!localip) | |
| 526 | return NULL; | |
| 527 | ||
| 528 | if (mycookie) { | |
| 529 | memcpy(ck, mycookie, 8); | |
| 530 | aim_im_sendch2_odcrequest(sess, ck, TRUE, sn, localip, port); | |
| 531 | } else | |
| 532 | aim_im_sendch2_odcrequest(sess, ck, FALSE, sn, localip, port); | |
| 533 | ||
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
534 | cookie = (IcbmCookie *)calloc(1, sizeof(IcbmCookie)); |
| 13235 | 535 | memcpy(cookie->cookie, ck, 8); |
| 536 | cookie->type = AIM_COOKIETYPE_OFTIM; | |
| 537 | ||
| 538 | /* this one is for the cookie */ | |
| 539 | priv = (struct aim_odc_intdata *)calloc(1, sizeof(struct aim_odc_intdata)); | |
| 540 | ||
| 541 | memcpy(priv->cookie, ck, 8); | |
| 542 | strncpy(priv->sn, sn, sizeof(priv->sn)); | |
| 543 | cookie->data = priv; | |
| 544 | aim_cachecookie(sess, cookie); | |
| 545 | ||
| 546 | /* XXX - switch to aim_cloneconn()? */ | |
|
13255
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
547 | if (!(newconn = oscar_connection_new(sess, AIM_CONN_TYPE_LISTENER))) { |
| 13235 | 548 | close(listenfd); |
| 549 | return NULL; | |
| 550 | } | |
| 551 | ||
| 552 | /* this one is for the conn */ | |
| 553 | priv = (struct aim_odc_intdata *)calloc(1, sizeof(struct aim_odc_intdata)); | |
| 554 | ||
| 555 | memcpy(priv->cookie, ck, 8); | |
| 556 | strncpy(priv->sn, sn, sizeof(priv->sn)); | |
| 557 | ||
| 558 | newconn->fd = listenfd; | |
| 559 | newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM; | |
| 560 | newconn->internal = priv; | |
| 561 | newconn->lastactivity = time(NULL); | |
| 562 | ||
| 563 | return newconn; | |
| 564 | } | |
| 565 | ||
| 566 | /** | |
| 567 | * Connect directly to the given buddy for directim. | |
| 568 | * | |
|
13255
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
569 | * This is a wrapper for oscar_connection_new. |
| 13235 | 570 | * |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
571 | * If addr is NULL, the socket is not created, but the connection is |
| 13235 | 572 | * allocated and setup to connect. |
| 573 | * | |
| 574 | * @param sess The Godly session. | |
| 575 | * @param sn The screen name we're connecting to. I hope it's a girl... | |
| 576 | * @param addr Address to connect to. | |
| 577 | * @return The new connection. | |
| 578 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
579 | OscarConnection * |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
580 | aim_odc_connect(OscarSession *sess, const char *sn, const char *addr, const guint8 *cookie) |
| 13235 | 581 | { |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
582 | OscarConnection *newconn; |
| 13235 | 583 | struct aim_odc_intdata *intdata; |
| 584 | ||
| 585 | if (!sess || !sn) | |
| 586 | return NULL; | |
| 587 | ||
| 588 | if (!(intdata = calloc(1, sizeof(struct aim_odc_intdata)))) | |
| 589 | return NULL; | |
| 590 | memcpy(intdata->cookie, cookie, 8); | |
| 591 | strncpy(intdata->sn, sn, sizeof(intdata->sn)); | |
| 592 | if (addr) | |
| 593 | strncpy(intdata->ip, addr, sizeof(intdata->ip)); | |
| 594 | ||
| 595 | /* XXX - verify that non-blocking connects actually work */ | |
|
13255
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
596 | if (!(newconn = oscar_connection_new(sess, AIM_CONN_TYPE_RENDEZVOUS))) { |
| 13235 | 597 | free(intdata); |
| 598 | return NULL; | |
| 599 | } | |
| 600 | ||
| 601 | newconn->internal = intdata; | |
| 602 | newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM; | |
| 603 | ||
| 604 | return newconn; | |
| 605 | } | |
| 606 | ||
| 607 | /** | |
| 608 | * Sometimes you just don't know with these kinds of people. | |
| 609 | * | |
| 610 | * @param sess The session. | |
| 611 | * @param conn The ODC connection of the incoming data. | |
| 612 | * @param frr The frame allocated for the incoming data. | |
| 613 | * @param bs It stands for "bologna sandwich." | |
| 614 | * @return Return 0 if no errors, otherwise return the error number. | |
| 615 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
616 | static int |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
617 | handlehdr_odc(OscarSession *sess, OscarConnection *conn, FlapFrame *frr, ByteStream *bs) |
| 13235 | 618 | { |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
619 | FlapFrame fr; |
| 13235 | 620 | int ret = 0; |
| 621 | aim_rxcallback_t userfunc; | |
| 622 | guint32 payloadlength; | |
| 623 | guint16 flags, encoding; | |
| 624 | char *snptr = NULL; | |
| 625 | ||
| 626 | fr.conn = conn; | |
| 627 | ||
| 628 | /* AAA - ugly */ | |
| 629 | aim_bstream_setpos(bs, 20); | |
| 630 | payloadlength = aimbs_get32(bs); | |
| 631 | ||
| 632 | aim_bstream_setpos(bs, 24); | |
| 633 | encoding = aimbs_get16(bs); | |
| 634 | ||
| 635 | aim_bstream_setpos(bs, 30); | |
| 636 | flags = aimbs_get16(bs); | |
| 637 | ||
| 638 | aim_bstream_setpos(bs, 36); | |
| 639 | /* XXX - create an aimbs_getnullstr function? */ | |
| 640 | snptr = aimbs_getstr(bs, 32); /* Next 32 bytes contain the sn, padded with null chars */ | |
| 641 | ||
| 642 | gaim_debug_misc("oscar", "faim: OFT frame: handlehdr_odc: %04x / %04x / %s\n", payloadlength, flags, snptr); | |
| 643 | ||
| 644 | if (flags & 0x0008) { | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
645 | if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, PEER_TYPE_DIRECTIMTYPING))) |
| 13235 | 646 | ret = userfunc(sess, &fr, snptr, 2); |
| 647 | } else if (flags & 0x0004) { | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
648 | if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, PEER_TYPE_DIRECTIMTYPING))) |
| 13235 | 649 | ret = userfunc(sess, &fr, snptr, 1); |
| 650 | } else { | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
651 | if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, PEER_TYPE_DIRECTIMTYPING))) |
| 13235 | 652 | ret = userfunc(sess, &fr, snptr, 0); |
| 653 | } | |
| 654 | ||
| 655 | if ((payloadlength != 0) && (payloadlength != UINT_MAX)) { | |
| 656 | char *msg; | |
| 657 | int recvd = 0; | |
| 658 | int i, isawaymsg; | |
| 659 | ||
| 660 | isawaymsg = flags & 0x0001; | |
| 661 | ||
| 662 | if (!(msg = calloc(1, payloadlength+1))) { | |
| 663 | free(snptr); | |
| 664 | return -ENOMEM; | |
| 665 | } | |
| 666 | ||
| 667 | while (payloadlength - recvd) { | |
| 668 | if (payloadlength - recvd >= 1024) | |
| 669 | i = aim_recv(conn->fd, &msg[recvd], 1024); | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
670 | else |
| 13235 | 671 | i = aim_recv(conn->fd, &msg[recvd], payloadlength - recvd); |
| 672 | if (i <= 0) { | |
| 673 | free(msg); | |
| 674 | free(snptr); | |
| 675 | return -1; | |
| 676 | } | |
| 677 | recvd = recvd + i; | |
| 678 | if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_IMAGETRANSFER))) | |
| 679 | ret = userfunc(sess, &fr, snptr, (double)recvd / payloadlength); | |
| 680 | } | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
681 | |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
682 | if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, PEER_TYPE_DIRECTIMINCOMING))) |
| 13235 | 683 | ret = userfunc(sess, &fr, snptr, msg, payloadlength, encoding, isawaymsg); |
| 684 | ||
| 685 | free(msg); | |
| 686 | } | |
| 687 | ||
| 688 | free(snptr); | |
| 689 | ||
| 690 | return ret; | |
| 691 | } | |
| 692 | ||
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
693 | PeerConnection * |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
694 | aim_oft_createinfo(OscarSession *sess, const guint8 *cookie, const char *sn, const char *ip, guint16 port, guint32 size, guint32 modtime, char *filename, int send_or_recv, int method, int stage) |
| 13235 | 695 | { |
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
696 | PeerConnection *new; |
| 13235 | 697 | |
| 698 | if (!sess) | |
| 699 | return NULL; | |
| 700 | ||
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
701 | if (!(new = (PeerConnection *)calloc(1, sizeof(PeerConnection)))) |
| 13235 | 702 | return NULL; |
| 703 | ||
| 704 | new->sess = sess; | |
| 705 | if (cookie) | |
| 706 | memcpy(new->cookie, cookie, 8); | |
| 707 | else | |
| 708 | aim_icbm_makecookie(new->cookie); | |
| 709 | if (ip) | |
| 710 | new->clientip = strdup(ip); | |
| 711 | else | |
| 712 | new->clientip = NULL; | |
| 713 | if (sn) | |
| 714 | new->sn = strdup(sn); | |
| 715 | else | |
| 716 | new->sn = NULL; | |
| 717 | new->method = method; | |
| 718 | new->send_or_recv = send_or_recv; | |
| 719 | new->stage = stage; | |
| 720 | new->port = port; | |
| 721 | new->xfer_reffed = FALSE; | |
| 722 | new->success = FALSE; | |
| 723 | new->fh.totfiles = 1; | |
| 724 | new->fh.filesleft = 1; | |
| 725 | new->fh.totparts = 1; | |
| 726 | new->fh.partsleft = 1; | |
| 727 | new->fh.totsize = size; | |
| 728 | new->fh.size = size; | |
| 729 | new->fh.modtime = modtime; | |
| 730 | new->fh.checksum = 0xffff0000; | |
| 731 | new->fh.rfrcsum = 0xffff0000; | |
| 732 | new->fh.rfcsum = 0xffff0000; | |
| 733 | new->fh.recvcsum = 0xffff0000; | |
| 734 | strncpy(new->fh.idstring, "OFT_Windows ICBMFT V1.1 32", 31); | |
| 735 | if (filename) { | |
| 736 | strncpy(new->fh.name, filename, 63); | |
| 737 | new->fh.name[63] = '\0'; | |
| 738 | } | |
| 739 | ||
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
740 | sess->peer_connections = g_list_prepend(sess->peer_connections, new); |
| 13235 | 741 | |
| 742 | return new; | |
| 743 | } | |
| 744 | ||
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
745 | PeerProxyInfo *aim_rv_proxy_createinfo(OscarSession *sess, const guint8 *cookie, |
| 13235 | 746 | guint16 port) |
| 747 | { | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
748 | PeerProxyInfo *proxy_info; |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
749 | |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
750 | if (!(proxy_info = (PeerProxyInfo*)calloc(1, sizeof(PeerProxyInfo)))) |
| 13235 | 751 | return NULL; |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
752 | |
| 13235 | 753 | proxy_info->sess = sess; |
| 754 | proxy_info->port = port; | |
| 755 | proxy_info->packet_ver = AIM_RV_PROXY_PACKETVER_DFLT; | |
| 756 | proxy_info->unknownA = AIM_RV_PROXY_UNKNOWNA_DFLT; | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
757 | |
| 13235 | 758 | if (cookie) |
| 759 | memcpy(proxy_info->cookie, cookie, 8); | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
760 | |
| 13235 | 761 | return proxy_info; |
| 762 | } | |
| 763 | ||
| 764 | /** | |
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
765 | * Remove the given PeerConnection from the PeerConnection linked list, and |
| 13235 | 766 | * then free its memory. |
| 767 | * | |
| 768 | * @param sess The session. | |
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
769 | * @param peer_connection The PeerConnection that we're destroying. |
| 13235 | 770 | * @return Return 0 if no errors, otherwise return the error number. |
| 771 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
772 | int |
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
773 | aim_oft_destroyinfo(PeerConnection *peer_connection) |
| 13235 | 774 | { |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
775 | OscarSession *sess; |
| 13235 | 776 | |
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
777 | if (!peer_connection || !(sess = peer_connection->sess)) |
| 13235 | 778 | return -EINVAL; |
| 779 | ||
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
780 | sess->peer_connections = g_list_remove(sess->peer_connections, peer_connection); |
| 13235 | 781 | |
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
782 | free(peer_connection->sn); |
|
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
783 | free(peer_connection->proxyip); |
|
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
784 | free(peer_connection->clientip); |
|
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
785 | free(peer_connection->verifiedip); |
|
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
786 | free(peer_connection); |
| 13235 | 787 | |
| 788 | return 0; | |
| 789 | } | |
| 790 | ||
| 791 | /** | |
| 792 | * Creates a listener socket so the other dude can connect to us. | |
| 793 | * | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
794 | * You'll want to set up some kind of watcher on this socket. |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
795 | * When the state changes, call aim_handlerendconnection with |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
796 | * the connection returned by this. aim_handlerendconnection |
| 13235 | 797 | * will accept the pending connection and stop listening. |
| 798 | * | |
| 799 | * @param sess The session. | |
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
800 | * @param peer_connection File transfer information associated with this |
| 13235 | 801 | * connection. |
| 802 | * @return Return 0 if no errors, otherwise return the error number. | |
| 803 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
804 | int |
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
805 | aim_sendfile_listen(OscarSession *sess, PeerConnection *peer_connection, int listenfd) |
| 13235 | 806 | { |
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
807 | if (!peer_connection) |
| 13235 | 808 | return -EINVAL; |
| 809 | ||
|
13255
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
810 | if (!(peer_connection->conn = oscar_connection_new(sess, AIM_CONN_TYPE_LISTENER))) { |
| 13235 | 811 | close(listenfd); |
| 812 | return -ENOMEM; | |
| 813 | } | |
| 814 | ||
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
815 | peer_connection->conn->fd = listenfd; |
|
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
816 | peer_connection->conn->subtype = AIM_CONN_SUBTYPE_OFT_SENDFILE; |
|
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
817 | peer_connection->conn->lastactivity = time(NULL); |
| 13235 | 818 | |
| 819 | return 0; | |
| 820 | } | |
| 821 | ||
| 822 | /** | |
| 823 | * Extract an &aim_fileheader_t from the given buffer. | |
| 824 | * | |
| 825 | * @param bs The should be from an incoming rendezvous packet. | |
| 826 | * @return A pointer to new struct on success, or NULL on error. | |
| 827 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
828 | static PeerFrame * |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
829 | aim_oft_getheader(ByteStream *bs) |
| 13235 | 830 | { |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
831 | PeerFrame *fh; |
| 13235 | 832 | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
833 | if (!(fh = calloc(1, sizeof(PeerFrame)))) |
| 13235 | 834 | return NULL; |
| 835 | ||
| 836 | /* The bstream should be positioned after the hdrtype. */ | |
| 837 | aimbs_getrawbuf(bs, fh->bcookie, 8); | |
| 838 | fh->encrypt = aimbs_get16(bs); | |
| 839 | fh->compress = aimbs_get16(bs); | |
| 840 | fh->totfiles = aimbs_get16(bs); | |
| 841 | fh->filesleft = aimbs_get16(bs); | |
| 842 | fh->totparts = aimbs_get16(bs); | |
| 843 | fh->partsleft = aimbs_get16(bs); | |
| 844 | fh->totsize = aimbs_get32(bs); | |
| 845 | fh->size = aimbs_get32(bs); | |
| 846 | fh->modtime = aimbs_get32(bs); | |
| 847 | fh->checksum = aimbs_get32(bs); | |
| 848 | fh->rfrcsum = aimbs_get32(bs); | |
| 849 | fh->rfsize = aimbs_get32(bs); | |
| 850 | fh->cretime = aimbs_get32(bs); | |
| 851 | fh->rfcsum = aimbs_get32(bs); | |
| 852 | fh->nrecvd = aimbs_get32(bs); | |
| 853 | fh->recvcsum = aimbs_get32(bs); | |
| 854 | aimbs_getrawbuf(bs, (guchar *)fh->idstring, 32); | |
| 855 | fh->flags = aimbs_get8(bs); | |
| 856 | fh->lnameoffset = aimbs_get8(bs); | |
| 857 | fh->lsizeoffset = aimbs_get8(bs); | |
| 858 | aimbs_getrawbuf(bs, (guchar *)fh->dummy, 69); | |
| 859 | aimbs_getrawbuf(bs, (guchar *)fh->macfileinfo, 16); | |
| 860 | fh->nencode = aimbs_get16(bs); | |
| 861 | fh->nlanguage = aimbs_get16(bs); | |
| 862 | aimbs_getrawbuf(bs, (guchar *)fh->name, 64); /* XXX - filenames longer than 64B */ | |
| 863 | fh->name[63] = '\0'; | |
| 864 | ||
| 865 | return fh; | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
866 | } |
| 13235 | 867 | |
| 868 | /** | |
| 869 | * Fills a buffer with network-order fh data | |
| 870 | * | |
| 871 | * @param bs A bstream to fill -- automatically initialized | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
872 | * @param fh A PeerFrame to get data from. |
| 13235 | 873 | * @return Return non-zero on error. |
| 874 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
875 | static int |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
876 | aim_oft_buildheader(ByteStream *bs, PeerFrame *fh) |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
877 | { |
| 13235 | 878 | guint8 *hdr; |
| 879 | ||
| 880 | if (!bs || !fh) | |
| 881 | return -EINVAL; | |
| 882 | ||
| 883 | if (!(hdr = (unsigned char *)calloc(1, 0x100 - 8))) | |
| 884 | return -ENOMEM; | |
| 885 | ||
| 886 | aim_bstream_init(bs, hdr, 0x100 - 8); | |
| 887 | aimbs_putraw(bs, fh->bcookie, 8); | |
| 888 | aimbs_put16(bs, fh->encrypt); | |
| 889 | aimbs_put16(bs, fh->compress); | |
| 890 | aimbs_put16(bs, fh->totfiles); | |
| 891 | aimbs_put16(bs, fh->filesleft); | |
| 892 | aimbs_put16(bs, fh->totparts); | |
| 893 | aimbs_put16(bs, fh->partsleft); | |
| 894 | aimbs_put32(bs, fh->totsize); | |
| 895 | aimbs_put32(bs, fh->size); | |
| 896 | aimbs_put32(bs, fh->modtime); | |
| 897 | aimbs_put32(bs, fh->checksum); | |
| 898 | aimbs_put32(bs, fh->rfrcsum); | |
| 899 | aimbs_put32(bs, fh->rfsize); | |
| 900 | aimbs_put32(bs, fh->cretime); | |
| 901 | aimbs_put32(bs, fh->rfcsum); | |
| 902 | aimbs_put32(bs, fh->nrecvd); | |
| 903 | aimbs_put32(bs, fh->recvcsum); | |
| 904 | aimbs_putraw(bs, (guchar *)fh->idstring, 32); | |
| 905 | aimbs_put8(bs, fh->flags); | |
| 906 | aimbs_put8(bs, fh->lnameoffset); | |
| 907 | aimbs_put8(bs, fh->lsizeoffset); | |
| 908 | aimbs_putraw(bs, (guchar *)fh->dummy, 69); | |
| 909 | aimbs_putraw(bs, (guchar *)fh->macfileinfo, 16); | |
| 910 | aimbs_put16(bs, fh->nencode); | |
| 911 | aimbs_put16(bs, fh->nlanguage); | |
| 912 | aimbs_putraw(bs, (guchar *)fh->name, 64); /* XXX - filenames longer than 64B */ | |
| 913 | ||
| 914 | return 0; | |
| 915 | } | |
| 916 | ||
| 917 | /** | |
| 918 | * Create an OFT packet based on the given information, and send it on its merry way. | |
| 919 | * | |
| 920 | * @param sess The session. | |
| 921 | * @param type The subtype of the OFT packet we're sending. | |
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
922 | * @param peer_connection The PeerConnection with the connection and OFT |
| 13235 | 923 | * info we're sending. |
| 924 | * @return Return 0 if no errors, otherwise return the error number. | |
| 925 | */ | |
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
926 | int aim_oft_sendheader(OscarSession *sess, guint16 type, PeerConnection *peer_connection) |
| 13235 | 927 | { |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
928 | FlapFrame *fr; |
| 13235 | 929 | |
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
930 | if (!sess || !peer_connection || !peer_connection->conn || (peer_connection->conn->type != AIM_CONN_TYPE_RENDEZVOUS)) |
| 13235 | 931 | return -EINVAL; |
| 932 | ||
| 933 | #if 0 | |
| 934 | /* | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
935 | * If you are receiving a file, the cookie should be null, if you are sending a |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
936 | * file, the cookie should be the same as the one used in the ICBM negotiation |
| 13235 | 937 | * SNACs. |
| 938 | */ | |
| 939 | fh->lnameoffset = 0x1a; | |
| 940 | fh->lsizeoffset = 0x10; | |
| 941 | ||
| 942 | /* These should be the same as charset and charsubset in ICBMs */ | |
| 943 | fh->nencode = 0x0000; | |
| 944 | fh->nlanguage = 0x0000; | |
| 945 | #endif | |
| 946 | ||
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
947 | aim_oft_dirconvert_tostupid(peer_connection->fh.name); |
| 13235 | 948 | |
|
13254
3fbb3f3efba7
[gaim-migrate @ 15619]
Mark Doliner <markdoliner@pidgin.im>
parents:
13253
diff
changeset
|
949 | if (!(fr = flap_frame_new(sess, peer_connection->conn, AIM_FRAMETYPE_OFT, type, 0))) |
| 13235 | 950 | return -ENOMEM; |
| 951 | ||
|
13253
5ad8373f2d1e
[gaim-migrate @ 15618]
Mark Doliner <markdoliner@pidgin.im>
parents:
13240
diff
changeset
|
952 | if (aim_oft_buildheader(&fr->data, &peer_connection->fh) == -1) { |
| 13235 | 953 | aim_frame_destroy(fr); |
| 954 | return -ENOMEM; | |
| 955 | } | |
| 956 | ||
| 957 | memcpy(fr->hdr.rend.magic, "OFT2", 4); | |
| 958 | fr->hdr.rend.hdrlen = aim_bstream_curpos(&fr->data) + 8; | |
| 959 | ||
| 960 | aim_tx_enqueue(sess, fr); | |
| 961 | ||
| 962 | return 0; | |
| 963 | } | |
| 964 | ||
| 965 | /** | |
| 966 | * Create a rendezvous "init recv" packet and send it on its merry way. | |
| 967 | * This is the first packet sent to the proxy server by the second client | |
| 968 | * involved in this rendezvous proxy session. | |
| 969 | * | |
| 970 | * @param sess The session. | |
| 971 | * @param proxy_info Changable pieces of data for this packet | |
| 972 | * @return Return 0 if no errors, otherwise return the error number. | |
| 973 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
974 | int |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
975 | aim_rv_proxy_init_recv(PeerProxyInfo *proxy_info) |
| 13235 | 976 | { |
| 977 | #if 0 | |
| 978 | aim_tlvlist_t *tlvlist_sendfile; | |
| 979 | #endif | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
980 | ByteStream bs; |
| 13235 | 981 | guint8 *bs_raw; |
| 982 | guint16 packet_len; | |
| 983 | guint8 sn_len; | |
| 984 | int err; | |
| 985 | ||
| 986 | err = 0; | |
| 987 | ||
| 988 | if (!proxy_info) | |
| 989 | return -EINVAL; | |
| 990 | ||
| 991 | sn_len = strlen(proxy_info->sess->sn); | |
| 992 | packet_len = 2 + 2 /* packet_len, packet_ver */ | |
| 993 | + 2 + 4 /* cmd_type, unknownA */ | |
| 994 | + 2 /* flags */ | |
| 995 | + 1 + sn_len /* Length/value pair for screenname */ | |
| 996 | + 8 /* ICBM Cookie */ | |
| 997 | + 2 /* port */ | |
| 998 | + 2 + 2 + 16; /* TLV for Filesend capability block */ | |
| 999 | ||
| 1000 | if (!(bs_raw = malloc(packet_len))) | |
| 1001 | return -ENOMEM; | |
| 1002 | ||
| 1003 | aim_bstream_init(&bs, bs_raw, packet_len); | |
| 1004 | aimbs_put16(&bs, packet_len - 2); /* Length includes only packets after length marker */ | |
| 1005 | aimbs_put16(&bs, proxy_info->packet_ver); | |
| 1006 | aimbs_put16(&bs, AIM_RV_PROXY_INIT_RECV); | |
| 1007 | aimbs_put32(&bs, proxy_info->unknownA); | |
| 1008 | aimbs_put16(&bs, proxy_info->flags); | |
| 1009 | aimbs_put8(&bs, sn_len); | |
| 1010 | aimbs_putraw(&bs, (const guchar *)proxy_info->sess->sn, sn_len); | |
| 1011 | aimbs_put16(&bs, proxy_info->port); | |
| 1012 | aimbs_putraw(&bs, proxy_info->cookie, 8); | |
| 1013 | ||
| 1014 | aimbs_put16(&bs, 0x0001); /* Type */ | |
| 1015 | aimbs_put16(&bs, 16); /* Length */ | |
| 1016 | aimbs_putcaps(&bs, AIM_CAPS_SENDFILE); /* Value */ | |
| 1017 | ||
| 1018 | ||
| 1019 | #if 0 | |
| 1020 | /* TODO: Use built-in TLV */ | |
| 1021 | aim_tlvlist_add_caps(&tlvlist_sendfile, 0x0001, AIM_CAPS_SENDFILE); | |
| 1022 | aim_tlvlist_write(&bs, &tlvlist_sendfile); | |
| 1023 | #endif | |
| 1024 | ||
| 1025 | aim_bstream_rewind(&bs); | |
| 1026 | if (aim_bstream_send(&bs, proxy_info->conn, packet_len) != packet_len) | |
| 1027 | err = errno; | |
| 1028 | proxy_info->conn->lastactivity = time(NULL); | |
| 1029 | ||
| 1030 | #if 0 | |
| 1031 | aim_tlvlist_free(tlvlist_sendfile); | |
| 1032 | #endif | |
| 1033 | free(bs_raw); | |
| 1034 | ||
| 1035 | return err; | |
| 1036 | } | |
| 1037 | ||
| 1038 | ||
| 1039 | /** | |
| 1040 | * Create a rendezvous "init send" packet and send it on its merry way. | |
| 1041 | * This is the first packet sent to the proxy server by the client | |
| 1042 | * first indicating that this will be a proxied connection | |
| 1043 | * | |
| 1044 | * @param sess The session. | |
| 1045 | * @param proxy_info Changable pieces of data for this packet | |
| 1046 | * @return Return 0 if no errors, otherwise return the error number. | |
| 1047 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1048 | int |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1049 | aim_rv_proxy_init_send(PeerProxyInfo *proxy_info) |
| 13235 | 1050 | { |
| 1051 | #if 0 | |
| 1052 | aim_tlvlist_t *tlvlist_sendfile; | |
| 1053 | #endif | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1054 | ByteStream bs; |
| 13235 | 1055 | guint8 *bs_raw; |
| 1056 | guint16 packet_len; | |
| 1057 | guint8 sn_len; | |
| 1058 | int err; | |
| 1059 | ||
| 1060 | err = 0; | |
| 1061 | ||
| 1062 | if (!proxy_info) | |
| 1063 | return -EINVAL; | |
| 1064 | ||
| 1065 | sn_len = strlen(proxy_info->sess->sn); | |
| 1066 | packet_len = 2 + 2 /* packet_len, packet_ver */ | |
| 1067 | + 2 + 4 /* cmd_type, unknownA */ | |
| 1068 | + 2 /* flags */ | |
| 1069 | + 1 + sn_len /* Length/value pair for screenname */ | |
| 1070 | + 8 /* ICBM Cookie */ | |
| 1071 | + 2 + 2 + 16; /* TLV for Filesend capability block */ | |
| 1072 | ||
| 1073 | if (!(bs_raw = malloc(packet_len))) | |
| 1074 | return -ENOMEM; | |
| 1075 | ||
| 1076 | aim_bstream_init(&bs, bs_raw, packet_len); | |
| 1077 | aimbs_put16(&bs, packet_len - 2); /* Length includes only packets after length marker */ | |
| 1078 | aimbs_put16(&bs, proxy_info->packet_ver); | |
| 1079 | aimbs_put16(&bs, AIM_RV_PROXY_INIT_SEND); | |
| 1080 | aimbs_put32(&bs, proxy_info->unknownA); | |
| 1081 | aimbs_put16(&bs, proxy_info->flags); | |
| 1082 | aimbs_put8(&bs, sn_len); | |
| 1083 | aimbs_putraw(&bs, (const guchar *)proxy_info->sess->sn, sn_len); | |
| 1084 | aimbs_putraw(&bs, proxy_info->cookie, 8); | |
| 1085 | ||
| 1086 | aimbs_put16(&bs, 0x0001); /* Type */ | |
| 1087 | aimbs_put16(&bs, 16); /* Length */ | |
| 1088 | aimbs_putcaps(&bs, AIM_CAPS_SENDFILE); /* Value */ | |
| 1089 | ||
| 1090 | /* TODO: Use built-in TLV */ | |
| 1091 | #if 0 | |
| 1092 | aim_tlvlist_add_caps(&tlvlist_sendfile, 0x0001, AIM_CAPS_SENDFILE); | |
| 1093 | aim_tlvlist_write(&bs, &tlvlist_sendfile); | |
| 1094 | #endif | |
| 1095 | ||
| 1096 | aim_bstream_rewind(&bs); | |
| 1097 | if (aim_bstream_send(&bs, proxy_info->conn, packet_len) != packet_len) | |
| 1098 | err = errno; | |
| 1099 | proxy_info->conn->lastactivity = time(NULL); | |
| 1100 | ||
| 1101 | #if 0 | |
| 1102 | aim_tlvlist_free(tlvlist_sendfile); | |
| 1103 | #endif | |
| 1104 | free(bs_raw); | |
| 1105 | ||
| 1106 | return err; | |
| 1107 | } | |
| 1108 | ||
| 1109 | /** | |
| 1110 | * Handle incoming data on a rendezvous connection. This is analogous to the | |
| 1111 | * consumesnac function in rxhandlers.c, and I really think this should probably | |
| 1112 | * be in rxhandlers.c as well, but I haven't finished cleaning everything up yet. | |
| 1113 | * | |
| 1114 | * @param sess The session. | |
| 1115 | * @param fr The frame allocated for the incoming data. | |
| 1116 | * @return Return 0 if the packet was handled correctly, otherwise return the | |
| 1117 | * error number. | |
| 1118 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1119 | int |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1120 | aim_rxdispatch_rendezvous(OscarSession *sess, FlapFrame *fr) |
| 13235 | 1121 | { |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1122 | OscarConnection *conn = fr->conn; |
| 13235 | 1123 | int ret = 1; |
| 1124 | ||
| 1125 | if (conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) { | |
| 1126 | if (fr->hdr.rend.type == 0x0001) | |
| 1127 | ret = handlehdr_odc(sess, conn, fr, &fr->data); | |
| 1128 | else | |
| 1129 | gaim_debug_info("oscar", "ODC directim frame unknown, type is %04x\n", fr->hdr.rend.type); | |
| 1130 | ||
| 1131 | } else { | |
| 1132 | aim_rxcallback_t userfunc; | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1133 | PeerFrame *header = aim_oft_getheader(&fr->data); |
| 13235 | 1134 | aim_oft_dirconvert_fromstupid(header->name); /* XXX - This should be client-side */ |
| 1135 | ||
| 1136 | if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, fr->hdr.rend.type))) | |
| 1137 | ret = userfunc(sess, fr, conn, header->bcookie, header); | |
| 1138 | ||
| 1139 | free(header); | |
| 1140 | } | |
| 1141 | ||
| 1142 | if (ret == -1) | |
|
13255
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
1143 | aim_conn_close(sess, conn); |
| 13235 | 1144 | |
| 1145 | return ret; | |
| 1146 | } | |
| 1147 | ||
| 1148 | /** | |
| 1149 | * Handle incoming data on a rendezvous proxy connection. This is similar to | |
| 1150 | * aim_rxdispatch_rendezvous above and should probably be kept with that function. | |
| 1151 | * | |
| 1152 | * @param sess The session. | |
| 1153 | * @param fr The frame allocated for the incoming data. | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1154 | * @return Return 0 if the packet was handled correctly, otherwise return the |
| 13235 | 1155 | * error number. |
| 1156 | */ | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1157 | PeerProxyInfo * |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1158 | aim_rv_proxy_read(OscarSession *sess, OscarConnection *conn) |
| 13235 | 1159 | { |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1160 | ByteStream bs_hdr; |
| 13235 | 1161 | guint8 hdr_buf[AIM_RV_PROXY_HDR_LEN]; |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1162 | ByteStream bs_body; /* The body (everything but the header) of the packet */ |
| 13235 | 1163 | guint8 *body_buf = NULL; |
| 1164 | guint8 body_len; | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1165 | |
| 13235 | 1166 | char str_ip[30] = {""}; |
| 1167 | guint8 ip_temp[4]; | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1168 | |
| 13235 | 1169 | guint16 len; |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1170 | PeerProxyInfo *proxy_info; |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1171 | |
|
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1172 | if(!(proxy_info = malloc(sizeof(PeerProxyInfo)))) |
| 13235 | 1173 | return NULL; |
| 1174 | ||
| 1175 | aim_bstream_init(&bs_hdr, hdr_buf, AIM_RV_PROXY_HDR_LEN); | |
| 1176 | if (aim_bstream_recv(&bs_hdr, conn->fd, AIM_RV_PROXY_HDR_LEN) == AIM_RV_PROXY_HDR_LEN) { | |
| 1177 | aim_bstream_rewind(&bs_hdr); | |
| 1178 | len = aimbs_get16(&bs_hdr); | |
| 1179 | proxy_info->packet_ver = aimbs_get16(&bs_hdr); | |
| 1180 | proxy_info->cmd_type = aimbs_get16(&bs_hdr); | |
| 1181 | proxy_info->unknownA = aimbs_get32(&bs_hdr); | |
| 1182 | proxy_info->flags = aimbs_get16(&bs_hdr); | |
| 1183 | if(proxy_info->cmd_type == AIM_RV_PROXY_READY) { | |
| 1184 | /* Do a little victory dance | |
| 1185 | * A ready packet contains no additional information */ | |
| 1186 | } else if(proxy_info->cmd_type == AIM_RV_PROXY_ERROR) { | |
| 1187 | if(len == AIM_RV_PROXY_ERROR_LEN - 2) { | |
| 1188 | body_len = AIM_RV_PROXY_ERROR_LEN - AIM_RV_PROXY_HDR_LEN; | |
| 1189 | body_buf = malloc(body_len); | |
| 1190 | aim_bstream_init(&bs_body, body_buf, body_len); | |
| 1191 | if (aim_bstream_recv(&bs_body, conn->fd, body_len) == body_len) { | |
| 1192 | aim_bstream_rewind(&bs_body); | |
| 1193 | proxy_info->err_code = aimbs_get16(&bs_body); | |
| 1194 | } else { | |
| 1195 | gaim_debug_warning("oscar","error reading rv proxy error packet\n"); | |
|
13255
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
1196 | aim_conn_close(sess, conn); |
| 13235 | 1197 | free(proxy_info); |
| 1198 | proxy_info = NULL; | |
| 1199 | } | |
| 1200 | } else { | |
| 1201 | gaim_debug_warning("oscar","invalid length for proxy error packet\n"); | |
| 1202 | free(proxy_info); | |
| 1203 | proxy_info = NULL; | |
| 1204 | } | |
| 1205 | } else if(proxy_info->cmd_type == AIM_RV_PROXY_ACK) { | |
| 1206 | if(len == AIM_RV_PROXY_ACK_LEN - 2) { | |
| 1207 | body_len = AIM_RV_PROXY_ACK_LEN - AIM_RV_PROXY_HDR_LEN; | |
| 1208 | body_buf = malloc(body_len); | |
| 1209 | aim_bstream_init(&bs_body, body_buf, body_len); | |
| 1210 | if (aim_bstream_recv(&bs_body, conn->fd, body_len) == body_len) { | |
| 1211 | int i; | |
| 1212 | aim_bstream_rewind(&bs_body); | |
| 1213 | proxy_info->port = aimbs_get16(&bs_body); | |
| 1214 | for(i=0; i<4; i++) | |
| 1215 | ip_temp[i] = aimbs_get8(&bs_body); | |
| 1216 | snprintf(str_ip, sizeof(str_ip), "%hhu.%hhu.%hhu.%hhu", | |
| 1217 | ip_temp[0], ip_temp[1], | |
| 1218 | ip_temp[2], ip_temp[3]); | |
| 1219 | proxy_info->ip = strdup(str_ip); | |
| 1220 | } else { | |
| 1221 | gaim_debug_warning("oscar","error reading rv proxy error packet\n"); | |
|
13255
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
1222 | aim_conn_close(sess, conn); |
| 13235 | 1223 | free(proxy_info); |
| 1224 | proxy_info = NULL; | |
| 1225 | } | |
| 1226 | } else { | |
| 1227 | gaim_debug_warning("oscar","invalid length for proxy error packet\n"); | |
| 1228 | free(proxy_info); | |
| 1229 | proxy_info = NULL; | |
| 1230 | } | |
| 1231 | } else { | |
| 1232 | gaim_debug_warning("oscar","unknown type for aim rendezvous proxy packet\n"); | |
|
13240
db5187cc40d1
[gaim-migrate @ 15605]
Mark Doliner <markdoliner@pidgin.im>
parents:
13235
diff
changeset
|
1233 | } |
| 13235 | 1234 | } else { |
| 1235 | gaim_debug_warning("oscar","error reading header of rv proxy packet\n"); | |
|
13255
b318f395092d
[gaim-migrate @ 15620]
Mark Doliner <markdoliner@pidgin.im>
parents:
13254
diff
changeset
|
1236 | aim_conn_close(sess, conn); |
| 13235 | 1237 | free(proxy_info); |
| 1238 | proxy_info = NULL; | |
| 1239 | } | |
| 1240 | if(body_buf) { | |
| 1241 | free(body_buf); | |
| 1242 | body_buf = NULL; | |
| 1243 | } | |
| 1244 | return proxy_info; | |
| 1245 | } |