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 >
Text File  |  1995-02-22  |  6KB  |  207 lines

  1. /****************************************************************************
  2. **    File: SEND.C
  3. **
  4. **    Description:
  5. **
  6. **        Sample code that demonstrates how to send a message to a user.
  7. **        If the user is logged in to multiple connections, a message is
  8. **        sent to each connection.
  9. **
  10. **    Disclaimer:
  11. **
  12. **        Novell, Inc. makes no representations or warranties with respect to
  13. **        any NetWare software, and specifically disclaims any express or
  14. **        implied warranties of merchantability, title, or fitness for a
  15. **        particular purpose.  
  16. **
  17. **        Distribution of any NetWare software is forbidden without the
  18. **        express written consent of Novell, Inc.  Further, Novell reserves
  19. **        the right to discontinue distribution of any NetWare software.
  20. **
  21. **        Novell is not responsible for lost profits or revenue, loss of use
  22. **        of the software, loss of data, costs of re-creating lost data, the
  23. **        cost of any substitute equipment or program, or claims by any party
  24. **        other than you.  Novell strongly recommends a backup be made before
  25. **        any software is installed.   Developer support for this software
  26. **        may be provided at the discretion of Novell.
  27. **
  28. **    QMK386 options used:
  29. **
  30. **        None
  31. **
  32. **    Programmers:
  33. **
  34. **        Ini    Who                            Firm
  35. **        -----------------------------------------------------------------------
  36. **        ABJ    Adam B. Jerome                Novell Developer Support.
  37. **
  38. **    History:
  39. **
  40. **        When        Who    What
  41. **        -----------------------------------------------------------------------
  42. **        12-22-94    ABJ    First code.
  43. */
  44.  
  45. /****************************************************************************
  46. **    Compiler Setup
  47. */
  48.     /*------------------------------------------------------------------------
  49.     **    ANSI
  50.     */
  51.     #include <stdlib.h>            /* exit()                                */
  52.     #include <stdio.h>            /* printf()                                */
  53.     #include <string.h>            /*    strlen()                                */
  54.     #include <errno.h>            /* ANSI standard error codes.        */
  55.  
  56.     /*------------------------------------------------------------------------
  57.     **    NetWare
  58.     */
  59.     #include <nwmsg.h>            /* SendBroadcastMessage()             */
  60.     #include <nwconn.h>            /*    GetObjectConnectionNumbers()    */
  61.     #include <niterror.h>        /* NetWare standard error codes.    */
  62.     #include <nwbindry.h>        /*    OT_USER                                */
  63.  
  64.     /*------------------------------------------------------------------------
  65.     **    SEND
  66.     */
  67.     #define NLM_MAX_USER_CONNECTIONS    (1000)
  68.  
  69. /****************************************************************************
  70. **    Sends a specified message to all connections of specified userName.
  71. */
  72. int NLM_SendMsgToUserConnections(char *userName, char *message)
  73.     {
  74.     WORD    connectionList[NLM_MAX_USER_CONNECTIONS];
  75.     BYTE    resultList[NLM_MAX_USER_CONNECTIONS];
  76.     WORD    numberOfConnections;
  77.     int    rVal;
  78.     int    nCnt;
  79.  
  80.     /*------------------------------------------------------------------------
  81.     **    Check that message is in spec.
  82.     */
  83.     if(strlen(message) > (58-1))
  84.         {
  85.         printf("ERROR: NLM_SendMsgToUserConnections(): Message exceeds 58 chars (w/zero term)\n");
  86.         return(EFAILURE);
  87.         }
  88.  
  89.     /*------------------------------------------------------------------------
  90.     **    Get the first user connection number, if any.
  91.     */
  92.     rVal=GetObjectConnectionNumbers(
  93.         /* I-    objectName                */    userName,
  94.         /*    I-    objectType                */    OT_USER,
  95.         /*    -O    numberOfConnections    */    &numberOfConnections,
  96.         /*    -O    connectionList            */    connectionList,
  97.         /*    I-    maxConnections            */    NLM_MAX_USER_CONNECTIONS
  98.         );
  99.     if(rVal != ESUCCESS)
  100.         {
  101.         switch(NetWareErrno)
  102.             {
  103.             default:
  104.                 printf("ERROR: GetObjectConnectionNumbers() indicates NetWareErrno %d\n", rVal);
  105.                 break;
  106.             }
  107.  
  108.         return(rVal);
  109.         }
  110.  
  111.     if(numberOfConnections == 0)
  112.         {
  113.         printf("ERROR:  User %s is not connected. \n", userName);
  114.         return(EFAILURE);
  115.         }
  116.  
  117.     /*------------------------------------------------------------------------
  118.     **    Send the message.
  119.     */
  120.     rVal=SendBroadcastMessage(
  121.         /*    I-    message                */    message,
  122.         /*    I-    connectionList        */    connectionList,
  123.         /*    -O    resultList            */    resultList,
  124.         /*    I-    connectionCount    */    numberOfConnections
  125.         );
  126.     if(rVal != ESUCCESS)
  127.         {
  128.         switch(rVal)
  129.             {
  130.             case ERR_SERVER_OUT_OF_MEMORY:
  131.                 printf("ERROR: SendBroadcaseMessage() indicates SERVER OUT OF MEMORY\n");
  132.                 return(rVal);
  133.  
  134.             case ERR_IO_FAILURE:
  135.                 printf("ERROR: SendBroadcaseMessage() indicates I/O FAILURE\n");
  136.                 return(rVal);
  137.  
  138.             default:
  139.                 printf("ERROR: SendBroadcaseMessage() indicates %d\n", rVal);
  140.                 return(rVal);
  141.             }
  142.         }
  143.  
  144.     /*------------------------------------------------------------------------
  145.     **    Display results.
  146.     */
  147.     for(nCnt=0; nCnt < numberOfConnections; ++nCnt)
  148.         {
  149.         printf("Message %s to connection %hd",
  150.             resultList[nCnt] ? "not sent" : "sent",
  151.             connectionList[nCnt]
  152.             );
  153.  
  154.         switch(resultList[nCnt])
  155.             {
  156.             case 0x00:
  157.                 printf("\n");
  158.                 break;
  159.  
  160.             case 0xFC:
  161.                 printf(" (Rejected)\n");
  162.                 break;
  163.  
  164.             case 0xFD:
  165.                 printf(" (Invalid Connection Number)\n");
  166.                 break;
  167.  
  168.             case 0xFF:
  169.                 printf(" (Blocked)\n");
  170.                 break;
  171.  
  172.             default:
  173.                 printf(" (Result code: 0x%02hX)\n", 0x00FF & resultList[nCnt]);
  174.                 break;
  175.             }
  176.         }
  177.  
  178.     return(ESUCCESS); 
  179.     }
  180.  
  181. /****************************************************************************
  182. **    Program start.
  183. */
  184. void main(int argC, char *argV[])
  185.     {
  186.  
  187.     /*------------------------------------------------------------------------
  188.     **    Verify command line args.
  189.     */
  190.     if(argC != 3)
  191.         {
  192.         printf("Usage:  %s {userName} \"{message}\"\n", argV[0]);
  193.         printf("\n");
  194.         printf("     {userName}  NetWare username of any currently logged in user.\n");
  195.         printf("\n");
  196.         printf("     {message}   Message (up to 57 characters)\n");
  197.         printf("\n");
  198.         printf("\n");
  199.         exit(0);
  200.         }
  201.  
  202.     NLM_SendMsgToUserConnections(argV[1], argV[2]);
  203.     
  204.     exit(0);
  205.     }
  206.  
  207.