home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / LANMAN.ZIP / PERROR.C < prev    next >
C/C++ Source or Header  |  1991-01-01  |  4KB  |  110 lines

  1. /*-------------------------------------------------------------------
  2.   PERROR.C -- PBX error message routines
  3.  
  4.   Description:
  5.  
  6.   This file contains the function used by PBXSRV.EXE to report
  7.   errors into the LAN Manager error log.
  8.  
  9.   Author:  Brendan Dixon
  10.            Microsoft, inc.
  11.            LAN Manager Developer Support
  12.  
  13.   This code example is provided for demonstration purposes only.
  14.   Microsoft makes no warranty, either express or implied,
  15.   as to its usability in any given situation.
  16. -------------------------------------------------------------------*/
  17.  
  18. // Includes ---------------------------------------------------------
  19. #define   INCL_DOS
  20. #define   INCL_DOSERRORS
  21. #include  <os2.h>
  22.  
  23. #define   INCL_NETERRORLOG
  24. #define   INCL_NETSERVICE
  25. #define   INCL_NETERRORS
  26. #include  <lan.h>
  27.  
  28. #include  <stdio.h>
  29. #include  <string.h>
  30.  
  31. #include  "pbxsrv.h"
  32.  
  33. // Function prototypes ----------------------------------------------
  34. void AddStr(CHAR **ppbBuf, CHAR *pszStr);
  35.  
  36.  
  37. /* AddStr -----------------------------------------------------------
  38.   Description:  Add a string into a buffer of strings.
  39.   Input      :  ppbBuf -- Pointer to buffer pointer
  40.                 pszStr -- Pointer to string to add
  41.   Output     :  None
  42. -------------------------------------------------------------------*/
  43. void AddStr(CHAR **ppbBuf, CHAR *pszStr)
  44. {
  45.   while (*(*ppbBuf)++ = *pszStr++);
  46.   return;
  47. }
  48.  
  49.  
  50. /* ErrorRpt ---------------------------------------------------------
  51.   Description:  Write an error to the LAN Manager error log.
  52.   Input      :  pszMsg ---- Error message
  53.                 pszFile --- File name (e.g., PBXSRV.C, ROUTER.C)
  54.                 usLine ---- Line number of error report call
  55.                 usRC   ---- Optional return code (0 is ignored)
  56.                 esSev  ---- Error message severity
  57.   Output     :  None
  58. -------------------------------------------------------------------*/
  59. void ErrorRpt(PSZ    pszMsg,
  60.               PSZ    pszFile,
  61.               USHORT usLine,
  62.               USHORT usRC,
  63.               ERRSEV esSev)
  64. {
  65.   CHAR    cTmp[80];                       // Temporary buffer
  66.   CHAR    cArgs[255];                     // Error strings
  67.   CHAR    *pcBuf;                         // Pointer to buffer
  68.  
  69.   // Build the error message
  70.   pcBuf = cArgs;
  71.   AddStr(&pcBuf, "MSJ ");                 // System name
  72.   AddStr(&pcBuf, "PBX Service ");         // Service name
  73.  
  74.   switch (esSev) {                        // Severity
  75.     case Error        : AddStr(&pcBuf, "Error ");         break;
  76.     case Warning      : AddStr(&pcBuf, "Warning ");       break;
  77.     case Informational: AddStr(&pcBuf, "Informational "); break;
  78.   }
  79.  
  80.   sprintf(cTmp, "File: %s ",    pszFile); // OEM Sub-id and data
  81.   AddStr(&pcBuf, cTmp);
  82.   sprintf(cTmp, "Line: %u ",    usLine);
  83.   AddStr(&pcBuf, cTmp);
  84.   sprintf(cTmp, "Message: %s ", pszMsg);
  85.   AddStr(&pcBuf, cTmp);
  86.  
  87.   // Include any non-zero return code
  88.   if (usRC != NO_ERROR) {
  89.     sprintf(cTmp, "Return Code: %u ", usRC);
  90.     AddStr(&pcBuf, cTmp);
  91.   }
  92.   else
  93.     AddStr(&pcBuf, " ");
  94.  
  95.   AddStr(&pcBuf, " ");
  96.   AddStr(&pcBuf, " ");
  97.  
  98.   // Write error to log file
  99.   NetErrorLogWrite(NULL,                  // Always NULL
  100.                    NELOG_OEM_Code,        // Internal error
  101.                    "PBX Service",         // Component
  102.                    NULL,                  // No Raw data
  103.                    0,
  104.                    cArgs,                 // Error messages
  105.                    9,                     // Nine strings
  106.                    NULL);                 // Always NULL
  107.  
  108.   return;
  109. }
  110.