/* Miranda NG: the free IM client for Microsoft* Windows* Copyright (C) 2012-17 Miranda NG project, all portions of this codebase are copyrighted to the people listed in contributors.txt. 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 "stdafx.h" static int CompareProtos(const PROTOCOLDESCRIPTOR *p1, const PROTOCOLDESCRIPTOR *p2) { return strcmp(p1->szName, p2->szName); } LIST protos(10, CompareProtos); extern HANDLE hAckEvent; ///////////////////////////////////////////////////////////////////////////////////////// MIR_APP_DLL(PROTOCOLDESCRIPTOR*) Proto_IsProtocolLoaded(const char *szProtoName) { if (szProtoName == NULL) return NULL; PROTOCOLDESCRIPTOR tmp; tmp.szName = (char*)szProtoName; return protos.find(&tmp); } ///////////////////////////////////////////////////////////////////////////////////////// MIR_APP_DLL(void) Proto_EnumProtocols(int *nProtos, PROTOCOLDESCRIPTOR ***pProtos) { if (nProtos) *nProtos = protos.getCount(); if (pProtos) *pProtos = protos.getArray(); } ///////////////////////////////////////////////////////////////////////////////////////// MIR_APP_DLL(INT_PTR) ProtoBroadcastAck(const char *szModule, MCONTACT hContact, int type, int result, HANDLE hProcess, LPARAM lParam) { ACKDATA ack = { sizeof(ACKDATA), szModule, hContact, type, result, hProcess, lParam }; return NotifyEventHooks(hAckEvent, 0, (LPARAM)&ack); } ///////////////////////////////////////////////////////////////////////////////////////// MIR_APP_DLL(void) ProtoConstructor(PROTO_INTERFACE *pThis, LPCSTR pszModuleName, LPCTSTR ptszUserName) { pThis->m_iVersion = 2; pThis->m_iStatus = pThis->m_iDesiredStatus = ID_STATUS_OFFLINE; pThis->m_szModuleName = mir_strdup(pszModuleName); pThis->m_hProtoIcon = IcoLib_IsManaged(Skin_LoadProtoIcon(pszModuleName, ID_STATUS_ONLINE)); pThis->m_tszUserName = mir_wstrdup(ptszUserName); db_set_resident(pThis->m_szModuleName, "Status"); } MIR_APP_DLL(void) ProtoDestructor(PROTO_INTERFACE *pThis) { mir_free(pThis->m_szModuleName); mir_free(pThis->m_tszUserName); WindowList_Destroy(pThis->m_hWindowList); } MIR_APP_DLL(void) ProtoCreateService(PROTO_INTERFACE *pThis, const char* szService, ProtoServiceFunc serviceProc) { char str[MAXMODULELABELLENGTH * 2]; strncpy_s(str, pThis->m_szModuleName, _TRUNCATE); strncat_s(str, szService, _TRUNCATE); ::CreateServiceFunctionObj(str, (MIRANDASERVICEOBJ)*(void**)&serviceProc, pThis); } MIR_APP_DLL(void) ProtoCreateServiceParam(PROTO_INTERFACE *pThis, const char* szService, ProtoServiceFuncParam serviceProc, LPARAM lParam) { char str[MAXMODULELABELLENGTH * 2]; strncpy_s(str, pThis->m_szModuleName, _TRUNCATE); strncat_s(str, szService, _TRUNCATE); ::CreateServiceFunctionObjParam(str, (MIRANDASERVICEOBJPARAM)*(void**)&serviceProc, pThis, lParam); } MIR_APP_DLL(void) ProtoHookEvent(PROTO_INTERFACE *pThis, const char* szEvent, ProtoEventFunc handler) { ::HookEventObj(szEvent, (MIRANDAHOOKOBJ)*(void**)&handler, pThis); } MIR_APP_DLL(HANDLE) ProtoCreateHookableEvent(PROTO_INTERFACE *pThis, const char* szName) { char str[MAXMODULELABELLENGTH * 2]; strncpy_s(str, pThis->m_szModuleName, _TRUNCATE); strncat_s(str, szName, _TRUNCATE); return CreateHookableEvent(str); } MIR_APP_DLL(void) ProtoForkThread(PROTO_INTERFACE *pThis, ProtoThreadFunc pFunc, void *param) { UINT threadID; CloseHandle((HANDLE)::mir_forkthreadowner((pThreadFuncOwner)*(void**)&pFunc, pThis, param, &threadID)); } MIR_APP_DLL(HANDLE) ProtoForkThreadEx(PROTO_INTERFACE *pThis, ProtoThreadFunc pFunc, void *param, UINT* threadID) { UINT lthreadID; return (HANDLE)::mir_forkthreadowner((pThreadFuncOwner)*(void**)&pFunc, pThis, param, threadID ? threadID : <hreadID); } MIR_APP_DLL(void) ProtoWindowAdd(PROTO_INTERFACE *pThis, HWND hwnd) { if (pThis->m_hWindowList == NULL) pThis->m_hWindowList = WindowList_Create(); WindowList_Add(pThis->m_hWindowList, hwnd, NULL); } MIR_APP_DLL(void) ProtoWindowRemove(PROTO_INTERFACE *pThis, HWND hwnd) { WindowList_Remove(pThis->m_hWindowList, hwnd); } ///////////////////////////////////////////////////////////////////////////////////////// MIR_APP_DLL(LPCTSTR) ProtoGetAvatarExtension(int format) { if (format == PA_FORMAT_PNG) return L".png"; if (format == PA_FORMAT_JPEG) return L".jpg"; if (format == PA_FORMAT_ICON) return L".ico"; if (format == PA_FORMAT_BMP) return L".bmp"; if (format == PA_FORMAT_GIF) return L".gif"; if (format == PA_FORMAT_SWF) return L".swf"; if (format == PA_FORMAT_XML) return L".xml"; return L""; } MIR_APP_DLL(int) ProtoGetAvatarFormat(const wchar_t *ptszFileName) { if (ptszFileName == NULL) return PA_FORMAT_UNKNOWN; const wchar_t *ptszExt = wcsrchr(ptszFileName, '.'); if (ptszExt == NULL) return PA_FORMAT_UNKNOWN; if (!wcsicmp(ptszExt, L".png")) return PA_FORMAT_PNG; if (!wcsicmp(ptszExt, L".jpg") || !wcsicmp(ptszExt, L".jpeg")) return PA_FORMAT_JPEG; if (!wcsicmp(ptszExt, L".ico")) return PA_FORMAT_ICON; if (!wcsicmp(ptszExt, L".bmp") || !wcsicmp(ptszExt, L".rle")) return PA_FORMAT_BMP; if (!wcsicmp(ptszExt, L".gif")) return PA_FORMAT_GIF; if (!wcsicmp(ptszExt, L".swf")) return PA_FORMAT_SWF; if (!wcsicmp(ptszExt, L".xml")) return PA_FORMAT_XML; return PA_FORMAT_UNKNOWN; } MIR_APP_DLL(int) ProtoGetBufferFormat(const void *pBuffer, const wchar_t **ptszExtension) { if (!memcmp(pBuffer, "\x89PNG", 4)) { if (ptszExtension) *ptszExtension = L".png"; return PA_FORMAT_PNG; } if (!memcmp(pBuffer, "GIF8", 4)) { if (ptszExtension) *ptszExtension = L".gif"; return PA_FORMAT_GIF; } if (!memicmp(pBuffer, "