// Copyright © 2010 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 list Accounts; int GetJabberInterface(WPARAM, LPARAM) //get interface for all jabber accounts, options later { int count = 0; PROTOACCOUNT **accounts; ProtoEnumAccounts(&count, &accounts); list ::iterator p; Accounts.push_back(new JabberAccount); p = Accounts.begin(); (*p)->AccountNumber = 0; for(int i = 0; i < count; i++) //get only jabber accounts from all accounts { char *tmp = mir_u2a(accounts[i]->tszAccountName); IJabberInterface *JIftmp = getJabberApi(tmp); int a = 0; if(JIftmp) { (*p)->JabberInterface = JIftmp; (*p)->AccountName = accounts[i]->tszAccountName; (*p)->AccountNumber = a; (*p)->hIqHandler = (*p)->hMessageHandler = (*p)->hPrescenseHandler = INVALID_HANDLE_VALUE; a++; p++; Accounts.push_back(new JabberAccount); } mir_free(tmp); } Accounts.pop_back(); return 0; } static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, void *pUserData); static JABBER_HANDLER_FUNC MessageHandler(IJabberInterface *ji, HXML node, void *pUserData); static JABBER_HANDLER_FUNC IqHandler(IJabberInterface *ji, HXML node, void *pUserData); int HandleDbNewContact(WPARAM w, LPARAM l) { list ::iterator p = Accounts.begin(); for(unsigned int i = 0; i < Accounts.size(); i++, p++) { if(!(*p)) break; IJabberSysInterface *ijsys = (*p)->JabberInterface->Sys(); LPTSTR tmp = ijsys->ContactToJID(HANDLE(w)); if(tmp) { if(_tcsstr(_T(JUICK_JID), tmp)) { if((*p)->hPrescenseHandler == INVALID_HANDLE_VALUE && (*p)->hMessageHandler == INVALID_HANDLE_VALUE && (*p)->hIqHandler == INVALID_HANDLE_VALUE) { IJabberNetInterface *ijnet = (*p)->JabberInterface->Net(); (*p)->hPrescenseHandler = ijnet->AddPresenceHandler((JABBER_HANDLER_FUNC)PrescenseHandler); (*p)->hMessageHandler = ijnet->AddMessageHandler((JABBER_HANDLER_FUNC)MessageHandler, JABBER_MESSAGE_TYPE_ANY, 0, 0); (*p)->hIqHandler = ijnet->AddIqHandler((JABBER_HANDLER_FUNC)IqHandler, JABBER_IQ_TYPE_ANY, 0, 0); } } } } return 0; } int HandleDbContactDeleted(WPARAM w, LPARAM l) { list ::iterator p = Accounts.begin(); for(unsigned int i = 0; i < Accounts.size(); i++, p++) { if(!(*p)) break; IJabberSysInterface *ijsys = (*p)->JabberInterface->Sys(); LPTSTR tmp = ijsys->ContactToJID(HANDLE(w)); if(tmp) { if(_tcsstr(_T(JUICK_JID), tmp)) { if((*p)->hPrescenseHandler != INVALID_HANDLE_VALUE && (*p)->hMessageHandler != INVALID_HANDLE_VALUE && (*p)->hIqHandler != INVALID_HANDLE_VALUE) { IJabberNetInterface *ijnet = (*p)->JabberInterface->Net(); ijnet->RemoveHandler((*p)->hPrescenseHandler); ijnet->RemoveHandler((*p)->hMessageHandler); ijnet->RemoveHandler((*p)->hIqHandler); } } } } return 0; } void FindJuickAccounts() { list ::iterator p = Accounts.begin(); for(unsigned int i = 0; i < Accounts.size(); i++, p++) { if(!(*p)) break; IJabberSysInterface *ijsys = (*p)->JabberInterface->Sys(); if(ijsys->ContactFromJID(_T(JUICK_JID))) //i should use this contact handler { if((*p)->hPrescenseHandler == INVALID_HANDLE_VALUE && (*p)->hMessageHandler == INVALID_HANDLE_VALUE && (*p)->hIqHandler == INVALID_HANDLE_VALUE) { IJabberNetInterface *ijnet = (*p)->JabberInterface->Net(); (*p)->hPrescenseHandler = ijnet->AddPresenceHandler((JABBER_HANDLER_FUNC)PrescenseHandler); (*p)->hMessageHandler = ijnet->AddMessageHandler((JABBER_HANDLER_FUNC)MessageHandler, JABBER_MESSAGE_TYPE_ANY, 0, 0); (*p)->hIqHandler = ijnet->AddIqHandler((JABBER_HANDLER_FUNC)IqHandler, JABBER_IQ_TYPE_ANY, 0, 0); } } } } static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, void *pUserData) { return FALSE; } static JABBER_HANDLER_FUNC MessageHandler(IJabberInterface *ji, HXML node, void *pUserData) { if(!_tcsstr(xi.getAttr(node, 0), _T(JUICK_JID))) return FALSE; return FALSE; } static JABBER_HANDLER_FUNC IqHandler(IJabberInterface *ji, HXML node, void *pUserData) { return FALSE; } BOOL JabberAccount::operator!() { if(!this) return TRUE; return FALSE; } JabberAccount::JabberAccount() { AccountName = _T(""); AccountNumber = 0; } 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; }