00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "python/py_spoolss.h"
00022 #include "python/py_conv.h"
00023
00024 static BOOL py_from_printerdata(PyObject **dict, char *key, char *value,
00025 uint16 data_type, uint8 *data,
00026 uint32 data_size)
00027 {
00028 *dict = PyDict_New();
00029
00030 PyDict_SetItemString(*dict, "key", Py_BuildValue("s", key ? key : ""));
00031 PyDict_SetItemString(*dict, "value", Py_BuildValue("s", value));
00032 PyDict_SetItemString(*dict, "type", Py_BuildValue("i", data_type));
00033
00034 PyDict_SetItemString(*dict, "data",
00035 Py_BuildValue("s#", data, data_size));
00036
00037 return True;
00038 }
00039
00040 static BOOL py_to_printerdata(char **key, char **value, uint16 *data_type,
00041 uint8 **data, uint32 *data_size,
00042 PyObject *dict)
00043 {
00044 PyObject *obj;
00045
00046 if ((obj = PyDict_GetItemString(dict, "key"))) {
00047
00048 if (!PyString_Check(obj)) {
00049 PyErr_SetString(spoolss_error,
00050 "key not a string");
00051 return False;
00052 }
00053
00054 if (key) {
00055 *key = PyString_AsString(obj);
00056
00057 if (!key[0])
00058 *key = NULL;
00059 }
00060 } else
00061 *key = NULL;
00062
00063 if ((obj = PyDict_GetItemString(dict, "value"))) {
00064
00065 if (!PyString_Check(obj)) {
00066 PyErr_SetString(spoolss_error,
00067 "value not a string");
00068 return False;
00069 }
00070
00071 *value = PyString_AsString(obj);
00072 } else {
00073 PyErr_SetString(spoolss_error, "no value present");
00074 return False;
00075 }
00076
00077 if ((obj = PyDict_GetItemString(dict, "type"))) {
00078
00079 if (!PyInt_Check(obj)) {
00080 PyErr_SetString(spoolss_error,
00081 "type not an integer");
00082 return False;
00083 }
00084
00085 *data_type = PyInt_AsLong(obj);
00086 } else {
00087 PyErr_SetString(spoolss_error, "no type present");
00088 return False;
00089 }
00090
00091 if ((obj = PyDict_GetItemString(dict, "data"))) {
00092
00093 if (!PyString_Check(obj)) {
00094 PyErr_SetString(spoolss_error,
00095 "data not a string");
00096 return False;
00097 }
00098
00099 *data = PyString_AsString(obj);
00100 *data_size = PyString_Size(obj);
00101 } else {
00102 PyErr_SetString(spoolss_error, "no data present");
00103 return False;
00104 }
00105
00106 return True;
00107 }
00108
00109 PyObject *spoolss_hnd_getprinterdata(PyObject *self, PyObject *args, PyObject *kw)
00110 {
00111 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
00112 static char *kwlist[] = { "value", NULL };
00113 char *valuename;
00114 WERROR werror;
00115 PyObject *result;
00116 REGISTRY_VALUE value;
00117
00118
00119
00120 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &valuename))
00121 return NULL;
00122
00123
00124
00125 werror = rpccli_spoolss_getprinterdata(
00126 hnd->cli, hnd->mem_ctx, &hnd->pol, valuename,
00127 &value);
00128
00129 if (!W_ERROR_IS_OK(werror)) {
00130 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
00131 return NULL;
00132 }
00133
00134 py_from_printerdata(
00135 &result, NULL, valuename, value.type, value.data_p,
00136 value.size);
00137
00138 return result;
00139 }
00140
00141 PyObject *spoolss_hnd_setprinterdata(PyObject *self, PyObject *args, PyObject *kw)
00142 {
00143 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
00144 static char *kwlist[] = { "data", NULL };
00145 PyObject *py_data;
00146 char *valuename;
00147 WERROR werror;
00148 REGISTRY_VALUE value;
00149
00150 if (!PyArg_ParseTupleAndKeywords(
00151 args, kw, "O!", kwlist, &PyDict_Type, &py_data))
00152 return NULL;
00153
00154 if (!py_to_printerdata(
00155 NULL, &valuename, &value.type, &value.data_p,
00156 &value.size, py_data))
00157 return NULL;
00158
00159 fstrcpy(value.valuename, valuename);
00160
00161
00162
00163 werror = rpccli_spoolss_setprinterdata(
00164 hnd->cli, hnd->mem_ctx, &hnd->pol, &value);
00165
00166 if (!W_ERROR_IS_OK(werror)) {
00167 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
00168 return NULL;
00169 }
00170
00171 Py_INCREF(Py_None);
00172 return Py_None;
00173 }
00174
00175 PyObject *spoolss_hnd_enumprinterdata(PyObject *self, PyObject *args, PyObject *kw)
00176 {
00177 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
00178 static char *kwlist[] = { NULL };
00179 uint32 data_needed, value_needed, ndx = 0;
00180 WERROR werror;
00181 PyObject *result;
00182 REGISTRY_VALUE value;
00183
00184 if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist))
00185 return NULL;
00186
00187
00188
00189 werror = rpccli_spoolss_enumprinterdata(
00190 hnd->cli, hnd->mem_ctx, &hnd->pol, ndx, 0, 0,
00191 &value_needed, &data_needed, NULL);
00192
00193 if (!W_ERROR_IS_OK(werror)) {
00194 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
00195 return NULL;
00196 }
00197
00198
00199
00200 result = PyDict_New();
00201
00202 while (W_ERROR_IS_OK(werror)) {
00203 PyObject *obj;
00204
00205 werror = rpccli_spoolss_enumprinterdata(
00206 hnd->cli, hnd->mem_ctx, &hnd->pol, ndx,
00207 value_needed, data_needed, NULL, NULL, &value);
00208
00209 if (py_from_printerdata(
00210 &obj, NULL, value.valuename, value.type,
00211 value.data_p, value.size))
00212 PyDict_SetItemString(result, value.valuename, obj);
00213
00214 ndx++;
00215 }
00216
00217 return result;
00218 }
00219
00220 PyObject *spoolss_hnd_deleteprinterdata(PyObject *self, PyObject *args, PyObject *kw)
00221 {
00222 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
00223 static char *kwlist[] = { "value", NULL };
00224 char *value;
00225 WERROR werror;
00226
00227
00228
00229 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &value))
00230 return NULL;
00231
00232
00233
00234 werror = rpccli_spoolss_deleteprinterdata(
00235 hnd->cli, hnd->mem_ctx, &hnd->pol, value);
00236
00237 if (!W_ERROR_IS_OK(werror)) {
00238 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
00239 return NULL;
00240 }
00241
00242 Py_INCREF(Py_None);
00243 return Py_None;
00244 }
00245
00246 PyObject *spoolss_hnd_getprinterdataex(PyObject *self, PyObject *args, PyObject *kw)
00247 {
00248 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
00249 static char *kwlist[] = { "key", "value", NULL };
00250 char *key, *valuename;
00251 WERROR werror;
00252 PyObject *result;
00253 REGISTRY_VALUE value;
00254
00255
00256
00257 if (!PyArg_ParseTupleAndKeywords(args, kw, "ss", kwlist, &key, &valuename))
00258 return NULL;
00259
00260
00261
00262 werror = rpccli_spoolss_getprinterdataex(
00263 hnd->cli, hnd->mem_ctx, &hnd->pol, key,
00264 valuename, &value);
00265
00266 if (!W_ERROR_IS_OK(werror)) {
00267 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
00268 return NULL;
00269 }
00270
00271 py_from_printerdata(
00272 &result, key, valuename, value.type, value.data_p, value.size);
00273
00274 return result;
00275 }
00276
00277 PyObject *spoolss_hnd_setprinterdataex(PyObject *self, PyObject *args, PyObject *kw)
00278 {
00279 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
00280 static char *kwlist[] = { "data", NULL };
00281 PyObject *py_data;
00282 char *keyname, *valuename;
00283 WERROR werror;
00284 REGISTRY_VALUE value;
00285
00286 if (!PyArg_ParseTupleAndKeywords(
00287 args, kw, "O!", kwlist, &PyDict_Type, &py_data))
00288 return NULL;
00289
00290 if (!py_to_printerdata(
00291 &keyname, &valuename, &value.type, &value.data_p, &value.size, py_data))
00292 return NULL;
00293
00294 fstrcpy(value.valuename, valuename);
00295
00296
00297
00298 werror = rpccli_spoolss_setprinterdataex(
00299 hnd->cli, hnd->mem_ctx, &hnd->pol, keyname, &value);
00300
00301 if (!W_ERROR_IS_OK(werror)) {
00302 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
00303 return NULL;
00304 }
00305
00306 Py_INCREF(Py_None);
00307 return Py_None;
00308 }
00309
00310 PyObject *spoolss_hnd_enumprinterdataex(PyObject *self, PyObject *args, PyObject *kw)
00311 {
00312 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
00313 static char *kwlist[] = { "key", NULL };
00314 uint32 i;
00315 char *key;
00316 WERROR werror;
00317 PyObject *result;
00318 REGVAL_CTR *ctr;
00319
00320 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &key))
00321 return NULL;
00322
00323 if (!(ctr = TALLOC_ZERO_P(hnd->mem_ctx, REGVAL_CTR))) {
00324 PyErr_SetString(spoolss_error, "talloc failed");
00325 return NULL;
00326 }
00327
00328
00329
00330 werror = rpccli_spoolss_enumprinterdataex(
00331 hnd->cli, hnd->mem_ctx, &hnd->pol, key, &ctr);
00332
00333 if (!W_ERROR_IS_OK(werror)) {
00334 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
00335 return NULL;
00336 }
00337
00338
00339
00340 result = PyDict_New();
00341
00342 for (i = 0; i < regval_ctr_numvals(&ctr); i++) {
00343 REGISTRY_VALUE *value;
00344 PyObject *item;
00345
00346 item = PyDict_New();
00347 value = regval_ctr_specific_value(&ctr, i);
00348
00349 if (py_from_printerdata(
00350 &item, key, value->valuename, value->type,
00351 value->data_p, value->size))
00352 PyDict_SetItemString(result, value->valuename, item);
00353 }
00354
00355 return result;
00356 }
00357
00358 PyObject *spoolss_hnd_deleteprinterdataex(PyObject *self, PyObject *args, PyObject *kw)
00359 {
00360 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
00361 static char *kwlist[] = { "key", "value", NULL };
00362 char *key, *value;
00363 WERROR werror;
00364
00365
00366
00367 if (!PyArg_ParseTupleAndKeywords(args, kw, "ss", kwlist, &key, &value))
00368 return NULL;
00369
00370
00371
00372 werror = rpccli_spoolss_deleteprinterdataex(
00373 hnd->cli, hnd->mem_ctx, &hnd->pol, key, value);
00374
00375 if (!W_ERROR_IS_OK(werror)) {
00376 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
00377 return NULL;
00378 }
00379
00380 Py_INCREF(Py_None);
00381 return Py_None;
00382 }
00383
00384 PyObject *spoolss_hnd_enumprinterkey(PyObject *self, PyObject *args,
00385 PyObject *kw)
00386 {
00387 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
00388 static char *kwlist[] = { "key", NULL };
00389 char *keyname;
00390 WERROR werror;
00391 uint32 keylist_len;
00392 uint16 *keylist;
00393 PyObject *result;
00394
00395
00396
00397 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &keyname))
00398 return NULL;
00399
00400
00401
00402 werror = rpccli_spoolss_enumprinterkey(
00403 hnd->cli, hnd->mem_ctx, &hnd->pol, keyname, &keylist,
00404 &keylist_len);
00405
00406 if (!W_ERROR_IS_OK(werror)) {
00407 PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
00408 return NULL;
00409 }
00410
00411 result = from_unistr_list(keylist);
00412
00413 return result;
00414 }
00415
00416 #if 0
00417
00418 PyObject *spoolss_hnd_deleteprinterkey(PyObject *self, PyObject *args,
00419 PyObject *kw)
00420 {
00421 spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
00422 static char *kwlist[] = { "key", NULL };
00423 char *keyname;
00424 WERROR werror;
00425
00426 if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &keyname))
00427 return NULL;
00428
00429 Py_INCREF(Py_None);
00430 return Py_None;
00431 }
00432
00433 #endif