Example #1
0
c_bool
u_cfValueScan(
    c_value value,
    c_valueKind valueKind,
    c_value *valuePtr)
{
    int i;
    c_bool result = FALSE;

    if (value.kind == V_STRING) {
        switch (valueKind) {
        __CASE__(CHAR,c_char);
        __CASE__(SHORT,c_short);
        __CASE__(USHORT,c_ushort);
        __CASE__(LONG,c_long);
        __CASE__(ULONG,c_ulong);
        __CASE__(LONGLONG,c_longlong);
        __CASE__(ULONGLONG,c_ulonglong);
        __CASE__(FLOAT,c_float);
        case V_BOOLEAN:
        {
            c_bool dest;
            result = u_cfValueScanBoolean(value.is.String, &dest);
            if (result) {
                *valuePtr = c_boolValue(dest);
            }
        }
        break;
        case V_STRING:
        {
             c_char *str;
             c_ulong length;

             length = (c_ulong)strlen(value.is.String);
             str = os_malloc(length + 1U);
             os_strncpy(str, value.is.String, length);
             str[length] = 0;
             *valuePtr = c_stringValue(str);
             result = TRUE;
        }
        break;
        case V_OCTET:
        case V_DOUBLE:
        default:
            result = FALSE;
            assert(0); /* Catch unhandled case */
        break;
        }
    } else {
        result = FALSE;
    }

    return result;
}
Example #2
0
static in_result
in_ddsiStreamReaderImplDerializePayloadByKeyHash(
	in_ddsiStreamReaderImpl _this,
	in_ddsiSubmessageData submessage,
	in_connectivityPeerWriter peerWriter,
	v_topic topic,
	v_message *messageObject,
	c_octet* keyHash)
{
	in_result result;
	c_long nrOfKeys, i, bytesCopied;
	c_array messageKeyList;
	c_value value;
	c_base base;

	assert(_this);
	assert(submessage);
	assert(peerWriter);
	assert(topic);
	assert(*messageObject);

	messageKeyList = v_topicMessageKeyList(topic);
	nrOfKeys = c_arraySize(messageKeyList);
	bytesCopied = 0;
	base = c_getBase(topic);
	result = IN_RESULT_OK;

	/*TODO: In case key is larger then 16 bytes, MD5 must be used*/
	for (i=0;(i<nrOfKeys) && (result == IN_RESULT_OK);i++)
	{
		switch(c_fieldValueKind(messageKeyList[i]))
		{
		case V_BOOLEAN:
			value = c_boolValue(*((c_bool*)&(keyHash[bytesCopied])));
			bytesCopied += sizeof(c_bool);
		break;
		case V_OCTET:
			value = c_octetValue(*((c_octet*)&(keyHash[bytesCopied])));
			bytesCopied += sizeof(c_octet);
		break;
		case V_SHORT:
#ifdef PA_BIG_ENDIAN
			value = c_shortValue(*((c_short*)&(keyHash[bytesCopied])));
#else
			value = c_shortValue(IN_UINT16_SWAP_LE_BE(*((c_short*)&(keyHash[bytesCopied]))));
#endif
			bytesCopied += sizeof(c_short);
		break;
		case V_USHORT:
#ifdef PA_BIG_ENDIAN
			value = c_ushortValue(*((c_ushort*)&(keyHash[bytesCopied])));
#else
			value = c_ushortValue(IN_UINT16_SWAP_LE_BE(*((c_ushort*)&(keyHash[bytesCopied]))));
#endif
			bytesCopied += sizeof(c_ushort);
		break;
		case V_LONG:
#ifdef PA_BIG_ENDIAN
			value = c_longValue(*((c_long*)&(keyHash[bytesCopied])));
#else
			value = c_longValue(IN_UINT32_SWAP_LE_BE(*((c_long*)&(keyHash[bytesCopied]))));
#endif
			bytesCopied += sizeof(c_long);
		break;

		case V_ULONG:
#ifdef PA_BIG_ENDIAN
			value = c_ulongValue(*((c_ulong*)&(keyHash[bytesCopied])));
#else
			value = c_ulongValue(IN_UINT32_SWAP_LE_BE(*((c_ulong*)&(keyHash[bytesCopied]))));
#endif
			bytesCopied += sizeof(c_long);
		break;
		case V_CHAR:
			value = c_charValue(*((c_char*)&(keyHash[bytesCopied])));
			bytesCopied += sizeof(c_char);
		break;
		case V_STRING:
#ifdef PA_BIG_ENDIAN
			value = c_ulongValue(*((c_ulong*)&(keyHash[bytesCopied])));
#else
			value = c_ulongValue(IN_UINT32_SWAP_LE_BE(*((c_ulong*)&(keyHash[bytesCopied]))));
#endif
			bytesCopied += 4;
			/*TODO: validate the string copy algorithm*/
			if(value.is.ULong != 0)
			{
				value = c_stringValue(
					c_stringNew(base,((c_string)(&(keyHash[bytesCopied])))));
				bytesCopied += strlen(value.is.String) + 1;
			} else
			{
				value = c_stringValue(c_stringNew(base, ""));
				bytesCopied += 1;
			}
		break;
		case V_DOUBLE:
			value = c_undefinedValue();
			bytesCopied += sizeof(c_double);
			result = IN_RESULT_PRECONDITION_NOT_MET;
		break;
		case V_FLOAT:
			value = c_undefinedValue();
			bytesCopied += sizeof(c_float);
			result = IN_RESULT_PRECONDITION_NOT_MET;
		break;
		case V_ULONGLONG:
			value = c_undefinedValue();
			bytesCopied += sizeof(c_ulonglong);
			result = IN_RESULT_PRECONDITION_NOT_MET;
		break;
		case V_LONGLONG:
			value = c_undefinedValue();
			bytesCopied += sizeof(c_longlong);
			result = IN_RESULT_PRECONDITION_NOT_MET;
		break;
		default:
			value = c_undefinedValue();
			assert(FALSE);
			result = IN_RESULT_ERROR;
		break;
		}
		c_fieldAssign(messageKeyList[i],*messageObject, value);
		c_valueFreeRef(value);
	}

	return result;
}