home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / an401x.exe / DOIT.C next >
C/C++ Source or Header  |  1993-11-24  |  5KB  |  146 lines

  1. /*
  2.  ████████████████████████████████████████████████████████████████████████████
  3.  █                                                                          █
  4.  █ doit.c                                                                   █
  5.  █                                                                          █
  6.  █ Submit a "job" to the job server.  A job is a DOS command line.          █
  7.  █                                                                          █
  8.  ████████████████████████████████████████████████████████████████████████████
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <ctype.h>
  14. #include <mem.h>
  15. #include <conio.h>
  16. #include <io.h>
  17. #include <string.h>
  18. #include "..\doit.h"
  19. #include <nwcalls.h>
  20. #include "..\doitacct.h"
  21.  
  22. #define NWDOS
  23.  
  24. void main()
  25. {
  26.     NWCCODE                cCode;
  27.     char                response;
  28.     DWORD                queueID,
  29.                         serverID;
  30.     NWFILE_HANDLE        fileHandle;
  31.     NWCONN_NUM            connNumber;
  32.     char                userName[48];
  33.     char                inBuf[255];
  34.     size_t                buflen;
  35.     NWCONN_HANDLE        connID;
  36.     NWQueueJobStruct    jobStructure;
  37.     long                balance;
  38.     long                limit;
  39.     long                charge;
  40.  
  41.     cCode = NWCallsInit(NULL, NULL);
  42.     if (cCode == 0)
  43.         printf("Call to NWCallsInit successful\n");
  44.     else {
  45.         printf("Call to NWCallsInit failed\n");
  46.         exit(-1);
  47.     }
  48.  
  49.     /* Get the connection ID of the file server that has the job server's queue */
  50.     cCode = NWGetDefaultConnectionID(&connID);
  51.     if (cCode == 0)
  52.         printf("Call to NWGetDefaultConnectionID successful\n");
  53.     else {
  54.         printf("Call to NWGetDefaultConnectionID failed\n");
  55.         exit(-1);
  56.     }
  57.  
  58.     /* get your connection number */
  59.     cCode = NWGetConnectionNumber(connID, &connNumber);
  60.     if (cCode != 0) {
  61.         printf("Unable to get your connection number to default server\n");
  62.         exit(-1);
  63.     }
  64.  
  65.     /* get user name */
  66.     cCode = NWGetConnectionInformation(connID, connNumber, userName, NULL, NULL, NULL);
  67.     if (cCode != 0) {
  68.         printf("Unable to get your user name\n");
  69.         exit(-1);
  70.     }
  71.  
  72.     /* get the bindery object ID of the job server */
  73.     cCode = NWGetObjectID(connID, JOBSERV_NAME, OT_DOIT, &serverID);
  74.     if (cCode == 0)
  75.         printf("Call to NWGetObjectID successful\n");
  76.     else
  77.         printf("Call to NWGetObjectID failed, cCode = %X\n", cCode);
  78.  
  79.     /* get the bindery object ID of the queue */
  80.     cCode = NWGetObjectID(connID, JOBSERV_NAME, OT_DOIT_Q, &queueID);
  81.     if (cCode == 0)
  82.         printf("Call to NWGetObjectID successful\n");
  83.     else
  84.         printf("Call to NWGetObjectID failed, cCode = %X\n", cCode);
  85.  
  86.     /* fill in the job entry structure */
  87.  
  88.     /* set the target server to that of the job server.*/
  89.     jobStructure.targetServerID = serverID;
  90.  
  91.     /* set the target execution time to immediate */
  92.     memset(jobStructure.targetExecutionTime, 0xFF, 6);
  93.  
  94.     /* set the target jobType according to job priority */
  95.     printf("High priority job?\n");
  96.     do {
  97.         printf("Y/N >");
  98.         response = toupper(getche());
  99.         printf("\n");
  100.     } while ((response != 'Y') && (response != 'N'));
  101.     if (response == 'Y') {
  102.        jobStructure.jobType = DOIT_JOB_PRIORITY_1;
  103.        charge = 2L;
  104.     } else {
  105.        jobStructure.jobType = DOIT_JOB_PRIORITY_2;
  106.        charge = 1L;
  107.     }
  108.  
  109.     /* make sure user has enough credit to submit job
  110.        job server also checks, but submitting program can save the user
  111.        the trouble of submitting a job and having it fail in the job server */
  112.     cCode = DoItGetAccountStatus(connID, OT_USER, userName, &balance, &limit);
  113.     if (cCode != SUCCESSFUL) {
  114.         printf("You are not authorized to submit jobs\n");
  115.         exit(-1);
  116.     } else if ((balance < charge) || (balance - charge < limit)) {
  117.         printf("Insufficient credit to submit jobs\n");
  118.         exit(-1);
  119.     }
  120.  
  121.     /* set the job for auto start */
  122.     jobStructure.jobControlFlags = 0x08;
  123.  
  124.     /* ceate a queue file so you can get back a file handle to write to */
  125.     cCode = NWCreateQueueFile2(connID, queueID, &jobStructure, &fileHandle);
  126.     if (cCode == 0)
  127.         printf("Call to NWCreateQueueFile2 successful\n");
  128.     else
  129.         printf("Call to NWCreateQueueFile2 failed, cCode = %X\n", cCode);
  130.  
  131.     /* get a command to send to the job server for execution */
  132.     printf("Please input a DOS command:");
  133.     gets(inBuf);
  134.     buflen = strlen(inBuf);
  135.  
  136.     /* write the command to the job file */
  137.     write(fileHandle,inBuf,buflen) ;
  138.  
  139.     /* close the file */
  140.     cCode = NWCloseFileAndStartQueueJob2(connID, queueID, jobStructure.jobNumber, fileHandle);
  141.     if (cCode == 0)
  142.         printf("Call to NWCloseFileAndStartQueueJob2 successful\n");
  143.     else
  144.         printf("Call to NWCloseFileAndStartQueueJob2 failed, cCode = %X\n", cCode);
  145. }
  146.