]>
Commit | Line | Data |
---|---|---|
a4d04587 | 1 | /* |
f2d18633 | 2 | * "$Id$" |
a4d04587 | 3 | * |
71e16022 | 4 | * Backend functions for CUPS. |
a4d04587 | 5 | * |
12f89d24 | 6 | * Copyright 2007-2012 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 | ||
36 | static 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 | 46 | * |
f3c17241 | 47 | * @since CUPS 1.2/OS X 10.5@ |
a4d04587 | 48 | */ |
49 | ||
ac884b6a | 50 | const char * /* O - Device URI or @code NULL@ */ |
a4d04587 | 51 | cupsBackendDeviceURI(char **argv) /* I - Command-line arguments */ |
52 | { | |
eac3a0a0 MS |
53 | const char *device_uri, /* Device URI */ |
54 | *auth_info_required; /* AUTH_INFO_REQUIRED env var */ | |
5eb9da71 | 55 | _cups_globals_t *cg = _cupsGlobals(); /* Global info */ |
eac3a0a0 | 56 | int options; /* Resolve options */ |
f3c17241 MS |
57 | ppd_file_t *ppd; /* PPD file */ |
58 | ppd_attr_t *ppdattr; /* PPD attribute */ | |
a4d04587 | 59 | |
60 | ||
5eb9da71 MS |
61 | if ((device_uri = getenv("DEVICE_URI")) == NULL) |
62 | { | |
63 | if (!argv || !argv[0] || !strchr(argv[0], ':')) | |
64 | return (NULL); | |
a4d04587 | 65 | |
5eb9da71 MS |
66 | device_uri = argv[0]; |
67 | } | |
68 | ||
eac3a0a0 MS |
69 | options = _HTTP_RESOLVE_STDERR; |
70 | if ((auth_info_required = getenv("AUTH_INFO_REQUIRED")) != NULL && | |
71 | !strcmp(auth_info_required, "negotiate")) | |
72 | options |= _HTTP_RESOLVE_FQDN; | |
73 | ||
f3c17241 MS |
74 | if ((ppd = ppdOpenFile(getenv("PPD"))) != NULL) |
75 | { | |
76 | if ((ppdattr = ppdFindAttr(ppd, "cupsIPPFaxOut", NULL)) != NULL && | |
77 | !_cups_strcasecmp(ppdattr->value, "true")) | |
78 | options |= _HTTP_RESOLVE_FAXOUT; | |
79 | ||
80 | ppdClose(ppd); | |
81 | } | |
82 | ||
5eb9da71 | 83 | return (_httpResolveURI(device_uri, cg->resolved_uri, |
eac3a0a0 | 84 | sizeof(cg->resolved_uri), options, NULL, NULL)); |
a4d04587 | 85 | } |
86 | ||
87 | ||
88 | /* | |
749b1e90 MS |
89 | * 'cupsBackendReport()' - Write a device line from a backend. |
90 | * | |
91 | * This function writes a single device line to stdout for a backend. | |
92 | * It handles quoting of special characters in the device-make-and-model, | |
93 | * device-info, device-id, and device-location strings. | |
426c6a59 | 94 | * |
f3c17241 | 95 | * @since CUPS 1.4/OS X 10.6@ |
749b1e90 MS |
96 | */ |
97 | ||
98 | void | |
99 | cupsBackendReport( | |
100 | const char *device_scheme, /* I - device-scheme string */ | |
101 | const char *device_uri, /* I - device-uri string */ | |
102 | const char *device_make_and_model, /* I - device-make-and-model string or @code NULL@ */ | |
103 | const char *device_info, /* I - device-info string or @code NULL@ */ | |
104 | const char *device_id, /* I - device-id string or @code NULL@ */ | |
105 | const char *device_location) /* I - device-location string or @code NULL@ */ | |
106 | { | |
107 | if (!device_scheme || !device_uri) | |
108 | return; | |
109 | ||
110 | printf("%s %s", device_scheme, device_uri); | |
111 | if (device_make_and_model && *device_make_and_model) | |
112 | quote_string(device_make_and_model); | |
113 | else | |
114 | quote_string("unknown"); | |
115 | quote_string(device_info); | |
116 | quote_string(device_id); | |
117 | quote_string(device_location); | |
118 | putchar('\n'); | |
119 | fflush(stdout); | |
120 | } | |
121 | ||
122 | ||
123 | /* | |
124 | * 'quote_string()' - Write a quoted string to stdout, escaping \ and ". | |
125 | */ | |
126 | ||
127 | static void | |
128 | quote_string(const char *s) /* I - String to write */ | |
129 | { | |
130 | fputs(" \"", stdout); | |
131 | ||
132 | if (s) | |
133 | { | |
134 | while (*s) | |
135 | { | |
136 | if (*s == '\\' || *s == '\"') | |
137 | putchar('\\'); | |
138 | ||
5a9febac | 139 | if (((*s & 255) < ' ' && *s != '\t') || *s == 0x7f) |
12f89d24 MS |
140 | putchar(' '); |
141 | else | |
142 | putchar(*s); | |
749b1e90 MS |
143 | |
144 | s ++; | |
145 | } | |
146 | } | |
147 | ||
148 | putchar('\"'); | |
149 | } | |
150 | ||
151 | ||
152 | /* | |
f2d18633 | 153 | * End of "$Id$". |
a4d04587 | 154 | */ |