string Account::executePostDeleteRequest(ptree & root) { string ret = MPAO::DEFAULT_JSON_ID; delAccount( urlPairs[0].second , atoi( argvals.find("version")->second ) ); return ret; }
void FSHost::accountReloadCmd(QSharedPointer<Account> acc) { QString res; QString arg = QString("profile softphone killgw %1").arg(acc.data()->getName()); connect(this, SIGNAL(delAccount(QSharedPointer<Account>)), this, SLOT(accountReloadSlot(QSharedPointer<Account>))); if (g_FSHost->sendCmd("sofia", arg.toAscii().data() , &res) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not killgw %s from profile softphone.\n", acc.data()->getName().toAscii().data()); } _reloading_Accounts.append(acc.data()->getName()); }
void FSHost::generalEventHandler(QSharedPointer<switch_event_t>event) { QString uuid = switch_event_get_header_nil(event.data(), "Unique-ID"); emit newEvent(event); switch(event.data()->event_id) { case SWITCH_EVENT_CHANNEL_CREATE: /*1A - 17B*/ { eventChannelCreate(event, uuid); break; } case SWITCH_EVENT_CHANNEL_ANSWER: /*2A - 31B*/ { eventChannelAnswer(event, uuid); break; } case SWITCH_EVENT_CODEC:/*3/4A - 24/25B*/ { eventCodec(event, uuid); break; } case SWITCH_EVENT_CHANNEL_STATE:/*6/7/8/37/44/46A - 20/21/22/28/38/40/42B*/ { eventChannelState(event, uuid); break; } case SWITCH_EVENT_CHANNEL_EXECUTE:/*9/11/13/15A*/ { eventChannelExecute(event, uuid); break; } case SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE:/*10/12/14/16/35A*/ { eventChannelExecuteComplete(event, uuid); break; } case SWITCH_EVENT_CHANNEL_OUTGOING:/*18B*/ { eventChannelOutgoing(event, uuid); break; } case SWITCH_EVENT_CHANNEL_ORIGINATE:/*19B*/ { eventChannelOriginate(event, uuid); break; } case SWITCH_EVENT_CALL_UPDATE:/*23/29/30B*/ { eventCallUpdate(event, uuid); break; } case SWITCH_EVENT_CHANNEL_PROGRESS: { eventChannelProgress(event, uuid); break; } case SWITCH_EVENT_CHANNEL_PROGRESS_MEDIA:/*26B*/ { eventChannelProgressMedia(event, uuid); break; } case SWITCH_EVENT_CHANNEL_BRIDGE:/*27A*/ { eventChannelBridge(event, uuid); break; } /*32?*/ /*case SWITCH_EVENT_RECV_INFO: { eventRecvInfo(event, uuid); break; }*/ case SWITCH_EVENT_CHANNEL_HANGUP:/*36A-33B*/ { eventChannelHangup(event, uuid); break; } case SWITCH_EVENT_CHANNEL_UNBRIDGE:/*34A*/ { eventChannelUnbridge(event, uuid); break; } case SWITCH_EVENT_CHANNEL_HANGUP_COMPLETE:/*39/43B*/ { eventChannelHangupComplete(event, uuid); break; } case SWITCH_EVENT_CHANNEL_DESTROY:/*45A-41B*/ { eventChannelDestroy(event, uuid); break; } case SWITCH_EVENT_CUSTOM:/*5A*/ { if (strcmp(event.data()->subclass_name, "sofia::gateway_state") == 0) { QString state = switch_event_get_header_nil(event.data(), "State"); QString gw = switch_event_get_header_nil(event.data(), "Gateway"); QSharedPointer<Account> acc = _accounts.value(gw); if (acc.isNull()) return; if (state == "TRYING") { acc.data()->setStatusPhrase(switch_event_get_header_nil(event.data(), "Phrase")); acc.data()->setState(FSCOMM_GW_STATE_TRYING); emit accountStateChange(acc); } else if (state == "REGISTER") { acc.data()->setStatusPhrase(switch_event_get_header_nil(event.data(), "Phrase")); acc.data()->setState(FSCOMM_GW_STATE_REGISTER); emit accountStateChange(acc); } else if (state == "REGED") { acc.data()->setStatusPhrase(switch_event_get_header_nil(event.data(), "Phrase")); acc.data()->setState(FSCOMM_GW_STATE_REGED); emit accountStateChange(acc); } else if (state == "UNREGED") { acc.data()->setStatusPhrase(switch_event_get_header_nil(event.data(), "Phrase")); acc.data()->setState(FSCOMM_GW_STATE_UNREGED); emit accountStateChange(acc); } else if (state == "UNREGISTER") { acc.data()->setStatusPhrase(switch_event_get_header_nil(event.data(), "Phrase")); acc.data()->setState(FSCOMM_GW_STATE_UNREGISTER); emit accountStateChange(acc); } else if (state =="FAILED") { acc.data()->setStatusPhrase(switch_event_get_header_nil(event.data(), "Phrase")); acc.data()->setState(FSCOMM_GW_STATE_FAILED); emit accountStateChange(acc); } else if (state == "FAIL_WAIT") { acc.data()->setState(FSCOMM_GW_STATE_FAIL_WAIT); emit accountStateChange(acc); } else if (state == "EXPIRED") { acc.data()->setStatusPhrase(switch_event_get_header_nil(event.data(), "Phrase")); acc.data()->setState(FSCOMM_GW_STATE_EXPIRED); emit accountStateChange(acc); } else if (state == "NOREG") { acc.data()->setStatusPhrase(switch_event_get_header_nil(event.data(), "Phrase")); acc.data()->setState(FSCOMM_GW_STATE_NOREG); emit accountStateChange(acc); } } else if (strcmp(event.data()->subclass_name, "sofia::gateway_add") == 0) { QString gw = switch_event_get_header_nil(event.data(), "Gateway"); Account * accPtr = new Account(gw); QSharedPointer<Account> acc = QSharedPointer<Account>(accPtr); acc.data()->setState(FSCOMM_GW_STATE_NOAVAIL); _accounts.insert(gw, acc); emit newAccount(acc); } else if (strcmp(event.data()->subclass_name, "sofia::gateway_delete") == 0) { QSharedPointer<Account> acc = _accounts.take(switch_event_get_header_nil(event.data(), "Gateway")); if (!acc.isNull()) emit delAccount(acc); } else { //printEventHeaders(event); } break; } case SWITCH_EVENT_MODULE_LOAD: { QString modType = switch_event_get_header_nil(event.data(), "type"); QString modKey = switch_event_get_header_nil(event.data(), "key"); emit loadedModule(modType, modKey); break; } default: break; } }
//------------------------------------------------------------------------------------- bool KBEEmailVerificationTableRedis::resetpassword(DBInterface * pdbi, const std::string& name, const std::string& password, const std::string& code) { /* kbe_email_verification:code = hashes(accountName, type, datas, logtime) kbe_email_verification:accountName = code */ redisReply* pRedisReply = NULL; if (!pdbi->query(fmt::format("HMGET kbe_email_verification:{} accountName type, datas logtime", code), false)) { ERROR_MSG(fmt::format("KBEEmailVerificationTableRedis::bindEMail({}): cmd({}) is failed({})!\n", code, pdbi->lastquery(), pdbi->getstrerror())); } uint64 logtime = 1; int type = -1; std::string qname, qemail; if(pRedisReply) { if(pRedisReply->type == REDIS_REPLY_ARRAY) { if(RedisHelper::check_array_results(pRedisReply)) { qname = pRedisReply->element[0]->str; StringConv::str2value(type, pRedisReply->element[1]->str); qemail = pRedisReply->element[2]->str; StringConv::str2value(logtime, pRedisReply->element[3]->str); } } freeReplyObject(pRedisReply); } if(logtime > 0 && time(NULL) - logtime > g_kbeSrvConfig.emailResetPasswordInfo_.deadline) { ERROR_MSG(fmt::format("KBEEmailVerificationTableRedis::resetpassword({}): is expired! {} > {}.\n", code, (time(NULL) - logtime), g_kbeSrvConfig.emailResetPasswordInfo_.deadline)); return false; } if(qname.size() == 0 || password.size() == 0) { ERROR_MSG(fmt::format("KBEEmailVerificationTableRedis::resetpassword({}): name or password is NULL.\n", code)); return false; } if(qname != name) { WARNING_MSG(fmt::format("KBEEmailVerificationTableRedis::resetpassword: code({}) username({} != {}) not match.\n" , code, name, qname)); return false; } if((int)KBEEmailVerificationTable::V_TYPE_RESETPASSWORD != type) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::resetpassword({}): type({}) error!\n", code, type)); return false; } // 寻找dblog是否有此账号 KBEAccountTable* pTable = static_cast<KBEAccountTable*>(EntityTables::findByInterfaceName(pdbi->name()).findKBETable("kbe_accountinfos")); KBE_ASSERT(pTable); if(!pTable->updatePassword(pdbi, qname, KBE_MD5::getDigest(password.data(), password.length()))) { ERROR_MSG(fmt::format("KBEEmailVerificationTableRedis::resetpassword({}): update accountName({}) password error({})!\n", code, qname, pdbi->getstrerror())); return false; } delAccount(pdbi, (int8)V_TYPE_RESETPASSWORD, qname); return true; }
//------------------------------------------------------------------------------------- bool KBEEmailVerificationTableRedis::bindEMail(DBInterface * pdbi, const std::string& name, const std::string& code) { /* kbe_email_verification:code = hashes(accountName, type, datas, logtime) kbe_email_verification:accountName = code */ redisReply* pRedisReply = NULL; if (!pdbi->query(fmt::format("HMGET kbe_email_verification:{} accountName type, datas logtime", code), false)) { ERROR_MSG(fmt::format("KBEEmailVerificationTableRedis::bindEMail({}): cmd({}) is failed({})!\n", code, pdbi->lastquery(), pdbi->getstrerror())); } uint64 logtime = 1; int type = -1; std::string qname, qemail; if(pRedisReply) { if(pRedisReply->type == REDIS_REPLY_ARRAY) { if(RedisHelper::check_array_results(pRedisReply)) { qname = pRedisReply->element[0]->str; StringConv::str2value(type, pRedisReply->element[1]->str); qemail = pRedisReply->element[2]->str; StringConv::str2value(logtime, pRedisReply->element[3]->str); } } freeReplyObject(pRedisReply); } if(logtime > 0 && time(NULL) - logtime > g_kbeSrvConfig.emailBindInfo_.deadline) { ERROR_MSG(fmt::format("KBEEmailVerificationTableRedis::bindEMail({}): is expired! {} > {}.\n", code, (time(NULL) - logtime), g_kbeSrvConfig.emailBindInfo_.deadline)); return false; } if(qname.size() == 0 || qemail.size() == 0) { ERROR_MSG(fmt::format("KBEEmailVerificationTableRedis::bindEMail({}): name or email is NULL.\n", code)); return false; } if(qemail != name) { WARNING_MSG(fmt::format("KBEEmailVerificationTableRedis::bindEMail: code({}) username({}:{}, {}) not match.\n" , code, name, qname, qemail)); return false; } if((int)KBEEmailVerificationTable::V_TYPE_BIND_MAIL != type) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::bindEMail({}): type({}) error!\n", code, type)); return false; } /* kbe_accountinfos:accountName = hashes(password, bindata, email, entityDBID, flags, deadline, regtime, lasttime, numlogin) */ // 如果查询失败则返回存在, 避免可能产生的错误 if(!pdbi->query(fmt::format("HSET kbe_accountinfos:{} email {}", qname, qemail), false)) { ERROR_MSG(fmt::format("KBEEmailVerificationTableRedis::bindEMail({}): update kbe_accountinfos({}) error({})!\n", code, qname, pdbi->getstrerror())); return false; } delAccount(pdbi, (int8)V_TYPE_BIND_MAIL, name); return true; }
//------------------------------------------------------------------------------------- bool KBEEmailVerificationTableRedis::activateAccount(DBInterface * pdbi, const std::string& code, ACCOUNT_INFOS& info) { /* kbe_email_verification:code = hashes(accountName, type, datas, logtime) kbe_email_verification:accountName = code */ redisReply* pRedisReply = NULL; if (!static_cast<DBInterfaceRedis*>(pdbi)->query(fmt::format("HMGET kbe_email_verification:{} accountName type, datas logtime", code), &pRedisReply, false)) return false; uint64 logtime = 1; int type = -1; if(pRedisReply) { if(pRedisReply->type == REDIS_REPLY_ARRAY) { if(RedisHelper::check_array_results(pRedisReply)) { info.name = pRedisReply->element[0]->str; StringConv::str2value(type, pRedisReply->element[1]->str); info.password = pRedisReply->element[2]->str; StringConv::str2value(logtime, pRedisReply->element[3]->str); } } freeReplyObject(pRedisReply); } if(logtime > 0 && time(NULL) - logtime > g_kbeSrvConfig.emailAtivationInfo_.deadline) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::activateAccount({}): is expired! {} > {}.\n", code, (time(NULL) - logtime), g_kbeSrvConfig.emailAtivationInfo_.deadline)); return false; } if(info.name.size() == 0) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::activateAccount({}): name is NULL.\n", code)); return false; } if((int)KBEEmailVerificationTable::V_TYPE_CREATEACCOUNT != type) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::activateAccount({}): type({}) error!\n", code, type)); return false; } std::string password = info.password; // 寻找dblog是否有此账号 KBEAccountTable* pTable = static_cast<KBEAccountTable*>(EntityTables::findByInterfaceName(pdbi->name()).findKBETable("kbe_accountinfos")); KBE_ASSERT(pTable); info.flags = 0; if(!pTable->queryAccount(pdbi, info.name, info)) { return false; } if((info.flags & ACCOUNT_FLAG_NOT_ACTIVATED) <= 0) { ERROR_MSG(fmt::format("KBEEmailVerificationTableRedis::activateAccount({}): Has been activated, flags={}.\n", code, info.flags)); return false; } info.flags &= ~ACCOUNT_FLAG_NOT_ACTIVATED; if(!pTable->setFlagsDeadline(pdbi, info.name, info.flags, info.deadline)) { ERROR_MSG(fmt::format("KBEEmailVerificationTableRedis::activateAccount({}): set deadline is error({})!\n", code, pdbi->getstrerror())); return false; } if(!pTable->updatePassword(pdbi, info.name, password)) { ERROR_MSG(fmt::format("KBEEmailVerificationTableRedis::activateAccount({}): update password is error({})!\n", code, pdbi->getstrerror())); return false; } info.dbid = 0; ScriptDefModule* pModule = EntityDef::findScriptModule(DBUtil::accountScriptName()); // 防止多线程问题, 这里做一个拷贝。 MemoryStream copyAccountDefMemoryStream(pTable->accountDefMemoryStream()); info.dbid = EntityTables::findByInterfaceName(pdbi->name()).writeEntity(pdbi, 0, -1, ©AccountDefMemoryStream, pModule); KBE_ASSERT(info.dbid > 0); /* kbe_accountinfos:accountName = hashes(password, bindata, email, entityDBID, flags, deadline, regtime, lasttime, numlogin) */ // 如果查询失败则返回存在, 避免可能产生的错误 if(!pdbi->query(fmt::format("HSET kbe_accountinfos:{} entityDBID {}", info.name, info.dbid), false)) { ERROR_MSG(fmt::format("KBEEmailVerificationTableRedis::activateAccount({}): update kbe_accountinfos is error({})!\n", code, pdbi->getstrerror())); return false; } delAccount(pdbi, (int8)V_TYPE_CREATEACCOUNT, info.name); return true; }
//------------------------------------------------------------------------------------- bool KBEEmailVerificationTableMysql::resetpassword(DBInterface * dbi, const std::string& name, const std::string& password, const std::string& code) { std::string sqlstr = "select accountName, logtime from kbe_email_verification where code like \""; char* tbuf = new char[code.size() * 2 + 1]; mysql_real_escape_string(static_cast<DBInterfaceMysql*>(dbi)->mysql(), tbuf, code.c_str(), code.size()); sqlstr += tbuf; sqlstr += "\" and type="; kbe_snprintf(tbuf, MAX_BUF, "%d", (int)KBEEmailVerificationTable::V_TYPE_RESETPASSWORD); sqlstr += tbuf; SAFE_RELEASE_ARRAY(tbuf); if(!dbi->query(sqlstr.c_str(), sqlstr.size(), false)) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::resetpassword({}): sql({}) is failed({})!\n", code, sqlstr, dbi->getstrerror())); return false; } uint64 logtime = 1; std::string qname; MYSQL_RES * pResult = mysql_store_result(static_cast<DBInterfaceMysql*>(dbi)->mysql()); if(pResult) { MYSQL_ROW arow; while((arow = mysql_fetch_row(pResult)) != NULL) { qname = arow[0]; KBEngine::StringConv::str2value(logtime, arow[1]); } mysql_free_result(pResult); } if(logtime > 0 && time(NULL) - logtime > g_kbeSrvConfig.emailResetPasswordInfo_.deadline) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::bindEMail({}): is expired! {} > {}.\n", code, (time(NULL) - logtime), g_kbeSrvConfig.emailResetPasswordInfo_.deadline)); return false; } if(qname.size() == 0 || password.size() == 0) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::resetpassword({}): name or password is NULL.\n", code)); return false; } if(qname != name) { WARNING_MSG(fmt::format("KBEEmailVerificationTableMysql::resetpassword: code({}) username({}, {}) not match.\n" , code, name, qname)); return false; } // 寻找dblog是否有此账号 KBEAccountTable* pTable = static_cast<KBEAccountTable*>(EntityTables::getSingleton().findKBETable("kbe_accountinfos")); KBE_ASSERT(pTable); if(!pTable->updatePassword(dbi, name, KBE_MD5::getDigest(password.data(), password.length()))) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::resetpassword({}): update password is error({})!\n", code, dbi->getstrerror())); return false; } try { delAccount(dbi, (int8)V_TYPE_RESETPASSWORD, name); } catch (...) { } return true; }
//------------------------------------------------------------------------------------- bool KBEEmailVerificationTableMysql::bindEMail(DBInterface * dbi, const std::string& name, const std::string& code) { std::string sqlstr = "select accountName, datas, logtime from kbe_email_verification where code like \""; char* tbuf = new char[code.size() * 2 + 1]; mysql_real_escape_string(static_cast<DBInterfaceMysql*>(dbi)->mysql(), tbuf, code.c_str(), code.size()); sqlstr += tbuf; sqlstr += "\" and type="; kbe_snprintf(tbuf, MAX_BUF, "%d", (int)KBEEmailVerificationTable::V_TYPE_BIND_MAIL); sqlstr += tbuf; SAFE_RELEASE_ARRAY(tbuf); if(!dbi->query(sqlstr.c_str(), sqlstr.size(), false)) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::bindEMail({}): sql({}) is failed({})!\n", code, sqlstr, dbi->getstrerror())); return false; } uint64 logtime = 1; std::string qname, qemail; MYSQL_RES * pResult = mysql_store_result(static_cast<DBInterfaceMysql*>(dbi)->mysql()); if(pResult) { MYSQL_ROW arow; while((arow = mysql_fetch_row(pResult)) != NULL) { qname = arow[0]; qemail = arow[1]; KBEngine::StringConv::str2value(logtime, arow[2]); } mysql_free_result(pResult); } if(logtime > 0 && time(NULL) - logtime > g_kbeSrvConfig.emailBindInfo_.deadline) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::bindEMail({}): is expired! {} > {}.\n", code, (time(NULL) - logtime), g_kbeSrvConfig.emailBindInfo_.deadline)); return false; } if(qname.size() == 0 || qemail.size() == 0) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::bindEMail({}): name or email is NULL.\n", code)); return false; } if(qname != name) { WARNING_MSG(fmt::format("KBEEmailVerificationTableMysql::bindEMail: code({}) username({}, {}) not match.\n" , code, name, qname)); return false; } tbuf = new char[code.size() * 2 + 1]; mysql_real_escape_string(static_cast<DBInterfaceMysql*>(dbi)->mysql(), tbuf, qemail.c_str(), qemail.size()); sqlstr = "update kbe_accountinfos set email=\""; sqlstr += tbuf; sqlstr += "\" where accountName like \""; mysql_real_escape_string(static_cast<DBInterfaceMysql*>(dbi)->mysql(), tbuf, name.c_str(), name.size()); sqlstr += tbuf; sqlstr += "\""; SAFE_RELEASE_ARRAY(tbuf); if(!dbi->query(sqlstr, false)) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::bindEMail({}): update kbe_accountinfos is error({})!\n", code, dbi->getstrerror())); return false; } try { delAccount(dbi, (int8)V_TYPE_BIND_MAIL, name); } catch (...) { } return true; }
//------------------------------------------------------------------------------------- bool KBEEmailVerificationTableMysql::activateAccount(DBInterface * dbi, const std::string& code, ACCOUNT_INFOS& info) { std::string sqlstr = "select accountName, datas, logtime from kbe_email_verification where code like \""; char* tbuf = new char[code.size() * 2 + 1]; mysql_real_escape_string(static_cast<DBInterfaceMysql*>(dbi)->mysql(), tbuf, code.c_str(), code.size()); sqlstr += tbuf; sqlstr += "\" and type="; kbe_snprintf(tbuf, MAX_BUF, "%d", (int)KBEEmailVerificationTable::V_TYPE_CREATEACCOUNT); sqlstr += tbuf; SAFE_RELEASE_ARRAY(tbuf); if(!dbi->query(sqlstr.c_str(), sqlstr.size(), false)) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::activateAccount({}): sql({}) is failed({})!\n", code, sqlstr, dbi->getstrerror())); return false; } uint64 logtime = 1; MYSQL_RES * pResult = mysql_store_result(static_cast<DBInterfaceMysql*>(dbi)->mysql()); if(pResult) { MYSQL_ROW arow; while((arow = mysql_fetch_row(pResult)) != NULL) { info.name = arow[0]; info.password = arow[1]; KBEngine::StringConv::str2value(logtime, arow[2]); } mysql_free_result(pResult); } if(logtime > 0 && time(NULL) - logtime > g_kbeSrvConfig.emailAtivationInfo_.deadline) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::activateAccount({}): is expired! {} > {}.\n", code, (time(NULL) - logtime), g_kbeSrvConfig.emailAtivationInfo_.deadline)); return false; } if(info.name.size() == 0) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::activateAccount({}): name is NULL.\n", code)); return false; } std::string password = info.password; // 寻找dblog是否有此账号 KBEAccountTable* pTable = static_cast<KBEAccountTable*>(EntityTables::getSingleton().findKBETable("kbe_accountinfos")); KBE_ASSERT(pTable); info.flags = 0; if(!pTable->queryAccount(dbi, info.name, info)) { return false; } if((info.flags & ACCOUNT_FLAG_NOT_ACTIVATED) <= 0) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::activateAccount({}): Has been activated, flags={}.\n", code, info.flags)); return false; } info.flags &= ~ACCOUNT_FLAG_NOT_ACTIVATED; if(!pTable->setFlagsDeadline(dbi, info.name, info.flags, info.deadline)) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::activateAccount({}): set deadline is error({})!\n", code, dbi->getstrerror())); return false; } if(!pTable->updatePassword(dbi, info.name, password)) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::activateAccount({}): update password is error({})!\n", code, dbi->getstrerror())); return false; } info.dbid = 0; ScriptDefModule* pModule = EntityDef::findScriptModule(DBUtil::accountScriptName()); // 防止多线程问题, 这里做一个拷贝。 MemoryStream copyAccountDefMemoryStream(pTable->accountDefMemoryStream()); info.dbid = EntityTables::getSingleton().writeEntity(dbi, 0, -1, ©AccountDefMemoryStream, pModule); KBE_ASSERT(info.dbid > 0); // 如果查询失败则返回存在, 避免可能产生的错误 tbuf = new char[MAX_BUF * 3]; mysql_real_escape_string(static_cast<DBInterfaceMysql*>(dbi)->mysql(), tbuf, info.name.c_str(), info.name.size()); if(!dbi->query(fmt::format("update kbe_accountinfos set entityDBID={} where accountName like \"{}\"", info.dbid, tbuf), false)) { ERROR_MSG(fmt::format("KBEEmailVerificationTableMysql::activateAccount({}): update kbe_accountinfos is error({})!\n", code, dbi->getstrerror())); SAFE_RELEASE_ARRAY(tbuf); return false; } SAFE_RELEASE_ARRAY(tbuf); try { delAccount(dbi, (int8)V_TYPE_CREATEACCOUNT, info.name); } catch (...) { } return true; }
//------------------------------------------------------------------------------------- bool KBEEmailVerificationTableMysql::resetpassword(DBInterface * dbi, const std::string& name, const std::string& password, const std::string& code) { std::string sqlstr = "select accountName, logtime from kbe_email_verification where code like \""; char* tbuf = new char[code.size() * 2 + 1]; mysql_real_escape_string(static_cast<DBInterfaceMysql*>(dbi)->mysql(), tbuf, code.c_str(), code.size()); sqlstr += tbuf; sqlstr += "\" and type="; kbe_snprintf(tbuf, MAX_BUF, "%d", (int)KBEEmailVerificationTable::V_TYPE_RESETPASSWORD); sqlstr += tbuf; SAFE_RELEASE_ARRAY(tbuf); if(!dbi->query(sqlstr.c_str(), sqlstr.size(), false)) return false; uint64 logtime = 1; std::string qname; MYSQL_RES * pResult = mysql_store_result(static_cast<DBInterfaceMysql*>(dbi)->mysql()); if(pResult) { MYSQL_ROW arow; while((arow = mysql_fetch_row(pResult)) != NULL) { qname = arow[0]; KBEngine::StringConv::str2value(logtime, arow[1]); } mysql_free_result(pResult); } if(logtime > 0 && time(NULL) - logtime > g_kbeSrvConfig.emailResetPasswordInfo_.deadline) return false; if(qname.size() == 0 || password.size() == 0) { return false; } if(qname != name) { WARNING_MSG(boost::format("KBEEmailVerificationTableMysql::resetpassword: code(%1%) username(%2%, %3%) not match.\n") % code % name % qname); return false; } // 寻找dblog是否有此账号 KBEAccountTable* pTable = static_cast<KBEAccountTable*>(EntityTables::getSingleton().findKBETable("kbe_accountinfos")); KBE_ASSERT(pTable); unsigned char md[16]; MD5((unsigned char *)password.c_str(), password.length(), md); char tmp[3]={'\0'}, md5password[33] = {'\0'}; for (int i = 0; i < 16; i++) { sprintf(tmp,"%2.2X", md[i]); strcat(md5password, tmp); } if(!pTable->updatePassword(dbi, name, md5password)) return false; try { delAccount(dbi, (int8)V_TYPE_RESETPASSWORD, name); } catch (...) { } return true; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), preferences(NULL), _consoleWindow(NULL), _stateDebugDialog(NULL) { ui->setupUi(this); /* Setup the taskbar icon */ sysTray = new QSystemTrayIcon(QIcon(":/images/taskbar_icon"), this); sysTray->setToolTip(tr("FSComm")); /* Connect DTMF buttons */ dialpadMapper = new QSignalMapper(this); connect(ui->dtmf0Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf1Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf2Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf3Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf4Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf5Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf6Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf7Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf8Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf9Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmfABtn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmfBBtn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmfCBtn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmfDBtn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmfAstBtn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmfPoundBtn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); dialpadMapper->setMapping(ui->dtmf0Btn, QString("0")); dialpadMapper->setMapping(ui->dtmf1Btn, QString("1")); dialpadMapper->setMapping(ui->dtmf2Btn, QString("2")); dialpadMapper->setMapping(ui->dtmf3Btn, QString("3")); dialpadMapper->setMapping(ui->dtmf4Btn, QString("4")); dialpadMapper->setMapping(ui->dtmf5Btn, QString("5")); dialpadMapper->setMapping(ui->dtmf6Btn, QString("6")); dialpadMapper->setMapping(ui->dtmf7Btn, QString("7")); dialpadMapper->setMapping(ui->dtmf8Btn, QString("8")); dialpadMapper->setMapping(ui->dtmf9Btn, QString("9")); dialpadMapper->setMapping(ui->dtmfABtn, QString("A")); dialpadMapper->setMapping(ui->dtmfBBtn, QString("B")); dialpadMapper->setMapping(ui->dtmfCBtn, QString("C")); dialpadMapper->setMapping(ui->dtmfDBtn, QString("D")); dialpadMapper->setMapping(ui->dtmfAstBtn, QString("*")); dialpadMapper->setMapping(ui->dtmfPoundBtn, QString("#")); connect(dialpadMapper, SIGNAL(mapped(QString)), this, SLOT(sendDTMF(QString))); /* Connect events related to FreeSWITCH */ connect(g_FSHost, SIGNAL(ready()),this, SLOT(fshostReady())); connect(g_FSHost, SIGNAL(ringing(QSharedPointer<Call>)), this, SLOT(ringing(QSharedPointer<Call>))); connect(g_FSHost, SIGNAL(answered(QSharedPointer<Call>)), this, SLOT(answered(QSharedPointer<Call>))); connect(g_FSHost, SIGNAL(hungup(QSharedPointer<Call>)), this, SLOT(hungup(QSharedPointer<Call>))); connect(g_FSHost, SIGNAL(newOutgoingCall(QSharedPointer<Call>)), this, SLOT(newOutgoingCall(QSharedPointer<Call>))); connect(g_FSHost, SIGNAL(callFailed(QSharedPointer<Call>)), this, SLOT(callFailed(QSharedPointer<Call>))); connect(g_FSHost, SIGNAL(accountStateChange(QSharedPointer<Account>)), this, SLOT(accountStateChanged(QSharedPointer<Account>))); connect(g_FSHost, SIGNAL(newAccount(QSharedPointer<Account>)), this, SLOT(accountAdd(QSharedPointer<Account>))); connect(g_FSHost, SIGNAL(delAccount(QSharedPointer<Account>)), this, SLOT(accountDel(QSharedPointer<Account>))); connect(g_FSHost, SIGNAL(coreLoadingError(QString)), this, SLOT(coreLoadingError(QString))); /* Connect call commands */ connect(ui->newCallBtn, SIGNAL(clicked()), this, SLOT(makeCall())); connect(ui->answerBtn, SIGNAL(clicked()), this, SLOT(paAnswer())); connect(ui->hangupBtn, SIGNAL(clicked()), this, SLOT(paHangup())); connect(ui->recoredCallBtn, SIGNAL(toggled(bool)), SLOT(recordCall(bool))); connect(ui->btnHold, SIGNAL(toggled(bool)), this, SLOT(holdCall(bool))); /*connect(ui->btnTransfer, SIGNAL(clicked()), this, SLOT(transferCall()));*/ connect(ui->tableCalls, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(callTableDoubleClick(QTableWidgetItem*))); connect(ui->action_Preferences, SIGNAL(triggered()), this, SLOT(prefTriggered())); connect(ui->action_Exit, SIGNAL(triggered()), this, SLOT(close())); connect(ui->actionConsole, SIGNAL(triggered()), this, SLOT(debugConsoleTriggered())); connect(ui->actionEvents, SIGNAL(triggered()), this, SLOT(debugEventsTriggered())); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAbout())); connect(ui->actionSetDefaultAccount, SIGNAL(triggered(bool)), this, SLOT(setDefaultAccount())); connect(sysTray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(sysTrayActivated(QSystemTrayIcon::ActivationReason))); /* Set the context menus */ ui->tableAccounts->addAction(ui->actionSetDefaultAccount); /* Set other properties */ ui->tableAccounts->horizontalHeader()->setStretchLastSection(true); /* Set the call timer */ callTimer = new QTimer(this); callTimer->setInterval(1000); connect(callTimer, SIGNAL(timeout()), this, SLOT(updateCallTimers())); callTimer->start(); }