Mercurial > pidgin.yaz
annotate src/protocols/oscar/ft.c @ 3694:e941bfbacf7c
[gaim-migrate @ 3824]
Adds an option for unread mail notification for AIM over oscar. Yippy.
This involves making a connection to the email AIM servers (parallel to
chatnav, bos, auth, ads, etc.). Also added were functions n' stuff to
handle getting mail status updates.
AIM does this in a very silly way. They only tell you how many messages
you have when you sign on, so I had to change connection_has_mail so it
will just say "bleh has new mail," without saying the number of new
messages.
Also, I haven't really looked into having you auto-login to webmail,
though it is possible. This is good for now.
Oh, and since I'm sure people will ask... AIM screen names come with an
email account @netscape.net. You have to sign in to netscape.net to
activate it.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 14 Oct 2002 07:47:51 +0000 |
parents | e597186997d5 |
children | 988485669631 |
rev | line source |
---|---|
2086 | 1 /* |
2 * File transfer (OFT) and DirectIM (ODC). | |
3 * (OSCAR File Transfer, Oscar Direct Connect(ion?) | |
4 */ | |
5 | |
6 #define FAIM_INTERNAL | |
2931 | 7 |
2711
b7455c506979
[gaim-migrate @ 2724]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
8 #ifdef HAVE_CONFIG_H |
b7455c506979
[gaim-migrate @ 2724]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
9 #include <config.h> |
b7455c506979
[gaim-migrate @ 2724]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
10 #endif |
2086 | 11 #include <aim.h> |
12 | |
13 | |
14 #ifndef _WIN32 | |
15 #include <netdb.h> | |
16 #include <sys/socket.h> | |
17 #include <netinet/in.h> | |
18 #include <sys/utsname.h> /* for aim_directim_initiate */ | |
3630 | 19 #include <arpa/inet.h> /* for inet_ntoa */ |
3646
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
20 #endif |
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
21 |
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
22 #include "gaim.h" |
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
23 |
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
24 #ifdef _WIN32 |
3630 | 25 #include "win32dep.h" |
26 #endif | |
2086 | 27 |
28 | |
29 /* TODO: | |
30 o look for memory leaks.. there's going to be shitloads, i'm sure. | |
31 */ | |
32 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
33 struct aim_directim_intdata { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
34 fu8_t cookie[8]; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
35 char sn[MAXSNLEN+1]; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
36 char ip[22]; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
37 }; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
38 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
39 static int listenestablish(fu16_t portnum); |
3630 | 40 static struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr); |
2086 | 41 |
42 /** | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
43 * aim_handlerendconnect - call this to accept OFT connections and set up the required structures |
2086 | 44 * @sess: the session |
45 * @cur: the conn the incoming connection is on | |
46 * | |
47 * call this when you get an outstanding read on a conn with subtype | |
48 * AIM_CONN_SUBTYPE_RENDEZVOUS_OUT, it will clone the current | |
49 * &aim_conn_t and tweak things as appropriate. the new conn and the | |
50 * listener conn are both returned to the client in the | |
51 * %AIM_CB_FAM_OFT, %AIM_CB_OFT_<CLASS>INITIATE callback. | |
52 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
53 faim_export int aim_handlerendconnect(aim_session_t *sess, aim_conn_t *cur) |
2086 | 54 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
55 int acceptfd = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
56 struct sockaddr cliaddr; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
57 int clilen = sizeof(cliaddr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
58 int ret = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
59 aim_conn_t *newconn; |
2086 | 60 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
61 if ((acceptfd = accept(cur->fd, &cliaddr, &clilen)) == -1) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
62 return 0; /* not an error */ |
2086 | 63 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
64 if (cliaddr.sa_family != AF_INET) { /* just in case IPv6 really is happening */ |
3630 | 65 #ifndef _WIN32 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
66 close(acceptfd); |
3630 | 67 #else |
68 closesocket(acceptfd); | |
69 #endif | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
70 aim_conn_close(cur); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
71 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
72 } |
2086 | 73 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
74 if (!(newconn = aim_cloneconn(sess, cur))) { |
3630 | 75 #ifndef _WIN32 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
76 close(acceptfd); |
3630 | 77 #else |
78 closesocket(acceptfd); | |
79 #endif | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
80 aim_conn_close(cur); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
81 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
82 } |
2086 | 83 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
84 newconn->type = AIM_CONN_TYPE_RENDEZVOUS; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
85 newconn->fd = acceptfd; |
2086 | 86 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
87 if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
88 struct aim_directim_intdata *priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
89 aim_rxcallback_t userfunc; |
2086 | 90 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
91 priv = (struct aim_directim_intdata *)(newconn->internal = cur->internal); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
92 cur->internal = NULL; |
2086 | 93 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
94 snprintf(priv->ip, sizeof(priv->ip), "%s:%u", |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
95 inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
96 ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); |
2086 | 97 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
98 if ((userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
99 ret = userfunc(sess, NULL, newconn, cur); |
2086 | 100 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
101 } else if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
102 struct aim_filetransfer_priv *priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
103 aim_rxcallback_t userfunc; |
2086 | 104 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
105 newconn->priv = cur->priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
106 cur->priv = NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
107 priv = (struct aim_filetransfer_priv *)newconn->priv; |
2086 | 108 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
109 snprintf(priv->ip, sizeof(priv->ip), "%s:%u", inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); |
2086 | 110 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
111 if ((userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEINITIATE))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
112 ret = userfunc(sess, NULL, newconn, cur); |
3630 | 113 } else if (newconn->subtype == AIM_CONN_SUBTYPE_OFT_SENDFILE) { |
114 struct aim_filetransfer_priv *ft; | |
115 aim_rxcallback_t userfunc; | |
116 | |
117 /* The new conn automatically inherits the priv value | |
118 * of cur. */ | |
119 cur->priv = NULL; | |
120 ft = (struct aim_filetransfer_priv *)newconn->priv; | |
121 | |
122 snprintf(ft->ip, sizeof(ft->ip), "%s:%u", inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); | |
123 | |
124 if ((userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEINITIATE))) | |
125 ret = userfunc(sess, NULL, newconn, cur); | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
126 } else { |
2844
e63cd7fdd9eb
[gaim-migrate @ 2857]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2764
diff
changeset
|
127 faimdprintf(sess, 1,"Got a Connection on a listener that's not Rendezvous Closing conn.\n"); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
128 aim_conn_close(newconn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
129 ret = -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
130 } |
2086 | 131 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
132 return ret; |
2086 | 133 } |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
134 |
2086 | 135 /** |
2993 | 136 * aim_send_typing - send client-to-client typing notification over established connection |
2086 | 137 * @sess: session to conn |
138 * @conn: directim connection | |
2993 | 139 * @typing: If true, notify user has started typing; if false, notify user has stopped. |
2086 | 140 * |
2993 | 141 * The connection must have been previously established. |
2086 | 142 */ |
2993 | 143 faim_export int aim_send_typing(aim_session_t *sess, aim_conn_t *conn, int typing) |
2086 | 144 { |
2993 | 145 |
146 struct aim_directim_intdata *intdata = (struct aim_directim_intdata *)conn->internal; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
147 aim_frame_t *fr; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
148 aim_bstream_t hdrbs; /* XXX this should be within aim_frame_t */ |
2086 | 149 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
150 if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
151 return -EINVAL; |
2086 | 152 |
2993 | 153 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x01, 0))) |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
154 return -ENOMEM; |
2086 | 155 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
156 memcpy(fr->hdr.oft.magic, "ODC2", 4); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
157 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
158 fr->hdr.oft.hdr2len = 0x44; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
159 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
160 if (!(fr->hdr.oft.hdr2 = calloc(1, fr->hdr.oft.hdr2len))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
161 aim_frame_destroy(fr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
162 return -ENOMEM; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
163 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
164 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
165 aim_bstream_init(&hdrbs, fr->hdr.oft.hdr2, fr->hdr.oft.hdr2len); |
2086 | 166 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
167 aimbs_put16(&hdrbs, 0x0006); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
168 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
169 aimbs_putraw(&hdrbs, intdata->cookie, 8); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
170 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
171 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
172 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
173 aimbs_put16(&hdrbs, 0x0000); |
2993 | 174 aimbs_put32(&hdrbs, 0x00000000); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
175 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
176 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
177 aimbs_put16(&hdrbs, 0x0000); |
2086 | 178 |
2993 | 179 /* flags -- 0x000e for "started typing", 0x0002 for "stopped typing */ |
180 aimbs_put16(&hdrbs, ( typing ? 0x000e : 0x0002)); | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
181 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
182 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
183 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
184 aimbs_putraw(&hdrbs, sess->sn, strlen(sess->sn)); |
2993 | 185 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
186 aim_bstream_setpos(&hdrbs, 52); /* bleeehh */ |
2086 | 187 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
188 aimbs_put8(&hdrbs, 0x00); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
189 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
190 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
191 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
192 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
193 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
194 aimbs_put16(&hdrbs, 0x0000); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
195 aimbs_put16(&hdrbs, 0x0000); |
2086 | 196 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
197 /* end of hdr2 */ |
2086 | 198 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
199 aim_tx_enqueue(sess, fr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
200 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
201 return 0; |
2086 | 202 } |
203 | |
2993 | 204 /** |
205 * aim_send_im_direct - send IM client-to-client over established connection | |
206 * @sess: session to conn | |
207 * @conn: directim connection | |
3033 | 208 * @msg: null-terminated string to send. |
209 * len: The length of the message to send, including binary data. | |
2993 | 210 * |
211 * Call this just like you would aim_send_im, to send a directim. You | |
212 * _must_ have previously established the directim connection. | |
213 */ | |
3033 | 214 faim_export int aim_send_im_direct(aim_session_t *sess, aim_conn_t *conn, const char *msg, int len) |
2993 | 215 { |
216 struct aim_directim_intdata *intdata = (struct aim_directim_intdata *)conn->internal; | |
217 aim_frame_t *fr; | |
218 aim_bstream_t hdrbs; /* XXX this should be within aim_frame_t */ | |
219 | |
220 if (!sess || !conn || !msg || (conn->type != AIM_CONN_TYPE_RENDEZVOUS)) | |
221 return -EINVAL; | |
222 | |
3033 | 223 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x01, len))) |
2993 | 224 return -ENOMEM; |
225 | |
226 memcpy(fr->hdr.oft.magic, "ODC2", 4); | |
227 | |
228 fr->hdr.oft.hdr2len = 0x44; | |
229 | |
230 if (!(fr->hdr.oft.hdr2 = calloc(1, fr->hdr.oft.hdr2len))) { | |
231 aim_frame_destroy(fr); | |
232 return -ENOMEM; | |
233 } | |
234 | |
235 aim_bstream_init(&hdrbs, fr->hdr.oft.hdr2, fr->hdr.oft.hdr2len); | |
236 | |
237 aimbs_put16(&hdrbs, 0x0006); | |
238 aimbs_put16(&hdrbs, 0x0000); | |
239 aimbs_putraw(&hdrbs, intdata->cookie, 8); | |
240 aimbs_put16(&hdrbs, 0x0000); | |
241 aimbs_put16(&hdrbs, 0x0000); | |
242 aimbs_put16(&hdrbs, 0x0000); | |
243 aimbs_put16(&hdrbs, 0x0000); | |
3033 | 244 aimbs_put32(&hdrbs, len); |
2993 | 245 aimbs_put16(&hdrbs, 0x0000); |
246 aimbs_put16(&hdrbs, 0x0000); | |
247 aimbs_put16(&hdrbs, 0x0000); | |
248 | |
249 /* flags -- 0x000e for "started typing", 0x0002 for "stopped typing, 0x0000 for message */ | |
250 aimbs_put16(&hdrbs, 0x0000); | |
251 | |
252 aimbs_put16(&hdrbs, 0x0000); | |
253 aimbs_put16(&hdrbs, 0x0000); | |
254 aimbs_putraw(&hdrbs, sess->sn, strlen(sess->sn)); | |
255 | |
256 aim_bstream_setpos(&hdrbs, 52); /* bleeehh */ | |
257 | |
258 aimbs_put8(&hdrbs, 0x00); | |
259 aimbs_put16(&hdrbs, 0x0000); | |
260 aimbs_put16(&hdrbs, 0x0000); | |
261 aimbs_put16(&hdrbs, 0x0000); | |
262 aimbs_put16(&hdrbs, 0x0000); | |
263 aimbs_put16(&hdrbs, 0x0000); | |
264 aimbs_put16(&hdrbs, 0x0000); | |
265 aimbs_put16(&hdrbs, 0x0000); | |
266 | |
267 /* end of hdr2 */ | |
268 | |
269 #if 0 /* XXX this is how you send buddy icon info... */ | |
270 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0008); | |
271 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x000c); | |
272 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); | |
273 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x1466); | |
274 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0001); | |
275 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x2e0f); | |
276 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x393e); | |
277 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0xcac8); | |
278 #endif | |
3033 | 279 aimbs_putraw(&fr->data, msg, len); |
2993 | 280 |
281 aim_tx_enqueue(sess, fr); | |
282 | |
283 return 0; | |
284 } | |
285 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
286 static int getlocalip(fu8_t *ip) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
287 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
288 struct hostent *hptr; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
289 char localhost[129]; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
290 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
291 /* XXX if available, use getaddrinfo() */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
292 /* XXX allow client to specify which IP to use for multihomed boxes */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
293 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
294 if (gethostname(localhost, 128) < 0) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
295 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
296 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
297 if (!(hptr = gethostbyname(localhost))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
298 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
299 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
300 memcpy(ip, hptr->h_addr_list[0], 4); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
301 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
302 return 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
303 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
304 |
2086 | 305 /** |
306 * aim_directim_intitiate - For those times when we want to open up the directim channel ourselves. | |
307 * @sess: your session, | |
308 * @conn: the BOS conn, | |
309 * @priv: a dummy priv value (we'll let it get filled in later) (if you pass a %NULL, we alloc one) | |
310 * @destsn: the SN to connect to. | |
311 * | |
312 */ | |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
313 faim_export aim_conn_t *aim_directim_initiate(aim_session_t *sess, const char *destsn) |
2086 | 314 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
315 aim_conn_t *newconn; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
316 aim_msgcookie_t *cookie; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
317 struct aim_directim_intdata *priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
318 int listenfd; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
319 fu16_t port = 4443; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
320 fu8_t localip[4]; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
321 fu8_t ck[8]; |
2086 | 322 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
323 if (getlocalip(localip) == -1) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
324 return NULL; |
2086 | 325 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
326 if ((listenfd = listenestablish(port)) == -1) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
327 return NULL; |
2086 | 328 |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
329 aim_request_directim(sess, destsn, localip, port, ck); |
2086 | 330 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
331 cookie = (aim_msgcookie_t *)calloc(1, sizeof(aim_msgcookie_t)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
332 memcpy(cookie->cookie, ck, 8); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
333 cookie->type = AIM_COOKIETYPE_OFTIM; |
2086 | 334 |
2247
f721ae9582d5
[gaim-migrate @ 2257]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
335 /* this one is for the cookie */ |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
336 priv = (struct aim_directim_intdata *)calloc(1, sizeof(struct aim_directim_intdata)); |
2086 | 337 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
338 memcpy(priv->cookie, ck, 8); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
339 strncpy(priv->sn, destsn, sizeof(priv->sn)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
340 cookie->data = priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
341 aim_cachecookie(sess, cookie); |
2086 | 342 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
343 /* XXX switch to aim_cloneconn()? */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
344 if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL))) { |
3630 | 345 #ifndef _WIN32 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
346 close(listenfd); |
3630 | 347 #else |
348 closesocket(listenfd); | |
349 #endif | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
350 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
351 } |
2086 | 352 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
353 /* this one is for the conn */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
354 priv = (struct aim_directim_intdata *)calloc(1, sizeof(struct aim_directim_intdata)); |
2086 | 355 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
356 memcpy(priv->cookie, ck, 8); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
357 strncpy(priv->sn, destsn, sizeof(priv->sn)); |
2086 | 358 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
359 newconn->fd = listenfd; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
360 newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
361 newconn->internal = priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
362 newconn->lastactivity = time(NULL); |
2086 | 363 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
364 faimdprintf(sess, 2,"faim: listening (fd = %d, unconnected)\n", newconn->fd); |
2086 | 365 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
366 return newconn; |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
367 } |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
368 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
369 /** |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
370 * aim_sendfile_intitiate - For those times when we want to send the file ourselves. |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
371 * @sess: your session, |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
372 * @conn: the BOS conn, |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
373 * @destsn: the SN to connect to. |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
374 * @filename: the name of the files you want to send |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
375 * |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
376 */ |
3630 | 377 faim_export aim_conn_t *aim_sendfile_initiate(aim_session_t *sess, const char *destsn, const char *filename, fu16_t numfiles, fu32_t totsize, char *cookret) |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
378 { |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
379 aim_conn_t *newconn; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
380 aim_msgcookie_t *cookie; |
3630 | 381 struct aim_filetransfer_priv *ft; |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
382 int listenfd; |
3630 | 383 |
384 /* Due to other limitations, we can only initiate one | |
385 * sendfile transfer at a time, so it seems safe to | |
386 * restrict the listener to a single port. -- wtm | |
387 */ | |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
388 fu16_t port = 4443; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
389 fu8_t localip[4]; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
390 fu8_t ck[8]; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
391 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
392 if (getlocalip(localip) == -1) |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
393 return NULL; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
394 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
395 if ((listenfd = listenestablish(port)) == -1) |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
396 return NULL; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
397 |
3630 | 398 { |
399 /* XXX */ | |
400 char *basename = g_path_get_basename(filename); | |
401 aim_request_sendfile(sess, destsn, basename, | |
402 numfiles, totsize, localip, port, ck); | |
403 g_free(basename); | |
404 } | |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
405 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
406 cookie = (aim_msgcookie_t *)calloc(1, sizeof(aim_msgcookie_t)); |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
407 memcpy(cookie->cookie, ck, 8); |
3630 | 408 cookie->type = AIM_COOKIETYPE_OFTSEND; |
409 memcpy(cookret, ck, 8); | |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
410 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
411 /* this one is for the cookie */ |
3630 | 412 ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)); |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
413 |
3630 | 414 memcpy(ft->cookie, ck, 8); |
415 strncpy(ft->sn, destsn, sizeof(ft->sn)); | |
416 cookie->data = ft; | |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
417 aim_cachecookie(sess, cookie); |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
418 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
419 if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL))) { |
3630 | 420 #ifndef _WIN32 |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
421 close(listenfd); |
3630 | 422 #else |
423 closesocket(listenfd); | |
424 #endif | |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
425 return NULL; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
426 } |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
427 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
428 /* this one is for the conn */ |
3630 | 429 ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)); |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
430 |
3630 | 431 memcpy(ft->cookie, ck, 8); |
432 strncpy(ft->sn, destsn, sizeof(ft->sn)); | |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
433 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
434 newconn->fd = listenfd; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
435 newconn->subtype = AIM_CONN_SUBTYPE_OFT_SENDFILE; |
3630 | 436 newconn->priv = ft; |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
437 newconn->lastactivity = time(NULL); |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
438 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
439 faimdprintf(sess, 2,"faim: listening (fd = %d, unconnected)\n", newconn->fd); |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
440 |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
441 return newconn; |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
442 } |
2086 | 443 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
444 #if 0 |
2086 | 445 /** |
446 * unsigned int aim_oft_listener_clean - close up old listeners | |
447 * @sess: session to clean up in | |
448 * @age: maximum age in seconds | |
449 * | |
450 * returns number closed, -1 on error. | |
451 */ | |
3630 | 452 faim_export unsigned int aim_oft_listener_clean(aim_session_t *sess, |
453 time_t age) | |
2086 | 454 { |
3630 | 455 aim_conn_t *cur; |
2086 | 456 time_t now; |
457 unsigned int hit = 0; | |
458 | |
459 if (!sess) | |
460 return -1; | |
461 now = time(NULL); | |
462 for(cur = sess->connlist;cur; cur = cur->next) | |
463 if (cur->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) { | |
464 if (cur->lastactivity < (now - age) ) { | |
465 aim_conn_close(cur); | |
466 hit++; | |
3630 | 467 } |
2086 | 468 } |
469 return hit; | |
470 } | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
471 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
472 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
473 faim_export const char *aim_directim_getsn(aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
474 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
475 struct aim_directim_intdata *intdata; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
476 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
477 if (!conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
478 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
479 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
480 if ((conn->type != AIM_CONN_TYPE_RENDEZVOUS) || |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
481 (conn->subtype != AIM_CONN_SUBTYPE_OFT_DIRECTIM)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
482 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
483 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
484 if (!conn->internal) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
485 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
486 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
487 intdata = (struct aim_directim_intdata *)conn->internal; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
488 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
489 return intdata->sn; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
490 } |
2086 | 491 |
492 /** | |
493 * aim_directim_connect - connect to buddy for directim | |
494 * @sess: the session to append the conn to, | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
495 * @sn: the SN we're connecting to |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
496 * @addr: address to connect to |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
497 * |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
498 * This is a wrapper for aim_newconn. |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
499 * |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
500 * If addr is NULL, the socket is not created, but the connection is |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
501 * allocated and setup to connect. |
2086 | 502 * |
503 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
504 faim_export aim_conn_t *aim_directim_connect(aim_session_t *sess, const char *sn, const char *addr, const fu8_t *cookie) |
2086 | 505 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
506 aim_conn_t *newconn; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
507 struct aim_directim_intdata *intdata; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
508 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
509 if (!sess || !sn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
510 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
511 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
512 if (!(intdata = malloc(sizeof(struct aim_directim_intdata)))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
513 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
514 memset(intdata, 0, sizeof(struct aim_directim_intdata)); |
2086 | 515 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
516 memcpy(intdata->cookie, cookie, 8); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
517 strncpy(intdata->sn, sn, sizeof(intdata->sn)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
518 if (addr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
519 strncpy(intdata->ip, addr, sizeof(intdata->ip)); |
2086 | 520 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
521 /* XXX verify that non-blocking connects actually work */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
522 if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, addr))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
523 free(intdata); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
524 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
525 } |
2086 | 526 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
527 if (!newconn) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
528 free(intdata); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
529 return newconn; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
530 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
531 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
532 newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
533 newconn->internal = intdata; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
534 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
535 return newconn; |
2086 | 536 } |
537 | |
538 /** | |
539 * aim_directim_getconn - find a directim conn for buddy name | |
540 * @sess: your session, | |
541 * @name: the name to get, | |
542 * | |
543 * returns conn for directim with name, %NULL if none found. | |
544 * | |
545 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
546 faim_export aim_conn_t *aim_directim_getconn(aim_session_t *sess, const char *name) |
2086 | 547 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
548 aim_conn_t *cur; |
2086 | 549 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
550 if (!sess || !name || !strlen(name)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
551 return NULL; |
2086 | 552 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
553 for (cur = sess->connlist; cur; cur = cur->next) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
554 struct aim_directim_intdata *intdata; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
555 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
556 if ((cur->type != AIM_CONN_TYPE_RENDEZVOUS) || (cur->subtype != AIM_CONN_SUBTYPE_OFT_DIRECTIM)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
557 continue; |
2086 | 558 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
559 intdata = cur->internal; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
560 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
561 if (aim_sncmp(intdata->sn, name) == 0) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
562 break; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
563 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
564 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
565 return cur; |
2086 | 566 } |
567 | |
568 /** | |
569 * aim_accepttransfer - accept a file transfer request | |
570 * @sess: the session, | |
571 * @conn: the BOS conn for the CAP reply | |
572 * @sn: the screenname to send it to, | |
573 * @cookie: the cookie used | |
574 * @ip: the ip to connect to | |
3630 | 575 * @port: the port to use |
576 * @rendid: capability type (%AIM_CAPS_GETFILE or %AIM_CAPS_SENDFILE) | |
577 * | |
2086 | 578 * @listingfiles: number of files to share |
579 * @listingtotsize: total size of shared files | |
580 * @listingsize: length of the listing file(buffer) | |
581 * @listingchecksum: checksum of the listing | |
582 * | |
583 * Returns new connection or %NULL on error. | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
584 * |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
585 * XXX this should take a struct. |
2086 | 586 */ |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
587 faim_export aim_conn_t *aim_accepttransfer(aim_session_t *sess, |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
588 aim_conn_t *conn, |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
589 const char *sn, const fu8_t *cookie, |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
590 const fu8_t *ip, |
3630 | 591 fu16_t port, |
592 fu16_t rendid, | |
593 ...) | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
594 { |
3630 | 595 aim_frame_t *newpacket; |
596 aim_conn_t *newconn; | |
2086 | 597 struct aim_filetransfer_priv *priv; |
3630 | 598 int i; |
599 char addr[21]; | |
2086 | 600 |
601 if (!sess || !conn || !sn || !cookie || !ip) { | |
602 return NULL; | |
603 } | |
604 | |
3630 | 605 /* OSCAR CAP accept packet */ |
606 | |
607 | |
608 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x0002, 10+8+2+1+strlen(sn)+4+2+8+16))) { | |
609 return NULL; | |
610 } | |
611 | |
612 aim_putsnac(&newpacket->data, 0x0004, 0x0006, 0x0000, sess->snacid_next); | |
613 | |
614 for (i = 0; i < 8; i++) | |
615 aimbs_put8(&newpacket->data, cookie[i]); | |
616 | |
617 aimbs_put16(&newpacket->data, 0x0002); | |
618 aimbs_put8(&newpacket->data, strlen(sn)); | |
619 aimbs_putraw(&newpacket->data, sn, strlen(sn)); | |
620 aimbs_put16(&newpacket->data, 0x0005); | |
621 aimbs_put16(&newpacket->data, 0x001a); | |
622 aimbs_put16(&newpacket->data, AIM_RENDEZVOUS_ACCEPT); | |
623 | |
624 for (i = 0; i < 8; i++) /* yes, again... */ | |
625 aimbs_put8(&newpacket->data, cookie[i]); | |
626 | |
627 aim_putcap(&newpacket->data, rendid); | |
628 aim_tx_enqueue(sess, newpacket); | |
629 | |
630 | |
631 g_snprintf(addr, sizeof(addr), "%s:%d", ip, port); | |
632 newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, addr); | |
633 | |
634 if (newconn->status & AIM_CONN_STATUS_CONNERR) { | |
635 return NULL; | |
636 } | |
2086 | 637 |
638 if (!newconn || (newconn->fd == -1)) { | |
639 perror("aim_newconn"); | |
640 faimdprintf(sess, 2, "could not connect to %s (fd: %i)\n", ip, newconn?newconn->fd:0); | |
641 return newconn; | |
642 } | |
643 | |
3630 | 644 priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)); |
645 | |
646 memcpy(priv->cookie, cookie, 8); | |
647 priv->state = 0; | |
648 strncpy(priv->sn, sn, MAXSNLEN); | |
649 strncpy(priv->ip, ip, sizeof(priv->ip)); | |
650 newconn->priv = (void *)priv; | |
651 | |
652 faimdprintf(sess, 2, "faim: connected to peer (fd = %d)\n", newconn->fd); | |
653 | |
654 if (rendid == AIM_CAPS_GETFILE) { | |
655 return NULL; /* This should never happen for now. -- wtm */ | |
656 #if 0 | |
657 struct aim_fileheader_t *fh; | |
658 aim_frame_t *newoft; | |
659 aim_msgcookie_t *cachedcook; | |
660 /* XXX take the following parameters fu16_t listingfiles, | |
661 fu16_t listingtotsize, | |
662 fu16_t listingsize, | |
663 fu32_t listingchecksum, */ | |
664 | |
2086 | 665 newconn->subtype = AIM_CONN_SUBTYPE_OFT_GETFILE; |
666 | |
667 faimdprintf(sess, 2, "faim: getfile request accept\n"); | |
668 | |
669 if (!(newoft = aim_tx_new(sess, newconn, AIM_FRAMETYPE_OFT, 0x1108, 0))) { | |
670 faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n"); | |
671 /* XXX: conn leak here */ | |
672 return NULL; | |
673 } | |
674 | |
675 memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
676 newoft->hdr.oft.hdr2len = 0x100 - 8; | |
677 | |
678 if (!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t)))) { | |
679 /* XXX: conn leak here */ | |
680 perror("calloc"); | |
681 return NULL; | |
682 } | |
683 | |
684 fh->encrypt = 0x0000; | |
685 fh->compress = 0x0000; | |
686 fh->totfiles = listingfiles; | |
687 fh->filesleft = listingfiles; /* is this right -- total parts and parts left?*/ | |
688 fh->totparts = 0x0001; | |
689 fh->partsleft = 0x0001; | |
690 fh->totsize = listingtotsize; | |
691 fh->size = listingsize; /* ls -l listing.txt */ | |
692 fh->modtime = (int)time(NULL); /* we'll go with current time for now */ | |
693 fh->checksum = listingchecksum; | |
694 fh->rfcsum = 0x00000000; | |
695 fh->rfsize = 0x00000000; | |
696 fh->cretime = 0x00000000; | |
697 fh->rfcsum = 0x00000000; | |
698 fh->nrecvd = 0x00000000; | |
699 fh->recvcsum = 0x00000000; | |
700 memset(fh->idstring, 0, sizeof(fh->idstring)); | |
3630 | 701 strncpy(fh->idstring, "OFT_Windows ICBMFT V1.1 32", sizeof(fh->idstring)); |
2086 | 702 fh->flags = 0x02; |
703 fh->lnameoffset = 0x1a; | |
704 fh->lsizeoffset = 0x10; | |
705 memset(fh->dummy, 0, sizeof(fh->dummy)); | |
706 memset(fh->macfileinfo, 0, sizeof(fh->macfileinfo)); | |
707 | |
708 /* we need to figure out these encodings for filenames */ | |
709 fh->nencode = 0x0000; | |
710 fh->nlanguage = 0x0000; | |
711 memset(fh->name, 0, sizeof(fh->name)); | |
3630 | 712 strncpy(fh->name, "listing.txt", sizeof(fh->name)); |
2086 | 713 |
714 if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
715 aim_frame_destroy(newoft); |
2086 | 716 /* XXX: conn leak */ |
717 perror("calloc (1)"); | |
718 return NULL; | |
719 } | |
720 | |
721 memcpy(fh->bcookie, cookie, 8); | |
722 | |
723 if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, fh))) | |
724 faimdprintf(sess, 1, "eek, bh fail!\n"); | |
725 | |
726 aim_tx_enqueue(sess, newoft); | |
727 | |
3630 | 728 if (!(cachedcook = (aim_msgcookie_t *)calloc(1, sizeof(aim_msgcookie_t)))) { |
2086 | 729 faimdprintf(sess, 1, "faim: accepttransfer: couldn't calloc cachedcook. yeep!\n"); |
730 /* XXX: more cleanup, conn leak */ | |
731 perror("calloc (2)"); | |
732 return NULL; | |
733 } | |
734 | |
735 memcpy(&(priv->fh), fh, sizeof(struct aim_fileheader_t)); | |
736 memcpy(cachedcook->cookie, cookie, 8); | |
737 | |
738 cachedcook->type = AIM_COOKIETYPE_OFTGET; | |
3630 | 739 /* XXX doesn't priv need to be copied so we don't |
740 * double free? -- wtm | |
741 */ | |
2086 | 742 cachedcook->data = (void *)priv; |
743 | |
744 if (aim_cachecookie(sess, cachedcook) == -1) | |
745 faimdprintf(sess, 1, "faim: ERROR caching message cookie\n"); | |
746 | |
747 free(fh); | |
3630 | 748 #endif |
749 | |
750 } else if (rendid == AIM_CAPS_SENDFILE) { | |
751 newconn->subtype = AIM_CONN_SUBTYPE_OFT_SENDFILE; | |
752 priv->fh.recvcsum = 0xffff0000; | |
2086 | 753 } else { |
754 return NULL; | |
755 } | |
3630 | 756 |
757 return newconn; | |
758 } | |
759 | |
760 /* conn is a BOS connection over which to send the cancel msg */ | |
761 faim_export int aim_canceltransfer(aim_session_t *sess, aim_conn_t *conn, | |
762 const char *cookie, const char *sn, int rendid) | |
763 { | |
764 aim_frame_t *newpacket; | |
765 int i; | |
766 | |
767 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x0002, 10+8+2+1+strlen(sn)+4+2+8+16))) { | |
768 return 1; | |
769 } | |
2086 | 770 |
3630 | 771 aim_putsnac(&newpacket->data, 0x0004, 0x0006, 0x0000, sess->snacid_next); |
2086 | 772 |
773 for (i = 0; i < 8; i++) | |
3630 | 774 aimbs_put8(&newpacket->data, cookie[i]); |
2086 | 775 |
3630 | 776 aimbs_put16(&newpacket->data, 0x0002); |
777 aimbs_put8(&newpacket->data, strlen(sn)); | |
778 aimbs_putraw(&newpacket->data, sn, strlen(sn)); | |
779 aimbs_put16(&newpacket->data, 0x0005); | |
780 aimbs_put16(&newpacket->data, 0x001a); | |
781 aimbs_put16(&newpacket->data, AIM_RENDEZVOUS_CANCEL); | |
2086 | 782 |
3630 | 783 for (i = 0; i < 8; i++) |
784 aimbs_put8(&newpacket->data, cookie[i]); | |
785 | |
786 aim_putcap(&newpacket->data, rendid); | |
2086 | 787 aim_tx_enqueue(sess, newpacket); |
788 | |
3630 | 789 return 0; |
2086 | 790 } |
791 | |
792 /** | |
793 * aim_getlisting(FILE *file) -- get an aim_fileheader_t for a given FILE* | |
794 * @file is an opened listing file | |
795 * | |
796 * returns a pointer to the filled-in fileheader_t | |
797 * | |
798 * Currently omits checksum. we'll fix this when AOL breaks us, i | |
799 * guess. | |
800 * | |
801 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
802 faim_export struct aim_fileheader_t *aim_getlisting(aim_session_t *sess, FILE *file) |
2086 | 803 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
804 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
805 #if 0 |
2086 | 806 struct aim_fileheader_t *fh; |
807 u_long totsize = 0, size = 0, checksum = 0xffff0000; | |
808 short totfiles = 0; | |
809 char *linebuf, sizebuf[9]; | |
810 | |
811 int linelength = 1024; | |
812 | |
813 /* XXX: if we have a line longer than 1024chars, God help us. */ | |
814 if ( (linebuf = (char *)calloc(1, linelength)) == NULL ) { | |
815 faimdprintf(sess, 2, "linebuf calloc failed\n"); | |
816 return NULL; | |
817 } | |
818 | |
819 if (fseek(file, 0, SEEK_END) == -1) { /* use this for sanity check */ | |
820 perror("getlisting END1 fseek:"); | |
821 faimdprintf(sess, 2, "getlising fseek END1 error\n"); | |
822 } | |
823 | |
824 if ((size = ftell(file)) == -1) { | |
825 perror("getlisting END1 getpos:"); | |
826 faimdprintf(sess, 2, "getlising getpos END1 error\n"); | |
827 } | |
828 | |
829 if (fseek(file, 0, SEEK_SET) != 0) { | |
830 perror("getlesting fseek(SET):"); | |
831 faimdprintf(sess, 2, "faim: getlisting: couldn't seek to beginning of listing file\n"); | |
832 } | |
833 | |
834 memset(linebuf, 0, linelength); | |
835 | |
836 size = 0; | |
837 | |
838 while(fgets(linebuf, linelength, file)) { | |
839 totfiles++; | |
840 memset(sizebuf, 0, 9); | |
841 | |
842 size += strlen(linebuf); | |
843 | |
844 if (strlen(linebuf) < 23) { | |
845 faimdprintf(sess, 2, "line \"%s\" too short. skipping\n", linebuf); | |
846 continue; | |
847 } | |
848 if (linebuf[strlen(linebuf)-1] != '\n') { | |
849 faimdprintf(sess, 2, "faim: OFT: getlisting -- hit EOF or line too long!\n"); | |
850 } | |
851 | |
852 memcpy(sizebuf, linebuf+17, 8); | |
853 | |
854 totsize += strtol(sizebuf, NULL, 10); | |
855 memset(linebuf, 0, linelength); | |
856 } | |
857 | |
858 if (fseek(file, 0, SEEK_SET) == -1) { | |
859 perror("getlisting END2 fseek:"); | |
860 faimdprintf(sess, 2, "getlising fseek END2 error\n"); | |
861 } | |
862 | |
863 free(linebuf); | |
864 | |
865 /* we're going to ignore checksumming the data for now -- that | |
866 * requires walking the whole listing.txt. it should probably be | |
867 * done at register time and cached, but, eh. */ | |
868 | |
869 if (!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t)))) | |
870 return NULL; | |
871 | |
872 fh->encrypt = 0x0000; | |
873 fh->compress = 0x0000; | |
874 fh->totfiles = totfiles; | |
875 fh->filesleft = totfiles; /* is this right ?*/ | |
876 fh->totparts = 0x0001; | |
877 fh->partsleft = 0x0001; | |
878 fh->totsize = totsize; | |
879 fh->size = size; /* ls -l listing.txt */ | |
880 fh->modtime = (int)time(NULL); /* we'll go with current time for now */ | |
881 fh->checksum = checksum; /* XXX: checksum ! */ | |
882 fh->rfcsum = 0x00000000; | |
883 fh->rfsize = 0x00000000; | |
884 fh->cretime = 0x00000000; | |
885 fh->rfcsum = 0x00000000; | |
886 fh->nrecvd = 0x00000000; | |
887 fh->recvcsum = 0x00000000; | |
888 | |
889 /* memset(fh->idstring, 0, sizeof(fh->idstring)); */ | |
890 memcpy(fh->idstring, "OFT_Windows ICBMFT V1.1 32", sizeof(fh->idstring)); | |
891 memset(fh->idstring+strlen(fh->idstring), 0, sizeof(fh->idstring)-strlen(fh->idstring)); | |
892 | |
893 fh->flags = 0x02; | |
894 fh->lnameoffset = 0x1a; | |
895 fh->lsizeoffset = 0x10; | |
896 | |
897 /* memset(fh->dummy, 0, sizeof(fh->dummy)); */ | |
898 memset(fh->macfileinfo, 0, sizeof(fh->macfileinfo)); | |
899 | |
900 fh->nencode = 0x0000; /* we need to figure out these encodings for filenames */ | |
901 fh->nlanguage = 0x0000; | |
902 | |
903 /* memset(fh->name, 0, sizeof(fh->name)); */ | |
3630 | 904 strncpy(fh->name, "listing.txt", sizeof(fh->name)); |
2086 | 905 memset(fh->name+strlen(fh->name), 0, 64-strlen(fh->name)); |
906 | |
907 faimdprintf(sess, 2, "faim: OFT: listing fh name %s / %s\n", fh->name, (fh->name+(strlen(fh->name)))); | |
908 return fh; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
909 #endif |
2086 | 910 } |
911 | |
912 /** | |
913 * aim_listenestablish - create a listening socket on a port. | |
914 * @portnum: the port number to bind to. | |
915 * | |
916 * you need to call accept() when it's connected. returns your fd | |
917 * | |
2717
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
918 * XXX: give the client author the responsibility of setting up a |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
919 * listener, then we no longer have a libfaim problem with broken |
03bf072c6238
[gaim-migrate @ 2730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2711
diff
changeset
|
920 * solaris *innocent smile* -jbm |
2086 | 921 */ |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
922 static int listenestablish(fu16_t portnum) |
2086 | 923 { |
2711
b7455c506979
[gaim-migrate @ 2724]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2675
diff
changeset
|
924 #if HAVE_GETADDRINFO |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
925 int listenfd; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
926 const int on = 1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
927 struct addrinfo hints, *res, *ressave; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
928 char serv[5]; |
2086 | 929 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
930 snprintf(serv, sizeof(serv), "%d", portnum); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
931 memset(&hints, 0, sizeof(struct addrinfo)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
932 hints.ai_flags = AI_PASSIVE; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
933 hints.ai_family = AF_UNSPEC; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
934 hints.ai_socktype = SOCK_STREAM; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
935 if (getaddrinfo(NULL /*any IP*/, serv, &hints, &res) != 0) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
936 perror("getaddrinfo"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
937 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
938 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
939 ressave = res; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
940 do { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
941 listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
942 if (listenfd < 0) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
943 continue; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
944 setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
945 if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
946 break; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
947 /* success */ |
3630 | 948 #ifndef _WIN32 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
949 close(listenfd); |
3630 | 950 #else |
951 closesocket(listenfd); | |
952 #endif | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
953 } while ( (res = res->ai_next) ); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
954 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
955 if (!res) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
956 return -1; |
2086 | 957 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
958 if (listen(listenfd, 1024)!=0) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
959 perror("listen"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
960 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
961 } |
2086 | 962 |
3630 | 963 fcntl(listenfd, F_SETFL, O_NONBLOCK); |
964 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
965 freeaddrinfo(ressave); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
966 return listenfd; |
2086 | 967 #else |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
968 int listenfd; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
969 const int on = 1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
970 struct sockaddr_in sockin; |
3646
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
971 #ifdef _WIN32 |
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
972 u_long imode; |
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
973 #endif |
2086 | 974 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
975 if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
976 perror("socket(listenfd)"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
977 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
978 } |
2086 | 979 |
2421
95b4ec08abec
[gaim-migrate @ 2434]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2247
diff
changeset
|
980 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) != 0) { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
981 perror("setsockopt(listenfd)"); |
3630 | 982 #ifndef _WIN32 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
983 close(listenfd); |
3630 | 984 #else |
985 closesocket(listenfd); | |
986 #endif | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
987 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
988 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
989 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
990 memset(&sockin, 0, sizeof(struct sockaddr_in)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
991 sockin.sin_family = AF_INET; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
992 sockin.sin_port = htons(portnum); |
2086 | 993 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
994 if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
995 perror("bind(listenfd)"); |
3630 | 996 #ifndef _WIN32 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
997 close(listenfd); |
3630 | 998 #else |
999 closesocket(listenfd); | |
1000 #endif | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1001 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1002 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1003 if (listen(listenfd, 4) != 0) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1004 perror("listen(listenfd)"); |
3630 | 1005 #ifndef _WIN32 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1006 close(listenfd); |
3630 | 1007 #else |
1008 closesocket(listenfd); | |
1009 #endif | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1010 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1011 } |
3646
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1012 #ifndef _WIN32 |
3630 | 1013 fcntl(listenfd, F_SETFL, O_NONBLOCK); |
3646
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1014 #else |
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1015 imode = 1; |
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1016 ioctlsocket(listenfd, FIONBIO, &imode); |
bfd8df165f32
[gaim-migrate @ 3770]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
1017 #endif |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1018 return listenfd; |
2086 | 1019 #endif |
1020 } | |
1021 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1022 static int getcommand_getfile(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1023 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1024 #if 0 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1025 struct aim_filetransfer_priv *ft; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1026 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1027 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1028 ft = conn->priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1029 if (ft->state == 2) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1030 /* waiting on listing data */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1031 int ret = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1032 char *listing; |
3630 | 1033 aim_frame_t *newoft; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1034 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1035 if (!(listing = malloc(ft->fh.size))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1036 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1037 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1038 ft->state = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1039 if (aim_recv(conn->fd, listing, ft->fh.size) != ft->fh.size) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1040 faimdprintf(sess, 2, "OFT get: file %s was short. (0x%lx)\n", ft->fh.name, ft->fh.size); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1041 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1042 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x120b, 0))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1043 faimdprintf(sess, 2, "faim: aim_get_command_rendezvous: getfile listing: tx_new OFT failed\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1044 free(listing); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1045 aim_conn_close(conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1046 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1047 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1048 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1049 memcpy(newoft->hdr.oft.magic, "OFT2", 4); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1050 newoft->hdr.oft.hdr2len = 0x100 - 8; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1051 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1052 /* Protocol BS - set nrecvd to size of listing, recvcsum to listing checksum, flags to 0 */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1053 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1054 ft->fh.nrecvd = ft->fh.size; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1055 ft->fh.recvcsum = ft->fh.checksum; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1056 ft->fh.flags = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1057 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1058 if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1059 aim_frame_destroy(newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1060 free(listing); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1061 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1062 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1063 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1064 if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1065 faimdprintf(sess, 2, "eek! bh fail listing\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1066 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1067 /* send the 120b */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1068 aim_tx_enqueue(sess, newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1069 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTING)) ) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1070 ret = userfunc(sess, NULL, conn, ft, listing); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1071 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1072 free(listing); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1073 return ret; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1074 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1075 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1076 if (ft->state == 3) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1077 /* waiting on file data */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1078 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILERECEIVE)) ) |
3630 | 1079 return userfunc(sess, NULL, conn, ft->fh.name, |
1080 ft->fh.size); | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1081 return 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1082 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1083 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1084 if (ft->state == 4) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1085 if( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILESTATE4)) ) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1086 return userfunc(sess, NULL, conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1087 aim_conn_close(conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1088 return 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1089 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1090 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1091 return 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1092 #else |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1093 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1094 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1095 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1096 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1097 static void connclose_sendfile(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1098 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1099 aim_msgcookie_t *cook; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1100 struct aim_filetransfer_priv *priv = (struct aim_filetransfer_priv *)conn->priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1101 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1102 cook = aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTSEND); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1103 aim_cookie_free(sess, cook); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1104 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1105 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1106 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1107 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1108 static void connkill_sendfile(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1109 { |
3630 | 1110 /* XXX we don't free conn->priv here because it is currently |
1111 * freed in the caller. If that ever changes, we should | |
1112 * free it here. -- wtm | |
1113 */ | |
1114 conn->priv = NULL; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1115 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1116 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1117 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1118 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1119 static void connclose_getfile(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1120 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1121 aim_msgcookie_t *cook; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1122 struct aim_filetransfer_priv *priv = (struct aim_filetransfer_priv *)conn->priv; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1123 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1124 cook = aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTGET); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1125 aim_cookie_free(sess, cook); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1126 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1127 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1128 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1129 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1130 static void connkill_getfile(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1131 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1132 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1133 free(conn->internal); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1134 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1135 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1136 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1137 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1138 static void connclose_directim(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1139 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1140 struct aim_directim_intdata *intdata = (struct aim_directim_intdata *)conn->internal; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1141 aim_msgcookie_t *cook; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1142 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1143 cook = aim_uncachecookie(sess, intdata->cookie, AIM_COOKIETYPE_OFTIM); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1144 aim_cookie_free(sess, cook); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1145 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1146 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1147 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1148 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1149 static void connkill_directim(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1150 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1151 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1152 free(conn->internal); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1153 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1154 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1155 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1156 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1157 faim_internal void aim_conn_close_rend(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1158 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1159 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1160 if (conn->type != AIM_CONN_TYPE_RENDEZVOUS) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1161 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1162 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1163 if (conn->subtype == AIM_CONN_SUBTYPE_OFT_SENDFILE) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1164 connclose_sendfile(sess, conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1165 else if (conn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1166 connclose_getfile(sess, conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1167 else if (conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1168 connclose_directim(sess, conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1169 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1170 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1171 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1172 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1173 faim_internal void aim_conn_kill_rend(aim_session_t *sess, aim_conn_t *conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1174 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1175 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1176 if (conn->type != AIM_CONN_TYPE_RENDEZVOUS) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1177 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1178 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1179 if (conn->subtype == AIM_CONN_SUBTYPE_OFT_SENDFILE) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1180 connkill_sendfile(sess, conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1181 else if (conn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1182 connkill_getfile(sess, conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1183 else if (conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1184 connkill_directim(sess, conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1185 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1186 return; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1187 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1188 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1189 static int handlehdr_directim(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1190 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1191 aim_frame_t fr; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1192 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1193 fu32_t payloadlength; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1194 fu16_t flags; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1195 char *snptr = NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1196 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1197 fr.conn = conn; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1198 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1199 payloadlength = aimutil_get32(hdr+22); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1200 flags = aimutil_get16(hdr+32); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1201 snptr = (char *)hdr+38; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1202 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1203 faimdprintf(sess, 2, "faim: OFT frame: handlehdr_directim: %04x / %04x / %s\n", payloadlength, flags, snptr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1204 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1205 if (flags == 0x000e) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1206 int ret = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1207 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1208 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING))) |
2993 | 1209 ret = userfunc(sess, &fr, snptr, 1); |
1210 | |
1211 return ret; | |
1212 | |
1213 } else if (flags == 0x0002) { | |
1214 int ret = 0; | |
1215 | |
1216 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING))) | |
1217 ret = userfunc(sess, &fr, snptr, 0); | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1218 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1219 return ret; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1220 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1221 } else if ((flags == 0x0000) && payloadlength) { |
2993 | 1222 char *msg, *msg2; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1223 int ret = 0; |
2993 | 1224 int recvd = 0; |
1225 int i; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1226 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1227 if (!(msg = calloc(1, payloadlength+1))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1228 return -1; |
2993 | 1229 msg2 = msg; |
1230 | |
1231 while (payloadlength - recvd) { | |
1232 if (payloadlength - recvd >= 1024) | |
1233 i = aim_recv(conn->fd, msg2, 1024); | |
1234 else | |
1235 i = aim_recv(conn->fd, msg2, payloadlength - recvd); | |
3012 | 1236 if (i <= 0) { |
2993 | 1237 free(msg); |
1238 return -1; | |
1239 } | |
1240 recvd = recvd + i; | |
1241 msg2 = msg2 + i; | |
3033 | 1242 if ((userfunc=aim_callhandler(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_IMAGETRANSFER))) |
2993 | 1243 userfunc(sess, &fr, snptr, (double)recvd / payloadlength); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1244 } |
2993 | 1245 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1246 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) ) |
2993 | 1247 ret = userfunc(sess, &fr, snptr, msg, payloadlength); |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1248 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1249 free(msg); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1250 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1251 return ret; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1252 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1253 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1254 return 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1255 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1256 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1257 static int handlehdr_getfile_listing(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1258 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1259 #if 0 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1260 struct aim_filetransfer_priv *ft; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1261 struct aim_fileheader_t *fh; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1262 struct aim_msgcookie_t *cook; |
3630 | 1263 aim_frame_t *newoft; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1264 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1265 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1266 faimdprintf(sess, 2,"faim: rend: fileget 0x1108\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1267 fh = aim_oft_getfh(hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1268 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1269 faim_mutex_unlock(&conn->active); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1270 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1271 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1272 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1273 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1274 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1275 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1276 ft = cook->data; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1277 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1278 /* we're waaaaiiiting.. for listing.txt */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1279 ft->state = 2; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1280 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1281 memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1282 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1283 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1284 if(aim_cachecookie(sess, cook) == -1) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1285 faimdprintf(sess, 1, "error caching cookie\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1286 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1287 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1288 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1289 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x1209, 0))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1290 aim_conn_close(conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1291 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1292 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1293 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1294 memcpy(newoft->hdr.oft.magic, "OFT2", 4); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1295 newoft->hdr.oft.hdr2len = 0x100 - 8; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1296 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1297 if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1298 newoft->lock = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1299 aim_frame_destroy(newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1300 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1301 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1302 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1303 if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1304 newoft->lock = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1305 aim_frame_destroy(newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1306 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1307 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1308 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1309 newoft->lock = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1310 aim_tx_enqueue(sess, newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1311 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1312 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1313 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1314 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1315 static int handlehdr_getfile_listing2(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1316 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1317 #if 0 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1318 struct aim_filetransfer_priv *ft; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1319 struct aim_fileheader_t *fh; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1320 struct aim_msgcookie_t *cook; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1321 int ret = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1322 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1323 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1324 fh = aim_oft_getfh(hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1325 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1326 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1327 faimdprintf(sess, 2, "shit, no cookie in 0x1209. (%i/%s)going to crash..\n", AIM_COOKIETYPE_OFTGET, fh->bcookie); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1328 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1329 ft = cook->data; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1330 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1331 if (ft->fh.size != fh->size) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1332 faimdprintf(sess, 2, "hrm. ft->fh.size (%ld) != fh->size (%ld). um. using ft->fh.size\n", ft->fh.size, fh->size); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1333 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1334 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGREQ))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1335 ret = userfunc(sess, NULL, conn, fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1336 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1337 faimdprintf(sess, 2, "faim: get_command_rendezvous: hit end of 1209\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1338 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1339 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1340 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1341 return ret; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1342 #else |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1343 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1344 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1345 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1346 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1347 static int handlehdr_getfile_listing3(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1348 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1349 #if 0 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1350 struct aim_filetransfer_priv *ft; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1351 struct aim_msgcookie_t *cook; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1352 struct aim_fileheader_t *fh; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1353 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1354 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1355 fh = aim_oft_getfh(hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1356 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1357 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1358 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1359 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1360 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1361 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1362 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1363 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1364 ft = cook->data; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1365 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1366 if (aim_cachecookie(sess, cook) == -1) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1367 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1368 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1369 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGRXCONFIRM))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1370 return userfunc(sess, NULL, conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1371 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1372 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1373 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1374 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1375 static int handlehdr_getfile_request(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1376 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1377 #if 0 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1378 struct aim_filetransfer_priv *ft; |
3630 | 1379 aim_msgcookie_t *cook; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1380 struct aim_fileheader_t *fh; |
3630 | 1381 aim_frame_t *newoft; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1382 int i = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1383 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1384 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1385 fh = aim_oft_getfh(hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1386 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1387 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1388 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1389 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1390 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1391 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1392 ft = cook->data; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1393 memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1394 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1395 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1396 aim_cachecookie(sess, cook); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1397 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1398 faimdprintf(sess, 2, "faim: fileget: %s seems to want %s\n", ft->sn, ft->fh.name); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1399 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1400 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) ) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1401 i = userfunc(sess, NULL, conn, &(ft->fh), cook->cookie); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1402 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1403 if (i < 0) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1404 return i; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1405 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1406 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0101, 0))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1407 faimdprintf(sess, 2, "faim: send_final_transfer: tx_new OFT failed\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1408 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1409 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1410 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1411 memcpy(newoft->hdr.oft.magic, "OFT2", 4); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1412 newoft->hdr.oft.hdr2len = 0x100 - 8; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1413 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1414 if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1415 aim_frame_destroy(newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1416 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1417 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1418 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1419 /* protocol BS: nrecvd, recvcsum to 0, flags to 0x20. */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1420 ft->fh.nrecvd = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1421 ft->fh.recvcsum = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1422 ft->fh.flags = 0x20; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1423 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1424 aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1425 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1426 aim_tx_enqueue(sess, newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1427 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1428 faimdprintf(sess, 2, "faim: OFT: OFT file header enqueued.\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1429 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1430 return i; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1431 #else |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1432 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1433 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1434 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1435 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1436 static int handlehdr_getfile_sending(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1437 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1438 #if 0 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1439 struct aim_fileheader_t *fh; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1440 struct aim_filetransfer_priv *ft; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1441 struct aim_msgcookie_t *cook; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1442 struct command_tx_struct *newoft; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1443 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1444 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1445 fh = aim_oft_getfh(hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1446 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1447 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1448 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1449 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1450 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1451 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1452 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1453 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1454 ft = cook->data; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1455 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1456 ft->state = 3; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1457 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1458 if (aim_cachecookie(sess, cook) == -1) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1459 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1460 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1461 faimdprintf(sess, 2, "faim: fileget: %s seems to want to send %s\n", ft->sn, ft->fh.name); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1462 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1463 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0202, 0))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1464 faimdprintf(sess, 2, "faim: send_final_transfer: tx_new OFT failed\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1465 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1466 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1467 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1468 newoft->lock = 1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1469 memcpy(newoft->hdr.oft.magic, "OFT2", 4); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1470 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1471 newoft->hdr.oft.hdr2len = 0x100 - 8; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1472 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1473 if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1474 aim_frame_destroy(newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1475 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1476 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1477 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1478 aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1479 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1480 newoft->lock = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1481 aim_tx_enqueue(sess, newoft); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1482 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1483 faimdprintf(sess, 2, "faim: OFT: OFT 0x0202 enqueued.\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1484 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1485 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) == NULL) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1486 return 1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1487 #else |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1488 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1489 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1490 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1491 |
3630 | 1492 static int handlehdr_sendfile_sending(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
1493 { | |
1494 struct aim_filetransfer_priv *ft; | |
1495 struct aim_fileheader_t *fh; | |
1496 aim_frame_t *newoft; | |
1497 aim_rxcallback_t userfunc; | |
1498 | |
1499 fh = aim_oft_getfh(hdr); | |
1500 | |
1501 /* We receive a null cookie for the first file; we must fill | |
1502 * it in to authenticate ourselves. -- wtm | |
1503 */ | |
1504 ft = conn->priv; | |
1505 memcpy(&(fh->bcookie), ft->cookie, 8); | |
1506 | |
1507 memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t)); | |
1508 free(fh); | |
1509 | |
1510 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0202, 0))) { | |
1511 faimdprintf(sess, 2, "faim: send_final_transfer: tx_new OFT failed\n"); | |
1512 return -1; | |
1513 } | |
1514 | |
1515 memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
1516 | |
1517 newoft->hdr.oft.hdr2len = 0x100 - 8; | |
1518 | |
1519 if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) { | |
1520 aim_frame_destroy(newoft); | |
1521 return -1; | |
1522 } | |
1523 | |
1524 if (!aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, | |
1525 &(ft->fh))) { | |
1526 return -1; | |
1527 } | |
1528 | |
1529 aim_tx_enqueue(sess, newoft); | |
1530 | |
1531 faimdprintf(sess, 2, "faim: OFT: OFT 0x0202 enqueued.\n"); | |
1532 | |
1533 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) == NULL) | |
1534 return 1; | |
1535 | |
1536 { | |
1537 char *cur; | |
1538 /* Convert the directory separator: it is sent | |
1539 * as ^A (0x01). | |
1540 */ | |
1541 while ((cur = strchr(ft->fh.name, 0x01))) { | |
1542 *cur = G_DIR_SEPARATOR; | |
1543 } | |
1544 } | |
1545 return userfunc(sess, NULL, conn, ft->fh.name, ft->fh.size); | |
1546 } | |
1547 | |
1548 | |
1549 /* | |
1550 * These were originally described by Josh Myer: | |
1551 * http://www.geocrawler.com/archives/3/896/2000/9/0/4291064/ | |
1552 * -- wtm | |
1553 */ | |
1554 static int handlehdr_sendfile_resume(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) { | |
1555 aim_frame_t *newoft; | |
1556 aim_msgcookie_t *cook; | |
1557 struct aim_fileheader_t *fh; | |
1558 struct aim_filetransfer_priv *ft; | |
1559 | |
1560 fh = aim_oft_getfh(hdr); | |
1561 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTSEND))) { | |
1562 free(fh); | |
1563 return -1; | |
1564 } | |
1565 ft = (struct aim_filetransfer_priv *)cook->data; | |
1566 | |
1567 ft->fh.nrecvd = fh->nrecvd; | |
1568 ft->fh.recvcsum = fh->recvcsum; | |
1569 strncpy(ft->fh.name, fh->name, sizeof(ft->fh.name)); | |
1570 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0106, 0))) { | |
1571 faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n"); | |
1572 free(fh); | |
1573 return -1; | |
1574 } | |
1575 memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
1576 newoft->hdr.oft.hdr2len = 0x100 - 8; | |
1577 | |
1578 if (!(newoft->hdr.oft.hdr2 = (unsigned char *)calloc(1,newoft->hdr.oft.hdr2len))) { | |
1579 aim_frame_destroy(newoft); | |
1580 return -1; | |
1581 } | |
1582 | |
1583 if (!(aim_oft_buildheader(newoft->hdr.oft.hdr2, &(ft->fh)))) { | |
1584 aim_frame_destroy(newoft); | |
1585 free(fh); | |
1586 return -1; | |
1587 } | |
1588 | |
1589 aim_tx_enqueue(sess, newoft); | |
1590 free(fh); | |
1591 | |
1592 return 0; | |
1593 } | |
1594 | |
1595 static int handlehdr_sendfile_recv(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) { | |
1596 struct aim_fileheader_t *fh; | |
1597 aim_msgcookie_t *cook; | |
1598 int ret = 1; | |
1599 struct aim_filetransfer_priv *ft; | |
1600 aim_rxcallback_t userfunc; | |
1601 | |
1602 fh = aim_oft_getfh(hdr); | |
1603 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTSEND))) { | |
1604 free(fh); | |
1605 return -1; | |
1606 } | |
1607 ft = (struct aim_filetransfer_priv *)cook->data; | |
1608 | |
1609 faimdprintf(sess, 2, "faim: get_rend: looks like we're ready to send data.(oft 0x0202)\n"); | |
1610 | |
1611 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND)) ) | |
1612 ret = userfunc(sess, NULL, conn, ft->fh.nrecvd); | |
1613 | |
1614 free(fh); | |
1615 | |
1616 return ret; | |
1617 } | |
1618 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1619 static int handlehdr_getfile_recv(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1620 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1621 #if 0 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1622 struct aim_fileheader_t *fh; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1623 struct aim_msgcookie_t *cook; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1624 int ret = 1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1625 aim_rxcallback_t userfunc; |
3630 | 1626 struct aim_filetransfer_priv *ft; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1627 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1628 fh = aim_oft_getfh(hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1629 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1630 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTGET))) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1631 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1632 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1633 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1634 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1635 ft = cook->data; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1636 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1637 faimdprintf(sess, 2, "faim: get_rend: looks like we're ready to send data.(oft 0x0202)\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1638 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1639 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND)) ) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1640 ret = userfunc(sess, NULL, conn, fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1641 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1642 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1643 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1644 return ret; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1645 #else |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1646 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1647 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1648 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1649 |
3630 | 1650 static int handlehdr_sendfile_finish(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
1651 { | |
1652 struct aim_fileheader_t *fh; | |
1653 aim_msgcookie_t *cook; | |
1654 aim_rxcallback_t userfunc; | |
1655 | |
1656 fh = aim_oft_getfh(hdr); | |
1657 | |
1658 if (!(cook = aim_checkcookie(sess, fh->bcookie, AIM_COOKIETYPE_OFTSEND))) { | |
1659 free(fh); | |
1660 return -1; | |
1661 } | |
1662 | |
1663 faimdprintf(sess, 2, "faim: get_rend: looks like we're done with a transfer (oft 0x0204)\n"); | |
1664 | |
1665 debug_printf("wtm: they sent csum %x\n", fh->recvcsum); | |
1666 | |
1667 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE)) ) | |
1668 userfunc(sess, NULL, conn, fh->bcookie); | |
1669 | |
1670 free(fh); | |
1671 return 0; | |
1672 } | |
1673 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1674 static int handlehdr_getfile_finish(aim_session_t *sess, aim_conn_t *conn, fu8_t *hdr) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1675 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1676 #if 0 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1677 struct aim_fileheader_t *fh; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1678 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1679 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1680 fh = aim_oft_getfh(hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1681 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1682 faimdprintf(sess, 2, "faim: get_rend: looks like we're done with a transfer (oft 0x0204)\n"); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1683 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1684 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE)) ) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1685 userfunc(sess, NULL, conn, fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1686 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1687 free(fh); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1688 #endif |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1689 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1690 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1691 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1692 |
2086 | 1693 /** |
1694 * aim_get_command_rendezvous - OFT equivalent of aim_get_command | |
1695 * @sess: session to work on | |
1696 * @conn: conn to pull data from | |
1697 * | |
1698 * this reads and handles data from conn->fd. currently a little rough | |
1699 * around the edges | |
1700 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1701 faim_internal int aim_get_command_rendezvous(aim_session_t *sess, aim_conn_t *conn) |
2086 | 1702 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1703 fu8_t hdrbuf1[6]; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1704 fu8_t *hdr = NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1705 int hdrlen, hdrtype; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1706 int ret = -1; |
2086 | 1707 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1708 if (!sess || !conn) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1709 return -1; |
2086 | 1710 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1711 memset(hdrbuf1, 0, sizeof(hdrbuf1)); |
2086 | 1712 |
3630 | 1713 if (conn->subtype == AIM_CONN_SUBTYPE_OFT_GETFILE) { |
1714 /* This should never happen yet. -- wtm */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1715 return getcommand_getfile(sess, conn); |
3630 | 1716 } |
2086 | 1717 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1718 /* XXX fix all the error cases here */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1719 if (aim_recv(conn->fd, hdrbuf1, 6) < 6) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1720 faimdprintf(sess, 2, "faim: rend: read error (fd: %i)\n", conn->fd); |
2086 | 1721 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1722 aim_conn_close(conn); |
2086 | 1723 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1724 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1725 } |
2086 | 1726 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1727 hdrlen = aimutil_get16(hdrbuf1+4); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1728 hdrlen -= 6; |
2086 | 1729 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1730 hdr = malloc(hdrlen); |
2086 | 1731 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1732 if (aim_recv(conn->fd, hdr, hdrlen) < hdrlen) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1733 faimdprintf(sess, 2, "faim: rend: read2 error on %d (%d)\n", conn->fd, hdrlen); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1734 free(hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1735 aim_conn_close(conn); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1736 return -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1737 } |
2086 | 1738 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1739 hdrtype = aimutil_get16(hdr); |
2086 | 1740 |
3630 | 1741 if (conn->subtype == AIM_CONN_SUBTYPE_OFT_SENDFILE) { |
1742 switch(hdrtype) { | |
1743 case 0x0101: | |
1744 ret = handlehdr_sendfile_sending(sess, conn, hdr); | |
1745 break; | |
1746 case 0x0205: | |
1747 /* This seems equivalent to 0x0202, | |
1748 * but has the nrecvd and nrecvcsum | |
1749 * fields filled in. We send back a | |
1750 * 0x0106, and get then a 0x0207 which | |
1751 * we treat just like a 0x0202. -- wtm */ | |
1752 ret = handlehdr_sendfile_resume(sess, | |
1753 conn, hdr); | |
1754 break; | |
1755 case 0x0207: /* see above */; | |
1756 case 0x0202: | |
1757 ret = handlehdr_sendfile_recv(sess, conn, hdr); | |
1758 break; | |
1759 case 0x0204: | |
1760 ret = handlehdr_sendfile_finish(sess, conn, hdr); | |
1761 break; | |
1762 default: | |
1763 debug_printf("unknown header type %x received", hdrtype); | |
1764 ret = -1; | |
1765 break; | |
1766 } | |
1767 free(hdr); | |
1768 if (ret == -1) | |
1769 aim_conn_close(conn); | |
1770 return ret; | |
1771 } | |
1772 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1773 if (hdrtype == 0x0001) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1774 ret = handlehdr_directim(sess, conn, hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1775 else if (hdrtype == 0x1108) /* getfile listing.txt incoming tx->rx */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1776 ret = handlehdr_getfile_listing(sess, conn, hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1777 else if (hdrtype == 0x1209) /* get file listing ack rx->tx */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1778 ret = handlehdr_getfile_listing2(sess, conn, hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1779 else if (hdrtype == 0x120b) /* get file listing rx confirm */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1780 ret = handlehdr_getfile_listing3(sess, conn, hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1781 else if (hdrtype == 0x120c) /* getfile request */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1782 ret = handlehdr_getfile_request(sess, conn, hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1783 else if (hdrtype == 0x0101) /* getfile sending data */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1784 ret = handlehdr_getfile_sending(sess, conn, hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1785 else if (hdrtype == 0x0202) /* getfile recv data */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1786 ret = handlehdr_getfile_recv(sess, conn, hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1787 else if (hdrtype == 0x0204) /* getfile finished */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1788 ret = handlehdr_getfile_finish(sess, conn, hdr); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1789 else { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1790 faimdprintf(sess, 2,"faim: OFT frame: uknown type %04x\n", hdrtype); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1791 ret = -1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1792 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1793 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1794 free(hdr); |
2086 | 1795 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1796 if (ret == -1) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1797 aim_conn_close(conn); |
2086 | 1798 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1799 return ret; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1800 } |
2086 | 1801 |
1802 /** | |
1803 * aim_oft_getfh - extracts an &aim_fileheader_t from buffer hdr. | |
1804 * @hdr: buffer to extract header from | |
1805 * | |
1806 * returns pointer to new struct on success; %NULL on error. | |
1807 * | |
1808 */ | |
1809 static struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr) | |
1810 { | |
1811 struct aim_fileheader_t *fh; | |
1812 int i, j; | |
1813 if (!(fh = calloc(1, sizeof(struct aim_fileheader_t)))) | |
1814 return NULL; | |
1815 | |
1816 /* [0] and [1] are the type. we can ignore those here. */ | |
1817 i = 2; | |
1818 for(j = 0; j < 8; j++, i++) | |
1819 fh->bcookie[j] = hdr[i]; | |
1820 fh->encrypt = aimutil_get16(hdr+i); | |
1821 i += 2; | |
1822 fh->compress = aimutil_get16(hdr+i); | |
1823 i += 2; | |
1824 fh->totfiles = aimutil_get16(hdr+i); | |
1825 i += 2; | |
1826 fh->filesleft = aimutil_get16(hdr+i); | |
1827 i += 2; | |
1828 fh->totparts = aimutil_get16(hdr+i); | |
1829 i += 2; | |
1830 fh->partsleft = aimutil_get16(hdr+i); | |
1831 i += 2; | |
1832 fh->totsize = aimutil_get32(hdr+i); | |
1833 i += 4; | |
1834 fh->size = aimutil_get32(hdr+i); | |
1835 i += 4; | |
1836 fh->modtime = aimutil_get32(hdr+i); | |
1837 i += 4; | |
1838 fh->checksum = aimutil_get32(hdr+i); | |
1839 i += 4; | |
1840 fh->rfrcsum = aimutil_get32(hdr+i); | |
1841 i += 4; | |
1842 fh->rfsize = aimutil_get32(hdr+i); | |
1843 i += 4; | |
1844 fh->cretime = aimutil_get32(hdr+i); | |
1845 i += 4; | |
1846 fh->rfcsum = aimutil_get32(hdr+i); | |
1847 i += 4; | |
1848 fh->nrecvd = aimutil_get32(hdr+i); | |
1849 i += 4; | |
1850 fh->recvcsum = aimutil_get32(hdr+i); | |
1851 i += 4; | |
1852 memcpy(fh->idstring, hdr+i, 32); | |
1853 i += 32; | |
1854 fh->flags = aimutil_get8(hdr+i); | |
1855 i += 1; | |
1856 fh->lnameoffset = aimutil_get8(hdr+i); | |
1857 i += 1; | |
1858 fh->lsizeoffset = aimutil_get8(hdr+i); | |
1859 i += 1; | |
1860 memcpy(fh->dummy, hdr+i, 69); | |
1861 i += 69; | |
1862 memcpy(fh->macfileinfo, hdr+i, 16); | |
1863 i += 16; | |
1864 fh->nencode = aimutil_get16(hdr+i); | |
1865 i += 2; | |
1866 fh->nlanguage = aimutil_get16(hdr+i); | |
1867 i += 2; | |
1868 memcpy(fh->name, hdr+i, 64); | |
1869 i += 64; | |
1870 return fh; | |
1871 } | |
1872 | |
1873 /** | |
1874 * aim_oft_checksum - calculate oft checksum of buffer | |
1875 * @buffer: buffer of data to checksum | |
1876 * @bufsize: size of buffer | |
3630 | 1877 * @prevcheck: previous checksum |
2086 | 1878 * |
3630 | 1879 * Prevcheck should be 0xFFFF0000 for each new file; you can have this |
1880 * checksum chunks of files in series if you just call it repeatedly in a | |
1881 * for(; ; ) loop and don't reset the checksum between each call. And you | |
1882 * thought we didn't care about you and your pathetic client's meomry | |
1883 * footprint ;^) | |
2086 | 1884 * |
3630 | 1885 * Thanks to Graham Booker for providing this improved checksum |
1886 * routine, which is simpler and should be more accurate than Josh | |
1887 * Meyer's original code. -- wtm | |
2086 | 1888 * |
3630 | 1889 * This algorithim works every time I have tried it. The other fails |
1890 * sometimes. So, AOL who thought this up? It has got to be the weirdest | |
1891 * checksum I have ever seen. | |
2086 | 1892 */ |
3630 | 1893 faim_export fu32_t aim_oft_checksum(const unsigned char *buffer, int bufferlen, int prevcheck) { |
1894 fu32_t check = (prevcheck >> 16) & 0xffff, oldcheck; | |
1895 int i; | |
1896 unsigned short val; | |
1897 | |
1898 for(i=0;i<bufferlen;i++){ | |
1899 oldcheck = check; | |
1900 if(i&1){ | |
1901 val = buffer[i]; | |
1902 } else { | |
1903 val = buffer[i] << 8; | |
1904 } | |
1905 check -= val; | |
1906 /* The follownig appears to be necessary.... It happens every once in a while and the checksum doesn't fail. */ | |
1907 if(check > oldcheck) { | |
1908 check--; | |
1909 } | |
1910 } | |
1911 check = ((check & 0x0000ffff) + (check >> 16)); | |
1912 check = ((check & 0x0000ffff) + (check >> 16)); | |
1913 return check << 16; | |
1914 } | |
2086 | 1915 |
3630 | 1916 faim_export fu32_t aim_update_checksum(aim_session_t *sess, aim_conn_t *conn, |
1917 const unsigned char *buffer, int len) { | |
1918 struct aim_filetransfer_priv *ft = conn->priv; | |
2086 | 1919 |
3630 | 1920 ft->fh.nrecvd += len; |
1921 ft->fh.recvcsum = aim_oft_checksum(buffer, len, ft->fh.recvcsum); | |
2086 | 1922 |
3630 | 1923 return 0; |
1924 } | |
2086 | 1925 |
1926 /** | |
1927 * aim_oft_buildheader - fills a buffer with network-order fh data | |
1928 * @dest: buffer to fill -- pre-alloced | |
1929 * @fh: fh to get data from | |
1930 * | |
1931 * returns length written; -1 on error. | |
1932 * DOES NOT DO BOUNDS CHECKING! | |
1933 * | |
1934 */ | |
3630 | 1935 faim_export int aim_oft_buildheader(unsigned char *dest, struct aim_fileheader_t *fh) |
2086 | 1936 { |
1937 int i, curbyte; | |
1938 if (!dest || !fh) | |
1939 return -1; | |
1940 curbyte = 0; | |
1941 for(i = 0; i < 8; i++) | |
1942 curbyte += aimutil_put8(dest+curbyte, fh->bcookie[i]); | |
1943 curbyte += aimutil_put16(dest+curbyte, fh->encrypt); | |
1944 curbyte += aimutil_put16(dest+curbyte, fh->compress); | |
1945 curbyte += aimutil_put16(dest+curbyte, fh->totfiles); | |
1946 curbyte += aimutil_put16(dest+curbyte, fh->filesleft); | |
1947 curbyte += aimutil_put16(dest+curbyte, fh->totparts); | |
1948 curbyte += aimutil_put16(dest+curbyte, fh->partsleft); | |
1949 curbyte += aimutil_put32(dest+curbyte, fh->totsize); | |
1950 curbyte += aimutil_put32(dest+curbyte, fh->size); | |
1951 curbyte += aimutil_put32(dest+curbyte, fh->modtime); | |
1952 curbyte += aimutil_put32(dest+curbyte, fh->checksum); | |
1953 curbyte += aimutil_put32(dest+curbyte, fh->rfrcsum); | |
1954 curbyte += aimutil_put32(dest+curbyte, fh->rfsize); | |
1955 curbyte += aimutil_put32(dest+curbyte, fh->cretime); | |
1956 curbyte += aimutil_put32(dest+curbyte, fh->rfcsum); | |
1957 curbyte += aimutil_put32(dest+curbyte, fh->nrecvd); | |
1958 curbyte += aimutil_put32(dest+curbyte, fh->recvcsum); | |
1959 memcpy(dest+curbyte, fh->idstring, 32); | |
1960 curbyte += 32; | |
1961 curbyte += aimutil_put8(dest+curbyte, fh->flags); | |
1962 curbyte += aimutil_put8(dest+curbyte, fh->lnameoffset); | |
1963 curbyte += aimutil_put8(dest+curbyte, fh->lsizeoffset); | |
1964 memcpy(dest+curbyte, fh->dummy, 69); | |
1965 curbyte += 69; | |
1966 memcpy(dest+curbyte, fh->macfileinfo, 16); | |
1967 curbyte += 16; | |
1968 curbyte += aimutil_put16(dest+curbyte, fh->nencode); | |
1969 curbyte += aimutil_put16(dest+curbyte, fh->nlanguage); | |
1970 memset(dest+curbyte, 0x00, 64); | |
1971 memcpy(dest+curbyte, fh->name, 64); | |
1972 | |
1973 /* XXX: Filenames longer than 64B */ | |
1974 curbyte += 64; | |
1975 return curbyte; | |
1976 } | |
1977 | |
1978 /** | |
1979 * aim_getfile_intitiate - Request an OFT getfile session | |
1980 * @sess: your session, | |
1981 * @conn: the BOS conn, | |
1982 * @destsn is the SN to connect to. | |
1983 * | |
1984 * returns a new &aim_conn_t on success, %NULL on error | |
1985 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1986 faim_export aim_conn_t *aim_getfile_initiate(aim_session_t *sess, aim_conn_t *conn, const char *destsn) |
2086 | 1987 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1988 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1989 #if 0 |
2086 | 1990 struct command_tx_struct *newpacket; |
1991 struct aim_conn_t *newconn; | |
1992 struct aim_filetransfer_priv *priv; | |
1993 struct aim_msgcookie_t *cookie; | |
1994 int curbyte, i, listenfd; | |
1995 short port = 4443; | |
1996 struct hostent *hptr; | |
1997 struct utsname myname; | |
1998 char cap[16]; | |
1999 char d[4]; | |
2000 | |
2001 /* Open our socket */ | |
2002 | |
2003 if ( (listenfd = aim_listenestablish(port)) == -1) | |
2004 return NULL; | |
2005 | |
2006 /* get our local IP */ | |
2007 | |
2008 if (uname(&myname) < 0) | |
2009 return NULL; | |
2010 if ( (hptr = gethostbyname(myname.nodename)) == NULL) | |
2011 return NULL; | |
2012 memcpy(&d, hptr->h_addr_list[0], 4); | |
2013 | |
2014 aim_putcap(cap, 16, AIM_CAPS_GETFILE); | |
2015 | |
2016 /* create the OSCAR packet */ | |
2017 | |
2018 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+8+2+1+strlen(destsn)+4+4+0x42))) | |
2019 return NULL; | |
2020 newpacket->lock = 1; | |
2021 | |
2022 /* lock struct */ | |
2023 curbyte = 0; | |
2024 curbyte += aim_putsnac(newpacket->data+curbyte, 0x0004, 0x0006, 0x0000, sess->snac_nextid); | |
2025 | |
2026 /* XXX: check the cookie before commiting to using it */ | |
2027 | |
2028 /* Generate a random message cookie | |
2029 * This cookie needs to be alphanumeric and NULL-terminated to be TOC-compatible. */ | |
2030 for (i=0; i<7; i++) | |
2031 curbyte += aimutil_put8(newpacket->data+curbyte, 0x30 + ((u_char) random() % 10)); | |
2032 | |
2033 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); | |
2034 | |
2035 /* grab all the data for cookie caching. */ | |
2036 | |
2037 if (!(cookie = (struct aim_msgcookie_t *)calloc(1, sizeof(struct aim_msgcookie_t)))) | |
2038 return NULL; | |
2039 memcpy(cookie->cookie, newpacket->data+curbyte-8, 8); | |
2040 cookie->type = AIM_COOKIETYPE_OFTGET; | |
2041 | |
2042 if (!(priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) | |
2043 return NULL; | |
2044 memcpy(priv->cookie, cookie, 8); | |
2045 memcpy(priv->sn, destsn, sizeof(priv->sn)); | |
2046 memcpy(priv->fh.name, "listing.txt", strlen("listing.txt")); | |
2047 priv->state = 1; | |
2048 | |
2049 cookie->data = priv; | |
2050 | |
2051 aim_cachecookie(sess, cookie); | |
2052 | |
2053 /* Channel ID */ | |
2054 curbyte += aimutil_put16(newpacket->data+curbyte,0x0002); | |
2055 | |
2056 /* Destination SN (prepended with byte length) */ | |
2057 curbyte += aimutil_put8(newpacket->data+curbyte,strlen(destsn)); | |
2058 curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn)); | |
2059 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003); | |
2060 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
2061 | |
2062 /* enTLV start */ | |
2063 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); | |
2064 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0042); | |
2065 | |
2066 /* Flag data / ICBM Parameters? */ | |
2067 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); | |
2068 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); | |
2069 | |
2070 /* Cookie */ | |
2071 curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cookie, 8); | |
2072 | |
2073 /* Capability String */ | |
2074 curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cap, 0x10); | |
2075 | |
2076 /* 000a/0002 : 0001 */ | |
2077 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000a); | |
2078 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); | |
2079 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001); | |
2080 | |
2081 /* 0003/0004: IP address */ | |
2082 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003); | |
2083 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0004); | |
2084 for(i = 0; i < 4; i++) | |
2085 curbyte += aimutil_put8(newpacket->data+curbyte, d[i]); | |
2086 | |
2087 /* already in network byte order */ | |
2088 | |
2089 /* 0005/0002: Port */ | |
2090 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); | |
2091 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); | |
2092 curbyte += aimutil_put16(newpacket->data+curbyte, port); | |
2093 | |
2094 /* 000f/0000: ?? */ | |
2095 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000f); | |
2096 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
2097 | |
2098 /* 2711/000c: ?? */ | |
2099 curbyte += aimutil_put16(newpacket->data+curbyte, 0x2711); | |
2100 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000c); | |
2101 curbyte += aimutil_put32(newpacket->data+curbyte, 0x00120001); | |
2102 | |
2103 for(i = 0; i < 0x000c - 4; i++) | |
2104 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); | |
2105 | |
2106 newpacket->commandlen = curbyte; | |
2107 newpacket->lock = 0; | |
2108 aim_tx_enqueue(sess, newpacket); | |
2109 | |
2110 /* allocate and set up our connection */ | |
2111 | |
2112 i = fcntl(listenfd, F_GETFL, 0); | |
2113 fcntl(listenfd, F_SETFL, i | O_NONBLOCK); | |
2114 newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL); | |
2115 | |
2116 if (!newconn){ | |
2117 perror("aim_newconn"); | |
2118 return NULL; | |
2119 } | |
2120 | |
2121 newconn->fd = listenfd; | |
2122 newconn->subtype = AIM_CONN_SUBTYPE_OFT_GETFILE; | |
2123 newconn->priv = priv; | |
2124 faimdprintf(sess, 2,"faim: listening (fd = %d, unconnected)\n", newconn->fd); | |
2125 | |
2126 return newconn; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2127 #endif |
2086 | 2128 } |
2129 | |
2130 /** | |
2131 * aim_oft_getfile_request - request a particular file over an established getfile connection | |
2132 * @sess: your session | |
2133 * @conn: the established OFT getfile connection | |
2134 * @name: filename to request | |
2135 * @size: size of the file | |
2136 * | |
2137 * | |
2138 * returns -1 on error, 0 on successful enqueuing | |
2139 */ | |
3630 | 2140 #if 0 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2141 faim_export int aim_oft_getfile_request(aim_session_t *sess, aim_conn_t *conn, const char *name, int size) |
2086 | 2142 { |
3630 | 2143 aim_frame_t *newoft; |
2086 | 2144 struct aim_filetransfer_priv *ft; |
2145 if (!sess || !conn || !conn->priv || !name) | |
2146 return -1; | |
2147 | |
2148 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x120c, 0))) { | |
2149 faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n"); | |
2150 return -1; | |
2151 } | |
2152 memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
2153 newoft->hdr.oft.hdr2len = 0x100 - 8; | |
2154 | |
2155 ft = (struct aim_filetransfer_priv *)conn->priv; | |
2156 ft->fh.filesleft = 1; | |
2157 ft->fh.totfiles = 1; | |
2158 ft->fh.totparts = 1; | |
2159 ft->fh.partsleft = 1; | |
2160 ft->fh.totsize = size; | |
2161 ft->fh.size = size; | |
2162 ft->fh.checksum = 0; | |
2163 memcpy(ft->fh.name, name, strlen(name)); | |
2164 memset(ft->fh.name+strlen(name), 0, 1); | |
2165 | |
2166 if (!(newoft->hdr.oft.hdr2 = (unsigned char *)calloc(1,newoft->hdr.oft.hdr2len))) { | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2167 aim_frame_destroy(newoft); |
2086 | 2168 return -1; |
2169 } | |
2170 | |
2171 if (!(aim_oft_buildheader(newoft->hdr.oft.hdr2, &(ft->fh)))) { | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2172 aim_frame_destroy(newoft); |
2086 | 2173 return -1; |
2174 } | |
2175 | |
3630 | 2176 aim_tx_enqueue(sess, newoft); |
2177 return 0; | |
2178 } | |
2179 #endif | |
2180 | |
2181 /* Identify a file that we are about to send by transmitting the | |
2182 * appropriate header. | |
2183 */ | |
2184 faim_export int aim_oft_sendfile_request(aim_session_t *sess, aim_conn_t *conn, const char *name, int filesdone, int numfiles, int size, int totsize) | |
2185 { | |
2186 aim_frame_t *newoft; | |
2187 aim_msgcookie_t *cook; | |
2188 struct aim_filetransfer_priv *ft = (struct aim_filetransfer_priv *)conn->priv; | |
2189 struct aim_fileheader_t *fh; | |
2190 | |
2191 if (!sess || !conn || !name) | |
2192 return -1; | |
2193 | |
2194 /* Authenticate whomever connected to our listener by checking | |
2195 * that the correct cookie was proivided. */ | |
2196 if (!(cook = aim_checkcookie(sess, ft->cookie, | |
2197 AIM_COOKIETYPE_OFTSEND))) { | |
2198 return -1; | |
2199 } | |
2200 | |
2201 if (!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t)))) | |
2202 return -1; | |
2203 | |
2204 fh->encrypt = 0x0000; | |
2205 fh->compress = 0x0000; | |
2206 fh->totfiles = numfiles; | |
2207 fh->filesleft = numfiles - filesdone; | |
2208 fh->totparts = 0x0001; | |
2209 fh->partsleft = 0x0001; | |
2210 fh->totsize = totsize; | |
2211 fh->size = size; | |
2212 fh->modtime = (int)time(NULL); /* we'll go with current time for now */ | |
2213 fh->checksum = 0xffffffff; /* XXX: checksum ! */ | |
2214 fh->rfcsum = 0x00000000; | |
2215 fh->rfsize = 0x00000000; | |
2216 fh->cretime = 0x00000000; | |
2217 fh->rfcsum = 0x00000000; | |
2218 fh->nrecvd = 0x00000000; /* always zero initially */ | |
2219 fh->recvcsum = 0x00000000; /* ditto */ | |
2220 | |
2221 strncpy(fh->idstring, "OFT_Windows ICBMFT V1.1 32", sizeof(fh->idstring)); | |
2222 fh->flags = 0x02; | |
2223 fh->lnameoffset = 0x1a; | |
2224 fh->lsizeoffset = 0x10; | |
2225 memset(fh->dummy, 0, sizeof(fh->dummy)); | |
2226 memset(fh->macfileinfo, 0, sizeof(fh->macfileinfo)); | |
2227 | |
2228 /* we need to figure out these encodings for filenames */ | |
2229 fh->nencode = 0x0000; | |
2230 fh->nlanguage = 0x0000; | |
2231 | |
2232 { | |
2233 /* Don't "show full pathname to buddy", just because it is | |
2234 * non-portable. -- wtm | |
2235 */ | |
2236 char *basename = g_path_get_basename(name); | |
2237 strncpy(fh->name, basename, sizeof(fh->name)); | |
2238 g_free(basename); | |
2239 } | |
2240 | |
2241 memcpy(fh->bcookie, cook->cookie, 8); | |
2242 /* Update both headers to be safe. */ | |
2243 memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t)); | |
2244 memcpy(&(((struct aim_filetransfer_priv *)cook->data)->fh), fh, | |
2245 sizeof(struct aim_fileheader_t)); | |
2246 | |
2247 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0101, 0))) { | |
2248 faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n"); | |
2249 free(fh); | |
2250 return -1; | |
2251 } | |
2252 memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
2253 newoft->hdr.oft.hdr2len = 0x100 - 8; | |
2254 | |
2255 if (!(newoft->hdr.oft.hdr2 = (unsigned char *)calloc(1,newoft->hdr.oft.hdr2len))) { | |
2256 aim_frame_destroy(newoft); | |
2257 free(fh); | |
2258 return -1; | |
2259 } | |
2260 | |
2261 if (!(aim_oft_buildheader(newoft->hdr.oft.hdr2, fh))) { | |
2262 aim_frame_destroy(newoft); | |
2263 free(fh); | |
2264 return -1; | |
2265 } | |
2086 | 2266 |
2267 aim_tx_enqueue(sess, newoft); | |
3630 | 2268 free(fh); |
2086 | 2269 return 0; |
2270 } | |
2271 | |
2272 /** | |
2273 * aim_oft_getfile_ack - acknowledge a getfile download as complete | |
2274 * @sess: your session | |
2275 * @conn: the getfile conn to send the ack over | |
2276 * | |
2277 * Call this function after you have read all the data in a particular | |
2278 * filetransfer. Returns -1 on error, 0 on apparent success | |
2279 * | |
2280 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2281 faim_export int aim_oft_getfile_ack(aim_session_t *sess, aim_conn_t *conn) |
2086 | 2282 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2283 return -EINVAL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2284 #if 0 |
2086 | 2285 struct command_tx_struct *newoft; |
2286 struct aim_filetransfer_priv *ft; | |
2287 | |
2288 if (!sess || !conn || !conn->priv) | |
2289 return -1; | |
2290 | |
2291 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0202, 0))) { | |
2292 faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n"); | |
2293 return -1; | |
2294 } | |
2295 | |
2296 newoft->lock = 1; | |
2297 | |
2298 memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
2299 newoft->hdr.oft.hdr2len = 0x100-8; | |
2300 | |
2301 if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { | |
2302 newoft->lock = 0; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2303 aim_frame_destroy(newoft); |
2086 | 2304 return -1; |
2305 } | |
2306 | |
2307 ft = (struct aim_filetransfer_priv *)conn->priv; | |
2308 | |
2309 if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) { | |
2310 newoft->lock = 0; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2311 aim_frame_destroy(newoft); |
2086 | 2312 return -1; |
2313 } | |
2314 | |
2315 newoft->lock = 0; | |
2316 aim_tx_enqueue(sess, newoft); | |
2317 return 0; | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2318 #endif |
2086 | 2319 } |
2320 | |
2321 /** | |
3630 | 2322 * aim_oft_end - end a getfile/sendfile. |
2086 | 2323 * @sess: your session |
2324 * @conn: the getfile connection | |
2325 * | |
2326 * call this before you close the getfile connection if you're on the | |
2327 * receiving/requesting end. | |
2328 */ | |
3630 | 2329 faim_export int aim_oft_end(aim_session_t *sess, aim_conn_t *conn) |
2086 | 2330 { |
3630 | 2331 aim_frame_t *newoft; |
2086 | 2332 struct aim_filetransfer_priv *ft; |
2333 | |
2334 if (!sess || !conn || !conn->priv) | |
2335 return -1; | |
2336 | |
2337 if (!(newoft = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x0204, 0))) { | |
2338 faimdprintf(sess, 2, "faim: aim_accepttransfer: tx_new OFT failed\n"); | |
2339 return -1; | |
2340 } | |
2341 | |
2342 memcpy(newoft->hdr.oft.magic, "OFT2", 4); | |
2343 newoft->hdr.oft.hdr2len = 0x100 - 8; | |
2344 | |
2345 if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) { | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2346 aim_frame_destroy(newoft); |
2086 | 2347 return -1; |
2348 } | |
2349 | |
2350 ft = (struct aim_filetransfer_priv *)conn->priv; | |
2351 ft->state = 4; /* no longer wanting data */ | |
2352 ft->fh.flags = 0x21; | |
2353 | |
2354 if (!(aim_oft_buildheader((unsigned char *)newoft->hdr.oft.hdr2, &(ft->fh)))) { | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2355 aim_frame_destroy(newoft); |
2086 | 2356 return -1; |
2357 } | |
2358 | |
2359 aim_tx_enqueue(sess, newoft); | |
2360 | |
2361 return 0; | |
2362 } | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
2363 |