home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / printq.exe / READQ.C < prev    next >
Text File  |  1995-01-09  |  9KB  |  253 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:   READQ.C
  22. **
  23. **      Desc:   This program will read a print queue then take the file in 
  24. **              the queue and write it out to a file called printq.out.
  25. **              This utility tests the Novell Queue Servicing APIs
  26. **              Note: The USER logged in must be in the QUEUE SERVER list in
  27. **              the bindry to attach to the queue.  Since PCONSOLE does not
  28. **              have this functionality, the ADDPSERV.C utility has been
  29. **              provided.
  30. **              This program will take the first 'READY' job from the
  31. **              queue and write it to file (printq.OUT).
  32. **
  33. **      Parameter descriptions:    > input
  34. **                                 < output
  35. **
  36. ** 
  37. **      Programmers:
  38. **      Ini   Who                     Firm
  39. **      ------------------------------------------------------------------
  40. **      ARM   A. Ray Maxwell          Novell Developer Support.
  41. **
  42. **      History:
  43. **
  44. **      ------------------------------------------------------------------
  45. **      08-19-94      ARM     First code.
  46. */
  47.  
  48. /***************************************************************************
  49. **      Include headers, macros, function prototypes, etc.
  50. */
  51.  
  52.    /*------------------------------------------------------------------
  53.    **      ANSI
  54.    */
  55.    #include <stdlib.h>             /* exit(), atol()                 */
  56.    #include <stdio.h>              /* sprintf()                      */
  57.    #include <string.h>             /* strupr(), strcpy               */
  58.    #include <io.h>                 /* eof()                          */
  59.    #include <fcntl.h>              /* open()                         */
  60.    #include <sys\stat.h>           /* open()                         */
  61.  
  62.    /*------------------------------------------------------------------
  63.    **      NetWare
  64.    */
  65.    #include <nwcalls.h>
  66.     
  67.    /*------------------------------------------------------------------
  68.    **Defines
  69.    */
  70.    #define NWDOS
  71.  
  72.  
  73. /****************************************************************************
  74. **      Program Start
  75. */
  76. void main(int argc, char *argv[])
  77. {
  78.    /*-----------------------------------------------------------------------
  79.    **  NWGetQueueJobList2 parameters
  80.    */
  81.    QueueJobListReply job;
  82.    NWNUM             startPosition = 0;
  83.  
  84.    /*-----------------------------------------------------------------------
  85.    **  NWServiceQueueJob2 parameters
  86.    */
  87.    NWQueueJobStruct  queueJob;
  88.    NWFILE_HANDLE     nwfHandle;
  89.  
  90.    NWSIZE            fileSize; /* queue jobs file size NWGetQueueJobFileSize2 */
  91.    NWCONN_HANDLE     connHandle;
  92.    CONNECT_INFO      connInfo;
  93.    NWCONN_NUM        connNumber;
  94.    NWOBJ_ID          objectID;
  95.    NWOBJ_ID          queObjectID;
  96.    NWCCODE           ccode;
  97.    BYTE              loginTime;
  98.    char              server[50];
  99.    char              queObjectName[50];
  100.    char              objectName[50];
  101.    int               hout;    /* dos file handle */
  102.    unsigned char     buf[8192];
  103.    int               eofCheck;
  104.    int               jobNumber = 0;
  105.    long              processed = 0L;
  106.    int               cnt=1;
  107.    long              fileposition;
  108.    int               fhandle;
  109.  
  110.    if(argc != 3) {
  111.       printf("Usage: READQ <servername> <queue name>\n");
  112.       exit(1);
  113.    }
  114.  
  115.    strcpy(server,  strupr(argv[1]));
  116.    strcpy(queObjectName, strupr(argv[2]));
  117.  
  118.    ccode = NWCallsInit(NULL, NULL);
  119.  
  120.    if(ccode)
  121.       exit(1);
  122.  
  123.    ccode = NWGetConnectionHandle(
  124.            /* > servername        */ server,
  125.            /*   Novell Reserved1  */ 0,
  126.            /* < connection Handle */ &connHandle,
  127.            /*   Novell Reserved2  */ NULL);
  128.  
  129.    if(ccode)
  130.       exit(1);
  131.    ccode = NWGetConnectionNumber(connHandle,&connNumber);
  132.    if(ccode)
  133.       exit(1);
  134.  
  135.    ccode = NWGetConnectionInformation(
  136.            /* > Connection Handle             */  connHandle,
  137.            /* > Server connection Number      */   connNumber,
  138.            /* < Pointer to Object Name        */  objectName,
  139.            /* < Pointer to bindry Object Type */    NULL,
  140.            /* < Pointer to bindry Object ID   */   &objectID,
  141.            /* < Pointer to time               */   &loginTime);
  142.    if(ccode)
  143.       exit(1);
  144.  
  145.    ccode = NWGetObjectID(
  146.            /* > connection Handle             */ connHandle,
  147.            /* > connection Handle             */ queObjectName,
  148.            /* > Pointer to name of object     */ OT_PRINT_QUEUE,
  149.            /* < Pointer to the found object ID*/ &queObjectID);
  150.    if(ccode)
  151.       exit(1);
  152.  
  153.    ccode = NWAttachQueueServerToQueue(
  154.            /* > connection Handle             */ connHandle,
  155.            /* > bindery object ID of queue      */ queObjectID);
  156.    if(ccode)
  157.       exit(1);
  158.  
  159.  
  160.    ccode = NWGetQueueJobList2(
  161.            /* > connection Handle             */ connHandle,
  162.            /* > bindery object ID             */ queObjectID,
  163.            /* > position of next job          */ startPosition,
  164.            /* < Pointer to array of job nums  */ &job);
  165.    if(ccode)
  166.       exit(1);
  167.  
  168.    ccode = NWReadQueueJobEntry2(
  169.            /* > connection Handle             */ connHandle,
  170.            /* > bindery object ID of queue    */ queObjectID,
  171.            /* > Number of Job being read      */ job.jobNumberList[0],
  172.            /* < Pointer to NWWueueJobStruct   */ &queueJob);
  173.    if (ccode)
  174.       exit(1);
  175.  
  176.    if(job.totalQueueJobs){  /* check to see if there are any jobs in queue */
  177.  
  178.  
  179.  
  180.      /*----------------------------------------------------------------------
  181.      ** NOTE: The following function call will not work with the SDK V1.0e the
  182.      **       problems have been fixed and work with the 4.02 SDK 
  183.      **       being released mid to end of OCT, 1994.
  184.      */
  185.       ccode = NWServiceQueueJob2(
  186.               /* > connection Handle          */ connHandle,
  187.               /* > bindery object ID          */ queObjectID,
  188.               /* > Type of job to be serviced */ 0,
  189.               /* < Pointer to NWWueueJobStruct*/ &queueJob,
  190.               /* < Pointer to file handle     */ &nwfHandle);
  191.       if(ccode)
  192.          exit(1);
  193.  
  194.       ccode = NWGetQueueJobFileSize2(
  195.               /* > connection Handle          */ connHandle,
  196.               /* > bindery object ID          */ queObjectID,
  197.               /* > number of job for info     */ queueJob.jobNumber,
  198.               /* < Pointer queue job file size*/ &fileSize);
  199.       if(ccode)
  200.          exit(1);
  201.  
  202.  
  203.    }
  204.    else {
  205.       ccode = NWAbortServicingQueueJob2(
  206.               /* > connection Handle          */ connHandle,
  207.               /* > bindery object ID of queue */ queObjectID,
  208.               /* > number of job for info     */ queueJob.jobNumber,
  209.               /* > Pointer to file handle     */ nwfHandle);
  210.       printf("there are no jobs in the print queue");
  211.       exit (1);
  212.       }
  213.  
  214.     hout = open( "printq.out", O_CREAT|O_TRUNC|O_BINARY|O_WRONLY, S_IWRITE);
  215.     if (hout<0 )
  216.       printf("\nFailed.  Could not open output file.");
  217.  
  218.  
  219.       do{
  220.          cnt=read(nwfHandle, buf, sizeof(buf));
  221.          write (hout, buf,cnt);
  222.         processed+=cnt;
  223.      }while(cnt!=0 && cnt!=-1); 
  224.    close(hout);
  225.  
  226.    if (processed<fileSize) {
  227.       printf( "\nProcessing failure: %ld bytes of %ld processed",
  228.               processed,
  229.               fileSize);
  230.       ccode = NWAbortServicingQueueJob2(
  231.               /* > connection Handle          */ connHandle,
  232.               /* > bindery object ID of queue */ queObjectID,
  233.               /* > number of job for info     */ queueJob.jobNumber,
  234.               /* > Pointer to file handle     */ nwfHandle);
  235.    }
  236.    ccode = NWFinishServicingQueueJob2( 
  237.            /* > connection Handle          */ connHandle,
  238.            /* > bindery object ID of queue */ queObjectID,
  239.            /* > number of job for info     */ queueJob.jobNumber,
  240.            /* > Pointer to file handle     */ nwfHandle);
  241.    if (ccode)
  242.       printf("\nNWFinishServicingQueueJobAndFile Error: %X\n", ccode);
  243.    else {
  244.       printf( "\nProcessed Job successfully:\nJobNum: %ld    size: %d",
  245.               queueJob.jobNumber,
  246.               fileSize);
  247.    }
  248.  
  249.    NWDetachQueueServerFromQueue( connHandle,
  250.                   queObjectID);
  251.    printf("\nSuccess\n");
  252. }
  253.