Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. ParmNum.c
  5. Abstract:
  6. This module contains Remote Admin Protocol (RAP) routines. These routines
  7. are shared between XactSrv and RpcXlate.
  8. Author:
  9. Shanku Niyogi (W-Shanku) 14-Apr-1991
  10. Environment:
  11. Portable to any flat, 32-bit environment. (Uses Win32 typedefs.)
  12. Requires ANSI C extensions: slash-slash comments, long external names.
  13. Revision History:
  14. 14-Apr-1991 W-Shanku
  15. Created.
  16. 17-Apr-1991 JohnRo
  17. Reduce recompiles.
  18. 06-May-1991 JohnRo
  19. Use REM_UNSUPPORTED_FIELD equate.
  20. 15-May-1991 JohnRo
  21. Added native vs. RAP handling.
  22. 04-Jun-1991 JohnRo
  23. Made changes suggested by PC-LINT.
  24. 11-Jul-1991 JohnRo
  25. RapExamineDescriptor() has yet another parameter.
  26. Also added more debug code.
  27. Made minor changes allowing descriptors to be UNICODE someday.
  28. 15-Aug-1991 JohnRo
  29. Reduce recompiles (use MEMCPY macro).
  30. 21-Nov-1991 JohnRo
  31. Removed NT dependencies to reduce recompiles.
  32. --*/
  33. // These must be included first:
  34. #include <windef.h> // IN, DWORD, etc.
  35. #include <lmcons.h> // NET_API_STATUS.
  36. // These may be included in any order:
  37. #include <netlib.h> // NetpMemoryAllocate().
  38. #include <netdebug.h> // NetpAssert(), NetpKdPrint(()), FORMAT equates.
  39. #include <rap.h> // LPDESC, my prototype.
  40. #include <rapdebug.h> // IF_DEBUG().
  41. #include <remtypes.h> // REM_UNSUPPORTED_FIELD.
  42. #include <tstring.h> // MEMCPY().
  43. LPDESC
  44. RapParmNumDescriptor(
  45. IN LPDESC Descriptor,
  46. IN DWORD ParmNum,
  47. IN RAP_TRANSMISSION_MODE TransmissionMode,
  48. IN BOOL Native
  49. )
  50. /*++
  51. Routine Description:
  52. This routine determines the substring for a given field number within
  53. a descriptor string, makes a null-terminated copy of it, and returns
  54. a pointer to this string.
  55. Arguments:
  56. Descriptor - the format of the structure.
  57. ParmNum - the field number.
  58. Transmission Mode - Indicates whether this array is part of a response,
  59. a request, or both.
  60. Native - TRUE iff the descriptor defines a native structure. (This flag is
  61. used to decide whether or not to align fields.)
  62. Return Value:
  63. LPDESC - A pointer to a descriptor string for the field. This string is
  64. dynamically allocated and must be freed with NetpMemoryFree.
  65. If the parmnum is invalid, a pointer to an unsupported field
  66. descriptor ( REM_UNSUPPORTED_FIELD ) is returned. If the string
  67. cannot be allocated, a NULL pointer is returned.
  68. --*/
  69. {
  70. static DESC_CHAR descUnsupported[] = { REM_UNSUPPORTED_FIELD, '\0' };
  71. LPDESC descStart;
  72. LPDESC descEnd;
  73. LPDESC descCopy;
  74. DWORD length;
  75. //
  76. // I (JR) have a theory that this must only being used for data structures,
  77. // and never requests or responses. So, let's do a quick check:
  78. //
  79. NetpAssert( TransmissionMode == Both );
  80. //
  81. // Scan the descriptor for the field indexed by ParmNum. Set descStart
  82. // to point to that portion of the descriptor.
  83. //
  84. RapExamineDescriptor(
  85. Descriptor,
  86. &ParmNum,
  87. NULL,
  88. NULL,
  89. NULL,
  90. &descStart,
  91. NULL, // don't need to know structure alignment
  92. TransmissionMode,
  93. Native
  94. );
  95. if ( descStart == NULL ) {
  96. IF_DEBUG(PARMNUM) {
  97. NetpKdPrint(( "RapParmNumDescriptor: examine says unsupported.\n" ));
  98. }
  99. descStart = descUnsupported;
  100. } else if (*descStart == REM_UNSUPPORTED_FIELD) {
  101. IF_DEBUG(PARMNUM) {
  102. NetpKdPrint(( "RapParmNumDescriptor: desc says unsupported.\n" ));
  103. }
  104. }
  105. //
  106. // See if descriptor character is followed by any numeric characters.
  107. // These are part of the descriptor.
  108. //
  109. descEnd = descStart + 1;
  110. (void) RapAsciiToDecimal( &descEnd );
  111. //
  112. // Find the length of the field descriptor, and allocate memory for it.
  113. //
  114. NetpAssert( descEnd > descStart );
  115. length = (DWORD) (descEnd - descStart);
  116. descCopy = NetpMemoryAllocate( (length + 1) * sizeof(DESC_CHAR) );
  117. if ( descCopy == NULL ) {
  118. return NULL;
  119. }
  120. //
  121. // Copy the string, and put a null terminator after it.
  122. //
  123. (void) MEMCPY( descCopy, descStart, length * sizeof(DESC_CHAR) );
  124. descCopy[length] = '\0';
  125. IF_DEBUG(PARMNUM) {
  126. NetpKdPrint(( "RapParmNumDescriptor: final desc for field "
  127. FORMAT_DWORD " is " FORMAT_LPDESC ".\n",
  128. ParmNum, descCopy ));
  129. }
  130. return descCopy;
  131. } // RapParmNumDescriptor