void LogToMessageWindow(XSTATUSCHANGE *xsc, BOOL opening) { // cut message if needed if (opt.LTruncateMsg && (opt.LMsgLen > 0) && xsc->stzText && (_tcslen(xsc->stzText) > opt.LMsgLen)) { TCHAR buff[MAX_TEXT_LEN + 3]; _tcsncpy(buff, xsc->stzText, opt.LMsgLen); buff[opt.LMsgLen] = 0; _tcscat(buff, _T("...")); mir_free(xsc->stzText); xsc->stzText = mir_tstrdup(buff); } TCHAR *Template = _T(""); switch (xsc->action) { case NOTIFY_NEW_XSTATUS: Template = templates.LogNewXstatus; break; case NOTIFY_NEW_MESSAGE: Template = templates.LogNewMsg; break; case NOTIFY_REMOVE: Template = templates.LogRemove; break; case NOTIFY_OPENING_ML: Template = templates.LogOpening; break; } TCHAR stzLogText[2*MAX_TEXT_LEN]; TCHAR stzLastLog[2*MAX_TEXT_LEN]; ReplaceVars(xsc, Template, templates.LogDelimiter, stzLogText); DBGetStringDefault(xsc->hContact, MODULE, DB_LASTLOG, stzLastLog, SIZEOF(stzLastLog), _T("")); if (!opt.KeepInHistory || !(opt.PreventIdentical && _tcscmp(stzLastLog, stzLogText) == 0)) db_set_ws(xsc->hContact, MODULE, DB_LASTLOG, stzLogText); }
bool StatusInit( void ) /*********************/ { char buff[MAXBUF]; ReplaceVars( buff, sizeof( buff ), GetVariableStrVal( "AppName" ) ); return( OpenStatusWindow( buff ) ); }
static void SetDynamic( gui_window *gui, vhandle var_handle, bool *drive_checked ) /*******************************************************************************/ { char buff[256]; const char *p; p = VarGetStrVal( var_handle ); if( !*drive_checked ) { while( *p ) { if( *p == '%' ) { if( strnicmp( p, "%DriveFree", 10 ) == 0 ) { CheckDrive( FALSE ); *drive_checked = TRUE; } } ++p; } } ReplaceVars( buff, VarGetStrVal( var_handle ) ); AddInstallName( buff, FALSE ); GUISetText( gui, VarGetId( var_handle ), buff ); }
extern dlg_state GenericDialog( gui_window *parent, a_dialog_header *curr_dialog ) /********************************************************************************/ { char *title; DLG_WINDOW_SET result; int width; int height; char buff[MAXBUF]; if( curr_dialog == NULL ) { return( DLG_CAN ); } AdjustDialogControls( curr_dialog ); result.state = DLG_CAN; result.current_dialog = curr_dialog; if( curr_dialog->title != NULL ) { title = curr_dialog->title; } else { ReplaceVars( buff, GetVariableStrVal( "Appname" ) ); title = buff; } width = curr_dialog->cols; height = curr_dialog->rows; #if defined( __OS2__ ) && !defined( _UI ) height -= 1; #endif if( width < strlen(title) + WIDTH_BORDER + 2 ) { width = strlen(title) + WIDTH_BORDER + 2; } GUIRefresh(); GUIModalDlgOpen( parent == NULL ? MainWnd : parent, title, height, width, curr_dialog->controls, curr_dialog->num_controls, &GenericEventProc, &result ); ResetDriveInfo(); return( result.state ); }
extern void GUImain( void ) /*************************/ { int argc = 0; char **argv = NULL; char *dir; char *drive; char *inf_name; char *tmp_path; char *arc_name; char *new_inf; char current_dir[_MAX_PATH]; bool ret = FALSE; dlg_state state; GUIMemOpen(); GUIGetArgs( &argv, &argc ); #if defined( __NT__ ) if( CheckWin95Uninstall( argc, argv ) ) return; #endif #ifdef __WINDOWS__ if( CheckForSetup32( argc, argv ) ) return; #endif // initialize paths and env. vbls. if( !SetupPreInit() ) return; if( !GetDirParams( argc, argv, &inf_name, &tmp_path, &arc_name ) ) return; if( !SetupInit() ) return; GUIDrainEvents(); // push things along FileInit( arc_name ); InitGlobalVarList(); strcpy( current_dir, tmp_path ); while( InitInfo( inf_name, tmp_path ) ) { ret = DoMainLoop( &state ); if( state == DLG_DONE ) break; // if( CancelSetup == TRUE || !ret ) break; if( CancelSetup == TRUE ) break; // if( !ret ) break; // look for another SETUP.INF if( GetVariableByName( "SetupPath" ) == NO_VAR ) { if( DirParamStack( &inf_name, &tmp_path, Stack_IsEmpty ) == FALSE ) { // "IsEmpty"? DirParamStack( &inf_name, &tmp_path, Stack_Pop ); // "Pop" CloseDownMessage( ret ); CancelSetup = FALSE; ret = TRUE; } else { CloseDownMessage( ret ); break; } } else { if( GetVariableIntVal( "IsMultiInstall" ) ) { // push current script on stack DirParamStack( &inf_name, &tmp_path, Stack_Push ); // "Push" } new_inf = GUIMemAlloc( _MAX_PATH ); drive = GUIMemAlloc( _MAX_DRIVE ); dir = GUIMemAlloc( _MAX_PATH ); if( new_inf == NULL || drive == NULL || dir == NULL ) { GUIMemFree( new_inf ); GUIMemFree( drive ); GUIMemFree( dir ); break; } // construct new path relative to previous ReplaceVars( new_inf, GetVariableStrVal( "SetupPath" ) ); _splitpath( current_dir, drive, dir, NULL, NULL ); _makepath( inf_name, drive, dir, new_inf, NULL ); _splitpath( inf_name, drive, dir, NULL, NULL ); _makepath( tmp_path, drive, dir, NULL, NULL ); // strcpy( current_dir, tmp_path ); GUIMemFree( new_inf ); GUIMemFree( drive ); GUIMemFree( dir ); } /* if */ FreeGlobalVarList( FALSE ); FreeDefaultDialogs(); FreeAllStructs(); ConfigModified = FALSE; } /* while */ FileFini(); FreeGlobalVarList( TRUE ); FreeDefaultDialogs(); FreeAllStructs(); FreeDirParams( &inf_name, &tmp_path, &arc_name ); CloseDownProgram(); }
int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) { HANDLE hContact = (HANDLE)wParam; DBEVENTINFO *dbei = (DBEVENTINFO *)lParam; char *msgblob; POPUPDATA ppdp = {0}; DBTIMETOSTRING tts = {0}; char protoOption[256] = {0}; char *response, *tmp, *challenge; int buflen = MAX_BUFFER_LENGTH; TCHAR buf[MAX_BUFFER_LENGTH]; TCHAR *message = NULL, *challengeW = NULL, *tmpW = NULL; TCHAR *whitelist = NULL, *ptok; TCHAR mexpr[64]; int maxmsglen = 0, a, b, i; BOOL bayesEnabled = _getOptB("BayesEnabled", defaultBayesEnabled); BOOL bCorrectResponse = FALSE; // get hContact from DBEVENTINFO as icq_proto.c doesn't pass hContact the usual way for some reason. if (dbei->eventType == EVENTTYPE_AUTHREQUEST) hContact = *((PHANDLE)(dbei->pBlob+sizeof(DWORD))); // get maximum length of the message a protocol supports maxmsglen = CallProtoService(dbei->szModule, PS_GETCAPS, PFLAG_MAXLENOFMESSAGE, (LPARAM)hContact); /*** Dequeue and learn messages ***/ if (bayesEnabled && _getOptB("BayesAutolearnNotApproved", defaultBayesAutolearnNotApproved)) if (time(NULL) - last_queue_check > 4*3600) { // dequeue every 4 hours dequeue_messages(); last_queue_check = time(NULL); } /*** Check for conditional and unconditional approval ***/ // Pass-through if protocol is not enabled strcat(protoOption, "proto_"); strcat(protoOption, dbei->szModule); if (_getOptB(protoOption, 0) == 0) // Protocol is not handled by Spam-o-tron return 0; // Pass-through if the event is not of type EVENTTYPE_MESSAGE or EVENTTYPE_AUTHREQUEST if (dbei->eventType != EVENTTYPE_MESSAGE && dbei->eventType != EVENTTYPE_AUTHREQUEST) return 0; // Pass-through if contact is already verified. if (_getCOptB(hContact, "Verified", 0) == 1) return 0; // Pass-through if the event is already read. if (dbei->flags & DBEF_READ) return 0; // Pass-through if event is from a contact that is already in the list. if (db_get_b(hContact, "CList", "NotOnList", 1) == 0) // Already in the list return 0; // Pass-through if event is from a contact that is already in the server-side contact list if (db_get_w(hContact, dbei->szModule, "ServerId", 0)) return 0; // Pass-through if contact is a MetaContact if (db_get_dw(hContact, "MetaContacts", "NumContacts", 0)) return 0; // Pass-through and approve if outgoing event. if (dbei->flags & DBEF_SENT) { if (_getOptB("ApproveOnMsgOut", 0)) { _setCOptB(hContact, "Verified", 1); if (_getOptB("AddPermanently", defaultAddPermanently)) db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Delete"); } return 0; } // Hide the contact until verified if option set. if (_getOptB("HideUnverified", defaultHideUnverified)) db_set_b(hContact, "CList", "Hidden", 1); // Fetch the incoming message body if (dbei->eventType == EVENTTYPE_MESSAGE) { msgblob = (char *)dbei->pBlob; } else if (dbei->eventType == EVENTTYPE_AUTHREQUEST) { msgblob = (char *)(dbei->pBlob + sizeof(DWORD) + sizeof(HANDLE)); for(a=4;a>0;a--) msgblob += strlen(msgblob)+1; } if (dbei->flags & DBEF_UTF) message = mir_utf8decodeW(msgblob); else message = mir_a2u(msgblob); /*** Check for words in white-list ***/ if (_getOptB("ApproveOnMsgIn", defaultApproveOnMsgIn)) { whitelist = (TCHAR*)malloc(2048 * sizeof(TCHAR)); if (whitelist != NULL) { _getOptS(whitelist, 2048, "ApproveOnMsgInWordlist", defaultApproveOnMsgInWordlist); if (_isregex(whitelist)) { if (_regmatch(message, whitelist)) bCorrectResponse = TRUE; } else { ptok = _tcstok(whitelist, L" "); while (ptok != NULL) { if (_tcsstr(message, ptok)) { bCorrectResponse = TRUE; break; } ptok = _tcstok(NULL, L" "); } } free(whitelist); if (bCorrectResponse) { _setCOptB(hContact, "Verified", 1); if (_getOptB("HideUnverified", defaultHideUnverified)) db_unset(hContact, "CList", "Hidden"); if (_getOptB("AddPermanently", defaultAddPermanently)) db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Delete"); if (_getOptB("ReplyOnSuccess", defaultReplyOnSuccess) && (_getCOptB(hContact, "MsgSent", 0))) { tmp = mir_u2a(_getOptS(buf, buflen, "SuccessResponse", defaultSuccessResponse)); response = mir_utf8encode(tmp); mir_free(tmp); CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)response); mir_free(response); } return 0; } } } /*** Check for correct answer ***/ switch (_getOptB("Mode", defaultMode)) { case SPAMOTRON_MODE_ROTATE: case SPAMOTRON_MODE_RANDOM: get_response(buf, buflen, _getCOptD(hContact, "ResponseNum", 0)); if (_isregex(buf)) { if (_regmatch(message, buf)) bCorrectResponse = TRUE; } else { if (_tcsstr_cc(message, buf, _getOptB("ResponseCC", defaultResponseCC)) && (_tcslen(message) == _tcslen(buf))) bCorrectResponse = TRUE; } break; case SPAMOTRON_MODE_PLAIN: _getOptS(buf, buflen, "Response", defaultResponse); i = get_response_num(buf); while (i-- > 0) { get_response(buf, buflen, i-1); if (_isregex(buf)) { if (_regmatch(message, buf)) { bCorrectResponse = TRUE; break; } } else { if (_tcsstr_cc(message, buf, _getOptB("ResponseCC", defaultResponseCC)) && (_tcslen(message) == _tcslen(buf))) { bCorrectResponse = TRUE; break; } } } break; case SPAMOTRON_MODE_MATH: if (message == NULL) break; _itot(_getCOptD(hContact, "ResponseMath", -1), buf, 10); if (_tcsstr(message, buf) && (_tcslen(buf) == _tcslen(message))) { bCorrectResponse = TRUE; } break; } if (bCorrectResponse) { _setCOptB(hContact, "Verified", 1); if (_getOptB("HideUnverified", defaultHideUnverified)) db_unset(hContact, "CList", "Hidden"); if (_getOptB("AddPermanently", defaultAddPermanently)) db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Delete"); db_unset(hContact, "CList", "ResponseNum"); if (_getOptB("ReplyOnSuccess", defaultReplyOnSuccess)) { tmp = mir_u2a(_getOptS(buf, buflen, "SuccessResponse", defaultSuccessResponse)); response = mir_utf8encode(tmp); mir_free(tmp); CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)response); mir_free(response); } _notify(hContact, POPUP_APPROVED, TranslateT("Contact %s approved."), NULL); // Resubmit pending authorization request if (_getCOptB(hContact, "AuthEventPending", FALSE)) { DBVARIANT _dbv; TCHAR AuthEventModule[100]; char* szAuthEventModule; if (db_get(hContact, PLUGIN_NAME, "AuthEvent", &_dbv) == 0) { DBEVENTINFO *_dbei = (DBEVENTINFO *)malloc(sizeof(DBEVENTINFO)); if (_dbei != NULL) { memcpy(&_dbei->cbBlob, _dbv.pbVal, sizeof(DWORD)); _dbei->eventType = EVENTTYPE_AUTHREQUEST; _getCOptS(AuthEventModule, 100, hContact, "AuthEventModule", _T("ICQ")); szAuthEventModule = mir_u2a(AuthEventModule); _dbei->szModule = szAuthEventModule; _dbei->timestamp = dbei->timestamp; _dbei->flags = 0; _dbei->cbSize = sizeof(DBEVENTINFO); _dbei->pBlob = _dbv.pbVal + sizeof(DWORD); db_event_add(hContact,_dbei); db_unset(hContact, PLUGIN_NAME, "AuthEvent"); db_unset(hContact, PLUGIN_NAME, "AuthEventPending"); db_unset(hContact, PLUGIN_NAME, "AuthEventModule"); mir_free(szAuthEventModule); free(_dbei); } db_free(&_dbv); } } // User approved, learn from previous messages if (bayesEnabled && _getOptB("BayesAutolearnApproved", defaultBayesAutolearnApproved)) bayes_approve_contact(hContact); // Mark previous messages unread if option set if (_getOptB("KeepBlockedMsg", defaultKeepBlockedMsg) && _getOptB("MarkMsgUnreadOnApproval", defaultMarkMsgUnreadOnApproval) && hContact != NULL) { // We will mark unread all blocked messages for the most recent day MarkUnread(hContact); } return 1; } /*** Check for rejection ***/ // Completely reject if challenge was already sent today for MaxMsgContactCountPerDay times // and the option is turned on. if (isOneDay(dbei->timestamp, _getCOptD(hContact, "MsgSentTime", 0)) && _getOptD("MaxMsgContactCountPerDay", defaultMaxMsgContactCountPerDay) > 0 && _getCOptD(hContact, "MsgSent", 0) >= _getOptD("MaxMsgContactCountPerDay", defaultMaxMsgContactCountPerDay)) { _notify(hContact, POPUP_BLOCKED, TranslateT("Message from %s rejected because it reached a maximum for challenge requests per day."), message); if (bayesEnabled) queue_message(hContact, dbei->timestamp, message); return 1; } // Completely reject if duplicate incoming message found if (_getOptD("MaxSameMsgCountPerDay", defaultMaxSameMsgCountPerDay) > 0 && _getCOptD(hContact, "SameMsgCount", 0) >= _getOptD("MaxSameMsgCountPerDay", defaultMaxSameMsgCountPerDay) && _tcscmp(message, _getCOptS(buf, buflen, hContact, "LastInMsg", _T(""))) == 0) { _notify(hContact, POPUP_BLOCKED, TranslateT("Message from %s rejected because it reached a maximum for same responses per day."), message); if (bayesEnabled) queue_message(hContact, dbei->timestamp, message); return 1; } // Completely reject if incoming message contains any word from DontReplyMsgWordlist option if (_getOptB("DontReplyMsg", defaultDontReplyMsg) && Contains(message, _getOptS(buf, buflen, "DontReplyMsgWordlist", defaultDontReplyMsgWordlist))) { _notify(hContact, POPUP_BLOCKED, TranslateT("Message from %s dropped because it has a word from black list."), message); return 1; } /*** Bayes checks ***/ // Drop if score > spam score if (bayesEnabled && _getOptB("BayesBlockMsg", defaultBayesBlockMsg)) if (get_msg_score(message) >= (double)_getOptD("BayesSpamScore", defaultBayesSpamScore) * SCORE_C) { _notify(hContact, POPUP_BLOCKED, TranslateT("Message from %s dropped because of high spam score."), message); if (bayesEnabled && _getOptB("BayesAutolearnNotApproved", defaultBayesAutolearnNotApproved)) queue_message(hContact, dbei->timestamp, message); return 1; } // Accept if score < ham score if (bayesEnabled && _getOptB("BayesAutoApprove", defaultBayesAutoApprove)) if (get_msg_score(message) <= (double)_getOptD("BayesHamScore", defaultBayesHamScore) * SCORE_C) { _notify(hContact, POPUP_APPROVED, TranslateT("Contact %s approved."), message); _setCOptB(hContact, "Verified", 1); if (_getOptB("HideUnverified", defaultHideUnverified)) db_unset(hContact, "CList", "Hidden"); if (_getOptB("AddPermanently", defaultAddPermanently)) db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Delete"); if (bayesEnabled && _getOptB("BayesAutolearnApproved", defaultBayesAutolearnApproved) && _getOptB("BayesAutolearnAutoApproved", defaultBayesAutolearnAutoApproved)) { queue_message(hContact, dbei->timestamp, message); bayes_approve_contact(hContact); } return 0; } // Accept if event is EVENTTYPE_AUTHREQUEST and ReplyOnAuth is NOT set if (dbei->eventType == EVENTTYPE_AUTHREQUEST && !_getOptB("ReplyOnAuth", defaultReplyOnAuth)) return 0; // Accept if event is EVENTTYPE_MESSAGE and ReplyOnMsg is NOT set if (dbei->eventType == EVENTTYPE_MESSAGE && !_getOptB("ReplyOnMsg", defaultReplyOnMsg)) return 0; /*** Send Challenge ***/ challengeW = (TCHAR *)malloc(maxmsglen*sizeof(TCHAR)); tmpW = (TCHAR *)malloc(maxmsglen*sizeof(TCHAR)); switch (_getOptB("Mode", defaultMode)) { case SPAMOTRON_MODE_PLAIN: if (dbei->eventType == EVENTTYPE_AUTHREQUEST) _getOptS(challengeW, maxmsglen, "AuthChallenge", defaultAuthChallenge); else _getOptS(challengeW, maxmsglen, "Challenge", defaultChallenge); ReplaceVars(challengeW, maxmsglen); tmp = mir_u2a(challengeW); challenge = mir_utf8encode(tmp); mir_free(tmp); CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)challenge); mir_free(challenge); _notify(hContact, POPUP_CHALLENGE, TranslateT("Sending plain challenge to %s."), message); break; case SPAMOTRON_MODE_ROTATE: if (dbei->eventType == EVENTTYPE_AUTHREQUEST) _getOptS(challengeW, maxmsglen, "AuthChallenge", defaultAuthChallenge); else _getOptS(challengeW, maxmsglen, "Challenge", defaultChallenge); _getOptS(buf, buflen, "Response", defaultResponse); if (_getCOptD(hContact, "ResponseNum", 0) >= (unsigned int)(get_response_num(buf)-1)) { _setCOptD(hContact, "ResponseNum", -1); } _setCOptD(hContact, "ResponseNum", _getCOptD(hContact, "ResponseNum", -1) + 1); ReplaceVarsNum(challengeW, maxmsglen, _getCOptD(hContact, "ResponseNum", 0)); tmp = mir_u2a(challengeW); challenge = mir_utf8encode(tmp); mir_free(tmp); CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)challenge); mir_free(challenge); _notify(hContact, POPUP_CHALLENGE, TranslateT("Sending round-robin challenge to %s."), message); break; case SPAMOTRON_MODE_RANDOM: if (dbei->eventType == EVENTTYPE_AUTHREQUEST) _getOptS(challengeW, maxmsglen, "AuthChallenge", defaultAuthChallenge); else _getOptS(challengeW, maxmsglen, "Challenge", defaultChallenge); _getOptS(buf, buflen, "Response", defaultResponse); srand(time(NULL)); _setCOptD(hContact, "ResponseNum", rand() % get_response_num(buf)); ReplaceVarsNum(challengeW, maxmsglen, _getCOptD(hContact, "ResponseNum", 0)); tmp = mir_u2a(challengeW); challenge = mir_utf8encode(tmp); mir_free(tmp); CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)challenge); mir_free(challenge); _notify(hContact, POPUP_CHALLENGE, TranslateT("Sending random challenge to %s."), message); break; case SPAMOTRON_MODE_MATH: a = (rand() % 10) + 1; b = (rand() % 10) + 1; mir_sntprintf(mexpr, sizeof(mexpr), _T("%d + %d"), a, b); if (dbei->eventType == EVENTTYPE_AUTHREQUEST) _getOptS(challengeW, maxmsglen, "AuthChallengeMath", defaultAuthChallengeMath); else _getOptS(challengeW, maxmsglen, "ChallengeMath", defaultChallengeMath); ReplaceVar(challengeW, maxmsglen, _T("%mathexpr%"), mexpr); _setCOptD(hContact, "ResponseMath", a + b); tmp = mir_u2a(challengeW); challenge = mir_utf8encode(tmp); mir_free(tmp); CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)challenge); mir_free(challenge); _notify(hContact, POPUP_CHALLENGE, TranslateT("Sending math expression challenge to %s."), message); break; } free(challengeW); free(tmpW); // As a workaround for temporary NotOnList contact not being deleted from server-side list // (which was added by the ICQ server itself upon first outgoing challenge request message) // we need to set Delete setting, so that contacts gets deleted on next restart/connect. db_set_b(hContact, "CList", "Delete", 1); // Queue user message in Bayes db if (bayesEnabled && message != NULL) queue_message(hContact, dbei->timestamp, message); /*** Do any post-send procedures we need to do ***/ // Increment MsgSent if it was sent the same day. Otherwise set it to 1. if (isOneDay(dbei->timestamp, _getCOptD(hContact, "MsgSentTime",0))) _setCOptD(hContact, "MsgSent", _getCOptD(hContact, "MsgSent", 0)+1); else _setCOptD(hContact, "MsgSent", 1); _setCOptD(hContact, "MsgSentTime", dbei->timestamp); // Save Last Msg and update SameMsgCount if (message != NULL) { if (_tcscmp(_getCOptS(buf, buflen, hContact, "LastInMsg", _T("")), message) == 0) _setCOptD(hContact, "SameMsgCount", 1+_getCOptD(hContact, "SameMsgCount", 0)); else _setCOptD(hContact, "SameMsgCount", 1); _setCOptTS(hContact, "LastInMsg", message); } if (message != NULL) mir_free(message); // Finally silently save the message to contact history if corresponding option is set if (_getOptB("KeepBlockedMsg", defaultKeepBlockedMsg)) { if (dbei->eventType == EVENTTYPE_AUTHREQUEST) { // Save the request to database so that it can be automatically submitted on user approval PBYTE eventdata = (PBYTE)malloc(sizeof(DWORD) + dbei->cbBlob); if (eventdata != NULL && dbei->cbBlob > 0) { memcpy(eventdata, &dbei->cbBlob, sizeof(DWORD)); memcpy(eventdata + sizeof(DWORD), dbei->pBlob, dbei->cbBlob); db_set_blob(hContact, PLUGIN_NAME, "AuthEvent", eventdata, sizeof(DWORD) + dbei->cbBlob); _setCOptS(hContact, "AuthEventModule", dbei->szModule); _setCOptB(hContact, "AuthEventPending", TRUE); free(eventdata); } } else { if (_getOptB("MarkMsgUnreadOnApproval", defaultMarkMsgUnreadOnApproval)) { DBVARIANT _dbv; DWORD dbei_size = 3*sizeof(DWORD) + sizeof(WORD) + dbei->cbBlob + (DWORD)strlen(dbei->szModule)+1; PBYTE eventdata = (PBYTE)malloc(dbei_size); PBYTE pos = eventdata; if (eventdata != NULL && dbei->cbBlob > 0) { if (db_get(hContact, PLUGIN_NAME, "LastMsgEvents", &_dbv) == 0) { eventdata = (PBYTE)realloc(eventdata, dbei_size + _dbv.cpbVal); pos = eventdata; memcpy(eventdata, _dbv.pbVal, _dbv.cpbVal); pos += _dbv.cpbVal; db_free(&_dbv); } memcpy(pos, &dbei->eventType, sizeof(WORD)); memcpy(pos+sizeof(WORD), &dbei->flags, sizeof(DWORD)); memcpy(pos+sizeof(WORD)+sizeof(DWORD), &dbei->timestamp, sizeof(DWORD)); memcpy(pos+sizeof(WORD)+sizeof(DWORD)*2, dbei->szModule, strlen(dbei->szModule)+1); memcpy(pos+sizeof(WORD)+sizeof(DWORD)*2+strlen(dbei->szModule)+1, &dbei->cbBlob, sizeof(DWORD)); memcpy(pos+sizeof(WORD)+sizeof(DWORD)*3+strlen(dbei->szModule)+1, dbei->pBlob, dbei->cbBlob); db_set_blob(hContact, PLUGIN_NAME, "LastMsgEvents", eventdata, (pos - eventdata) + dbei_size); free(eventdata); } } else { dbei->flags |= DBEF_READ; db_event_add(hContact, dbei); } } } return 1; }
void LogToMessageWindow(XSTATUSCHANGE *xsc, BOOL opening) { // cut message if needed if (opt.LTruncateMsg && (opt.LMsgLen > 0) && xsc->stzText && (_tcslen(xsc->stzText) > opt.LMsgLen)) { TCHAR buff[MAX_TEXT_LEN + 3]; _tcsncpy(buff, xsc->stzText, opt.LMsgLen); buff[opt.LMsgLen] = 0; _tcscat(buff, _T("...")); mir_free(xsc->stzText); xsc->stzText = mir_tstrdup(buff); } TCHAR *Template; switch (xsc->action) { case NOTIFY_NEW_XSTATUS: Template = templates.LogNewXstatus; break; case NOTIFY_NEW_MESSAGE: Template = templates.LogNewMsg; break; case NOTIFY_REMOVE: Template = templates.LogRemove; break; case NOTIFY_OPENING_ML: Template = templates.LogOpening; break; } TCHAR stzLogText[2*MAX_TEXT_LEN]; TCHAR stzLastLog[2*MAX_TEXT_LEN]; ReplaceVars(xsc, Template, templates.LogDelimiter, stzLogText); DBGetStringDefault(xsc->hContact, MODULE, DB_LASTLOG, stzLastLog, SIZEOF(stzLastLog), _T("")); if (!opt.KeepInHistory || !(opt.PreventIdentical && _tcscmp(stzLastLog, stzLogText) == 0)) { DBWriteContactSettingTString(xsc->hContact, MODULE, DB_LASTLOG, stzLogText); char *blob; #ifdef _UNICODE blob = mir_utf8encodeT(stzLogText); #else blob = mir_strdup(stzLogText); #endif DBEVENTINFO dbei = {0}; dbei.cbSize = sizeof(dbei); dbei.cbBlob = (DWORD)strlen(blob) + 1; dbei.pBlob = (PBYTE) blob; dbei.eventType = EVENTTYPE_STATUSCHANGE; dbei.flags = DBEF_READ; #ifdef _UNICODE dbei.flags |= DBEF_UTF; #endif dbei.timestamp = (DWORD)time(NULL); dbei.szModule = xsc->szProto; HANDLE hDBEvent = (HANDLE)CallService(MS_DB_EVENT_ADD, (WPARAM)xsc->hContact, (LPARAM)&dbei); mir_free(blob); if (!opt.KeepInHistory) { DBEVENT *dbevent = (DBEVENT *)mir_alloc(sizeof(DBEVENT)); dbevent->hContact = xsc->hContact; dbevent->hDBEvent = hDBEvent; li.List_Insert(eventList, dbevent, eventList->realCount); } } }
void ShowPopup(XSTATUSCHANGE *xsc) { DBVARIANT dbv; char szSetting[64]; POPUPDATAT ppd = {0}; ppd.lchContact = xsc->hContact; switch(xsc->type) { case TYPE_JABBER_MOOD: case TYPE_JABBER_ACTIVITY: { mir_snprintf(szSetting, SIZEOF(szSetting), "%s/%s/%s", xsc->szProto, (xsc->type == TYPE_JABBER_MOOD) ? "mood" : "activity", "icon"); if (!DBGetContactSettingString(xsc->hContact, "AdvStatus", szSetting, &dbv)) { ppd.lchIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)dbv.pszVal); DBFreeVariant(&dbv); } break; } case TYPE_ICQ_XSTATUS: { int statusId = DBGetContactSettingByte(xsc->hContact, xsc->szProto, "XStatusId", 0); ppd.lchIcon = (HICON)CallProtoService(xsc->szProto, PS_ICQ_GETCUSTOMSTATUSICON, statusId, LR_SHARED); } } if (ppd.lchIcon == NULL) ppd.lchIcon = LoadSkinnedProtoIcon(xsc->szProto, DBGetContactSettingWord(xsc->hContact, xsc->szProto, "Status", ID_STATUS_ONLINE)); switch (opt.Colors) { case POPUP_COLOR_OWN: ppd.colorBack = DBGetContactSettingDword(0, MODULE, "40081bg", COLOR_BG_AVAILDEFAULT); ppd.colorText = DBGetContactSettingDword(0, MODULE, "40081tx", COLOR_TX_DEFAULT); break; case POPUP_COLOR_WINDOWS: ppd.colorBack = GetSysColor(COLOR_BTNFACE); ppd.colorText = GetSysColor(COLOR_WINDOWTEXT); break; case POPUP_COLOR_POPUP: ppd.colorBack = ppd.colorText = 0; break; } _tcscpy(ppd.lptzContactName, (TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)xsc->hContact, GSMDF_TCHAR)); if (opt.ShowGroup) //add group name to popup title { if (!DBGetContactSettingTString(xsc->hContact, "CList", "Group", &dbv)) { _tcscat(ppd.lptzContactName, _T(" (")); _tcscat(ppd.lptzContactName, dbv.ptszVal); _tcscat(ppd.lptzContactName, _T(")")); DBFreeVariant(&dbv); } } // cut message if needed if (opt.PTruncateMsg && (opt.PMsgLen > 0) && xsc->stzText && (_tcslen(xsc->stzText) > opt.PMsgLen)) { TCHAR buff[MAX_TEXT_LEN + 3]; _tcsncpy(buff, xsc->stzText, opt.PMsgLen); buff[opt.PMsgLen] = 0; _tcscat(buff, _T("...")); mir_free(xsc->stzText); xsc->stzText = mir_tstrdup(buff); } TCHAR *Template; switch (xsc->action) { case NOTIFY_NEW_XSTATUS: Template = templates.PopupNewXstatus; break; case NOTIFY_NEW_MESSAGE: Template = templates.PopupNewMsg; break; case NOTIFY_REMOVE: Template = templates.PopupRemove; break; } TCHAR stzPopupText[2*MAX_TEXT_LEN]; ReplaceVars(xsc, Template, templates.PopupDelimiter, stzPopupText); _tcsncpy(ppd.lptzText, stzPopupText, SIZEOF(ppd.lptzText)); ppd.lptzText[SIZEOF(ppd.lptzText) - 1] = 0; ppd.PluginWindowProc = (WNDPROC)PopupDlgProc; ppd.iSeconds = opt.PopupTimeout; PUAddPopUpT(&ppd); }
static bool UseDDE( bool uninstall ) /**********************************/ { WORD dir_index, icon_number, version; int i, num_icons, num_groups; int num_installed, num_total_install; int len; DWORD temp; bool ok; char prog_name[_MAX_PATH], prog_desc[_MAX_PATH]; char icon_name[_MAX_PATH], working_dir[_MAX_PATH]; char buff[_MAX_PATH], t1[_MAX_PATH], t2[_MAX_PATH]; HWND hwnd_pm; DWORD ddeinst = 0; // Important that this is initially 0 UINT rc; HSZ happ, htopic; HCONV hconv; char progman[] = "PROGMAN"; SimGetPMGroup( t1 ); if( t1[ 0 ] == '\0' ) { return( TRUE ); } // Initiate a conversation with the Program Manager. // NOTE: No callback provided since we only issue execute commands rc = DdeInitialize( &ddeinst, NULL, APPCMD_CLIENTONLY, 0L ); if( rc != 0 ) { return( FALSE ); } happ = DdeCreateStringHandle( ddeinst, progman, CP_WINANSI ); htopic = DdeCreateStringHandle( ddeinst, progman, CP_WINANSI ); hconv = DdeConnect( ddeinst, happ, htopic, NULL ); if( hconv == (HCONV)NULL ) { return( FALSE ); } // Disable the Program Manager so that the user can't work with it // while we are doing our stuff. hwnd_pm = FindWindow( progman, NULL ); if( hwnd_pm != NULL ) { ShowWindow( hwnd_pm, SW_RESTORE ); EnableWindow( hwnd_pm, FALSE ); } if( uninstall ) { // Delete the PM Group box num_groups = SimGetNumPMGroups(); for( i = 0; i < num_groups; i++ ) { SimGetPMGroupName( i, t1 ); if( *t1 != '\0' ) { // Delete the PM Group box sprintf( buff, "[DeleteGroup(%s)]", t1 ); ok = SendCommand( ddeinst, hconv, buff ); } } goto cleanup; // I can't believe I'm doing this } else { // Delete the PM Group box to get rid of stale icons // (Don't do this for SQL install, since user may install // the server, and then install the client) sprintf( buff, "[DeleteGroup(%s)]", t1 ); ok = SendCommand( ddeinst, hconv, buff ); // re-Create the PM Group box. SimGetPMGroupFileName( t2 ); if( t2[ 0 ] == '\0' ) { #if defined( __NT__ ) sprintf( buff, "[CreateGroup(%s,0)]", t1 ); // create a personal group #else sprintf( buff, "[CreateGroup(%s)]", t1 ); #endif } else { sprintf( buff, "[CreateGroup(%s,%s)]", t1, t2 ); } ok = SendCommand( ddeinst, hconv, buff ); } // Add the individual PM files to the Group box. num_icons = SimGetNumPMProgs(); StatusLines( STAT_CREATEPROGRAMFOLDER, "" ); num_total_install = 0; for( i = 0; i < num_icons; i++ ) { if( SimCheckPMCondition( i ) ) { ++num_total_install; } } num_installed = 0; StatusAmount( 0, num_total_install ); for( i = 0; ok && ( i < num_icons ); i++ ) { if( !SimCheckPMCondition( i ) ) { continue; } SimGetPMDesc( i, prog_desc ); dir_index = SimGetPMProgName( i, prog_name ); if( strcmp( prog_name, "GROUP" ) == 0 ) { // Delete the PM Group box to get rid of stale icons sprintf( buff, "[DeleteGroup(%s)]", prog_desc ); ok = SendCommand( ddeinst, hconv, buff ); /* creating a new group */ SimGetPMParms( i, t1 ); if( t1[ 0 ] == '\0' ) { #if defined( __NT__ ) sprintf( buff, "[CreateGroup(%s,0)]", prog_desc ); // create a personal group #else sprintf( buff, "[CreateGroup(%s)]", prog_desc ); #endif } else { sprintf( buff, "[CreateGroup(%s,%s)]", prog_desc, t1 ); } } else { /* adding item to group */ if( dir_index == SIM_INIT_ERROR ) { working_dir[0] = '\0'; ReplaceVars( t2, prog_name ); strcpy( prog_name, t2 ); } else { SimDirNoSlash( dir_index, working_dir ); } // get parameters SimGetPMParms( i, t1 ); if( t1[0] != '\0' ) { // add parameters to end of prog_name len = strlen( prog_name ); prog_name[len] = ' '; ReplaceVars( &prog_name[len + 1], t1 ); } // Append the subdir where the icon file is and the icon file's name. temp = SimGetPMIconInfo( i, icon_name ); dir_index = LOWORD( temp ); icon_number = HIWORD( temp ); if( icon_number == SIM_INIT_ERROR ) { icon_number = 0; } if( dir_index != SIM_INIT_ERROR ) { SimGetDir( dir_index, t1 ); strcat( t1, icon_name ); strcpy( icon_name, t1 ); } // Add the new file to the already created PM Group. version = (WORD)GetVersion(); if( (LOBYTE( version ) > 3) || // Version 3.1 or higher (LOBYTE( version ) == 3 && HIBYTE( version ) > 0) ) { sprintf( buff, "[ReplaceItem(%s)]", prog_desc ); SendCommand( ddeinst, hconv, buff ); sprintf( buff, "[AddItem(%s,%s,%s,%d,-1,-1,%s)]", prog_name, prog_desc, icon_name, icon_number, working_dir ); } else { sprintf( buff, "[AddItem(%s%s,%s,%s,%d)]", working_dir, prog_name, prog_desc, icon_name, icon_number ); } } ok = SendCommand( ddeinst, hconv, buff ); ++num_installed; StatusAmount( num_installed, num_total_install ); if( StatusCancelled() ) break; } StatusAmount( num_total_install, num_total_install ); cleanup: // Terminate the DDE conversation with the Program Manager. DdeFreeStringHandle( ddeinst, happ ); DdeFreeStringHandle( ddeinst, htopic ); // DdeDisconnect( hconv ); // win95 setup was crashing on ddeuninitialize //(only if running from CD)removing this call seems to be an OK workaround DdeUninitialize( ddeinst ); if( hwnd_pm != NULL ) { EnableWindow( hwnd_pm, TRUE ); } return( ok ); }
static bool UseIShellLink( bool uninstall ) /*****************************************/ { WORD dir_index, icon_number; int i, num_icons, num_groups; int num_installed, num_total_install; DWORD temp; char prog_name[_MAX_PATH], prog_desc[_MAX_PATH]; char icon_name[_MAX_PATH], working_dir[_MAX_PATH]; char group[_MAX_PATH], prog_arg[_MAX_PATH], tmp[_MAX_PATH]; BOOL rc; if( uninstall ) { num_groups = SimGetNumPMGroups(); for( i = 0; i < num_groups; i++ ) { SimGetPMGroupName( i, group ); if( *group != '\0' ) { // Delete the PM Group box remove_group( group ); } } return( TRUE ); } SimGetPMGroup( group ); if( group[0] == '\0' ) { return( TRUE ); } CoInitialize( NULL ); // Create the PM Group box. if( !create_group( group ) ) { CoUninitialize(); return( FALSE ); } // Add the individual PM files to the Group box. num_icons = SimGetNumPMProgs(); StatusLines( STAT_CREATEPROGRAMFOLDER, "" ); num_total_install = 0; for( i = 0; i < num_icons; i++ ) { if( SimCheckPMCondition( i ) ) { ++num_total_install; } } num_installed = 0; StatusAmount( 0, num_total_install ); for( i = 0; i < num_icons; i++ ) { if( !SimCheckPMCondition( i ) ) { continue; } SimGetPMDesc( i, prog_desc ); dir_index = SimGetPMProgName( i, prog_name ); if( strcmp( prog_name, "GROUP" ) == 0 ) { /* creating a new group */ strcpy( group, prog_desc ); if( !create_group( group ) ) { CoUninitialize(); return( FALSE ); } } else { // Adding item to group if( dir_index == SIM_INIT_ERROR ) { working_dir[ 0 ] = '\0'; ReplaceVars( tmp, prog_name ); strcpy( prog_name, tmp ); } else { SimDirNoSlash( dir_index, working_dir ); } // Get parameters SimGetPMParms( i, tmp ); ReplaceVars( prog_arg, tmp ); // Append the subdir where the icon file is and the icon file's name. temp = SimGetPMIconInfo( i, icon_name ); dir_index = LOWORD( temp ); icon_number = HIWORD( temp ); if( icon_number == SIM_INIT_ERROR ) icon_number = 0; if( dir_index != SIM_INIT_ERROR ) { SimGetDir( dir_index, tmp ); strcat( tmp, icon_name ); strcpy( icon_name, tmp ); } // Add the new file to the already created PM Group. rc = create_icon( group, prog_name, prog_desc, prog_arg, working_dir, icon_name, icon_number ); if( rc == FALSE ) { CoUninitialize(); return( FALSE ); } } ++num_installed; StatusAmount( num_installed, num_total_install ); if( StatusCancelled() ) break; } StatusAmount( num_total_install, num_total_install ); CoUninitialize(); return( TRUE ); }