]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/testadmin.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / testadmin.c
1 /*
2 * "$Id: testadmin.c 6649 2007-07-11 21:46:42Z mike $"
3 *
4 * Admin function test program for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 2007 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.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 = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
57
58 /*
59 * Set the current configuration if we have anything on the command-line...
60 */
61
62 if (argc > 1)
63 {
64 for (i = 1, num_settings = 0; i < argc; i ++)
65 num_settings = cupsParseOptions(argv[i], num_settings, &settings);
66
67 if (cupsAdminSetServerSettings(http, num_settings, settings))
68 {
69 puts("New server settings:");
70 cupsFreeOptions(num_settings, settings);
71 }
72 else
73 {
74 printf("Server settings not changed: %s\n", cupsLastErrorString());
75 return (1);
76 }
77 }
78 else
79 puts("Current server settings:");
80
81 /*
82 * Get the current configuration...
83 */
84
85 if (cupsAdminGetServerSettings(http, &num_settings, &settings))
86 {
87 show_settings(num_settings, settings);
88 cupsFreeOptions(num_settings, settings);
89 return (0);
90 }
91 else
92 {
93 printf(" %s\n", cupsLastErrorString());
94 return (1);
95 }
96 }
97
98
99 /*
100 * 'show_settings()' - Show settings in the array...
101 */
102
103 static void
104 show_settings(
105 int num_settings, /* I - Number of settings */
106 cups_option_t *settings) /* I - Settings */
107 {
108 while (num_settings > 0)
109 {
110 printf(" %s=%s\n", settings->name, settings->value);
111
112 settings ++;
113 num_settings --;
114 }
115 }
116
117
118 /*
119 * End of "$Id: testadmin.c 6649 2007-07-11 21:46:42Z mike $".
120 */