Leaked source code of windows server 2003
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.

276 lines
6.3 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. charconv.cxx
  5. Abstract:
  6. Single byte character conversion routines.
  7. Author:
  8. Donna Liu (DonnaLi) ??-???-19??
  9. Environment:
  10. This code should execute in all environments supported by RPC
  11. (DOS, Win 3.X, and Win/NT as well as OS2).
  12. Comments:
  13. The EBCDIC to ASCII data conversion will not be tested until we
  14. interoperate with some system which speaks EBCDIC.
  15. Revision history:
  16. ... (long...)
  17. Dov Harel 04-24-1992 Added char_array_from_ndr.
  18. Dov Harel 04-24-1992 Fixed both _from_ndr to do EBCDIC => ASCII
  19. conversion. Changed the EbcdicToAscii
  20. table to "unsigned char" array type.
  21. Donna Liu 07-23-1992 Added LowerIndex parameter to
  22. <basetype>_array_from_ndr routines
  23. Dov Harel 08-19-1992 Added RpcpMemoryCopy ([_f]memcpy)
  24. to ..._array_from_ndr routines
  25. --*/
  26. #include <string.h>
  27. #include <sysinc.h>
  28. #include <rpc.h>
  29. #include <rpcdcep.h>
  30. #include <rpcndr.h>
  31. #include <ndrlibp.h>
  32. // Note this is the conversion from IBM 1047 EBCDIC codeset to ANSI 1252 code page.
  33. //
  34. // Also please see a comment in endian.c regarding disputable mapping involving
  35. // EBCDIC 0x15->0x0a and 0x25->0x85.
  36. //
  37. extern const
  38. unsigned char EbcdicToAscii[];
  39. #if !defined(DOS) || defined(WIN)
  40. //
  41. // Due to the DOS NDR1/NDR2 split, this function is now defined for DOS
  42. // in ndr20\dos
  43. //
  44. size_t RPC_ENTRY
  45. MIDL_wchar_strlen (
  46. IN wchar_t s[]
  47. )
  48. {
  49. size_t i = 0;
  50. while (s[i] != (wchar_t)0)
  51. {
  52. ++i;
  53. }
  54. return i;
  55. }
  56. #endif
  57. void RPC_ENTRY
  58. MIDL_wchar_strcpy (
  59. OUT void * t,
  60. IN wchar_t * s
  61. )
  62. {
  63. while ( *(*(wchar_t **)&t)++ = *s++ )
  64. ;
  65. }
  66. void RPC_ENTRY
  67. char_from_ndr (
  68. IN OUT PRPC_MESSAGE SourceMessage,
  69. OUT unsigned char * Target
  70. )
  71. /*++
  72. Routine Description:
  73. Unmarshall a single char from an RPC message buffer into
  74. the target (*Target). This routine:
  75. o Unmarshalls the char (as unsigned char); performs data
  76. conversion if necessary, and
  77. o Advances the buffer pointer to the address immediately
  78. following the unmarshalled char.
  79. Arguments:
  80. SourceMessage - A pointer to an RPC_MESSAGE.
  81. IN - SourceMessage->Buffer points to the address just prior to
  82. the char to be unmarshalled.
  83. OUT - SourceMessage->Buffer points to the address just following
  84. the char which was just unmarshalled.
  85. Target - A pointer to the char to unmarshall the data into.
  86. Return Values:
  87. None.
  88. --*/
  89. {
  90. if ( (SourceMessage->DataRepresentation & NDR_CHAR_REP_MASK) ==
  91. NDR_EBCDIC_CHAR )
  92. {
  93. //
  94. // The sender is an EBCDIC system. To convert to ASCII:
  95. // retrieve *(SourceMessage->Buffer) as an unsigned char, and use
  96. // that value to index into the EbcdicToAscii table.
  97. //
  98. *Target = EbcdicToAscii[*(unsigned char *)SourceMessage->Buffer];
  99. }
  100. else
  101. {
  102. //
  103. // The sender is an ASCII system. To unmarshall, just
  104. // copy an unsigned character from the buffer to the Target.
  105. //
  106. *Target = *(unsigned char *)SourceMessage->Buffer;
  107. }
  108. //
  109. // Advance the buffer pointer before returning
  110. //
  111. (*(unsigned char**)&SourceMessage->Buffer)++;
  112. }
  113. //
  114. // end char_from_ndr
  115. //
  116. void RPC_ENTRY
  117. char_array_from_ndr (
  118. IN OUT PRPC_MESSAGE SourceMessage,
  119. IN unsigned long LowerIndex,
  120. IN unsigned long UpperIndex,
  121. OUT unsigned char Target[]
  122. )
  123. /*++
  124. Routine Description:
  125. Unmarshall an array of chars from an RPC message buffer into
  126. the range Target[LowerIndex] .. Target[UpperIndex-1] of the
  127. target array of shorts (Target[]). This routine:
  128. o Unmarshalls MemberCount chars; performs data
  129. conversion if necessary, and
  130. o Advances the buffer pointer to the address immediately
  131. following the last unmarshalled char.
  132. Arguments:
  133. SourceMessage - A pointer to an RPC_MESSAGE.
  134. IN - SourceMessage->Buffer points to the address just prior to
  135. the first char to be unmarshalled.
  136. OUT - SourceMessage->Buffer points to the address just following
  137. the last char which was just unmarshalled.
  138. LowerIndex - Lower index into the target array.
  139. UpperIndex - Upper bound index into the target array.
  140. Target - An array of chars to unmarshall the data into.
  141. Return Values:
  142. None.
  143. --*/
  144. {
  145. register unsigned char * MsgBuffer = (unsigned char *)SourceMessage->Buffer;
  146. unsigned int Index;
  147. int byteCount = (int)(UpperIndex - LowerIndex);
  148. if ( (SourceMessage->DataRepresentation & NDR_CHAR_REP_MASK) ==
  149. NDR_EBCDIC_CHAR )
  150. {
  151. for (Index = (int)LowerIndex; Index < UpperIndex; Index++)
  152. {
  153. //
  154. // The sender is an EBCDIC system. To convert to ASCII:
  155. // retrieve *(SourceMessage->Buffer) as an unsigned char, and use
  156. // that value to Index into the EbcdicToAscii table.
  157. //
  158. Target[Index] =
  159. EbcdicToAscii[ MsgBuffer[(Index-LowerIndex)] ];
  160. }
  161. }
  162. else
  163. {
  164. RpcpMemoryCopy(
  165. &Target[LowerIndex],
  166. MsgBuffer,
  167. byteCount
  168. );
  169. /* Replaced by RpcpMemoryCopy:
  170. for (Index = LowerIndex; Index < UpperIndex; Index++)
  171. {
  172. //
  173. // The sender is an ASCII system. To unmarshall, just
  174. // copy an unsigned character from the buffer to the Target.
  175. //
  176. Target[Index] = MsgBuffer[(Index-LowerIndex)];
  177. }
  178. */
  179. }
  180. //
  181. // Advance the buffer pointer before returning
  182. //
  183. *(unsigned char **)&SourceMessage->Buffer += byteCount;
  184. }
  185. //
  186. // end char_array_from_ndr
  187. //
  188. /*
  189. //
  190. // Changed name to ..._bytecount. Not currently used.
  191. //
  192. int MIDL_wchar_bytecount (
  193. unsigned char s[]
  194. )
  195. {
  196. int i = 0;
  197. while (s[2*i] || s[2*i+1]) ++i;
  198. return i;
  199. }
  200. */