]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Added lpq command.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 9 Jun 1999 20:03:48 +0000 (20:03 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 9 Jun 1999 20:03:48 +0000 (20:03 +0000)
Changed http: references to ipp:.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@373 7a7537e8-13f0-0310-91df-b6672ffda945

berkeley/Makefile
berkeley/lpc.c
berkeley/lpq.c [new file with mode: 0644]
berkeley/lprm.c

index 1de5131c79421fa2d0d1fd15209111a477529158..778f020f120866d033cf839fd47847cb3434471b 100644 (file)
@@ -1,5 +1,5 @@
 #
-# "$Id: Makefile,v 1.1 1999/05/13 20:39:58 mike Exp $"
+# "$Id: Makefile,v 1.2 1999/06/09 20:03:46 mike Exp $"
 #
 #   Berkeley commands makefile for the Common UNIX Printing System (CUPS).
 #
@@ -24,8 +24,8 @@
 
 include ../Makedefs
 
-TARGETS        =       lpc lpr lprm
-OBJS   =       lpc.o lpr.o lprm.o
+TARGETS        =       lpc lpq lpr lprm
+OBJS   =       lpc.o lpq.o lpr.o lprm.o
 
 #
 # Make all targets...
@@ -59,6 +59,15 @@ lpc: lpc.o ../cups/libcups.a
 
 lpc.o: ../cups/cups.h ../Makedefs
 
+#
+# lpq
+#
+
+lpq:   lpq.o ../cups/libcups.a
+       $(CC) $(LDFLAGS) -o lpq lpq.o $(LIBS)
+
+lpq.o: ../cups/cups.h ../Makedefs
+
 #
 # lpr
 #
@@ -78,5 +87,5 @@ lprm: lprm.o ../cups/libcups.a
 lprm.o:        ../cups/cups.h ../Makedefs
 
 #
-# End of "$Id: Makefile,v 1.1 1999/05/13 20:39:58 mike Exp $".
+# End of "$Id: Makefile,v 1.2 1999/06/09 20:03:46 mike Exp $".
 #
index 449a4873fad7b23996f7fbc233ea1053eb4b6f5e..6a0365dd8950ad8a66fe3462d98b25f0e543d795 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: lpc.c,v 1.1 1999/05/13 20:39:59 mike Exp $"
+ * "$Id: lpc.c,v 1.2 1999/06/09 20:03:47 mike Exp $"
  *
  *   "lpc" command for the Common UNIX Printing System (CUPS).
  *
@@ -225,7 +225,7 @@ show_status(http_t *http,   /* I - HTTP connection to server */
                                /* Printer URI */
 
 
-  DEBUG_printf(("show_printers(%08x, %08x)\n", http, dests));
+  DEBUG_printf(("show_status(%08x, %08x)\n", http, dests));
 
   if (http == NULL)
     return;
@@ -257,7 +257,7 @@ show_status(http_t *http,   /* I - HTTP connection to server */
 
   if ((response = cupsDoRequest(http, request, "/printers/")) != NULL)
   {
-    DEBUG_puts("show_printers: request succeeded...");
+    DEBUG_puts("show_status: request succeeded...");
 
    /*
     * Loop through the printers returned in the list and display
@@ -397,15 +397,15 @@ show_status(http_t *http, /* I - HTTP connection to server */
 
          language = cupsLangDefault();
 
-         attr = ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
-                             "attributes-charset", NULL,
-                             cupsLangEncoding(language));
+         ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
+                       "attributes-charset", NULL,
+                      cupsLangEncoding(language));
 
-         attr = ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
-                             "attributes-natural-language", NULL,
-                             language->language);
+         ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
+                       "attributes-natural-language", NULL,
+                      language->language);
 
-          sprintf(printer_uri, "http://localhost/printers/%s", printer);
+          sprintf(printer_uri, "ipp://localhost/printers/%s", printer);
          attr = ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                              "printer-uri", NULL, printer_uri);
 
@@ -448,5 +448,5 @@ show_status(http_t *http,   /* I - HTTP connection to server */
 
 
 /*
- * End of "$Id: lpc.c,v 1.1 1999/05/13 20:39:59 mike Exp $".
+ * End of "$Id: lpc.c,v 1.2 1999/06/09 20:03:47 mike Exp $".
  */
diff --git a/berkeley/lpq.c b/berkeley/lpq.c
new file mode 100644 (file)
index 0000000..c08d2fe
--- /dev/null
@@ -0,0 +1,366 @@
+/*
+ * "$Id: lpq.c,v 1.1 1999/06/09 20:03:47 mike Exp $"
+ *
+ *   "lpq" command for the Common UNIX Printing System (CUPS).
+ *
+ *   Copyright 1997-1999 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-3111 USA
+ *
+ *       Voice: (301) 373-9603
+ *       EMail: cups-info@cups.org
+ *         WWW: http://www.cups.org
+ *
+ * Contents:
+ *
+ */
+
+/*
+ * Include necessary headers...
+ */
+
+/*
+ * Include necessary headers...
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <cups/cups.h>
+#include <cups/language.h>
+#include <cups/debug.h>
+
+
+/*
+ * Local functions...
+ */
+
+static int     show_jobs(http_t *, char *, char *, int, int);
+
+
+/*
+ * 'main()' - Parse options and commands.
+ */
+
+int
+main(int  argc,                /* I - Number of command-line arguments */
+     char *argv[])     /* I - Command-line arguments */
+{
+  int          i;              /* Looping var */
+  http_t       *http;          /* Connection to server */
+  char         *dest,          /* Desired printer */
+               *user;          /* Desired user */
+  int          id,             /* Desired job ID */
+               interval,       /* Reporting interval */
+               longstatus;     /* Show file details */
+
+ /*
+  * Connect to the scheduler...
+  */
+
+  http = httpConnect("localhost", ippPort());
+
+ /*
+  * Check for command-line options...
+  */
+
+  dest       = NULL;
+  user       = NULL;
+  id         = 0;
+  interval   = 0;
+  longstatus = 0;
+
+  for (i = 1; i < argc; i ++)
+    if (argv[i][0] == '+')
+      interval = atoi(argv[i] + 1);
+    else if (argv[i][0] == '-')
+    {
+      switch (argv[i][1])
+      {
+        case 'P' : /* Printer */
+           if (argv[i][2])
+             dest = argv[i] + 2;
+           else
+           {
+             i ++;
+             dest = argv[i];
+           }
+           break;
+
+       case 'l' : /* Long status */
+           longstatus = 1;
+           break;
+
+       default :
+           fputs("Usage: lpq [-P dest] [-l] [+interval]\n", stderr);
+           return (1);
+      }
+    }
+    else if (isdigit(argv[i][0]))
+      id = atoi(argv[i]);
+    else
+      user = argv[i];
+
+ /*
+  * Show the status in a loop...
+  */
+
+  for (;;)
+  {
+    i = show_jobs(http, dest, user, id, longstatus);
+
+    if (i && interval)
+      sleep(interval);
+    else
+      break;
+  }
+
+ /*
+  * Close the connection to the server and return...
+  */
+
+  httpClose(http);
+
+  return (0);
+}
+
+
+/*
+ * 'show_jobs()' - Show printers.
+ */
+
+static int                     /* O - Number of jobs in queue */
+show_jobs(http_t *http,                /* I - HTTP connection to server */
+          char   *dest,                /* I - Destination */
+         char   *user,         /* I - User */
+         int    id,            /* I - Job ID */
+         int    longstatus)    /* I - 1 if long report desired */
+{
+  ipp_t                *request,       /* IPP Request */
+               *response;      /* IPP Response */
+  ipp_attribute_t *attr;       /* Current attribute */
+  cups_lang_t  *language;      /* Default language */
+  char         *jobdest,       /* Pointer into job-printer-uri */
+               *jobuser,       /* Pointer to job-originating-user-name */
+               *jobname;       /* Pointer to job-name */
+  ipp_jstate_t jobstate;       /* job-state */
+  int          jobid,          /* job-id */
+               jobsize,        /* job-k-octets */
+               jobpriority,    /* job-priority */
+               jobcount,       /* Number of jobs */
+               rank;           /* Rank of job */
+  char         resource[1024]; /* Resource string */
+  static char  *ranks[10] =    /* Ranking strings */
+               {
+                 "th",
+                 "st",
+                 "nd",
+                 "rd",
+                 "th",
+                 "th",
+                 "th",
+                 "th",
+                 "th",
+                 "th"
+               };
+
+
+  DEBUG_printf(("show_jobs(%08x, %08x, %08x, %d, %d)\n", http, dest, user, id,
+                longstatus));
+
+  if (http == NULL)
+    return;
+
+ /*
+  * Build an IPP_GET_JOBS or IPP_GET_JOB_ATTRIBUTES request, which requires
+  * the following attributes:
+  *
+  *    attributes-charset
+  *    attributes-natural-language
+  *    job-uri or printer-uri
+  *    [
+  */
+
+  request = ippNew();
+
+  request->request.op.operation_id = id ? IPP_GET_JOB_ATTRIBUTES : IPP_GET_JOBS;
+  request->request.op.request_id   = 1;
+
+  language = cupsLangDefault();
+
+  attr = ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
+                      "attributes-charset", NULL, cupsLangEncoding(language));
+
+  attr = ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
+                      "attributes-natural-language", NULL, language->language);
+
+  if (dest == NULL)
+  {
+    if (id)
+      sprintf(resource, "ipp://localhost/jobs/%d", id);
+    else
+      strcpy(resource, "ipp://localhost/jobs");
+
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
+                 NULL, resource);
+  }
+  else
+  {
+    sprintf(resource, "ipp://localhost/printers/%s", dest);
+
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
+                 NULL, resource);
+  }
+
+  if (user)
+  {
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+                 "requesting-user-name", NULL, user);
+    ippAddBoolean(request, IPP_TAG_OPERATION, "my-jobs", 1);
+  }
+
+ /*
+  * Do the request and get back a response...
+  */
+
+  if (!longstatus)
+    puts("Rank\tPri   Owner  Job    Files              Total Size");
+
+  jobcount = 0;
+
+  if ((response = cupsDoRequest(http, request, "/jobs/")) != NULL)
+  {
+    rank = 1;
+
+   /*
+    * Loop through the job list and display them...
+    */
+
+    for (attr = response->attrs; attr != NULL; attr = attr->next)
+    {
+     /*
+      * Skip leading attributes until we hit a job...
+      */
+
+      while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
+        attr = attr->next;
+
+      if (attr == NULL)
+        break;
+
+     /*
+      * Pull the needed attributes from this job...
+      */
+
+      jobid       = 0;
+      jobsize     = 0;
+      jobpriority = 50;
+      jobstate    = IPP_JOB_PENDING;
+      jobname     = "untitled";
+      jobuser     = NULL;
+      jobdest     = NULL;
+
+      while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
+      {
+        if (strcmp(attr->name, "job-id") == 0 &&
+           attr->value_tag == IPP_TAG_INTEGER)
+         jobid = attr->values[0].integer;
+
+        if (strcmp(attr->name, "job-k-octets") == 0 &&
+           attr->value_tag == IPP_TAG_INTEGER)
+         jobsize = attr->values[0].integer * 1024;
+
+        if (strcmp(attr->name, "job-priority") == 0 &&
+           attr->value_tag == IPP_TAG_INTEGER)
+         jobpriority = attr->values[0].integer;
+
+        if (strcmp(attr->name, "job-state") == 0 &&
+           attr->value_tag == IPP_TAG_ENUM)
+         jobstate = (ipp_jstate_t)attr->values[0].integer;
+
+        if (strcmp(attr->name, "job-printer-uri") == 0 &&
+           attr->value_tag == IPP_TAG_URI)
+         if ((jobdest = strrchr(attr->values[0].string.text, '/')) != NULL)
+           jobdest ++;
+
+        if (strcmp(attr->name, "job-originating-user-name") == 0 &&
+           attr->value_tag == IPP_TAG_NAME)
+         jobuser = attr->values[0].string.text;
+
+        if (strcmp(attr->name, "job-name") == 0 &&
+           attr->value_tag == IPP_TAG_NAME)
+         jobname = attr->values[0].string.text;
+
+        attr = attr->next;
+      }
+
+     /*
+      * See if we have everything needed...
+      */
+
+      if (jobdest == NULL || jobid == 0)
+      {
+        if (attr == NULL)
+         break;
+       else
+          continue;
+      }
+
+      jobcount ++;
+
+     /*
+      * Display the job...
+      */
+
+      if (longstatus)
+      {
+        puts("");
+
+        if (jobstate == IPP_JOB_PROCESSING)
+         printf("%s: active\t\t\t\t ", jobuser);
+       else
+       {
+         printf("%s: %d%s\t\t\t\t ", jobuser, rank, ranks[rank % 10]);
+         rank ++;
+       }
+
+        printf("[job %03dlocalhost]\n", jobid);
+        printf("\t%-33s%d bytes\n", jobname, jobsize);
+      }
+      else
+      {
+        if (jobstate == IPP_JOB_PROCESSING)
+         printf("active\t");
+       else
+       {
+         printf("%d%s\t", rank, ranks[rank % 10]);
+         rank ++;
+       }
+
+        printf(" %-5d%-7.7s%-7d%-19s%d bytes\n", jobpriority, jobuser, jobid,
+              jobname, jobsize);
+      }
+      if (attr == NULL)
+        break;
+    }
+
+    ippDelete(response);
+  }
+
+  return (jobcount);
+}
+
+
+/*
+ * End of "$Id: lpq.c,v 1.1 1999/06/09 20:03:47 mike Exp $".
+ */
index 958f1467904752284cb48af0a15f5b349d97b87d..603887aad97c58cd555673b421a209557b3fc392 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: lprm.c,v 1.1 1999/05/13 20:40:00 mike Exp $"
+ * "$Id: lprm.c,v 1.2 1999/06/09 20:03:48 mike Exp $"
  *
  *   "lprm" command for the Common UNIX Printing System (CUPS).
  *
@@ -146,7 +146,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
 
       if (dest)
       {
-        sprintf(uri, "http://localhost/printers/%s", dest);
+        sprintf(uri, "ipp://localhost/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",
@@ -154,7 +154,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
       }
       else
       {
-        sprintf(uri, "http://localhost/jobs/%d", job_id);
+        sprintf(uri, "ipp://localhost/jobs/%d", job_id);
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL,
                     uri);
       }
@@ -194,5 +194,5 @@ main(int  argc,                     /* I - Number of command-line arguments */
 
 
 /*
- * End of "$Id: lprm.c,v 1.1 1999/05/13 20:40:00 mike Exp $".
+ * End of "$Id: lprm.c,v 1.2 1999/06/09 20:03:48 mike Exp $".
  */