home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
xsnd1.exe
/
SEND.C
next >
Wrap
Text File
|
1995-02-22
|
6KB
|
207 lines
/****************************************************************************
** File: SEND.C
**
** Description:
**
** Sample code that demonstrates how to send a message to a user.
** If the user is logged in to multiple connections, a message is
** sent to each connection.
**
** 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. Developer support for this software
** may be provided at the discretion of Novell.
**
** QMK386 options used:
**
** None
**
** Programmers:
**
** Ini Who Firm
** -----------------------------------------------------------------------
** ABJ Adam B. Jerome Novell Developer Support.
**
** History:
**
** When Who What
** -----------------------------------------------------------------------
** 12-22-94 ABJ First code.
*/
/****************************************************************************
** Compiler Setup
*/
/*------------------------------------------------------------------------
** ANSI
*/
#include <stdlib.h> /* exit() */
#include <stdio.h> /* printf() */
#include <string.h> /* strlen() */
#include <errno.h> /* ANSI standard error codes. */
/*------------------------------------------------------------------------
** NetWare
*/
#include <nwmsg.h> /* SendBroadcastMessage() */
#include <nwconn.h> /* GetObjectConnectionNumbers() */
#include <niterror.h> /* NetWare standard error codes. */
#include <nwbindry.h> /* OT_USER */
/*------------------------------------------------------------------------
** SEND
*/
#define NLM_MAX_USER_CONNECTIONS (1000)
/****************************************************************************
** Sends a specified message to all connections of specified userName.
*/
int NLM_SendMsgToUserConnections(char *userName, char *message)
{
WORD connectionList[NLM_MAX_USER_CONNECTIONS];
BYTE resultList[NLM_MAX_USER_CONNECTIONS];
WORD numberOfConnections;
int rVal;
int nCnt;
/*------------------------------------------------------------------------
** Check that message is in spec.
*/
if(strlen(message) > (58-1))
{
printf("ERROR: NLM_SendMsgToUserConnections(): Message exceeds 58 chars (w/zero term)\n");
return(EFAILURE);
}
/*------------------------------------------------------------------------
** Get the first user connection number, if any.
*/
rVal=GetObjectConnectionNumbers(
/* I- objectName */ userName,
/* I- objectType */ OT_USER,
/* -O numberOfConnections */ &numberOfConnections,
/* -O connectionList */ connectionList,
/* I- maxConnections */ NLM_MAX_USER_CONNECTIONS
);
if(rVal != ESUCCESS)
{
switch(NetWareErrno)
{
default:
printf("ERROR: GetObjectConnectionNumbers() indicates NetWareErrno %d\n", rVal);
break;
}
return(rVal);
}
if(numberOfConnections == 0)
{
printf("ERROR: User %s is not connected. \n", userName);
return(EFAILURE);
}
/*------------------------------------------------------------------------
** Send the message.
*/
rVal=SendBroadcastMessage(
/* I- message */ message,
/* I- connectionList */ connectionList,
/* -O resultList */ resultList,
/* I- connectionCount */ numberOfConnections
);
if(rVal != ESUCCESS)
{
switch(rVal)
{
case ERR_SERVER_OUT_OF_MEMORY:
printf("ERROR: SendBroadcaseMessage() indicates SERVER OUT OF MEMORY\n");
return(rVal);
case ERR_IO_FAILURE:
printf("ERROR: SendBroadcaseMessage() indicates I/O FAILURE\n");
return(rVal);
default:
printf("ERROR: SendBroadcaseMessage() indicates %d\n", rVal);
return(rVal);
}
}
/*------------------------------------------------------------------------
** Display results.
*/
for(nCnt=0; nCnt < numberOfConnections; ++nCnt)
{
printf("Message %s to connection %hd",
resultList[nCnt] ? "not sent" : "sent",
connectionList[nCnt]
);
switch(resultList[nCnt])
{
case 0x00:
printf("\n");
break;
case 0xFC:
printf(" (Rejected)\n");
break;
case 0xFD:
printf(" (Invalid Connection Number)\n");
break;
case 0xFF:
printf(" (Blocked)\n");
break;
default:
printf(" (Result code: 0x%02hX)\n", 0x00FF & resultList[nCnt]);
break;
}
}
return(ESUCCESS);
}
/****************************************************************************
** Program start.
*/
void main(int argC, char *argV[])
{
/*------------------------------------------------------------------------
** Verify command line args.
*/
if(argC != 3)
{
printf("Usage: %s {userName} \"{message}\"\n", argV[0]);
printf("\n");
printf(" {userName} NetWare username of any currently logged in user.\n");
printf("\n");
printf(" {message} Message (up to 57 characters)\n");
printf("\n");
printf("\n");
exit(0);
}
NLM_SendMsgToUserConnections(argV[1], argV[2]);
exit(0);
}