#include "cups-private.h"
#include "backend.h"
#include "ppd.h"
static void quote_string(const char *s);
const char *
cupsBackendDeviceURI(char **argv)
{
const char *device_uri,
*auth_info_required;
_cups_globals_t *cg = _cupsGlobals();
int options;
ppd_file_t *ppd;
ppd_attr_t *ppdattr;
if ((device_uri = getenv("DEVICE_URI")) == NULL)
{
if (!argv || !argv[0] || !strchr(argv[0], ':'))
return (NULL);
device_uri = argv[0];
}
options = _HTTP_RESOLVE_STDERR;
if ((auth_info_required = getenv("AUTH_INFO_REQUIRED")) != NULL &&
!strcmp(auth_info_required, "negotiate"))
options |= _HTTP_RESOLVE_FQDN;
if ((ppd = ppdOpenFile(getenv("PPD"))) != NULL)
{
if ((ppdattr = ppdFindAttr(ppd, "cupsIPPFaxOut", NULL)) != NULL &&
!_cups_strcasecmp(ppdattr->value, "true"))
options |= _HTTP_RESOLVE_FAXOUT;
ppdClose(ppd);
}
return (_httpResolveURI(device_uri, cg->resolved_uri,
sizeof(cg->resolved_uri), options, NULL, NULL));
}
void
cupsBackendReport(
const char *device_scheme,
const char *device_uri,
const char *device_make_and_model,
const char *device_info,
const char *device_id,
const char *device_location)
{
if (!device_scheme || !device_uri)
return;
printf("%s %s", device_scheme, device_uri);
if (device_make_and_model && *device_make_and_model)
quote_string(device_make_and_model);
else
quote_string("unknown");
quote_string(device_info);
quote_string(device_id);
quote_string(device_location);
putchar('\n');
fflush(stdout);
}
static void
quote_string(const char *s)
{
fputs(" \"", stdout);
if (s)
{
while (*s)
{
if (*s == '\\' || *s == '\"')
putchar('\\');
if (((*s & 255) < ' ' && *s != '\t') || *s == 0x7f)
putchar(' ');
else
putchar(*s);
s ++;
}
}
putchar('\"');
}