Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Alternative if Server Variable Is Empty

Posted on 2006-06-29
2
Medium Priority
?
432 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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 this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

730 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