]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/backend.c
a21ee387adff1383dd6ae4cbc8981cde9842b40b
2 * Backend functions for CUPS.
4 * Copyright 2007-2015 by Apple Inc.
5 * Copyright 2006 by Easy Software Products.
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/".
13 * This file is subject to the Apple OS-Developed Software exception.
17 * Include necessary headers...
20 #include "cups-private.h"
29 static void quote_string(const char *s
);
33 * 'cupsBackendDeviceURI()' - Get the device URI for a backend.
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
40 * @since CUPS 1.2/macOS 10.5@
43 const char * /* O - Device URI or @code NULL@ */
44 cupsBackendDeviceURI(char **argv
) /* I - Command-line arguments */
46 const char *device_uri
, /* Device URI */
47 *auth_info_required
; /* AUTH_INFO_REQUIRED env var */
48 _cups_globals_t
*cg
= _cupsGlobals(); /* Global info */
49 int options
; /* Resolve options */
50 ppd_file_t
*ppd
; /* PPD file */
51 ppd_attr_t
*ppdattr
; /* PPD attribute */
54 if ((device_uri
= getenv("DEVICE_URI")) == NULL
)
56 if (!argv
|| !argv
[0] || !strchr(argv
[0], ':'))
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
;
67 if ((ppd
= ppdOpenFile(getenv("PPD"))) != NULL
)
69 if ((ppdattr
= ppdFindAttr(ppd
, "cupsIPPFaxOut", NULL
)) != NULL
&&
70 !_cups_strcasecmp(ppdattr
->value
, "true"))
71 options
|= _HTTP_RESOLVE_FAXOUT
;
76 return (_httpResolveURI(device_uri
, cg
->resolved_uri
,
77 sizeof(cg
->resolved_uri
), options
, NULL
, NULL
));
82 * 'cupsBackendReport()' - Write a device line from a backend.
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.
88 * @since CUPS 1.4/macOS 10.6@
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@ */
100 if (!device_scheme
|| !device_uri
)
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
);
107 quote_string("unknown");
108 quote_string(device_info
);
109 quote_string(device_id
);
110 quote_string(device_location
);
117 * 'quote_string()' - Write a quoted string to stdout, escaping \ and ".
121 quote_string(const char *s
) /* I - String to write */
123 fputs(" \"", stdout
);
129 if (*s
== '\\' || *s
== '\"')
132 if (((*s
& 255) < ' ' && *s
!= '\t') || *s
== 0x7f)