comparison src/protocols/oscar/ft.c @ 2993:7239a392486c

[gaim-migrate @ 3006] 0.53 :) committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Sat, 02 Mar 2002 04:52:21 +0000
parents 10a2d4d5bcf2
children 08327a2f25aa
comparison
equal deleted inserted replaced
2992:d16a0504f1c8 2993:7239a392486c
107 107
108 return ret; 108 return ret;
109 } 109 }
110 110
111 /** 111 /**
112 * aim_send_typing - send client-to-client typing notification over established connection
113 * @sess: session to conn
114 * @conn: directim connection
115 * @typing: If true, notify user has started typing; if false, notify user has stopped.
116 *
117 * The connection must have been previously established.
118 */
119 faim_export int aim_send_typing(aim_session_t *sess, aim_conn_t *conn, int typing)
120 {
121
122 struct aim_directim_intdata *intdata = (struct aim_directim_intdata *)conn->internal;
123 aim_frame_t *fr;
124 aim_bstream_t hdrbs; /* XXX this should be within aim_frame_t */
125
126 if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS))
127 return -EINVAL;
128
129 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x01, 0)))
130 return -ENOMEM;
131
132 memcpy(fr->hdr.oft.magic, "ODC2", 4);
133
134 fr->hdr.oft.hdr2len = 0x44;
135
136 if (!(fr->hdr.oft.hdr2 = calloc(1, fr->hdr.oft.hdr2len))) {
137 aim_frame_destroy(fr);
138 return -ENOMEM;
139 }
140
141 aim_bstream_init(&hdrbs, fr->hdr.oft.hdr2, fr->hdr.oft.hdr2len);
142
143 aimbs_put16(&hdrbs, 0x0006);
144 aimbs_put16(&hdrbs, 0x0000);
145 aimbs_putraw(&hdrbs, intdata->cookie, 8);
146 aimbs_put16(&hdrbs, 0x0000);
147 aimbs_put16(&hdrbs, 0x0000);
148 aimbs_put16(&hdrbs, 0x0000);
149 aimbs_put16(&hdrbs, 0x0000);
150 aimbs_put32(&hdrbs, 0x00000000);
151 aimbs_put16(&hdrbs, 0x0000);
152 aimbs_put16(&hdrbs, 0x0000);
153 aimbs_put16(&hdrbs, 0x0000);
154
155 /* flags -- 0x000e for "started typing", 0x0002 for "stopped typing */
156 aimbs_put16(&hdrbs, ( typing ? 0x000e : 0x0002));
157
158 aimbs_put16(&hdrbs, 0x0000);
159 aimbs_put16(&hdrbs, 0x0000);
160 aimbs_putraw(&hdrbs, sess->sn, strlen(sess->sn));
161
162 aim_bstream_setpos(&hdrbs, 52); /* bleeehh */
163
164 aimbs_put8(&hdrbs, 0x00);
165 aimbs_put16(&hdrbs, 0x0000);
166 aimbs_put16(&hdrbs, 0x0000);
167 aimbs_put16(&hdrbs, 0x0000);
168 aimbs_put16(&hdrbs, 0x0000);
169 aimbs_put16(&hdrbs, 0x0000);
170 aimbs_put16(&hdrbs, 0x0000);
171 aimbs_put16(&hdrbs, 0x0000);
172
173 /* end of hdr2 */
174
175 aim_tx_enqueue(sess, fr);
176
177 return 0;
178 }
179
180 /**
112 * aim_send_im_direct - send IM client-to-client over established connection 181 * aim_send_im_direct - send IM client-to-client over established connection
113 * @sess: session to conn 182 * @sess: session to conn
114 * @conn: directim connection 183 * @conn: directim connection
115 * @msg: null-terminated string to send; if this is NULL, it will send a "typing" notice. 184 * @msg: null-terminated string to send.
116 * 185 *
117 * Call this just like you would aim_send_im, to send a directim. You 186 * Call this just like you would aim_send_im, to send a directim. You
118 * _must_ have previously established the directim connection. 187 * _must_ have previously established the directim connection.
119 */ 188 */
120 faim_export int aim_send_im_direct(aim_session_t *sess, aim_conn_t *conn, const char *msg) 189 faim_export int aim_send_im_direct(aim_session_t *sess, aim_conn_t *conn, const char *msg)
121 { 190 {
122 struct aim_directim_intdata *intdata = (struct aim_directim_intdata *)conn->internal; 191 struct aim_directim_intdata *intdata = (struct aim_directim_intdata *)conn->internal;
123 aim_frame_t *fr; 192 aim_frame_t *fr;
124 aim_bstream_t hdrbs; /* XXX this should be within aim_frame_t */ 193 aim_bstream_t hdrbs; /* XXX this should be within aim_frame_t */
125 194
126 if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS)) 195 if (!sess || !conn || !msg || (conn->type != AIM_CONN_TYPE_RENDEZVOUS))
127 return -EINVAL; 196 return -EINVAL;
128 197
129 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x01, strlen(msg)))) 198 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_OFT, 0x01, strlen(msg))))
130 return -ENOMEM; 199 return -ENOMEM;
131 200
132 memcpy(fr->hdr.oft.magic, "ODC2", 4); 201 memcpy(fr->hdr.oft.magic, "ODC2", 4);
133 202
134 fr->hdr.oft.hdr2len = 0x44; 203 fr->hdr.oft.hdr2len = 0x44;
135 204
137 aim_frame_destroy(fr); 206 aim_frame_destroy(fr);
138 return -ENOMEM; 207 return -ENOMEM;
139 } 208 }
140 209
141 aim_bstream_init(&hdrbs, fr->hdr.oft.hdr2, fr->hdr.oft.hdr2len); 210 aim_bstream_init(&hdrbs, fr->hdr.oft.hdr2, fr->hdr.oft.hdr2len);
142 211
143 aimbs_put16(&hdrbs, 0x0006); 212 aimbs_put16(&hdrbs, 0x0006);
144 aimbs_put16(&hdrbs, 0x0000); 213 aimbs_put16(&hdrbs, 0x0000);
145 aimbs_putraw(&hdrbs, intdata->cookie, 8); 214 aimbs_putraw(&hdrbs, intdata->cookie, 8);
146 aimbs_put16(&hdrbs, 0x0000); 215 aimbs_put16(&hdrbs, 0x0000);
147 aimbs_put16(&hdrbs, 0x0000); 216 aimbs_put16(&hdrbs, 0x0000);
149 aimbs_put16(&hdrbs, 0x0000); 218 aimbs_put16(&hdrbs, 0x0000);
150 aimbs_put32(&hdrbs, strlen(msg)); 219 aimbs_put32(&hdrbs, strlen(msg));
151 aimbs_put16(&hdrbs, 0x0000); 220 aimbs_put16(&hdrbs, 0x0000);
152 aimbs_put16(&hdrbs, 0x0000); 221 aimbs_put16(&hdrbs, 0x0000);
153 aimbs_put16(&hdrbs, 0x0000); 222 aimbs_put16(&hdrbs, 0x0000);
154 223
155 /* flags -- 0x000e for "typing", 0x0000 for message */ 224 /* flags -- 0x000e for "started typing", 0x0002 for "stopped typing, 0x0000 for message */
156 aimbs_put16(&hdrbs, msg ? 0x0000 : 0x000e); 225 aimbs_put16(&hdrbs, 0x0000);
157 226
158 aimbs_put16(&hdrbs, 0x0000); 227 aimbs_put16(&hdrbs, 0x0000);
159 aimbs_put16(&hdrbs, 0x0000); 228 aimbs_put16(&hdrbs, 0x0000);
160 aimbs_putraw(&hdrbs, sess->sn, strlen(sess->sn)); 229 aimbs_putraw(&hdrbs, sess->sn, strlen(sess->sn));
161 230
162 aim_bstream_setpos(&hdrbs, 52); /* bleeehh */ 231 aim_bstream_setpos(&hdrbs, 52); /* bleeehh */
163 232
164 aimbs_put8(&hdrbs, 0x00); 233 aimbs_put8(&hdrbs, 0x00);
165 aimbs_put16(&hdrbs, 0x0000); 234 aimbs_put16(&hdrbs, 0x0000);
166 aimbs_put16(&hdrbs, 0x0000); 235 aimbs_put16(&hdrbs, 0x0000);
167 aimbs_put16(&hdrbs, 0x0000); 236 aimbs_put16(&hdrbs, 0x0000);
168 aimbs_put16(&hdrbs, 0x0000); 237 aimbs_put16(&hdrbs, 0x0000);
169 aimbs_put16(&hdrbs, 0x0000); 238 aimbs_put16(&hdrbs, 0x0000);
170 aimbs_put16(&hdrbs, 0x0000); 239 aimbs_put16(&hdrbs, 0x0000);
171 aimbs_put16(&hdrbs, 0x0000); 240 aimbs_put16(&hdrbs, 0x0000);
172 241
173 /* end of hdr2 */ 242 /* end of hdr2 */
174 243
175 if (msg) {
176 #if 0 /* XXX this is how you send buddy icon info... */ 244 #if 0 /* XXX this is how you send buddy icon info... */
177 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0008); 245 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0008);
178 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x000c); 246 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x000c);
179 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); 247 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
180 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x1466); 248 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x1466);
181 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0001); 249 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0001);
182 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x2e0f); 250 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x2e0f);
183 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x393e); 251 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x393e);
184 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0xcac8); 252 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0xcac8);
185 #endif 253 #endif
186 aimbs_putraw(&fr->data, msg, strlen(msg)); 254 aimbs_putraw(&fr->data, msg, strlen(msg));
187 } 255
188
189 aim_tx_enqueue(sess, fr); 256 aim_tx_enqueue(sess, fr);
190 257
191 return 0; 258 return 0;
192 } 259 }
193 260
194 static int getlocalip(fu8_t *ip) 261 static int getlocalip(fu8_t *ip)
195 { 262 {
1019 1086
1020 if (flags == 0x000e) { 1087 if (flags == 0x000e) {
1021 int ret = 0; 1088 int ret = 0;
1022 1089
1023 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING))) 1090 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING)))
1024 ret = userfunc(sess, &fr, snptr); 1091 ret = userfunc(sess, &fr, snptr, 1);
1025 1092
1026 return ret; 1093 return ret;
1094
1095 } else if (flags == 0x0002) {
1096 int ret = 0;
1097
1098 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING)))
1099 ret = userfunc(sess, &fr, snptr, 0);
1100
1101 return ret;
1027 1102
1028 } else if ((flags == 0x0000) && payloadlength) { 1103 } else if ((flags == 0x0000) && payloadlength) {
1029 char *msg; 1104 char *msg, *msg2;
1030 int ret = 0; 1105 int ret = 0;
1106 int recvd = 0;
1107 int i;
1031 1108
1032 if (!(msg = calloc(1, payloadlength+1))) 1109 if (!(msg = calloc(1, payloadlength+1)))
1033 return -1; 1110 return -1;
1034 1111 msg2 = msg;
1035 if (aim_recv(conn->fd, msg, payloadlength) < payloadlength) { 1112
1036 free(msg); 1113 while (payloadlength - recvd) {
1037 return -1; 1114 if (payloadlength - recvd >= 1024)
1115 i = aim_recv(conn->fd, msg2, 1024);
1116 else
1117 i = aim_recv(conn->fd, msg2, payloadlength - recvd);
1118 if (i == 0) {
1119 free(msg);
1120 return -1;
1121 }
1122 recvd = recvd + i;
1123 msg2 = msg2 + i;
1124 if ((userfunc=aim_callhandler(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DOWNLOADIMAGE)))
1125 userfunc(sess, &fr, snptr, (double)recvd / payloadlength);
1038 } 1126 }
1039 1127
1040 msg[payloadlength] = '\0';
1041
1042 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) ) 1128 if ( (userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) )
1043 ret = userfunc(sess, &fr, snptr, msg); 1129 ret = userfunc(sess, &fr, snptr, msg, payloadlength);
1044 1130
1045 free(msg); 1131 free(msg);
1046 1132
1047 return ret; 1133 return ret;
1048 } 1134 }