void SessionImpl::open(const std::string& connect) { if (connect != connectionString()) { if (isConnected()) throw InvalidAccessException("Session already connected"); if (!connect.empty()) setConnectionString(connect); } poco_assert_dbg (!connectionString().empty()); try { ActiveConnector connector(connectionString(), &_pDB); ActiveResult<int> result = connector.connect(); if (!result.tryWait(getLoginTimeout() * 1000)) throw ConnectionFailedException("Timed out."); int rc = result.data(); if (rc != 0) { close(); Utility::throwException(rc); } } catch (SQLiteException& ex) { throw ConnectionFailedException(ex.displayText()); } _connected = true; }
void MainFrame::OnInit(void) { an_statusbar = new AnStatusBar(this); setMessageString(); setConnectionString(false, wxEmptyString); SetStatusBar(an_statusbar); GetStatusBar()->Show(); PositionStatusBar(); Layout(); }
void SessionImpl::open(const std::string& connect) { if (connect != connectionString()) { if (isConnected()) throw InvalidAccessException("Session already connected"); if (!connect.empty()) setConnectionString(connect); } poco_assert_dbg (!connectionString().empty()); try { ActiveConnector connector(connectionString(), &_pDB); ActiveResult<int> result = connector.connect(); if (!result.tryWait(getLoginTimeout() * 1000)) throw ConnectionFailedException("Timed out."); int rc = result.data(); if (rc != 0) { close(); Utility::throwException(rc); } } catch (SQLiteException& ex) { throw ConnectionFailedException(ex.displayText()); } if (SQLITE_OK != sqlite3_exec(_pDB, "attach database ':memory:' as sys;" "create table sys.dual (dummy);", 0, 0, 0)) { throw ExecutionException("Cannot create system database."); } _connected = true; }
void SessionImpl::open(const std::string& connect) { if (connect != connectionString()) { if (isConnected()) throw InvalidAccessException("Session already connected"); if (!connect.empty()) setConnectionString(connect); } poco_assert_dbg (!connectionString().empty()); _handle.init(); unsigned int timeout = static_cast<unsigned int>(getLoginTimeout()); _handle.options(MYSQL_OPT_CONNECT_TIMEOUT, timeout); std::map<std::string, std::string> options; // Default values options["host"] = "localhost"; options["port"] = "3306"; options["user"] = ""; options["password"] = ""; options["db"] = ""; options["compress"] = ""; options["auto-reconnect"] = ""; options["secure-auth"] = ""; options["character-set"] = "utf8"; const std::string& connString = connectionString(); for (std::string::const_iterator start = connString.begin();;) { std::string::const_iterator finish = std::find(start, connString.end(), ';'); std::string::const_iterator middle = std::find(start, finish, '='); if (middle == finish) throw MySQLException("create session: bad connection string format, can not find '='"); options[copyStripped(start, middle)] = copyStripped(middle + 1, finish); if ((finish == connString.end()) || (finish + 1 == connString.end())) break; start = finish + 1; } if (options["user"].empty()) throw MySQLException("create session: specify user name"); const char * db = NULL; if (!options["db"].empty()) db = options["db"].c_str(); unsigned int port = 0; if (!NumberParser::tryParseUnsigned(options["port"], port) || 0 == port || port > 65535) throw MySQLException("create session: specify correct port (numeric in decimal notation)"); if (options["compress"] == "true") _handle.options(MYSQL_OPT_COMPRESS); else if (options["compress"] == "false") ; else if (!options["compress"].empty()) throw MySQLException("create session: specify correct compress option (true or false) or skip it"); if (options["auto-reconnect"] == "true") _handle.options(MYSQL_OPT_RECONNECT, true); else if (options["auto-reconnect"] == "false") _handle.options(MYSQL_OPT_RECONNECT, false); else if (!options["auto-reconnect"].empty()) throw MySQLException("create session: specify correct auto-reconnect option (true or false) or skip it"); if (options["secure-auth"] == "true") _handle.options(MYSQL_SECURE_AUTH, true); else if (options["secure-auth"] == "false") _handle.options(MYSQL_SECURE_AUTH, false); else if (!options["secure-auth"].empty()) throw MySQLException("create session: specify correct secure-auth option (true or false) or skip it"); if (!options["character-set"].empty()) _handle.options(MYSQL_SET_CHARSET_NAME, options["character-set"].c_str()); // Real connect _handle.connect(options["host"].c_str(), options["user"].c_str(), options["password"].c_str(), db, port); addFeature("autoCommit", &SessionImpl::autoCommit, &SessionImpl::isAutoCommit); _connected = true; }
void MainFrame::OnConnectionStateChange(wxCommandEvent& event) { JobCtrl *instance = JobCtrl::instance(); JobCtrl::ConnectionState newState = (JobCtrl::ConnectionState)event.GetInt(); bool connected = (newState == JobCtrl::CONNECTED); wxString hostname = event.GetString(); wxString logMessage; switch (newState) { case JobCtrl::CONNECTED: logMessage = wxString::Format( _("Connection established with %ls"), hostname.c_str()); Debug::info(logMessage); doUpgradeNotify(); break; case JobCtrl::DISCONNECTED: case JobCtrl::ERR_RW: logMessage = wxString::Format( _("Disconnected from %ls"), hostname.c_str()); Debug::info(logMessage); break; case JobCtrl::ERR_CONNECT: case JobCtrl::ERR_REG: logMessage = wxString::Format( _("Connection to %ls failed!"), hostname.c_str()); Debug::err(logMessage); break; case JobCtrl::ERR_VERSION_PROT: if (instance->getDaemonProtocolVersion() < ANOUBIS_PROTO_VERSION) { logMessage.Printf(_("Because of an incompatible " "protocol version (xanoubis: %i, Anoubis daemon: " "%i) the connection was rejected. Please update " "the Anoubis daemon package!"), ANOUBIS_PROTO_VERSION, instance->getDaemonProtocolVersion()); } else { logMessage.Printf(_("Because of an incompatible " "protocol version (xanoubis: %i, Anoubis daemon: " "%i) the connection was rejected. Please update " "the xanoubis package!"), ANOUBIS_PROTO_VERSION, instance->getDaemonProtocolVersion()); } anMessageBox(logMessage, _("Protocol version mismatch"), wxOK | wxICON_ERROR, this); Debug::info(logMessage); break; case JobCtrl::ERR_VERSION_APN: if (instance->getDaemonApnVersion() < apn_parser_version()) { logMessage.Printf(_("The APN parser (v%i.%i) is newer " "than the parser of the Anoubis daemon (v%i.%i). " "Please update the Anoubis daemon package!"), APN_PARSER_MAJOR(apn_parser_version()), APN_PARSER_MINOR(apn_parser_version()), APN_PARSER_MAJOR(instance->getDaemonApnVersion()), APN_PARSER_MINOR(instance->getDaemonApnVersion())); } else { logMessage.Printf(_("The APN parser (v%i.%i) is older " "than the parser of the Anoubis daemon (v%i.%i). " "Please update the xanoubis package!"), APN_PARSER_MAJOR(apn_parser_version()), APN_PARSER_MINOR(apn_parser_version()), APN_PARSER_MAJOR(instance->getDaemonApnVersion()), APN_PARSER_MINOR(instance->getDaemonApnVersion())); } anMessageBox(logMessage, _("APN version mismatch"), wxOK | wxICON_ERROR, this); Debug::info(logMessage); break; case JobCtrl::ERR_NO_KEY: logMessage = _("Because of missing keys the connection was " "rejected. Please check your key-configuration " "(certificate, private key)."); anMessageBox(logMessage, _("Missing key"), wxOK | wxICON_ERROR, this); Debug::info(logMessage); break; case JobCtrl::ERR_KEYID: logMessage.Printf(_("Your configured certificate does not " "match with the certificate requested by the daemon. " "Please check your key-configuration or ask your " "system-administrator to configure your certificate at " "the daemon.")); anMessageBox(logMessage, _("Certificate mismatch"), wxOK | wxICON_ERROR, this); Debug::info(logMessage); break; case JobCtrl::ERR_INV_KEY: case JobCtrl::ERR_INV_CERT: logMessage.Printf(_("Your configured certificate or private " "key is missconfigured or is not supported by Anoubis. " "Please check your certificate and private key.")); Debug::info(logMessage); anMessageBox(logMessage, _("Invalid Certificate / Private Key"), wxOK | wxICON_ERROR, this); break; case JobCtrl::ERR_AUTH_SYS_FAIL: logMessage.Printf(_("An internal error occured while " "processing the authentication.")); Debug::info(logMessage); anMessageBox(logMessage, _("Internal Error"), wxOK | wxICON_ERROR, this); break; } setConnectionString(connected, hostname); an_menubar->Check(ID_MIFILECONNECT, connected); event.Skip(); }
void SessionImpl::open(const std::string& connect) { if (connect != connectionString()) { if (isConnected()) throw InvalidAccessException("Session already connected"); if (!connect.empty()) setConnectionString(connect); } poco_assert_dbg (!connectionString().empty()); SQLULEN tout = static_cast<SQLULEN>(getLoginTimeout()); if (Utility::isError(SQLSetConnectAttr(_db, SQL_ATTR_LOGIN_TIMEOUT, (SQLPOINTER) tout, 0))) { if (Utility::isError(SQLGetConnectAttr(_db, SQL_ATTR_LOGIN_TIMEOUT, &tout, 0, 0)) || getLoginTimeout() != tout) { ConnectionError e(_db); throw ConnectionFailedException(e.toString()); } } SQLCHAR connectOutput[512] = {0}; SQLSMALLINT result; if (Utility::isError(Poco::Data::ODBC::SQLDriverConnect(_db , NULL ,(SQLCHAR*) connectionString().c_str() ,(SQLSMALLINT) SQL_NTS , connectOutput , sizeof(connectOutput) , &result , SQL_DRIVER_NOPROMPT))) { ConnectionError err(_db); std::string errStr = err.toString(); close(); throw ConnectionFailedException(errStr); } _dataTypes.fillTypeInfo(_db); addProperty("dataTypeInfo", &SessionImpl::setDataTypeInfo, &SessionImpl::dataTypeInfo); addFeature("autoCommit", &SessionImpl::autoCommit, &SessionImpl::isAutoCommit); addFeature("autoBind", &SessionImpl::autoBind, &SessionImpl::isAutoBind); addFeature("autoExtract", &SessionImpl::autoExtract, &SessionImpl::isAutoExtract); addProperty("maxFieldSize", &SessionImpl::setMaxFieldSize, &SessionImpl::getMaxFieldSize); addProperty("queryTimeout", &SessionImpl::setQueryTimeout, &SessionImpl::getQueryTimeout); Poco::Data::ODBC::SQLSetConnectAttr(_db, SQL_ATTR_QUIET_MODE, 0, 0); if (!canTransact()) autoCommit("", true); }