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