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