summaryrefslogtreecommitdiff
path: root/protocols/Skype/src/skype_proto.cpp
blob: 1f78e2dd57cc9c6a557680d8a035c1dbf851f6b7 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include "skype_proto.h"

CSkypeProto::CSkypeProto(const char* protoName, const TCHAR* userName)
{
	this->isOffline = true;
	this->m_iVersion = 2;
	this->m_iStatus = ID_STATUS_OFFLINE;
	this->m_tszUserName = mir_tstrdup(userName);
	this->m_szModuleName = mir_strdup(protoName);
	this->m_szProtoName = mir_strdup(protoName);
	_strlwr(m_szProtoName);
	this->m_szProtoName[0] = toupper(m_szProtoName[0]);

	TCHAR name[128];
	mir_sntprintf(name, SIZEOF(name), TranslateT("%s connection"), this->m_tszUserName);

	NETLIBUSER nlu = {0};
	nlu.cbSize = sizeof( nlu );
	nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_HTTPCONNS | NUF_TCHAR;	// | NUF_HTTPGATEWAY;
	nlu.ptszDescriptiveName = name;
	nlu.szSettingsModule = m_szModuleName;
	this->hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);

	this->Log("Setting protocol/module name to '%s/%s'", m_szProtoName, m_szModuleName);

	this->CreateProtoService(PS_CREATEACCMGRUI, &CSkypeProto::SvcCreateAccMgrUI);
}

CSkypeProto::~CSkypeProto()
{
	Netlib_CloseHandle(this->hNetlibUser);
	this->hNetlibUser = NULL;

	mir_free(this->m_szProtoName);
	mir_free(this->m_szModuleName);
	mir_free(this->m_tszUserName);
}

INT_PTR CALLBACK SkypeAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
	CSkypeProto *proto;

	switch ( message )
	{
	case WM_INITDIALOG:
		TranslateDialogDefault(hwnd);

		proto = reinterpret_cast<CSkypeProto*>(lparam);
		SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);

		DBVARIANT dbv;
		if ( !DBGetContactSettingString(0, proto->ModuleName(), "SkypeName", &dbv))
		{
			SetDlgItemText(hwnd, IDC_SN, dbv.ptszVal);
			DBFreeVariant(&dbv);
		}

		if ( !DBGetContactSettingString(0, proto->ModuleName(), "Password", &dbv))
		{
			CallService(
				MS_DB_CRYPT_DECODESTRING,
				wcslen(dbv.ptszVal) + 1,
				reinterpret_cast<LPARAM>(dbv.ptszVal));
			SetDlgItemText(hwnd, IDC_PW, dbv.ptszVal);
			DBFreeVariant(&dbv);
		}

		if ( !proto->IsOffline()) 
		{
			SendMessage(GetDlgItem(hwnd, IDC_SN), EM_SETREADONLY, 1, 0);
			SendMessage(GetDlgItem(hwnd, IDC_PW), EM_SETREADONLY, 1, 0); 
		}

		return TRUE;

	case WM_COMMAND:
		if (HIWORD(wparam) == EN_CHANGE && reinterpret_cast<HWND>(lparam) == GetFocus())
		{
			switch(LOWORD(wparam))
			{
			case IDC_SN:
			case IDC_PW:
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
			}
		}
		break;

	case WM_NOTIFY:
		if (reinterpret_cast<NMHDR*>(lparam)->code == PSN_APPLY)
		{
			proto = reinterpret_cast<CSkypeProto*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
			TCHAR str[128];

			GetDlgItemText(hwnd, IDC_SN, str, sizeof(str));
			DBWriteContactSettingTString(0, proto->ModuleName(), "SkypeName", str);

			GetDlgItemText(hwnd, IDC_PW, str, sizeof(str));
			CallService(MS_DB_CRYPT_ENCODESTRING, sizeof(str), reinterpret_cast<LPARAM>(str));
			DBWriteContactSettingTString(0, proto->ModuleName(), "Password", str);

			return TRUE;
		}
		break;

	}

	return FALSE;
}

INT_PTR __cdecl CSkypeProto::SvcCreateAccMgrUI(WPARAM wParam, LPARAM lParam)
{
	return (int)CreateDialogParam(
		g_hInstance, 
		MAKEINTRESOURCE(IDD_SKYPEACCOUNT), 
		(HWND)lParam, 
		::SkypeAccountProc, (LPARAM)this);
}

HANDLE __cdecl CSkypeProto::AddToList( int flags, PROTOSEARCHRESULT* psr ) { return 0; }
HANDLE __cdecl CSkypeProto::AddToListByEvent( int flags, int iContact, HANDLE hDbEvent ) { return 0; }
int    __cdecl CSkypeProto::Authorize( HANDLE hDbEvent ) { return 0; }
int    __cdecl CSkypeProto::AuthDeny( HANDLE hDbEvent, const TCHAR* szReason ) { return 0; }
int    __cdecl CSkypeProto::AuthRecv( HANDLE hContact, PROTORECVEVENT* ) { return 0; }
int    __cdecl CSkypeProto::AuthRequest( HANDLE hContact, const TCHAR* szMessage ) { return 0; }

HANDLE __cdecl CSkypeProto::ChangeInfo( int iInfoType, void* pInfoData ) { return 0; }

HANDLE __cdecl CSkypeProto::FileAllow( HANDLE hContact, HANDLE hTransfer, const TCHAR* szPath ) { return 0; }
int    __cdecl CSkypeProto::FileCancel( HANDLE hContact, HANDLE hTransfer ) { return 0; }
int    __cdecl CSkypeProto::FileDeny( HANDLE hContact, HANDLE hTransfer, const TCHAR* szReason ) { return 0; }
int    __cdecl CSkypeProto::FileResume( HANDLE hTransfer, int* action, const TCHAR** szFilename ) { return 0; }

DWORD_PTR __cdecl CSkypeProto:: GetCaps( int type, HANDLE hContact ) { return 0; }
HICON  __cdecl CSkypeProto::GetIcon( int iconIndex ) { return 0; }
int    __cdecl CSkypeProto::GetInfo( HANDLE hContact, int infoType ) { return 0; }

HANDLE __cdecl CSkypeProto::SearchBasic( const TCHAR* id ) { return 0; }
HANDLE __cdecl CSkypeProto::SearchByEmail( const TCHAR* email ) { return 0; }
HANDLE __cdecl CSkypeProto::SearchByName( const TCHAR* nick, const TCHAR* firstName, const TCHAR* lastName ) { return 0; }
HWND   __cdecl CSkypeProto::SearchAdvanced( HWND owner ) { return 0; }
HWND   __cdecl CSkypeProto::CreateExtendedSearchUI( HWND owner ) { return 0; }

int    __cdecl CSkypeProto::RecvContacts( HANDLE hContact, PROTORECVEVENT* ) { return 0; }
int    __cdecl CSkypeProto::RecvFile( HANDLE hContact, PROTORECVFILET* ) { return 0; }
int    __cdecl CSkypeProto::RecvMsg( HANDLE hContact, PROTORECVEVENT* ) { return 0; }
int    __cdecl CSkypeProto::RecvUrl( HANDLE hContact, PROTORECVEVENT* ) { return 0; }

int    __cdecl CSkypeProto::SendContacts( HANDLE hContact, int flags, int nContacts, HANDLE* hContactsList ) { return 0; }
HANDLE __cdecl CSkypeProto::SendFile( HANDLE hContact, const TCHAR* szDescription, TCHAR** ppszFiles ) { return 0; }
int    __cdecl CSkypeProto::SendMsg( HANDLE hContact, int flags, const char* msg ) { return 0; }
int    __cdecl CSkypeProto::SendUrl( HANDLE hContact, int flags, const char* url ) { return 0; }

int    __cdecl CSkypeProto::SetApparentMode( HANDLE hContact, int mode ) { return 0; }
int CSkypeProto::SetStatus(int new_status)
{
	switch(new_status)
	{
	case ID_STATUS_OFFLINE:	
		if ( !this->isOffline)
		{
			this->isOffline = true;
		   account->Logout(false);
		};
		break;

	case ID_STATUS_ONLINE:
		if (g_skype->GetAccount("", this->account))
		{
			this->isOffline = false;
			account->LoginWithPassword("", false, false);

			// Loop until LoggedIn or login failure
			//while ( (!account->loggedIn) && (!account->loggedOut) ) { Delay(1); };
		}
		break;
	}

	return 0;
}

HANDLE __cdecl CSkypeProto::GetAwayMsg( HANDLE hContact ) { return 0; }
int    __cdecl CSkypeProto::RecvAwayMsg( HANDLE hContact, int mode, PROTORECVEVENT* evt ) { return 0; }
int    __cdecl CSkypeProto::SendAwayMsg( HANDLE hContact, HANDLE hProcess, const char* msg ) { return 0; }
int    __cdecl CSkypeProto::SetAwayMsg( int m_iStatus, const TCHAR* msg ) { return 0; }

int    __cdecl CSkypeProto::UserIsTyping( HANDLE hContact, int type ) { return 0; }

int    __cdecl CSkypeProto::OnEvent( PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam ) { return 0; }

void CSkypeProto::Log(const char* fmt, ...)
{
	va_list va;
	char msg[1024];

	va_start(va, fmt);
	mir_vsnprintf(msg, sizeof(msg), fmt, va);
	va_end(va);

	CallService(MS_NETLIB_LOG, ( WPARAM )this->hNetlibUser, (LPARAM)msg);
}

void CSkypeProto::CreateProtoService(const char* szService, SkypeServiceFunc serviceProc)
{
	char temp[MAX_PATH*2];

	mir_snprintf(temp, sizeof(temp), "%s%s", this->m_szModuleName, szService);
	CreateServiceFunctionObj(temp, (MIRANDASERVICEOBJ)*(void**)&serviceProc, this);
}

char* CSkypeProto::ModuleName()
{
	return this->m_szProtoName;
}

bool CSkypeProto::IsOffline()
{
	return this->isOffline;
}