Hi John
I think that I may have a solution.
1. In fnInsertHTMLString() in webutils.c exchange the following code:
// This routine is used to insert a string in place of the £XAB marker, which is assumed to be always 4 bytes long
// The inserted text should be at least 4 bytes of length to ensue that nothing is left in the buffer
// Typically this routine is used to set check boxes or selected fields, etc.
//
extern int fnInsertHTMLString(CHAR *cToAdd, unsigned short usAddLength, unsigned char **ptrBuffer, unsigned short *usMaxLen, unsigned short *usLen)
{
unsigned char *ptrEnd;
unsigned char *ptrShift;
unsigned short usLength = *usLen - 1;
#ifndef TEST_INSERT
CHAR cShort[4];
if (usAddLength < 4) { // if the user wants to insert something which is shorter than the 4 command bytes,
we increase its length by inserting spaces before it
unsigned char ucShift = (4 - usAddLength);
uMemset(cShort, ' ', 4);
while (ucShift < 4) {
cShort[ucShift++] = *cToAdd++;
}
usAddLength = 4;
cToAdd = cShort;
}
#endif
ptrEnd = *ptrBuffer + usLength; // set pointer to end of buffer
ptrShift = ptrEnd - usAddLength; // set pointer to end after insertion
if ((*ptrBuffer - 4 + usAddLength) >= ptrEnd) {
#ifdef TEST_INSERT
int iFrameReduction = ptrEnd - *ptrBuffer + 4;
*usMaxLen -= (usLength + 4);
*ptrBuffer = 0; // present frame terminated so mark by clearing pointer
return (iFrameReduction);
#else
*usMaxLen -= (usLength + 4);
return (ptrEnd - *ptrBuffer + 4); // we don't have the necessary space to add at the moment (shorten the present frame
to make it possible next time around)
#endif
}
#ifdef TEST_INSERT
if (usAddLength >= 4) {
usLength -= (usAddLength - 4); // the remaining length after insertion
ptrShift += 4;
if (ptrEnd == ptrShift) { // no shift necessary in this case
usLength = 0;
}
while (usLength--) {
*(--ptrEnd) = *(--ptrShift); // shift remaining bytes along in buffer, making room for the insertion
}
}
else {
ptrShift = *ptrBuffer - (4 - usAddLength);
ptrEnd = *ptrBuffer;
uMemcpy(ptrShift, ptrEnd, usLength);
}
#else
usLength -= (usAddLength - 4); // the remaining length after insertion
ptrShift += 4;
while (usLength--) {
*(--ptrEnd) = *(--ptrShift); // shift remaining bytes along in buffer, making room for the insertion
}
#endif
ptrShift = *ptrBuffer - 4;
uMemcpy(ptrShift, cToAdd, usAddLength); // insert the string
*ptrBuffer = ptrShift + usAddLength;
#ifdef TEST_INSERT
if (usAddLength >= 4) {
usAddLength -= 4;
*usLen -= (usAddLength); // correct lengths after insertion
*usMaxLen -= usAddLength;
}
else {
return (4 - usAddLength); // shorten complete file by this amount
}
#else
usAddLength -= 4;
*usLen -= (usAddLength); // correct lengths after insertion
*usMaxLen -= usAddLength;
#endif
return 0;
}
#endif
2. In http.c make the following change
if ((usLost = fnInsertHTMLString((CHAR *)cInsertString, usInsertLength, &ptrBuffer, usMaxLen, &usLen)) != 0) {
#ifdef TEST_INSERT
if (ptrBuffer != 0) { // file length reduction
usToSend -= usLost;
}
else {
return (usToSend - usLost); // parameter list cut off, handle it next time around
}
#else
return (usToSend - usLost); // parameter list cut off, handle it next time around
#endif
By adding TEST_INSERT as project define - for example in config.h - the new method will be used. By removing it, you can fall back to the old method should
any new problem be encoutered,
Basically I was lazy when originally writing the string insertion routine. It padded to avoid buffer manipulation when inserting short strings (shorter that
the control sequence) which actually works fine in most html code since space padding is also ignored. But spaces in a form input are set as default input
which was not perfect - I believe the right alignment made it easier to see that the string wasn't followed by spaces.
My tests with the above code were good but I tested only the standard pages in the demo project and I can't exclude a surprise (originally it did take quite
a lot of work to ensure that every possible sequence was encountered for - eg. when frames have to be cut short because the new string won't fit, etc. etc.).
I will keep this new code active in my reference project and if there is no negative feedback from anyone who uses it I will activate it in the next service
packs. Should anyone detect a new problem, send me the offending web page and I will try to fix it asap. There is however a good chance that it will already
be stable.
Regards
Mark