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