summaryrefslogtreecommitdiff
path: root/utilities.cpp
blob: 1ddb504b9d471471471b03ec1b0f9c01f210a609 (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
// Copyright © 2008 sss, chaos.persei
// 
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


#include "commonheaders.h"


TCHAR* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,const char* szSetting, TCHAR* szDef)
{
  DBVARIANT dbv = {DBVT_DELETED};
  TCHAR* szRes;
  if (DBGetContactSettingTString(hContact, szModule, szSetting, &dbv))
	 return _tcsdup(szDef);
  if(dbv.pszVal)
	  szRes = _tcsdup(dbv.ptszVal);
  DBFreeVariant(&dbv);
  return szRes;
}

extern JabberAccount Accounts;

int GetAccountsCount();

int GetJabberInterface(WPARAM, LPARAM) //get interface for all jabber accounts, options later
{
	IJabberInterface *JIftmp[50]; //should it be dynamic ?
	int count = 0;
	PROTOACCOUNT **accounts;
	JabberAccount *acc = &Accounts;
	if(!acc)
		acc = new(JabberAccount);
	ProtoEnumAccounts(&count, &accounts);
	acc->AccountNumber = 0;
	for(int i = 0; i < count; i++)
	{
		char *tmp = mir_u2a(accounts[i]->tszAccountName);
		JIftmp[i] = getJabberApi(tmp);
		if(!acc)
			acc = new(JabberAccount);
		if(JIftmp[i])
		{
			acc->JabberInterface = JIftmp[i];
			acc->AccountName = accounts[i]->tszAccountName;
			acc->AccountNumber = i;
			acc = acc->next;
			acc = new(JabberAccount);
		}
		mir_free(tmp);
	}
	if(!GetAccountsCount())
		return 1; //no jabber accounts found
	return 0;
}

int HandleNewContact(WPARAM w, LPARAM l)
{
	for(int i = 0; i < GetAccountsCount(); i++)
	{
		JabberAccount *acc = &Accounts;
		if(!acc)
			break;
		IJabberSysInterface *ijsys = acc->JabberInterface->Sys();
		if(_tcsstr(_T(JUICK_JID), ijsys->ContactToJID(HANDLE(w))))
		{
			IJabberNetInterface *ijnet = acc->JabberInterface->Net();
			if(!acc->hPrescenseHandler && !acc->hMessageHandler && !acc->hIqHandler)
			{
				acc->hPrescenseHandler = ijnet->AddPresenceHandler(acc->PrescenseHandler());
				acc->hMessageHandler = ijnet->AddMessageHandler(acc->MessageHandler(), JABBER_MESSAGE_TYPE_ANY, _T(""), _T("")); //hm...
				acc->hIqHandler = ijnet->AddIqHandler(acc->IqHandler(), JABBER_IQ_TYPE_ANY, _T(""), _T("")); //hm...
			}
		}
		else if (acc->hPrescenseHandler && acc->hMessageHandler && acc->hIqHandler)
		{
			IJabberNetInterface *ijnet = acc->JabberInterface->Net();
			ijnet->RemoveHandler(acc->hPrescenseHandler);
			ijnet->RemoveHandler(acc->hMessageHandler);
			ijnet->RemoveHandler(acc->hIqHandler);			
		}
		acc = acc->next;
	}
	return 0;
}

void FindJuickAccounts()
{
	
	for(int i = 0; i < GetAccountsCount(); i++)
	{
		JabberAccount *acc = &Accounts;
		if(!acc)
			break;
		IJabberSysInterface *ijsys;
		ijsys = acc->JabberInterface->Sys();
		if(ijsys->ContactFromJID(_T(JUICK_JID)))
		{
			IJabberNetInterface *ijnet = acc->JabberInterface->Net();
			if(!acc->hPrescenseHandler && !acc->hMessageHandler && !acc->hIqHandler)
			{
				acc->hPrescenseHandler = ijnet->AddPresenceHandler(acc->PrescenseHandler());
				acc->hMessageHandler = ijnet->AddMessageHandler(acc->MessageHandler(), JABBER_MESSAGE_TYPE_ANY, _T(""), _T("")); //hm...
				acc->hIqHandler = ijnet->AddIqHandler(acc->IqHandler(), JABBER_IQ_TYPE_ANY, _T(""), _T("")); //hm...
			}
		}
		acc = acc->next;
	}
}

JABBER_HANDLER_FUNC JabberAccount::PrescenseHandler()
{
	return FALSE;
}

JABBER_HANDLER_FUNC JabberAccount::MessageHandler()
{
	return FALSE;
}

JABBER_HANDLER_FUNC JabberAccount::IqHandler()
{
	return FALSE;
}

BOOL JabberAccount::operator!()
{
	if(!this)
		return TRUE;
	return FALSE;
}
JabberAccount::JabberAccount()
{
	AccountName = _T("");
	AccountNumber = 0;

}

JabberAccount::~JabberAccount()
{
	delete this;
}
int GetAccountsCount()
{
	int i;
	JabberAccount *tmp = &Accounts;
	for(i = 0; tmp; tmp=tmp->next, i++)
		;
	return i;
}


char *date()
{
	static char d[11];
	char *tmp = __DATE__, m[4], mn[3] = "01";
	m[0]=tmp[0];
	m[1]=tmp[1];
	m[2]=tmp[2];
	if(strstr(m,"Jan"))
		strcpy(mn,"01");
	else if(strstr(m,"Feb"))
		strcpy(mn,"02");
	else if(strstr(m,"Mar"))
		strcpy(mn,"03");
	else if(strstr(m,"Apr"))
		strcpy(mn,"04");
	else if(strstr(m,"May"))
		strcpy(mn,"05");
	else if(strstr(m,"Jun"))
		strcpy(mn,"06");
	else if(strstr(m,"Jul"))
		strcpy(mn,"07");
	else if(strstr(m,"Aug"))
		strcpy(mn,"08");
	else if(strstr(m,"Sep"))
		strcpy(mn,"09");
	else if(strstr(m,"Oct"))
		strcpy(mn,"10");
	else if(strstr(m,"Nov"))
		strcpy(mn,"11");
	else if(strstr(m,"Dec"))
		strcpy(mn,"12");
	d[0]=tmp[7];
	d[1]=tmp[8];
	d[2]=tmp[9];
	d[3]=tmp[10];
	d[4]='.';
	d[5]=mn[0];
	d[6]=mn[1];
	d[7]='.';
	if (tmp[4] == ' ')
		d[8] = '0';
	else
		d[8]=tmp[4];
	d[9]=tmp[5];
	return d;
}