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 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 15 | /*[clinic input] |
| 16 | module _msi |
| 17 | class _msi.Record "msiobj *" "&record_Type" |
| 18 | class _msi.SummaryInformation "msiobj *" "&summary_Type" |
| 19 | class _msi.View "msiobj *" "&msiview_Type" |
| 20 | class _msi.Database "msiobj *" "&msidb_Type" |
| 21 | [clinic start generated code]*/ |
| 22 | /*[clinic end generated code: output=da39a3ee5e6b4b0d input=89a3605762cf4bdc]*/ |
| 23 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 24 | static PyObject *MSIError; |
| 25 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 26 | /*[clinic input] |
| 27 | _msi.UuidCreate |
| 28 | |
| 29 | Return the string representation of a new unique identifier. |
| 30 | [clinic start generated code]*/ |
| 31 | |
| 32 | static PyObject * |
| 33 | _msi_UuidCreate_impl(PyObject *module) |
| 34 | /*[clinic end generated code: output=534ecf36f10af98e input=168024ab4b3e832b]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 35 | { |
| 36 | UUID result; |
Victor Stinner | 9d3b93b | 2011-11-22 02:27:30 +0100 | [diff] [blame] | 37 | wchar_t *cresult; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 38 | PyObject *oresult; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 39 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 40 | /* May return ok, local only, and no address. |
| 41 | For local only, the documentation says we still get a uuid. |
| 42 | For RPC_S_UUID_NO_ADDRESS, it's not clear whether we can |
| 43 | use the result. */ |
| 44 | if (UuidCreate(&result) == RPC_S_UUID_NO_ADDRESS) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 45 | PyErr_SetString(PyExc_NotImplementedError, "processing 'no address' result"); |
| 46 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 49 | if (UuidToStringW(&result, &cresult) == RPC_S_OUT_OF_MEMORY) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 50 | PyErr_SetString(PyExc_MemoryError, "out of memory in uuidgen"); |
| 51 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Victor Stinner | 9d3b93b | 2011-11-22 02:27:30 +0100 | [diff] [blame] | 54 | oresult = PyUnicode_FromWideChar(cresult, wcslen(cresult)); |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 55 | RpcStringFreeW(&cresult); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 56 | return oresult; |
| 57 | |
| 58 | } |
| 59 | |
Serhiy Storchaka | ba67d73 | 2020-06-30 11:56:03 +0300 | [diff] [blame] | 60 | /* Helper for converting file names from UTF-8 to wchat_t*. */ |
| 61 | static wchar_t * |
| 62 | utf8_to_wchar(const char *s, int *err) |
| 63 | { |
| 64 | PyObject *obj = PyUnicode_FromString(s); |
| 65 | if (obj == NULL) { |
| 66 | if (PyErr_ExceptionMatches(PyExc_MemoryError)) { |
| 67 | *err = ENOMEM; |
| 68 | } |
| 69 | else { |
| 70 | *err = EINVAL; |
| 71 | } |
| 72 | PyErr_Clear(); |
| 73 | return NULL; |
| 74 | } |
| 75 | wchar_t *ws = PyUnicode_AsWideCharString(obj, NULL); |
| 76 | if (ws == NULL) { |
| 77 | *err = ENOMEM; |
| 78 | PyErr_Clear(); |
| 79 | } |
| 80 | Py_DECREF(obj); |
| 81 | return ws; |
| 82 | } |
| 83 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 84 | /* FCI callback functions */ |
| 85 | |
| 86 | static FNFCIALLOC(cb_alloc) |
| 87 | { |
Serhiy Storchaka | ba67d73 | 2020-06-30 11:56:03 +0300 | [diff] [blame] | 88 | return PyMem_RawMalloc(cb); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static FNFCIFREE(cb_free) |
| 92 | { |
Serhiy Storchaka | ba67d73 | 2020-06-30 11:56:03 +0300 | [diff] [blame] | 93 | PyMem_RawFree(memory); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static FNFCIOPEN(cb_open) |
| 97 | { |
Serhiy Storchaka | ba67d73 | 2020-06-30 11:56:03 +0300 | [diff] [blame] | 98 | wchar_t *ws = utf8_to_wchar(pszFile, err); |
| 99 | if (ws == NULL) { |
| 100 | return -1; |
| 101 | } |
| 102 | int result = _wopen(ws, oflag | O_NOINHERIT, pmode); |
| 103 | PyMem_Free(ws); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 104 | if (result == -1) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 105 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 106 | return result; |
| 107 | } |
| 108 | |
| 109 | static FNFCIREAD(cb_read) |
| 110 | { |
Victor Stinner | 6715828 | 2013-11-20 00:14:49 +0100 | [diff] [blame] | 111 | UINT result = (UINT)_read((int)hf, memory, cb); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 112 | if (result != cb) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 113 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 114 | return result; |
| 115 | } |
| 116 | |
| 117 | static FNFCIWRITE(cb_write) |
| 118 | { |
Victor Stinner | 6715828 | 2013-11-20 00:14:49 +0100 | [diff] [blame] | 119 | UINT result = (UINT)_write((int)hf, memory, cb); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 120 | if (result != cb) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 121 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 122 | return result; |
| 123 | } |
| 124 | |
| 125 | static FNFCICLOSE(cb_close) |
| 126 | { |
Victor Stinner | 6715828 | 2013-11-20 00:14:49 +0100 | [diff] [blame] | 127 | int result = _close((int)hf); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 128 | if (result != 0) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 129 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 130 | return result; |
| 131 | } |
| 132 | |
| 133 | static FNFCISEEK(cb_seek) |
| 134 | { |
Victor Stinner | 6715828 | 2013-11-20 00:14:49 +0100 | [diff] [blame] | 135 | long result = (long)_lseek((int)hf, dist, seektype); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 136 | if (result == -1) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 137 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 138 | return result; |
| 139 | } |
| 140 | |
| 141 | static FNFCIDELETE(cb_delete) |
| 142 | { |
Serhiy Storchaka | ba67d73 | 2020-06-30 11:56:03 +0300 | [diff] [blame] | 143 | wchar_t *ws = utf8_to_wchar(pszFile, err); |
| 144 | if (ws == NULL) { |
| 145 | return -1; |
| 146 | } |
| 147 | int result = _wremove(ws); |
| 148 | PyMem_Free(ws); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 149 | if (result != 0) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 150 | *err = errno; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 151 | return result; |
| 152 | } |
| 153 | |
| 154 | static FNFCIFILEPLACED(cb_fileplaced) |
| 155 | { |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | static FNFCIGETTEMPFILE(cb_gettempfile) |
| 160 | { |
| 161 | char *name = _tempnam("", "tmp"); |
| 162 | if ((name != NULL) && ((int)strlen(name) < cbTempName)) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 163 | strcpy(pszTempName, name); |
| 164 | free(name); |
| 165 | return TRUE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | if (name) free(name); |
| 169 | return FALSE; |
| 170 | } |
| 171 | |
| 172 | static FNFCISTATUS(cb_status) |
| 173 | { |
| 174 | if (pv) { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 175 | _Py_IDENTIFIER(status); |
Martin v. Löwis | afe55bb | 2011-10-09 10:38:36 +0200 | [diff] [blame] | 176 | |
| 177 | PyObject *result = _PyObject_CallMethodId(pv, &PyId_status, "iii", typeStatus, cb1, cb2); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 178 | if (result == NULL) |
| 179 | return -1; |
| 180 | Py_DECREF(result); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 181 | } |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | static FNFCIGETNEXTCABINET(cb_getnextcabinet) |
| 186 | { |
| 187 | if (pv) { |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 188 | _Py_IDENTIFIER(getnextcabinet); |
Martin v. Löwis | afe55bb | 2011-10-09 10:38:36 +0200 | [diff] [blame] | 189 | |
| 190 | PyObject *result = _PyObject_CallMethodId(pv, &PyId_getnextcabinet, "i", pccab->iCab); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 191 | if (result == NULL) |
| 192 | return -1; |
| 193 | if (!PyBytes_Check(result)) { |
| 194 | PyErr_Format(PyExc_TypeError, |
| 195 | "Incorrect return type %s from getnextcabinet", |
| 196 | result->ob_type->tp_name); |
| 197 | Py_DECREF(result); |
| 198 | return FALSE; |
| 199 | } |
| 200 | strncpy(pccab->szCab, PyBytes_AsString(result), sizeof(pccab->szCab)); |
| 201 | return TRUE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 202 | } |
| 203 | return FALSE; |
| 204 | } |
| 205 | |
| 206 | static FNFCIGETOPENINFO(cb_getopeninfo) |
| 207 | { |
| 208 | BY_HANDLE_FILE_INFORMATION bhfi; |
| 209 | FILETIME filetime; |
| 210 | HANDLE handle; |
| 211 | |
Serhiy Storchaka | ba67d73 | 2020-06-30 11:56:03 +0300 | [diff] [blame] | 212 | wchar_t *ws = utf8_to_wchar(pszName, err); |
| 213 | if (ws == NULL) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 214 | return -1; |
Serhiy Storchaka | ba67d73 | 2020-06-30 11:56:03 +0300 | [diff] [blame] | 215 | } |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 216 | |
Serhiy Storchaka | ba67d73 | 2020-06-30 11:56:03 +0300 | [diff] [blame] | 217 | /* Need Win32 handle to get time stamps */ |
| 218 | handle = CreateFileW(ws, GENERIC_READ, FILE_SHARE_READ, NULL, |
| 219 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 220 | if (handle == INVALID_HANDLE_VALUE) { |
| 221 | PyMem_Free(ws); |
| 222 | return -1; |
| 223 | } |
| 224 | |
| 225 | if (GetFileInformationByHandle(handle, &bhfi) == FALSE) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 226 | CloseHandle(handle); |
Serhiy Storchaka | ba67d73 | 2020-06-30 11:56:03 +0300 | [diff] [blame] | 227 | PyMem_Free(ws); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 228 | return -1; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | FileTimeToLocalFileTime(&bhfi.ftLastWriteTime, &filetime); |
| 232 | FileTimeToDosDateTime(&filetime, pdate, ptime); |
| 233 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 234 | *pattribs = (int)(bhfi.dwFileAttributes & |
| 235 | (_A_RDONLY | _A_SYSTEM | _A_HIDDEN | _A_ARCH)); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 236 | |
| 237 | CloseHandle(handle); |
| 238 | |
Serhiy Storchaka | ba67d73 | 2020-06-30 11:56:03 +0300 | [diff] [blame] | 239 | int result = _wopen(ws, _O_RDONLY | _O_BINARY | O_NOINHERIT); |
| 240 | PyMem_Free(ws); |
| 241 | return result; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 244 | /*[clinic input] |
| 245 | _msi.FCICreate |
| 246 | cabname: str |
| 247 | the name of the CAB file |
| 248 | files: object |
| 249 | a list of tuples, each containing the name of the file on disk, |
| 250 | and the name of the file inside the CAB file |
| 251 | / |
| 252 | |
| 253 | Create a new CAB file. |
| 254 | [clinic start generated code]*/ |
| 255 | |
| 256 | static PyObject * |
| 257 | _msi_FCICreate_impl(PyObject *module, const char *cabname, PyObject *files) |
| 258 | /*[clinic end generated code: output=55dc05728361b799 input=1d2d75fdc8b44b71]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 259 | { |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 260 | const char *p; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 261 | CCAB ccab; |
| 262 | HFCI hfci; |
| 263 | ERF erf; |
Christian Heimes | 0bd4e11 | 2008-02-12 22:59:25 +0000 | [diff] [blame] | 264 | Py_ssize_t i; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 265 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 266 | if (!PyList_Check(files)) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 267 | PyErr_SetString(PyExc_TypeError, "FCICreate expects a list"); |
| 268 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | ccab.cb = INT_MAX; /* no need to split CAB into multiple media */ |
| 272 | ccab.cbFolderThresh = 1000000; /* flush directory after this many bytes */ |
| 273 | ccab.cbReserveCFData = 0; |
| 274 | ccab.cbReserveCFFolder = 0; |
| 275 | ccab.cbReserveCFHeader = 0; |
| 276 | |
| 277 | ccab.iCab = 1; |
| 278 | ccab.iDisk = 1; |
| 279 | |
| 280 | ccab.setID = 0; |
| 281 | ccab.szDisk[0] = '\0'; |
| 282 | |
Serhiy Storchaka | ba67d73 | 2020-06-30 11:56:03 +0300 | [diff] [blame] | 283 | for (i = 0, p = cabname; *p; p++) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 284 | if (*p == '\\' || *p == '/') |
| 285 | i = p - cabname + 1; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 286 | |
Christian Heimes | 0bd4e11 | 2008-02-12 22:59:25 +0000 | [diff] [blame] | 287 | if (i >= sizeof(ccab.szCabPath) || |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 288 | strlen(cabname+i) >= sizeof(ccab.szCab)) { |
| 289 | PyErr_SetString(PyExc_ValueError, "path name too long"); |
| 290 | return 0; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Christian Heimes | 0bd4e11 | 2008-02-12 22:59:25 +0000 | [diff] [blame] | 293 | if (i > 0) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 294 | memcpy(ccab.szCabPath, cabname, i); |
| 295 | ccab.szCabPath[i] = '\0'; |
| 296 | strcpy(ccab.szCab, cabname+i); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 297 | } else { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 298 | strcpy(ccab.szCabPath, ".\\"); |
| 299 | strcpy(ccab.szCab, cabname); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | hfci = FCICreate(&erf, cb_fileplaced, cb_alloc, cb_free, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 303 | cb_open, cb_read, cb_write, cb_close, cb_seek, cb_delete, |
| 304 | cb_gettempfile, &ccab, NULL); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 305 | |
| 306 | if (hfci == NULL) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 307 | PyErr_Format(PyExc_ValueError, "FCI error %d", erf.erfOper); |
| 308 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | for (i=0; i < PyList_GET_SIZE(files); i++) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 312 | PyObject *item = PyList_GET_ITEM(files, i); |
| 313 | char *filename, *cabname; |
Zachary Ware | 0a29e89 | 2015-05-18 00:47:15 -0500 | [diff] [blame] | 314 | |
| 315 | if (!PyArg_ParseTuple(item, "ss", &filename, &cabname)) { |
| 316 | PyErr_SetString(PyExc_TypeError, "FCICreate expects a list of tuples containing two strings"); |
| 317 | FCIDestroy(hfci); |
| 318 | return NULL; |
| 319 | } |
| 320 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 321 | if (!FCIAddFile(hfci, filename, cabname, FALSE, |
| 322 | cb_getnextcabinet, cb_status, cb_getopeninfo, |
| 323 | tcompTYPE_MSZIP)) |
| 324 | goto err; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | if (!FCIFlushCabinet(hfci, FALSE, cb_getnextcabinet, cb_status)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 328 | goto err; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 329 | |
| 330 | if (!FCIDestroy(hfci)) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 331 | goto err; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 332 | |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 333 | Py_RETURN_NONE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 334 | err: |
Zachary Ware | 0a29e89 | 2015-05-18 00:47:15 -0500 | [diff] [blame] | 335 | if(erf.fError) |
| 336 | PyErr_Format(PyExc_ValueError, "FCI error %d", erf.erfOper); /* XXX better error type */ |
| 337 | else |
| 338 | PyErr_SetString(PyExc_ValueError, "FCI general error"); |
| 339 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 340 | FCIDestroy(hfci); |
| 341 | return NULL; |
| 342 | } |
| 343 | |
| 344 | typedef struct msiobj{ |
| 345 | PyObject_HEAD |
| 346 | MSIHANDLE h; |
| 347 | }msiobj; |
| 348 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 349 | static void |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 350 | msiobj_dealloc(msiobj* msidb) |
| 351 | { |
| 352 | MsiCloseHandle(msidb->h); |
| 353 | msidb->h = 0; |
Zackery Spytz | cb04f75 | 2017-11-07 03:03:09 -0700 | [diff] [blame] | 354 | PyObject_Del(msidb); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | static PyObject* |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 358 | msierror(int status) |
| 359 | { |
| 360 | int code; |
| 361 | char buf[2000]; |
| 362 | char *res = buf; |
| 363 | DWORD size = sizeof(buf); |
| 364 | MSIHANDLE err = MsiGetLastErrorRecord(); |
| 365 | |
| 366 | if (err == 0) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 367 | switch(status) { |
| 368 | case ERROR_ACCESS_DENIED: |
| 369 | PyErr_SetString(MSIError, "access denied"); |
| 370 | return NULL; |
| 371 | case ERROR_FUNCTION_FAILED: |
| 372 | PyErr_SetString(MSIError, "function failed"); |
| 373 | return NULL; |
| 374 | case ERROR_INVALID_DATA: |
| 375 | PyErr_SetString(MSIError, "invalid data"); |
| 376 | return NULL; |
| 377 | case ERROR_INVALID_HANDLE: |
| 378 | PyErr_SetString(MSIError, "invalid handle"); |
| 379 | return NULL; |
| 380 | case ERROR_INVALID_STATE: |
| 381 | PyErr_SetString(MSIError, "invalid state"); |
| 382 | return NULL; |
| 383 | case ERROR_INVALID_PARAMETER: |
| 384 | PyErr_SetString(MSIError, "invalid parameter"); |
| 385 | return NULL; |
Berker Peksag | 4864a61 | 2017-11-24 12:53:58 +0300 | [diff] [blame] | 386 | case ERROR_OPEN_FAILED: |
| 387 | PyErr_SetString(MSIError, "open failed"); |
| 388 | return NULL; |
| 389 | case ERROR_CREATE_FAILED: |
| 390 | PyErr_SetString(MSIError, "create failed"); |
| 391 | return NULL; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 392 | default: |
| 393 | PyErr_Format(MSIError, "unknown error %x", status); |
| 394 | return NULL; |
| 395 | } |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | code = MsiRecordGetInteger(err, 1); /* XXX code */ |
| 399 | if (MsiFormatRecord(0, err, res, &size) == ERROR_MORE_DATA) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 400 | res = malloc(size+1); |
Zackery Spytz | 4e51937 | 2018-09-07 16:02:56 -0600 | [diff] [blame] | 401 | if (res == NULL) { |
| 402 | MsiCloseHandle(err); |
| 403 | return PyErr_NoMemory(); |
| 404 | } |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 405 | MsiFormatRecord(0, err, res, &size); |
| 406 | res[size]='\0'; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 407 | } |
| 408 | MsiCloseHandle(err); |
| 409 | PyErr_SetString(MSIError, res); |
| 410 | if (res != buf) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 411 | free(res); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 412 | return NULL; |
| 413 | } |
| 414 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 415 | #include "clinic/_msi.c.h" |
| 416 | |
| 417 | /*[clinic input] |
| 418 | _msi.Database.Close |
| 419 | |
| 420 | Close the database object. |
| 421 | [clinic start generated code]*/ |
| 422 | |
| 423 | static PyObject * |
| 424 | _msi_Database_Close_impl(msiobj *self) |
| 425 | /*[clinic end generated code: output=ddf2d7712ea804f1 input=104330ce4a486187]*/ |
Berker Peksag | a935654 | 2017-11-07 15:58:53 +0300 | [diff] [blame] | 426 | { |
| 427 | int status; |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 428 | if ((status = MsiCloseHandle(self->h)) != ERROR_SUCCESS) { |
Berker Peksag | a935654 | 2017-11-07 15:58:53 +0300 | [diff] [blame] | 429 | return msierror(status); |
| 430 | } |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 431 | self->h = 0; |
Berker Peksag | a935654 | 2017-11-07 15:58:53 +0300 | [diff] [blame] | 432 | Py_RETURN_NONE; |
| 433 | } |
| 434 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 435 | /*************************** Record objects **********************/ |
| 436 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 437 | /*[clinic input] |
| 438 | _msi.Record.GetFieldCount |
| 439 | |
| 440 | Return the number of fields of the record. |
| 441 | [clinic start generated code]*/ |
| 442 | |
| 443 | static PyObject * |
| 444 | _msi_Record_GetFieldCount_impl(msiobj *self) |
| 445 | /*[clinic end generated code: output=112795079c904398 input=5fb9d4071b28897b]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 446 | { |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 447 | return PyLong_FromLong(MsiRecordGetFieldCount(self->h)); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 450 | /*[clinic input] |
| 451 | _msi.Record.GetInteger |
| 452 | field: unsigned_int(bitwise=True) |
| 453 | / |
| 454 | |
| 455 | Return the value of field as an integer where possible. |
| 456 | [clinic start generated code]*/ |
| 457 | |
| 458 | static PyObject * |
| 459 | _msi_Record_GetInteger_impl(msiobj *self, unsigned int field) |
| 460 | /*[clinic end generated code: output=7174ebb6e8ed1c79 input=d19209947e2bfe61]*/ |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 461 | { |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 462 | int status; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 463 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 464 | status = MsiRecordGetInteger(self->h, field); |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 465 | if (status == MSI_NULL_INTEGER){ |
| 466 | PyErr_SetString(MSIError, "could not convert record field to integer"); |
| 467 | return NULL; |
| 468 | } |
Martin v. Löwis | 704d8b1 | 2008-06-02 11:32:23 +0000 | [diff] [blame] | 469 | return PyLong_FromLong((long) status); |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 472 | /*[clinic input] |
| 473 | _msi.Record.GetString |
| 474 | field: unsigned_int(bitwise=True) |
| 475 | / |
| 476 | |
| 477 | Return the value of field as a string where possible. |
| 478 | [clinic start generated code]*/ |
| 479 | |
| 480 | static PyObject * |
| 481 | _msi_Record_GetString_impl(msiobj *self, unsigned int field) |
| 482 | /*[clinic end generated code: output=f670d1b484cfa47c input=ffa11f21450b77d8]*/ |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 483 | { |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 484 | unsigned int status; |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 485 | WCHAR buf[2000]; |
| 486 | WCHAR *res = buf; |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 487 | DWORD size = sizeof(buf); |
| 488 | PyObject* string; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 489 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 490 | status = MsiRecordGetStringW(self->h, field, res, &size); |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 491 | if (status == ERROR_MORE_DATA) { |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 492 | res = (WCHAR*) malloc((size + 1)*sizeof(WCHAR)); |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 493 | if (res == NULL) |
| 494 | return PyErr_NoMemory(); |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 495 | status = MsiRecordGetStringW(self->h, field, res, &size); |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 496 | } |
| 497 | if (status != ERROR_SUCCESS) |
| 498 | return msierror((int) status); |
Victor Stinner | 9d3b93b | 2011-11-22 02:27:30 +0100 | [diff] [blame] | 499 | string = PyUnicode_FromWideChar(res, size); |
Martin v. Löwis | e95593e | 2008-06-02 10:08:54 +0000 | [diff] [blame] | 500 | if (buf != res) |
| 501 | free(res); |
| 502 | return string; |
| 503 | } |
| 504 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 505 | /*[clinic input] |
| 506 | _msi.Record.ClearData |
| 507 | |
| 508 | Set all fields of the record to 0. |
| 509 | [clinic start generated code]*/ |
| 510 | |
| 511 | static PyObject * |
| 512 | _msi_Record_ClearData_impl(msiobj *self) |
| 513 | /*[clinic end generated code: output=1891467214b977f4 input=2a911c95aaded102]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 514 | { |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 515 | int status = MsiRecordClearData(self->h); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 516 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 517 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 518 | |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 519 | Py_RETURN_NONE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 522 | /*[clinic input] |
| 523 | _msi.Record.SetString |
| 524 | field: int |
| 525 | value: Py_UNICODE |
| 526 | / |
| 527 | |
| 528 | Set field to a string value. |
| 529 | [clinic start generated code]*/ |
| 530 | |
| 531 | static PyObject * |
| 532 | _msi_Record_SetString_impl(msiobj *self, int field, const Py_UNICODE *value) |
| 533 | /*[clinic end generated code: output=2e37505b0f11f985 input=fb8ec70a2a6148e0]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 534 | { |
| 535 | int status; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 536 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 537 | if ((status = MsiRecordSetStringW(self->h, field, value)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 538 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 539 | |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 540 | Py_RETURN_NONE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 541 | } |
| 542 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 543 | /*[clinic input] |
| 544 | _msi.Record.SetStream |
| 545 | field: int |
| 546 | value: Py_UNICODE |
| 547 | / |
| 548 | |
| 549 | Set field to the contents of the file named value. |
| 550 | [clinic start generated code]*/ |
| 551 | |
| 552 | static PyObject * |
| 553 | _msi_Record_SetStream_impl(msiobj *self, int field, const Py_UNICODE *value) |
| 554 | /*[clinic end generated code: output=442facac16913b48 input=a07aa19b865e8292]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 555 | { |
| 556 | int status; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 557 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 558 | if ((status = MsiRecordSetStreamW(self->h, field, value)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 559 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 560 | |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 561 | Py_RETURN_NONE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 564 | /*[clinic input] |
| 565 | _msi.Record.SetInteger |
| 566 | field: int |
| 567 | value: int |
| 568 | / |
| 569 | |
| 570 | Set field to an integer value. |
| 571 | [clinic start generated code]*/ |
| 572 | |
| 573 | static PyObject * |
| 574 | _msi_Record_SetInteger_impl(msiobj *self, int field, int value) |
| 575 | /*[clinic end generated code: output=669e8647775d0ce7 input=c571aa775e7e451b]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 576 | { |
| 577 | int status; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 578 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 579 | if ((status = MsiRecordSetInteger(self->h, field, value)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 580 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 581 | |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 582 | Py_RETURN_NONE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | |
| 586 | |
| 587 | static PyMethodDef record_methods[] = { |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 588 | _MSI_RECORD_GETFIELDCOUNT_METHODDEF |
| 589 | _MSI_RECORD_GETINTEGER_METHODDEF |
| 590 | _MSI_RECORD_GETSTRING_METHODDEF |
| 591 | _MSI_RECORD_SETSTRING_METHODDEF |
| 592 | _MSI_RECORD_SETSTREAM_METHODDEF |
| 593 | _MSI_RECORD_SETINTEGER_METHODDEF |
| 594 | _MSI_RECORD_CLEARDATA_METHODDEF |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 595 | { NULL, NULL } |
| 596 | }; |
| 597 | |
| 598 | static PyTypeObject record_Type = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 599 | PyVarObject_HEAD_INIT(NULL, 0) |
| 600 | "_msi.Record", /*tp_name*/ |
| 601 | sizeof(msiobj), /*tp_basicsize*/ |
| 602 | 0, /*tp_itemsize*/ |
| 603 | /* methods */ |
| 604 | (destructor)msiobj_dealloc, /*tp_dealloc*/ |
Jeroen Demeyer | 530f506 | 2019-05-31 04:13:39 +0200 | [diff] [blame] | 605 | 0, /*tp_vectorcall_offset*/ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 606 | 0, /*tp_getattr*/ |
| 607 | 0, /*tp_setattr*/ |
Jeroen Demeyer | 530f506 | 2019-05-31 04:13:39 +0200 | [diff] [blame] | 608 | 0, /*tp_as_async*/ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 609 | 0, /*tp_repr*/ |
| 610 | 0, /*tp_as_number*/ |
| 611 | 0, /*tp_as_sequence*/ |
| 612 | 0, /*tp_as_mapping*/ |
| 613 | 0, /*tp_hash*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 614 | 0, /*tp_call*/ |
| 615 | 0, /*tp_str*/ |
| 616 | PyObject_GenericGetAttr,/*tp_getattro*/ |
| 617 | PyObject_GenericSetAttr,/*tp_setattro*/ |
| 618 | 0, /*tp_as_buffer*/ |
| 619 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 620 | 0, /*tp_doc*/ |
| 621 | 0, /*tp_traverse*/ |
| 622 | 0, /*tp_clear*/ |
| 623 | 0, /*tp_richcompare*/ |
| 624 | 0, /*tp_weaklistoffset*/ |
| 625 | 0, /*tp_iter*/ |
| 626 | 0, /*tp_iternext*/ |
| 627 | record_methods, /*tp_methods*/ |
| 628 | 0, /*tp_members*/ |
| 629 | 0, /*tp_getset*/ |
| 630 | 0, /*tp_base*/ |
| 631 | 0, /*tp_dict*/ |
| 632 | 0, /*tp_descr_get*/ |
| 633 | 0, /*tp_descr_set*/ |
| 634 | 0, /*tp_dictoffset*/ |
| 635 | 0, /*tp_init*/ |
| 636 | 0, /*tp_alloc*/ |
| 637 | 0, /*tp_new*/ |
| 638 | 0, /*tp_free*/ |
| 639 | 0, /*tp_is_gc*/ |
| 640 | }; |
| 641 | |
| 642 | static PyObject* |
| 643 | record_new(MSIHANDLE h) |
| 644 | { |
Victor Stinner | 9205520 | 2020-04-08 00:38:15 +0200 | [diff] [blame] | 645 | msiobj *result = PyObject_New(struct msiobj, &record_Type); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 646 | |
| 647 | if (!result) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 648 | MsiCloseHandle(h); |
| 649 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | result->h = h; |
| 653 | return (PyObject*)result; |
| 654 | } |
| 655 | |
| 656 | /*************************** SummaryInformation objects **************/ |
| 657 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 658 | /*[clinic input] |
| 659 | _msi.SummaryInformation.GetProperty |
| 660 | field: int |
| 661 | the name of the property, one of the PID_* constants |
| 662 | / |
| 663 | |
| 664 | Return a property of the summary. |
| 665 | [clinic start generated code]*/ |
| 666 | |
| 667 | static PyObject * |
| 668 | _msi_SummaryInformation_GetProperty_impl(msiobj *self, int field) |
| 669 | /*[clinic end generated code: output=f8946a33ee14f6ef input=f8dfe2c890d6cb8b]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 670 | { |
| 671 | int status; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 672 | PyObject *result; |
| 673 | UINT type; |
| 674 | INT ival; |
| 675 | FILETIME fval; |
| 676 | char sbuf[1000]; |
| 677 | char *sval = sbuf; |
Tzu-ping Chung | 2de576e | 2019-02-03 01:13:23 +0800 | [diff] [blame] | 678 | DWORD ssize = sizeof(sbuf); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 679 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 680 | status = MsiSummaryInfoGetProperty(self->h, field, &type, &ival, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 681 | &fval, sval, &ssize); |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 682 | if (status == ERROR_MORE_DATA) { |
Tzu-ping Chung | 2de576e | 2019-02-03 01:13:23 +0800 | [diff] [blame] | 683 | ssize++; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 684 | sval = malloc(ssize); |
Zackery Spytz | 4e51937 | 2018-09-07 16:02:56 -0600 | [diff] [blame] | 685 | if (sval == NULL) { |
| 686 | return PyErr_NoMemory(); |
| 687 | } |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 688 | status = MsiSummaryInfoGetProperty(self->h, field, &type, &ival, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 689 | &fval, sval, &ssize); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 690 | } |
Zackery Spytz | 549e55a | 2019-05-31 18:16:20 -0600 | [diff] [blame] | 691 | if (status != ERROR_SUCCESS) { |
| 692 | return msierror(status); |
| 693 | } |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 694 | |
| 695 | switch(type) { |
Tzu-ping Chung | 2de576e | 2019-02-03 01:13:23 +0800 | [diff] [blame] | 696 | case VT_I2: |
| 697 | case VT_I4: |
| 698 | result = PyLong_FromLong(ival); |
| 699 | break; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 700 | case VT_FILETIME: |
| 701 | PyErr_SetString(PyExc_NotImplementedError, "FILETIME result"); |
Tzu-ping Chung | 2de576e | 2019-02-03 01:13:23 +0800 | [diff] [blame] | 702 | result = NULL; |
| 703 | break; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 704 | case VT_LPSTR: |
| 705 | result = PyBytes_FromStringAndSize(sval, ssize); |
Tzu-ping Chung | 2de576e | 2019-02-03 01:13:23 +0800 | [diff] [blame] | 706 | break; |
Berker Peksag | 19fb134 | 2017-11-24 18:11:18 +0300 | [diff] [blame] | 707 | case VT_EMPTY: |
Tzu-ping Chung | 2de576e | 2019-02-03 01:13:23 +0800 | [diff] [blame] | 708 | Py_INCREF(Py_None); |
| 709 | result = Py_None; |
| 710 | break; |
| 711 | default: |
| 712 | PyErr_Format(PyExc_NotImplementedError, "result of type %d", type); |
| 713 | result = NULL; |
| 714 | break; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 715 | } |
Tzu-ping Chung | 2de576e | 2019-02-03 01:13:23 +0800 | [diff] [blame] | 716 | if (sval != sbuf) |
| 717 | free(sval); |
| 718 | return result; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 719 | } |
| 720 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 721 | /*[clinic input] |
| 722 | _msi.SummaryInformation.GetPropertyCount |
| 723 | |
| 724 | Return the number of summary properties. |
| 725 | [clinic start generated code]*/ |
| 726 | |
| 727 | static PyObject * |
| 728 | _msi_SummaryInformation_GetPropertyCount_impl(msiobj *self) |
| 729 | /*[clinic end generated code: output=68e94b2aeee92b3d input=2e71e985586d82dc]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 730 | { |
| 731 | int status; |
| 732 | UINT result; |
| 733 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 734 | status = MsiSummaryInfoGetPropertyCount(self->h, &result); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 735 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 736 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 737 | |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 738 | return PyLong_FromLong(result); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 739 | } |
| 740 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 741 | /*[clinic input] |
| 742 | _msi.SummaryInformation.SetProperty |
| 743 | field: int |
| 744 | the name of the property, one of the PID_* constants |
| 745 | value as data: object |
| 746 | the new value of the property (integer or string) |
| 747 | / |
| 748 | |
| 749 | Set a property. |
| 750 | [clinic start generated code]*/ |
| 751 | |
| 752 | static PyObject * |
| 753 | _msi_SummaryInformation_SetProperty_impl(msiobj *self, int field, |
| 754 | PyObject *data) |
| 755 | /*[clinic end generated code: output=3d4692c8984bb675 input=f2a7811b905abbed]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 756 | { |
| 757 | int status; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 758 | |
Martin v. Löwis | 371bb50 | 2008-08-16 13:02:57 +0000 | [diff] [blame] | 759 | if (PyUnicode_Check(data)) { |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 760 | #if USE_UNICODE_WCHAR_CACHE |
| 761 | _Py_COMP_DIAG_PUSH |
| 762 | _Py_COMP_DIAG_IGNORE_DEPR_DECLS |
Serhiy Storchaka | ccdc09e | 2017-06-28 09:55:22 +0300 | [diff] [blame] | 763 | const WCHAR *value = _PyUnicode_AsUnicode(data); |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 764 | _Py_COMP_DIAG_POP |
| 765 | #else /* USE_UNICODE_WCHAR_CACHE */ |
| 766 | WCHAR *value = PyUnicode_AsWideCharString(data, NULL); |
| 767 | #endif /* USE_UNICODE_WCHAR_CACHE */ |
Serhiy Storchaka | f7eae0a | 2017-06-28 08:30:06 +0300 | [diff] [blame] | 768 | if (value == NULL) { |
| 769 | return NULL; |
| 770 | } |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 771 | status = MsiSummaryInfoSetPropertyW(self->h, field, VT_LPSTR, |
Serhiy Storchaka | f7eae0a | 2017-06-28 08:30:06 +0300 | [diff] [blame] | 772 | 0, NULL, value); |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 773 | #if !USE_UNICODE_WCHAR_CACHE |
| 774 | PyMem_Free(value); |
| 775 | #endif /* USE_UNICODE_WCHAR_CACHE */ |
Martin v. Löwis | d1a1d1e | 2007-12-04 22:10:37 +0000 | [diff] [blame] | 776 | } else if (PyLong_CheckExact(data)) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 777 | long value = PyLong_AsLong(data); |
| 778 | if (value == -1 && PyErr_Occurred()) { |
| 779 | return NULL; |
| 780 | } |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 781 | status = MsiSummaryInfoSetProperty(self->h, field, VT_I4, |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 782 | value, NULL, NULL); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 783 | } else { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 784 | PyErr_SetString(PyExc_TypeError, "unsupported type"); |
| 785 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 786 | } |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 787 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 788 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 789 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 790 | |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 791 | Py_RETURN_NONE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 795 | /*[clinic input] |
| 796 | _msi.SummaryInformation.Persist |
| 797 | |
| 798 | Write the modified properties to the summary information stream. |
| 799 | [clinic start generated code]*/ |
| 800 | |
| 801 | static PyObject * |
| 802 | _msi_SummaryInformation_Persist_impl(msiobj *self) |
| 803 | /*[clinic end generated code: output=c564bd17f5e122c9 input=e3dda9d530095ef7]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 804 | { |
| 805 | int status; |
| 806 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 807 | status = MsiSummaryInfoPersist(self->h); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 808 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 809 | return msierror(status); |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 810 | Py_RETURN_NONE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | static PyMethodDef summary_methods[] = { |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 814 | _MSI_SUMMARYINFORMATION_GETPROPERTY_METHODDEF |
| 815 | _MSI_SUMMARYINFORMATION_GETPROPERTYCOUNT_METHODDEF |
| 816 | _MSI_SUMMARYINFORMATION_SETPROPERTY_METHODDEF |
| 817 | _MSI_SUMMARYINFORMATION_PERSIST_METHODDEF |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 818 | { NULL, NULL } |
| 819 | }; |
| 820 | |
| 821 | static PyTypeObject summary_Type = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 822 | PyVarObject_HEAD_INIT(NULL, 0) |
| 823 | "_msi.SummaryInformation", /*tp_name*/ |
| 824 | sizeof(msiobj), /*tp_basicsize*/ |
| 825 | 0, /*tp_itemsize*/ |
| 826 | /* methods */ |
| 827 | (destructor)msiobj_dealloc, /*tp_dealloc*/ |
Jeroen Demeyer | 530f506 | 2019-05-31 04:13:39 +0200 | [diff] [blame] | 828 | 0, /*tp_vectorcall_offset*/ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 829 | 0, /*tp_getattr*/ |
| 830 | 0, /*tp_setattr*/ |
Jeroen Demeyer | 530f506 | 2019-05-31 04:13:39 +0200 | [diff] [blame] | 831 | 0, /*tp_as_async*/ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 832 | 0, /*tp_repr*/ |
| 833 | 0, /*tp_as_number*/ |
| 834 | 0, /*tp_as_sequence*/ |
| 835 | 0, /*tp_as_mapping*/ |
| 836 | 0, /*tp_hash*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 837 | 0, /*tp_call*/ |
| 838 | 0, /*tp_str*/ |
| 839 | PyObject_GenericGetAttr,/*tp_getattro*/ |
| 840 | PyObject_GenericSetAttr,/*tp_setattro*/ |
| 841 | 0, /*tp_as_buffer*/ |
| 842 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 843 | 0, /*tp_doc*/ |
| 844 | 0, /*tp_traverse*/ |
| 845 | 0, /*tp_clear*/ |
| 846 | 0, /*tp_richcompare*/ |
| 847 | 0, /*tp_weaklistoffset*/ |
| 848 | 0, /*tp_iter*/ |
| 849 | 0, /*tp_iternext*/ |
| 850 | summary_methods, /*tp_methods*/ |
| 851 | 0, /*tp_members*/ |
| 852 | 0, /*tp_getset*/ |
| 853 | 0, /*tp_base*/ |
| 854 | 0, /*tp_dict*/ |
| 855 | 0, /*tp_descr_get*/ |
| 856 | 0, /*tp_descr_set*/ |
| 857 | 0, /*tp_dictoffset*/ |
| 858 | 0, /*tp_init*/ |
| 859 | 0, /*tp_alloc*/ |
| 860 | 0, /*tp_new*/ |
| 861 | 0, /*tp_free*/ |
| 862 | 0, /*tp_is_gc*/ |
| 863 | }; |
| 864 | |
| 865 | /*************************** View objects **************/ |
| 866 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 867 | /*[clinic input] |
| 868 | _msi.View.Execute |
| 869 | params as oparams: object |
| 870 | a record describing actual values of the parameter tokens |
| 871 | in the query or None |
| 872 | / |
| 873 | |
| 874 | Execute the SQL query of the view. |
| 875 | [clinic start generated code]*/ |
| 876 | |
| 877 | static PyObject * |
| 878 | _msi_View_Execute(msiobj *self, PyObject *oparams) |
| 879 | /*[clinic end generated code: output=f0f65fd2900bcb4e input=cb163a15d453348e]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 880 | { |
| 881 | int status; |
| 882 | MSIHANDLE params = 0; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 883 | |
| 884 | if (oparams != Py_None) { |
| 885 | if (oparams->ob_type != &record_Type) { |
| 886 | PyErr_SetString(PyExc_TypeError, "Execute argument must be a record"); |
| 887 | return NULL; |
| 888 | } |
| 889 | params = ((msiobj*)oparams)->h; |
| 890 | } |
| 891 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 892 | status = MsiViewExecute(self->h, params); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 893 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 894 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 895 | |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 896 | Py_RETURN_NONE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 897 | } |
| 898 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 899 | /*[clinic input] |
| 900 | _msi.View.Fetch |
| 901 | |
| 902 | Return a result record of the query. |
| 903 | [clinic start generated code]*/ |
| 904 | |
| 905 | static PyObject * |
| 906 | _msi_View_Fetch_impl(msiobj *self) |
| 907 | /*[clinic end generated code: output=ba154a3794537d4e input=7f3e3d06c449001c]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 908 | { |
| 909 | int status; |
| 910 | MSIHANDLE result; |
| 911 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 912 | status = MsiViewFetch(self->h, &result); |
Berker Peksag | bdb8315 | 2017-11-23 15:47:30 +0300 | [diff] [blame] | 913 | if (status == ERROR_NO_MORE_ITEMS) { |
| 914 | Py_RETURN_NONE; |
| 915 | } else if (status != ERROR_SUCCESS) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 916 | return msierror(status); |
Berker Peksag | bdb8315 | 2017-11-23 15:47:30 +0300 | [diff] [blame] | 917 | } |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 918 | |
| 919 | return record_new(result); |
| 920 | } |
| 921 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 922 | /*[clinic input] |
| 923 | _msi.View.GetColumnInfo |
| 924 | kind: int |
| 925 | MSICOLINFO_NAMES or MSICOLINFO_TYPES |
| 926 | / |
| 927 | |
| 928 | Return a record describing the columns of the view. |
| 929 | [clinic start generated code]*/ |
| 930 | |
| 931 | static PyObject * |
| 932 | _msi_View_GetColumnInfo_impl(msiobj *self, int kind) |
| 933 | /*[clinic end generated code: output=e7c1697db9403660 input=afedb892bf564a3b]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 934 | { |
| 935 | int status; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 936 | MSIHANDLE result; |
| 937 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 938 | if ((status = MsiViewGetColumnInfo(self->h, kind, &result)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 939 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 940 | |
| 941 | return record_new(result); |
| 942 | } |
| 943 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 944 | /*[clinic input] |
| 945 | _msi.View.Modify |
| 946 | kind: int |
| 947 | one of the MSIMODIFY_* constants |
| 948 | data: object |
| 949 | a record describing the new data |
| 950 | / |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 951 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 952 | Modify the view. |
| 953 | [clinic start generated code]*/ |
| 954 | |
| 955 | static PyObject * |
| 956 | _msi_View_Modify_impl(msiobj *self, int kind, PyObject *data) |
| 957 | /*[clinic end generated code: output=69aaf3ce8ddac0ba input=2828de22de0d47b4]*/ |
| 958 | { |
| 959 | int status; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 960 | |
| 961 | if (data->ob_type != &record_Type) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 962 | PyErr_SetString(PyExc_TypeError, "Modify expects a record object"); |
| 963 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 964 | } |
| 965 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 966 | if ((status = MsiViewModify(self->h, kind, ((msiobj*)data)->h)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 967 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 968 | |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 969 | Py_RETURN_NONE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 972 | /*[clinic input] |
| 973 | _msi.View.Close |
| 974 | |
| 975 | Close the view. |
| 976 | [clinic start generated code]*/ |
| 977 | |
| 978 | static PyObject * |
| 979 | _msi_View_Close_impl(msiobj *self) |
| 980 | /*[clinic end generated code: output=488f7b8645ca104a input=de6927d1308c401c]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 981 | { |
| 982 | int status; |
| 983 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 984 | if ((status = MsiViewClose(self->h)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 985 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 986 | |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 987 | Py_RETURN_NONE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | static PyMethodDef view_methods[] = { |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 991 | _MSI_VIEW_EXECUTE_METHODDEF |
| 992 | _MSI_VIEW_GETCOLUMNINFO_METHODDEF |
| 993 | _MSI_VIEW_FETCH_METHODDEF |
| 994 | _MSI_VIEW_MODIFY_METHODDEF |
| 995 | _MSI_VIEW_CLOSE_METHODDEF |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 996 | { NULL, NULL } |
| 997 | }; |
| 998 | |
| 999 | static PyTypeObject msiview_Type = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1000 | PyVarObject_HEAD_INIT(NULL, 0) |
| 1001 | "_msi.View", /*tp_name*/ |
| 1002 | sizeof(msiobj), /*tp_basicsize*/ |
| 1003 | 0, /*tp_itemsize*/ |
| 1004 | /* methods */ |
| 1005 | (destructor)msiobj_dealloc, /*tp_dealloc*/ |
Jeroen Demeyer | 530f506 | 2019-05-31 04:13:39 +0200 | [diff] [blame] | 1006 | 0, /*tp_vectorcall_offset*/ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1007 | 0, /*tp_getattr*/ |
| 1008 | 0, /*tp_setattr*/ |
Jeroen Demeyer | 530f506 | 2019-05-31 04:13:39 +0200 | [diff] [blame] | 1009 | 0, /*tp_as_async*/ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1010 | 0, /*tp_repr*/ |
| 1011 | 0, /*tp_as_number*/ |
| 1012 | 0, /*tp_as_sequence*/ |
| 1013 | 0, /*tp_as_mapping*/ |
| 1014 | 0, /*tp_hash*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1015 | 0, /*tp_call*/ |
| 1016 | 0, /*tp_str*/ |
| 1017 | PyObject_GenericGetAttr,/*tp_getattro*/ |
| 1018 | PyObject_GenericSetAttr,/*tp_setattro*/ |
| 1019 | 0, /*tp_as_buffer*/ |
| 1020 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1021 | 0, /*tp_doc*/ |
| 1022 | 0, /*tp_traverse*/ |
| 1023 | 0, /*tp_clear*/ |
| 1024 | 0, /*tp_richcompare*/ |
| 1025 | 0, /*tp_weaklistoffset*/ |
| 1026 | 0, /*tp_iter*/ |
| 1027 | 0, /*tp_iternext*/ |
| 1028 | view_methods, /*tp_methods*/ |
| 1029 | 0, /*tp_members*/ |
| 1030 | 0, /*tp_getset*/ |
| 1031 | 0, /*tp_base*/ |
| 1032 | 0, /*tp_dict*/ |
| 1033 | 0, /*tp_descr_get*/ |
| 1034 | 0, /*tp_descr_set*/ |
| 1035 | 0, /*tp_dictoffset*/ |
| 1036 | 0, /*tp_init*/ |
| 1037 | 0, /*tp_alloc*/ |
| 1038 | 0, /*tp_new*/ |
| 1039 | 0, /*tp_free*/ |
| 1040 | 0, /*tp_is_gc*/ |
| 1041 | }; |
| 1042 | |
| 1043 | /*************************** Database objects **************/ |
| 1044 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 1045 | /*[clinic input] |
| 1046 | _msi.Database.OpenView |
| 1047 | sql: Py_UNICODE |
| 1048 | the SQL statement to execute |
| 1049 | / |
| 1050 | |
| 1051 | Return a view object. |
| 1052 | [clinic start generated code]*/ |
| 1053 | |
| 1054 | static PyObject * |
| 1055 | _msi_Database_OpenView_impl(msiobj *self, const Py_UNICODE *sql) |
| 1056 | /*[clinic end generated code: output=e712e6a11229abfd input=50f1771f37e500df]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1057 | { |
| 1058 | int status; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1059 | MSIHANDLE hView; |
| 1060 | msiobj *result; |
| 1061 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 1062 | if ((status = MsiDatabaseOpenViewW(self->h, sql, &hView)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1063 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1064 | |
Victor Stinner | 9205520 | 2020-04-08 00:38:15 +0200 | [diff] [blame] | 1065 | result = PyObject_New(struct msiobj, &msiview_Type); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1066 | if (!result) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1067 | MsiCloseHandle(hView); |
| 1068 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | result->h = hView; |
| 1072 | return (PyObject*)result; |
| 1073 | } |
| 1074 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 1075 | /*[clinic input] |
| 1076 | _msi.Database.Commit |
| 1077 | |
| 1078 | Commit the changes pending in the current transaction. |
| 1079 | [clinic start generated code]*/ |
| 1080 | |
| 1081 | static PyObject * |
| 1082 | _msi_Database_Commit_impl(msiobj *self) |
| 1083 | /*[clinic end generated code: output=f33021feb8b0cdd8 input=375bb120d402266d]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1084 | { |
| 1085 | int status; |
| 1086 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 1087 | if ((status = MsiDatabaseCommit(self->h)) != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1088 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1089 | |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 1090 | Py_RETURN_NONE; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 1093 | /*[clinic input] |
| 1094 | _msi.Database.GetSummaryInformation |
| 1095 | count: int |
| 1096 | the maximum number of updated values |
| 1097 | / |
| 1098 | |
| 1099 | Return a new summary information object. |
| 1100 | [clinic start generated code]*/ |
| 1101 | |
| 1102 | static PyObject * |
| 1103 | _msi_Database_GetSummaryInformation_impl(msiobj *self, int count) |
| 1104 | /*[clinic end generated code: output=781e51a4ea4da847 input=18a899ead6521735]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1105 | { |
| 1106 | int status; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1107 | MSIHANDLE result; |
| 1108 | msiobj *oresult; |
| 1109 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 1110 | status = MsiGetSummaryInformation(self->h, NULL, count, &result); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1111 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1112 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1113 | |
Victor Stinner | 9205520 | 2020-04-08 00:38:15 +0200 | [diff] [blame] | 1114 | oresult = PyObject_New(struct msiobj, &summary_Type); |
Zackery Spytz | bf94cc7 | 2019-03-07 11:20:13 -0700 | [diff] [blame] | 1115 | if (!oresult) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1116 | MsiCloseHandle(result); |
| 1117 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | oresult->h = result; |
| 1121 | return (PyObject*)oresult; |
| 1122 | } |
| 1123 | |
| 1124 | static PyMethodDef db_methods[] = { |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 1125 | _MSI_DATABASE_OPENVIEW_METHODDEF |
| 1126 | _MSI_DATABASE_COMMIT_METHODDEF |
| 1127 | _MSI_DATABASE_GETSUMMARYINFORMATION_METHODDEF |
| 1128 | _MSI_DATABASE_CLOSE_METHODDEF |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1129 | { NULL, NULL } |
| 1130 | }; |
| 1131 | |
| 1132 | static PyTypeObject msidb_Type = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1133 | PyVarObject_HEAD_INIT(NULL, 0) |
| 1134 | "_msi.Database", /*tp_name*/ |
| 1135 | sizeof(msiobj), /*tp_basicsize*/ |
| 1136 | 0, /*tp_itemsize*/ |
| 1137 | /* methods */ |
| 1138 | (destructor)msiobj_dealloc, /*tp_dealloc*/ |
Jeroen Demeyer | 530f506 | 2019-05-31 04:13:39 +0200 | [diff] [blame] | 1139 | 0, /*tp_vectorcall_offset*/ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1140 | 0, /*tp_getattr*/ |
| 1141 | 0, /*tp_setattr*/ |
Jeroen Demeyer | 530f506 | 2019-05-31 04:13:39 +0200 | [diff] [blame] | 1142 | 0, /*tp_as_async*/ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1143 | 0, /*tp_repr*/ |
| 1144 | 0, /*tp_as_number*/ |
| 1145 | 0, /*tp_as_sequence*/ |
| 1146 | 0, /*tp_as_mapping*/ |
| 1147 | 0, /*tp_hash*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1148 | 0, /*tp_call*/ |
| 1149 | 0, /*tp_str*/ |
| 1150 | PyObject_GenericGetAttr,/*tp_getattro*/ |
| 1151 | PyObject_GenericSetAttr,/*tp_setattro*/ |
| 1152 | 0, /*tp_as_buffer*/ |
| 1153 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
| 1154 | 0, /*tp_doc*/ |
| 1155 | 0, /*tp_traverse*/ |
| 1156 | 0, /*tp_clear*/ |
| 1157 | 0, /*tp_richcompare*/ |
| 1158 | 0, /*tp_weaklistoffset*/ |
| 1159 | 0, /*tp_iter*/ |
| 1160 | 0, /*tp_iternext*/ |
| 1161 | db_methods, /*tp_methods*/ |
| 1162 | 0, /*tp_members*/ |
| 1163 | 0, /*tp_getset*/ |
| 1164 | 0, /*tp_base*/ |
| 1165 | 0, /*tp_dict*/ |
| 1166 | 0, /*tp_descr_get*/ |
| 1167 | 0, /*tp_descr_set*/ |
| 1168 | 0, /*tp_dictoffset*/ |
| 1169 | 0, /*tp_init*/ |
| 1170 | 0, /*tp_alloc*/ |
| 1171 | 0, /*tp_new*/ |
| 1172 | 0, /*tp_free*/ |
| 1173 | 0, /*tp_is_gc*/ |
| 1174 | }; |
| 1175 | |
Steve Dower | 6ceda63 | 2016-09-09 11:56:34 -0700 | [diff] [blame] | 1176 | #define Py_NOT_PERSIST(x, flag) \ |
Segev Finer | 679b566 | 2017-07-27 01:17:57 +0300 | [diff] [blame] | 1177 | (x != (SIZE_T)(flag) && \ |
| 1178 | x != ((SIZE_T)(flag) | MSIDBOPEN_PATCHFILE)) |
Steve Dower | 6ceda63 | 2016-09-09 11:56:34 -0700 | [diff] [blame] | 1179 | |
| 1180 | #define Py_INVALID_PERSIST(x) \ |
| 1181 | (Py_NOT_PERSIST(x, MSIDBOPEN_READONLY) && \ |
| 1182 | Py_NOT_PERSIST(x, MSIDBOPEN_TRANSACT) && \ |
| 1183 | Py_NOT_PERSIST(x, MSIDBOPEN_DIRECT) && \ |
| 1184 | Py_NOT_PERSIST(x, MSIDBOPEN_CREATE) && \ |
| 1185 | Py_NOT_PERSIST(x, MSIDBOPEN_CREATEDIRECT)) |
| 1186 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 1187 | /*[clinic input] |
| 1188 | _msi.OpenDatabase |
| 1189 | path: Py_UNICODE |
| 1190 | the file name of the MSI file |
| 1191 | persist: int |
| 1192 | the persistence mode |
| 1193 | / |
| 1194 | |
| 1195 | Return a new database object. |
| 1196 | [clinic start generated code]*/ |
| 1197 | |
| 1198 | static PyObject * |
| 1199 | _msi_OpenDatabase_impl(PyObject *module, const Py_UNICODE *path, int persist) |
| 1200 | /*[clinic end generated code: output=d34b7202b745de05 input=1300f3b97659559b]*/ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1201 | { |
| 1202 | int status; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1203 | MSIHANDLE h; |
| 1204 | msiobj *result; |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 1205 | |
Steve Dower | 6ceda63 | 2016-09-09 11:56:34 -0700 | [diff] [blame] | 1206 | /* We need to validate that persist is a valid MSIDBOPEN_* value. Otherwise, |
| 1207 | MsiOpenDatabase may treat the value as a pointer, leading to unexpected |
| 1208 | behavior. */ |
| 1209 | if (Py_INVALID_PERSIST(persist)) |
| 1210 | return msierror(ERROR_INVALID_PARAMETER); |
Serhiy Storchaka | 55939b1 | 2020-06-25 11:37:12 +0300 | [diff] [blame] | 1211 | status = MsiOpenDatabaseW(path, (LPCWSTR)(SIZE_T)persist, &h); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1212 | if (status != ERROR_SUCCESS) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1213 | return msierror(status); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1214 | |
Victor Stinner | 9205520 | 2020-04-08 00:38:15 +0200 | [diff] [blame] | 1215 | result = PyObject_New(struct msiobj, &msidb_Type); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1216 | if (!result) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1217 | MsiCloseHandle(h); |
| 1218 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1219 | } |
| 1220 | result->h = h; |
| 1221 | return (PyObject*)result; |
| 1222 | } |
| 1223 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 1224 | /*[clinic input] |
| 1225 | _msi.CreateRecord |
| 1226 | count: int |
| 1227 | the number of fields of the record |
| 1228 | / |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1229 | |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 1230 | Return a new record object. |
| 1231 | [clinic start generated code]*/ |
| 1232 | |
| 1233 | static PyObject * |
| 1234 | _msi_CreateRecord_impl(PyObject *module, int count) |
| 1235 | /*[clinic end generated code: output=0ba0a00beea3e99e input=53f17d5b5d9b077d]*/ |
| 1236 | { |
| 1237 | MSIHANDLE h; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1238 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1239 | h = MsiCreateRecord(count); |
| 1240 | if (h == 0) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1241 | return msierror(0); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1242 | |
| 1243 | return record_new(h); |
| 1244 | } |
| 1245 | |
| 1246 | |
| 1247 | static PyMethodDef msi_methods[] = { |
Serhiy Storchaka | 5d5c84e | 2020-07-01 21:53:07 +0300 | [diff] [blame^] | 1248 | _MSI_UUIDCREATE_METHODDEF |
| 1249 | _MSI_FCICREATE_METHODDEF |
| 1250 | _MSI_OPENDATABASE_METHODDEF |
| 1251 | _MSI_CREATERECORD_METHODDEF |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1252 | {NULL, NULL} /* sentinel */ |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1253 | }; |
| 1254 | |
| 1255 | static char msi_doc[] = "Documentation"; |
| 1256 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 1257 | |
| 1258 | static struct PyModuleDef _msimodule = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1259 | PyModuleDef_HEAD_INIT, |
| 1260 | "_msi", |
| 1261 | msi_doc, |
| 1262 | -1, |
| 1263 | msi_methods, |
| 1264 | NULL, |
| 1265 | NULL, |
| 1266 | NULL, |
| 1267 | NULL |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 1268 | }; |
| 1269 | |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1270 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 1271 | PyInit__msi(void) |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1272 | { |
| 1273 | PyObject *m; |
| 1274 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 1275 | m = PyModule_Create(&_msimodule); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1276 | if (m == NULL) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1277 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1278 | |
Segev Finer | 679b566 | 2017-07-27 01:17:57 +0300 | [diff] [blame] | 1279 | PyModule_AddIntConstant(m, "MSIDBOPEN_CREATEDIRECT", (long)(SIZE_T)MSIDBOPEN_CREATEDIRECT); |
| 1280 | PyModule_AddIntConstant(m, "MSIDBOPEN_CREATE", (long)(SIZE_T)MSIDBOPEN_CREATE); |
| 1281 | PyModule_AddIntConstant(m, "MSIDBOPEN_DIRECT", (long)(SIZE_T)MSIDBOPEN_DIRECT); |
| 1282 | PyModule_AddIntConstant(m, "MSIDBOPEN_READONLY", (long)(SIZE_T)MSIDBOPEN_READONLY); |
| 1283 | PyModule_AddIntConstant(m, "MSIDBOPEN_TRANSACT", (long)(SIZE_T)MSIDBOPEN_TRANSACT); |
| 1284 | PyModule_AddIntConstant(m, "MSIDBOPEN_PATCHFILE", (long)(SIZE_T)MSIDBOPEN_PATCHFILE); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1285 | |
Charles-Francois Natali | 74ca886 | 2013-05-20 19:13:19 +0200 | [diff] [blame] | 1286 | PyModule_AddIntMacro(m, MSICOLINFO_NAMES); |
| 1287 | PyModule_AddIntMacro(m, MSICOLINFO_TYPES); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1288 | |
Charles-Francois Natali | 74ca886 | 2013-05-20 19:13:19 +0200 | [diff] [blame] | 1289 | PyModule_AddIntMacro(m, MSIMODIFY_SEEK); |
| 1290 | PyModule_AddIntMacro(m, MSIMODIFY_REFRESH); |
| 1291 | PyModule_AddIntMacro(m, MSIMODIFY_INSERT); |
| 1292 | PyModule_AddIntMacro(m, MSIMODIFY_UPDATE); |
| 1293 | PyModule_AddIntMacro(m, MSIMODIFY_ASSIGN); |
| 1294 | PyModule_AddIntMacro(m, MSIMODIFY_REPLACE); |
| 1295 | PyModule_AddIntMacro(m, MSIMODIFY_MERGE); |
| 1296 | PyModule_AddIntMacro(m, MSIMODIFY_DELETE); |
| 1297 | PyModule_AddIntMacro(m, MSIMODIFY_INSERT_TEMPORARY); |
| 1298 | PyModule_AddIntMacro(m, MSIMODIFY_VALIDATE); |
| 1299 | PyModule_AddIntMacro(m, MSIMODIFY_VALIDATE_NEW); |
| 1300 | PyModule_AddIntMacro(m, MSIMODIFY_VALIDATE_FIELD); |
| 1301 | PyModule_AddIntMacro(m, MSIMODIFY_VALIDATE_DELETE); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1302 | |
Charles-Francois Natali | 74ca886 | 2013-05-20 19:13:19 +0200 | [diff] [blame] | 1303 | PyModule_AddIntMacro(m, PID_CODEPAGE); |
| 1304 | PyModule_AddIntMacro(m, PID_TITLE); |
| 1305 | PyModule_AddIntMacro(m, PID_SUBJECT); |
| 1306 | PyModule_AddIntMacro(m, PID_AUTHOR); |
| 1307 | PyModule_AddIntMacro(m, PID_KEYWORDS); |
| 1308 | PyModule_AddIntMacro(m, PID_COMMENTS); |
| 1309 | PyModule_AddIntMacro(m, PID_TEMPLATE); |
| 1310 | PyModule_AddIntMacro(m, PID_LASTAUTHOR); |
| 1311 | PyModule_AddIntMacro(m, PID_REVNUMBER); |
| 1312 | PyModule_AddIntMacro(m, PID_LASTPRINTED); |
| 1313 | PyModule_AddIntMacro(m, PID_CREATE_DTM); |
| 1314 | PyModule_AddIntMacro(m, PID_LASTSAVE_DTM); |
| 1315 | PyModule_AddIntMacro(m, PID_PAGECOUNT); |
| 1316 | PyModule_AddIntMacro(m, PID_WORDCOUNT); |
| 1317 | PyModule_AddIntMacro(m, PID_CHARCOUNT); |
| 1318 | PyModule_AddIntMacro(m, PID_APPNAME); |
| 1319 | PyModule_AddIntMacro(m, PID_SECURITY); |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1320 | |
| 1321 | MSIError = PyErr_NewException ("_msi.MSIError", NULL, NULL); |
| 1322 | if (!MSIError) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 1323 | return NULL; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1324 | PyModule_AddObject(m, "MSIError", MSIError); |
Amaury Forgeot d'Arc | bf9e966 | 2008-06-17 21:39:46 +0000 | [diff] [blame] | 1325 | return m; |
Martin v. Löwis | fbab90e | 2006-03-05 13:36:04 +0000 | [diff] [blame] | 1326 | } |