4 * CUPS control program for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 2006-2007 by Easy Software Products.
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/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * main() - Get/set server settings.
20 * usage() - Show program usage.
24 * Include necessary headers...
27 #include <cups/adminutil.h>
28 #include <cups/string.h>
29 #include <cups/i18n.h>
37 static void usage(const char *opt
);
41 * 'main()' - Get/set server settings.
44 int /* O - Exit status */
45 main(int argc
, /* I - Number of command-line args */
46 char *argv
[]) /* I - Command-line arguments */
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 */
56 * Process the command-line...
64 for (i
= 1; i
< argc
; i
++)
66 if (argv
[i
][0] == '-')
68 if (argv
[i
][1] == '-')
70 if (!strcmp(argv
[i
], "--debug-logging"))
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
);
111 for (opt
= argv
[i
] + 1; *opt
; opt
++)
115 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
123 cupsSetUser(argv
[i
]);
131 cupsSetServer(argv
[i
]);
140 else if (strchr(argv
[i
], '='))
141 num_settings
= cupsParseOptions(argv
[i
], num_settings
, &settings
);
147 * Connect to the server using the defaults...
150 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
151 cupsEncryption())) == NULL
)
153 _cupsLangPrintf(stderr
, _("cupsctl: Unable to connect to server: %s\n"),
159 * Set the current configuration if we have anything on the command-line...
162 if (num_settings
> 0)
164 if (!cupsAdminSetServerSettings(http
, num_settings
, settings
))
166 _cupsLangPrintf(stderr
, "cupsctl: %s\n", cupsLastErrorString());
170 else if (!cupsAdminGetServerSettings(http
, &num_settings
, &settings
))
172 _cupsLangPrintf(stderr
, "cupsctl: %s\n", cupsLastErrorString());
177 for (i
= 0; i
< num_settings
; i
++)
178 _cupsLangPrintf(stdout
, "%s=%s\n", settings
[i
].name
, settings
[i
].value
);
181 cupsFreeOptions(num_settings
, settings
);
187 * 'usage()' - Show program usage.
191 usage(const char *opt
) /* I - Option character/string */
196 _cupsLangPrintf(stderr
, _("cupsctl: Unknown option \"%s\"!\n"), opt
);
198 _cupsLangPrintf(stderr
, _("cupsctl: Unknown option \"-%c\"!\n"), *opt
);
201 _cupsLangPuts(stdout
,
202 _("Usage: cupsctl [options] [param=value ... paramN=valueN]\n"
206 " -E Enable encryption\n"
207 " -U username Specify username\n"
208 " -h server[:port] Specify server address\n"
210 " --[no-]debug-logging Turn debug logging on/off\n"
211 " --[no-]remote-admin Turn remote administration "
213 " --[no-]remote-any Allow/prevent access from the "
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 "