FreeBSD/sys/dev/hyperv/utilities/hv_kvp.c
/*
 * Prepare a host kvp msg based on user kvp msg (utf8 to utf16)
 */
Prepare a host kvp msg based on user kvp msg (utf8 to utf16)
Prepare a host kvp msg based on user kvp msg ( utf8 to utf16 )
static int
hv_kvp_convert_usermsg_to_hostmsg(struct hv_kvp_msg *umsg, struct hv_kvp_msg *hmsg)
{
	int hkey_len = 0, hvalue_len = 0, utf_err = 0;
	struct hv_kvp_exchg_msg_value *host_exchg_data;
	char *key_name, *value;
	struct hv_kvp_ip_msg *host_ip_msg = (struct hv_kvp_ip_msg *)hmsg;
	switch (hmsg->kvp_hdr.operation) {
	case HV_KVP_OP_GET_IP_INFO:
		return (hv_kvp_convert_utf8_ipinfo_to_utf16(umsg, host_ip_msg));
	case HV_KVP_OP_SET_IP_INFO:
	case HV_KVP_OP_SET:
	case HV_KVP_OP_DELETE:
		return (KVP_SUCCESS);
	case HV_KVP_OP_ENUMERATE:
		host_exchg_data = &hmsg->body.kvp_enum_data.data;
		key_name = umsg->body.kvp_enum_data.data.key;
		hkey_len = utf8_to_utf16((uint16_t *)host_exchg_data->key,
				((HV_KVP_EXCHANGE_MAX_KEY_SIZE / 2) - 2),
				key_name, strlen(key_name),
				1, &utf_err);
		host_exchg_data->key_size = 2 * (hkey_len + 1);
		value = umsg->body.kvp_enum_data.data.msg_value.value;
		hvalue_len = utf8_to_utf16(
				(uint16_t *)host_exchg_data->msg_value.value,
				((HV_KVP_EXCHANGE_MAX_VALUE_SIZE / 2) - 2),
				value, strlen(value),
				1, &utf_err);
		host_exchg_data->value_size = 2 * (hvalue_len + 1);
		host_exchg_data->value_type = HV_REG_SZ;
		if ((hkey_len < 0) || (hvalue_len < 0))
			return (HV_KVP_E_FAIL);
		return (KVP_SUCCESS);
	case HV_KVP_OP_GET:
		host_exchg_data = &hmsg->body.kvp_get.data;
		value = umsg->body.kvp_get.data.msg_value.value;
		hvalue_len = utf8_to_utf16(
				(uint16_t *)host_exchg_data->msg_value.value,
				((HV_KVP_EXCHANGE_MAX_VALUE_SIZE / 2) - 2),
				value, strlen(value),
				1, &utf_err);
		host_exchg_data->value_size = 2 * (hvalue_len + 1);
		host_exchg_data->value_type = HV_REG_SZ;
		if ((hkey_len < 0) || (hvalue_len < 0))
			return (HV_KVP_E_FAIL);
		return (KVP_SUCCESS);
	default:
		return (HV_KVP_E_FAIL);
	}
}
static int hv_kvp_convert_usermsg_to_hostmsg ( struct hv_kvp_msg * umsg , struct hv_kvp_msg * hmsg ) { int hkey_len = 0 , hvalue_len = 0 , utf_err = 0 ; struct hv_kvp_exchg_msg_value * host_exchg_data ; char * key_name , * value ; struct hv_kvp_ip_msg * host_ip_msg = ( struct hv_kvp_ip_msg * ) hmsg ; switch ( hmsg -> kvp_hdr . operation ) { case HV_KVP_OP_GET_IP_INFO : return ( hv_kvp_convert_utf8_ipinfo_to_utf16 ( umsg , host_ip_msg ) ) ; case HV_KVP_OP_SET_IP_INFO : case HV_KVP_OP_SET : case HV_KVP_OP_DELETE : return ( KVP_SUCCESS ) ; case HV_KVP_OP_ENUMERATE : host_exchg_data = & hmsg -> body . kvp_enum_data . data ; key_name = umsg -> body . kvp_enum_data . data . key ; hkey_len = utf8_to_utf16 ( ( uint16_t * ) host_exchg_data -> key , ( ( HV_KVP_EXCHANGE_MAX_KEY_SIZE / 2 ) - 2 ) , key_name , strlen ( key_name ) , 1 , & utf_err ) ; host_exchg_data -> key_size = 2 * ( hkey_len + 1 ) ; value = umsg -> body . kvp_enum_data . data . msg_value . value ; hvalue_len = utf8_to_utf16 ( ( uint16_t * ) host_exchg_data -> msg_value . value , ( ( HV_KVP_EXCHANGE_MAX_VALUE_SIZE / 2 ) - 2 ) , value , strlen ( value ) , 1 , & utf_err ) ; host_exchg_data -> value_size = 2 * ( hvalue_len + 1 ) ; host_exchg_data -> value_type = HV_REG_SZ ; if ( ( hkey_len < 0 ) || ( hvalue_len < 0 ) ) return ( HV_KVP_E_FAIL ) ; return ( KVP_SUCCESS ) ; case HV_KVP_OP_GET : host_exchg_data = & hmsg -> body . kvp_get . data ; value = umsg -> body . kvp_get . data . msg_value . value ; hvalue_len = utf8_to_utf16 ( ( uint16_t * ) host_exchg_data -> msg_value . value , ( ( HV_KVP_EXCHANGE_MAX_VALUE_SIZE / 2 ) - 2 ) , value , strlen ( value ) , 1 , & utf_err ) ; host_exchg_data -> value_size = 2 * ( hvalue_len + 1 ) ; host_exchg_data -> value_type = HV_REG_SZ ; if ( ( hkey_len < 0 ) || ( hvalue_len < 0 ) ) return ( HV_KVP_E_FAIL ) ; return ( KVP_SUCCESS ) ; default : return ( HV_KVP_E_FAIL ) ; } }
Prepare a host kvp msg based on user kvp msg (utf8 to utf16)
Prepare a host kvp msg based on user kvp msg ( utf8 to utf16 )
/* utf16 encoding */ /* Convert value size to uft16 */ /* Use values by string */