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