Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1 | /* Helper library for MSI creation with Python. |
Florent Xicluna | c934f32 | 2010-09-03 23:47:32 +0000 | [diff] [blame] | 2 | * Copyright (C) 2005 Martin v. Löwis |
Martin v. Löwis | dd860ca | 2006-03-05 13:39:10 +0000 | [diff] [blame] | 3 | * Licensed to PSF under a contributor agreement. |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <Python.h> |
| 7 | #include <fci.h> |
| 8 | #include <fcntl.h> |
| 9 | #include <windows.h> |
| 10 | #include <msi.h> |
| 11 | #include <msiquery.h> |
| 12 | #include <msidefs.h> |
| 13 | #include <rpc.h> |
| 14 | |
| 15 | static PyObject *MSIError; |
| 16 | |
| 17 | static PyObject* |
| 18 | uuidcreate(PyObject* obj, PyObject*args) |
| 19 | { |
| 20 | UUID result; |
Victor Stinner | 9d3b93b | 2011-11-22 02:27:30 +0100 | [diff] [blame] | 21 | wchar_t *cresult; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 22 | PyObject *oresult; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 23 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 24 | /* May return ok, local only, and no address. |
| 25 | For local only, the documentation says we still get a uuid. |
| 26 | For RPC_S_UUID_NO_ADDRESS, it's not clear whether we can |
| 27 | use the result. */ |
| 28 | if (UuidCreate(&result) == RPC_S_UUID_NO_ADDRESS) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 29 | PyErr_SetString(PyExc_NotImplementedError, "processing 'no address' result"); |
| 30 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 33 | if (UuidToStringW(&result, &cresult) == RPC_S_OUT_OF_MEMORY) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 34 | PyErr_SetString(PyExc_MemoryError, "out of memory in uuidgen"); |
| 35 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Victor Stinner | 9d3b93b | 2011-11-22 02:27:30 +0100 | [diff] [blame] | 38 | oresult = PyUnicode_FromWideChar(cresult, wcslen(cresult)); |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 39 | RpcStringFreeW(&cresult); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 40 | return oresult; |
| 41 | |
| 42 | } |
| 43 | |
| 44 | /* FCI callback functions */ |
| 45 | |
| 46 | static FNFCIALLOC(cb_alloc) |
| 47 | { |
| 48 | return malloc(cb); |
| 49 | } |
| 50 | |
| 51 | static FNFCIFREE(cb_free) |
| 52 | { |
| 53 | free(memory); |
| 54 | } |
| 55 | |
| 56 | static FNFCIOPEN(cb_open) |
| 57 | { |
| 58 | int result = _open(pszFile, oflag, pmode); |
| 59 | if (result == -1) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 60 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 61 | return result; |
| 62 | } |
| 63 | |
| 64 | static FNFCIREAD(cb_read) |
| 65 | { |
| 66 | UINT result = (UINT)_read(hf, memory, cb); |
| 67 | if (result != cb) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 68 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 69 | return result; |
| 70 | } |
| 71 | |
| 72 | static FNFCIWRITE(cb_write) |
| 73 | { |
| 74 | UINT result = (UINT)_write(hf, memory, cb); |
| 75 | if (result != cb) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 76 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 77 | return result; |
| 78 | } |
| 79 | |
| 80 | static FNFCICLOSE(cb_close) |
| 81 | { |
| 82 | int result = _close(hf); |
| 83 | if (result != 0) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 84 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 85 | return result; |
| 86 | } |
| 87 | |
| 88 | static FNFCISEEK(cb_seek) |
| 89 | { |
| 90 | long result = (long)_lseek(hf, dist, seektype); |
| 91 | if (result == -1) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 92 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 93 | return result; |
| 94 | } |
| 95 | |
| 96 | static FNFCIDELETE(cb_delete) |
| 97 | { |
| 98 | int result = remove(pszFile); |
| 99 | if (result != 0) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 100 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 101 | return result; |
| 102 | } |
| 103 | |
| 104 | static FNFCIFILEPLACED(cb_fileplaced) |
| 105 | { |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static FNFCIGETTEMPFILE(cb_gettempfile) |
| 110 | { |
| 111 | char *name = _tempnam("", "tmp"); |
| 112 | if ((name != NULL) && ((int)strlen(name) < cbTempName)) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 113 | strcpy(pszTempName, name); |
| 114 | free(name); |
| 115 | return TRUE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | if (name) free(name); |
| 119 | return FALSE; |
| 120 | } |
| 121 | |
| 122 | static FNFCISTATUS(cb_status) |
| 123 | { |
| 124 | if (pv) { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 125 | _Py_IDENTIFIER(status); |
Martin v. Löwis | afe55bb | 2011-10-09 10:38:36 +0200 | [diff] [blame] | 126 | |
| 127 | PyObject *result = _PyObject_CallMethodId(pv, &PyId_status, "iii", typeStatus, cb1, cb2); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 128 | if (result == NULL) |
| 129 | return -1; |
| 130 | Py_DECREF(result); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 131 | } |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | static FNFCIGETNEXTCABINET(cb_getnextcabinet) |
| 136 | { |
| 137 | if (pv) { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 138 | _Py_IDENTIFIER(getnextcabinet); |
Martin v. Löwis | afe55bb | 2011-10-09 10:38:36 +0200 | [diff] [blame] | 139 | |
| 140 | PyObject *result = _PyObject_CallMethodId(pv, &PyId_getnextcabinet, "i", pccab->iCab); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 141 | if (result == NULL) |
| 142 | return -1; |
| 143 | if (!PyBytes_Check(result)) { |
| 144 | PyErr_Format(PyExc_TypeError, |
| 145 | "Incorrect return type %s from getnextcabinet", |
| 146 | result->ob_type->tp_name); |
| 147 | Py_DECREF(result); |
| 148 | return FALSE; |
| 149 | } |
| 150 | strncpy(pccab->szCab, PyBytes_AsString(result), sizeof(pccab->szCab)); |
| 151 | return TRUE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 152 | } |
| 153 | return FALSE; |
| 154 | } |
| 155 | |
| 156 | static FNFCIGETOPENINFO(cb_getopeninfo) |
| 157 | { |
| 158 | BY_HANDLE_FILE_INFORMATION bhfi; |
| 159 | FILETIME filetime; |
| 160 | HANDLE handle; |
| 161 | |
| 162 | /* Need Win32 handle to get time stamps */ |
| 163 | handle = CreateFile(pszName, GENERIC_READ, FILE_SHARE_READ, NULL, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 164 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 165 | if (handle == INVALID_HANDLE_VALUE) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 166 | return -1; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 167 | |
| 168 | if (GetFileInformationByHandle(handle, &bhfi) == FALSE) |
| 169 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 170 | CloseHandle(handle); |
| 171 | return -1; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | FileTimeToLocalFileTime(&bhfi.ftLastWriteTime, &filetime); |
| 175 | FileTimeToDosDateTime(&filetime, pdate, ptime); |
| 176 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 177 | *pattribs = (int)(bhfi.dwFileAttributes & |
| 178 | (_A_RDONLY | _A_SYSTEM | _A_HIDDEN | _A_ARCH)); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 179 | |
| 180 | CloseHandle(handle); |
| 181 | |
| 182 | return _open(pszName, _O_RDONLY | _O_BINARY); |
| 183 | } |
| 184 | |
| 185 | static PyObject* fcicreate(PyObject* obj, PyObject* args) |
| 186 | { |
Christian Heimes | 0bd4e11 | 2008-02-12 22:59:25 +0000 | [diff] [blame] | 187 | char *cabname, *p; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 188 | PyObject *files; |
| 189 | CCAB ccab; |
| 190 | HFCI hfci; |
| 191 | ERF erf; |
Christian Heimes | 0bd4e11 | 2008-02-12 22:59:25 +0000 | [diff] [blame] | 192 | Py_ssize_t i; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 193 | |
| 194 | |
| 195 | if (!PyArg_ParseTuple(args, "sO:FCICreate", &cabname, &files)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 196 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 197 | |
| 198 | if (!PyList_Check(files)) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 199 | PyErr_SetString(PyExc_TypeError, "FCICreate expects a list"); |
| 200 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | ccab.cb = INT_MAX; /* no need to split CAB into multiple media */ |
| 204 | ccab.cbFolderThresh = 1000000; /* flush directory after this many bytes */ |
| 205 | ccab.cbReserveCFData = 0; |
| 206 | ccab.cbReserveCFFolder = 0; |
| 207 | ccab.cbReserveCFHeader = 0; |
| 208 | |
| 209 | ccab.iCab = 1; |
| 210 | ccab.iDisk = 1; |
| 211 | |
| 212 | ccab.setID = 0; |
| 213 | ccab.szDisk[0] = '\0'; |
| 214 | |
Christian Heimes | 0bd4e11 | 2008-02-12 22:59:25 +0000 | [diff] [blame] | 215 | for (i = 0, p = cabname; *p; p = CharNext(p)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 216 | if (*p == '\\' || *p == '/') |
| 217 | i = p - cabname + 1; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 218 | |
Christian Heimes | 0bd4e11 | 2008-02-12 22:59:25 +0000 | [diff] [blame] | 219 | if (i >= sizeof(ccab.szCabPath) || |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 220 | strlen(cabname+i) >= sizeof(ccab.szCab)) { |
| 221 | PyErr_SetString(PyExc_ValueError, "path name too long"); |
| 222 | return 0; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Christian Heimes | 0bd4e11 | 2008-02-12 22:59:25 +0000 | [diff] [blame] | 225 | if (i > 0) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 226 | memcpy(ccab.szCabPath, cabname, i); |
| 227 | ccab.szCabPath[i] = '\0'; |
| 228 | strcpy(ccab.szCab, cabname+i); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 229 | } else { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 230 | strcpy(ccab.szCabPath, ".\\"); |
| 231 | strcpy(ccab.szCab, cabname); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | hfci = FCICreate(&erf, cb_fileplaced, cb_alloc, cb_free, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 235 | cb_open, cb_read, cb_write, cb_close, cb_seek, cb_delete, |
| 236 | cb_gettempfile, &ccab, NULL); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 237 | |
| 238 | if (hfci == NULL) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 239 | PyErr_Format(PyExc_ValueError, "FCI error %d", erf.erfOper); |
| 240 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | for (i=0; i < PyList_GET_SIZE(files); i++) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 244 | PyObject *item = PyList_GET_ITEM(files, i); |
| 245 | char *filename, *cabname; |
| 246 | if (!PyArg_ParseTuple(item, "ss", &filename, &cabname)) |
| 247 | goto err; |
| 248 | if (!FCIAddFile(hfci, filename, cabname, FALSE, |
| 249 | cb_getnextcabinet, cb_status, cb_getopeninfo, |
| 250 | tcompTYPE_MSZIP)) |
| 251 | goto err; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | if (!FCIFlushCabinet(hfci, FALSE, cb_getnextcabinet, cb_status)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 255 | goto err; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 256 | |
| 257 | if (!FCIDestroy(hfci)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 258 | goto err; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 259 | |
| 260 | Py_INCREF(Py_None); |
| 261 | return Py_None; |
| 262 | err: |
| 263 | PyErr_Format(PyExc_ValueError, "FCI error %d", erf.erfOper); /* XXX better error type */ |
| 264 | FCIDestroy(hfci); |
| 265 | return NULL; |
| 266 | } |
| 267 | |
| 268 | typedef struct msiobj{ |
| 269 | PyObject_HEAD |
| 270 | MSIHANDLE h; |
| 271 | }msiobj; |
| 272 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 273 | static void |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 274 | msiobj_dealloc(msiobj* msidb) |
| 275 | { |
| 276 | MsiCloseHandle(msidb->h); |
| 277 | msidb->h = 0; |
| 278 | } |
| 279 | |
| 280 | static PyObject* |
| 281 | msiobj_close(msiobj* msidb, PyObject *args) |
| 282 | { |
| 283 | MsiCloseHandle(msidb->h); |
| 284 | msidb->h = 0; |
| 285 | Py_INCREF(Py_None); |
| 286 | return Py_None; |
| 287 | } |
| 288 | |
| 289 | static PyObject* |
| 290 | msierror(int status) |
| 291 | { |
| 292 | int code; |
| 293 | char buf[2000]; |
| 294 | char *res = buf; |
| 295 | DWORD size = sizeof(buf); |
| 296 | MSIHANDLE err = MsiGetLastErrorRecord(); |
| 297 | |
| 298 | if (err == 0) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 299 | switch(status) { |
| 300 | case ERROR_ACCESS_DENIED: |
| 301 | PyErr_SetString(MSIError, "access denied"); |
| 302 | return NULL; |
| 303 | case ERROR_FUNCTION_FAILED: |
| 304 | PyErr_SetString(MSIError, "function failed"); |
| 305 | return NULL; |
| 306 | case ERROR_INVALID_DATA: |
| 307 | PyErr_SetString(MSIError, "invalid data"); |
| 308 | return NULL; |
| 309 | case ERROR_INVALID_HANDLE: |
| 310 | PyErr_SetString(MSIError, "invalid handle"); |
| 311 | return NULL; |
| 312 | case ERROR_INVALID_STATE: |
| 313 | PyErr_SetString(MSIError, "invalid state"); |
| 314 | return NULL; |
| 315 | case ERROR_INVALID_PARAMETER: |
| 316 | PyErr_SetString(MSIError, "invalid parameter"); |
| 317 | return NULL; |
| 318 | default: |
| 319 | PyErr_Format(MSIError, "unknown error %x", status); |
| 320 | return NULL; |
| 321 | } |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | code = MsiRecordGetInteger(err, 1); /* XXX code */ |
| 325 | if (MsiFormatRecord(0, err, res, &size) == ERROR_MORE_DATA) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 326 | res = malloc(size+1); |
| 327 | MsiFormatRecord(0, err, res, &size); |
| 328 | res[size]='\0'; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 329 | } |
| 330 | MsiCloseHandle(err); |
| 331 | PyErr_SetString(MSIError, res); |
| 332 | if (res != buf) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 333 | free(res); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 334 | return NULL; |
| 335 | } |
| 336 | |
| 337 | /*************************** Record objects **********************/ |
| 338 | |
| 339 | static PyObject* |
| 340 | record_getfieldcount(msiobj* record, PyObject* args) |
| 341 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 342 | return PyLong_FromLong(MsiRecordGetFieldCount(record->h)); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | static PyObject* |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 346 | record_getinteger(msiobj* record, PyObject* args) |
| 347 | { |
| 348 | unsigned int field; |
| 349 | int status; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 350 | |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 351 | if (!PyArg_ParseTuple(args, "I:GetInteger", &field)) |
| 352 | return NULL; |
| 353 | status = MsiRecordGetInteger(record->h, field); |
| 354 | if (status == MSI_NULL_INTEGER){ |
| 355 | PyErr_SetString(MSIError, "could not convert record field to integer"); |
| 356 | return NULL; |
| 357 | } |
Martin v. Löwis | 704d8b1 | 2008-06-02 11:32:23 +0000 | [diff] [blame] | 358 | return PyLong_FromLong((long) status); |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | static PyObject* |
| 362 | record_getstring(msiobj* record, PyObject* args) |
| 363 | { |
| 364 | unsigned int field; |
| 365 | unsigned int status; |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 366 | WCHAR buf[2000]; |
| 367 | WCHAR *res = buf; |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 368 | DWORD size = sizeof(buf); |
| 369 | PyObject* string; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 370 | |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 371 | if (!PyArg_ParseTuple(args, "I:GetString", &field)) |
| 372 | return NULL; |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 373 | status = MsiRecordGetStringW(record->h, field, res, &size); |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 374 | if (status == ERROR_MORE_DATA) { |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 375 | res = (WCHAR*) malloc((size + 1)*sizeof(WCHAR)); |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 376 | if (res == NULL) |
| 377 | return PyErr_NoMemory(); |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 378 | status = MsiRecordGetStringW(record->h, field, res, &size); |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 379 | } |
| 380 | if (status != ERROR_SUCCESS) |
| 381 | return msierror((int) status); |
Victor Stinner | 9d3b93b | 2011-11-22 02:27:30 +0100 | [diff] [blame] | 382 | string = PyUnicode_FromWideChar(res, size); |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 383 | if (buf != res) |
| 384 | free(res); |
| 385 | return string; |
| 386 | } |
| 387 | |
| 388 | static PyObject* |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 389 | record_cleardata(msiobj* record, PyObject *args) |
| 390 | { |
| 391 | int status = MsiRecordClearData(record->h); |
| 392 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 393 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 394 | |
| 395 | Py_INCREF(Py_None); |
| 396 | return Py_None; |
| 397 | } |
| 398 | |
| 399 | static PyObject* |
| 400 | record_setstring(msiobj* record, PyObject *args) |
| 401 | { |
| 402 | int status; |
| 403 | int field; |
Victor Stinner | 9d3b93b | 2011-11-22 02:27:30 +0100 | [diff] [blame] | 404 | wchar_t *data; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 405 | |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 406 | if (!PyArg_ParseTuple(args, "iu:SetString", &field, &data)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 407 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 408 | |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 409 | if ((status = MsiRecordSetStringW(record->h, field, data)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 410 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 411 | |
| 412 | Py_INCREF(Py_None); |
| 413 | return Py_None; |
| 414 | } |
| 415 | |
| 416 | static PyObject* |
| 417 | record_setstream(msiobj* record, PyObject *args) |
| 418 | { |
| 419 | int status; |
| 420 | int field; |
Victor Stinner | 9d3b93b | 2011-11-22 02:27:30 +0100 | [diff] [blame] | 421 | wchar_t *data; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 422 | |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 423 | if (!PyArg_ParseTuple(args, "iu:SetStream", &field, &data)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 424 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 425 | |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 426 | if ((status = MsiRecordSetStreamW(record->h, field, data)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 427 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 428 | |
| 429 | Py_INCREF(Py_None); |
| 430 | return Py_None; |
| 431 | } |
| 432 | |
| 433 | static PyObject* |
| 434 | record_setinteger(msiobj* record, PyObject *args) |
| 435 | { |
| 436 | int status; |
| 437 | int field; |
| 438 | int data; |
| 439 | |
| 440 | if (!PyArg_ParseTuple(args, "ii:SetInteger", &field, &data)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 441 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 442 | |
| 443 | if ((status = MsiRecordSetInteger(record->h, field, data)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 444 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 445 | |
| 446 | Py_INCREF(Py_None); |
| 447 | return Py_None; |
| 448 | } |
| 449 | |
| 450 | |
| 451 | |
| 452 | static PyMethodDef record_methods[] = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 453 | { "GetFieldCount", (PyCFunction)record_getfieldcount, METH_NOARGS, |
| 454 | PyDoc_STR("GetFieldCount() -> int\nWraps MsiRecordGetFieldCount")}, |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 455 | { "GetInteger", (PyCFunction)record_getinteger, METH_VARARGS, |
| 456 | PyDoc_STR("GetInteger(field) -> int\nWraps MsiRecordGetInteger")}, |
| 457 | { "GetString", (PyCFunction)record_getstring, METH_VARARGS, |
| 458 | PyDoc_STR("GetString(field) -> string\nWraps MsiRecordGetString")}, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 459 | { "SetString", (PyCFunction)record_setstring, METH_VARARGS, |
| 460 | PyDoc_STR("SetString(field,str) -> None\nWraps MsiRecordSetString")}, |
| 461 | { "SetStream", (PyCFunction)record_setstream, METH_VARARGS, |
| 462 | PyDoc_STR("SetStream(field,filename) -> None\nWraps MsiRecordSetInteger")}, |
| 463 | { "SetInteger", (PyCFunction)record_setinteger, METH_VARARGS, |
| 464 | PyDoc_STR("SetInteger(field,int) -> None\nWraps MsiRecordSetInteger")}, |
| 465 | { "ClearData", (PyCFunction)record_cleardata, METH_NOARGS, |
| 466 | PyDoc_STR("ClearData() -> int\nWraps MsiRecordGClearData")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 467 | { NULL, NULL } |
| 468 | }; |
| 469 | |
| 470 | static PyTypeObject record_Type = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 471 | PyVarObject_HEAD_INIT(NULL, 0) |
| 472 | "_msi.Record", /*tp_name*/ |
| 473 | sizeof(msiobj), /*tp_basicsize*/ |
| 474 | 0, /*tp_itemsize*/ |
| 475 | /* methods */ |
| 476 | (destructor)msiobj_dealloc, /*tp_dealloc*/ |
| 477 | 0, /*tp_print*/ |
| 478 | 0, /*tp_getattr*/ |
| 479 | 0, /*tp_setattr*/ |
| 480 | 0, /*tp_reserved*/ |
| 481 | 0, /*tp_repr*/ |
| 482 | 0, /*tp_as_number*/ |
| 483 | 0, /*tp_as_sequence*/ |
| 484 | 0, /*tp_as_mapping*/ |
| 485 | 0, /*tp_hash*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 486 | 0, /*tp_call*/ |
| 487 | 0, /*tp_str*/ |
| 488 | PyObject_GenericGetAttr,/*tp_getattro*/ |
| 489 | PyObject_GenericSetAttr,/*tp_setattro*/ |
| 490 | 0, /*tp_as_buffer*/ |
| 491 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 492 | 0, /*tp_doc*/ |
| 493 | 0, /*tp_traverse*/ |
| 494 | 0, /*tp_clear*/ |
| 495 | 0, /*tp_richcompare*/ |
| 496 | 0, /*tp_weaklistoffset*/ |
| 497 | 0, /*tp_iter*/ |
| 498 | 0, /*tp_iternext*/ |
| 499 | record_methods, /*tp_methods*/ |
| 500 | 0, /*tp_members*/ |
| 501 | 0, /*tp_getset*/ |
| 502 | 0, /*tp_base*/ |
| 503 | 0, /*tp_dict*/ |
| 504 | 0, /*tp_descr_get*/ |
| 505 | 0, /*tp_descr_set*/ |
| 506 | 0, /*tp_dictoffset*/ |
| 507 | 0, /*tp_init*/ |
| 508 | 0, /*tp_alloc*/ |
| 509 | 0, /*tp_new*/ |
| 510 | 0, /*tp_free*/ |
| 511 | 0, /*tp_is_gc*/ |
| 512 | }; |
| 513 | |
| 514 | static PyObject* |
| 515 | record_new(MSIHANDLE h) |
| 516 | { |
| 517 | msiobj *result = PyObject_NEW(struct msiobj, &record_Type); |
| 518 | |
| 519 | if (!result) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 520 | MsiCloseHandle(h); |
| 521 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | result->h = h; |
| 525 | return (PyObject*)result; |
| 526 | } |
| 527 | |
| 528 | /*************************** SummaryInformation objects **************/ |
| 529 | |
| 530 | static PyObject* |
| 531 | summary_getproperty(msiobj* si, PyObject *args) |
| 532 | { |
| 533 | int status; |
| 534 | int field; |
| 535 | PyObject *result; |
| 536 | UINT type; |
| 537 | INT ival; |
| 538 | FILETIME fval; |
| 539 | char sbuf[1000]; |
| 540 | char *sval = sbuf; |
| 541 | DWORD ssize = sizeof(sval); |
| 542 | |
| 543 | if (!PyArg_ParseTuple(args, "i:GetProperty", &field)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 544 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 545 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 546 | status = MsiSummaryInfoGetProperty(si->h, field, &type, &ival, |
| 547 | &fval, sval, &ssize); |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 548 | if (status == ERROR_MORE_DATA) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 549 | sval = malloc(ssize); |
| 550 | status = MsiSummaryInfoGetProperty(si->h, field, &type, &ival, |
| 551 | &fval, sval, &ssize); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | switch(type) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 555 | case VT_I2: case VT_I4: |
| 556 | return PyLong_FromLong(ival); |
| 557 | case VT_FILETIME: |
| 558 | PyErr_SetString(PyExc_NotImplementedError, "FILETIME result"); |
| 559 | return NULL; |
| 560 | case VT_LPSTR: |
| 561 | result = PyBytes_FromStringAndSize(sval, ssize); |
| 562 | if (sval != sbuf) |
| 563 | free(sval); |
| 564 | return result; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 565 | } |
| 566 | PyErr_Format(PyExc_NotImplementedError, "result of type %d", type); |
| 567 | return NULL; |
| 568 | } |
| 569 | |
| 570 | static PyObject* |
| 571 | summary_getpropertycount(msiobj* si, PyObject *args) |
| 572 | { |
| 573 | int status; |
| 574 | UINT result; |
| 575 | |
| 576 | status = MsiSummaryInfoGetPropertyCount(si->h, &result); |
| 577 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 578 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 579 | |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 580 | return PyLong_FromLong(result); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | static PyObject* |
| 584 | summary_setproperty(msiobj* si, PyObject *args) |
| 585 | { |
| 586 | int status; |
| 587 | int field; |
| 588 | PyObject* data; |
| 589 | |
| 590 | if (!PyArg_ParseTuple(args, "iO:SetProperty", &field, &data)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 591 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 592 | |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 593 | if (PyUnicode_Check(data)) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 594 | status = MsiSummaryInfoSetPropertyW(si->h, field, VT_LPSTR, |
| 595 | 0, NULL, PyUnicode_AsUnicode(data)); |
Martin v. Löwis | d1a1d1e | 2007-12-04 22:10:37 +0000 | [diff] [blame] | 596 | } else if (PyLong_CheckExact(data)) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 597 | long value = PyLong_AsLong(data); |
| 598 | if (value == -1 && PyErr_Occurred()) { |
| 599 | return NULL; |
| 600 | } |
| 601 | status = MsiSummaryInfoSetProperty(si->h, field, VT_I4, |
| 602 | value, NULL, NULL); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 603 | } else { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 604 | PyErr_SetString(PyExc_TypeError, "unsupported type"); |
| 605 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 606 | } |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 607 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 608 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 609 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 610 | |
| 611 | Py_INCREF(Py_None); |
| 612 | return Py_None; |
| 613 | } |
| 614 | |
| 615 | |
| 616 | static PyObject* |
| 617 | summary_persist(msiobj* si, PyObject *args) |
| 618 | { |
| 619 | int status; |
| 620 | |
| 621 | status = MsiSummaryInfoPersist(si->h); |
| 622 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 623 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 624 | Py_INCREF(Py_None); |
| 625 | return Py_None; |
| 626 | } |
| 627 | |
| 628 | static PyMethodDef summary_methods[] = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 629 | { "GetProperty", (PyCFunction)summary_getproperty, METH_VARARGS, |
| 630 | PyDoc_STR("GetProperty(propid) -> value\nWraps MsiSummaryInfoGetProperty")}, |
| 631 | { "GetPropertyCount", (PyCFunction)summary_getpropertycount, METH_NOARGS, |
| 632 | PyDoc_STR("GetProperty() -> int\nWraps MsiSummaryInfoGetPropertyCount")}, |
| 633 | { "SetProperty", (PyCFunction)summary_setproperty, METH_VARARGS, |
| 634 | PyDoc_STR("SetProperty(value) -> None\nWraps MsiSummaryInfoProperty")}, |
| 635 | { "Persist", (PyCFunction)summary_persist, METH_NOARGS, |
| 636 | PyDoc_STR("Persist() -> None\nWraps MsiSummaryInfoPersist")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 637 | { NULL, NULL } |
| 638 | }; |
| 639 | |
| 640 | static PyTypeObject summary_Type = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 641 | PyVarObject_HEAD_INIT(NULL, 0) |
| 642 | "_msi.SummaryInformation", /*tp_name*/ |
| 643 | sizeof(msiobj), /*tp_basicsize*/ |
| 644 | 0, /*tp_itemsize*/ |
| 645 | /* methods */ |
| 646 | (destructor)msiobj_dealloc, /*tp_dealloc*/ |
| 647 | 0, /*tp_print*/ |
| 648 | 0, /*tp_getattr*/ |
| 649 | 0, /*tp_setattr*/ |
| 650 | 0, /*tp_reserved*/ |
| 651 | 0, /*tp_repr*/ |
| 652 | 0, /*tp_as_number*/ |
| 653 | 0, /*tp_as_sequence*/ |
| 654 | 0, /*tp_as_mapping*/ |
| 655 | 0, /*tp_hash*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 656 | 0, /*tp_call*/ |
| 657 | 0, /*tp_str*/ |
| 658 | PyObject_GenericGetAttr,/*tp_getattro*/ |
| 659 | PyObject_GenericSetAttr,/*tp_setattro*/ |
| 660 | 0, /*tp_as_buffer*/ |
| 661 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 662 | 0, /*tp_doc*/ |
| 663 | 0, /*tp_traverse*/ |
| 664 | 0, /*tp_clear*/ |
| 665 | 0, /*tp_richcompare*/ |
| 666 | 0, /*tp_weaklistoffset*/ |
| 667 | 0, /*tp_iter*/ |
| 668 | 0, /*tp_iternext*/ |
| 669 | summary_methods, /*tp_methods*/ |
| 670 | 0, /*tp_members*/ |
| 671 | 0, /*tp_getset*/ |
| 672 | 0, /*tp_base*/ |
| 673 | 0, /*tp_dict*/ |
| 674 | 0, /*tp_descr_get*/ |
| 675 | 0, /*tp_descr_set*/ |
| 676 | 0, /*tp_dictoffset*/ |
| 677 | 0, /*tp_init*/ |
| 678 | 0, /*tp_alloc*/ |
| 679 | 0, /*tp_new*/ |
| 680 | 0, /*tp_free*/ |
| 681 | 0, /*tp_is_gc*/ |
| 682 | }; |
| 683 | |
| 684 | /*************************** View objects **************/ |
| 685 | |
| 686 | static PyObject* |
| 687 | view_execute(msiobj *view, PyObject*args) |
| 688 | { |
| 689 | int status; |
| 690 | MSIHANDLE params = 0; |
| 691 | PyObject *oparams = Py_None; |
| 692 | |
| 693 | if (!PyArg_ParseTuple(args, "O:Execute", &oparams)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 694 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 695 | |
| 696 | if (oparams != Py_None) { |
| 697 | if (oparams->ob_type != &record_Type) { |
| 698 | PyErr_SetString(PyExc_TypeError, "Execute argument must be a record"); |
| 699 | return NULL; |
| 700 | } |
| 701 | params = ((msiobj*)oparams)->h; |
| 702 | } |
| 703 | |
| 704 | status = MsiViewExecute(view->h, params); |
| 705 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 706 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 707 | |
| 708 | Py_INCREF(Py_None); |
| 709 | return Py_None; |
| 710 | } |
| 711 | |
| 712 | static PyObject* |
| 713 | view_fetch(msiobj *view, PyObject*args) |
| 714 | { |
| 715 | int status; |
| 716 | MSIHANDLE result; |
| 717 | |
| 718 | if ((status = MsiViewFetch(view->h, &result)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 719 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 720 | |
| 721 | return record_new(result); |
| 722 | } |
| 723 | |
| 724 | static PyObject* |
| 725 | view_getcolumninfo(msiobj *view, PyObject *args) |
| 726 | { |
| 727 | int status; |
| 728 | int kind; |
| 729 | MSIHANDLE result; |
| 730 | |
| 731 | if (!PyArg_ParseTuple(args, "i:GetColumnInfo", &kind)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 732 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 733 | |
| 734 | if ((status = MsiViewGetColumnInfo(view->h, kind, &result)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 735 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 736 | |
| 737 | return record_new(result); |
| 738 | } |
| 739 | |
| 740 | static PyObject* |
| 741 | view_modify(msiobj *view, PyObject *args) |
| 742 | { |
| 743 | int kind; |
| 744 | PyObject *data; |
| 745 | int status; |
| 746 | |
| 747 | if (!PyArg_ParseTuple(args, "iO:Modify", &kind, &data)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 748 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 749 | |
| 750 | if (data->ob_type != &record_Type) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 751 | PyErr_SetString(PyExc_TypeError, "Modify expects a record object"); |
| 752 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | if ((status = MsiViewModify(view->h, kind, ((msiobj*)data)->h)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 756 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 757 | |
| 758 | Py_INCREF(Py_None); |
| 759 | return Py_None; |
| 760 | } |
| 761 | |
| 762 | static PyObject* |
| 763 | view_close(msiobj *view, PyObject*args) |
| 764 | { |
| 765 | int status; |
| 766 | |
| 767 | if ((status = MsiViewClose(view->h)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 768 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 769 | |
| 770 | Py_INCREF(Py_None); |
| 771 | return Py_None; |
| 772 | } |
| 773 | |
| 774 | static PyMethodDef view_methods[] = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 775 | { "Execute", (PyCFunction)view_execute, METH_VARARGS, |
| 776 | PyDoc_STR("Execute(params=None) -> None\nWraps MsiViewExecute")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 777 | { "GetColumnInfo", (PyCFunction)view_getcolumninfo, METH_VARARGS, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 778 | PyDoc_STR("GetColumnInfo() -> result\nWraps MsiGetColumnInfo")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 779 | { "Fetch", (PyCFunction)view_fetch, METH_NOARGS, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 780 | PyDoc_STR("Fetch() -> result\nWraps MsiViewFetch")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 781 | { "Modify", (PyCFunction)view_modify, METH_VARARGS, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 782 | PyDoc_STR("Modify(mode,record) -> None\nWraps MsiViewModify")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 783 | { "Close", (PyCFunction)view_close, METH_NOARGS, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 784 | PyDoc_STR("Close() -> result\nWraps MsiViewClose")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 785 | { NULL, NULL } |
| 786 | }; |
| 787 | |
| 788 | static PyTypeObject msiview_Type = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 789 | PyVarObject_HEAD_INIT(NULL, 0) |
| 790 | "_msi.View", /*tp_name*/ |
| 791 | sizeof(msiobj), /*tp_basicsize*/ |
| 792 | 0, /*tp_itemsize*/ |
| 793 | /* methods */ |
| 794 | (destructor)msiobj_dealloc, /*tp_dealloc*/ |
| 795 | 0, /*tp_print*/ |
| 796 | 0, /*tp_getattr*/ |
| 797 | 0, /*tp_setattr*/ |
| 798 | 0, /*tp_reserved*/ |
| 799 | 0, /*tp_repr*/ |
| 800 | 0, /*tp_as_number*/ |
| 801 | 0, /*tp_as_sequence*/ |
| 802 | 0, /*tp_as_mapping*/ |
| 803 | 0, /*tp_hash*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 804 | 0, /*tp_call*/ |
| 805 | 0, /*tp_str*/ |
| 806 | PyObject_GenericGetAttr,/*tp_getattro*/ |
| 807 | PyObject_GenericSetAttr,/*tp_setattro*/ |
| 808 | 0, /*tp_as_buffer*/ |
| 809 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 810 | 0, /*tp_doc*/ |
| 811 | 0, /*tp_traverse*/ |
| 812 | 0, /*tp_clear*/ |
| 813 | 0, /*tp_richcompare*/ |
| 814 | 0, /*tp_weaklistoffset*/ |
| 815 | 0, /*tp_iter*/ |
| 816 | 0, /*tp_iternext*/ |
| 817 | view_methods, /*tp_methods*/ |
| 818 | 0, /*tp_members*/ |
| 819 | 0, /*tp_getset*/ |
| 820 | 0, /*tp_base*/ |
| 821 | 0, /*tp_dict*/ |
| 822 | 0, /*tp_descr_get*/ |
| 823 | 0, /*tp_descr_set*/ |
| 824 | 0, /*tp_dictoffset*/ |
| 825 | 0, /*tp_init*/ |
| 826 | 0, /*tp_alloc*/ |
| 827 | 0, /*tp_new*/ |
| 828 | 0, /*tp_free*/ |
| 829 | 0, /*tp_is_gc*/ |
| 830 | }; |
| 831 | |
| 832 | /*************************** Database objects **************/ |
| 833 | |
| 834 | static PyObject* |
| 835 | msidb_openview(msiobj *msidb, PyObject *args) |
| 836 | { |
| 837 | int status; |
| 838 | char *sql; |
| 839 | MSIHANDLE hView; |
| 840 | msiobj *result; |
| 841 | |
| 842 | if (!PyArg_ParseTuple(args, "s:OpenView", &sql)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 843 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 844 | |
| 845 | if ((status = MsiDatabaseOpenView(msidb->h, sql, &hView)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 846 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 847 | |
| 848 | result = PyObject_NEW(struct msiobj, &msiview_Type); |
| 849 | if (!result) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 850 | MsiCloseHandle(hView); |
| 851 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | result->h = hView; |
| 855 | return (PyObject*)result; |
| 856 | } |
| 857 | |
| 858 | static PyObject* |
| 859 | msidb_commit(msiobj *msidb, PyObject *args) |
| 860 | { |
| 861 | int status; |
| 862 | |
| 863 | if ((status = MsiDatabaseCommit(msidb->h)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 864 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 865 | |
| 866 | Py_INCREF(Py_None); |
| 867 | return Py_None; |
| 868 | } |
| 869 | |
| 870 | static PyObject* |
| 871 | msidb_getsummaryinformation(msiobj *db, PyObject *args) |
| 872 | { |
| 873 | int status; |
| 874 | int count; |
| 875 | MSIHANDLE result; |
| 876 | msiobj *oresult; |
| 877 | |
| 878 | if (!PyArg_ParseTuple(args, "i:GetSummaryInformation", &count)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 879 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 880 | |
| 881 | status = MsiGetSummaryInformation(db->h, NULL, count, &result); |
| 882 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 883 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 884 | |
| 885 | oresult = PyObject_NEW(struct msiobj, &summary_Type); |
| 886 | if (!result) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 887 | MsiCloseHandle(result); |
| 888 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | oresult->h = result; |
| 892 | return (PyObject*)oresult; |
| 893 | } |
| 894 | |
| 895 | static PyMethodDef db_methods[] = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 896 | { "OpenView", (PyCFunction)msidb_openview, METH_VARARGS, |
| 897 | PyDoc_STR("OpenView(sql) -> viewobj\nWraps MsiDatabaseOpenView")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 898 | { "Commit", (PyCFunction)msidb_commit, METH_NOARGS, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 899 | PyDoc_STR("Commit() -> None\nWraps MsiDatabaseCommit")}, |
| 900 | { "GetSummaryInformation", (PyCFunction)msidb_getsummaryinformation, METH_VARARGS, |
| 901 | PyDoc_STR("GetSummaryInformation(updateCount) -> viewobj\nWraps MsiGetSummaryInformation")}, |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 902 | { NULL, NULL } |
| 903 | }; |
| 904 | |
| 905 | static PyTypeObject msidb_Type = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 906 | PyVarObject_HEAD_INIT(NULL, 0) |
| 907 | "_msi.Database", /*tp_name*/ |
| 908 | sizeof(msiobj), /*tp_basicsize*/ |
| 909 | 0, /*tp_itemsize*/ |
| 910 | /* methods */ |
| 911 | (destructor)msiobj_dealloc, /*tp_dealloc*/ |
| 912 | 0, /*tp_print*/ |
| 913 | 0, /*tp_getattr*/ |
| 914 | 0, /*tp_setattr*/ |
| 915 | 0, /*tp_reserved*/ |
| 916 | 0, /*tp_repr*/ |
| 917 | 0, /*tp_as_number*/ |
| 918 | 0, /*tp_as_sequence*/ |
| 919 | 0, /*tp_as_mapping*/ |
| 920 | 0, /*tp_hash*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 921 | 0, /*tp_call*/ |
| 922 | 0, /*tp_str*/ |
| 923 | PyObject_GenericGetAttr,/*tp_getattro*/ |
| 924 | PyObject_GenericSetAttr,/*tp_setattro*/ |
| 925 | 0, /*tp_as_buffer*/ |
| 926 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 927 | 0, /*tp_doc*/ |
| 928 | 0, /*tp_traverse*/ |
| 929 | 0, /*tp_clear*/ |
| 930 | 0, /*tp_richcompare*/ |
| 931 | 0, /*tp_weaklistoffset*/ |
| 932 | 0, /*tp_iter*/ |
| 933 | 0, /*tp_iternext*/ |
| 934 | db_methods, /*tp_methods*/ |
| 935 | 0, /*tp_members*/ |
| 936 | 0, /*tp_getset*/ |
| 937 | 0, /*tp_base*/ |
| 938 | 0, /*tp_dict*/ |
| 939 | 0, /*tp_descr_get*/ |
| 940 | 0, /*tp_descr_set*/ |
| 941 | 0, /*tp_dictoffset*/ |
| 942 | 0, /*tp_init*/ |
| 943 | 0, /*tp_alloc*/ |
| 944 | 0, /*tp_new*/ |
| 945 | 0, /*tp_free*/ |
| 946 | 0, /*tp_is_gc*/ |
| 947 | }; |
| 948 | |
| 949 | static PyObject* msiopendb(PyObject *obj, PyObject *args) |
| 950 | { |
| 951 | int status; |
| 952 | char *path; |
| 953 | int persist; |
| 954 | MSIHANDLE h; |
| 955 | msiobj *result; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 956 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 957 | if (!PyArg_ParseTuple(args, "si:MSIOpenDatabase", &path, &persist)) |
| 958 | return NULL; |
| 959 | |
| 960 | status = MsiOpenDatabase(path, (LPCSTR)persist, &h); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 961 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 962 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 963 | |
| 964 | result = PyObject_NEW(struct msiobj, &msidb_Type); |
| 965 | if (!result) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 966 | MsiCloseHandle(h); |
| 967 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 968 | } |
| 969 | result->h = h; |
| 970 | return (PyObject*)result; |
| 971 | } |
| 972 | |
| 973 | static PyObject* |
| 974 | createrecord(PyObject *o, PyObject *args) |
| 975 | { |
| 976 | int count; |
| 977 | MSIHANDLE h; |
| 978 | |
| 979 | if (!PyArg_ParseTuple(args, "i:CreateRecord", &count)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 980 | return NULL; |
| 981 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 982 | h = MsiCreateRecord(count); |
| 983 | if (h == 0) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 984 | return msierror(0); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 985 | |
| 986 | return record_new(h); |
| 987 | } |
| 988 | |
| 989 | |
| 990 | static PyMethodDef msi_methods[] = { |
| 991 | {"UuidCreate", (PyCFunction)uuidcreate, METH_NOARGS, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 992 | PyDoc_STR("UuidCreate() -> string")}, |
| 993 | {"FCICreate", (PyCFunction)fcicreate, METH_VARARGS, |
| 994 | PyDoc_STR("fcicreate(cabname,files) -> None")}, |
| 995 | {"OpenDatabase", (PyCFunction)msiopendb, METH_VARARGS, |
| 996 | PyDoc_STR("OpenDatabase(name, flags) -> dbobj\nWraps MsiOpenDatabase")}, |
| 997 | {"CreateRecord", (PyCFunction)createrecord, METH_VARARGS, |
| 998 | PyDoc_STR("OpenDatabase(name, flags) -> dbobj\nWraps MsiCreateRecord")}, |
| 999 | {NULL, NULL} /* sentinel */ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1000 | }; |
| 1001 | |
| 1002 | static char msi_doc[] = "Documentation"; |
| 1003 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 1004 | |
| 1005 | static struct PyModuleDef _msimodule = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1006 | PyModuleDef_HEAD_INIT, |
| 1007 | "_msi", |
| 1008 | msi_doc, |
| 1009 | -1, |
| 1010 | msi_methods, |
| 1011 | NULL, |
| 1012 | NULL, |
| 1013 | NULL, |
| 1014 | NULL |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 1015 | }; |
| 1016 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1017 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 1018 | PyInit__msi(void) |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1019 | { |
| 1020 | PyObject *m; |
| 1021 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 1022 | m = PyModule_Create(&_msimodule); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1023 | if (m == NULL) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1024 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1025 | |
| 1026 | PyModule_AddIntConstant(m, "MSIDBOPEN_CREATEDIRECT", (int)MSIDBOPEN_CREATEDIRECT); |
| 1027 | PyModule_AddIntConstant(m, "MSIDBOPEN_CREATE", (int)MSIDBOPEN_CREATE); |
| 1028 | PyModule_AddIntConstant(m, "MSIDBOPEN_DIRECT", (int)MSIDBOPEN_DIRECT); |
| 1029 | PyModule_AddIntConstant(m, "MSIDBOPEN_READONLY", (int)MSIDBOPEN_READONLY); |
| 1030 | PyModule_AddIntConstant(m, "MSIDBOPEN_TRANSACT", (int)MSIDBOPEN_TRANSACT); |
| 1031 | PyModule_AddIntConstant(m, "MSIDBOPEN_PATCHFILE", (int)MSIDBOPEN_PATCHFILE); |
| 1032 | |
| 1033 | PyModule_AddIntConstant(m, "MSICOLINFO_NAMES", MSICOLINFO_NAMES); |
| 1034 | PyModule_AddIntConstant(m, "MSICOLINFO_TYPES", MSICOLINFO_TYPES); |
| 1035 | |
| 1036 | PyModule_AddIntConstant(m, "MSIMODIFY_SEEK", MSIMODIFY_SEEK); |
| 1037 | PyModule_AddIntConstant(m, "MSIMODIFY_REFRESH", MSIMODIFY_REFRESH); |
| 1038 | PyModule_AddIntConstant(m, "MSIMODIFY_INSERT", MSIMODIFY_INSERT); |
| 1039 | PyModule_AddIntConstant(m, "MSIMODIFY_UPDATE", MSIMODIFY_UPDATE); |
| 1040 | PyModule_AddIntConstant(m, "MSIMODIFY_ASSIGN", MSIMODIFY_ASSIGN); |
| 1041 | PyModule_AddIntConstant(m, "MSIMODIFY_REPLACE", MSIMODIFY_REPLACE); |
| 1042 | PyModule_AddIntConstant(m, "MSIMODIFY_MERGE", MSIMODIFY_MERGE); |
| 1043 | PyModule_AddIntConstant(m, "MSIMODIFY_DELETE", MSIMODIFY_DELETE); |
| 1044 | PyModule_AddIntConstant(m, "MSIMODIFY_INSERT_TEMPORARY", MSIMODIFY_INSERT_TEMPORARY); |
| 1045 | PyModule_AddIntConstant(m, "MSIMODIFY_VALIDATE", MSIMODIFY_VALIDATE); |
| 1046 | PyModule_AddIntConstant(m, "MSIMODIFY_VALIDATE_NEW", MSIMODIFY_VALIDATE_NEW); |
| 1047 | PyModule_AddIntConstant(m, "MSIMODIFY_VALIDATE_FIELD", MSIMODIFY_VALIDATE_FIELD); |
| 1048 | PyModule_AddIntConstant(m, "MSIMODIFY_VALIDATE_DELETE", MSIMODIFY_VALIDATE_DELETE); |
| 1049 | |
| 1050 | PyModule_AddIntConstant(m, "PID_CODEPAGE", PID_CODEPAGE); |
| 1051 | PyModule_AddIntConstant(m, "PID_TITLE", PID_TITLE); |
| 1052 | PyModule_AddIntConstant(m, "PID_SUBJECT", PID_SUBJECT); |
| 1053 | PyModule_AddIntConstant(m, "PID_AUTHOR", PID_AUTHOR); |
| 1054 | PyModule_AddIntConstant(m, "PID_KEYWORDS", PID_KEYWORDS); |
| 1055 | PyModule_AddIntConstant(m, "PID_COMMENTS", PID_COMMENTS); |
| 1056 | PyModule_AddIntConstant(m, "PID_TEMPLATE", PID_TEMPLATE); |
| 1057 | PyModule_AddIntConstant(m, "PID_LASTAUTHOR", PID_LASTAUTHOR); |
| 1058 | PyModule_AddIntConstant(m, "PID_REVNUMBER", PID_REVNUMBER); |
| 1059 | PyModule_AddIntConstant(m, "PID_LASTPRINTED", PID_LASTPRINTED); |
| 1060 | PyModule_AddIntConstant(m, "PID_CREATE_DTM", PID_CREATE_DTM); |
| 1061 | PyModule_AddIntConstant(m, "PID_LASTSAVE_DTM", PID_LASTSAVE_DTM); |
| 1062 | PyModule_AddIntConstant(m, "PID_PAGECOUNT", PID_PAGECOUNT); |
| 1063 | PyModule_AddIntConstant(m, "PID_WORDCOUNT", PID_WORDCOUNT); |
| 1064 | PyModule_AddIntConstant(m, "PID_CHARCOUNT", PID_CHARCOUNT); |
| 1065 | PyModule_AddIntConstant(m, "PID_APPNAME", PID_APPNAME); |
| 1066 | PyModule_AddIntConstant(m, "PID_SECURITY", PID_SECURITY); |
| 1067 | |
| 1068 | MSIError = PyErr_NewException ("_msi.MSIError", NULL, NULL); |
| 1069 | if (!MSIError) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1070 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1071 | PyModule_AddObject(m, "MSIError", MSIError); |
Amaury Forgeot d'Arc | bf9e966 | 2008-06-17 21:39:46 +0000 | [diff] [blame] | 1072 | return m; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1073 | } |