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 >
Wrap
C/C++ Source or Header
|
1995-05-01
|
13KB
|
465 lines
/****************************************************************************
** File:PRINT.C
**
** Description:
**
** PRINT.C uses many of the NWPSCfg calls to create a printserver,
** queue, and printer in the current context. An operator is added to the
** queue and a person to be notified is added to the printer. A printer configuration
** is added to the printer.
**
** Disclaimer:
**
** Novell, Inc. makes no representations or warranties with respect to
** any NetWare software, and specifically disclaims any express or
** implied warranties of merchantability, title, or fitness for a
** particular purpose.
**
** Distribution of any NetWare software is forbidden without the
** express written consent of Novell, Inc. Further, Novell reserves
** the right to discontinue distribution of any NetWare software.
**
** Novell is not responsible for lost profits or revenue, loss of use
** of the software, loss of data, costs of re-creating lost data, the
** cost of any substitute equipment or program, or claims by any party
** other than you. Novell strongly recommends a backup be made before
** any software is installed. Technical support for this software
** may be provided at the discretion of Novell.
**
**
**
** Programmers:
**
** Ini Who Firm
** -----------------------------------------------------------------------
** MDP Marina D Pimentel Novell Developer Support
**
** History:
**
** When Who What
** -----------------------------------------------------------------------
** 04-30-95 MDP First code.
**
*/
/*---------------------------------------------------------------------------
** Include headers, macros, structures, typedefs, etc.
*/
#define NWDOS
#include <stdio.h>
#include <string.h>
#include <nwcalls.h>
#include <nwnet.h>
#include <nwpsrv.h>
#include <stdlib.h>
extern _stklen = (8 * 1024U);
void create(void);
void deletep(void);
void spx(void);
void job(void);
NWDSContextHandle context;
/*---------------------------------------------------------------------------
** Program start.
*/
void main(void)
{
WORD ccode;
char buffer[48];
char c=1;
ccode=NWCallsInit(NULL,NULL);
if(ccode)
{
printf("NWCallsInit returned a [%x]\n",ccode);
goto release;
}
ccode=NWInitUnicodeTables(001,437) ;
if(ccode)
{
printf("NWInitUnicodeTables returned a [%x]\n",ccode);
goto release;
}
context=NWDSCreateContext();
if(context==ERR_CONTEXT_CREATION)
{
printf("Could not create context\n");
goto release;
}
/*----------------------------------------------------------------------------
** Main loop
*/
while(c!='Q')
{
do
{
printf("Please enter (C)reate, (D)elete, (S)px, (J)ob info, (Q)uit \n");
c=toupper(getch());
}while( (c!='C')&&(c!='D')&&(c!='S')&&(c!='J')&&(c!='Q') );
switch (c)
{
case 'C':
create();
break;
case 'D':
deletep();
break;
case 'S':
spx();
break;
case 'J':
job();
break;
case 'Q':
printf("Pressed Q\n");
break;
}
}
release:
NWFreeUnicodeTables();
NWDSFreeContext(context);
}
void create(void)
{
char buffer[48];
WORD ccode;
char pserver[48],
queue[48],
printer[48],
notify[48],
oper[48];
Typed_Name_T *notifyTypedName;
NWPS_Typed_Name notifyType,
operatorType;
WORD printerNum=0xFFFF;
NWPS_PConfig *pconfig;
Typed_Name_T queueAttr,psAttr;
/*----------------------------------------------------------------------------
** NWPSCfgAddPrintServer() adds a print server to the fileserver.
*/
printf("Please enter the name of the printserver you wish to create.\n");
gets(buffer);
strcpy(pserver,strupr(buffer));
ccode=NWPSCfgAddPrintServer(NWPS_DIRECTORY_SERVICE,context,pserver);
if(ccode)
{
printf("NWPSCfgAddPrintServer returned a [%x]\n",ccode);
return;
}
/*----------------------------------------------------------------------------
** NWPSCfgAddPrintQueue() adds a print queue to the fileserver.
*/
printf("Please enter the name of the queue you wish to create.\n");
gets(buffer);
strcpy(queue,strupr(buffer));
ccode=NWPSCfgAddPrintQueue(NWPS_DIRECTORY_SERVICE,context,queue,"FELIZ4_SYS" );
if(ccode)
{
printf("NWPSCfgAddPrintQueue returned a [%x]\n",ccode);
return;
}
ccode=NWPSCfgAddPrintQueueAttr(NWPS_DIRECTORY_SERVICE,context,queue,NWPS_ATTR_HOST_SER,"FELIZ4");
if(ccode)
{
printf("NWPSCfgAddPrintQueueAttr returned [%x]\n");
return;
}
/*----------------------------------------------------------------------------
** NWPSCfgAddPrintQueueAttr() adds a print queue attribute to the print queue.
** In this case, the attribute is the name of a queue operator.
*/
printf("Please enter the name of the queue operator.\n");
gets(buffer);
strcpy(oper,strupr(buffer));
operatorType.objectType=OT_USER;
operatorType.tName=oper;
ccode=NWPSCfgAddPrintQueueAttr(NWPS_DIRECTORY_SERVICE,context,queue,NWPS_ATTR_OPER,&operatorType);
if(ccode)
{
printf("NWPSCfgAddPrintQueueAttr returned a [%x]\n",ccode);
return;
}
/*----------------------------------------------------------------------------
** NWPSCfgAddPrinter() adds a printer to the print server. Having set
** printerNum to -1, the printer number that will be returned is the next
** printer number available for that print server.
*/
printf("Please enter the name of the printer you wish to create.\n");
gets(buffer);
strcpy(printer,strupr(buffer));
ccode=NWPSCfgAddPrinter(NWPS_DIRECTORY_SERVICE,context,pserver,printer,&printerNum);
if(ccode)
{
printf("NWPSCfgAddPrinter returned a [%x]\n",ccode);
return;
}
/*----------------------------------------------------------------------------
** NWPSCfgAddPrinterAttr() adds a printer attribute to the printer. In this
** case, the printer attribute is the name of a person to be notified
** when problems arise with the printer.
*/
printf("Please enter the name of person to notify if printer problems.\n");
gets(buffer);
strcpy(notify,strupr(buffer));
notifyTypedName=(Typed_Name_T*)malloc(sizeof(Typed_Name_T));
notifyTypedName->objectName=notify;
notifyTypedName->level=1;
notifyTypedName->interval=1;
notifyType.objectType=OT_USER;
notifyType.tName=notifyTypedName;
ccode=NWPSCfgAddPrinterAttr(NWPS_DIRECTORY_SERVICE,context,pserver,printer,NWPS_ATTR_NOTIFY,¬ifyType);
if(ccode)
{
printf("NWPSCfgAddPrinterAttr returned a [%x]\n",ccode);
return;
}
queueAttr.objectName = queue;
queueAttr.level = 1; /* Priority */
queueAttr.interval = 0;
ccode=NWPSCfgAddPrinterAttr( NWPS_DIRECTORY_SERVICE, context, pserver,printer, NWPS_ATTR_QUEUE, &queueAttr );
if(ccode)
{
printf("NWPSCfgAddPrinterAttr returned [%x]\n",ccode);
return;
}
psAttr.objectName = printer;
psAttr.level = 1; /* Priority */
psAttr.interval = 0;
ccode=NWPSCfgAddPrintServerAttr( NWPS_DIRECTORY_SERVICE, context, pserver,NWPS_ATTR_PRINTER, &psAttr );
if(ccode)
{
printf("NWPSCfgAddPrintServerAttr returned [%x]\n",ccode);
return;
}
free(notifyTypedName);
}
void deletep(void)
{
char buffer[48];
WORD ccode;
char pserver[48],
queue[48],
printer[48],
notify[48],
oper[48];
Typed_Name_T *notifyTypedName;
NWPS_Typed_Name notifyType,
operatorType;
NWPS_PConfig *pconfig;
/*----------------------------------------------------------------------------
** NWPSCfgDeletePrintServer() deletes a print server from the fileserver.
*/
printf("Please enter the name of the printserver you wish to delete.\n");
gets(buffer);
strcpy(pserver,strupr(buffer));
ccode=NWPSCfgDeletePrintServer(NWPS_DIRECTORY_SERVICE,context,pserver);
if(ccode)
{
printf("NWPSCfgDeletePrintServer returned a [%x]\n",ccode);
return;
}
/*----------------------------------------------------------------------------
** NWPSCfgDeletePrintQueue() adds a print queue to the fileserver.
*/
printf("Please enter the name of the queue you wish to delete.\n");
gets(buffer);
strcpy(queue,strupr(buffer));
ccode=NWPSCfgDeletePrintQueue(NWPS_DIRECTORY_SERVICE,context,queue);
if(ccode)
{
printf("NWPSCfgAddPrintQueue returned a [%x]\n",ccode);
return;
}
/*----------------------------------------------------------------------------
** NWPSCfgDeletePrinter() adds a printer to the print server.
*/
printf("Please enter the name of the printer you wish to delete.\n");
gets(buffer);
strcpy(printer,strupr(buffer));
ccode=NWPSCfgDeletePrinter(NWPS_DIRECTORY_SERVICE,context,pserver,printer);
if(ccode)
{
printf("NWPSCfgAddPrinter returned a [%x]\n",ccode);
return;
}
}
void spx(void)
{
WORD ccode;
DWORD queueID,
pserverID;
WORD spxID;
WORD accessLevel;
NWPS_PSInfo psInfo;
WORD size;
BYTE status;
BYTE troubleCode;
BYTE active;
BYTE serviceMode;
WORD formNumber ;
char formName[33];
char printerName[33];
ccode=NWPSComAttachToPrintServer(NWPS_DIRECTORY_SERVICE,context,5,"TESTSPX",&spxID);
if(ccode)
{
printf("NWPSComAttachToPrintServer returned a [%u]\n\r",ccode);
return;
}
ccode=NWPSComLoginToPrintServer(NWPS_DIRECTORY_SERVICE,context,spxID,&accessLevel);
if(ccode)
{
printf("NWPSComLoginToPrintServer returned a [%u]\n\r",ccode);
return;
}
//gets the client's access rights from the bindery to determine if has operator rights to pserver
size = sizeof(NWPS_PSInfo);
ccode = NWPSComGetPrintServerInfo(spxID,&psInfo, size);
if(ccode)
{
printf("NWCallsInit returned a [%u]\n\r",ccode);
return;
}
printf("%-20.20s %2d\n", "Status", psInfo.status);
printf("%-20.20s %2d\n", "Number of Printers", psInfo.numPrinters);
printf("%-20.20s %2d\n", "Number of Modes", psInfo.numModes);
printf("%-20.20s %2d\n", "Major Version", psInfo.majorVersion);
printf("%-20.20s %2d\n", "Minor Version", psInfo.minorVersion);
printf("%-20.20s %2d\n", "Revision", psInfo.revision);
printf("%-20.20s %2d\n", "PServer Type", psInfo.serverType);
ccode = NWPSComGetPrinterStatus(spxID,0,&status,&troubleCode,&active,&serviceMode,&formNumber,&formName,&printerName);
if(ccode)
{
printf("NWPSComGetPrinterStatus returned a [%u]\n\r",ccode);
return;
}
ccode = NWPSComSetRemoteMode(spxID,0,1);
if(ccode)
{
printf("NWPSComSetRemoteMode returned a [%u]\n\r",ccode);
return;
}
ccode = NWPSComDetachFromPrintServer(spxID);
if(ccode)
{
printf("NWPSComDetachFromPrintServer returned a [%u]\n\r",ccode);
return;
}
}
void job(void)
{
WORD ccode;
char queueName[48];
char pJob[64];
WORD defaultJob;
NWPSListHandle handle;
NWCONN_ID connID;
NWPS_Job_Rec job1,job2;
NWCAPTURE_FLAGSRW captureFlagsRW;
WORD headerlen, taillen;
BYTE *header,*tail;
WORD reserve2;
DWORD queueID;
char serverName[48];
char jobName[48];
char dbOwner[48];
char buffer[48];
NWFLAGS tempFlags;
int tabSize,ti,copies;
char c;
/*----------------------------------------------------------------------------
** NWPSJobGetDefault() returns default job of user logged in.
*/
printf("Please enter the name of the user\n");
gets(buffer);
strcpy(dbOwner,strupr(buffer));
ccode=NWPSJobGetDefault(NWPS_DIRECTORY_SERVICE,context,1,dbOwner,&jobName,(NWPS_Job_Rec *)&job1);
if(ccode)
{
printf("NWPSJobGetDefault returned a [%x]\n\r",ccode);
return;
}
printf("tabsize: %d\n",job1.tabSize);
printf("copies: %d\n",job1.copies);
printf("bannername: %s\n",job1.bannerName);
printf("ti: %d\n",job1.timeOutCount);
printf("Please enter new tabSize\n");
gets(buffer);
tabSize=atoi(buffer);
job1.tabSize=tabSize;
printf("Please enter new number of copies\n");
gets(buffer);
copies=atoi(buffer);
job1.copies=copies;
printf("Please enter new bannerName\n");
gets(buffer);
strcpy(job1.bannerName,strupr(buffer));
printf("Please enter new timeOutCount\n");
gets(buffer);
ti=atoi(buffer);
job1.timeOutCount=ti;
ccode=NWPSJobWrite(NWPS_DIRECTORY_SERVICE,context,dbOwner,jobName,&job1);
ccode=NWPSJobGetFirstJob(NWPS_DIRECTORY_SERVICE,context,NWPS_SINGLE_SEARCH,&handle,dbOwner,pJob,&defaultJob);
if(ccode)
{
printf("NWPSJobGetFirstJob returned [%x]\n",ccode);
return;
}
ccode=NWPSJobRead(NWPS_DIRECTORY_SERVICE,context,dbOwner,pJob,&job1);
if(ccode)
{
printf("NWPSJobRead returned [%x]\n",ccode);
return;
}
printf("The new values for the default printjob are as follows:\n");
printf("tabsize: %d\n",job1.tabSize);
printf("copies: %d\n",job1.copies);
printf("bannername: %s\n",job1.bannerName);
printf("ti: %d\n",job1.timeOutCount);
ccode=NWPSJobEndNextJob(handle);
if(ccode)
{
printf("NWPSJobEndNextJob returned [%x]\n",ccode);
return;
}
do
{
printf("Would you like to return to initial values? (Y)es, (N)o\n");
c=toupper(getch());
}while( (c!='Y')&&(c!='N') );
if(c=='Y')
{
ccode=NWPSJobInit(&job1);
if(ccode)
{
printf("NWPSJobInit returned [%x]\n",ccode);
return;
}
ccode=NWPSJobWrite(NWPS_DIRECTORY_SERVICE,context,dbOwner,jobName,&job1);
if(ccode)
{
printf("NWPSJobWrite returned [%x]\n",ccode);
return;
}
}
}