コード例 #1
0
/**
 * Extracts the data for a named flag from a list of flags.
 *
 * Example flag:  FORWARD_A839D7E73849CF934
 * inFlagDataPrefix:  FORWARD_
 * Return value:  A839D7E73849CF934
 *
 * @param inFlags a string of of |-delimited flags.
 *   Destroyed by caller.
 * @param inFlagDataPrefix the name of the flag (in other words,
 *   the prefix in the flag that comes before the data to get).
 *   Destroyed by caller.
 *
 * @return the flag's data as a new string, or NULL if the flag
 *   is not found.
 *   Destroyed by caller.
 */
char *
        getFlagData (char *inFlags, char *inFlagDataPrefix)
{
    
    char *returnData = NULL;
    
    // find start of flag in list of flags
    char *pointerToFlag = strstr (inFlags, inFlagDataPrefix);
    
    if (pointerToFlag != NULL)
    {
        // message has this flag
        
        // extract the data from the flag
        char *copyOfFlag = stringDuplicate (pointerToFlag);
        char *pointerToFlagSeparator = strstr (copyOfFlag, "|");
        
        if (pointerToFlagSeparator != NULL)
        {
            // terminate string at separator
            pointerToFlagSeparator[0] = '\0';
        }
        
        // skip the prefix to get to the data
        int prefixLength = strlen (inFlagDataPrefix);
        char *pointerToData = &(copyOfFlag[prefixLength]);
        
        returnData = stringDuplicate (pointerToData);
        
        delete[]copyOfFlag;
    }
    
    return returnData;
}
コード例 #2
0
ファイル: FileLog.cpp プロジェクト: vinay/Gravitation
FileLog::FileLog( char *inFileName, unsigned long inSecondsBetweenBackups )
    : mLogFile( NULL ),
      mLogFileName( stringDuplicate( inFileName ) ),
      mSecondsBetweenBackups( inSecondsBetweenBackups ),
      mTimeOfLastBackup( time( NULL ) ) {

    
    mLogFile = fopen( mLogFileName, "a" );

    if( mLogFile == NULL ) {
        printf( "Log file %s failed to open.\n", mLogFileName );
        printf( "Writing log to default file:  %s\n",
                mDefaultLogFileName );

        // switch to default log file name
        
        delete [] mLogFileName;
        mLogFileName = stringDuplicate( mDefaultLogFileName );

        
        mLogFile = fopen( mLogFileName, "a" );
        
        if( mLogFile == NULL ) {
            printf( "Default log file %s failed to open.\n",
                    mLogFileName );
            }
        }
    
    }
コード例 #3
0
ファイル: ticketHash.cpp プロジェクト: MrPhil/CastleDoctrine
char *replaceTicketHash( char *inString ) {
    const char *keyA = "sequence_number=";
    const char *keyB = "ticket_hmac=";
    
    if( inString == NULL ) {
        return NULL;
        }
    else if( strstr( inString, keyA ) != NULL &&
             strstr( inString, keyB ) != NULL ) {
        
        // present

        char *copy = stringDuplicate( inString );
        
        char *startPointerA = strstr( copy, keyA );
        char *startPointerB = strstr( copy, keyB );
 
        char *hmacStart = &( startPointerB[ strlen( keyB ) ] );
        
        
        int i = 0;
        while( hmacStart[i] != '\0' &&
               ( ( hmacStart[i] >= '0' && 
                   hmacStart[i] <= '9' )
                 || 
                 ( hmacStart[i] >= 'A' &&
                   hmacStart[i] <= 'F' ) ) ) {
            i++;
            }
        
        // truncate here, after end of hmac
        hmacStart[i] = '\0';
        
        
        // now startPointerA points to the full hash
        
        char *newHash = getTicketHash();

        char found;
        
        char *newHashInPlace = replaceOnce( inString, startPointerA,
                                            newHash,
                                            &found );

        delete [] newHash;
        delete [] copy;
        delete [] inString;

        return newHashInPlace;
        }
    else {
        // no hash present
        char *result = stringDuplicate( inString );
        delete [] inString;
        return result;
        }
    }
コード例 #4
0
ファイル: stringUtils.cpp プロジェクト: nsb/Calypso
char *replaceAll( const char *inHaystack, const char *inTarget,
                  const char *inSubstitute,
                  char *outFound ) {

    // repeatedly replace once until replacing fails
    
    char lastFound = true;
    char atLeastOneFound = false;
    char *returnString = stringDuplicate( inHaystack );

    while( lastFound ) {

        char *nextReturnString =
            replaceOnce( returnString, inTarget, inSubstitute, &lastFound );

        delete [] returnString;
        
        returnString = nextReturnString;

        if( lastFound ) {
            atLeastOneFound = true;
            }
        }

    *outFound = atLeastOneFound;
    
    return returnString;    
    }
コード例 #5
0
ファイル: field.cpp プロジェクト: kuailexs/symbiandump-mw3
Field::Field(const TCHAR* Name, const TCHAR* String, bool store, bool index, bool token, const bool storeTermVector)
{
//Func - Constructor
//Pre  - Name != NULL and contains the name of the field
//       String != NULL and contains the value of the field
//       store indicates if the field must be stored
//       index indicates if the field must be indexed
//       token indicates if the field must be tokenized
//Post - The instance has been created

    CND_PRECONDITION(Name != NULL, "Name is NULL");
    CND_PRECONDITION(String != NULL,"String is NULL");
    CND_PRECONDITION(!(!index && storeTermVector),"cannot store a term vector for fields that are not indexed.");

    _name        = LStringIntern::intern( Name CL_FILELINE);
    _stringValue = stringDuplicate( String );
    _readerValue = NULL;
    _streamValue = NULL;
    boost=1.0f;
    omitNorms = false;

    int cfg = 0;
    if ( store )
        cfg |= STORE_YES;
    if ( index && token )
        cfg |= INDEX_TOKENIZED;
    else if ( index && !token )
        cfg |= INDEX_UNTOKENIZED;

    if ( storeTermVector )
        _CLTHROWA(CL_ERR_IllegalArgument,"Stored term vector is deprecated with using this constructor");

    setConfig(cfg);
}
コード例 #6
0
char DuplicateMessageDetector::checkIfMessageSeen( char *inMessageUniqueID ) {
    mLock->lock();

    mTotalMessageCount++;
    
    int numIDs = mSeenIDs->size();

    char matchSeen = false;
    for( int i=0; i<numIDs && !matchSeen; i++ ) {

        char *otherID = *( mSeenIDs->getElement( i ) ); 

        if( strcmp( otherID, inMessageUniqueID ) == 0 ) {
            // match

            // push the ID back to the end of the queue
            mSeenIDs->deleteElement( i );
            mSeenIDs->push_back( otherID );
            matchSeen = true;
            }
        }

    if( mHistoryOutputFile != NULL ) {
        fprintf( mHistoryOutputFile,
                 "%d %d %s",
                 mTotalMessageCount,
                 (int)( time( NULL ) ),
                 inMessageUniqueID );
        }
    
    
    if( !matchSeen ) {

        // add the message
        mSeenIDs->push_back( stringDuplicate( inMessageUniqueID ) );

        // make sure history not too long
        if( mSeenIDs->size() > mMaxHistorySize ) {
            delete [] *( mSeenIDs->getElement( 0 ) );
            mSeenIDs->deleteElement( 0 );
            }

        if( mHistoryOutputFile != NULL ) {
            fprintf( mHistoryOutputFile, "\n" );
            }
        }
    else {
        // add duplicate tag
        if( mHistoryOutputFile != NULL ) {
            fprintf( mHistoryOutputFile, " D\n" );
            }
        }

    if( mHistoryOutputFile != NULL ) {
        fflush( mHistoryOutputFile );
        }
    
    mLock->unlock();    
    return matchSeen;    
    }
コード例 #7
0
    /** Creates new WildcardTermEnum */
    WildcardTermEnum::WildcardTermEnum(IndexReader* reader, Term* term):
	    FilteredTermEnum(),
		__term(_CL_POINTER(term)),
		fieldMatch(false),
		_endEnum(false)
    {
       
		pre = stringDuplicate(term->text());

		const TCHAR* sidx = _tcschr( pre, LUCENE_WILDCARDTERMENUM_WILDCARD_STRING );
		const TCHAR* cidx = _tcschr( pre, LUCENE_WILDCARDTERMENUM_WILDCARD_CHAR );
		const TCHAR* tidx = sidx;
		if (tidx == NULL) 
			tidx = cidx;
		else if ( cidx && cidx > pre) 
			tidx = min(sidx, cidx);
		CND_PRECONDITION(tidx != NULL, "tidx==NULL");
		int32_t idx = (int32_t)(tidx - pre);
		preLen = idx;
		CND_PRECONDITION(preLen<term->textLength(), "preLen >= term->textLength()");
		pre[preLen]=0; //trim end

		Term* t = _CLNEW Term(__term, pre);
		setEnum( reader->terms(t) );
		_CLDECDELETE(t);
  }
コード例 #8
0
ファイル: SocketLinux.cpp プロジェクト: nsb/Calypso
HostAddress *Socket::getRemoteHostAddress() {
    int *socketIDptr = (int *)( mNativeObjectPointer );
	int socketID = socketIDptr[0];

    // adapted from Unix Socket FAQ
    
    socklen_t len;
    struct sockaddr_in sin;
    
    len = sizeof sin;
    int error = getpeername( socketID, (struct sockaddr *) &sin, &len );

    if( error ) {
        return NULL;
        }

    // this is potentially insecure, since a fake DNS name might be returned
    // we should use the IP address only
    //
    // struct hostent *host = gethostbyaddr( (char *) &sin.sin_addr,
    //                                       sizeof sin.sin_addr,
    //                                       AF_INET );


    NetworkFunctionLocks::mInet_ntoaLock.lock();
    // returned string is statically allocated, copy it
    char *ipAddress = stringDuplicate( inet_ntoa( sin.sin_addr ) );
    NetworkFunctionLocks::mInet_ntoaLock.unlock();

    int port = ntohs( sin.sin_port );
    
    return new HostAddress( ipAddress, port );    
    }
コード例 #9
0
ファイル: protocolUtils.cpp プロジェクト: nsb/Calypso
char *readStreamUpToTag( InputStream *inInputStream,
                         char *inTag,
                         int inMaxCharsToRead ) {

    char *readCharBuffer = new char[ inMaxCharsToRead + 1 ];


    int numCharsRead = 0;
    char tagSeen = false;
    char readError = false;

    int tagLength = strlen( inTag );

    while( numCharsRead < inMaxCharsToRead && !tagSeen && !readError ) {
        long numRead = inInputStream->readByte(
                           (unsigned char *)
                           ( &( readCharBuffer[ numCharsRead ] ) ) );

        if( numRead != 1 ) {
            readError = true;
        }
        else {
            numCharsRead++;


            if( numCharsRead > tagLength ) {
                char *possibleBodyStart =
                    &( readCharBuffer[ numCharsRead - tagLength ] );

                if( memcmp( possibleBodyStart, inTag, tagLength ) == 0 ) {
                    tagSeen = true;
                }
            }
        }
    }

    readCharBuffer[ numCharsRead ] = '\0';


    if( !readError && tagSeen ) {
        char *returnString = stringDuplicate( readCharBuffer );

        delete [] readCharBuffer;

        return returnString;
    }
    else {
//        char *message = autoSprintf(
//            "Failed to find end tag \"%s\", read %d characters:\n%s\n",
//            inTag, numCharsRead, readCharBuffer );

//        AppLog::info( "readStreamUpToTag", message );

//        delete [] message;

        delete [] readCharBuffer;

        return NULL;
    }
}
コード例 #10
0
ファイル: HostAddressLinux.cpp プロジェクト: vinay/Transcend
HostAddress *HostAddress::getLocalAddress() {
	int bufferLength = 200;
	char *buffer = new char[ bufferLength ];

	gethostname( buffer, bufferLength );

    
    char *name = stringDuplicate( buffer );

	delete [] buffer;


    // this class will destroy name for us
    HostAddress *nameAddress = new HostAddress( name, 0 );

    HostAddress *fullAddress = nameAddress->getNumericalAddress();

    if( fullAddress != NULL ) {
    
        delete nameAddress;

        return fullAddress;
        }
    else {
        return nameAddress;
        }
    
    }
コード例 #11
0
ファイル: Field.cpp プロジェクト: Beirdo/beirdobot
Field::Field(const TCHAR* Name, const TCHAR* Value, int _config, const bool duplicateValue):
	lazy(false)
{
	CND_PRECONDITION(Name != NULL, "Name cannot be NULL");
	CND_PRECONDITION(Value != NULL, "value cannot be NULL");
	CND_PRECONDITION(_tcslen(Value)>0 && _tcslen(Name)>0, "name and value cannot both be empty");

	/*
	if (_config & INDEX_NO && _config & STORE_NO)
		_CLTHROWA(CL_ERR_IllegalArgument,"it doesn't make sense to have a field that is neither indexed nor stored");
	if (_config & INDEX_NO && _config & TERMVECTOR_YES)
		_CLTHROWA(CL_ERR_IllegalArgument,"cannot store term vector information for a field that is not indexed");
	*/

	_name        = CLStringIntern::intern( Name );
	if (duplicateValue)
		fieldsData = stringDuplicate( Value );
	else
		fieldsData = (void*)Value;
	valueType = VALUE_STRING;

	boost=1.0f;

	//config = INDEX_TOKENIZED; // default Field is tokenized and indexed

	setConfig(_config);
}
コード例 #12
0
char *BuyAuctionPage::getGalleryContents() {
    if( mGalleryContents != NULL ) {
        return stringDuplicate( mGalleryContents );
        }

    return NULL;
    }
コード例 #13
0
void ReplayRobHousePage::setLog( RobberyLog inLog ) {
    mGridDisplay.setHouseMap( inLog.houseMap );
    mGridDisplay.setMoveList( inLog.moveList );
    mGridDisplay.setWifeMoney( inLog.wifeMoney );
    
    mGridDisplay.setWifeName( inLog.wifeName );
    mGridDisplay.setSonName( inLog.sonName );
    mGridDisplay.setDaughterName( inLog.daughterName );
    

    mMusicSeed = inLog.musicSeed;
    
    if( mDescription != NULL ) {
        delete [] mDescription;
        }
    
    const char *descriptionKey = "replayDescription";
    
    if( inLog.isBounty ) {
        descriptionKey = "replayDescriptionBounty";
        }

    mDescription = autoSprintf( translate( descriptionKey ),
                                inLog.robberName,
                                inLog.victimName,
                                inLog.lootValue );

    if( mPackSlotsString != NULL ) {
        delete [] mPackSlotsString;
        }
    mPackSlotsString = stringDuplicate( inLog.backpackContents );
    
    inventorySlotsFromString( mPackSlotsString, mPackSlots, NUM_PACK_SLOTS );
    }
コード例 #14
0
ファイル: Term.cpp プロジェクト: e1z0/openvpn_client
void Term::set(const TCHAR* fld, const TCHAR* txt,bool internField)
{
    CND_PRECONDITION(fld != NULL, "fld contains NULL");
    CND_PRECONDITION(txt != NULL, "txt contains NULL");

    //save field for unintern later
    const TCHAR* oldField = _field;
    cachedHashCode = 0;
    textLen = _tcslen(txt);

    //Delete text if it is the owner
#ifdef LUCENE_TERM_TEXT_LENGTH
    if (textLen > LUCENE_TERM_TEXT_LENGTH)
        textLen = LUCENE_TERM_TEXT_LENGTH;

    _tcsncpy(_text,txt,textLen+1);
    _text[textLen]=0;
#else
    //if the term text buffer is bigger than what we have
    if (_text && textLen > textLenBuf) {
        if (_text != LUCENE_BLANK_STRING) {
            _CLDELETE_ARRAY(_text);
        } else {
            _text = NULL;
        }
        textLenBuf = 0;
    }

    if (_text == LUCENE_BLANK_STRING) {
        _text = LUCENE_BLANK_STRING;
    } else if (_text == NULL) {
        if (txt[0] == 0) {
            //if the string is blank and we aren't re-using the buffer...
            _text = LUCENE_BLANK_STRING;
        } else {
            //duplicate the text
            _text  = stringDuplicate(txt);
            textLenBuf = textLen;
        }
    } else {
        //re-use the buffer
        _tcscpy(_text,txt);
    }
#endif

    //Set Term Field
    if (internField) {
        _field = CLStringIntern::intern(fld  CL_FILELINE);
    } else {
        _field = fld;
    }

    //unintern old field after interning new one, 
    if (internF)
        CLStringIntern::unintern(oldField);
    internF = internField;

    CND_PRECONDITION(_tcscmp(fld, _field) == 0, "field not equal");
}
コード例 #15
0
ファイル: Field.cpp プロジェクト: Beirdo/beirdobot
void Field::setValue(TCHAR* value, const bool duplicateValue) {
	_resetValue();
	if (duplicateValue)
		fieldsData = stringDuplicate( value );
	else
		fieldsData = value;
	valueType = VALUE_STRING;
}
コード例 #16
0
char *Path::extractRoot( const char *inPathString ) {
    if( isAbsolute( inPathString )  ){
        return stringDuplicate( "/" );
        }
    else {
        return NULL;
        }
    }
コード例 #17
0
ファイル: WebRequest.cpp プロジェクト: MrPhil/CastleDoctrine
char *WebRequest::getResult() {
    if( mResultReady ) {
        return stringDuplicate( mResult );
        }
    else {
        return NULL;
        }
    }
コード例 #18
0
void FinalMessagePage::setSubMessage( const char *inSubMessage ) {
    if( mSubMessage != NULL ) {
        delete [] mSubMessage;
        mSubMessage = NULL;
        }
    if( inSubMessage != NULL ) {
        mSubMessage = stringDuplicate( inSubMessage );
        }
    }
コード例 #19
0
ファイル: lineageLog.cpp プロジェクト: duralakun/OneLife
void recordPlayerLineage( char *inEmail, double inAge,
                          int inPlayerID, int inParentID,
                          int inDisplayID, int inKillerID,
                          const char *inName,
                          const char *inLastSay,
                          char inMale ) {

    if( useLineageServer ) {

        if( inName == NULL ) {
            inName = "NAMELESS";
            }
        if( inLastSay == NULL ) {
            inLastSay = "";
            }
        
        
        WebRequest *request;
        
        char *encodedEmail = URLUtils::urlEncode( inEmail );

        char *url = autoSprintf( 
            "%s?action=get_sequence_number"
            "&email=%s",
            lineageServerURL,
            encodedEmail );
        
        delete [] encodedEmail;
        
        request = new WebRequest( "GET", url, NULL );
        printf( "Starting new web request for %s\n", url );
        
        delete [] url;

        LineageRecord r = { stringDuplicate( inEmail ), inAge, 
                            inPlayerID, inParentID, inDisplayID,
                            inKillerID,
                            stringDuplicate( inName ),
                            stringDuplicate( inLastSay ),
                            inMale,
                            request, -1 };
        records.push_back( r );
        }
    }
コード例 #20
0
HostAddress *HostAddress::getNumericalAddress() {

    // make sure we're not already numerical
    if( this->isNumerical() ) {
        return this->copy();
        }


    if( !Socket::isFrameworkInitialized() ) {
		
		// try to init the framework
		
		int error = Socket::initSocketFramework();
		
		if( error == -1 ) {
			
			printf( "initializing network socket framework failed\n" );
			return NULL;
			}
		}

    // need to use two function locks here

    // first, lock for gethostbyname
    NetworkFunctionLocks::mGetHostByNameLock.lock();
    struct hostent *host = gethostbyname( mAddressString );

    if (host != NULL) {

        // this line adapted from the
        // Unix Socket FAQ
        struct in_addr *inetAddress = (struct in_addr *) *host->h_addr_list;


        // now lock for inet_ntoa
        NetworkFunctionLocks::mInet_ntoaLock.lock();
        // the returned string is statically allocated, so copy it
        char *inetAddressString = stringDuplicate( inet_ntoa( *inetAddress ) );

        NetworkFunctionLocks::mInet_ntoaLock.unlock();

        
        // done with returned hostent now, so unlock first lock
        NetworkFunctionLocks::mGetHostByNameLock.unlock();
        
        return new HostAddress( inetAddressString, mPort );
        }
    else {

        // unlock first lock before returning
        NetworkFunctionLocks::mGetHostByNameLock.unlock();
        
        return NULL;
        }

    }
コード例 #21
0
ファイル: stringUtils.cpp プロジェクト: nsb/Calypso
char *stringToLowerCase( const char *inString  ) {

    int length = strlen( inString );

    char *returnString = stringDuplicate( inString );
    
    for( int i=0; i<length; i++ ) {
        returnString[i] = tolower( returnString[i] );
        }

    return returnString;
    }
コード例 #22
0
static Person personCreate(const char* name, int id) {
	assert(name);
	Person person = malloc(sizeof(struct Person_t));
	if (!person) {
		return NULL;
	}
	person->name = stringDuplicate(name);
	if (!name) {
		personDestroy(person);
		return NULL;
	}
	person->id = id;
	return person;
}
コード例 #23
0
ファイル: field.cpp プロジェクト: kuailexs/symbiandump-mw3
Field::Field(const TCHAR* Name, const TCHAR* Value, int config)
{
    CND_PRECONDITION(Name != NULL, "Name is NULL");
    CND_PRECONDITION(Value != NULL, "value is NULL");

    _name        = LStringIntern::intern( Name  CL_FILELINE);
    _stringValue = stringDuplicate( Value );
    _readerValue = NULL;
    _streamValue = NULL;
    boost=1.0f;
    omitNorms = false;

    setConfig(config);
}
コード例 #24
0
ファイル: stringUtils.cpp プロジェクト: nsb/Calypso
SimpleVector<char *> *tokenizeString( char *inString ) {

    char *tempString = stringDuplicate( inString );

    char *restOfString = tempString;
    
    SimpleVector<char *> *foundTokens = new SimpleVector<char *>();

    SimpleVector<char> *currentToken = new SimpleVector<char>();


    while( restOfString[0] != '\0' ) {
        // characters remain

        // skip whitespace
        char nextChar = restOfString[0];
        while( nextChar == ' ' || nextChar == '\n' ||
               nextChar == '\r' || nextChar == '\t' ) {

            restOfString = &( restOfString[1] );
            nextChar = restOfString[0];
            }

        if( restOfString[0] != '\0' ) {

            // a token

            while( nextChar != ' ' && nextChar != '\n' &&
                   nextChar != '\r' && nextChar != '\t' &&
                   nextChar != '\0'  ) {

                // still not whitespace
                currentToken->push_back( nextChar );
                
                restOfString = &( restOfString[1] );
                nextChar = restOfString[0];
                }

            // reached end of token
            foundTokens->push_back( currentToken->getElementString() );
            currentToken->deleteAll();
            }        
        }

    delete [] tempString;

    delete currentToken;

    return foundTokens;
    }
コード例 #25
0
ファイル: TextButton.cpp プロジェクト: duralakun/OneLife
void TextButton::setLabelText( const char *inLabelText ) {
    if( mLabelText != NULL ) {
        delete [] mLabelText;
        }
    
    mLabelText = stringDuplicate( inLabelText );
    

    // button width
    mWide = mFont->measureString( inLabelText ) + mFont->getFontHeight();
    
    // button height
    mHigh = 2 * mFont->getFontHeight();
    }
コード例 #26
0
char *nameParse( char *inNameString ) {

    char found;

    char *name = replaceAll( inNameString, "_", " ", &found );

    delete [] inNameString;

    if( strcmp( name, "You" ) == 0 ) {
        delete [] name;

        name = stringDuplicate( translate( "nameYou" ) );
    }

    return name;
}
コード例 #27
0
ファイル: IndexInput.cpp プロジェクト: Afreeca/qt
   TCHAR* IndexInput::readString(const bool _unique){
    int32_t len = readVInt();
      
    if ( len == 0){
      if ( _unique ) //todo: does non unique ever occur?
         return stringDuplicate(LUCENE_BLANK_STRING);
      else
         return LUCENE_BLANK_STRING;
    }

    TCHAR* ret = _CL_NEWARRAY(TCHAR,len+1);
    readChars(ret, 0, len);
    ret[len] = 0;

    return ret;
  }
コード例 #28
0
ChannelReceivingThread::ChannelReceivingThread (InputStream * inInputStream,
                                                OutboundChannel *
                                                inOutboundChannel,
                                                Socket * inSocket,
                                                char *inRemoteAddress,
                                                int inRemotePort,
                                                LocalAddressReceiver *
                                                inMessageReceiver,
                                                OutboundChannelManager *
                                                inOutboundChannelManager,
                                                void *inConnectionMaintainer,
                                                HostCatcher * inHostCatcher,
                                                MessageIDTracker *
                                                inMessageIDTracker,
                                                KbLimiter *
                                                inLimiter,
                                                RandomSource * inRandSource):
mLock (new QMutex ()),
mInputStream (inInputStream),
mOutboundChannel (inOutboundChannel),
mSocket (inSocket),
mRemoteAddress (stringDuplicate (inRemoteAddress)),
mRemotePort (inRemotePort),
mReceiver (inMessageReceiver),
mOutboundChannelManager (inOutboundChannelManager),
mConnectionMaintainer (inConnectionMaintainer),
mHostCatcher (inHostCatcher),
mMessageIDTracker (inMessageIDTracker),
mLimiter (inLimiter),
mStopSignal (false),
mFinished (false),
mLoggerName (NULL),
mRandSource (inRandSource)
{
    
    
    mLoggerName = autoSprintf ("ChannelReceivingThread %s:%d\n",
                               mRemoteAddress, mRemotePort);
    
    mMaxUtilityCounter = settings->getMaxMessageUtilitySetting();
    mUtilityAlpha = settings->getUtilityAlphaSetting();
    mUtilityBeta = settings->getUtilityBetaSetting();
    mUtilityGamma = settings->getUtilityGammaSetting();
    
    this->start ();
}
コード例 #29
0
ファイル: LocalAddressReceiver.cpp プロジェクト: nsb/Calypso
void LocalAddressReceiver::addReceiveAddress( char *inAddress ) {
    mReceiveAddressLock->lock();

    // make sure address not already added
    int index = findAddressIndex( inAddress );
    if( index != -1 ) {        
        mReceiveAddressLock->unlock();
        return;
        }
    
    // add address and a message queue
    mAddressVector->push_back( stringDuplicate( inAddress ) );
    mMessageQueueVector->push_back( new SimpleVector<char *>() );
    mFromAddressQueueVector->push_back( new SimpleVector<char *>() );
    
    mReceiveAddressLock->unlock();
    }
コード例 #30
0
ファイル: OutboundChannel.cpp プロジェクト: nsb/Calypso
char OutboundChannel::sendMessage( char * inMessage, int inPriority ) {
    mLock->lock();


    char sent;
    
    if( !mConnectionBroken ) {
        // add it to the queue
        SimpleVector<char *> *queueToUse;

        if( inPriority <=0 ) {
            queueToUse = mMessageQueue;
            }
        else {
            queueToUse = mHighPriorityMessageQueue;
            }

        
        queueToUse->push_back( stringDuplicate( inMessage ) );
        sent = true;

        if( queueToUse->size() > mMaxQueueSize ) {
            // the queue is over-full
            // drop the oldest message

            char *message = *( queueToUse->getElement( 0 ) );
            queueToUse->deleteElement( 0 );
            delete [] message;

            mDroppedMessageCount++;
            }
        }
    else {
        // channel no longer working
        sent = false;
        }
        
    mLock->unlock();

    if( sent ) {
        mMessageReadySemaphore->signal();
        }
    
    return sent;
    }