]> git.ipfire.org Git - thirdparty/cups.git/blob - cgi-bin/testtemplate.c
Sandboxed applications were not able to get the default printer (Issue #5676)
[thirdparty/cups.git] / cgi-bin / testtemplate.c
1 /*
2 * CGI template test program for CUPS.
3 *
4 * Copyright 2007-2011 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 "cgi.h"
15
16
17 /*
18 * 'main()' - Test the template code.
19 */
20
21 int /* O - Exit status */
22 main(int argc, /* I - Number of command-line arguments */
23 char *argv[]) /* I - Command-line arguments */
24 {
25 int i; /* Looping var */
26 char *value; /* Value in name=value */
27 FILE *out; /* Where to send output */
28
29
30 /*
31 * Don't buffer stdout or stderr so that the mixed output is sane...
32 */
33
34 setbuf(stdout, NULL);
35 setbuf(stderr, NULL);
36
37 /*
38 * Loop through the command-line, assigning variables for any args with
39 * "name=value"...
40 */
41
42 out = stdout;
43
44 for (i = 1; i < argc; i ++)
45 {
46 if (!strcmp(argv[i], "-o"))
47 {
48 i ++;
49 if (i < argc)
50 {
51 out = fopen(argv[i], "w");
52 if (!out)
53 {
54 perror(argv[i]);
55 return (1);
56 }
57 }
58 }
59 else if (!strcmp(argv[i], "-e"))
60 {
61 i ++;
62
63 if (i < argc)
64 {
65 if (!freopen(argv[i], "w", stderr))
66 {
67 perror(argv[i]);
68 return (1);
69 }
70 }
71 }
72 else if (!strcmp(argv[i], "-q"))
73 freopen("/dev/null", "w", stderr);
74 else if ((value = strchr(argv[i], '=')) != NULL)
75 {
76 *value++ = '\0';
77 cgiSetVariable(argv[i], value);
78 }
79 else
80 cgiCopyTemplateFile(out, argv[i]);
81 }
82
83 /*
84 * Return with no errors...
85 */
86
87 return (0);
88 }