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