]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/backend.c
Remove all of the Subversion keywords from various source files.
[thirdparty/cups.git] / cups / backend.c
CommitLineData
a4d04587 1/*
f787e1e3 2 * Backend functions for CUPS.
a4d04587 3 *
f787e1e3
MS
4 * Copyright 2007-2015 by Apple Inc.
5 * Copyright 2006 by Easy Software Products.
a4d04587 6 *
f787e1e3
MS
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * file is missing or damaged, see the license at "http://www.cups.org/".
a4d04587 12 *
f787e1e3 13 * This file is subject to the Apple OS-Developed Software exception.
a4d04587 14 */
15
16/*
17 * Include necessary headers...
18 */
19
71e16022 20#include "cups-private.h"
a4d04587 21#include "backend.h"
f787e1e3 22#include "ppd.h"
a4d04587 23
24
749b1e90
MS
25/*
26 * Local functions...
27 */
28
29static void quote_string(const char *s);
30
31
a4d04587 32/*
33 * 'cupsBackendDeviceURI()' - Get the device URI for a backend.
34 *
35 * The "argv" argument is the argv argument passed to main(). This
36 * function returns the device URI passed in the DEVICE_URI environment
37 * variable or the device URI passed in argv[0], whichever is found
38 * first.
426c6a59 39 *
f3c17241 40 * @since CUPS 1.2/OS X 10.5@
a4d04587 41 */
42
ac884b6a 43const char * /* O - Device URI or @code NULL@ */
a4d04587 44cupsBackendDeviceURI(char **argv) /* I - Command-line arguments */
45{
eac3a0a0
MS
46 const char *device_uri, /* Device URI */
47 *auth_info_required; /* AUTH_INFO_REQUIRED env var */
5eb9da71 48 _cups_globals_t *cg = _cupsGlobals(); /* Global info */
eac3a0a0 49 int options; /* Resolve options */
f3c17241
MS
50 ppd_file_t *ppd; /* PPD file */
51 ppd_attr_t *ppdattr; /* PPD attribute */
a4d04587 52
53
5eb9da71
MS
54 if ((device_uri = getenv("DEVICE_URI")) == NULL)
55 {
56 if (!argv || !argv[0] || !strchr(argv[0], ':'))
57 return (NULL);
a4d04587 58
5eb9da71
MS
59 device_uri = argv[0];
60 }
61
eac3a0a0
MS
62 options = _HTTP_RESOLVE_STDERR;
63 if ((auth_info_required = getenv("AUTH_INFO_REQUIRED")) != NULL &&
64 !strcmp(auth_info_required, "negotiate"))
65 options |= _HTTP_RESOLVE_FQDN;
66
f3c17241
MS
67 if ((ppd = ppdOpenFile(getenv("PPD"))) != NULL)
68 {
69 if ((ppdattr = ppdFindAttr(ppd, "cupsIPPFaxOut", NULL)) != NULL &&
70 !_cups_strcasecmp(ppdattr->value, "true"))
71 options |= _HTTP_RESOLVE_FAXOUT;
72
73 ppdClose(ppd);
74 }
75
5eb9da71 76 return (_httpResolveURI(device_uri, cg->resolved_uri,
eac3a0a0 77 sizeof(cg->resolved_uri), options, NULL, NULL));
a4d04587 78}
79
80
81/*
749b1e90
MS
82 * 'cupsBackendReport()' - Write a device line from a backend.
83 *
84 * This function writes a single device line to stdout for a backend.
85 * It handles quoting of special characters in the device-make-and-model,
86 * device-info, device-id, and device-location strings.
426c6a59 87 *
f3c17241 88 * @since CUPS 1.4/OS X 10.6@
749b1e90
MS
89 */
90
91void
92cupsBackendReport(
93 const char *device_scheme, /* I - device-scheme string */
94 const char *device_uri, /* I - device-uri string */
95 const char *device_make_and_model, /* I - device-make-and-model string or @code NULL@ */
96 const char *device_info, /* I - device-info string or @code NULL@ */
97 const char *device_id, /* I - device-id string or @code NULL@ */
98 const char *device_location) /* I - device-location string or @code NULL@ */
99{
100 if (!device_scheme || !device_uri)
101 return;
102
103 printf("%s %s", device_scheme, device_uri);
104 if (device_make_and_model && *device_make_and_model)
105 quote_string(device_make_and_model);
106 else
107 quote_string("unknown");
108 quote_string(device_info);
109 quote_string(device_id);
110 quote_string(device_location);
111 putchar('\n');
112 fflush(stdout);
113}
114
115
116/*
117 * 'quote_string()' - Write a quoted string to stdout, escaping \ and ".
118 */
119
120static void
121quote_string(const char *s) /* I - String to write */
122{
123 fputs(" \"", stdout);
124
125 if (s)
126 {
127 while (*s)
128 {
129 if (*s == '\\' || *s == '\"')
130 putchar('\\');
131
5a9febac 132 if (((*s & 255) < ' ' && *s != '\t') || *s == 0x7f)
12f89d24
MS
133 putchar(' ');
134 else
135 putchar(*s);
749b1e90
MS
136
137 s ++;
138 }
139 }
140
141 putchar('\"');
142}