Imported Upstream version 2.3.1
[platform/upstream/cups.git] / cups / testadmin.c
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  * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
8  */
9
10 /*
11  * Include necessary headers...
12  */
13
14 #include "adminutil.h"
15 #include "string-private.h"
16
17
18 /*
19  * Local functions...
20  */
21
22 static void     show_settings(int num_settings, cups_option_t *settings);
23
24
25 /*
26  * 'main()' - Main entry.
27  */
28
29 int                                     /* O - Exit status */
30 main(int  argc,                         /* I - Number of command-line args */
31      char *argv[])                      /* I - Command-line arguments */
32 {
33   int           i,                      /* Looping var */
34                 num_settings;           /* Number of settings */
35   cups_option_t *settings;              /* Settings */
36   http_t        *http;                  /* Connection to server */
37
38
39  /*
40   * Connect to the server using the defaults...
41   */
42
43   http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC,
44                       cupsEncryption(), 1, 30000, NULL);
45
46  /*
47   * Set the current configuration if we have anything on the command-line...
48   */
49
50   if (argc > 1)
51   {
52     for (i = 1, num_settings = 0, settings = NULL; i < argc; i ++)
53       num_settings = cupsParseOptions(argv[i], num_settings, &settings);
54
55     if (cupsAdminSetServerSettings(http, num_settings, settings))
56     {
57       puts("New server settings:");
58       cupsFreeOptions(num_settings, settings);
59     }
60     else
61     {
62       printf("Server settings not changed: %s\n", cupsLastErrorString());
63       return (1);
64     }
65   }
66   else
67     puts("Current server settings:");
68
69  /*
70   * Get the current configuration...
71   */
72
73   if (cupsAdminGetServerSettings(http, &num_settings, &settings))
74   {
75     show_settings(num_settings, settings);
76     cupsFreeOptions(num_settings, settings);
77     return (0);
78   }
79   else
80   {
81     printf("    %s\n", cupsLastErrorString());
82     return (1);
83   }
84 }
85
86
87 /*
88  * 'show_settings()' - Show settings in the array...
89  */
90
91 static void
92 show_settings(
93     int           num_settings,         /* I - Number of settings */
94     cups_option_t *settings)            /* I - Settings */
95 {
96   while (num_settings > 0)
97   {
98     printf("    %s=%s\n", settings->name, settings->value);
99
100     settings ++;
101     num_settings --;
102   }
103 }