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.

932 lines
23 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. apitest.c
  5. Abstract:
  6. Program to test DAV
  7. Author:
  8. Shishir Pardikar (shishirp) 4-24-97
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #include <windows.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <time.h>
  18. #include <wininet.h>
  19. #include <winnetwk.h>
  20. //=================================================================================
  21. #define MAX_COMMAND_ARGS 32
  22. #define DEFAULT_BUFFER_SIZE 1024 // 1k
  23. //=================================================================================
  24. // The order of these must match the order in GlobalCommandInfo[]
  25. typedef enum _COMMAND_CODE {
  26. CmdDAVGetProp,
  27. CmdDAVSetProp,
  28. CmdDAVEnumServer,
  29. CmdGetSpace,
  30. CmdFreeSpace,
  31. CmdHelp,
  32. CmdQuit,
  33. UnknownCommand
  34. } COMMAND_CODE, *LPCOMMAND_CODE;
  35. typedef struct _COMMAND_INFO {
  36. LPSTR CommandName;
  37. LPSTR CommandParams;
  38. COMMAND_CODE CommandCode;
  39. } COMMAND_INFO, *LPCOMMAND_INFO;
  40. DWORD
  41. ProcessDAVSetProp(
  42. DWORD argc,
  43. LPSTR *argv
  44. );
  45. DWORD
  46. ProcessDAVGetProp(
  47. DWORD argc,
  48. LPSTR *argv
  49. );
  50. DWORD
  51. ProcessDAVEnumServer(
  52. DWORD argc,
  53. LPSTR *argv
  54. );
  55. DWORD
  56. ProcessDAVGetSpace(
  57. DWORD argc,
  58. LPSTR *argv
  59. );
  60. DWORD
  61. ProcessDAVFreeSpace(
  62. DWORD argc,
  63. LPSTR *argv
  64. );
  65. DWORD
  66. APIENTRY
  67. DavFreeUsedDiskSpace(
  68. DWORD dwPercent
  69. );
  70. DWORD
  71. APIENTRY
  72. DavGetDiskSpaceUsage(
  73. LPWSTR lptzLocation,
  74. DWORD *lpdwSize,
  75. ULARGE_INTEGER *lpMaxSpace,
  76. ULARGE_INTEGER *lpUsedSpace
  77. );
  78. //=================================================================================
  79. FILE *UncList = NULL;
  80. LPSTR g_lpWriteFileBuf = NULL;
  81. FILE *DumpUncList = NULL;
  82. DWORD cCommands = 0;
  83. DWORD cFails = 0;
  84. DWORD g_dwNumIterations = 1;
  85. DWORD g_dwIteration = 0;
  86. DWORD g_dwNumCmdIterations = 1;
  87. DWORD g_dwCmdIteration = 0;
  88. DWORD g_dwFileSize = 0;
  89. DWORD g_dwDiskCache = 0;
  90. BOOL g_bWriteFile = FALSE;
  91. BOOL g_bQuietMode = FALSE;
  92. BOOL g_bPerfMode = FALSE;
  93. BOOL g_bUseFile = FALSE;
  94. COMMAND_INFO GlobalCommandInfo[] = {
  95. {"GetProp", "Server", CmdDAVGetProp},
  96. {"SetProp", "Server Property Value", CmdDAVSetProp},
  97. {"Enum", "Enumerate shares", CmdDAVEnumServer},
  98. {"GetSpace", "Get Used Disk Space", CmdGetSpace},
  99. {"FreeSpace", "FreeSpace <percent of cache in decimal>", CmdFreeSpace},
  100. {"Help", "", CmdHelp},
  101. {"Quit", "", CmdQuit}
  102. };
  103. char szTestBuff[] = "00000888";
  104. char szDavProviderName[] = "Web Client Network";
  105. DWORD WINAPIV Format_String(LPSTR *plpsz, LPSTR lpszFmt, ...);
  106. DWORD WINAPI Format_Error(DWORD dwErr, LPSTR *plpsz);
  107. DWORD WINAPI Format_StringV(LPSTR *plpsz, LPCSTR lpszFmt, va_list *vArgs);
  108. DWORD WINAPI Format_MessageV(DWORD dwFlags, DWORD dwErr, LPSTR *plpsz, LPCSTR lpszFmt, va_list *vArgs);
  109. //=================================================================================
  110. DWORD
  111. ProcessCommandCode (
  112. DWORD CommandCode,
  113. DWORD CommandArgc,
  114. LPSTR *CommandArgv
  115. );
  116. DWORD
  117. GetLeafLenFromPath(
  118. LPSTR lpszPath
  119. );
  120. char rgXmlHeader[] = "Content-Type: text/xml; charset=\"utf-8\"";
  121. char rgXmlData[] =
  122. //"<?xml version=\"1.0\" encoding=\"utf-8\" ?> \r <D:propertyupdate xmlns:D=\"DAV:\" xmlns:Z=\"http://www.w3.com\"> \r <D:set><D:prop><Z:Win32FileAttributes>3</Z:Win32FileAttributes></D:prop></D:set></D:propertyupdate>";
  123. "<?xml version=\"1.0\" encoding=\"utf-8\" ?> \r <D:propertyupdate xmlns:D=\"DAV:\" xmlns:Z=\"http://www.w3.com\"> \r <D:set><D:prop><Z:Win32lastModifiedTime> 1000 2000 </Z:Win32lastModifiedTime></D:prop></D:set></D:propertyupdate>";
  124. char rgXmlDataHeader[] = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> \r <D:propertyupdate xmlns:D=\"DAV:\" xmlns:Z=\"http://www.w3.com\"> \r <D:set><D:prop>";
  125. char rgXmlDataTrailer[] = "</D:prop></D:set></D:propertyupdate>";
  126. char rgLastModifiedTimeTagHeader[] = "<Z:Win32lastModifiedTime>";
  127. char rgLastModifiedTimeTagTrailer[] = "</Z:Win32lastModifiedTime>";
  128. char Buffer[4096];
  129. //=================================================================================
  130. #if DBG
  131. #define TestDbgAssert(Predicate) \
  132. { \
  133. if (!(Predicate)) \
  134. TestDbgAssertFailed( #Predicate, __FILE__, __LINE__, NULL ); \
  135. }
  136. VOID
  137. TestDbgAssertFailed(
  138. LPSTR FailedAssertion,
  139. LPSTR FileName,
  140. DWORD LineNumber,
  141. LPSTR Message
  142. )
  143. /*++
  144. Routine Description:
  145. Assertion failed.
  146. Arguments:
  147. FailedAssertion :
  148. FileName :
  149. LineNumber :
  150. Message :
  151. Return Value:
  152. none.
  153. --*/
  154. {
  155. printf("Assert @ %s \n", FailedAssertion );
  156. printf("Assert Filename, %s \n", FileName );
  157. printf("Line Num. = %ld.\n", LineNumber );
  158. printf("Message is %s\n", Message );
  159. DebugBreak();
  160. }
  161. #else
  162. #define TestDbgAssert(_x_)
  163. #endif // DBG
  164. //=================================================================================
  165. VOID
  166. ParseArguments(
  167. LPSTR InBuffer,
  168. LPSTR *CArgv,
  169. LPDWORD CArgc
  170. )
  171. {
  172. LPSTR CurrentPtr = InBuffer;
  173. DWORD i = 0;
  174. DWORD Cnt = 0;
  175. for ( ;; ) {
  176. //
  177. // skip blanks.
  178. //
  179. while( *CurrentPtr == ' ' ) {
  180. CurrentPtr++;
  181. }
  182. if( *CurrentPtr == '\0' ) {
  183. break;
  184. }
  185. CArgv[i++] = CurrentPtr;
  186. //
  187. // go to next space.
  188. //
  189. while( (*CurrentPtr != '\0') &&
  190. (*CurrentPtr != '\n') ) {
  191. if( *CurrentPtr == '"' ) { // Deal with simple quoted args
  192. if( Cnt == 0 )
  193. CArgv[i-1] = ++CurrentPtr; // Set arg to after quote
  194. else
  195. *CurrentPtr = '\0'; // Remove end quote
  196. Cnt = !Cnt;
  197. }
  198. if( (Cnt == 0) && (*CurrentPtr == ' ') || // If we hit a space and no quotes yet we are done with this arg
  199. (*CurrentPtr == '\0') )
  200. break;
  201. CurrentPtr++;
  202. }
  203. if( *CurrentPtr == '\0' ) {
  204. break;
  205. }
  206. *CurrentPtr++ = '\0';
  207. }
  208. *CArgc = i;
  209. return;
  210. }
  211. #ifdef MAYBE
  212. //=================================================================================
  213. LPSTR
  214. GetUncFromFile ()
  215. {
  216. if (!UncList)
  217. {
  218. UncList = fopen ("Unclist", "r");
  219. if (UncList == NULL)
  220. return NULL;
  221. }
  222. if (fgets( UncBuffer, DEFAULT_BUFFER_SIZE, UncList))
  223. {
  224. UncBuffer[strlen(UncBuffer) -1] = '\0'; //kill line feed for no param cmds
  225. return UncBuffer;
  226. }
  227. else
  228. {
  229. fclose (UncList);
  230. UncList = NULL;
  231. return GetUncFromFile();
  232. }
  233. }
  234. #endif
  235. //=================================================================================
  236. COMMAND_CODE
  237. DecodeCommand(
  238. LPSTR CommandName
  239. )
  240. {
  241. DWORD i;
  242. DWORD NumCommands;
  243. NumCommands = sizeof(GlobalCommandInfo) / sizeof(COMMAND_INFO);
  244. TestDbgAssert( NumCommands <= UnknownCommand );
  245. for( i = 0; i < NumCommands; i++) {
  246. if(( lstrcmpi( CommandName, GlobalCommandInfo[i].CommandName ) == 0 )){
  247. return( GlobalCommandInfo[i].CommandCode );
  248. }
  249. }
  250. return( UnknownCommand );
  251. }
  252. //=================================================================================
  253. VOID
  254. PrintCommands(
  255. VOID
  256. )
  257. {
  258. DWORD i;
  259. DWORD NumCommands;
  260. NumCommands = sizeof(GlobalCommandInfo) / sizeof(COMMAND_INFO);
  261. TestDbgAssert( NumCommands <= UnknownCommand );
  262. for( i = 0; i < NumCommands; i++) {
  263. fprintf(stderr, " %s (%s)\n",
  264. GlobalCommandInfo[i].CommandName,
  265. GlobalCommandInfo[i].CommandParams );
  266. }
  267. }
  268. //=================================================================================
  269. VOID
  270. DisplayUsage(
  271. VOID
  272. )
  273. {
  274. DWORD dwTemp;
  275. char InBuffer[ DEFAULT_BUFFER_SIZE];
  276. memset( InBuffer, 0, sizeof(InBuffer));
  277. if (dwTemp = GetEnvironmentVariable("USERPROFILE", InBuffer, DEFAULT_BUFFER_SIZE))
  278. {
  279. fprintf(stderr, "Got var %x\n", dwTemp );
  280. fprintf(stderr, "%S\n", InBuffer );
  281. }
  282. else
  283. {
  284. fprintf(stderr, "No var\n" );
  285. fprintf(stderr, "Error %x\n", GetLastError());
  286. }
  287. fprintf(stderr, "Usage: command <command parameters>\n" );
  288. sscanf(szTestBuff, "%x", &dwTemp);
  289. fprintf(stderr, "%x \n", dwTemp);
  290. fprintf(stderr, "Commands : \n");
  291. PrintCommands();
  292. return;
  293. }
  294. //=================================================================================
  295. FILETIME
  296. GetGmtTime(
  297. VOID
  298. )
  299. {
  300. SYSTEMTIME SystemTime;
  301. FILETIME Time;
  302. GetSystemTime( &SystemTime );
  303. SystemTimeToFileTime( &SystemTime, &Time );
  304. return( Time );
  305. }
  306. //=================================================================================
  307. //=================================================================================
  308. DWORD
  309. ProcessCommandCode (
  310. DWORD CommandCode,
  311. DWORD CommandArgc,
  312. LPSTR *CommandArgv
  313. )
  314. {
  315. DWORD Error = ERROR_SUCCESS;
  316. switch( CommandCode ) {
  317. case CmdDAVGetProp:
  318. Error = ProcessDAVGetProp(CommandArgc, CommandArgv);
  319. break;
  320. case CmdDAVSetProp:
  321. Error = ProcessDAVSetProp(CommandArgc, CommandArgv);
  322. break;
  323. case CmdDAVEnumServer:
  324. Error = ProcessDAVEnumServer(CommandArgc, CommandArgv);
  325. case CmdGetSpace:
  326. Error = ProcessDAVGetSpace(CommandArgc, CommandArgv);
  327. break;
  328. case CmdFreeSpace:
  329. Error = ProcessDAVFreeSpace(CommandArgc, CommandArgv);
  330. break;
  331. case CmdHelp:
  332. DisplayUsage();
  333. break;
  334. case CmdQuit :
  335. exit (0);
  336. default:
  337. TestDbgAssert( FALSE );
  338. fprintf(stderr, "Unknown Command Specified.\n");
  339. DisplayUsage();
  340. break;
  341. }
  342. cCommands++;
  343. if( Error != ERROR_SUCCESS ) {
  344. LPSTR lpstr;
  345. cFails++;
  346. Format_Error(Error, &lpstr);
  347. printf("FAILED (%s), %ld-%s.\n",
  348. GlobalCommandInfo[CommandCode].CommandName, Error, lpstr );
  349. LocalFree(lpstr);
  350. }
  351. else {
  352. if(!g_bQuietMode)
  353. printf("Command (%s) successfully completed.\n", GlobalCommandInfo[CommandCode].CommandName );
  354. }
  355. return Error;
  356. }
  357. //=================================================================================
  358. VOID
  359. __cdecl
  360. main(
  361. int argc,
  362. char *argv[]
  363. )
  364. {
  365. DWORD Error;
  366. COMMAND_CODE CommandCode;
  367. CHAR InBuffer[DEFAULT_BUFFER_SIZE];
  368. DWORD CArgc;
  369. LPSTR CArgv[MAX_COMMAND_ARGS];
  370. unsigned u1 = 1, u2 = 0xffffffff;
  371. DWORD CommandArgc;
  372. LPSTR *CommandArgv;
  373. /* must check for batch mode. if there are command line parms, assume batch mode */
  374. if (argc > 1)
  375. {
  376. //this means that the arguments translate directly into CommandArgc....
  377. CommandCode = DecodeCommand( argv[1] );
  378. if( CommandCode == UnknownCommand ) {
  379. printf("Unknown Command Specified.\n");
  380. return;
  381. }
  382. CommandArgc = argc - 2;
  383. CommandArgv = &argv[2];
  384. Error = ProcessCommandCode (CommandCode,CommandArgc,CommandArgv);
  385. if (DumpUncList)
  386. fclose(DumpUncList);
  387. if (UncList)
  388. fclose(UncList);
  389. return;
  390. }
  391. DisplayUsage();
  392. for(;;) {
  393. fprintf(stderr, "Command : " );
  394. gets( InBuffer );
  395. CArgc = 0;
  396. ParseArguments( InBuffer, CArgv, &CArgc );
  397. if( CArgc < 1 ) {
  398. continue;
  399. }
  400. //
  401. // decode command.
  402. //
  403. CommandCode = DecodeCommand( CArgv[0] );
  404. if( CommandCode == UnknownCommand ) {
  405. fprintf(stderr, "Unknown Command Specified.\n");
  406. continue;
  407. }
  408. CommandArgc = CArgc - 1;
  409. CommandArgv = &CArgv[1];
  410. Error = ProcessCommandCode (CommandCode,CommandArgc,CommandArgv);
  411. }
  412. return;
  413. }
  414. //=================================================================================
  415. DWORD
  416. GetLeafLenFromPath(
  417. LPSTR lpszPath
  418. )
  419. {
  420. DWORD len;
  421. LPSTR lpT;
  422. if(!lpszPath)
  423. return(0);
  424. len = lstrlen(lpszPath);
  425. if (len == 0) {
  426. return (len);
  427. }
  428. lpT = lpszPath+len-1;
  429. if (*lpT =='\\') {
  430. --lpT;
  431. }
  432. for (; lpT >= lpszPath; --lpT) {
  433. if (*lpT == '\\') {
  434. break;
  435. }
  436. }
  437. return (lstrlen(lpT));
  438. }
  439. //=================================================================================
  440. DWORD WINAPIV Format_String(LPSTR *plpsz, LPSTR lpszFmt, ...)
  441. {
  442. const char c_Func_Name[] = "[Format_String] ";
  443. DWORD dwRet;
  444. va_list vArgs;
  445. va_start (vArgs, lpszFmt);
  446. dwRet = Format_StringV(plpsz, lpszFmt, &vArgs);
  447. va_end (vArgs);
  448. return(dwRet);
  449. }
  450. //=================================================================================
  451. DWORD WINAPI Format_Error(DWORD dwErr, LPSTR *plpsz)
  452. {
  453. DWORD dwRet;
  454. if(dwErr != ERROR_SUCCESS)
  455. {
  456. dwRet = Format_MessageV(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  457. dwErr, plpsz, NULL, NULL);
  458. }
  459. else
  460. {
  461. const char szMsg[] = "No Error";
  462. Format_String(plpsz, (LPSTR)szMsg);
  463. dwRet = lstrlen(szMsg);
  464. }
  465. return(dwRet);
  466. }
  467. //=================================================================================
  468. DWORD WINAPI Format_StringV(LPSTR *plpsz, LPCSTR lpszFmt, va_list *vArgs)
  469. {
  470. return(Format_MessageV(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
  471. 0, plpsz, lpszFmt, vArgs));
  472. }
  473. // ***************************************************************************
  474. DWORD WINAPI Format_MessageV(DWORD dwFlags, DWORD dwErr, LPSTR *plpsz, LPCSTR lpszFmt, va_list *vArgs)
  475. {
  476. const char c_Func_Name[] = "[Format_MessageV]";
  477. DWORD dwRet;
  478. DWORD dwGLE;
  479. *plpsz = NULL;
  480. dwRet = FormatMessage(dwFlags, lpszFmt, dwErr, 0, (LPSTR) plpsz, 0, vArgs);
  481. if (!dwRet || !*plpsz)
  482. {
  483. dwGLE = GetLastError();
  484. printf("%s FormatMessage Failed: %s. dwRet: %#lx!. *plpsz:%#lx! GLE:%d\r\n", c_Func_Name, lpszFmt, dwRet, *plpsz, dwGLE);
  485. if (*plpsz)
  486. LocalFree ((HLOCAL) *plpsz);
  487. *plpsz = NULL;
  488. return 0;
  489. }
  490. return(dwRet);
  491. }
  492. DWORD
  493. ProcessDAVGetProp(
  494. DWORD argc,
  495. LPSTR *argv
  496. )
  497. {
  498. HINTERNET hDavOpen=NULL, hDavConnect = NULL, hRequest = NULL;
  499. DWORD dwError = ERROR_SUCCESS;
  500. LPSTR lpRequestHeader=NULL, lpOptionalData = NULL, lpTemp;
  501. if (argc < 2)
  502. {
  503. printf("GetProp Needs more args\n");
  504. return ERROR_INVALID_PARAMETER;
  505. }
  506. hDavOpen = InternetOpen("DAVtest",
  507. INTERNET_OPEN_TYPE_PRECONFIG,
  508. NULL,
  509. NULL,
  510. 0);
  511. if (hDavOpen == NULL) {
  512. dwError = GetLastError();
  513. goto bailout;
  514. }
  515. hDavConnect = InternetConnect( hDavOpen,
  516. argv[0],
  517. INTERNET_DEFAULT_HTTP_PORT,
  518. NULL,
  519. NULL,
  520. INTERNET_SERVICE_HTTP,
  521. 0,
  522. 0);
  523. if (hDavConnect == NULL)
  524. {
  525. dwError = GetLastError();
  526. goto bailout;
  527. }
  528. hRequest = HttpOpenRequest(hDavConnect,
  529. "PROPFIND",
  530. argv[1],
  531. HTTP_VERSION,
  532. NULL,
  533. NULL,
  534. INTERNET_FLAG_KEEP_CONNECTION |
  535. INTERNET_FLAG_RELOAD |
  536. INTERNET_FLAG_NO_AUTO_REDIRECT,
  537. 0);
  538. if (hRequest == NULL)
  539. {
  540. dwError = GetLastError();
  541. goto bailout;
  542. }
  543. if (!HttpSendRequest(hRequest, NULL, 0, NULL, 0))
  544. {
  545. dwError = GetLastError();
  546. }
  547. bailout:
  548. if (hRequest)
  549. {
  550. InternetCloseHandle(hRequest);
  551. }
  552. if (hDavConnect)
  553. {
  554. InternetCloseHandle(hDavConnect);
  555. }
  556. if (hDavOpen)
  557. {
  558. InternetCloseHandle(hDavOpen);
  559. }
  560. return dwError;
  561. }
  562. DWORD
  563. ProcessDAVSetProp(
  564. DWORD argc,
  565. LPSTR *argv
  566. )
  567. {
  568. HINTERNET hDavOpen=NULL, hDavConnect = NULL, hRequest = NULL;
  569. DWORD dwError = ERROR_SUCCESS, dwLen;
  570. LPSTR lpRequestHeader=NULL, lpOptionalData = NULL, lpTemp;
  571. SYSTEMTIME sSystemTime;
  572. char sTimeBuff[INTERNET_RFC1123_BUFSIZE+10];
  573. if (argc < 2)
  574. {
  575. printf("SetProp Needs more args\n");
  576. return ERROR_INVALID_PARAMETER;
  577. }
  578. hDavOpen = InternetOpen("DAVtest",
  579. INTERNET_OPEN_TYPE_PRECONFIG,
  580. NULL,
  581. NULL,
  582. 0);
  583. if (hDavOpen == NULL) {
  584. dwError = GetLastError();
  585. goto bailout;
  586. }
  587. hDavConnect = InternetConnect( hDavOpen,
  588. argv[0],
  589. INTERNET_DEFAULT_HTTP_PORT,
  590. NULL,
  591. NULL,
  592. INTERNET_SERVICE_HTTP,
  593. 0,
  594. 0);
  595. if (hDavConnect == NULL)
  596. {
  597. dwError = GetLastError();
  598. goto bailout;
  599. }
  600. #if 0
  601. hRequest = HttpOpenRequest(hDavConnect,
  602. "PROPFIND",
  603. argv[1],
  604. HTTP_VERSION,
  605. NULL,
  606. NULL,
  607. INTERNET_FLAG_KEEP_CONNECTION |
  608. INTERNET_FLAG_RELOAD |
  609. INTERNET_FLAG_NO_AUTO_REDIRECT,
  610. 0);
  611. if (hRequest == NULL)
  612. {
  613. dwError = GetLastError();
  614. goto bailout;
  615. }
  616. if (!HttpSendRequest(hRequest, NULL, 0, NULL, 0))
  617. {
  618. dwError = GetLastError();
  619. }
  620. #endif
  621. hRequest = HttpOpenRequest(hDavConnect,
  622. "PROPPATCH",
  623. argv[1],
  624. HTTP_VERSION,
  625. NULL,
  626. NULL,
  627. INTERNET_FLAG_KEEP_CONNECTION |
  628. INTERNET_FLAG_RELOAD |
  629. INTERNET_FLAG_NO_AUTO_REDIRECT,
  630. 0);
  631. if (hRequest == NULL)
  632. {
  633. dwError = GetLastError();
  634. goto bailout;
  635. }
  636. memset(Buffer, 0, sizeof(Buffer));
  637. lpTemp = Buffer;
  638. strcpy(lpTemp, rgXmlDataHeader);
  639. lpTemp += (sizeof(rgXmlDataHeader)-1);
  640. memcpy(lpTemp, rgLastModifiedTimeTagHeader, (sizeof(rgLastModifiedTimeTagHeader)-1));
  641. lpTemp += (sizeof(rgLastModifiedTimeTagHeader)-1);
  642. GetSystemTime(&sSystemTime);
  643. InternetTimeFromSystemTimeA(&sSystemTime, INTERNET_RFC1123_FORMAT, sTimeBuff, sizeof(sTimeBuff));
  644. dwLen = strlen(sTimeBuff);
  645. memcpy(lpTemp, sTimeBuff, dwLen);
  646. lpTemp += dwLen;
  647. memcpy(lpTemp, rgLastModifiedTimeTagTrailer, (sizeof(rgLastModifiedTimeTagTrailer)-1));
  648. lpTemp += (sizeof(rgLastModifiedTimeTagTrailer)-1);
  649. strcpy(lpTemp, rgXmlDataTrailer);
  650. if (!HttpSendRequest(hRequest,
  651. (LPVOID)rgXmlHeader,
  652. strlen(rgXmlHeader),
  653. (LPVOID)Buffer,
  654. strlen(Buffer)))
  655. {
  656. dwError = GetLastError();
  657. }
  658. bailout:
  659. if (hRequest)
  660. {
  661. InternetCloseHandle(hRequest);
  662. }
  663. if (hDavConnect)
  664. {
  665. InternetCloseHandle(hDavConnect);
  666. }
  667. if (hDavOpen)
  668. {
  669. InternetCloseHandle(hDavOpen);
  670. }
  671. return dwError;
  672. }
  673. DWORD
  674. ProcessDAVEnumServer(
  675. DWORD argc,
  676. LPSTR *argv
  677. )
  678. {
  679. HINTERNET hDavOpen=NULL, hDavConnect = NULL, hRequest = NULL;
  680. DWORD dwError = ERROR_SUCCESS;
  681. LPSTR lpRequestHeader=NULL, lpOptionalData = NULL, lpTemp;
  682. NETRESOURCEA sRes;
  683. HANDLE hEnum = 0;
  684. char Buffer[4096];
  685. if (argc < 1)
  686. {
  687. printf("EnumResource Needs more args\n");
  688. return ERROR_INVALID_PARAMETER;
  689. }
  690. memset(&sRes, 0, sizeof(sRes));
  691. sRes.lpRemoteName = argv[0];
  692. sRes.lpProvider = szDavProviderName;
  693. if(WNetOpenEnumA(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, RESOURCEUSAGE_CONTAINER, &sRes, &hEnum) == NO_ERROR)
  694. {
  695. DWORD dwCount, dwSize;
  696. dwCount = 1;
  697. dwSize = sizeof(Buffer);
  698. while (WNetEnumResourceA(hEnum, &dwCount, Buffer, &dwSize)== NO_ERROR)
  699. {
  700. dwCount = 1;
  701. dwSize = sizeof(Buffer);
  702. printf("%s \n", ((LPNETRESOURCE)Buffer)->lpRemoteName);
  703. }
  704. WNetCloseEnum(hEnum);
  705. }
  706. else
  707. {
  708. dwError = GetLastError();
  709. }
  710. return dwError;
  711. }
  712. DWORD
  713. ProcessDAVGetSpace(
  714. DWORD argc,
  715. LPSTR *argv
  716. )
  717. {
  718. DWORD dwError = ERROR_SUCCESS;
  719. ULARGE_INTEGER MaxSpace, UsedSpace;
  720. WCHAR tzLocation[MAX_PATH];
  721. DWORD dwSize;
  722. dwSize = sizeof(tzLocation);
  723. if ((dwError = DavGetDiskSpaceUsage(tzLocation, &dwSize, &MaxSpace, &UsedSpace)) == ERROR_SUCCESS)
  724. {
  725. printf("Location=%ls MaxSpace=%I64d UsedSpace=%I64d\n", tzLocation, MaxSpace, UsedSpace);
  726. }
  727. return dwError;
  728. }
  729. DWORD
  730. ProcessDAVFreeSpace(
  731. DWORD argc,
  732. LPSTR *argv
  733. )
  734. {
  735. DWORD dwError = ERROR_SUCCESS, dwPercent;
  736. if (argc < 1)
  737. {
  738. printf("FreeSpace Needs more args\n");
  739. return ERROR_INVALID_PARAMETER;
  740. }
  741. if(sscanf(argv[0], "%d", &dwPercent) == 1)
  742. {
  743. dwError = DavFreeUsedDiskSpace(dwPercent);
  744. }
  745. else
  746. {
  747. dwError = ERROR_INVALID_PARAMETER;
  748. }
  749. return dwError;
  750. }