]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/testadmin.c
28dafa7f263fe4235ececdecabdfec085a718921
[thirdparty/cups.git] / cups / testadmin.c
1 /*
2 * "$Id$"
3 *
4 * Admin function test program for CUPS.
5 *
6 * Copyright 2007-2013 by Apple Inc.
7 * Copyright 2006 by Easy Software Products.
8 *
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/".
14 *
15 * This file is subject to the Apple OS-Developed Software exception.
16 *
17 * Contents:
18 *
19 * main() - Main entry.
20 * show_settings() - Show settings in the array...
21 */
22
23 /*
24 * Include necessary headers...
25 */
26
27 #include "adminutil.h"
28 #include "string-private.h"
29
30
31 /*
32 * Local functions...
33 */
34
35 static void show_settings(int num_settings, cups_option_t *settings);
36
37
38 /*
39 * 'main()' - Main entry.
40 */
41
42 int /* O - Exit status */
43 main(int argc, /* I - Number of command-line args */
44 char *argv[]) /* I - Command-line arguments */
45 {
46 int i, /* Looping var */
47 num_settings; /* Number of settings */
48 cups_option_t *settings; /* Settings */
49 http_t *http; /* Connection to server */
50
51
52 /*
53 * Connect to the server using the defaults...
54 */
55
56 http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC,
57 cupsEncryption(), 1, 30000, NULL);
58
59 /*
60 * Set the current configuration if we have anything on the command-line...
61 */
62
63 if (argc > 1)
64 {
65 for (i = 1, num_settings = 0, settings = NULL; i < argc; i ++)
66 num_settings = cupsParseOptions(argv[i], num_settings, &settings);
67
68 if (cupsAdminSetServerSettings(http, num_settings, settings))
69 {
70 puts("New server settings:");
71 cupsFreeOptions(num_settings, settings);
72 }
73 else
74 {
75 printf("Server settings not changed: %s\n", cupsLastErrorString());
76 return (1);
77 }
78 }
79 else
80 puts("Current server settings:");
81
82 /*
83 * Get the current configuration...
84 */
85
86 if (cupsAdminGetServerSettings(http, &num_settings, &settings))
87 {
88 show_settings(num_settings, settings);
89 cupsFreeOptions(num_settings, settings);
90 return (0);
91 }
92 else
93 {
94 printf(" %s\n", cupsLastErrorString());
95 return (1);
96 }
97 }
98
99
100 /*
101 * 'show_settings()' - Show settings in the array...
102 */
103
104 static void
105 show_settings(
106 int num_settings, /* I - Number of settings */
107 cups_option_t *settings) /* I - Settings */
108 {
109 while (num_settings > 0)
110 {
111 printf(" %s=%s\n", settings->name, settings->value);
112
113 settings ++;
114 num_settings --;
115 }
116 }
117
118
119 /*
120 * End of "$Id$".
121 */