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.

445 lines
9.7 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. gopher.cxx
  5. Abstract:
  6. Contains methods for GOPHER_FIND_HANDLE_OBJECT and GOPHER_FILE_HANDLE_OBJECT
  7. classes
  8. Contents:
  9. RMakeGfrFindObjectHandle
  10. RMakeGfrFileObjectHandle
  11. RMakeGfrFixedObjectHandle
  12. Author:
  13. Madan Appiah (madana) 16-Nov-1994
  14. Environment:
  15. User Mode - Win32
  16. Revision History:
  17. Sophia Chung (sophiac) 14-Feb-1995 (added FTP and Archie class impl.)
  18. (code adopted from madana)
  19. --*/
  20. #include <wininetp.h>
  21. //
  22. // functions
  23. //
  24. DWORD
  25. RMakeGfrFindObjectHandle(
  26. IN HINTERNET ParentHandle,
  27. IN OUT HINTERNET * ChildHandle,
  28. IN CLOSE_HANDLE_FUNC wCloseFunc,
  29. IN DWORD_PTR dwContext
  30. )
  31. /*++
  32. Routine Description:
  33. Routine Description:
  34. C-callable wrapper for creating a GOPHER_FIND_HANDLE_OBJECT
  35. Arguments:
  36. ParentHandle - mapped address of parent (connect) handle
  37. ChildHandle - IN: protocol-specific handle value associated with object
  38. OUT: mapped address of GOPHER_FIND_HANDLE_OBJECT
  39. wCloseFunc - address of protocol-specific function to be called when
  40. object is closed
  41. dwContext - app-supplied context value
  42. Return Value:
  43. DWORD
  44. Success - ERROR_SUCCESS
  45. Failure - ERROR_NOT_ENOUGH_MEMORY
  46. --*/
  47. {
  48. DWORD error;
  49. GOPHER_FIND_HANDLE_OBJECT * hFind;
  50. hFind = new GOPHER_FIND_HANDLE_OBJECT(
  51. (INTERNET_CONNECT_HANDLE_OBJECT *)ParentHandle,
  52. *ChildHandle,
  53. wCloseFunc,
  54. dwContext
  55. );
  56. if (hFind != NULL) {
  57. error = hFind->GetStatus();
  58. if (error == ERROR_SUCCESS) {
  59. //
  60. // inform the app of the new handle
  61. //
  62. error = InternetIndicateStatusNewHandle((LPVOID)hFind);
  63. //
  64. // ERROR_INTERNET_OPERATION_CANCELLED is the only error that we are
  65. // expecting here. If we get this error then the app has cancelled
  66. // the operation. Either way, the handle we just generated will be
  67. // already deleted
  68. //
  69. if (error != ERROR_SUCCESS) {
  70. INET_ASSERT(error == ERROR_INTERNET_OPERATION_CANCELLED);
  71. hFind = NULL;
  72. }
  73. } else {
  74. delete hFind;
  75. hFind = NULL;
  76. }
  77. } else {
  78. error = ERROR_NOT_ENOUGH_MEMORY;
  79. }
  80. *ChildHandle = (HINTERNET)hFind;
  81. return error;
  82. }
  83. DWORD
  84. RMakeGfrFixedObjectHandle(
  85. IN HINTERNET ParentHandle,
  86. IN OUT HINTERNET * ChildHandle,
  87. IN DWORD dwFixedType
  88. )
  89. /*++
  90. Routine Description:
  91. Routine Description:
  92. C-callable wrapper for creating a GOPHER_FIND_HANDLE_OBJECT
  93. Arguments:
  94. ParentHandle - mapped address of parent (connect) handle
  95. ChildHandle - IN: protocol-specific handle value associated with object
  96. OUT: mapped address of GOPHER_FIND_HANDLE_OBJECT
  97. Return Value:
  98. DWORD
  99. Success - ERROR_SUCCESS
  100. Failure - ERROR_NOT_ENOUGH_MEMORY
  101. --*/
  102. {
  103. DWORD error;
  104. GOPHER_FIND_HANDLE_OBJECT * hFind;
  105. hFind = new GOPHER_FIND_HANDLE_OBJECT(
  106. (INTERNET_CONNECT_HANDLE_OBJECT *)ParentHandle,
  107. *ChildHandle,
  108. dwFixedType
  109. );
  110. if (!hFind) {
  111. error = ERROR_NOT_ENOUGH_MEMORY;
  112. } else {
  113. error = hFind->GetStatus();
  114. if (error != ERROR_SUCCESS) {
  115. delete hFind;
  116. hFind = NULL;
  117. }
  118. }
  119. *ChildHandle = (HINTERNET)hFind;
  120. return error;
  121. }
  122. DWORD
  123. RMakeGfrFileObjectHandle(
  124. IN HINTERNET ParentHandle,
  125. IN OUT HINTERNET * ChildHandle,
  126. IN CLOSE_HANDLE_FUNC wCloseFunc,
  127. IN DWORD_PTR dwContext
  128. )
  129. /*++
  130. Routine Description:
  131. C-callable wrapper for creating a GOPHER_FILE_HANDLE_OBJECT
  132. Arguments:
  133. ParentHandle - mapped address of parent (connect) handle
  134. ChildHandle - IN: protocol-specific handle value associated with object
  135. OUT: mapped address of GOPHER_FILE_HANDLE_OBJECT
  136. wCloseFunc - address of protocol-specific function to be called when
  137. object is closed
  138. dwContext - app-supplied context value
  139. Return Value:
  140. DWORD
  141. Success - ERROR_SUCCESS
  142. Failure - ERROR_NOT_ENOUGH_MEMORY
  143. --*/
  144. {
  145. DWORD error;
  146. GOPHER_FILE_HANDLE_OBJECT * hFile;
  147. hFile = new GOPHER_FILE_HANDLE_OBJECT(
  148. (INTERNET_CONNECT_HANDLE_OBJECT *)ParentHandle,
  149. *ChildHandle,
  150. wCloseFunc,
  151. dwContext
  152. );
  153. if (hFile != NULL) {
  154. error = hFile->GetStatus();
  155. if (error == ERROR_SUCCESS) {
  156. //
  157. // inform the app of the new handle
  158. //
  159. error = InternetIndicateStatusNewHandle((LPVOID)hFile);
  160. //
  161. // ERROR_INTERNET_OPERATION_CANCELLED is the only error that we are
  162. // expecting here. If we get this error then the app has cancelled
  163. // the operation. Either way, the handle we just generated will be
  164. // already deleted
  165. //
  166. if (error != ERROR_SUCCESS) {
  167. INET_ASSERT(error == ERROR_INTERNET_OPERATION_CANCELLED);
  168. hFile = NULL;
  169. }
  170. } else {
  171. delete hFile;
  172. hFile = NULL;
  173. }
  174. } else {
  175. error = ERROR_NOT_ENOUGH_MEMORY;
  176. }
  177. *ChildHandle = (HINTERNET)hFile;
  178. return error;
  179. }
  180. //
  181. // GOPHER_FIND_HANDLE_OBJECT class implementation
  182. //
  183. GOPHER_FIND_HANDLE_OBJECT::GOPHER_FIND_HANDLE_OBJECT(
  184. INTERNET_CONNECT_HANDLE_OBJECT *Parent,
  185. HINTERNET Child,
  186. CLOSE_HANDLE_FUNC wCloseFunc,
  187. DWORD_PTR dwContext
  188. ) : INTERNET_CONNECT_HANDLE_OBJECT(Parent)
  189. {
  190. _FindHandle = Child;
  191. _wCloseFunction = wCloseFunc;
  192. _IsHtml = FALSE;
  193. _dwFixedType = 0;
  194. _lpszUrl = NULL;
  195. _lpszDirEntry = NULL;
  196. _QueryBuffer = NULL;
  197. _QueryBufferLength = 0;
  198. _QueryOffset = 0;
  199. _QueryBytesAvailable = 0;
  200. _Context = dwContext;
  201. SetObjectType(TypeGopherFindHandle);
  202. }
  203. //
  204. // Constructor for poser find handle to return html form...
  205. //
  206. GOPHER_FIND_HANDLE_OBJECT::GOPHER_FIND_HANDLE_OBJECT(
  207. INTERNET_CONNECT_HANDLE_OBJECT *Parent,
  208. HINTERNET Child,
  209. DWORD dwFixedType
  210. ) : INTERNET_CONNECT_HANDLE_OBJECT (Parent)
  211. {
  212. _FindHandle = Child;
  213. _wCloseFunction = NULL;
  214. _IsHtml = FALSE; // must set FALSE so RSetHtmlHandleType can set TRUE!
  215. _dwFixedType = dwFixedType;
  216. _lpszUrl = NULL;
  217. _lpszDirEntry = NULL;
  218. _QueryBuffer = NULL;
  219. _QueryBufferLength = 0;
  220. _QueryOffset = 0;
  221. _QueryBytesAvailable = 0;
  222. _Context = 0;
  223. SetObjectType(TypeGopherFindHandle);
  224. }
  225. GOPHER_FIND_HANDLE_OBJECT::~GOPHER_FIND_HANDLE_OBJECT(
  226. VOID
  227. )
  228. {
  229. //
  230. // close local handle with appropriate function.
  231. //
  232. if (_FindHandle != NULL) {
  233. _Status = _wCloseFunction(_FindHandle);
  234. } else {
  235. _Status = ERROR_SUCCESS;
  236. }
  237. //
  238. // clear out any strings we allocated
  239. //
  240. if (_lpszUrl != NULL) {
  241. DEL_STRING(_lpszUrl);
  242. }
  243. if (_lpszDirEntry != NULL) {
  244. DEL_STRING(_lpszDirEntry);
  245. }
  246. //
  247. // and the query buffer
  248. //
  249. FreeQueryBuffer();
  250. }
  251. HINTERNET
  252. GOPHER_FIND_HANDLE_OBJECT::GetHandle(
  253. VOID
  254. )
  255. {
  256. return _FindHandle;
  257. }
  258. DWORD
  259. GOPHER_FIND_HANDLE_OBJECT::QueryHtmlDataAvailable(
  260. OUT LPDWORD lpdwNumberOfBytesAvailable
  261. )
  262. {
  263. DWORD error;
  264. if (_QueryBuffer != NULL) {
  265. error = ERROR_SUCCESS;
  266. } else {
  267. error = AllocateQueryBuffer();
  268. }
  269. INET_ASSERT(_QueryBytesAvailable == 0);
  270. if (error == ERROR_SUCCESS) {
  271. DWORD nRead;
  272. _QueryOffset = 0;
  273. if (ReadHtmlUrlData((HINTERNET)this,
  274. _QueryBuffer,
  275. _QueryBufferLength,
  276. lpdwNumberOfBytesAvailable
  277. )) {
  278. _QueryBytesAvailable = *lpdwNumberOfBytesAvailable;
  279. //SetAvailableDataLength(_QueryBytesAvailable);
  280. if (_QueryBytesAvailable == 0) {
  281. SetEndOfFile();
  282. }
  283. } else {
  284. error = GetLastError();
  285. }
  286. }
  287. return error;
  288. }
  289. //
  290. // GOPHER_FILE_HANDLE_OBJECT class implementation
  291. //
  292. GOPHER_FILE_HANDLE_OBJECT::GOPHER_FILE_HANDLE_OBJECT(
  293. INTERNET_CONNECT_HANDLE_OBJECT *Parent,
  294. HINTERNET Child,
  295. CLOSE_HANDLE_FUNC wCloseFunc,
  296. DWORD_PTR dwContext
  297. ) : INTERNET_CONNECT_HANDLE_OBJECT(Parent)
  298. {
  299. _FileHandle = Child;
  300. _wCloseFunction = wCloseFunc;
  301. _IsHtml = FALSE;
  302. _lpszUrl = NULL;
  303. _lpszDirEntry = NULL;
  304. _Context = dwContext;
  305. SetObjectType(TypeGopherFileHandle);
  306. }
  307. GOPHER_FILE_HANDLE_OBJECT::~GOPHER_FILE_HANDLE_OBJECT(
  308. VOID
  309. )
  310. {
  311. //
  312. // close local handle with appropriate function.
  313. //
  314. if (_FileHandle != NULL) {
  315. _Status = _wCloseFunction(_FileHandle);
  316. } else {
  317. _Status = ERROR_SUCCESS;
  318. }
  319. //
  320. // clear out any strings we allocated
  321. //
  322. if (_lpszUrl != NULL) {
  323. DEL_STRING(_lpszUrl);
  324. }
  325. if (_lpszDirEntry != NULL) {
  326. DEL_STRING(_lpszDirEntry);
  327. }
  328. }
  329. HINTERNET
  330. GOPHER_FILE_HANDLE_OBJECT::GetHandle(
  331. VOID
  332. )
  333. {
  334. return _FileHandle;
  335. }