Программирование в IIS


Пример 5.4

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Name:GetALLHTTPHeader

In: pECB - pointer to the Extension control block structure

psElement - string pointer to XML document being built that will be updated with the element for the ALL_HTTP server variable value.

Out: nothing returned but the string psElement points to will be updated.

Purpose: Updates the XML document string by adding an element for the ALL_HTTP server variable. This variable contains all of the http headers so some additional parsing must take place on the headers to format them into XML.

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ void GetALLHTTPHeader(EXTENSION_CONTROL_BLOCK *pECB, string *psElement) { TCHAR szTempBuffer[BUFFER_LENGTH]; DWORD dwBufferSize = BUFFER_LENGTH; const string EQUAL("="); const string SPACE(" ");

string sAllHeaders; //used to cut up 'all headers' returned int nNewLinePos = 0; int nEndLinePos = 0; string sName; string sValue;

//pull the whole HTTP header if (pECB->GetServerVariable( pECB->ConnID, "ALL_HTTP", szTempBuffer, &dwBufferSize)) { //if the whole http header was pulled then parse it sAllHeaders.assign(szTempBuffer);

//get the name / value pairs while (GetHeaderValuePair( sAllHeaders, nNewLinePos, &sName, &sValue, &nEndLinePos)) { //add the attribute to the element psElement->append( SPACE + sName + EQUAL + QUOTE + ValidateValue(sValue) + QUOTE);

//reset the newline to the last endline nNewLinePos = nEndLinePos;

//dump the values sName.erase(); sValue.erase(); } } }

Листинг 5.4. GetALLHTTPHeader Function Building XML Element in SEUX ISAPI Extension

Закрыть окно

Содержание  Назад  Вперед