[pulseaudio-discuss] [PATCH 1/2] client-conf-x11|client-conf: refactor cookie loaders
Alexander Couzens
lynxis at fe80.eu
Tue Aug 13 02:36:54 PDT 2013
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) {
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);
}
return 0;
}
-int pa_client_conf_load_cookie(pa_client_conf* c) {
+static int pa_client_conf_parse_cookie_file(pa_client_conf* c) {
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);
+
+/* Load cookie data from hexdecimal string into c->cookie */
+int pa_client_conf_load_cookie_from_hex(pa_client_conf* c, const char *cookie_in_hex);
#endif
--
1.8.3.4
More information about the pulseaudio-discuss
mailing list