]>
Commit | Line | Data |
---|---|---|
bc44d920 | 1 | /* |
1f0275e3 | 2 | * "$Id$" |
bc44d920 | 3 | * |
71e16022 | 4 | * Scheduler control program for CUPS. |
bc44d920 | 5 | * |
f3c17241 | 6 | * Copyright 2007-2012 by Apple Inc. |
bc44d920 | 7 | * Copyright 2006-2007 by Easy Software Products. |
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 | * which should have been included with this file. If this file is | |
13 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
14 | * | |
15 | * This file is subject to the Apple OS-Developed Software exception. | |
16 | * | |
17 | * Contents: | |
18 | * | |
19 | * main() - Get/set server settings. | |
20 | * usage() - Show program usage. | |
21 | */ | |
22 | ||
23 | /* | |
24 | * Include necessary headers... | |
25 | */ | |
26 | ||
71e16022 | 27 | #include <cups/cups-private.h> |
bc44d920 | 28 | #include <cups/adminutil.h> |
bc44d920 | 29 | |
30 | ||
31 | /* | |
32 | * Local functions... | |
33 | */ | |
34 | ||
85dda01c | 35 | static void usage(const char *opt) __attribute__((noreturn)); |
bc44d920 | 36 | |
37 | ||
38 | /* | |
39 | * 'main()' - Get/set server settings. | |
40 | */ | |
41 | ||
42 | int /* O - Exit status */ | |
43 | main(int argc, /* I - Number of command-line args */ | |
44 | char *argv[]) /* I - Command-line arguments */ | |
45 | { | |
46 | int i, /* Looping var */ | |
47 | num_settings; /* Number of settings */ | |
48 | cups_option_t *settings; /* Settings */ | |
49 | const char *opt; /* Current option character */ | |
50 | http_t *http; /* Connection to server */ | |
51 | ||
52 | ||
53 | /* | |
54 | * Process the command-line... | |
55 | */ | |
56 | ||
57 | _cupsSetLocale(argv); | |
58 | ||
59 | num_settings = 0; | |
60 | settings = NULL; | |
61 | ||
62 | for (i = 1; i < argc; i ++) | |
63 | { | |
64 | if (argv[i][0] == '-') | |
65 | { | |
66 | if (argv[i][1] == '-') | |
67 | { | |
355e94dc | 68 | if (!strcmp(argv[i], "--debug-logging")) |
bc44d920 | 69 | num_settings = cupsAddOption(CUPS_SERVER_DEBUG_LOGGING, "1", |
70 | num_settings, &settings); | |
71 | else if (!strcmp(argv[i], "--no-debug-logging")) | |
72 | num_settings = cupsAddOption(CUPS_SERVER_DEBUG_LOGGING, "0", | |
73 | num_settings, &settings); | |
74 | else if (!strcmp(argv[i], "--remote-admin")) | |
75 | num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ADMIN, "1", | |
76 | num_settings, &settings); | |
77 | else if (!strcmp(argv[i], "--no-remote-admin")) | |
78 | num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ADMIN, "0", | |
79 | num_settings, &settings); | |
80 | else if (!strcmp(argv[i], "--remote-any")) | |
81 | num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ANY, "1", | |
82 | num_settings, &settings); | |
83 | else if (!strcmp(argv[i], "--no-remote-any")) | |
84 | num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ANY, "0", | |
85 | num_settings, &settings); | |
bc44d920 | 86 | else if (!strcmp(argv[i], "--share-printers")) |
87 | num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS, "1", | |
88 | num_settings, &settings); | |
89 | else if (!strcmp(argv[i], "--no-share-printers")) | |
90 | num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS, "0", | |
91 | num_settings, &settings); | |
92 | else if (!strcmp(argv[i], "--user-cancel-any")) | |
93 | num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY, "1", | |
94 | num_settings, &settings); | |
95 | else if (!strcmp(argv[i], "--no-user-cancel-any")) | |
96 | num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY, "0", | |
97 | num_settings, &settings); | |
98 | else | |
99 | usage(argv[i]); | |
100 | } | |
101 | else | |
102 | { | |
103 | for (opt = argv[i] + 1; *opt; opt ++) | |
104 | switch (*opt) | |
105 | { | |
106 | case 'E' : | |
107 | cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); | |
108 | break; | |
109 | ||
110 | case 'U' : | |
111 | i ++; | |
112 | if (i >= argc) | |
113 | usage(NULL); | |
114 | ||
115 | cupsSetUser(argv[i]); | |
116 | break; | |
117 | ||
118 | case 'h' : | |
119 | i ++; | |
120 | if (i >= argc) | |
121 | usage(NULL); | |
122 | ||
123 | cupsSetServer(argv[i]); | |
124 | break; | |
125 | ||
126 | default : | |
127 | usage(opt); | |
128 | break; | |
129 | } | |
130 | } | |
131 | } | |
132 | else if (strchr(argv[i], '=')) | |
133 | num_settings = cupsParseOptions(argv[i], num_settings, &settings); | |
134 | else | |
135 | usage(argv[i]); | |
136 | } | |
137 | ||
0268488e MS |
138 | if (cupsGetOption("Listen", num_settings, settings) || |
139 | cupsGetOption("Port", num_settings, settings)) | |
140 | { | |
82f97232 | 141 | _cupsLangPuts(stderr, _("cupsctl: Cannot set Listen or Port directly.")); |
0268488e MS |
142 | return (1); |
143 | } | |
144 | ||
bc44d920 | 145 | /* |
146 | * Connect to the server using the defaults... | |
147 | */ | |
148 | ||
db0bd74a MS |
149 | if ((http = httpConnectEncrypt(cupsServer(), ippPort(), |
150 | cupsEncryption())) == NULL) | |
151 | { | |
0837b7e8 | 152 | _cupsLangPrintf(stderr, _("cupsctl: Unable to connect to server: %s"), |
db0bd74a MS |
153 | strerror(errno)); |
154 | return (1); | |
155 | } | |
bc44d920 | 156 | |
157 | /* | |
158 | * Set the current configuration if we have anything on the command-line... | |
159 | */ | |
160 | ||
161 | if (num_settings > 0) | |
162 | { | |
163 | if (!cupsAdminSetServerSettings(http, num_settings, settings)) | |
164 | { | |
0837b7e8 | 165 | _cupsLangPrintf(stderr, "cupsctl: %s", cupsLastErrorString()); |
bc44d920 | 166 | return (1); |
167 | } | |
168 | } | |
169 | else if (!cupsAdminGetServerSettings(http, &num_settings, &settings)) | |
170 | { | |
0837b7e8 | 171 | _cupsLangPrintf(stderr, "cupsctl: %s", cupsLastErrorString()); |
bc44d920 | 172 | return (1); |
173 | } | |
174 | else | |
175 | { | |
176 | for (i = 0; i < num_settings; i ++) | |
0837b7e8 | 177 | _cupsLangPrintf(stdout, "%s=%s", settings[i].name, settings[i].value); |
bc44d920 | 178 | } |
179 | ||
180 | cupsFreeOptions(num_settings, settings); | |
181 | return (0); | |
182 | } | |
183 | ||
184 | ||
185 | /* | |
186 | * 'usage()' - Show program usage. | |
187 | */ | |
188 | ||
189 | static void | |
190 | usage(const char *opt) /* I - Option character/string */ | |
191 | { | |
192 | if (opt) | |
193 | { | |
194 | if (*opt == '-') | |
0837b7e8 | 195 | _cupsLangPrintf(stderr, _("cupsctl: Unknown option \"%s\""), opt); |
bc44d920 | 196 | else |
0837b7e8 | 197 | _cupsLangPrintf(stderr, _("cupsctl: Unknown option \"-%c\""), *opt); |
bc44d920 | 198 | } |
199 | ||
0837b7e8 MS |
200 | _cupsLangPuts(stdout, _("Usage: cupsctl [options] [param=value ... " |
201 | "paramN=valueN]")); | |
202 | _cupsLangPuts(stdout, ""); | |
203 | _cupsLangPuts(stdout, _("Options:")); | |
204 | _cupsLangPuts(stdout, ""); | |
f3c17241 | 205 | _cupsLangPuts(stdout, _(" -E Encrypt the connection.")); |
84315f46 MS |
206 | _cupsLangPuts(stdout, _(" -U username Specify username.")); |
207 | _cupsLangPuts(stdout, _(" -h server[:port] Specify server " | |
0837b7e8 MS |
208 | "address.")); |
209 | _cupsLangPuts(stdout, ""); | |
84315f46 | 210 | _cupsLangPuts(stdout, _(" --[no-]debug-logging Turn debug logging " |
0837b7e8 | 211 | "on/off.")); |
84315f46 | 212 | _cupsLangPuts(stdout, _(" --[no-]remote-admin Turn remote " |
0837b7e8 | 213 | "administration on/off.")); |
84315f46 | 214 | _cupsLangPuts(stdout, _(" --[no-]remote-any Allow/prevent access " |
0837b7e8 | 215 | "from the Internet.")); |
84315f46 | 216 | _cupsLangPuts(stdout, _(" --[no-]share-printers Turn printer sharing " |
0837b7e8 | 217 | "on/off.")); |
84315f46 | 218 | _cupsLangPuts(stdout, _(" --[no-]user-cancel-any Allow/prevent users to " |
0837b7e8 | 219 | "cancel any job.")); |
bc44d920 | 220 | |
221 | exit(1); | |
222 | } | |
223 | ||
224 | ||
225 | /* | |
1f0275e3 | 226 | * End of "$Id$". |
bc44d920 | 227 | */ |