Blob Blame History Raw
#ifndef PTYCON_H
#define PTYCON_H

#include <ntapi/ntapi.h>
#include <stdint.h>

#include "ptycon_api.h"

#ifdef __cplusplus
extern "C" {
#endif

/* pre-alpha */
#ifndef PTYC_APP
#ifndef PTYC_PRE_ALPHA
#error  libptycon: pre-alpha: ABI is not final!
#error  to use the library, please pass -DPTYC_PRE_ALPHA to the compiler.
#endif
#endif

/* daemon */
#define PTYC_PORT_GUID_DAEMON		{0x38a31275,  \
					  0x8c52,     \
					  0x4285,     \
					 {0xaa,0x34,0x70,0xe0,0x6c,0x30,0x6d,0xe5}}

/* status codes */
#define PTYC_OK				0x00
#define PTYC_USAGE			0x01
#define PTYC_ERROR			0x02

/* driver flags */
#define PTYC_DRIVER_VERBOSITY_NONE	0x0000
#define PTYC_DRIVER_VERBOSITY_ERRORS	0x0001
#define PTYC_DRIVER_VERBOSITY_STATUS	0x0002
#define PTYC_DRIVER_VERBOSITY_USAGE	0x0004
#define PTYC_DRIVER_CLONE_VECTOR	0x0008

#define PTYC_DRIVER_VERSION		0x0010
#define PTYC_DRIVER_BELL		0x0020
#define PTYC_DRIVER_DBG_EVENT		0x0100
#define PTYC_DRIVER_DBG_OVEN		0x0200
#define PTYC_DRIVER_DBG_RAW		0x0400
#define PTYC_DRIVER_DBG_WAIT		0x0800
#define PTYC_DRIVER_DAEMON_ALWAYS	0x1000
#define PTYC_DRIVER_DAEMON_NEVER	0x2000

#define PTYC_DRIVER_DBG_MODE		(PTYC_DRIVER_DBG_EVENT \
					| PTYC_DRIVER_DBG_OVEN \
					| PTYC_DRIVER_DBG_RAW)

struct ptyc_source_version {
	int		major;
	int		minor;
	int		revision;
	const char *	commit;
};

struct ptyc_common_ctx {
	uint64_t			drvflags;
	uint64_t			actflags;
	uint64_t			fmtflags;
	nt_pty *			hpts;
	nt_pty *			hptm;
	void *				hroot;
	const char *			sysroot;
	char **				catv;
	char **				eargv;
};

struct ptyc_driver_ctx {
	const char **			units;
	const char *			program;
	const char *			module;
	const struct ptyc_common_ctx *	cctx;
	void *				any;
	int				status;
	int				nerrors;
};

/* package info */
ptyc_api				const struct ptyc_source_version * ptyc_source_version(void);

/* driver api */
ptyc_api int  ptyc_get_driver_ctx	(char ** argv, char ** envp, uint32_t flags, struct ptyc_driver_ctx **);
ptyc_api void ptyc_free_driver_ctx	(struct ptyc_driver_ctx *);

/* pty api */
ptyc_api int  ptyc_alloc_pty		(struct ptyc_driver_ctx *);
ptyc_api void ptyc_free_pty		(struct ptyc_driver_ctx *);
ptyc_api int  ptyc_spawn		(struct ptyc_driver_ctx *);

/* console api */
ptyc_api int  ptyc_alloc_console	(struct ptyc_driver_ctx *);
ptyc_api int  ptyc_wait_for_console	(struct ptyc_driver_ctx *);
ptyc_api void ptyc_free_console		(struct ptyc_driver_ctx *);

/* utility api */
ptyc_api int  ptyc_main			(char **, char **);

#ifdef __cplusplus
}
#endif

#endif