Makes the purpose of the structure clearear.
}
/* Called from main context */
-static void pstream_packet_callback(pa_pstream *p, pa_packet *packet, const pa_ancil *ancil, void *userdata) {
+static void pstream_packet_callback(pa_pstream *p, pa_packet *packet, const pa_cmsg_ancil_data *ancil_data, void *userdata) {
struct userdata *u = userdata;
pa_assert(p);
pa_assert(packet);
pa_assert(u);
- if (pa_pdispatch_run(u->pdispatch, packet, ancil, u) < 0) {
+ if (pa_pdispatch_run(u->pdispatch, packet, ancil_data, u) < 0) {
pa_log("Invalid packet");
pa_module_unload_request(u->module, true);
return;
pa_context_fail(c, PA_ERR_CONNECTIONTERMINATED);
}
-static void pstream_packet_callback(pa_pstream *p, pa_packet *packet, const pa_ancil *ancil, void *userdata) {
+static void pstream_packet_callback(pa_pstream *p, pa_packet *packet, const pa_cmsg_ancil_data *ancil_data, void *userdata) {
pa_context *c = userdata;
pa_assert(p);
pa_context_ref(c);
- if (pa_pdispatch_run(c->pdispatch, packet, ancil, c) < 0)
+ if (pa_pdispatch_run(c->pdispatch, packet, ancil_data, c) < 0)
pa_context_fail(c, PA_ERR_PROTOCOL);
pa_context_unref(c);
#include <pulsecore/socket.h>
#include <stdbool.h>
-#define MAX_ANCIL_FDS 2
+#define MAX_ANCIL_DATA_FDS 2
typedef struct pa_creds pa_creds;
-typedef struct pa_ancil pa_ancil;
+typedef struct pa_cmsg_ancil_data pa_cmsg_ancil_data;
#if defined(SCM_CREDENTIALS)
};
/* Struct for handling ancillary data, i e, extra data that can be sent together with a message
- over unix pipes. Supports sending and receiving credentials and file descriptors. */
-struct pa_ancil {
+ * over unix pipes. Supports sending and receiving credentials and file descriptors. */
+struct pa_cmsg_ancil_data {
pa_creds creds;
bool creds_valid;
int nfd;
- int fds[MAX_ANCIL_FDS];
+ int fds[MAX_ANCIL_DATA_FDS];
};
#else
struct iovec iov;
union {
struct cmsghdr hdr;
- uint8_t data[CMSG_SPACE(sizeof(int) * MAX_ANCIL_FDS)];
+ uint8_t data[CMSG_SPACE(sizeof(int) * MAX_ANCIL_DATA_FDS)];
} cmsg;
pa_assert(io);
pa_assert(io->ofd >= 0);
pa_assert(fds);
pa_assert(nfd > 0);
- pa_assert(nfd <= MAX_ANCIL_FDS);
+ pa_assert(nfd <= MAX_ANCIL_DATA_FDS);
pa_zero(iov);
iov.iov_base = (void*) data;
return r;
}
-ssize_t pa_iochannel_read_with_ancil(pa_iochannel*io, void*data, size_t l, pa_ancil *ancil) {
+ssize_t pa_iochannel_read_with_ancil_data(pa_iochannel*io, void*data, size_t l, pa_cmsg_ancil_data *ancil_data) {
ssize_t r;
struct msghdr mh;
struct iovec iov;
union {
struct cmsghdr hdr;
- uint8_t data[CMSG_SPACE(sizeof(struct ucred)) + CMSG_SPACE(sizeof(int) * MAX_ANCIL_FDS)];
+ uint8_t data[CMSG_SPACE(sizeof(struct ucred)) + CMSG_SPACE(sizeof(int) * MAX_ANCIL_DATA_FDS)];
} cmsg;
pa_assert(io);
pa_assert(data);
pa_assert(l);
pa_assert(io->ifd >= 0);
- pa_assert(ancil);
+ pa_assert(ancil_data);
if (io->ifd_type > 0) {
- ancil->creds_valid = false;
- ancil->nfd = 0;
+ ancil_data->creds_valid = false;
+ ancil_data->nfd = 0;
return pa_iochannel_read(io, data, l);
}
if ((r = recvmsg(io->ifd, &mh, 0)) >= 0) {
struct cmsghdr *cmh;
- ancil->creds_valid = false;
- ancil->nfd = 0;
+ ancil_data->creds_valid = false;
+ ancil_data->nfd = 0;
for (cmh = CMSG_FIRSTHDR(&mh); cmh; cmh = CMSG_NXTHDR(&mh, cmh)) {
pa_assert(cmh->cmsg_len == CMSG_LEN(sizeof(struct ucred)));
memcpy(&u, CMSG_DATA(cmh), sizeof(struct ucred));
- ancil->creds.gid = u.gid;
- ancil->creds.uid = u.uid;
- ancil->creds_valid = true;
+ ancil_data->creds.gid = u.gid;
+ ancil_data->creds.uid = u.uid;
+ ancil_data->creds_valid = true;
}
else if (cmh->cmsg_type == SCM_RIGHTS) {
int nfd = (cmh->cmsg_len - CMSG_LEN(0)) / sizeof(int);
- if (nfd > MAX_ANCIL_FDS) {
+ if (nfd > MAX_ANCIL_DATA_FDS) {
int i;
pa_log("Trying to receive too many file descriptors!");
for (i = 0; i < nfd; i++)
pa_close(((int*) CMSG_DATA(cmh))[i]);
continue;
}
- memcpy(ancil->fds, CMSG_DATA(cmh), nfd * sizeof(int));
- ancil->nfd = nfd;
+ memcpy(ancil_data->fds, CMSG_DATA(cmh), nfd * sizeof(int));
+ ancil_data->nfd = nfd;
}
}
if (r == -1 && errno == ENOTSOCK) {
io->ifd_type = 1;
- return pa_iochannel_read_with_ancil(io, data, l, ancil);
+ return pa_iochannel_read_with_ancil_data(io, data, l, ancil_data);
}
return r;
ssize_t pa_iochannel_write_with_fds(pa_iochannel*io, const void*data, size_t l, int nfd, const int *fds);
ssize_t pa_iochannel_write_with_creds(pa_iochannel*io, const void*data, size_t l, const pa_creds *ucred);
-ssize_t pa_iochannel_read_with_ancil(pa_iochannel*io, void*data, size_t l, pa_ancil *ancil);
+ssize_t pa_iochannel_read_with_ancil_data(pa_iochannel*io, void*data, size_t l, pa_cmsg_ancil_data *ancil_data);
#endif
bool pa_iochannel_is_readable(pa_iochannel*io);
PA_LLIST_HEAD(struct reply_info, replies);
pa_pdispatch_drain_cb_t drain_callback;
void *drain_userdata;
- const pa_ancil *ancil;
+ const pa_cmsg_ancil_data *ancil_data;
bool use_rtclock;
};
pa_pdispatch_unref(pd);
}
-int pa_pdispatch_run(pa_pdispatch *pd, pa_packet*packet, const pa_ancil *ancil, void *userdata) {
+int pa_pdispatch_run(pa_pdispatch *pd, pa_packet *packet, const pa_cmsg_ancil_data *ancil_data, void *userdata) {
uint32_t tag, command;
pa_tagstruct *ts = NULL;
int ret = -1;
}
#endif
- pd->ancil = ancil;
+ pd->ancil_data = ancil_data;
if (command == PA_COMMAND_ERROR || command == PA_COMMAND_REPLY) {
struct reply_info *r;
ret = 0;
finish:
- pd->ancil = NULL;
+ pd->ancil_data = NULL;
if (ts)
pa_tagstruct_free(ts);
pa_assert(pd);
pa_assert(PA_REFCNT_VALUE(pd) >= 1);
- if (pd->ancil && pd->ancil->creds_valid)
- return &pd->ancil->creds;
+ if (pd->ancil_data && pd->ancil_data->creds_valid)
+ return &pd->ancil_data->creds;
return NULL;
}
pa_assert(PA_REFCNT_VALUE(pd) >= 1);
pa_assert(nfd);
- if (pd->ancil) {
- *nfd = pd->ancil->nfd;
- return pd->ancil->fds;
+ if (pd->ancil_data) {
+ *nfd = pd->ancil_data->nfd;
+ return pd->ancil_data->fds;
}
*nfd = 0;
void pa_pdispatch_unref(pa_pdispatch *pd);
pa_pdispatch* pa_pdispatch_ref(pa_pdispatch *pd);
-int pa_pdispatch_run(pa_pdispatch *pd, pa_packet*p, const pa_ancil *ancil, void *userdata);
+int pa_pdispatch_run(pa_pdispatch *pd, pa_packet *p, const pa_cmsg_ancil_data *ancil_data, void *userdata);
void pa_pdispatch_register_reply(pa_pdispatch *pd, uint32_t tag, int timeout, pa_pdispatch_cb_t callback, void *userdata, pa_free_cb_t free_cb);
/*** pstream callbacks ***/
-static void pstream_packet_callback(pa_pstream *p, pa_packet *packet, const pa_ancil *ancil, void *userdata) {
+static void pstream_packet_callback(pa_pstream *p, pa_packet *packet, const pa_cmsg_ancil_data *ancil_data, void *userdata) {
pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
pa_assert(p);
pa_assert(packet);
pa_native_connection_assert_ref(c);
- if (pa_pdispatch_run(c->pdispatch, packet, ancil, c) < 0) {
+ if (pa_pdispatch_run(c->pdispatch, packet, ancil_data, c) < 0) {
pa_log("invalid packet.");
native_connection_unlink(c);
}
#include "pstream-util.h"
-static void pa_pstream_send_tagstruct_with_ancil(pa_pstream *p, pa_tagstruct *t, const pa_ancil *ancil) {
+static void pa_pstream_send_tagstruct_with_ancil_data(pa_pstream *p, pa_tagstruct *t, const pa_cmsg_ancil_data *ancil_data) {
size_t length;
uint8_t *data;
pa_packet *packet;
pa_assert_se(data = pa_tagstruct_free_data(t, &length));
pa_assert_se(packet = pa_packet_new_dynamic(data, length));
- pa_pstream_send_packet(p, packet, ancil);
+ pa_pstream_send_packet(p, packet, ancil_data);
pa_packet_unref(packet);
}
void pa_pstream_send_tagstruct_with_creds(pa_pstream *p, pa_tagstruct *t, const pa_creds *creds) {
if (creds) {
- pa_ancil a;
+ pa_cmsg_ancil_data a;
a.nfd = 0;
a.creds_valid = true;
a.creds = *creds;
- pa_pstream_send_tagstruct_with_ancil(p, t, &a);
+ pa_pstream_send_tagstruct_with_ancil_data(p, t, &a);
}
else
- pa_pstream_send_tagstruct_with_ancil(p, t, NULL);
+ pa_pstream_send_tagstruct_with_ancil_data(p, t, NULL);
}
void pa_pstream_send_tagstruct_with_fds(pa_pstream *p, pa_tagstruct *t, int nfd, const int *fds) {
if (nfd > 0) {
- pa_ancil a;
+ pa_cmsg_ancil_data a;
a.nfd = nfd;
a.creds_valid = false;
- pa_assert(nfd <= MAX_ANCIL_FDS);
+ pa_assert(nfd <= MAX_ANCIL_DATA_FDS);
memcpy(a.fds, fds, sizeof(int) * nfd);
- pa_pstream_send_tagstruct_with_ancil(p, t, &a);
+ pa_pstream_send_tagstruct_with_ancil_data(p, t, &a);
}
else
- pa_pstream_send_tagstruct_with_ancil(p, t, NULL);
+ pa_pstream_send_tagstruct_with_ancil_data(p, t, NULL);
}
#else
void pa_pstream_send_tagstruct_with_creds(pa_pstream *p, pa_tagstruct *t, const pa_creds *creds) {
- pa_pstream_send_tagstruct_with_ancil(p, t, NULL);
+ pa_pstream_send_tagstruct_with_ancil_data(p, t, NULL);
}
void pa_pstream_send_tagstruct_with_fds(pa_pstream *p, pa_tagstruct *t, int nfd, const int *fds) {
/* packet info */
pa_packet *packet;
#ifdef HAVE_CREDS
- bool with_ancil;
- pa_ancil ancil;
+ bool with_ancil_data;
+ pa_cmsg_ancil_data ancil_data;
#endif
/* memblock info */
pa_mempool *mempool;
#ifdef HAVE_CREDS
- pa_ancil read_ancil, write_ancil;
- bool send_ancil_now;
+ pa_cmsg_ancil_data read_ancil_data, write_ancil_data;
+ bool send_ancil_data_now;
#endif
};
pa_xfree(p);
}
-void pa_pstream_send_packet(pa_pstream*p, pa_packet *packet, const pa_ancil *ancil) {
+void pa_pstream_send_packet(pa_pstream*p, pa_packet *packet, const pa_cmsg_ancil_data *ancil_data) {
struct item_info *i;
pa_assert(p);
i->packet = pa_packet_ref(packet);
#ifdef HAVE_CREDS
- if ((i->with_ancil = !!ancil)) {
- i->ancil = *ancil;
- if (ancil->creds_valid)
- pa_assert(ancil->nfd == 0);
+ if ((i->with_ancil_data = !!ancil_data)) {
+ i->ancil_data = *ancil_data;
+ if (ancil_data->creds_valid)
+ pa_assert(ancil_data->nfd == 0);
else
- pa_assert(ancil->nfd > 0);
+ pa_assert(ancil_data->nfd > 0);
}
#endif
i->offset = offset;
i->seek_mode = seek_mode;
#ifdef HAVE_CREDS
- i->with_ancil = false;
+ i->with_ancil_data = false;
#endif
pa_queue_push(p->send_queue, i);
item->type = PA_PSTREAM_ITEM_SHMRELEASE;
item->block_id = block_id;
#ifdef HAVE_CREDS
- item->with_ancil = false;
+ item->with_ancil_data = false;
#endif
pa_queue_push(p->send_queue, item);
item->type = PA_PSTREAM_ITEM_SHMREVOKE;
item->block_id = block_id;
#ifdef HAVE_CREDS
- item->with_ancil = false;
+ item->with_ancil_data = false;
#endif
pa_queue_push(p->send_queue, item);
}
#ifdef HAVE_CREDS
- if ((p->send_ancil_now = p->write.current->with_ancil))
- p->write_ancil = p->write.current->ancil;
+ if ((p->send_ancil_data_now = p->write.current->with_ancil_data))
+ p->write_ancil_data = p->write.current->ancil_data;
#endif
}
pa_assert(l > 0);
#ifdef HAVE_CREDS
- if (p->send_ancil_now) {
- if (p->write_ancil.creds_valid) {
- pa_assert(p->write_ancil.nfd == 0);
- if ((r = pa_iochannel_write_with_creds(p->io, d, l, &p->write_ancil.creds)) < 0)
+ if (p->send_ancil_data_now) {
+ if (p->write_ancil_data.creds_valid) {
+ pa_assert(p->write_ancil_data.nfd == 0);
+ if ((r = pa_iochannel_write_with_creds(p->io, d, l, &p->write_ancil_data.creds)) < 0)
goto fail;
}
else
- if ((r = pa_iochannel_write_with_fds(p->io, d, l, p->write_ancil.nfd, p->write_ancil.fds)) < 0)
+ if ((r = pa_iochannel_write_with_fds(p->io, d, l, p->write_ancil_data.nfd, p->write_ancil_data.fds)) < 0)
goto fail;
- p->send_ancil_now = false;
+ p->send_ancil_data_now = false;
} else
#endif
if (p->srb)
else
#ifdef HAVE_CREDS
{
- pa_ancil b;
+ pa_cmsg_ancil_data b;
- if ((r = pa_iochannel_read_with_ancil(p->io, d, l, &b)) <= 0)
+ if ((r = pa_iochannel_read_with_ancil_data(p->io, d, l, &b)) <= 0)
goto fail;
if (b.creds_valid) {
- p->read_ancil.creds_valid = true;
- p->read_ancil.creds = b.creds;
+ p->read_ancil_data.creds_valid = true;
+ p->read_ancil_data.creds = b.creds;
}
if (b.nfd > 0) {
- pa_assert(b.nfd <= MAX_ANCIL_FDS);
- p->read_ancil.nfd = b.nfd;
- memcpy(p->read_ancil.fds, b.fds, sizeof(int) * b.nfd);
+ pa_assert(b.nfd <= MAX_ANCIL_DATA_FDS);
+ p->read_ancil_data.nfd = b.nfd;
+ memcpy(p->read_ancil_data.fds, b.fds, sizeof(int) * b.nfd);
}
}
#else
if (p->receive_packet_callback)
#ifdef HAVE_CREDS
- p->receive_packet_callback(p, re->packet, &p->read_ancil, p->receive_packet_callback_userdata);
+ p->receive_packet_callback(p, re->packet, &p->read_ancil_data, p->receive_packet_callback_userdata);
#else
p->receive_packet_callback(p, re->packet, NULL, p->receive_packet_callback_userdata);
#endif
re->data = NULL;
#ifdef HAVE_CREDS
- p->read_ancil.creds_valid = false;
- p->read_ancil.nfd = 0;
+ p->read_ancil_data.creds_valid = false;
+ p->read_ancil_data.nfd = 0;
#endif
return 0;
typedef struct pa_pstream pa_pstream;
-typedef void (*pa_pstream_packet_cb_t)(pa_pstream *p, pa_packet *packet, const pa_ancil *ancil, void *userdata);
+typedef void (*pa_pstream_packet_cb_t)(pa_pstream *p, pa_packet *packet, const pa_cmsg_ancil_data *ancil_data, void *userdata);
typedef void (*pa_pstream_memblock_cb_t)(pa_pstream *p, uint32_t channel, int64_t offset, pa_seek_mode_t seek, const pa_memchunk *chunk, void *userdata);
typedef void (*pa_pstream_notify_cb_t)(pa_pstream *p, void *userdata);
typedef void (*pa_pstream_block_id_cb_t)(pa_pstream *p, uint32_t block_id, void *userdata);
void pa_pstream_unlink(pa_pstream *p);
-void pa_pstream_send_packet(pa_pstream*p, pa_packet *packet, const pa_ancil *ancil);
+void pa_pstream_send_packet(pa_pstream*p, pa_packet *packet, const pa_cmsg_ancil_data *ancil_data);
void pa_pstream_send_memblock(pa_pstream*p, uint32_t channel, int64_t offset, pa_seek_mode_t seek, const pa_memchunk *chunk);
void pa_pstream_send_release(pa_pstream *p, uint32_t block_id);
void pa_pstream_send_revoke(pa_pstream *p, uint32_t block_id);
static unsigned packets_checksum;
static size_t packets_length;
-static void packet_received(pa_pstream *p, pa_packet *packet, const pa_ancil *ancil, void *userdata) {
+static void packet_received(pa_pstream *p, pa_packet *packet, const pa_cmsg_ancil_data *ancil_data, void *userdata) {
unsigned i;
fail_unless(packets_length == packet->length);
packets_received++;