]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/pstream.c
* add new function pa_check_in_group()
[pulseaudio] / src / pulsecore / pstream.c
index 7992ccb660dcd9b6b0605dd352777e0a735e880e..de5fa43e6c871b77fbfa14d47fa5132b6e51d920 100644 (file)
@@ -27,6 +27,8 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <unistd.h>
+#include <sys/socket.h>
+#include <sys/un.h>
 
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
@@ -39,6 +41,7 @@
 #include <pulsecore/queue.h>
 #include <pulsecore/log.h>
 #include <pulsecore/core-scache.h>
+#include <pulsecore/creds.h>
 
 #include "pstream.h"
 
@@ -67,8 +70,9 @@ struct item_info {
 
     /* packet info */
     pa_packet *packet;
-#ifdef SCM_CREDENTIALS
+#ifdef HAVE_CREDS
     int with_creds;
+    pa_creds creds;
 #endif
 };
 
@@ -111,10 +115,9 @@ struct pa_pstream {
 
     pa_memblock_stat *memblock_stat;
 
-#ifdef SCM_CREDENTIALS
-    int send_creds_now;
-    struct ucred ucred;
-    int creds_valid;
+#ifdef HAVE_CREDS
+    pa_creds read_creds, write_creds;
+    int read_creds_valid, send_creds_now;
 #endif
 };
 
@@ -214,9 +217,9 @@ pa_pstream *pa_pstream_new(pa_mainloop_api *m, pa_iochannel *io, pa_memblock_sta
     pa_iochannel_socket_set_rcvbuf(io, 1024*8); 
     pa_iochannel_socket_set_sndbuf(io, 1024*8);
 
-#ifdef SCM_CREDENTIALS
+#ifdef HAVE_CREDS
     p->send_creds_now = 0;
-    p->creds_valid = 0;
+    p->read_creds_valid = 0;
 #endif
     return p;
 }
@@ -256,7 +259,7 @@ static void pstream_free(pa_pstream *p) {
     pa_xfree(p);
 }
 
-void pa_pstream_send_packet(pa_pstream*p, pa_packet *packet, int with_creds) {
+void pa_pstream_send_packet(pa_pstream*p, pa_packet *packet, const pa_creds *creds) {
     struct item_info *i;
     assert(p && packet && p->ref >= 1);
 
@@ -268,8 +271,9 @@ void pa_pstream_send_packet(pa_pstream*p, pa_packet *packet, int with_creds) {
     i = pa_xnew(struct item_info, 1);
     i->type = PA_PSTREAM_ITEM_PACKET;
     i->packet = pa_packet_ref(packet);
-#ifdef SCM_CREDENTIALS
-    i->with_creds = with_creds;
+#ifdef HAVE_CREDS
+    if ((i->with_creds = !!creds))
+        i->creds = *creds;
 #endif
 
     pa_queue_push(p->send_queue, i);
@@ -291,7 +295,7 @@ void pa_pstream_send_memblock(pa_pstream*p, uint32_t channel, int64_t offset, pa
     i->channel = channel;
     i->offset = offset;
     i->seek_mode = seek_mode;
-#ifdef SCM_CREDENTIALS
+#ifdef HAVE_CREDS
     i->with_creds = 0;
 #endif
 
@@ -331,8 +335,10 @@ static void prepare_next_write_item(pa_pstream *p) {
         p->write.descriptor[PA_PSTREAM_DESCRIPTOR_SEEK] = htonl(p->write.current->seek_mode);
     }
 
-#ifdef SCM_CREDENTIALS
-    p->send_creds_now = p->write.current->with_creds;
+#ifdef HAVE_CREDS
+    if ((p->send_creds_now = p->write.current->with_creds))
+        p->write_creds = p->write.current->creds;
+    
 #endif
 
 }
@@ -359,10 +365,10 @@ static int do_write(pa_pstream *p) {
         l = ntohl(p->write.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]) - (p->write.index - PA_PSTREAM_DESCRIPTOR_SIZE);
     }
 
-#ifdef SCM_CREDENTIALS
+#ifdef HAVE_CREDS
     if (p->send_creds_now) {
 
-        if ((r = pa_iochannel_write_with_creds(p->io, d, l)) < 0)
+        if ((r = pa_iochannel_write_with_creds(p->io, d, l, &p->write_creds)) < 0)
             return -1;
 
         p->send_creds_now = 0;
@@ -401,14 +407,14 @@ static int do_read(pa_pstream *p) {
         l = ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]) - (p->read.index - PA_PSTREAM_DESCRIPTOR_SIZE);
     }
 
-#ifdef SCM_CREDENTIALS
+#ifdef HAVE_CREDS
     {
-        int b;
+        int b = 0;
         
-        if ((r = pa_iochannel_read_with_creds(p->io, d, l, &p->ucred, &b)) <= 0)
+        if ((r = pa_iochannel_read_with_creds(p->io, d, l, &p->read_creds, &b)) <= 0)
             return -1;
 
-        p->creds_valid = p->creds_valid || b;
+        p->read_creds_valid = p->read_creds_valid || b;
     }
 #else
     if ((r = pa_iochannel_read(p->io, d, l)) <= 0)
@@ -490,8 +496,8 @@ static int do_read(pa_pstream *p) {
                 assert(p->read.packet);
                 
                 if (p->recieve_packet_callback)
-#ifdef SCM_CREDENTIALS                    
-                    p->recieve_packet_callback(p, p->read.packet, p->creds_valid ? &p->ucred : NULL, p->recieve_packet_callback_userdata);
+#ifdef HAVE_CREDS
+                    p->recieve_packet_callback(p, p->read.packet, p->read_creds_valid ? &p->read_creds : NULL, p->recieve_packet_callback_userdata);
 #else
                     p->recieve_packet_callback(p, p->read.packet, NULL, p->recieve_packet_callback_userdata);
 #endif
@@ -501,8 +507,8 @@ static int do_read(pa_pstream *p) {
             }
 
             p->read.index = 0;
-#ifdef SCM_CREDENTIALS
-            p->creds_valid = 0;
+#ifdef HAVE_CREDS
+            p->read_creds_valid = 0;
 #endif
         }
     }