00001 /* 00002 Free Download Manager Copyright (c) 2003-2007 FreeDownloadManager.ORG 00003 Open Download Manager Copyright (c) 2008 OpenDownloadManager.ORG 00004 */ 00005 00006 #include "stdafx.h" 00007 #include "vmsHttpRequest.h" 00008 #include "base64.c" 00009 00010 vmsHttpRequest::vmsHttpRequest() 00011 { 00012 00013 } 00014 00015 vmsHttpRequest::~vmsHttpRequest() 00016 { 00017 00018 } 00019 00020 BOOL vmsHttpRequest::Receive(SOCKET sConnection) 00021 { 00022 std::string strRequest; 00023 00024 do 00025 { 00026 char sz [100]; 00027 00028 int n = recv (sConnection, sz, sizeof (sz) - 1, 0); 00029 00030 if (n == 0) 00031 return FALSE; 00032 if (n == SOCKET_ERROR) 00033 return FALSE; 00034 00035 sz [n] = 0; 00036 strRequest += sz; 00037 } 00038 00039 while (lstrcmp (strRequest.c_str () + strRequest.length () - 4, "\r\n\r\n")); 00040 00041 return ParseRequest (strRequest.c_str ()); 00042 } 00043 00044 BOOL vmsHttpRequest::ParseRequest(LPCSTR pszReq) 00045 { 00046 00047 00048 m_strRequestType = ExtractString (pszReq); 00049 if (m_strRequestType == "") 00050 return FALSE; 00051 m_strResourcePath = ExtractString (pszReq); 00052 if (m_strResourcePath == "") 00053 return FALSE; 00054 m_strHttpVersion = ExtractString (pszReq); 00055 if (m_strHttpVersion == "") 00056 return FALSE; 00057 00058 m_strAuth = ""; 00059 00060 LPCSTR psz = strstr (pszReq, "Authorization: "); 00061 if (psz) 00062 { 00063 00064 psz += lstrlen ("Authorization: "); 00065 if (strnicmp (psz, "Basic ", 6) == 0) 00066 { 00067 psz += 6; 00068 char sz [1000]; 00069 ZeroMemory (sz, sizeof (sz)); 00070 base64_decode (psz, sz); 00071 m_strAuth = sz; 00072 } 00073 } 00074 00075 return TRUE; 00076 } 00077 00078 BOOL vmsHttpRequest::IsBlank(char c) 00079 { 00080 return c == ' ' || c == '\t'; 00081 } 00082 00083 BOOL vmsHttpRequest::IsCLRF(LPCSTR psz) 00084 { 00085 return *psz == '\r' || *psz == '\n'; 00086 } 00087 00088 std::string vmsHttpRequest::ExtractString(LPCSTR &psz) 00089 { 00090 std::string str; 00091 00092 while (*psz && FALSE == IsBlank (*psz) && FALSE == IsCLRF (psz)) 00093 str += *psz++; 00094 00095 while (IsBlank (*++psz)); 00096 00097 return str; 00098 } 00099 00100 LPCSTR vmsHttpRequest::get_ResourcePath() 00101 { 00102 return m_strResourcePath.c_str (); 00103 } 00104 00105 LPCSTR vmsHttpRequest::get_RequestType() 00106 { 00107 return m_strRequestType.c_str (); 00108 } 00109 00110 LPCSTR vmsHttpRequest::get_Auth() 00111 { 00112 return m_strAuth.c_str (); 00113 }
1.5.6