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.

117 lines
3.0 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4. #include <wininet.h>
  5. #ifndef _CRTAPI1
  6. #define _CRTAPI1
  7. #endif
  8. #define IS_ARG(c) (((c) == '-') || ((c) == '/'))
  9. void _CRTAPI1 main(int, char**);
  10. void usage(void);
  11. void _CRTAPI1 main(int argc, char** argv) {
  12. HINTERNET h1;
  13. HINTERNET h2;
  14. HINTERNET h3;
  15. HINTERNET h4;
  16. LPSTR search;
  17. search = NULL;
  18. for (--argc, ++argv; argc; --argc, ++argv) {
  19. if (IS_ARG(**argv)) {
  20. switch (*++*argv) {
  21. case 'v':
  22. printf("Ha! There is no verbose mode, sucker. Try again\n");
  23. break;
  24. default:
  25. printf("error: unrecognized command line flag '%c'\n", **argv);
  26. usage();
  27. }
  28. } else if (!search) {
  29. search = *argv;
  30. } else {
  31. printf("error: unrecognized command line argument \"%s\"\n", *argv);
  32. usage();
  33. }
  34. }
  35. h1 = InternetOpen("multfind", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
  36. if (!h1) {
  37. printf("error: InternetOpen() returns %d\n", GetLastError());
  38. exit(1);
  39. }
  40. h2 = InternetConnect(h1,
  41. "rfirthmips",
  42. 0,
  43. NULL,
  44. NULL,
  45. INTERNET_SERVICE_FTP,
  46. 0,
  47. 0
  48. );
  49. if (!h2) {
  50. printf("error: InternetConnect() returns %d\n", GetLastError());
  51. exit(1);
  52. }
  53. h3 = FtpFindFirstFile(h2, search, NULL, INTERNET_FLAG_RELOAD, 0);
  54. if (!h3) {
  55. printf("error: FtpFindFirstFile() #1 returns %d\n", GetLastError());
  56. exit(1);
  57. }
  58. //
  59. // try simultaneous search for same thing - should fail
  60. //
  61. h4 = FtpFindFirstFile(h2, search, NULL, INTERNET_FLAG_RELOAD, 0);
  62. if (h4) {
  63. printf("error: FtpFindFirstFile() #2 returns OK\n");
  64. exit(1);
  65. } else {
  66. printf("FtpFindFirstFile() #2 returns %d\n", GetLastError());
  67. }
  68. //
  69. // close first handle and try again - should succeed
  70. //
  71. if (!InternetCloseHandle(h3)) {
  72. printf("error: InternetCloseHandle() returns %d\n", GetLastError());
  73. }
  74. h3 = FtpFindFirstFile(h2, search, NULL, INTERNET_FLAG_RELOAD, 0);
  75. if (!h3) {
  76. printf("error: FtpFindFirstFile() returns %d\n", GetLastError());
  77. exit(1);
  78. }
  79. //
  80. // try a second time again - should fail again
  81. //
  82. h4 = FtpFindFirstFile(h2, search, NULL, INTERNET_FLAG_RELOAD, 0);
  83. if (h4) {
  84. printf("error: FtpFindFirstFile() #2 returns OK\n");
  85. exit(1);
  86. } else {
  87. printf("FtpFindFirstFile() #2 returns %d\n", GetLastError());
  88. }
  89. printf("Done.\n");
  90. exit(0);
  91. }
  92. void usage() {
  93. printf("usage: multfind [-v] [search argument]\n"
  94. "where: -v = Verbose mode\n"
  95. );
  96. exit(1);
  97. }