Solved

Alternative if Server Variable Is Empty

Posted on 2006-06-29
2
404 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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…
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now