2002-03-20 06:29:03 +03:00
/*
Python wrappers for DCERPC / SMB client routines .
Copyright ( C ) Tim Potter , 2002
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
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2002-03-20 06:29:03 +03:00
( 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
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2002-03-20 06:29:03 +03:00
*/
2002-03-28 07:14:43 +03:00
# include "python/py_spoolss.h"
2002-03-20 06:29:03 +03:00
/* Add a form */
2002-05-15 10:22:53 +04:00
PyObject * spoolss_hnd_addform ( PyObject * self , PyObject * args , PyObject * kw )
2002-03-20 06:29:03 +03:00
{
2002-03-26 09:25:47 +03:00
spoolss_policy_hnd_object * hnd = ( spoolss_policy_hnd_object * ) self ;
2002-03-20 06:29:03 +03:00
WERROR werror ;
2002-05-17 06:32:02 +04:00
PyObject * info ;
2002-03-20 06:29:03 +03:00
FORM form ;
2002-05-17 06:32:02 +04:00
int level ;
static char * kwlist [ ] = { " form " , NULL } ;
2002-03-20 06:29:03 +03:00
/* Parse parameters */
2002-05-17 06:32:02 +04:00
2002-03-20 06:29:03 +03:00
if ( ! PyArg_ParseTupleAndKeywords (
2002-05-17 06:32:02 +04:00
args , kw , " O! " , kwlist , & PyDict_Type , & info ) )
2002-03-20 06:29:03 +03:00
return NULL ;
/* Call rpc function */
2002-05-17 06:32:02 +04:00
if ( ! py_to_FORM ( & form , info ) ) {
2002-04-09 08:23:52 +04:00
PyErr_SetString ( spoolss_error , " invalid form " ) ;
return NULL ;
}
2002-03-20 06:29:03 +03:00
2002-05-17 06:32:02 +04:00
if ( ! get_level_value ( info , & level ) ) {
PyErr_SetString ( spoolss_error , " invalid info level " ) ;
return NULL ;
}
if ( level ! = 1 ) {
PyErr_SetString ( spoolss_error , " unsupported info level " ) ;
return NULL ;
}
2002-04-09 08:23:52 +04:00
switch ( level ) {
2002-05-17 06:32:02 +04:00
case 1 : {
PyObject * obj = PyDict_GetItemString ( info , " name " ) ;
char * form_name = PyString_AsString ( obj ) ;
2003-09-26 01:26:16 +04:00
init_unistr2 ( & form . name , form_name , UNI_STR_TERMINATE ) ;
2002-03-20 06:29:03 +03:00
break ;
2002-05-17 06:32:02 +04:00
}
2002-03-20 06:29:03 +03:00
default :
PyErr_SetString ( spoolss_error , " unsupported info level " ) ;
return NULL ;
}
2002-05-17 06:32:02 +04:00
2005-10-07 08:54:41 +04:00
werror = rpccli_spoolss_addform ( hnd - > cli , hnd - > mem_ctx , & hnd - > pol ,
level , & form ) ;
2002-03-20 06:29:03 +03:00
if ( ! W_ERROR_IS_OK ( werror ) ) {
2002-04-05 09:48:01 +04:00
PyErr_SetObject ( spoolss_werror , py_werror_tuple ( werror ) ) ;
2002-03-20 06:29:03 +03:00
return NULL ;
}
Py_INCREF ( Py_None ) ;
return Py_None ;
}
/* Get form properties */
2002-05-15 10:22:53 +04:00
PyObject * spoolss_hnd_getform ( PyObject * self , PyObject * args , PyObject * kw )
2002-03-20 06:29:03 +03:00
{
2002-03-26 09:25:47 +03:00
spoolss_policy_hnd_object * hnd = ( spoolss_policy_hnd_object * ) self ;
2002-03-20 06:29:03 +03:00
WERROR werror ;
PyObject * result ;
char * form_name ;
int level = 1 ;
2002-03-26 09:25:47 +03:00
static char * kwlist [ ] = { " form_name " , " level " , NULL } ;
2002-03-20 06:29:03 +03:00
FORM_1 form ;
/* Parse parameters */
2002-05-16 08:00:31 +04:00
if ( ! PyArg_ParseTupleAndKeywords (
args , kw , " s|i " , kwlist , & form_name , & level ) )
2002-03-20 06:29:03 +03:00
return NULL ;
/* Call rpc function */
2005-10-07 08:54:41 +04:00
werror = rpccli_spoolss_getform (
hnd - > cli , hnd - > mem_ctx , & hnd - > pol , form_name , level , & form ) ;
2002-03-20 06:29:03 +03:00
if ( ! W_ERROR_IS_OK ( werror ) ) {
2002-04-05 09:48:01 +04:00
PyErr_SetObject ( spoolss_werror , py_werror_tuple ( werror ) ) ;
2002-03-20 06:29:03 +03:00
return NULL ;
}
result = Py_None ;
switch ( level ) {
case 1 :
2002-04-05 09:48:01 +04:00
py_from_FORM_1 ( & result , & form ) ;
2002-03-20 06:29:03 +03:00
break ;
}
Py_INCREF ( result ) ;
return result ;
}
/* Set form properties */
2002-05-15 10:22:53 +04:00
PyObject * spoolss_hnd_setform ( PyObject * self , PyObject * args , PyObject * kw )
2002-03-20 06:29:03 +03:00
{
2002-03-26 09:25:47 +03:00
spoolss_policy_hnd_object * hnd = ( spoolss_policy_hnd_object * ) self ;
2002-03-20 06:29:03 +03:00
WERROR werror ;
2002-05-17 06:32:02 +04:00
PyObject * info , * form_name ;
int level ;
static char * kwlist [ ] = { " form " , NULL } ;
2002-03-20 06:29:03 +03:00
FORM form ;
/* Parse parameters */
2002-05-16 08:00:31 +04:00
if ( ! PyArg_ParseTupleAndKeywords (
2002-05-27 10:28:18 +04:00
args , kw , " O! " , kwlist , & PyDict_Type , & info ) )
2002-03-20 06:29:03 +03:00
return NULL ;
2002-05-17 06:32:02 +04:00
if ( ! get_level_value ( info , & level ) ) {
PyErr_SetString ( spoolss_error , " invalid info level " ) ;
return NULL ;
}
if ( level ! = 1 ) {
PyErr_SetString ( spoolss_error , " unsupported info level " ) ;
return NULL ;
}
2002-03-20 06:29:03 +03:00
/* Call rpc function */
2002-05-17 06:32:02 +04:00
if ( ! py_to_FORM ( & form , info ) ) {
2002-04-05 09:48:01 +04:00
PyErr_SetString ( spoolss_error , " invalid form " ) ;
return NULL ;
}
2002-05-17 06:32:02 +04:00
form_name = PyDict_GetItemString ( info , " name " ) ;
2002-03-20 06:29:03 +03:00
2005-10-07 08:54:41 +04:00
werror = rpccli_spoolss_setform (
2002-05-17 06:32:02 +04:00
hnd - > cli , hnd - > mem_ctx , & hnd - > pol , level ,
PyString_AsString ( form_name ) , & form ) ;
2002-03-20 06:29:03 +03:00
if ( ! W_ERROR_IS_OK ( werror ) ) {
2002-04-05 09:48:01 +04:00
PyErr_SetObject ( spoolss_werror , py_werror_tuple ( werror ) ) ;
2002-03-20 06:29:03 +03:00
return NULL ;
}
Py_INCREF ( Py_None ) ;
return Py_None ;
}
/* Delete a form */
2002-05-15 10:22:53 +04:00
PyObject * spoolss_hnd_deleteform ( PyObject * self , PyObject * args , PyObject * kw )
2002-03-20 06:29:03 +03:00
{
2002-03-26 09:25:47 +03:00
spoolss_policy_hnd_object * hnd = ( spoolss_policy_hnd_object * ) self ;
2002-03-20 06:29:03 +03:00
WERROR werror ;
2002-05-17 06:32:02 +04:00
static char * kwlist [ ] = { " form_name " , NULL } ;
2002-03-20 06:29:03 +03:00
char * form_name ;
/* Parse parameters */
if ( ! PyArg_ParseTupleAndKeywords (
2002-05-06 08:52:45 +04:00
args , kw , " s " , kwlist , & form_name ) )
2002-03-20 06:29:03 +03:00
return NULL ;
/* Call rpc function */
2005-10-07 08:54:41 +04:00
werror = rpccli_spoolss_deleteform (
2002-03-20 06:29:03 +03:00
hnd - > cli , hnd - > mem_ctx , & hnd - > pol , form_name ) ;
if ( ! W_ERROR_IS_OK ( werror ) ) {
2002-04-05 09:48:01 +04:00
PyErr_SetObject ( spoolss_werror , py_werror_tuple ( werror ) ) ;
2002-03-20 06:29:03 +03:00
return NULL ;
}
Py_INCREF ( Py_None ) ;
return Py_None ;
}
/* Enumerate forms */
2002-05-15 10:22:53 +04:00
PyObject * spoolss_hnd_enumforms ( PyObject * self , PyObject * args , PyObject * kw )
2002-03-20 06:29:03 +03:00
{
2002-03-26 09:25:47 +03:00
PyObject * result ;
spoolss_policy_hnd_object * hnd = ( spoolss_policy_hnd_object * ) self ;
2002-03-20 06:29:03 +03:00
WERROR werror ;
2005-07-20 19:35:29 +04:00
uint32 level = 1 , num_forms , i ;
2002-03-26 09:25:47 +03:00
static char * kwlist [ ] = { " level " , NULL } ;
2002-03-20 06:29:03 +03:00
FORM_1 * forms ;
/* Parse parameters */
if ( ! PyArg_ParseTupleAndKeywords (
2002-03-26 09:25:47 +03:00
args , kw , " |i " , kwlist , & level ) )
2002-03-20 06:29:03 +03:00
return NULL ;
/* Call rpc function */
2005-10-07 08:54:41 +04:00
werror = rpccli_spoolss_enumforms (
hnd - > cli , hnd - > mem_ctx , & hnd - > pol , level , & num_forms , & forms ) ;
2002-03-20 06:29:03 +03:00
if ( ! W_ERROR_IS_OK ( werror ) ) {
2002-04-05 09:48:01 +04:00
PyErr_SetObject ( spoolss_werror , py_werror_tuple ( werror ) ) ;
2002-03-20 06:29:03 +03:00
return NULL ;
}
2002-05-16 11:32:55 +04:00
switch ( level ) {
case 1 :
result = PyDict_New ( ) ;
for ( i = 0 ; i < num_forms ; i + + ) {
PyObject * value ;
fstring name ;
rpcstr_pull ( name , forms [ i ] . name . buffer ,
sizeof ( fstring ) , - 1 , STR_TERMINATE ) ;
2002-03-20 06:29:03 +03:00
2002-05-16 11:32:55 +04:00
py_from_FORM_1 ( & value , & forms [ i ] ) ;
2002-03-20 06:29:03 +03:00
2002-05-16 11:32:55 +04:00
PyDict_SetItemString (
value , " level " , PyInt_FromLong ( 1 ) ) ;
PyDict_SetItemString ( result , name , value ) ;
2002-03-20 06:29:03 +03:00
}
2002-05-16 11:32:55 +04:00
break ;
default :
PyErr_SetString ( spoolss_error , " unknown info level " ) ;
return NULL ;
2002-03-20 06:29:03 +03:00
}
return result ;
}