void PostErrorMessage(const wxChar* t) { wxString text; text << t << wxT("\nVýpis: ") << wxSysErrorMsg(wxSysErrorCode()); wxMessageBox(text, wxT("Chyba!"), wxOK | wxICON_EXCLAMATION); //MessageBox(NULL, wxSysErrorMsg(wxSysErrorCode()), t, NULL); }
void gqbView::SaveAsImage(const wxString &fileName, wxBitmapType imgType) { updateModelSize(NULL, true); if (modelSize.GetWidth() == 0 || modelSize.GetHeight() == 0) { wxMessageBox(_("Nothing to be saved!"), _("Save As an image"), wxOK | wxICON_INFORMATION); return; } int width = 0, height = 0; GetVirtualSize(&width, &height); /* * Create the bitmap from the Explain window */ wxMemoryDC memDC; wxBitmap tempBitmap(width, height); memDC.SelectObject(tempBitmap); memDC.Clear(); // Draw the diagram on the bitmap (Memory Device Context) drawAll(memDC, false); memDC.SelectObject(wxNullBitmap); if (!tempBitmap.SaveFile(fileName, imgType)) { wxLogError(_("Could not write the file %s: Errcode=%d."), fileName.c_str(), wxSysErrorCode()); } }
void ExplainCanvas::SaveAsImage(const wxString &fileName, wxBitmapType imageType) { if (GetDiagram()->GetCount() == 0) { wxMessageBox(_("Nothing to be saved!"), _("Save As an image"), wxOK | wxICON_INFORMATION); return; } int width = 0, height = 0; GetVirtualSize(&width, &height); /* * Create the bitmap from the Explain window */ wxMemoryDC memDC; wxBitmap tempBitmap(width, height); memDC.SelectObject(tempBitmap); memDC.Clear(); // Draw the diagram on the bitmap (Memory Device Context) GetDiagram()->Redraw(memDC); memDC.SelectObject(wxNullBitmap); if (!tempBitmap.SaveFile(fileName, imageType)) { wxLogError(_("Could not write file \"%s\": error code %d."), fileName.c_str(), wxSysErrorCode()); } }
void *CSSHTunnelThread::Entry() { while (1) { int forwardsock = accept(m_listensock, (struct sockaddr *) & m_sin, &m_sinlen); if (-1 == forwardsock) { #ifdef WIN32 if(wxSysErrorCode() != WSAEINTR && wxSysErrorCode() != WSAEBADF) #else if(wxSysErrorCode() != EINTR && wxSysErrorCode() != EBADF && wxSysErrorCode() != ECONNABORTED) #endif { LogSSHTunnelErrors(wxString::Format(_("SSH error: accept failed with error code %d"), wxSysErrorCode()), GetId()); Cleanup(); } break; } // Create thread for read/write. CSubThread *subThread = new CSubThread(m_sin, m_remote_desthost, m_remote_destport, m_session, forwardsock); if ( subThread->Create() != wxTHREAD_NO_ERROR ) { delete subThread; subThread = NULL; } else { if (subThread->Run() != wxTHREAD_NO_ERROR ) { delete subThread; subThread = NULL; } else { g_SSHThreadMutex.Lock(); g_setSocketDescriptor.insert(forwardsock); g_SSHThreadMutex.Unlock(); } } } return NULL; }
bool CIOThread::DoWrite(const char* pBuffer, int len) { int fd = m_pFile->fd(); if (wxWrite(fd, pBuffer, len) == len) return true; int code = wxSysErrorCode(); const wxString error = wxSysErrorMsg(code); wxMutexLocker locker(m_mutex); delete [] m_error_description; m_error_description = new wxChar[error.Len() + 1]; wxStrcpy(m_error_description, error); return false; }
DWORD UncompressNSave(LPCTSTR szFileName, BYTE* compr, size_t comprLen) { wxMemoryInputStream mis(compr, comprLen); wxZlibInputStream zis(mis, wxZLIB_ZLIB); wxFile file; if ( file.Create(szFileName, true) == false ) { wxRemoveFile(szFileName); return wxSysErrorCode(); } wxFileOutputStream fos(file); zis.Read(fos); return ERROR_SUCCESS; }
void PostErrorMessageC(wxString t) { wxString text; text << t << wxT("\nVýpis: ") << wxSysErrorMsg(wxSysErrorCode()); wxMessageBox(text, wxT("Chyba!"), wxOK | wxICON_EXCLAMATION); }
void frmMain::OnSaveDefinition(wxCommandEvent &event) { wxLogInfo(wxT("Saving object definition")); if (sqlPane->GetText().IsNull()) { wxLogError(__("There is nothing in the SQL pane to save!")); return; } wxString file; settings->Read(wxT("frmMain/LastFile"), &file, wxEmptyString); #ifdef __WXMSW__ wxFileDialog filename(this, _("Select output file"), ::wxPathOnly(file), file, _("SQL Scripts (*.sql)|*.sql|All files (*.*)|*.*"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT); #else wxFileDialog filename(this, _("Select output file"), ::wxPathOnly(file), file, _("SQL Scripts (*.sql)|*.sql|All files (*)|*"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT); #endif // Show the dialogue if (filename.ShowModal() == wxID_OK) { // Write the file if (!FileWrite(filename.GetPath(), sqlPane->GetText())) { wxLogError(__("Could not write the file %s: Errcode=%d."), filename.GetPath().c_str(), wxSysErrorCode()); } } else { wxLogInfo(wxT("User cancelled")); } settings->Write(wxT("frmMain/LastFile"), filename.GetPath()); }
void frmReport::OnOK(wxCommandEvent &ev) { wxString filename; if (rbHtml->GetValue()) filename = txtHtmlFile->GetValue(); else filename = txtXmlFile->GetValue(); wxFileName fn(filename); fn.MakeAbsolute(); // Check if the file exsits, and if so, whether to overwrite it if (wxFileExists(fn.GetFullPath())) { wxString msg; msg.Printf(_("The file: \n\n%s\n\nalready exists. Do you want to overwrite it?"), fn.GetFullPath().c_str()); if (wxMessageBox(msg, _("Overwrite file?"), wxYES_NO | wxICON_QUESTION) != wxYES) { if (rbHtml->GetValue()) txtHtmlFile->SetFocus(); else txtXmlFile->SetFocus(); return; } } // Yield, to allow the messagebox to go wxTheApp->Yield(true); // Add the title, notes and SQL if (txtTitle->GetValue() != wxT("")) XmlAddHeaderValue(wxT("title"), txtTitle->GetValue()); if (txtNotes->GetValue() != wxT("")) XmlAddHeaderValue(wxT("notes"), txtNotes->GetValue()); // Generate the report data wxString report; if (rbHtml->GetValue()) { if (rbHtmlBuiltin->GetValue()) { wxString xml = GetXmlReport(wxEmptyString); wxString xsl = GetDefaultXsl(GetEmbeddedCss(GetDefaultCss())); report = XslProcessReport(xml, xsl); } else if (rbHtmlEmbed->GetValue()) { wxString xml = GetXmlReport(wxEmptyString); wxString css = FileRead(txtHtmlStylesheet->GetValue()); if (css.IsEmpty()) { wxLogError(_("No stylesheet data could be read from the file %s: Errcode=%d."), txtHtmlStylesheet->GetValue().c_str(), wxSysErrorCode()); return; } wxString xsl = GetDefaultXsl(GetEmbeddedCss(css)); report = XslProcessReport(xml, xsl); } else { wxString xml = GetXmlReport(wxEmptyString); wxString xsl = GetDefaultXsl(GetCssLink(txtHtmlStylesheet->GetValue())); report = XslProcessReport(xml, xsl); } } else { if (rbXmlPlain->GetValue()) { report = GetXmlReport(wxEmptyString); } else if (rbXmlLink->GetValue()) { report = GetXmlReport(txtXmlStylesheet->GetValue()); } else { wxString xml = GetXmlReport(wxEmptyString); wxString xsl = FileRead(txtXmlStylesheet->GetValue()); if (xsl.IsEmpty()) { wxLogError(_("No stylesheet data could be read from the file %s: Errcode=%d."), txtXmlStylesheet->GetValue().c_str(), wxSysErrorCode()); return; } report = XslProcessReport(xml, xsl); } } // If report is empty, an error must have occurred if (report.IsEmpty()) return; // Save it to disk wxFile file(fn.GetFullPath(), wxFile::write); if (!file.IsOpened()) { wxLogError(_("Failed to open file %s."), fn.GetFullPath().c_str()); return; } file.Write(report, wxConvUTF8); file.Close(); // Open the file in the default browser if required if (chkBrowser->GetValue()) #ifdef __WXMSW__ wxLaunchDefaultBrowser(fn.GetFullPath()); #else wxLaunchDefaultBrowser(wxT("file://") + fn.GetFullPath()); #endif // Save the settings for next time round settings->Write(wxT("Reports/LastNotes"), txtNotes->GetValue()); if (rbHtml->GetValue()) settings->Write(wxT("Reports/ReportFormat"), wxT("h")); else settings->Write(wxT("Reports/ReportFormat"), wxT("x")); if (rbHtmlBuiltin->GetValue()) settings->Write(wxT("Reports/HtmlStylesheetMode"), wxT("b")); else if (rbHtmlEmbed->GetValue()) settings->Write(wxT("Reports/HtmlStylesheetMode"), wxT("e")); else settings->Write(wxT("Reports/HtmlStylesheetMode"), wxT("l")); if (rbXmlPlain->GetValue()) settings->Write(wxT("Reports/XmlStylesheetMode"), wxT("p")); else if (rbXmlLink->GetValue()) settings->Write(wxT("Reports/XmlStylesheetMode"), wxT("l")); else settings->Write(wxT("Reports/XmlStylesheetMode"), wxT("r")); settings->Write(wxT("Reports/LastHtmlStylesheet"), txtHtmlStylesheet->GetValue()); settings->Write(wxT("Reports/LastXmlStylesheet"), txtXmlStylesheet->GetValue()); settings->Write(wxT("Reports/LastHtmlFile"), txtHtmlFile->GetValue()); settings->Write(wxT("Reports/LastXmlFile"), txtXmlFile->GetValue()); settings->WriteBool(wxT("Reports/IncludeSQL"), chkSql->GetValue()); settings->WriteBool(wxT("Reports/OpenInBrowser"), chkBrowser->GetValue()); // Now go away if (IsModal()) EndModal(wxID_OK); else Destroy(); }
// get error message from system const wxChar *wxSysErrorMsg(unsigned long nErrCode) { if ( nErrCode == 0 ) nErrCode = wxSysErrorCode(); #if defined(__WXMSW__) && !defined(__WXMICROWIN__) static wxChar s_szBuf[1024]; // get error message from system LPVOID lpMsgBuf; if ( ::FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, nErrCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL ) == 0 ) { // if this happens, something is seriously wrong, so don't use _() here // for safety wxSprintf(s_szBuf, _T("unknown error %lx"), nErrCode); return s_szBuf; } // copy it to our buffer and free memory // Crashes on SmartPhone (FIXME) #if !defined(__SMARTPHONE__) /* of WinCE */ if( lpMsgBuf != 0 ) { wxStrncpy(s_szBuf, (const wxChar *)lpMsgBuf, WXSIZEOF(s_szBuf) - 1); s_szBuf[WXSIZEOF(s_szBuf) - 1] = wxT('\0'); LocalFree(lpMsgBuf); // returned string is capitalized and ended with '\r\n' - bad s_szBuf[0] = (wxChar)wxTolower(s_szBuf[0]); size_t len = wxStrlen(s_szBuf); if ( len > 0 ) { // truncate string if ( s_szBuf[len - 2] == wxT('\r') ) s_szBuf[len - 2] = wxT('\0'); } } else #endif // !__SMARTPHONE__ { s_szBuf[0] = wxT('\0'); } return s_szBuf; #else // !__WXMSW__ #if wxUSE_UNICODE static wchar_t s_wzBuf[1024]; wxConvCurrent->MB2WC(s_wzBuf, strerror((int)nErrCode), WXSIZEOF(s_wzBuf) - 1); return s_wzBuf; #else return strerror((int)nErrCode); #endif #endif // __WXMSW__/!__WXMSW__ }
void WXDLLEXPORT wxVLogSysError(const wxChar *szFormat, va_list argptr) { wxVLogSysError(wxSysErrorCode(), szFormat, argptr); }
bool CSSHTunnelThread::Initialize() { int rc, auth = AUTH_NONE; const char *fingerprint; char *userauthlist; #ifdef WIN32 char sockopt; WSADATA wsadata; int err; err = WSAStartup(MAKEWORD(2, 0), &wsadata); if(err != 0) { wxLogInfo(wxT("WSAStartup failed with error: %d"), err); return false; } #else int sockopt; #endif wxArrayString arrTunnelHostIP; if (resolveDNS(m_tunnelhost.mb_str(), arrTunnelHostIP)) { rc = libssh2_init (0); if (rc != 0) { LogSSHTunnelErrors(wxString::Format(_("libssh2 initialization failed with error code %d"), rc), GetId()); return false; } /* Connect to SSH server */ m_sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); m_sin.sin_family = AF_INET; if (INADDR_NONE == (m_sin.sin_addr.s_addr = inet_addr(arrTunnelHostIP.Item(0).mb_str()))) { LogSSHTunnelErrors(wxString::Format(_("SSH error: Error in inet address with error code %d"), wxSysErrorCode()), GetId()); return false; } m_sin.sin_port = htons(m_tunnelPort); if (connect(m_sock, (struct sockaddr *)(&m_sin), sizeof(struct sockaddr_in)) != 0) { LogSSHTunnelErrors(wxString::Format(_("SSH error: Could not connect to socket with error code %d"), wxSysErrorCode()), GetId()); return false; } /* Create a session instance */ m_session = libssh2_session_init(); if (!m_session) { LogSSHTunnelErrors(_("SSH error: Could not initialize SSH session!"), GetId()); return false; } /* ... start it up. This will trade welcome banners, exchange keys, * and setup crypto, compression, and MAC layers */ rc = libssh2_session_handshake(m_session, m_sock); if (rc) { LogSSHTunnelErrors(wxString::Format(_("SSH error: Error when starting up SSH session with error code %d"), rc), GetId()); return false; } /* At this point we havn't yet authenticated. The first thing to do * is check the hostkey's fingerprint against our known hosts Your app * may have it hard coded, may go to a file, may present it to the * user, that's your call */ fingerprint = libssh2_hostkey_hash(m_session, LIBSSH2_HOSTKEY_HASH_SHA1); wxString newHostKey = wxEmptyString; for(int i = 0; i < 20; i++) { newHostKey += wxString::Format(wxT("%02X "), (unsigned char)fingerprint[i]); } // Check if the SSH Host Key is verified if(!IsHostKeyVerified(newHostKey)) { Cleanup(); return false; } /* check what authentication methods are available */ userauthlist = libssh2_userauth_list(m_session, m_username.mb_str(), strlen(m_username.mb_str())); if (strstr(userauthlist, "password")) auth |= AUTH_PASSWORD; if(strstr(userauthlist, "keyboard-interactive")) auth |= AUTH_KEYBOARD_INTERACTIVE; if (strstr(userauthlist, "publickey")) auth |= AUTH_PUBLICKEY; if ((auth & AUTH_PASSWORD) && (m_enAuthMethod == AUTH_PASSWORD)) auth = AUTH_PASSWORD; else if ((auth & AUTH_KEYBOARD_INTERACTIVE) && (m_enAuthMethod == AUTH_PASSWORD)) auth = AUTH_KEYBOARD_INTERACTIVE; if ((auth & AUTH_PUBLICKEY) && (m_enAuthMethod == AUTH_PUBLICKEY)) auth = AUTH_PUBLICKEY; if (auth & AUTH_PASSWORD) { rc = libssh2_userauth_password(m_session, m_username.mb_str(), m_password.mb_str()); if (rc) { LogSSHTunnelErrors(wxString::Format(_("SSH error: Authentication by password failed with error code %d"), rc), GetId()); Cleanup(); return false; } } else if (auth & AUTH_KEYBOARD_INTERACTIVE) { rc = libssh2_userauth_keyboard_interactive(m_session, m_username.mb_str(), &CSSHTunnelThread::keyboard_interactive); if (rc) { LogSSHTunnelErrors(wxString::Format(_("SSH error: Authentication by password failed with error code %d"), rc), GetId()); Cleanup(); return false; } } else if (auth & AUTH_PUBLICKEY) { #ifdef HAVE_GCRYPT rc = libssh2_userauth_publickey_fromfile(m_session, m_username.mb_str(), m_publickey.mb_str(), m_privatekey.mb_str(), m_password.mb_str()); #else rc = libssh2_userauth_publickey_fromfile(m_session, m_username.mb_str(), NULL, m_privatekey.mb_str(), m_password.mb_str()); #endif if (rc) { LogSSHTunnelErrors(wxString::Format(_("SSH error: Authentication by identity file failed with error code %d"), rc), GetId()); Cleanup(); return false; } } else { LogSSHTunnelErrors(_("SSH error: No supported authentication methods found!"), GetId()); Cleanup(); return false; } // Get the IP Address of local machine wxArrayString arrLocalIP; if(resolveDNS("localhost", arrLocalIP)) { m_listensock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); memset(&m_sin, 0 , sizeof(m_sin)); m_sin.sin_family = AF_INET; // Give port no to 0 so that bind will automatically select the available port. m_sin.sin_port = htons(0); if (INADDR_NONE == (m_sin.sin_addr.s_addr = inet_addr(arrLocalIP.Item(0).mb_str()))) { Cleanup(); return false; } sockopt = 1; setsockopt(m_listensock, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(sockopt)); m_sinlen = sizeof(m_sin); if (-1 == bind(m_listensock, (struct sockaddr *)&m_sin, m_sinlen)) { LogSSHTunnelErrors(wxString::Format(_("SSH error: bind failed with error code %d"), wxSysErrorCode()), GetId()); Cleanup(); return false; } if (getsockname(m_listensock, (struct sockaddr *)&m_sin, &m_sinlen) == -1) { LogSSHTunnelErrors(wxString::Format(_("SSH error: getsockname() failed with error code %d"), wxSysErrorCode()), GetId()); Cleanup(); return false; } if (-1 == listen(m_listensock, 2)) { LogSSHTunnelErrors(wxString::Format(_("SSH error: listen failed with error code %d"), wxSysErrorCode()), GetId()); Cleanup(); return false; } m_local_listenip = wxString(inet_ntoa(m_sin.sin_addr), wxConvLibc); m_local_listenport = ntohs(m_sin.sin_port); wxLogInfo(wxT("Waiting for TCP connection on %s:%d..."), m_local_listenip.c_str(), m_local_listenport); return true; } else { LogSSHTunnelErrors(_("SSH error: Unable to resolve localhost"), GetId()); } } else { LogSSHTunnelErrors(wxString::Format(_("SSH error: Unable to resolve host: %s"), m_tunnelhost.c_str()), GetId()); } return false; }
void * CSubThread::Entry() { fd_set fds; struct timeval tv; ssize_t len, wr; char buf[20480]; int rc, i = 0; const char *shost = inet_ntoa(m_sin.sin_addr); unsigned int sport = ntohs(m_sin.sin_port); wxLogInfo(wxT("Forwarding connection from %s:%d to %s:%d"), wxString(inet_ntoa(m_sin.sin_addr), wxConvLibc).c_str(), sport, m_remote_desthost.c_str(), m_remote_destport); /* Must use blocking here to avoid connect errors */ //libssh2_session_set_blocking(m_subThreadSession, 1); while((m_channel = libssh2_channel_direct_tcpip_ex(m_subThreadSession, m_remote_desthost.mb_str(), m_remote_destport, shost, sport)) == NULL) { rc = libssh2_session_last_error(m_subThreadSession, NULL, NULL, 0); if (rc == LIBSSH2_ERROR_EAGAIN) Sleep(10); else break; } /* Must use non-blocking IO hereafter due to the current libssh2 API */ libssh2_session_set_blocking(m_subThreadSession, 0); if (!m_channel) { wxLogInfo(_("SSH error: Could not open a direct-tcpip channel!")); goto shutdown; } while (1) { FD_ZERO(&fds); FD_SET(m_forwardsock, &fds); tv.tv_sec = 0; tv.tv_usec = 100000; rc = select(m_forwardsock + 1, &fds, NULL, NULL, &tv); memset(buf, 0, sizeof(buf)); if (-1 == rc) { wxLogInfo(_("SSH error: select failed with error code %d"), wxSysErrorCode()); goto shutdown; } if (rc && FD_ISSET(m_forwardsock, &fds)) { len = recv(m_forwardsock, buf, sizeof(buf), 0); if (len < 0) { wxLogInfo(_("SSH error: read failed with error code %d"), wxSysErrorCode()); goto shutdown; } else if (0 == len) { wxLogInfo(_("The client at %s:%d disconnected!"), wxString(inet_ntoa(m_sin.sin_addr), wxConvLibc).c_str(), sport); goto shutdown; } wr = 0; do { i = libssh2_channel_write(m_channel, buf, len); if (i < 0) { wxLogInfo(_("SSH error: libssh2_channel_write with error code %d"), i); goto shutdown; } wr += i; } while (i > 0 && wr < len); } while (1) { len = libssh2_channel_read(m_channel, buf, sizeof(buf)); if (LIBSSH2_ERROR_EAGAIN == len) break; else if (len < 0) { wxLogInfo(_("SSH error: libssh2_channel_read with error code %d"), (int)len); goto shutdown; } wr = 0; while (wr < len) { i = send(m_forwardsock, buf + wr, len - wr, 0); if (i <= 0) { wxLogInfo(_("SSH error: write failed with error code %d"), wxSysErrorCode()); goto shutdown; } wr += i; } if (libssh2_channel_eof(m_channel)) { wxLogInfo(_("Connection at %s:%d disconnected by server"), wxString(inet_ntoa(m_sin.sin_addr), wxConvLibc).c_str(), sport); goto shutdown; } } } shutdown: #ifdef WIN32 closesocket(m_forwardsock); #else close(m_forwardsock); #endif if (m_channel) { libssh2_channel_close(m_channel); libssh2_channel_free(m_channel); m_channel = NULL; } return NULL; }
EWXWEXPORT(int,ELJSysErrorCode)() { return (int)wxSysErrorCode(); }
unsigned long bmx_wxsyserrorcode() { return wxSysErrorCode(); }