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