home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / parser.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  10.4 KB  |  276 lines

  1. #pragma option push -b -a8 -pc -A- /*P_O_Push*/
  2.  
  3. //=============================================================================
  4. //  Microsoft (R) Bloodhound (tm). Copyright (C) 1991-1994.
  5. //
  6. //  MODULE: parser.h
  7. //
  8. //  This header file defines helper functions for use by Bloodhound parser DLL's.
  9. //=============================================================================
  10.  
  11. #include "bhtypes.h"
  12. #include "frame.h"
  13.  
  14. #if !defined(_PARSER_)
  15.  
  16. #define _PARSER_
  17.  
  18. #pragma pack(1)
  19.  
  20.  
  21. //=============================================================================
  22. //  Format Procedure Type.
  23. //
  24. //  NOTE: All format functions *must* be decalred as WINAPIV not WINAPI!
  25. //=============================================================================
  26.  
  27. typedef VOID (WINAPIV *FORMAT)(LPPROPERTYINST, ...);
  28.  
  29. //=============================================================================
  30. //  PROTOCOL_STATUS_RECOGNIZED:
  31. //
  32. //  The protocol recognized the frame and moved the pointer to end of its
  33. //  protocol header. Bloodhound uses the protocols follow set to continue
  34. //  parsing.
  35. //=============================================================================
  36.  
  37. #define PROTOCOL_STATUS_RECOGNIZED                        0
  38.  
  39. //=============================================================================
  40. //  PROTOCOL_STATUS_NOT_RECOGNIZED:
  41. //
  42. //  The protocol did not recognized the frame and did not move the pointer
  43. //  (i.e. the start data pointer which was passed in). Bloodhound uses the
  44. //  protocols follow set to continue parsing.
  45. //=============================================================================
  46.  
  47. #define PROTOCOL_STATUS_NOT_RECOGNIZED                    1
  48.  
  49. //=============================================================================
  50. //  PROTOCOL_STATUS_CLAIMED:
  51. //
  52. //  The protocol recognized the frame and claimed it all for itself,
  53. //  and parsing terminates.
  54. //=============================================================================
  55.  
  56. #define PROTOCOL_STATUS_CLAIMED                           2
  57.  
  58. //=============================================================================
  59. //  PROTOCOL_STATUS_NEXT_PROTOCOL:
  60. //
  61. //  The protocol recognized the frame and moved the pointer to end of its
  62. //  protocol header. The current protocol requests that Bloodhound continue
  63. //  parsing at a known next protocol by returning the next protocols handle back
  64. //  to Bloodhound. In this case, the follow of the current protocol, if any,
  65. //  is not used.
  66. //=============================================================================
  67.  
  68. #define PROTOCOL_STATUS_NEXT_PROTOCOL                     3
  69.  
  70. //=============================================================================
  71. //  Macros.
  72. //=============================================================================
  73.  
  74. extern  BYTE HexTable[];
  75.  
  76. #define XCHG(x)         MAKEWORD( HIBYTE(x), LOBYTE(x) )
  77.  
  78. #define DXCHG(x)        MAKELONG( XCHG(HIWORD(x)), XCHG(LOWORD(x)) )
  79.  
  80. #define LONIBBLE(b) ((BYTE) ((b) & 0x0F))
  81.  
  82. #define HINIBBLE(b)     ((BYTE) ((b) >> 4))
  83.  
  84. #define HEX(b)          (HexTable[LONIBBLE(b)])
  85.  
  86. #define SWAPBYTES(w)    ((w) = XCHG(w))
  87.  
  88. #define SWAPWORDS(d)    ((d) = DXCHG(d))
  89.  
  90. //=============================================================================
  91. //  All the MAC frame types combined.
  92. //=============================================================================
  93.  
  94. typedef union _MACFRAME
  95. {
  96.     LPBYTE      MacHeader;              //... generic pointer.
  97.     LPETHERNET  Ethernet;               //... ethernet pointer.
  98.     LPTOKENRING Tokenring;              //... tokenring pointer.
  99.     LPFDDI      Fddi;                   //... FDDI pointer.
  100. } MACFRAME;
  101.  
  102. typedef MACFRAME *LPMACFRAME;
  103.  
  104. #define HOT_SIGNATURE       MAKE_IDENTIFIER('H', 'O', 'T', '$')
  105. #define HOE_SIGNATURE       MAKE_IDENTIFIER('H', 'O', 'E', '$')
  106.  
  107. typedef struct _HANDOFFENTRY
  108. {
  109. #ifdef DEBUGNEVER  // remove retail/debug mixing nightmare.
  110.     DWORD       hoe_sig;                    //... 'HOE$'
  111. #endif
  112.  
  113.    DWORD        hoe_ProtIdentNumber;        //Port/Socket number used to determine who to handoff to
  114.    HPROTOCOL    hoe_ProtocolHandle;         //Handle of Protocol to hand off to
  115.    DWORD        hoe_ProtocolData;           //Additional Data to pass to protocol when handed off
  116. } HANDOFFENTRY;
  117.  
  118. typedef HANDOFFENTRY * LPHANDOFFENTRY;    
  119.  
  120. typedef struct _HANDOFFTABLE
  121. {
  122. #ifdef DEBUGNEVER  // remove retail/debug mixing nightmare.
  123.     DWORD           hot_sig;                //... 'HOT$'
  124. #endif
  125.  
  126.     DWORD           hot_NumEntries;
  127.     LPHANDOFFENTRY  hot_Entries;
  128. } HANDOFFTABLE, *LPHANDOFFTABLE;
  129.  
  130. //=============================================================================
  131. //  Parser helper macros.
  132. //=============================================================================
  133.  
  134. INLINE LPVOID GetPropertyInstanceData(LPPROPERTYINST PropertyInst)
  135. {
  136.     if ( PropertyInst->DataLength != (WORD) -1 )
  137.     {
  138.         return PropertyInst->lpData;
  139.     }
  140.  
  141.     return (LPVOID) PropertyInst->lpPropertyInstEx->Byte;
  142. }
  143.  
  144. #define GetPropertyInstanceDataValue(p, type)  ((type *) GetPropertyInstanceData(p))[0]
  145.  
  146. INLINE DWORD GetPropertyInstanceFrameDataLength(LPPROPERTYINST PropertyInst)
  147. {
  148.     if ( PropertyInst->DataLength != (WORD) -1 )
  149.     {
  150.         return PropertyInst->DataLength;
  151.     }
  152.  
  153.     return PropertyInst->lpPropertyInstEx->Length;
  154. }
  155.  
  156. INLINE DWORD GetPropertyInstanceExDataLength(LPPROPERTYINST PropertyInst)
  157. {
  158.     if ( PropertyInst->DataLength == (WORD) -1 )
  159.     {
  160.         PropertyInst->lpPropertyInstEx->Length;
  161.     }
  162.  
  163.     return (WORD) -1;
  164. }
  165.  
  166. //=============================================================================
  167. //  Parser helper functions.
  168. //=============================================================================
  169.  
  170. extern LPLABELED_WORD  WINAPI GetProtocolDescriptionTable(LPDWORD TableSize);
  171.  
  172. extern LPLABELED_WORD  WINAPI GetProtocolDescription(DWORD ProtocolID);
  173.  
  174. extern DWORD        WINAPI GetMacHeaderLength(LPVOID MacHeader, DWORD MacType);
  175.  
  176. extern DWORD        WINAPI GetLLCHeaderLength(LPLLC Frame);
  177.  
  178. extern DWORD        WINAPI GetEtype(LPVOID MacHeader, DWORD MacType);
  179.  
  180. extern DWORD        WINAPI GetSaps(LPVOID MacHeader, DWORD MacType);
  181.  
  182. extern BOOL         WINAPI IsLLCPresent(LPVOID MacHeader, DWORD MacType);
  183.  
  184. extern VOID         WINAPI CanonicalizeHexString(LPSTR hex, LPSTR dest, DWORD len);
  185.  
  186. extern void         WINAPI CanonHex(UCHAR * pDest, UCHAR * pSource, int iLen, BOOL fOx );
  187.  
  188. extern DWORD        WINAPI ByteToBinary(LPSTR string, DWORD ByteValue);
  189.  
  190. extern DWORD        WINAPI WordToBinary(LPSTR string, DWORD WordValue);
  191.  
  192. extern DWORD        WINAPI DwordToBinary(LPSTR string, DWORD DwordValue);
  193.  
  194. extern LPSTR        WINAPI AddressToString(LPSTR string, BYTE *lpAddress);
  195.  
  196. extern LPBYTE       WINAPI StringToAddress(BYTE *lpAddress, LPSTR string);
  197.  
  198. extern LPDWORD      WINAPI VarLenSmallIntToDword( LPBYTE  pValue, 
  199.                                                   WORD    ValueLen, 
  200.                                                   BOOL    fIsByteswapped,
  201.                                                   LPDWORD lpDword );
  202.  
  203. extern LPBYTE       WINAPI LookupByteSetString (LPSET lpSet, BYTE Value);
  204.  
  205. extern LPBYTE       WINAPI LookupWordSetString (LPSET lpSet, WORD Value);
  206.  
  207. extern LPBYTE       WINAPI LookupDwordSetString (LPSET lpSet, DWORD Value);
  208.  
  209. extern DWORD        WINAPIV FormatByteFlags(LPSTR string, DWORD ByteValue, DWORD BitMask);
  210.  
  211. extern DWORD        WINAPIV FormatWordFlags(LPSTR string, DWORD WordValue, DWORD BitMask);
  212.  
  213. extern DWORD        WINAPIV FormatDwordFlags(LPSTR string, DWORD DwordValue, DWORD BitMask);
  214.  
  215. extern LPSTR        WINAPIV FormatTimeAsString(SYSTEMTIME *time, LPSTR string);
  216.  
  217. extern VOID         WINAPIV FormatLabeledByteSetAsFlags(LPPROPERTYINST lpPropertyInst);
  218.  
  219. extern VOID         WINAPIV FormatLabeledWordSetAsFlags(LPPROPERTYINST lpPropertyInst);
  220.  
  221. extern VOID         WINAPIV FormatLabeledDwordSetAsFlags(LPPROPERTYINST lpPropertyInst);
  222.  
  223. extern VOID         WINAPIV FormatPropertyDataAsByte(LPPROPERTYINST lpPropertyInst, DWORD Base);
  224.  
  225. extern VOID         WINAPIV FormatPropertyDataAsWord(LPPROPERTYINST lpPropertyInst, DWORD Base);
  226.  
  227. extern VOID         WINAPIV FormatPropertyDataAsDword(LPPROPERTYINST lpPropertyInst, DWORD Base);
  228.  
  229. extern VOID         WINAPIV FormatLabeledByteSet(LPPROPERTYINST lpPropertyInst);
  230.  
  231. extern VOID         WINAPIV FormatLabeledWordSet(LPPROPERTYINST lpPropertyInst);
  232.  
  233. extern VOID         WINAPIV FormatLabeledDwordSet(LPPROPERTYINST lpPropertyInst);
  234.  
  235. extern VOID         WINAPIV FormatPropertyDataAsInt64(LPPROPERTYINST lpPropertyInst, DWORD Base);
  236.  
  237. extern VOID         WINAPIV FormatPropertyDataAsTime(LPPROPERTYINST lpPropertyInst);
  238.  
  239. extern VOID         WINAPIV FormatPropertyDataAsString(LPPROPERTYINST lpPropertyInst);
  240.  
  241. extern VOID         WINAPIV FormatPropertyDataAsHexString(LPPROPERTYINST lpPropertyInst);
  242.  
  243.  
  244. // Parsers should NOT call LockFrame().  If a parser takes a lock and then gets
  245. // faulted or returns without unlocking, it leaves the system in a state where
  246. // it cannot change protocols or cut/copy frames.  Parsers should use ParserTemporaryLockFrame
  247. // which grants a lock ONLY during the context of the api entry into the parser.  The 
  248. // lock is released on exit from the parser for that frame.
  249. extern LPBYTE       WINAPI ParserTemporaryLockFrame(HFRAME hFrame);
  250.  
  251. extern LPVOID       WINAPI GetCCInstPtr(VOID);
  252. extern VOID         WINAPI SetCCInstPtr(LPVOID lpCurCaptureInst);
  253. extern LPVOID       WINAPI CCHeapAlloc(DWORD dwBytes, BOOL bZeroInit);
  254. extern LPVOID       WINAPI CCHeapReAlloc(LPVOID lpMem, DWORD dwBytes, BOOL bZeroInit);
  255. extern BOOL         WINAPI CCHeapFree(LPVOID lpMem);
  256. extern DWORD        WINAPI CCHeapSize(LPVOID lpMem);
  257.  
  258. extern BOOL BERGetInteger( LPBYTE  pCurrentPointer,
  259.                            LPBYTE *ppValuePointer,
  260.                            LPDWORD pHeaderLength,
  261.                            LPDWORD pDataLength,
  262.                            LPBYTE *ppNext);
  263. extern BOOL BERGetString( LPBYTE  pCurrentPointer,
  264.                           LPBYTE *ppValuePointer,
  265.                           LPDWORD pHeaderLength,
  266.                           LPDWORD pDataLength,
  267.                           LPBYTE *ppNext);
  268. extern BOOL BERGetHeader( LPBYTE  pCurrentPointer,
  269.                           LPBYTE  pTag,
  270.                           LPDWORD pHeaderLength,
  271.                           LPDWORD pDataLength,
  272.                           LPBYTE *ppNext);
  273. #pragma pack()
  274. #endif
  275. #pragma option pop /*P_O_Pop*/
  276.