}
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;
.auto_connect_display = false
};
+static int 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));
r = f ? pa_config_parse(fn, f, table, NULL, NULL) : 0;
if (!r)
- r = pa_client_conf_load_cookie(c);
+ r = parse_cookie_file(c);
finish:
pa_xfree(fn);
}
if ((e = getenv(ENV_COOKIE_FILE))) {
- pa_xfree(c->cookie_file);
- c->cookie_file = pa_xstrdup(e);
-
- return pa_client_conf_load_cookie(c);
+ return pa_client_conf_load_cookie_from_file(c, e);
}
return 0;
}
-int pa_client_conf_load_cookie(pa_client_conf* c) {
+static int parse_cookie_file(pa_client_conf* c) {
int k;
pa_assert(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];
+
+ pa_assert(c);
+ pa_assert(cookie_in_hex);
+
+ if (pa_parsehex(cookie_in_hex, cookie, sizeof(cookie)) != sizeof(cookie)) {
+ pa_log(_("Failed to parse cookie data"));
+ return -PA_ERR_INVALID;
+ }
+
+ pa_xfree(c->cookie_file);
+ c->cookie_file = NULL;
+
+ return pa_client_conf_set_cookie(c, cookie, PA_NATIVE_COOKIE_LENGTH);
+}
+
+int pa_client_conf_load_cookie_from_file(pa_client_conf *c, const char *cookie_file_path) {
+ pa_assert(c);
+ pa_assert(cookie_file_path);
+
+ pa_xfree(c->cookie_file);
+ c->cookie_file = pa_xstrdup(cookie_file_path);
+ return parse_cookie_file(c);
+}
+
+int pa_client_conf_set_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie_size) {
+ pa_assert(c);
+ pa_assert(cookie);
+
+ if (cookie_size != PA_NATIVE_COOKIE_LENGTH)
+ return -PA_ERR_INVALID;
+ memcpy(c->cookie, cookie, cookie_size);
+ c->cookie_valid = true;
+ return 0;
+}
process, overwriting the current settings in *c. */
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);
+/* Load cookie data from cookie_file_path into c->cookie */
+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);
+
+/* Set cookie direct from memory */
+int pa_client_conf_set_cookie(pa_client_conf *c, uint8_t *cookie, size_t cookie_size);
#endif