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.

314 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. gopher.hxx
  5. Abstract:
  6. Contains the client-side gopher handle class
  7. Contents:
  8. Author:
  9. Richard L Firth (rfirth) 03-Jan-1996
  10. Revision History:
  11. 03-Jan-1996 rfirth
  12. Created
  13. --*/
  14. //
  15. // classes
  16. //
  17. /*++
  18. Class Description:
  19. This class defines the GOPHER_FIND_HANDLE_OBJECT.
  20. Private Member functions:
  21. None.
  22. Public Member functions:
  23. GetHandle : Virtual function that gets the service handle value from
  24. the generic object handle.
  25. --*/
  26. class GOPHER_FIND_HANDLE_OBJECT : public INTERNET_CONNECT_HANDLE_OBJECT {
  27. private:
  28. HINTERNET _FindHandle;
  29. CLOSE_HANDLE_FUNC _wCloseFunction;
  30. BOOL _IsHtml;
  31. HTML_STATE _HtmlState;
  32. LPSTR _lpszUrl;
  33. LPSTR _lpszDirEntry;
  34. DWORD _dwFixedType; // for CSO or gopher index search text
  35. //
  36. // _QueryBuffer - buffer used to query socket data available
  37. //
  38. LPVOID _QueryBuffer;
  39. //
  40. // _QueryBufferLength - length of _QueryBuffer
  41. //
  42. DWORD _QueryBufferLength;
  43. //
  44. // _QueryOffset - offset of next read from _QueryBuffer
  45. //
  46. DWORD _QueryOffset;
  47. //
  48. // _QueryBytesAvailable - number of bytes we think are available for this
  49. // socket in the query buffer
  50. //
  51. DWORD _QueryBytesAvailable;
  52. public:
  53. GOPHER_FIND_HANDLE_OBJECT
  54. (INTERNET_CONNECT_HANDLE_OBJECT * InternetConnectObj,
  55. LPTSTR Locator,
  56. LPTSTR SearchString,
  57. LPGOPHER_FIND_DATA Buffer,
  58. DWORD_PTR dwContext
  59. );
  60. GOPHER_FIND_HANDLE_OBJECT(
  61. INTERNET_CONNECT_HANDLE_OBJECT * Parent,
  62. HINTERNET Child,
  63. CLOSE_HANDLE_FUNC wCloseFunc,
  64. DWORD_PTR dwContext
  65. );
  66. GOPHER_FIND_HANDLE_OBJECT(
  67. INTERNET_CONNECT_HANDLE_OBJECT * Parent,
  68. HINTERNET Child,
  69. DWORD dwFixedType
  70. );
  71. virtual ~GOPHER_FIND_HANDLE_OBJECT(VOID);
  72. virtual HINTERNET GetHandle(VOID);
  73. virtual HINTERNET_HANDLE_TYPE GetHandleType(VOID) {
  74. return _IsHtml ? TypeGopherFindHandleHtml : TypeGopherFindHandle;
  75. }
  76. virtual VOID SetHtml(VOID) {
  77. _HtmlState = HTML_STATE_START;
  78. _IsHtml = TRUE;
  79. }
  80. DWORD GetFixedType (VOID) {
  81. return _dwFixedType;
  82. }
  83. virtual VOID SetHtmlState(HTML_STATE State) {
  84. _HtmlState = State;
  85. }
  86. virtual HTML_STATE GetHtmlState(VOID) {
  87. return _HtmlState;
  88. }
  89. virtual LPSTR GetUrl(VOID) {
  90. return _lpszUrl;
  91. }
  92. virtual VOID SetUrl(LPSTR Url) {
  93. _lpszUrl = Url;
  94. }
  95. virtual VOID SetDirEntry(LPSTR DirEntry) {
  96. _lpszDirEntry = DirEntry;
  97. }
  98. virtual LPSTR GetDirEntry(VOID) {
  99. return _lpszDirEntry;
  100. }
  101. VOID SetFindHandle(HINTERNET hInternet) {
  102. INET_ASSERT(_FindHandle == NULL);
  103. _FindHandle = hInternet;
  104. }
  105. DWORD AllocateQueryBuffer(VOID) {
  106. INET_ASSERT(_QueryBuffer == NULL);
  107. INET_ASSERT(_QueryBufferLength == 0);
  108. INET_ASSERT(_QueryOffset == 0);
  109. INET_ASSERT(_QueryBytesAvailable == 0);
  110. _QueryBuffer = ALLOCATE_MEMORY(LMEM_FIXED,
  111. DEFAULT_HTML_QUERY_BUFFER_LENGTH
  112. );
  113. if (_QueryBuffer != NULL) {
  114. _QueryBufferLength = DEFAULT_HTML_QUERY_BUFFER_LENGTH;
  115. return ERROR_SUCCESS;
  116. }
  117. return ERROR_NOT_ENOUGH_MEMORY;
  118. }
  119. VOID FreeQueryBuffer(VOID) {
  120. if (_QueryBuffer != NULL) {
  121. DEBUG_PRINT(API,
  122. INFO,
  123. ("Freeing gopher query buffer %#x\n",
  124. _QueryBuffer
  125. ));
  126. FREE_MEMORY((HLOCAL)_QueryBuffer);
  127. _QueryBuffer = NULL;
  128. _QueryBufferLength = 0;
  129. _QueryOffset = 0;
  130. _QueryBytesAvailable = 0;
  131. }
  132. }
  133. BOOL HaveQueryData(VOID) {
  134. return (_QueryBytesAvailable != 0) ? TRUE : FALSE;
  135. }
  136. DWORD CopyQueriedData(LPVOID lpBuffer, DWORD dwBufferLength) {
  137. INET_ASSERT(lpBuffer != NULL);
  138. INET_ASSERT(dwBufferLength != 0);
  139. DWORD len = min(_QueryBytesAvailable, dwBufferLength);
  140. if (len != 0) {
  141. memcpy(lpBuffer,
  142. (LPVOID)((LPBYTE)_QueryBuffer + _QueryOffset),
  143. len
  144. );
  145. DEBUG_PRINT(API,
  146. INFO,
  147. ("Copied %d bytes from query buffer @ %#x - %d left\n",
  148. len,
  149. (LPBYTE)_QueryBuffer + _QueryOffset,
  150. _QueryBytesAvailable - len
  151. ));
  152. _QueryOffset += len;
  153. _QueryBytesAvailable -= len;
  154. }
  155. return len;
  156. }
  157. DWORD
  158. QueryHtmlDataAvailable(
  159. OUT LPDWORD lpdwNumberOfBytesAvailable
  160. );
  161. };
  162. /*++
  163. Class Description:
  164. This class defines the GOPHER_FILE_HANDLE_OBJECT.
  165. Private Member functions:
  166. None.
  167. Public Member functions:
  168. GetHandle : Virtual function that gets the service handle value from
  169. the generic object handle.
  170. --*/
  171. class GOPHER_FILE_HANDLE_OBJECT : public INTERNET_CONNECT_HANDLE_OBJECT {
  172. private:
  173. HINTERNET _FileHandle;
  174. CLOSE_HANDLE_FUNC _wCloseFunction;
  175. BOOL _IsHtml;
  176. HTML_STATE _HtmlState;
  177. LPSTR _lpszUrl;
  178. LPSTR _lpszDirEntry;
  179. public:
  180. GOPHER_FILE_HANDLE_OBJECT
  181. (INTERNET_CONNECT_HANDLE_OBJECT * InternetConnectObj,
  182. LPTSTR Locator,
  183. LPTSTR View,
  184. DWORD Flags,
  185. DWORD_PTR dwContext
  186. );
  187. GOPHER_FILE_HANDLE_OBJECT(
  188. INTERNET_CONNECT_HANDLE_OBJECT * Parent,
  189. HINTERNET Child,
  190. CLOSE_HANDLE_FUNC wCloseFunc,
  191. DWORD_PTR dwContext
  192. );
  193. virtual ~GOPHER_FILE_HANDLE_OBJECT(VOID);
  194. virtual HINTERNET GetHandle(VOID);
  195. virtual HINTERNET_HANDLE_TYPE GetHandleType(VOID) {
  196. return _IsHtml ? TypeGopherFileHandleHtml : TypeGopherFileHandle;
  197. }
  198. virtual VOID SetHtml(VOID) {
  199. _HtmlState = HTML_STATE_START;
  200. _IsHtml = TRUE;
  201. }
  202. virtual VOID SetHtmlState(HTML_STATE State) {
  203. _HtmlState = State;
  204. }
  205. virtual HTML_STATE GetHtmlState(VOID) {
  206. return _HtmlState;
  207. }
  208. virtual LPSTR GetUrl(VOID) {
  209. return _lpszUrl;
  210. }
  211. virtual VOID SetUrl(LPSTR Url) {
  212. _lpszUrl = Url;
  213. }
  214. virtual VOID SetDirEntry(LPSTR DirEntry) {
  215. _lpszDirEntry = DirEntry;
  216. }
  217. virtual LPSTR GetDirEntry(VOID) {
  218. return _lpszDirEntry;
  219. }
  220. VOID SetFileHandle(HINTERNET hInternet) {
  221. INET_ASSERT(_FileHandle == NULL);
  222. _FileHandle = hInternet;
  223. }
  224. };