summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2014-04-04 13:36:01 -0400
committerMike Blumenkrantz <zmike@samsung.com>2014-04-04 13:36:01 -0400
commitc8131ccf553a48aaf2a665d5fdce9ddede88cc9b (patch)
tree4d4f32bc48d730e0629092335bb9f550ee5ab00f
parente4a16f80dd6832df142e807e3d778dc0167b00cb (diff)
rebase from e19
-rw-r--r--main.c2
-rw-r--r--msg.c10
-rw-r--r--pa.c69
-rw-r--r--pa.h10
-rw-r--r--serial.c2
-rw-r--r--sink.c4
-rw-r--r--tag.c6
7 files changed, 69 insertions, 34 deletions
diff --git a/main.c b/main.c
index 622d291..ae2e2d5 100644
--- a/main.c
+++ b/main.c
@@ -68,7 +68,7 @@ main(int argc, char *argv[])
68 conn = pulse_new(); 68 conn = pulse_new();
69 if (!conn) goto error; 69 if (!conn) goto error;
70 if (!pulse_connect(conn)) goto error; 70 if (!pulse_connect(conn)) goto error;
71 71
72 ecore_main_loop_begin(); 72 ecore_main_loop_begin();
73 return 0; 73 return 0;
74error: 74error:
diff --git a/msg.c b/msg.c
index 078c4e0..5bb091c 100644
--- a/msg.c
+++ b/msg.c
@@ -44,7 +44,7 @@ msg_recv_creds(Pulse *conn, Pulse_Tag *tag)
44#else 44#else
45 conn = NULL; 45 conn = NULL;
46 tag = NULL; 46 tag = NULL;
47#endif 47#endif
48} 48}
49 49
50Eina_Bool 50Eina_Bool
@@ -91,14 +91,14 @@ msg_recv(Pulse *conn, Pulse_Tag *tag)
91#else 91#else
92 conn = NULL; 92 conn = NULL;
93 tag = NULL; 93 tag = NULL;
94#endif 94#endif
95 return EINA_FALSE; 95 return EINA_FALSE;
96} 96}
97 97
98void 98void
99msg_sendmsg_creds(Pulse *conn, Pulse_Tag *tag) 99msg_sendmsg_creds(Pulse *conn, Pulse_Tag *tag)
100{ 100{
101#ifdef __linux__ 101#ifdef __linux__
102 int r; 102 int r;
103 struct msghdr mh; 103 struct msghdr mh;
104 struct iovec iov; 104 struct iovec iov;
@@ -144,13 +144,13 @@ msg_sendmsg_creds(Pulse *conn, Pulse_Tag *tag)
144#else 144#else
145 conn = NULL; 145 conn = NULL;
146 tag = NULL; 146 tag = NULL;
147#endif 147#endif
148} 148}
149 149
150void 150void
151msg_send_creds(Pulse *conn, Pulse_Tag *tag) 151msg_send_creds(Pulse *conn, Pulse_Tag *tag)
152{ 152{
153#ifdef __linux__ 153#ifdef __linux__
154 int r; 154 int r;
155 155
156 INF("trying to send 20 byte auth header"); 156 INF("trying to send 20 byte auth header");
diff --git a/pa.c b/pa.c
index d1acf3d..9c01b55 100644
--- a/pa.c
+++ b/pa.c
@@ -57,11 +57,11 @@ proplist_init(Pulse_Tag *tag)
57 snprintf(pid, sizeof(pid), "%"PRIu32, getpid()); 57 snprintf(pid, sizeof(pid), "%"PRIu32, getpid());
58 eina_hash_add(tag->props, "application.process.id", eina_stringshare_add(pid)); 58 eina_hash_add(tag->props, "application.process.id", eina_stringshare_add(pid));
59 tag->dsize += PA_TAG_SIZE_ARBITRARY + sizeof("application.process.id") + strlen(pid) + 2 + PA_TAG_SIZE_U32; 59 tag->dsize += PA_TAG_SIZE_ARBITRARY + sizeof("application.process.id") + strlen(pid) + 2 + PA_TAG_SIZE_U32;
60 60
61 str = getenv("USER"); 61 str = getenv("USER");
62 eina_hash_add(tag->props, "application.process.user", eina_stringshare_add(str)); 62 eina_hash_add(tag->props, "application.process.user", eina_stringshare_add(str));
63 tag->dsize += PA_TAG_SIZE_ARBITRARY + sizeof("application.process.user") + strlen(str) + 2 + PA_TAG_SIZE_U32; 63 tag->dsize += PA_TAG_SIZE_ARBITRARY + sizeof("application.process.user") + strlen(str) + 2 + PA_TAG_SIZE_U32;
64 64
65 file = eina_file_open("/etc/hostname", EINA_FALSE); 65 file = eina_file_open("/etc/hostname", EINA_FALSE);
66 if (file) 66 if (file)
67 { 67 {
@@ -77,7 +77,7 @@ proplist_init(Pulse_Tag *tag)
77 eina_hash_add(tag->props, "application.process.host", eina_stringshare_add("")); 77 eina_hash_add(tag->props, "application.process.host", eina_stringshare_add(""));
78 tag->dsize += PA_TAG_SIZE_ARBITRARY + sizeof("application.process.host") + 2 + PA_TAG_SIZE_U32; 78 tag->dsize += PA_TAG_SIZE_ARBITRARY + sizeof("application.process.host") + 2 + PA_TAG_SIZE_U32;
79 } 79 }
80 80
81 ecore_app_args_get(&argc, &argv); 81 ecore_app_args_get(&argc, &argv);
82 str = strrchr(argv[0], '/'); 82 str = strrchr(argv[0], '/');
83 str = (str) ? str + 1 : argv[0]; 83 str = (str) ? str + 1 : argv[0];
@@ -85,14 +85,14 @@ proplist_init(Pulse_Tag *tag)
85 tag->dsize += PA_TAG_SIZE_ARBITRARY + sizeof("application.process.binary") + strlen(str) + 2 + PA_TAG_SIZE_U32; 85 tag->dsize += PA_TAG_SIZE_ARBITRARY + sizeof("application.process.binary") + strlen(str) + 2 + PA_TAG_SIZE_U32;
86 eina_hash_add(tag->props, "application.name", eina_stringshare_add(str)); 86 eina_hash_add(tag->props, "application.name", eina_stringshare_add(str));
87 tag->dsize += PA_TAG_SIZE_ARBITRARY + sizeof("application.name") + strlen(str) + 2 + PA_TAG_SIZE_U32; 87 tag->dsize += PA_TAG_SIZE_ARBITRARY + sizeof("application.name") + strlen(str) + 2 + PA_TAG_SIZE_U32;
88 88
89 str = getenv("LANG"); 89 str = getenv("LANG");
90 if (str) 90 if (str)
91 { 91 {
92 eina_hash_add(tag->props, "application.language", eina_stringshare_add(str)); 92 eina_hash_add(tag->props, "application.language", eina_stringshare_add(str));
93 tag->dsize += PA_TAG_SIZE_ARBITRARY + sizeof("application.language") + strlen(str) + 2 + PA_TAG_SIZE_U32; 93 tag->dsize += PA_TAG_SIZE_ARBITRARY + sizeof("application.language") + strlen(str) + 2 + PA_TAG_SIZE_U32;
94 } 94 }
95 95
96 str = getenv("DISPLAY"); 96 str = getenv("DISPLAY");
97 if (str) 97 if (str)
98 { 98 {
@@ -136,7 +136,7 @@ cookie_file(uint8_t *cookie)
136 size_t size; 136 size_t size;
137 void *cookie_data; 137 void *cookie_data;
138 138
139 snprintf(buf, sizeof(buf), "%s/.pulse-cookie", getenv("HOME")); 139 snprintf(buf, sizeof(buf), "%s/.pulse-cookie", getenv("HOME"));
140 file = eina_file_open(buf, EINA_FALSE); 140 file = eina_file_open(buf, EINA_FALSE);
141 size = eina_file_size_get(file); 141 size = eina_file_size_get(file);
142 cookie_data = eina_file_map_all(file, EINA_FILE_WILLNEED); 142 cookie_data = eina_file_map_all(file, EINA_FILE_WILLNEED);
@@ -151,26 +151,26 @@ login_setup(Pulse *conn)
151 Pulse_Tag *tag; 151 Pulse_Tag *tag;
152 uint32_t x; 152 uint32_t x;
153 uint8_t cookie[PA_NATIVE_COOKIE_LENGTH]; 153 uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
154 154
155 tag = calloc(1, sizeof(Pulse_Tag)); 155 tag = calloc(1, sizeof(Pulse_Tag));
156 tag->dsize = 4 * PA_TAG_SIZE_U32 + sizeof(cookie); 156 tag->dsize = 4 * PA_TAG_SIZE_U32 + sizeof(cookie);
157 tag->data = malloc(tag->dsize); 157 tag->data = calloc(1, tag->dsize);
158 tag_simple_init(conn, tag, PA_COMMAND_AUTH, PA_TAG_U32); 158 tag_simple_init(conn, tag, PA_COMMAND_AUTH, PA_TAG_U32);
159 DBG("%zu bytes", tag->dsize); 159 DBG("%zu bytes", tag->dsize);
160 160
161 if (!getuid()) 161 if (!getuid())
162 x = PA_PROTOCOL_VERSION; 162 x = PA_PROTOCOL_VERSION;
163 else 163 else
164 x = PA_PROTOCOL_VERSION | 0x80000000U; 164 x = PA_PROTOCOL_VERSION | 0x80000000U;
165 tag_uint32(tag, x); 165 tag_uint32(tag, x);
166 DBG("%zu bytes", tag->dsize); 166 DBG("%zu bytes", tag->dsize);
167 167
168 cookie_file(cookie); 168 cookie_file(cookie);
169 tag_arbitrary(tag, cookie, sizeof(cookie)); 169 tag_arbitrary(tag, cookie, sizeof(cookie));
170 DBG("%zu bytes", tag->dsize); 170 DBG("%zu bytes", tag->dsize);
171 171
172 tag_finish(tag); 172 tag_finish(tag);
173 173
174 return tag; 174 return tag;
175} 175}
176 176
@@ -262,7 +262,7 @@ fdh_func(Pulse *conn, Ecore_Fd_Handler *fdh)
262 pa_write = !!ecore_main_fd_handler_active_get(fdh, ECORE_FD_WRITE) * ECORE_FD_WRITE; 262 pa_write = !!ecore_main_fd_handler_active_get(fdh, ECORE_FD_WRITE) * ECORE_FD_WRITE;
263 rprev = eina_list_data_get(conn->iq); 263 rprev = eina_list_data_get(conn->iq);
264 wprev = eina_list_data_get(conn->oq); 264 wprev = eina_list_data_get(conn->oq);
265 265
266 switch (conn->state) 266 switch (conn->state)
267 { 267 {
268 case PA_STATE_INIT: 268 case PA_STATE_INIT:
@@ -274,7 +274,7 @@ fdh_func(Pulse *conn, Ecore_Fd_Handler *fdh)
274 274
275 if (!wprev->auth) 275 if (!wprev->auth)
276 msg_sendmsg_creds(conn, wprev); 276 msg_sendmsg_creds(conn, wprev);
277 277
278 278
279 if (wprev->auth && msg_send(conn, wprev)) 279 if (wprev->auth && msg_send(conn, wprev))
280 { 280 {
@@ -326,7 +326,7 @@ fdh_func(Pulse *conn, Ecore_Fd_Handler *fdh)
326 Pulse_Tag *tag; 326 Pulse_Tag *tag;
327 PA_Commands command; 327 PA_Commands command;
328 if (!pulse_recv(conn, fdh, &tag)) break; 328 if (!pulse_recv(conn, fdh, &tag)) break;
329 329
330 command = (uintptr_t)eina_hash_find(conn->tag_handlers, &tag->tag_count); 330 command = (uintptr_t)eina_hash_find(conn->tag_handlers, &tag->tag_count);
331 eina_hash_del_by_key(conn->tag_handlers, &tag->tag_count); 331 eina_hash_del_by_key(conn->tag_handlers, &tag->tag_count);
332 deserialize_tag(conn, command, tag); 332 deserialize_tag(conn, command, tag);
@@ -353,12 +353,14 @@ con(Pulse *conn, int type __UNUSED__, Ecore_Con_Event_Server_Add *ev)
353 INF("connected to %s", ecore_con_server_name_get(ev->server)); 353 INF("connected to %s", ecore_con_server_name_get(ev->server));
354 354
355 fd = ecore_con_server_fd_get(ev->server); 355 fd = ecore_con_server_fd_get(ev->server);
356 if (fd >= -1)
357 conn->fd = dup(fd);
356 if (fd == -1) 358 if (fd == -1)
357 { 359 {
358 pulse_disconnect(conn); 360 pulse_disconnect(conn);
359 return ECORE_CALLBACK_RENEW; 361 return ECORE_CALLBACK_RENEW;
360 } 362 }
361 conn->fd = dup(fd); 363
362#ifdef SO_PASSCRED 364#ifdef SO_PASSCRED
363 setsockopt(conn->fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)); 365 setsockopt(conn->fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
364#endif 366#endif
@@ -623,7 +625,7 @@ int
623pulse_init(void) 625pulse_init(void)
624{ 626{
625 if (pulse_init_count++) return pulse_init_count; 627 if (pulse_init_count++) return pulse_init_count;
626 628
627 eina_init(); 629 eina_init();
628 ecore_init(); 630 ecore_init();
629 ecore_con_init(); 631 ecore_con_init();
@@ -713,13 +715,38 @@ pulse_new(void)
713 if (!prev) 715 if (!prev)
714 { 716 {
715 struct stat st; 717 struct stat st;
716 buf = eina_stringshare_add(STATEDIR "/run/pulse/native"); 718 char *s;
717 if (stat(buf, &st)) 719
720 s = getenv("XDG_RUNTIME_DIR");
721 if (s) snprintf(h, sizeof(h), "%s/pulse/native", s);
722 buf = eina_stringshare_add(h);
723 if ((!s) || (stat(h, &st)))
718 { 724 {
719 INF("could not locate local socket '%s'!", buf); 725 snprintf(h, sizeof(h), "/run/user/%i/pulse/native",
720 free(conn); 726 (int)getuid());
721 return NULL; 727 if (stat(h, &st))
728 {
729 snprintf(h, sizeof(h), "%s/run/user/%i/pulse/native",
730 STATEDIR, (int)getuid());
731 if (stat(h, &st))
732 {
733 buf = eina_stringshare_add(STATEDIR "/run/pulse/native");
734 if (stat(buf, &st))
735 {
736 eina_stringshare_del(buf);
737 INF("could not locate local socket '%s'!", buf);
738 free(conn);
739 return NULL;
740 }
741 }
742 else
743 buf = eina_stringshare_add(h);
744 }
745 else
746 buf = eina_stringshare_add(h);
722 } 747 }
748 else
749 buf = eina_stringshare_add(h);
723 conn->socket = buf; 750 conn->socket = buf;
724 } 751 }
725 else conn->socket = prev; 752 else conn->socket = prev;
diff --git a/pa.h b/pa.h
index c5870f0..1a07901 100644
--- a/pa.h
+++ b/pa.h
@@ -5,6 +5,14 @@
5# include "config.h" 5# include "config.h"
6#endif 6#endif
7 7
8#ifdef HAVE_ARPA_INET_H
9# include <arpa/inet.h>
10#endif
11
12#ifdef HAVE_NETINET_IN_H
13# include <netinet/in.h>
14#endif
15
8#include <Ecore.h> 16#include <Ecore.h>
9#include <Ecore_Con.h> 17#include <Ecore_Con.h>
10#include <inttypes.h> 18#include <inttypes.h>
@@ -245,7 +253,7 @@ typedef enum
245 PA_TAG_SIZE_CVOLUME = 2, 253 PA_TAG_SIZE_CVOLUME = 2,
246 PA_TAG_SIZE_PROPLIST = 1 + PA_TAG_SIZE_STRING_NULL, 254 PA_TAG_SIZE_PROPLIST = 1 + PA_TAG_SIZE_STRING_NULL,
247 PA_TAG_SIZE_VOLUME = 2 255 PA_TAG_SIZE_VOLUME = 2
248} PA_Tag_Size; 256} PA_Tag_Size;
249 257
250/** Volume specification: 258/** Volume specification:
251 * PA_VOLUME_MUTED: silence; 259 * PA_VOLUME_MUTED: silence;
diff --git a/serial.c b/serial.c
index ed3fc63..99678c0 100644
--- a/serial.c
+++ b/serial.c
@@ -16,7 +16,7 @@ deserialize_server_info(Pulse *conn, Pulse_Tag *tag)
16 EINA_SAFETY_ON_FALSE_GOTO(untag_sample(tag, &spec), error); 16 EINA_SAFETY_ON_FALSE_GOTO(untag_sample(tag, &spec), error);
17 EINA_SAFETY_ON_FALSE_GOTO(untag_string(tag, &ev->default_sink), error); 17 EINA_SAFETY_ON_FALSE_GOTO(untag_string(tag, &ev->default_sink), error);
18 EINA_SAFETY_ON_FALSE_GOTO(untag_string(tag, &ev->default_source), error); 18 EINA_SAFETY_ON_FALSE_GOTO(untag_string(tag, &ev->default_source), error);
19 19
20 return ev; 20 return ev;
21error: 21error:
22 pulse_server_info_free(ev); 22 pulse_server_info_free(ev);
diff --git a/sink.c b/sink.c
index 18cf2cd..c5134ca 100644
--- a/sink.c
+++ b/sink.c
@@ -264,7 +264,7 @@ pulse_sink_channel_names_get(Pulse_Sink *sink)
264{ 264{
265 Eina_List *ret = NULL; 265 Eina_List *ret = NULL;
266 unsigned int x; 266 unsigned int x;
267 267
268 EINA_SAFETY_ON_NULL_RETURN_VAL(sink, NULL); 268 EINA_SAFETY_ON_NULL_RETURN_VAL(sink, NULL);
269 for (x = 0; x < sink->volume.channels; x++) 269 for (x = 0; x < sink->volume.channels; x++)
270 ret = eina_list_append(ret, pulse_sink_channel_id_get_name(sink, x)); 270 ret = eina_list_append(ret, pulse_sink_channel_id_get_name(sink, x));
@@ -275,7 +275,7 @@ unsigned int
275pulse_sink_channel_name_get_id(Pulse_Sink *sink, const char *name) 275pulse_sink_channel_name_get_id(Pulse_Sink *sink, const char *name)
276{ 276{
277 unsigned int x; 277 unsigned int x;
278 278
279 EINA_SAFETY_ON_NULL_RETURN_VAL(sink, UINT_MAX); 279 EINA_SAFETY_ON_NULL_RETURN_VAL(sink, UINT_MAX);
280 EINA_SAFETY_ON_NULL_RETURN_VAL(name, UINT_MAX); 280 EINA_SAFETY_ON_NULL_RETURN_VAL(name, UINT_MAX);
281 for (x = 0; x < sink->channel_map.channels; x++) 281 for (x = 0; x < sink->channel_map.channels; x++)
diff --git a/tag.c b/tag.c
index 60ab764..56d7207 100644
--- a/tag.c
+++ b/tag.c
@@ -174,7 +174,7 @@ untag_arbitrary(Pulse_Tag *tag, Eina_Binbuf **val)
174 ret = tag->data + tag->size; 174 ret = tag->data + tag->size;
175 if (*ret != PA_TAG_ARBITRARY) return 0; 175 if (*ret != PA_TAG_ARBITRARY) return 0;
176 ret += PA_TAG_SIZE_ARBITRARY; 176 ret += PA_TAG_SIZE_ARBITRARY;
177 177
178 *val = eina_binbuf_new(); 178 *val = eina_binbuf_new();
179 eina_binbuf_append_length(*val, ret, len); 179 eina_binbuf_append_length(*val, ret, len);
180 ret += len; 180 ret += len;
@@ -215,7 +215,7 @@ tag_proplist(Pulse_Tag *tag)
215 215
216 ret = tag->data + tag->size; 216 ret = tag->data + tag->size;
217 *ret = PA_TAG_PROPLIST, tag->size++; 217 *ret = PA_TAG_PROPLIST, tag->size++;
218 218
219 eina_hash_foreach(tag->props, (Eina_Hash_Foreach)tag_proplist_foreach, tag); 219 eina_hash_foreach(tag->props, (Eina_Hash_Foreach)tag_proplist_foreach, tag);
220 return tag_string(tag, NULL); 220 return tag_string(tag, NULL);
221} 221}
@@ -303,7 +303,7 @@ untag_cvol(Pulse_Tag *tag, pa_cvolume *cvol)
303 memcpy(&pa_vol, ret, sizeof(pa_vol)); 303 memcpy(&pa_vol, ret, sizeof(pa_vol));
304 cvol->values[x] = ntohl(pa_vol); 304 cvol->values[x] = ntohl(pa_vol);
305 } 305 }
306 306
307 tag->size = ret - tag->data; 307 tag->size = ret - tag->data;
308 return ret; 308 return ret;
309} 309}