Avatar of Sven
SvenFlag for Germany asked on

Compiling problem while trying to modify ISAPI Filter (C++)

I am trying to enhance a ISAPI filter written in Visual C++ 6.0 for IIS 6.0 but I am a beginner on C++ programming. When compiling the below code (only fragment of it) I receive the error message:

"error C2228: Der linke Teil von '.erase' muss eine Klasse/Struktur/Union sein"
in english s.th. like "error C2228: The left part of '.erase' have to be a Class/Structure/Union"

Error is on line:
szNewUrl.Left(_tcsstr(szUrl, ";DECLARE")-1);

What am I doing wrong? I am only trying to add the block:

      if (_tcsstr(szUrl, ";DECLARE"))
      {
            _tcscat(szNewUrl,szUrl);
            szNewUrl.Left(_tcsstr(szUrl, ";DECLARE")-1);
            //szNewUrl.erase(_tcsstr(szUrl, ";DECLARE"));
            pHeaders->SetHeader(pCtxt->m_pFC, "url", szNewUrl);
            return SF_STATUS_REQ_NEXT_NOTIFICATION;
      }

All characters after the string ;DECLARE in the URL should be erased from the URL.
DWORD CURLMapperFilter::OnPreprocHeaders(CHttpFilterContext *pCtxt, PHTTP_FILTER_PREPROC_HEADERS pHeaders)
{
	CHAR szUrl[1024];
	CHAR szNewUrl[2048] = "";
	DWORD BufSize;
	char *c;
	int i;
	BufSize = 1024;
	pHeaders->GetHeader(pCtxt->m_pFC, "url", szUrl, &BufSize);
 
	_tcslwr(szUrl);
 
	// Ausschlussliste zur schnelleren Bearbeitung
	if (_tcsstr(szUrl,"_vti")) return SF_STATUS_REQ_NEXT_NOTIFICATION;
	if (_tcsstr(szUrl,"/images")) return SF_STATUS_REQ_NEXT_NOTIFICATION;
	if (_tcsstr(szUrl,"include")) return SF_STATUS_REQ_NEXT_NOTIFICATION;
 
	// Trefferliste
 
	if (_tcsnicmp(szUrl, "/goto/", 6) == 0) 
	{
		c = szUrl;
		i = 0;
		while (szUrl[i] != '\0')
		{
			if (szUrl[i] == '?') 
			{
				szUrl[i] = '&';
				break;
			}
			i++;
		}
 
		for (i=0;i<6;++i)
			c = _tcsinc(c);
 
		_tcscat(szNewUrl,"/go_to.asp?dest=");
		_tcscat(szNewUrl,c);
		pHeaders->SetHeader(pCtxt->m_pFC, "url", szNewUrl);
		return SF_STATUS_REQ_NEXT_NOTIFICATION;
	}
 
	if ((_tcsnicmp(szUrl, "/products/", 10) == 0) ||
	    (_tcsnicmp(szUrl, "/product/", 9) == 0) ||
		(_tcsnicmp(szUrl, "/groups/", 8) == 0) ||
		(_tcsnicmp(szUrl, "/group/", 7) == 0) ||
		(_tcsnicmp(szUrl, "/manus/", 7) == 0) ||
		(_tcsnicmp(szUrl, "/manu/", 6) == 0) || 
		(_tcsnicmp(szUrl, "/map/", 5) == 0))
	{
		i = 0;
		while (szUrl[i] != '\0')
		{
			if (szUrl[i] == '?') 
			{
				szUrl[i] = '&';
				break;
			}
			i++;
		}
		_tcscat(szNewUrl,"/urlmapper2.asp?mapurl=");
		_tcscat(szNewUrl,szUrl);
		_tcscat(szNewUrl,"&urlmapped=true");
		pHeaders->SetHeader(pCtxt->m_pFC, "url", szNewUrl);
		return SF_STATUS_REQ_NEXT_NOTIFICATION;
	}
 
	if (_tcsstr(szUrl, ";DECLARE"))
	{
		_tcscat(szNewUrl,szUrl);
		szNewUrl.Left(_tcsstr(szUrl, ";DECLARE")-1);
		//szNewUrl.erase(_tcsstr(szUrl, ";DECLARE"));
		pHeaders->SetHeader(pCtxt->m_pFC, "url", szNewUrl);
		return SF_STATUS_REQ_NEXT_NOTIFICATION;
	}
	
	// Keine Treffer gefunden
	return SF_STATUS_REQ_NEXT_NOTIFICATION;
}

Open in new window

Editors IDEsC++

Avatar of undefined
Last Comment
Sven

8/22/2022 - Mon
alb66

szNewUrl.Left(_tcsstr(szUrl, ";DECLARE")-1);

szNewUrl is an array of char, so it hasn't the Left method (it is not a class)

If I understand what you want to do you must write:

char* pp = _tcsstr(szUrl, ";DECLARE" );
if ( pp != NULL )
{
  int nLen = pp - szUrl;
  strncpy( szNewUrl, szUrl, nLen;
}


ASKER CERTIFIED SOLUTION
alb66

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Sven

I do not know if this works, cause now I have the problem that I can not debug the ISAPI extension. I followed the instruction spreaded over the internet but there is some problem with the project. So you have to patient until I can grant you the points!
alb66

Don't worry...
the important is that you can solve your problem
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER
Sven

Compiling worked now but it does not work as I want:

char* pp = _tcsstr(szUrl, ";DECLARE" );
if ( pp != NULL )
{
  int nLen = pp - szUrl;
  _tcsncpy( szNewUrl, szUrl, nLen );
}

What I want is, that a string szUrl is cut to a new string szNewUrl, like:

  http://www.mydomain.com/default.asp?v=123;DECLARE%20@S

is cut to:

  http://www.mydomain.com/default.asp?v=123
ASKER
Sven

Now it works as alb66 suggested!