/* * DownloadCheckDirs: Make sure that directories needed for downloading exist. * hParent is parent for error dialog. * Return True iff they all exist. */ Bool DownloadCheckDirs(HWND hParent) { // Make sure that necessary subdirectories exist if (MakeDirectory(download_dir) == False) { ClientError(hInst, hMain, IDS_CANTMAKEDIR, download_dir, GetLastErrorStr()); return False; } if (MakeDirectory(resource_dir) == False) { ClientError(hInst, hMain, IDS_CANTMAKEDIR, resource_dir, GetLastErrorStr()); return False; } if (MakeDirectory(help_dir) == False) { ClientError(hInst, hMain, IDS_CANTMAKEDIR, help_dir, GetLastErrorStr()); return False; } if (MakeDirectory(mail_dir) == False) { ClientError(hInst, hMain, IDS_CANTMAKEDIR, mail_dir, GetLastErrorStr()); return False; } if (MakeDirectory(ad_dir) == False) { ClientError(hInst, hMain, IDS_CANTMAKEDIR, ad_dir, GetLastErrorStr()); return False; } return True; }
void MainReadSocket(HWND hwnd, int SelectType, SOCKET s, int error) { switch (SelectType) { case FD_CONNECT: if (state != STATE_CONNECTING) { debug(("MainReadSocket got connect in wrong state (%d)\n", state)); return; } ConnectingDone(error); break; case FD_CLOSE: // When guest server denies us during login, don't abort if (config.guest && (state == STATE_CONNECTING || state == STATE_LOGIN)) return; MainSetState(STATE_OFFLINE); /* Kill off dialogs, etc. */ connection = CON_NONE; ClientError(hInst, hMain, IDS_LOSTSERVER); return; case FD_READ: /* Read stuff from server */ ReadServer(); MainProcessBuffer(); break; default: ClientError(hInst, hMain, IDS_SOCKETMESSAGE); break; } }
/* * DownloadNewClient: Spawn external program to get new client executable. * Arguments are passed as command line paramenters to external program. */ void DownloadNewClient(char *hostname, char *filename) { SHELLEXECUTEINFO shExecInfo; char command_line[MAX_CMDLINE]; char exe_name[MAX_PATH]; char client_directory[MAX_PATH]; char update_program_path[MAX_PATH]; char *ptr; SystemInfo sysinfo; if (AreYouSure(hInst, hMain, YES_BUTTON, IDS_NEEDNEWVERSION)) { // Make download dir if not already there DownloadCheckDirs(hMain); // Destination directory is wherever client executable is running. // Because of UAC, this is likely not the current working directory. GetModuleFileName(NULL, exe_name, MAX_PATH); strcpy(client_directory, exe_name); ptr = strrchr(client_directory, '\\'); if (ptr != NULL) *ptr = 0; sprintf(update_program_path, "%s\\%s", client_directory, update_program); sprintf(command_line, "\"%s\" UPDATE \"%s\" \"%s\" \"%s\\%s\" \"%s\"", exe_name, hostname, filename, download_dir, update_filename, client_directory); // Using full pathname of client can overrun 128 character DOS command line limit GetSystemStats(&sysinfo); if (strlen(command_line) >= 127 && (sysinfo.platform == VER_PLATFORM_WIN32_WINDOWS)) { ClientError(hInst, hMain, IDS_LONGCMDLINE, command_line); } shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); shExecInfo.fMask = 0; shExecInfo.hwnd = NULL; shExecInfo.lpVerb = "runas"; shExecInfo.lpFile = update_program_path; shExecInfo.lpParameters = command_line; // Run in parent of resource directory; club will take care of copying // exes to Program Files if necessary. shExecInfo.lpDirectory = NULL; shExecInfo.nShow = SW_NORMAL; shExecInfo.hInstApp = NULL; if (!ShellExecuteEx(&shExecInfo)) ClientError(hInst, hMain, IDS_CANTUPDATE, update_program); } // Quit client PostMessage(hMain, WM_DESTROY, 0, 0); }
void LoginError(int err_string) { HWND hParent = GetMessageBoxParent(); ClientError(hInst, hParent, err_string); config.quickstart = FALSE; LoginReset(); }
/* * RscAddCallback: Called for each new resource that's loaded from a file. * Add given resource to table. */ bool RscAddCallback(char *fname, int res, char *string) { resource_type entry, r; entry = (resource_type) SafeMalloc(sizeof(resource_struct)); entry->idnum = res; entry->data = (char *) SafeMalloc(strlen(string) + 1); strcpy(entry->data, string); if (table_insert(t, entry, ResourceHash, ResourceCompare) != 0) { if (!ignore_duplicates) { ClientError(hInst, hMain, IDS_DUPRESOURCE, res, fname); FreeRsc(entry); } else { // Free existing resource r = (resource_type) table_lookup(t, &res, IdHash, IdResourceCompare); if (r != NULL) { table_delete_item(t, r, ResourceHash, ResourceCompare); FreeRsc(r); table_insert(t, entry, ResourceHash, ResourceCompare); } } } return true; }
/* * DeleteRscFiles: Delete given list of resource files */ void DeleteRscFiles(list_type files) { list_type l; char filename[MAX_PATH + FILENAME_MAX], game_path[MAX_PATH]; char *fname; struct stat s; GetGamePath( game_path ); for (l = files; l != NULL; l = l->next) { fname = (char *) l->data; sprintf(filename, "%s%s\\%.*s", game_path, resource_dir, FILENAME_MAX, fname); /* If file doesn't exist, we're ok */ if (stat(filename, &s) != 0) { debug(("Couldn't find file %s to delete\n", filename)); continue; } if (unlink(filename) != 0) ClientError(hInst, hMain, IDS_CANTDELETE, filename); } }
/* * DeleteAllRscFiles: Delete all resource files in resource directory. * Also resets last download time to 0. */ void DeleteAllRscFiles(void) { HANDLE hFindFile; WIN32_FIND_DATA file_info; char path[MAX_PATH + FILENAME_MAX], game_path[MAX_PATH]; GetGamePath( game_path ); // Reset last download time to never DownloadSetTime(0); debug(("Deleting all resource files\n")); sprintf(path, "%s%s\\*.*", game_path, resource_dir); hFindFile = FindFirstFile(path, &file_info); if (hFindFile == INVALID_HANDLE_VALUE) return; for(;;) { // Skip directories if (!(file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { sprintf(path, "%s%s\\%s", game_path, resource_dir, file_info.cFileName); if (unlink(path) != 0) ClientError(hInst, hMain, IDS_CANTDELETE, path); } if (FindNextFile(hFindFile, &file_info) == FALSE) break; } FindClose(hFindFile); }
/* * DownloadUnarchiveFile: Unarchive archive zip_name to given * directory. Return True on success. */ Bool DownloadUnarchiveFile(char *zip_name, char *dir) { Bool retval = True; // Does file exist? struct stat s; if (stat(zip_name, &s) != 0) { ClientError(hInst, hDownloadDialog, IDS_MISSINGARCHIVE, zip_name); return False; } while (1) { extraction_error = 0; TransferMessage(GetString(hInst, IDS_DECOMPRESSING)); ExtractArchive(zip_name, dir); if (extraction_error == 0) // This means the user hit the abort button break; if (!AreYouSure(hInst, hDownloadDialog, YES_BUTTON, IDS_CANTUNCOMPRESS, zip_name, GetString(hInst, extraction_error))) { retval = False; break; } } return retval; }
omero::cmd::StatusPtr CmdCallbackI::getStatusOrThrow() { IceUtil::RecMutex::Lock lock(mutex); omero::cmd::StatusPtr s = state.second; if (!s) { throw ClientError(__FILE__, __LINE__, "Status not present!"); } return s; };
/* * DownloadUncrushFile: Unarchive Crusher archive zip_name to given directory. * Return True on success. */ Bool DownloadUncrushFile(char *zip_name, char *dir) { Bool retval = True; // Does file exist? struct stat s; if (stat(zip_name, &s) != 0) { ClientError(hInst, hDownloadDialog, IDS_MISSINGARCHIVE, zip_name); return False; } if (!WrapIsArchive(zip_name)) { ClientError(hInst, hDownloadDialog, IDS_BADARCHIVE2, zip_name); return False; } WrapSetExtractionCallback(DownloadProgressCallback); while (1) { char temp_path[MAX_PATH]; extraction_error = 0; TransferMessage(GetString(hInst, IDS_DECOMPRESSING)); GetTempPath(sizeof(temp_path), temp_path); WrapExtractArchive(zip_name, dir, temp_path); if (extraction_error == 0) break; if (!AreYouSure(hInst, hDownloadDialog, YES_BUTTON, IDS_CANTUNCOMPRESS, zip_name, GetString(hInst, extraction_error))) { retval = False; break; } } WrapSetExtractionCallback(NULL); return retval; }
void AnimationTimerStart(void) { // See if already started if (animation_timer != 0) return; animation_timer = SetTimer(hMain, TIMER_ANIMATE, ANIMATE_INTERVAL, NULL); if (animation_timer == 0) ClientError(hInst, hMain, IDS_NOTIMERS); }
/* * MailSendReply: Bring up send mail dialog, and initialize it with info * in given structure. Only works if send mail dialog isn't already up. * hParent is window from which request originated; used as parent for errors. */ void MailSendReply(HWND hParent, MailInfo *reply) { int i; if (hSendMailDlg != NULL) { ClientError(hInst, hParent, IDS_MAILONEDIALOG); return; } // Can't reply to people with commas in their name (i.e. messages from the game) for (i=0; i < reply->num_recipients; i++) if (strchr(reply->recipients[i], ',') != NULL) { ClientError(hInst, hParent, IDS_CANTREPLY); return; } CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAILSEND), NULL, SendMailDialogProc, (LPARAM) reply); }
/* * MailRecipientsReceived: Server has translated recipient names into given object * numbers (in the same order). Now send the mail message. */ void MailRecipientsReceived(WORD num_objects, ID *objs) { int i, len, chars; HWND hEdit; char buf[MAXMAIL + MAX_SUBJECT + 20]; Bool names_legal; if (hSendMailDlg == NULL || info == NULL) return; if (num_objects != info->num_recipients) { debug(("Mismatch in # of recipients (got %d, expected %d)\n", num_objects, info->num_recipients)); SafeFree(info); return; } // Verify that object numbers are legal names_legal = True; for (i=0; i < num_objects; i++) if (objs[i] == 0) { ClientError(hInst, hSendMailDlg, IDS_BADNAME, info->recipients[i]); SetDlgItemText(hSendMailDlg, IDC_SENDMAILMSG, ""); names_legal = False; break; } if (names_legal) { /* Get subject and text, and send the message */ chars = sprintf(buf, "%s", GetString(hInst, IDS_SUBJECT)); len = GetDlgItemText(hSendMailDlg, IDC_SUBJECT, buf + chars, MAX_SUBJECT); buf[chars + len] = '\n'; chars += len + 1; hEdit = GetDlgItem(hSendMailDlg, IDC_MAILEDIT); len = Edit_GetTextLength(hEdit); Edit_GetText(hEdit, buf + chars, len + 1); SendMail(num_objects, objs, buf); SendMessage(hSendMailDlg, WM_CLOSE, 0, 0); } else EnableWindow(GetDlgItem(hSendMailDlg, IDC_OK), TRUE); SafeFree(info); info = NULL; }
void CALLBACK StartupTimerProc(HWND hwnd, UINT msg, UINT timer, DWORD dwTime) { /* See if we've timed out */ timeout += BEACON_INTERVAL; debug(("In timer proc\n")); if (timeout >= BEACON_TIMEOUT) { Logoff(); ClientError(hInst, hMain, IDS_CONNECTERROR); return; } /* Spew at server again */ WriteServer((char *) client_string1, INITSTR_LENGTH); }
/* * StartupInit: Send startup string, and wait for string from server. * final_state is the state we should end up in if the resynchronization succeeds. * This should be STATE_LOGIN if we are just connecting to the server or if we * try to resync in login mode, and STATE_GAME if we are trying to resync in game mode. */ void StartupInit(int final_state) { dest_state = final_state; pos = 0; timeout = 0; /* Set timer to keep writing initial string to server */ WriteServer((char *) client_string1, INITSTR_LENGTH); timer_id = SetTimer(NULL, 0, BEACON_INTERVAL, StartupTimerProc); if (timer_id == 0) { ClientError(hInst, hMain, IDS_NOTIMERS); return; } }
void NonBlockingSSL_Connect(SSL* ssl, SSL_CTX* ctx, SOCKET_T& sockfd) { int ret = SSL_connect(ssl); while (ret =! SSL_SUCCESS && (SSL_get_error(ssl, 0) == SSL_ERROR_WANT_READ)) { printf("... client would block\n"); #ifdef _WIN32 Sleep(1000); #else sleep(1); #endif ret = SSL_connect(ssl); } if (ret != SSL_SUCCESS) ClientError(ctx, ssl, sockfd, "SSL_connect failed"); }
void Connection::checkErrors() const { mpd_error code = mpd_connection_get_error(m_connection.get()); if (code != MPD_ERROR_SUCCESS) { std::string msg = mpd_connection_get_error_message(m_connection.get()); if (code == MPD_ERROR_SERVER) { mpd_server_error server_code = mpd_connection_get_server_error(m_connection.get()); bool clearable = mpd_connection_clear_error(m_connection.get()); throw ServerError(server_code, msg, clearable); } else { bool clearable = mpd_connection_clear_error(m_connection.get()); throw ClientError(code, msg, clearable); } } }
void ConfigMenuLaunch(void) { STARTUPINFO si; PROCESS_INFORMATION pi; char command_line[MAX_CMDLINE]; sprintf(command_line, "%s", "m59bind.exe"); memset(&si, sizeof(si), 0); si.cb = sizeof(si); GetStartupInfo(&si); /* shouldn't need to do this. very weird */ if (!CreateProcess(NULL, command_line, NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)) { debug(("Failed running configuration menu program %s\n", command_line)); ClientError(hInst, hMain, IDS_NOCONFIGMENUEXE, config.browser); } }
/* * MailDeleteMessage: Delete the mail message with the given number. * Return True on success. */ Bool MailDeleteMessage(int number) { char filename[MAX_PATH + FILENAME_MAX]; int index; if ((index = MailFindIndex(number)) == -1) { debug(("Message number not found to delete\n")); return False; } ListBox_GetText(hMsgList, index, filename); if (unlink(filename) != 0) { ClientError(hInst, hReadMailDlg, IDS_CANTDELETEMAIL, filename); return False; } ListBox_DeleteString(hMsgList, index); return True; }
/* * DownloadNewClient: Open patcher from the default location if installed, * otherwise send user to OpenMeridian.org webpage to * download it. */ void DownloadNewClient(char *hostname, char *filename) { SHELLEXECUTEINFO shExecInfo; TCHAR szPath[MAX_PATH]; if (AreYouSure(hInst, hMain, YES_BUTTON, IDS_NEEDNEWVERSION)) { // No longer use club.exe to update the Meridian executable, instead // we run the patcher if installed, otherwise send the user to download it. if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAMS, NULL, 0, szPath))) strcat(szPath, TEXT(update_program)); shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); shExecInfo.fMask = 0; shExecInfo.hwnd = NULL; shExecInfo.lpVerb = TEXT("open"); shExecInfo.lpFile = TEXT(szPath); shExecInfo.lpParameters = NULL; shExecInfo.lpDirectory = NULL; shExecInfo.nShow = SW_SHOW; shExecInfo.hInstApp = NULL; if (!ShellExecuteEx(&shExecInfo)) { // Running patcher failed, send them to the webpage. If that fails, // throw an error (telling the user to contact us at the forums) and exit. shExecInfo.lpFile = TEXT(update_internet); if (!ShellExecuteEx(&shExecInfo)) ClientError(hInst, hMain, IDS_CANTUPDATE); } } // Quit client PostMessage(hMain, WM_DESTROY, 0, 0); }
/* * LoginDialogProc: Get login information. */ BOOL CALLBACK LoginDialogProc(HWND hDlg, UINT message, UINT wParam, LONG lParam) { static HWND hUser, hPasswd, hServer; /* Edit boxes in dialog */ static HWND hGroupBox, hTryPreviewButton; int value; BOOL success; switch (message) { case WM_INITDIALOG: CenterWindow(hDlg, GetParent(hDlg)); hUser = GetDlgItem(hDlg, IDC_USERNAME); hPasswd = GetDlgItem(hDlg, IDC_PASSWORD); hServer = GetDlgItem(hDlg, IDC_SERVERNUM); hGroupBox = GetDlgItem(hDlg, IDC_NEW_TO_MERIDIAN_59); Edit_LimitText(hUser, MAXUSERNAME); Edit_LimitText(hPasswd, MAXPASSWORD); Edit_LimitText(hServer, MAXSERVERNUM); SetWindowFont(hUser, GetFont(FONT_INPUT), FALSE); SetWindowFont(hPasswd, GetFont(FONT_INPUT), FALSE); SetWindowFont(hServer, GetFont(FONT_INPUT), FALSE); // Set server number, if it's valid if (config.comm.server_num != -1) { SetDlgItemInt(hDlg, IDC_SERVERNUM, config.comm.server_num, FALSE); // If already logged in, can't change server number if (connection != CON_NONE) EnableWindow(hServer, FALSE); } /* If we have a default name, go to password edit box */ Edit_SetText(hUser, config.username); Edit_SetSel(hUser, 0, -1); if (config.guest) { RECT rc; int bottom; Edit_SetText(hUser, "GUEST"); Edit_SetText(hPasswd, "GUEST"); EnableWindow(hUser, FALSE); EnableWindow(hPasswd, FALSE); EnableWindow(hServer, FALSE); EnableWindow(GetDlgItem(hDlg,IDC_OK), FALSE); GetWindowRect(hGroupBox, &rc); bottom = rc.bottom + 5; GetWindowRect(hDlg, &rc); MoveWindow(hDlg, rc.left, rc.top, rc.right - rc.left, bottom - rc.top, TRUE); } else if (strlen(config.username) > 0) { Edit_SetText(hPasswd, config.password); Edit_SetSel(hPasswd, 0, -1); SetFocus(hPasswd); return 0; /* We have already set focus */ } return 1; /* Set focus to default window */ case BK_DIALOGDONE: EndDialog(hDlg, IDOK); return TRUE; case WM_COMMAND: switch(GET_WM_COMMAND_ID(wParam, lParam)) { case IDC_GUEST: strcpy(config.username, "GUEST"); strcpy(config.password, "GUEST"); ConfigSetServerNameByNumber(config.server_guest); ConfigSetSocketPortByNumber(config.server_guest); config.comm.server_num = config.server_guest; EndDialog(hDlg, IDOK); return TRUE; case IDC_HOMEPAGE: { char url[256]; LoadString(hInst,IDS_HOMEPAGEURL,url,sizeof(url)); if (*url) { WebLaunchBrowser(url); EndDialog(hDlg, IDCANCEL); PostMessage(hMain,WM_SYSCOMMAND,SC_CLOSE,0); } } return TRUE; case IDOK: /* User has pressed return on one of the edit boxes */ if (GetFocus() == hUser) { SetFocus(hPasswd); return True; } if (GetFocus() == hPasswd) { // Go to server edit box if it's empty value = GetDlgItemInt(hDlg, IDC_SERVERNUM, &success, FALSE); if (success) PostMessage(hDlg, WM_COMMAND, IDC_OK, 0); else SetFocus(hServer); return True; } if (GetFocus() == hServer) PostMessage(hDlg, WM_COMMAND, IDC_OK, 0); return TRUE; case IDC_OK: /* Get username & password */ Edit_GetText(hUser, config.username, MAXUSERNAME + 1); Edit_GetText(hPasswd, config.password, MAXPASSWORD + 1); value = GetDlgItemInt(hDlg, IDC_SERVERNUM, &success, FALSE); if (!success) { // If logging in as "guest", no server number required if (!stricmp(config.username, GetString(hInst, IDS_GUEST))) value = config.server_guest; else { ClientError(hInst, hDlg, IDS_NOSERVERNUM); return TRUE; } } // If value changed, set server name and socketport if (value != config.comm.server_num) { ConfigSetServerNameByNumber(value); ConfigSetSocketPortByNumber(value); config.comm.server_num = value; } /* Kill off dialog */ EndDialog(hDlg, IDOK); return TRUE; case IDC_HANGUP: case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; } break; } return FALSE; }
BOOL CALLBACK PasswordDialogProc(HWND hDlg, UINT message, UINT wParam, LONG lParam) { static HWND hOldPasswd, hNewPasswd1, hNewPasswd2; char oldpasswd[MAXPASSWORD + 1], newpasswd1[MAXPASSWORD + 1], newpasswd2[MAXPASSWORD + 1]; char buf1[ENCRYPT_LEN + 1], buf2[ENCRYPT_LEN + 1]; switch (message) { case WM_INITDIALOG: if (hPasswdDialog) { DestroyWindow(hDlg); return TRUE; } CenterWindow(hDlg, GetParent(hDlg)); hOldPasswd = GetDlgItem(hDlg, IDC_OLDPASSWD); hNewPasswd1 = GetDlgItem(hDlg, IDC_NEWPASSWD1); hNewPasswd2 = GetDlgItem(hDlg, IDC_NEWPASSWD2); Edit_LimitText(hOldPasswd, MAXPASSWORD); Edit_LimitText(hNewPasswd1, MAXPASSWORD); Edit_LimitText(hNewPasswd2, MAXPASSWORD); SetWindowFont(hOldPasswd, GetFont(FONT_INPUT), FALSE); SetWindowFont(hNewPasswd1, GetFont(FONT_INPUT), FALSE); SetWindowFont(hNewPasswd2, GetFont(FONT_INPUT), FALSE); hPasswdDialog = hDlg; return TRUE; case WM_COMMAND: switch(GET_WM_COMMAND_ID(wParam, lParam)) { case IDOK: /* User has pressed return on one of the edit boxes */ if (GetFocus() == hOldPasswd) { SetFocus(hNewPasswd1); return TRUE; } if (GetFocus() == hNewPasswd1) { SetFocus(hNewPasswd2); return TRUE; } if (GetFocus() == hNewPasswd2) PostMessage(hDlg, WM_COMMAND, IDC_OK, 0); return TRUE; case IDC_OK: /* Send results to server */ Edit_GetText(hOldPasswd, oldpasswd, MAXPASSWORD + 1); Edit_GetText(hNewPasswd1, newpasswd1, MAXPASSWORD + 1); Edit_GetText(hNewPasswd2, newpasswd2, MAXPASSWORD + 1); if (0 != strcmp(newpasswd1, newpasswd2)) { ClientError(hInst, hDlg, IDS_PASSWDMATCH); return TRUE; } if (strlen(newpasswd1) < MINPASSWORD) { ClientError(hInst, hDlg, IDS_PASSWDLENGTH, MINPASSWORD); return TRUE; } // Recall this was the last attempt to change a password. // It's just stopping the auto-nagging feature from popping // up a dialog box later. // // The config.password is checked elsewhere, such as by // modules that need confirmation for drastic features. // // To improve the security, we only update these if we *think* // they're right about the password. Not perfect, but we // never get word from the server that the password was right. // if (0 == strcmp(oldpasswd, config.password)) { config.lastPasswordChange = time(NULL); strcpy(config.password, newpasswd1); } // Encrypt old and new passwords for the server. // It's up to the server to check if we are allowed to change // the password, based on the correct old password. // MDString(oldpasswd, (unsigned char *) buf1); buf1[ENCRYPT_LEN] = 0; MDString(newpasswd1, (unsigned char *) buf2); buf2[ENCRYPT_LEN] = 0; RequestChangePassword(buf1, buf2); hPasswdDialog = NULL; EndDialog(hDlg, IDOK); return TRUE; case IDCANCEL: hPasswdDialog = NULL; EndDialog(hDlg, IDCANCEL); return TRUE; } break; } return FALSE; }
void CoreClient::handleSessionFinished(boost::shared_ptr<Error> error) { if (options.forgetPassword) { purgePassword(); } resetSession(); boost::optional<ClientError> actualError; if (error) { ClientError clientError; if (boost::shared_ptr<ClientSession::Error> actualError = boost::dynamic_pointer_cast<ClientSession::Error>(error)) { switch(actualError->type) { case ClientSession::Error::AuthenticationFailedError: clientError = ClientError(ClientError::AuthenticationFailedError); break; case ClientSession::Error::CompressionFailedError: clientError = ClientError(ClientError::CompressionFailedError); break; case ClientSession::Error::ServerVerificationFailedError: clientError = ClientError(ClientError::ServerVerificationFailedError); break; case ClientSession::Error::NoSupportedAuthMechanismsError: clientError = ClientError(ClientError::NoSupportedAuthMechanismsError); break; case ClientSession::Error::UnexpectedElementError: clientError = ClientError(ClientError::UnexpectedElementError); break; case ClientSession::Error::ResourceBindError: clientError = ClientError(ClientError::ResourceBindError); break; case ClientSession::Error::SessionStartError: clientError = ClientError(ClientError::SessionStartError); break; case ClientSession::Error::TLSError: clientError = ClientError(ClientError::TLSError); break; case ClientSession::Error::TLSClientCertificateError: clientError = ClientError(ClientError::ClientCertificateError); break; case ClientSession::Error::StreamError: clientError = ClientError(ClientError::StreamError); break; } } else if (boost::shared_ptr<TLSError> actualError = boost::dynamic_pointer_cast<TLSError>(error)) { switch(actualError->getType()) { case TLSError::CertificateCardRemoved: clientError = ClientError(ClientError::CertificateCardRemoved); break; default: clientError = ClientError(ClientError::TLSError); break; } } else if (boost::shared_ptr<SessionStream::SessionStreamError> actualError = boost::dynamic_pointer_cast<SessionStream::SessionStreamError>(error)) { switch(actualError->type) { case SessionStream::SessionStreamError::ParseError: clientError = ClientError(ClientError::XMLError); break; case SessionStream::SessionStreamError::TLSError: clientError = ClientError(ClientError::TLSError); break; case SessionStream::SessionStreamError::InvalidTLSCertificateError: clientError = ClientError(ClientError::ClientCertificateLoadError); break; case SessionStream::SessionStreamError::ConnectionReadError: clientError = ClientError(ClientError::ConnectionReadError); break; case SessionStream::SessionStreamError::ConnectionWriteError: clientError = ClientError(ClientError::ConnectionWriteError); break; } } else if (boost::shared_ptr<CertificateVerificationError> verificationError = boost::dynamic_pointer_cast<CertificateVerificationError>(error)) { switch(verificationError->getType()) { case CertificateVerificationError::UnknownError: clientError = ClientError(ClientError::UnknownCertificateError); break; case CertificateVerificationError::Expired: clientError = ClientError(ClientError::CertificateExpiredError); break; case CertificateVerificationError::NotYetValid: clientError = ClientError(ClientError::CertificateNotYetValidError); break; case CertificateVerificationError::SelfSigned: clientError = ClientError(ClientError::CertificateSelfSignedError); break; case CertificateVerificationError::Rejected: clientError = ClientError(ClientError::CertificateRejectedError); break; case CertificateVerificationError::Untrusted: clientError = ClientError(ClientError::CertificateUntrustedError); break; case CertificateVerificationError::InvalidPurpose: clientError = ClientError(ClientError::InvalidCertificatePurposeError); break; case CertificateVerificationError::PathLengthExceeded: clientError = ClientError(ClientError::CertificatePathLengthExceededError); break; case CertificateVerificationError::InvalidSignature: clientError = ClientError(ClientError::InvalidCertificateSignatureError); break; case CertificateVerificationError::InvalidCA: clientError = ClientError(ClientError::InvalidCAError); break; case CertificateVerificationError::InvalidServerIdentity: clientError = ClientError(ClientError::InvalidServerIdentityError); break; case CertificateVerificationError::Revoked: clientError = ClientError(ClientError::RevokedError); break; case CertificateVerificationError::RevocationCheckFailed: clientError = ClientError(ClientError::RevocationCheckFailedError); break; } } actualError = boost::optional<ClientError>(clientError); } onDisconnected(actualError); }
BOOL CALLBACK ReadMailDialogProc(HWND hDlg, UINT message, UINT wParam, LONG lParam) { static HWND hEdit, hList; static int mail_index; /* Number of currently displayed message, -1 if none */ MailHeader *header; int index, msg_num, count; char str[MAX_HEADERLINE], msg[MAXMAIL]; MINMAXINFO *lpmmi; LV_COLUMN lvcol; LV_ITEM lvitem; LV_HITTESTINFO lvhit; NM_LISTVIEW *nm; switch (message) { case WM_INITDIALOG: CenterWindow(hDlg, cinfo->hMain); hReadMailDlg = hDlg; hEdit = GetDlgItem(hDlg, IDC_MAILEDIT); hList = GetDlgItem(hDlg, IDC_MAILLIST); SendMessage(hDlg, BK_SETDLGFONTS, 0, 0); ListView_SetExtendedListViewStyleEx(hList, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT); /* Store dialog rectangle in case of resize */ GetWindowRect(hDlg, &dlg_rect); // Add column headings lvcol.mask = LVCF_TEXT | LVCF_WIDTH; lvcol.pszText = GetString(hInst, IDS_MHEADER1); lvcol.cx = 25; ListView_InsertColumn(hList, 0, &lvcol); lvcol.pszText = GetString(hInst, IDS_MHEADER2); lvcol.cx = 80; ListView_InsertColumn(hList, 1, &lvcol); lvcol.pszText = GetString(hInst, IDS_MHEADER3); lvcol.cx = 150; ListView_InsertColumn(hList, 2, &lvcol); lvcol.pszText = GetString(hInst, IDS_MHEADER4); lvcol.cx = 135; ListView_InsertColumn(hList, 3, &lvcol); mail_index = -1; SetFocus(hReadMailDlg); MailGetMessageList(); RequestReadMail(); return TRUE; case WM_SIZE: ResizeDialog(hDlg, &dlg_rect, mailread_controls); return TRUE; case WM_GETMINMAXINFO: lpmmi = (MINMAXINFO *) lParam; lpmmi->ptMinTrackSize.x = 200; lpmmi->ptMinTrackSize.y = 300; return 0; case WM_ACTIVATE: if (wParam == 0) *cinfo->hCurrentDlg = NULL; else *cinfo->hCurrentDlg = hDlg; return TRUE; case BK_SETDLGFONTS: SetWindowFont(hEdit, GetFont(FONT_MAIL), TRUE); SetWindowFont(hList, GetFont(FONT_MAIL), TRUE); return TRUE; case BK_SETDLGCOLORS: ListView_SetTextColor(hList, GetColor(COLOR_LISTFGD)); ListView_SetBkColor(hList, GetColor(COLOR_LISTBGD)); InvalidateRect(hDlg, NULL, TRUE); return TRUE; case EN_SETFOCUS: /* By default, whole message becomes selected for some reason */ Edit_SetSel(hEdit, -1, 0); break; case BK_NEWMAIL: /* wParam = message number, lParam = message header string */ msg_num = wParam; header = (MailHeader *) lParam; // Add message to list view sprintf(str, "%d", msg_num); lvitem.mask = LVIF_TEXT | LVIF_PARAM; lvitem.iItem = 0; lvitem.iSubItem = 0; lvitem.pszText = str; lvitem.lParam = msg_num; ListView_InsertItem(hList, &lvitem); // Add subitems lvitem.mask = LVIF_TEXT; lvitem.iSubItem = 1; lvitem.pszText = header->sender; ListView_SetItem(hList, &lvitem); lvitem.iSubItem = 2; lvitem.pszText = header->subject; ListView_SetItem(hList, &lvitem); lvitem.iSubItem = 3; lvitem.pszText = header->date; ListView_SetItem(hList, &lvitem); // Erase message in status area SetDlgItemText(hDlg, IDC_MAILINFO, ""); return TRUE; case BK_NONEWMAIL: SetDlgItemText(hDlg, IDC_MAILINFO, GetString(hInst, IDS_NONEWMAIL)); return TRUE; HANDLE_MSG(hDlg, WM_CTLCOLOREDIT, MailCtlColor); HANDLE_MSG(hDlg, WM_CTLCOLORLISTBOX, MailCtlColor); HANDLE_MSG(hDlg, WM_CTLCOLORSTATIC, MailCtlColor); HANDLE_MSG(hDlg, WM_CTLCOLORDLG, MailCtlColor); HANDLE_MSG(hDlg, WM_INITMENUPOPUP, InitMenuPopupHandler); case WM_CLOSE: SendMessage(hDlg, WM_COMMAND, IDCANCEL, 0); return TRUE; case WM_DESTROY: hReadMailDlg = NULL; if (exiting) PostMessage(cinfo->hMain, BK_MODULEUNLOAD, 0, MODULE_ID); return TRUE; case WM_NOTIFY: if (wParam != IDC_MAILLIST) return TRUE; nm = (NM_LISTVIEW *) lParam; switch (nm->hdr.code) { case NM_CLICK: // If you click on an item, select it--why doesn't control work this way by default? GetCursorPos(&lvhit.pt); ScreenToClient(hList, &lvhit.pt); lvhit.pt.x = 10; index = ListView_HitTest(hList, &lvhit); if (index == -1) break; ListView_SetItemState(hList, index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); break; case LVN_ITEMCHANGED: // New item selected; get its message number lvitem.mask = LVIF_STATE | LVIF_PARAM; lvitem.stateMask = LVIS_SELECTED; lvitem.iItem = nm->iItem; lvitem.iSubItem = 0; ListView_GetItem(hList, &lvitem); if (!(lvitem.state & LVIS_SELECTED)) break; msg_num = lvitem.lParam; if (msg_num == mail_index) break; if (MailLoadMessage(msg_num, MAXMAIL, msg) == False) { ClientError(hInst, hReadMailDlg, IDS_CANTLOADMSG); break; } mail_index = msg_num; Edit_SetText(hEdit, msg); break; } return TRUE; case WM_COMMAND: UserDidSomething(); switch(GET_WM_COMMAND_ID(wParam, lParam)) { case IDC_DELETEMSG: if (!ListViewGetCurrentData(hList, &index, &msg_num)) return TRUE; if (MailDeleteMessage(msg_num) == True) { /* Display new current message, if any */ Edit_SetText(hEdit, ""); ListView_DeleteItem(hList, index); count = ListView_GetItemCount(hList); if (count == 0) return TRUE; index = min(index, count - 1); // in case last message deleted ListView_SetItemState(hList, index, LVIS_SELECTED, LVIS_SELECTED); } return TRUE; case IDC_RESCAN: SetDlgItemText(hDlg, IDC_MAILINFO, GetString(hInst, IDS_GETTINGMSGS)); RequestReadMail(); return TRUE; case IDC_SEND: UserSendMail(); return TRUE; case IDC_REPLY: case IDC_REPLYALL: /* Find message number for currently selected message */ if (!ListViewGetCurrentData(hList, &index, &msg_num)) return TRUE; UserMailReply(msg_num, (Bool) (GET_WM_COMMAND_ID(wParam, lParam) == IDC_REPLYALL)); return TRUE; case IDCANCEL: /* Note: This code is also used by the WM_CLOSE message */ MailDeleteMessageList(); DestroyWindow(hDlg); return TRUE; } break; } return FALSE; }
void Connection::checkConnection() const { if (!m_connection) throw ClientError(MPD_ERROR_STATE, "No active MPD connection", false); }
/* * SendMailMessage: hDlg is filled in with mail message info; build up message * and ask server to validate recipient names. * Return True if message successfully sent. */ Bool SendMailMessage(HWND hDlg) { char line[MAX_LINE + 1], *ptr, *temp; int i, j, k; info = (MailInfo *) SafeMalloc(sizeof(MailInfo)); info->num_recipients = 0; // Read recipients GetDlgItemText(hDlg, IDC_RECIPIENTS, line, MAX_LINE); ptr = strtok(line, ","); while (ptr != NULL) { if (info->num_recipients >= MAX_RECIPIENTS) { if (!AreYouSure(hInst, hDlg, NO_BUTTON, IDS_TOOMANYRECIPIENTS, MAX_RECIPIENTS)) { SafeFree(info); info = NULL; return False; } break; } // Skip leading spaces while (*ptr == ' ') ptr++; // Skip trailing spaces temp = ptr + strlen(ptr) - 1; while (temp > ptr && *temp == ' ') temp--; *(temp + 1) = 0; strncpy(info->recipients[info->num_recipients], ptr, MAXUSERNAME); info->recipients[info->num_recipients][MAXUSERNAME - 1] = 0; info->num_recipients++; ptr = strtok(NULL, ","); } /* Must have >= 1 recipient */ if (info->num_recipients == 0) { ClientError(hInst, hDlg, IDS_NORECIPIENTS); return False; } // Remove duplicate recipients for (i = 0; i < info->num_recipients; i++) for (j = i + 1; j < info->num_recipients; j++) if (!stricmp(info->recipients[i], info->recipients[j])) { // Move everyone else up one slot for (k = j; k < info->num_recipients - 1; k++) strcpy(info->recipients[k], info->recipients[k + 1]); info->num_recipients--; j--; } // Translate names into object numbers line[0] = 0; for (i=0; i < info->num_recipients; i++) { if (i != 0) strcat(line, ","); strcat(line, info->recipients[i]); } RequestLookupNames(info->num_recipients, line); // Disable OK button, so that only one lookup happens at once EnableWindow(GetDlgItem(hDlg, IDC_OK), FALSE); SetDlgItemText(hDlg, IDC_SENDMAILMSG, GetString(hInst, IDS_CHECKNAMES)); return True; }
void client_test(void* args) { #ifdef _WIN32 WSADATA wsd; WSAStartup(0x0002, &wsd); #endif SOCKET_T sockfd = 0; int argc = 0; char** argv = 0; set_args(argc, argv, *static_cast<func_args*>(args)); tcp_connect(sockfd); #ifdef NON_BLOCKING tcp_set_nonblocking(sockfd); #endif SSL_METHOD* method = TLSv1_client_method(); SSL_CTX* ctx = SSL_CTX_new(method); set_certs(ctx); SSL* ssl = SSL_new(ctx); SSL_set_fd(ssl, sockfd); #ifdef NON_BLOCKING NonBlockingSSL_Connect(ssl, ctx, sockfd); #else // if you get an error here see note at top of README if (SSL_connect(ssl) != SSL_SUCCESS) ClientError(ctx, ssl, sockfd, "SSL_connect failed"); #endif showPeer(ssl); const char* cipher = 0; int index = 0; char list[1024]; strncpy(list, "cipherlist", 11); while ( (cipher = SSL_get_cipher_list(ssl, index++)) ) { strncat(list, ":", 2); strncat(list, cipher, strlen(cipher) + 1); } printf("%s\n", list); printf("Using Cipher Suite: %s\n", SSL_get_cipher(ssl)); char msg[] = "hello yassl!"; if (SSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) ClientError(ctx, ssl, sockfd, "SSL_write failed"); char reply[1024]; int input = SSL_read(ssl, reply, sizeof(reply)); if (input > 0) { reply[input] = 0; printf("Server response: %s\n", reply); } #ifdef TEST_RESUME SSL_SESSION* session = SSL_get_session(ssl); SSL* sslResume = SSL_new(ctx); #endif SSL_shutdown(ssl); SSL_free(ssl); tcp_close(sockfd); #ifdef TEST_RESUME tcp_connect(sockfd); SSL_set_fd(sslResume, sockfd); SSL_set_session(sslResume, session); if (SSL_connect(sslResume) != SSL_SUCCESS) ClientError(ctx, sslResume, sockfd, "SSL_resume failed"); showPeer(sslResume); if (SSL_write(sslResume, msg, sizeof(msg)) != sizeof(msg)) ClientError(ctx, sslResume, sockfd, "SSL_write failed"); input = SSL_read(sslResume, reply, sizeof(reply)); if (input > 0) { reply[input] = 0; printf("Server response: %s\n", reply); } SSL_shutdown(sslResume); SSL_free(sslResume); tcp_close(sockfd); #endif // TEST_RESUME SSL_CTX_free(ctx); ((func_args*)args)->return_code = 0; }
void LoginTimeout(void) { config.quickstart = FALSE; ClientError(hInst, hMain, IDS_TIMEOUT); }