Changes from APPLIANCE_HEAD:
authorDavid O'Neill <dmo@samba.org>
Tue, 14 Nov 2000 15:26:53 +0000 (15:26 +0000)
committerDavid O'Neill <dmo@samba.org>
Tue, 14 Nov 2000 15:26:53 +0000 (15:26 +0000)
- merged Tim's vlp (virtual lp) test program.  Enable it with
      -DDEVELOPER or by using ./configure.developer
  (source/include/smb.h source/configure.developer
   source/printing/lpq_parse.c source/param/loadparm.c
   testsuite/printing/.cvsignore testsuite/printing/Makefile.vlp
   testsuite/printing/vlp.c)
(This used to be commit fbcf83140da1823e74f63227f0a95d07c6e76764)

source3/configure.developer
source3/include/smb.h
source3/param/loadparm.c
source3/printing/lpq_parse.c
testsuite/printing/.cvsignore
testsuite/printing/Makefile.vlp [new file with mode: 0644]
testsuite/printing/vlp.c [new file with mode: 0644]

index e7c8831f62c5930b1ce7c2fec4ea01ae34b13274..07ce9fcf12aef4f1fef98d9b0a4efd74cad84eb7 100755 (executable)
@@ -1,4 +1,4 @@
 #!/bin/sh
 #!/bin/sh
-CFLAGS="-g -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -DDEBUG_PASSWORD"
+CFLAGS="-g -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -DDEBUG_PASSWORD -DDEVELOPER"
 export CFLAGS
 ./configure $*
 export CFLAGS
 ./configure $*
index 57a62b7f1f0ec8e5045bb49e9569078e780d69e5..a5ace1eb4d34d91860c65516d5c49a53f3d24c33 100644 (file)
@@ -1405,7 +1405,12 @@ enum server_types
 
 /* printing types */
 enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
 
 /* printing types */
 enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
-                    PRINT_QNX,PRINT_PLP,PRINT_LPRNG,PRINT_SOFTQ,PRINT_CUPS,PRINT_LPRNT,PRINT_LPROS2};
+                    PRINT_QNX,PRINT_PLP,PRINT_LPRNG,PRINT_SOFTQ,
+                    PRINT_CUPS,PRINT_LPRNT,PRINT_LPROS2
+#ifdef DEVELOPER
+,PRINT_TEST,PRINT_VLP
+#endif /* DEVELOPER */
+};
 
 /* Remote architectures we know about. */
 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_WIN2K, RA_SAMBA};
 
 /* Remote architectures we know about. */
 enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_WIN2K, RA_SAMBA};
index dc2082423b9cde09294cf4da946fb2657cdaaf28..9dcd7bbc2e331195413358480199a49fc20a80f2 100644 (file)
@@ -561,6 +561,10 @@ static struct enum_list enum_printing[] = {
        {PRINT_CUPS, "cups"},
        {PRINT_LPRNT, "nt"},
        {PRINT_LPROS2, "os2"},
        {PRINT_CUPS, "cups"},
        {PRINT_LPRNT, "nt"},
        {PRINT_LPROS2, "os2"},
+#ifdef DEVELOPER
+       {PRINT_TEST, "test"},
+       {PRINT_TEST, "vlp"},
+#endif /* DEVELOPER */
        {-1, NULL}
 };
 
        {-1, NULL}
 };
 
@@ -1099,6 +1103,18 @@ static void init_printer_values(void)
                        string_set(&sDefault.szLpresumecommand,
                                   "qstat -s -j%j -r");
                        break;
                        string_set(&sDefault.szLpresumecommand,
                                   "qstat -s -j%j -r");
                        break;
+#ifdef DEVELOPER
+       case PRINT_TEST:
+       case PRINT_VLP:
+               string_set(&sDefault.szPrintcommand, "vlp print %p %s");
+               string_set(&sDefault.szLpqcommand, "vlp lpq %p");
+               string_set(&sDefault.szLprmcommand, "vlp lprm %p %j");
+               string_set(&sDefault.szLppausecommand, "vlp lppause %p %j");
+               string_set(&sDefault.szLpresumecommand, "vlp lpresum %p %j");
+               string_set(&sDefault.szQueuepausecommand, "vlp queuepause %p");
+               string_set(&sDefault.szQueueresumecommand, "vlp queueresume %p");
+               break;
+#endif /* DEVELOPER */
 
        }
 }
 
        }
 }
index e0b3ed192f847a14d090f602197848272a7c992e..f6bf7f06dfed4ee5d4de5f6c670251fe29629729 100644 (file)
@@ -938,6 +938,51 @@ static char *stat0_strings[] = { "enabled", "online", "idle", "no entries", "fre
 static char *stat1_strings[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL };
 static char *stat2_strings[] = { "jam", "paper", "error", "responding", "not accepting", "not running", "turned off", NULL };
 
 static char *stat1_strings[] = { "offline", "disabled", "down", "off", "waiting", "no daemon", NULL };
 static char *stat2_strings[] = { "jam", "paper", "error", "responding", "not accepting", "not running", "turned off", NULL };
 
+#ifdef DEVELOPER
+
+/****************************************************************************
+parse a vlp line
+****************************************************************************/
+static BOOL parse_lpq_vlp(char *line,print_queue_struct *buf,BOOL first)
+{
+       int toknum = 0;
+       fstring tok;
+
+       /* First line is printer status */
+
+       if (!isdigit(line[0])) return False;
+
+       /* Parse a print job entry */
+
+       while(next_token(&line, tok, NULL, sizeof(fstring))) {
+               switch (toknum) {
+               case 0:
+                       buf->job = atoi(tok);
+                       break;
+               case 1:
+                       buf->size = atoi(tok);
+                       break;
+               case 2:
+                       buf->status = atoi(tok);
+                       break;
+               case 3:
+                       buf->time = atoi(tok);
+                       break;
+               case 4:
+                       fstrcpy(buf->user, tok);
+                       break;
+               case 5:
+                       fstrcpy(buf->file, tok);
+                       break;
+               }
+               toknum++;
+       }
+
+       return True;
+}
+
+#endif /* DEVELOPER */
+
 /****************************************************************************
 parse a lpq line. Choose printing style
 ****************************************************************************/
 /****************************************************************************
 parse a lpq line. Choose printing style
 ****************************************************************************/
@@ -976,6 +1021,12 @@ BOOL parse_lpq_entry(int snum,char *line,
     case PRINT_LPROS2:
       ret = parse_lpq_os2(line,buf,first);
       break;
     case PRINT_LPROS2:
       ret = parse_lpq_os2(line,buf,first);
       break;
+#ifdef DEVELOPER
+    case PRINT_VLP:
+    case PRINT_TEST:
+           ret = parse_lpq_vlp(line,buf,first);
+           break;
+#endif /* DEVELOPER */
     default:
       ret = parse_lpq_bsd(line,buf,first);
       break;
     default:
       ret = parse_lpq_bsd(line,buf,first);
       break;
index cdbd566c2d4797e5aafed96b8aca868a88a29c3c..392f2777686783ef211b956f3ef6ea657054232d 100644 (file)
@@ -1 +1,2 @@
+vlp
 psec
 psec
diff --git a/testsuite/printing/Makefile.vlp b/testsuite/printing/Makefile.vlp
new file mode 100644 (file)
index 0000000..142082e
--- /dev/null
@@ -0,0 +1,14 @@
+#
+# Makefile for vlp utility
+#
+
+vlp_default: vlp
+
+include ../../source/Makefile
+
+VLP_OBJ1 = $(LIB_OBJ) $(PARAM_OBJ) $(UBIQX_OBJ) 
+
+VLP_OBJS = $(VLP_OBJ1:%=$(srcdir)/%)
+
+vlp: $(VLP_OBJS) vlp.o
+       $(CC) -o $@ vlp.o $(VLP_OBJS) $(LIBS)
diff --git a/testsuite/printing/vlp.c b/testsuite/printing/vlp.c
new file mode 100644 (file)
index 0000000..2dd028f
--- /dev/null
@@ -0,0 +1,426 @@
+/* 
+   Unix SMB/Netbios implementation.
+
+   Virtual lp system for printer testing
+
+   Copyright (C) Tim Potter 2000
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+
+#define PRINT_TDB "/tmp/vlp.tdb"
+#define PRINT_FIRSTJOB "100"
+
+static TDB_CONTEXT *tdb;
+
+struct vlp_job {
+       fstring owner;
+       int jobid;
+       fstring jobname;
+       int size;
+       int status;
+       time_t submit_time;
+       int deleted;
+};
+
+/* Print usage */
+
+static void usage(void)
+{
+       printf("Usage: print-test lpq|lprm|print|queuepause|queueresume|"
+              "lppause|lpresume [args]\n");
+}
+
+/* Return an array of vlp jobs that is the printer queue */
+
+static void get_job_list(char *printer, struct vlp_job **job_list, 
+                        int *num_jobs)
+{
+       fstring keystr;
+       TDB_DATA data;
+
+       slprintf(keystr, sizeof(keystr) - 1, "LPQ/%s", printer);
+       data = tdb_fetch_by_string(tdb, keystr);
+
+       *job_list = (struct vlp_job *)data.dptr;
+       *num_jobs = data.dsize / sizeof(struct vlp_job);
+}
+
+/* Store an array of vl jobs for the queue */
+
+static void set_job_list(char *printer, struct vlp_job *job_list, 
+                        int num_jobs)
+{
+       fstring keystr;
+
+       slprintf(keystr, sizeof(keystr) - 1, "LPQ/%s", printer);
+
+       tdb_store_by_string(tdb, keystr, job_list, 
+                           num_jobs * sizeof(struct vlp_job));
+}
+
+/* Return the next job number for a printer */
+
+static int next_jobnum(char *printer)
+{
+       fstring keystr;
+       int jobnum;
+
+       slprintf(keystr, sizeof(keystr) - 1, "JOBNUM/%s", printer);
+
+       tdb_lock_bystring(tdb, keystr);
+
+       jobnum = tdb_fetch_int(tdb, keystr);
+
+       /* Create next job index if none exists */
+
+       if (jobnum == -1) {
+               jobnum = atoi(PRINT_FIRSTJOB);
+       }
+
+       jobnum++;
+       tdb_store_int(tdb, keystr, jobnum);
+
+       tdb_unlock_bystring(tdb, keystr);
+
+       return jobnum;
+}
+
+static void set_printer_status(char *printer, int status)
+{
+       fstring keystr;
+       int result;
+
+       slprintf(keystr, sizeof(keystr) - 1, "STATUS/%s", printer);
+       result = tdb_store_int(tdb, keystr, status);
+}
+
+static int get_printer_status(char *printer)
+{
+       fstring keystr;
+       TDB_DATA data;
+
+       slprintf(keystr, sizeof(keystr) - 1, "STATUS/%s", printer);
+
+       data.dptr = keystr;
+       data.dsize = strlen(keystr) + 1;
+
+       if (!tdb_exists(tdb, data)) {
+               set_printer_status(printer, LPSTAT_OK);
+               return LPSTAT_OK;
+       }
+
+       return tdb_fetch_int(tdb, keystr);
+}
+
+/* Display printer queue */
+
+static int lpq_command(int argc, char **argv)
+{
+       char *printer;
+       struct vlp_job *job_list = NULL;
+       int i, num_jobs, job_count = 0;
+
+       if (argc != 2) {
+               printf("Usage: lpq <printername>\n");
+               return 1;
+       }
+
+       printer = argv[1];
+
+       /* Display printer status */
+
+       switch (get_printer_status(printer)) {
+       case LPSTAT_OK:
+               printf("enabled\n");
+               break;
+       case LPSTAT_STOPPED:
+               printf("disabled\n");
+               break;
+       case LPSTAT_ERROR:
+       default:
+               printf("error\n");
+               break;
+       }
+
+       /* Print queued documents */
+
+       get_job_list(printer, &job_list, &num_jobs);
+
+       for (i = 0; i < num_jobs; i++) {
+               if (job_list[i].deleted) continue;
+               printf("%d\t%d\t%d\t%ld\t%s\t%s\n", job_list[i].jobid,
+                      job_list[i].size, 
+                      (i == 0 && job_list[i].status == LPQ_QUEUED) ? 
+                      LPQ_SPOOLING : job_list[i].status,
+                      job_list[i].submit_time, job_list[i].owner, 
+                      job_list[i].jobname);
+               job_count++;
+       }
+
+       free(job_list);
+
+       return 0;
+}
+
+/* Remove a job */
+
+static int lprm_command(int argc, char **argv)
+{
+       char *printer;
+       int jobid, num_jobs, i;
+       struct vlp_job *job_list;
+
+       if (argc < 3) {
+               printf("Usage: lprm <printername> <jobid>\n");
+               return 1;
+       }
+
+       printer = argv[1];
+       jobid = atoi(argv[2]);
+
+       get_job_list(printer, &job_list, &num_jobs);
+
+       for (i = 0; i < num_jobs; i++) {
+               if (job_list[i].jobid == jobid) {
+                       job_list[i].deleted = 1;
+                       set_job_list(printer, job_list, num_jobs);
+                       break;
+               }
+       }
+
+       return 0;
+}
+
+/* print command = print-test %p %s */
+
+static int print_command(int argc, char **argv)
+{
+       char *printer;
+       fstring keystr;
+       struct passwd *pw;
+       TDB_DATA value;
+       struct vlp_job job;
+       int i;
+
+       if (argc < 3) {
+               printf("Usage: print <printername> <jobname>\n");
+               return 1;
+       }
+
+       printer = argv[1];
+
+       ZERO_STRUCT(job);
+
+       /* Create a job record */
+
+       for (i = 2; i < argc; i++) {
+               fstrcat(job.jobname, argv[i]);
+               if (i < argc - 1) {
+                       fstrcat(job.jobname, " ");
+               }
+       }
+
+       if (!(pw = getpwuid(getuid()))) {
+               return 1;
+       }
+
+       fstrcpy(job.owner, pw->pw_name);
+
+       job.jobid = next_jobnum(printer);
+       job.size = 666;
+       job.submit_time = time(NULL);
+
+       /* Store job entry in queue */
+
+       slprintf(keystr, sizeof(keystr) - 1, "LPQ/%s", printer);
+       
+       value = tdb_fetch_by_string(tdb, keystr);
+
+       if (value.dptr) {
+
+               /* Add job to end of queue */
+
+               value.dptr = realloc(value.dptr, value.dsize + 
+                                    sizeof(struct vlp_job));
+               if (!value.dptr) return 1;
+
+               memcpy(value.dptr + value.dsize, &job, sizeof(struct vlp_job));
+
+               tdb_store_by_string(tdb, keystr, value.dptr, value.dsize +
+                                   sizeof(struct vlp_job));
+
+               free(value.dptr);
+
+       } else {
+               
+               /* Create new queue */
+
+               tdb_store_by_string(tdb, keystr, &job, sizeof(struct vlp_job));
+       }               
+
+       return 0;
+}
+
+/* Pause the queue */
+
+static int queuepause_command(int argc, char **argv)
+{
+       char *printer;
+
+       if (argc != 2) {
+               printf("Usage: queuepause <printername>\n");
+               return 1;
+       }
+
+       printer = argv[1];
+       set_printer_status(printer, LPSTAT_STOPPED);
+
+       return 0;
+}
+
+/* Resume the queue */
+
+static int queueresume_command(int argc, char **argv)
+{
+       char *printer;
+
+       if (argc != 2) {
+               printf("Usage: queueresume <printername>\n");
+               return 1;
+       }
+
+       printer = argv[1];
+       set_printer_status(printer, LPSTAT_OK);
+
+       return 0;
+}
+
+/* Pause a job */
+
+static int lppause_command(int argc, char **argv)
+{
+       struct vlp_job *job_list;
+       char *printer;
+       int jobid, num_jobs, i;
+
+       if (argc != 3) {
+               printf("Usage: lppause <printername> <jobid>\n");
+               return 1;
+       }
+
+       printer = argv[1];
+       jobid = atoi(argv[2]);
+
+       get_job_list(printer, &job_list, &num_jobs);
+
+       for (i = 0; i < num_jobs; i++) {
+               if (job_list[i].jobid == jobid) {
+                       job_list[i].status = LPQ_PAUSED;
+                       set_job_list(printer, job_list, num_jobs);
+                       return 0;
+               }
+       }
+
+       return 1;
+}
+
+/* Resume a job */
+
+static int lpresume_command(int argc, char **argv)
+{
+       struct vlp_job *job_list;
+       char *printer;
+       int jobid, num_jobs, i;
+
+       if (argc != 3) {
+               printf("Usage: lpresume <printername> <jobid>\n");
+               return 1;
+       }
+
+       printer = argv[1];
+       jobid = atoi(argv[2]);
+
+       get_job_list(printer, &job_list, &num_jobs);
+
+       for (i = 0; i < num_jobs; i++) {
+               if (job_list[i].jobid == jobid) {
+                       job_list[i].status = LPQ_QUEUED;
+                       set_job_list(printer, job_list, num_jobs);
+                       return 0;
+               }
+       }
+
+       return 1;
+}
+
+int main(int argc, char **argv)
+{
+       /* Parameter check */
+
+       if (argc == 1) {
+               usage();
+               return 1;
+       }
+
+       /* Initialise */
+
+       if (!(tdb = tdb_open(PRINT_TDB, 0, 0, O_RDWR | O_CREAT,
+                            0666))) {
+               printf("%s: unable to open %s\n", argv[0], PRINT_TDB);
+               return 1;
+       }
+
+       /* Ensure we are modes 666 */
+
+       chmod(PRINT_TDB, 0666);
+
+       /* Do commands */
+
+       if (strcmp(argv[1], "lpq") == 0) {
+               return lpq_command(argc - 1, &argv[1]);
+       }
+
+       if (strcmp(argv[1], "lprm") == 0) {
+               return lprm_command(argc - 1, &argv[1]);
+       }
+
+       if (strcmp(argv[1], "print") == 0) {
+               return print_command(argc - 1, &argv[1]);
+       }
+
+       if (strcmp(argv[1], "queuepause") == 0) {
+               return queuepause_command(argc - 1, &argv[1]);
+       }
+
+       if (strcmp(argv[1], "queueresume") == 0) {
+               return queueresume_command(argc - 1, &argv[1]);
+       }
+
+       if (strcmp(argv[1], "lppause") == 0) {
+               return lppause_command(argc - 1, &argv[1]);
+       }
+
+       if (strcmp(argv[1], "lpresume") == 0) {
+               return lpresume_command(argc - 1, &argv[1]);
+       }
+
+       /* Unknown command */
+
+       printf("%s: invalid command %s\n", argv[0], argv[1]);
+       return 1;
+}