Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ISAPI Filter for Dynamic Content

Status
Not open for further replies.

Gorkem

Programmer
Jun 18, 2002
259
CA
Hi all,

I am trying to create an ISAPI filter to check the current user to see if they have administrative rights to edit pages on the server.. If so, I want to display 3 links at the top of any page that is displayed: EDIT, UPLOAD, UNDO.

The authentication seems to work without any problems.. Now the problem lies within the section that I need to add the links.. 1 of 3 things happen each time I try it:

1) My links do not show..
2) Links do show up, but cuts off the bottom part of all the pages (Content-Length: issue?)
3) The IIS service crashes and needs to be restarted.

Here is the code more recent code I am using to display the links.. I've also tried the WriteClient which doesn't work as well.. ANY HELP would be appreciated..!!

Oh yeah.. I'm using Visual C++ 6.0 to compile.. (if that makes any difference at all)



DWORD CEditNewFilter::OnSendRawData(CHttpFilterContext* pCtxt,
PHTTP_FILTER_RAW_DATA pRawData)
{

LPTSTR Txt="";
DWORD dwSize = pRawData->cbInData;
char* nTxt="";
dwSize += 34;

Txt = (LPTSTR)pRawData->pvInData;

if (strstr(Txt,&quot;<body&quot;))
{

PHTTP_FILTER_RAW_DATA nRaw;
memset( &nRaw, 0, sizeof(nRaw) );
nRaw->pvInData = pCtxt->AllocMem(dwSize, 0 );
nRaw->cbInBuffer = dwSize;
wsprintf(nTxt,&quot;%s %s&quot;,Edit_Text,Edit_Text);
strcat((char*)nRaw->pvInData,nTxt);
pRawData->cbInBuffer = nRaw->cbInBuffer;
pRawData->cbInData = nRaw->cbInData;
pRawData->pvInData = nRaw->pvInData;
}
return SF_STATUS_REQ_NEXT_NOTIFICATION;
}


Cheers,

G.
 
>> wsprintf(nTxt,&quot;%s %s&quot;,Edit_Text,Edit_Text);

that's probably why it crashes, you never allocated &quot;nTxt&quot;

I've never tried to modify the output stream so can't help with that part.

-pete
 
nTxt is defined near the top:

>> char* nTxt=&quot;&quot;;

I've had some luck with adding to the content, however it uses the preset data length.. I've tried to increase the data length but it doesn't seem to help.

Is there anywhere on the net that would explain in detail how to add additional text to an output stream? I've found a few.. but they seem to be outdated and do not work with VC++ 6.0.

Cheers,

G.
 
Hmm.. now that I look at my last post.. it doesn't make much sense.. let me go into a little bit more detail..

What I mean about preset data lenght is the the data length allocated for the output stream (the current page that is streaming). If I add additional text at the end, it doesn't show.. if I add additional text to the beginning of the stream, it will display however, it will cut off anything past the data length of the original stream.

IE:

If I add &quot;HELLO WORLD&quot; to the begining of:

<html>
TESTING
</html>

it will show up as:

HELLO WORLD
<html>
TES


Any idea's or links to pages that could help?

Cheers,

G.
 
>> nTxt is defined near the top:

yeah i know but it's never allocated and since wsprintf has a maximum of 1024 what u want to do is

char nTxt[1025];

now u can use it in wsprintf without crashing

Also what is &quot;Edit_Text&quot;? it is not defined in your post, as per wsprintf if the combined string is greater than 1024 in length your out of luck with it.

-pete
 
Thanks.. I didn't know I had to allocate it before I used it.. I'm fairly new to C++ (not a pro, but not extremely amatuer either).. I'll try the allocation and see if it works any better.

Sorry.. should have mentioned about the Edit_Text earlier..

Edit_Text is defined at the begining of the file:

// For Testing
#define Edit_Text &quot;This text is inserted&quot;

and the wsprintf is wrong.. I mistyped it in the post.. it should be:

wsprintf (nTxt,&quot;%s %s&quot;,Edit_Text,Txt);

Cheers,

G.
 
Hi Palbano,

Unfortunately, the allocation didn't stop the crashing. :(

Cheers,

G.
 
r u sure ur not going over the 1024 limit of wsprintf()?

-pete
 
Positive.. hehe.. The streaming output is:

<html>
<body>
TESTING
</body>
</html>


Unless........ maybe it also contains the html headers.. in which case, it may be over the 1024 characters....

Could I maybe use sprintf? or is there another command I can use to do this without the limitations?

Cheers,

G.
 
i don't know of any limitation to sprintf() of course the old fashioned way always works memcpy() that's what i stick with.

make sure your allocating your buffers and use the correct sizes in parameters to avoid buffer overflow errors. the bain of web server developement! i.e., the correct size is always the size of the destination buffer not the input buffer.

hope this helps
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top