]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/backend.c
Sync up some other changes.
[thirdparty/cups.git] / cups / backend.c
CommitLineData
a4d04587 1/*
749b1e90 2 * "$Id: backend.c 7810 2008-07-29 01:11:15Z mike $"
a4d04587 3 *
71e16022 4 * Backend functions for CUPS.
a4d04587 5 *
71e16022 6 * Copyright 2007-2010 by Apple Inc.
a4d04587 7 * Copyright 2006 by Easy Software Products.
8 *
9 * These coded instructions, statements, and computer programs are the
bc44d920 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/".
a4d04587 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.
749b1e90
MS
20 * cupsBackendReport() - Write a device line from a backend.
21 * quote_string() - Write a quoted string to stdout, escaping \ and ".
a4d04587 22 */
23
24/*
25 * Include necessary headers...
26 */
27
71e16022 28#include "cups-private.h"
a4d04587 29#include "backend.h"
a4d04587 30
31
749b1e90
MS
32/*
33 * Local functions...
34 */
35
36static void quote_string(const char *s);
37
38
a4d04587 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.
426c6a59
MS
46 *
47 * @since CUPS 1.2/Mac OS X 10.5@
a4d04587 48 */
49
ac884b6a 50const char * /* O - Device URI or @code NULL@ */
a4d04587 51cupsBackendDeviceURI(char **argv) /* I - Command-line arguments */
52{
53 const char *device_uri; /* Device URI */
5eb9da71 54 _cups_globals_t *cg = _cupsGlobals(); /* Global info */
a4d04587 55
56
5eb9da71
MS
57 if ((device_uri = getenv("DEVICE_URI")) == NULL)
58 {
59 if (!argv || !argv[0] || !strchr(argv[0], ':'))
60 return (NULL);
a4d04587 61
5eb9da71
MS
62 device_uri = argv[0];
63 }
64
65 return (_httpResolveURI(device_uri, cg->resolved_uri,
1f0275e3 66 sizeof(cg->resolved_uri), 1));
a4d04587 67}
68
69
70/*
749b1e90
MS
71 * 'cupsBackendReport()' - Write a device line from a backend.
72 *
73 * This function writes a single device line to stdout for a backend.
74 * It handles quoting of special characters in the device-make-and-model,
75 * device-info, device-id, and device-location strings.
426c6a59 76 *
178cb736 77 * @since CUPS 1.4/Mac OS X 10.6@
749b1e90
MS
78 */
79
80void
81cupsBackendReport(
82 const char *device_scheme, /* I - device-scheme string */
83 const char *device_uri, /* I - device-uri string */
84 const char *device_make_and_model, /* I - device-make-and-model string or @code NULL@ */
85 const char *device_info, /* I - device-info string or @code NULL@ */
86 const char *device_id, /* I - device-id string or @code NULL@ */
87 const char *device_location) /* I - device-location string or @code NULL@ */
88{
89 if (!device_scheme || !device_uri)
90 return;
91
92 printf("%s %s", device_scheme, device_uri);
93 if (device_make_and_model && *device_make_and_model)
94 quote_string(device_make_and_model);
95 else
96 quote_string("unknown");
97 quote_string(device_info);
98 quote_string(device_id);
99 quote_string(device_location);
100 putchar('\n');
101 fflush(stdout);
102}
103
104
105/*
106 * 'quote_string()' - Write a quoted string to stdout, escaping \ and ".
107 */
108
109static void
110quote_string(const char *s) /* I - String to write */
111{
112 fputs(" \"", stdout);
113
114 if (s)
115 {
116 while (*s)
117 {
118 if (*s == '\\' || *s == '\"')
119 putchar('\\');
120
121 putchar(*s);
122
123 s ++;
124 }
125 }
126
127 putchar('\"');
128}
129
130
131/*
132 * End of "$Id: backend.c 7810 2008-07-29 01:11:15Z mike $".
a4d04587 133 */