Integrated support for NT and OS/2 lpq parsing. Code from
authorJeremy Allison <jra@samba.org>
Sat, 7 Oct 2000 00:48:27 +0000 (00:48 +0000)
committerJeremy Allison <jra@samba.org>
Sat, 7 Oct 2000 00:48:27 +0000 (00:48 +0000)
Jim McDonough
Infoprint Manager Development
Linux Technology Center
IBM Boulder

Jeremy.
(This used to be commit d9eedd5db1728be8e23d73c954db13bbbcadf3fb)

source3/include/smb.h
source3/param/loadparm.c
source3/printing/lpq_parse.c

index 1bc1d3fba4f1f7b75b72719c86caff98c161b83d..16fb954ad87d3056cc3a8e1e11b8c9ca3db9c08c 100644 (file)
@@ -1411,7 +1411,7 @@ enum server_types
 
 /* printing types */
 enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
-                    PRINT_QNX,PRINT_PLP,PRINT_LPRNG,PRINT_SOFTQ,PRINT_CUPS};
+                    PRINT_QNX,PRINT_PLP,PRINT_LPRNG,PRINT_SOFTQ,PRINT_CUPS,PRINT_LPRNT,PRINT_LPROS2};
 
 /* Remote architectures we know about. */
 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_WIN2K, RA_SAMBA};
index 452c207dfba45423702aa686cd039e674b2f22e9..09ecdf83fa53c314697ac3eab659e5fc1e3eea4e 100644 (file)
@@ -549,6 +549,8 @@ static struct enum_list enum_printing[] = {
        {PRINT_LPRNG, "lprng"},
        {PRINT_SOFTQ, "softq"},
        {PRINT_CUPS, "cups"},
+       {PRINT_LPRNT, "nt"},
+       {PRINT_LPROS2, "os2"},
        {-1, NULL}
 };
 
@@ -1005,6 +1007,8 @@ static void init_printer_values(void)
        {
                case PRINT_BSD:
                case PRINT_AIX:
+               case PRINT_LPRNT:
+               case PRINT_LPROS2:
                        string_set(&sDefault.szLpqcommand, "lpq -P%p");
                        string_set(&sDefault.szLprmcommand, "lprm -P%p %j");
                        string_set(&sDefault.szPrintcommand,
index 42da593c8dfa1e5a4c84b9c6194732159542f206..4a4cf6306bf690f795a3224ed16bbc8f680ed981 100644 (file)
@@ -779,6 +779,163 @@ static BOOL parse_lpq_softq(char *line,print_queue_struct *buf,BOOL first)
   return(True);
 }
 
+/*******************************************************************
+parse lpq on an NT system
+
+                         Windows 2000 LPD Server
+                              Printer \\10.0.0.2\NP17PCL (Paused)
+
+Owner       Status         Jobname          Job-Id    Size   Pages  Priority
+----------------------------------------------------------------------------
+root (9.99. Printing  /usr/lib/rhs/rhs-pr      3       625      0      1
+root (9.99. Paused    /usr/lib/rhs/rhs-pr      4       625      0      1
+jmcd        Waiting   Re: Samba Open Sour     26     32476      1      1
+
+********************************************************************/
+static BOOL parse_lpq_nt(char *line,print_queue_struct *buf,BOOL first)
+{
+#define LPRNT_OWNSIZ 11
+#define LPRNT_STATSIZ 9
+#define LPRNT_JOBSIZ 19
+#define LPRNT_IDSIZ 6
+#define LPRNT_SIZSIZ 9
+  typedef struct 
+  {
+    char owner[LPRNT_OWNSIZ];
+    char space1;
+    char status[LPRNT_STATSIZ];
+    char space2;
+    char jobname[LPRNT_JOBSIZ];
+    char space3;
+    char jobid[LPRNT_IDSIZ];
+    char space4;
+    char size[LPRNT_SIZSIZ];
+    char terminator;
+  } nt_lpq_line;
+
+  nt_lpq_line parse_line;
+#define LPRNT_PRINTING "Printing"
+#define LPRNT_WAITING "Waiting"
+#define LPRNT_PAUSED "Paused"
+
+  memset(&parse_line, '\0', sizeof(parse_line));
+  strncpy((char *) &parse_line, line, sizeof(parse_line) -1);
+
+  if (strlen((char *) &parse_line) != sizeof(parse_line) - 1)
+    return(False);
+
+  /* Just want the first word in the owner field - the username */
+  if (strchr(parse_line.owner, ' '))
+    *(strchr(parse_line.owner, ' ')) = '\0';
+  else
+    parse_line.space1 = '\0';
+
+  /* Make sure we have an owner */
+  if (!strlen(parse_line.owner))
+    return(False);
+
+  /* Make sure the status is valid */
+  parse_line.space2 = '\0';
+  trim_string(parse_line.status, NULL, " ");
+  if (!strequal(parse_line.status, LPRNT_PRINTING) &&
+      !strequal(parse_line.status, LPRNT_PAUSED) &&
+      !strequal(parse_line.status, LPRNT_WAITING))
+    return(False);
+  
+  parse_line.space3 = '\0';
+  trim_string(parse_line.jobname, NULL, " ");
+
+  buf->job = atoi(parse_line.jobid);
+  buf->priority = 0;
+  buf->size = atoi(parse_line.size);
+  buf->time = time(NULL);
+  StrnCpy(buf->user, parse_line.owner, sizeof(buf->user)-1);
+  StrnCpy(buf->file, parse_line.jobname, sizeof(buf->file)-1);
+  if (strequal(parse_line.status, LPRNT_PRINTING))
+    buf->status = LPQ_PRINTING;
+  else if (strequal(parse_line.status, LPRNT_PAUSED))
+    buf->status = LPQ_PAUSED;
+  else
+    buf->status = LPQ_QUEUED;
+
+  return(True);
+}
+
+/*******************************************************************
+parse lpq on an OS2 system
+
+JobID  File Name          Rank      Size        Status          Comment       
+-----  ---------------    ------    --------    ------------    ------------  
+    3  Control                 1          68    Queued          root@psflinu  
+    4  /etc/motd               2       11666    Queued          root@psflinu  
+
+********************************************************************/
+static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first)
+{
+#define LPROS2_IDSIZ 5
+#define LPROS2_JOBSIZ 15
+#define LPROS2_SIZSIZ 8
+#define LPROS2_STATSIZ 12
+#define LPROS2_OWNSIZ 12
+  typedef struct 
+  {
+    char jobid[LPROS2_IDSIZ];
+    char space1[2];
+    char jobname[LPROS2_JOBSIZ];
+    char space2[14];
+    char size[LPROS2_SIZSIZ];
+    char space3[4];
+    char status[LPROS2_STATSIZ];
+    char space4[4];
+    char owner[LPROS2_OWNSIZ];
+    char terminator;
+  } os2_lpq_line;
+
+  os2_lpq_line parse_line;
+#define LPROS2_PRINTING "Printing"
+#define LPROS2_WAITING "Queued"
+#define LPROS2_PAUSED "Paused"
+
+  memset(&parse_line, '\0', sizeof(parse_line));
+  strncpy((char *) &parse_line, line, sizeof(parse_line) -1);
+
+  if (strlen((char *) &parse_line) != sizeof(parse_line) - 1)
+    return(False);
+
+  /* Get the jobid */
+  buf->job = atoi(parse_line.jobid);
+
+  /* Get the job name */
+  parse_line.space2[0] = '\0';
+  trim_string(parse_line.jobname, NULL, " ");
+  StrnCpy(buf->file, parse_line.jobname, sizeof(buf->file)-1);
+
+  buf->priority = 0;
+  buf->size = atoi(parse_line.size);
+  buf->time = time(NULL);
+
+  /* Make sure we have an owner */
+  if (!strlen(parse_line.owner))
+    return(False);
+
+  /* Make sure we have a valid status */
+  parse_line.space4[0] = '\0';
+  trim_string(parse_line.status, NULL, " ");
+  if (!strequal(parse_line.status, LPROS2_PRINTING) &&
+      !strequal(parse_line.status, LPROS2_PAUSED) &&
+      !strequal(parse_line.status, LPROS2_WAITING))
+    return(False);
+
+  StrnCpy(buf->user, parse_line.owner, sizeof(buf->user)-1);
+  if (strequal(parse_line.status, LPROS2_PRINTING))
+    buf->status = LPQ_PRINTING;
+  else if (strequal(parse_line.status, LPROS2_PAUSED))
+    buf->status = LPQ_PAUSED;
+  else
+    buf->status = LPQ_QUEUED;
+
+  return(True);
+}
 
 static char *stat0_strings[] = { "enabled", "online", "idle", "no entries", "free", "ready", NULL };
 static char *stat1_strings[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL };
@@ -816,6 +973,12 @@ BOOL parse_lpq_entry(int snum,char *line,
     case PRINT_SOFTQ:
       ret = parse_lpq_softq(line,buf,first);
       break;
+    case PRINT_LPRNT:
+      ret = parse_lpq_nt(line,buf,first);
+      break;
+    case PRINT_LPROS2:
+      ret = parse_lpq_os2(line,buf,first);
+      break;
     default:
       ret = parse_lpq_bsd(line,buf,first);
       break;