Update of /cvsroot/pywin32/pywin32/isapi/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1831/src
Modified Files:
PyExtensionObjects.cpp PyFilterObjects.cpp
Log Message:
Handle server variables > 8k in length and also handle IIS6 'UNICODE_'
variables.
Index: PyExtensionObjects.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/isapi/src/PyExtensionObjects.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** PyExtensionObjects.cpp 12 Oct 2006 07:00:37 -0000 1.4
--- PyExtensionObjects.cpp 14 Dec 2006 08:35:34 -0000 1.5
***************
*** 344,354 ****
char buf[8192] = "";
! DWORD bufsize = sizeof(buf)/sizeof(buf[0]);
if (pecb->m_pcb){
Py_BEGIN_ALLOW_THREADS
bRes = pecb->m_pcb->GetServerVariable(variable, buf, &bufsize);
Py_END_ALLOW_THREADS
if (!bRes) {
if (def) {
Py_INCREF(def);
--- 344,377 ----
char buf[8192] = "";
! DWORD bufsize = sizeof(buf);
! char *bufUse = buf;
if (pecb->m_pcb){
Py_BEGIN_ALLOW_THREADS
bRes = pecb->m_pcb->GetServerVariable(variable, buf, &bufsize);
+ if (!bRes && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+ // Although the IIS docs say it should be good, IIS5
+ // returns -1 for 'bufsize' and MS samples show not
+ // to trust it too. Like the MS sample, we max out
+ // at some value - we choose 64k. We double each
+ // time, meaning we get 3 goes around the loop
+ bufUse = NULL;
+ bufsize = sizeof(buf);
+ for (int i=0;i<3;i++) {
+ bufsize *= 2;
+ bufUse = (char *)realloc(bufUse, bufsize);
+ if (!bufUse)
+ break;
+ bRes = pecb->m_pcb->GetServerVariable(variable, bufUse, &bufsize);
+ if (bRes || GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+ break;
+ }
+ }
Py_END_ALLOW_THREADS
+ if (!bufUse)
+ return PyErr_NoMemory();
if (!bRes) {
+ if (bufUse != buf)
+ free(bufUse);
if (def) {
Py_INCREF(def);
***************
*** 358,362 ****
}
}
! return PyString_FromStringAndSize(buf, bufsize);
}
--- 381,390 ----
}
}
! PyObject *ret = strncmp("UNICODE_", variable, 8) == 0 ?
! PyUnicode_FromWideChar((WCHAR *)bufUse, bufsize / sizeof(WCHAR)) :
! PyString_FromStringAndSize(bufUse, bufsize);
! if (bufUse != buf)
! free(bufUse);
! return ret;
}
Index: PyFilterObjects.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/isapi/src/PyFilterObjects.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** PyFilterObjects.cpp 12 Oct 2006 01:44:57 -0000 1.7
--- PyFilterObjects.cpp 14 Dec 2006 08:35:34 -0000 1.8
***************
*** 229,237 ****
--- 229,260 ----
char buf[8192] = "";
DWORD bufsize = sizeof(buf)/sizeof(buf[0]);
+ char *bufUse = buf;
if (phfc->m_pfc){
Py_BEGIN_ALLOW_THREADS
bRes = phfc->m_pfc->GetServerVariable(variable, buf, &bufsize);
+ if (!bRes && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+ // Although the IIS docs say it should be good, IIS5
+ // returns -1 for 'bufsize' and MS samples show not
+ // to trust it too. Like the MS sample, we max out
+ // at some value - we choose 64k. We double each
+ // time, meaning we get 3 goes around the loop
+ bufUse = NULL;
+ bufsize = sizeof(buf);
+ for (int i=0;i<3;i++) {
+ bufsize *= 2;
+ bufUse = (char *)realloc(bufUse, bufsize);
+ if (!bufUse)
+ break;
+ bRes = phfc->m_pfc->GetServerVariable(variable, bufUse, &bufsize);
+ if (bRes || GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+ break;
+ }
+ }
Py_END_ALLOW_THREADS
+ if (!bufUse)
+ return PyErr_NoMemory();
if (!bRes) {
+ if (bufUse != buf)
+ free(bufUse);
if (def) {
Py_INCREF(def);
***************
*** 241,245 ****
}
}
! return PyString_FromStringAndSize(buf, bufsize);
}
--- 264,273 ----
}
}
! PyObject *ret = strncmp("UNICODE_", variable, 8) == 0 ?
! PyUnicode_FromWideChar((WCHAR *)bufUse, bufsize / sizeof(WCHAR)) :
! PyString_FromStringAndSize(bufUse, bufsize);
! if (bufUse != buf)
! free(bufUse);
! return ret;
}
|