virtual void onCall(const sg::rpc::Uri& target) { common::ConversationID conv_id(getFrom()); common::UserPointID usr_ptid(getRequestData().sender_ua_uri()); common::UserPointID target_ptid(target); LOG(info, "recv msg from " << usr_ptid << " to " << target_ptid << " conversation id =: " << conv_id); LOG(info, "msgid=" << getRequestData().msg_id() << ", content: " << getRequestData().content()); }
void MethodAckChatMsg::onCall(const sg::rpc::Uri& target) { common::UserPointID user_ptid(getFrom()); common::UserID sender_user_id(getRequestData().sender_usr_id()); InstantMessagingService::instance()->getUsersManager().getUser( user_ptid)->ackChatMessage(sender_user_id, getRequestData().msg_id()); reply(target); }
void MethodNewSession::onCall(const sg::rpc::Uri& target) { rpc::NewSessionResponse resp; UserAccessService::instance()->getSessionsManager().generateNewSession( getRequestData().uid(), getRequestData().extra_uri_info(), resp.mutable_session(), resp.mutable_nonce()); resp.set_ua_ipaddr( UserAccessService::instance()->getProperties().get<string>( "server.address")); reply(target, resp); }
void YunClient::startRequest(QByteArray url) { #ifndef QREQUEST qDebug() << " request url : " << url; std::string std_url = url.toStdString(); // "http://121.40.218.177:8080/ml/rs/mediaReleaseVersions/1/10/null/null/90001"; std::string readData; CurlUpload *curl = new CurlUpload(); QString data = curl->getRequest(std_url, readData); delete curl; QJsonObject dataJson = getRequestData(QString(data)); QJsonArray listJson = setPagingInfo(dataJson); setVersionList(listJson); #else QNetworkRequest request; request.setUrl(QUrl(url)); manager = new QNetworkAccessManager(this); //发送GET请求 reply = manager->get(request); //连接请求结束信号 disconnect(reply); connect(reply, &QNetworkReply::finished, this, &YunClient::replyFinished); 连接响应时返回数据信号 connect(reply, &QNetworkReply::readyRead, this, &YunClient::readyRead); 请求更新进度 connect(reply, &QNetworkReply::downloadProgress, this, &YunClient::updateDataReadProgress); #endif }
bool LocalNode::_cmdDisconnect( Command& command ) { EQASSERT( _inReceiverThread( )); const NodeDisconnectPacket* packet = command.get< NodeDisconnectPacket >(); NodePtr node = static_cast<Node*>( getRequestData( packet->requestID )); EQASSERT( node.isValid( )); ConnectionPtr connection = node->_outgoing; if( connection.isValid( )) { node->_state = STATE_CLOSED; node->_outgoing = 0; _removeConnection( connection ); EQASSERT( _connectionNodes.find( connection )!=_connectionNodes.end( )); _objectStore->removeInstanceData( node->_id ); _connectionNodes.erase( connection ); { base::ScopedMutex< base::SpinLock > mutex( _nodes ); _nodes->erase( node->_id ); } EQINFO << node << " disconnected from " << this << " connection used " << connection->getRefCount() << std::endl; } EQASSERT( node->_state == STATE_CLOSED ); serveRequest( packet->requestID ); return true; }
void YunClient::readyRead() { if (reply->error() == QNetworkReply::NoError){ QByteArray str = reply->readAll(); qDebug() << " request return ::: " << str; QJsonObject dataJson = getRequestData(QString(str)); switch (request_type) { case get_version_list:{ QJsonArray listJson = setPagingInfo(dataJson); setVersionList(listJson); break; } case get_media_list:{ setUpdateList(dataJson); break; } default: break; } } else { //获取响应的信息,状态码为200表示正常 QVariant status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); qDebug() << "request error! return code : " << status_code; } }
void MethodAuth::onCall(const sg::rpc::Uri& target) { // bus验证密码 sg::Proxy bus_proxy( AuthService::instance()->getRoutingTable()->getHandler(SVC_BUSSINESS)); sg::rpc::Uri bustarget; common::createUri(&bustarget, SVC_BUSSINESS); bus_proxy.target(bustarget); business_server::methods::rpc::AuthenRequest auth_req; auth_req.set_auth_type(getRequestData().auth_type()); auth_req.set_auth_data(getRequestData().auth_data()); auth_req.set_uid(getRequestData().uid()); business_server::methods::rpc::AuthenResponse auth_resp; bus_proxy.call<business_server::methods::rpc::Authen>(auth_req, &auth_resp); common::user_id_t uid = auth_resp.uid(); if (getRequestData().has_uid() && getRequestData().uid() != uid) THROW_APP_EXCEPTION(sg::rpc::EC_RPC_APPLICATION_ERROR, "uid inconsistent."); // ua创建新session sg::Proxy ua_proxy( AuthService::instance()->getRoutingTable()->getHandler( SVC_USER_ACCESS, AuthService::instance()->getProperties().get<string>("server.line"))); user_access_server::methods::rpc::NewSessionRequest newsession_req; newsession_req.set_uid(uid); newsession_req.set_allocated_extra_uri_info(auth_resp.release_extra_uri_info()); user_access_server::methods::rpc::NewSessionResponse newsession_resp; ua_proxy.call<user_access_server::methods::rpc::NewSession>(newsession_req, &newsession_resp); rpc::AuthResponse resp; resp.set_uid(uid); resp.set_allocated_ua_ipaddr(newsession_resp.release_ua_ipaddr()); resp.set_allocated_session(newsession_resp.release_session()); resp.set_allocated_nonce(newsession_resp.release_nonce()); resp.set_allocated_extra_data(auth_resp.release_extra_data()); resp.set_curtime(::time(NULL)); reply(target, resp); }
void MethodRegister::onCall(const sg::rpc::Uri& target) { if (!getFrom().has_service_type() || getFrom().service_type().empty()) THROW_APP_EXCEPTION(sg::rpc::EC_RPC_INVALID_PARAMS, "missing service type field!"); base::net::SockAddr sockaddr(getHandler()->addr().getAddr().c_str(), getRequestData().routing_port()); common::ServerID svc_id(getFrom()); ConfigService::instance()->getServersList().addServer( svc_id, sockaddr, boost::static_pointer_cast<ServerConnectionHandler>(getHandler()), getRequestData().info(), getRequestData().overwrite_if_exist()); rpc::RegisterResponse resp; resp.set_service_number(svc_id.svc_num); reply(target, resp); }
void MethodSaveSysMsgs::onCall(const sg::rpc::Uri& target) { common::UserID uid(target); if (getRequestData().msgs_size()) { mongo::BSONArrayBuilder objarray_msgdata; mongo::BSONObj obj_lastmsgdata; for (int i=0; i<getRequestData().msgs_size(); ++i) { const methods::rpc::SysMsgData& data = getRequestData().msgs(i); mongo::BSONObjBuilder obj_msgdata; obj_msgdata.append(COLL_SYSMSGS_DATA_MSGID, (long long)data.sysmsg_id()). appendTimeT(COLL_SYSMSGS_DATA_TIME, data.sysmsg_time()). append(COLL_SYSMSGS_DATA_MSG_TYPE, data.sysmsg_type()). append(COLL_SYSMSGS_DATA_MSG_DATA, data.sysmsg_data()); objarray_msgdata.append(obj_msgdata.done()); if (i == getRequestData().msgs_size() - 1) obj_lastmsgdata = obj_msgdata.obj(); } mongo::ScopedDbConnection conn( MongoDBManagerSingleton::instance().host()); conn->update(COLL_SYSMSGS, QUERY(COLL_SYSMSGS_UID << uid.toString() << COLL_SYSMSGS_CHANNEL << getRequestData().channel()), BSON("$pushAll" << BSON(COLL_SYSMSGS_DATA << objarray_msgdata.arr())), mongo::UpdateOption_Upsert); time_t contacttime = getRequestData().msgs().rbegin()->sysmsg_time(); long long last_msgid = getRequestData().msgs().rbegin()->sysmsg_id(); mongo::BSONObjBuilder obj_builder; obj_builder.appendTimeT(COLL_RECENTCONTACTS_SYS"."COLL_RECENTCONTACTS_SYS_TIME, contacttime). append(COLL_RECENTCONTACTS_SYS"."COLL_RECENTCONTACTS_SYS_MSG, obj_lastmsgdata); mongo::BSONObj obj_contact = BSON("$set" << obj_builder.done()); if (uid.isLocalDomain()) { conn->update(COLL_RECENTCONTACTS, QUERY(COLL_RECENTCONTACTS_UID << uid.toString() << COLL_RECENTCONTACTS_SYS"."COLL_RECENTCONTACTS_SYS_CHANNEL << getRequestData().channel()), obj_contact, mongo::UpdateOption_Upsert); } conn.done(); } reply(target); }
void MethodSendGrpChatMsg::onCall(const sg::rpc::Uri& target) { common::UserPointID sender_ptid(getFrom()); common::GroupID group_id(target); uint32_t msg_time = ::time(NULL); common::msg_id_t msg_id = GroupMessagingService::instance()->getGroupsManager().createGroup( target)->sendChatMessage(sender_ptid, msg_time, getRequestData().content_type(), getRequestData().content()); rpc::SendGrpChatMsgResponse resp; resp.set_msg_id(msg_id); resp.set_msg_time(msg_time); reply(target, resp); }
void MethodUpdateStatus::onCall(const sg::rpc::Uri& target) { if (!getFrom().has_service_number()) THROW_APP_EXCEPTION(sg::rpc::EC_RPC_INVALID_PARAMS, "service id is empty."); ConfigService::instance()->getServersList().updateServerStatus( common::ServerID(getFrom()), boost::static_pointer_cast<ServerConnectionHandler>(getHandler()), getRequestData().status()); reply(target); }
void MethodRemoveRecentContacts::onCall(const sg::rpc::Uri& target) { if (getRequestData().user_ids_size()) { common::UserID uid(common::UserPointID(this->getFrom())); mongo::ScopedDbConnection conn( MongoDBManagerSingleton::instance().host()); mongo::BSONArrayBuilder contactsBuilder; for (int i=0; i<getRequestData().user_ids_size(); ++i) { contactsBuilder << common::UserID(getRequestData().user_ids(i)).toString(); } conn->remove(COLL_RECENTCONTACTS, QUERY(COLL_RECENTCONTACTS_UID << uid.toString() << "$or" << BSON(COLL_RECENTCONTACTS_CONTACT << contactsBuilder.arr()))); conn.done(); } reply(target); }
void MethodSendUserNotice::onCall(const sg::rpc::Uri& target) { common::UserID target_user_id(target); uint32_t notice_time = ::time(NULL); base::ErrorCode ec; boost::shared_ptr<User> sp_user = InstantMessagingService::instance()->getUsersManager().getUser( target_user_id, &ec); if (sp_user) { sp_user->sendUserNotice( getFrom(), notice_time, getRequestData().user_notice_type(), getRequestData().user_notice_data()); } rpc::SendUserNoticeResponse resp; resp.set_notice_time(notice_time); reply(target, resp); }
void MethodOpenService::onCall(const sg::rpc::Uri& target) { boost::shared_ptr<UserPoint> sp_point = UserAccessService::instance()->getUserPointsManager().getUserPoint( boost::static_pointer_cast<ClientHandler>(getHandler())); sg::Proxy proxy( UserAccessService::instance()->getRoutingTable()->getHandler( sp_point->getID().uid, getRequestData().svc_uri())); proxy.target(getRequestData().svc_uri()); common::rpc::OpenRequest open_request; sp_point->getID().serializeToUserAccessUri(open_request.mutable_ua_cli_uri()); open_request.set_params(getRequestData().open_params()); boost::shared_ptr<AsyncTask> asyn_task( new AsyncTask(this->shared_from_this(), target, boost::bind(&MethodOpenService::openCallback, this, _1, _2, boost::weak_ptr<UserPoint>(sp_point), proxy.getHandler()))); proxy.call<common::rpc::Open>(open_request, asyn_task, getExpiredMilliSecs()); }
void MethodGetRecentContacts::onCall(const sg::rpc::Uri& target) { common::UserID uid(common::UserPointID(this->getFrom())); mongo::BSONObj returnfield = BSON(COLL_RECENTCONTACTS_CONTACT << 1); mongo::ScopedDbConnection conn( MongoDBManagerSingleton::instance().host()); auto_ptr<mongo::DBClientCursor> cursor = conn->query( COLL_RECENTCONTACTS, QUERY(COLL_RECENTCONTACTS_UID << uid.toString()).sort(COLL_RECENTCONTACTS_CONTACT"."COLL_RECENTCONTACTS_CONTACT_TIME, -1), getRequestData().max_count(), 0, &returnfield); methods::rpc::GetRecentContactsResponse resp; while (cursor->more()) { mongo::BSONObj p = cursor->nextSafe(); methods::rpc::GetRecentContactsResponse_Contact* contact = resp.add_contacts(); common::UserID contact_uid; contact_uid.parseFromString(p[COLL_RECENTCONTACTS_CONTACT_UID].String()); contact_uid.get(contact->mutable_user_id()); bool flag = p[COLL_CHATMSGS_DATA_FLAG].Int(); if (contact_uid.uid < uid.uid) flag = !flag; methods::rpc::ChatMsgData* pdata = contact->mutable_last_msg(); pdata->set_flag(flag ? methods::rpc::ChatMsgData_Flag_FLAG_RECV : methods::rpc::ChatMsgData_Flag_FLAG_SEND); pdata->set_msg_id(p[COLL_CHATMSGS_DATA_MSGID].Long()); pdata->set_msg_time(p[COLL_CHATMSGS_DATA_TIME].Date().toTimeT()); p[COLL_CHATMSGS_DATA_CONTENT_TYPE].Val(*pdata->mutable_content_type()); p[COLL_CHATMSGS_DATA_CONTENT].Val(*pdata->mutable_content()); } conn.done(); reply(target, resp); }
void YunClient::requestVersionInfo(const int &row) { QStringList rowValue = rowList.at(row); QString verId = rowValue.at(1); QString verName = rowValue.at(2); qDebug() << "version id :" << verId << "version name : " << verName; if(!verId.toInt()){ qDebug() << "version id error!"; return; } request_type = get_media_list; QByteArray url = host.toLatin1() + "/ml/rs/mediaReleaseVersions/" + verId.toLatin1(); #ifndef QREQUEST std::string std_url = url.toStdString(); std::string readData; CurlUpload *curl = new CurlUpload(); QString data = curl->getRequest(std_url, readData); #else startRequest(url); #endif bool isUpdate = false; if (rowValue.last().compare("已更新") == 0) isUpdate = true; dialog = new YunDM(); dialog->initSqlAndVersion(_sql, verId, verName, isUpdate); connect(this, &YunClient::sqlValue, dialog, &YunDM::setSqlValue); #ifndef QREQUEST QJsonObject dataJson = getRequestData(data); setUpdateList(dataJson); #else #endif dialog->exec(); getUpdateVersionList(); }
int SslOcspStapling::createRequest() { int len, len64, n1; unsigned char *pReqData, *pReqData64; unsigned char ReqData[4000], ReqData64[4000]; struct stat st; if (::stat(m_sRespfileTmp.c_str(), &st) == 0) return 0; pReqData = ReqData; pReqData64 = ReqData64; len = getRequestData(pReqData); if (len <= 0) return LS_FAIL; len64 = ls_base64_encode((const char *)ReqData, len, (char *)pReqData64); const char *pUrl = m_sOcspResponder.c_str(); memcpy(pReqData, pUrl, m_sOcspResponder.len()); pReqData += m_sOcspResponder.len(); if (pUrl[m_sOcspResponder.len() - 1] != '/') *pReqData++ = '/'; n1 = escapeBase64Uri(pReqData64, len64, pReqData); pReqData += n1; *pReqData = 0; len = pReqData - ReqData; if (m_pHttpFetch != NULL) delete m_pHttpFetch; m_pHttpFetch = new HttpFetch(); m_pHttpFetch->setResProcessor(OcspRespCb, this); m_pHttpFetch->setTimeout(30); //Set Req timeout as 30 seconds m_pHttpFetch->startReq((const char *)ReqData, 1, 1, NULL, 0, m_sRespfileTmp.c_str(), NULL, m_addrResponder); setLastErrMsg("%lu, len = %d\n%s \n", m_pHttpFetch, len, ReqData); //printf("%s\n", s_ErrMsg.c_str()); return 0; }
bool LocalNode::_cmdConnectReply( Command& command ) { EQASSERT( !command.getNode( )); EQASSERT( _inReceiverThread( )); const NodeConnectReplyPacket* packet = command.get< NodeConnectReplyPacket >(); ConnectionPtr connection = _incoming.getConnection(); const NodeID& nodeID = packet->nodeID; EQVERB << "handle connect reply " << packet << std::endl; EQASSERT( _connectionNodes.find( connection ) == _connectionNodes.end( )); NodePtr remoteNode; // No locking needed, only recv thread modifies NodeHash::const_iterator i = _nodes->find( nodeID ); if( i != _nodes->end( )) remoteNode = i->second; if( nodeID == NodeID::ZERO || // connection refused // Node exists, probably simultaneous connect ( remoteNode.isValid() && remoteNode->isConnected( ))) { EQINFO << "ignoring connect reply, node already connected" << std::endl; _removeConnection( connection ); if( packet->requestID != EQ_UNDEFINED_UINT32 ) serveRequest( packet->requestID, false ); return true; } // create and add node if( !remoteNode ) { if( packet->requestID != EQ_UNDEFINED_UINT32 ) { void* ptr = getRequestData( packet->requestID ); EQASSERT( dynamic_cast< Node* >( (Dispatcher*)ptr )); remoteNode = static_cast< Node* >( ptr ); } else remoteNode = createNode( packet->nodeType ); } EQASSERT( remoteNode->getType() == packet->nodeType ); EQASSERT( remoteNode->_state == STATE_CLOSED ); std::string data = packet->nodeData; if( !remoteNode->deserialize( data )) EQWARN << "Error during node initialization" << std::endl; EQASSERT( data.empty( )); EQASSERT( remoteNode->_id == nodeID ); remoteNode->_outgoing = connection; remoteNode->_state = STATE_CONNECTED; _connectionNodes[ connection ] = remoteNode; { base::ScopedMutex< base::SpinLock > mutex( _nodes ); _nodes.data[ remoteNode->_id ] = remoteNode; } EQVERB << "Added node " << nodeID << std::endl; if( packet->requestID != EQ_UNDEFINED_UINT32 ) serveRequest( packet->requestID, true ); NodeConnectAckPacket ack; remoteNode->send( ack ); _connectMulticast( remoteNode ); return true; }