示例#1
0
// the name is stored so that when it relays a message, it can indicate who it was from.
void cmdName(void *base, risp_length_t length, risp_data_t *data) 
{
	// At every opportunity, we need to make sure that our data is legit.
	assert(base != NULL);
	assert(length >= 0);
	assert(data != NULL);
	
	// the protocol allows a name up to 255 chars in length. 
	assert(length < 256);

	// The base pointer that is passed thru the library doesnt know about the session structure we 
	// are using, so we need to make a cast-pointer for it.
	session_t *session = (session_t *) base;
	assert(session);
	assert(session->id >= 0);
	printf("Session[%d] Received NAME\n", session->id);
	
	if (checkAuth(session) == true) {
		// copy the string that was provides from the stream (which is guaranteed to be complete)
		assert(length < 256);
		memcpy(session->data.name, data, length);
		session->data.name[length] = '\0';	// null-terminate it to make it easier to manipulate.
		printf("Session[%d]: Setting Name to '%s'\n", session->id, session->data.name);
	}
}
示例#2
0
//SSL Certificate register/revoke/list
bool AuthorizationManager::RegisterCertificate(QString token, QString pubkey, QString nickname, QString email){
  if(!checkAuth(token)){ return false; }
  QString user = hashID(token).section("::::",2,2); //get the user name from the currently-valid token
  //NOTE: The public key should be a base64 encoded string
  CONFIG->setValue("RegisteredCerts/"+user+"/"+pubkey, "Nickname: "+nickname+"\nEmail: "+email+"\nDate Registered: "+QDateTime::currentDateTime().toString(Qt::ISODate) );
  return true;
}
示例#3
0
AuthDialog::AuthDialog( Auth * auth ,  QWidget * parent )
:QDialog ( parent )
{
    m_auth = auth;
    setupUi( this );
    connect (okButton , SIGNAL(clicked() ) , this , SLOT(checkAuth()) );
    leUser->setFocus();
    setWindowTitle( tr("Auth") );
}
示例#4
0
文件: request.cpp 项目: tanakh/mongo
    void Request::process( int attempt ) {
        init();
        int op = _m.operation();
        assert( op > dbMsg );

        if ( op == dbKillCursors ) {
            cursorCache.gotKillCursors( _m );
            return;
        }


        MONGO_LOG(3) << "Request::process ns: " << getns() << " msg id:" << (int)(_m.header()->id) << " attempt: " << attempt << endl;

        Strategy * s = SHARDED;
        _counter = &opsNonSharded;

        _d.markSet();

        bool iscmd = false;
        if ( op == dbQuery ) {
            try {
                iscmd = isCommand();
                s->queryOp( *this );
            }
            catch ( RecvStaleConfigException& stale ) {
                _d.markReset();
                log( attempt == 0 ) << "got RecvStaleConfigException at top level: " << stale.toString() << " attempt: " << attempt << endl;
                massert( 16062 , "too many attemps to handle RecvStaleConfigException at top level" , attempt <= 5 );
                process( attempt + 1 );
                return;
            }
        }
        else if ( op == dbGetMore ) {
            checkAuth( Auth::READ ); // this is important so someone can't steal a cursor
            s->getMore( *this );
        }
        else {
            checkAuth( Auth::WRITE );
            s->writeOp( op, *this );
        }

        globalOpCounters.gotOp( op , iscmd );
        _counter->gotOp( op , iscmd );
    }
示例#5
0
/*
	0x9000  MESSAGE  (Bi-directional)
    
        When sent from a client, will take that parameter, and pass it (along with the msg ID and 
        name) to the other clients, depending on their FOLLOW or UPDATE modes.

        When sent from server to client, indicates that a message was received at the server, and 
        relayed to the client.  Will also be accompanied by a MSG_ID and a NAME command before the 
        MESSAGE.
        
        The MSG_ID can be used to update the ID of the latest message.  

        If the server is sending multiple messages from the same Name, it will only send Name once, 
        followed by the multiple messages.  Only when messages are being sent from different names, 
        will those entries also be included.
    
*/
void cmdMessage(void *base, risp_length_t length, risp_data_t *data) 
{
	session_t *session = (session_t *) base;
	
	// At every opportunity, we need to make sure that our data is legit.
	assert(base != NULL);
	assert(length >= 0);
	assert(data != NULL);
	
	// the protocol allows a message up to 64k chars in length.  If it is greater than that, then we ignore it.
	assert(length < 65536);
	if (length < 65536) {

		if (checkAuth(session) == true) {

			/// need to relay the message to each client that is connected and in follow mode (other than this 
			/// one, unless it has echo enabled).
			
			maindata_t *maindata = session->maindata;
			assert(maindata);
			
			// store the message in our messages store.
			long long msgID = message_new(maindata, session->data.name, length, (char *) data);
			assert(msgID > 0);

			// when we added the message to the messages array, it copied the message and ensured it was null 
			// termined, so we can now get a pointer to it.
			unsigned char *message = message_get_msg(maindata, msgID);
			unsigned char *name = message_get_name(maindata, msgID);
			
			printf("Session[%d]: Received Message '%s'\n", session->id, message); 

			//   Response for sessions in NOFOLLOW mode.
			//		CMD_LATEST_MSG_ID(integer)
			//
			//   Response for sessions in FOLLOW mode.
			//		CMD_MSG_ID(integer)
			//		CMD_NAME(string)	- If name is supplied.
			//		CMD_MESSAGE(string)

			// the sessions are referenced in an array. 
			assert(maindata);
			assert(maindata->sessions.list);
			assert(maindata->sessions.max > 0);
			for (int i=0; i<maindata->sessions.max; i++) {
				session_t *relay = maindata->sessions.list[i];
				if (relay) {
					if (relay->session_ptr) {
						relay_msg(relay, msgID, name, length, data);
					}
				}
			}
		}
	}
}
示例#6
0
void cmdSendSince(void *base, risp_int_t value)
{
	// The base pointer that is passed thru the library doesnt know about the session structure we 
	// are using, so we need to make a cast-pointer for it.
	session_t *session = (session_t *) base;
	assert(session);
	assert(session->id >= 0);
	printf("Session[%d]: Received CMD_SEND_SINCE(%ld)\n", session->id, value);
	
	if (checkAuth(session) == true) {
		// this code is not currently completed.
		assert(0);
	}
}
示例#7
0
//--------------------------------------------------------------------------------------------------
// This callback function is to be fired when the CMD_ECHO command is received.  This will turn on 
// the functionality (that is off by default) that echo's commands back to the client that sent the 
// message.  By default clients dont receive the commands they send.
void cmdEcho(void *base) 
{
	// The base pointer that is passed thru the library doesnt know about the session structure we 
	// are using, so we need to make a cast-pointer for it.
	session_t *session = (session_t *) base;
	assert(session);
	assert(session->id >= 0);
	printf("Session [%d]: Received ECHO\n", session->id);

	if (checkAuth(session) == true) {
		// session is not closing.
		session->data.echo = true;
	}
}
示例#8
0
//--------------------------------------------------------------------------------------------------
// Puts the session in NoFollow mode (the default).  When new messages are received from other 
// clients, it will not send the details to the client, but will send a message updating the 
// LATEST_ID.
void cmdNoFollow(void *base) 
{
	// The base pointer that is passed thru the library doesnt know about the session structure we 
	// are using, so we need to make a cast-pointer for it.
	session_t *session = (session_t *) base;
	assert(session);
	
	assert(session->id >= 0);
	printf("Session [%d]: Received NO_FOLLOW\n", session->id);
	
	if (checkAuth(session) == true) {
		// remove the follow flag.
		session->data.follow = false;
	}
}
示例#9
0
void cmdSendMsg(void *base, risp_int_t value)
{
	// The base pointer that is passed thru the library doesnt know about the session structure we 
	// are using, so we need to make a cast-pointer for it.
	session_t *session = (session_t *) base;
	assert(session);
	
	assert(sizeof(value) >= sizeof(long long));
	assert(session->id >= 0);
	printf("Session [%d]: Received CMD_SEND_MSG(%ld)\n", session->id, value);
	
	if (checkAuth(session) == true) {
		// this code is not currently completed.
		
		maindata_t *maindata = session->maindata;
		assert(maindata);

		assert(maindata->messages.list);
		assert(maindata->messages.latest >= 0);
		
		
		// when we added the message to the messages array, it copied the message and ensured it w
		// as null termined, so we can now get a pointer to it.
		unsigned char *message = message_get_msg(maindata, value);
		if (message) {
			unsigned char *name = message_get_name(maindata, value);
			
			//   Response:
			//		CMD_MSG_ID(integer)
			//		CMD_NAME(string)	- If name is supplied.
			//		CMD_MESSAGE(string)

			printf("Session[%d]: By request, Sending message(%lld).\n", session->id, (long long) value);
			assert(session->session_ptr);
			rispsession_send_int(session->session_ptr, CMD_MSG_ID, value);
			if (name) { rispsession_send_str(session->session_ptr, CMD_NAME, strlen((const char *) name), name); }
			rispsession_send_str(session->session_ptr, CMD_MESSAGE, strlen((const char *) message), message);
		}
	}
}
示例#10
0
// client is asking to know the latest msg ID that is available.
void cmdGetLatestMsgID(void *base)
{
	// The base pointer that is passed thru the library doesnt know about the session structure we 
	// are using, so we need to make a cast-pointer for it.
	session_t *session = (session_t *) base;
	assert(session);
	assert(session->id >= 0);
	printf("Session [%d]: Received CMD_GET_LATEST_MSG_ID\n", session->id);
	
	if (checkAuth(session) == true) {
		// this code is not currently completed.
		
		maindata_t *maindata = session->maindata;
		assert(maindata);

		// the list should either be empty, or have something in it.
		assert((maindata->messages.list == NULL && maindata->messages.latest == 0) || (maindata->messages.list && maindata->messages.latest > 0));

		printf("Session[%d]: Sending Latest Message ID: %lld\n", session->id, (long long) maindata->messages.latest);

		assert(session->session_ptr);
		rispsession_send_int(session->session_ptr, CMD_LATEST_MSG_ID, maindata->messages.latest);
	}
}
示例#11
0
    /** called as the health threads get new results */
    void Manager::msgCheckNewState() {
        {
            theReplSet->assertValid();
            rs->assertValid();

            RSBase::lock lk(rs);

            if( busyWithElectSelf ) return;
            
            checkElectableSet();
            checkAuth();

            const Member *p = rs->box.getPrimary();
            if( p && p != rs->_self ) {
                if( !p->hbinfo().up() ||
                        !p->hbinfo().hbstate.primary() ) {
                    p = 0;
                    rs->box.setOtherPrimary(0);
                }
            }

            const Member *p2;
            {
                bool two;
                p2 = findOtherPrimary(two);
                if( two ) {
                    /* two other nodes think they are primary (asynchronously polled) -- wait for things to settle down. */
                    log() << "replSet info two primaries (transiently)" << rsLog;
                    return;
                }
            }

            if( p2 ) {
                noteARemoteIsPrimary(p2);
                return;
            }

            /* didn't find anyone who wants to be primary */

            if( p ) {
                /* we are already primary */

                if( p != rs->_self ) {
                    rs->sethbmsg("error p != rs->self in checkNewState");
                    log() << "replSet " << p->fullName() << rsLog;
                    log() << "replSet " << rs->_self->fullName() << rsLog;
                    return;
                }

                if( rs->elect.shouldRelinquish() ) {
                    log() << "can't see a majority of the set, relinquishing primary" << rsLog;
                    rs->relinquish();
                }

                return;
            }

            if( !rs->iAmPotentiallyHot() ) { // if not we never try to be primary
                OCCASIONALLY log() << "replSet I don't see a primary and I can't elect myself" << endl;
                return;
            }

            /* no one seems to be primary.  shall we try to elect ourself? */
            if( !rs->elect.aMajoritySeemsToBeUp() ) {
                static time_t last;
                static int n;
                int ll = 0;
                if( ++n > 5 ) ll++;
                if( last + 60 > time(0 ) ) ll++;
                log(ll) << "replSet can't see a majority, will not try to elect self" << rsLog;
                last = time(0);
                return;
            }

            if( !rs->iAmElectable() ) {
                return;
            }

            busyWithElectSelf = true; // don't try to do further elections & such while we are already working on one.
        }
        try {
            rs->elect.electSelf();
        }
        catch(RetryAfterSleepException&) {
            /* we want to process new inbounds before trying this again.  so we just put a checkNewstate in the queue for eval later. */
            requeue();
        }
        catch(...) {
            log() << "replSet error unexpected assertion in rs manager" << rsLog;
        }
        busyWithElectSelf = false;
    }
示例#12
0
///0:成功;-1:失败
int UnistorHandler4Recv::recvMessage()
{
	int ret = 0;
    bool bUnpack=false; ///<是否unpack了消息报
    do{
        if (!m_recvMsgData){///一个空包
            ret = UNISTOR_ERR_ERROR;
            strcpy(m_tss->m_szBuf2K, "msg is empty.");
            break;
        }
        if (!m_bAuth){
            if (!m_tss->m_pReader->unpack(m_recvMsgData->rd_ptr(), m_recvMsgData->length(), false)){
                ret = UNISTOR_ERR_ERROR;
                strcpy(m_tss->m_szBuf2K, m_tss->m_pReader->getErrMsg());
                break;
            }
            if (!checkAuth(m_tss)){
                ret = UNISTOR_ERR_ERROR;
                break;
            }
            bUnpack = true;
        }
        if ((m_header.getMsgType() == UnistorPoco::MSG_TYPE_RECV_ADD)||
            (m_header.getMsgType() == UnistorPoco::MSG_TYPE_RECV_SET) ||
            (m_header.getMsgType() == UnistorPoco::MSG_TYPE_RECV_UPDATE)||
            (m_header.getMsgType() == UnistorPoco::MSG_TYPE_RECV_INC)||
            (m_header.getMsgType() == UnistorPoco::MSG_TYPE_RECV_IMPORT)||
            (m_header.getMsgType() == UnistorPoco::MSG_TYPE_RECV_DEL))
        {///如果是写请求
            if (m_pApp->getRecvWriteHandler()->isCanWrite()){
                if (m_pApp->getWriteTheadPool()->getQueuedMsgNum() > m_pApp->getConfig().getCommon().m_uiMaxWriteQueueNum){
                    ret = UNISTOR_ERR_TOO_MANY_WRITE;
                    CwxCommon::snprintf(m_tss->m_szBuf2K, 2047, "Too many message in write queue, max:%u", m_pApp->getConfig().getCommon().m_uiMaxWriteQueueNum);
                    break;
                }
                if (!bUnpack){
                    if (!m_tss->m_pReader->unpack(m_recvMsgData->rd_ptr(), m_recvMsgData->length(), false)){
                        ret = UNISTOR_ERR_ERROR;
                        strcpy(m_tss->m_szBuf2K, m_tss->m_pReader->getErrMsg());
                        break;
                    }
                }
                if (UNISTOR_ERR_SUCCESS != (ret = relayWriteThread())) break;
                return 0;
            }else if (UnistorHandler4Trans::m_bCanTrans){///转发给master
                if (m_pApp->getTaskBoard().getTaskNum() > m_pApp->getConfig().getCommon().m_uiMaxMasterTranMsgNum){
                    ret = UNISTOR_ERR_TOO_MANY_TRANS;
                    CwxCommon::snprintf(m_tss->m_szBuf2K, 2047, "Too many message for trans to master, max:%u", m_pApp->getConfig().getCommon().m_uiMaxMasterTranMsgNum);
                }else{
                    relayTransThread(m_recvMsgData);
                    m_recvMsgData = NULL;
                    return 0;
                }
            }else{
                ret = UNISTOR_ERR_NO_MASTER;
                strcpy(m_tss->m_szBuf2K, "No master.");
                break;
            }
        }else{
            if (UnistorPoco::isFromMaster(m_header.getAttr())){
                if (m_tss->isMasterIdc()){///是master idc
                    if (!m_tss->isMaster()){///自己不是master
                        if (UnistorHandler4Trans::m_bCanTrans){
                            relayTransThread(m_recvMsgData);
                            m_recvMsgData = NULL;
                            return 0;
                        }
                        ret = UNISTOR_ERR_NO_MASTER;
                        strcpy(m_tss->m_szBuf2K, "No master.");
                        break;
                    }
                    ///若自己是master,则查询数据
                }else{
                    ret = UNISTOR_ERR_NO_MASTER;
                    strcpy(m_tss->m_szBuf2K, "No master.");
                    break;
                }
            }
            if (!bUnpack){
                if (!m_tss->m_pReader->unpack(m_recvMsgData->rd_ptr(), m_recvMsgData->length(), false)){
                    ret = UNISTOR_ERR_ERROR;
                    strcpy(m_tss->m_szBuf2K, m_tss->m_pReader->getErrMsg());
                    break;
                }
            }

            if (m_header.getMsgType() == UnistorPoco::MSG_TYPE_RECV_GET){
                ret =  getKv(m_tss);
                if (UNISTOR_ERR_SUCCESS == ret) return 0;///已经回复
            }else if (m_header.getMsgType() == UnistorPoco::MSG_TYPE_RECV_GETS){
                ret = getKvs(m_tss);
                if (UNISTOR_ERR_SUCCESS == ret) return 0;///已经回复
            }else if (m_header.getMsgType() == UnistorPoco::MSG_TYPE_RECV_LIST){
                ret = getList(m_tss);
                if (UNISTOR_ERR_SUCCESS == ret) return 0;///已经回复
            }else if (m_header.getMsgType() == UnistorPoco::MSG_TYPE_RECV_EXIST){
                ret = existKv(m_tss);
                if (UNISTOR_ERR_SUCCESS == ret) return 0;///已经回复
            }else if (m_header.getMsgType() == UnistorPoco::MSG_TYPE_RECV_AUTH){
                ret = UNISTOR_ERR_SUCCESS;
            }else{
                ret = UNISTOR_ERR_ERROR;
                CwxCommon::snprintf(m_tss->m_szBuf2K, 2047, "Invalid msg type:%d", m_header.getMsgType());
                return -1; ///无效消息类型,直接关闭连接
            }
        }
    }while(0);

    CwxMsgBlock* msg = packReplyMsg(m_tss,
        m_header.getTaskId(),
        m_header.getMsgType()+1,
        ret,
        0,
        0,
        m_tss->m_szBuf2K);
    if (!msg) return -1; ///关闭连接
    return reply(msg, false);
}
示例#13
0
    /** called as the health threads get new results */
    void Manager::msgCheckNewState() {
        {
            theReplSet->assertValid();
            rs->assertValid();

            RSBase::lock lk(rs);

            if( busyWithElectSelf ) return;
            
            checkElectableSet();
            checkAuth();

            const Member *p = rs->box.getPrimary();
            if( p && p != rs->_self ) {
                if( !p->hbinfo().up() ||
                        !p->hbinfo().hbstate.primary() ) {
                    p = 0;
                    rs->box.setOtherPrimary(0);
                }
            }

            const Member *p2;
            {
                bool two;
                p2 = findOtherPrimary(two);
                if( two ) {
                    /* two other nodes think they are primary (asynchronously polled) -- wait for things to settle down. */
                    log() << "replSet info two primaries (transiently)" << rsLog;
                    return;
                }
            }

            if( p2 ) {
                /* someone else thinks they are primary. */
                if( p == p2 ) {
                    // we thought the same; all set.
                    return;
                }
                if( p == 0 ) {
                    noteARemoteIsPrimary(p2);
                    return;
                }
                // todo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                if( p != rs->_self ) {
                    // switch primary from oldremotep->newremotep2
                    noteARemoteIsPrimary(p2);
                    return;
                }
                /* we thought we were primary, yet now someone else thinks they are. */
                if( !rs->elect.aMajoritySeemsToBeUp() ) {
                    /* we can't see a majority.  so the other node is probably the right choice. */
                    noteARemoteIsPrimary(p2);
                    return;
                }
                /* ignore for now, keep thinking we are master.
                   this could just be timing (we poll every couple seconds) or could indicate
                   a problem?  if it happens consistently for a duration of time we should
                   alert the sysadmin.
                */
                return;
            }

            /* didn't find anyone who wants to be primary */

            if( p ) {
                /* we are already primary */

                if( p != rs->_self ) {
                    rs->sethbmsg("error p != rs->self in checkNewState");
                    log() << "replSet " << p->fullName() << rsLog;
                    log() << "replSet " << rs->_self->fullName() << rsLog;
                    return;
                }

                if( rs->elect.shouldRelinquish() ) {
                    log() << "can't see a majority of the set, relinquishing primary" << rsLog;
                    rs->relinquish();
                }

                return;
            }

            if( !rs->iAmPotentiallyHot() ) // if not we never try to be primary
                return;
            
            /* no one seems to be primary.  shall we try to elect ourself? */
            if( !rs->elect.aMajoritySeemsToBeUp() ) {
                static time_t last;
                static int n;
                int ll = 0;
                if( ++n > 5 ) ll++;
                if( last + 60 > time(0 ) ) ll++;
                log(ll) << "replSet can't see a majority, will not try to elect self" << rsLog;
                last = time(0);
                return;
            }

            if( !rs->iAmElectable() ) {
                return;
            }

            busyWithElectSelf = true; // don't try to do further elections & such while we are already working on one.
        }
        try {
            rs->elect.electSelf();
        }
        catch(RetryAfterSleepException&) {
            /* we want to process new inbounds before trying this again.  so we just put a checkNewstate in the queue for eval later. */
            requeue();
        }
        catch(...) {
            log() << "replSet error unexpected assertion in rs manager" << rsLog;
        }
        busyWithElectSelf = false;
    }
示例#14
0
文件: manager.cpp 项目: nvdnkpr/mongo
/** called as the health threads get new results */
void Manager::msgCheckNewState() {
    bool authIssue = false;
    {
        theReplSet->assertValid();
        rs->assertValid();

        boost::unique_lock<boost::mutex> lock(rs->stateChangeMutex);
        {
            RSBase::lock lk(rs);

            if( busyWithElectSelf ) return;

            checkElectableSet();
            authIssue = checkAuth();
            if (!authIssue) {
                const Member *p = rs->box.getPrimary();
                if( p && p != rs->_self ) {
                    if( !p->hbinfo().up() ||
                            !p->hbinfo().hbstate.primary() ) {
                        p = 0;
                        rs->box.setOtherPrimary(0);
                    }
                }

                const Member *p2;
                {
                    bool two;
                    p2 = findOtherPrimary(two);
                    if( two ) {
                        /* two other nodes think they are primary (asynchronously polled) -- wait for things to settle down. */
                        log() << "replSet info two primaries (transiently)" << rsLog;
                        return;
                    }
                }

                if( p2 ) {
                    noteARemoteIsPrimary(p2);
                    return;
                }

                /* didn't find anyone who wants to be primary */

                if( p ) {
                    /* we are already primary */

                    if( p != rs->_self ) {
                        rs->sethbmsg("error p != rs->self in checkNewState");
                        log() << "replSet " << p->fullName() << rsLog;
                        log() << "replSet " << rs->_self->fullName() << rsLog;
                        return;
                    }

                    if( rs->elect.shouldRelinquish() ) {
                        log() << "can't see a majority of the set, relinquishing primary" << rsLog;
                        rs->relinquish();
                    }

                    if (GTID::cmp(theReplSet->gtidManager->getLiveState(), theReplSet->lastOtherGTID()) < 0) {
                        // this can happen if we transiently have two primaries, which can
                        // happen if a primary loses contact with the replica set,
                        // triggering an election, but it connects back before it has a
                        // chance to step down
                        log() << "we see a secondary that is ahead, relinquishing primary" << rsLog;
                        rs->relinquish();
                    }

                    return;
                }

                if( !rs->iAmPotentiallyHot() ) { // if not we never try to be primary
                    OCCASIONALLY log() << "replSet I don't see a primary and I can't elect myself" << endl;
                    return;
                }

                /* no one seems to be primary.  shall we try to elect ourself? */
                if( !rs->elect.aMajoritySeemsToBeUp() ) {
                    static time_t last;
                    static int n;
                    int ll = 0;
                    if( ++n > 5 ) ll++;
                    if( last + 60 > time(0 ) ) ll++;
                    LOG(ll) << "replSet can't see a majority, will not try to elect self" << rsLog;
                    last = time(0);
                    return;
                }

                if( !rs->iAmElectable() ) {
                    return;
                }

                busyWithElectSelf = true; // don't try to do further elections & such while we are already working on one.
            }
        }
        // blockSync outside of rslock
        // can't hold rslock because we may try to stop the opsync thread
        if (authIssue) {
            {
                RSBase::lock lk(rs);
                if (rs->box.getPrimary() == rs->_self) {
                    log() << "auth problems, relinquishing primary" << rsLog;
                    rs->relinquish();
                }
            }
            rs->blockSync(true);
            return;
        }
    }
    try {
        rs->elect.electSelf();
    }
    catch(RetryAfterSleepException&) {
        /* we want to process new inbounds before trying this again.  so we just put a checkNewstate in the queue for eval later. */
        requeue();
    }
    catch(...) {
        log() << "replSet error unexpected assertion in rs manager" << rsLog;
    }
    busyWithElectSelf = false;
}
示例#15
0
eHTTPDataSource *eHTTPDynPathResolver::getDataSource(eString request, eString path, eHTTPConnection *conn)
{
	eString p, opt;
	if (path.find('?')!=eString::npos)
	{
		p=path.left(path.find('?'));
		opt=path.mid(path.find('?')+1);
	}	else
	{
		p=path;
		opt="";
	}
	for (ePtrList<eHTTPDynEntry>::iterator i(dyn); i != dyn.end(); ++i)
	{
		if ((i->path==p) && (i->request==request))
		{
			if (i->mustAuth )
			{
				eString hosts = ";";
				eString host;
				host.sprintf(";%s;",conn->RemoteHost().c_str());
				char* h = NULL;
				eConfig::getInstance()->getKey("/ezap/webif/trustedhosts", h);
				if (h)
				{
					char* h1 = strtok(h,";");
					struct hostent* he;
					while (h1)
					{
						he = gethostbyname(h1);
						if (he)
						{
							for (int i = 0; he->h_addr_list[i]; i++)
							{
								hosts += eString(inet_ntoa(*(in_addr*)he->h_addr_list[i]));
								hosts += ";";
							}
						}
						h1 = strtok(NULL,";");
					}
				}
				if (hosts.find(host) == eString::npos )
				{
					std::map<eString, eString>::iterator i=conn->remote_header.find("Authorization");
					if ((i == conn->remote_header.end()) || checkAuth(i->second))
					{
						conn->local_header["WWW-Authenticate"]="Basic realm=\"dreambox\"";
						return new eHTTPError(conn, 401); // auth req'ed
					}
				}
			}

			conn->code=-1;
			eString s=i->function(request, path, opt, conn);

// removed to allow return of empty string for e.g. 204 no content...
//			if (s) 
				return new eHTTPDyn(conn, s);

//			return new eHTTPError(conn, 500);
		}
	}
	return 0;
}