]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/h/zephyr/zephyr.h
b2a54bdf8aa202cc289259f816041ff02d46b781
[1ts-debian.git] / zephyr / h / zephyr / zephyr.h
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It contains global definitions
3  *
4  *      Created by:     Robert French
5  *
6  *      $Id: zephyr.h 2362 2009-03-28 21:05:19Z kcr@ATHENA.MIT.EDU $
7  *
8  *      Copyright (c) 1987,1988,1991 by the Massachusetts Institute of
9  *      Technology. For copying and distribution information, see the
10  *      file "mit-copyright.h".
11  */
12
13 #ifndef __ZEPHYR_H__
14 #define __ZEPHYR_H__
15
16 #include <sys/types.h>
17 #include <sys/time.h>
18 #include <sys/socket.h>
19
20 #include <zephyr/zephyr_err.h>
21
22 #ifndef IPPROTO_MAX     /* Make sure not already included */
23 #include <netinet/in.h>
24 #endif
25
26 #include <stdarg.h>
27
28 /* Service names */
29 #define HM_SVCNAME              "zephyr-hm"
30 #define HM_SRV_SVCNAME          "zephyr-hm-srv"
31 #define SERVER_SVCNAME          "zephyr-clt"
32 #define SERVER_SERVICE          "zephyr"
33 #define SERVER_INSTANCE         "zephyr"
34 #define SERVER_KRB5_SERVICE     "zephyr"
35
36 #define ZVERSIONHDR     "ZEPH"
37 #define ZVERSIONMAJOR   0
38 #define ZVERSIONMINOR   2
39
40 #define Z_MAXPKTLEN             1024
41 #define Z_MAXHEADERLEN          800
42 #define Z_MAXOTHERFIELDS        10      /* Max unknown fields in ZNotice_t */
43 #define Z_NUMFIELDS             19
44
45 /* Authentication levels returned by ZCheckAuthentication */
46 #define ZAUTH_FAILED            (-1)
47 #define ZAUTH_YES               1
48 #define ZAUTH_NO                0
49
50 #define ZNOTICE_SOCKADDR        1
51 #define ZNOTICE_CHARSET         1
52
53 #define ZCHARSET_UNKNOWN        0
54 /* The following are from http://www.iana.org/assignments/character-sets */
55 #define ZCHARSET_ISO_8859_1     4
56 #define ZCHARSET_UTF_8          106
57
58 typedef char ZPacket_t[Z_MAXPKTLEN];
59
60 /* Packet type */
61 typedef enum {
62     UNSAFE, UNACKED, ACKED, HMACK, HMCTL, SERVACK, SERVNAK, CLIENTACK, STAT
63 } ZNotice_Kind_t;
64 extern const char *ZNoticeKinds[9];
65
66 struct _ZTimeval {
67         int tv_sec;
68         int tv_usec;
69 };
70
71 /* Unique ID format */
72 typedef struct _ZUnique_Id_t {
73     struct      in_addr zuid_addr;
74     struct      _ZTimeval       tv;
75 } ZUnique_Id_t;
76
77 /* Checksum */
78 typedef unsigned int ZChecksum_t;
79
80 /* Notice definition */
81 typedef struct _ZNotice_t {
82     char                *z_packet;
83     char                *z_version;
84     ZNotice_Kind_t      z_kind;
85     ZUnique_Id_t        z_uid;
86     union {
87         struct sockaddr         sa;
88         struct sockaddr_in      ip4;
89         struct sockaddr_in6     ip6;
90     } z_sender_sockaddr;
91     /* heavily deprecated: */
92 #define z_sender_addr   z_sender_sockaddr.ip4.sin_addr
93     /* probably a bad idea?: */
94     struct              _ZTimeval z_time;
95     unsigned short      z_port;
96     unsigned short      z_charset;
97     int                 z_auth;
98     int                 z_checked_auth;
99     int                 z_authent_len;
100     char                *z_ascii_authent;
101     char                *z_class;
102     char                *z_class_inst;
103     char                *z_opcode;
104     char                *z_sender;
105     char                *z_recipient;
106     char                *z_default_format;
107     char                *z_multinotice;
108     ZUnique_Id_t        z_multiuid;
109     ZChecksum_t         z_checksum;
110     char                *z_ascii_checksum;
111     int                 z_num_other_fields;
112     char                *z_other_fields[Z_MAXOTHERFIELDS];
113     caddr_t             z_message;
114     int                 z_message_len;
115     int                 z_num_hdr_fields;
116     char                **z_hdr_fields;
117 } ZNotice_t;
118
119 /* Subscription structure */
120 typedef struct _ZSubscriptions_t {
121     char        *zsub_recipient;
122     char        *zsub_class;
123     char        *zsub_classinst;
124 } ZSubscription_t;
125
126 /* Function return code */
127 typedef int Code_t;
128
129 /* Locations structure */
130 typedef struct _ZLocations_t {
131     char        *host;
132     char        *time;
133     char        *tty;
134 } ZLocations_t;
135
136 typedef struct _ZAsyncLocateData_t {
137     char                *user;
138     ZUnique_Id_t        uid;
139     char                *version;
140 } ZAsyncLocateData_t;
141
142 /* for ZSetDebug */
143 #ifdef Z_DEBUG
144 void (*__Z_debug_print)(const char *fmt, va_list args, void *closure);
145 void *__Z_debug_print_closure;
146 #endif
147
148 int ZCompareUIDPred(ZNotice_t *, void *);
149 int ZCompareMultiUIDPred(ZNotice_t *, void *);
150
151 /* Defines for ZFormatNotice, et al. */
152 typedef Code_t (*Z_AuthProc)(ZNotice_t*, char *, int, int *);
153 Code_t ZMakeAuthentication(ZNotice_t*, char *,int, int*);
154 Code_t ZMakeZcodeAuthentication(ZNotice_t*, char *,int, int*);
155 Code_t ZMakeZcodeRealmAuthentication(ZNotice_t*, char *,int, int*, char*);
156
157 char *ZGetSender(void);
158 char *ZGetVariable(char *);
159 Code_t ZSetVariable(char *var, char *value);
160 Code_t ZUnsetVariable(char *var);
161 int ZGetWGPort(void);
162 Code_t ZSetDestAddr(struct sockaddr_in *);
163 Code_t ZFormatNoticeList(ZNotice_t*, char**, int,
164                          char **, int*, Z_AuthProc);
165 Code_t ZParseNotice(char*, int, ZNotice_t *);
166 Code_t ZReadAscii(char*, int, unsigned char*, int);
167 Code_t ZReadAscii32(char *, int, unsigned long *);
168 Code_t ZReadAscii16(char *, int, unsigned short *);
169 Code_t ZReadZcode(unsigned char*, unsigned char*, int, int *);
170 Code_t ZSendPacket(char*, int, int);
171 Code_t ZSendList(ZNotice_t*, char *[], int, Z_AuthProc);
172 Code_t ZSrvSendList(ZNotice_t*, char*[], int, Z_AuthProc,
173                     Code_t (*)(ZNotice_t *, char *, int, int));
174 Code_t ZSendNotice(ZNotice_t *, Z_AuthProc);
175 Code_t ZSrvSendNotice(ZNotice_t*, Z_AuthProc,
176                       Code_t (*)(ZNotice_t *, char *, int, int));
177 Code_t ZFormatNotice(ZNotice_t*, char**, int*, Z_AuthProc);
178 Code_t ZFormatSmallNotice(ZNotice_t*, ZPacket_t, int*, Z_AuthProc);
179 Code_t ZFormatRawNoticeList(ZNotice_t *, char *[], int, char **, int *);
180 Code_t ZFormatSmallRawNotice(ZNotice_t *, ZPacket_t, int *);
181 Code_t ZNewFormatSmallRawNotice(ZNotice_t *, ZPacket_t, int *);
182 Code_t ZLocateUser(char *, int *, Z_AuthProc);
183 Code_t ZRequestLocations(char *, ZAsyncLocateData_t *,
184                          ZNotice_Kind_t, Z_AuthProc);
185 Code_t ZhmStat(struct in_addr *, ZNotice_t *);
186 Code_t ZInitialize(void);
187 Code_t ZSetServerState(int);
188 Code_t ZSetFD(int);
189 Code_t ZFormatSmallRawNotice(ZNotice_t*, ZPacket_t, int*);
190 int ZCompareUID(ZUnique_Id_t*, ZUnique_Id_t*);
191 Code_t ZSrvSendRawList(ZNotice_t*, char*[], int,
192                        Code_t (*)(ZNotice_t *, char *, int, int));
193 Code_t ZMakeAscii(char*, int, unsigned char*, int);
194 Code_t ZMakeAscii32(char *, int, unsigned long);
195 Code_t ZMakeAscii16(char *, int, unsigned int);
196 Code_t ZMakeZcode(char*, int, unsigned char*, int);
197 Code_t ZMakeZcode32(char *, int, unsigned long);
198 Code_t ZReceivePacket(ZPacket_t, int*, struct sockaddr_in*);
199 Code_t ZCheckAuthentication(ZNotice_t*, struct sockaddr_in*);
200 Code_t ZCheckZcodeAuthentication(ZNotice_t*, struct sockaddr_in*);
201 Code_t ZCheckZcodeRealmAuthentication(ZNotice_t*, struct sockaddr_in*, char *realm);
202 Code_t ZInitLocationInfo(char *hostname, char *tty);
203 Code_t ZSetLocation(char *exposure);
204 Code_t ZUnsetLocation(void);
205 Code_t ZFlushMyLocations(void);
206 char *ZParseExposureLevel(char *text);
207 Code_t ZFormatRawNotice(ZNotice_t *, char**, int *);
208 Code_t ZRetrieveSubscriptions(unsigned short, int*);
209 Code_t ZRetrieveDefaultSubscriptions(int *);
210 Code_t ZGetSubscriptions(ZSubscription_t *, int *);
211 Code_t ZOpenPort(unsigned short *port);
212 Code_t ZClosePort(void);
213 Code_t ZFlushLocations(void);
214 Code_t ZFlushSubscriptions(void);
215 Code_t ZFreeNotice(ZNotice_t *notice);
216 Code_t ZGetLocations(ZLocations_t *, int *);
217 Code_t ZParseLocations(register ZNotice_t *notice,
218                        register ZAsyncLocateData_t *zald, int *nlocs,
219                        char **user);
220 int ZCompareALDPred(ZNotice_t *notice, void *zald);
221 void ZFreeALD(register ZAsyncLocateData_t *zald);
222 Code_t ZCheckIfNotice(ZNotice_t *notice, struct sockaddr_in *from,
223                       register int (*predicate)(ZNotice_t *,void *),
224                       void *args);
225 Code_t ZPeekPacket(char **buffer, int *ret_len,
226                    struct sockaddr_in *from);
227 Code_t ZPeekNotice(ZNotice_t *notice, struct sockaddr_in *from);
228 Code_t ZIfNotice(ZNotice_t *notice, struct sockaddr_in *from,
229                  int (*predicate)(ZNotice_t *, void *), void *args);
230 Code_t ZSubscribeTo(ZSubscription_t *sublist, int nitems,
231                     unsigned int port);
232 Code_t ZSubscribeToSansDefaults(ZSubscription_t *sublist, int nitems,
233                                 unsigned int port);
234 Code_t ZUnsubscribeTo(ZSubscription_t *sublist, int nitems,
235                       unsigned int port);
236 Code_t ZCancelSubscriptions(unsigned int port);
237 int ZPending(void);
238 Code_t ZReceiveNotice(ZNotice_t *notice, struct sockaddr_in *from);
239 unsigned short ZGetCharset(char *charset);
240 const char *ZCharsetToString(unsigned short charset);
241 #ifdef Z_DEBUG
242 void Z_debug(const char *, ...);
243 #endif
244 char *ZExpandRealm(char *realm);
245
246 /* Compatibility */
247 #define ZNewLocateUser ZLocateUser
248
249 /* Not macros to retrieve Zephyr library values. */
250 const char *ZGetRealm(void);
251 int ZGetFD (void);
252 int ZQLength (void);
253 struct sockaddr_in ZGetDestAddr (void);
254
255
256 #ifdef Z_DEBUG
257 void ZSetDebug (void (*)(const char *, va_list, void *), void *);
258 #define ZSetDebug(proc,closure)    (__Z_debug_print=(proc), \
259                                     __Z_debug_print_closure=(closure), \
260                                     (void) 0)
261 #else
262 #define ZSetDebug(proc,closure)
263 #endif
264
265 /* Maximum queue length */
266 #define Z_MAXQLEN               30
267
268 /* Successful function return */
269 #define ZERR_NONE               0
270
271 /* Hostmanager wait time (in secs) */
272 #define HM_TIMEOUT              10
273
274 /* Server wait time (in secs) */
275 #define SRV_TIMEOUT             30
276
277 #define ZAUTH (ZMakeAuthentication)
278 #define ZCAUTH (ZMakeZcodeAuthentication)
279 #define ZNOAUTH ((Z_AuthProc)0)
280
281 /* Packet strings */
282 #define ZSRVACK_SENT            "SENT"  /* SERVACK codes */
283 #define ZSRVACK_NOTSENT         "LOST"
284 #define ZSRVACK_FAIL            "FAIL"
285
286 /* Server internal class */
287 #define ZEPHYR_ADMIN_CLASS      "ZEPHYR_ADMIN"  /* Class */
288
289 /* Control codes sent to a server */
290 #define ZEPHYR_CTL_CLASS        "ZEPHYR_CTL"    /* Class */
291
292 #define ZEPHYR_CTL_REALM        "REALM"         /* Inst: From realm */
293 #define REALM_ADD_SUBSCRIBE     "ADD_SUBSCRIBE" /* Opcode: Add subs */
294 #define REALM_REQ_SUBSCRIBE     "REQ_SUBSCRIBE" /* Opcode: Request subs */
295 #define REALM_SUBSCRIBE         "RLM_SUBSCRIBE" /* Opcode: Subscribe realm */
296 #define REALM_UNSUBSCRIBE       "RLM_UNSUBSCRIBE" /* Opcode: Unsub realm */
297
298 #define ZEPHYR_CTL_CLIENT       "CLIENT"        /* Inst: From client */
299 #define CLIENT_SUBSCRIBE        "SUBSCRIBE"     /* Opcode: Subscribe */
300 #define CLIENT_SUBSCRIBE_NODEFS "SUBSCRIBE_NODEFS"      /* Opcode: Subscribe */
301 #define CLIENT_UNSUBSCRIBE      "UNSUBSCRIBE"   /* Opcode: Unsubsubscribe */
302 #define CLIENT_CANCELSUB        "CLEARSUB"      /* Opcode: Clear all subs */
303 #define CLIENT_GIMMESUBS        "GIMME"         /* Opcode: Give me subs */
304 #define CLIENT_GIMMEDEFS        "GIMMEDEFS"     /* Opcode: Give me default
305                                                  * subscriptions */
306
307 #define ZEPHYR_CTL_HM           "HM"            /* Inst: From HM */
308 #define HM_BOOT                 "BOOT"          /* Opcode: Boot msg */
309 #define HM_FLUSH                "FLUSH"         /* Opcode: Flush me */
310 #define HM_DETACH               "DETACH"        /* Opcode: Detach me */
311 #define HM_ATTACH               "ATTACH"        /* Opcode: Attach me */
312
313 /* Control codes send to a HostManager */
314 #define HM_CTL_CLASS            "HM_CTL"        /* Class */
315
316 #define HM_CTL_SERVER           "SERVER"        /* Inst: From server */
317 #define SERVER_SHUTDOWN         "SHUTDOWN"      /* Opcode: Server shutdown */
318 #define SERVER_PING             "PING"          /* Opcode: PING */
319
320 #define HM_CTL_CLIENT           "CLIENT"        /* Inst: From client */
321 #define CLIENT_FLUSH            "FLUSH"         /* Opcode: Send flush to srv */
322 #define CLIENT_NEW_SERVER       "NEWSERV"       /* Opcode: Find new server */
323
324 /* HM Statistics */
325 #define HM_STAT_CLASS           "HM_STAT"       /* Class */
326
327 #define HM_STAT_CLIENT          "HMST_CLIENT"   /* Inst: From client */
328 #define HM_GIMMESTATS           "GIMMESTATS"    /* Opcode: get stats */
329
330 /* Login class messages */
331 #define LOGIN_CLASS             "LOGIN"         /* Class */
332
333 /* Class Instance is principal of user who is logging in or logging out */
334
335 #define EXPOSE_NONE             "NONE"          /* Opcode: Not visible */
336 #define EXPOSE_OPSTAFF          "OPSTAFF"       /* Opcode: Opstaff visible */
337 #define EXPOSE_REALMVIS         "REALM-VISIBLE" /* Opcode: Realm visible */
338 #define EXPOSE_REALMANN         "REALM-ANNOUNCED"/* Opcode: Realm announced */
339 #define EXPOSE_NETVIS           "NET-VISIBLE"   /* Opcode: Net visible */
340 #define EXPOSE_NETANN           "NET-ANNOUNCED" /* Opcode: Net announced */
341 #define LOGIN_USER_LOGIN        "USER_LOGIN"    /* Opcode: user login
342                                                    (from server) */
343 #define LOGIN_USER_LOGOUT       "USER_LOGOUT"   /* Opcode: User logout */
344 #define LOGIN_USER_FLUSH        "USER_FLUSH"    /* Opcode: flush all locs */
345
346 /* Locate class messages */
347 #define LOCATE_CLASS            "USER_LOCATE"   /* Class */
348
349 #define LOCATE_HIDE             "USER_HIDE"     /* Opcode: Hide me */
350 #define LOCATE_UNHIDE           "USER_UNHIDE"   /* Opcode: Unhide me */
351
352 /* Class Instance is principal of user to locate */
353 #define LOCATE_LOCATE           "LOCATE"        /* Opcode: Locate user */
354
355 /* WG_CTL class messages */
356 #define WG_CTL_CLASS            "WG_CTL"        /* Class */
357
358 #define WG_CTL_USER             "USER"          /* Inst: User request */
359 #define USER_REREAD             "REREAD"        /* Opcode: Reread desc file */
360 #define USER_SHUTDOWN           "SHUTDOWN"      /* Opcode: Go catatonic */
361 #define USER_STARTUP            "STARTUP"       /* Opcode: Come out of it */
362 #define USER_EXIT               "EXIT"          /* Opcode: Exit the client */
363
364 #endif /* __ZEPHYR_H__ */