Update of /cvsroot/pywin32/pywin32/win32/src/win32wnet
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16887/win32wnet
Modified Files:
Tag: py3k
Netres.h PyNCB.cpp PyNCB.h PyNetresource.cpp win32wnet.cpp
Log Message:
Changes to build for Python 3.0
Index: win32wnet.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32wnet/win32wnet.cpp,v
retrieving revision 1.13
retrieving revision 1.13.2.1
diff -C2 -d -r1.13 -r1.13.2.1
*** win32wnet.cpp 3 Jun 2007 14:53:07 -0000 1.13
--- win32wnet.cpp 29 Aug 2008 05:00:24 -0000 1.13.2.1
***************
*** 61,65 ****
-
/****************************************************************************
HELPER FUNCTIONS
--- 61,64 ----
***************
*** 130,182 ****
// @pymethod |win32wnet|WNetAddConnection2|Creates a connection to a network resource. The function can redirect
// a local device to the network resource.
! static
! PyObject *
! PyWNetAddConnection2 (PyObject *self, PyObject *args)
!
{
! // @todo Eventually should update this to use a NETRESOURCE object (it was written before PyNETRESOURCE)
! DWORD Type; // @pyparm int|type||The resource type. May be either RESOURCETYPE_DISK, RESOURCETYPE_PRINT, or RESOURCETYPE_ANY (from win32netcon)
! LPSTR LocalName; // @pyparm string|localName||holds the name of a local device to map connection to; may be NULL
! LPSTR RemoteName; // @pyparm string|remoteName||holds the passed in remote machine\service name.
! LPSTR ProviderName = NULL; // @pyparm string|ProviderName|None|holds name of network provider to use (if any): NULL lets OS handle it
! LPSTR Username = NULL; // @pyparm string|userName|None|The user name to connect as.
! LPSTR Password = NULL; // @pyparm string|password|None|The password to use.
!
DWORD ErrorNo; // holds the returned error number, if any
! DWORD flags = 0; // @pyparm int|flags|0|Specifies a DWORD value that describes connection options. The following value is currently defined.
! // @flagh Value|Meaning
! // @flag CONNECT_UPDATE_PROFILE|The network resource connection should be remembered.
! // <nl>If this bit flag is set, the operating system automatically attempts to restore the connection when the user logs on.
! // <nl>The operating system remembers only successful connections that redirect local devices. It does not remember connections that are unsuccessful or deviceless connections. (A deviceless connection occurs when the lpLocalName member is NULL or points to an empty string.)
! // <nl>If this bit flag is clear, the operating system does not automatically restore the connection at logon.
! NETRESOURCE NetResource;
! if (!PyArg_ParseTuple(args,"izs|zzzi",&Type,&LocalName,&RemoteName,&ProviderName,&Username,&Password, &flags))
return NULL;
!
! // Build the NETRESOURCE structure
! Py_BEGIN_ALLOW_THREADS
!
! memset((void *)&NetResource, '\0', sizeof(NETRESOURCE));
! NetResource.dwType = Type;
! NetResource.lpLocalName = LocalName;
! NetResource.lpProvider = ProviderName;
! NetResource.lpRemoteName = RemoteName;
!
! #ifdef _WIN32_WCE_ // Windows CE only has the #3 version...use NULL for HWND to simulate #2
! ErrorNo = WNetAddConnection3(NULL,&NetResource, Password, Username, flags);
! #else
! ErrorNo = WNetAddConnection2(&NetResource, Password, Username, flags);
! #endif
! Py_END_ALLOW_THREADS
!
! if (ErrorNo != NO_ERROR)
! {
! return ReturnNetError("WNetAddConnection2", ErrorNo);
! }
!
! Py_INCREF(Py_None);
! return Py_None;
!
};
--- 129,172 ----
// @pymethod |win32wnet|WNetAddConnection2|Creates a connection to a network resource. The function can redirect
// a local device to the network resource.
! // @comm This function previously accepted separate parameters to construct a <o PyNETRESOURCE>. It has been
! // changed to accept a NETRESOURCE object instead of the individual elements.
! // @comm Accepts keyword arguments.
! // @pyseeapi WNetAddConnection2
! static PyObject *PyWNetAddConnection2 (PyObject *self, PyObject *args, PyObject *kwargs)
{
! LPTSTR Username = NULL;
! LPTSTR Password = NULL;
! PyObject *obnr, *obPassword=Py_None, *obUsername=Py_None, *ret=NULL;
DWORD ErrorNo; // holds the returned error number, if any
! DWORD flags = 0;
! NETRESOURCE * pNetResource;
! static char *keywords[] = {"NetResource","Password","UserName","Flags", NULL};
! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OOk", keywords,
! &obnr, // @pyparm <o PyNETRESOURCE>|NetResource||Describes the network resource for the connection.
! &obPassword, // @pyparm str|Password|None|The password to use. Use None for default credentials.
! &obUsername, // @pyparm str|UserName|None|The user name to connect as. Use None for default credentials.
! &flags)) // @pyparm int|Flags|0|Combination win32netcon.CONNECT_* flags
return NULL;
! if (PyWinObject_AsNETRESOURCE(obnr, &pNetResource, FALSE)
! && PyWinObject_AsTCHAR(obPassword, &Password, TRUE)
! && PyWinObject_AsTCHAR(obUsername, &Username, TRUE)){
! Py_BEGIN_ALLOW_THREADS
! #ifdef _WIN32_WCE_ // Windows CE only has the #3 version...use NULL for HWND to simulate #2
! ErrorNo = WNetAddConnection3(NULL, pNetResource, Password, Username, flags);
! #else
! ErrorNo = WNetAddConnection2(pNetResource, Password, Username, flags);
! #endif
! Py_END_ALLOW_THREADS
! if (ErrorNo != NO_ERROR)
! ReturnNetError("WNetAddConnection2", ErrorNo);
! else{
! Py_INCREF(Py_None);
! ret = Py_None;
! }
! }
! PyWinObject_FreeTCHAR(Password);
! PyWinObject_FreeTCHAR(Username);
! return ret;
};
***************
*** 186,201 ****
PyWNetCancelConnection2 (PyObject *self, PyObject *args)
{
! LPSTR lpName; // @pyparm string|name||Name of existing connection to be closed
DWORD dwFlags; // @pyparm int|flags||Currently determines if the persisent connection information will be updated as a result of this call.
DWORD bForce; // @pyparm int|force||indicates if the close operation should be forced. (i.e. ignore open files and connections)
DWORD ErrorNo;
! if(!PyArg_ParseTuple(args, "sii",&lpName, &dwFlags, &bForce))
return NULL;
-
Py_BEGIN_ALLOW_THREADS
ErrorNo = WNetCancelConnection2(lpName, dwFlags, (BOOL)bForce);
Py_END_ALLOW_THREADS
!
if (ErrorNo != NO_ERROR)
{
--- 176,193 ----
PyWNetCancelConnection2 (PyObject *self, PyObject *args)
{
! LPTSTR lpName; // @pyparm string|name||Name of existing connection to be closed
DWORD dwFlags; // @pyparm int|flags||Currently determines if the persisent connection information will be updated as a result of this call.
DWORD bForce; // @pyparm int|force||indicates if the close operation should be forced. (i.e. ignore open files and connections)
DWORD ErrorNo;
! PyObject *obName;
! if(!PyArg_ParseTuple(args, "Okk", &obName, &dwFlags, &bForce))
! return NULL;
! if (!PyWinObject_AsTCHAR(obName, &lpName, FALSE))
return NULL;
Py_BEGIN_ALLOW_THREADS
ErrorNo = WNetCancelConnection2(lpName, dwFlags, (BOOL)bForce);
Py_END_ALLOW_THREADS
! PyWinObject_FreeTCHAR(lpName);
if (ErrorNo != NO_ERROR)
{
***************
*** 220,232 ****
// @pyparm int|type||Specifies the resource types to enumerate.
// @pyparm int|usage||Specifies the resource usage to be enumerated.
! // @pyparm <o NETRESOURCE>|resource||Python NETRESOURCE object.
if (!PyArg_ParseTuple(args, "iiiO", &dwScope,&dwType,&dwUsage,&ob_nr))
return NULL;
! if (ob_nr == Py_None)
! p_nr = NULL;
! else if
! (!PyWinObject_AsNETRESOURCE(ob_nr, &p_nr, FALSE))
! return(ReturnError("failed converting NetResource Object","WNetOpenEnum"));
Py_BEGIN_ALLOW_THREADS
--- 212,221 ----
// @pyparm int|type||Specifies the resource types to enumerate.
// @pyparm int|usage||Specifies the resource usage to be enumerated.
! // @pyparm <o PyNETRESOURCE>|resource||Python NETRESOURCE object.
if (!PyArg_ParseTuple(args, "iiiO", &dwScope,&dwType,&dwUsage,&ob_nr))
return NULL;
! if (!PyWinObject_AsNETRESOURCE(ob_nr, &p_nr, TRUE))
! return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 263,267 ****
};
! // @pymethod [<o NETRESOURCE>, ...]|win32wnet|WNetEnumResource|Enumerates a list of resources
static
PyObject *
--- 252,256 ----
};
! // @pymethod [<o PyNETRESOURCE>, ...]|win32wnet|WNetEnumResource|Enumerates a list of resources
static
PyObject *
***************
*** 478,482 ****
}
! // @pymethod (<o NETRESOURCE>, str)|win32wnet|WNetGetResourceInformation|Finds the type and provider of a network resource
// @rdesc Returns a NETRESOURCE and a string containing the trailing part of the remote path
PyObject *
--- 467,471 ----
}
! // @pymethod (<o PyNETRESOURCE>, str)|win32wnet|WNetGetResourceInformation|Finds the type and provider of a network resource
// @rdesc Returns a NETRESOURCE and a string containing the trailing part of the remote path
PyObject *
***************
*** 494,498 ****
if (!PyArg_ParseTuple(args, "O!", &PyNETRESOURCEType,
! &NRT)) // @pyparm <o NETRESOURCE>|NetResource||Describes a network resource. lpRemoteName is required, dwType and lpProvider can be supplied if known
return NULL;
--- 483,487 ----
if (!PyArg_ParseTuple(args, "O!", &PyNETRESOURCEType,
! &NRT)) // @pyparm <o PyNETRESOURCE>|NetResource||Describes a network resource. lpRemoteName is required, dwType and lpProvider can be supplied if known
return NULL;
***************
*** 563,567 ****
TCHAR errstr[1024], provider[256];
Py_BEGIN_ALLOW_THREADS
! err=WNetGetLastError(&extendederr, errstr, sizeof(errstr), provider, sizeof(provider));
Py_END_ALLOW_THREADS
if (err==NO_ERROR)
--- 552,556 ----
TCHAR errstr[1024], provider[256];
Py_BEGIN_ALLOW_THREADS
! err=WNetGetLastError(&extendederr, errstr, sizeof(errstr)/sizeof(TCHAR), provider, sizeof(provider)/sizeof(TCHAR));
Py_END_ALLOW_THREADS
if (err==NO_ERROR)
***************
*** 570,574 ****
}
! // @pymethod <o NETRESOURCE>|win32wnet|WNetGetResourceParent|Finds the parent resource of a network resource
PyObject *PyWNetGetResourceParent(PyObject *self, PyObject *args)
{
--- 559,563 ----
}
! // @pymethod <o PyNETRESOURCE>|win32wnet|WNetGetResourceParent|Finds the parent resource of a network resource
PyObject *PyWNetGetResourceParent(PyObject *self, PyObject *args)
{
***************
*** 580,584 ****
PyObject *obnr, *ret=NULL;
if (!PyArg_ParseTuple(args, "O:WNetGetResourceParent",
! &obnr)) // @pyparm <o NETRESOURCE>|NetResource||Describes a network resource. lpRemoteName and lpProvider are required, dwType is recommended for efficiency
return NULL;
if (!PyWinObject_AsNETRESOURCE(obnr, &nr, FALSE))
--- 569,573 ----
PyObject *obnr, *ret=NULL;
if (!PyArg_ParseTuple(args, "O:WNetGetResourceParent",
! &obnr)) // @pyparm <o PyNETRESOURCE>|NetResource||Describes a network resource. lpRemoteName and lpProvider are required, dwType is recommended for efficiency
return NULL;
if (!PyWinObject_AsNETRESOURCE(obnr, &nr, FALSE))
***************
*** 621,625 ****
{"Netbios", PyWinMethod_Netbios, 1, "Calls the windows Netbios function"},
// @pymeth WNetAddConnection2|Creates a connection to a network resource.
! {"WNetAddConnection2", PyWNetAddConnection2, 1, "type,localname,remotename,provider,username,password (does not use NETRESOURCE)"},
// @pymeth WNetCancelConnection2|Closes network connections made by WNetAddConnection2 or 3
{"WNetCancelConnection2", PyWNetCancelConnection2, 1, "localname,dwflags,bforce"},
--- 610,614 ----
{"Netbios", PyWinMethod_Netbios, 1, "Calls the windows Netbios function"},
// @pymeth WNetAddConnection2|Creates a connection to a network resource.
! {"WNetAddConnection2", (PyCFunction)PyWNetAddConnection2, METH_KEYWORDS|METH_VARARGS, "WNetAddConnection2(NetResource, Password, UserName, Flags)"},
// @pymeth WNetCancelConnection2|Closes network connections made by WNetAddConnection2 or 3
{"WNetCancelConnection2", PyWNetCancelConnection2, 1, "localname,dwflags,bforce"},
***************
*** 643,662 ****
};
! extern "C" __declspec(dllexport)
! void
! initwin32wnet(void)
!
{
! PyObject *dict, *module;
! module = Py_InitModule("win32wnet", win32wnet_functions);
! if (!module) return;
! dict = PyModule_GetDict(module);
! if (!dict) return;
! PyWinGlobals_Ensure();
! PyDict_SetItemString(dict, "error", PyWinExc_ApiError);
! PyDict_SetItemString(dict, "NETRESOURCEType", (PyObject *)&PyNETRESOURCEType);
! PyDict_SetItemString(dict, "NCBType", (PyObject *)&PyNCBType);
! Py_INCREF(PyWinExc_ApiError);
! }
--- 632,682 ----
};
! extern "C" __declspec(dllexport)
! #if (PY_VERSION_HEX < 0x03000000)
! void initwin32wnet(void)
! #else
! PyObject *PyInit_win32wnet(void)
! #endif
{
! PyObject *dict, *module;
! #if (PY_VERSION_HEX < 0x03000000)
! module = Py_InitModule("win32wnet", win32wnet_functions);
! if (!module)
! return;
! dict = PyModule_GetDict(module);
! if (!dict)
! return;
! #else
! static PyModuleDef win32wnet_def = {
! PyModuleDef_HEAD_INIT,
! "win32wnet",
! "A module that exposes the Windows Networking API.",
! -1,
! win32wnet_functions
! };
! module = PyModule_Create(&win32wnet_def);
! if (!module)
! return NULL;
! dict = PyModule_GetDict(module);
! if (!dict)
! return NULL;
! #endif
!
! PyWinGlobals_Ensure();
! Py_INCREF(PyWinExc_ApiError);
! PyDict_SetItemString(dict, "error", PyWinExc_ApiError);
!
! #if (PY_VERSION_HEX >= 0x03000000)
! if ((PyType_Ready(&PyNETRESOURCEType) == -1) ||
! (PyType_Ready(&PyNCBType) == -1))
! return NULL;
! #endif
+ PyDict_SetItemString(dict, "NETRESOURCEType", (PyObject *)&PyNETRESOURCEType);
+ PyDict_SetItemString(dict, "NCBType", (PyObject *)&PyNCBType);
+
+ #if (PY_VERSION_HEX >= 0x03000000)
+ return module;
+ #endif;
+ }
Index: PyNetresource.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32wnet/PyNetresource.cpp,v
retrieving revision 1.3
retrieving revision 1.3.4.1
diff -C2 -d -r1.3 -r1.3.4.1
*** PyNetresource.cpp 19 Apr 2006 03:15:11 -0000 1.3
--- PyNetresource.cpp 29 Aug 2008 05:00:24 -0000 1.3.4.1
***************
*** 38,42 ****
/* Main PYTHON entry point for creating a new reference. Registered by win32wnet module */
! // @pymethod <o NETRESOURCE>|win32wnet|NETRESOURCE|Creates a new <o NETRESOURCE> object.
PyObject *PyWinMethod_NewNETRESOURCE(PyObject *self, PyObject *args)
--- 38,42 ----
/* Main PYTHON entry point for creating a new reference. Registered by win32wnet module */
! // @pymethod <o PyNETRESOURCE>|win32wnet|NETRESOURCE|Creates a new <o NETRESOURCE> object.
PyObject *PyWinMethod_NewNETRESOURCE(PyObject *self, PyObject *args)
***************
*** 81,90 ****
! // @object NETRESOURCE|A Python object that encapsulates a Win32 NETRESOURCE structure.
__declspec(dllexport)
PyTypeObject PyNETRESOURCEType =
{
! PyObject_HEAD_INIT(&PyType_Type)
! 0,
"PyNETRESOURCE",
sizeof(PyNETRESOURCE),
--- 81,89 ----
! // @object PyNETRESOURCE|A Python object that encapsulates a Win32 NETRESOURCE structure.
__declspec(dllexport)
PyTypeObject PyNETRESOURCEType =
{
! PYWIN_OBJECT_HEAD
"PyNETRESOURCE",
sizeof(PyNETRESOURCE),
***************
*** 92,97 ****
PyNETRESOURCE::deallocFunc, /* tp_dealloc */
0, /* tp_print */
! PyNETRESOURCE::getattr, /* tp_getattr */
! PyNETRESOURCE::setattr, /* tp_setattr */
PyNETRESOURCE::compareFunc, /* tp_compare */
0, /* tp_repr */
--- 91,96 ----
PyNETRESOURCE::deallocFunc, /* tp_dealloc */
0, /* tp_print */
! 0, /* tp_getattr */
! 0, /* tp_setattr */
PyNETRESOURCE::compareFunc, /* tp_compare */
0, /* tp_repr */
***************
*** 102,116 ****
0, /* tp_call */
0, /* tp_str */
};
-
#define OFF(e) offsetof(PyNETRESOURCE, e)
! struct memberlist PyNETRESOURCE::memberlist[] =
{
! {"dwScope", T_LONG, OFF(m_nr.dwScope), 0}, // @prop integer|dwScope|
! {"dwType", T_LONG, OFF(m_nr.dwType), 0}, // @prop integer|dwType|
! {"dwDisplayType", T_LONG,OFF(m_nr.dwDisplayType), 0}, // @prop integer|dwDisplayType|
! {"dwUsage", T_LONG, OFF(m_nr.dwUsage), 0}, // @prop integer|dwUsage|
{"lpLocalName", T_STRING, OFF(m_nr.lpLocalName), 0}, // @prop string|localName|
{"lpRemoteName",T_STRING, OFF(m_nr.lpRemoteName), 0},// @prop string|remoteName|
--- 101,138 ----
0, /* tp_call */
0, /* tp_str */
+ PyNETRESOURCE::getattro, /* tp_getattro */
+ PyNETRESOURCE::setattro, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ PyNETRESOURCE::members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ 0, /* tp_new */
};
#define OFF(e) offsetof(PyNETRESOURCE, e)
! struct PyMemberDef PyNETRESOURCE::members[] =
{
! {"dwScope", T_ULONG, OFF(m_nr.dwScope), 0}, // @prop integer|dwScope|
! {"dwType", T_ULONG, OFF(m_nr.dwType), 0}, // @prop integer|dwType|
! {"dwDisplayType", T_ULONG,OFF(m_nr.dwDisplayType), 0}, // @prop integer|dwDisplayType|
! {"dwUsage", T_ULONG, OFF(m_nr.dwUsage), 0}, // @prop integer|dwUsage|
!
! // These are handled by getattro/setattro
{"lpLocalName", T_STRING, OFF(m_nr.lpLocalName), 0}, // @prop string|localName|
{"lpRemoteName",T_STRING, OFF(m_nr.lpRemoteName), 0},// @prop string|remoteName|
***************
*** 125,274 ****
_Py_NewReference(this);
memset(&m_nr, 0, sizeof(m_nr));
- m_nr.lpLocalName = szLName;
- m_nr.lpRemoteName = szRName;
- m_nr.lpProvider = szProv;
- m_nr.lpComment = szComment;
- szLName[0] = _T('\0');
- szRName[0] = _T('\0');
- szProv[0] = _T('\0');
- szComment[0] = _T('\0');
}
! PyNETRESOURCE::PyNETRESOURCE(const NETRESOURCE *pO)
{
ob_type = &PyNETRESOURCEType;
_Py_NewReference(this);
! m_nr.dwScope = pO->dwScope;
! m_nr.dwType = pO->dwType;
! m_nr.dwDisplayType = pO->dwDisplayType;
! m_nr.dwUsage = pO->dwUsage;
! m_nr.lpLocalName = szLName;
! m_nr.lpRemoteName = szRName;
! m_nr.lpProvider = szProv;
! m_nr.lpComment = szComment;
!
! if (pO->lpLocalName == NULL)
! szLName[0] = _T('\0');
! else
! {
! _tcsncpy(szLName, pO->lpLocalName, MAX_NAME);
! szLName[MAX_NAME-1] = _T('\0'); // explicit termination!
! }
!
!
! if (pO->lpRemoteName == NULL)
! szRName[0] = _T('\0');
! else
! {
! _tcsncpy(szRName, pO->lpRemoteName, MAX_NAME);
! szRName[MAX_NAME-1] = _T('\0'); // explicit termination!
! }
!
!
! if (pO->lpProvider == NULL)
! szProv[0] = _T('\0');
! else
! {
! _tcsncpy(szProv, pO->lpProvider, MAX_NAME);
! szProv[MAX_NAME-1] = _T('\0'); // explicit termination!
! }
!
! if (pO->lpComment == NULL)
! szComment[0] = _T('\0');
! else
! {
! _tcsncpy(szComment, pO->lpComment, MAX_COMMENT);
! szComment[MAX_COMMENT-1] = _T('\0');
! }
}
PyNETRESOURCE::~PyNETRESOURCE(void)
{
!
}
! PyObject *PyNETRESOURCE::getattr(PyObject *self, char *name)
{
! #ifdef UNICODE
PyNETRESOURCE *This = (PyNETRESOURCE *)self;
! if (strcmp(name, "lpProvider") == 0)
! return PyWinObject_FromWCHAR(This->m_nr.lpProvider);
! else if
! (strcmp(name, "lpRemoteName") == 0)
! return PyWinObject_FromWCHAR(This->m_nr.lpRemoteName);
! else if
! (strcmp(name, "lpLocalName") == 0)
! return PyWinObject_FromWCHAR(This->m_nr.lpLocalName);
! else if
! (strcmp(name, "lpComment") == 0)
! return PyWinObject_FromWCHAR(This->m_nr.lpComment);
! else
! #endif
! return PyMember_Get((char *)self, memberlist, name);
}
!
!
! int PyNETRESOURCE::setattr(PyObject *self, char *name, PyObject *v)
{
- PyNETRESOURCE *This = (PyNETRESOURCE *)self;
-
if (v == NULL) {
PyErr_SetString(PyExc_AttributeError, "can't delete NETRESOURCE attributes");
return -1;
}
! // the following specific string attributes can be set, all others generate an error.
!
! if (PyString_Check(v))
! {
! int ret;
! TCHAR *value;
! if (!PyWinObject_AsTCHAR(v, &value, FALSE))
return -1;
! if (strcmp (name, "lpProvider") == 0)
! {
! _tcsncpy(This->szProv, value, MAX_NAME); // no overflow allowed!
! This->szProv[MAX_NAME-1] = _T('\0'); // make sure NULL terminated!
! ret = 0;
! }
! else
! if (strcmp(name, "lpRemoteName") == 0)
! {
! _tcsncpy(This->szRName, value, MAX_NAME);
! This->szRName[MAX_NAME-1] = _T('\0');
! ret = 0;
}
! else
! if (strcmp(name, "lpLocalName") == 0)
! {
! _tcsncpy(This->szLName, value, MAX_NAME);
! This->szLName[MAX_NAME-1] = _T('\0');
! ret = 0;
}
! else
! if (strcmp(name, "lpComment") == 0)
! {
! _tcsncpy(This->szComment, value, MAX_COMMENT);
! This->szComment[MAX_COMMENT-1] = _T('\0');
! ret = 0;
}
! else
! {
! PyErr_SetString(PyExc_AttributeError, "The attribute is not a PyNETRESOURCE string");
! ret = -1;
}
! PyWinObject_FreeTCHAR(value);
! return ret;
! } // PyString_Check
!
! return PyMember_Set((char *)self, memberlist, name, v);
}
-
void PyNETRESOURCE::deallocFunc(PyObject *ob)
{
--- 147,241 ----
_Py_NewReference(this);
memset(&m_nr, 0, sizeof(m_nr));
}
! PyNETRESOURCE::PyNETRESOURCE(const NETRESOURCE *p_nr)
{
ob_type = &PyNETRESOURCEType;
_Py_NewReference(this);
! m_nr=*p_nr;
+ // Copy strings so they can be freed in same way as when set via setattro
+ // No error checking here, no way to return an error from a constructor anyway
+ if (p_nr->lpProvider)
+ m_nr.lpProvider=PyWin_CopyString(p_nr->lpProvider);
+ if (p_nr->lpRemoteName)
+ m_nr.lpRemoteName=PyWin_CopyString(p_nr->lpRemoteName);
+ if (p_nr->lpLocalName)
+ m_nr.lpLocalName=PyWin_CopyString(p_nr->lpLocalName);
+ if (p_nr->lpComment)
+ m_nr.lpComment=PyWin_CopyString(p_nr->lpComment);
}
PyNETRESOURCE::~PyNETRESOURCE(void)
{
! PyWinObject_FreeTCHAR(m_nr.lpProvider);
! PyWinObject_FreeTCHAR(m_nr.lpRemoteName);
! PyWinObject_FreeTCHAR(m_nr.lpLocalName);
! PyWinObject_FreeTCHAR(m_nr.lpComment);
}
! PyObject *PyNETRESOURCE::getattro(PyObject *self, PyObject *obname)
{
! char *name=PYWIN_ATTR_CONVERT(obname);
! if (name==NULL)
! return NULL;
PyNETRESOURCE *This = (PyNETRESOURCE *)self;
! if (strcmp(name, "lpProvider")==0)
! return PyWinObject_FromTCHAR(This->m_nr.lpProvider);
! if (strcmp(name, "lpRemoteName")==0)
! return PyWinObject_FromTCHAR(This->m_nr.lpRemoteName);
! if (strcmp(name, "lpLocalName")==0)
! return PyWinObject_FromTCHAR(This->m_nr.lpLocalName);
! if (strcmp(name, "lpComment")==0)
! return PyWinObject_FromTCHAR(This->m_nr.lpComment);
! return PyObject_GenericGetAttr(self, obname);
}
! int PyNETRESOURCE::setattro(PyObject *self, PyObject *obname, PyObject *v)
{
if (v == NULL) {
PyErr_SetString(PyExc_AttributeError, "can't delete NETRESOURCE attributes");
return -1;
}
+ char *name=PYWIN_ATTR_CONVERT(obname);
+ if (name==NULL)
+ return NULL;
+ PyNETRESOURCE *This = (PyNETRESOURCE *)self;
! TCHAR *value;
! if (strcmp(name, "lpProvider")==0){
! if (!PyWinObject_AsTCHAR(v, &value, TRUE))
return -1;
! PyWinObject_FreeTCHAR(This->m_nr.lpProvider);
! This->m_nr.lpProvider=value;
! return 0;
}
! if (strcmp(name, "lpRemoteName")==0){
! if (!PyWinObject_AsTCHAR(v, &value, TRUE))
! return -1;
! PyWinObject_FreeTCHAR(This->m_nr.lpRemoteName);
! This->m_nr.lpRemoteName=value;
! return 0;
}
! if (strcmp(name, "lpLocalName")==0){
! if (!PyWinObject_AsTCHAR(v, &value, TRUE))
! return -1;
! PyWinObject_FreeTCHAR(This->m_nr.lpLocalName);
! This->m_nr.lpLocalName=value;
! return 0;
}
! if (strcmp(name, "lpComment")==0){
! if (!PyWinObject_AsTCHAR(v, &value, TRUE))
! return -1;
! PyWinObject_FreeTCHAR(This->m_nr.lpComment);
! This->m_nr.lpComment=value;
! return 0;
}
! return PyObject_GenericSetAttr(self, obname, v);
}
void PyNETRESOURCE::deallocFunc(PyObject *ob)
{
***************
*** 281,299 ****
if (!PyWinObject_AsNETRESOURCE(ob, &p_nr, FALSE)) // sets error exception
! return NULL;
// do integer tests first
! if ((m_nr.dwType != p_nr->dwType) ||
! (m_nr.dwScope != p_nr->dwScope) ||
! (m_nr.dwUsage != p_nr->dwUsage) ||
! (m_nr.dwDisplayType != p_nr->dwDisplayType))
! return (0);
!
! if ((_tcscmp(szComment, GetComment())) ||
! (_tcscmp(szLName, GetLName())) ||
! (_tcscmp(szProv, GetProvider())) ||
! (_tcscmp(szRName, GetRName())))
! return 0;
! return 1;
};
--- 248,288 ----
if (!PyWinObject_AsNETRESOURCE(ob, &p_nr, FALSE)) // sets error exception
! return -1;
// do integer tests first
! if (m_nr.dwType != p_nr->dwType ||
! m_nr.dwScope != p_nr->dwScope ||
! m_nr.dwUsage != p_nr->dwUsage ||
! m_nr.dwDisplayType != p_nr->dwDisplayType)
! return 1;
! if (m_nr.lpComment && p_nr->lpComment){
! if (_tcscmp(m_nr.lpComment, p_nr->lpComment) != 0)
! return 1;
! }
! else if (m_nr.lpComment || p_nr->lpComment)
! return 1;
!
! if (m_nr.lpLocalName && p_nr->lpLocalName){
! if (_tcscmp(m_nr.lpLocalName, p_nr->lpLocalName) != 0)
! return 1;
! }
! else if (m_nr.lpLocalName || p_nr->lpLocalName)
! return 1;
!
! if (m_nr.lpProvider && p_nr->lpProvider){
! if (_tcscmp(m_nr.lpProvider, p_nr->lpProvider) != 0)
! return 1;
! }
! else if (m_nr.lpProvider || p_nr->lpProvider)
! return 1;
!
! if (m_nr.lpRemoteName && p_nr->lpRemoteName){
! if (_tcscmp(m_nr.lpRemoteName, p_nr->lpRemoteName) != 0)
! return 1;
! }
! else if (m_nr.lpRemoteName || p_nr->lpRemoteName)
! return 1;
!
! return 0;
};
Index: PyNCB.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32wnet/PyNCB.h,v
retrieving revision 1.2
retrieving revision 1.2.4.1
diff -C2 -d -r1.2 -r1.2.4.1
*** PyNCB.h 28 Mar 2000 11:34:29 -0000 1.2
--- PyNCB.h 29 Aug 2008 05:00:24 -0000 1.2.4.1
***************
*** 33,45 ****
static void deallocFunc(PyObject *ob);
! static PyObject *getattr(PyObject *self, char *name);
! static int setattr(PyObject *self, char *name, PyObject *v);
!
!
! #pragma warning( disable : 4251 )
! static struct memberlist memberlist[];
! #pragma warning( default : 4251 )
-
NCB m_ncb;
DWORD dwStatus; // status of this object (used during copy construct)
--- 33,41 ----
static void deallocFunc(PyObject *ob);
! static PyObject *getattro(PyObject *self, PyObject *obname);
! static int setattro(PyObject *self, PyObject *obname, PyObject *v);
! static struct PyMemberDef members[];
! static struct PyMethodDef methods[];
NCB m_ncb;
DWORD dwStatus; // status of this object (used during copy construct)
Index: PyNCB.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32wnet/PyNCB.cpp,v
retrieving revision 1.4
retrieving revision 1.4.4.1
diff -C2 -d -r1.4 -r1.4.4.1
*** PyNCB.cpp 21 Oct 2005 06:14:04 -0000 1.4
--- PyNCB.cpp 29 Aug 2008 05:00:24 -0000 1.4.4.1
***************
*** 30,34 ****
#endif
!
#include <windows.h>
#include "python.h"
--- 30,34 ----
#endif
! #include "Pywintypes.h"
#include <windows.h>
#include "python.h"
***************
*** 40,60 ****
__declspec(dllexport)PyTypeObject PyNCBType =
{
! PyObject_HEAD_INIT(&PyType_Type)
! 0,
"PyNCB",
sizeof(PyNCB),
0,
! PyNCB::deallocFunc, /* tp_dealloc */
! 0, /* tp_print */
! PyNCB::getattr, /* tp_getattr */
! PyNCB::setattr, /* tp_setattr */
! // PyNCB::compareFunc, /* tp_compare */
! 0, /* tp_repr */
! 0, /* tp_as_number */
! 0, /* tp_as_sequence */
! 0, /* tp_as_mapping */
! 0, /* hash? */
! 0, /* tp_call */
! 0, /* tp_str */
};
--- 40,81 ----
__declspec(dllexport)PyTypeObject PyNCBType =
{
! PYWIN_OBJECT_HEAD
"PyNCB",
sizeof(PyNCB),
0,
! PyNCB::deallocFunc, /* tp_dealloc */
! 0, /* tp_print */
! 0, /* tp_getattr */
! 0, /* tp_setattr */
! 0, /* tp_compare */
! 0, /* tp_repr */
! 0, /* tp_as_number */
! 0, /* tp_as_sequence */
! 0, /* tp_as_mapping */
! 0, /* tp_hash */
! 0, /* tp_call */
! 0, /* tp_str */
! PyNCB::getattro, /* tp_getattro */
! PyNCB::setattro, /* tp_setattro */
! 0, /* tp_as_buffer */
! Py_TPFLAGS_DEFAULT, /* tp_flags */
! 0, /* tp_doc */
! 0, /* tp_traverse */
! 0, /* tp_clear */
! 0, /* tp_richcompare */
! 0, /* tp_weaklistoffset */
! 0, /* tp_iter */
! 0, /* tp_iternext */
! PyNCB::methods, /* tp_methods */
! PyNCB::members, /* tp_members */
! 0, /* tp_getset */
! 0, /* tp_base */
! 0, /* tp_dict */
! 0, /* tp_descr_get */
! 0, /* tp_descr_set */
! 0, /* tp_dictoffset */
! 0, /* tp_init */
! 0, /* tp_alloc */
! 0, /* tp_new */
};
***************
*** 69,73 ****
}
! static struct PyMethodDef PyUnicode_methods[] = {
{ "Reset", PyNCB_Reset, METH_VARARGS },
{ NULL },
--- 90,94 ----
}
! struct PyMethodDef PyNCB::methods[] = {
{ "Reset", PyNCB_Reset, METH_VARARGS },
{ NULL },
***************
*** 76,80 ****
// @object NCB|A Python object that encapsulates a Win32 NCB structure.
#define OFF(e) offsetof(PyNCB, e)
! struct memberlist PyNCB::memberlist[] =
{
{"Command", T_UBYTE, OFF(m_ncb.ncb_command), 0}, // @prop int|Command|
--- 97,101 ----
// @object NCB|A Python object that encapsulates a Win32 NCB structure.
#define OFF(e) offsetof(PyNCB, e)
! struct PyMemberDef PyNCB::members[] =
{
{"Command", T_UBYTE, OFF(m_ncb.ncb_command), 0}, // @prop int|Command|
***************
*** 184,191 ****
/********************************************...
[truncated message content] |