home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / xqms1.exe / SUBMTJOB.C next >
C/C++ Source or Header  |  1995-08-25  |  7KB  |  248 lines

  1. /**************************************************************************
  2. ** File: submtjob.c
  3. **
  4. ** Desc: Sample NLM to submit a print job to a queue
  5. **
  6. **
  7. **   DISCLAIMER  
  8. **  
  9. **   Novell, Inc. makes no representations or warranties with respect to
  10. **   any NetWare software, and specifically disclaims any express or
  11. **   implied warranties of merchantability, title, or fitness for a
  12. **   particular purpose.  
  13. **
  14. **   Distribution of any NetWare software is forbidden without the
  15. **   express written consent of Novell, Inc.  Further, Novell reserves
  16. **   the right to discontinue distribution of any NetWare software.
  17. **   
  18. **   Novell is not responsible for lost profits or revenue, loss of use
  19. **   of the software, loss of data, costs of re-creating lost data, the
  20. **   cost of any substitute equipment or program, or claims by any party
  21. **   other than you.  Novell strongly recommends a backup be made before
  22. **   any software is installed.   Technical support for this software
  23. **   may be provided at the discretion of Novell.
  24. **
  25. ** QMK386 Options
  26. **    none
  27. **
  28. ** Programmers:
  29. **
  30. **    Ini   Who                  Firm
  31. **    ---------------------------------------------------------------------
  32. **    DWH   Dirk W. Howard       Novell Developer Support
  33. **
  34. **
  35. ** History:
  36. **
  37. **    When        Who      What
  38. **    ---------------------------------------------------------------------
  39. **    8-11-1995    DWH      First code.
  40. **
  41. */
  42.  
  43. /****************************************************************************
  44. **   Include headers, macros, etc.
  45. */
  46.    /*------------------------------------------------------------------------
  47.    **   ANSI C.
  48.    */
  49.    #include <stdlib.h>  /* exit()    */
  50.    #include <stdio.h>   /* printf()  */
  51.    #include <string.h>  /* strupr()  */
  52.    #include <io.h>      /* write()   */
  53.    #include <conio.h>   /* clrscr()  */
  54.    #include <errno.h>
  55.  
  56.    /*------------------------------------------------------------------------
  57.    **   NetWare Library
  58.    */
  59.    #include <nwqueue.h>
  60.    #include <nwps_job.h>
  61.    #include <nwbindry.h>
  62.    #include <nwmisc.h>
  63.  
  64.  
  65. /****************************************************************************
  66. ** Global variables.
  67. */
  68.  
  69.  
  70. /****************************************************************************
  71. ** Main program start.
  72. */
  73. void main(int argc, char *argv[]){
  74.  
  75.   int          ccode;
  76.   LONG         printQID;
  77.   NWQJobRec_t  jobInfo;
  78.   int          jobFile;
  79.   NWPS_ClientRecord *psInfo;        /* this is the struct pointer for the
  80.                                         clientRecordArea in jobInfo         */
  81.   char queueName[48];
  82.  
  83.   if (argc < 2){
  84.      clrscr();
  85.      printf( "USAGE: LOAD %s <queueName>\n", argv[0] );
  86.      goto EXIT;
  87.   }
  88.  
  89.   strcpy( queueName,strupr( argv[1] ) );
  90.  
  91.   /*------------------------------------------------------------------------
  92.   ** Get the object ID for the desired print queue to print to.
  93.   */
  94.   ccode = GetBinderyObjectID(
  95.         /*   >   objectName   */   queueName,
  96.         /*   >   objectType   */   OT_PRINT_QUEUE,
  97.         /*   <   objectID     */   (long *)&printQID);
  98.  
  99.   switch(ccode)
  100.   {
  101.      case ESUCCESS:
  102.         break;
  103.  
  104.      default:
  105.         printf("ERROR:  Unknown error GetBinderyObjectID: %d\n", ccode);
  106.         goto EXIT;
  107.   }
  108.  
  109.   /*------------------------------------------------------------------------
  110.   **   Fill out jobInfo structure.
  111.   */
  112.   memset(&jobInfo, 0x00, sizeof(jobInfo));   /* zero out structure */
  113.  
  114.   /*------------------------------------------------------------------------
  115.   **   Wildcard: any print server may service this job.
  116.   */
  117.  
  118.    jobInfo.target.id = 0xFFFFFFFFL;
  119.  
  120.    memset(&jobInfo.target.executionTime, 0xFF, 6);   /* 0xFFFFFFFFFFFF: ASAP */
  121.    jobInfo.job.controlFlags |= 0x10;
  122.  
  123.   /*------------------------------------------------------------------------
  124.   **   Fill out NetWare Print Server specific information in the clientRecord
  125.   ** Area of the jobInfo structure.
  126.   */
  127.   psInfo = (NWPS_ClientRecord *)(jobInfo.jobServerRecord);
  128.   psInfo->versionNumber      =   0;
  129.   psInfo->tabSize            =   8;
  130.   psInfo->numberOfCopies     =   IntSwap(1);
  131.   psInfo->printControlFlags  =   NWPS_JOB_NO_FORMFEED;
  132.   psInfo->maxLinesPerPage    =   IntSwap(66);
  133.   psInfo->maxCharsPerLine    =   IntSwap(132);
  134.   psInfo->formName[0]        =   '\0';
  135.   /* psInfo->reserved[9]; */
  136.   strcpy(psInfo->bannerNameField,"BannerName");
  137.   strcpy(psInfo->bannerFileField,"BannerFile");
  138.   strcpy(psInfo->headerFileName, "HeaderName");
  139.   psInfo->directoryPath[0]   =   '\0';
  140.  
  141.   /*------------------------------------------------------------------------
  142.   ** Create a queue file using the known ID and connection handle
  143.   */
  144.   ccode=NWQCreateJob(
  145.      /* >  queueID         */ printQID,
  146.      /* <> jobStructure    */ &jobInfo,
  147.      /* <  fileHandle      */ &jobFile
  148.      );
  149.   switch(ccode)
  150.   {
  151.      case ESUCCESS:
  152.         break;
  153.  
  154.      case 0xD3:
  155.         printf("ERROR:  NO rights to print queue: %s.\n", queueName);
  156.         goto EXIT;
  157.  
  158.      default:
  159.         printf("ERROR:  Unknown error NWCreateQueueFile2: 0x%04X\n", ccode);
  160.         goto EXIT;
  161.   }
  162.  
  163.  
  164.   /*------------------------------------------------------------------------
  165.   ** Print job
  166.   */
  167.   write(jobFile,"this is a test",14);
  168.  
  169.  
  170.   /*------------------------------------------------------------------------
  171.   ** Close print job now that data has been sent.
  172.   */
  173.   ccode=NWQMarkJobForService(
  174.         /* >  queueID     */   printQID,
  175.         /* >  jobNumber   */   jobInfo.job.num,
  176.         /* >   fileHandle  */   jobFile);
  177.  
  178.   switch(ccode)
  179.   {
  180.      case ESUCCESS:
  181.         break;
  182.  
  183.      case 0x99:
  184.         printf("ERROR:  Queue directory full.\n");
  185.         break;
  186.  
  187.      case 0xD0:
  188.         printf("ERROR:  Queue I/O failure.\n");
  189.         break;
  190.  
  191.      case 0xD1:
  192.         printf("ERROR:  No such queue.\n");
  193.         break;
  194.  
  195.      case 0xD2:
  196.         printf("ERROR:  No queue server.\n");
  197.         break;
  198.  
  199.      case 0xD3:
  200.         printf("ERROR: NO rights to print in queue.\n");
  201.         break;
  202.  
  203.      case 0xD4: /* ERR_QUEUE_FULL */
  204.         printf("ERROR: Print queue full.\n");
  205.         break;
  206.  
  207.      case 0xD5:
  208.         printf("ERROR: Invalid job number specified.\n");
  209.         break;
  210.  
  211.      case 0xD6:
  212.         printf("ERROR: NO rights to place a job into this queue\n.");
  213.         break;
  214.  
  215.      case 0xD7:
  216.         printf("ERROR: Queue being serviced now and not accepting jobs\n.");
  217.         break;
  218.  
  219.      case 0xD8:
  220.         printf("ERROR: Queue currently not active and not accepting jobs\n.");
  221.         break;
  222.  
  223.      case 0xD9:
  224.         printf("ERROR:  The Queue Station is not a Server\n.");
  225.         break;
  226.  
  227.      case 0xDA:
  228.         printf("ERROR:  Queue is currently halted and not accepting jobs\n.");
  229.         break;
  230.  
  231.      case 0xDB:
  232.         printf("ERROR:  Too many servers\n.");
  233.         break;
  234.  
  235.      case   0xFF:
  236.         printf("ERROR:   General failure NWQMarkJobForService\r\n.");
  237.         break;
  238.  
  239.      default:
  240.         printf("Unknown error NWQMarkJobForService: %d\n", ccode);
  241.         break;
  242.   }
  243.  
  244.   EXIT:
  245.   return;
  246.  
  247. }
  248.