home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / crprnt.exe / CRPRINT.C next >
C/C++ Source or Header  |  1995-04-14  |  7KB  |  192 lines

  1. /****************************************************************************
  2. ** File:CRPRINT.C
  3. **
  4. **    Description:
  5. **
  6. **            CRPRINT.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-14-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.  
  61. /*---------------------------------------------------------------------------
  62. **    Program start.
  63. */
  64.  
  65. void main(void)
  66. {
  67.   NWDSContextHandle context;
  68.   WORD ccode;
  69.   char buffer[48];
  70.  
  71.   char pserver[48],
  72.        queue[48],
  73.        printer[48],
  74.        notify[48],
  75.        oper[48];
  76.   Typed_Name_T  *notifyTypedName;
  77.   NWPS_Typed_Name notifyType,
  78.           operatorType;
  79.   WORD printerNum=0xFFFF;
  80.   Octet_String_T *octet;
  81.   NWPS_PConfig *pconfig;
  82.  
  83.  
  84.   ccode=NWCallsInit(NULL,NULL);
  85.   if(ccode)
  86.     printf("NWCallsInit returned a [%x]\n",ccode);
  87.   ccode=NWInitUnicodeTables(001,437) ;
  88.   if(ccode)
  89.     printf("NWInitUnicodeTables returned a [%x]\n",ccode);
  90.   context=NWDSCreateContext();
  91.   if(context==ERR_CONTEXT_CREATION)
  92.     printf("Could not create context\n");
  93.  
  94.   /*----------------------------------------------------------------------------
  95. **  NWPSCfgAddPrintServer() adds a print server to the fileserver.
  96. */
  97.   printf("Please enter the name of the printserver you wish to create.\n");
  98.   gets(buffer);
  99.   strcpy(pserver,strupr(buffer));
  100.   ccode=NWPSCfgAddPrintServer(NWPS_DIRECTORY_SERVICE,context,pserver);
  101.   if(ccode)
  102.     printf("NWPSCfgAddPrintServer returned a [%x]\n",ccode);
  103.  
  104. /*----------------------------------------------------------------------------
  105. **  NWPSCfgAddPrintQueue() adds a print queue to the fileserver.
  106. */
  107.   printf("Please enter the name of the queue you wish to create.\n");
  108.   gets(buffer);
  109.   strcpy(queue,strupr(buffer));
  110.   ccode=NWPSCfgAddPrintQueue(NWPS_DIRECTORY_SERVICE,context,queue,"FELIZ4_SYS" );
  111.   if(ccode)
  112.     printf("NWPSCfgAddPrintQueue returned a [%x]\n",ccode);
  113.   ccode=NWPSCfgAddPrintQueueAttr(NWPS_DIRECTORY_SERVICE,context,queue,NWPS_ATTR_HOST_SER,"FELIZ4");
  114.   if(ccode)
  115.     printf("NWPSCfgAddPrintQueueAttr returned [%x]\n");
  116.  
  117. /*----------------------------------------------------------------------------
  118. **  NWPSCfgAddPrintQueueAttr() adds a print queue attribute to the print queue.
  119. **  In this case, the attribute is the name of a queue operator.
  120. */
  121.   printf("Please enter the name of the queue operator.\n");
  122.   gets(buffer);
  123.   strcpy(oper,strupr(buffer));
  124.   operatorType.objectType=OT_USER;
  125.   operatorType.tName=oper;
  126.   ccode=NWPSCfgAddPrintQueueAttr(NWPS_DIRECTORY_SERVICE,context,queue,NWPS_ATTR_OPER,&operatorType);
  127.   if(ccode)
  128.     printf("NWPSCfgAddPrintQueueAttr returned a [%x]\n",ccode);
  129.  
  130. /*----------------------------------------------------------------------------
  131. **  NWPSCfgAddPrinter() adds a printer to the print server.  Having set
  132. **  printerNum to -1, the printer number that will be returned is the next
  133. **  printer number available for that print server.
  134. */
  135.   printf("Please enter the name of the printer you wish to create.\n");
  136.   gets(buffer);
  137.   strcpy(printer,strupr(buffer));
  138.   ccode=NWPSCfgAddPrinter(NWPS_DIRECTORY_SERVICE,context,pserver,printer,&printerNum);
  139.   if(ccode)
  140.     printf("NWPSCfgAddPrinter returned a [%x]\n",ccode);
  141.  
  142. /*----------------------------------------------------------------------------
  143. **  NWPSCfgAddPrinterAttr() adds a printer attribute to the printer.  In this
  144. **  case, the printer attribute is the name of a person to be notified
  145. **  when problems arise with the printer.
  146. */
  147.   printf("Please enter the name of person to notify if printer problems.\n");
  148.   gets(buffer);
  149.   strcpy(notify,strupr(buffer));
  150.   notifyTypedName=(Typed_Name_T*)malloc(sizeof(Typed_Name_T));
  151.   notifyTypedName->objectName=notify;
  152.   notifyTypedName->level=1;
  153.   notifyTypedName->interval=1;
  154.   notifyType.objectType=OT_USER;
  155.   notifyType.tName=notifyTypedName;
  156.   ccode=NWPSCfgAddPrinterAttr(NWPS_DIRECTORY_SERVICE,context,pserver,printer,NWPS_ATTR_NOTIFY,¬ifyType);
  157.   if(ccode)
  158.     printf("NWPSCfgAddPrinterAttr returned a [%x]\n",ccode);
  159.  
  160. /*----------------------------------------------------------------------------
  161. **  NWPSCfgGetPrinterDefaults() returns the printer defaults of the
  162. **  printer type.  In this case, printerType has been defined as a
  163. **  serial printer.  Thus, this call returns the printer defaults
  164. **  associated with a serial printer.
  165. */
  166.   octet=malloc(sizeof(NWPS_PConfig)+sizeof(Octet_String_T));
  167.   octet->data=(BYTE *)(octet+1);
  168.   pconfig=(NWPS_PConfig *)octet->data;
  169.   pconfig->printerType=NWPS_P_SER;
  170.   ccode=NWPSCfgGetPrinterDefaults(pconfig->printerType,0,pconfig);
  171.   if(ccode)
  172.     printf("NWPSCfgGetPrinterDefaults returned a [%x]\n",ccode);
  173.  
  174. /*----------------------------------------------------------------------------
  175. **  This call to NWPSCfgAddPrinterAttr() adds the printer attribute of the
  176. **  printer configuration.
  177. */
  178.   ccode=NWPSCfgAddPrinterAttr(NWPS_DIRECTORY_SERVICE,context,pserver,printer,NWPS_ATTR_CONF,octet);
  179.   if(ccode)
  180.     printf("NWPSCfgAddPrinterAttr returned a [%x]\n",ccode);
  181.  
  182.  
  183.   free(notifyTypedName);
  184.   free(octet);
  185.   NWFreeUnicodeTables();
  186.   NWDSFreeContext(context);
  187.  
  188. }
  189.  
  190.  
  191.  
  192.