Solved

Alternative if Server Variable Is Empty

Posted on 2006-06-29
2
417 Views
Last Modified: 2013-11-20
Hi,

I have an isapi to validate against a database based on IP adddress REMOTE_ADDR header -

char szAddress[80];
DWORD dwSize = sizeof(szAddress);
if (pCtxt->GetServerVariable("REMOTE_ADDR", szAddress, &dwSize))
{
// VALIDATION
}

I want to modify this to work for WAP validation based on HTTP_X_UP_SUBNO header, but it must use REMOTE_ADDR if there is no HTTP_X_UP_SUBNO

So something like -

if header HTTP_X_UP_SUBNO exists then
  // validate on HTTP_X_UP_SUBNO
else if header REMOTEADDR exist then
  // validate on REMOTE_ADDR
else
 // failed validation
end if

Ive got code like this -

char szAddress[80];
DWORD dwSize = sizeof(szAddress);
// TRY WAP SUB NO FIRST
if (pCtxt->GetServerVariable("HTTP_X_UP_SUBNO", szAddress, &dwSize))
{
// validate HTTP_X_UP_SUBNO
}
else if (pCtxt->GetServerVariable("REMOTE_ADDR", szAddress, &dwSize))
{
// validate REMOTE_ADDR
}

The problem i have is that its going into the first IF when there is no HTTP_X_UP_SUBNO, is there a way to check for a string null or 0 string length to make sure it goes into the REMOTE_ADDR section if HTTP_X_UP_SUBNO is empty?

My C++ is not very good, i thought that pCtxt->GetServerVariable("HTTP_X_UP_SUBNO", szAddress, &dwSize) would return false if the header doesnt exist or was empty but it doesnt seem to be working like that.

Thanks for help in advance.

0
Comment
Question by:x2cmsac
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 17011351
The return value will only be false when the function call could not be executed, so if you want to know wether REMOTE_ADDR is vaid, you'll need to check if you got anything back, e.g. like

char szAddress[80];
DWORD dwSize = sizeof(szAddress);
// TRY WAP SUB NO FIRST
if (pCtxt->GetServerVariable("HTTP_X_UP_SUBNO", szAddress, &dwSize))
{
// validate HTTP_X_UP_SUBNO
}
else if (pCtxt->GetServerVariable("REMOTE_ADDR", szAddress, &dwSize))
{
// validate REMOTE_ADDR

  if ( 0 == dwSize )
  {
    // VALIDATION FAILED
  }
}

See also http://msdn2.microsoft.com/zh-tw/library/84h2xz5w.aspx ("CHttpServerContext::GetServerVariable")
0
 

Author Comment

by:x2cmsac
ID: 17012247
Thanks that worked using

 if ( 0 == dwSize )
  {
    // VALIDATION FAILED
  }
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl Awk Need Help 3 129
Process filename extension 3 196
How to determine file rename from EventLog ? 2 55
format the code in java 6 102
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question