]>
Commit | Line | Data |
---|---|---|
a4d04587 | 1 | /* |
749b1e90 | 2 | * "$Id: backend.c 7810 2008-07-29 01:11:15Z mike $" |
a4d04587 | 3 | * |
4 | * Backend functions for the Common UNIX Printing System (CUPS). | |
5 | * | |
178cb736 | 6 | * Copyright 2007-2009 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 | ||
28 | #include <stdlib.h> | |
29 | #include "backend.h" | |
5eb9da71 | 30 | #include "globals.h" |
a4d04587 | 31 | |
32 | ||
749b1e90 MS |
33 | /* |
34 | * Local functions... | |
35 | */ | |
36 | ||
37 | static void quote_string(const char *s); | |
38 | ||
39 | ||
a4d04587 | 40 | /* |
41 | * 'cupsBackendDeviceURI()' - Get the device URI for a backend. | |
42 | * | |
43 | * The "argv" argument is the argv argument passed to main(). This | |
44 | * function returns the device URI passed in the DEVICE_URI environment | |
45 | * variable or the device URI passed in argv[0], whichever is found | |
46 | * first. | |
426c6a59 MS |
47 | * |
48 | * @since CUPS 1.2/Mac OS X 10.5@ | |
a4d04587 | 49 | */ |
50 | ||
ac884b6a | 51 | const char * /* O - Device URI or @code NULL@ */ |
a4d04587 | 52 | cupsBackendDeviceURI(char **argv) /* I - Command-line arguments */ |
53 | { | |
54 | const char *device_uri; /* Device URI */ | |
5eb9da71 | 55 | _cups_globals_t *cg = _cupsGlobals(); /* Global info */ |
a4d04587 | 56 | |
57 | ||
5eb9da71 MS |
58 | if ((device_uri = getenv("DEVICE_URI")) == NULL) |
59 | { | |
60 | if (!argv || !argv[0] || !strchr(argv[0], ':')) | |
61 | return (NULL); | |
a4d04587 | 62 | |
5eb9da71 MS |
63 | device_uri = argv[0]; |
64 | } | |
65 | ||
66 | return (_httpResolveURI(device_uri, cg->resolved_uri, | |
1f0275e3 | 67 | sizeof(cg->resolved_uri), 1)); |
a4d04587 | 68 | } |
69 | ||
70 | ||
71 | /* | |
749b1e90 MS |
72 | * 'cupsBackendReport()' - Write a device line from a backend. |
73 | * | |
74 | * This function writes a single device line to stdout for a backend. | |
75 | * It handles quoting of special characters in the device-make-and-model, | |
76 | * device-info, device-id, and device-location strings. | |
426c6a59 | 77 | * |
178cb736 | 78 | * @since CUPS 1.4/Mac OS X 10.6@ |
749b1e90 MS |
79 | */ |
80 | ||
81 | void | |
82 | cupsBackendReport( | |
83 | const char *device_scheme, /* I - device-scheme string */ | |
84 | const char *device_uri, /* I - device-uri string */ | |
85 | const char *device_make_and_model, /* I - device-make-and-model string or @code NULL@ */ | |
86 | const char *device_info, /* I - device-info string or @code NULL@ */ | |
87 | const char *device_id, /* I - device-id string or @code NULL@ */ | |
88 | const char *device_location) /* I - device-location string or @code NULL@ */ | |
89 | { | |
90 | if (!device_scheme || !device_uri) | |
91 | return; | |
92 | ||
93 | printf("%s %s", device_scheme, device_uri); | |
94 | if (device_make_and_model && *device_make_and_model) | |
95 | quote_string(device_make_and_model); | |
96 | else | |
97 | quote_string("unknown"); | |
98 | quote_string(device_info); | |
99 | quote_string(device_id); | |
100 | quote_string(device_location); | |
101 | putchar('\n'); | |
102 | fflush(stdout); | |
103 | } | |
104 | ||
105 | ||
106 | /* | |
107 | * 'quote_string()' - Write a quoted string to stdout, escaping \ and ". | |
108 | */ | |
109 | ||
110 | static void | |
111 | quote_string(const char *s) /* I - String to write */ | |
112 | { | |
113 | fputs(" \"", stdout); | |
114 | ||
115 | if (s) | |
116 | { | |
117 | while (*s) | |
118 | { | |
119 | if (*s == '\\' || *s == '\"') | |
120 | putchar('\\'); | |
121 | ||
122 | putchar(*s); | |
123 | ||
124 | s ++; | |
125 | } | |
126 | } | |
127 | ||
128 | putchar('\"'); | |
129 | } | |
130 | ||
131 | ||
132 | /* | |
133 | * End of "$Id: backend.c 7810 2008-07-29 01:11:15Z mike $". | |
a4d04587 | 134 | */ |