[pywin32-checkins] pywin32/win32/src win32inet_winhttp.cpp, 1.2, 1.3
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-12-08 12:38:03
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv1301/win32/src Modified Files: win32inet_winhttp.cpp Log Message: Add win32inet.WinHttpGetDefaultProxyConfiguration and various winhttp constants. Index: win32inet_winhttp.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32inet_winhttp.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** win32inet_winhttp.cpp 9 Apr 2008 04:31:07 -0000 1.2 --- win32inet_winhttp.cpp 8 Dec 2008 12:37:51 -0000 1.3 *************** *** 10,15 **** #include "winhttp.h" #include "pywintypes.h" ! ! extern PyObject *PyObject_FromHINTERNET(HINTERNET hi); // @doc --- 10,14 ---- #include "winhttp.h" #include "pywintypes.h" ! #include "pywinobjects.h" // @doc *************** *** 17,20 **** --- 16,22 ---- static funcWinHttpGetIEProxyConfigForCurrentUser pfnWinHttpGetIEProxyConfigForCurrentUser=NULL; + typedef BOOL (WINAPI *funcWinHttpGetDefaultProxyConfiguration)(WINHTTP_PROXY_INFO *); + static funcWinHttpGetDefaultProxyConfiguration pfnWinHttpGetDefaultProxyConfiguration=NULL; + typedef BOOL (WINAPI *funcWinHttpGetProxyForUrl)(HINTERNET, LPCWSTR, WINHTTP_AUTOPROXY_OPTIONS*, WINHTTP_PROXY_INFO *); static funcWinHttpGetProxyForUrl pfnWinHttpGetProxyForUrl=NULL; *************** *** 23,26 **** --- 25,31 ---- static funcWinHttpOpen pfnWinHttpOpen=NULL; + typedef BOOL (WINAPI *funcWinHttpCloseHandle)(HINTERNET); + static funcWinHttpCloseHandle pfnWinHttpCloseHandle=NULL; + #define CHECK_PFN(fname) \ if (pfn##fname==NULL) \ *************** *** 46,49 **** --- 51,96 ---- LOAD_PFN(WinHttpGetProxyForUrl); LOAD_PFN(WinHttpOpen); + LOAD_PFN(WinHttpCloseHandle); + LOAD_PFN(WinHttpGetDefaultProxyConfiguration); + // winhttp.dll also provides the string resources for its errors. + PyWin_RegisterErrorMessageModule(WINHTTP_ERROR_BASE, WINHTTP_ERROR_LAST, hmod); + } + + // A handle used by WinHttpOpen; even though it is documented as a HINTERNET, + // our standard HINTERNET isn't suitable as (a) the callbacks fail and (b) + // the handle must be closed via WinHttpCloseHandle. + class PyHWINHTTP : public PyHANDLE + { + public: + PyHWINHTTP(HINTERNET hInit) : PyHANDLE((HANDLE)hInit) {;} + + virtual BOOL Close(void) { + BOOL ret=TRUE; + // We've already checked we have the function-pointer - but + // it can't hurt to check again! + if (m_handle && pfnWinHttpCloseHandle){ + HINTERNET h=m_handle; + m_handle = 0; // don't try again! + ret=(*pfnWinHttpCloseHandle)(h); + if (!ret) + PyWin_SetAPIError("WinHttpCloseHandle"); + } + return ret; + } + virtual const char *GetTypeName() {return "PyHWINHTTP";} + }; + + PyObject *PyObject_FromWinHttpHandle(HINTERNET hi) + { + // Don't allow handles to be created if we can't close them! + CHECK_PFN(WinHttpCloseHandle); + PyHWINHTTP *ret=new PyHWINHTTP(hi); + if (ret==NULL) + return PyErr_NoMemory(); + if (PyErr_Occurred()){ + Py_DECREF(ret); + ret = NULL; + } + return ret; } *************** *** 75,79 **** } ! // @object WINHTTP_AUTOPROXY_OPTIONS|Used by <om win32inet.WinHTTPGetProxyForUrl> BOOL PyObject_AsWINHTTP_AUTOPROXY_OPTIONS(PyObject *ob, WINHTTP_AUTOPROXY_OPTIONS *out) { --- 122,139 ---- } ! // @object PyWINHTTP_PROXY_INFO|A tuple representing a WINHTTP_PROXY_INFO structure. ! ! PyObject *PyObject_FromWINHTTP_PROXY_INFO(WINHTTP_PROXY_INFO *i, BOOL bFreeStrings=TRUE) ! { ! PyObject *ret = Py_BuildValue("kuu", ! i->dwAccessType, // @tupleitem 0|int|dwAccessType| ! i->lpszProxy, // @tupleitem 2|string|lpszProxy| ! i->lpszProxyBypass); // @tupleitem 3|string|lpszProxy ! if (i->lpszProxy) GlobalFree(i->lpszProxy); ! if (i->lpszProxyBypass) GlobalFree(i->lpszProxyBypass); ! return ret; ! } ! ! // @object PyWINHTTP_AUTOPROXY_OPTIONS|Used by <om win32inet.WinHTTPGetProxyForUrl> BOOL PyObject_AsWINHTTP_AUTOPROXY_OPTIONS(PyObject *ob, WINHTTP_AUTOPROXY_OPTIONS *out) { *************** *** 105,110 **** } ! // @pymethod tuple|win32inet|WinHttpGetIEProxyConfigForCurrentUser|Obtains ! // the Internet Explorer proxy configuration for the current user. PyObject *PyWinHttpGetProxyForUrl(PyObject *self, PyObject *args) { --- 165,190 ---- } ! // @pymethod <o PyWINHTTP_PROXY_INFO>|win32inet|WinHttpGetDefaultProxyConfiguration| ! // Retrieves the default WinHTTP proxy configuration from the registry. ! PyObject *PyWinHttpGetDefaultProxyConfiguration(PyObject *self, PyObject *args) ! { ! CHECK_PFN(WinHttpGetDefaultProxyConfiguration); ! if (!PyArg_ParseTuple(args, ":WinHttpGetDefaultProxyConfiguration")) ! return NULL; ! WINHTTP_PROXY_INFO info; ! memset(&info, 0, sizeof(info)); ! BOOL ok; ! Py_BEGIN_ALLOW_THREADS ! ok = (*pfnWinHttpGetDefaultProxyConfiguration)(&info); ! Py_END_ALLOW_THREADS ! if (!ok) { ! PyWin_SetAPIError("WinHttpGetDefaultProxyConfiguration"); ! return NULL; ! } ! return PyObject_FromWINHTTP_PROXY_INFO(&info); ! } ! ! // @pymethod <o PyWINHTTP_PROXY_INFO>|win32inet|WinHttpGetProxyForUrl|Obtains ! // the Internet Explorer proxy configuration for the specified URL. PyObject *PyWinHttpGetProxyForUrl(PyObject *self, PyObject *args) { *************** *** 114,118 **** &obHandle, // @pyparm <o HANDLE>/int|handle|| &obURL, // @pyparm unicode/string|url|| ! &obOptions // @pyparm tuple|options|| )) return NULL; --- 194,198 ---- &obHandle, // @pyparm <o HANDLE>/int|handle|| &obURL, // @pyparm unicode/string|url|| ! &obOptions // @pyparm <o PyWINHTTP_AUTOPROXY_OPTIONS>|options|| )) return NULL; *************** *** 143,157 **** goto done; } ! // @rdesc The result is a windows WINHTTP_PROXY_INFO ! // structure; a tuple of an int (bool) and 2 unicode strings ! // (dwAccessType, lpszProxy, lpszProxyBypass). ! // @pyseeapi WinHttpGetProxyForUrl ! // @pyseeapi WINHTTP_PROXY_INFO ! ret = Py_BuildValue("kuu", ! info.dwAccessType, ! info.lpszProxy, ! info.lpszProxyBypass); ! if (info.lpszProxy) GlobalFree(info.lpszProxy); ! if (info.lpszProxyBypass) GlobalFree(info.lpszProxyBypass); done: if (url) --- 223,227 ---- goto done; } ! ret = PyObject_FromWINHTTP_PROXY_INFO(&info); done: if (url) *************** *** 198,202 **** } // @pyseeapi WinHttpOpen ! ret = PyObject_FromHINTERNET(hi); done: if (ua) --- 268,272 ---- } // @pyseeapi WinHttpOpen ! ret = PyObject_FromWinHttpHandle(hi); done: if (ua) |