1 | /* $Id: larvnetd.h,v 1.3 1998-10-21 20:02:06 ghudson Exp $ */ |
---|
2 | |
---|
3 | /* Copyright 1998 by the Massachusetts Institute of Technology. |
---|
4 | * |
---|
5 | * Permission to use, copy, modify, and distribute this |
---|
6 | * software and its documentation for any purpose and without |
---|
7 | * fee is hereby granted, provided that the above copyright |
---|
8 | * notice appear in all copies and that both that copyright |
---|
9 | * notice and this permission notice appear in supporting |
---|
10 | * documentation, and that the name of M.I.T. not be used in |
---|
11 | * advertising or publicity pertaining to distribution of the |
---|
12 | * software without specific, written prior permission. |
---|
13 | * M.I.T. makes no representations about the suitability of |
---|
14 | * this software for any purpose. It is provided "as is" |
---|
15 | * without express or implied warranty. |
---|
16 | */ |
---|
17 | |
---|
18 | #ifndef LARVNETD__H |
---|
19 | #define LARVNETD__H |
---|
20 | |
---|
21 | #include <sys/types.h> |
---|
22 | #include <netinet/in.h> |
---|
23 | #include <stdio.h> |
---|
24 | #include <time.h> |
---|
25 | #include <ares.h> |
---|
26 | #include "timer.h" |
---|
27 | |
---|
28 | enum busystate { BUSY, FREE, UNKNOWN_BUSYSTATE }; |
---|
29 | |
---|
30 | struct cluster { |
---|
31 | char *name; |
---|
32 | char *phone; |
---|
33 | int cgroup; /* Index into config.cgroups, or -1 */ |
---|
34 | }; |
---|
35 | |
---|
36 | struct archname { |
---|
37 | char *reportname; |
---|
38 | char **netnames; |
---|
39 | int nnetnames; |
---|
40 | }; |
---|
41 | |
---|
42 | struct machine { |
---|
43 | /* Configuration data */ |
---|
44 | char *name; |
---|
45 | int cluster; /* Index into config.clusters */ |
---|
46 | |
---|
47 | /* State information */ |
---|
48 | enum busystate busy; |
---|
49 | char *arch; /* Architecture name reported in status */ |
---|
50 | time_t laststatus; /* Time of last status report */ |
---|
51 | time_t lastpoll; /* Time of last poll we sent */ |
---|
52 | int numpolls; /* Number of polls since laststatus */ |
---|
53 | }; |
---|
54 | |
---|
55 | struct printer { |
---|
56 | /* Configuration data */ |
---|
57 | char *name; |
---|
58 | char *location; |
---|
59 | int cluster; /* Index into config.clusters */ |
---|
60 | |
---|
61 | /* State information */ |
---|
62 | int up; |
---|
63 | int jobs; |
---|
64 | int s; /* Communications socket for polling */ |
---|
65 | int to_send; /* Non-zero if we want to send data */ |
---|
66 | char buf[BUFSIZ]; /* Data to send or data received */ |
---|
67 | int buflen; /* Amount of data in buf */ |
---|
68 | int jobs_counted; /* Jobs counted from data received so far */ |
---|
69 | int up_so_far; /* 1 until we find out the printer is down */ |
---|
70 | Timer *timer; /* Timer for next poll (when s == -1) */ |
---|
71 | }; |
---|
72 | |
---|
73 | struct cgroup { |
---|
74 | char *name; |
---|
75 | int x; |
---|
76 | int y; |
---|
77 | }; |
---|
78 | |
---|
79 | struct config { |
---|
80 | struct cluster *clusters; |
---|
81 | int nclusters; |
---|
82 | struct archname *arches; |
---|
83 | int narch; |
---|
84 | struct machine *machines; /* Sorted by name */ |
---|
85 | int nmachines; |
---|
86 | struct printer *printers; |
---|
87 | int nprinters; |
---|
88 | struct cgroup *cgroups; |
---|
89 | int ncgroups; |
---|
90 | char *report_other; |
---|
91 | char *report_unknown; |
---|
92 | }; |
---|
93 | |
---|
94 | struct serverstate { |
---|
95 | struct config config; |
---|
96 | ares_channel channel; |
---|
97 | void *hescontext; |
---|
98 | int server_socket; |
---|
99 | unsigned short poll_port; |
---|
100 | int startmachine; |
---|
101 | const char *configfile; |
---|
102 | }; |
---|
103 | |
---|
104 | /* config.c */ |
---|
105 | void read_initial_config(struct serverstate *state); |
---|
106 | void reread_config(struct serverstate *state); |
---|
107 | |
---|
108 | /* printer.c */ |
---|
109 | void printer_start_polls(struct serverstate *state); |
---|
110 | void printer_handle_output(struct serverstate *state, struct printer *printer); |
---|
111 | void printer_handle_input(struct serverstate *state, struct printer *printer); |
---|
112 | |
---|
113 | /* report.c */ |
---|
114 | void report(void *arg); |
---|
115 | |
---|
116 | /* util.c */ |
---|
117 | void *emalloc(size_t size); |
---|
118 | void *erealloc(void *ptr, size_t size); |
---|
119 | char *estrdup(const char *s); |
---|
120 | char *estrndup(const char *s, size_t n); |
---|
121 | int read_line(FILE *fp, char **buf, int *bufsize); |
---|
122 | |
---|
123 | /* ws.c */ |
---|
124 | void ws_poll(void *arg); |
---|
125 | void ws_handle_status(int s, struct config *config); |
---|
126 | struct machine *ws_find(struct config *config, const char *name); |
---|
127 | void ws_sort(struct config *config); |
---|
128 | |
---|
129 | #endif /* LARVNETD__H */ |
---|