📄 atlrt.cpp
字号:
int columnIndex;
if (szArgs == NULL)
{
resultsName = DEFAULT_RESULTS;
columnIndex = -1;
}
else
{
// parse the argument string
ArgParser parser;
if (!parser.Parse(szArgs))
{
// this is combo #4
resultsName = DEFAULT_RESULTS;
columnIndex = atoi(szArgs);
}
else
{
// is this combo #2?
if (parser.GetAttribute("name", resultsName) != 1)
{
// if we got here, then we have an error, tell the user and get out of here
m_HttpResponse << BAD_ARGSTRING;
m_HttpResponse << USEAGE_GETCOLUMNVALUE;
return HTTP_SUCCESS;
}
else
{
// if we got here, then we assume at this point that have combo #2
columnIndex = -1;
}
// this check may turn our combo #2 into combo #3
CStringA temp;
if (parser.GetAttribute("column", temp) == 1)
{
// if we got here, then we have combo #3
columnIndex = atoi(temp);
}
}
}
// ok, if we got here then we have a valid pair of result name and column value
// make sure we have a results set of the give name
if (!_CheckForResults(resultsName))
{
// getting here means we have no results for the specified name, _CheckForResults
// has already sent an error message so we can just return
return HTTP_SUCCESS;
}
// if we have results, get the value at the specified column and output it
if (columnIndex == -1)
{
// if the column value is -1, then use the current column value stored in our CmdResult
m_HttpResponse << m_resultsMap[resultsName].GetColumnValue();
}
else
{
// otherwise, get the column value at the current index
m_HttpResponse << m_resultsMap[resultsName].GetColumnValue(columnIndex);
}
return HTTP_SUCCESS;
}
HTTP_CODE CATLRTHandler::OnSaveColumnValue(TCHAR *szArgs)
{
// szArgs allows the following combinations (these combinations are not meant to be a
// complete list, rather they address the most common useage)
//
// 1. szArgs == "name=result name;column=column index;save_as=save as name"
// - use all the specified values
// 2. szArgs == "name=result name;column=column index"
// - use the result name as the save_as name
// 3. szArgs == NULL
// - use the default result name, current column and default save as name (default result name)
// 4. szArgs == "save_as=save as name"
// - use the default result name, current column and specified save as name
// 5. szArgs == "column=column index;save_as=save as name"
// - use the default result name, specified column and specified save as name
CStringA resultName;
CStringA saveAs;
int columnIndex;
if (szArgs == NULL)
{
// easy, we have combo #3
resultName = DEFAULT_RESULTS;
saveAs = "";
columnIndex = -1;
}
else
{
// parse our arguments to see what we have
ArgParser parser;
if (!parser.Parse(szArgs))
{
// sorry, we don't allow this one, it would be too ambiguous, would szArgs == column index, or
// save as name, or result?
// report an error and get out of here
m_HttpResponse << BAD_ARGSTRING;
m_HttpResponse << USEAGE_SAVECOLUMN;
return HTTP_SUCCESS;
}
// look for our values, go to defaults for any we can't find
// we have to find at least 1 in order for the string to be valid
int numFound = 0;
if (parser.GetAttribute("name", resultName) != 1)
{
// use a default result name
resultName = DEFAULT_RESULTS;
}
else
{
numFound++;
}
if (parser.GetAttribute("save_as", saveAs) != 1)
{
// use a default save as name
saveAs = "";
}
else
{
numFound++;
}
CString temp;
if (parser.GetAttribute("column", temp) != 1)
{
// use a default column index
columnIndex = -1;
}
else
{
numFound++;
columnIndex = atoi(temp);
}
if (numFound == 0)
{
// if we didn't find any values then the argument string was invalid, tell the user
// and get out of here
m_HttpResponse << BAD_ARGSTRING;
m_HttpResponse << USEAGE_SAVECOLUMN;
return HTTP_SUCCESS;
}
}
// ok, if we got here, then we have values for our result name, save as name and column index
// first, make sure we have results for the specified name
if (!_CheckForResults(resultName))
{
// getting here means we have no results for the specified name, _CheckForResults
// has already sent an error message so we can just return
return HTTP_SUCCESS;
}
// now we know we have results
if (columnIndex == -1)
{
// if we are using the current column index, figure out what that value is right now
columnIndex = m_resultsMap[resultName].GetCurrentColumn();
}
if (resultName == "")
{
// if we are using a default save as name, setup a name now, based on the default
// results and current column
saveAs.Format("%s_%i", resultName, columnIndex);
}
// get our value for the specified result and store it in our variable map
m_variableMap->SetAt(saveAs, m_resultsMap[resultName].GetColumnValue(columnIndex));
// all done
return HTTP_SUCCESS;
}
HTTP_CODE CATLRTHandler::OnGetRowNumber(TCHAR *szArgs)
{
// szArg allows the following combinations
// 1. szArgs == NULL
// - use the default result name
// 2. szArgs == result name
// - use the specified result name
CStringA resultName;
if (szArgs == NULL)
{
// combo #1
resultName = DEFAULT_RESULTS;
}
else
{
// combo #2
resultName = szArgs;
}
if (!_CheckForResults(resultName))
{
// getting here means we have no results for the specified name, _CheckForResults
// has already sent an error message so we can just return
return HTTP_SUCCESS;
}
// we've got results so output the current column value
m_HttpResponse << m_resultsMap[resultName].GetCurrentRow();
return HTTP_SUCCESS;
}
HTTP_CODE CATLRTHandler::OnGetColumnNumber(TCHAR *szArgs)
{
// szArg allows the following combinations
// 1. szArgs == NULL
// - use the default result name
// 2. szArgs == result name
// - use the specified result name
CStringA resultName;
if (szArgs == NULL)
{
// combo #1
resultName = DEFAULT_RESULTS;
}
else
{
// combo #2
resultName = szArgs;
}
if (!_CheckForResults(resultName))
{
// getting here means we have no results for the specified name, _CheckForResults
// has already sent an error message so we can just return
return HTTP_SUCCESS;
}
// we've got results so output the current column value
m_HttpResponse << m_resultsMap[resultName].GetCurrentColumn();
return HTTP_SUCCESS;
}
HTTP_CODE CATLRTHandler::OnResetResults(TCHAR *szArgs)
{
// szArg allows the following combinations
// 1. szArgs == NULL
// - use the default result name
// 2. szArgs == result name
// - use the specified result name
CStringA resultName;
if (szArgs == NULL)
{
// combo #1
resultName = DEFAULT_RESULTS;
}
else
{
// combo #2
resultName = szArgs;
}
if (!_CheckForResults(resultName))
{
// getting here means we have no results for the specified name, _CheckForResults
// has already sent an error message so we can just return
return HTTP_SUCCESS;
}
// we've got results, so reset that result
m_resultsMap[resultName].ResetColumns();
m_resultsMap[resultName].ResetRows();
return HTTP_SUCCESS;
}
HTTP_CODE CATLRTHandler::OnCloseResults(TCHAR *szArgs)
{
// szArg allows the following combinations
// 1. szArgs == NULL
// - use the default result name
// 2. szArgs == result name
// - use the specified result name
CStringA resultName;
if (szArgs == NULL)
{
// combo #1
resultName = DEFAULT_RESULTS;
}
else
{
// combo #2
resultName = szArgs;
}
if (!_CheckForResults(resultName))
{
// getting here means we have no results for the specified name, _CheckForResults
// has already sent an error message so we can just return
return HTTP_SUCCESS;
}
// close these results
m_resultsMap[resultName].Close();
m_resultsMap.RemoveKey(resultName);
return HTTP_SUCCESS;
}
HTTP_CODE CATLRTHandler::OnRowCount(TCHAR *szArgs)
{
// szArg allows the following combinations
// 1. szArgs == NULL
// - use the default result name
// 2. szArgs == result name
// - use the specified result name
CStringA resultName;
if (szArgs == NULL)
{
// combo #1
resultName = DEFAULT_RESULTS;
}
else
{
// combo #2
resultName = szArgs;
}
if (!_CheckForResults(resultName))
{
// getting here means we have no results for the specified name, _CheckForResults
// has already sent an error message so we can just return
return HTTP_SUCCESS;
}
// we've got results so output the current column value
m_HttpResponse << m_resultsMap[resultName].GetRowValues().GetNumRows();
return HTTP_SUCCESS;
}
/////////////////////////////////////////////////////////////////////
// HTTP Operations
/////////////////////////////////////////////////////////////////////
HTTP_CODE CATLRTHandler::OnSetContentType(TCHAR *szContentType)
{
m_HttpResponse.SetContentType(szContentType);
return HTTP_SUCCESS;
}
/////////////////////////////////////////////////////////////////////
// Internal utility methods
/////////////////////////////////////////////////////////////////////
bool CATLRTHandler::_CheckForResults(CString& resultsName)
{
const CmdResultsMap::CPair *pair = m_resultsMap.Lookup(resultsName);
if (pair == NULL)
{
// there were no results by the specified name, tell the user and return
m_HttpResponse << "No results of the name: " << resultsName;
return false;
}
else
return true;
}
// looks for values in the following order
// 1. variable map
// 2. request parameters
// 3. server variables
LPCSTR CATLRTHandler::_GetValue(CStringA& name)
{
LPCSTR szValue = NULL;
StringMap::CPair *pair = m_variableMap->Lookup(name);
if (pair != NULL) // try to find the variable value in our variable map
{
szValue = pair->m_value;
}
else // if the value is not in our variable map, try to get it from the request parameters
{
// look in both query and form parameters because you may have a mix of get and post
// parameters
// first try GET
szValue = this->m_HttpRequest.m_QueryParams.Lookup(name);
if (!szValue)
{
// try POST if GET fails
szValue = this->m_HttpRequest.m_pFormVars->Lookup(name);
}
}
if (szValue == NULL)
{
// if after looking in the variable map and the request parameters unsuccesfully,
// try the server variables
CStringA value;
if (m_HttpRequest.GetServerVariable((LPCSTR)name, value))
{
szValue = value;
}
}
return szValue;
}
int CATLRTHandler::_ResolveParameters(Params params, StringList& values)
{
// if we don't have parameters, just return now
int attributeCount = params.GetCount();
if (attributeCount == 0)
{
return attributeCount;
}
// try to get our first element
POSITION begin = params.GetHeadPosition();
ASSERT(begin != NULL);
while (begin != NULL)
{
// get our parameter information
Param ps = params.GetNext(begin);
if (!ps.isLiteral)
{
// try to resolve our parameter if we don't want the literal value
LPCSTR szValue = _GetValue(ps.paramName);
if (szValue == NULL)
{
// we could not find a value for this name
// don't exit yet so the user can see all the names that
// don't match
m_HttpResponse << "could not get value for: " << ps.paramName << "<br>";
}
else
{
values.AddTail(CStringA(szValue));
}
}
}
return attributeCount;
}
/////////////////////////////////////////////////////////////////////
// The ATL Server ISAPI extension
/////////////////////////////////////////////////////////////////////
typedef CatlrtExtension<CThreadPool<CATLRTExtensionWorker> > ExtensionType;
ExtensionType theExtension;
// Delegate ISAPI exports to theExtension
//
extern "C" DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
{
return theExtension.HttpExtensionProc(lpECB);
}
extern "C" BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO* pVer)
{
return theExtension.GetExtensionVersion(pVer);
}
extern "C" BOOL WINAPI TerminateExtension(DWORD dwFlags)
{
return theExtension.TerminateExtension(dwFlags);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -