home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / nwpssm.exe / NWPSSAMP.C next >
C/C++ Source or Header  |  1995-05-01  |  13KB  |  465 lines

  1. /****************************************************************************
  2. ** File:PRINT.C
  3. **
  4. **    Description:
  5. **
  6. **            PRINT.C uses many of the NWPSCfg calls to create a printserver,
  7. **             queue, and printer in the current context.  An operator is added to the
  8. **        queue and a person to be notified is added to the printer.  A printer configuration
  9. **        is added to the printer.
  10. **
  11. **    Disclaimer:
  12. **
  13. **        Novell, Inc. makes no representations or warranties with respect to
  14. **        any NetWare software, and specifically disclaims any express or
  15. **        implied warranties of merchantability, title, or fitness for a
  16. **        particular purpose.
  17. **
  18. **        Distribution of any NetWare software is forbidden without the
  19. **        express written consent of Novell, Inc.  Further, Novell reserves
  20. **        the right to discontinue distribution of any NetWare software.
  21. **
  22. **        Novell is not responsible for lost profits or revenue, loss of use
  23. **        of the software, loss of data, costs of re-creating lost data, the
  24. **        cost of any substitute equipment or program, or claims by any party
  25. **        other than you.  Novell strongly recommends a backup be made before
  26. **        any software is installed.   Technical support for this software
  27. **        may be provided at the discretion of Novell.
  28. **
  29. **
  30. **
  31. **    Programmers:
  32. **
  33. **        Ini    Who                    Firm
  34. **        -----------------------------------------------------------------------
  35. **        MDP    Marina D Pimentel        Novell Developer Support
  36. **
  37. **    History:
  38. **
  39. **        When        Who    What
  40. **        -----------------------------------------------------------------------
  41. **        04-30-95    MDP    First code.
  42. **
  43. */
  44.  
  45. /*---------------------------------------------------------------------------
  46. ** Include headers, macros, structures, typedefs, etc.
  47. */
  48.  
  49. #define NWDOS
  50.  
  51. #include <stdio.h>
  52. #include <string.h>
  53. #include <nwcalls.h>
  54. #include <nwnet.h>
  55. #include <nwpsrv.h>
  56. #include <stdlib.h>
  57.  
  58. extern _stklen = (8 * 1024U);
  59.  
  60. void create(void);
  61. void deletep(void);
  62. void spx(void);
  63. void job(void);
  64.  
  65. NWDSContextHandle context;
  66.  
  67. /*---------------------------------------------------------------------------
  68. **    Program start.
  69. */
  70.  
  71. void main(void)
  72. {
  73.   WORD ccode;
  74.   char buffer[48];
  75.   char c=1;
  76.  
  77.   ccode=NWCallsInit(NULL,NULL);
  78.   if(ccode)
  79.   {
  80.     printf("NWCallsInit returned a [%x]\n",ccode);
  81.     goto release;
  82.   }
  83.   ccode=NWInitUnicodeTables(001,437) ;
  84.   if(ccode)
  85.   {
  86.     printf("NWInitUnicodeTables returned a [%x]\n",ccode);
  87.     goto release;
  88.   }
  89.   context=NWDSCreateContext();
  90.   if(context==ERR_CONTEXT_CREATION)
  91.   {
  92.     printf("Could not create context\n");
  93.     goto release;
  94.   }
  95.  
  96.   /*----------------------------------------------------------------------------
  97. **  Main loop
  98. */
  99.   while(c!='Q')
  100.   {
  101.     do
  102.     {
  103.       printf("Please enter (C)reate, (D)elete, (S)px, (J)ob info, (Q)uit \n");
  104.       c=toupper(getch());
  105.     }while( (c!='C')&&(c!='D')&&(c!='S')&&(c!='J')&&(c!='Q') );
  106.     switch (c)
  107.     {
  108.     case 'C':
  109.        create();
  110.             break;
  111.     case 'D':
  112.        deletep();
  113.             break;
  114.     case 'S':
  115.        spx();
  116.             break;
  117.     case 'J':
  118.        job();
  119.             break;
  120.     case 'Q':
  121.       printf("Pressed Q\n");
  122.             break;
  123.     }
  124.   }
  125.   release:
  126.   NWFreeUnicodeTables();
  127.   NWDSFreeContext(context);
  128.  
  129. }
  130.  
  131. void create(void)
  132. {
  133.   char buffer[48];
  134.   WORD ccode;
  135.   char pserver[48],
  136.        queue[48],
  137.        printer[48],
  138.        notify[48],
  139.        oper[48];
  140.   Typed_Name_T  *notifyTypedName;
  141.   NWPS_Typed_Name notifyType,
  142.           operatorType;
  143.   WORD printerNum=0xFFFF;
  144.   NWPS_PConfig *pconfig;
  145.   Typed_Name_T     queueAttr,psAttr;
  146.  
  147. /*----------------------------------------------------------------------------
  148. **  NWPSCfgAddPrintServer() adds a print server to the fileserver.
  149. */
  150.   printf("Please enter the name of the printserver you wish to create.\n");
  151.   gets(buffer);
  152.   strcpy(pserver,strupr(buffer));
  153.   ccode=NWPSCfgAddPrintServer(NWPS_DIRECTORY_SERVICE,context,pserver);
  154.   if(ccode)
  155.   {
  156.     printf("NWPSCfgAddPrintServer returned a [%x]\n",ccode);
  157.     return;
  158.   }
  159.  
  160. /*----------------------------------------------------------------------------
  161. **  NWPSCfgAddPrintQueue() adds a print queue to the fileserver.
  162. */
  163.   printf("Please enter the name of the queue you wish to create.\n");
  164.   gets(buffer);
  165.   strcpy(queue,strupr(buffer));
  166.   ccode=NWPSCfgAddPrintQueue(NWPS_DIRECTORY_SERVICE,context,queue,"FELIZ4_SYS" );
  167.   if(ccode)
  168.   {
  169.     printf("NWPSCfgAddPrintQueue returned a [%x]\n",ccode);
  170.     return;
  171.   }
  172.   ccode=NWPSCfgAddPrintQueueAttr(NWPS_DIRECTORY_SERVICE,context,queue,NWPS_ATTR_HOST_SER,"FELIZ4");
  173.   if(ccode)
  174.   {
  175.     printf("NWPSCfgAddPrintQueueAttr returned [%x]\n");
  176.     return;
  177.   }
  178. /*----------------------------------------------------------------------------
  179. **  NWPSCfgAddPrintQueueAttr() adds a print queue attribute to the print queue.
  180. **  In this case, the attribute is the name of a queue operator.
  181. */
  182.   printf("Please enter the name of the queue operator.\n");
  183.   gets(buffer);
  184.   strcpy(oper,strupr(buffer));
  185.   operatorType.objectType=OT_USER;
  186.   operatorType.tName=oper;
  187.   ccode=NWPSCfgAddPrintQueueAttr(NWPS_DIRECTORY_SERVICE,context,queue,NWPS_ATTR_OPER,&operatorType);
  188.   if(ccode)
  189.   {
  190.     printf("NWPSCfgAddPrintQueueAttr returned a [%x]\n",ccode);
  191.     return;
  192.   }
  193. /*----------------------------------------------------------------------------
  194. **  NWPSCfgAddPrinter() adds a printer to the print server.  Having set
  195. **  printerNum to -1, the printer number that will be returned is the next
  196. **  printer number available for that print server.
  197. */
  198.   printf("Please enter the name of the printer you wish to create.\n");
  199.   gets(buffer);
  200.   strcpy(printer,strupr(buffer));
  201.   ccode=NWPSCfgAddPrinter(NWPS_DIRECTORY_SERVICE,context,pserver,printer,&printerNum);
  202.   if(ccode)
  203.   {
  204.     printf("NWPSCfgAddPrinter returned a [%x]\n",ccode);
  205.     return;
  206.   }
  207. /*----------------------------------------------------------------------------
  208. **  NWPSCfgAddPrinterAttr() adds a printer attribute to the printer.  In this
  209. **  case, the printer attribute is the name of a person to be notified
  210. **  when problems arise with the printer.
  211. */
  212.   printf("Please enter the name of person to notify if printer problems.\n");
  213.   gets(buffer);
  214.   strcpy(notify,strupr(buffer));
  215.   notifyTypedName=(Typed_Name_T*)malloc(sizeof(Typed_Name_T));
  216.   notifyTypedName->objectName=notify;
  217.   notifyTypedName->level=1;
  218.   notifyTypedName->interval=1;
  219.   notifyType.objectType=OT_USER;
  220.   notifyType.tName=notifyTypedName;
  221.   ccode=NWPSCfgAddPrinterAttr(NWPS_DIRECTORY_SERVICE,context,pserver,printer,NWPS_ATTR_NOTIFY,¬ifyType);
  222.   if(ccode)
  223.   {
  224.     printf("NWPSCfgAddPrinterAttr returned a [%x]\n",ccode);
  225.     return;
  226.   }
  227.   queueAttr.objectName = queue;
  228.   queueAttr.level = 1;    /* Priority */
  229.   queueAttr.interval = 0;
  230.   ccode=NWPSCfgAddPrinterAttr( NWPS_DIRECTORY_SERVICE, context, pserver,printer, NWPS_ATTR_QUEUE, &queueAttr );
  231.   if(ccode)
  232.   {
  233.     printf("NWPSCfgAddPrinterAttr returned [%x]\n",ccode);
  234.     return;
  235.   }
  236.   psAttr.objectName = printer;
  237.   psAttr.level = 1;    /* Priority */
  238.   psAttr.interval = 0;
  239.   ccode=NWPSCfgAddPrintServerAttr( NWPS_DIRECTORY_SERVICE, context, pserver,NWPS_ATTR_PRINTER, &psAttr );
  240.   if(ccode)
  241.   {
  242.     printf("NWPSCfgAddPrintServerAttr returned [%x]\n",ccode);
  243.     return;
  244.   }
  245.   free(notifyTypedName);
  246. }
  247.  
  248. void deletep(void)
  249. {
  250.   char buffer[48];
  251.   WORD ccode;
  252.   char pserver[48],
  253.        queue[48],
  254.        printer[48],
  255.        notify[48],
  256.        oper[48];
  257.   Typed_Name_T  *notifyTypedName;
  258.   NWPS_Typed_Name notifyType,
  259.           operatorType;
  260.   NWPS_PConfig *pconfig;
  261.  
  262.   /*----------------------------------------------------------------------------
  263. **  NWPSCfgDeletePrintServer() deletes a print server from the fileserver.
  264. */
  265.   printf("Please enter the name of the printserver you wish to delete.\n");
  266.   gets(buffer);
  267.   strcpy(pserver,strupr(buffer));
  268.   ccode=NWPSCfgDeletePrintServer(NWPS_DIRECTORY_SERVICE,context,pserver);
  269.   if(ccode)
  270.   {
  271.     printf("NWPSCfgDeletePrintServer returned a [%x]\n",ccode);
  272.     return;
  273.   }
  274. /*----------------------------------------------------------------------------
  275. **  NWPSCfgDeletePrintQueue() adds a print queue to the fileserver.
  276. */
  277.   printf("Please enter the name of the queue you wish to delete.\n");
  278.   gets(buffer);
  279.   strcpy(queue,strupr(buffer));
  280.   ccode=NWPSCfgDeletePrintQueue(NWPS_DIRECTORY_SERVICE,context,queue);
  281.   if(ccode)
  282.   {
  283.     printf("NWPSCfgAddPrintQueue returned a [%x]\n",ccode);
  284.     return;
  285.   }
  286.  
  287. /*----------------------------------------------------------------------------
  288. **  NWPSCfgDeletePrinter() adds a printer to the print server.
  289. */
  290.   printf("Please enter the name of the printer you wish to delete.\n");
  291.   gets(buffer);
  292.   strcpy(printer,strupr(buffer));
  293.   ccode=NWPSCfgDeletePrinter(NWPS_DIRECTORY_SERVICE,context,pserver,printer);
  294.   if(ccode)
  295.   {
  296.     printf("NWPSCfgAddPrinter returned a [%x]\n",ccode);
  297.     return;
  298.   }
  299. }
  300.  
  301. void spx(void)
  302. {
  303. WORD ccode;
  304. DWORD queueID,
  305.       pserverID;
  306. WORD spxID;
  307. WORD     accessLevel;
  308. NWPS_PSInfo psInfo;
  309. WORD size;
  310. BYTE status;
  311. BYTE troubleCode;
  312. BYTE active;
  313. BYTE serviceMode;
  314. WORD formNumber ;
  315. char formName[33];
  316. char printerName[33];
  317.  
  318. ccode=NWPSComAttachToPrintServer(NWPS_DIRECTORY_SERVICE,context,5,"TESTSPX",&spxID);
  319. if(ccode)
  320. {
  321.   printf("NWPSComAttachToPrintServer returned a [%u]\n\r",ccode);
  322.   return;
  323. }
  324. ccode=NWPSComLoginToPrintServer(NWPS_DIRECTORY_SERVICE,context,spxID,&accessLevel);
  325. if(ccode)
  326. {
  327.   printf("NWPSComLoginToPrintServer returned a [%u]\n\r",ccode);
  328.   return;
  329. }
  330. //gets the client's access rights from the bindery to determine if has operator rights to pserver
  331. size = sizeof(NWPS_PSInfo);
  332. ccode = NWPSComGetPrintServerInfo(spxID,&psInfo, size);
  333.  
  334. if(ccode)
  335. {
  336.   printf("NWCallsInit returned a [%u]\n\r",ccode);
  337.   return;
  338. }
  339. printf("%-20.20s %2d\n", "Status", psInfo.status);
  340. printf("%-20.20s %2d\n", "Number of Printers", psInfo.numPrinters);
  341. printf("%-20.20s %2d\n", "Number of Modes", psInfo.numModes);
  342. printf("%-20.20s %2d\n", "Major Version", psInfo.majorVersion);
  343. printf("%-20.20s %2d\n", "Minor Version", psInfo.minorVersion);
  344. printf("%-20.20s %2d\n", "Revision", psInfo.revision);
  345. printf("%-20.20s %2d\n", "PServer Type", psInfo.serverType);
  346. ccode = NWPSComGetPrinterStatus(spxID,0,&status,&troubleCode,&active,&serviceMode,&formNumber,&formName,&printerName);
  347. if(ccode)
  348. {
  349.   printf("NWPSComGetPrinterStatus returned a [%u]\n\r",ccode);
  350.   return;
  351. }
  352. ccode = NWPSComSetRemoteMode(spxID,0,1);
  353. if(ccode)
  354. {
  355.   printf("NWPSComSetRemoteMode returned a [%u]\n\r",ccode);
  356.   return;
  357. }
  358. ccode = NWPSComDetachFromPrintServer(spxID);
  359. if(ccode)
  360. {
  361.   printf("NWPSComDetachFromPrintServer returned a [%u]\n\r",ccode);
  362.   return;
  363. }
  364. }
  365.  
  366. void job(void)
  367. {
  368.   WORD ccode;
  369.   char queueName[48];
  370.   char pJob[64];
  371.   WORD defaultJob;
  372.   NWPSListHandle handle;
  373.   NWCONN_ID connID;
  374.   NWPS_Job_Rec job1,job2;
  375.   NWCAPTURE_FLAGSRW captureFlagsRW;
  376.   WORD headerlen, taillen;
  377.   BYTE *header,*tail;
  378.   WORD reserve2;
  379.   DWORD queueID;
  380.   char serverName[48];
  381.   char jobName[48];
  382.   char dbOwner[48];
  383.   char buffer[48];
  384.   NWFLAGS tempFlags;
  385.   int tabSize,ti,copies;
  386.   char c;
  387.  
  388.   /*----------------------------------------------------------------------------
  389. **  NWPSJobGetDefault() returns default job of user logged in.
  390. */
  391. printf("Please enter the name of the user\n");
  392. gets(buffer);
  393. strcpy(dbOwner,strupr(buffer));
  394. ccode=NWPSJobGetDefault(NWPS_DIRECTORY_SERVICE,context,1,dbOwner,&jobName,(NWPS_Job_Rec *)&job1);
  395. if(ccode)
  396. {
  397.   printf("NWPSJobGetDefault returned a [%x]\n\r",ccode);
  398.   return;
  399. }
  400. printf("tabsize:     %d\n",job1.tabSize);
  401. printf("copies:      %d\n",job1.copies);
  402. printf("bannername:  %s\n",job1.bannerName);
  403. printf("ti:          %d\n",job1.timeOutCount);
  404. printf("Please enter new tabSize\n");
  405. gets(buffer);
  406. tabSize=atoi(buffer);
  407. job1.tabSize=tabSize;
  408. printf("Please enter new number of copies\n");
  409. gets(buffer);
  410. copies=atoi(buffer);
  411. job1.copies=copies;
  412. printf("Please enter new bannerName\n");
  413. gets(buffer);
  414. strcpy(job1.bannerName,strupr(buffer));
  415. printf("Please enter new timeOutCount\n");
  416. gets(buffer);
  417. ti=atoi(buffer);
  418. job1.timeOutCount=ti;
  419. ccode=NWPSJobWrite(NWPS_DIRECTORY_SERVICE,context,dbOwner,jobName,&job1);
  420. ccode=NWPSJobGetFirstJob(NWPS_DIRECTORY_SERVICE,context,NWPS_SINGLE_SEARCH,&handle,dbOwner,pJob,&defaultJob);
  421. if(ccode)
  422. {
  423.   printf("NWPSJobGetFirstJob returned [%x]\n",ccode);
  424.   return;
  425. }
  426. ccode=NWPSJobRead(NWPS_DIRECTORY_SERVICE,context,dbOwner,pJob,&job1);
  427. if(ccode)
  428. {
  429.   printf("NWPSJobRead returned [%x]\n",ccode);
  430.   return;
  431. }
  432. printf("The new values for the default printjob are as follows:\n");
  433. printf("tabsize:     %d\n",job1.tabSize);
  434. printf("copies:      %d\n",job1.copies);
  435. printf("bannername:  %s\n",job1.bannerName);
  436. printf("ti:          %d\n",job1.timeOutCount);
  437. ccode=NWPSJobEndNextJob(handle);
  438. if(ccode)
  439. {
  440.   printf("NWPSJobEndNextJob returned [%x]\n",ccode);
  441.   return;
  442. }
  443. do
  444. {
  445.    printf("Would you like to return to initial values? (Y)es, (N)o\n");
  446.    c=toupper(getch());
  447. }while( (c!='Y')&&(c!='N') );
  448. if(c=='Y')
  449. {
  450.   ccode=NWPSJobInit(&job1);
  451.   if(ccode)
  452.   {
  453.     printf("NWPSJobInit returned [%x]\n",ccode);
  454.     return;
  455.   }
  456.   ccode=NWPSJobWrite(NWPS_DIRECTORY_SERVICE,context,dbOwner,jobName,&job1);
  457.   if(ccode)
  458.   {
  459.     printf("NWPSJobWrite returned [%x]\n",ccode);
  460.     return;
  461.   }
  462.   }
  463. }
  464.  
  465.