1 /*
2 * Admin function test program for CUPS.
3 *
4 * Copyright 2007-2013 by Apple Inc.
5 * Copyright 2006 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 * 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 "adminutil.h"
21 #include "string-private.h"
22
23
24 /*
25 * Local functions...
26 */
27
28 static void show_settings(int num_settings, cups_option_t *settings);
29
30
31 /*
32 * 'main()' - Main entry.
33 */
34
35 int /* O - Exit status */
main(int argc,char * argv[])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 http_t *http; /* Connection to server */
43
44
45 /*
46 * Connect to the server using the defaults...
47 */
48
49 http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC,
50 cupsEncryption(), 1, 30000, NULL);
51
52 /*
53 * Set the current configuration if we have anything on the command-line...
54 */
55
56 if (argc > 1)
57 {
58 for (i = 1, num_settings = 0, settings = NULL; i < argc; i ++)
59 num_settings = cupsParseOptions(argv[i], num_settings, &settings);
60
61 if (cupsAdminSetServerSettings(http, num_settings, settings))
62 {
63 puts("New server settings:");
64 cupsFreeOptions(num_settings, settings);
65 }
66 else
67 {
68 printf("Server settings not changed: %s\n", cupsLastErrorString());
69 return (1);
70 }
71 }
72 else
73 puts("Current server settings:");
74
75 /*
76 * Get the current configuration...
77 */
78
79 if (cupsAdminGetServerSettings(http, &num_settings, &settings))
80 {
81 show_settings(num_settings, settings);
82 cupsFreeOptions(num_settings, settings);
83 return (0);
84 }
85 else
86 {
87 printf(" %s\n", cupsLastErrorString());
88 return (1);
89 }
90 }
91
92
93 /*
94 * 'show_settings()' - Show settings in the array...
95 */
96
97 static void
show_settings(int num_settings,cups_option_t * settings)98 show_settings(
99 int num_settings, /* I - Number of settings */
100 cups_option_t *settings) /* I - Settings */
101 {
102 while (num_settings > 0)
103 {
104 printf(" %s=%s\n", settings->name, settings->value);
105
106 settings ++;
107 num_settings --;
108 }
109 }
110