Example #1
0
 int ShardKeyPattern::compare( const BSONObj& lObject , const BSONObj& rObject ) const {
     BSONObj L = extractKey(lObject);
     uassert( 10198 , "left object doesn't have full shard key", L.nFields() == (int)patternfields.size());
     BSONObj R = extractKey(rObject);
     uassert( 10199 , "right object doesn't have full shard key", R.nFields() == (int)patternfields.size());
     return L.woCompare(R);
 }
Example #2
0
 int ShardKeyPattern::compare( const BSONObj& lObject , const BSONObj& rObject ) const {
     BSONObj L = extractKey(lObject);
     uassert( 10198 , str::stream() << "left object ("  << lObject << ") doesn't have full shard key (" << pattern << ')',
             L.nFields() == (int)patternfields.size());
     BSONObj R = extractKey(rObject);
     uassert( 10199 , str::stream() << "right object (" << rObject << ") doesn't have full shard key (" << pattern << ')',
             R.nFields() == (int)patternfields.size());
     return L.woCompare(R);
 }
void DocumentSourceSort::loadDocument(const Document& doc) {
    invariant(!populated);
    if (!_sorter) {
        _sorter.reset(MySorter::make(makeSortOptions(), Comparator(*this)));
    }
    _sorter->add(extractKey(doc), doc);
}
Example #4
0
void Settings::update() {
    std::string name;
    std::string value;

    m_values.clear();

    std::ifstream settings(m_fileName.c_str());
    if (!settings.is_open()) {
        std::cout << "Failed to open " << m_fileName << "\n";
        return;
    }

    do {
        std::getline(settings, m_rawStr);

        m_index = 0;
        name = extractKey();
        value = extractValue();

        // Add name-value pair to map
        m_values[name] = value;
    } while (!settings.eof());

    settings.close();

    std::cout << "Settings loaded from " << m_fileName << "\n";
}
Example #5
0
void decryptWhatsappDatabase7(const std::string &filename, const std::string &filenameDecrypted, const std::string &keyFilename)
{
	unsigned char key[32];
	unsigned char iv[16];

	extractKey(keyFilename, key, iv);
	decryptWhatsappDatabase7(filename, filenameDecrypted, key, iv);
}
Example #6
0
void ConfigFile::extractContents(const std::string &line)
{
    std::string temp = line;
    temp.erase(0, temp.find_first_not_of("\t "));
    size_t sepPos = temp.find('=');

    std::string key, value;
    extractKey(key, sepPos, temp);
    extractValue(value, sepPos, temp);

    if (!keyExists(key))
        contents.insert(std::pair<std::string, std::string > (key, value));
    else
        std::cout << "CFG: Can only have unique key names!\n" << std::endl;
}
Example #7
0
void Config::extractLine(const std::string& section, const std::string& line, std::ifstream& file, int& lineNb)
{
    std::string temp = line;
    temp.erase(0, temp.find_first_not_of(" \t\r\n\v\f"));
    size_t sepPos = temp.find('=');

    std::string key;
    std::string value;
    extractKey(key, sepPos, temp);
    key = section.substr(1, section.length()-2) + "." + key;
    extractValue(value, sepPos, temp);

    if (!isKeyExists(key)) {
        _map.insert(std::pair<std::string, std::string>(key, value));
    }
    else {
		Log(LOG_TYPE::ERROR) << "Config: Can only have unique key names!";
    }
}
void DocumentSourceSort::populate() {
    if (_mergingPresorted) {
        typedef DocumentSourceMergeCursors DSCursors;
        typedef DocumentSourceCommandShards DSCommands;
        if (DSCursors* castedSource = dynamic_cast<DSCursors*>(pSource)) {
            populateFromCursors(castedSource->getCursors());
        } else if (DSCommands* castedSource = dynamic_cast<DSCommands*>(pSource)) {
            populateFromBsonArrays(castedSource->getArrays());
        } else {
            msgasserted(17196, "can only mergePresorted from MergeCursors and CommandShards");
        }
    } else {
        scoped_ptr<MySorter> sorter (MySorter::make(makeSortOptions(), Comparator(*this)));
        while (boost::optional<Document> next = pSource->getNext()) {
            sorter->add(extractKey(*next), *next);
        }
        _output.reset(sorter->done());
    }
    populated = true;
}
    void DocumentSourceSort::populate() {
        /* make sure we've got a sort key */
        verify(vSortKey.size());

        SortOptions opts;
        if (limitSrc)
            opts.limit = limitSrc->getLimit();

        opts.maxMemoryUsageBytes = 100*1024*1024;
        opts.extSortAllowed = pExpCtx->extSortAllowed && !pExpCtx->inRouter;

        scoped_ptr<MySorter> sorter (MySorter::make(opts, Comparator(*this)));

        while (boost::optional<Document> next = pSource->getNext()) {
            sorter->add(extractKey(*next), *next);
        }

        _output.reset(sorter->done());
        populated = true;
    }
Example #10
0
void ConfigFile::extractContents(const std::string &line)
{
	// called from parse_line(), validated there

	std::string tmp = line;
	// remove leading whitespace
	tmp.erase(0, tmp.find_first_not_of("\t "));
	size_t sep_pos = tmp.find('=');

	std::string key, value;
	extractKey(key, sep_pos, tmp);
	extractValue(value, sep_pos, tmp);

	if (!containsKey(key))
	{
		contents.insert(std::pair<std::string, std::string>(key, value));
	}
	else
	{
		ConfigUtil::warn(key + " was declared at least twice in configuration file.");
	}
}
Example #11
0
static void findJavaPropertiesTags (void)
{
	const unsigned char *line;
	bool in_value = false;
	bool value_continues;
	static vString *key;

	if (key == NULL)
		key = vStringNew ();
	else
		vStringClear (key);

	while ((line = readLineFromInputFile ()) != NULL)
	{
		if (in_value)
		{
			value_continues = doesValueContinue (line);
			if (!value_continues)
				in_value = false;
			continue;
		}

		line = skipWhiteSpace (line);
		if (*line == '\0'
		    || *line == '!' || *line == '#')
			continue;

		line = extractKey (line, key);
		makeSimpleTag (key, K_KEY);
		vStringClear (key);

		value_continues = doesValueContinue (line);
		if (value_continues)
			in_value = true;
	}
}
Example #12
0
    QueryResult* processGetMore(const char* ns,
                                int ntoreturn,
                                long long cursorid,
                                CurOp& curop,
                                int pass,
                                bool& exhaust,
                                bool* isCursorAuthorized ) {

        bool hasRunner = false;

        // Scoped to kill the pin after seeing if the runner's there.
        {
            // See if there's a runner.  We do this until agg. is behind a Runner instead of a CC.
            ClientCursorPin p(cursorid);
            ClientCursor *cc = p.c();
            if (NULL != cc && NULL != cc->getRunner()) {
                hasRunner = true;
            }
        }

        if (hasRunner) {
            return newGetMore(ns, ntoreturn, cursorid, curop, pass, exhaust,
                              isCursorAuthorized);
        }

        exhaust = false;

        int bufSize = 512 + sizeof( QueryResult ) + MaxBytesToReturnToClientAtOnce;

        BufBuilder b( bufSize );
        b.skip(sizeof(QueryResult));
        int resultFlags = ResultFlag_AwaitCapable;
        int start = 0;
        int n = 0;

        scoped_ptr<Client::ReadContext> ctx(new Client::ReadContext(ns));
        // call this readlocked so state can't change
        replVerifyReadsOk();

        ClientCursorPin p(cursorid);
        ClientCursor *cc = p.c();

        if ( unlikely(!cc) ) {
            LOGSOME << "getMore: cursorid not found " << ns << " " << cursorid << endl;
            cursorid = 0;
            resultFlags = ResultFlag_CursorNotFound;
        }
        else {
            // Some internal users create a ClientCursor with a Runner.  Don't crash if this
            // happens.  Instead, hand them off to the new framework.
            if (NULL != cc->getRunner()) {
                p.release();
                return newGetMore(ns, ntoreturn, cursorid, curop, pass, exhaust, isCursorAuthorized);
            }

            // check for spoofing of the ns such that it does not match the one originally there for the cursor
            uassert(14833, "auth error", str::equals(ns, cc->ns().c_str()));

            *isCursorAuthorized = true;

            // This must be done after auth check to ensure proper cleanup.
            uassert(16951, "failing getmore due to set failpoint",
                    !MONGO_FAIL_POINT(getMoreError));

            // If the operation that spawned this cursor had a time limit set, apply leftover
            // time to this getmore.
            curop.setMaxTimeMicros( cc->getLeftoverMaxTimeMicros() );
            killCurrentOp.checkForInterrupt(); // May trigger maxTimeAlwaysTimeOut fail point.

            if ( pass == 0 )
                cc->updateSlaveLocation( curop );

            int queryOptions = cc->queryOptions();
            
            curop.debug().query = cc->query();
            curop.setQuery( cc->query() );

            start = cc->pos();
            Cursor *c = cc->c();

            if (!c->requiresLock()) {
                // make sure it won't be destroyed under us
                fassert(16952, !c->shouldDestroyOnNSDeletion());
                fassert(16953, !c->supportYields());
                ctx.reset(); // unlocks
            }

            c->recoverFromYield();
            DiskLoc last;

            // This metadata may be stale, but it's the state of chunking when the cursor was
            // created.
            CollectionMetadataPtr metadata = cc->getCollMetadata();
            KeyPattern keyPattern( metadata ? metadata->getKeyPattern() : BSONObj() );

            while ( 1 ) {
                if ( !c->ok() ) {
                    if ( c->tailable() ) {
                        // when a tailable cursor hits "EOF", ok() goes false, and current() is
                        // null.  however advance() can still be retries as a reactivation attempt.
                        // when there is new data, it will return true.  that's what we are doing
                        // here.
                        if ( c->advance() )
                            continue;

                        if( n == 0 && (queryOptions & QueryOption_AwaitData) && pass < 1000 ) {
                            return 0;
                        }

                        break;
                    }
                    p.release();
                    bool ok = ClientCursor::erase(cursorid);
                    verify(ok);
                    cursorid = 0;
                    cc = 0;
                    break;
                }

                MatchDetails details;
                if ( cc->fields && cc->fields->getArrayOpType() == Projection::ARRAY_OP_POSITIONAL ) {
                    // field projection specified, and contains an array operator
                    details.requestElemMatchKey();
                }

                // in some cases (clone collection) there won't be a matcher
                if ( !c->currentMatches( &details ) ) {
                }
                else if ( metadata && !metadata->keyBelongsToMe( extractKey(c, keyPattern ) ) ) {
                    LOG(2) << "cursor skipping document in un-owned chunk: " << c->current()
                               << endl;
                }
                else {
                    if( c->getsetdup(c->currLoc()) ) {
                        //out() << "  but it's a dup \n";
                    }
                    else {
                        last = c->currLoc();
                        n++;

                        // Fill out the fields requested by the query.
                        const Projection::KeyOnly *keyFieldsOnly = c->keyFieldsOnly();
                        if ( keyFieldsOnly ) {
                            fillQueryResultFromObj( b, 0, keyFieldsOnly->hydrate(
                            c->currKey() ), &details );
                        }
                        else {
                            DiskLoc loc = c->currLoc();
                            fillQueryResultFromObj( b, cc->fields.get(), c->current(), &details,
                                    ( ( cc->pq.get() && cc->pq->showDiskLoc() ) ? &loc : 0 ) );
                        }

                        if ( ( ntoreturn && n >= ntoreturn ) || b.len() > MaxBytesToReturnToClientAtOnce ) {
                            c->advance();
                            cc->incPos( n );
                            break;
                        }
                    }
                }
                c->advance();

                if ( ! cc->yieldSometimes( ( c->ok() && c->keyFieldsOnly() ) ?
                                          ClientCursor::DontNeed : ClientCursor::WillNeed ) ) {
                    ClientCursor::erase(cursorid);
                    cursorid = 0;
                    cc = 0;
                    break;
                }
            }
            
            if ( cc ) {
                if ( c->supportYields() ) {
                    ClientCursor::YieldData data;
                    verify( cc->prepareToYield( data ) );
                }
                else {
                    cc->c()->noteLocation();
                }
                cc->storeOpForSlave( last );
                exhaust = cc->queryOptions() & QueryOption_Exhaust;

                // If the getmore had a time limit, remaining time is "rolled over" back to the
                // cursor (for use by future getmore ops).
                cc->setLeftoverMaxTimeMicros( curop.getRemainingMaxTimeMicros() );
            }
        }

        QueryResult *qr = (QueryResult *) b.buf();
        qr->len = b.len();
        qr->setOperation(opReply);
        qr->_resultFlags() = resultFlags;
        qr->cursorId = cursorid;
        qr->startingFrom = start;
        qr->nReturned = n;
        b.decouple();

        return qr;
    }
Example #13
0
int Aleat::generate(std::string key)
{
    std::vector<int> kest = extractKey(key);
    return generate(kest.at(0), kest.at(1), kest.at(2));
}
Example #14
0
bool CManager::EvalKeys(
                    const char          *p,
                    const unsigned char *rsaString,
                    char                *encrypted )
{
    bool    ret = false;
    char    target[BUFSIZ];

    sprintf( target, "usernameFor%s", (const char *)m_serviceSymbol );
    if ( evalKey( p, target, m_username ) )
        ret = true;
    if ( ret == false ) {
        sprintf( target, "passwordFor%sEncrypted",
                 (const char *)m_serviceSymbol );
        if ( evalKey( p, target, encrypted ) ) {
            extractKey( m_password,
                        (unsigned char *)encrypted,
                        (unsigned char *)rsaString );
            ret = true;
        }
    }

    if ( ret == false ) {
        sprintf( target, "useOAuthFor%s",
                 (const char *)m_serviceSymbol );
        if ( evalKey( p, target, m_useOAuth ) )
            ret = true;
    }
    if ( ret == false ) {
        sprintf( target, "useBasicFor%s",
                 (const char *)m_serviceSymbol );
        if ( evalKey( p, target, m_useBASIC ) )
            ret = true;
    }

    if ( ret == false ) {
        sprintf( target, "oauthTokenFor%sEncrypted",
                 (const char *)m_serviceSymbol );
        if ( evalKey( p, target, encrypted ) ) {
            extractKey( m_oauthToken,
                        (unsigned char *)encrypted,
                        (unsigned char *)rsaString );
            ret = true;
        }
    }
    if ( ret == false ) {
        sprintf( target, "oauthTokenSecretFor%sEncrypted",
                 (const char *)m_serviceSymbol );
        if ( evalKey( p, target, encrypted ) ) {
            extractKey( m_oauthTokenSecret,
                        (unsigned char *)encrypted,
                        (unsigned char *)rsaString );
            ret = true;
        }
    }

    if ( ret == false ) {
        sprintf( target, "screennameFor%s",
                 (const char *)m_serviceSymbol );
        if ( evalKey( p, target, m_screenName ) )
            ret = true;
    }
    if ( ret == false ) {
        sprintf( target, "simultaneousPostAs%s",
                 (const char *)m_serviceSymbol );
        if ( evalKey( p, target, m_simultaneousPost ) )
            ret = true;
    }
    if ( ret == false )
        ret = EvalKeys( &m_sFriendsTimeline, "Friends", p );
    if ( ret == false )
        ret = EvalKeys( &m_sPublicTimeline,  "Public",  p );
    if ( ret == false )
        ret = EvalKeys( &m_sUserTimeline,    "User",    p );

    return ( ret );
}