2 * "$Id: cupsctl.c 6379 2007-03-21 14:57:22Z mike $"
4 * CUPS control program for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 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>
36 static void usage(const char *opt
);
40 * 'main()' - Get/set server settings.
43 int /* O - Exit status */
44 main(int argc
, /* I - Number of command-line args */
45 char *argv
[]) /* I - Command-line arguments */
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 */
55 * Process the command-line...
63 for (i
= 1; i
< argc
; i
++)
65 if (argv
[i
][0] == '-')
67 if (argv
[i
][1] == '-')
69 if (!strcmp(argv
[i
], "--debug-logging"))
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
);
110 for (opt
= argv
[i
] + 1; *opt
; opt
++)
114 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
122 cupsSetUser(argv
[i
]);
130 cupsSetServer(argv
[i
]);
139 else if (strchr(argv
[i
], '='))
140 num_settings
= cupsParseOptions(argv
[i
], num_settings
, &settings
);
146 * Connect to the server using the defaults...
149 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
152 * Set the current configuration if we have anything on the command-line...
155 if (num_settings
> 0)
157 if (!cupsAdminSetServerSettings(http
, num_settings
, settings
))
159 _cupsLangPrintf(stderr
, "cupsctl: %s\n", cupsLastErrorString());
163 else if (!cupsAdminGetServerSettings(http
, &num_settings
, &settings
))
165 _cupsLangPrintf(stderr
, "cupsctl: %s\n", cupsLastErrorString());
170 for (i
= 0; i
< num_settings
; i
++)
171 _cupsLangPrintf(stdout
, "%s=%s\n", settings
[i
].name
, settings
[i
].value
);
174 cupsFreeOptions(num_settings
, settings
);
180 * 'usage()' - Show program usage.
184 usage(const char *opt
) /* I - Option character/string */
189 _cupsLangPrintf(stderr
, _("cupsctl: Unknown option \"%s\"!\n"), opt
);
191 _cupsLangPrintf(stderr
, _("cupsctl: Unknown option \"-%c\"!\n"), *opt
);
194 _cupsLangPuts(stdout
,
195 _("Usage: cupsctl [options] [param=value ... paramN=valueN]\n"
199 " -E Enable encryption\n"
200 " -U username Specify username\n"
201 " -h server[:port] Specify server address\n"
203 " --[no-]debug-logging Turn debug logging on/off\n"
204 " --[no-]remote-admin Turn remote administration "
206 " --[no-]remote-any Allow/prevent access from the "
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 "
218 * End of "$Id: cupsctl.c 6379 2007-03-21 14:57:22Z mike $".