Solved

Alternative if Server Variable Is Empty

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

 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

Question has a verified solution.

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

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. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

627 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