int main(int argc, char *argv[]) { QApplication a(argc, argv); // 翻訳ファイルをセットする QString c_code = QLocale::system().name().split("_")[0]; QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf8")); // :Qtライブラリ QTranslator trQ, trMe; trQ.load("qt_" + c_code, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); a.installTranslator(&trQ); // :MyApp trMe.load(qApp->applicationDirPath() + "/../translate/tr_" + c_code); a.installTranslator(&trMe); std::unique_ptr<TwqNet> pNet(new TwqNet(nullptr)); std::unique_ptr<TwqUser> pUser(new TwqUser(nullptr)); std::unique_ptr<TwqTweet> pTweet(new TwqTweet(nullptr)); std::unique_ptr<TwqResource> pRes(new TwqResource); TwqMain w; w.show(); try { return a.exec(); } catch(const ExceptionBase& e) { QMessageBox::warning(&w, QApplication::tr("unknown error"), QApplication::tr("unhandled exception throwed\n%1").arg(e.whatQs())); } return 1; }
virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth) { CString const user(Auth->GetUsername()); CString const pass(Auth->GetPassword()); CUser* pUser(CZNC::Get().FindUser(user)); sasl_conn_t *sasl_conn(0); if (!pUser) { // @todo Will want to do some sort of && !m_bAllowCreate in the future Auth->RefuseLogin("Invalid User - Halting SASL Authentication"); return HALT; } CString const key(CString(user + ":" + pass).MD5()); if (m_Cache.HasItem(key)) { Auth->AcceptLogin(*pUser); DEBUG("+++ Found in cache"); } else if (sasl_server_new("znc", NULL, NULL, NULL, NULL, cbs, 0, &sasl_conn) == SASL_OK && sasl_checkpass(sasl_conn, user.c_str(), user.size(), pass.c_str(), pass.size()) == SASL_OK) { Auth->AcceptLogin(*pUser); m_Cache.AddItem(key); DEBUG("+++ Successful SASL password check"); } else { Auth->RefuseLogin("SASL Authentication failed"); DEBUG("--- FAILED SASL password check"); } sasl_dispose(&sasl_conn); return HALT; }
LRESULT CChatWnd::OnChatAddUser(WPARAM /*wParam*/, LPARAM lParam) { CAutoPtr< CChatUser > pUser( (CChatUser*)lParam ); LVFINDINFO lvfi = { LVFI_STRING, pUser->m_sNick }; int index = -1; for (;;) { index = m_wndUsers.FindItem( &lvfi, index ); if ( index == -1 ) break; CChatUser* pCurrent = (CChatUser*)m_wndUsers.GetItemData( index ); if ( pCurrent->m_bType == pUser->m_bType ) { // Update existing user pCurrent->m_sDescription = pUser->m_sDescription; // TODO: Other user properties return 0; } } // New User int i = m_wndUsers.InsertItem( 0, pUser->m_sNick, pUser->m_bType ); m_wndUsers.SetItemData( i, (DWORD_PTR)pUser.Detach() ); return 0; }
virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth) { const CString& sUsername = Auth->GetUsername(); const CString& sPassword = Auth->GetPassword(); CUser *pUser(CZNC::Get().FindUser(sUsername)); sasl_conn_t *sasl_conn(NULL); bool bSuccess = false; if (!pUser && !CreateUser()) { return CONTINUE; } const CString sCacheKey(CString(sUsername + ":" + sPassword).MD5()); if (m_Cache.HasItem(sCacheKey)) { bSuccess = true; DEBUG("saslauth: Found [" + sUsername + "] in cache"); } else if (sasl_server_new("znc", NULL, NULL, NULL, NULL, m_cbs, 0, &sasl_conn) == SASL_OK && sasl_checkpass(sasl_conn, sUsername.c_str(), sUsername.size(), sPassword.c_str(), sPassword.size()) == SASL_OK) { m_Cache.AddItem(sCacheKey); DEBUG("saslauth: Successful SASL authentication [" + sUsername + "]"); bSuccess = true; } sasl_dispose(&sasl_conn); if (bSuccess) { if (!pUser) { CString sErr; pUser = new CUser(sUsername); if (ShouldCloneUser()) { CUser *pBaseUser = CZNC::Get().FindUser(CloneUser()); if (!pBaseUser) { DEBUG("saslauth: Clone User [" << CloneUser() << "] User not found"); delete pUser; pUser = NULL; } if (pUser && !pUser->Clone(*pBaseUser, sErr)) { DEBUG("saslauth: Clone User [" << CloneUser() << "] failed: " << sErr); delete pUser; pUser = NULL; } } if (pUser) { // "::" is an invalid MD5 hash, so user won't be able to login by usual method pUser->SetPass("::", CUser::HASH_MD5, "::"); } if (pUser && !CZNC::Get().AddUser(pUser, sErr)) { DEBUG("saslauth: Add user [" << sUsername << "] failed: " << sErr); delete pUser; pUser = NULL; } } if (pUser) { Auth->AcceptLogin(*pUser); return HALT; } } return CONTINUE; }