Changeset 7869e48 for libfaim/ft.c
- Timestamp:
- Jan 12, 2013, 1:43:13 PM (11 years ago)
- Children:
- e3a0d71, 4485285
- Parents:
- 4626016
- git-author:
- Jason Gross <jgross@mit.edu> (01/12/13 13:13:18)
- git-committer:
- Jason Gross <jgross@mit.edu> (01/12/13 13:43:13)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfaim/ft.c
rfa8f439 r7869e48 3 3 * (ODC is also referred to as DirectIM and IM Image.) 4 4 * 5 * There are a few static helper functions at the top, then 5 * There are a few static helper functions at the top, then 6 6 * ODC stuff, then ft stuff. 7 7 * 8 * I feel like this is a good place to explain OFT, so I'm going to 9 * do just that. Each OFT packet has a header type. I guess this 10 * is pretty similar to the subtype of a SNAC packet. The type 11 * basically tells the other client the meaning of the OFT packet. 12 * There are two distinct types of file transfer, which I usually 13 * call "sendfile" and "getfile." Sendfile is when you send a file 14 * to another AIM user. Getfile is when you share a group of files, 8 * I feel like this is a good place to explain OFT, so I'm going to 9 * do just that. Each OFT packet has a header type. I guess this 10 * is pretty similar to the subtype of a SNAC packet. The type 11 * basically tells the other client the meaning of the OFT packet. 12 * There are two distinct types of file transfer, which I usually 13 * call "sendfile" and "getfile." Sendfile is when you send a file 14 * to another AIM user. Getfile is when you share a group of files, 15 15 * and other users request that you send them the files. 16 16 * 17 17 * A typical sendfile file transfer goes like this: 18 * 1) Sender sends a channel 2 ICBM telling the other user that 19 * we want to send them a file. At the same time, we open a 20 * listener socket (this should be done before sending the 21 * ICBM) on some port, and wait for them to connect to us. 22 * The ICBM we sent should contain our IP address and the port 18 * 1) Sender sends a channel 2 ICBM telling the other user that 19 * we want to send them a file. At the same time, we open a 20 * listener socket (this should be done before sending the 21 * ICBM) on some port, and wait for them to connect to us. 22 * The ICBM we sent should contain our IP address and the port 23 23 * number that we're listening on. 24 * 2) The receiver connects to the sender on the given IP address 25 * and port. After the connection is established, the receiver 24 * 2) The receiver connects to the sender on the given IP address 25 * and port. After the connection is established, the receiver 26 26 * sends an ICBM signifying that we are ready and waiting. 27 * 3) The sender sends an OFT PROMPT message over the OFT 27 * 3) The sender sends an OFT PROMPT message over the OFT 28 28 * connection. 29 * 4) The receiver of the file sends back an exact copy of this 30 * OFT packet, except the cookie is filled in with the cookie 31 * from the ICBM. I think this might be an attempt to verify 32 * that the user that is connected is actually the guy that 29 * 4) The receiver of the file sends back an exact copy of this 30 * OFT packet, except the cookie is filled in with the cookie 31 * from the ICBM. I think this might be an attempt to verify 32 * that the user that is connected is actually the guy that 33 33 * we sent the ICBM to. Oh, I've been calling this the ACK. 34 * 5) The sender starts sending raw data across the connection 34 * 5) The sender starts sending raw data across the connection 35 35 * until the entire file has been sent. 36 * 6) The receiver knows the file is finished because the sender 37 * sent the file size in an earlier OFT packet. So then the 38 * receiver sends the DONE thingy (after filling in the 36 * 6) The receiver knows the file is finished because the sender 37 * sent the file size in an earlier OFT packet. So then the 38 * receiver sends the DONE thingy (after filling in the 39 39 * "received" checksum and size) and closes the connection. 40 40 */ … … 102 102 * Calculate oft checksum of buffer 103 103 * 104 * Prevcheck should be 0xFFFF0000 when starting a checksum of a file. The 105 * checksum is kind of a rolling checksum thing, so each time you get bytes 106 * of a file you just call this puppy and it updates the checksum. You can 107 * calculate the checksum of an entire file by calling this in a while or a 104 * Prevcheck should be 0xFFFF0000 when starting a checksum of a file. The 105 * checksum is kind of a rolling checksum thing, so each time you get bytes 106 * of a file you just call this puppy and it updates the checksum. You can 107 * calculate the checksum of an entire file by calling this in a while or a 108 108 * for loop, or something. 109 109 * 110 * Thanks to Graham Booker for providing this improved checksum routine, 111 * which is simpler and should be more accurate than Josh Myer's original 110 * Thanks to Graham Booker for providing this improved checksum routine, 111 * which is simpler and should be more accurate than Josh Myer's original 112 112 * code. -- wtm 113 113 * 114 * This algorithim works every time I have tried it. The other fails 115 * sometimes. So, AOL who thought this up? It has got to be the weirdest 114 * This algorithim works every time I have tried it. The other fails 115 * sometimes. So, AOL who thought this up? It has got to be the weirdest 116 116 * checksum I have ever seen. 117 117 * … … 134 134 check -= val; 135 135 /* 136 * The following appears to be necessary.... It happens 136 * The following appears to be necessary.... It happens 137 137 * every once in a while and the checksum doesn't fail. 138 138 */ … … 164 164 * Create a listening socket on a given port. 165 165 * 166 * XXX - Give the client author the responsibility of setting up a 167 * listener, then we no longer have a libfaim problem with broken 166 * XXX - Give the client author the responsibility of setting up a 167 * listener, then we no longer have a libfaim problem with broken 168 168 * solaris *innocent smile* -- jbm 169 169 * … … 187 187 perror("getaddrinfo"); 188 188 return -1; 189 } 189 } 190 190 ressave = res; 191 do { 191 do { 192 192 listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); 193 193 if (listenfd < 0) … … 313 313 * @param sess The session. 314 314 * @param conn The already-connected ODC connection. 315 * @param typing If 0x0002, sends a "typing" message, 0x0001 sends "typed," and 315 * @param typing If 0x0002, sends a "typing" message, 0x0001 sends "typed," and 316 316 * 0x0000 sends "stopped." 317 317 * @return Return 0 if no errors, otherwise return the error number. … … 386 386 * Send client-to-client IM over an established direct connection. 387 387 * Call this just like you would aim_send_im, to send a directim. 388 * 388 * 389 389 * @param sess The session. 390 390 * @param conn The already-connected ODC connection. … … 453 453 /* end of hdr2 */ 454 454 455 #if 0 /* XXX - this is how you send buddy icon info... */ 455 #if 0 /* XXX - this is how you send buddy icon info... */ 456 456 aimbs_put16(hdrbs, 0x0008); 457 457 aimbs_put16(hdrbs, 0x000c); … … 472 472 /** 473 473 * Get the screen name of the peer of a direct connection. 474 * 474 * 475 475 * @param conn The ODC connection. 476 476 * @return The screen name of the dude, or NULL if there was an anomaly. … … 483 483 return NULL; 484 484 485 if ((conn->type != AIM_CONN_TYPE_RENDEZVOUS) || 485 if ((conn->type != AIM_CONN_TYPE_RENDEZVOUS) || 486 486 (conn->subtype != AIM_CONN_SUBTYPE_OFT_DIRECTIM)) 487 487 return NULL; … … 497 497 * @param sess The session. 498 498 * @param sn The screen name of the buddy whose direct connection you want to find. 499 * @return The conn for the direct connection with the given buddy, or NULL if no 499 * @return The conn for the direct connection with the given buddy, or NULL if no 500 500 * connection was found. 501 501 */ … … 522 522 * For those times when we want to open up the direct connection channel ourselves. 523 523 * 524 * You'll want to set up some kind of watcher on this socket. 525 * When the state changes, call aim_handlerendconnection with 526 * the connection returned by this. aim_handlerendconnection 524 * You'll want to set up some kind of watcher on this socket. 525 * When the state changes, call aim_handlerendconnection with 526 * the connection returned by this. aim_handlerendconnection 527 527 * will accept the pending connection and stop listening. 528 528 * … … 586 586 * This is a wrapper for aim_newconn. 587 587 * 588 * If addr is NULL, the socket is not created, but the connection is 588 * If addr is NULL, the socket is not created, but the connection is 589 589 * allocated and setup to connect. 590 590 * … … 683 683 if (payloadlength - recvd >= 1024) 684 684 i = aim_recv(conn->fd, &msg[recvd], 1024); 685 else 685 else 686 686 i = aim_recv(conn->fd, &msg[recvd], payloadlength - recvd); 687 687 if (i <= 0) { … … 694 694 ret = userfunc(sess, &fr, snptr, (double)recvd / payloadlength); 695 695 } 696 696 697 697 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING))) 698 698 ret = userfunc(sess, &fr, snptr, msg, payloadlength, encoding, isawaymsg); … … 746 746 747 747 /** 748 * Remove the given oft_info struct from the oft_info linked list, and 748 * Remove the given oft_info struct from the oft_info linked list, and 749 749 * then free its memory. 750 750 * … … 781 781 * Creates a listener socket so the other dude can connect to us. 782 782 * 783 * You'll want to set up some kind of watcher on this socket. 784 * When the state changes, call aim_handlerendconnection with 785 * the connection returned by this. aim_handlerendconnection 783 * You'll want to set up some kind of watcher on this socket. 784 * When the state changes, call aim_handlerendconnection with 785 * the connection returned by this. aim_handlerendconnection 786 786 * will accept the pending connection and stop listening. 787 787 * 788 788 * @param sess The session. 789 * @param oft_info File transfer information associated with this 789 * @param oft_info File transfer information associated with this 790 790 * connection. 791 791 * @return Return 0 if no errors, otherwise return the error number. … … 855 855 856 856 return fh; 857 } 857 } 858 858 859 859 /** … … 865 865 */ 866 866 static int aim_oft_buildheader(aim_bstream_t *bs, struct aim_fileheader_t *fh) 867 { 867 { 868 868 fu8_t *hdr; 869 869 … … 910 910 * @param sess The session. 911 911 * @param type The subtype of the OFT packet we're sending. 912 * @param oft_info The aim_oft_info struct with the connection and OFT 912 * @param oft_info The aim_oft_info struct with the connection and OFT 913 913 * info we're sending. 914 914 * @return Return 0 if no errors, otherwise return the error number. … … 923 923 #if 0 924 924 /* 925 * If you are receiving a file, the cookie should be null, if you are sending a 926 * file, the cookie should be the same as the one used in the ICBM negotiation 925 * If you are receiving a file, the cookie should be null, if you are sending a 926 * file, the cookie should be the same as the one used in the ICBM negotiation 927 927 * SNACs. 928 928 */ … … 956 956 957 957 /** 958 * Handle incoming data on a rendezvous connection. This is analogous to the 959 * consumesnac function in rxhandlers.c, and I really think this should probably 958 * Handle incoming data on a rendezvous connection. This is analogous to the 959 * consumesnac function in rxhandlers.c, and I really think this should probably 960 960 * be in rxhandlers.c as well, but I haven't finished cleaning everything up yet. 961 961 * 962 962 * @param sess The session. 963 963 * @param fr The frame allocated for the incoming data. 964 * @return Return 0 if the packet was handled correctly, otherwise return the 964 * @return Return 0 if the packet was handled correctly, otherwise return the 965 965 * error number. 966 966 */
Note: See TracChangeset
for help on using the changeset viewer.