void ReadPostData(Buf &buf) { DWORD dwStep=4096; DWORD dwReadThis; DWORD dwThisStep; DWORD dwTotalBytes; Buf lpszContentLength; GetEnv(__T("CONTENT_LENGTH"), lpszContentLength); dwTotalBytes = (DWORD)_tstol(lpszContentLength.Get()); buf.AllocExact(dwTotalBytes + 1); buf.Clear(); do { dwThisStep = (DWORD) min(dwTotalBytes-buf.Length(),dwStep); dwReadThis = dwThisStep; if ( dwThisStep > 0 ) { dwReadThis = 0; if ( !ReadFile(GetStdHandle(STD_INPUT_HANDLE),buf.GetTail(),dwReadThis, &dwReadThis,NULL) ) dwReadThis = 0; } buf.SetLength(buf.Length() + dwReadThis); } while ( (dwReadThis==dwThisStep) && (buf.Length()<dwTotalBytes) ); *buf.GetTail() = __T('\0'); lpszContentLength.Free(); }
// // Works like _getenv(), but uses win32 functions instead. // void GetEnv(LPTSTR lpszEnvVar, Buf &buf) { DWORD dwLen = 0; if ( lpszEnvVar ) { dwLen = GetEnvironmentVariable(lpszEnvVar, NULL, 0); } if ( dwLen == 0 ) buf.Clear(); else { buf.AllocExact(dwLen+1); GetEnvironmentVariable(lpszEnvVar, buf.Get(), dwLen); buf.SetLength(); } }
void SearchVar(Buf &lpszParamCgi,LPCTSTR lpszVarName,BOOL fMimeDecode, Buf &ret) { Buf lpAlloc; LPTSTR lpszProvCmp,lpszVarForCmp; DWORD dwVarNameLen=(DWORD)_tcslen(lpszVarName); DWORD dwLineLen=(DWORD)lpszParamCgi.Length(); DWORD dwPos=0; ret.Clear(); lpAlloc.AllocExact((dwVarNameLen+0x10)*2); lpszProvCmp=lpAlloc.Get(); lpszVarForCmp=lpAlloc.Get()+(((dwVarNameLen+7)/4)*4); _tcscpy(lpszVarForCmp,lpszVarName); _tcscat(lpszVarForCmp,__T("=")); *(lpszProvCmp+dwVarNameLen+1) = __T('\0'); while ( dwPos < dwLineLen ) { DWORD dwNextPos = SearchNextPos(lpszParamCgi.Get()+dwPos,FALSE); if ( dwPos+dwVarNameLen >= dwLineLen ) break; memcpy(lpszProvCmp,lpszParamCgi.Get()+dwPos,(dwVarNameLen+1)*sizeof(_TCHAR)); if ( _tcsicmp(lpszProvCmp,lpszVarForCmp) == 0 ) { DWORD dwLenContent = dwNextPos-(dwVarNameLen+1); ret.Alloc(dwLenContent+0x10); ret.Add(lpszParamCgi.Get()+dwPos+dwVarNameLen+1,dwLenContent); if ( fMimeDecode ) { url_decode(ret.Get()); ret.SetLength(); } break; } dwPos += dwNextPos+1; } lpAlloc.Free(); }