]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - berkeley/lprm.c
Load cups into easysw/current.
[thirdparty/cups.git] / berkeley / lprm.c
index f6fe9fc6b4b5cfd3347da36b1038f51073714425..574f2650746f815559f87725ca342e1dfc0ac179 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: lprm.c 4906 2006-01-10 20:53:28Z mike $"
+ * "$Id: lprm.c 5878 2006-08-24 15:55:42Z mike $"
  *
  *   "lprm" command for the Common UNIX Printing System (CUPS).
  *
@@ -55,12 +55,14 @@ main(int  argc,                     /* I - Number of command-line arguments */
   ipp_t                *request;       /* IPP request */
   ipp_t                *response;      /* IPP response */
   ipp_op_t     op;             /* Operation */
-  cups_lang_t  *language;      /* Language */
   int          num_dests;      /* Number of destinations */
-  cups_dest_t  *dests;         /* Destinations */
+  cups_dest_t  *dests,         /* Destinations */
+               *defdest;       /* Default destination */
   http_encryption_t encryption;        /* Encryption? */
 
 
+  _cupsSetLocale();
+
  /*
   * Setup to cancel individual print jobs...
   */
@@ -71,12 +73,6 @@ main(int  argc,                      /* I - Number of command-line arguments */
   response   = NULL;
   http       = NULL;
   encryption = cupsEncryption();
-  language   = cupsLangDefault();
-  num_dests  = cupsGetDests(&dests);
-
-  for (i = 0; i < num_dests; i ++)
-    if (dests[i].is_default)
-      dest = dests[i].name;
 
  /*
   * Open a connection to the server...
@@ -84,11 +80,14 @@ main(int  argc,                     /* I - Number of command-line arguments */
 
   if ((http = httpConnectEncrypt(cupsServer(), ippPort(), encryption)) == NULL)
   {
-    _cupsLangPuts(stderr, language, _("lprm: Unable to contact server!\n"));
-    cupsFreeDests(num_dests, dests);
+    _cupsLangPuts(stderr, _("lprm: Unable to contact server!\n"));
     return (1);
   }
 
+  num_dests  = cupsGetDests2(http, &dests);
+  defdest    = cupsGetDest(NULL, NULL, num_dests, dests);
+  dest       = defdest ? defdest->name : NULL;
+
  /*
   * Process command-line arguments...
   */
@@ -102,8 +101,9 @@ main(int  argc,                     /* I - Number of command-line arguments */
            encryption = HTTP_ENCRYPT_REQUIRED;
 
            httpEncryption(http, encryption);
+           cupsSetEncryption(encryption);
 #else
-            _cupsLangPrintf(stderr, language,
+            _cupsLangPrintf(stderr,
                            _("%s: Sorry, no encryption support compiled in!\n"),
                            argv[0]);
 #endif /* HAVE_SSL */
@@ -123,17 +123,72 @@ main(int  argc,                   /* I - Number of command-line arguments */
 
            if (cupsGetDest(dest, NULL, num_dests, dests) == NULL)
            {
-             _cupsLangPrintf(stderr, language,
-                             _("lprm: Unknown destination \"%s\"!\n"), dest);
+             _cupsLangPrintf(stderr,
+                             _("%s: Error - unknown destination \"%s\"!\n"),
+                             argv[0], dest);
               cupsFreeDests(num_dests, dests);
              httpClose(http);
              return(1);
            }
            break;
 
+        case 'U' : /* Username */
+           if (argv[i][2] != '\0')
+             cupsSetUser(argv[i] + 2);
+           else
+           {
+             i ++;
+             if (i >= argc)
+             {
+               _cupsLangPrintf(stderr,
+                               _("%s: Error - expected username after "
+                                 "\'-U\' option!\n"),
+                               argv[0]);
+               return (1);
+             }
+
+              cupsSetUser(argv[i]);
+           }
+           break;
+           
+        case 'h' : /* Connect to host */
+           if (argv[i][2] != '\0')
+              cupsSetServer(argv[i] + 2);
+           else
+           {
+             i ++;
+
+             if (i >= argc)
+             {
+               _cupsLangPrintf(stderr,
+                               _("%s: Error - expected hostname after "
+                                 "\'-h\' option!\n"),
+                               argv[0]);
+               return (1);
+              }
+             else
+                cupsSetServer(argv[i]);
+           }
+
+            httpClose(http);
+            cupsFreeDests(num_dests, dests);
+
+           if ((http = httpConnectEncrypt(cupsServer(), ippPort(),
+                                          encryption)) == NULL)
+           {
+             _cupsLangPuts(stderr, _("lprm: Unable to contact server!\n"));
+             return (1);
+           }
+
+           num_dests  = cupsGetDests2(http, &dests);
+           defdest    = cupsGetDest(NULL, NULL, num_dests, dests);
+           dest       = defdest ? defdest->name : NULL;
+           break;
+
        default :
-           _cupsLangPrintf(stderr, language,
-                           _("lprm: Unknown option \'%c\'!\n"), argv[i][1]);
+           _cupsLangPrintf(stderr,
+                           _("%s: Error - unknown option \'%c\'!\n"),
+                           argv[0], argv[i][1]);
             cupsFreeDests(num_dests, dests);
            httpClose(http);
            return (1);
@@ -151,7 +206,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
        op     = IPP_CANCEL_JOB;
         job_id = atoi(argv[i]);
       }
-      else if (strcmp(argv[i], "-") == 0)
+      else if (!strcmp(argv[i], "-"))
       {
        /*
         * Cancel all jobs
@@ -175,21 +230,12 @@ main(int  argc,                   /* I - Number of command-line arguments */
       *    [requesting-user-name]
       */
 
-      request = ippNew();
-
-      request->request.op.operation_id = op;
-      request->request.op.request_id   = 1;
-
-      ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
-                  "attributes-charset", NULL, cupsLangEncoding(language));
-
-      ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
-                   "attributes-natural-language", NULL, language->language);
+      request = ippNewRequest(op);
 
       if (dest)
       {
-        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);
        ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id",
@@ -214,43 +260,12 @@ main(int  argc,                   /* I - Number of command-line arguments */
       else
         response = cupsDoRequest(http, request, "/jobs/");
 
-      if (response != NULL)
-      {
-        switch (response->request.status.status_code)
-       {
-         case IPP_NOT_FOUND :
-              _cupsLangPuts(stderr, language,
-                           _("lprm: Job or printer not found!\n"));
-             break;
-         case IPP_NOT_AUTHORIZED :
-              _cupsLangPuts(stderr, language,
-                           _("lprm: Not authorized to lprm job(s)!\n"));
-             break;
-         case IPP_FORBIDDEN :
-              _cupsLangPrintf(stderr, language,
-                             _("lprm: You don't own job ID %d!\n"), job_id);
-             break;
-         default :
-              if (response->request.status.status_code > IPP_OK_CONFLICT)
-                _cupsLangPuts(stderr, language,
-                             _("lprm: Unable to lprm job(s)!\n"));
-             break;
-       }
-
-        if (response->request.status.status_code > IPP_OK_CONFLICT)
-       {
-          ippDelete(response);
-          cupsFreeDests(num_dests, dests);
-          httpClose(http);
-         return (1);
-       }
-
-        ippDelete(response);
-      }
-      else
+      ippDelete(response);
+
+      if (cupsLastError() > IPP_OK_CONFLICT)
       {
-        _cupsLangPuts(stderr, language,
-                     _("lprm: Unable to cancel job(s)!\n"));
+        _cupsLangPrintf(stderr, "%s: %s\n", argv[0], cupsLastErrorString());
+
         cupsFreeDests(num_dests, dests);
         httpClose(http);
        return (1);
@@ -258,15 +273,14 @@ main(int  argc,                   /* I - Number of command-line arguments */
     }
 
  /*
-  * If nothing has been cancelled yet, cancel the current job on the specified
+  * If nothing has been canceled yet, cancel the current job on the specified
   * (or default) printer...
   */
 
   if (response == NULL)
     if (!cupsCancelJob(dest, 0))
     {
-      _cupsLangPuts(stderr, language,
-                    _("lprm: Unable to cancel job(s)!\n"));
+      _cupsLangPrintf(stderr, "%s: %s\n", argv[0], cupsLastErrorString());
       cupsFreeDests(num_dests, dests);
       httpClose(http);
       return (1);
@@ -280,5 +294,5 @@ main(int  argc,                     /* I - Number of command-line arguments */
 
 
 /*
- * End of "$Id: lprm.c 4906 2006-01-10 20:53:28Z mike $".
+ * End of "$Id: lprm.c 5878 2006-08-24 15:55:42Z mike $".
  */