]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - berkeley/lpq.c
Load cups into easysw/current.
[thirdparty/cups.git] / berkeley / lpq.c
index 6fd1dfc91ede849029b923472d82250b5a11e75f..43f01c6203a5f697cd926cfa7ca1a8f5f0e2f6a1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: lpq.c 4948 2006-01-19 03:23:41Z mike $"
+ * "$Id: lpq.c 5638 2006-06-06 20:08:13Z mike $"
  *
  *   "lpq" command for the Common UNIX Printing System (CUPS).
  *
@@ -49,6 +49,7 @@
  * Local functions...
  */
 
+static http_t  *connect_server(const char *, http_t *);
 static int     show_jobs(const char *, http_t *, const char *,
                          const char *, const int, const int);
 static void    show_printer(const char *, http_t *, const char *);
@@ -76,35 +77,21 @@ main(int  argc,                             /* I - Number of command-line arguments */
   int          num_dests;              /* Number of destinations */
   cups_dest_t  *dests;                 /* Destinations */
   cups_lang_t  *language;              /* Language */
-#ifdef HAVE_SSL
-  http_encryption_t encryption;                /* Encryption? */
-#endif /* HAVE_SSL */
 
 
-  language = cupsLangDefault();
-
- /*
-  * Connect to the scheduler...
-  */
-
-  if ((http = httpConnectEncrypt(cupsServer(), ippPort(),
-                                 cupsEncryption())) == NULL)
-  {
-    _cupsLangPrintf(stderr, _("%s: Unable to contact server!\n"), argv[0]);
-    return (1);
-  }
-
  /*
   * Check for command-line options...
   */
 
+  http       = NULL;
   dest       = NULL;
   user       = NULL;
   id         = 0;
   interval   = 0;
   longstatus = 0;
   all        = 0;
-  num_dests  = cupsGetDests(&dests);
+  language   = cupsLangDefault();
+  num_dests  = 0;
 
   for (i = 1; i < argc; i ++)
     if (argv[i][0] == '+')
@@ -115,10 +102,10 @@ main(int  argc,                           /* I - Number of command-line arguments */
       {
         case 'E' : /* Encrypt */
 #ifdef HAVE_SSL
-           encryption = HTTP_ENCRYPT_REQUIRED;
+           cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
 
            if (http)
-             httpEncryption(http, encryption);
+             httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
 #else
             _cupsLangPrintf(stderr,
                            _("%s: Sorry, no encryption support compiled in!\n"),
@@ -166,6 +153,11 @@ main(int  argc,                            /* I - Number of command-line arguments */
            if ((instance = strchr(dest, '/')) != NULL)
              *instance++ = '\0';
 
+            http = connect_server(argv[0], http);
+
+            if (num_dests == 0)
+              num_dests = cupsGetDests2(http, &dests);
+
             if (cupsGetDest(dest, instance, num_dests, dests) == NULL)
            {
              if (instance)
@@ -186,8 +178,11 @@ main(int  argc,                            /* I - Number of command-line arguments */
            break;
 
         case 'h' : /* Connect to host */
-           if (http != NULL)
+           if (http)
+           {
              httpClose(http);
+             http = NULL;
+           }
 
            if (argv[i][2] != '\0')
               cupsSetServer(argv[i] + 2);
@@ -225,8 +220,13 @@ main(int  argc,                            /* I - Number of command-line arguments */
     else
       user = argv[i];
 
+  http = connect_server(argv[0], http);
+
   if (dest == NULL && !all)
   {
+    if (num_dests == 0)
+      num_dests = cupsGetDests2(http, &dests);
+
     for (i = 0; i < num_dests; i ++)
       if (dests[i].is_default)
        dest = dests[i].name;
@@ -294,6 +294,30 @@ main(int  argc,                            /* I - Number of command-line arguments */
 }
 
 
+/*
+ * 'connect_server()' - Connect to the server as necessary...
+ */
+
+static http_t *                                /* O - New HTTP connection */
+connect_server(const char *command,    /* I - Command name */
+               http_t     *http)       /* I - Current HTTP connection */
+{
+  if (!http)
+  {
+    http = httpConnectEncrypt(cupsServer(), ippPort(),
+                             cupsEncryption());
+
+    if (http == NULL)
+    {
+      _cupsLangPrintf(stderr, _("%s: Unable to connect to server\n"), command);
+      exit(1);
+    }
+  }
+
+  return (http);
+}
+
+
 /*
  * 'show_jobs()' - Show jobs.
  */
@@ -368,8 +392,8 @@ show_jobs(const char *command,              /* I - Command name */
   }
   else
   {
-    httpAssembleURIf(resource, sizeof(resource), "ipp", NULL, "localhost", 0,
-                    "/printers/%s", dest);
+    httpAssembleURIf(HTTP_URI_CODING_ALL, resource, sizeof(resource), "ipp",
+                     NULL, "localhost", 0, "/printers/%s", dest);
 
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
                  NULL, resource);
@@ -592,8 +616,8 @@ show_printer(const char *command,   /* I - Command name */
 
   request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
 
-  httpAssembleURIf(uri, sizeof(uri), "ipp", NULL, "localhost", 0,
-                  "/printers/%s", dest);
+  httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+                   "localhost", 0, "/printers/%s", dest);
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                "printer-uri", NULL, uri);
 
@@ -651,5 +675,5 @@ usage(void)
 
 
 /*
- * End of "$Id: lpq.c 4948 2006-01-19 03:23:41Z mike $".
+ * End of "$Id: lpq.c 5638 2006-06-06 20:08:13Z mike $".
  */