mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	Remove glib from config loading
This commit is contained in:
		
							parent
							
								
									1a48bccca0
								
							
						
					
					
						commit
						b9e2b1c0e3
					
				
					 5 changed files with 67 additions and 23 deletions
				
			
		| 
						 | 
					@ -48,6 +48,11 @@ typedef struct {
 | 
				
			||||||
  size_t size;
 | 
					  size_t size;
 | 
				
			||||||
} PinosTransportInfo;
 | 
					} PinosTransportInfo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * PinosTransportArea:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Shared structure between client and server
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
struct _PinosTransportArea {
 | 
					struct _PinosTransportArea {
 | 
				
			||||||
  unsigned int       max_inputs;
 | 
					  unsigned int       max_inputs;
 | 
				
			||||||
  unsigned int       n_inputs;
 | 
					  unsigned int       n_inputs;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -81,3 +81,23 @@ pinos_free_strv (char **str)
 | 
				
			||||||
    free (str[i]);
 | 
					    free (str[i]);
 | 
				
			||||||
  free (str);
 | 
					  free (str);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					char *
 | 
				
			||||||
 | 
					pinos_strip (char       *str,
 | 
				
			||||||
 | 
					             const char *whitespace)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  char *e, *l = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  str += strspn (str, whitespace);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  for (e = str; *e; e++)
 | 
				
			||||||
 | 
					     if (!strchr (whitespace, *e))
 | 
				
			||||||
 | 
					         l = e;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (l)
 | 
				
			||||||
 | 
					    *(l+1) = '\0';
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    *str = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return str;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,6 +36,9 @@ char **      pinos_split_strv   (const char *str,
 | 
				
			||||||
                                 int        *n_tokens);
 | 
					                                 int        *n_tokens);
 | 
				
			||||||
void         pinos_free_strv    (char **str);
 | 
					void         pinos_free_strv    (char **str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					char *       pinos_strip        (char       *str,
 | 
				
			||||||
 | 
					                                 const char *whitespace);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}  /* extern "C" */
 | 
					}  /* extern "C" */
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,6 +23,7 @@
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#include <errno.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <pinos/client/pinos.h>
 | 
					#include <pinos/client/pinos.h>
 | 
				
			||||||
#include <pinos/server/command.h>
 | 
					#include <pinos/server/command.h>
 | 
				
			||||||
| 
						 | 
					@ -48,7 +49,7 @@ parse_line (PinosDaemonConfig  *config,
 | 
				
			||||||
    *p = '\0';
 | 
					    *p = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /* remove whitespaces */
 | 
					  /* remove whitespaces */
 | 
				
			||||||
  g_strstrip (line);
 | 
					  pinos_strip (line, "\n\r \t");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (*line == '\0') /* empty line */
 | 
					  if (*line == '\0') /* empty line */
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
| 
						 | 
					@ -112,29 +113,42 @@ pinos_daemon_config_load_file (PinosDaemonConfig *config,
 | 
				
			||||||
                               const char        *filename,
 | 
					                               const char        *filename,
 | 
				
			||||||
                               char             **err)
 | 
					                               char             **err)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  char *data;
 | 
					  unsigned int line;
 | 
				
			||||||
  char **lines;
 | 
					  FILE *f;
 | 
				
			||||||
  bool ret = true;
 | 
					  char buf[4096];
 | 
				
			||||||
  unsigned int i;
 | 
					 | 
				
			||||||
  int n_lines;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_log_debug ("deamon-config %p loading file %s", config, filename);
 | 
					  pinos_log_debug ("deamon-config %p: loading configuration file '%s'", config, filename);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!g_file_get_contents (filename, &data, NULL, NULL))
 | 
					  if ((f = fopen (filename, "r")) == NULL) {
 | 
				
			||||||
    return false;
 | 
					    asprintf (err, "failed to open configuration file '%s': %s", filename, strerror (errno));
 | 
				
			||||||
 | 
					    goto open_error;
 | 
				
			||||||
  lines = pinos_split_strv (data, "\n", 0, &n_lines);
 | 
					 | 
				
			||||||
  for (i = 0; lines[i] != NULL; i++) {
 | 
					 | 
				
			||||||
    if (!parse_line (config, filename, lines[i], i+1, err)) {
 | 
					 | 
				
			||||||
      ret = false;
 | 
					 | 
				
			||||||
      break;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pinos_free_strv (lines);
 | 
					  line = 0;
 | 
				
			||||||
  free (data);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return ret;
 | 
					  while (!feof(f)) {
 | 
				
			||||||
 | 
					    if (!fgets(buf, sizeof (buf), f)) {
 | 
				
			||||||
 | 
					      if (feof(f))
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      asprintf (err, "failed to read configuration file '%s': %s", filename, strerror (errno));
 | 
				
			||||||
 | 
					      goto read_error;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    line++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!parse_line (config, filename, buf, line, err))
 | 
				
			||||||
 | 
					      goto parse_failed;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  fclose (f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					parse_failed:
 | 
				
			||||||
 | 
					read_error:
 | 
				
			||||||
 | 
					  fclose (f);
 | 
				
			||||||
 | 
					open_error:
 | 
				
			||||||
 | 
					  return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,9 +21,9 @@
 | 
				
			||||||
#ifndef __PINOS_DAEMON_CONFIG_H__
 | 
					#ifndef __PINOS_DAEMON_CONFIG_H__
 | 
				
			||||||
#define __PINOS_DAEMON_CONFIG_H__
 | 
					#define __PINOS_DAEMON_CONFIG_H__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <glib-object.h>
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					extern "C" {
 | 
				
			||||||
G_BEGIN_DECLS
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <pinos/server/daemon.h>
 | 
					#include <pinos/server/daemon.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,7 +42,9 @@ bool                pinos_daemon_config_load          (PinosDaemonConfig  *confi
 | 
				
			||||||
                                                       char              **err);
 | 
					                                                       char              **err);
 | 
				
			||||||
bool                pinos_daemon_config_run_commands  (PinosDaemonConfig  *config,
 | 
					bool                pinos_daemon_config_run_commands  (PinosDaemonConfig  *config,
 | 
				
			||||||
                                                       PinosDaemon        *daemon);
 | 
					                                                       PinosDaemon        *daemon);
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
G_END_DECLS
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* __PINOS_DAEMON_CONFIG_H__ */
 | 
					#endif /* __PINOS_DAEMON_CONFIG_H__ */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue