void _pmdSession::detach () { PD_LOG( PDINFO, "Session[%s] detach edu[%d]", sessionName(), eduID() ) ; _onDetach() ; clear() ; _client.detachCB() ; _pEDUCB->detachSession() ; _pEDUCB->setClientSock( NULL ) ; _pEDUCB = NULL ; }
int LoginData::userSession(int user_index) { QString user_session = data(user_index, m_UsersModel, QLightDM::UsersModel::SessionRole); for (int i = 0; i < m_SessionsModel.rowCount(QModelIndex()); i++) { if (sessionName(i) == user_session) { return i; } } return -1; }
void _pmdSession::attach( _pmdEDUCB * cb ) { SDB_ASSERT( cb, "cb can't be NULL" ) ; PD_LOG( PDINFO, "Session[%s] attach edu[%d]", sessionName(), cb->getID() ) ; _pDPSCB = pmdGetKRCB()->getDPSCB() ; if ( SDB_ROLE_COORD != pmdGetDBRole() && _pDPSCB && !_pDPSCB->isLogLocal() ) { _pDPSCB = NULL ; } _pEDUCB = cb ; _eduID = cb->getID() ; _pEDUCB->attachSession( this ) ; _pEDUCB->setName( sessionName() ) ; _pEDUCB->setClientSock( socket() ) ; _client.attachCB( cb ) ; _onAttach() ; }
INT32 _mongoSession::_onMsgEnd( INT32 result, MsgHeader *msg ) { if ( result && SDB_DMS_EOC != result ) { PD_LOG( PDWARNING, "Session[%s] process msg[opCode=%d, len: %d, " "TID: %d, requestID: %llu] failed, rc: %d", sessionName(), msg->opCode, msg->messageLength, msg->TID, msg->requestID, result ) ; } MON_END_OP( _pEDUCB->getMonAppCB() ) ; return SDB_OK ; }
int LoginData::suggestedSession() { int suggestedSessionIndex = 0; for (int i = 0; i < numberOfSessions(); i++) { if (sessionName(i) == "razor") { suggestedSessionIndex = i; break; } } return suggestedSessionIndex; }
INT32 _mongoSession::run() { INT32 rc = SDB_OK ; BOOLEAN bigEndian = FALSE ; UINT32 msgSize = 0 ; UINT32 headerLen = sizeof( mongoMsgHeader ) - sizeof( INT32 ) ; INT32 bodyLen = 0 ; engine::pmdEDUMgr *pmdEDUMgr = NULL ; CHAR *pBuff = NULL ; const CHAR *pBody = NULL ; const CHAR *pInMsg = NULL ; engine::monDBCB *mondbcb = engine::pmdGetKRCB()->getMonDBCB() ; if ( !_pEDUCB ) { rc = SDB_SYS ; goto error ; } pmdEDUMgr = _pEDUCB->getEDUMgr() ; bigEndian = checkBigEndian() ; while ( !_pEDUCB->isDisconnected() && !_socket.isClosed() ) { _pEDUCB->resetInterrupt() ; _pEDUCB->resetInfo( engine::EDU_INFO_ERROR ) ; _pEDUCB->resetLsn() ; rc = recvData( (CHAR*)&msgSize, sizeof(UINT32) ) ; if ( rc ) { if ( SDB_APP_FORCED != rc ) { PD_LOG( PDERROR, "Session[%s] failed to recv msg size, " "rc: %d", sessionName(), rc ) ; } break ; } if ( bigEndian ) { } if ( msgSize < headerLen || msgSize > SDB_MAX_MSG_LENGTH ) { PD_LOG( PDERROR, "Session[%s] recv msg size[%d] is less than " "mongoMsgHeader size[%d] or more than max msg size[%d]", sessionName(), msgSize, sizeof( mongoMsgHeader ), SDB_MAX_MSG_LENGTH ) ; rc = SDB_INVALIDARG ; break ; } else { pBuff = getBuff( msgSize + 1 ) ; if ( !pBuff ) { rc = SDB_OOM ; break ; } *(UINT32*)pBuff = msgSize ; rc = recvData( pBuff + sizeof(UINT32), msgSize - sizeof(UINT32) ) ; if ( rc ) { if ( SDB_APP_FORCED != rc ) { PD_LOG( PDERROR, "Session[%s] failed to recv rest msg, rc: %d", sessionName(), rc ) ; } break ; } pBuff[ msgSize ] = 0 ; { _resetBuffers() ; _converter.loadFrom( pBuff, msgSize ) ; rc = _converter.convert( _inBuffer ) ; if ( SDB_OK != rc && SDB_OPTION_NOT_SUPPORT != rc) { goto error ; } _pEDUCB->incEventCount() ; mondbcb->addReceiveNum() ; if ( SDB_OK != ( rc = pmdEDUMgr->activateEDU( _pEDUCB ) ) ) { PD_LOG( PDERROR, "Session[%s] activate edu failed, rc: %d", sessionName(), rc ) ; goto error ; } if ( _preProcessMsg( _converter.getParser(), _resource, _contextBuff ) ) { goto reply ; } pInMsg = _inBuffer.data() ; while ( NULL != pInMsg ) { rc = _processMsg( pInMsg ) ; if ( SDB_OK == rc ) { _authed = TRUE ; } rc = _converter.reConvert( _inBuffer, &_replyHeader ) ; if ( SDB_OK != rc ) { goto reply ; } else { if ( !_inBuffer.empty() ) { _contextBuff.release() ; pInMsg = _inBuffer.data() ; } else { pInMsg = NULL ; } } } reply: _handleResponse( _converter.getOpType(), _contextBuff ) ; pBody = _contextBuff.data() ; bodyLen = _contextBuff.size() ; INT32 rcTmp = _reply( &_replyHeader, pBody, bodyLen ) ; if ( rcTmp ) { PD_LOG( PDERROR, "Session[%s] failed to send response," "rc: %d", sessionName(), rcTmp ) ; goto error ; } pBody = NULL ; bodyLen = 0 ; _contextBuff.release() ; if ( SDB_OK != ( rc = pmdEDUMgr->waitEDU( _pEDUCB ) ) ) { PD_LOG( PDERROR, "Session[%s] wait edu failed, rc: %d", sessionName(), rc ) ; goto error ; } } } } // end while done: disconnect() ; return rc ; error: goto done ; }
INT32 _mongoSession::_setSeesionAttr() { INT32 rc = SDB_OK ; engine::pmdEDUMgr *pmdEDUMgr = _pEDUCB->getEDUMgr() ; const CHAR *cmd = CMD_ADMIN_PREFIX CMD_NAME_SETSESS_ATTR ; MsgOpQuery *set = NULL ; bson::BSONObj obj ; bson::BSONObj emptyObj ; msgBuffer msgSetAttr ; if ( _masterRead ) { goto done ; } msgSetAttr.reverse( sizeof( MsgOpQuery ) ) ; msgSetAttr.advance( sizeof( MsgOpQuery ) - 4 ) ; obj = BSON( FIELD_NAME_PREFERED_INSTANCE << PREFER_REPL_MASTER ) ; set = (MsgOpQuery *)msgSetAttr.data() ; set->header.opCode = MSG_BS_QUERY_REQ ; set->header.TID = 0 ; set->header.routeID.value = 0 ; set->header.requestID = 0 ; set->version = 0 ; set->w = 0 ; set->padding = 0 ; set->flags = 0 ; set->nameLength = ossStrlen(cmd) ; set->numToSkip = 0 ; set->numToReturn = -1 ; msgSetAttr.write( cmd, set->nameLength + 1, TRUE ) ; msgSetAttr.write( obj, TRUE ) ; msgSetAttr.write( emptyObj, TRUE ) ; msgSetAttr.write( emptyObj, TRUE ) ; msgSetAttr.write( emptyObj, TRUE ) ; msgSetAttr.doneLen() ; if ( SDB_OK != ( rc = pmdEDUMgr->activateEDU( _pEDUCB ) ) ) { PD_LOG( PDERROR, "Session[%s] activate edu failed, rc: %d", sessionName(), rc ) ; goto error ; } rc = _processMsg( msgSetAttr.data() ) ; if ( SDB_OK != rc ) { goto error ; } _masterRead = TRUE ; if ( SDB_OK != ( rc = pmdEDUMgr->waitEDU( _pEDUCB ) ) ) { PD_LOG( PDERROR, "Session[%s] wait edu failed, rc: %d", sessionName(), rc ) ; goto error ; } done: return rc ; error: goto done ; }
INT32 _mongoSession::_reply( MsgOpReply *replyHeader, const CHAR *pBody, const INT32 len ) { INT32 rc = SDB_OK ; INT32 offset = 0 ; mongoMsgReply reply ; bson::BSONObjBuilder bob ; bson::BSONObj bsonBody ; bson::BSONObj objToSend ; mongoDataPacket &packet = _converter.getParser().dataPacket() ; if ( OP_KILLCURSORS == _converter.getOpType() || dbInsert == packet.opCode || dbUpdate == packet.opCode || dbDelete == packet.opCode ) { goto done; } reply.header.requestId = 0 ;//replyHeader->header.requestID ; reply.header.responseTo = packet.requestId ; reply.header.opCode = dbReply ; reply.header.flags = 0 ; reply.header.version = 0 ; reply.header.reservedFlags = 0 ; if ( SDB_AUTH_AUTHORITY_FORBIDDEN == replyHeader->flags ) { reply.header.reservedFlags |= 2 ; } if ( -1 != replyHeader->contextID ) { _cursorStartFrom.cursorId = reply.cursorId ; reply.startingFrom = replyHeader->startFrom ; _cursorStartFrom.startFrom = reply.startingFrom + replyHeader->numReturned ; } else { if ( replyHeader->contextID == _cursorStartFrom.cursorId ) { reply.startingFrom = _cursorStartFrom.startFrom ; } else { reply.startingFrom = 0; } _cursorStartFrom.cursorId = 0 ; _cursorStartFrom.startFrom = 0 ; } if ( SDB_OK != replyHeader->flags ) { reply.cursorId = 0 ; } else { reply.cursorId = replyHeader->contextID + 1 ; } if ( packet.with( OPTION_CMD ) && OP_GETMORE != _converter.getOpType() ) { reply.nReturned = ( replyHeader->numReturned > 0 ? replyHeader->numReturned : 1 ) ; } else { reply.nReturned = replyHeader->numReturned ; } if ( reply.nReturned > 1 ) { while ( offset < len ) { bsonBody.init( pBody + offset ) ; _outBuffer.write( bsonBody.objdata(), bsonBody.objsize() ) ; offset += ossRoundUpToMultipleX( bsonBody.objsize(), 4 ) ; } } else { if ( pBody ) { if ( 0 == reply.cursorId && ( SDB_OK == _replyHeader.flags && OP_QUERY != _converter.getOpType() ) ) { bsonBody.init( pBody ) ; if ( !bsonBody.hasField( "ok" ) ) { bob.append( "ok", 0 == replyHeader->flags ? TRUE : FALSE ) ; bob.append( "code", replyHeader->flags ) ; bob.append( "err", _errorInfo.getStringField( OP_ERRDESP_FIELD) ) ; bob.appendElements( bsonBody ) ; objToSend = bob.obj() ; _outBuffer.write( objToSend ) ; } else { _outBuffer.write( bsonBody ) ; } } else { bsonBody.init( pBody ) ; _outBuffer.write( bsonBody ) ; } } else { if ( OP_GETMORE != _converter.getOpType() && OP_CMD_GET_INDEX == _converter.getOpType() ) { bob.append( "ok", 1.0 ) ; objToSend = bob.obj() ; _outBuffer.write( objToSend ) ; } } } if ( !_outBuffer.empty() ) { pBody = _outBuffer.data() ; } reply.header.msgLen = sizeof( mongoMsgReply ) + _outBuffer.size() ; rc = sendData( (CHAR *)&reply, sizeof( mongoMsgReply ) ) ; if ( rc ) { PD_LOG( PDERROR, "Session[%s] failed to send response header, rc: %d", sessionName(), rc ) ; goto error ; } if ( pBody ) { rc = sendData( pBody, reply.header.msgLen - sizeof( mongoMsgReply ) ) ; if ( rc ) { PD_LOG( PDERROR, "Session[%s] failed to send response body, rc: %d", sessionName(), rc ) ; goto error ; } } done: return rc ; error: goto done ; }
INT32 _mongoSession::_reply( MsgOpReply *replyHeader, const CHAR *pBody, const INT32 len ) { INT32 rc = SDB_OK ; INT32 offset = 0 ; mongoMsgReply reply ; bson::BSONObjBuilder bob ; bson::BSONObj bsonBody ; reply.header.id = 0 ; reply.header.responseTo = replyHeader->header.requestID ; reply.header.opCode = dbReply ; reply.header._flags = 0 ; reply.header._version = 0 ; reply.header.reservedFlags = 0 ; reply.cursorId = ( -1 == replyHeader->contextID ? 0 : replyHeader->contextID ) ; reply.startingFrom = replyHeader->startFrom ; if ( _converter->getParser().withCmd || _needReply ) { reply.nReturned = replyHeader->numReturned > 0 ? replyHeader->numReturned : 1 ; } else { reply.nReturned = replyHeader->numReturned ; } if ( !_converter->getParser().withCmd && reply.nReturned > 0 ) { while ( offset < len ) { bsonBody.init( pBody + offset ) ; _outBuffer.write( bsonBody.objdata(), bsonBody.objsize() ) ; offset += ossRoundUpToMultipleX( bsonBody.objsize(), 4 ) ; } pBody = _outBuffer.data() ; reply.header.len = sizeof( mongoMsgReply ) + _outBuffer.size() ; } else { if ( pBody ) { bsonBody.init( pBody ) ; if ( !bsonBody.hasField( "ok" )) { bob.append( "ok", 0 == replyHeader->flags ? TRUE : replyHeader->flags ) ; bob.appendElements( bsonBody ) ; pBody = bob.done().objdata() ; reply.header.len = sizeof( mongoMsgReply ) + bob.done().objsize() ; } else { reply.header.len = sizeof( mongoMsgReply ) + len ; } } else { bob.append( "ok", 1.0 ) ; pBody = bob.done().objdata() ; reply.header.len = sizeof( mongoMsgReply ) + bob.done().objsize() ; } } rc = sendData( (CHAR *)&reply, sizeof( mongoMsgReply ) ) ; if ( rc ) { PD_LOG( PDERROR, "Session[%s] failed to send response header, rc: %d", sessionName(), rc ) ; goto error ; } if ( pBody ) { rc = sendData( pBody, reply.header.len - sizeof( mongoMsgReply ) ) ; if ( rc ) { PD_LOG( PDERROR, "Session[%s] failed to send response body, rc: %d", sessionName(), rc ) ; goto error ; } } bob.decouple() ; done: return rc ; error: goto done ; }
INT32 _mongoSession::run() { INT32 rc = SDB_OK ; BOOLEAN bigEndian = FALSE ; UINT32 msgSize = 0 ; UINT32 headerLen = sizeof( mongoMsgHeader ) - sizeof( INT32 ) ; CHAR *pBuff = NULL ; const CHAR *pBody = NULL ; INT32 bodyLen = 0 ; engine::pmdEDUMgr *pmdEDUMgr = NULL ; std::vector< msgBuffer * >::iterator itr ; if ( !_pEDUCB ) { rc = SDB_SYS ; goto error ; } pmdEDUMgr = _pEDUCB->getEDUMgr() ; bigEndian = checkBigEndian() ; while ( !_pEDUCB->isDisconnected() && !_socket.isClosed() ) { _pEDUCB->resetInterrupt() ; _pEDUCB->resetInfo( engine::EDU_INFO_ERROR ) ; _pEDUCB->resetLsn() ; rc = recvData( (CHAR*)&msgSize, sizeof(UINT32) ) ; if ( rc ) { if ( SDB_APP_FORCED != rc ) { PD_LOG( PDERROR, "Session[%s] failed to recv msg size, " "rc: %d", sessionName(), rc ) ; } break ; } if ( bigEndian ) { } if ( msgSize < headerLen || msgSize > SDB_MAX_MSG_LENGTH ) { PD_LOG( PDERROR, "Session[%s] recv msg size[%d] is less than " "mongoMsgHeader size[%d] or more than max msg size[%d]", sessionName(), msgSize, sizeof( mongoMsgHeader ), SDB_MAX_MSG_LENGTH ) ; rc = SDB_INVALIDARG ; break ; } else { pBuff = getBuff( msgSize + 1 ) ; if ( !pBuff ) { rc = SDB_OOM ; break ; } *(UINT32*)pBuff = msgSize ; rc = recvData( pBuff + sizeof(UINT32), msgSize - sizeof(UINT32) ) ; if ( rc ) { if ( SDB_APP_FORCED != rc ) { PD_LOG( PDERROR, "Session failed to recv rest msg, rc: %d", sessionName(), rc ) ; } break ; } pBuff[ msgSize ] = 0 ; { resetBuffers() ; _converter->loadFrom( pBuff, msgSize ) ; rc = _converter->convert( _inBufferVec ) ; if ( SDB_OK != rc ) { if ( SDB_OPTION_NOT_SUPPORT == rc ) { } else { goto error ; } } if ( _preProcessMsg( _converter->getParser(), _resource, _contextBuff ) ) { goto reply ; } itr = _inBufferVec.begin() ; for ( ; itr != _inBufferVec.end() ; ++itr ) { _pEDUCB->incEventCount() ; _needReply = FALSE ; if ( SDB_OK != ( rc = pmdEDUMgr->activateEDU( _pEDUCB ) ) ) { PD_LOG( PDERROR, "Session[%s] activate edu failed, rc: %d", sessionName(), rc ) ; goto error ; } rc = _processMsg( (*itr)->data() ) ; if ( rc ) { if ( SDB_DMS_CS_EXIST == rc && OP_CMD_CREATE == _converter->getOpType()) { _contextBuff.release() ; } else { goto reply ; } } if ( SDB_OK != ( rc = pmdEDUMgr->waitEDU( _pEDUCB ) ) ) { PD_LOG( PDERROR, "Session[%s] wait edu failed, rc: %d", sessionName(), rc ) ; goto error ; } } reply: pBody = _contextBuff.data() ; bodyLen = _contextBuff.size() ; INT32 rcTmp = _reply( &_replyHeader, pBody, bodyLen ) ; if ( rcTmp ) { PD_LOG( PDERROR, "Session[%s] failed to send response, rc: %d", sessionName(), rcTmp ) ; goto error ; } pBody = NULL ; bodyLen = 0 ; } } } // end while done: disconnect() ; return rc ; error: goto done ; }