]> git.ipfire.org Git - thirdparty/cups.git/blame - systemv/cupsctl.c
More localization work.
[thirdparty/cups.git] / systemv / cupsctl.c
CommitLineData
a5de518c 1/*
c97b7208 2 * "$Id$"
a5de518c 3 *
3d94661a 4 * Scheduler control program for CUPS.
a5de518c 5 *
3d94661a 6 * Copyright 2007-2010 by Apple Inc.
a5de518c 7 * Copyright 2006-2007 by Easy Software Products.
8 *
9 * These coded instructions, statements, and computer programs are the
4e8d321f 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/".
a5de518c 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
3d94661a 27#include <cups/cups-private.h>
a5de518c 28#include <cups/adminutil.h>
a5de518c 29
30
31/*
32 * Local functions...
33 */
34
35static void usage(const char *opt);
36
37
38/*
39 * 'main()' - Get/set server settings.
40 */
41
42int /* O - Exit status */
43main(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 {
8e25418b 68 if (!strcmp(argv[i], "--debug-logging"))
a5de518c 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);
86 else if (!strcmp(argv[i], "--remote-printers"))
87 num_settings = cupsAddOption(CUPS_SERVER_REMOTE_PRINTERS, "1",
88 num_settings, &settings);
89 else if (!strcmp(argv[i], "--no-remote-printers"))
90 num_settings = cupsAddOption(CUPS_SERVER_REMOTE_PRINTERS, "0",
91 num_settings, &settings);
92 else if (!strcmp(argv[i], "--share-printers"))
93 num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS, "1",
94 num_settings, &settings);
95 else if (!strcmp(argv[i], "--no-share-printers"))
96 num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS, "0",
97 num_settings, &settings);
98 else if (!strcmp(argv[i], "--user-cancel-any"))
99 num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY, "1",
100 num_settings, &settings);
101 else if (!strcmp(argv[i], "--no-user-cancel-any"))
102 num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY, "0",
103 num_settings, &settings);
104 else
105 usage(argv[i]);
106 }
107 else
108 {
109 for (opt = argv[i] + 1; *opt; opt ++)
110 switch (*opt)
111 {
112 case 'E' :
113 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
114 break;
115
116 case 'U' :
117 i ++;
118 if (i >= argc)
119 usage(NULL);
120
121 cupsSetUser(argv[i]);
122 break;
123
124 case 'h' :
125 i ++;
126 if (i >= argc)
127 usage(NULL);
128
129 cupsSetServer(argv[i]);
130 break;
131
132 default :
133 usage(opt);
134 break;
135 }
136 }
137 }
138 else if (strchr(argv[i], '='))
139 num_settings = cupsParseOptions(argv[i], num_settings, &settings);
140 else
141 usage(argv[i]);
142 }
143
144 /*
145 * Connect to the server using the defaults...
146 */
147
9bd1efb0 148 if ((http = httpConnectEncrypt(cupsServer(), ippPort(),
149 cupsEncryption())) == NULL)
150 {
4c4eea89 151 _cupsLangPrintf(stderr, _("cupsctl: Unable to connect to server: %s"),
9bd1efb0 152 strerror(errno));
153 return (1);
154 }
a5de518c 155
156 /*
157 * Set the current configuration if we have anything on the command-line...
158 */
159
160 if (num_settings > 0)
161 {
162 if (!cupsAdminSetServerSettings(http, num_settings, settings))
163 {
4c4eea89 164 _cupsLangPrintf(stderr, "cupsctl: %s", cupsLastErrorString());
a5de518c 165 return (1);
166 }
167 }
168 else if (!cupsAdminGetServerSettings(http, &num_settings, &settings))
169 {
4c4eea89 170 _cupsLangPrintf(stderr, "cupsctl: %s", cupsLastErrorString());
a5de518c 171 return (1);
172 }
173 else
174 {
175 for (i = 0; i < num_settings; i ++)
4c4eea89 176 _cupsLangPrintf(stdout, "%s=%s", settings[i].name, settings[i].value);
a5de518c 177 }
178
179 cupsFreeOptions(num_settings, settings);
180 return (0);
181}
182
183
184/*
185 * 'usage()' - Show program usage.
186 */
187
188static void
189usage(const char *opt) /* I - Option character/string */
190{
191 if (opt)
192 {
193 if (*opt == '-')
4c4eea89 194 _cupsLangPrintf(stderr, _("cupsctl: Unknown option \"%s\""), opt);
a5de518c 195 else
4c4eea89 196 _cupsLangPrintf(stderr, _("cupsctl: Unknown option \"-%c\""), *opt);
a5de518c 197 }
198
4c4eea89 199 _cupsLangPuts(stdout, _("Usage: cupsctl [options] [param=value ... "
200 "paramN=valueN]"));
201 _cupsLangPuts(stdout, "");
202 _cupsLangPuts(stdout, _("Options:"));
203 _cupsLangPuts(stdout, "");
204 _cupsLangPuts(stdout, _(" -E Enable encryption."));
205 _cupsLangPuts(stdout, _(" -U username Specify username."));
206 _cupsLangPuts(stdout, _(" -h server[:port] Specify server "
207 "address."));
208 _cupsLangPuts(stdout, "");
209 _cupsLangPuts(stdout, _(" --[no-]debug-logging Turn debug logging "
210 "on/off."));
211 _cupsLangPuts(stdout, _(" --[no-]remote-admin Turn remote "
212 "administration on/off."));
213 _cupsLangPuts(stdout, _(" --[no-]remote-any Allow/prevent access "
214 "from the Internet."));
215 _cupsLangPuts(stdout, _(" --[no-]remote-printers Show/hide remote "
216 "printers."));
217 _cupsLangPuts(stdout, _(" --[no-]share-printers Turn printer sharing "
218 "on/off."));
219 _cupsLangPuts(stdout, _(" --[no-]user-cancel-any Allow/prevent users to "
220 "cancel any job."));
a5de518c 221
222 exit(1);
223}
224
225
226/*
c97b7208 227 * End of "$Id$".
a5de518c 228 */