]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/backend.c
2 * Backend functions for CUPS.
4 * Copyright 2007-2015 by Apple Inc.
5 * Copyright 2006 by Easy Software Products.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
11 * Include necessary headers...
14 #include "cups-private.h"
23 static void quote_string(const char *s
);
27 * 'cupsBackendDeviceURI()' - Get the device URI for a backend.
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
34 * @since CUPS 1.2/macOS 10.5@
37 const char * /* O - Device URI or @code NULL@ */
38 cupsBackendDeviceURI(char **argv
) /* I - Command-line arguments */
40 const char *device_uri
, /* Device URI */
41 *auth_info_required
; /* AUTH_INFO_REQUIRED env var */
42 _cups_globals_t
*cg
= _cupsGlobals(); /* Global info */
43 int options
; /* Resolve options */
44 ppd_file_t
*ppd
; /* PPD file */
45 ppd_attr_t
*ppdattr
; /* PPD attribute */
48 if ((device_uri
= getenv("DEVICE_URI")) == NULL
)
50 if (!argv
|| !argv
[0] || !strchr(argv
[0], ':'))
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
;
61 if ((ppd
= ppdOpenFile(getenv("PPD"))) != NULL
)
63 if ((ppdattr
= ppdFindAttr(ppd
, "cupsIPPFaxOut", NULL
)) != NULL
&&
64 !_cups_strcasecmp(ppdattr
->value
, "true"))
65 options
|= _HTTP_RESOLVE_FAXOUT
;
70 return (_httpResolveURI(device_uri
, cg
->resolved_uri
,
71 sizeof(cg
->resolved_uri
), options
, NULL
, NULL
));
76 * 'cupsBackendReport()' - Write a device line from a backend.
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.
82 * @since CUPS 1.4/macOS 10.6@
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@ */
94 if (!device_scheme
|| !device_uri
)
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
);
101 quote_string("unknown");
102 quote_string(device_info
);
103 quote_string(device_id
);
104 quote_string(device_location
);
111 * 'quote_string()' - Write a quoted string to stdout, escaping \ and ".
115 quote_string(const char *s
) /* I - String to write */
117 fputs(" \"", stdout
);
123 if (*s
== '\\' || *s
== '\"')
126 if (((*s
& 255) < ' ' && *s
!= '\t') || *s
== 0x7f)