home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
printq.exe
/
READQ.C
< prev
next >
Wrap
Text File
|
1995-01-09
|
9KB
|
253 lines
/****************************************************************************
** 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.
****************************************************************************
**
** File: READQ.C
**
** Desc: This program will read a print queue then take the file in
** the queue and write it out to a file called printq.out.
** This utility tests the Novell Queue Servicing APIs
** Note: The USER logged in must be in the QUEUE SERVER list in
** the bindry to attach to the queue. Since PCONSOLE does not
** have this functionality, the ADDPSERV.C utility has been
** provided.
** This program will take the first 'READY' job from the
** queue and write it to file (printq.OUT).
**
** Parameter descriptions: > input
** < output
**
**
** Programmers:
** Ini Who Firm
** ------------------------------------------------------------------
** ARM A. Ray Maxwell Novell Developer Support.
**
** History:
**
** ------------------------------------------------------------------
** 08-19-94 ARM First code.
*/
/***************************************************************************
** Include headers, macros, function prototypes, etc.
*/
/*------------------------------------------------------------------
** ANSI
*/
#include <stdlib.h> /* exit(), atol() */
#include <stdio.h> /* sprintf() */
#include <string.h> /* strupr(), strcpy */
#include <io.h> /* eof() */
#include <fcntl.h> /* open() */
#include <sys\stat.h> /* open() */
/*------------------------------------------------------------------
** NetWare
*/
#include <nwcalls.h>
/*------------------------------------------------------------------
**Defines
*/
#define NWDOS
/****************************************************************************
** Program Start
*/
void main(int argc, char *argv[])
{
/*-----------------------------------------------------------------------
** NWGetQueueJobList2 parameters
*/
QueueJobListReply job;
NWNUM startPosition = 0;
/*-----------------------------------------------------------------------
** NWServiceQueueJob2 parameters
*/
NWQueueJobStruct queueJob;
NWFILE_HANDLE nwfHandle;
NWSIZE fileSize; /* queue jobs file size NWGetQueueJobFileSize2 */
NWCONN_HANDLE connHandle;
CONNECT_INFO connInfo;
NWCONN_NUM connNumber;
NWOBJ_ID objectID;
NWOBJ_ID queObjectID;
NWCCODE ccode;
BYTE loginTime;
char server[50];
char queObjectName[50];
char objectName[50];
int hout; /* dos file handle */
unsigned char buf[8192];
int eofCheck;
int jobNumber = 0;
long processed = 0L;
int cnt=1;
long fileposition;
int fhandle;
if(argc != 3) {
printf("Usage: READQ <servername> <queue name>\n");
exit(1);
}
strcpy(server, strupr(argv[1]));
strcpy(queObjectName, strupr(argv[2]));
ccode = NWCallsInit(NULL, NULL);
if(ccode)
exit(1);
ccode = NWGetConnectionHandle(
/* > servername */ server,
/* Novell Reserved1 */ 0,
/* < connection Handle */ &connHandle,
/* Novell Reserved2 */ NULL);
if(ccode)
exit(1);
ccode = NWGetConnectionNumber(connHandle,&connNumber);
if(ccode)
exit(1);
ccode = NWGetConnectionInformation(
/* > Connection Handle */ connHandle,
/* > Server connection Number */ connNumber,
/* < Pointer to Object Name */ objectName,
/* < Pointer to bindry Object Type */ NULL,
/* < Pointer to bindry Object ID */ &objectID,
/* < Pointer to time */ &loginTime);
if(ccode)
exit(1);
ccode = NWGetObjectID(
/* > connection Handle */ connHandle,
/* > connection Handle */ queObjectName,
/* > Pointer to name of object */ OT_PRINT_QUEUE,
/* < Pointer to the found object ID*/ &queObjectID);
if(ccode)
exit(1);
ccode = NWAttachQueueServerToQueue(
/* > connection Handle */ connHandle,
/* > bindery object ID of queue */ queObjectID);
if(ccode)
exit(1);
ccode = NWGetQueueJobList2(
/* > connection Handle */ connHandle,
/* > bindery object ID */ queObjectID,
/* > position of next job */ startPosition,
/* < Pointer to array of job nums */ &job);
if(ccode)
exit(1);
ccode = NWReadQueueJobEntry2(
/* > connection Handle */ connHandle,
/* > bindery object ID of queue */ queObjectID,
/* > Number of Job being read */ job.jobNumberList[0],
/* < Pointer to NWWueueJobStruct */ &queueJob);
if (ccode)
exit(1);
if(job.totalQueueJobs){ /* check to see if there are any jobs in queue */
/*----------------------------------------------------------------------
** NOTE: The following function call will not work with the SDK V1.0e the
** problems have been fixed and work with the 4.02 SDK
** being released mid to end of OCT, 1994.
*/
ccode = NWServiceQueueJob2(
/* > connection Handle */ connHandle,
/* > bindery object ID */ queObjectID,
/* > Type of job to be serviced */ 0,
/* < Pointer to NWWueueJobStruct*/ &queueJob,
/* < Pointer to file handle */ &nwfHandle);
if(ccode)
exit(1);
ccode = NWGetQueueJobFileSize2(
/* > connection Handle */ connHandle,
/* > bindery object ID */ queObjectID,
/* > number of job for info */ queueJob.jobNumber,
/* < Pointer queue job file size*/ &fileSize);
if(ccode)
exit(1);
}
else {
ccode = NWAbortServicingQueueJob2(
/* > connection Handle */ connHandle,
/* > bindery object ID of queue */ queObjectID,
/* > number of job for info */ queueJob.jobNumber,
/* > Pointer to file handle */ nwfHandle);
printf("there are no jobs in the print queue");
exit (1);
}
hout = open( "printq.out", O_CREAT|O_TRUNC|O_BINARY|O_WRONLY, S_IWRITE);
if (hout<0 )
printf("\nFailed. Could not open output file.");
do{
cnt=read(nwfHandle, buf, sizeof(buf));
write (hout, buf,cnt);
processed+=cnt;
}while(cnt!=0 && cnt!=-1);
close(hout);
if (processed<fileSize) {
printf( "\nProcessing failure: %ld bytes of %ld processed",
processed,
fileSize);
ccode = NWAbortServicingQueueJob2(
/* > connection Handle */ connHandle,
/* > bindery object ID of queue */ queObjectID,
/* > number of job for info */ queueJob.jobNumber,
/* > Pointer to file handle */ nwfHandle);
}
ccode = NWFinishServicingQueueJob2(
/* > connection Handle */ connHandle,
/* > bindery object ID of queue */ queObjectID,
/* > number of job for info */ queueJob.jobNumber,
/* > Pointer to file handle */ nwfHandle);
if (ccode)
printf("\nNWFinishServicingQueueJobAndFile Error: %X\n", ccode);
else {
printf( "\nProcessed Job successfully:\nJobNum: %ld size: %d",
queueJob.jobNumber,
fileSize);
}
NWDetachQueueServerFromQueue( connHandle,
queObjectID);
printf("\nSuccess\n");
}