-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibvzsock.h
139 lines (126 loc) · 3.9 KB
/
libvzsock.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* $Id: util.h,v 1.21 2008/06/26 14:40:12 krasnov Exp $
*
* Copyright (C) 2008, Parallels, Inc. All rights reserved.
*
*/
#ifndef __LIBVZM_H__
#define __LIBVZM_H__
#include <stdio.h>
#include <stdarg.h>
#include <limits.h>
/* supported connection types */
#define VZSOCK_UNDEF 0
#define VZSOCK_SOCK 1 /* plain socket */
#define VZSOCK_SSH 2
#define VZSOCK_SSL 3
#define VZSOCK_FD 4
/* default timeout */
#define VZSOCK_DEF_TMO 3600
struct vzsock_ctx {
int type;
/* handlers for this vzsock type */
void *handlers;
/* list of connections */
void *clist;
/* specific data */
void *data;
int debug;
int code; /* reply code from server side, used on client only */
int errcode;
char errmsg[BUFSIZ];
int (*logger)(int level, const char *fmt, va_list pvar);
int (*readpwd)(const char *prompt, char *pass, size_t size);
char tmpdir[PATH_MAX+1];
char password[BUFSIZ];
long tmo;
};
/* data types (vzsock_set() function) */
#define VZSOCK_DATA_HOSTNAME 1 /* dst hostname */
#define VZSOCK_DATA_ADDR 2 /* address */
#define VZSOCK_DATA_FDPAIR 3 /* pair of file descriptors */
#define VZSOCK_DATA_SOCK_DOMAIN 4 /* socket domain */
#define VZSOCK_DATA_SOCK_TYPE 5 /* socket type */
#define VZSOCK_DATA_SOCK_PROTO 6 /* socket protocol */
#define VZSOCK_DATA_TMO 7 /* connection timeout */
#define VZSOCK_DATA_DEBUG 8 /* debug level */
#define VZSOCK_DATA_CRTFILE 9 /* certificate file name */
#define VZSOCK_DATA_KEYFILE 10 /* private key file name */
#define VZSOCK_DATA_CIPHERS 11 /* ciphers list */
#define VZSOCK_DATA_CAFILE 12 /* CA certificate file */
#define VZSOCK_DATA_CAPATH 13 /* CA certificate path */
#define VZSOCK_DATA_PASSWORD 14 /* password */
/* errors code */
#define VZS_ERR_SYSTEM 1
#define VZS_ERR_CANT_CONNECT 2
#define VZS_ERR_BAD_PARAM 3 /* invalid parameter value */
#define VZS_ERR_TIMEOUT 4 /* timeout exceeded */
#define VZS_ERR_CONN_BROKEN 5
#define VZS_ERR_TOOLONG 6 /* too long message */
#define VZS_ERR_SSL 7 /* SSL error */
#ifdef __cplusplus
extern "C" {
#endif
int vzsock_init(
int type,
struct vzsock_ctx *ctx,
int (*logger)(int level, const char *fmt, va_list pvar),
int (*readpwd)(const char *prompt, char *pass, size_t size));
int vzsock_open(struct vzsock_ctx *ctx);
void vzsock_close(struct vzsock_ctx *ctx);
int vzsock_set(struct vzsock_ctx *ctx, int type, void *data, size_t size);
int vzsock_get(struct vzsock_ctx *ctx, int type, void *data, size_t *size);
int vzsock_open_conn(struct vzsock_ctx *ctx, void *data, void **conn);
int vzsock_accept_conn(struct vzsock_ctx *ctx, void *srv_conn, void **conn);
int vzsock_is_open_conn(struct vzsock_ctx *ctx, void *conn);
int vzsock_close_conn(struct vzsock_ctx *ctx, void *conn);
int vzsock_set_conn(struct vzsock_ctx *ctx, void *conn,
int type, void *data, size_t size);
int vzsock_get_conn(struct vzsock_ctx *ctx, void *conn,
int type, void *data, size_t *size);
int vzsock_send(
struct vzsock_ctx *ctx,
void *conn,
const char * data,
size_t size);
int vzsock_send_err_msg(
struct vzsock_ctx *ctx,
void *conn,
const char * data,
size_t size);
/* read string, separated by <separator>. Will write '\0' on end of string */
int vzsock_recv(
struct vzsock_ctx *ctx,
void *conn,
char separator,
char *data,
size_t size);
#define vzsock_recv_str(ctx, conn, data, size) \
vzsock_recv((ctx), (conn), ('\0'), (data), (size))
/*
To read reply from server(destination) side as |errcode|:replymessage
NOTE: use only on client(source) side
NOTE: you also can send debug/info/warning messages from destination node
*/
int vzsock_read_srv_reply(
struct vzsock_ctx *ctx,
void *conn,
char *reply,
size_t size);
int vzsock_send_srv_reply(
struct vzsock_ctx *ctx,
void *conn,
int code,
char *reply);
/* */
int vzsock_send_data(
struct vzsock_ctx *ctx,
void *conn,
char * const *argv);
int vzsock_recv_data(
struct vzsock_ctx *ctx,
void *conn,
char * const *argv);
#ifdef __cplusplus
}
#endif
#endif