From 48540940b6c28bb4378abfeb500ec45a625b37b6 Mon Sep 17 00:00:00 2001 From: Vadim Dashevskiy Date: Tue, 15 May 2012 10:38:20 +0000 Subject: initial commit git-svn-id: http://svn.miranda-ng.org/main/trunk@2 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/MRA/Mra_svcs.cpp | 2302 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2302 insertions(+) create mode 100644 protocols/MRA/Mra_svcs.cpp (limited to 'protocols/MRA/Mra_svcs.cpp') diff --git a/protocols/MRA/Mra_svcs.cpp b/protocols/MRA/Mra_svcs.cpp new file mode 100644 index 0000000000..55621e4bce --- /dev/null +++ b/protocols/MRA/Mra_svcs.cpp @@ -0,0 +1,2302 @@ +#include "Mra.h" +#include "proto.h" + + + + + +INT_PTR MraXStatusMenu (WPARAM wParam,LPARAM lParam,LPARAM param); + +int MraContactDeleted (WPARAM wParam,LPARAM lParam); +int MraDbSettingChanged (WPARAM wParam,LPARAM lParam); +int MraRebuildContactMenu (WPARAM wParam,LPARAM lParam); +int MraExtraIconsApply (WPARAM wParam,LPARAM lParam); +int MraExtraIconsRebuild (WPARAM wParam,LPARAM lParam); +int MraRebuildStatusMenu (WPARAM wParam,LPARAM lParam); +int MraMusicChanged (WPARAM wParam,LPARAM lParam); + +DWORD MraSendNewStatus (DWORD dwStatusMir,DWORD dwXStatusMir,LPWSTR lpwszStatusTitle,SIZE_T dwStatusTitleSize,LPWSTR lpwszStatusDesc,SIZE_T dwStatusDescSize); + + +HANDLE AddToListByEmail (MRA_LPS *plpsEMail,MRA_LPS *plpsNick,MRA_LPS *plpsFirstName,MRA_LPS *plpsLastName,DWORD dwFlags); + + + +INT_PTR LoadServices(void) +{ + CHAR szServiceFunction[MAX_PATH],*pszServiceFunctionName; + + memmove(szServiceFunction,PROTOCOL_NAMEA,PROTOCOL_NAME_SIZE); + pszServiceFunctionName=szServiceFunction+PROTOCOL_NAME_LEN; + + // Service creation + for (SIZE_T i=0;iszModule,-1,"CList",5)==CSTR_EQUAL) + {// CList section + if (CompareStringA(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NORM_IGNORECASE,cws->szSetting,-1,"MyHandle",8)==CSTR_EQUAL) + {// MyHandle setting + LPWSTR lpwszNewNick; + + if (cws->value.type==DBVT_DELETED) + {// allways store custom nick + lstrcpynW(wszNick,GetContactNameW(hContact),SIZEOF(wszNick)); + lpwszNewNick=wszNick; + dwNickSize=lstrlenW(lpwszNewNick); + DB_SetStringExW(hContact,"CList","MyHandle",lpwszNewNick,dwNickSize); + }else{ + if (cws->value.pszVal) + { + switch(cws->value.type){ + case DBVT_WCHAR: + lpwszNewNick=cws->value.pwszVal; + dwNickSize=lstrlenW(lpwszNewNick); + break; + case DBVT_UTF8: + lpwszNewNick=wszNick; + dwNickSize=MultiByteToWideChar(CP_UTF8,0,cws->value.pszVal,-1,wszNick,SIZEOF(wszNick)); + break; + case DBVT_ASCIIZ: + lpwszNewNick=wszNick; + dwNickSize=MultiByteToWideChar(MRA_CODE_PAGE,0,cws->value.pszVal,-1,wszNick,SIZEOF(wszNick)); + break; + default: + lpwszNewNick=NULL; + dwNickSize=0; + break; + } + if (lpwszNewNick) + if (GetContactBasicInfoW(hContact,&dwID,&dwGroupID,&dwContactFlag,NULL,NULL,szEMail,SIZEOF(szEMail),&dwEMailSize,NULL,0,NULL,szPhones,SIZEOF(szPhones),&dwPhonesSize)==NO_ERROR) + { + MraSendCommand_ModifyContactW(hContact,dwID,dwContactFlag,dwGroupID,szEMail,dwEMailSize,lpwszNewNick,dwNickSize,szPhones,dwPhonesSize); + } + } + } + }else + if (CompareStringA(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NORM_IGNORECASE,cws->szSetting,-1,"Group",5)==CSTR_EQUAL) + {// Group setting //***deb + if (TRUE) + {// manage group on server + switch(cws->value.type){ + case DBVT_ASCIIZ: + + break; + case DBVT_DELETED: + + break; + } + } + }else + if (CompareStringA(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NORM_IGNORECASE,cws->szSetting,-1,"NotOnList",9)==CSTR_EQUAL) + {// NotOnList setting // Has a temporary contact just been added permanently? + if (cws->value.type==DBVT_DELETED || (cws->value.type==DBVT_BYTE && cws->value.bVal==0)) + { + WCHAR wszAuthMessage[MAX_PATH]; + SIZE_T dwAuthMessageSize; + + if (DB_Mra_GetStaticStringW(NULL,"AuthMessage",wszAuthMessage,SIZEOF(wszAuthMessage),&dwAuthMessageSize)==FALSE) + {// def auth message + lstrcpynW(wszAuthMessage,TranslateW(MRA_DEFAULT_AUTH_MESSAGE),SIZEOF(wszAuthMessage)); + dwAuthMessageSize=lstrlenW(wszAuthMessage); + } + + DBDeleteContactSetting(hContact,"CList","Hidden"); + GetContactBasicInfoW(hContact,NULL,&dwGroupID,&dwContactFlag,NULL,NULL,szEMail,SIZEOF(szEMail),&dwEMailSize,wszNick,SIZEOF(wszNick),&dwNickSize,szPhones,SIZEOF(szPhones),&dwPhonesSize); + MraSendCommand_AddContactW(hContact,dwContactFlag,dwGroupID,szEMail,dwEMailSize,wszNick,dwNickSize,szPhones,dwPhonesSize,wszAuthMessage,dwAuthMessageSize,0); + } + }else + if (CompareStringA(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NORM_IGNORECASE,cws->szSetting,-1,"Hidden",6)==CSTR_EQUAL) + {// Hidden setting + GetContactBasicInfoW(hContact,&dwID,&dwGroupID,&dwContactFlag,NULL,NULL,szEMail,SIZEOF(szEMail),&dwEMailSize,wszNick,SIZEOF(wszNick),&dwNickSize,szPhones,SIZEOF(szPhones),&dwPhonesSize); + if(cws->value.type==DBVT_DELETED || (cws->value.type==DBVT_BYTE && cws->value.bVal==0)) + { + dwContactFlag&=~CONTACT_FLAG_SHADOW; + }else{ + dwContactFlag|=CONTACT_FLAG_SHADOW; + } + MraSendCommand_ModifyContactW(hContact,dwID,dwContactFlag,dwGroupID,szEMail,dwEMailSize,wszNick,dwNickSize,szPhones,dwPhonesSize); + } + }else + if (CompareStringA(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NORM_IGNORECASE,cws->szModule,-1,"Ignore",6)==CSTR_EQUAL) + {// Ignore section + if (CompareStringA(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NORM_IGNORECASE,cws->szSetting,-1,"Mask1",5)==CSTR_EQUAL) + { + GetContactBasicInfoW(hContact,&dwID,&dwGroupID,&dwContactFlag,NULL,NULL,szEMail,SIZEOF(szEMail),&dwEMailSize,wszNick,SIZEOF(wszNick),&dwNickSize,szPhones,SIZEOF(szPhones),&dwPhonesSize); + if(cws->value.type==DBVT_DELETED || (cws->value.type==DBVT_DWORD && cws->value.dVal&IGNOREEVENT_MESSAGE)==0) + { + dwContactFlag&=~CONTACT_FLAG_IGNORE; + }else{ + dwContactFlag|=CONTACT_FLAG_IGNORE; + } + MraSendCommand_ModifyContactW(hContact,dwID,dwContactFlag,dwGroupID,szEMail,dwEMailSize,wszNick,dwNickSize,szPhones,dwPhonesSize); + } + }else + if (CompareStringA(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NORM_IGNORECASE,cws->szModule,-1,"UserInfo",8)==CSTR_EQUAL) + {// User info section + if (CompareStringA(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NORM_IGNORECASE,cws->szSetting,-1,"MyPhone0",8)==CSTR_EQUAL + || CompareStringA(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NORM_IGNORECASE,cws->szSetting,-1,"MyPhone1",8)==CSTR_EQUAL + || CompareStringA(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NORM_IGNORECASE,cws->szSetting,-1,"MyPhone2",8)==CSTR_EQUAL) + { + //if(cws->value.type!=DBVT_DELETED) + { + GetContactBasicInfoW(hContact,&dwID,&dwGroupID,&dwContactFlag,NULL,NULL,szEMail,SIZEOF(szEMail),&dwEMailSize,wszNick,SIZEOF(wszNick),&dwNickSize,szPhones,SIZEOF(szPhones),&dwPhonesSize); + MraSendCommand_ModifyContactW(hContact,dwID,dwContactFlag,dwGroupID,szEMail,dwEMailSize,wszNick,dwNickSize,szPhones,dwPhonesSize); + } + } + } + } + }else{// not contact + if (CompareStringA(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NORM_IGNORECASE,cws->szModule,-1,"CListGroups",11)==CSTR_EQUAL) + {// CList section //***deb + if (TRUE) + {// manage group on server + switch(cws->value.type){ + case DBVT_ASCIIZ: + + break; + case DBVT_DELETED: + + break; + } + } + } + } + + + /*if ( hContact == NULL && MyOptions.ManageServer && !strcmp( cws->szModule, "CListGroups" )) { + int iNumber = atol( cws->szSetting ); + LPCSTR szId = MSN_GetGroupByNumber( iNumber ); + if ( szId != NULL ) { + if ( cws->value.type == DBVT_DELETED ) { + msnNsThread->sendPacket( "RMG", szId ); + } + else if ( cws->value.type == DBVT_ASCIIZ ) { + LPCSTR oldId = MSN_GetGroupByName( cws->value.pszVal+1 ); + if ( oldId == NULL ) { + CHAR* p = Utf8Encode( cws->value.pszVal+1 ), szNewName[ 200 ]; + UrlEncode( p, szNewName, sizeof szNewName ); + msnNsThread->sendPacket( "REG", "%s %s", szId, szNewName ); + free( p ); + } + else MSN_SetGroupNumber( oldId, iNumber ); + } } + else if ( cws->value.type == DBVT_ASCIIZ ) + MSN_AddServerGroup( cws->value.pszVal+1 ); + + return 0; + } + + if ( !strcmp( cws->szModule, "CList" ) && MyOptions.ManageServer ) { + CHAR* szProto = ( CHAR* )MSN_CallService( MS_PROTO_GETCONTACTBASEPROTO, ( WPARAM ) hContact, 0 ); + if ( szProto == NULL || strcmp( szProto, msnProtocolName )) + return 0; + + if ( !strcmp( cws->szSetting, "Group" )) { + if ( cws->value.type == DBVT_DELETED ) + MSN_MoveContactToGroup( hContact, NULL ); + else if ( cws->value.type == DBVT_ASCIIZ ) { + LPCSTR p = MSN_GetGroupByName( cws->value.pszVal ); + if ( p == NULL ) + MSN_AddServerGroup( cws->value.pszVal ); + + MSN_MoveContactToGroup( hContact, cws->value.pszVal ); + } + return 0; + } + + } }*/ + + } +return(0); +} + + +int MraRebuildContactMenu(WPARAM wParam,LPARAM lParam) +{ + BOOL bIsContactMRA,bHasEMail,bHasEMailMR,bChatAgent; + DWORD dwContactSeverFlags=0; + SIZE_T dwBlogStatusMsgSize=0; + HANDLE hContact=(HANDLE)wParam; + + bIsContactMRA=IsContactMra(hContact); + if (bIsContactMRA)//**deb телефонные контакты! + {// proto own contact + bHasEMail=TRUE; + bHasEMailMR=TRUE; + bChatAgent=IsContactChatAgent(hContact); + GetContactBasicInfoW(hContact,NULL,NULL,NULL,&dwContactSeverFlags,NULL,NULL,0,NULL,NULL,0,NULL,NULL,0,NULL); + DB_Mra_GetStaticStringW(hContact,DBSETTING_BLOGSTATUS,NULL,0,&dwBlogStatusMsgSize); + }else{// non proto contact + bHasEMail=FALSE; + bHasEMailMR=FALSE; + bChatAgent=FALSE; + if (DB_Mra_GetByte(NULL,"HideMenuItemsForNonMRAContacts",MRA_DEFAULT_HIDE_MENU_ITEMS_FOR_NON_MRA)==FALSE) + if (IsContactMraProto(hContact)==FALSE)// избегаем добавления менюшек в контакты других копий MRA + if (GetContactEMailCount(hContact,FALSE)) + { + bHasEMail=TRUE; + if (GetContactEMailCount(hContact,TRUE)) bHasEMailMR=TRUE; + } + } + + //"Request authorization" + CListShowMenuItem(masMraSettings.hContactMenuItems[0],(masMraSettings.bLoggedIn && bIsContactMRA));// && (dwContactSeverFlags&CONTACT_INTFLAG_NOT_AUTHORIZED) + + //"Grant authorization" + CListShowMenuItem(masMraSettings.hContactMenuItems[1],(masMraSettings.bLoggedIn && bIsContactMRA && bChatAgent==FALSE)); + + //"&Send postcard" + CListShowMenuItem(masMraSettings.hContactMenuItems[2],(masMraSettings.bLoggedIn && bHasEMail && bChatAgent==FALSE)); + + //"&View Album" + CListShowMenuItem(masMraSettings.hContactMenuItems[3],(masMraSettings.bLoggedIn && bHasEMailMR && bChatAgent==FALSE)); + + //"&Read Blog" + CListShowMenuItem(masMraSettings.hContactMenuItems[4],(masMraSettings.bLoggedIn && bHasEMailMR && bChatAgent==FALSE)); + + //"Reply Blog Status" + CListShowMenuItem(masMraSettings.hContactMenuItems[5],(masMraSettings.bLoggedIn && dwBlogStatusMsgSize && bChatAgent==FALSE)); + + //"View Video" + CListShowMenuItem(masMraSettings.hContactMenuItems[6],(masMraSettings.bLoggedIn && bHasEMailMR && bChatAgent==FALSE)); + + //"Answers" + CListShowMenuItem(masMraSettings.hContactMenuItems[7],(masMraSettings.bLoggedIn && bHasEMailMR && bChatAgent==FALSE)); + + //"World" + CListShowMenuItem(masMraSettings.hContactMenuItems[8],(masMraSettings.bLoggedIn && bHasEMailMR && bChatAgent==FALSE)); + + //"Send &Nudge" + if (masMraSettings.heNudgeReceived==NULL) + { + CListShowMenuItem(masMraSettings.hContactMenuItems[9],(masMraSettings.bLoggedIn && bIsContactMRA)); + } + +return(0); +} + + +int MraExtraIconsApply(WPARAM wParam,LPARAM lParam) +{ + SetExtraIcons((HANDLE)wParam); +return(0); +} + + +int MraExtraIconsRebuild(WPARAM wParam,LPARAM lParam) +{ + for(SIZE_T i=0;icbSize != sizeof(LISTENINGTOINFO) ) + { + MraSendCommand_ChangeUserBlogStatus(MRIM_BLOG_STATUS_MUSIC,NULL,0,0); + DB_Mra_DeleteValue(NULL,DBSETTING_BLOGSTATUSMUSIC); + }else + if (pliInfo->dwFlags & LTI_UNICODE) + { + LPWSTR pwszListeningTo; + WCHAR wszListeningTo[MICBLOG_STATUS_MAX+4]; + SIZE_T dwListeningToSize; + + if (ServiceExists(MS_LISTENINGTO_GETPARSEDTEXT)) + { + pwszListeningTo=(LPWSTR)CallService(MS_LISTENINGTO_GETPARSEDTEXT,(WPARAM)L"%track%. %title% - %artist% - %player%",(LPARAM)pliInfo); + dwListeningToSize=lstrlenW(pwszListeningTo); + }else{ + pwszListeningTo=wszListeningTo; + dwListeningToSize=mir_sntprintf(pwszListeningTo,SIZEOF(wszListeningTo),L"%s. %s - %s - %s", pliInfo->ptszTrack?pliInfo->ptszTrack:L"", pliInfo->ptszTitle?pliInfo->ptszTitle:L"", pliInfo->ptszArtist?pliInfo->ptszArtist:L"", pliInfo->ptszPlayer?pliInfo->ptszPlayer:L""); + } + + DB_Mra_SetStringExW(NULL,DBSETTING_BLOGSTATUSMUSIC,pwszListeningTo,dwListeningToSize); + MraSendCommand_ChangeUserBlogStatus(MRIM_BLOG_STATUS_MUSIC,pwszListeningTo,dwListeningToSize,0); + + if (pwszListeningTo!=wszListeningTo) mir_free(pwszListeningTo); + } + +return(0); +} + + +int MraMusicChanged(WPARAM wParam,LPARAM lParam) +{ + switch (wParam){ + case WAT_EVENT_PLAYERSTATUS: + if (1==lParam) + {// stopped + DB_Mra_DeleteValue(NULL,DBSETTING_BLOGSTATUSMUSIC); + MraSendCommand_ChangeUserBlogStatus(MRIM_BLOG_STATUS_MUSIC,NULL,0,0); + } + break; + case WAT_EVENT_NEWTRACK: + { + SONGINFO *psiSongInfo; + + if (WAT_RES_OK==CallService(MS_WAT_GETMUSICINFO,WAT_INF_UNICODE,(LPARAM)&psiSongInfo)) + { + WCHAR wszMusic[MICBLOG_STATUS_MAX+4]; + SIZE_T dwMusicSize; + + dwMusicSize=mir_sntprintf(wszMusic,SIZEOF(wszMusic),L"%ld. %s - %s - %s",psiSongInfo->track,psiSongInfo->artist,psiSongInfo->title,psiSongInfo->player); + DB_Mra_SetStringExW(NULL,DBSETTING_BLOGSTATUSMUSIC,wszMusic,dwMusicSize); + MraSendCommand_ChangeUserBlogStatus(MRIM_BLOG_STATUS_MUSIC,wszMusic,dwMusicSize,0); + } + } + break; + default: + break; + } + +return(0); +} + + +INT_PTR MraGetCaps(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet; + + switch(wParam){ + case PFLAGNUM_1: + iRet=PF1_IM|PF1_FILE|PF1_MODEMSG|PF1_SERVERCLIST|PF1_AUTHREQ|PF1_ADDED|PF1_VISLIST|PF1_INVISLIST|PF1_INDIVSTATUS|PF1_PEER2PEER|/*PF1_NEWUSER|*/PF1_CHAT|PF1_BASICSEARCH|PF1_EXTSEARCH|PF1_CANRENAMEFILE|PF1_FILERESUME|PF1_ADDSEARCHRES|PF1_CONTACT|PF1_SEARCHBYEMAIL|PF1_USERIDISEMAIL|PF1_SEARCHBYNAME|PF1_EXTSEARCHUI; + break; + case PFLAGNUM_2: + iRet=PF2_ONLINE|PF2_INVISIBLE|PF2_SHORTAWAY|PF2_HEAVYDND|PF2_FREECHAT; + break; + case PFLAGNUM_3: + iRet=PF2_ONLINE|PF2_INVISIBLE|PF2_SHORTAWAY|PF2_HEAVYDND|PF2_FREECHAT; + break; + case PFLAGNUM_4: + iRet=PF4_FORCEAUTH|PF4_FORCEADDED|/*PF4_NOCUSTOMAUTH|*/PF4_SUPPORTTYPING|PF4_AVATARS|PF4_IMSENDUTF; + break; + case PFLAG_UNIQUEIDTEXT: + iRet=(INT_PTR)Translate("E-mail address"); + break; + case PFLAG_MAXCONTACTSPERPACKET: + iRet=MRA_MAXCONTACTSPERPACKET; + break; + case PFLAG_UNIQUEIDSETTING: + iRet=(INT_PTR)"e-mail"; + break; + case PFLAG_MAXLENOFMESSAGE: + iRet=MRA_MAXLENOFMESSAGE; + break; + default: + iRet=0; + break; + } +return(iRet); +} + + +INT_PTR MraGetName(WPARAM wParam,LPARAM lParam) +{ + lstrcpynA((LPSTR)lParam,PROTOCOL_DISPLAY_NAMEA,wParam); +return(0); +} + + +INT_PTR MraLoadIcon(WPARAM wParam,LPARAM lParam) +{ + UINT id; + + switch(wParam&0xFFFF){ + case PLI_PROTOCOL:id=IDI_MRA;break;// IDI_TM is the main icon for the protocol + default:return(0); + } +return((INT_PTR)LoadImage(masMraSettings.hInstance,MAKEINTRESOURCE(id),IMAGE_ICON,GetSystemMetrics((wParam&PLIF_SMALL)?SM_CXSMICON:SM_CXICON),GetSystemMetrics((wParam&PLIF_SMALL)?SM_CYSMICON:SM_CYICON),0)); +} + + +INT_PTR MraSetStatus(WPARAM wParam,LPARAM lParam) +{ + // remap global statuses to local supported + switch(wParam){ + case ID_STATUS_OFFLINE: + wParam=ID_STATUS_OFFLINE; + break; + case ID_STATUS_ONLINE: + wParam=ID_STATUS_ONLINE; + break; + case ID_STATUS_AWAY: + wParam=ID_STATUS_AWAY; + break; + case ID_STATUS_DND: + case ID_STATUS_OCCUPIED: + wParam=ID_STATUS_DND; + break; + case ID_STATUS_FREECHAT: + wParam=ID_STATUS_FREECHAT; + break; + case ID_STATUS_INVISIBLE: + wParam=ID_STATUS_INVISIBLE; + break; + case ID_STATUS_NA: + case ID_STATUS_ONTHEPHONE: + case ID_STATUS_OUTTOLUNCH: + wParam=ID_STATUS_AWAY; + break; + default: + wParam=ID_STATUS_OFFLINE; + break; + } + + + if (InterlockedExchangeAdd((volatile LONG*)&masMraSettings.dwStatusMode,0)==wParam && wParam!=lParam) + {// nothink to change + ProtoBroadcastAckAsynchEx(PROTOCOL_NAMEA,NULL,ACKTYPE_STATUS,ACKRESULT_SUCCESS,(HANDLE)wParam,wParam,0); + }else{ + DWORD dwOldStatusMode; + + if ((masMraSettings.dwDesiredStatusMode=wParam)==ID_STATUS_OFFLINE) + {//set all contacts to offline + masMraSettings.bLoggedIn=FALSE; + dwOldStatusMode=InterlockedExchange((volatile LONG*)&masMraSettings.dwStatusMode,masMraSettings.dwDesiredStatusMode); + + if (dwOldStatusMode>ID_STATUS_OFFLINE) + {// всех в offline, только если мы бывали подключены + for(HANDLE hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDFIRST,0,0);hContact!=NULL;hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact,0)) + {// функция сама проверяет принадлежность контакта к MRA + SetContactBasicInfoW(hContact,SCBIFSI_LOCK_CHANGES_EVENTS,(SCBIF_ID|SCBIF_GROUP_ID|SCBIF_SERVER_FLAG|SCBIF_STATUS),-1,-1,0,0,ID_STATUS_OFFLINE,NULL,0,NULL,0,NULL,0); + } + } + Netlib_CloseHandle(masMraSettings.hConnection); + }else{ + // если offline то сразу ставим connecting, но обработка как offline + dwOldStatusMode=InterlockedCompareExchange((volatile LONG*)&masMraSettings.dwStatusMode,ID_STATUS_CONNECTING,ID_STATUS_OFFLINE); + + switch(dwOldStatusMode){ + case ID_STATUS_OFFLINE:// offline, connecting + if (StartConnect()!=NO_ERROR) + {//err + masMraSettings.bLoggedIn=FALSE; + masMraSettings.dwDesiredStatusMode=ID_STATUS_OFFLINE; + dwOldStatusMode=InterlockedExchange((volatile LONG*)&masMraSettings.dwStatusMode,masMraSettings.dwDesiredStatusMode); + } + break; + case ID_STATUS_ONLINE:// connected, change status + case ID_STATUS_AWAY: + case ID_STATUS_DND: + case ID_STATUS_FREECHAT: + case ID_STATUS_INVISIBLE: + MraSendNewStatus(masMraSettings.dwDesiredStatusMode,MraGetXStatusInternal(),NULL,0,NULL,0); + case ID_STATUS_CONNECTING: + if (dwOldStatusMode==ID_STATUS_CONNECTING && wParam!=lParam) + {// предотвращаем переход в любой статус (кроме offline) из статуса connecting, если он не вызван самим плагином + break; + } + default: + dwOldStatusMode=InterlockedExchange((volatile LONG*)&masMraSettings.dwStatusMode,masMraSettings.dwDesiredStatusMode); + //MraSendNewStatus(masMraSettings.dwDesiredStatusMode,MraGetXStatusInternal(),NULL,0,NULL,0); + break; + } + } + MraSetContactStatus(NULL,masMraSettings.dwStatusMode); + ProtoBroadcastAckAsynchEx(PROTOCOL_NAMEA,NULL,ACKTYPE_STATUS,ACKRESULT_SUCCESS,(HANDLE)dwOldStatusMode,masMraSettings.dwStatusMode,0); + } +return(0); +} + + +INT_PTR MraGetStatus(WPARAM wParam,LPARAM lParam) +{ +return(InterlockedExchangeAdd((volatile LONG*)&masMraSettings.dwStatusMode,0)); +} + + +DWORD MraSetXStatusInternal(DWORD dwXStatus) +{ + DWORD dwOldStatusMode; + + if (IsXStatusValid(dwXStatus)) + { + CHAR szValueName[MAX_PATH]; + WCHAR szBuff[4096]; + SIZE_T dwBuffSize; + + // obsolete (TODO: remove in next version) + mir_snprintf(szValueName,SIZEOF(szValueName),"XStatus%ldName",dwXStatus); + if (DB_Mra_GetStaticStringW(NULL,szValueName,szBuff,SIZEOF(szBuff),&dwBuffSize)==FALSE) + {// default xstatus name + lstrcpynW(szBuff,lpcszXStatusNameDef[dwXStatus],SIZEOF(szBuff)); + dwBuffSize=lstrlenW(szBuff); + } + if (dwBuffSize>STATUS_TITLE_MAX) dwBuffSize=STATUS_TITLE_MAX; + DB_Mra_SetStringExW(NULL,DBSETTING_XSTATUSNAME,szBuff,dwBuffSize); + + // obsolete (TODO: remove in next version) + mir_snprintf(szValueName,SIZEOF(szValueName),"XStatus%ldMsg",dwXStatus); + if (DB_Mra_GetStaticStringW(NULL,szValueName,szBuff,SIZEOF(szBuff),&dwBuffSize)) + {// custom xstatus description + if (dwBuffSize>STATUS_DESC_MAX) dwBuffSize=STATUS_DESC_MAX; + DB_Mra_SetStringExW(NULL,DBSETTING_XSTATUSMSG,szBuff,dwBuffSize); + }else{// default xstatus description + DB_Mra_DeleteValue(NULL,DBSETTING_XSTATUSMSG); + } + }else{ + DB_Mra_DeleteValue(NULL,DBSETTING_XSTATUSNAME); + DB_Mra_DeleteValue(NULL,DBSETTING_XSTATUSMSG); + dwXStatus=MRA_MIR_XSTATUS_NONE; + } + + dwOldStatusMode=InterlockedExchange((volatile LONG*)&masMraSettings.dwXStatusMode,dwXStatus); + DB_Mra_SetByte(NULL,DBSETTING_XSTATUSID,(BYTE)dwXStatus); + + MraSendNewStatus(MraGetStatus(0,0),dwXStatus,NULL,0,NULL,0); + +return(dwOldStatusMode); +} + +DWORD MraGetXStatusInternal() +{ +return(InterlockedExchangeAdd((volatile LONG*)&masMraSettings.dwXStatusMode,0)); +} + + + +INT_PTR MraSetXStatus(WPARAM wParam,LPARAM lParam) +{// obsolete (TODO: remove in next version) + INT_PTR iRet=0; + + if (IsXStatusValid(wParam) || wParam==MRA_MIR_XSTATUS_NONE) + { + MraSetXStatusInternal(wParam); + iRet=wParam; + } +return(iRet); +} + +INT_PTR MraSetXStatusEx(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=1; + DWORD dwXStatus; + ICQ_CUSTOM_STATUS *pData=(ICQ_CUSTOM_STATUS*)lParam; + + if (pData->cbSize>=sizeof(ICQ_CUSTOM_STATUS)) + { + iRet=0; + + if (pData->flags&CSSF_MASK_STATUS) + {// fill status member + dwXStatus=(*pData->status); + if (IsXStatusValid(dwXStatus)==FALSE && dwXStatus!=MRA_MIR_XSTATUS_NONE) iRet=1; + }else{ + dwXStatus=MraGetXStatusInternal(); + } + + if (pData->flags&(CSSF_MASK_NAME|CSSF_MASK_MESSAGE) && iRet==0) + {// + if (IsXStatusValid(dwXStatus) || dwXStatus==MRA_MIR_XSTATUS_NONE) + { + CHAR szValueName[MAX_PATH]; + SIZE_T dwBuffSize; + + if (pData->flags&CSSF_MASK_NAME) + {// set custom status name + mir_snprintf(szValueName,SIZEOF(szValueName),"XStatus%ldName",dwXStatus); + if (pData->flags&CSSF_UNICODE) + { + dwBuffSize=lstrlenW(pData->pwszName); + if (dwBuffSize>STATUS_TITLE_MAX) dwBuffSize=STATUS_TITLE_MAX; + + DB_Mra_SetStringExW(NULL,szValueName,pData->pwszName,dwBuffSize); + DB_Mra_SetStringExW(NULL,DBSETTING_XSTATUSNAME,pData->pwszName,dwBuffSize); + }else{ + dwBuffSize=lstrlenA(pData->pszName); + if (dwBuffSize>STATUS_TITLE_MAX) dwBuffSize=STATUS_TITLE_MAX; + + DB_Mra_SetStringExA(NULL,szValueName,pData->pszName,dwBuffSize); + DB_Mra_SetStringExA(NULL,DBSETTING_XSTATUSNAME,pData->pszName,dwBuffSize); + } + } + + if (pData->flags&CSSF_MASK_MESSAGE) + {// set custom status message + mir_snprintf(szValueName,SIZEOF(szValueName),"XStatus%ldMsg",dwXStatus); + if (pData->flags&CSSF_UNICODE) + { + dwBuffSize=lstrlenW(pData->pwszMessage); + if (dwBuffSize>STATUS_TITLE_MAX) dwBuffSize=STATUS_DESC_MAX; + + DB_Mra_SetStringExW(NULL,szValueName,pData->pwszMessage,dwBuffSize); + DB_Mra_SetStringExW(NULL,DBSETTING_XSTATUSMSG,pData->pwszMessage,dwBuffSize); + }else{ + dwBuffSize=lstrlenA(pData->pszMessage); + if (dwBuffSize>STATUS_TITLE_MAX) dwBuffSize=STATUS_DESC_MAX; + + DB_Mra_SetStringExA(NULL,szValueName,pData->pszMessage,dwBuffSize); + DB_Mra_SetStringExA(NULL,DBSETTING_XSTATUSMSG,pData->pszMessage,dwBuffSize); + } + } + }else{// неудача только если мы не ставили Хстатус и попытались записать сообщения для "нет" статуса + if ((pData->flags&CSSF_MASK_STATUS)==0) iRet=1; + } + } + + if (pData->flags&(CSSF_MASK_STATUS|CSSF_MASK_NAME|CSSF_MASK_MESSAGE) && iRet==0) + {// set/update xstatus code and/or message + MraSetXStatusInternal(dwXStatus); + } + + if (pData->flags&CSSF_DISABLE_UI) + {// hide menu items + masMraSettings.bHideXStatusUI=(*pData->wParam)? FALSE:TRUE; + for (DWORD i=0;icbSize>=sizeof(ICQ_CUSTOM_STATUS)) + { + DWORD dwXStatus; + + iRet=0; + + if (pData->flags&CSSF_MASK_STATUS) + {// fill status member + *pData->status=MraGetXStatusInternal(); + } + + if (pData->flags&CSSF_MASK_NAME) + {// fill status name member + if (pData->flags&CSSF_DEFAULT_NAME) + { + dwXStatus=(*pData->wParam); + if (IsXStatusValid(dwXStatus)) + { + if (pData->flags&CSSF_UNICODE) + { + lstrcpynW(pData->pwszName,lpcszXStatusNameDef[dwXStatus],(STATUS_TITLE_MAX+1)); + }else{ + SIZE_T dwStatusTitleSize; + + dwStatusTitleSize=lstrlenW(lpcszXStatusNameDef[dwXStatus]); + if (dwStatusTitleSize>STATUS_TITLE_MAX) dwStatusTitleSize=STATUS_TITLE_MAX; + + WideCharToMultiByte(MRA_CODE_PAGE,0,lpcszXStatusNameDef[dwXStatus],dwStatusTitleSize,pData->pszName,MAX_PATH,NULL,NULL ); + (*((CHAR*)(pData->pszName+dwStatusTitleSize)))=0; + } + }else{// failure + iRet=1; + } + }else{ + if (pData->flags&CSSF_UNICODE) + { + DB_Mra_GetStaticStringW(hContact,DBSETTING_XSTATUSNAME,pData->pwszName,(STATUS_TITLE_MAX+1),NULL); + }else{ + DB_Mra_GetStaticStringA(hContact,DBSETTING_XSTATUSNAME,pData->pszName,(STATUS_TITLE_MAX+1),NULL); + } + } + } + + if (pData->flags&CSSF_MASK_MESSAGE) + {// fill status message member + if (pData->flags&CSSF_UNICODE) + { + DB_Mra_GetStaticStringW(hContact,DBSETTING_XSTATUSMSG,pData->pwszMessage,(STATUS_DESC_MAX+1),NULL); + }else{ + DB_Mra_GetStaticStringA(hContact,DBSETTING_XSTATUSMSG,pData->pszMessage,(STATUS_DESC_MAX+1),NULL); + } + } + + if (pData->flags&CSSF_DISABLE_UI) + { + if (pData->wParam) (*pData->wParam)=masMraSettings.bHideXStatusUI; + } + + if (pData->flags&CSSF_STATUSES_COUNT) + { + if (pData->wParam) (*pData->wParam)=(MRA_XSTATUS_COUNT-1); + } + + if (pData->flags&CSSF_STR_SIZES) + {//**deb можно оптимизировать, данный параметр возможно уже был вычислен при получении самих текстов + if (pData->wParam) DB_Mra_GetStaticStringW(hContact,DBSETTING_XSTATUSNAME,NULL,0,(SIZE_T*)pData->wParam); + if (pData->lParam) DB_Mra_GetStaticStringW(hContact,DBSETTING_XSTATUSMSG,NULL,0,(SIZE_T*)pData->lParam); + } + } +return(iRet); +} + +INT_PTR MraGetXStatusIcon(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet; + + if (wParam==0) wParam=MraGetXStatusInternal(); + iRet=(INT_PTR)IconLibGetIconEx(masMraSettings.hXStatusAdvancedStatusIcons[wParam],lParam); + +return(iRet); +} + + +DWORD MraSendNewStatus(DWORD dwStatusMir,DWORD dwXStatusMir,LPWSTR lpwszStatusTitle,SIZE_T dwStatusTitleSize,LPWSTR lpwszStatusDesc,SIZE_T dwStatusDescSize) +{ + if (masMraSettings.bLoggedIn) + { + CHAR szValueName[MAX_PATH]; + WCHAR wszStatusTitle[STATUS_TITLE_MAX+4],wszStatusDesc[STATUS_DESC_MAX+4]; + DWORD dwStatus,dwXStatus; + + dwStatus=GetMraStatusFromMiradaStatus(dwStatusMir,dwXStatusMir,&dwXStatus); + if (IsXStatusValid(dwXStatusMir)) + {// xstatuses + if (lpwszStatusTitle==NULL || dwStatusTitleSize==0) + { + mir_snprintf(szValueName,SIZEOF(szValueName),"XStatus%ldName",dwXStatusMir); + if (DB_Mra_GetStaticStringW(NULL,szValueName,wszStatusTitle,(STATUS_TITLE_MAX+1),&dwStatusTitleSize)) + {// custom xstatus name + lpwszStatusTitle=wszStatusTitle; + }else{// default xstatus name + lpwszStatusTitle=TranslateW(lpcszXStatusNameDef[dwXStatusMir]); + dwStatusTitleSize=lstrlenW(lpwszStatusTitle); + } + } + + if (lpwszStatusDesc==NULL || dwStatusDescSize==0) + { + mir_snprintf(szValueName,SIZEOF(szValueName),"XStatus%ldMsg",dwXStatusMir); + if (DB_Mra_GetStaticStringW(NULL,szValueName,wszStatusDesc,(STATUS_DESC_MAX+1),&dwStatusDescSize)) + {// custom xstatus description + lpwszStatusDesc=wszStatusDesc; + }else{// default xstatus description + lpwszStatusDesc=NULL; + dwStatusDescSize=0; + } + } + }else{// not xstatuses + if (lpwszStatusTitle==NULL || dwStatusTitleSize==0) + { + lpwszStatusTitle=GetStatusModeDescriptionW(dwStatusMir); + dwStatusTitleSize=lstrlenW(lpwszStatusTitle); + } + } + + MraSendCommand_ChangeStatusW(dwStatus,lpcszStatusUri[dwXStatus],lstrlenA(lpcszStatusUri[dwXStatus]),lpwszStatusTitle,dwStatusTitleSize,lpwszStatusDesc,dwStatusDescSize,((DB_Mra_GetByte(NULL,"RTFReceiveEnable",MRA_DEFAULT_RTF_RECEIVE_ENABLE)? FEATURE_FLAG_RTF_MESSAGE:0)|MRA_FEATURE_FLAGS)); + } + +return(0); +} + + + +INT_PTR MraSetAwayMsgA(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=1; + + if (masMraSettings.bLoggedIn) + { + WCHAR wszStatusDesc[STATUS_DESC_MAX+1]; + SIZE_T dwStatusDescSize; + + if (lParam) + { + dwStatusDescSize=MultiByteToWideChar(MRA_CODE_PAGE,0,(LPSTR)lParam,-1,wszStatusDesc,(SIZEOF(wszStatusDesc)-1)); + }else{ + dwStatusDescSize=0; + } + wszStatusDesc[dwStatusDescSize]=0; + + iRet=MraSetAwayMsg(wParam,(LPARAM)wszStatusDesc); + } +return(iRet); +} + +INT_PTR MraSetAwayMsg(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=1; + + if (masMraSettings.bLoggedIn) + { + LPWSTR lpwszStatusDesc; + DWORD dwStatus,dwXStatus; + SIZE_T dwStatusDescSize; + + lpwszStatusDesc=(LPWSTR)lParam; + dwStatusDescSize=lstrlenW(lpwszStatusDesc); + dwStatus=MraGetStatus(0,0); + dwXStatus=MraGetXStatusInternal(); + + if (dwStatus!=ID_STATUS_ONLINE || IsXStatusValid(dwXStatus)==FALSE) + {// не отправляем новый статусный текст для хстатусов, для хстатусов только эвей сообщения + dwStatusDescSize=min(dwStatusDescSize,STATUS_DESC_MAX); + MraSendNewStatus(dwStatus,dwXStatus,NULL,0,lpwszStatusDesc,dwStatusDescSize); + } + iRet=0; + } +return(iRet); +} + + +INT_PTR MraGetAwayMsg(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=0; + + if (masMraSettings.bLoggedIn && lParam) + { + CHAR szStatusDesc[MICBLOG_STATUS_MAX+MICBLOG_STATUS_MAX+MAX_PATH],szBlogStatus[MICBLOG_STATUS_MAX+4],szTime[64]; + DWORD dwTime; + SIZE_T dwStatusDescSize; + CCSDATA* ccs=(CCSDATA*)lParam; + SYSTEMTIME stBlogStatusTime={0}; + + if (DB_Mra_GetStaticStringA(ccs->hContact,DBSETTING_BLOGSTATUS,szBlogStatus,SIZEOF(szBlogStatus),NULL)) + { + dwTime=DB_Mra_GetDword(ccs->hContact,DBSETTING_BLOGSTATUSTIME,0); + if (dwTime && MakeLocalSystemTimeFromTime32(dwTime,&stBlogStatusTime)) + { + mir_snprintf(szTime,SIZEOF(szTime),"%04ld.%02ld.%02ld %02ld:%02ld: ",stBlogStatusTime.wYear,stBlogStatusTime.wMonth,stBlogStatusTime.wDay,stBlogStatusTime.wHour,stBlogStatusTime.wMinute); + }else{ + szTime[0]=0; + } + + dwStatusDescSize=mir_snprintf(szStatusDesc,SIZEOF(szStatusDesc),"%s%s",szTime,szBlogStatus); + + iRet=GetTickCount(); + ProtoBroadcastAckAsynchEx(PROTOCOL_NAMEA,ccs->hContact,ACKTYPE_AWAYMSG,ACKRESULT_SUCCESS,(HANDLE)iRet,(LPARAM)szStatusDesc,dwStatusDescSize); + } + } +return(iRet); +} + + +INT_PTR MraAuthAllow(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=1; + + if (masMraSettings.bLoggedIn) + { + DBEVENTINFO dbei={0}; + + dbei.cbSize=sizeof(dbei); + if ((dbei.cbBlob=CallService(MS_DB_EVENT_GETBLOBSIZE,wParam,0))!=-1) + { + dbei.pBlob=(PBYTE)MEMALLOC(dbei.cbBlob); + if (dbei.pBlob) + { + if (CallService(MS_DB_EVENT_GET,wParam,(LPARAM)&dbei)==0) + if (dbei.eventType==EVENTTYPE_AUTHREQUEST) + if (CompareStringA(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NORM_IGNORECASE,dbei.szModule,-1,PROTOCOL_NAMEA,PROTOCOL_NAME_LEN)==CSTR_EQUAL) + { + LPSTR lpszNick,lpszFirstName,lpszLastName,lpszEMail,lpszRequestReason; + + lpszNick=(LPSTR)(dbei.pBlob+sizeof(DWORD)*2); + lpszFirstName=lpszNick+lstrlenA(lpszNick)+1; + lpszLastName=lpszFirstName+lstrlenA(lpszFirstName)+1; + lpszEMail=lpszLastName+lstrlenA(lpszLastName)+1; + lpszRequestReason=lpszEMail+lstrlenA(lpszEMail)+1; + + MraSendCommand_Authorize(lpszEMail,lstrlenA(lpszEMail)); + iRet=0; + } + MEMFREE(dbei.pBlob); + } + } + } +return(iRet); +} + + +INT_PTR MraAuthDeny(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=1; + + if (lParam && masMraSettings.bLoggedIn) + { + DBEVENTINFO dbei={0}; + + dbei.cbSize=sizeof(dbei); + if ((dbei.cbBlob=CallService(MS_DB_EVENT_GETBLOBSIZE,wParam,0))!=-1) + { + dbei.pBlob=(PBYTE)MEMALLOC(dbei.cbBlob); + if (dbei.pBlob) + { + if (CallService(MS_DB_EVENT_GET,wParam,(LPARAM)&dbei)==0) + if (dbei.eventType==EVENTTYPE_AUTHREQUEST) + if (CompareStringA(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NORM_IGNORECASE,dbei.szModule,-1,PROTOCOL_NAMEA,PROTOCOL_NAME_LEN)==CSTR_EQUAL) + { + LPSTR lpszNick,lpszFirstName,lpszLastName,lpszEMail,lpszRequestReason; + SIZE_T dwEMailSize,dwRequestReasonSize; + //HANDLE hContact; + + lpszNick=(LPSTR)(dbei.pBlob+sizeof(DWORD)*2); + lpszFirstName=lpszNick+lstrlenA(lpszNick)+1; + lpszLastName=lpszFirstName+lstrlenA(lpszFirstName)+1; + lpszEMail=lpszLastName+lstrlenA(lpszLastName)+1; + dwEMailSize=lstrlenA(lpszEMail); + lpszRequestReason=(LPSTR)lParam; + dwRequestReasonSize=lstrlenA(lpszRequestReason); + + if (dwRequestReasonSize) MraSendCommand_MessageW(FALSE,NULL,0,0,lpszEMail,dwEMailSize,(LPWSTR)lpszRequestReason,dwRequestReasonSize,NULL,0); + //hContact=MraHContactFromEmail(lpszEMail,dwEMailSize,FALSE,TRUE,NULL); + //if (DBGetContactSettingByte(hContact,"CList","NotOnList",0)) CallService(MS_DB_CONTACT_DELETE,(WPARAM)hContact,0); + + iRet=0; + } + MEMFREE(dbei.pBlob); + } + } + } +return(iRet); +} + + + +HANDLE AddToListByEmail(MRA_LPS *plpsEMail,MRA_LPS *plpsNick,MRA_LPS *plpsFirstName,MRA_LPS *plpsLastName,DWORD dwFlags) +{ + HANDLE hContact=NULL; + + if (plpsEMail) + if (plpsEMail->dwSize) + { + BOOL bAdded; + + hContact=MraHContactFromEmail(plpsEMail->lpszData,plpsEMail->dwSize,TRUE,TRUE,&bAdded); + if (hContact) + { + if (plpsNick) + if (plpsNick->dwSize) + { + DB_Mra_SetLPSStringA(hContact,"Nick",plpsNick); + if (bAdded) + {// впервые добавляется контакт в базу///***deb + //SetContactBasicInfoW(hContact,SCBIFSI_LOCK_CHANGES_EVENTS,SCBIF_NICK,0,0,0,0,0,NULL,0,plpsNick->lpszData,plpsNick->dwSize,NULL,0); + } + } + + if (plpsFirstName) + if (plpsFirstName->dwSize) DB_Mra_SetLPSStringA(hContact,"FirstName",plpsFirstName); + + if (plpsLastName) + if (plpsLastName->dwSize) DB_Mra_SetLPSStringA(hContact,"LastName",plpsLastName); + + if (dwFlags&PALF_TEMPORARY) + { + DBWriteContactSettingByte(hContact,"CList","Hidden",1); + }else{ + DBDeleteContactSetting(hContact,"CList","NotOnList"); + } + + if (bAdded) MraUpdateContactInfo(hContact); + } + } +return(hContact); +} + + +INT_PTR MraAddToList(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet; + PROTOSEARCHRESULT *psr=(PROTOSEARCHRESULT*)lParam; + + if (psr->cbSize==sizeof(PROTOSEARCHRESULT)) + { + MRA_LPS lpsEMail,lpsNick,lpsFirstName,lpsLastName; + + lpsEMail.dwSize=lstrlenA((LPSTR)psr->email); + lpsEMail.lpwszData=psr->email; + lpsNick.dwSize=lstrlenA((LPSTR)psr->nick); + lpsNick.lpwszData=psr->nick; + lpsFirstName.dwSize=lstrlenA((LPSTR)psr->firstName); + lpsFirstName.lpwszData=psr->firstName; + lpsLastName.dwSize=lstrlenA((LPSTR)psr->lastName); + lpsLastName.lpwszData=psr->lastName; + + iRet=(INT_PTR)AddToListByEmail(&lpsEMail,&lpsNick,&lpsFirstName,&lpsLastName,wParam); + }else{ + iRet=0; + } +return(iRet); +} + + +INT_PTR MraAddToListByEvent(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=0; + DBEVENTINFO dbei={0}; + + dbei.cbSize=sizeof(dbei); + if ((dbei.cbBlob=CallService(MS_DB_EVENT_GETBLOBSIZE,lParam,0))!=-1) + { + dbei.pBlob=(PBYTE)MEMALLOC(dbei.cbBlob); + if (dbei.pBlob) + { + if (CallService(MS_DB_EVENT_GET,lParam,(LPARAM)&dbei)==0) + if (CompareStringA(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NORM_IGNORECASE,dbei.szModule,-1,PROTOCOL_NAMEA,PROTOCOL_NAME_LEN)==CSTR_EQUAL) + if (dbei.eventType==EVENTTYPE_AUTHREQUEST || dbei.eventType==EVENTTYPE_CONTACTS) + { + LPSTR lpszRequestReason; + MRA_LPS lpsEMail,lpsNick,lpsFirstName,lpsLastName; + + lpsNick.lpszData=(LPSTR)(dbei.pBlob+ ((dbei.eventType==EVENTTYPE_AUTHREQUEST)?(sizeof(DWORD)*2):0) ); + lpsNick.dwSize=lstrlenA(lpsNick.lpszData); + lpsFirstName.lpszData=lpsNick.lpszData+lpsNick.dwSize+1; + lpsFirstName.dwSize=lstrlenA(lpsFirstName.lpszData); + lpsLastName.lpszData=lpsFirstName.lpszData+lpsFirstName.dwSize+1; + lpsLastName.dwSize=lstrlenA(lpsLastName.lpszData); + lpsEMail.lpszData=lpsLastName.lpszData+lpsLastName.dwSize+1; + lpsEMail.dwSize=lstrlenA(lpsEMail.lpszData); + lpszRequestReason=lpsEMail.lpszData+lpsEMail.dwSize+1; + + iRet=(INT_PTR)AddToListByEmail(&lpsEMail,&lpsNick,&lpsFirstName,&lpsLastName,0); + }else{ + dbei.eventType=dbei.eventType; + DebugBreak(); + } + MEMFREE(dbei.pBlob); + } + } +return(iRet); +} + + +/* + --------------------------------- + | Receiving | + --------------------------------- +*/ +INT_PTR MraRecvMessage(WPARAM wParam,LPARAM lParam) +{ + CallService(MS_PROTO_RECVMSG,0,(LPARAM)lParam); +return(0); +} + + +INT_PTR MraRecvContacts(WPARAM wParam,LPARAM lParam) +{ + CCSDATA* ccs=(CCSDATA*)lParam; + DBEVENTINFO dbei={0}; + PROTORECVEVENT* pre=(PROTORECVEVENT*)ccs->lParam; + + dbei.cbSize=sizeof(dbei); + dbei.szModule=PROTOCOL_NAMEA; + dbei.timestamp=pre->timestamp; + dbei.flags=(pre->flags&PREF_CREATEREAD)?DBEF_READ:0; + dbei.eventType=EVENTTYPE_CONTACTS; + dbei.cbBlob=pre->lParam; + dbei.pBlob=(PBYTE)pre->szMessage; + + CallService(MS_DB_EVENT_ADD,(WPARAM)ccs->hContact,(LPARAM)&dbei); +return(0); +} + + +INT_PTR MraRecvFile(WPARAM wParam,LPARAM lParam) +{ + CCSDATA* ccs=(CCSDATA*)lParam; + PROTORECVFILET* pre=(PROTORECVFILET*)ccs->lParam; + + CallService(MS_PROTO_RECVFILET,0,(LPARAM)lParam); +return(0); +} + + +INT_PTR MraRecvAuth(WPARAM wParam,LPARAM lParam) +{ + CCSDATA* ccs=(CCSDATA*)lParam; + DBEVENTINFO dbei={0}; + PROTORECVEVENT* pre=(PROTORECVEVENT*)ccs->lParam; + + dbei.cbSize=sizeof(dbei); + dbei.szModule=PROTOCOL_NAMEA; + dbei.timestamp=pre->timestamp; + dbei.flags=(pre->flags&PREF_CREATEREAD)?DBEF_READ:0; + dbei.eventType=EVENTTYPE_AUTHREQUEST; + dbei.cbBlob=pre->lParam; + dbei.pBlob=(PBYTE)pre->szMessage; + + CallService(MS_DB_EVENT_ADD,(WPARAM)NULL,(LPARAM)&dbei); +return(0); +} + + +/* + --------------------------------- + | Sending | + --------------------------------- +*/ +INT_PTR MraSendAuthRequest(WPARAM wParam,LPARAM lParam) +{// internal only + INT_PTR iRet=1; + + if (masMraSettings.bLoggedIn && lParam) + { + BOOL bSlowSend; + CHAR szEMail[MAX_EMAIL_LEN]; + LPWSTR lpwszMessage; + SIZE_T dwEMailSize,dwMessageSize; + CCSDATA* ccs=(CCSDATA*)lParam; + + if (ccs->wParam&PREF_UNICODE)//flags + { + lpwszMessage=(LPWSTR)ccs->lParam; + dwMessageSize=lstrlenW(lpwszMessage); + }else{ + dwEMailSize=lstrlenA((LPSTR)ccs->lParam); + lpwszMessage=(LPWSTR)MEMALLOC(((dwEMailSize+MAX_PATH)*sizeof(WCHAR))); + if (lpwszMessage) + { + dwMessageSize=MultiByteToWideChar(MRA_CODE_PAGE,0,(LPSTR)ccs->lParam,dwEMailSize,lpwszMessage,(dwEMailSize+MAX_PATH)); + } + } + + if (lpwszMessage) + { + if (DB_Mra_GetStaticStringA(ccs->hContact,"e-mail",szEMail,SIZEOF(szEMail),&dwEMailSize)) + { + bSlowSend=DB_Mra_GetByte(NULL,"SlowSend",MRA_DEFAULT_SLOW_SEND); + iRet=MraSendCommand_MessageW(bSlowSend,ccs->hContact,ACKTYPE_AUTHREQ,MESSAGE_FLAG_AUTHORIZE,szEMail,dwEMailSize,lpwszMessage,dwMessageSize,NULL,0); + if (bSlowSend==FALSE) + { + ProtoBroadcastAckAsynchEx(PROTOCOL_NAMEA,ccs->hContact,ACKTYPE_AUTHREQ,ACKRESULT_SUCCESS,(HANDLE)iRet,(LPARAM)NULL,0); + } + iRet=0; + } + + if (lpwszMessage!=(LPWSTR)ccs->lParam) MEMFREE(lpwszMessage); + } + } +return(iRet); +} + + +INT_PTR MraSendMessage(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=0; + CCSDATA* ccs=(CCSDATA*)lParam; + + if (masMraSettings.bLoggedIn) + { + BOOL bSlowSend,bMemAllocated=FALSE; + CHAR szEMail[MAX_EMAIL_LEN]; + DWORD dwFlags=0; + LPSTR lpszMessage; + LPWSTR lpwszMessage=NULL; + SIZE_T dwEMailSize,dwMessageSize=0; + + lpszMessage=(LPSTR)ccs->lParam; + dwMessageSize=lstrlenA(lpszMessage); + if (ccs->wParam&PREF_UNICODE)//flags + { + lpwszMessage=(LPWSTR)(lpszMessage+dwMessageSize+1); + }else + if (ccs->wParam&PREF_UTF){// convert to unicode from utf8 + lpwszMessage=(LPWSTR)MEMALLOC(((dwMessageSize+MAX_PATH)*sizeof(WCHAR))); + if (lpwszMessage) + { + dwMessageSize=MultiByteToWideChar(CP_UTF8,0,lpszMessage,dwMessageSize,lpwszMessage,(dwMessageSize+MAX_PATH)); + bMemAllocated=TRUE; + } + }else{// convert to unicode from ansi + MraPopupShowFromAgentW(MRA_POPUP_TYPE_DEBUG,0,TranslateW(L"Send ANSI")); + lpwszMessage=(LPWSTR)MEMALLOC(((dwMessageSize+MAX_PATH)*sizeof(WCHAR))); + if (lpwszMessage) + { + dwMessageSize=MultiByteToWideChar(MRA_CODE_PAGE,0,lpszMessage,dwMessageSize,lpwszMessage,(dwMessageSize+MAX_PATH)); + bMemAllocated=TRUE; + } + } + + if (lpwszMessage) + { + if (DB_Mra_GetStaticStringA(ccs->hContact,"e-mail",szEMail,SIZEOF(szEMail),&dwEMailSize)) + { + bSlowSend=DB_Mra_GetByte(NULL,"SlowSend",MRA_DEFAULT_SLOW_SEND); + + if (DB_Mra_GetByte(NULL,"RTFSendEnable",MRA_DEFAULT_RTF_SEND_ENABLE) && (MraContactCapabilitiesGet(ccs->hContact)&FEATURE_FLAG_RTF_MESSAGE)) + { + dwFlags|=MESSAGE_FLAG_RTF; + } + + iRet=MraSendCommand_MessageW(bSlowSend,ccs->hContact,ACKTYPE_MESSAGE,dwFlags,szEMail,dwEMailSize,lpwszMessage,dwMessageSize,NULL,0); + if (bSlowSend==FALSE) + { + ProtoBroadcastAckAsynchEx(PROTOCOL_NAMEA,ccs->hContact,ACKTYPE_MESSAGE,ACKRESULT_SUCCESS,(HANDLE)iRet,(LPARAM)NULL,0); + } + } + + if (bMemAllocated) MEMFREE(lpwszMessage); + }else{ + ProtoBroadcastAckAsynchEx(PROTOCOL_NAMEA,ccs->hContact,ACKTYPE_MESSAGE,ACKRESULT_FAILED,NULL,(LPARAM)"Cant allocate buffer for convert to unicode.",-1); + } + }else{ + ProtoBroadcastAckAsynchEx(PROTOCOL_NAMEA,ccs->hContact,ACKTYPE_MESSAGE,ACKRESULT_FAILED,NULL,(LPARAM)"You cannot send when you are offline.",-1); + } +return(iRet); +} + + +INT_PTR MraSendContacts(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=0; + CCSDATA* ccs=(CCSDATA*)lParam; + + if (masMraSettings.bLoggedIn && lParam) + { + BOOL bSlowSend; + CHAR szEMail[MAX_EMAIL_LEN]; + LPWSTR lpwszData,lpwszDataCurrent,lpwszNick; + SIZE_T i,dwContacts,dwDataBuffSize,dwEMailSize,dwStringSize,dwNickSize; + HANDLE *hContactsList=(HANDLE*)ccs->lParam; + + dwContacts=HIWORD(ccs->wParam); + dwDataBuffSize=(dwContacts*(MAX_EMAIL_LEN*2)); + lpwszData=(LPWSTR)MEMALLOC((dwDataBuffSize*sizeof(WCHAR))); + if (lpwszData) + { + lpwszDataCurrent=lpwszData; + if (DB_Mra_GetStaticStringA(ccs->hContact,"e-mail",szEMail,SIZEOF(szEMail),&dwEMailSize)) + { + for(i=0;ihContact,ACKTYPE_CONTACTS,MESSAGE_FLAG_CONTACT,szEMail,dwEMailSize,lpwszData,(lpwszDataCurrent-lpwszData),NULL,0); + if (bSlowSend==FALSE) + { + ProtoBroadcastAckAsynchEx(PROTOCOL_NAMEA,ccs->hContact,ACKTYPE_CONTACTS,ACKRESULT_SUCCESS,(HANDLE)iRet,(LPARAM)NULL,0); + } + } + MEMFREE(lpwszData); + } + }else{ + ProtoBroadcastAckAsynchEx(PROTOCOL_NAMEA,ccs->hContact,ACKTYPE_CONTACTS,ACKRESULT_FAILED,NULL,(LPARAM)"You cannot send when you are offline.",-1); + } +return(iRet); +} + + +INT_PTR MraSendUserIsTyping(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=1; + + if (masMraSettings.bLoggedIn && wParam && lParam!=PROTOTYPE_SELFTYPING_OFF) + { + CHAR szEMail[MAX_EMAIL_LEN]; + SIZE_T dwEMailSize; + HANDLE hContact=(HANDLE)wParam; + + if (MraGetContactStatus(hContact)!=ID_STATUS_OFFLINE && MraGetStatus(0,0)!=ID_STATUS_INVISIBLE) + if (DB_Mra_GetStaticStringA(hContact,"e-mail",szEMail,SIZEOF(szEMail),&dwEMailSize)) + { + if (MraSendCommand_MessageW(FALSE,hContact,0,MESSAGE_FLAG_NOTIFY,szEMail,dwEMailSize,L" ",1,NULL,0)) iRet=0; + } + } +return(iRet); +} + + +INT_PTR MraSendNudge(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=1; + + if (masMraSettings.bLoggedIn && wParam) + { + CHAR szEMail[MAX_EMAIL_LEN]; + LPWSTR lpwszAlarmMessage=TranslateW(MRA_ALARM_MESSAGE); + SIZE_T dwEMailSize; + HANDLE hContact=(HANDLE)wParam; + + if (DB_Mra_GetStaticStringA(hContact,"e-mail",szEMail,SIZEOF(szEMail),&dwEMailSize)) + { + if (MraSendCommand_MessageW(FALSE,hContact,0,(MESSAGE_FLAG_RTF|MESSAGE_FLAG_ALARM),szEMail,dwEMailSize,lpwszAlarmMessage,lstrlenW(lpwszAlarmMessage),NULL,0)) iRet=0; + } + } +return(iRet); +} + + +INT_PTR MraSetApparentMode(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=1; + + if (masMraSettings.bLoggedIn && lParam) + { + CCSDATA *ccs=(CCSDATA*)lParam; + + if (ccs->hContact && ccs->wParam==0 || ccs->wParam==ID_STATUS_ONLINE || ccs->wParam==ID_STATUS_OFFLINE) + {// Only 3 modes are supported + DWORD dwOldMode=DB_Mra_GetWord(ccs->hContact,"ApparentMode",0); + + // Dont send redundant updates + if (ccs->wParam!=dwOldMode) + { + CHAR szEMail[MAX_EMAIL_LEN],szPhones[MAX_EMAIL_LEN]; + WCHAR wszNick[MAX_EMAIL_LEN]; + DWORD dwID,dwGroupID,dwContactFlag=0; + SIZE_T dwEMailSize,dwNickSize,dwPhonesSize; + + GetContactBasicInfoW(ccs->hContact,&dwID,&dwGroupID,&dwContactFlag,NULL,NULL,szEMail,SIZEOF(szEMail),&dwEMailSize,wszNick,SIZEOF(wszNick),&dwNickSize,szPhones,SIZEOF(szPhones),&dwPhonesSize); + + dwContactFlag&=~(CONTACT_FLAG_INVISIBLE|CONTACT_FLAG_VISIBLE); + switch(ccs->wParam){ + case ID_STATUS_OFFLINE: + dwContactFlag|=CONTACT_FLAG_INVISIBLE; + break; + case ID_STATUS_ONLINE: + dwContactFlag|=CONTACT_FLAG_VISIBLE; + break; + } + + if (MraSendCommand_ModifyContactW(ccs->hContact,dwID,dwContactFlag,dwGroupID,szEMail,dwEMailSize,wszNick,dwNickSize,szPhones,dwPhonesSize)) + { + SetContactBasicInfoW(ccs->hContact,0,SCBIF_FLAG,0,0,dwContactFlag,0,0,NULL,0,NULL,0,NULL,0); + iRet=0;// Success + } + } + } + } +return(iRet); +} + + +INT_PTR MraGetInfo(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=1; + + if (MraUpdateContactInfo(((CCSDATA*)lParam)->hContact)) + { + iRet=0; + } +return(iRet); +} + + +INT_PTR MraGetAvatarCaps(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=0; + + switch(wParam){ + case AF_MAXSIZE: + iRet=-1; + break; + case AF_PROPORTION: + iRet=PIP_NONE; + break; + case AF_FORMATSUPPORTED: + iRet=0;// no formats to set + break; + case AF_ENABLED: + iRet=1;// allways on + break; + case AF_DONTNEEDDELAYS: + iRet=0;// need delay + break; + case AF_MAXFILESIZE: + iRet=0;// + break; + case AF_DELAYAFTERFAIL: + iRet=5000; + break; + } + +return(iRet); +} + + +INT_PTR MraGetAvatarInfo(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=GAIR_NOAVATAR; + + if (lParam) + {//(DWORD)wParam&GAIF_FORCE + PROTO_AVATAR_INFORMATION *ppai=(PROTO_AVATAR_INFORMATION*)lParam; + iRet=(INT_PTR)MraAvatarsQueueGetAvatar(masMraSettings.hAvatarsQueueHandle,(DWORD)wParam,ppai->hContact,NULL,(DWORD*)&ppai->format,ppai->filename); + } +return(iRet); +} + + +INT_PTR MraGetMyAvatar(WPARAM wParam,LPARAM lParam) +{// need call MS_AV_REPORTMYAVATARCHANGED hook + INT_PTR iRet=1; + + if (MraAvatarsGetFileName(masMraSettings.hAvatarsQueueHandle,NULL,GetContactAvatarFormat(NULL,PA_FORMAT_DEFAULT),(LPSTR)wParam,(SIZE_T)lParam,NULL)==NO_ERROR) + { + LPSTR lpsz=(LPSTR)wParam; + iRet=0; + } +return(iRet); +} + + +INT_PTR MraBasicSearch(WPARAM wParam,LPARAM lParam) +{ +return(MraSearchByEmail(wParam,lParam)); +} + +INT_PTR MraSearchByEmail(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=0; + + if (masMraSettings.bLoggedIn && lParam) + { + CHAR szEMail[MAX_EMAIL_LEN]={0}; + SIZE_T dwEMailSize; + + dwEMailSize=(WideCharToMultiByte(MRA_CODE_PAGE,0,(LPWSTR)lParam,-1,szEMail,SIZEOF(szEMail),NULL,NULL)-1); + iRet=MraSendCommand_WPRequestByEMail(NULL,ACKTYPE_SEARCH,szEMail,dwEMailSize); + } +return(iRet); +} + +INT_PTR MraSearchByName(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=0; + + if (masMraSettings.bLoggedIn && lParam) + { + PROTOSEARCHBYNAME *psbn=(PROTOSEARCHBYNAME*)lParam; + + if (psbn->pszNick || psbn->pszFirstName || psbn->pszLastName) + { + DWORD dwRequestFlags=0; + SIZE_T dwNickSize=0,dwFirstNameSize=0,dwLastNameSize=0; + + if (psbn->pszNick) dwNickSize=lstrlenW(psbn->pszNick); + if (psbn->pszFirstName) dwFirstNameSize=lstrlenW(psbn->pszFirstName); + if (psbn->pszLastName) dwLastNameSize=lstrlenW(psbn->pszLastName); + + if (dwNickSize) SetBit(dwRequestFlags,MRIM_CS_WP_REQUEST_PARAM_NICKNAME); + if (dwFirstNameSize) SetBit(dwRequestFlags,MRIM_CS_WP_REQUEST_PARAM_FIRSTNAME); + if (dwLastNameSize) SetBit(dwRequestFlags,MRIM_CS_WP_REQUEST_PARAM_LASTNAME); + + iRet=MraSendCommand_WPRequestW(NULL,ACKTYPE_SEARCH,dwRequestFlags,NULL,0,NULL,0,psbn->pszNick,dwNickSize,psbn->pszFirstName,dwFirstNameSize,psbn->pszLastName,dwLastNameSize,0,0,0,0,0,0,0,0,0); + } + } +return(iRet); +} + +INT_PTR MraCreateAdvSearchUI(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=0; + + if (masMraSettings.hInstance && lParam) + { + iRet=(INT_PTR)CreateDialogParam(masMraSettings.hInstance,MAKEINTRESOURCE(IDD_MRAADVANCEDSEARCH),(HWND)lParam,AdvancedSearchDlgProc,0); + } +return(iRet); +} + +INT_PTR MraSearchByAdvanced(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=0; + + if (masMraSettings.bLoggedIn && lParam) + { + iRet=(INT_PTR)AdvancedSearchFromDlg((HWND)lParam); + } +return(iRet); +} + + + + + +INT_PTR MraFileResume(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=1; + + if (wParam && lParam) + { + PROTOFILERESUME *pfr=(PROTOFILERESUME*)lParam; + //icq_sendFileResume((filetransfer*)wParam,pfr->action,pfr->szFilename); + iRet=0;// Success + } +return(iRet); +} + +INT_PTR MraFileAllow(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=0; + + if (lParam) + if (((CCSDATA*)lParam)->wParam) + { + LPWSTR lpwszPath; + SIZE_T dwPathSize; + CCSDATA *pcds=(CCSDATA*)lParam; + PROTORECVEVENT *prce=(PROTORECVEVENT*)pcds->lParam; + PROTORECVFILET *prcf=(PROTORECVFILET*)pcds->lParam; + + lpwszPath=(LPWSTR)((CCSDATA*)lParam)->lParam; + dwPathSize=lstrlenW(lpwszPath); + + if (MraFilesQueueAccept(masMraSettings.hFilesQueueHandle,((CCSDATA*)lParam)->wParam,lpwszPath,dwPathSize)==NO_ERROR) + { + iRet=((CCSDATA*)lParam)->wParam; // Success + } + } +return(iRet); +} + +INT_PTR MraFileDenyCancel(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=1; + + if (lParam) + if (((CCSDATA*)lParam)->wParam) + {// description: (LPSTR)((CCSDATA*)lParam)->lParam + MraFilesQueueCancel(masMraSettings.hFilesQueueHandle,((CCSDATA*)lParam)->wParam,TRUE); + iRet=0; // Success + } +return(iRet); +} + + + +INT_PTR MraFileSend(WPARAM wParam,LPARAM lParam) +{ + INT_PTR iRet=0; + + if (masMraSettings.bLoggedIn && wParam && lParam) + if (((CCSDATA*)lParam)->hContact && ((CCSDATA*)lParam)->lParam) + {// (LPSTR)((CCSDATA*)lParam)->wParam,lstrlenA((LPSTR)((CCSDATA*)lParam)->wParam) - description + LPWSTR *plpwszFiles=(LPWSTR*)((CCSDATA*)lParam)->lParam; + SIZE_T dwFilesCount; + + for(dwFilesCount=0;plpwszFiles[dwFilesCount];dwFilesCount++); + + MraFilesQueueAddSend(masMraSettings.hFilesQueueHandle,0,((CCSDATA*)lParam)->hContact,plpwszFiles,dwFilesCount,(DWORD*)&iRet); + } +return(iRet); +} -- cgit v1.2.3