conf: add config_dup_block_path()
This commit is contained in:
		
							
								
								
									
										20
									
								
								src/conf.c
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								src/conf.c
									
									
									
									
									
								
							| @@ -606,6 +606,26 @@ config_get_block_string(const struct config_param *param, const char *name, | |||||||
| 	return bp->value; | 	return bp->value; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | char * | ||||||
|  | config_dup_block_path(const struct config_param *param, const char *name, | ||||||
|  | 		      GError **error_r) | ||||||
|  | { | ||||||
|  | 	assert(error_r != NULL); | ||||||
|  | 	assert(*error_r == NULL); | ||||||
|  |  | ||||||
|  | 	const struct block_param *bp = config_get_block_param(param, name); | ||||||
|  | 	if (bp == NULL) | ||||||
|  | 		return NULL; | ||||||
|  |  | ||||||
|  | 	char *path = parsePath(bp->value, error_r); | ||||||
|  | 	if (G_UNLIKELY(path == NULL)) | ||||||
|  | 		g_prefix_error(error_r, | ||||||
|  | 			       "Invalid path in \"%s\" at line %i: ", | ||||||
|  | 			       name, bp->line); | ||||||
|  |  | ||||||
|  | 	return path; | ||||||
|  | } | ||||||
|  |  | ||||||
| unsigned | unsigned | ||||||
| config_get_block_unsigned(const struct config_param *param, const char *name, | config_get_block_unsigned(const struct config_param *param, const char *name, | ||||||
| 			  unsigned default_value) | 			  unsigned default_value) | ||||||
|   | |||||||
| @@ -194,6 +194,15 @@ config_dup_block_string(const struct config_param *param, const char *name, | |||||||
| 	return g_strdup(config_get_block_string(param, name, default_value)); | 	return g_strdup(config_get_block_string(param, name, default_value)); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Same as config_dup_path(), but looks up the setting in the | ||||||
|  |  * specified block. | ||||||
|  |  */ | ||||||
|  | G_GNUC_MALLOC | ||||||
|  | char * | ||||||
|  | config_dup_block_path(const struct config_param *param, const char *name, | ||||||
|  | 		      GError **error_r); | ||||||
|  |  | ||||||
| G_GNUC_PURE | G_GNUC_PURE | ||||||
| unsigned | unsigned | ||||||
| config_get_block_unsigned(const struct config_param *param, const char *name, | config_get_block_unsigned(const struct config_param *param, const char *name, | ||||||
|   | |||||||
| @@ -178,30 +178,25 @@ fifo_open(struct fifo_data *fd, GError **error) | |||||||
| static void * | static void * | ||||||
| fifo_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, | fifo_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, | ||||||
| 		 const struct config_param *param, | 		 const struct config_param *param, | ||||||
| 		 GError **error) | 		 GError **error_r) | ||||||
| { | { | ||||||
| 	struct fifo_data *fd; | 	struct fifo_data *fd; | ||||||
| 	char *value, *path; |  | ||||||
|  |  | ||||||
| 	value = config_dup_block_string(param, "path", NULL); | 	GError *error = NULL; | ||||||
| 	if (value == NULL) { | 	char *path = config_dup_block_path(param, "path", &error); | ||||||
| 		g_set_error(error, fifo_output_quark(), errno, |  | ||||||
| 			    "No \"path\" parameter specified"); |  | ||||||
| 		return NULL; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	path = parsePath(value, error); |  | ||||||
| 	g_free(value); |  | ||||||
| 	if (!path) { | 	if (!path) { | ||||||
| 		g_prefix_error(error, "Invalid path in line %i: ", | 		if (error != NULL) | ||||||
| 			       param->line); | 			g_propagate_error(error_r, error); | ||||||
|  | 		else | ||||||
|  | 			g_set_error(error_r, fifo_output_quark(), 0, | ||||||
|  | 				    "No \"path\" parameter specified"); | ||||||
| 		return NULL; | 		return NULL; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	fd = fifo_data_new(); | 	fd = fifo_data_new(); | ||||||
| 	fd->path = path; | 	fd->path = path; | ||||||
|  |  | ||||||
| 	if (!fifo_open(fd, error)) { | 	if (!fifo_open(fd, error_r)) { | ||||||
| 		fifo_data_free(fd); | 		fifo_data_free(fd); | ||||||
| 		return NULL; | 		return NULL; | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Max Kellermann
					Max Kellermann