/* extract_val(): Extract value from a key=value pair list (comma separated). Only value for the given key is returend. Function allocates memory for the value, remember to free! */
static char* extract_val(const char *str, const char *key)
/* extract_val(): Extract value from a key=value pair list (comma separated). Only value for the given key is returend. Function allocates memory for the value, remember to free! */
static char* extract_val(const char *str, const char *key)
{
	char *v, *k;
	char *s, *strcopy;
	char *new = NULL;
	strcopy = strdup(str);
	if (strcopy == NULL)
		return NULL;
	s = strcopy;
	while (s) {
		v = strsep(&s, ",");
		if (!v)
			break;
		k = strsep(&v, "=");
		if (!k)
			break;
		if  (strcmp(k, key) == 0) {
			new = strdup(v);
			break;
		}
	}
	free(strcopy);
	return new;
}