]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/backend.c
Merge changes from CUPS 1.5svn-r9763.
[thirdparty/cups.git] / cups / backend.c
index 68d234d12314c4bc54760bf0bcc652a8a705a1b7..db4ce22e55b6e0376199aa0fd44ded3962cc0934 100644 (file)
@@ -1,40 +1,39 @@
 /*
- * "$Id: backend.c 5024 2006-01-29 14:58:15Z mike $"
+ * "$Id: backend.c 7810 2008-07-29 01:11:15Z mike $"
  *
- *   Backend functions for the Common UNIX Printing System (CUPS).
+ *   Backend functions for CUPS.
  *
+ *   Copyright 2007-2010 by Apple Inc.
  *   Copyright 2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products and are protected by Federal
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE.txt" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   property of Apple Inc. and are protected by Federal copyright
+ *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ *   which should have been included with this file.  If this file is
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
  *
  *   This file is subject to the Apple OS-Developed Software exception.
  *
  * Contents:
  *
  *   cupsBackendDeviceURI() - Get the device URI for a backend.
+ *   cupsBackendReport()    - Write a device line from a backend.
+ *   quote_string()         - Write a quoted string to stdout, escaping \ and ".
  */
 
 /*
  * Include necessary headers...
  */
 
-#include <stdlib.h>
+#include "cups-private.h"
 #include "backend.h"
-#include "string.h"
+
+
+/*
+ * Local functions...
+ */
+
+static void    quote_string(const char *s);
 
 
 /*
  * function returns the device URI passed in the DEVICE_URI environment
  * variable or the device URI passed in argv[0], whichever is found
  * first.
+ *
+ * @since CUPS 1.2/Mac OS X 10.5@
  */
 
-const char *                           /* O - Device URI or NULL */
+const char *                           /* O - Device URI or @code NULL@ */
 cupsBackendDeviceURI(char **argv)      /* I - Command-line arguments */
 {
-  const char   *device_uri;            /* Device URI */
+  const char   *device_uri,            /* Device URI */
+               *auth_info_required;    /* AUTH_INFO_REQUIRED env var */
+  _cups_globals_t *cg = _cupsGlobals();        /* Global info */
+  int          options;                /* Resolve options */
 
 
-  if ((device_uri = getenv("DEVICE_URI")) != NULL)
-    return (device_uri);
+  if ((device_uri = getenv("DEVICE_URI")) == NULL)
+  {
+    if (!argv || !argv[0] || !strchr(argv[0], ':'))
+      return (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;
+
+  return (_httpResolveURI(device_uri, cg->resolved_uri,
+                          sizeof(cg->resolved_uri), options, NULL, NULL));
+}
+
+
+/*
+ * 'cupsBackendReport()' - Write a device line from a backend.
+ *
+ * This function writes a single device line to stdout for a backend.
+ * It handles quoting of special characters in the device-make-and-model,
+ * device-info, device-id, and device-location strings.
+ *
+ * @since CUPS 1.4/Mac OS X 10.6@
+ */
+
+void
+cupsBackendReport(
+    const char *device_scheme,         /* I - device-scheme string */
+    const char *device_uri,            /* I - device-uri string */
+    const char *device_make_and_model, /* I - device-make-and-model string or @code NULL@ */
+    const char *device_info,           /* I - device-info string or @code NULL@ */
+    const char *device_id,             /* I - device-id string or @code NULL@ */
+    const char *device_location)       /* I - device-location string or @code NULL@ */
+{
+  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
-    return (argv[0]);
+    quote_string("unknown");
+  quote_string(device_info);
+  quote_string(device_id);
+  quote_string(device_location);
+  putchar('\n');
+  fflush(stdout);
+}
+
+
+/*
+ * 'quote_string()' - Write a quoted string to stdout, escaping \ and ".
+ */
+
+static void
+quote_string(const char *s)            /* I - String to write */
+{
+  fputs(" \"", stdout);
+
+  if (s)
+  {
+    while (*s)
+    {
+      if (*s == '\\' || *s == '\"')
+       putchar('\\');
+
+      putchar(*s);
+
+      s ++;
+    }
+  }
+
+  putchar('\"');
 }
 
 
 /*
- * End of "$Id: backend.c 5024 2006-01-29 14:58:15Z mike $".
+ * End of "$Id: backend.c 7810 2008-07-29 01:11:15Z mike $".
  */