Source code of Windows XP (NT5)
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.

181 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. faxitg.cpp
  5. Abstract:
  6. This file implements the FaxQueue object.
  7. The purpose of this object is to gain access
  8. to the fax service's fax queue and retrieve
  9. a received fax from the queue.
  10. Author:
  11. Wesley Witt (wesw) 13-May-1997
  12. Environment:
  13. User Mode
  14. --*/
  15. #include "stdafx.h"
  16. #include "faxitg.h"
  17. #include "faxqueue.h"
  18. #include "faxsvr.h"
  19. extern WCHAR g_ClientDir[MAX_PATH*2];
  20. CFaxQueue::CFaxQueue()
  21. {
  22. }
  23. CFaxQueue::~CFaxQueue()
  24. {
  25. }
  26. STDMETHODIMP CFaxQueue::get_GetNextFax(BSTR * pVal)
  27. {
  28. INT Bytes;
  29. FAX_QUEUE_MESSAGE Msg;
  30. LPWSTR FileName;
  31. WCHAR SrcName[MAX_PATH];
  32. WCHAR DstName[MAX_PATH];
  33. //
  34. // request the next avail fax
  35. //
  36. Msg.Request = REQ_NEXT_FAX;
  37. Bytes = send( m_Socket, (char*)&Msg, sizeof(Msg), 0 );
  38. if (Bytes == SOCKET_ERROR) {
  39. return E_FAIL;
  40. }
  41. //
  42. // receive the file name
  43. //
  44. Bytes = recv( m_Socket, (char*)&Msg, sizeof(Msg), 0 );
  45. if (Bytes == SOCKET_ERROR) {
  46. return E_FAIL;
  47. }
  48. FileName = (LPWSTR) Msg.Buffer;
  49. if (FileName[0] == 0 || Msg.Response != RSP_GOOD) {
  50. return E_FAIL;
  51. }
  52. //
  53. // copy the file from the server
  54. //
  55. wcscpy( SrcName, m_ServerDir );
  56. wcscat( SrcName, FileName );
  57. wcscpy( DstName, g_ClientDir );
  58. wcscat( DstName, FileName );
  59. if (CopyFile( SrcName, DstName, FALSE )) {
  60. Msg.Response = 1;
  61. } else {
  62. Msg.Response = 0;
  63. }
  64. Msg.Request = REQ_ACK;
  65. //
  66. // send our response
  67. //
  68. Bytes = send( m_Socket, (char*)&Msg, sizeof(Msg), 0 );
  69. if (Bytes == SOCKET_ERROR) {
  70. return E_FAIL;
  71. }
  72. *pVal = SysAllocString( FileName );
  73. if (*pVal == NULL) {
  74. return E_FAIL;
  75. }
  76. return S_OK;
  77. }
  78. STDMETHODIMP CFaxQueue::put_Connect(BSTR ServerName)
  79. {
  80. PHOSTENT Host;
  81. SOCKADDR_IN cli_addr;
  82. CHAR ServerNameA[MAX_COMPUTERNAME_LENGTH];
  83. DWORD Size;
  84. Size = WideCharToMultiByte(
  85. CP_ACP,
  86. 0,
  87. ServerName,
  88. -1,
  89. ServerNameA,
  90. sizeof(ServerNameA),
  91. NULL,
  92. NULL
  93. );
  94. if (Size == 0) {
  95. return E_FAIL;
  96. }
  97. Host = gethostbyname( ServerNameA );
  98. if (Host == NULL || *Host->h_addr_list == NULL) {
  99. return E_FAIL;
  100. }
  101. CopyMemory ((char *) &m_RemoteIpAddress, Host->h_addr, Host->h_length);
  102. //
  103. // set up client socket
  104. //
  105. m_Socket = socket( PF_INET, SOCK_STREAM, 0 );
  106. if (m_Socket == INVALID_SOCKET){
  107. return E_FAIL;
  108. }
  109. //
  110. // connect to the server
  111. //
  112. ZeroMemory( &cli_addr, sizeof(cli_addr) );
  113. cli_addr.sin_family = AF_INET;
  114. cli_addr.sin_port = htons( SERVICE_PORT );
  115. cli_addr.sin_addr = m_RemoteIpAddress;
  116. if (connect( m_Socket, (LPSOCKADDR)&cli_addr, sizeof(cli_addr) ) == SOCKET_ERROR){
  117. return E_FAIL;
  118. }
  119. //
  120. // create the server dir name
  121. //
  122. wcscpy( m_ServerDir, L"\\\\" );
  123. wcscat( m_ServerDir, ServerName );
  124. wcscat( m_ServerDir, L"\\itg\\" );
  125. //
  126. // return success
  127. //
  128. return S_OK;
  129. }