home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / lanserv / messag32 / messag32.c < prev    next >
C/C++ Source or Header  |  1998-10-01  |  4KB  |  147 lines

  1. /****************************************************************************/
  2. /*
  3.  *    PROGRAM NAME: MESSG32
  4.  *    ------------
  5.  *
  6.  *    What this program does:  Prompts the user for a servername,
  7.  *      username, and message, and then sends the message by calling
  8.  *      the Net32MessageBufferSend API.
  9.  *
  10.  *    SYNTAX:
  11.  *    ------
  12.  *    MESSG32
  13.  *
  14.  *    REQUIRED FILES:
  15.  *    --------------
  16.  *    MESSG32.C         -  Source code for this program
  17.  *
  18.  *    REQUIRED LIBRARIES:
  19.  *    ------------------
  20.  *    NETAPI32.LIB     -  Netapi library (in \IBMLAN\NETSRC\LIB directory)
  21.  *
  22.  *    NetAPI functions used in this program:
  23.  *    -------------------------------------
  24.  *    Net32MessageBufferSend
  25.  *
  26.  *    HOW TO COMPILE THIS PROGRAM:
  27.  *    ---------------------------
  28.  *    icc /Gt+ /DPURE_32 messg32.c
  29.  */
  30. /****************************************************************************/
  31.  
  32. /*------- OS/2 include files -----------------------------------------------*/
  33. #include <os2.h>
  34.  
  35. /*------- NET APIs include files -------------------------------------------*/
  36. #include <netcons.h>
  37. #include <neterr.h>
  38. #include <message.h>
  39.  
  40. /*------- C include files --------------------------------------------------*/
  41. #include <stdio.h>
  42. #include <string.h>
  43.  
  44. /*------- Defines ----------------------------------------------------------*/
  45. #define MAXCHAR 256
  46. #define MAXBUF  100
  47.  
  48. void
  49. main(void)
  50. {
  51.     unsigned char       pszServer[UNCLEN + 1];
  52.     unsigned char       pszRecipient[UNLEN + 1];
  53.     CHAR                pMsgBuf[MAXCHAR];
  54.     USHORT              usRc,
  55.                         usChoice;
  56.  
  57.     /* Get servername option: */
  58.     printf("\nWhere should the message be sent from?\n");
  59.     printf("\t1 - the local machine\n");
  60.     printf("\t2 - a remote server\n");
  61.     printf("\nResponse: ");
  62.     fflush(stdout);
  63.     scanf("%d", &usChoice);
  64.  
  65.     /* If remote server was indicated, prompt for it. */
  66.     if (usChoice == 2)
  67.     {
  68.         printf("\n\nEnter the name of the remote server (maximum name length %d):\n",
  69.                 UNCLEN);
  70.         fflush(stdout);
  71.         scanf("%s", pszServer);
  72.     }
  73.     /* We'll take any value other than 2 to mean local... */
  74.     else
  75.     {
  76.         printf("\n\nSending from the local machine.\n");
  77.         fflush(stdout);
  78.         *pszServer = '\0';
  79.     }
  80.  
  81.     /* Prompt for the name of the message recipient. */
  82.     printf("\nWho will the message be sent to?\n");
  83.     printf("\t1 - a user\n");
  84.     printf("\t2 - a domain\n");
  85.     printf("\t3 - all requesters on the LAN\n");
  86.     printf("\nResponse: ");
  87.     fflush(stdout);
  88.     scanf("%d", &usChoice);
  89.  
  90.     if (usChoice == 3)
  91.     {
  92.         strcpy(pszRecipient, "*");
  93.     }
  94.     else if (usChoice == 2)
  95.     {
  96.         printf("\nEnter the domain name: ");
  97.         fflush(stdout);
  98.         scanf("%s", pszRecipient);
  99.         strcat(pszRecipient, "*");
  100.     }
  101.     /* We'll take any value other than 2 or 3 to mean a userid. */
  102.     else
  103.     {
  104.         printf("\n\nEnter the name of the user: ");
  105.         fflush(stdout);
  106.         scanf("%s", pszRecipient);
  107.     }
  108.  
  109.     /*
  110.      * Userid's, domain names, etc. are stored as uppercase strings,
  111.      * and case is important to the NetMessageBufferSend API; so,
  112.      * uppercase the name of the recipient.
  113.      */
  114.     strupr(pszRecipient);
  115.  
  116.     /* Prompt for the message. */
  117.     memset(pMsgBuf, 0, MAXCHAR);
  118.     printf("\nEnter the message to be sent: ");
  119.     fflush(stdout);
  120.     fflush(stdin);
  121.     scanf("%[^\n]", pMsgBuf);
  122.  
  123.     /* Send the message. */
  124.     printf("Sending a message from %s to %s...\n",
  125.             *pszServer ? pszServer : "the local machine",
  126.             pszRecipient);
  127.     /* debugdebugdebugdebug */
  128.     printf("and the message is...\n\"%s\"\n", pMsgBuf);
  129.     /* debugdebugdebugdebug */
  130.     fflush(stdout);
  131.  
  132.     usRc = Net32MessageBufferSend(pszServer,
  133.                                   pszRecipient,
  134.                                   pMsgBuf,
  135.                                   strlen(pMsgBuf));
  136.  
  137.     /* Report the return code. */
  138.     if (usRc == NERR_Success)
  139.         printf("\nThe message was sent successfully.\n");
  140.     else
  141.         printf("Error: NetMessageBufferSend returned %d.\n", usRc);
  142.  
  143.     fflush(stdout);
  144.  
  145.     DosExit(EXIT_PROCESS, usRc);
  146. }
  147.