MODULEINFO* MM_AddModule(const char* pszModule) { if (!pszModule) return NULL; if (!MM_FindModule(pszModule)) { MODULEINFO *node = (MODULEINFO*) mir_alloc(sizeof(MODULEINFO)); ZeroMemory(node, sizeof(MODULEINFO)); node->pszModule = (char*)mir_alloc(lstrlenA(pszModule) + 1); lstrcpyA(node->pszModule, pszModule); if (m_ModList == NULL) // list is empty { m_ModList = node; node->next = NULL; } else { node->next = m_ModList; m_ModList = node; } return node; } return FALSE; }
static void CreateColorMap( char* Text, int *pIndex, SESSION_INFO* si) { char *p1, *p2, *pEnd; int iIndex = 1; static const char* lpszFmt = "\\red%[^ \x5b\\]\\green%[^ \x5b\\]\\blue%[^ \x5b;];"; char szRed[10], szGreen[10], szBlue[10]; p1 = strstr(Text, "\\colortbl" ); if ( !p1 ) return; pEnd = strchr(p1, '}'); p2 = strstr(p1, "\\red" ); while (p2 && p2 < pEnd) { if ( sscanf( p2, lpszFmt, &szRed, &szGreen, &szBlue) > 0 ) { int i; MODULEINFO * pMod = MM_FindModule(si->pszModule); for (i = 0; i < pMod->nColorCount ; i ++) if (pMod->crColors[i] == RGB( atoi(szRed), atoi(szGreen), atoi(szBlue))) pIndex[i] = iIndex; } iIndex++; p1 = p2; p1 ++; p2 = strstr(p1, "\\red" ); } }
SESSION_INFO* SM_AddSession(const TCHAR* pszID, const char* pszModule) { if (!pszID || !pszModule) return NULL; if (!SM_FindSession(pszID, pszModule)) { SESSION_INFO*node = (SESSION_INFO*) mir_alloc(sizeof(SESSION_INFO)); ZeroMemory(node, sizeof(SESSION_INFO)); node->ptszID = mir_tstrdup(pszID); node->pszModule = mir_strdup(pszModule); MODULEINFO *mi = MM_FindModule(pszModule); if(mi) { mi->idleTimeStamp = time(0); SM_BroadcastMessage(pszModule, GC_UPDATESTATUSBAR, 0, 1, TRUE); } if (m_WndList == NULL) { // list is empty m_WndList = node; node->next = NULL; } else { node->next = m_WndList; m_WndList = node; } node->Highlight = g_Settings.Highlight; return node; } return NULL; }
static int RTFColorToIndex(int *pIndex, int iCol, SESSION_INFO* si) { int i; MODULEINFO * pMod = MM_FindModule(si->pszModule); for (i = 0; i < pMod->nColorCount ; i++) if ( pIndex[i] == iCol ) return i; return -1; }
int CList_RoomDoubleclicked(WPARAM wParam, LPARAM lParam) { DBVARIANT dbv; char *szProto; BOOL bRedrawFlag = FALSE; bool fCreate = false; HANDLE hContact = (HANDLE)wParam; if (!hContact) return 0; szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0); if (MM_FindModule(szProto)) { if (M->GetByte(hContact, szProto, "ChatRoom", 0) == 0) return 0; if (!M->GetTString(hContact, szProto, "ChatRoomID", &dbv)) { SESSION_INFO* si = SM_FindSession(dbv.ptszVal, szProto); if (si) { // is the "toggle visibility option set, so we need to close the window? if (si->hWnd != NULL && M->GetByte("Chat", "ToggleVisibility", 0) == 1 && !CallService(MS_CLIST_GETEVENT, (WPARAM)hContact, 0) && IsWindowVisible(si->hWnd) && !IsIconic(si->pContainer->hwnd)) { PostMessage(si->hWnd, GC_CLOSEWINDOW, 0, 0); DBFreeVariant(&dbv); return 1; } else fCreate = true; ShowRoom(si, WINDOW_VISIBLE, TRUE); if(lParam && fCreate) { SendMessage(si->hWnd, DM_ACTIVATEME, 0, 0); if(si->dat) SetForegroundWindow(si->dat->pContainer->hwnd); } } DBFreeVariant(&dbv); return 1; } } return 0; }
BOOL CList_SetAllOffline(BOOL bHide) { HANDLE hContact; char * szProto; hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); while ( hContact ) { szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0); if ( MM_FindModule( szProto )) { int i = DBGetContactSettingByte(hContact, szProto, "ChatRoom", 0); if ( i != 0 ) { DBWriteContactSettingWord(hContact, szProto,"ApparentMode",(LPARAM)(WORD) 0); DBWriteContactSettingWord(hContact, szProto, "Status", ID_STATUS_OFFLINE); if (bHide && i == GCW_CHATROOM) DBWriteContactSettingByte(hContact, "CList", "Hidden", 1); } } hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM) hContact, 0); } return TRUE; }
int CList_RoomDoubleclicked( WPARAM wParam, LPARAM lParam ) { DBVARIANT dbv; char *szProto; BOOL bRedrawFlag = FALSE; HANDLE hContact = (HANDLE)wParam; if ( !hContact ) return 0; szProto = ( char* )CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0); if ( MM_FindModule(szProto)) { if ( DBGetContactSettingByte( hContact, szProto, "ChatRoom", 0 ) == 0 ) return 0; if ( !DBGetContactSettingTString( hContact, szProto, "ChatRoomID", &dbv )) { SESSION_INFO* si = SM_FindSession( dbv.ptszVal, szProto ); if ( si ) { // is the "toggle visibility option set, so we need to close the window? if (si->hWnd != NULL && DBGetContactSettingByte(NULL, "Chat", "ToggleVisibility", 0)==1 && !CallService(MS_CLIST_GETEVENT, (WPARAM)hContact, 0) && IsWindowVisible(si->hWnd) && !IsIconic(si->hWnd)) { if (g_Settings.TabsEnable) SendMessage(si->hWnd, GC_REMOVETAB, 1, (LPARAM) si ); else PostMessage(si->hWnd, GC_CLOSEWINDOW, 0, 0); DBFreeVariant(&dbv); return 1; } ShowRoom(si, WINDOW_VISIBLE, TRUE); } DBFreeVariant(&dbv); return 1; } } return 0; }
BOOL CList_SetAllOffline(BOOL bHide, const char *pszModule) { HANDLE hContact; char* szProto; hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); while (hContact) { szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0); if (MM_FindModule(szProto)) { if (!pszModule || (pszModule && !strcmp(pszModule, szProto))) { int i = M->GetByte(hContact, szProto, "ChatRoom", 0); if (i != 0) { DBWriteContactSettingWord(hContact, szProto, "ApparentMode", (LPARAM)(WORD) 0); DBWriteContactSettingWord(hContact, szProto, "Status", ID_STATUS_OFFLINE); } } } hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM) hContact, 0); } return TRUE; }
TCHAR* DoRtfToTags( char* pszText, SESSION_INFO* si) { char *p1; int* pIndex; int i, iRemoveChars, cp = CP_ACP; char InsertThis[50]; BOOL bJustRemovedRTF = TRUE; BOOL bTextHasStarted = FALSE; int iUcMode = 0; if ( !pszText ) return FALSE; // create an index of colors in the module and map them to // corresponding colors in the RTF color table pIndex = mir_alloc(sizeof(int) * MM_FindModule(si->pszModule)->nColorCount); for(i = 0; i < MM_FindModule(si->pszModule)->nColorCount ; i++) pIndex[i] = -1; CreateColorMap( pszText, pIndex, si ); // scan the file for rtf commands and remove or parse them p1 = strstr( pszText, "\\pard" ); if ( p1 == NULL ) { mir_free(pIndex); return FALSE; } p1 += 5; memmove(pszText, p1, strlen(p1) + 1); p1 = pszText; // iterate through all characters, if rtf control character found then take action while ( *p1 != '\0' ) { InsertThis[0] = 0; iRemoveChars = 0; switch (*p1) { case '\\': if ( !memcmp(p1, "\\cf", 3 )) { // foreground color int iCol, iInd; iRemoveChars = 3 + ReadInteger(p1+3, &iCol); iInd = RTFColorToIndex(pIndex, iCol, si); bJustRemovedRTF = TRUE; if (bTextHasStarted || iInd >= 0) mir_snprintf( InsertThis, SIZEOF(InsertThis), ( iInd >= 0 ) ? "%%c%02u" : "%%C", iInd); } else if ( !memcmp(p1, "\\highlight", 10 )) { //background color int iCol, iInd; iRemoveChars = 10 + ReadInteger(p1+10, &iCol); iInd = RTFColorToIndex(pIndex, iCol, si); bJustRemovedRTF = TRUE; if (bTextHasStarted || iInd >= 0) mir_snprintf( InsertThis, SIZEOF(InsertThis), ( iInd >= 0 ) ? "%%f%02u" : "%%F", iInd); } else if ( !memcmp(p1, "\\lang", 5 )) { // language id bTextHasStarted = bJustRemovedRTF = TRUE; iRemoveChars = 5 + ReadInteger( p1+5, NULL ); } else if ( !memcmp(p1, "\\par", 4 )) { // newline bTextHasStarted = bJustRemovedRTF = TRUE; iRemoveChars = 4; strcpy(InsertThis, "\n" ); } else if ( !memcmp(p1, "\\line", 5 )) { // newline bTextHasStarted = bJustRemovedRTF = TRUE; iRemoveChars = 5; strcpy(InsertThis, "\n" ); } else if (!memcmp(p1, "\\bullet", 7)) { bTextHasStarted = TRUE; bJustRemovedRTF = TRUE; iRemoveChars = 7; #if defined(_UNICODE) strcpy(InsertThis, "\xE2\x80\xA2"); #else strcpy(InsertThis, "\x95"); #endif } else if ( !memcmp(p1, "\\b", 2 )) { //bold bTextHasStarted = bJustRemovedRTF = TRUE; iRemoveChars = (p1[2] != '0')?2:3; mir_snprintf(InsertThis, SIZEOF(InsertThis), (p1[2] != '0') ? "%%b": "%%B" ); } else if ( !memcmp(p1, "\\i", 2 )) { // italics bTextHasStarted = bJustRemovedRTF = TRUE; iRemoveChars = (p1[2] != '0')?2:3; mir_snprintf(InsertThis, SIZEOF(InsertThis), (p1[2] != '0') ? "%%i" : "%%I" ); } else if ( !memcmp(p1, "\\uc", 3 )) { // number of Unicode chars bTextHasStarted = bJustRemovedRTF = TRUE; iUcMode = p1[3] - '0'; iRemoveChars = 4; } else if ( !memcmp(p1, "\\ul", 3 )) { // underlined bTextHasStarted = bJustRemovedRTF = TRUE; if (p1[3] == 'n') iRemoveChars = 7; else if (p1[3] == '0') iRemoveChars = 4; else iRemoveChars = 3; mir_snprintf(InsertThis, SIZEOF(InsertThis), (p1[3] != '0' && p1[3] != 'n') ? "%%u" : "%%U" ); } else if ( p1[1] == 'f' && isdigit( p1[2] )) { // unicode char bTextHasStarted = bJustRemovedRTF = TRUE; iRemoveChars = 2 + ReadInteger( p1+2, NULL ); } else if ( !memcmp(p1, "\\tab", 4 )) { // tab bTextHasStarted = TRUE; bJustRemovedRTF = TRUE; iRemoveChars = 4; strcpy(InsertThis, " " ); } else if (!memcmp(p1, "\\endash", 7)) { bTextHasStarted = TRUE; bJustRemovedRTF = TRUE; iRemoveChars = 7; #if defined(_UNICODE) strcpy(InsertThis, "\xE2\x80\x93"); #else strcpy(InsertThis, "\x96"); #endif } else if (!memcmp(p1, "\\emdash", 7)) { bTextHasStarted = TRUE; bJustRemovedRTF = TRUE; iRemoveChars = 7; #if defined(_UNICODE) strcpy(InsertThis, "\xE2\x80\x94"); #else strcpy(InsertThis, "\x97"); #endif } else if (!memcmp(p1, "\\lquote",7)) { bTextHasStarted = TRUE; bJustRemovedRTF = TRUE; iRemoveChars = 7; #if defined(_UNICODE) strcpy(InsertThis, "\xE2\x80\x98"); #else strcpy(InsertThis, "\x91"); #endif } else if (!memcmp(p1, "\\rquote",7)) { bTextHasStarted = TRUE; bJustRemovedRTF = TRUE; iRemoveChars = 7; #if defined(_UNICODE) strcpy(InsertThis, "\xE2\x80\x99"); #else strcpy(InsertThis, "\x92"); #endif } else if (!memcmp(p1, "\\ldblquote",10)) { bTextHasStarted = TRUE; bJustRemovedRTF = TRUE; iRemoveChars = 10; #if defined(_UNICODE) strcpy(InsertThis, "\xe2\x80\x9c"); #else strcpy(InsertThis, "\""); #endif } else if (!memcmp(p1, "\\rdblquote",10)) { bTextHasStarted = TRUE; bJustRemovedRTF = TRUE; iRemoveChars = 10; #if defined(_UNICODE) strcpy(InsertThis, "\xe2\x80\x9d"); #else strcpy(InsertThis, "\""); #endif } else if ( p1[1] == '\\' || p1[1] == '{' || p1[1] == '}' ) { // escaped characters bTextHasStarted = TRUE; bJustRemovedRTF = FALSE; iRemoveChars = 2; mir_snprintf(InsertThis, SIZEOF(InsertThis), "%c", p1[1]); } else if ( p1[1] == '~' ) { // non-breaking space bTextHasStarted = TRUE; bJustRemovedRTF = FALSE; iRemoveChars = 2; #if defined(_UNICODE) strcpy(InsertThis, "\xC2\xA0"); #else strcpy(InsertThis, "\xA0"); #endif } else if ( p1[1] == '\'' ) { // special character char tmp[4], *p3 = tmp; bTextHasStarted = TRUE; bJustRemovedRTF = FALSE; if (p1[2] != ' ' && p1[2] != '\\') { *p3++ = p1[2]; iRemoveChars = 3; if ( p1[3] != ' ' && p1[3] != '\\') { *p3++ = p1[3]; iRemoveChars++; } *p3 = 0; sscanf( tmp, "%x", InsertThis ); InsertThis[1] = 0; } else iRemoveChars = 2; } else if ( bJustRemovedRTF ) { // remove unknown RTF command int j = 1; bJustRemovedRTF = TRUE; while(p1[j] != ' ' && p1[j] != '\\' && p1[j] != '\0') j++; iRemoveChars = j; } break; case '{': // other RTF control characters case '}': iRemoveChars = 1; break; case '\r': case '\n': bTextHasStarted = TRUE; bJustRemovedRTF = FALSE; iRemoveChars = 1; break; case '%': // escape chat -> protocol control character bTextHasStarted = TRUE; bJustRemovedRTF = FALSE; iRemoveChars = 1; strcpy(InsertThis, "%%"); break; case ' ': // remove spaces following a RTF command if (bJustRemovedRTF) iRemoveChars = 1; bJustRemovedRTF = FALSE; bTextHasStarted = TRUE; break; default: // other text that should not be touched bTextHasStarted = TRUE; bJustRemovedRTF = FALSE; break; } // move the memory and paste in new commands instead of the old RTF if (InsertThis[0] || iRemoveChars) { size_t len = strlen(InsertThis); memmove(p1 + len , p1 + iRemoveChars, strlen(p1) - iRemoveChars + 1); memcpy(p1, InsertThis, len); p1 += len; } else p1++; } mir_free(pIndex); #if !defined( _UNICODE ) return pszText; #else return mir_utf8decodeW(pszText); #endif }
static INT_PTR Service_NewChat(WPARAM wParam, LPARAM lParam) { MODULEINFO* mi; GCSESSION *gcw =(GCSESSION *)lParam; if (gcw== NULL) return GC_NEWSESSION_ERROR; if (gcw->cbSize != SIZEOF_STRUCT_GCWINDOW_V1) return GC_NEWSESSION_WRONGVER; EnterCriticalSection(&cs); if (( mi = MM_FindModule( gcw->pszModule )) != NULL ) { TCHAR* ptszID = a2tf( gcw->ptszID, gcw->dwFlags ); SESSION_INFO* si = SM_AddSession( ptszID, gcw->pszModule); if (mi->hOfflineIcon == NULL) { LoadModuleIcons(mi); } // create a new session and set the defaults if ( si != NULL ) { TCHAR szTemp[256]; si->dwItemData = gcw->dwItemData; if ( gcw->iType != GCW_SERVER ) si->wStatus = ID_STATUS_ONLINE; si->iType = gcw->iType; si->dwFlags = gcw->dwFlags; si->ptszName = a2tf( gcw->ptszName, gcw->dwFlags ); si->ptszStatusbarText = a2tf( gcw->ptszStatusbarText, gcw->dwFlags ); si->iSplitterX = g_Settings.iSplitterX; si->iSplitterY = g_Settings.iSplitterY; si->iLogFilterFlags = (int)DBGetContactSettingDword(NULL, "Chat", "FilterFlags", 0x03E0); si->bFilterEnabled = DBGetContactSettingByte(NULL, "Chat", "FilterEnabled", 0); si->bNicklistEnabled = DBGetContactSettingByte(NULL, "Chat", "ShowNicklist", 1); #if defined( _UNICODE ) if ( !( gcw->dwFlags & GC_UNICODE )) { si->pszID = mir_strdup( gcw->pszID ); si->pszName = mir_strdup( gcw->pszName ); } #endif if ( mi->bColor ) { si->iFG = 4; si->bFGSet = TRUE; } if ( mi->bBkgColor ) { si->iBG = 2; si->bBGSet = TRUE; } if (si->iType == GCW_SERVER) mir_sntprintf(szTemp, SIZEOF(szTemp), _T("Server: %s"), si->ptszName); else mir_sntprintf(szTemp, SIZEOF(szTemp), _T("%s"), si->ptszName); si->windowData.hContact = CList_AddRoom( gcw->pszModule, ptszID, szTemp, si->iType); si->windowData.codePage = DBGetContactSettingWord(si->windowData.hContact, si->pszModule, "CodePage", (WORD) CP_ACP); si->pszHeader = Log_CreateRtfHeader(mi, si); DBWriteContactSettingString(si->windowData.hContact, si->pszModule , "Topic", ""); DBDeleteContactSetting(si->windowData.hContact, "CList", "StatusMsg"); if (si->ptszStatusbarText) DBWriteContactSettingTString(si->windowData.hContact, si->pszModule, "StatusBar", si->ptszStatusbarText); else DBWriteContactSettingString(si->windowData.hContact, si->pszModule, "StatusBar", ""); } else { SESSION_INFO* si2 = SM_FindSession( ptszID, gcw->pszModule ); if ( si2 ) { UM_RemoveAll(&si2->pUsers); TM_RemoveAll(&si2->pStatuses); si2->iStatusCount = 0; si2->nUsersInNicklist = 0; if (si2->hWnd ) RedrawWindow(GetDlgItem(si2->hWnd, IDC_CHAT_LIST), NULL, NULL, RDW_INVALIDATE); } } LeaveCriticalSection(&cs); mir_free( ptszID ); return 0; } LeaveCriticalSection(&cs); return GC_NEWSESSION_ERROR; }