]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lpmove.c
Remove svn:keywords since they cause svn_load_dirs.pl to complain about every file.
[thirdparty/cups.git] / systemv / lpmove.c
index 5980a972d5136f7dbe6a00157ac3329d2fb5b629..49674014f69e1886a56354be81f806fd99d82f2b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: lpmove.c 4906 2006-01-10 20:53:28Z mike $"
+ * "$Id: lpmove.c 177 2006-06-21 00:20:03Z jlovell $"
  *
  *   "lpmove" command for the Common UNIX Printing System (CUPS).
  *
@@ -44,7 +44,8 @@
  * Local functions...
  */
 
-static void    move_job(http_t *, int, const char *);
+static int     move_job(http_t *http, const char *src, int jobid,
+                        const char *dest);
 
 
 /*
@@ -58,16 +59,20 @@ main(int  argc,                             /* I - Number of command-line arguments */
   int          i;                      /* Looping var */
   http_t       *http;                  /* Connection to server */
   const char   *job;                   /* Job name */
+  int          jobid;                  /* Job ID */
   int          num_dests;              /* Number of destinations */
   cups_dest_t  *dests;                 /* Destinations */
-  const char   *dest;                  /* New destination */
+  const char   *src,                   /* Original queue */
+               *dest;                  /* New destination */
 
 
+  dest      = NULL;
+  dests     = NULL;
   http      = NULL;
   job       = NULL;
-  dest      = NULL;
+  jobid     = 0;
   num_dests = 0;
-  dests     = NULL;
+  src       = NULL;
 
   for (i = 1; i < argc; i ++)
     if (argv[i][0] == '-')
@@ -80,7 +85,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
            if (http)
              httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
 #else
-            _cupsLangPrintf(stderr, NULL,
+            _cupsLangPrintf(stderr,
                            _("%s: Sorry, no encryption support compiled in!\n"),
                            argv[0]);
 #endif /* HAVE_SSL */
@@ -101,7 +106,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
              if (i >= argc)
              {
-               _cupsLangPuts(stderr, NULL,
+               _cupsLangPuts(stderr,
                              _("Error: need hostname after \'-h\' option!\n"));
                return (1);
               }
@@ -111,33 +116,33 @@ main(int  argc,                           /* I - Number of command-line arguments */
            break;
 
        default :
-           _cupsLangPrintf(stderr, NULL, _("lpmove: Unknown option \'%c\'!\n"),
+           _cupsLangPrintf(stderr, _("lpmove: Unknown option \'%c\'!\n"),
                            argv[i][1]);
            return (1);
       }
-    else if (job == NULL)
+    else if (!jobid && !src)
     {
       if (num_dests == 0)
         num_dests = cupsGetDests(&dests);
 
       if ((job = strrchr(argv[i], '-')) != NULL &&
           cupsGetDest(argv[i], NULL, num_dests, dests) == NULL)
-        job ++;
+        jobid = atoi(job + 1);
       else
-        job = argv[i];
+        src = argv[i];
     }
     else if (dest == NULL)
       dest = argv[i];
     else
     {
-      _cupsLangPrintf(stderr, NULL, _("lpmove: Unknown argument \'%s\'!\n"),
+      _cupsLangPrintf(stderr, _("lpmove: Unknown argument \'%s\'!\n"),
                       argv[i]);
       return (1);
     }
 
-  if (job == NULL || dest == NULL)
+  if ((!jobid && !src) || !dest)
   {
-    _cupsLangPuts(stdout, NULL, _("Usage: lpmove job dest\n"));
+    _cupsLangPuts(stdout, _("Usage: lpmove job/src dest\n"));
     return (1);
   }
 
@@ -147,16 +152,14 @@ main(int  argc,                           /* I - Number of command-line arguments */
 
     if (http == NULL)
     {
-      _cupsLangPrintf(stderr, NULL,
+      _cupsLangPrintf(stderr,
                       _("lpmove: Unable to connect to server: %s\n"),
                      strerror(errno));
       return (1);
     }
   }
 
-  move_job(http, atoi(job), dest);
-
-  return (0);
+  return (move_job(http, src, jobid, dest));
 }
 
 
@@ -164,21 +167,19 @@ main(int  argc,                           /* I - Number of command-line arguments */
  * 'move_job()' - Move a job.
  */
 
-static void
+static int                             /* O - 0 on success, 1 on error */
 move_job(http_t     *http,             /* I - HTTP connection to server */
+         const char *src,              /* I - Source queue */
          int        jobid,             /* I - Job ID */
-        const char *dest)              /* I - Destination */
+        const char *dest)              /* I - Destination queue */
 {
-  ipp_t                *request,               /* IPP Request */
-               *response;              /* IPP Response */
-  cups_lang_t  *language;              /* Default language */
-  char         job_uri[HTTP_MAX_URI],  /* job-uri */
-               printer_uri[HTTP_MAX_URI];
-                                       /* job-printer-uri */
+  ipp_t        *request;                       /* IPP Request */
+  char job_uri[HTTP_MAX_URI],          /* job-uri */
+       printer_uri[HTTP_MAX_URI];      /* job-printer-uri */
 
 
-  if (http == NULL)
-    return;
+  if (!http)
+    return (1);
 
  /*
   * Build a CUPS_MOVE_JOB request, which requires the following
@@ -186,31 +187,32 @@ move_job(http_t     *http,                /* I - HTTP connection to server */
   *
   *    attributes-charset
   *    attributes-natural-language
-  *    job-uri
+  *    job-uri/printer-uri
   *    job-printer-uri
+  *    requesting-user-name
   */
 
-  request = ippNew();
-
-  request->request.op.operation_id = CUPS_MOVE_JOB;
-  request->request.op.request_id   = 1;
-
-  language = cupsLangDefault();
-
-  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(CUPS_MOVE_JOB);
 
-  snprintf(job_uri, sizeof(job_uri), "ipp://localhost/jobs/%d", jobid);
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, job_uri);
+  if (jobid)
+  {
+    snprintf(job_uri, sizeof(job_uri), "ipp://localhost/jobs/%d", jobid);
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL,
+                job_uri);
+  }
+  else
+  {
+    httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL,
+                     "localhost", 0, "/printers/%s", src);
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL,
+                job_uri);
+  }
 
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
                NULL, cupsUser());
 
-  httpAssembleURIf(printer_uri, sizeof(printer_uri), "ipp", NULL, "localhost", 0,
-                   "/printers/%s", dest);
+  httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
+                   "ipp", NULL, "localhost", 0, "/printers/%s", dest);
   ippAddString(request, IPP_TAG_JOB, IPP_TAG_URI, "job-printer-uri",
                NULL, printer_uri);
 
@@ -218,24 +220,18 @@ move_job(http_t     *http,                /* I - HTTP connection to server */
   * Do the request and get back a response...
   */
 
-  if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
-  {
-    if (response->request.status.status_code > IPP_OK_CONFLICT)
-    {
-      _cupsLangPrintf(stderr, NULL, _("lpmove: move-job failed: %s\n"),
-                     ippErrorString(response->request.status.status_code));
-      ippDelete(response);
-      return;
-    }
+  ippDelete(cupsDoRequest(http, request, "/jobs"));
 
-    ippDelete(response);
+  if (cupsLastError() > IPP_OK_CONFLICT)
+  {
+    _cupsLangPrintf(stderr, "lpmove: %s\n", cupsLastErrorString());
+    return (1);
   }
   else
-    _cupsLangPrintf(stderr, NULL, _("lpmove: move-job failed: %s\n"),
-                   ippErrorString(cupsLastError()));
+    return (0);
 }
 
 
 /*
- * End of "$Id: lpmove.c 4906 2006-01-10 20:53:28Z mike $".
+ * End of "$Id: lpmove.c 177 2006-06-21 00:20:03Z jlovell $".
  */