home *** CD-ROM | disk | FTP | other *** search
/ Netware Super Library / Netware Super Library.iso / remote / jservr / jsubmit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-15  |  9.5 KB  |  293 lines

  1. /***************************************************************************** 
  2.  * 
  3.  * Program Name:jsubmit - Generic Job Server Front-End 
  4.  * 
  5.  * Filename:jsubmit.c 
  6.  * 
  7.  * Date Created:  November 21, 1988 
  8.  * 
  9.  * Version: 1.0 
  10.  * 
  11.  * Programmers:Greg Peto 
  12.  * 
  13.  * Files used:..\genjob.obj 
  14.  * 
  15.  * Date Modified: Jan. 28, 1989 
  16.  * 
  17.  * Comments:   
  18.  * 
  19.  *  This command line utility works in conjucntion with the generic job 
  20.  *     server utilities JSUPER, and JSERVER.  It is designed to let the 
  21.  *     user submit a dos command line to the job queue for remote 
  22.  *     execution on a job server machine. 
  23.  *  See the function of badUsage for summary of possible command line arguments 
  24.  *     to this utility.  All command line arguments are expected in the 
  25.  *     form: 
  26.  *       /<command keyword>=<command argument> 
  27.  *  To locate where global variables are initialized or set, look at 
  28.  *     ComAndInit for command line settings or for the variables as 
  29.  *     output variables passed to a function call. 
  30.  ****************************************************************************/ 
  31.  
  32. /* functions in this file: 
  33. */                           
  34. #include"..\genjob.h" 
  35. #include<sys\types.h> 
  36. #include<sys\stat.h> 
  37.  
  38. /* constants definitions */ 
  39. #defineVERB_TEST1       /* want verbose test messages */ 
  40.  
  41.  
  42. /* global variables and data types */ 
  43. COMMAND_ARGS command_args[] = 
  44.   /* token,     keyword      num sig,req. string,req. int */ 
  45. # defineCOM_ACKNOWLEDGE1 
  46.   {COM_ACKNOWLEDGE,"ACKNOWLEDGE",2, FALSE,    FALSE}, 
  47.  
  48. # defineCOM_SERVER COM_ACKNOWLEDGE + 1 
  49.   {COM_SERVER,"SERVER",   1,     TRUE,        FALSE}, 
  50.  
  51. # defineCOM_NACKNOWLEDGECOM_SERVER + 1 
  52.   {COM_NACKNOWLEDGE,"NACKNOWLEDGE",3,FALSE,FALSE} 
  53. }; 
  54.  
  55. JOBFILE     jobFile;    /* buffer of job file */ 
  56. CLIENT_REC_AREAjobClientArea;/* buffer of job client record area */ 
  57. JobStruct   job;          /* QMS job struct to be used in calls */ 
  58. WORD        jobType;    /* job type numer */ 
  59. BOOLEAN     wantServiceRestart= TRUE; 
  60. BOOLEAN     doAckMess     = TRUE;/* send message when job done */ 
  61.  
  62. /* module specific varables and data types */ 
  63. /* macro definitions */ 
  64.  
  65. /*****************************************************************************/ 
  66.  
  67.  
  68. main(argc,argv,envp) 
  69.   /* Descrip: 
  70.        This program supports the generic job server.  This utility 
  71.        allow the user ot submit DOS command lines to be executed 
  72.        remotely. 
  73.      Algorithm:// 
  74.          Parse and handle command line arguments, initialize defaults 
  75.          Get environment info for remote execution 
  76.          Put job in queue                                 
  77.   */ 
  78.   /* Input: */ 
  79. int argc; 
  80. char *argv[]; 
  81. char *envp[]; 
  82.    
  83. {   /* main // */ 
  84.   /*--------------------------------------------------main body */ 
  85.   if (argc == 1) 
  86.     BadUsage(NULL);/* missing command line arguments */ 
  87.  
  88.   ComAndInit(--argc,++argv);/* skip past program name */ 
  89.   GetJobEnviron(envp,&jobFile); 
  90.   PutJob(); 
  91. }   /* of main */ 
  92.  
  93. /********************************************************************/ 
  94.  
  95. BadUsage(message) 
  96.   /* Descrip: 
  97.        This function is called when a fatal error is detected in the 
  98.          command line.  It displays the command format and options 
  99.          and then exits the program. 
  100.   */ 
  101.   /* Input: */ 
  102. char*message;/* optional explanatory message */ 
  103.    
  104. {   /* BadUsage // */ 
  105.   /*--------------------------------------------------main body */ 
  106.   if (message) 
  107.     printf("Error: %s\n\n",message); 
  108.   printf("usage: jsubmit [<command parameters>] <command line>\n\n"); 
  109.   printf("   /ACknowledge\n"); 
  110.   printf("   /NACknowledge\n"); 
  111.   printf("   /Server=<target server with job queue>\n"); 
  112.   printf("   <command line> - DOS command line to be executed remotely\n"); 
  113.  
  114.   exit(1); 
  115. }   /* end of BadUsage */ 
  116.    
  117. /********************************************************************/ 
  118.  
  119. ComAndInit(argc,argv) 
  120.   /* Descrip: 
  121.          This function parses command line input and sets default values. 
  122.        Several global variables may be changed from their default values 
  123.          by command line arguments. 
  124.      Algorithm:// 
  125.          Scans command line arguments, overiding defaults as needed. 
  126.          See top of this file for notes on expected form of command 
  127.             line option and badUsage for specific form of commands. 
  128.        Saves remote execution command line in jobClientArea. 
  129.        Find server of target queue and save in global variable. 
  130.     BUGS: 
  131.        Not all command line options implemented yet. 
  132.   */ 
  133.   /* Input: */ 
  134. int argc; 
  135. char *argv[]; 
  136.    
  137. {   /* ComAndInit // */ 
  138.   /* name of server with job queue */ 
  139.   char queueServerName[MAX_FSERVER_NAME]; 
  140.   char argString[MAX_ARG_VAR];/* command parameter variable buffer */ 
  141.   long argInt;            /* numeric parameter variable */ 
  142.   JOB_TIMEargTime;        /* time parameter */ 
  143.   JOB_DATEargDate;        /* date parameter */ 
  144.   /*--------------------------------------------------main body */ 
  145.   queueServerName[0] = '\0'; 
  146.  
  147.   for (;argc; --argc, ++argv) 
  148.   { 
  149.     if (*argv[0] NOT= '/') 
  150.        break;/* no more command line options, quit for loop */ 
  151.     switch (ScanArg((*argv) + 1,command_args, 
  152.             sizeof(command_args)/sizeof(COMMAND_ARGS), 
  153.             argString,&argInt,&argTime,&argDate)) 
  154.     { 
  155.        caseCOM_ACKNOWLEDGE: 
  156.          doAckMess= TRUE; 
  157.          break; 
  158.        caseCOM_SERVER: 
  159.          if (strlen(argString) > (MAX_FSERVER_NAME - 1)) 
  160.          { 
  161.             printf("Server name length must be less than %d, aborting\n", 
  162.               MAX_FSERVER_NAME - 1); 
  163.             exit(1); 
  164.          } 
  165.          strcpy(queueServerName,argString); 
  166.          break; 
  167.        caseCOM_NACKNOWLEDGE: 
  168.          doAckMess= FALSE; 
  169.          break; 
  170.        default: 
  171.          printf("Internal error: ComAndInit"); 
  172.          exit(1); 
  173.     }   /* end of switch on ScanArg */ 
  174.      
  175.   } /* end of for argc loop */ 
  176.  
  177.   GetCopyCommand(argc,argv); 
  178.  
  179.   FindJobServer(queueServerName,TRUE); 
  180.   if (jobQueueID == NULL) 
  181.   { 
  182.     printf("Could not find any server with job queue.\n"); 
  183.     exit(1); 
  184.   } 
  185.  
  186. # if VERB_TEST 
  187.     printf("Found server %s, connection ID %x\n", 
  188.        queueServerName ? "(default)" : queueServerName, 
  189.        jobServerConID); 
  190. # endif 
  191. }   /* end of ComAndInit */ 
  192.    
  193. /********************************************************************/ 
  194.  
  195. GetCopyCommand(argc,argv) 
  196.   /* Descrip: 
  197.        This function copies the rest of the command line arguments 
  198.          into the buffer for the client record area. 
  199.   */ 
  200.   /* Input: */ 
  201. intargc; 
  202. char*argv[]; 
  203.    
  204. {   /* GetCopyCommand // */ 
  205.   /*--------------------------------------------------main body */ 
  206.   for (;argc; --argc, ++argv) 
  207.   { 
  208.     strncat((char *) jobClientArea.jobCommand,*argv); 
  209.     strncat(jobClientArea.jobCommand," "); 
  210.   } 
  211. # if VERB_TEST 
  212.     printf("Remote execute command line: %s\n",jobClientArea.jobCommand); 
  213. # endif 
  214. }   /* end of GetCopyCommand */ 
  215.    
  216. /********************************************************************/ 
  217.  
  218. PutJob() 
  219.   /* Descrip: 
  220.        This function attempts to put the job in the job queue. 
  221.      Algorithm:// 
  222.        Fill job structure with appropriate values. 
  223.        Create job in queue on server. 
  224.        Write associated file. 
  225.        Close job and file in queue, leave ready for processing. 
  226.   */ 
  227.    
  228. {   /* PutJob // */ 
  229.   int  i; 
  230.   int  assocFile;  /* DOS C handle to job associated file */ 
  231.   int  ccode; 
  232.   /*--------------------------------------------------main body */ 
  233.   SetPreferredConnectionID(jobServerConID); 
  234.   /* Set queue job default values */ 
  235.   if (wantServiceRestart) 
  236.     /* automatic requeue if server of job loses connection */ 
  237.     job.jobControlFlags   = QF_SERVICE_RESTART; 
  238.  
  239.   job.targetServerIDNumber= -1;/* any server */ 
  240.   for (i = 0;i < TARGET_TIME_BYTES; i++) 
  241.     job.targetExecutionTime[i]= -1;/* soonest time */ 
  242.  
  243.   job.jobType                = jobType; 
  244.   strcpy((char *) job.textJobDescription,"Command line job server"); 
  245.   jobClientArea.v         = 'v'; 
  246.   jobClientArea.period    = '.'; 
  247.   jobClientArea.versionNumber= '0' + JOB_REC_V_NUMBER; 
  248.   memcpy(job.clientRecordArea,&jobClientArea,sizeof(jobClientArea)); 
  249.  
  250.   if (ccode = CreateQueueJobAndFile(jobQueueID,&job,&assocFile)) 
  251.   { 
  252.     switch(ccode) 
  253.     { 
  254.        case NO_Q_RIGHTS: 
  255.        case INVALID_BINDERY_SECURITY: 
  256.        case NO_PROPERTY_CREATE_PRIVILEGE: 
  257.          printf("Insufficient rights to add a job to queue.\n"); 
  258.          break; 
  259.        case Q_FULL: 
  260.          printf("Queue is full, unable add job to queue.\n"); 
  261.          break; 
  262.        case SERVER_BINDERY_LOCKED: 
  263.          printf("Bindery locked, unable to add job to queue.\n"); 
  264.          break; 
  265.        case BINDERY_FAILURE: 
  266.          printf("Bindery failure, unable to add job to queue.\n"); 
  267.          break; 
  268.        default: 
  269.          printf("Unable to create job in queue.\n"); 
  270.     }   /* end of switch */ 
  271.     exit(1); 
  272.   } 
  273.  
  274.  
  275.   if (doAckMess) 
  276.     on_flag(jobFile.flags,DO_ACK_MESS); 
  277.   if (write(assocFile,&jobFile,sizeof(jobFile)) == -1) 
  278.   { 
  279.     printf("Unable to write to job associated file.\n"); 
  280.     exit(1); 
  281.   } 
  282.  
  283.   if (CloseFileAndStartQueueJob(jobQueueID,job.jobNumber,assocFile)) 
  284.   { 
  285.     printf("Unable to finish job entry in queue, submit failed.\n"); 
  286.     exit(1); 
  287.   } 
  288. }   /* end of PutJob */ 
  289.    
  290. /********************************************************************/ 
  291.  
  292.