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.

761 lines
23 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. cernprox.c
  5. Abstract:
  6. Tests CERN proxy support
  7. Author:
  8. Richard L Firth (rfirth) 28-Jun-1995
  9. Revision History:
  10. 28-Jun-1995 rfirth
  11. Created
  12. --*/
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <stdarg.h>
  16. #include <string.h>
  17. #include <malloc.h>
  18. #include <io.h>
  19. #include <fcntl.h>
  20. #include <windows.h>
  21. #include <wininet.h>
  22. #include <winsock.h>
  23. #ifndef _CRTAPI1
  24. #define _CRTAPI1
  25. #endif
  26. #define IS_ARG(c) (((c) == '-') || ((c) == '/'))
  27. //
  28. // prototypes
  29. //
  30. void _CRTAPI1 main(int, char**);
  31. void usage(void);
  32. void _CRTAPI1 my_cleanup(void);
  33. void my_callback(DWORD, DWORD, LPVOID, DWORD);
  34. void default_url_test(void);
  35. void open_urls(LPSTR*, int);
  36. void get_url_data(HINTERNET);
  37. void ftp_find(HINTERNET);
  38. void gopher_find(HINTERNET);
  39. void read_data(HINTERNET);
  40. void print_error(char*, char*, ...);
  41. char* map_error(DWORD);
  42. void get_last_internet_error(void);
  43. //
  44. // data
  45. //
  46. BOOL Verbose = FALSE;
  47. HINTERNET InternetHandle = NULL;
  48. INTERNET_STATUS_CALLBACK PreviousCallback;
  49. LPSTR default_urls[] = {
  50. //
  51. // WEB
  52. //
  53. "http://www.microsoft.com",
  54. "http://www.microsoft.com/pages/misc/whatsnew.htm",
  55. //
  56. // gopher
  57. //
  58. "gopher://gopher.microsoft.com",
  59. "gopher://gopher.microsoft.com/11/msft/",
  60. "gopher://gopher.microsoft.com/00\\welcome.txt",
  61. "gopher://gopher.tc.umn.edu/11Information%20About%20Gopher%09%09%2B",
  62. "gopher://spinaltap.micro.umn.edu/11/computer",
  63. "gopher://mudhoney.micro.umn.edu:4325/7",
  64. "gopher://mudhoney.micro.umn.edu:4325/7%09gopher",
  65. "gopher://spinaltap.micro.umn.edu/7mindex:lotsoplaces%09gopher%09%2b",
  66. //
  67. // FTP
  68. //
  69. "ftp://ftp.microsoft.com",
  70. "ftp://ftp.microsoft.com/MSNBRO.TXT",
  71. "ftp://ftp.microsoft.com/Services/"
  72. };
  73. #define NUMBER_OF_DEFAULT_URLS (sizeof(default_urls)/sizeof(default_urls[0]))
  74. //
  75. // functions
  76. //
  77. void _CRTAPI1 main(int argc, char** argv) {
  78. BOOL ok;
  79. LPSTR urls[64];
  80. int numberOfUrls = 0;
  81. BOOL fCallback = FALSE;
  82. INTERNET_PORT proxyPort = 0;
  83. LPSTR proxy = NULL;
  84. for (--argc, ++argv; argc; --argc, ++argv) {
  85. if (IS_ARG(**argv)) {
  86. switch (tolower(*++*argv)) {
  87. case 'c':
  88. fCallback = TRUE;
  89. break;
  90. case 'p':
  91. proxyPort = (INTERNET_PORT)atoi(++*argv);
  92. break;
  93. case 'v':
  94. Verbose = TRUE;
  95. break;
  96. default:
  97. printf("unknown command line flag: '%c'\n", **argv);
  98. usage();
  99. }
  100. } else if (proxy == NULL) {
  101. proxy = *argv;
  102. } else {
  103. if (numberOfUrls == sizeof(urls)/sizeof(urls[0]) - 1) {
  104. break;
  105. }
  106. urls[numberOfUrls++] = *argv;
  107. }
  108. }
  109. //
  110. // exit function
  111. //
  112. atexit(my_cleanup);
  113. //
  114. // let's have a status callback
  115. //
  116. if (fCallback) {
  117. PreviousCallback = InternetSetStatusCallback(my_callback);
  118. if (Verbose) {
  119. printf("previous Internet callback = %x\n", PreviousCallback);
  120. }
  121. }
  122. //
  123. // open gateway
  124. //
  125. InternetHandle = InternetOpen("cernprox",
  126. CERN_PROXY_INTERNET_ACCESS,
  127. proxy,
  128. proxyPort,
  129. 0
  130. );
  131. if (InternetHandle == NULL) {
  132. printf("error: cernprox: InternetOpen() returns %d\n", GetLastError());
  133. exit(1);
  134. }
  135. if (numberOfUrls == 0) {
  136. default_url_test();
  137. } else {
  138. open_urls(urls, numberOfUrls);
  139. }
  140. ok = InternetCloseHandle(InternetHandle);
  141. if (!ok) {
  142. printf("error: cernprox: InternetClose(InternetHandle) returns %d\n", GetLastError());
  143. exit(1);
  144. } else {
  145. InternetHandle = NULL;
  146. }
  147. printf("Done.\n");
  148. exit(0);
  149. }
  150. void usage() {
  151. printf("usage: cernprox [-c] [-v] <proxy> [-p#] [url]*\n"
  152. "where: -c = enable status call-backs\n"
  153. " -p = port for CERN proxy\n"
  154. " -v = Verbose mode\n"
  155. " proxy = CERN proxy server\n"
  156. " url = one or more URLs to open\n"
  157. );
  158. exit(1);
  159. }
  160. void _CRTAPI1 my_cleanup() {
  161. if (InternetHandle != NULL) {
  162. printf("closing Internet handle %x\n", InternetHandle);
  163. if (!InternetCloseHandle(InternetHandle)) {
  164. print_error("my_cleanup", "InternetCloseHandle()");
  165. }
  166. }
  167. }
  168. VOID
  169. my_callback(
  170. DWORD Context,
  171. DWORD Status,
  172. LPVOID Info,
  173. DWORD Length
  174. )
  175. {
  176. char* type$;
  177. switch (Status) {
  178. case INTERNET_STATUS_RESOLVING_NAME:
  179. type$ = "RESOLVING NAME";
  180. break;
  181. case INTERNET_STATUS_NAME_RESOLVED:
  182. type$ = "NAME RESOLVED";
  183. break;
  184. case INTERNET_STATUS_CONNECTING_TO_SERVER:
  185. type$ = "CONNECTING TO SERVER";
  186. break;
  187. case INTERNET_STATUS_CONNECTED_TO_SERVER:
  188. type$ = "CONNECTED TO SERVER";
  189. break;
  190. case INTERNET_STATUS_SENDING_REQUEST:
  191. type$ = "SENDING REQUEST";
  192. break;
  193. case INTERNET_STATUS_REQUEST_SENT:
  194. type$ = "REQUEST SENT";
  195. break;
  196. case INTERNET_STATUS_RECEIVING_RESPONSE:
  197. type$ = "RECEIVING RESPONSE";
  198. break;
  199. case INTERNET_STATUS_RESPONSE_RECEIVED:
  200. type$ = "RESPONSE RECEIVED";
  201. break;
  202. case INTERNET_STATUS_CLOSING_CONNECTION:
  203. type$ = "CLOSING CONNECTION";
  204. break;
  205. case INTERNET_STATUS_CONNECTION_CLOSED:
  206. type$ = "CONNECTION CLOSED";
  207. break;
  208. default:
  209. type$ = "???";
  210. break;
  211. }
  212. printf("callback: %s ", type$);
  213. if (Info) {
  214. printf(Info);
  215. }
  216. putchar('\n');
  217. }
  218. void default_url_test() {
  219. open_urls(default_urls, NUMBER_OF_DEFAULT_URLS);
  220. }
  221. void open_urls(LPSTR* purls, int nurls) {
  222. HINTERNET handle;
  223. while (nurls--) {
  224. printf("\nopening URL \"%s\"\n\n", *purls);
  225. handle = InternetOpenUrl(InternetHandle,
  226. *purls,
  227. NULL,
  228. 0,
  229. 0,
  230. 0
  231. );
  232. if (handle == NULL) {
  233. print_error("open_urls", "InternetOpenUrl(%s)", *purls);
  234. } else {
  235. get_url_data(handle);
  236. }
  237. ++purls;
  238. }
  239. }
  240. void get_url_data(HINTERNET handle) {
  241. DWORD handleType;
  242. DWORD handleTypeLen;
  243. handleTypeLen = sizeof(handleType);
  244. if (InternetQueryOption(handle,
  245. INTERNET_OPTION_HANDLE_TYPE,
  246. (LPVOID)&handleType,
  247. &handleTypeLen
  248. )) {
  249. if (handleType != INTERNET_HANDLE_TYPE_HTTP_REQUEST) {
  250. printf("error: get_url_data: handle type %d returned, should be %d\n",
  251. handleType,
  252. INTERNET_HANDLE_TYPE_HTTP_REQUEST
  253. );
  254. }
  255. switch (handleType) {
  256. case INTERNET_HANDLE_TYPE_INTERNET:
  257. printf("error: get_url_data: HANDLE_TYPE_INTERNET?\n");
  258. break;
  259. case INTERNET_HANDLE_TYPE_CONNECT_FTP:
  260. printf("error: get_url_data: INTERNET_HANDLE_TYPE_CONNECT_FTP?\n");
  261. break;
  262. case INTERNET_HANDLE_TYPE_CONNECT_GOPHER:
  263. printf("error: get_url_data: INTERNET_HANDLE_TYPE_CONNECT_GOPHER?\n");
  264. break;
  265. case INTERNET_HANDLE_TYPE_CONNECT_HTTP:
  266. printf("error: get_url_data: INTERNET_HANDLE_TYPE_CONNECT_HTTP?\n");
  267. break;
  268. case INTERNET_HANDLE_TYPE_FTP_FIND:
  269. ftp_find(handle);
  270. break;
  271. case INTERNET_HANDLE_TYPE_GOPHER_FIND:
  272. gopher_find(handle);
  273. break;
  274. case INTERNET_HANDLE_TYPE_FTP_FIND_HTML:
  275. case INTERNET_HANDLE_TYPE_FTP_FILE:
  276. case INTERNET_HANDLE_TYPE_FTP_FILE_HTML:
  277. case INTERNET_HANDLE_TYPE_GOPHER_FIND_HTML:
  278. case INTERNET_HANDLE_TYPE_GOPHER_FILE:
  279. case INTERNET_HANDLE_TYPE_GOPHER_FILE_HTML:
  280. case INTERNET_HANDLE_TYPE_HTTP_REQUEST:
  281. read_data(handle);
  282. break;
  283. default:
  284. printf("error: get_url_data: handleType == %d?\n", handleType);
  285. break;
  286. }
  287. if (!InternetCloseHandle(handle)) {
  288. print_error("get_url_data", "InternetCloseHandle()");
  289. }
  290. } else {
  291. print_error("get_url_data", "InternetQueryOption()");
  292. }
  293. }
  294. void ftp_find(HINTERNET handle) {
  295. WIN32_FIND_DATA ffd;
  296. while (InternetFindNextFile(handle, (LPVOID)&ffd)) {
  297. SYSTEMTIME stDbg;
  298. if (!FileTimeToSystemTime(&ffd.ftLastWriteTime, &stDbg)) {
  299. printf("| ftLastWriteTime = ERROR\n");
  300. }
  301. printf("%2d-%02d-%04d %2d:%02d:%02d %15d bytes %-s%-s%-s %s\n",
  302. stDbg.wMonth, stDbg.wDay, stDbg.wYear,
  303. stDbg.wHour, stDbg.wMinute, stDbg.wSecond,
  304. ffd.nFileSizeLow,
  305. (ffd.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) ? "Normal " : "",
  306. (ffd.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? "ReadOnly " : "",
  307. (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? "Directory " : "",
  308. ffd.cFileName
  309. );
  310. }
  311. if (GetLastError() != ERROR_NO_MORE_FILES) {
  312. print_error("ftp_find", "InternetFindNextFile()");
  313. }
  314. }
  315. void gopher_find(HINTERNET handle) {
  316. GOPHER_FIND_DATA data;
  317. int i;
  318. i = 0;
  319. while (InternetFindNextFile(handle, (LPVOID)&data)) {
  320. LPGOPHER_FIND_DATA p;
  321. SYSTEMTIME systemTime;
  322. char timeBuf[9];
  323. char sizeBuf[32];
  324. p = (LPGOPHER_FIND_DATA)&data;
  325. if ((p->LastModificationTime.dwLowDateTime != 0)
  326. && (p->LastModificationTime.dwHighDateTime != 0)) {
  327. FileTimeToSystemTime(&p->LastModificationTime, &systemTime);
  328. sprintf(timeBuf,
  329. "%02d-%02d-%02d",
  330. systemTime.wMonth,
  331. systemTime.wDay,
  332. systemTime.wYear % 100
  333. );
  334. sprintf(sizeBuf, "%d", p->SizeLow);
  335. } else {
  336. timeBuf[0] = '\0';
  337. sizeBuf[0] = '\0';
  338. }
  339. printf("%5d %c %7s %10s %8s %s\n",
  340. i,
  341. (p->GopherType & GOPHER_TYPE_GOPHER_PLUS) ? '+' : ' ',
  342. (p->GopherType & GOPHER_TYPE_TEXT_FILE) ? "Text"
  343. : (p->GopherType & GOPHER_TYPE_DIRECTORY) ? "Dir"
  344. : (p->GopherType & GOPHER_TYPE_CSO) ? "Phone"
  345. : (p->GopherType & GOPHER_TYPE_ERROR) ? "Error"
  346. : (p->GopherType & GOPHER_TYPE_MAC_BINHEX) ? "MAC"
  347. : (p->GopherType & GOPHER_TYPE_DOS_ARCHIVE) ? "Archive"
  348. : (p->GopherType & GOPHER_TYPE_UNIX_UUENCODED) ? "UNIX"
  349. : (p->GopherType & GOPHER_TYPE_INDEX_SERVER) ? "Index"
  350. : (p->GopherType & GOPHER_TYPE_TELNET) ? "Telnet"
  351. : (p->GopherType & GOPHER_TYPE_BINARY) ? "Binary"
  352. : (p->GopherType & GOPHER_TYPE_REDUNDANT) ? "Backup"
  353. : (p->GopherType & GOPHER_TYPE_TN3270) ? "TN3270"
  354. : (p->GopherType & GOPHER_TYPE_GIF) ? "GIF"
  355. : (p->GopherType & GOPHER_TYPE_IMAGE) ? "Image"
  356. : (p->GopherType & GOPHER_TYPE_BITMAP) ? "Bitmap"
  357. : (p->GopherType & GOPHER_TYPE_MOVIE) ? "Movie"
  358. : (p->GopherType & GOPHER_TYPE_SOUND) ? "Sound"
  359. : (p->GopherType & GOPHER_TYPE_HTML) ? "HTML"
  360. : (p->GopherType & GOPHER_TYPE_PDF) ? "PDF"
  361. : (p->GopherType & GOPHER_TYPE_CALENDAR) ? "Cal"
  362. : (p->GopherType & GOPHER_TYPE_INLINE) ? "Inline"
  363. : (p->GopherType & GOPHER_TYPE_UNKNOWN) ? "Unknown"
  364. : "\a????",
  365. sizeBuf,
  366. timeBuf,
  367. p->DisplayString
  368. );
  369. ++i;
  370. }
  371. if (GetLastError() != ERROR_NO_MORE_FILES) {
  372. print_error("gopher_find", "InternetFindNextFile()");
  373. }
  374. }
  375. void read_data(HINTERNET handle) {
  376. char buf[1021]; // odd number for fun!
  377. DWORD nread;
  378. while (InternetReadFile(handle, buf, sizeof(buf), &nread)) {
  379. if (!nread) {
  380. printf("=== end of file ===\n");
  381. break;
  382. } else {
  383. setmode(1, _O_BINARY);
  384. write(1, buf, nread);
  385. }
  386. }
  387. if (GetLastError() != ERROR_SUCCESS) {
  388. print_error("read_file", "InternetReadFile()");
  389. }
  390. }
  391. void print_error(char* func, char* format, ...) {
  392. va_list argptr;
  393. char buf[256];
  394. DWORD error;
  395. error = GetLastError();
  396. va_start(argptr, format);
  397. vsprintf(buf, format, argptr);
  398. printf("error: %s: %s returns %d [%s]\n", func, buf, error, map_error(error));
  399. va_end(argptr);
  400. if (error == ERROR_INTERNET_EXTENDED_ERROR) {
  401. get_last_internet_error();
  402. }
  403. }
  404. #define ERROR_CASE(error) case error: return # error
  405. char* map_error(DWORD error) {
  406. switch (error) {
  407. //
  408. // Windows base errors
  409. //
  410. ERROR_CASE(ERROR_SUCCESS);
  411. ERROR_CASE(ERROR_INVALID_FUNCTION);
  412. ERROR_CASE(ERROR_FILE_NOT_FOUND);
  413. ERROR_CASE(ERROR_PATH_NOT_FOUND);
  414. ERROR_CASE(ERROR_ACCESS_DENIED);
  415. ERROR_CASE(ERROR_INVALID_HANDLE);
  416. ERROR_CASE(ERROR_NOT_ENOUGH_MEMORY);
  417. ERROR_CASE(ERROR_NO_MORE_FILES);
  418. ERROR_CASE(ERROR_INVALID_PASSWORD);
  419. ERROR_CASE(ERROR_INVALID_PARAMETER);
  420. ERROR_CASE(ERROR_BUFFER_OVERFLOW);
  421. ERROR_CASE(ERROR_NO_MORE_SEARCH_HANDLES);
  422. ERROR_CASE(ERROR_INVALID_TARGET_HANDLE);
  423. ERROR_CASE(ERROR_CALL_NOT_IMPLEMENTED);
  424. ERROR_CASE(ERROR_INSUFFICIENT_BUFFER);
  425. ERROR_CASE(ERROR_INVALID_NAME);
  426. ERROR_CASE(ERROR_INVALID_LEVEL);
  427. ERROR_CASE(ERROR_BAD_PATHNAME);
  428. ERROR_CASE(ERROR_BUSY);
  429. ERROR_CASE(ERROR_ALREADY_EXISTS);
  430. ERROR_CASE(ERROR_FILENAME_EXCED_RANGE);
  431. ERROR_CASE(ERROR_MORE_DATA);
  432. ERROR_CASE(ERROR_NO_MORE_ITEMS);
  433. ERROR_CASE(ERROR_INVALID_ADDRESS);
  434. ERROR_CASE(ERROR_OPERATION_ABORTED);
  435. ERROR_CASE(RPC_S_INVALID_STRING_BINDING);
  436. ERROR_CASE(RPC_S_WRONG_KIND_OF_BINDING);
  437. ERROR_CASE(RPC_S_INVALID_BINDING);
  438. ERROR_CASE(RPC_S_PROTSEQ_NOT_SUPPORTED);
  439. ERROR_CASE(RPC_S_INVALID_RPC_PROTSEQ);
  440. ERROR_CASE(RPC_S_INVALID_STRING_UUID);
  441. ERROR_CASE(RPC_S_INVALID_ENDPOINT_FORMAT);
  442. ERROR_CASE(RPC_S_INVALID_NET_ADDR);
  443. ERROR_CASE(RPC_S_NO_ENDPOINT_FOUND);
  444. ERROR_CASE(RPC_S_INVALID_TIMEOUT);
  445. ERROR_CASE(RPC_S_OBJECT_NOT_FOUND);
  446. ERROR_CASE(RPC_S_ALREADY_REGISTERED);
  447. ERROR_CASE(RPC_S_TYPE_ALREADY_REGISTERED);
  448. ERROR_CASE(RPC_S_ALREADY_LISTENING);
  449. ERROR_CASE(RPC_S_NO_PROTSEQS_REGISTERED);
  450. ERROR_CASE(RPC_S_NOT_LISTENING);
  451. ERROR_CASE(RPC_S_UNKNOWN_MGR_TYPE);
  452. ERROR_CASE(RPC_S_UNKNOWN_IF);
  453. ERROR_CASE(RPC_S_NO_BINDINGS);
  454. ERROR_CASE(RPC_S_NO_PROTSEQS);
  455. ERROR_CASE(RPC_S_CANT_CREATE_ENDPOINT);
  456. ERROR_CASE(RPC_S_OUT_OF_RESOURCES);
  457. ERROR_CASE(RPC_S_SERVER_UNAVAILABLE);
  458. ERROR_CASE(RPC_S_SERVER_TOO_BUSY);
  459. ERROR_CASE(RPC_S_INVALID_NETWORK_OPTIONS);
  460. ERROR_CASE(RPC_S_NO_CALL_ACTIVE);
  461. ERROR_CASE(RPC_S_CALL_FAILED);
  462. ERROR_CASE(RPC_S_CALL_FAILED_DNE);
  463. ERROR_CASE(RPC_S_PROTOCOL_ERROR);
  464. ERROR_CASE(RPC_S_UNSUPPORTED_TRANS_SYN);
  465. ERROR_CASE(RPC_S_UNSUPPORTED_TYPE);
  466. ERROR_CASE(RPC_S_INVALID_TAG);
  467. ERROR_CASE(RPC_S_INVALID_BOUND);
  468. ERROR_CASE(RPC_S_NO_ENTRY_NAME);
  469. ERROR_CASE(RPC_S_INVALID_NAME_SYNTAX);
  470. ERROR_CASE(RPC_S_UNSUPPORTED_NAME_SYNTAX);
  471. ERROR_CASE(RPC_S_UUID_NO_ADDRESS);
  472. ERROR_CASE(RPC_S_DUPLICATE_ENDPOINT);
  473. ERROR_CASE(RPC_S_UNKNOWN_AUTHN_TYPE);
  474. ERROR_CASE(RPC_S_MAX_CALLS_TOO_SMALL);
  475. ERROR_CASE(RPC_S_STRING_TOO_LONG);
  476. ERROR_CASE(RPC_S_PROTSEQ_NOT_FOUND);
  477. ERROR_CASE(RPC_S_PROCNUM_OUT_OF_RANGE);
  478. ERROR_CASE(RPC_S_BINDING_HAS_NO_AUTH);
  479. ERROR_CASE(RPC_S_UNKNOWN_AUTHN_SERVICE);
  480. ERROR_CASE(RPC_S_UNKNOWN_AUTHN_LEVEL);
  481. ERROR_CASE(RPC_S_INVALID_AUTH_IDENTITY);
  482. ERROR_CASE(RPC_S_UNKNOWN_AUTHZ_SERVICE);
  483. ERROR_CASE(EPT_S_INVALID_ENTRY);
  484. ERROR_CASE(EPT_S_CANT_PERFORM_OP);
  485. ERROR_CASE(EPT_S_NOT_REGISTERED);
  486. ERROR_CASE(RPC_S_NOTHING_TO_EXPORT);
  487. ERROR_CASE(RPC_S_INCOMPLETE_NAME);
  488. ERROR_CASE(RPC_S_INVALID_VERS_OPTION);
  489. ERROR_CASE(RPC_S_NO_MORE_MEMBERS);
  490. ERROR_CASE(RPC_S_NOT_ALL_OBJS_UNEXPORTED);
  491. ERROR_CASE(RPC_S_INTERFACE_NOT_FOUND);
  492. ERROR_CASE(RPC_S_ENTRY_ALREADY_EXISTS);
  493. ERROR_CASE(RPC_S_ENTRY_NOT_FOUND);
  494. ERROR_CASE(RPC_S_NAME_SERVICE_UNAVAILABLE);
  495. ERROR_CASE(RPC_S_INVALID_NAF_ID);
  496. ERROR_CASE(RPC_S_CANNOT_SUPPORT);
  497. ERROR_CASE(RPC_S_NO_CONTEXT_AVAILABLE);
  498. ERROR_CASE(RPC_S_INTERNAL_ERROR);
  499. ERROR_CASE(RPC_S_ZERO_DIVIDE);
  500. ERROR_CASE(RPC_S_ADDRESS_ERROR);
  501. ERROR_CASE(RPC_S_FP_DIV_ZERO);
  502. ERROR_CASE(RPC_S_FP_UNDERFLOW);
  503. ERROR_CASE(RPC_S_FP_OVERFLOW);
  504. ERROR_CASE(RPC_X_NO_MORE_ENTRIES);
  505. ERROR_CASE(RPC_X_SS_CHAR_TRANS_OPEN_FAIL);
  506. ERROR_CASE(RPC_X_SS_CHAR_TRANS_SHORT_FILE);
  507. ERROR_CASE(RPC_X_SS_IN_NULL_CONTEXT);
  508. ERROR_CASE(RPC_X_SS_CONTEXT_DAMAGED);
  509. ERROR_CASE(RPC_X_SS_HANDLES_MISMATCH);
  510. ERROR_CASE(RPC_X_SS_CANNOT_GET_CALL_HANDLE);
  511. ERROR_CASE(RPC_X_NULL_REF_POINTER);
  512. ERROR_CASE(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
  513. ERROR_CASE(RPC_X_BYTE_COUNT_TOO_SMALL);
  514. ERROR_CASE(RPC_X_BAD_STUB_DATA);
  515. //
  516. // WinInet errors
  517. //
  518. ERROR_CASE(ERROR_INTERNET_OUT_OF_HANDLES);
  519. ERROR_CASE(ERROR_INTERNET_TIMEOUT);
  520. ERROR_CASE(ERROR_INTERNET_EXTENDED_ERROR);
  521. ERROR_CASE(ERROR_INTERNET_INTERNAL_ERROR);
  522. ERROR_CASE(ERROR_INTERNET_INVALID_URL);
  523. ERROR_CASE(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
  524. ERROR_CASE(ERROR_INTERNET_NAME_NOT_RESOLVED);
  525. ERROR_CASE(ERROR_INTERNET_PROTOCOL_NOT_FOUND);
  526. ERROR_CASE(ERROR_INTERNET_INVALID_OPTION);
  527. ERROR_CASE(ERROR_INTERNET_BAD_OPTION_LENGTH);
  528. ERROR_CASE(ERROR_INTERNET_OPTION_NOT_SETTABLE);
  529. ERROR_CASE(ERROR_INTERNET_SHUTDOWN);
  530. ERROR_CASE(ERROR_INTERNET_INCORRECT_USER_NAME);
  531. ERROR_CASE(ERROR_INTERNET_INCORRECT_PASSWORD);
  532. ERROR_CASE(ERROR_INTERNET_LOGIN_FAILURE);
  533. ERROR_CASE(ERROR_INTERNET_INVALID_OPERATION);
  534. ERROR_CASE(ERROR_INTERNET_OPERATION_CANCELLED);
  535. ERROR_CASE(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
  536. ERROR_CASE(ERROR_INTERNET_NOT_LOCAL_HANDLE);
  537. ERROR_CASE(ERROR_INTERNET_NOT_PROXY_REQUEST);
  538. ERROR_CASE(ERROR_INTERNET_REGISTRY_VALUE_NOT_FOUND);
  539. ERROR_CASE(ERROR_INTERNET_BAD_REGISTRY_PARAMETER);
  540. ERROR_CASE(ERROR_FTP_TRANSFER_IN_PROGRESS);
  541. ERROR_CASE(ERROR_FTP_CONNECTED);
  542. ERROR_CASE(ERROR_FTP_DROPPED);
  543. ERROR_CASE(ERROR_GOPHER_PROTOCOL_ERROR);
  544. ERROR_CASE(ERROR_GOPHER_NOT_FILE);
  545. ERROR_CASE(ERROR_GOPHER_DATA_ERROR);
  546. ERROR_CASE(ERROR_GOPHER_END_OF_DATA);
  547. ERROR_CASE(ERROR_GOPHER_INVALID_LOCATOR);
  548. ERROR_CASE(ERROR_GOPHER_INCORRECT_LOCATOR_TYPE);
  549. ERROR_CASE(ERROR_GOPHER_NOT_GOPHER_PLUS);
  550. ERROR_CASE(ERROR_GOPHER_ATTRIBUTE_NOT_FOUND);
  551. ERROR_CASE(ERROR_GOPHER_UNKNOWN_LOCATOR);
  552. ERROR_CASE(ERROR_HTTP_HEADER_NOT_FOUND);
  553. ERROR_CASE(ERROR_HTTP_DOWNLEVEL_SERVER);
  554. ERROR_CASE(ERROR_HTTP_INVALID_SERVER_RESPONSE);
  555. //
  556. // Windows sockets errors
  557. //
  558. ERROR_CASE(WSAEINTR);
  559. ERROR_CASE(WSAEBADF);
  560. ERROR_CASE(WSAEACCES);
  561. ERROR_CASE(WSAEFAULT);
  562. ERROR_CASE(WSAEINVAL);
  563. ERROR_CASE(WSAEMFILE);
  564. ERROR_CASE(WSAEWOULDBLOCK);
  565. ERROR_CASE(WSAEINPROGRESS);
  566. ERROR_CASE(WSAEALREADY);
  567. ERROR_CASE(WSAENOTSOCK);
  568. ERROR_CASE(WSAEDESTADDRREQ);
  569. ERROR_CASE(WSAEMSGSIZE);
  570. ERROR_CASE(WSAEPROTOTYPE);
  571. ERROR_CASE(WSAENOPROTOOPT);
  572. ERROR_CASE(WSAEPROTONOSUPPORT);
  573. ERROR_CASE(WSAESOCKTNOSUPPORT);
  574. ERROR_CASE(WSAEOPNOTSUPP);
  575. ERROR_CASE(WSAEPFNOSUPPORT);
  576. ERROR_CASE(WSAEAFNOSUPPORT);
  577. ERROR_CASE(WSAEADDRINUSE);
  578. ERROR_CASE(WSAEADDRNOTAVAIL);
  579. ERROR_CASE(WSAENETDOWN);
  580. ERROR_CASE(WSAENETUNREACH);
  581. ERROR_CASE(WSAENETRESET);
  582. ERROR_CASE(WSAECONNABORTED);
  583. ERROR_CASE(WSAECONNRESET);
  584. ERROR_CASE(WSAENOBUFS);
  585. ERROR_CASE(WSAEISCONN);
  586. ERROR_CASE(WSAENOTCONN);
  587. ERROR_CASE(WSAESHUTDOWN);
  588. ERROR_CASE(WSAETOOMANYREFS);
  589. ERROR_CASE(WSAETIMEDOUT);
  590. ERROR_CASE(WSAECONNREFUSED);
  591. ERROR_CASE(WSAELOOP);
  592. ERROR_CASE(WSAENAMETOOLONG);
  593. ERROR_CASE(WSAEHOSTDOWN);
  594. ERROR_CASE(WSAEHOSTUNREACH);
  595. ERROR_CASE(WSAENOTEMPTY);
  596. ERROR_CASE(WSAEPROCLIM);
  597. ERROR_CASE(WSAEUSERS);
  598. ERROR_CASE(WSAEDQUOT);
  599. ERROR_CASE(WSAESTALE);
  600. ERROR_CASE(WSAEREMOTE);
  601. ERROR_CASE(WSAEDISCON);
  602. ERROR_CASE(WSASYSNOTREADY);
  603. ERROR_CASE(WSAVERNOTSUPPORTED);
  604. ERROR_CASE(WSANOTINITIALISED);
  605. ERROR_CASE(WSAHOST_NOT_FOUND);
  606. ERROR_CASE(WSATRY_AGAIN);
  607. ERROR_CASE(WSANO_RECOVERY);
  608. ERROR_CASE(WSANO_DATA);
  609. default:
  610. return "?";
  611. }
  612. }
  613. void get_last_internet_error() {
  614. DWORD bufLength;
  615. char buffer[256];
  616. DWORD category;
  617. bufLength = sizeof(buffer);
  618. if (InternetGetLastResponseInfo(&category, buffer, &bufLength)) {
  619. printf("InternetGetLastResponseInfo() returns %d bytes\n", bufLength);
  620. if (bufLength != 0) {
  621. printf("Text = \"%s\"\n", buffer);
  622. }
  623. if (strlen(buffer) != bufLength) {
  624. printf("\aerror: get_last_internet_error: InternetGetLastResponseInfo() returns %d bytes; strlen(buffer) = %d\n",
  625. bufLength,
  626. strlen(buffer)
  627. );
  628. }
  629. } else {
  630. LPSTR errbuf;
  631. printf("InternetGetLastResponseInfo() returns error %d (bufLength = %d)\n",
  632. GetLastError(),
  633. bufLength
  634. );
  635. if ((errbuf = malloc(bufLength)) == NULL) {
  636. printf("error: get_last_internet_error: malloc(%d) failed\n", bufLength);
  637. return;
  638. }
  639. if (InternetGetLastResponseInfo(&category, errbuf, &bufLength)) {
  640. printf("InternetGetLastResponseInfo() returns %d bytes\n", bufLength);
  641. if (bufLength != 0) {
  642. printf("Text = \"%s\"\n", errbuf);
  643. }
  644. if (strlen(buffer) != bufLength) {
  645. printf("\aerror: get_last_internet_error: InternetGetLastResponseInfo() returns %d bytes; strlen(buffer) = %d\n",
  646. bufLength,
  647. strlen(buffer)
  648. );
  649. }
  650. } else {
  651. printf("error: get_last_internet_error: InternetGetLastResponseInfo() returns error %d (bufLength = %d)\n",
  652. GetLastError(),
  653. bufLength
  654. );
  655. }
  656. free(errbuf);
  657. }
  658. }