]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/backend.c
Merge changes from CUPS 1.5svn-r9763.
[thirdparty/cups.git] / cups / backend.c
1 /*
2 * "$Id: backend.c 7810 2008-07-29 01:11:15Z mike $"
3 *
4 * Backend functions for CUPS.
5 *
6 * Copyright 2007-2010 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 * cupsBackendDeviceURI() - Get the device URI for a backend.
20 * cupsBackendReport() - Write a device line from a backend.
21 * quote_string() - Write a quoted string to stdout, escaping \ and ".
22 */
23
24 /*
25 * Include necessary headers...
26 */
27
28 #include "cups-private.h"
29 #include "backend.h"
30
31
32 /*
33 * Local functions...
34 */
35
36 static void quote_string(const char *s);
37
38
39 /*
40 * 'cupsBackendDeviceURI()' - Get the device URI for a backend.
41 *
42 * The "argv" argument is the argv argument passed to main(). This
43 * function returns the device URI passed in the DEVICE_URI environment
44 * variable or the device URI passed in argv[0], whichever is found
45 * first.
46 *
47 * @since CUPS 1.2/Mac OS X 10.5@
48 */
49
50 const char * /* O - Device URI or @code NULL@ */
51 cupsBackendDeviceURI(char **argv) /* I - Command-line arguments */
52 {
53 const char *device_uri, /* Device URI */
54 *auth_info_required; /* AUTH_INFO_REQUIRED env var */
55 _cups_globals_t *cg = _cupsGlobals(); /* Global info */
56 int options; /* Resolve options */
57
58
59 if ((device_uri = getenv("DEVICE_URI")) == NULL)
60 {
61 if (!argv || !argv[0] || !strchr(argv[0], ':'))
62 return (NULL);
63
64 device_uri = argv[0];
65 }
66
67 options = _HTTP_RESOLVE_STDERR;
68 if ((auth_info_required = getenv("AUTH_INFO_REQUIRED")) != NULL &&
69 !strcmp(auth_info_required, "negotiate"))
70 options |= _HTTP_RESOLVE_FQDN;
71
72 return (_httpResolveURI(device_uri, cg->resolved_uri,
73 sizeof(cg->resolved_uri), options, NULL, NULL));
74 }
75
76
77 /*
78 * 'cupsBackendReport()' - Write a device line from a backend.
79 *
80 * This function writes a single device line to stdout for a backend.
81 * It handles quoting of special characters in the device-make-and-model,
82 * device-info, device-id, and device-location strings.
83 *
84 * @since CUPS 1.4/Mac OS X 10.6@
85 */
86
87 void
88 cupsBackendReport(
89 const char *device_scheme, /* I - device-scheme string */
90 const char *device_uri, /* I - device-uri string */
91 const char *device_make_and_model, /* I - device-make-and-model string or @code NULL@ */
92 const char *device_info, /* I - device-info string or @code NULL@ */
93 const char *device_id, /* I - device-id string or @code NULL@ */
94 const char *device_location) /* I - device-location string or @code NULL@ */
95 {
96 if (!device_scheme || !device_uri)
97 return;
98
99 printf("%s %s", device_scheme, device_uri);
100 if (device_make_and_model && *device_make_and_model)
101 quote_string(device_make_and_model);
102 else
103 quote_string("unknown");
104 quote_string(device_info);
105 quote_string(device_id);
106 quote_string(device_location);
107 putchar('\n');
108 fflush(stdout);
109 }
110
111
112 /*
113 * 'quote_string()' - Write a quoted string to stdout, escaping \ and ".
114 */
115
116 static void
117 quote_string(const char *s) /* I - String to write */
118 {
119 fputs(" \"", stdout);
120
121 if (s)
122 {
123 while (*s)
124 {
125 if (*s == '\\' || *s == '\"')
126 putchar('\\');
127
128 putchar(*s);
129
130 s ++;
131 }
132 }
133
134 putchar('\"');
135 }
136
137
138 /*
139 * End of "$Id: backend.c 7810 2008-07-29 01:11:15Z mike $".
140 */