Blame include/toksvc/toksvc.h

c0069e
#ifndef TOKSVC_H
c0069e
#define TOKSVC_H
c0069e
c0069e
#include <stdint.h>
c0069e
#include <stddef.h>
c0069e
c0069e
#include "toksvc_api.h"
c0069e
c0069e
#ifdef __cplusplus
c0069e
extern "C" {
c0069e
#endif
c0069e
c0069e
/* pre-alpha */
c0069e
#ifndef TOKS_APP
c0069e
#ifndef TOKS_PRE_ALPHA
c0069e
#error  libtoks: pre-alpha: ABI is not final!
c0069e
#error  to use the library, compile with -DTOKS_PRE_ALPHA.
c0069e
#endif
c0069e
#endif
c0069e
f9f1df
/* daemon */
f9f1df
#define TOKS_PORT_GUID_DAEMON		{0x7d36f145,  \
f9f1df
					  0xd8f0,     \
f9f1df
					  0x440f,     \
f9f1df
					 {0x92,0xbe,0xc3,0x53,0x61,0x7b,0xbc,0x96}}
f9f1df
00069c
#define TOKS_PORT_NAME_PREFIX		{'t','o','k','s','v','c'}
00069c
c0069e
/* status codes */
c0069e
#define TOKS_OK				0x00
c0069e
#define TOKS_USAGE			0x01
c0069e
#define TOKS_ERROR			0x02
c0069e
c0069e
/* driver flags */
c0069e
#define TOKS_DRIVER_VERBOSITY_NONE	0x0000
c0069e
#define TOKS_DRIVER_VERBOSITY_ERRORS	0x0001
c0069e
#define TOKS_DRIVER_VERBOSITY_STATUS	0x0002
c0069e
#define TOKS_DRIVER_VERBOSITY_USAGE	0x0004
c0069e
#define TOKS_DRIVER_CLONE_VECTOR	0x0008
c0069e
c0069e
#define TOKS_DRIVER_VERSION		0x0010
c0069e
#define TOKS_DRIVER_DRY_RUN		0x0020
c0069e
5e5175
#define TOKS_DRIVER_DAEMON_ALWAYS	0x0040
5e5175
#define TOKS_DRIVER_DAEMON_NEVER	0x0080
5e5175
c0069e
#define TOKS_DRIVER_ANNOTATE_ALWAYS	0x1000
c0069e
#define TOKS_DRIVER_ANNOTATE_NEVER	0x2000
c0069e
#define TOKS_DRIVER_ANNOTATE_FULL	0x4000
c0069e
618937
#define TOKS_DRIVER_MODE_SERVER		0X10000
618937
#define TOKS_DRIVER_MODE_CLIENT		0X20000
236509
#define TOKS_DRIVER_ROOT_UUID		0x40000
618937
02451d
#define TOKS_DRIVER_ACTION_ACQUIRE	0X100000
867b30
#define TOKS_DRIVER_ACTION_RELEASE	0X200000
520f51
#define TOKS_DRIVER_ACTION_ABORT	0X400000
02451d
bd4f0c
#define TOKS_DRIVER_ACTION_NTOKENS_GET	0X1000000
0f44d8
#define TOKS_DRIVER_ACTION_NTOKENS_SET	0X2000000
a644fe
#define TOKS_DRIVER_ACTION_LOGLEVEL_GET	0X4000000
a644fe
#define TOKS_DRIVER_ACTION_LOGLEVEL_SET	0X8000000
bd4f0c
0b7161
#define TOKS_DRIVER_ACTION_SVCINFO_GET	0X10000000
0b7161
#define TOKS_DRIVER_ACTION_SVCINFO_LOG	0X20000000
0b7161
c42b09
/* message options */
c42b09
#define TOKS_OPT_SYSTEM_PID		0x0000
c42b09
#define TOKS_OPT_FRAMEWORK_PID		0x0001
c42b09
c0069e
/* error flags */
c0069e
#define TOKS_ERROR_TOP_LEVEL		0x0001
c0069e
#define TOKS_ERROR_NESTED		0x0002
c0069e
#define TOKS_ERROR_CHILD		0x0004
c0069e
#define TOKS_ERROR_CUSTOM		0x0008
c0069e
e6c547
/* ioctl */
e6c547
#define TOKS_IOCTL_DEVICE_TOKEN_SERVICE	(0xdaaf)
e6c547
#define TOKS_IOCTL_OPCODE_BASE		(0xaaf)
e6c547
e6c547
#define TOKS_IOCTL_METHOD_BUFFERED	(0x0)
e6c547
#define TOKS_IOCTL_METHOD_INDIRECT	(0x1)
e6c547
#define TOKS_IOCTL_METHOD_OUTDIRECT	(0x2)
e6c547
#define TOKS_IOCTL_METHOD_NEITHER	(0x3)
e6c547
e6c547
#define TOKS_IOCTL_ACCESS_READ		(0x1)
e6c547
#define TOKS_IOCTL_ACCESS_WRITE		(0x2)
e6c547
e6c547
#define TOKS_IOCTL_IDX(IDX)		(TOKS_IOCTL_OPCODE_BASE + IDX)
e6c547
e6c547
#define TOKS_IOCTL_ANY(IDX,ACC,METHOD)	((TOKS_IOCTL_DEVICE_TOKEN_SERVICE << 16) \
e6c547
						| (TOKS_IOCTL_IDX(IDX) << 2)      \
e6c547
						| (ACC << 14) | (METHOD))
e6c547
e6c547
#define TOKS_IOCTL_GET(IDX)		TOKS_IOCTL_ANY(IDX,TOKS_IOCTL_ACCESS_READ,  \
e6c547
							TOKS_IOCTL_METHOD_OUTDIRECT)
e6c547
e6c547
#define TOKS_IOCTL_SET(IDX)		TOKS_IOCTL_ANY(IDX,TOKS_IOCTL_ACCESS_WRITE, \
e6c547
							TOKS_IOCTL_METHOD_INDIRECT)
e6c547
e6c547
#define TOKS_IOCTL_IDX_GET_TOKEN_COUNT	0
e6c547
#define TOKS_IOCTL_IDX_SET_TOKEN_COUNT	1
e6c547
ca08aa
#define TOKS_IOCTL_IDX_GET_SERVICE_INFO	2
ca08aa
#define TOKS_IOCTL_IDX_LOG_SERVICE_INFO	3
ca08aa
8ae1fc
#define TOKS_IOCTL_IDX_GET_TOKEN_INFO	4
8ae1fc
#define TOKS_IOCTL_IDX_LOG_TOKEN_INFO	5
8ae1fc
a644fe
#define TOKS_IOCTL_IDX_GET_LOG_LEVEL	6
a644fe
#define TOKS_IOCTL_IDX_SET_LOG_LEVEL	7
a644fe
e6c547
#define TOKS_IOCTL_GET_TOKEN_COUNT	TOKS_IOCTL_GET(TOKS_IOCTL_IDX_GET_TOKEN_COUNT)
a8a4af
#define TOKS_IOCTL_SET_TOKEN_COUNT	TOKS_IOCTL_SET(TOKS_IOCTL_IDX_SET_TOKEN_COUNT)
e6c547
ca08aa
#define TOKS_IOCTL_GET_SERVICE_INFO	TOKS_IOCTL_GET(TOKS_IOCTL_IDX_GET_SERVICE_INFO)
a8a4af
#define TOKS_IOCTL_LOG_SERVICE_INFO	TOKS_IOCTL_SET(TOKS_IOCTL_IDX_LOG_SERVICE_INFO)
ca08aa
8ae1fc
#define TOKS_IOCTL_GET_TOKEN_INFO	TOKS_IOCTL_GET(TOKS_IOCTL_IDX_GET_TOKEN_INFO)
8ae1fc
#define TOKS_IOCTL_LOG_TOKEN_INFO	TOKS_IOCTL_SET(TOKS_IOCTL_IDX_LOG_TOKEN_INFO)
8ae1fc
a644fe
#define TOKS_IOCTL_GET_LOG_LEVEL	TOKS_IOCTL_GET(TOKS_IOCTL_IDX_GET_LOG_LEVEL)
a644fe
#define TOKS_IOCTL_SET_LOG_LEVEL	TOKS_IOCTL_SET(TOKS_IOCTL_IDX_SET_LOG_LEVEL)
a644fe
c0069e
enum toks_custom_error {
c0069e
	TOKS_ERR_FLOW_ERROR,
c0069e
	TOKS_ERR_FLEE_ERROR,
c0069e
	TOKS_ERR_NULL_CONTEXT,
c0069e
	TOKS_ERR_BAD_DATA,
c0069e
	TOKS_ERR_CAP,
c0069e
};
c0069e
c0069e
enum toks_warning_level {
c0069e
	TOKS_WARNING_LEVEL_UNKNOWN,
c0069e
	TOKS_WARNING_LEVEL_ALL,
c0069e
	TOKS_WARNING_LEVEL_ERROR,
c0069e
	TOKS_WARNING_LEVEL_NONE,
c0069e
};
c0069e
0021e3
struct toks_uuid {
0021e3
	uint32_t	data1;
0021e3
	uint16_t	data2;
0021e3
	uint16_t	data3;
0021e3
	unsigned char	data4[8];
0021e3
};
442b76
c0069e
struct toks_source_version {
c0069e
	int		major;
c0069e
	int		minor;
c0069e
	int		revision;
c0069e
	const char *	commit;
c0069e
};
c0069e
abad9f
struct toks_token_string{
abad9f
	char            token[128];
abad9f
};
abad9f
ca08aa
struct toks_service_info {
0021e3
	struct toks_uuid	uuid;
ca08aa
	int32_t			syspid;
ca08aa
	int32_t			systid;
ca08aa
	int32_t			ctrlpid;
ca08aa
	int32_t			csyspid;
ca08aa
	int32_t			allocated;
ca08aa
	int32_t			available;
bf3927
	int32_t			tused;
bf3927
	int32_t			tfree;
ca08aa
	int32_t			loglevel;
ca08aa
};
ca08aa
7c2549
struct toks_token_info {
7c2549
	int32_t			tokpid;
7c2549
	int32_t			tsyspid;
7c2549
	uint32_t		keys[6];
7c2549
	uint32_t		meta[6];
7c2549
	uint32_t		pad;
7c2549
};
7c2549
7c2549
struct toks_token_ctx {
7c2549
	int32_t			allocated;
7c2549
	int32_t			available;
7c2549
	int32_t			tused;
7c2549
	int32_t			tfree;
7c2549
	struct toks_token_info	toks[];
7c2549
};
7c2549
c0069e
struct toks_error_info {
c0069e
	const struct toks_driver_ctx *	edctx;
c0069e
	const struct toks_unit_ctx *	euctx;
c0069e
	const char *			eunit;
c0069e
	int				esyscode;
c0069e
	int				elibcode;
c0069e
	const char *			efunction;
c0069e
	int				eline;
c0069e
	unsigned			eflags;
c0069e
	void *				eany;
c0069e
};
c0069e
c0069e
struct toks_common_ctx {
c0069e
	uint64_t			drvflags;
c0069e
	uint64_t			actflags;
c0069e
	uint64_t			fmtflags;
2f270e
	int32_t				loglevel;
0021e3
	const struct toks_uuid *	uuid;
c0069e
	void *				hroot;
c0069e
	const char *			sysroot;
ed52e5
	const char *			logfile;
412c74
	const char *			refstr;
c0069e
	char **				eargv;
c0069e
};
c0069e
c0069e
struct toks_driver_ctx {
c0069e
	const char **                   units;
c0069e
	const char *			program;
c0069e
	const char *			module;
c0069e
	const struct toks_common_ctx *	cctx;
c0069e
	struct toks_error_info **	errv;
c0069e
	void *				any;
c0069e
};
c0069e
c0069e
/* driver api */
c0069e
toks_api int  toks_get_driver_ctx       (char ** argv, char ** envp, uint32_t flags,
c0069e
                                         struct toks_driver_ctx **);
c0069e
c0069e
toks_api void toks_free_driver_ctx      (struct toks_driver_ctx *);
c0069e
b27e56
toks_api void toks_driver_set_timeout   (struct toks_driver_ctx *, int64_t millisecs);
b27e56
toks_api void toks_driver_unset_timeout (struct toks_driver_ctx *);
b27e56
f4d6f1
toks_api void toks_driver_set_refstr    (struct toks_driver_ctx *, const char *);
f4d6f1
toks_api void toks_driver_unset_refstr  (struct toks_driver_ctx *);
f4d6f1
c0069e
/* core api */
520f51
toks_api int  toks_service_abort        (struct toks_driver_ctx *);
073a98
toks_api int  toks_service_ioctl        (struct toks_driver_ctx *, uint32_t ctlcode, uintptr_t * data, void * any);
1a07be
toks_api int  toks_service_start        (struct toks_common_ctx *, int ntokens, int32_t ctrlpid, int32_t csyspid);
c0069e
486fcd
/* client api */
486fcd
toks_api int  toks_client_connect       (struct toks_driver_ctx *);
02451d
toks_api int  toks_client_acquire       (struct toks_driver_ctx *);
867b30
toks_api int  toks_client_release       (struct toks_driver_ctx *);
abad9f
toks_api int  toks_client_token_to_str  (struct toks_driver_ctx *, struct toks_token_string *);
abad9f
toks_api int  toks_client_str_to_token  (struct toks_driver_ctx *, const struct toks_token_string *);
d64f31
toks_api int  toks_client_query_service (struct toks_driver_ctx *, struct toks_service_info *);
c0069e
c0069e
/* utility api */
c0069e
toks_api int  toks_main                 (char **, char **);
c0069e
c0069e
/* error trace api */
c0069e
toks_api int  toks_output_error_record  (const struct toks_driver_ctx *, const struct toks_error_info *);
c0069e
toks_api int  toks_output_error_vector  (const struct toks_driver_ctx *);
c0069e
8da24d
/* helper api */
0021e3
toks_api  int  toks_uuid_from_path      (const char *, struct toks_uuid *);
0021e3
toks_api  int  toks_string_to_uuid      (const char (*)[40], struct toks_uuid *);
0021e3
toks_api  void toks_uuid_to_string      (const struct toks_uuid *, char (*)[40]);
8da24d
c0069e
/* package info */
c0069e
toks_api const struct toks_source_version * toks_source_version(void);
c0069e
c0069e
#ifdef __cplusplus
c0069e
}
c0069e
#endif
c0069e
c0069e
#endif