[PATCH 1/2] client-conf-x11|client-conf: refactor cookie loaders

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"client-conf" is sufficient for the commit prefix, instead of
"client-conf-x11|client-conf". (Sorry, I know there's no way for you to
know what the prefix should be, other than trial and error...)

On Tue, 2013-08-13 at 11:36 +0200, Alexander Couzens wrote:
> Signed-off-by: Alexander Couzens <lynxis at fe80.eu>
> ---
>  src/pulse/client-conf-x11.c | 12 +-----------
>  src/pulse/client-conf.c     | 33 ++++++++++++++++++++++++++++++---
>  src/pulse/client-conf.h     |  5 ++++-
>  3 files changed, 35 insertions(+), 15 deletions(-)
> 
> diff --git a/src/pulse/client-conf-x11.c b/src/pulse/client-conf-x11.c
> index 99265c5..f520619 100644
> --- a/src/pulse/client-conf-x11.c
> +++ b/src/pulse/client-conf-x11.c
> @@ -91,20 +91,10 @@ int pa_client_conf_from_x11(pa_client_conf *c, const char *dname) {
>      }
>  
>      if (pa_x11_get_prop(xcb, screen, "PULSE_COOKIE", t, sizeof(t))) {
> -        uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
> -
> -        if (pa_parsehex(t, cookie, sizeof(cookie)) != sizeof(cookie)) {
> +        if(pa_client_conf_load_cookie_from_hex(c, t) < 0) {

Missing space after "if".

>              pa_log(_("Failed to parse cookie data"));
>              goto finish;
>          }
> -
> -        pa_assert(sizeof(cookie) == sizeof(c->cookie));
> -        memcpy(c->cookie, cookie, sizeof(cookie));
> -
> -        c->cookie_valid = true;
> -
> -        pa_xfree(c->cookie_file);
> -        c->cookie_file = NULL;
>      }
>  
>      ret = 0;
> diff --git a/src/pulse/client-conf.c b/src/pulse/client-conf.c
> index 8301981..f881751 100644
> --- a/src/pulse/client-conf.c
> +++ b/src/pulse/client-conf.c
> @@ -66,6 +66,8 @@ static const pa_client_conf default_conf = {
>      .auto_connect_display = false
>  };
>  
> +static int pa_client_conf_parse_cookie_file(pa_client_conf* c);
> +
>  pa_client_conf *pa_client_conf_new(void) {
>      pa_client_conf *c = pa_xmemdup(&default_conf, sizeof(default_conf));
>  
> @@ -130,7 +132,7 @@ int pa_client_conf_load(pa_client_conf *c, const char *filename) {
>      r = f ? pa_config_parse(fn, f, table, NULL, NULL) : 0;
>  
>      if (!r)
> -        r = pa_client_conf_load_cookie(c);
> +        r = pa_client_conf_parse_cookie_file(c);
>  
>  finish:
>      pa_xfree(fn);
> @@ -171,13 +173,13 @@ int pa_client_conf_env(pa_client_conf *c) {
>          pa_xfree(c->cookie_file);
>          c->cookie_file = pa_xstrdup(e);
>  
> -        return pa_client_conf_load_cookie(c);
> +        return pa_client_conf_parse_cookie_file(c);

You could use pa_client_conf_load_cookie_from_file() here.

>      }
>  
>      return 0;
>  }
>  
> -int pa_client_conf_load_cookie(pa_client_conf* c) {
> +static int pa_client_conf_parse_cookie_file(pa_client_conf* c) {

Static functions shouldn't be prefixed, so the function name should be
"parse_cookie_file".

>      int k;
>  
>      pa_assert(c);
> @@ -203,3 +205,28 @@ int pa_client_conf_load_cookie(pa_client_conf* c) {
>      c->cookie_valid = true;
>      return 0;
>  }
> +
> +int pa_client_conf_load_cookie_from_hex(pa_client_conf* c, const char *cookie_in_hex) {
> +    uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
> +
> +    if (pa_parsehex(cookie_in_hex, cookie, sizeof(cookie)) != sizeof(cookie)) {
> +        pa_log(_("Failed to parse cookie data"));
> +        return -PA_ERR_INVALID;
> +    }
> +
> +    pa_assert(sizeof(cookie) == sizeof(c->cookie));
> +    memcpy(c->cookie, cookie, sizeof(cookie));
> +
> +    c->cookie_valid = true;
> +
> +    pa_xfree(c->cookie_file);
> +    c->cookie_file = NULL;
> +
> +    return 0;
> +}
> +
> +int pa_client_conf_load_cookie_from_file(pa_client_conf *c, const char *cookie_file_path) {
> +    pa_xfree(c->cookie_file);
> +    c->cookie_file = pa_xstrdup(cookie_file_path);
> +    return pa_client_conf_parse_cookie_file(c);
> +}
> diff --git a/src/pulse/client-conf.h b/src/pulse/client-conf.h
> index 9c509f7..7b9c0c1 100644
> --- a/src/pulse/client-conf.h
> +++ b/src/pulse/client-conf.h
> @@ -49,6 +49,9 @@ int pa_client_conf_load(pa_client_conf *c, const char *filename);
>  int pa_client_conf_env(pa_client_conf *c);
>  
>  /* Load cookie data from c->cookie_file into c->cookie */
> -int pa_client_conf_load_cookie(pa_client_conf* c);
> +int pa_client_conf_load_cookie_from_file(pa_client_conf* c, const char* cookie_file_path);

The comment above the function needs to be updated too.

-- 
Tanu



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux