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