Exemple #1
0
result_t MongoCursor::count(bool applySkipLimit, int32_t &retVal)
{
    bson bbq;

    bson_init(&bbq);
    bson_append_string(&bbq, "count", m_name.c_str());

    Isolate* isolate = Isolate::now();
    if (m_bSpecial)
        encodeValue(&bbq, "query",
                    v8::Local<v8::Object>::New(isolate->m_isolate, m_query)->Get(v8::String::NewFromUtf8(isolate->m_isolate, "query")));
    else
        encodeValue(&bbq, "query", v8::Local<v8::Object>::New(isolate->m_isolate, m_query));

    if (applySkipLimit)
    {
        if (m_cursor->limit)
            bson_append_int(&bbq, "limit", m_cursor->limit);
        if (m_cursor->skip)
            bson_append_int(&bbq, "skip", m_cursor->skip);
    }

    bson_finish(&bbq);

    v8::Local<v8::Object> res;

    result_t hr = m_cursor->m_db->run_command(&bbq, res);
    if (hr < 0)
        return hr;

    retVal = res->Get(v8::String::NewFromUtf8(isolate->m_isolate, "n"))->Int32Value();

    return 0;
}
Exemple #2
0
bool encodeObject(bson *bb, const char *name, v8::Local<v8::Value> element,
                  bool doJson)
{
    v8::Local<v8::Object> object = element->ToObject();

    if (doJson)
    {
        v8::Local<v8::Value> jsonFun = object->Get(
                                           v8::String::NewFromUtf8(isolate, "toJSON",
                                                   v8::String::kNormalString, 6));

        if (!IsEmpty(jsonFun) && jsonFun->IsFunction())
        {
            v8::Local<v8::Value> p = v8::String::NewFromUtf8(isolate, name ? name : "");
            v8::Local<v8::Value> element1 = v8::Local<v8::Function>::Cast(
                                                jsonFun)->Call(object, 1, &p);

            if (name)
            {
                encodeValue(bb, name, element1, false);
                return true;
            }

            if (!element1->IsObject())
                return false;

            object = element1->ToObject();
        }
    }

    if (!name
            && (object->IsDate() || object->IsArray() || object->IsRegExp()
                || Buffer_base::getInstance(object)))
        return false;

    if (name)
        bson_append_start_object(bb, name);

    v8::Local<v8::Array> properties = object->GetPropertyNames();

    for (int i = 0; i < (int) properties->Length(); i++)
    {
        v8::Local<v8::Value> prop_name = properties->Get(i);
        v8::Local<v8::Value> prop_val = object->Get(prop_name);

        v8::String::Utf8Value n(prop_name);
        const char *pname = ToCString(n);

        encodeValue(bb, pname, prop_val);
    }

    if (name)
        bson_append_finish_object(bb);

    return true;
}
Exemple #3
0
void EncodeBuffer::encodeCachedValue(unsigned int value,
                                     unsigned int numBits,
                                     IntCache & cache,
                                     unsigned int blockSize)
{
    (void)blockSize;

    unsigned int newBlockSize = cache.getBlockSize(numBits);
    unsigned int index;
    unsigned int sameDiff;

    // The index is encoded as the number of leading zeros before a 1
    // bit. The index value 2 is a magic escape code.

    DBG("encodeIntCache.\n");

    if (cache.lookup(value, index, PARTIAL_INT_MASK[numBits], sameDiff))
    {
        encodeIndex(index);
    }
    else
    {
        encodeEscapeIndex();
        if (sameDiff)
            encodeDirect(1, 1);
        else
        {
            encodeDirect(0, 1);
            encodeValue(value, numBits, newBlockSize);
        }
    }
}
Exemple #4
0
void
builtInEncode (int numArgs, macroArgument *args, environment *env, outputWriter *ow)
{
    if (!(numArgs == 1))
    {
	issueError(ERRMAC_WRONG_NUM_ARGS, "encode");
	return;
    }

    encodeValue(args[0].value.value, ow);
}
Exemple #5
0
result_t MongoDB::runCommand(exlib::string cmd, v8::Local<v8::Value> arg,
                             v8::Local<v8::Object> &retVal)
{
    bson bbq;

    bson_init(&bbq);
    encodeValue(holder(), &bbq, cmd.c_str(), arg);
    bson_finish(&bbq);

    return bsonHandler(&bbq, retVal);
}
  bool
encodeFunctionCall(functionCallTermType *functionCall)
{
	functionDefinitionType	*theFunction;
	int			 functionOrdinal;
	symbolInContextType	*workingContext;
	operandListType		*parameterList;

	nullEncode(functionCall);
	workingContext = getWorkingContext(functionCall->functionName);
	if (isFunction(workingContext)) {
		if (!encodeByte(FUNCTION_CALL_TAG))
			return(FALSE);
		theFunction = (functionDefinitionType *)workingContext->
			value->value;
		if (!encodeBigword(functionNumber(theFunction)))
			return(FALSE);
	} else if (isBuiltInFunction(workingContext)) {
		functionOrdinal = workingContext->value->value;
		if (builtInFunctionTable[functionOrdinal].isSpecialFunction)
			return(encodeValue((*builtInFunctionTable[
				functionOrdinal].functionEntry)(functionCall->
				parameters, NO_FIXUP)));
		if (!encodeByte(BUILTIN_FUNCTION_CALL_TAG))
			return(FALSE);
		if (builtInFunctionTable[functionOrdinal].ordinal < 0) {
			error(BUILT_IN_FUNCTION_NOT_AVAILABLE_IN_OBJECT_ERROR,
				builtInFunctionTable[functionOrdinal].
				functionName);
			return(FALSE);
		} else if (!encodeBigword(builtInFunctionTable[
				functionOrdinal].ordinal)) {
			return(FALSE);
		}
	} else {
		error(NOT_A_FUNCTION_ERROR, symbName(functionCall->
			functionName));
		return(FALSE);
	}
	parameterList = functionCall->parameters;
	if (!encodeByte(countParameters(parameterList)))
		return(FALSE);
	while (parameterList != NULL)
		if (!encodeOperand(parameterList))
			return(FALSE);
		else
			parameterList = parameterList->nextOperand;
	return(TRUE);
}
Exemple #7
0
QVariantHash Asterisk::originate(QString channel,
                                 QString exten,
                                 QString context,
                                 uint priority,
                                 QString application,
                                 QString data,
                                 uint timeout,
                                 QString callerId,
                                 QVariantHash variables,
                                 QString account,
                                 bool earlyMedia,
                                 bool async,
                                 QStringList codecs)
{
    QVariantHash headers;
    headers["Channel"] = channel;
    headers["EarlyMedia"] = earlyMedia;
    headers["Async"] = async;

    insertNotEmpty(&headers, "Timeout", timeout);
    insertNotEmpty(&headers, "CallerID", callerId);
    insertNotEmpty(&headers, "Account", account);
    insertNotEmpty(&headers, "Codecs", codecs.join(","));

    if (!exten.isEmpty() && !context.isEmpty() && priority > 0) {
        headers["Exten"] = exten;
        headers["Context"] = context;
        headers["Priority"] = priority;
    }

    if (!application.isEmpty()) {
        headers["Application"] = application;

        insertNotEmpty(&headers, "Data", data);
    }

    if (!variables.isEmpty()) {
        QHashIterator<QString, QVariant> variable(variables);
        while (variable.hasNext()) {
            variable.next();

            headers.insertMulti("Variable", QString("%1=%2").arg(variable.key(), encodeValue(variable.value())));
        }
    }

    return sendPacket("Originate", headers);
}
Exemple #8
0
void encodeArray(bson *bb, const char *name, v8::Local<v8::Value> element)
{
    v8::Local<v8::Array> a = v8::Local<v8::Array>::Cast(element);

    bson_append_start_array(bb, name);

    for (int i = 0, l = a->Length(); i < l; i++)
    {
        v8::Local<v8::Value> val = a->Get(i);
        char numStr[32];

        sprintf(numStr, "%d", i);
        encodeValue(bb, numStr, val);
    }

    bson_append_finish_array(bb);
}
Exemple #9
0
void EncodeBuffer::encodeCachedValue(unsigned char value,
                                     unsigned int numBits,
                                     CharCache & cache,
                                     unsigned int blockSize)
{
    unsigned int index;

    DBG("encodeCharCache.\n");

    if (cache.lookup(value, index))
    {
        encodeIndex(index);
    }
    else
    {
        encodeEscapeIndex();
        encodeValue(value, numBits, blockSize);
    }
}
Exemple #10
0
QVariantHash Asterisk::sendPacket(QString action, QVariantHash headers)
{
    QString actionId = QUuid::createUuid().toString();

    if (socket.state() == QTcpSocket::ConnectedState) {
        headers["Action"] = action;
        headers["ActionID"] = actionId;

        QHashIterator<QString, QVariant> header(headers);
        while (header.hasNext()) {
            header.next();

            socket.write(QString("%1: %2\r\n").arg(header.key(), encodeValue(header.value())).toLatin1());
        }

        socket.write("\r\n");
        socket.flush();
        socket.waitForReadyRead();
    }

    return responses.take(actionId);
}
Exemple #11
0
void
encodeValue (value *theValue, outputWriter *ow)
{
    assert(theValue != 0);

    switch (theValue->type)
    {
	case VALUE_UNDEFINED :
	    return;

	case VALUE_INTERNAL :
	    OUT_STRING(ow, "<internal>", 10);
	    break;

	case VALUE_BUILT_IN :
	    OUT_STRING(ow, "<builtIn>", 9);
	    break;

	case VALUE_SCALAR :
	    encodeDynstring(&theValue->v.scalar.scalar, ow);
	    break;

	case VALUE_LIST :
	    {
		int i;

		OUT_CHAR(ow, metaChar);
		OUT_STRING(ow, "list(", 5);
		if (valueListLength(theValue) > 0)
		{
		    encodeValue(valueListGetElement(theValue, 0), ow);
		    for (i = 1; i < valueListLength(theValue); ++i)
		    {
			OUT_CHAR(ow, ',');
			encodeValue(valueListGetElement(theValue, i), ow);
		    }
		}
		OUT_CHAR(ow, ')');
	    }
	    break;

	case VALUE_HASH :
	    {
		value *aValue,
		    *keyValue;
		char *aKey;
		hstate state;

		OUT_CHAR(ow, metaChar);
		OUT_STRING(ow, "hash(", 5);
		state = hash_state(theValue->v.hash.hash);
		if ((aValue = (value*)hash_next(&state, &aKey)) != 0)
		{
		    keyValue = valueNewScalarFromCString(aKey);
		    encodeValue(keyValue, ow);
		    OUT_CHAR(ow, ',');
		    encodeValue(aValue, ow);
		    while ((aValue = (value*)hash_next(&state, &aKey)) != 0)
		    {
			OUT_CHAR(ow, ',');
			keyValue = valueNewScalarFromCString(aKey);
			encodeValue(keyValue, ow);
			OUT_CHAR(ow, ',');
			encodeValue(aValue, ow);
		    }
		}
		OUT_CHAR(ow, ')');
	    }
	    break;

	case VALUE_LAMBDA :
	    {
		int i;

		OUT_CHAR(ow, metaChar);
		OUT_STRING(ow, "lambda(", 7);
		for (i = 0; i < theValue->v.lambda.numParams; ++i)
		{
		    encodeDynstring(&theValue->v.lambda.paramNames[i], ow);
		    OUT_CHAR(ow, ',');
		}
		encodeBytecode(theValue->v.lambda.code, ow);
		OUT_CHAR(ow, ')');
	    }
	    break;

	case VALUE_ENVIRONMENT :
	    OUT_STRING(ow, "<environment>", 13);
	    break;

	case VALUE_BYTECODE :
	    OUT_STRING(ow, "<bytecode>", 10);
	    break;

	case VALUE_WHATSIT :
	    OUT_STRING(ow, "<whatsit>", 9);
	    break;

	default :
	    assert(0);
    }
}
void SmtpConfigurationEditor::setSmtpPassword(const QString& str)
{
    setValue("smtppassword", encodeValue(str));
}
  bool
encodeExpression(expressionType *expression)
{
	nullEncode(expression);
	switch (expression->kindOfTerm) {

	case ARRAY_EXPR:
		error(ARRAY_TERM_IN_OBJECT_EXPRESSION_ERROR);
		return(FALSE);
		break;

	case ASSIGN_EXPR:
		return(encodeAssignmentTerm(expression->expressionTerm.binopUnion));
		break;

	case BINOP_EXPR:
		return(encodeBinopTerm(expression->expressionTerm.binopUnion));
		break;

	case CONDITION_CODE_EXPR:
		return(encodeCondition(expression->expressionTerm.conditionTypeUnion));
		break;

	case FUNCTION_CALL_EXPR:
		return(encodeFunctionCall(expression->expressionTerm.functionCallUnion));
		break;

	case HERE_EXPR:
		return(encodeHere());
		break;

	case IDENTIFIER_EXPR:
		return(encodeIdentifier(expression->expressionTerm.identifierUnion));
		break;

	case NUMBER_EXPR:
		return(encodeNumber(expression->expressionTerm.numberUnion));
		break;

	case POSTOP_EXPR:
		return(encodePostopTerm(expression->expressionTerm.postOpUnion));
		break;

	case PREOP_EXPR:
		return(encodePreopTerm(expression->expressionTerm.preOpUnion));
		break;

	case SUBEXPRESSION_EXPR:
		encodeExpression(expression->expressionTerm.expressionUnion);
		break;

	case STRING_EXPR:
		return(encodeString(expression->expressionTerm.stringUnion));
		break;

	case UNOP_EXPR:
		return(encodeUnopTerm(expression->expressionTerm.unopUnion));
		break;

	case VALUE_EXPR:
		return(encodeValue(expression->expressionTerm.valueUnion));
		break;

	default:
		botch("encodeExpression: funny expression kind %d\n",
			expression->kindOfTerm);
		break;
	}
}
  bool
encodeIdentifier(symbolTableEntryType *identifier)
{
	symbolInContextType	*workingContext;
	environmentType		*saveEnvironment;
	bool			 result;

	nullEncode(identifier);

	if (symbName(identifier)[0] == '$') {
		error(TEMP_SYMBOL_IN_OBJECT_ERROR, symbName(identifier));
		return(FALSE);
	}
	if (encodingFunction) {
		return(encodeByte(IDENTIFIER_TAG) &&
		       encodeBigword(identifier->ordinal));
	}
	if ((workingContext = getWorkingContext(identifier)) == NULL) {
		error(UNDEFINED_SYMBOL_ERROR, symbName(identifier));
		return(FALSE);
	}
	if (workingContext->usage == FUNCTION_SYMBOL || workingContext->usage
			== BUILT_IN_FUNCTION_SYMBOL) {
		error(FUNCTION_IS_NOT_A_VALUE_ERROR, symbName(identifier));
		return(FALSE);
	}
	if (workingContext->value == NULL) {
		error(UNDEFINED_SYMBOL_ERROR, symbName(identifier));
		return(FALSE);
	}
	if (workingContext->value->kindOfValue == UNDEFINED_VALUE) {
		if (workingContext->attributes & GLOBAL_ATT) {
			return(encodeByte(IDENTIFIER_TAG) &&
			       encodeBigword(identifier->ordinal));
		} else {
			error(UNDEFINED_SYMBOL_ERROR, symbName(identifier));
			return(FALSE);
		}
	}
	if (workingContext->value->kindOfValue == RELOCATABLE_VALUE) {
		return(encodeByte(IDENTIFIER_TAG) &&
		       encodeBigword(identifier->ordinal));
	}
	if (workingContext->value->kindOfValue == FAIL) {
		error(UNASSIGNED_SYMBOL_ERROR, symbName(identifier));
		return(FALSE);
	}
	if (workingContext->value->kindOfValue == OPERAND_VALUE) {
		saveEnvironment = currentEnvironment;
		if (workingContext->usage == ARGUMENT_SYMBOL) {
			currentEnvironment = currentEnvironment->
				previousEnvironment;
		}
		result = encodeOperand(workingContext->value->value);
		currentEnvironment = saveEnvironment;
		return(result);
	}
	if (workingContext->value->kindOfValue == BLOCK_VALUE) {
		error(BLOCK_OPERAND_IN_OBJECT_EXPRESSION_ERROR);
		return(FALSE);
	}
	return(encodeValue(workingContext->value));
}
Exemple #15
0
void encodeValue(bson *bb, const char *name, v8::Local<v8::Value> element)
{
    encodeValue(bb, name, element, true);
}