Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libcs/cs.h
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1990-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* Glenn Fowler
23
* AT&T Research
24
*
25
* connect stream interface definitions
26
*/
27
28
#ifndef _CS_H
29
#define _CS_H
30
31
#define CS_VERSION 19970717L
32
33
#include <ast.h>
34
#include <ast_cs.h>
35
#include <hashpart.h>
36
#include <ls.h>
37
#include <times.h>
38
39
#define cs _cs_info_
40
#define Cs (&cs)
41
42
#define CSTIME() (cs.time=(unsigned long)time(NiL))
43
#define CSTOSS(n,c) HASHPART(n,c)
44
45
#define CS_LOCAL (-1L) /* local address */
46
47
#define CS_NEVER (-1L) /* no timeout */
48
49
#define CS_EXACT 0x0001 /* csread() exact amount */
50
#define CS_LIMIT 0x0002 /* csread() amount limit */
51
#define CS_LINE 0x0004 /* csread() one or more lines */
52
#define CS_RESTART 0x1000 /* restart on interrupt */
53
54
#define CS_PORT_NORMAL 0x00000000 /* alloc normal port */
55
#define CS_PORT_MIN 0x00000001 /* min real port */
56
#define CS_PORT_MAX 0x0000ffff /* max real port */
57
#define CS_PORT_INVALID 0xffffffff /* invalid port */
58
#define CS_PORT_RESERVED 0xfffffffe /* alloc reserved port */
59
60
#define CS_NORMAL CS_PORT_NORMAL
61
#define CS_RESERVED CS_PORT_RESERVED
62
63
#define CS_HOST_GATEWAY "ftp" /* local net gateway host */
64
#define CS_HOST_LOCAL "local" /* local host */
65
#define CS_HOST_PROXY "proxy" /* local net proxy host */
66
#define CS_HOST_SHARE "share" /* any local net host */
67
#define CS_HOST_UNKNOWN "unknown" /* unknown host */
68
69
#define CS_STAT_DAEMON "lib/ssd" /* system stat daemon rel name */
70
#define CS_STAT_DIR "share/lib/ss" /* system stat dir rel path */
71
#define CS_STAT_DOWN (3*CS_STAT_FREQ)/* assumed down after . secs */
72
#define CS_STAT_FREQ 50 /* avg update frequency in secs */
73
#define CS_STAT_IGNORE (24*60*60) /* ignore user after . idle */
74
75
#define CS_SVC_ACCESS "access" /* local host access */
76
#define CS_SVC_DIR "lib/cs" /* service directory */
77
#define CS_SVC_DORMANT (5*60) /* min dormant secs */
78
#define CS_SVC_HOSTS "hosts" /* hosts that can run service */
79
#define CS_SVC_INFO "local" /* local host info */
80
#define CS_SVC_REMOTE "remote" /* remote gateway info */
81
#define CS_SVC_SUFFIX ".svc" /* service daemon suffix */
82
83
#define CS_MNT_MAX 14 /* max mount file name length */
84
#define CS_NAME_MAX 256 /* misc name max length */
85
86
#define CS_MNT_TAIL "-cs.mnt" /* mount file name tail */
87
88
#define CS_MNT_AUTH 'A' /* client authentication */
89
#define CS_MNT_LOCK 'X' /* mount lock */
90
#define CS_MNT_LOG 'L' /* error log */
91
#define CS_MNT_OLDLOG 'O' /* previous error log */
92
#define CS_MNT_OTHER '#' /* no auth suffix */
93
#define CS_MNT_PROCESS 'P' /* process id */
94
#define CS_MNT_STREAM 'S' /* connect stream */
95
#define CS_MNT_TMP 'Z' /* temporary */
96
97
#define CS_REMOTE_CONTROL "cs"
98
#define CS_REMOTE_DEBUG 'd'
99
#define CS_REMOTE_DELAY 8
100
#define CS_REMOTE_OPEN 'O'
101
#define CS_REMOTE_OPEN_AGENT 'A'
102
#define CS_REMOTE_OPEN_LOCAL 'L'
103
#define CS_REMOTE_OPEN_NOW 'N'
104
#define CS_REMOTE_OPEN_READ 'R'
105
#define CS_REMOTE_OPEN_SHARE 'S'
106
#define CS_REMOTE_OPEN_TEST 'T'
107
#define CS_REMOTE_OPEN_TRUST 'X'
108
#define CS_REMOTE_PROFILE "set true; $1 eval 'unset true eval; source ./.login >& /dev/null < /dev/null'; set eval CsH=true; $1 $CsH 'shift; shift; . ./.profile >/dev/null 2>&1 </dev/null'"
109
110
#define CS_FD_ALLOCATE (-2) /* csfd() table alloc */
111
112
#define CS_OPEN_READ 0 /* initiate and open for read */
113
#define CS_OPEN_CREATE 1 /* create */
114
115
#define CS_OPEN_AGENT (1<<1) /* initiate, no authenticate */
116
#define CS_OPEN_LOCAL (1<<2) /* CS_OPEN_READ local affinity */
117
#define CS_OPEN_MOUNT (1<<3) /* no open, mount namespace only*/
118
#define CS_OPEN_NOW (1<<4) /* non blocking open */
119
#define CS_OPEN_REMOTE (1<<5) /* force CS_ADDR_REMOTE */
120
#define CS_OPEN_SHARE (1<<6) /* share affinity */
121
#define CS_OPEN_SLAVE (1<<7) /* no daemon fork() on create */
122
#define CS_OPEN_TEST (1<<8) /* open for read, no initiate */
123
#define CS_OPEN_TRUST (1<<9) /* trusted service */
124
125
#define CS_PATH_NAME (1<<0) /* cspath addr name vs. n.n.n.n */
126
127
#define CS_VAR_LOCAL 0 /* csvar for local mount dir */
128
#define CS_VAR_PROXY 1 /* csvar for proxy service */
129
#define CS_VAR_SHARE 2 /* csvar for share mount dir */
130
#define CS_VAR_TRUST 3 /* csvar for trusted root dirs */
131
132
/*
133
* cs.flags -- CS_<function>_<flags>
134
*/
135
136
#define CS_ADDR_FULL (1<<0) /* retain fully qualified names */
137
#define CS_ADDR_LOCAL (1<<1) /* local host */
138
#define CS_ADDR_NOW (1<<2) /* for CS_OPEN_NOW */
139
#define CS_ADDR_NUMERIC (1<<3) /* n.n.n.n addr */
140
#define CS_ADDR_REMOTE (1<<4) /* remote host */
141
#define CS_ADDR_SHARE (1<<5) /* share host */
142
#define CS_ADDR_TEST (1<<6) /* share host */
143
#define CS_ADDR_TRUST (1<<7) /* for CS_OPEN_TRUST */
144
#define CS_DAEMON_SLAVE (1<<8) /* no daemon fork() */
145
#define CS_PIPE_BLOCKED (1<<9) /* SIGPIPE blocked */
146
#define CS_TEST (1<<10) /* enable test */
147
148
#define CS_CLIENT_ARGV (1<<0) /* just process argv */
149
#define CS_CLIENT_RAW (1<<1) /* tty raw mode input */
150
#define CS_CLIENT_SEP (1<<2) /* argv ':' line sep */
151
152
typedef struct
153
{
154
unsigned long addr[3]; /* address cookie */
155
} Csaddr_t;
156
157
typedef struct
158
{
159
unsigned long hid; /* host id */
160
unsigned long pid; /* process id */
161
unsigned long uid; /* user id */
162
unsigned long gid; /* group id */
163
} Csid_t;
164
165
typedef struct
166
{
167
unsigned long idle; /* min user idle secs */
168
long up; /* up (down<0) time in secs */
169
int load; /* load average */
170
int pctsys; /* % time for sys */
171
int pctusr; /* % time for usr */
172
int users; /* # interesting users */
173
} Csstat_t;
174
175
struct Cs_s;
176
typedef struct Cs_s Cs_t;
177
178
struct Csdisc_s;
179
typedef struct Csdisc_s Csdisc_t;
180
181
struct Csdisc_s /* user discipline */
182
{
183
unsigned long version; /* CS_VERSION */
184
unsigned long flags; /* CS_* flags */
185
Error_f errorf; /* error message handler */
186
};
187
188
struct Cs_s /* thread state */
189
{
190
char* id; /* library id */
191
Csdisc_t* disc; /* discipline from csalloc() */
192
unsigned long addr; /* addr from csbind() */
193
unsigned long port; /* port from csbind() */
194
unsigned long time; /* time updated by CSTIME() */
195
unsigned long flags; /* misc flags */
196
char* control; /* CS_MNT_* in cs.mount */
197
char* cs; /* service connect stream */
198
char type[8]; /* csopen() stream type */
199
char qual[CS_NAME_MAX];/* csopen() qualifier */
200
char host[CS_NAME_MAX];/* csaddr() real host */
201
char mount[PATH_MAX];/* current mount path */
202
char user[CS_NAME_MAX];/* csaddr() user */
203
204
#ifdef _CS_PRIVATE_
205
_CS_PRIVATE_
206
#endif
207
208
};
209
210
#if _BLD_cs && defined(__EXPORT__)
211
#define extern __EXPORT__
212
#endif
213
#if !_BLD_cs && defined(__IMPORT__)
214
#define extern extern __IMPORT__
215
#endif
216
217
extern Cs_t cs;
218
219
#undef extern
220
221
#if _BLD_cs && defined(__EXPORT__)
222
#define extern __EXPORT__
223
#endif
224
225
#if CS_INTERFACE <= 1
226
227
#define Cs_addr_t Csaddr_t
228
#define Cs_id_t Csid_t
229
#define Cs_info_t Cs_t
230
#define Cs_poll_t Cspoll_t
231
#define Cs_stat_t Csstat_t
232
233
#define CSADDR Csaddr_t
234
#define CSID Csid_t
235
#define CSINFO Csinfo_t
236
#define CSPOLL Cspoll_t
237
#define CSSTAT Csstat_t
238
239
#define csaddr _cs_addr
240
#define csattach _cs_attach
241
#define csattr _cs_attr
242
#define csauth _cs_auth
243
#define csbind _cs_bind
244
#define csclient _cs_client
245
#define csclone _cs_clone
246
#define cschallenge _cs_challenge
247
#define csdaemon _cs_daemon
248
#define csfd _cs_fd
249
#define csfrom _cs_from
250
#define csfull _cs_full
251
#define csinfo _cs_info
252
#define cslocal _cs_local
253
#define csname _cs_name
254
#define csnote _cs_note
255
#define csntoa _cs_ntoa
256
#define csopen _cs_open
257
#define cspath _cs_path
258
#define cspeek _cs_peek
259
#define csping _cs_ping
260
#define cspipe _cs_pipe
261
#define cspoll _cs_poll
262
#define csport _cs_port
263
#define csread _cs_read
264
#define csrecv _cs_recv
265
#define cssend _cs_send
266
#define csserve _cs_serve
267
#define csstat _cs_stat
268
#define cstimeout _cs_timeout
269
#define csto _cs_to
270
#define csvar _cs_var
271
#define cswakeup _cs_wakeup
272
#define cswrite _cs_write
273
274
#else
275
276
extern unsigned long csaddr(Cs_t*, const char*);
277
extern Cs_t* csalloc(Csdisc_t*);
278
extern int csattach(Cs_t*, const char*, int, int);
279
extern char* csattr(Cs_t*, const char*, const char*);
280
extern int csauth(Cs_t*, int, const char*, const char*);
281
extern int csbind(Cs_t*, const char*, unsigned long, unsigned long, unsigned long);
282
extern int cschallenge(Cs_t*, const char*, unsigned long*, unsigned long*);
283
extern int csclient(Cs_t*, int, const char*, const char*, char**, unsigned int);
284
extern unsigned long csclone(Cs_t*, int);
285
extern int csdaemon(Cs_t*, int);
286
extern int csfd(Cs_t*, int, int);
287
extern int csfree(Cs_t*);
288
extern ssize_t csfrom(Cs_t*, int, void*, size_t, Csaddr_t*);
289
extern char* csfull(Cs_t*, unsigned long);
290
extern Sfio_t* csinfo(Cs_t*, const char*, int*);
291
extern int cslocal(Cs_t*, const char*);
292
extern char* csname(Cs_t*, unsigned long);
293
extern int csnote(Cs_t*, const char*, Csstat_t*);
294
extern char* csntoa(Cs_t*, unsigned long);
295
extern int csopen(Cs_t*, const char*, int);
296
extern char* cspath(Cs_t*, int, int);
297
extern ssize_t cspeek(Cs_t*, int, void*, size_t);
298
extern int csping(Cs_t*, const char*);
299
extern int cspipe(Cs_t*, int*);
300
extern int cspoll(Cs_t*, Cspoll_t*, int, int);
301
extern unsigned long csport(Cs_t*, const char*, const char*);
302
extern ssize_t csread(Cs_t*, int, void*, size_t, int);
303
extern int csrecv(Cs_t*, int, Csid_t*, int*, int);
304
extern int cssend(Cs_t*, int, int*, int);
305
extern void csserve(Cs_t*, void*, const char*, void*(*)(void*, int), int(*)(void*, int), int(*)(void*, int, Csid_t*, int, char**), int(*)(void*, int), int(*)(void*, int), int(*)(void*));
306
extern int csstat(Cs_t*, const char*, Csstat_t*);
307
extern unsigned long cstimeout(Cs_t*, unsigned long);
308
extern ssize_t csto(Cs_t*, int, const void*, size_t, Csaddr_t*);
309
extern char* csvar(Cs_t*, int, int);
310
extern unsigned long cswakeup(Cs_t*, unsigned long);
311
extern ssize_t cswrite(Cs_t*, int, const void*, size_t);
312
313
#endif
314
315
#if CS_INTERFACE <= 1 || defined(_CS_PRIVATE_)
316
317
extern unsigned long _cs_addr(const char*);
318
extern int _cs_attach(const char*, int, int);
319
extern char* _cs_attr(const char*, const char*);
320
extern int _cs_auth(int, const char*, const char*);
321
extern int _cs_bind(const char*, unsigned long, unsigned long, unsigned long);
322
extern int _cs_client(int, const char*, const char*, char**, unsigned int);
323
extern unsigned long _cs_clone(int);
324
extern int _cs_daemon(int);
325
extern int _cs_fd(int, int);
326
extern ssize_t _cs_from(int, void*, size_t, Csaddr_t*);
327
extern char* _cs_full(unsigned long);
328
extern Sfio_t* _cs_info(const char*, int*);
329
extern int _cs_local(const char*);
330
extern char* _cs_name(unsigned long);
331
extern int _cs_note(const char*, Csstat_t*);
332
extern char* _cs_ntoa(unsigned long);
333
extern int _cs_open(const char*, int);
334
extern char* _cs_path(int, int);
335
extern ssize_t _cs_peek(int, void*, size_t);
336
extern int _cs_ping(const char*);
337
extern int _cs_pipe(int*);
338
extern int _cs_poll(Cspoll_t*, int, int);
339
extern unsigned long _cs_port(const char*, const char*);
340
extern ssize_t _cs_read(int, void*, size_t, int);
341
extern int _cs_recv(int, Csid_t*, int*, int);
342
extern int _cs_send(int, int*, int);
343
extern void _cs_serve(void*, const char*, void*(*)(void*, int), int(*)(void*, int), int(*)(void*, int, Csid_t*, int, char**), int(*)(void*, int), int(*)(void*, int), int(*)(void*));
344
extern int _cs_stat(const char*, Csstat_t*);
345
extern unsigned long _cs_timeout(unsigned long);
346
extern ssize_t _cs_to(int, const void*, size_t, Csaddr_t*);
347
extern char* _cs_var(int, int);
348
extern unsigned long _cs_wakeup(unsigned long);
349
extern ssize_t _cs_write(int, const void*, size_t);
350
351
#endif
352
353
#undef extern
354
355
#endif
356
357