00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "vmsHttpResponse.h"
00008
00009 vmsHttpResponse::vmsHttpResponse()
00010 {
00011 m_pBody = NULL;
00012 m_dwBodySize = 0;
00013 }
00014
00015 vmsHttpResponse::~vmsHttpResponse()
00016 {
00017 set_Body (NULL, 0);
00018 }
00019
00020 BOOL vmsHttpResponse::Send(SOCKET sConnection)
00021 {
00022 std::string str;
00023 str = m_strHttpVersion; str += ' ';
00024 str += m_strResponseCode; str += "\r\n";
00025 send (sConnection, str.c_str (), str.length (), 0);
00026
00027 if (strncmp (m_strResponseCode.c_str (), "401 ", 4) == 0)
00028 {
00029 str = "WWW-Authenticate: Basic realm=\"ODM Remote control server\"\r\n";
00030 send (sConnection, str.c_str (), str.length (), 0);
00031 }
00032
00033 str = "Content-Length: ";
00034 char sz [50];
00035 itoa (m_dwBodySize, sz, 10);
00036 str += sz; str += "\r\n";
00037 send (sConnection, str.c_str (), str.length (), 0);
00038
00039 send (sConnection, "\r\n", 2, 0);
00040
00041 if (m_pBody)
00042 {
00043 LPBYTE pb = (LPBYTE)m_pBody;
00044 DWORD dw = m_dwBodySize;
00045 while (dw)
00046 {
00047 int n = dw > 1000 ? 1000 : dw;
00048 n = send (sConnection, (LPSTR)pb, n, 0);
00049 if (n == 0)
00050 return FALSE;
00051 if (n == INVALID_SOCKET)
00052 return FALSE;
00053 pb += n;
00054 dw -= n;
00055 }
00056 }
00057
00058 return TRUE;
00059 }
00060
00061 void vmsHttpResponse::set_HttpVersion(LPCSTR psz)
00062 {
00063 m_strHttpVersion = psz;
00064 }
00065
00066 void vmsHttpResponse::set_ResponseCode(LPCSTR psz)
00067 {
00068 m_strResponseCode = psz;
00069 }
00070
00071 void vmsHttpResponse::set_Body(LPCVOID pv, DWORD dwSize)
00072 {
00073 if (m_pBody)
00074 delete [] m_pBody;
00075
00076 m_pBody = pv && dwSize ? new BYTE [dwSize] : NULL;
00077 m_dwBodySize = m_pBody ? dwSize : 0;
00078
00079 if (m_pBody)
00080 CopyMemory (m_pBody, pv, dwSize);
00081 }