summaryrefslogtreecommitdiff
path: root/protocols/AimOscar/src/away.cpp
blob: 96d4847d9b5b5167fca269008dd9e4322aef7c23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
Plugin of Miranda IM for communicating with users of the AIM protocol.
Copyright (c) 2008-2012 Boris Krasnovskiy
Copyright (C) 2005-2006 Aaron Myles Landwehr

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "stdafx.h"

static const int modes[] =
{
	ID_STATUS_ONLINE,
	ID_STATUS_AWAY,
	ID_STATUS_DND,
	ID_STATUS_NA,
	ID_STATUS_OCCUPIED,
	ID_STATUS_FREECHAT,
	ID_STATUS_INVISIBLE,
	ID_STATUS_ONTHEPHONE,
	ID_STATUS_OUTTOLUNCH,
};

char** CAimProto::get_status_msg_loc(int status)
{
	for (int i = 0; i < _countof(modes); i++)
		if (modes[i] == status)
			return &m_modeMsgs[i];

	return nullptr;
}

int CAimProto::aim_set_away(HNETLIBCONN hServerConn, unsigned short &seqno, const char *amsg, bool set)//user info
{
	unsigned short offset = 0;
	char *html_msg = nullptr;
	size_t msg_size = 0;
	if (set) {
		if (!amsg) return -1;
		setDword(AIM_KEY_LA, (DWORD)time(nullptr));
		html_msg = html_encode(amsg && amsg[0] ? amsg : DEFAULT_AWAY_MSG);
		msg_size = mir_strlen(html_msg);
	}

	aimString str(html_msg);
	const char *charset = str.isUnicode() ? AIM_MSG_TYPE_UNICODE : AIM_MSG_TYPE;
	const unsigned short charset_len = (unsigned short)mir_strlen(charset);

	const char *msg = str.getBuf();
	const unsigned short msg_len = str.getSize();

	char *buf = (char*)alloca(SNAC_SIZE + TLV_HEADER_SIZE * 3 + charset_len + msg_len + 1);

	aim_writesnac(0x02, 0x04, offset, buf);
	aim_writetlv(0x03, charset_len, charset, offset, buf);
	aim_writetlv(0x04, (unsigned short)msg_len, msg, offset, buf);

	mir_free(html_msg);

	return aim_sendflap(hServerConn, 0x02, offset, buf, seqno);
}

int CAimProto::aim_set_status(HNETLIBCONN hServerConn, unsigned short &seqno, unsigned long status_type)
{
	unsigned short offset = 0;
	char buf[SNAC_SIZE + TLV_HEADER_SIZE * 2];
	aim_writesnac(0x01, 0x1E, offset, buf);
	aim_writetlvlong(0x06, status_type, offset, buf);
	return aim_sendflap(hServerConn, 0x02, offset, buf, seqno);
}

int CAimProto::aim_set_statusmsg(HNETLIBCONN hServerConn, unsigned short &seqno, const char *msg)//user info
{
	size_t msg_size = mir_strlen(msg);

	unsigned short msgoffset = 0;
	char *msgbuf = (char*)alloca(10 + msg_size);
	if (msg_size) {
		char *msgb = (char*)alloca(4 + msg_size);
		msgb[0] = (unsigned char)(msg_size >> 8);
		msgb[1] = (unsigned char)(msg_size & 0xff);
		memcpy(&msgb[2], msg, msg_size);
		msgb[msg_size + 2] = 0;
		msgb[msg_size + 3] = 0;

		aim_writebartid(2, 4, (unsigned short)(msg_size + 4), msgb, msgoffset, msgbuf);
	}
	else aim_writebartid(2, 0, 0, nullptr, msgoffset, msgbuf);

	unsigned short offset = 0;
	char* buf = (char*)alloca(SNAC_SIZE + TLV_HEADER_SIZE + msgoffset + 8);
	aim_writesnac(0x01, 0x1e, offset, buf);
	aim_writetlv(0x1d, msgoffset, msgbuf, offset, buf);

	return aim_sendflap(hServerConn, 0x02, offset, buf, seqno);
}

int CAimProto::aim_query_away_message(HNETLIBCONN hServerConn, unsigned short &seqno, const char* sn)
{
	unsigned short offset = 0;
	unsigned short sn_length = (unsigned short)mir_strlen(sn);
	char *buf = (char*)alloca(SNAC_SIZE + 5 + sn_length);
	aim_writesnac(0x02, 0x15, offset, buf);
	aim_writegeneric(4, "\0\0\0\x02", offset, buf);
	aim_writegeneric(1, (char*)&sn_length, offset, buf);
	aim_writegeneric(sn_length, sn, offset, buf);
	int res = aim_sendflap(hServerConn, 0x02, offset, buf, seqno) == 0;
	return res;
}