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