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.

115 lines
2.2 KiB

  1. /*
  2. * basic client for sumserve remote checksum server
  3. *
  4. *
  5. * sends a request over a named pipe for a list of files and checksums,
  6. * and printf's the returned list
  7. */
  8. #include <windows.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include "..\server\sumserve.h"
  12. #include "ssclient.h"
  13. extern int __argc;
  14. extern char ** __argv;
  15. /* program entry point
  16. *
  17. * creates the named pipe, and loops waiting for client connections and
  18. * calling ss_handleclient for each connection. only exits when told
  19. * to by a client.
  20. *
  21. * currently permits only one client connection at once.
  22. */
  23. int PASCAL
  24. WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdParam,
  25. int nCmdShow)
  26. {
  27. HANDLE hpipe;
  28. SSRESPONSE resp;
  29. PSTR tag;
  30. /* we expect two args: the server name, and the pathname */
  31. if (__argc != 3) {
  32. printf("usage: client <servername> <pathname>");
  33. return(1);
  34. }
  35. hpipe = ss_connect(__argv[1]);
  36. if (hpipe == INVALID_HANDLE_VALUE) {
  37. printf("cannot connect to server %s\n", __argv[1]);
  38. return(2);
  39. }
  40. /* make a packet to send */
  41. if (!ss_sendrequest(hpipe, SSREQ_SCAN, __argv[2], strlen(__argv[2])+1)) {
  42. printf("pipe write error %d\n", GetLastError());
  43. return(3);
  44. }
  45. /* loop reading responses */
  46. for (; ;) {
  47. if (!ss_getresponse(hpipe, &resp)) {
  48. printf("pipe read error %d\n", GetLastError());
  49. return(4);
  50. }
  51. if (resp.lCode == SSRESP_END) {
  52. printf("-----------------end of list");
  53. break;
  54. }
  55. switch(resp.lCode) {
  56. case SSRESP_ERROR:
  57. tag = "ERROR";
  58. printf("%s\t\t\t%s\n", tag, resp.szFile);
  59. break;
  60. case SSRESP_DIR:
  61. tag = "dir";
  62. printf("%s\t\t\t%s\n", tag, resp.szFile);
  63. break;
  64. case SSRESP_FILE:
  65. tag = "file";
  66. printf("%s\t%08lx\t%d bytes\t%s\n", tag, resp.ulSum, resp.ulSize, resp.szFile);
  67. break;
  68. }
  69. }
  70. ss_terminate(hpipe);
  71. return(0);
  72. }
  73. /* error output functions - called by the ssclient library functions
  74. *
  75. * defined here so the library can be called from cmdline and windows
  76. * programs.
  77. *
  78. */
  79. BOOL
  80. Trace_Error(LPSTR str, BOOL fCancel)
  81. {
  82. printf("%s\n", str);
  83. return(TRUE);
  84. }
  85. /*
  86. * status update messages
  87. */
  88. void
  89. Trace_Status(LPSTR str)
  90. {
  91. printf("%s\n", str);
  92. }