- int curbyte=0;
- struct command_tx_struct *newpacket;
-
- if (!clientinfo || !sn || !password)
- return -1;
-
- if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152)))
- return -1;
-
- newpacket->lock = 1;
-
- newpacket->hdr.oscar.type = (sess->flags & AIM_SESS_FLAGS_SNACLOGIN)?0x02:0x01;
-
- if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN)
- curbyte = aim_putsnac(newpacket->data, 0x0017, 0x0002, 0x0000, 0x00010000);
- else {
- curbyte = aimutil_put16(newpacket->data, 0x0000);
- curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001);
- }
-
- curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0001, strlen(sn), sn);
-
- if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN) {
- unsigned char digest[16];
-
- aim_encode_password_md5(password, key, digest);
- curbyte+= aim_puttlv_str(newpacket->data+curbyte, 0x0025, 16, (char *)digest);
- } else {
- char *password_encoded;
-
- password_encoded = (char *) malloc(strlen(password));
- aim_encode_password(password, password_encoded);
- curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0002, strlen(password), password_encoded);
- free(password_encoded);
- }
-
- curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0003, strlen(clientinfo->clientstring), clientinfo->clientstring);
-
- if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN) {
-
- curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0016, (unsigned short)clientinfo->major2);
- curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0017, (unsigned short)clientinfo->major);
- curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0018, (unsigned short)clientinfo->minor);
- curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0019, (unsigned short)clientinfo->minor2);
- curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x001a, (unsigned short)clientinfo->build);
-
- } else {
- /* Use very specific version numbers, to further indicate the hack. */
- curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0016, 0x010a);
- curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0017, 0x0004);
- curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0018, 0x003c);
- curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0019, 0x0001);
- curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x001a, 0x0cce);
- curbyte += aim_puttlv_32(newpacket->data+curbyte, 0x0014, 0x00000055);
- }
-
- curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x000e, strlen(clientinfo->country), clientinfo->country);
- curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x000f, strlen(clientinfo->lang), clientinfo->lang);
-
- if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN) {
- curbyte += aim_puttlv_32(newpacket->data+curbyte, 0x0014, clientinfo->unknown);
- curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0009, 0x0015);
- }
-
- newpacket->commandlen = curbyte;
-
- newpacket->lock = 0;
- return aim_tx_enqueue(sess, newpacket);
+ aim_frame_t *fr;
+ aim_tlvlist_t *tl = NULL;
+
+ if (!clientinfo || !sn || !password)
+ return -EINVAL;
+
+ if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152)))
+ return -ENOMEM;
+
+ if (sess->flags & AIM_SESS_FLAGS_XORLOGIN) {
+ fr->hdr.flap.type = 0x01;
+
+ /* Use very specific version numbers to further indicate hack */
+ clientinfo->major2 = 0x010a;
+ clientinfo->major = 0x0004;
+ clientinfo->minor = 0x003c;
+ clientinfo->minor2 = 0x0001;
+ clientinfo->build = 0x0cce;
+ clientinfo->unknown = 0x00000055;
+ }
+
+ if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN)
+ aim_putsnac(&fr->data, 0x0017, 0x0002, 0x0000, 0x00010000);
+ else
+ aimbs_put32(&fr->data, 0x00000001);
+
+ aim_addtlvtochain_raw(&tl, 0x0001, strlen(sn), sn);
+
+ if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN) {
+ fu8_t digest[16];
+
+ aim_encode_password_md5(password, key, digest);
+ aim_addtlvtochain_raw(&tl, 0x0025, 16, digest);
+ } else {
+ char *password_encoded;
+
+ password_encoded = (char *) malloc(strlen(password));
+ aim_encode_password(password, password_encoded);
+ aim_addtlvtochain_raw(&tl, 0x0002, strlen(password), password_encoded);
+ free(password_encoded);
+ }
+
+ aim_addtlvtochain_raw(&tl, 0x0003, strlen(clientinfo->clientstring), clientinfo->clientstring);
+
+ aim_addtlvtochain16(&tl, 0x0016, (fu16_t)clientinfo->major2);
+ aim_addtlvtochain16(&tl, 0x0017, (fu16_t)clientinfo->major);
+ aim_addtlvtochain16(&tl, 0x0018, (fu16_t)clientinfo->minor);
+ aim_addtlvtochain16(&tl, 0x0019, (fu16_t)clientinfo->minor2);
+ aim_addtlvtochain16(&tl, 0x001a, (fu16_t)clientinfo->build);
+
+ aim_addtlvtochain_raw(&tl, 0x000e, strlen(clientinfo->country), clientinfo->country);
+ aim_addtlvtochain_raw(&tl, 0x000f, strlen(clientinfo->lang), clientinfo->lang);
+
+ if (sess->flags & AIM_SESS_FLAGS_SNACLOGIN)
+ aim_addtlvtochain16(&tl, 0x0009, 0x0015);
+
+ aim_writetlvchain(&fr->data, &tl);
+
+ aim_freetlvchain(&tl);
+
+ aim_tx_enqueue(sess, fr);
+
+ return 0;