55d5ccb4190cc448bce896ec4c8c8ef691702e60
[platform/upstream/cups.git] / scheduler / cupsd.h
1 /*
2  * "$Id: cupsd.h 9766 2011-05-11 22:17:34Z mike $"
3  *
4  *   Main header file for the CUPS scheduler.
5  *
6  *   Copyright 2007-2011 by Apple Inc.
7  *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
8  *
9  *   These coded instructions, statements, and computer programs are the
10  *   property of Apple Inc. and are protected by Federal copyright
11  *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
12  *   "LICENSE" which should have been included with this file.  If this
13  *   file is missing or damaged, see the license at "http://www.cups.org/".
14  */
15
16
17 /*
18  * Include necessary headers.
19  */
20
21 #include <cups/cups-private.h>
22 #include <cups/file-private.h>
23
24 #include <limits.h>
25 #include <time.h>
26 #include <signal.h>
27 #include <fcntl.h>
28 #include <math.h>
29 #include <sys/types.h>
30 #include <sys/time.h>
31 #include <sys/stat.h>
32 #include <sys/wait.h>
33
34 #ifdef WIN32
35 #  include <direct.h>
36 #else
37 #  include <unistd.h>
38 #endif /* WIN32 */
39
40 #include "mime.h"
41
42 #if defined(HAVE_CDSASSL)
43 #  include <CoreFoundation/CoreFoundation.h>
44 #endif /* HAVE_CDSASSL */
45
46
47 /*
48  * Some OS's don't have hstrerror(), most notably Solaris...
49  */
50
51 #ifndef HAVE_HSTRERROR
52 #  ifdef hstrerror
53 #    undef hstrerror
54 #  endif /* hstrerror */
55 #  define hstrerror cups_hstrerror
56
57 extern const char *cups_hstrerror(int);
58 #endif /* !HAVE_HSTRERROR */
59
60
61 /*
62  * Common constants.
63  */
64
65 #ifndef FALSE
66 #  define FALSE         0
67 #  define TRUE          (!FALSE)
68 #endif /* !FALSE */
69
70
71 /*
72  * Implementation limits...
73  */
74
75 #define MAX_ENV                 100     /* Maximum number of environment strings */
76 #define MAX_USERPASS            33      /* Maximum size of username/password */
77 #define MAX_FILTERS             20      /* Maximum number of filters */
78 #define MAX_SYSTEM_GROUPS       32      /* Maximum number of system groups */
79
80
81 /*
82  * Defaults...
83  */
84
85 #define DEFAULT_HISTORY         1       /* Preserve job history? */
86 #define DEFAULT_FILES           0       /* Preserve job files? */
87 #define DEFAULT_TIMEOUT         300     /* Timeout during requests/updates */
88 #define DEFAULT_KEEPALIVE       30      /* Timeout between requests */
89 #define DEFAULT_INTERVAL        30      /* Interval between browse updates */
90 #define DEFAULT_CHARSET         "utf-8" /* Default charset */
91
92
93 /*
94  * Global variable macros...
95  */
96
97 #ifdef _MAIN_C_
98 #  define VAR
99 #  define VALUE(x) =x
100 #  define VALUE2(x,y) ={x,y}
101 #else
102 #  define VAR      extern
103 #  define VALUE(x)
104 #  define VALUE2(x,y)
105 #endif /* _MAIN_C */
106
107
108 /*
109  * Other stuff for the scheduler...
110  */
111
112 #include "sysman.h"
113 #include "statbuf.h"
114 #include "cert.h"
115 #include "auth.h"
116 #include "client.h"
117 #include "policy.h"
118 #include "printers.h"
119 #include "classes.h"
120 #include "job.h"
121 #include "conf.h"
122 #include "banners.h"
123 #include "dirsvc.h"
124 #include "network.h"
125 #include "subscriptions.h"
126
127
128 /*
129  * Reload types...
130  */
131
132 #define RELOAD_NONE     0               /* No reload needed */
133 #define RELOAD_ALL      1               /* Reload everything */
134 #define RELOAD_CUPSD    2               /* Reload only cupsd.conf */
135
136
137 /*
138  * Select callback function type...
139  */
140
141 typedef void (*cupsd_selfunc_t)(void *data);
142
143
144 /*
145  * Globals...
146  */
147
148 VAR int                 TestConfigFile  VALUE(0),
149                                         /* Test the cupsd.conf file? */
150                         UseProfiles     VALUE(1);
151                                         /* Use security profiles for child procs? */
152 VAR int                 MaxFDs          VALUE(0);
153                                         /* Maximum number of files */
154
155 VAR time_t              ReloadTime      VALUE(0);
156                                         /* Time of reload request... */
157 VAR int                 NeedReload      VALUE(RELOAD_ALL),
158                                         /* Need to load configuration? */
159                         DoingShutdown   VALUE(0);
160                                         /* Shutting down the scheduler? */
161 VAR void                *DefaultProfile VALUE(0);
162                                         /* Default security profile */
163
164 #ifdef HAVE_GSSAPI
165 VAR int                 KerberosInitialized     VALUE(0);
166                                         /* Has Kerberos been initialized? */
167 VAR krb5_context        KerberosContext VALUE(NULL);
168                                         /* Kerberos context for credentials */
169 #endif /* HAVE_GSSAPI */
170
171 #ifdef HAVE_LAUNCH_H
172 VAR int                 Launchd         VALUE(0);
173                                         /* Running from launchd */
174 #endif /* HAVE_LAUNCH_H */
175
176
177 /*
178  * Prototypes...
179  */
180
181 /* env.c */
182 extern void             cupsdInitEnv(void);
183 extern int              cupsdLoadEnv(char *envp[], int envmax);
184 extern void             cupsdSetEnv(const char *name, const char *value);
185 extern void             cupsdSetEnvf(const char *name, const char *value, ...)
186 #ifdef __GNUC__
187 __attribute__ ((__format__ (__printf__, 2, 3)))
188 #endif /* __GNUC__ */
189 ;
190 extern void             cupsdUpdateEnv(void);
191
192 /* file.c */
193 extern void             cupsdCleanFiles(const char *path, const char *pattern);
194 extern int              cupsdCloseCreatedConfFile(cups_file_t *fp,
195                                                   const char *filename);
196 extern void             cupsdClosePipe(int *fds);
197 extern cups_file_t      *cupsdCreateConfFile(const char *filename, mode_t mode);
198 extern cups_file_t      *cupsdOpenConfFile(const char *filename);
199 extern int              cupsdOpenPipe(int *fds);
200 extern int              cupsdRemoveFile(const char *filename);
201
202 /* main.c */
203 extern int              cupsdAddString(cups_array_t **a, const char *s);
204 extern void             cupsdCheckProcess(void);
205 extern void             cupsdClearString(char **s);
206 extern void             cupsdFreeStrings(cups_array_t **a);
207 extern void             cupsdHoldSignals(void);
208 extern char             *cupsdMakeUUID(const char *name, int number,
209                                        char *buffer, size_t bufsize);
210 extern void             cupsdReleaseSignals(void);
211 extern void             cupsdSetString(char **s, const char *v);
212 extern void             cupsdSetStringf(char **s, const char *f, ...)
213 #ifdef __GNUC__
214 __attribute__ ((__format__ (__printf__, 2, 3)))
215 #endif /* __GNUC__ */
216 ;
217
218 /* process.c */
219 extern void             *cupsdCreateProfile(int job_id);
220 extern void             cupsdDestroyProfile(void *profile);
221 extern int              cupsdEndProcess(int pid, int force);
222 extern const char       *cupsdFinishProcess(int pid, char *name, int namelen,
223                                             int *job_id);
224 extern int              cupsdStartProcess(const char *command, char *argv[],
225                                           char *envp[], int infd, int outfd,
226                                           int errfd, int backfd, int sidefd,
227                                           int root, void *profile,
228                                           cupsd_job_t *job, int *pid);
229
230 /* select.c */
231 extern int              cupsdAddSelect(int fd, cupsd_selfunc_t read_cb,
232                                        cupsd_selfunc_t write_cb, void *data);
233 extern int              cupsdDoSelect(long timeout);
234 #ifdef CUPSD_IS_SELECTING
235 extern int              cupsdIsSelecting(int fd);
236 #endif /* CUPSD_IS_SELECTING */
237 extern void             cupsdRemoveSelect(int fd);
238 extern void             cupsdStartSelect(void);
239 extern void             cupsdStopSelect(void);
240
241 /* server.c */
242 extern void             cupsdStartServer(void);
243 extern void             cupsdStopServer(void);
244
245
246 /*
247  * End of "$Id: cupsd.h 9766 2011-05-11 22:17:34Z mike $".
248  */