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.

239 lines
6.2 KiB

  1. /*++
  2. Copyright (c) 1991-1992 Microsoft Corporation
  3. Module Name:
  4. luiint.c
  5. Abstract:
  6. This module provides routines for setting up search lists of string/value
  7. pairs using messages in the NET.MSG message file, and for traversing
  8. such a search list.
  9. Author:
  10. Dan Hinsley (danhi) 06-Jun-1991
  11. Environment:
  12. User Mode - Win32
  13. Revision History:
  14. 10-Jul-1989 chuckc
  15. Created
  16. 24-Apr-1991 danhi
  17. 32 bit NT version
  18. 06-Jun-1991 Danhi
  19. Sweep to conform to NT coding style
  20. 01-Oct-1992 JohnRo
  21. RAID 3556: Added NetpSystemTimeToGmtTime() for DosPrint APIs.
  22. 20-Feb-1993 YiHsinS
  23. Moved from netcmd\map32\search.c. And added LUI_GetMessageIns.
  24. --*/
  25. //
  26. // INCLUDES
  27. //
  28. #include <windows.h> // IN, LPTSTR, etc.
  29. #include <lmcons.h>
  30. #include <stdio.h>
  31. #include <tchar.h>
  32. #include <lmerr.h>
  33. #include <luiint.h>
  34. #include <netdebug.h> // NetpAssert
  35. #include "netascii.h"
  36. #include "msystem.h"
  37. /*-- routines proper --*/
  38. /*
  39. * Name: ILUI_setup_list
  40. * Given an array of 'search_list_data' (ie. msgno/value
  41. * pairs), create a string/value pair using the messages
  42. * in the message file.
  43. * Args: char * buffer - for holding the meesages retrieved
  44. * USHORT bufsiz - size of the above buffer
  45. * USHORT offset - the number of items already setup
  46. * in slist, we will offset our retrieved
  47. * string/value pais by this much.
  48. * PUSHORT bytesread - the number of bytes read into buffer
  49. * searchlist_data sdata[] - input array of msgno/value pairs,
  50. * we stop when we hit a message number
  51. * of 0
  52. * searchlist slist[] - will receive the string/value pairs
  53. * (string will be pointers into buffer)
  54. * Returns: 0 if ok, NERR_BufTooSmall otherwise.
  55. * Globals: (none)
  56. * Statics: (none)
  57. * Remarks: WARNING! We assume the caller KNOWs that slist is big enough
  58. * for the pairs to be retrieved. This can be determined statically
  59. * while buffer size cannot. Hence we provide checks for the
  60. * latter.
  61. * Updates: (none)
  62. */
  63. DWORD
  64. ILUI_setup_listW(
  65. LPTSTR buffer,
  66. DWORD bufsiz,
  67. DWORD offset,
  68. PDWORD bytesread,
  69. searchlist_data sdata[],
  70. searchlist slist[]
  71. )
  72. {
  73. DWORD err;
  74. unsigned int msglen;
  75. int i;
  76. *bytesread = 0 ;
  77. for ( i=0; sdata[i].msg_no != 0; i++)
  78. {
  79. if (err = LUI_GetMsgInsW(NULL, 0, buffer, bufsiz, sdata[i].msg_no,
  80. (unsigned *) &msglen))
  81. {
  82. return err;
  83. }
  84. slist[i+offset].s_str = buffer;
  85. slist[i+offset].val = sdata[i].value;
  86. buffer += msglen + 1;
  87. bufsiz -= msglen + 1;
  88. *bytesread += (msglen + 1) * sizeof(TCHAR);
  89. }
  90. return 0;
  91. }
  92. /*
  93. * Name: ILUI_traverse_slist
  94. * traverse a searchlist ('slist') of string/number pairs,
  95. * and return the number matching string 'str'.
  96. * Args: char * pszStr - the string to search for
  97. * searchlist * slist - pointer to head of a searchlist
  98. * int * pusVal - pointer to variable that receives
  99. * the vale retrieved
  100. * Returns: 0 if found, -1 otherwise.
  101. * Globals: (none)
  102. * Statics: (none)
  103. * Remarks: (none)
  104. * Updates: (none)
  105. */
  106. DWORD
  107. ILUI_traverse_slistW(
  108. LPTSTR pszStr,
  109. searchlist *slist,
  110. PLONG pusVal
  111. )
  112. {
  113. if (!slist)
  114. return (DWORD) -1;
  115. while (slist->s_str)
  116. {
  117. if (_tcsicmp(pszStr, slist->s_str) == 0)
  118. {
  119. *pusVal = slist->val ;
  120. return 0;
  121. }
  122. ++slist ;
  123. }
  124. return (DWORD) -1;
  125. }
  126. /*
  127. * Name: LUI_GetMsgIns
  128. * This routine is very similar to DOSGETMESSAGE,
  129. * except it:
  130. * 1) looks for messages in specific files
  131. * in a specific order:
  132. * a) MESSAGE_FILE in <lanman_dir>
  133. * b) MESSAGE_FILENAME in DPATH
  134. * c) OS2MSG_FILENAME in DPATH
  135. * 2) guarantees a null terminates string
  136. * 3) will accept NULL for msglen (see below).
  137. * Args: istrings : pointer to table of insert strings
  138. * nstrings : number of insert strings
  139. * msgbuf : buffer to hold message retrieved
  140. * bufsize : size of buffer
  141. * msgno : message number
  142. * msglen : pointer to variable that will receive message length
  143. * Returns: zero if ok, the DOSGETMESSAGE error code otherwise
  144. * Globals: (none)
  145. * Statics: NetMsgFileName, OS2MsgFileName
  146. */
  147. DWORD
  148. LUI_GetMsgInsW(
  149. PTCHAR *istrings,
  150. DWORD nstrings,
  151. PTCHAR msgbuf,
  152. DWORD bufsize,
  153. DWORD msgno,
  154. unsigned int *msglen
  155. )
  156. {
  157. DWORD result;
  158. DWORD tmplen = 0;
  159. static WCHAR NetMsgFileName[PATHLEN+1] = { 0 };
  160. static WCHAR OS2MsgFileName[PATHLEN+1] = { 0 };
  161. NetpAssert( bufsize > 0 );
  162. *msgbuf = NULLC ;
  163. /* make a path to the LANMAN message file */
  164. if (NetMsgFileName[0] == NULLC)
  165. {
  166. wcscpy(NetMsgFileName, MESSAGE_FILENAME);
  167. }
  168. /* make a path to the OS/2 message file */
  169. if (OS2MsgFileName[0] == NULLC)
  170. {
  171. wcscpy(OS2MsgFileName, OS2MSG_FILENAME);
  172. }
  173. result = DosGetMessageW(istrings,
  174. nstrings,
  175. msgbuf,
  176. bufsize - 1,
  177. msgno,
  178. NetMsgFileName,
  179. &tmplen);
  180. if (result == ERROR_MR_MID_NOT_FOUND)
  181. {
  182. /* Cannot find -- try OS2 message file instead */
  183. result = DosGetMessageW(istrings,
  184. nstrings,
  185. msgbuf,
  186. bufsize - 1,
  187. msgno,
  188. OS2MsgFileName,
  189. &tmplen);
  190. }
  191. /*
  192. * in all DosGetMessage above we passed it bufsize-1, so we are
  193. * assure of at least one spare byte for the \0 terminator.
  194. */
  195. msgbuf[min(tmplen, bufsize - 1)] = NULLC;
  196. if (msglen != NULL)
  197. {
  198. *msglen = tmplen;
  199. }
  200. return result;
  201. }