2008-09-19 02:27:40 +02:00
/*
Unix SMB / CIFS implementation .
Python bindings for COM library .
Copyright ( C ) Jelmer Vernooij < jelmer @ samba . org > 2008
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2009-01-08 12:20:20 +01:00
# include <Python.h>
2009-10-23 16:23:01 +11:00
# include "includes.h"
2008-09-19 02:27:40 +02:00
# include "lib/com/com.h"
2008-09-19 02:39:03 +02:00
# include "librpc/ndr/libndr.h"
# include "libcli/util/pyerrors.h"
2011-03-19 00:45:36 +01:00
void initcom ( void ) ;
2008-09-19 02:39:03 +02:00
static struct com_context * py_com_ctx = NULL ; /* FIXME: evil global */
2008-09-19 02:27:40 +02:00
static PyObject * py_get_class_object ( PyObject * self , PyObject * args )
{
char * s_clsid , * s_iid ;
struct GUID clsid , iid ;
struct IUnknown * object ;
2008-09-19 02:39:03 +02:00
NTSTATUS status ;
WERROR error ;
2008-09-19 02:27:40 +02:00
if ( ! PyArg_ParseTuple ( args , " ss " , & s_clsid , & s_iid ) )
return NULL ;
status = GUID_from_string ( s_clsid , & clsid ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
PyErr_FromNTSTATUS ( status ) ;
return NULL ;
}
status = GUID_from_string ( s_iid , & iid ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
PyErr_FromNTSTATUS ( status ) ;
return NULL ;
}
2008-09-19 02:39:03 +02:00
error = com_get_class_object ( py_com_ctx , & clsid , & iid , & object ) ;
2008-09-19 02:27:40 +02:00
if ( ! W_ERROR_IS_OK ( error ) ) {
PyErr_FromWERROR ( error ) ;
return NULL ;
}
/* FIXME: Magic, integrate with stubs generated by pidl. */
2009-01-06 04:13:57 +01:00
Py_RETURN_NONE ;
2008-09-19 02:27:40 +02:00
}
static struct PyMethodDef com_methods [ ] = {
{ " get_class_object " , ( PyCFunction ) py_get_class_object , METH_VARARGS , " S.get_class_object(clsid, iid) -> instance " } ,
{ NULL } ,
} ;
void initcom ( void )
{
PyObject * m ;
2008-09-19 02:39:03 +02:00
WERROR error ;
2008-09-19 02:27:40 +02:00
2008-09-19 02:39:03 +02:00
error = com_init_ctx ( & py_com_ctx , NULL ) ;
if ( ! W_ERROR_IS_OK ( error ) ) {
PyErr_FromWERROR ( error ) ;
return ;
}
2008-09-19 02:27:40 +02:00
m = Py_InitModule3 ( " com " , com_methods , " Simple COM implementation " ) ;
if ( m = = NULL )
return ;
}