Solved

Alternative if Server Variable Is Empty

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create frequencies of a variable from SAS dataset? 10 125
Unix / Linux grid computing 5 157
How to determine file rename from EventLog ? 2 49
canBalance challenge 34 85
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 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