home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / prtinf.exe / RDINFO.C < prev    next >
Text File  |  1995-07-25  |  10KB  |  280 lines

  1. /****************************************************************************
  2. **              DISCLAIMER  
  3. **  
  4. **      Novell, Inc. makes no representations or warranties with respect to
  5. **      any NetWare software, and specifically disclaims any express or
  6. **      implied warranties of merchantability, title, or fitness for a
  7. **      particular purpose.  
  8. **
  9. **      Distribution of any NetWare software is forbidden without the
  10. **      express written consent of Novell, Inc.  Further, Novell reserves
  11. **      the right to discontinue distribution of any NetWare software.
  12. **      
  13. **      Novell is not responsible for lost profits or revenue, loss of use
  14. **      of the software, loss of data, costs of re-creating lost data, the
  15. **      cost of any substitute equipment or program, or claims by any party
  16. **      other than you.  Novell strongly recommends a backup be made before
  17. **      any software is installed.   Technical support for this software
  18. **      may be provided at the discretion of Novell.
  19. ****************************************************************************
  20. **
  21. **      File:   QINFO.C
  22. **
  23. **      Desc:   This program will read a print queue for jobs and then print
  24. **              out some information that is seen on the screen in pconsole.
  25. **      NOTE:   This code is used principally to show how the job number is
  26. **              derived in pconsole and also to show the job status.
  27. **
  28. **      Parameter descriptions:    > input
  29. **                                 < output
  30. **
  31. **
  32. **      Programmers:
  33. **      Ini   Who                     Firm
  34. **      ------------------------------------------------------------------
  35. **      ARM   A. Ray Maxwell          Novell Developer Support.
  36. **
  37. **      History:
  38. **
  39. **      ------------------------------------------------------------------
  40. **      07-25-95      ARM     First code.
  41. */
  42.  
  43. /***************************************************************************
  44. **      Include headers, macros, function prototypes, etc.
  45. */
  46.  
  47.    /*------------------------------------------------------------------
  48.    **      ANSI
  49.    */
  50.    #include <stdlib.h>             /* exit(), atol()                 */
  51.    #include <stdio.h>
  52.    #include <string.h>             /* strupr(), strcpy               */
  53.  
  54.    /*------------------------------------------------------------------
  55.    **      NetWare
  56.    */
  57.    #include <nwcalls.h>
  58.  
  59.    /*------------------------------------------------------------------
  60.    **Defines
  61.    */
  62.    #define NWDOS
  63.    #define OPEN    1
  64.    #define HELD    2
  65.    #define ACTIVE  3
  66.    #define READY   4
  67.    #define WAITING 5
  68.  
  69.    /*------------------------------------------------------------------
  70.    ** Prototypes
  71.    */
  72.    int GetJobStatus(BYTE JobControlFlags,
  73.                     BYTE targetTime[],
  74.                     long serverID,
  75.                     NWCONN_HANDLE connHandle);
  76.  
  77.  
  78.    /*------------------------------------------------------------------
  79.    ** Global Variables
  80.    */
  81.    /*========================================================
  82.    This structure is overlayed on the QMS
  83.    NWQueueJobStruct.clientRecordArea to define a print job.
  84.    It is not used in any of the print services APIs.
  85.    (Formerly called NWPS_PJob.)
  86.    NOTE: This structure is defined in the NWPS_JOB.H header file and
  87.          is included here to show the devoloper how it can be used.
  88.    ========================================================*/
  89.    typedef struct {
  90.       BYTE                  versionNumber;
  91.       BYTE                  tabSize;
  92.       WORD                  numberOfCopies;
  93.       WORD                  printControlFlags;
  94.       WORD                  maxLinesPerPage;
  95.       WORD                  maxCharsPerLine;
  96.       BYTE                  formName[13];
  97.       BYTE                  reserve[9];
  98.       BYTE                  bannerNameField[13];
  99.       BYTE                  bannerFileField[13];
  100.       BYTE                  headerFileName[14];
  101.       BYTE                  directoryPath[80];
  102.    }  NWPS_ClientRecord;
  103.  
  104.  
  105. /****************************************************************************
  106. **      Program Start
  107. */
  108. void main(int argc, char *argv[])
  109. {
  110.    QueueJobListReply job;
  111.    NWCONN_NUM        connNumber;
  112.    NWNUM             startPosition = 0;
  113.    NWQueueJobStruct  queueJob;
  114.    NWCONN_HANDLE     connHandle;
  115.    NWOBJ_ID          queObjectID;
  116.    NWCCODE           ccode;
  117.    NWPS_ClientRecord *clientRecord;
  118.    char              server[50];
  119.    char              queObjectName[50];
  120.    char              statusString[8];
  121.    int i;                        
  122.    int status;
  123.    
  124.    if(argc != 3) {
  125.       printf("Usage: QINFO <servername> <queue name>\n");
  126.       exit(1);
  127.    }
  128.  
  129.    strcpy(server,  strupr(argv[1]));
  130.    strcpy(queObjectName, strupr(argv[2]));
  131.  
  132.    ccode = NWCallsInit(NULL, NULL);
  133.  
  134.    if(ccode)
  135.    {
  136.       printf("NWCallsInit failed %X\n",ccode);
  137.       exit(1);
  138.    }
  139.  
  140.    ccode = NWGetConnectionHandle(
  141.            /* > servername        */ server,
  142.            /*   Novell Reserved1  */ 0,
  143.            /* < connection Handle */ &connHandle,
  144.            /*   Novell Reserved2  */ NULL);
  145.    if(ccode)
  146.    {
  147.       printf("NWGetConnectionHandle failed: %X\n",ccode);
  148.       exit(1);
  149.    }
  150.  
  151.    ccode = NWGetConnectionNumber(connHandle,&connNumber);
  152.    if(ccode)
  153.    {
  154.       printf("NWGetConnectionNumber failed: %X\n",ccode);
  155.       exit(1);
  156.    }
  157.  
  158.  
  159.    ccode = NWGetObjectID(
  160.            /* > connection Handle             */ connHandle,
  161.            /* > connection Handle             */ queObjectName,
  162.            /* > Pointer to name of object     */ OT_PRINT_QUEUE,
  163.            /* < Pointer to the found object ID*/ &queObjectID);
  164.    if(ccode)
  165.    {
  166.       printf("NWGetObjectID failed: %X\n",ccode);
  167.       exit(1);
  168.    }
  169.  
  170.  
  171.    ccode = NWGetQueueJobList2(
  172.            /* > connection Handle             */ connHandle,
  173.            /* > bindery object ID             */ queObjectID,
  174.            /* > position of next job          */ startPosition,
  175.            /* < Pointer to array of job nums  */ &job);
  176.    if(ccode)
  177.    {
  178.       printf("NWGetQueueJobList2 failed: %X\n",ccode);
  179.       exit(1);
  180.    }
  181.  
  182.    printf("Print Job Status\n\n");
  183.    printf("Seq  BannerName   Description     Form Status   Job\n");
  184.  
  185.    clientRecord=(NWPS_ClientRecord *) queueJob.clientRecordArea;
  186.  
  187.    for(i=0;i<job.totalQueueJobs;i++)
  188.    {
  189.       ccode = NWReadQueueJobEntry2(
  190.               /* > connection Handle             */ connHandle,
  191.               /* > bindery object ID of queue    */ queObjectID,
  192.               /* > Number of Job being read      */ job.jobNumberList[i],
  193.               /* < Pointer to NWQueueJobStruct   */ &queueJob);
  194.       if (ccode)
  195.       {
  196.          printf("NWReadQeueueJobEntry2 failed: %X\n",ccode);
  197.          exit(1);
  198.       }
  199.       status=GetJobStatus(queueJob.jobControlFlags,
  200.                           queueJob.targetExecutionTime,
  201.                           queueJob.servicingServerID,
  202.                           connHandle);
  203.  
  204.       switch(status)
  205.       {
  206.          case OPEN      : strcpy(statusString,"OPEN");
  207.                           break;
  208.          case HELD      : strcpy(statusString,"HELD");
  209.                             break;
  210.          case ACTIVE    : strcpy(statusString,"ACTIVE");
  211.                           break;
  212.          case READY     : strcpy(statusString,"READY");
  213.                           break;
  214.          case WAITING   : strcpy(statusString,"WAITING");
  215.                           break;
  216.          default        : break;
  217.       }
  218.    /*-----------------------------------------------------------------------
  219.    **  Note the jobNumber is WordSwapped and then printed with %5u.
  220.    */
  221.    printf("%d    %s   %s      %d    %s    %5u\n",
  222.              queueJob.jobPosition,
  223.              clientRecord->bannerNameField,
  224.              queueJob.jobDescription,
  225.              queueJob.jobType,
  226.              statusString,
  227.              NWWordSwap(queueJob.jobNumber));
  228.  
  229.    }
  230. }
  231.  
  232. /***************************************************************************
  233. ** Get the job status
  234. */
  235. int GetJobStatus(BYTE jobControlFlags,
  236.                  BYTE targetTime[],
  237.                  long serverID,
  238.                  NWCONN_HANDLE connHandle)
  239. {
  240.    BYTE currentTime[7];         /* Current time from server           */   
  241.    int  status,               /* Status of this job                 */
  242.         printNow;             /* To be printed as soon as possible? */
  243.  
  244.    /*-----------------------------------------------------------------------
  245.    **   Is the job still open?
  246.    */
  247.    if (jobControlFlags & QF_ENTRY_OPEN)
  248.             status = OPEN;
  249.  
  250.    /*-----------------------------------------------------------------------
  251.    **   Is the job on hold?
  252.    */
  253.    else if (jobControlFlags & (QF_OPERATOR_HOLD | QF_USER_HOLD))
  254.       status = HELD;
  255.  
  256.    /*-----------------------------------------------------------------------
  257.    **   Is the job active?
  258.    */
  259.    else if (serverID != 0L)
  260.       status = ACTIVE;
  261.  
  262.    /*-----------------------------------------------------------------------
  263.       The job is either ready or waiting.  Assume its ready unless
  264.       there is a target time and that time has not arrived yet.
  265.    */
  266.    else
  267.    {
  268.       status = READY;
  269.       printNow = memcmp(targetTime, "\xff\xff\xff\xff\xff\xff", 6 ) == 0;
  270.  
  271.       if (!printNow)
  272.       {
  273.          NWGetFileServerDateAndTime(connHandle, currentTime);
  274.          if (memcmp(currentTime, targetTime, (WORD)6) <  0)
  275.             status = WAITING;
  276.       }
  277.    }
  278.    return (status);
  279. }
  280.