annotate libfaim/aim_ft.c @ 1247:f50146ce818e

[gaim-migrate @ 1257] more libfaim stuff committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Wed, 13 Dec 2000 00:51:37 +0000
parents 2ac6ccb94229
children 920c86b753d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 #include <faim/aim.h>
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2
889
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
3 #ifndef _WIN32
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
4 #include <netdb.h>
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
5 #include <sys/socket.h>
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
6 #include <netinet/in.h>
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 #include <sys/utsname.h> /* for aim_directim_initiate */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 #include <arpa/inet.h> /* for inet_ntoa */
889
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
9 #endif
640
2c0a7d245bd2 [gaim-migrate @ 650]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 503
diff changeset
10
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 /* aim_msgcookies.c is mostly new. just look at the diff and replace yours, easiest. */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 function name where i had it
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 aim_send_im_direct aim_im.c
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 aim_directim_initiate aim_im.c
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 aim_filetransfer_accept aim_im.c
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 aim_getlisting aim_misc.c (?!) -- prototype function. can be ignored.
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 establish aim_misc.c
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
20 aim_get_command_rendezvous aim_r
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21 oft_getfh aim_rxqueue.c
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
24 faim_export int aim_handlerendconnect(struct aim_session_t *sess, struct aim_conn_t *cur)
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26 int acceptfd = 0;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 rxcallback_t userfunc;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28 struct sockaddr cliaddr;
1245
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
29 socklen_t clilen = sizeof(cliaddr);
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 int ret = 0;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 * Listener sockets only have incoming connections. No data.
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 if( (acceptfd = accept(cur->fd, &cliaddr, &clilen)) == -1)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 return -1;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 if (cliaddr.sa_family != AF_INET) /* just in case IPv6 really is happening */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 return -1;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 switch(cur->subtype) {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 case AIM_CONN_SUBTYPE_OFT_DIRECTIM: {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43 struct aim_directim_priv *priv;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 snprintf(priv->ip, sizeof(priv->ip), "%s:%u", inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), ntohs(((struct sockaddr_in *)&cliaddr)->sin_port));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 if(!cur->priv)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 cur->priv = priv; /* what happens if there is one?! -- mid */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 cur->type = AIM_CONN_TYPE_RENDEZVOUS;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53 close(cur->fd); /* should we really do this? seems like the client should decide. maybe clone the connection and keep the listener open. -- mid */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 cur->fd = acceptfd;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56 if ( (userfunc = aim_callhandler(cur, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE)))
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 ret = userfunc(sess, NULL, cur);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59 break;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61 case AIM_CONN_SUBTYPE_OFT_GETFILE: {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 struct aim_filetransfer_priv *priv;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64 priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 snprintf(priv->ip, sizeof(priv->ip), "%s:%u", inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), ntohs(((struct sockaddr_in *)&cliaddr)->sin_port));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68 if(!cur->priv)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 cur->priv = priv;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71 if ( (userfunc = aim_callhandler(cur, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEINITIATE)))
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 ret = userfunc(sess, NULL, cur);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73 break;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 default: {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 /* XXX */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 return ret;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 * aim_send_im_direct:
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85 * sess - session
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 * conn - directim connection
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87 * msg - null-terminated string to send
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
90 faim_export int aim_send_im_direct(struct aim_session_t *sess,
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
91 struct aim_conn_t *conn,
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
92 char *msg)
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93 {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 struct command_tx_struct *newpacket , *newpacket2;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
95
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
96 /* newpacket contains a real header with data, newpacket2 is just a
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
97 null packet, with a cookie and a lot of 0x00s. newpacket is the
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98 "i'm sending", newpacket2 is the "i'm typing".*/
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 /* uhm. the client should send those as two seperate things -- mid */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 struct aim_directim_priv *priv = NULL;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103 int i;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
105 if (!sess || !conn || !(conn->type) || (conn->type != AIM_CONN_TYPE_RENDEZVOUS) || !conn->priv || !msg) {
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
106 printf("faim: directim: invalid arguments\n");
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107 return -1;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108 };
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
109
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
110 if (strlen(msg) >= MAXMSGLEN)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
111 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
112
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
113 priv = (struct aim_directim_priv *)conn->priv;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
114
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
115 /* NULLish Header */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
116
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
117 if (!(newpacket2 = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0001, conn, 0))) {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
118 printf("faim: directim: tx_new2 failed\n");
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
119 return -1;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
120 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
121
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122 newpacket2->lock = 1; /* lock struct */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
123
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
124 memcpy(newpacket2->hdr.oft.magic, "ODC2", 4);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
125 newpacket2->hdr.oft.hdr2len = 0x44;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
126
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127 if (!(newpacket2->hdr.oft.hdr2 = calloc(1,newpacket2->hdr.oft.hdr2len))) {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
128 free(newpacket2);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
129 return -1;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
130 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
131
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132 i = 0;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
133 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0006);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
136 i += aimutil_putstr(newpacket2->hdr.oft.hdr2+i, (char *)priv->cookie, 8);
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
139 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
140 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
141 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
142
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143 i += aimutil_put32(newpacket2->hdr.oft.hdr2+i, 0x00000000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
144
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
145 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
146 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
147 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
148
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
149 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x000e);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
150
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
151 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
152 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
153
1245
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
154 i += aimutil_putstr(newpacket2->hdr.oft.hdr2+i, sess->sn, strlen(sess->sn));
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
155
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
156 i = 52; /* 0x34 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
157 i += aimutil_put8(newpacket2->hdr.oft.hdr2+i, 0x00); /* 53 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); /* 55 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);/* 61 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);/* 65 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164 i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);/* end of hdr2 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
165
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
166 newpacket2->lock = 0;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167 newpacket2->data = NULL;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
169 aim_tx_enqueue(sess, newpacket2);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
170
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
171 /* Header packet */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
172
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
173 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0001, conn, strlen(msg)))) {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
174 printf("faim: directim: tx_new failed\n");
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
175 return -1;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
176 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
177
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
178 newpacket->lock = 1; /* lock struct */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
179
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
180 memcpy(newpacket->hdr.oft.magic, "ODC2", 4);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
181 newpacket->hdr.oft.hdr2len = 0x54;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
182
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
183 if (!(newpacket->hdr.oft.hdr2 = calloc(1,newpacket->hdr.oft.hdr2len))) {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
184 free(newpacket);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
185 return -1;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
186 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
187
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
188 i = 0;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
189 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0006);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
190 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
191
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
192 i += aimutil_putstr(newpacket->hdr.oft.hdr2+i, (char *)priv->cookie, 8);
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
193
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
194 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
195 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
196 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
197 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
198
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
199 i += aimutil_put32(newpacket->hdr.oft.hdr2+i, strlen(msg));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
200
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
201 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
202 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
203 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
204 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
205 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
206 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
207
1245
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
208 i += aimutil_putstr(newpacket->hdr.oft.hdr2+i, sess->sn, strlen(sess->sn));
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
209
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
210 i = 52; /* 0x34 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
211 i += aimutil_put8(newpacket->hdr.oft.hdr2+i, 0x00); /* 53 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
212 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); /* 55 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
213 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
214 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
215 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);/* 61 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
216 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
217 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);/* 65 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
218 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);/* end of hdr2 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
219
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
220 /* values grabbed from a dump */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
221 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0008); /* 69 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
222 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x000c);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
223 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);/* 71 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
224 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x1466);/* 73 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
225 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0001);/* 73 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
226 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x2e0f);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
227 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x393e);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
228 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0xcac8);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
229
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
230 memcpy(newpacket->data, msg, strlen(msg));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
231
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
232 newpacket->lock = 0;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
233
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
234 aim_tx_enqueue(sess, newpacket);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
235
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
236 return 0;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
237 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
238
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
239 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
240 * aim_directim_intitiate:
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
241 * For those times when we want to open up the directim channel ourselves.
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
242 * sess is your session,
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
243 * conn is the BOS conn,
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
244 * priv is a dummy priv value (we'll let it get filled in later) (if
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
245 * you pass a NULL, we alloc one)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
246 * destsn is the SN to connect to.
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
247 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
248
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
249
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
250 faim_export struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess,
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
251 struct aim_conn_t *conn,
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
252 struct aim_directim_priv *priv,
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
253 char *destsn)
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
254 {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
255 struct command_tx_struct *newpacket;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
256 struct aim_conn_t *newconn;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
257
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
258 struct aim_msgcookie_t *cookie;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
259
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
260 int curbyte, i, listenfd;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
261 short port = 4443;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
262
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
263 struct hostent *hptr;
889
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
264 char localhost[129];
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
265
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
266 unsigned char cap[16];
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
267 char d[4]; /* XXX: IPv6. *cough* */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
268
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
269 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
270 * Open our socket
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
271 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
272
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
273 if( (listenfd = aim_listenestablish(port)) == -1)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
274 return NULL;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
275
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
276 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
277 * get our local IP
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
278 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
279
889
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
280 if(gethostname(localhost, 128) < 0)
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
281 return NULL;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
282
889
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
283 if( (hptr = gethostbyname(localhost)) == NULL)
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
284 return NULL;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
285
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
286 memcpy(&d, hptr->h_addr_list[0], 4); /* XXX: this probably isn't quite kosher, but it works */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
287
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
288 aim_putcap(cap, 16, AIM_CAPS_IMIMAGE);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
289
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
290 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
291 * create the OSCAR packet
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
292 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
293
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
294 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(destsn)+4+4+0x32)))
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
295 return NULL;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
296
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
297 newpacket->lock = 1; /* lock struct */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
298
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
299 curbyte = 0;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
300 curbyte += aim_putsnac(newpacket->data+curbyte,
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
301 0x0004, 0x0006, 0x0000, sess->snac_nextid);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
302
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
303 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
304 * Generate a random message cookie
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
305 * This cookie needs to be alphanumeric and NULL-terminated to be TOC-compatible.
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
306 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
307 for (i=0;i<7;i++)
889
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
308 curbyte += aimutil_put8(newpacket->data+curbyte, 0x30 + ((u_char) rand() % 20));
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
309 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
310
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
311 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
312 * grab all the data for cookie caching.
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
313 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
314 cookie = (struct aim_msgcookie_t *)calloc(1, sizeof(struct aim_msgcookie_t));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
315
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
316 memcpy(cookie->cookie, newpacket->data+curbyte-8, 8);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
317 cookie->type = AIM_COOKIETYPE_OFTIM;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
318
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
319 if(!priv)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
320 priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
321
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
322 memcpy(priv->cookie, cookie, 8);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
323 memcpy(priv->sn, destsn, sizeof(priv->sn));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
324
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
325 cookie->data = priv;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
326
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
327 aim_cachecookie(sess, cookie); /* cache da cookie */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
328
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
329 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
330 * Channel ID
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
331 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
332 curbyte += aimutil_put16(newpacket->data+curbyte,0x0002);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
333
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
334 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
335 * Destination SN (prepended with byte length)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
336 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
337 curbyte += aimutil_put8(newpacket->data+curbyte,strlen(destsn));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
338 curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
339
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
340 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
341 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
342
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
343 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
344 * enTLV start
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
345 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
346 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
347 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0032);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
348
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
349 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
350 * Flag data / ICBM Parameters?
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
351 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
352 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
353 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
354
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
355 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
356 * Cookie
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
357 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
358 curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cookie, 8);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
359
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
360 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
361 * Capability String
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
362 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
363 curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cap, 0x10);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
364
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
365 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
366 * 000a/0002 : 0001
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
367 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
368 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000a);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
369 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
370 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
371
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
372 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
373 * 0003/0004: IP address
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
374 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
375
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
376 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
377 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0004);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
378
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
379 for(i = 0; i < 4; i++)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
380 curbyte += aimutil_put8(newpacket->data+curbyte, d[i]); /* already in network byte order */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
381
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
382 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
383 * 0005/0002: Port
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
384 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
385
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
386 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
387 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
388 curbyte += aimutil_put16(newpacket->data+curbyte, port);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
389
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
390 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
391 * 000f/0000: umm.. dunno. Zigamorph[1]?
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
392 * [1]: see esr's TNHD.
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
393 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
394
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
395 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000f);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
396 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
397
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
398 printf("curbyte: 0x%x\n",curbyte);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
399
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
400 newpacket->commandlen = curbyte;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
401 newpacket->lock = 0;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
402
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
403 aim_tx_enqueue(sess, newpacket);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
404
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
405 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
406 * allocate and set up our connection
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
407 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
408
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
409 newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
410 if (!newconn) {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
411 perror("aim_newconn");
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
412 aim_conn_kill(sess, &newconn);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
413 return NULL;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
414 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
415
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
416 newconn->fd = listenfd;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
417 newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
418 newconn->priv = priv;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
419 printf("faim: listening (fd = %d, unconnected)\n", newconn->fd);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
420
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
421 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
422 * XXX We need some way of closing the listener socket after
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
423 * n seconds of no connection. -- mid
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
424 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
425
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
426 #ifdef USE_SNAC_FOR_IMS
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
427 {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
428 struct aim_snac_t snac;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
429
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
430 snac.id = sess->snac_nextid;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
431 snac.family = 0x0004;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
432 snac.type = 0x0006;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
433 snac.flags = 0x0000;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
434
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
435 snac.data = malloc(strlen(destsn)+1);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
436 memcpy(snac.data, destsn, strlen(destsn)+1);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
437
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
438 aim_newsnac(sess, &snac);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
439
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
440 aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
441 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
442 #endif
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
443
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
444 return (newconn);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
445 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
446
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
447 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
448 * struct aim_conn_t *aim_directim_connect(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_directim_priv *priv)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
449 * sess is the session to append the conn to,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
450 * conn is the BOS connection,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
451 * priv is the filled-in priv data structure for the connection
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
452 * returns conn if connected, NULL on error
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
453 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
454
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
455
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
456 faim_export struct aim_conn_t *aim_directim_connect(struct aim_session_t *sess,
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
457 struct aim_conn_t *conn,
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
458 struct aim_directim_priv *priv )
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
459 {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
460 struct aim_conn_t *newconn = NULL;;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
461
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
462 newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, priv->ip);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
463 if (!newconn || (newconn->fd == -1)) {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
464 printf("could not connect to %s\n", priv->ip);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
465 perror("aim_newconn");
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
466 aim_conn_kill(sess, &newconn);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
467 return NULL;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
468 } else {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
469 newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
470 newconn->priv = priv;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
471 printf("faim: connected to peer (fd = %d)\n", newconn->fd);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
472 return newconn;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
473 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
474 return newconn;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
475 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
476
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
477 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
478 * struct aim_conn_t *aim_directim_getconn(struct aim_session_t *sess, const char *name)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
479 * sess is your session,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
480 * name is the name to get,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
481 * returns conn for directim with name, NULL if none found.
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
482 */
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
483
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
484 faim_export struct aim_conn_t *aim_directim_getconn(struct aim_session_t *sess, const char *name)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
485 {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
486 struct aim_conn_t *cur;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
487 struct aim_directim_priv *priv;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
488
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
489 faim_mutex_lock(&sess->connlistlock);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
490 for (cur = sess->connlist; cur; cur = cur->next) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
491 if (cur->type != AIM_CONN_TYPE_RENDEZVOUS || cur->subtype != AIM_CONN_SUBTYPE_OFT_DIRECTIM)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
492 continue;
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
493
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
494 priv = cur->priv;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
495 if (aim_sncmp(priv->sn, name) == 0)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
496 break;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
497 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
498 faim_mutex_unlock(&sess->connlistlock);
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
499
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
500 return cur;
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
501 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
502
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
503 /*
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
504 * aim_accepttransfer:
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
505 * accept a file transfer request.
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
506 * sess is the session,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
507 * conn is the BOS conn for the CAP reply
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
508 * sn is the screenname to send it to,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
509 * cookie is the cookie used
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
510 * ip is the ip to connect to
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
511 * file is the listing file to use
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
512 * rendid is CAP type
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
513 *
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
514 * returns connection
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
515 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
516
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
517 faim_export struct aim_conn_t *aim_accepttransfer(struct aim_session_t *sess,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
518 struct aim_conn_t *conn,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
519 char *sn,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
520 char *cookie,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
521 char *ip,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
522 FILE *file,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
523 unsigned short rendid)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
524 {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
525 struct command_tx_struct *newpacket, *newoft;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
526
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
527 struct aim_conn_t *newconn;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
528 struct aim_fileheader_t *listingfh;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
529 struct aim_filetransfer_priv *priv;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
530 struct aim_msgcookie_t *cachedcook;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
531
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
532 int curbyte, i;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
533
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
534 if(rendid == AIM_CAPS_GETFILE) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
535
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
536 newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, ip);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
537
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
538 newconn->subtype = AIM_CONN_SUBTYPE_OFT_GETFILE;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
539
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
540 if (!newconn || (newconn->fd == -1)) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
541 perror("aim_newconn");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
542 faimdprintf(2, "could not connect to %s (fd: %i)\n", ip, newconn?newconn->fd:0);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
543 aim_conn_kill(sess, &newconn);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
544 return NULL;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
545 } else {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
546 priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv));
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
547 memcpy(priv->cookie, cookie, 8);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
548 strncpy(priv->sn, sn, MAXSNLEN);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
549 strncpy(priv->ip, ip, sizeof(priv->ip));
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
550 newconn->priv = (void *)priv;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
551 faimdprintf(2, "faim: connected to peer (fd = %d)\n", newconn->fd);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
552 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
553
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
554 /* cache da cookie. COOOOOKIES! */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
555
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
556 if(!(cachedcook = (struct aim_msgcookie_t *)calloc(1, sizeof(struct aim_msgcookie_t)))) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
557 faimdprintf(1, "faim: accepttransfer: couldn't calloc cachedcook. yeep!\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
558 /* XXX die here, or go on? search for cachedcook for future references */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
559 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
560
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
561 if(cachedcook)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
562 memcpy(cachedcook->cookie, cookie, 8);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
563
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
564 /* strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name)); */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
565
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
566 if(cachedcook) { /* see above calloc of cachedcook */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
567 cachedcook->type = AIM_COOKIETYPE_OFTGET;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
568 cachedcook->data = (void *)priv;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
569
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
570 if (aim_cachecookie(sess, cachedcook) != 0)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
571 faimdprintf(1, "faim: ERROR caching message cookie\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
572 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
573
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
574 if(rendid == AIM_CAPS_GETFILE) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
575 faimdprintf(2, "faim: getfile request accept\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
576 if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x1108, newconn, 0))) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
577 faimdprintf(2, "faim: aim_accepttransfer: tx_new OFT failed\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
578 /* XXX: what else do we need to clean up here? */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
579 return NULL;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
580 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
581
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
582 newoft->lock = 1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
583
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
584 memcpy(newoft->hdr.oft.magic, "OFT2", 4);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
585 newoft->hdr.oft.hdr2len = 0xf8; /* 0x100 - 8 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
586
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
587 if(!(listingfh = aim_getlisting(file))) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
588 return NULL;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
589 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
590
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
591 if (!(newoft->hdr.oft.hdr2 = (char *)calloc(1,newoft->hdr.oft.hdr2len))) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
592 free(newoft);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
593 return NULL;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
594 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
595
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
596 memcpy(listingfh->bcookie, cookie, 8);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
597
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
598 aim_oft_buildheader((void *)newoft->hdr.oft.hdr2, listingfh);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
599
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
600 free(listingfh);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
601
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
602 newoft->lock = 0;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
603 aim_tx_enqueue(sess, newoft);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
604 printf("faim: getfile: OFT listing enqueued.\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
605
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
606 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
607
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
608 /* OSCAR CAP accept packet */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
609
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
610 if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(sn)+4+2+8+16)))
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
611 return NULL;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
612
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
613 newpacket->lock = 1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
614
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
615 curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0006, 0x0000, sess->snac_nextid);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
616 for (i = 0; i < 8; i++)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
617 curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
618 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
619 curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sn));
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
620 curbyte += aimutil_putstr(newpacket->data+curbyte, sn, strlen(sn));
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
621 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
622 curbyte += aimutil_put16(newpacket->data+curbyte, 0x001a);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
623 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002 /* accept */);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
624 for (i = 0; i < 8; i++)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
625 curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
626 curbyte += aim_putcap(newpacket->data+curbyte, 0x10, rendid);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
627
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
628 newpacket->lock = 0;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
629 aim_tx_enqueue(sess, newpacket);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
630
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
631 return newconn;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
632 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
633 return NULL;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
634 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
635
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
636 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
637 * aim_getlisting(FILE *file)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
638 *
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
639 * file is an opened listing file
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
640 * returns a pointer to the filled-in fileheader_t
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
641 *
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
642 * currently omits checksum. we'll fix this when AOL breaks us, i
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
643 * guess.
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
644 *
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
645 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
646
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
647 faim_internal struct aim_fileheader_t *aim_getlisting(FILE *file)
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
648 {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
649 struct aim_fileheader_t *fh;
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
650 u_long totsize = 0, size = 0, checksum = 0xffff0000;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
651 short totfiles = 0;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
652 char *linebuf, sizebuf[9];
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
653
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
654 int linelength = 1024;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
655
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
656 /* XXX: if we have a line longer than 1024chars, God help us. */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
657 if( (linebuf = (char *)calloc(1, linelength)) == NULL ) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
658 faimdprintf(2, "linebuf calloc failed\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
659 return NULL;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
660 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
661
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
662 if(fseek(file, 0, SEEK_END) == -1) { /* use this for sanity check */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
663 perror("getlisting END1 fseek:");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
664 faimdprintf(2, "getlising fseek END1 error\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
665 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
666
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
667 if(fgetpos(file, &size) == -1) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
668 perror("getlisting END1 getpos:");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
669 faimdprintf(2, "getlising getpos END1 error\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
670 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
671
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
672 if(fseek(file, 0, SEEK_SET) != 0) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
673 perror("getlesting fseek(SET):");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
674 faimdprintf(2, "faim: getlisting: couldn't seek to beginning of listing file\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
675 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
676
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
677 bzero(linebuf, linelength);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
678
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
679 size = 0;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
680
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
681 while(fgets(linebuf, linelength, file)) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
682 totfiles++;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
683 bzero(sizebuf, 9);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
684
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
685 size += strlen(linebuf);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
686
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
687 if(strlen(linebuf) < 23) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
688 faimdprintf(2, "line \"%s\" too short. skipping\n", linebuf);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
689 continue;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
690 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
691 if(linebuf[strlen(linebuf)-1] != '\n') {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
692 faimdprintf(2, "faim: OFT: getlisting -- hit EOF or line too long!\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
693 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
694
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
695 memcpy(sizebuf, linebuf+17, 8);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
696
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
697 totsize += strtol(sizebuf, NULL, 10);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
698 bzero(linebuf, linelength);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
699 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
700
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
701 /* if(size != 0) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
702 faimdprintf(2, "faim: getlisting: size != 0 after while.. %i\n", size);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
703 }*/
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
704
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
705 if(fseek(file, 0, SEEK_SET) == -1) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
706 perror("getlisting END2 fseek:");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
707 faimdprintf(2, "getlising fseek END2 error\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
708 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
709
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
710 free(linebuf);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
711
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
712 /* we're going to ignore checksumming the data for now -- that
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
713 * requires walking the whole listing.txt. it should probably be
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
714 * done at register time and cached, but, eh. */
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
715
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
716 if(!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t))))
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
717 return NULL;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
718
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
719 printf( "faim: OFT: getlisting: totfiles: %u, totsize: %lu, size: %lu\n", totfiles, totsize, size);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
720
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
721 fh->encrypt = 0x0000;
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
722 fh->compress = 0x0000;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
723 fh->totfiles = totfiles;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
724 fh->filesleft = totfiles; /* is this right ?*/
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
725 fh->totparts = 0x0001;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
726 fh->partsleft = 0x0001;
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
727 fh->totsize = totsize;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
728 fh->size = size; /* ls -l listing.txt */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
729 fh->modtime = (int)time(NULL); /* we'll go with current time for now */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
730 fh->checksum = checksum; /* XXX: checksum ! */
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
731 fh->rfcsum = 0x00000000;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
732 fh->rfsize = 0x00000000;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
733 fh->cretime = 0x00000000;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
734 fh->rfcsum = 0x00000000;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
735 fh->nrecvd = 0x00000000;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
736 fh->recvcsum = 0x00000000;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
737
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
738 /* memset(fh->idstring, 0, sizeof(fh->idstring)); */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
739 memcpy(fh->idstring, "OFT_Windows ICBMFT V1.1 32", sizeof(fh->idstring));
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
740 memset(fh->idstring+strlen(fh->idstring), 0, sizeof(fh->idstring)-strlen(fh->idstring));
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
741
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
742 fh->flags = 0x02;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
743 fh->lnameoffset = 0x1a;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
744 fh->lsizeoffset = 0x10;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
745
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
746 /* memset(fh->dummy, 0, sizeof(fh->dummy)); */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
747 memset(fh->macfileinfo, 0, sizeof(fh->macfileinfo));
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
748
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
749 fh->nencode = 0x0000; /* we need to figure out these encodings for filenames */
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
750 fh->nlanguage = 0x0000;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
751
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
752 /* memset(fh->name, 0, sizeof(fh->name)); */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
753 memcpy(fh->name, "listing.txt", sizeof(fh->name));
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
754 memset(fh->name+strlen(fh->name), 0, 64-strlen(fh->name));
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
755
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
756 faimdprintf(2, "faim: OFT: listing fh name %s / %s\n", fh->name, (fh->name+(strlen(fh->name))));
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
757 return fh;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
758 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
759
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
760 /*
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
761 * establish: create a listening socket on a port. you need to call
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
762 * accept() when it's connected.
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
763 * portnum is the port number to bind to.
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
764 * returns your fd
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
765 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
766
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
767 faim_internal int aim_listenestablish(u_short portnum)
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
768 {
889
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
769 #if defined(__linux__) /* XXX what other OS's support getaddrinfo? */
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
770 int listenfd;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
771 const int on = 1;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
772 struct addrinfo hints, *res, *ressave;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
773 char serv[5];
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
774 sprintf(serv, "%d", portnum);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
775 memset(&hints, 0, sizeof(struct addrinfo));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
776 hints.ai_flags = AI_PASSIVE;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
777 hints.ai_family = AF_UNSPEC;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
778 hints.ai_socktype = SOCK_STREAM;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
779 if (getaddrinfo(NULL/*any IP*/, serv, &hints, &res) != 0) {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
780 perror("getaddrinfo");
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
781 return -1;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
782 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
783 ressave = res;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
784 do {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
785 listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
786 if (listenfd < 0)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
787 continue;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
788 setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
789 if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
790 break; /* success */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
791 close(listenfd);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
792 } while ( (res = res->ai_next) );
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
793 if (!res)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
794 return -1;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
795 if (listen(listenfd, 1024)!=0) {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
796 perror("listen");
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
797 return -1;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
798 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
799 freeaddrinfo(ressave);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
800 return listenfd;
889
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
801 #else
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
802 int listenfd;
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
803 const int on = 1;
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
804 struct sockaddr_in sockin;
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
805
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
806 if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
807 perror("socket(listenfd)");
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
808 return -1;
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
809 }
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
810 if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on) != 0)) {
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
811 perror("setsockopt(listenfd)");
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
812 close(listenfd);
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
813 return -1;
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
814 }
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
815 memset(&sockin, 0, sizeof(struct sockaddr_in));
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
816 sockin.sin_family = AF_INET;
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
817 sockin.sin_port = htons(portnum);
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
818 if (bind(listenfd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) {
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
819 perror("bind(listenfd)");
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
820 close(listenfd);
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
821 return -1;
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
822 }
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
823 if (listen(listenfd, 4) != 0) {
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
824 perror("listen(listenfd)");
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
825 close(listenfd);
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
826 return -1;
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
827 }
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
828
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
829 return listenfd;
640
2c0a7d245bd2 [gaim-migrate @ 650]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 503
diff changeset
830 #endif
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
831 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
832
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
833 faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn)
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
834 {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
835 unsigned char hdrbuf1[6];
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
836 unsigned char *hdr = NULL;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
837 int hdrlen, hdrtype;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
838 int flags = 0;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
839 rxcallback_t userfunc = NULL;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
840
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
841
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
842 memset(hdrbuf1, 0, sizeof(hdrbuf1));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
843
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
844 faim_mutex_lock(&conn->active); /* gets locked down for the entirety */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
845
889
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
846 if ( (hdrlen = aim_recv(conn->fd, hdrbuf1, 6)) < 6) {
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
847
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
848 faimdprintf(2, "faim: rend: read error (fd: %i) %02x%02x%02x%02x%02x%02x (%i)\n", conn->fd, hdrbuf1[0],hdrbuf1[1],hdrbuf1[0],hdrbuf1[0],hdrbuf1[0],hdrbuf1[0],hdrlen);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
849 faim_mutex_unlock(&conn->active);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
850
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
851 if(hdrlen < 0)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
852 perror("read");
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
853 else { /* disconnected */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
854 switch(conn->subtype) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
855 case AIM_CONN_SUBTYPE_OFT_DIRECTIM: { /* XXX: clean up cookies here ? */
1002
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
856 struct aim_directim_priv *priv = NULL;
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
857 if(!(priv = (struct aim_directim_priv *)conn->priv) )
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
858 return -1; /* not much we can do */
1002
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
859 aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTIM);
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
860
1002
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
861
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
862 if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT)) ) {
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
863 aim_conn_close(conn);
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
864 return userfunc(sess, NULL, conn, priv->sn);
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
865 }
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
866
1002
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
867 break;
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
868 }
1002
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
869
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
870 case AIM_CONN_SUBTYPE_OFT_GETFILE: {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
871 struct aim_filetransfer_priv *priv;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
872 if(!(priv = (struct aim_filetransfer_priv *)conn->priv))
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
873 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
874
1002
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
875 aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTGET);
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
876
1002
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
877 if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEDISCONNECT)) ) {
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
878 aim_conn_close(conn);
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
879 return userfunc(sess, NULL, conn, priv->sn);
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
880 }
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
881
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
882 break;
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
883 }
1002
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
884
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
885 case AIM_CONN_SUBTYPE_OFT_SENDFILE: {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
886 struct aim_filetransfer_priv *priv;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
887 if(!(priv = (struct aim_filetransfer_priv *)conn->priv))
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
888 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
889
1002
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
890 aim_uncachecookie(sess, priv->cookie, AIM_COOKIETYPE_OFTSEND);
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
891
1002
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
892 if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_SENDFILEDISCONNECT)) ) {
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
893 aim_conn_close(conn);
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
894 return userfunc(sess, NULL, conn, priv->sn);
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
895 }
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
896
1002
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
897 break;
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
898 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
899 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
900
1002
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
901 aim_conn_close(conn);
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
902 aim_conn_kill(sess, &conn);
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
903
1d8f05ea6bdf [gaim-migrate @ 1012]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 960
diff changeset
904 return -1;
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
905 }
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
906 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
907
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
908 hdrlen = aimutil_get16(hdrbuf1+4);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
909
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
910 hdrlen -= 6;
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
911 if (!(hdr = malloc(hdrlen))) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
912 faim_mutex_unlock(&conn->active);
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
913 return -1;
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
914 }
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
915
889
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
916 if (aim_recv(conn->fd, hdr, hdrlen) < hdrlen) {
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
917 perror("read");
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
918 faimdprintf(2,"faim: rend: read2 error\n");
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
919 free(hdr);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
920 faim_mutex_unlock(&conn->active);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
921 aim_conn_close(conn);
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
922 return -1;
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
923 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
924
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
925 hdrtype = aimutil_get16(hdr);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
926
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
927 switch (hdrtype) {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
928 case 0x0001: { /* directim */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
929 int payloadlength = 0;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
930 char *snptr = NULL;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
931 struct aim_directim_priv *priv;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
932 int i;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
933
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
934 priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
935
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
936 payloadlength = aimutil_get32(hdr+22);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
937 flags = aimutil_get16(hdr+32);
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
938 snptr = (char *)hdr+38;
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
939
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
940 strncpy(priv->sn, snptr, MAXSNLEN);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
941
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
942 faimdprintf(2, "faim: OFT frame: %04x / %04x / %04x / %s\n", hdrtype, payloadlength, flags, snptr);
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
943
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
944 if (flags == 0x000e) {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
945 faim_mutex_unlock(&conn->active);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
946 if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING)) )
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
947 return userfunc(sess, NULL, snptr);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
948 } else if ((flags == 0x0000) && payloadlength) {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
949 unsigned char *msg;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
950
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
951 if(! (msg = calloc(1, payloadlength+1)) ) {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
952 faim_mutex_unlock(&conn->active);
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
953 return -1;
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
954 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
955
889
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
956 if (aim_recv(conn->fd, msg, payloadlength) < payloadlength) {
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
957 perror("read");
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
958 printf("faim: rend: read3 error\n");
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
959 free(msg);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
960 faim_mutex_unlock(&conn->active);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
961 aim_conn_close(conn);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
962 return -1;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
963 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
964 faim_mutex_unlock(&conn->active);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
965 msg[payloadlength] = '\0';
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
966 faimdprintf(2, "faim: directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, msg);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
967
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
968
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
969 if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) )
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
970 i = userfunc(sess, NULL, conn, snptr, msg);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
971
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
972 free(msg);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
973 return i;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
974 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
975 break;
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
976 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
977 #if 0
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
978 /* currently experimental to a non-compiling degree */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
979 case 0x1108: { /* getfile listing.txt incoming tx->rx */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
980 struct aim_filetransfer_priv *ft;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
981 struct aim_fileheader_t *fh;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
982 struct aim_msgcookie_t *cook;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
983 struct aim_conn_type *newoft;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
984
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
985 int commandlen;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
986 char *data;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
987
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
988 faimdprintf(2,"faim: rend: fileget 0x1108\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
989
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
990 if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
991 faimdprintf(2, "faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
992 faim_mutex_unlock(&conn->active);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
993 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
994 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
995
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
996 ft->state = 1; /* we're waaaaiiiting.. */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
997
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
998 fh = aim_oft_getfh(hdr);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
999
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1000 memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1001
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1002 if(!(cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET))) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1003 faim_mutex_unlock(&conn->active);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1004 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1005 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1006
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1007 if(cook->data)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1008 free(cook->data);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1009
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1010 cook->data = ft;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1011
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1012 aim_cachecookie(sess, cook);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1013
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1014 if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x1209, conn, 0))) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1015 /* XXX: what else do we need to clean up here? */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1016 faim_mutex_unlock(&conn->active);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1017 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1018 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1019
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1020
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1021 aim_oft_buildheader((void *)newoft->hdr.oft.hdr2, ft->fh); /* no change */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1022 newoft->lock = 0;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1023 aim_tx_enqueue(sess, newoft);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1024 break;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1025 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1026 #endif
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1027 case 0x1209: { /* get file listing ack rx->tx */
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1028 struct aim_filetransfer_priv *ft;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1029 struct aim_fileheader_t *fh;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1030 struct aim_msgcookie_t *cook;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1031
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1032 int commandlen;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1033 char *data;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1034
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1035 faimdprintf(2,"faim: rend: fileget 0x1209\n");
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1036
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1037 if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) {
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1038 faimdprintf(2, "faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n");
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1039 faim_mutex_unlock(&conn->active);
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1040 return -1;
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1041 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1042
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1043 fh = aim_oft_getfh(hdr);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1044
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1045 memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1046
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1047 cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1048
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1049 /* we currently trust the other client to be giving us Valid
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1050 * Enough input, else this gets to be a messy function (and we
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1051 * won't break like winaim does when it gets bad input =) */
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1052
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1053 if(cook->data)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1054 free(cook->data); /* XXX */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1055
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1056 cook->data = ft;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1057
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1058 aim_cachecookie(sess, cook);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1059
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1060 /* XXX: have this send chunks of the file instead of the whole
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1061 * file. requires rethinking some code. */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1062
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1063 if(fseek(sess->oft.listing, 0, SEEK_SET) != 0) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1064 perror("get_command_rendezvous 1209 fseek(SET):");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1065 faimdprintf(2, "faim: getlisting: couldn't seek to beginning of listing file\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1066 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1067 commandlen = ft->fh.size;
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1068
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1069 if((data = (char *)calloc(1, commandlen)) == NULL) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1070 faimdprintf(2, "faim: get_command_rendezvous 1209: couldn't malloc data.\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1071 faim_mutex_unlock(&conn->active);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1072 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1073
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1074 }
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1075
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1076 for(commandlen = 0; commandlen < ft->fh.size; commandlen++)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1077 if( (data[commandlen] = (unsigned char)fgetc(sess->oft.listing)) == EOF)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1078 faimdprintf(2, "faim: get_command_rendezvous 1209: got early EOF (error?)\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1079
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1080 commandlen = ft->fh.size;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1081
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1082 if (write(conn->fd, data, commandlen) != commandlen) {
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1083 perror("listing write error");
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1084 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1085 faim_mutex_unlock(&conn->active);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1086
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1087 faimdprintf(2, "faim: get_command_rendezvous: hit end of 1209\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1088
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1089 free(data);
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1090
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1091 break;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1092 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1093 case 0x120b: { /* get file second */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1094 struct aim_filetransfer_priv *ft;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1095 struct aim_msgcookie_t *cook;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1096
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1097 struct aim_fileheader_t *fh;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1098
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1099 faimdprintf(2, "faim: rend: fileget 120b\n");
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1100
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1101 if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) {
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1102 faimdprintf(2, "faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n");
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1103 faim_mutex_unlock(&conn->active);
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1104 return -1;
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1105 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1106
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1107 fh = aim_oft_getfh(hdr);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1108
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1109 memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1110
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1111 if(!(cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET))) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1112 faim_mutex_unlock(&conn->active);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1113 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1114 }
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1115
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1116 if(cook->data)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1117 free(cook->data); /* XXX: integrate cookie caching */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1118
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1119 cook->data = ft;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1120
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1121 aim_cachecookie(sess, cook);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1122
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1123 faim_mutex_unlock(&conn->active);
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1124
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1125 /* call listing.txt rx confirm */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1126
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1127 break;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1128 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1129 case 0x120c: { /* yet more get file */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1130 struct aim_filetransfer_priv *ft;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1131 struct aim_msgcookie_t *cook;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1132 struct aim_fileheader_t *listingfh;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1133 struct command_tx_struct *newoft;
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1134
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1135 int i;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1136
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1137 rxcallback_t userfunc;
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1138
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1139 printf("faim: rend: fileget 120c\n");
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1140
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1141 if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1142 printf("faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n");
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1143 faim_mutex_unlock(&conn->active);
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1144 return -1;
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1145 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1146
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1147 if(hdrlen != 0x100)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1148 printf("faim: fileget_command(120c): um. hdrlen != 0x100..\n");
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1149
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1150 listingfh = aim_oft_getfh((char *)hdr);
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1151
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1152 memcpy(&(ft->fh), listingfh, sizeof(struct aim_fileheader_t));
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1153
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1154 if(!(cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET))) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1155 faim_mutex_unlock(&conn->active);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1156 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1157 }
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1158
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1159 if(cook->data)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1160 free(cook->data); /* XXX */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1161
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1162 cook->data = ft;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1163
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1164 aim_cachecookie(sess, cook);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1165
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1166 faim_mutex_unlock(&conn->active);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1167
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1168 faimdprintf(2, "faim: fileget: %s seems to want %s\n", ft->sn, ft->fh.name);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1169
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1170 if( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) )
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1171 i = userfunc(sess, NULL, conn, &ft->fh, cook->cookie);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1172
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1173 if(i < 0)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1174 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1175
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1176 if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0101, conn, 0))) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1177 faimdprintf(2, "faim: send_final_transfer: tx_new OFT failed\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1178 return -1;
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1179 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1180
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1181 newoft->lock = 1;
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1182
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1183 memcpy(newoft->hdr.oft.magic, "OFT2", 4);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1184 newoft->hdr.oft.hdr2len = 0xf8; /* 0x100 - 8 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1185
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1186 if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) {
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1187 newoft->lock = 0;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1188 aim_tx_destroy(newoft);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1189 return -1;
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1190 }
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1191
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1192 /* memcpy(listingfh->bcookie, ft->fh.bcookie, 8); */
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1193
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1194 listingfh->nrecvd = 0; /* these need reset for protocol-correctness */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1195 listingfh->recvcsum = 0;
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1196
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1197 aim_oft_buildheader((void *)newoft->hdr.oft.hdr2, listingfh);
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1198
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1199 newoft->lock = 0;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1200 aim_tx_enqueue(sess, newoft);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1201 faimdprintf(2, "faim: OFT: OFT file enqueued.\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1202
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1203 if( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ)) == NULL)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1204 return 1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1205
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1206 i = userfunc(sess, NULL, conn, listingfh, listingfh->bcookie);
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1207
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1208 free(listingfh);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1209
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1210 return i;
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1211
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1212 break;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1213 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1214 case 0x0202: { /* get file: ready to recieve data */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1215 struct aim_fileheader_t *fh;
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1216 fh = aim_oft_getfh((char *)hdr);
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1217
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1218 faimdprintf(2, "faim: get_rend: looks like we're ready to send data.(oft 0x0202)\n");
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1219
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1220 faim_mutex_unlock(&conn->active);
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1221
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1222 if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND)) == NULL)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1223 return 1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1224
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1225 return userfunc(sess, NULL, conn, fh);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1226
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1227 free(fh);
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1228
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1229 break;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1230 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1231 case 0x0204: { /* get file: finished. close it up */
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1232 int i;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1233
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1234 struct aim_fileheader_t *fh;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1235 fh = aim_oft_getfh((char *)hdr);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1236
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1237 faimdprintf(2, "faim: get_rend: looks like we're done with a transfer (oft 0x0204)\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1238
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1239 faim_mutex_unlock(&conn->active);
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1240
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1241 if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE)) )
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1242 i = userfunc(sess, NULL, conn, fh);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1243 else
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1244 i = 1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1245
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1246 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1247 free(fh); */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1248 /* not sure where to do this yet, as we need to keep it to allow multiple file sends... bleh */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1249
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1250 return i;
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1251 break;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1252 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1253 default: {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1254 printf("OFT frame: type %04x\n", hdrtype);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1255 /* data connection may be unreliable here */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1256 faim_mutex_unlock(&conn->active);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1257 break;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1258 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1259 } /* switch */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1260
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1261 free(hdr);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1262
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1263 return 0;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1264 }
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1265
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1266 /*
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1267 * aim_oft_registerlisting()
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1268 * sess: aim session
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1269 * file: opened FILE *
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1270 * listingdir: the path to listing.txt
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1271 * returns -1 on error, 0 on success.
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1272 *
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1273 * it's not my problem if the listing fd is already set.
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1274 */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1275
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1276 faim_export int aim_oft_registerlisting(struct aim_session_t *sess, FILE *file, char* listingdir)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1277 {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1278 if(!sess)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1279 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1280
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1281 /* XXX: checksum each file in the listing */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1282
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1283 #if 0
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1284 if(sess->oft.listing) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1285 faimdprintf(1, "We already have a file pointer. Closing and overwriting.\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1286 fclose(sess->oft.listing);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1287 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1288 #endif
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1289 sess->oft.listing = file;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1290 #if 0
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1291 if(sess->oft.listingdir) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1292 faimdprintf(1, "We already have a directory string. Freeing and overwriting\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1293 free(sess->oft.listingdir);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1294 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1295 #endif
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1296
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1297 if( (sess->oft.listingdir = (char *)calloc(1, strlen(listingdir)+1)) )
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1298 memcpy(sess->oft.listingdir, listingdir, strlen(listingdir));
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1299 else
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1300 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1301 return 0;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1302 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1303
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 642
diff changeset
1304 faim_internal struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr)
503
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1305 {
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1306 struct aim_fileheader_t *fh;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1307 int i, j;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1308
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1309 if(!(fh = calloc(1, sizeof(struct aim_fileheader_t))))
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1310 return NULL;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1311
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1312 /* [0] and [1] are the type. we can ignore those here. */
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1313
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1314 i = 2;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1315
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1316 for(j = 0; j < 8; j++, i++)
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1317 fh->bcookie[j] = hdr[i];
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1318 fh->encrypt = aimutil_get16(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1319 i += 2;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1320 fh->compress = aimutil_get16(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1321 i += 2;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1322 fh->totfiles = aimutil_get16(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1323 i += 2;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1324 fh->filesleft = aimutil_get16(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1325 i += 2;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1326 fh->totparts = aimutil_get16(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1327 i += 2;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1328 fh->partsleft = aimutil_get16(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1329 i += 2;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1330 fh->totsize = aimutil_get32(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1331 i += 4;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1332 fh->size = aimutil_get32(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1333 i += 4;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1334 fh->modtime = aimutil_get32(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1335 i += 4;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1336 fh->checksum = aimutil_get32(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1337 i += 4;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1338 fh->rfrcsum = aimutil_get32(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1339 i += 4;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1340 fh->rfsize = aimutil_get32(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1341 i += 4;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1342 fh->cretime = aimutil_get32(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1343 i += 4;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1344 fh->rfcsum = aimutil_get32(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1345 i += 4;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1346 fh->nrecvd = aimutil_get32(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1347 i += 4;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1348 fh->recvcsum = aimutil_get32(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1349 i += 4;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1350
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1351 memcpy(fh->idstring, hdr+i, 32);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1352 i += 32;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1353
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1354 fh->flags = aimutil_get8(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1355 i += 1;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1356 fh->lnameoffset = aimutil_get8(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1357 i += 1;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1358 fh->lsizeoffset = aimutil_get8(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1359 i += 1;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1360
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1361 memcpy(fh->dummy, hdr+i, 69);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1362 i += 69;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1363
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1364 memcpy(fh->macfileinfo, hdr+i, 16);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1365 i += 16;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1366
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1367 fh->nencode = aimutil_get16(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1368 i += 2;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1369 fh->nlanguage = aimutil_get16(hdr+i);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1370 i += 2;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1371
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1372 memcpy(fh->name, hdr+i, 64);
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1373 i += 64;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1374
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1375 return fh;
6e318907bcce [gaim-migrate @ 513]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1376 }
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1377
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1378 faim_export int aim_oft_checksum(char *buffer, int bufsize, int *checksum)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1379 {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1380 short check0, check1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1381 int i;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1382
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1383 check0 = ((*checksum & 0xFF000000) >> 16);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1384 check1 = ((*checksum & 0x00ff0000) >> 16);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1385
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1386 for(i = 0; i < bufsize; i++) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1387
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1388 if(i % 2) { /* use check1 -- second byte */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1389 if ( (short)buffer[i] > check1 ) { /* wrapping */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1390
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1391 check1 += 0x100; /* this is a cheap way to wrap */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1392
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1393 /* if we're wrapping, decrement the other one */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1394 if(check0 == 0) /* XXX: check this corner case */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1395 check0 = 0x00ff;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1396 else
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1397 check0--;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1398 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1399
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1400 check1 -= buffer[i];
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1401 } else { /* use check0 -- first byte */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1402 if ( (short)buffer[i] > check0 ) { /* wrapping */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1403
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1404 check0 += 0x100; /* this is a cheap way to wrap */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1405
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1406 /* if we're wrapping, decrement the other one */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1407 if(check1 == 0) /* XXX: check this corner case */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1408 check1 = 0x00ff;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1409 else
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1410 check1--;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1411 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1412
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1413 check0 -= buffer[i];
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1414 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1415 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1416
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1417 if(check0 > 0xff || check1 > 0xff) { /* they shouldn't be able to do this. error! */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1418 faimdprintf(2, "check0 or check1 is too high: 0x%04x, 0x%04x\n", check0, check1);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1419 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1420 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1421
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1422 check0 &= 0xff; /* grab just the lowest byte */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1423 check1 &= 0xff; /* this should be clean, but just in case */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1424
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1425 *checksum = ((check0 * 0x1000000) + (check1 * 0x10000));
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1426
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1427 return *checksum;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1428 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1429
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1430
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1431 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1432 * aim_oft_buildheader:
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1433 * fills a buffer with network-order fh data.
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1434 * returns length written; -1 on error.
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1435 * dest: buffer to fill -- pre-alloced
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1436 * listingfh: fh to get data from
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1437 *
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1438 * DOES NOT DO BOUNDS CHECKING!
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1439 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1440
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1441
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1442 faim_internal int aim_oft_buildheader(char *dest,struct aim_fileheader_t *listingfh)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1443 {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1444 int i, curbyte;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1445
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1446 if(!dest || !listingfh)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1447 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1448
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1449 curbyte = 0;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1450 for(i = 0; i < 8; i++)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1451 curbyte += aimutil_put8(dest+curbyte, listingfh->bcookie[i]);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1452 curbyte += aimutil_put16(dest+curbyte, listingfh->encrypt);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1453 curbyte += aimutil_put16(dest+curbyte, listingfh->compress);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1454 curbyte += aimutil_put16(dest+curbyte, listingfh->totfiles);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1455 curbyte += aimutil_put16(dest+curbyte, listingfh->filesleft);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1456 curbyte += aimutil_put16(dest+curbyte, listingfh->totparts);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1457 curbyte += aimutil_put16(dest+curbyte, listingfh->partsleft);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1458 curbyte += aimutil_put32(dest+curbyte, listingfh->totsize);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1459 curbyte += aimutil_put32(dest+curbyte, listingfh->size);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1460 curbyte += aimutil_put32(dest+curbyte, listingfh->modtime);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1461 curbyte += aimutil_put32(dest+curbyte, listingfh->checksum);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1462 curbyte += aimutil_put32(dest+curbyte, listingfh->rfrcsum);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1463 curbyte += aimutil_put32(dest+curbyte, listingfh->rfsize);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1464 curbyte += aimutil_put32(dest+curbyte, listingfh->cretime);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1465 curbyte += aimutil_put32(dest+curbyte, listingfh->rfcsum);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1466 curbyte += aimutil_put32(dest+curbyte, listingfh->nrecvd);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1467 curbyte += aimutil_put32(dest+curbyte, listingfh->recvcsum);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1468
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1469 memcpy(dest+curbyte, listingfh->idstring, 32);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1470 curbyte += 32;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1471
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1472 curbyte += aimutil_put8(dest+curbyte, listingfh->flags);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1473 curbyte += aimutil_put8(dest+curbyte, listingfh->lnameoffset);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1474 curbyte += aimutil_put8(dest+curbyte, listingfh->lsizeoffset);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1475
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1476 memcpy(dest+curbyte, listingfh->dummy, 69);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1477 curbyte += 69;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1478
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1479 memcpy(dest+curbyte, listingfh->macfileinfo, 16);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1480 curbyte += 16;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1481
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1482 curbyte += aimutil_put16(dest+curbyte, listingfh->nencode);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1483 curbyte += aimutil_put16(dest+curbyte, listingfh->nlanguage);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1484
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1485 memcpy(dest+curbyte, listingfh->name, 64); /* XXX: Filenames longer than 64B */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1486 curbyte += 64;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1487
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1488 return curbyte;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1489 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1490
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1491 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1492 * int aim_getfile_send(struct aim_conn_t *conn, FILE *tosend, struct aim_fileheader_t *fh)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1493 * conn is the OFT connection to shove the data down,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1494 * tosend is the FILE * for the file to send
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1495 * fh is the filled-in fh value
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1496 * returns -1 on error, 1 on success.
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1497 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1498
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1499 faim_export int aim_getfile_send(struct aim_conn_t *conn, FILE *tosend, struct aim_fileheader_t *fh)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1500 {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1501 int pos, bufpos, i;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1502 const int bufsize = 4096;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1503 char *buf;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1504
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1505 /* sanity checks */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1506 if(conn->type != AIM_CONN_TYPE_RENDEZVOUS || conn->subtype != AIM_CONN_SUBTYPE_OFT_GETFILE) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1507 faimdprintf(1, "getfile_send: conn->type(0x%04x) != RENDEZVOUS or conn->subtype(0x%04x) != GETFILE\n", conn->type, conn->subtype);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1508 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1509 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1510
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1511 if(!tosend) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1512 faimdprintf(1, "getfile_send: file pointer isn't valid\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1513 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1514 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1515
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1516 if(!fh) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1517 faimdprintf(1, "getfile_send: fh isn't valid\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1518 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1519 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1520
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1521 /* real code */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1522
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1523 if(!(buf = (char *)calloc(1, bufsize))) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1524 perror("faim: getfile_send: calloc:");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1525 faimdprintf(2, "getfile_send calloc error\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1526 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1527 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1528
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1529 pos = 0;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1530
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1531 if( fseek(tosend, 0, SEEK_SET) == -1) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1532 perror("faim: getfile_send: fseek:");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1533 faimdprintf(2, "getfile_send fseek error\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1534 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1535
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1536 faimdprintf(2, "faim: getfile_send: using %i byte blocks\n", bufsize);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1537
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1538 for(pos = 0; pos < fh->size; pos++) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1539 bufpos = pos % bufsize;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1540
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1541 if(bufpos == 0 && pos > 0) { /* filled our buffer. spit it across the wire */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1542 if ( (i = write(conn->fd, buf, bufsize)) != bufsize ) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1543 perror("faim: getfile_send: write1: ");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1544 faimdprintf(1, "faim: getfile_send: whoopsy, didn't write it all...\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1545 free(buf);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1546 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1547 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1548 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1549 if( (buf[bufpos] = fgetc(tosend)) == EOF) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1550 if(pos != fh->size) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1551 printf("faim: getfile_send: hrm... apparent early EOF at pos 0x%x of 0x%lx\n", pos, fh->size);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1552 faimdprintf(1, "faim: getfile_send: hrm... apparent early EOF at pos 0x%lx of 0x%lx\n", pos, fh->size);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1553 free(buf);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1554 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1555 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1556 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1557
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1558
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1559 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1560
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1561 if( (i = write(conn->fd, buf, bufpos+1)) != (bufpos+1)) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1562 perror("faim: getfile_send: write2: ");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1563 faimdprintf(1, "faim: getfile_send cleanup: whoopsy, didn't write it all...\n");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1564 free(buf);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1565 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1566 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1567
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1568 free(buf);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1569
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1570 fclose(tosend);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1571 return 1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1572 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1573
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1574 /*
1245
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1575 * int aim_getfile_send_chunk(struct aim_conn_t *conn, FILE *tosend, struct aim_fileheader_t *fh, int pos, int bufsize)
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1576 * conn is the OFT connection to shove the data down,
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1577 * tosend is the FILE * for the file to send
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1578 * fh is the filled-in fh value
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1579 * pos is the position to start at (at beginning should be 0, after 5
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1580 * bytes are sent should be 5); -1 for "don't seek"
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1581 * bufsize is the size of the chunk to send
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1582 *
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1583 * returns -1 on error, new pos on success.
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1584 *
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1585 *
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1586 * Notes on usage:
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1587 * You don't really have to keep track of pos if you don't want
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1588 * to. just always call with -1 for pos, and it'll use the one
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1589 * contained within the FILE *.
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1590 *
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1591 * if (pos + chunksize > fh->size), we only send as much data as we
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1592 * can get (ie: up to fh->size.
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1593 */
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1594 faim_export int aim_getfile_send_chunk(struct aim_conn_t *conn, FILE *tosend, struct aim_fileheader_t *fh, int pos, int bufsize)
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1595 {
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1596 int bufpos;
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1597 char *buf;
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1598
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1599 /* sanity checks */
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1600 if(conn->type != AIM_CONN_TYPE_RENDEZVOUS || conn->type != AIM_CONN_SUBTYPE_OFT_GETFILE) {
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1601 faimdprintf(1, "faim: getfile_send_chunk: conn->type(0x%04x) != RENDEZVOUS or conn->subtype(0x%04x) != GETFILE\n", conn->type, conn->subtype);
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1602 return -1;
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1603 }
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1604
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1605 if(!tosend) {
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1606 faimdprintf(1, "faim: getfile_send_chunk: file pointer isn't valid\n");
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1607 return -1;
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1608 }
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1609
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1610 if(!fh) {
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1611 faimdprintf(1, "faim: getfile_send_chunk: fh isn't valid\n");
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1612 return -1;
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1613 }
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1614
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1615 /* real code */
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1616
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1617 if(!(buf = (char *)calloc(1, bufsize))) {
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1618 perror("faim: getfile_send_chunk: calloc:");
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1619 faimdprintf(2, "faim: getfile_send_chunk calloc error\n");
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1620 return -1;
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1621 }
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1622
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1623 if(pos != -1) {
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1624 if( fseek(tosend, pos, SEEK_SET) == -1) {
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1625 perror("faim: getfile_send_chunk: fseek:");
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1626 faimdprintf(2, "faim: getfile_send_chunk fseek error\n");
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1627 }
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1628 }
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1629
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1630 faimdprintf(2, "faim: getfile_send_chunk: using %i byte blocks\n", bufsize);
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1631
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1632 for(bufpos = 0; pos < fh->size; bufpos++, pos++) {
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1633 if( (buf[bufpos] = fgetc(tosend)) == EOF) {
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1634 if(pos != fh->size) {
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1635 faimdprintf(1, "faim: getfile_send_chunk: hrm... apparent early EOF at pos 0x%x of 0x%x\n", pos, fh->size);
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1636 free(buf);
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1637 return -1;
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1638 }
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1639 }
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1640 }
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1641
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1642 if( write(conn->fd, buf, bufpos+1) != (bufpos+1)) {
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1643 faimdprintf(1, "faim: getfile_send_chunk cleanup: whoopsy, didn't write it all...\n");
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1644 free(buf);
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1645 return -1;
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1646 }
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1647
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1648 free(buf);
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1649
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1650 return (pos + bufpos);
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1651 }
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1652
2ac6ccb94229 [gaim-migrate @ 1255]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1200
diff changeset
1653 /*
960
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1654 * aim_tx_destroy:
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1655 * free's tx_command_t's. if command is locked, doesn't free.
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1656 * returns -1 on error (locked struct); 0 on success.
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1657 * command is the command to free
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1658 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1659
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1660 faim_internal int aim_tx_destroy(struct command_tx_struct *command)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1661 {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1662 if(command->lock)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1663 return -1;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1664 if(command->data)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1665 free(command->data);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1666 free(command);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1667
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1668 return 0;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1669 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1670
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1671 #if 0
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1672 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1673 * aim_getfile_intitiate:
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1674 * For those times when we want to open up the directim channel ourselves.
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1675 * sess is your session,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1676 * conn is the BOS conn,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1677 * priv is a dummy priv value (we'll let it get filled in later) (if
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1678 * you pass a NULL, we alloc one)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1679 * destsn is the SN to connect to.
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1680 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1681
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1682
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1683 faim_export struct aim_conn_t *aim_getfile_initiate(struct aim_session_t *sess,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1684 struct aim_conn_t *conn,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1685 struct aim_getfile_priv *priv,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1686 char *destsn)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1687 {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1688 struct command_tx_struct *newpacket;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1689 struct aim_conn_t *newconn;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1690
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1691 struct aim_msgcookie_t *cookie;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1692
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1693 int curbyte, i, listenfd;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1694 short port = 4443;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1695
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1696 struct hostent *hptr;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1697 struct utsname myname;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1698
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1699 char cap[16];
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1700 char d[4]; /* XXX: IPv6. *cough* */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1701
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1702 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1703 * Open our socket
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1704 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1705
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1706 if( (listenfd = aim_listenestablish(port)) == -1)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1707 return NULL;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1708
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1709 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1710 * get our local IP
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1711 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1712
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1713 if(uname(&myname) < 0)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1714 return NULL;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1715
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1716 if( (hptr = gethostbyname(myname.nodename)) == NULL)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1717 return NULL;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1718
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1719 memcpy(&d, hptr->h_addr_list[0], 4); /* XXX: this probably isn't quite kosher, but it works */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1720
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1721 aim_putcap(cap, 16, AIM_CAPS_IMIMAGE);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1722
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1723 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1724 * create the OSCAR packet
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1725 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1726
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1727 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(destsn)+4+4+0x32)))
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1728 return NULL;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1729
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1730 newpacket->lock = 1; /* lock struct */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1731
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1732 curbyte = 0;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1733 curbyte += aim_putsnac(newpacket->data+curbyte,
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1734 0x0004, 0x0006, 0x0000, sess->snac_nextid);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1735
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1736 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1737 * Generate a random message cookie
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1738 * This cookie needs to be alphanumeric and NULL-terminated to be TOC-compatible.
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1739 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1740 for (i=0;i<7;i++)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1741 curbyte += aimutil_put8(newpacket->data+curbyte, 0x30 + ((u_char) random() % 20));
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1742 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1743
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1744 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1745 * grab all the data for cookie caching.
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1746 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1747 cookie = (struct aim_msgcookie_t *)calloc(1, sizeof(struct aim_msgcookie_t));
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1748
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1749 memcpy(cookie->cookie, newpacket->data+curbyte-8, 8);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1750 cookie->type = AIM_COOKIETYPE_OFTIM;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1751
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1752 if(!priv)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1753 priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv));
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1754
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1755 memcpy(priv->cookie, cookie, 8);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1756 memcpy(priv->sn, destsn, sizeof(priv->sn));
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1757
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1758 cookie->data = priv;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1759
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1760 aim_cachecookie(sess, cookie); /* cache da cookie */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1761
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1762 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1763 * Channel ID
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1764 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1765 curbyte += aimutil_put16(newpacket->data+curbyte,0x0002);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1766
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1767 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1768 * Destination SN (prepended with byte length)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1769 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1770 curbyte += aimutil_put8(newpacket->data+curbyte,strlen(destsn));
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1771 curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn));
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1772
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1773 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1774 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1775
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1776 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1777 * enTLV start
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1778 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1779 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1780 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0032);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1781
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1782 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1783 * Flag data / ICBM Parameters?
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1784 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1785 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1786 curbyte += aimutil_put8(newpacket->data+curbyte, 0x00);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1787
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1788 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1789 * Cookie
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1790 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1791 curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cookie, 8);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1792
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1793 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1794 * Capability String
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1795 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1796 curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cap, 0x10);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1797
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1798 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1799 * 000a/0002 : 0001
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1800 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1801 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000a);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1802 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1803 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1804
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1805 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1806 * 0003/0004: IP address
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1807 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1808
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1809 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1810 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0004);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1811
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1812 for(i = 0; i < 4; i++)
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1813 curbyte += aimutil_put8(newpacket->data+curbyte, d[i]); /* already in network byte order */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1814
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1815 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1816 * 0005/0002: Port
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1817 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1818
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1819 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1820 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1821 curbyte += aimutil_put16(newpacket->data+curbyte, port);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1822
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1823 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1824 * 000f/0000: umm.. dunno. Zigamorph[1]?
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1825 * [1]: see esr's TNHD.
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1826 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1827
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1828 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000f);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1829 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1830
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1831 printf("curbyte: 0x%x\n",curbyte);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1832
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1833 newpacket->commandlen = curbyte;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1834 newpacket->lock = 0;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1835
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1836 aim_tx_enqueue(sess, newpacket);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1837
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1838 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1839 * allocate and set up our connection
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1840 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1841
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1842 i = fcntl(listenfd, F_GETFL, 0);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1843 fcntl(listenfd, F_SETFL, i | O_NONBLOCK);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1844
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1845 newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1846 if (!newconn) {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1847 perror("aim_newconn");
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1848 aim_conn_kill(sess, &newconn);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1849 return NULL;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1850 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1851
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1852 newconn->fd = listenfd;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1853 newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1854 newconn->priv = priv;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1855 printf("faim: listening (fd = %d, unconnected)\n", newconn->fd);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1856
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1857 /*
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1858 * XXX We need some way of closing the listener socket after
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1859 * n seconds of no connection. -- mid
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1860 */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1861
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1862 #ifdef USE_SNAC_FOR_IMS
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1863 {
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1864 struct aim_snac_t snac;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1865
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1866 snac.id = sess->snac_nextid;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1867 snac.family = 0x0004;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1868 snac.type = 0x0006;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1869 snac.flags = 0x0000;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1870
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1871 snac.data = malloc(strlen(destsn)+1);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1872 memcpy(snac.data, destsn, strlen(destsn)+1);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1873
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1874 aim_newsnac(sess, &snac);
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1875
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1876 aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1877 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1878 #endif
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1879
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1880 return newconn;
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1881 }
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1882
fa681641643d [gaim-migrate @ 970]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 932
diff changeset
1883 #endif