[3/5] topology: Change uuid value to 16 separate characters in text conf file
diff mbox

Message ID d3cf452fd17a9ae3b2346ad3a75c8f07e28124c4.1468397702.git.mengdong.lin@linux.intel.com
State New
Headers show

Commit Message

mengdong.lin@linux.intel.com July 13, 2016, 8:44 a.m. UTC
From: Mengdong Lin <mengdong.lin@linux.intel.com>

Previously in text conf file, the uuid value of vendor tuples is a
16-characer string. Now change it to 16 characters separated by commas,
easier for users to edit it manually.

Signed-off-by: Mengdong Lin <mengdong.lin@linux.intel.com>

Comments

Takashi Sakamoto July 13, 2016, 9:46 a.m. UTC | #1
Hi,

On Jul 13 2016 17:44, mengdong.lin@linux.intel.com wrote:
> From: Mengdong Lin <mengdong.lin@linux.intel.com>
>
> Previously in text conf file, the uuid value of vendor tuples is a
> 16-characer string. Now change it to 16 characters separated by commas,
> easier for users to edit it manually.
>
> Signed-off-by: Mengdong Lin <mengdong.lin@linux.intel.com>
>
> diff --git a/include/topology.h b/include/topology.h
> index d666505..89bed6c 100644
> --- a/include/topology.h
> +++ b/include/topology.h
> @@ -273,8 +273,8 @@ extern "C" {
>    *		...
>    *	}
>    *
> - *	tuples."uuid" {
> - *		VENDOR_TOKEN_ID2 "16 character uuid"
> + *	tuples."uuid" {			# 16 characters separated by commas
> + *		VENDOR_TOKEN_ID2 "0x01,0x02,...,0x0f"
>    *		...
>    *	}
>    *
> diff --git a/src/topology/data.c b/src/topology/data.c
> index 7ff178f..65054d7 100644
> --- a/src/topology/data.c
> +++ b/src/topology/data.c
> @@ -176,6 +176,49 @@ static int get_hex_num(const char *str)
>   	return values;
>   }
>
> +/* get uuid from a string made by 16 characters separated by commas */
> +static int get_uuid(const char *str, unsigned char *uuid_le)

data.c:184:12: note: expected ‘unsigned char *’ but argument is of type 
‘char *’
  static int get_uuid(const char *str, unsigned char *uuid_le)
             ^

> +{
> +	unsigned long int  val;
> +	char *tmp, *s = NULL;
> +	int values = 0, ret = 0;
> +
> +	tmp = strdup(str);
> +	if (tmp == NULL)
> +		return -ENOMEM;
> +
> +	s = strtok(tmp, ",");
> +
> +	while (s != NULL) {
> +		errno = 0;
> +		val = strtoul(s, NULL, 0);
> +		if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))

data.c: In function ‘get_uuid’:
data.c:199:51: warning: comparison between signed and unsigned integer 
expressions [-Wsign-compare]
    if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
                                                    ^

> +			|| (errno != 0 && val == 0)
> +			|| (val > UCHAR_MAX)) {
> +			SNDERR("error: invalid value for uuid\n");
> +			ret = -EINVAL;
> +			goto out;
> +		}
> +
> +		 *(uuid_le + values) = (unsigned char)val;
> +
> +		values++;
> +		if (values >= 16)
> +			break;
> +
> +		s = strtok(NULL, ",");
> +	}
> +
> +	if (values < 16) {
> +		SNDERR("error: less than 16 integers for uuid\n");
> +		ret = -EINVAL;
> +	}
> +
> +out:
> +	free(tmp);
> +	return ret;
> +}
> +
>   static int write_hex(char *buf, char *str, int width)
>   {
>   	long val;
> @@ -536,14 +579,8 @@ static int parse_tuple_set(snd_tplg_t *tplg, snd_config_t *cfg,
>
>   		switch (type) {
>   		case SND_SOC_TPLG_TUPLE_TYPE_UUID:
> -			len = strlen(value);
> -			if (len > 16 || len == 0) {
> -				SNDERR("error: tuple %s: invalid uuid\n", id);
> +			if (get_uuid(value, tuple->uuid) < 0)
>   				goto err;
> -			}
> -
> -			memcpy(tuple->uuid, value, len);
> -			tplg_dbg("\t\t%s = %s\n", tuple->token, tuple->uuid);
>   			break;
>
>   		case SND_SOC_TPLG_TUPLE_TYPE_STRING:
>

Please work with compiler outputs, and pay enough attention to the 
persons to fix them...
http://mailman.alsa-project.org/pipermail/alsa-devel/2016-July/110100.html


Regards

Takashi Sakamoto

Patch
diff mbox

diff --git a/include/topology.h b/include/topology.h
index d666505..89bed6c 100644
--- a/include/topology.h
+++ b/include/topology.h
@@ -273,8 +273,8 @@  extern "C" {
  *		...
  *	}
  *
- *	tuples."uuid" {
- *		VENDOR_TOKEN_ID2 "16 character uuid"
+ *	tuples."uuid" {			# 16 characters separated by commas
+ *		VENDOR_TOKEN_ID2 "0x01,0x02,...,0x0f"
  *		...
  *	}
  *
diff --git a/src/topology/data.c b/src/topology/data.c
index 7ff178f..65054d7 100644
--- a/src/topology/data.c
+++ b/src/topology/data.c
@@ -176,6 +176,49 @@  static int get_hex_num(const char *str)
 	return values;
 }
 
+/* get uuid from a string made by 16 characters separated by commas */
+static int get_uuid(const char *str, unsigned char *uuid_le)
+{
+	unsigned long int  val;
+	char *tmp, *s = NULL;
+	int values = 0, ret = 0;
+
+	tmp = strdup(str);
+	if (tmp == NULL)
+		return -ENOMEM;
+
+	s = strtok(tmp, ",");
+
+	while (s != NULL) {
+		errno = 0;
+		val = strtoul(s, NULL, 0);
+		if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
+			|| (errno != 0 && val == 0)
+			|| (val > UCHAR_MAX)) {
+			SNDERR("error: invalid value for uuid\n");
+			ret = -EINVAL;
+			goto out;
+		}
+
+		 *(uuid_le + values) = (unsigned char)val;
+
+		values++;
+		if (values >= 16)
+			break;
+
+		s = strtok(NULL, ",");
+	}
+
+	if (values < 16) {
+		SNDERR("error: less than 16 integers for uuid\n");
+		ret = -EINVAL;
+	}
+
+out:
+	free(tmp);
+	return ret;
+}
+
 static int write_hex(char *buf, char *str, int width)
 {
 	long val;
@@ -536,14 +579,8 @@  static int parse_tuple_set(snd_tplg_t *tplg, snd_config_t *cfg,
 
 		switch (type) {
 		case SND_SOC_TPLG_TUPLE_TYPE_UUID:
-			len = strlen(value);
-			if (len > 16 || len == 0) {
-				SNDERR("error: tuple %s: invalid uuid\n", id);
+			if (get_uuid(value, tuple->uuid) < 0)
 				goto err;
-			}
-
-			memcpy(tuple->uuid, value, len);
-			tplg_dbg("\t\t%s = %s\n", tuple->token, tuple->uuid);
 			break;
 
 		case SND_SOC_TPLG_TUPLE_TYPE_STRING: