2024-11-22 08:03:55 +00:00
|
|
|
/* $OpenBSD: imsg.h,v 1.18 2024/11/21 13:03:21 claudio Exp $ */
|
2009-08-14 21:04:04 +00:00
|
|
|
|
|
|
|
/*
|
2024-01-17 09:41:53 +00:00
|
|
|
* Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org>
|
2009-08-14 21:04:04 +00:00
|
|
|
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
|
|
|
|
* Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org>
|
|
|
|
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2014-08-09 19:17:26 +00:00
|
|
|
#ifndef _IMSG_H_
|
|
|
|
#define _IMSG_H_
|
|
|
|
|
2024-01-17 09:41:53 +00:00
|
|
|
#include <sys/types.h>
|
2020-10-07 08:39:43 +00:00
|
|
|
|
2010-06-06 00:08:28 +00:00
|
|
|
#define IBUF_READ_SIZE 65535
|
2009-08-14 21:04:04 +00:00
|
|
|
#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
|
|
|
|
#define MAX_IMSGSIZE 16384
|
|
|
|
|
2010-06-06 00:08:28 +00:00
|
|
|
struct ibuf {
|
|
|
|
TAILQ_ENTRY(ibuf) entry;
|
2020-10-07 08:39:43 +00:00
|
|
|
unsigned char *buf;
|
2009-08-14 21:04:04 +00:00
|
|
|
size_t size;
|
|
|
|
size_t max;
|
|
|
|
size_t wpos;
|
|
|
|
size_t rpos;
|
|
|
|
int fd;
|
|
|
|
};
|
|
|
|
|
2024-11-22 08:03:55 +00:00
|
|
|
struct msgbuf;
|
2009-08-14 21:04:04 +00:00
|
|
|
|
|
|
|
struct imsgbuf {
|
2024-11-22 08:03:55 +00:00
|
|
|
struct msgbuf *w;
|
2009-08-14 21:04:04 +00:00
|
|
|
pid_t pid;
|
2024-11-22 08:03:55 +00:00
|
|
|
uint32_t maxsize;
|
|
|
|
int fd;
|
|
|
|
int flags;
|
2009-08-14 21:04:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct imsg_hdr {
|
2017-03-24 10:05:53 +00:00
|
|
|
uint32_t type;
|
2024-11-22 08:03:55 +00:00
|
|
|
uint32_t len;
|
2017-03-24 10:05:53 +00:00
|
|
|
uint32_t peerid;
|
|
|
|
uint32_t pid;
|
2009-08-14 21:04:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct imsg {
|
|
|
|
struct imsg_hdr hdr;
|
|
|
|
void *data;
|
2024-01-17 09:41:53 +00:00
|
|
|
struct ibuf *buf;
|
2009-08-14 21:04:04 +00:00
|
|
|
};
|
|
|
|
|
2024-01-17 09:41:53 +00:00
|
|
|
struct iovec;
|
2009-08-14 21:04:04 +00:00
|
|
|
|
2024-01-17 09:41:53 +00:00
|
|
|
/* imsg-buffer.c */
|
2010-06-06 00:08:28 +00:00
|
|
|
struct ibuf *ibuf_open(size_t);
|
|
|
|
struct ibuf *ibuf_dynamic(size_t, size_t);
|
|
|
|
int ibuf_add(struct ibuf *, const void *, size_t);
|
2024-01-17 09:41:53 +00:00
|
|
|
int ibuf_add_ibuf(struct ibuf *, const struct ibuf *);
|
|
|
|
int ibuf_add_zero(struct ibuf *, size_t);
|
|
|
|
int ibuf_add_n8(struct ibuf *, uint64_t);
|
|
|
|
int ibuf_add_n16(struct ibuf *, uint64_t);
|
|
|
|
int ibuf_add_n32(struct ibuf *, uint64_t);
|
|
|
|
int ibuf_add_n64(struct ibuf *, uint64_t);
|
|
|
|
int ibuf_add_h16(struct ibuf *, uint64_t);
|
|
|
|
int ibuf_add_h32(struct ibuf *, uint64_t);
|
|
|
|
int ibuf_add_h64(struct ibuf *, uint64_t);
|
2010-06-06 00:08:28 +00:00
|
|
|
void *ibuf_reserve(struct ibuf *, size_t);
|
|
|
|
void *ibuf_seek(struct ibuf *, size_t, size_t);
|
2024-01-17 09:41:53 +00:00
|
|
|
int ibuf_set(struct ibuf *, size_t, const void *, size_t);
|
|
|
|
int ibuf_set_n8(struct ibuf *, size_t, uint64_t);
|
|
|
|
int ibuf_set_n16(struct ibuf *, size_t, uint64_t);
|
|
|
|
int ibuf_set_n32(struct ibuf *, size_t, uint64_t);
|
|
|
|
int ibuf_set_n64(struct ibuf *, size_t, uint64_t);
|
|
|
|
int ibuf_set_h16(struct ibuf *, size_t, uint64_t);
|
|
|
|
int ibuf_set_h32(struct ibuf *, size_t, uint64_t);
|
|
|
|
int ibuf_set_h64(struct ibuf *, size_t, uint64_t);
|
|
|
|
void *ibuf_data(const struct ibuf *);
|
|
|
|
size_t ibuf_size(const struct ibuf *);
|
|
|
|
size_t ibuf_left(const struct ibuf *);
|
|
|
|
int ibuf_truncate(struct ibuf *, size_t);
|
|
|
|
void ibuf_rewind(struct ibuf *);
|
2010-06-06 00:08:28 +00:00
|
|
|
void ibuf_close(struct msgbuf *, struct ibuf *);
|
2024-01-17 09:41:53 +00:00
|
|
|
void ibuf_from_buffer(struct ibuf *, void *, size_t);
|
|
|
|
void ibuf_from_ibuf(struct ibuf *, const struct ibuf *);
|
|
|
|
int ibuf_get(struct ibuf *, void *, size_t);
|
|
|
|
int ibuf_get_ibuf(struct ibuf *, size_t, struct ibuf *);
|
|
|
|
int ibuf_get_n8(struct ibuf *, uint8_t *);
|
|
|
|
int ibuf_get_n16(struct ibuf *, uint16_t *);
|
|
|
|
int ibuf_get_n32(struct ibuf *, uint32_t *);
|
|
|
|
int ibuf_get_n64(struct ibuf *, uint64_t *);
|
|
|
|
int ibuf_get_h16(struct ibuf *, uint16_t *);
|
|
|
|
int ibuf_get_h32(struct ibuf *, uint32_t *);
|
|
|
|
int ibuf_get_h64(struct ibuf *, uint64_t *);
|
2024-11-22 08:03:55 +00:00
|
|
|
char *ibuf_get_string(struct ibuf *, size_t);
|
2024-01-17 09:41:53 +00:00
|
|
|
int ibuf_skip(struct ibuf *, size_t);
|
2010-06-06 00:08:28 +00:00
|
|
|
void ibuf_free(struct ibuf *);
|
2024-01-17 09:41:53 +00:00
|
|
|
int ibuf_fd_avail(struct ibuf *);
|
|
|
|
int ibuf_fd_get(struct ibuf *);
|
|
|
|
void ibuf_fd_set(struct ibuf *, int);
|
2024-11-22 08:03:55 +00:00
|
|
|
struct msgbuf *msgbuf_new(void);
|
|
|
|
struct msgbuf *msgbuf_new_reader(size_t, ssize_t (*)(struct ibuf *, void *),
|
|
|
|
void *);
|
|
|
|
void msgbuf_free(struct msgbuf *);
|
2009-08-14 21:04:04 +00:00
|
|
|
void msgbuf_clear(struct msgbuf *);
|
2024-01-17 09:41:53 +00:00
|
|
|
uint32_t msgbuf_queuelen(struct msgbuf *);
|
2024-11-22 08:03:55 +00:00
|
|
|
int ibuf_write(int, struct msgbuf *);
|
|
|
|
int msgbuf_write(int, struct msgbuf *);
|
|
|
|
int ibuf_read(int, struct msgbuf *);
|
|
|
|
int msgbuf_read(int, struct msgbuf *);
|
|
|
|
struct ibuf *msgbuf_get(struct msgbuf *);
|
2009-08-14 21:04:04 +00:00
|
|
|
|
|
|
|
/* imsg.c */
|
2024-11-22 08:03:55 +00:00
|
|
|
int imsgbuf_init(struct imsgbuf *, int);
|
|
|
|
void imsgbuf_allow_fdpass(struct imsgbuf *imsgbuf);
|
|
|
|
void imsgbuf_set_maxsize(struct imsgbuf *, uint32_t);
|
|
|
|
int imsgbuf_read(struct imsgbuf *);
|
|
|
|
int imsgbuf_write(struct imsgbuf *);
|
|
|
|
int imsgbuf_flush(struct imsgbuf *);
|
|
|
|
void imsgbuf_clear(struct imsgbuf *);
|
|
|
|
uint32_t imsgbuf_queuelen(struct imsgbuf *);
|
2009-08-14 21:04:04 +00:00
|
|
|
ssize_t imsg_get(struct imsgbuf *, struct imsg *);
|
2024-01-17 09:41:53 +00:00
|
|
|
int imsg_get_ibuf(struct imsg *, struct ibuf *);
|
|
|
|
int imsg_get_data(struct imsg *, void *, size_t);
|
|
|
|
int imsg_get_fd(struct imsg *);
|
|
|
|
uint32_t imsg_get_id(struct imsg *);
|
|
|
|
size_t imsg_get_len(struct imsg *);
|
|
|
|
pid_t imsg_get_pid(struct imsg *);
|
|
|
|
uint32_t imsg_get_type(struct imsg *);
|
|
|
|
int imsg_forward(struct imsgbuf *, struct imsg *);
|
2017-03-24 10:05:53 +00:00
|
|
|
int imsg_compose(struct imsgbuf *, uint32_t, uint32_t, pid_t, int,
|
2024-01-17 09:41:53 +00:00
|
|
|
const void *, size_t);
|
2017-03-24 10:05:53 +00:00
|
|
|
int imsg_composev(struct imsgbuf *, uint32_t, uint32_t, pid_t, int,
|
|
|
|
const struct iovec *, int);
|
2024-01-17 09:41:53 +00:00
|
|
|
int imsg_compose_ibuf(struct imsgbuf *, uint32_t, uint32_t, pid_t,
|
|
|
|
struct ibuf *);
|
|
|
|
struct ibuf *imsg_create(struct imsgbuf *, uint32_t, uint32_t, pid_t, size_t);
|
|
|
|
int imsg_add(struct ibuf *, const void *, size_t);
|
2010-06-06 00:08:28 +00:00
|
|
|
void imsg_close(struct imsgbuf *, struct ibuf *);
|
2009-08-14 21:04:04 +00:00
|
|
|
void imsg_free(struct imsg *);
|
2014-08-09 19:17:26 +00:00
|
|
|
|
|
|
|
#endif
|