Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Jack Jansen | 42218ce | 1997-01-31 16:15:11 +0000 | [diff] [blame] | 2 | Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 3 | The Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI or Corporation for National Research Initiatives or |
| 13 | CNRI not be used in advertising or publicity pertaining to |
| 14 | distribution of the software without specific, written prior |
| 15 | permission. |
| 16 | |
| 17 | While CWI is the initial source for this software, a modified version |
| 18 | is made available by the Corporation for National Research Initiatives |
| 19 | (CNRI) at the Internet address ftp://ftp.python.org. |
| 20 | |
| 21 | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
| 22 | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
| 23 | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
| 24 | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
| 25 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 26 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 27 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 28 | PERFORMANCE OF THIS SOFTWARE. |
| 29 | |
| 30 | ******************************************************************/ |
| 31 | |
| 32 | #include "Python.h" |
| 33 | #include "macglue.h" |
| 34 | |
| 35 | extern int ResObj_Convert(PyObject *, Handle *); /* From Resmodule.c */ |
| 36 | |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 37 | #ifdef WITHOUT_FRAMEWORKS |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 38 | // #if !TARGET_API_MAC_OS8 |
| 39 | // /* The Carbon headers define PRAGMA_ALIGN_SUPPORT to something illegal, |
| 40 | // ** because you shouldn't use it for Carbon. All good and well, but portable |
| 41 | // ** code still needs it. So, we undefine it here. |
| 42 | // */ |
| 43 | // #undef PRAGMA_ALIGN_SUPPORTED |
| 44 | // #define PRAGMA_ALIGN_SUPPORTED 0 |
| 45 | // #endif /* !TARGET_API_MAC_OS8 */ |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 46 | |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 47 | // #include "ICAPI.h" |
| 48 | #include <InternetConfig.h> |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 49 | #else |
| 50 | #include <Carbon/Carbon.h> |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 51 | #endif |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 52 | |
| 53 | static PyObject *ErrorObject; |
| 54 | |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 55 | /* ----------------------------------------------------- */ |
| 56 | |
| 57 | /* Declarations for objects of type ic_instance */ |
| 58 | |
| 59 | typedef struct { |
| 60 | PyObject_HEAD |
| 61 | ICInstance inst; |
| 62 | } iciobject; |
| 63 | |
Jeremy Hylton | 938ace6 | 2002-07-17 16:30:39 +0000 | [diff] [blame] | 64 | static PyTypeObject Icitype; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 65 | |
| 66 | |
| 67 | |
| 68 | /* ---------------------------------------------------------------- */ |
| 69 | |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 70 | #if TARGET_API_MAC_OS8 |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 71 | static char ici_ICFindConfigFile__doc__[] = |
| 72 | "()->None; Find config file in standard places" |
| 73 | ; |
| 74 | |
| 75 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 76 | ici_ICFindConfigFile(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 77 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 78 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 79 | |
| 80 | if (!PyArg_ParseTuple(args, "")) |
| 81 | return NULL; |
| 82 | if ((err=ICFindConfigFile(self->inst, 0, NULL)) != 0 ) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 83 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 84 | Py_INCREF(Py_None); |
| 85 | return Py_None; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | static char ici_ICFindUserConfigFile__doc__[] = |
| 90 | "(vRefNum, dirID)->None; Find config file in specified place" |
| 91 | ; |
| 92 | |
| 93 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 94 | ici_ICFindUserConfigFile(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 95 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 96 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 97 | ICDirSpec where; |
| 98 | |
| 99 | if (!PyArg_ParseTuple(args, "sl", &where.vRefNum, &where.dirID)) |
| 100 | return NULL; |
| 101 | if ((err=ICFindUserConfigFile(self->inst, &where)) != 0 ) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 102 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 103 | Py_INCREF(Py_None); |
| 104 | return Py_None; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | static char ici_ICChooseConfig__doc__[] = |
| 109 | "()->None; Let the user choose a config file" |
| 110 | ; |
| 111 | |
| 112 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 113 | ici_ICChooseConfig(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 114 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 115 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 116 | |
| 117 | if (!PyArg_ParseTuple(args, "")) |
| 118 | return NULL; |
| 119 | if ((err=ICChooseConfig(self->inst)) != 0 ) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 120 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 121 | Py_INCREF(Py_None); |
| 122 | return Py_None; |
| 123 | } |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 124 | |
| 125 | static char ici_ICChooseNewConfig__doc__[] = |
| 126 | "()->None; Let the user choose a new config file" |
| 127 | ; |
| 128 | |
| 129 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 130 | ici_ICChooseNewConfig(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 131 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 132 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 133 | |
| 134 | if (!PyArg_ParseTuple(args, "")) |
| 135 | return NULL; |
| 136 | if ((err=ICChooseNewConfig(self->inst)) != 0 ) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 137 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 138 | Py_INCREF(Py_None); |
| 139 | return Py_None; |
| 140 | } |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 141 | #endif /* TARGET_API_MAC_OS8 */ |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 142 | |
| 143 | |
| 144 | static char ici_ICGetSeed__doc__[] = |
| 145 | "()->int; Returns int that changes when configuration does" |
| 146 | ; |
| 147 | |
| 148 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 149 | ici_ICGetSeed(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 150 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 151 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 152 | long seed; |
| 153 | |
| 154 | if (!PyArg_ParseTuple(args, "")) |
| 155 | return NULL; |
| 156 | if ((err=ICGetSeed(self->inst, &seed)) != 0 ) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 157 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 158 | return Py_BuildValue("i", (int)seed); |
| 159 | } |
| 160 | |
| 161 | |
| 162 | static char ici_ICBegin__doc__[] = |
| 163 | "(perm)->None; Lock config file for read/write" |
| 164 | ; |
| 165 | |
| 166 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 167 | ici_ICBegin(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 168 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 169 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 170 | int perm; |
| 171 | |
| 172 | if (!PyArg_ParseTuple(args, "i", &perm)) |
| 173 | return NULL; |
| 174 | if ((err=ICBegin(self->inst, (ICPerm)perm)) != 0 ) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 175 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 176 | Py_INCREF(Py_None); |
| 177 | return Py_None; |
| 178 | } |
| 179 | |
| 180 | |
| 181 | static char ici_ICFindPrefHandle__doc__[] = |
| 182 | "(key, handle)->attrs; Lookup key, store result in handle, return attributes" |
| 183 | ; |
| 184 | |
| 185 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 186 | ici_ICFindPrefHandle(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 187 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 188 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 189 | Str255 key; |
| 190 | ICAttr attr; |
| 191 | Handle h; |
| 192 | |
| 193 | if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetStr255, &key, ResObj_Convert, &h)) |
| 194 | return NULL; |
| 195 | if ((err=ICFindPrefHandle(self->inst, key, &attr, h)) != 0 ) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 196 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 197 | return Py_BuildValue("i", (int)attr); |
| 198 | } |
| 199 | |
| 200 | |
| 201 | static char ici_ICSetPref__doc__[] = |
| 202 | "(key, attr, data)->None; Set preference key to data with attributes" |
| 203 | ; |
| 204 | |
| 205 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 206 | ici_ICSetPref(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 207 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 208 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 209 | Str255 key; |
| 210 | int attr; |
| 211 | char *data; |
| 212 | int datalen; |
| 213 | |
| 214 | if (!PyArg_ParseTuple(args, "O&is#", PyMac_GetStr255, &key, &attr, |
| 215 | &data, &datalen)) |
| 216 | return NULL; |
| 217 | if ((err=ICSetPref(self->inst, key, (ICAttr)attr, (Ptr)data, |
| 218 | (long)datalen)) != 0) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 219 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 220 | Py_INCREF(Py_None); |
| 221 | return Py_None; |
| 222 | } |
| 223 | |
| 224 | |
| 225 | static char ici_ICCountPref__doc__[] = |
| 226 | "()->int; Return number of preferences" |
| 227 | ; |
| 228 | |
| 229 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 230 | ici_ICCountPref(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 231 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 232 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 233 | long count; |
| 234 | |
| 235 | if (!PyArg_ParseTuple(args, "")) |
| 236 | return NULL; |
| 237 | if ((err=ICCountPref(self->inst, &count)) != 0 ) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 238 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 239 | return Py_BuildValue("i", (int)count); |
| 240 | } |
| 241 | |
| 242 | |
| 243 | static char ici_ICGetIndPref__doc__[] = |
| 244 | "(num)->key; Return key of preference with given index" |
| 245 | ; |
| 246 | |
| 247 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 248 | ici_ICGetIndPref(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 249 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 250 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 251 | long num; |
| 252 | Str255 key; |
| 253 | |
| 254 | if (!PyArg_ParseTuple(args, "l", &num)) |
| 255 | return NULL; |
| 256 | if ((err=ICGetIndPref(self->inst, num, key)) != 0 ) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 257 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 258 | return Py_BuildValue("O&", PyMac_BuildStr255, key); |
| 259 | } |
| 260 | |
| 261 | |
| 262 | static char ici_ICDeletePref__doc__[] = |
| 263 | "(key)->None; Delete preference" |
| 264 | ; |
| 265 | |
| 266 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 267 | ici_ICDeletePref(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 268 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 269 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 270 | Str255 key; |
| 271 | |
| 272 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, key)) |
| 273 | return NULL; |
| 274 | if ((err=ICDeletePref(self->inst, key)) != 0 ) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 275 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 276 | Py_INCREF(Py_None); |
| 277 | return Py_None; |
| 278 | } |
| 279 | |
| 280 | |
| 281 | static char ici_ICEnd__doc__[] = |
| 282 | "()->None; Unlock file after ICBegin call" |
| 283 | ; |
| 284 | |
| 285 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 286 | ici_ICEnd(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 287 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 288 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 289 | |
| 290 | if (!PyArg_ParseTuple(args, "")) |
| 291 | return NULL; |
| 292 | if ((err=ICEnd(self->inst)) != 0 ) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 293 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 294 | Py_INCREF(Py_None); |
| 295 | return Py_None; |
| 296 | } |
| 297 | |
| 298 | |
| 299 | static char ici_ICEditPreferences__doc__[] = |
| 300 | "(key)->None; Ask user to edit preferences, staring with key" |
| 301 | ; |
| 302 | |
| 303 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 304 | ici_ICEditPreferences(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 305 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 306 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 307 | Str255 key; |
| 308 | |
| 309 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, key)) |
| 310 | return NULL; |
| 311 | if ((err=ICEditPreferences(self->inst, key)) != 0 ) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 312 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 313 | Py_INCREF(Py_None); |
| 314 | return Py_None; |
| 315 | } |
| 316 | |
| 317 | |
| 318 | static char ici_ICParseURL__doc__[] = |
| 319 | "(hint, data, selStart, selEnd, handle)->selStart, selEnd; Find an URL, return in handle" |
| 320 | ; |
| 321 | |
| 322 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 323 | ici_ICParseURL(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 324 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 325 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 326 | Str255 hint; |
| 327 | char *data; |
| 328 | int datalen; |
| 329 | long selStart, selEnd; |
| 330 | Handle h; |
| 331 | |
| 332 | if (!PyArg_ParseTuple(args, "O&s#llO&", PyMac_GetStr255, hint, &data, &datalen, |
| 333 | &selStart, &selEnd, ResObj_Convert, &h)) |
| 334 | return NULL; |
| 335 | if ((err=ICParseURL(self->inst, hint, (Ptr)data, (long)datalen, |
| 336 | &selStart, &selEnd, h)) != 0 ) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 337 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 338 | return Py_BuildValue("ii", (int)selStart, (int)selEnd); |
| 339 | } |
| 340 | |
| 341 | |
| 342 | static char ici_ICLaunchURL__doc__[] = |
| 343 | "(hint, data, selStart, selEnd)->None; Find an URL and launch the correct app" |
| 344 | ; |
| 345 | |
| 346 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 347 | ici_ICLaunchURL(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 348 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 349 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 350 | Str255 hint; |
| 351 | char *data; |
| 352 | int datalen; |
| 353 | long selStart, selEnd; |
| 354 | |
| 355 | if (!PyArg_ParseTuple(args, "O&s#ll", PyMac_GetStr255, hint, &data, &datalen, |
| 356 | &selStart, &selEnd)) |
| 357 | return NULL; |
| 358 | if ((err=ICLaunchURL(self->inst, hint, (Ptr)data, (long)datalen, |
| 359 | &selStart, &selEnd)) != 0 ) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 360 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 361 | return Py_BuildValue("ii", (int)selStart, (int)selEnd); |
| 362 | } |
| 363 | |
| 364 | |
| 365 | static char ici_ICMapFilename__doc__[] = |
| 366 | "(filename)->mapinfo; Get filemap info for given filename" |
| 367 | ; |
| 368 | |
| 369 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 370 | ici_ICMapFilename(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 371 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 372 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 373 | Str255 filename; |
| 374 | ICMapEntry entry; |
| 375 | |
| 376 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, filename)) |
| 377 | return NULL; |
| 378 | if ((err=ICMapFilename(self->inst, filename, &entry)) != 0 ) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 379 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 380 | return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry.version, |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 381 | PyMac_BuildOSType, entry.fileType, |
| 382 | PyMac_BuildOSType, entry.fileCreator, |
| 383 | PyMac_BuildOSType, entry.postCreator, |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 384 | entry.flags, |
| 385 | PyMac_BuildStr255, entry.extension, |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 386 | PyMac_BuildStr255, entry.creatorAppName, |
| 387 | PyMac_BuildStr255, entry.postAppName, |
| 388 | PyMac_BuildStr255, entry.MIMEType, |
| 389 | PyMac_BuildStr255, entry.entryName); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | |
| 393 | static char ici_ICMapTypeCreator__doc__[] = |
| 394 | "(type, creator, filename)->mapinfo; Get filemap info for given tp/cr/filename" |
| 395 | ; |
| 396 | |
| 397 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 398 | ici_ICMapTypeCreator(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 399 | { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 400 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 401 | OSType type, creator; |
| 402 | Str255 filename; |
| 403 | ICMapEntry entry; |
| 404 | |
| 405 | if (!PyArg_ParseTuple(args, "O&O&O&", |
| 406 | PyMac_GetOSType, &type, |
| 407 | PyMac_GetOSType, &creator, |
| 408 | PyMac_GetStr255, filename)) |
| 409 | return NULL; |
| 410 | if ((err=ICMapTypeCreator(self->inst, type, creator, filename, &entry)) != 0 ) |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 411 | return PyMac_Error(err); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 412 | return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry.version, |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 413 | PyMac_BuildOSType, entry.fileType, |
| 414 | PyMac_BuildOSType, entry.fileCreator, |
| 415 | PyMac_BuildOSType, entry.postCreator, |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 416 | entry.flags, |
| 417 | PyMac_BuildStr255, entry.extension, |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 418 | PyMac_BuildStr255, entry.creatorAppName, |
| 419 | PyMac_BuildStr255, entry.postAppName, |
| 420 | PyMac_BuildStr255, entry.MIMEType, |
| 421 | PyMac_BuildStr255, entry.entryName); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | |
| 425 | static struct PyMethodDef ici_methods[] = { |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 426 | #if TARGET_API_MAC_OS8 |
Jack Jansen | 5a8115c | 2001-01-29 13:27:46 +0000 | [diff] [blame] | 427 | {"ICFindConfigFile", (PyCFunction)ici_ICFindConfigFile, METH_VARARGS, ici_ICFindConfigFile__doc__}, |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 428 | {"ICFindUserConfigFile", (PyCFunction)ici_ICFindUserConfigFile, METH_VARARGS, ici_ICFindUserConfigFile__doc__}, |
| 429 | {"ICChooseConfig", (PyCFunction)ici_ICChooseConfig, METH_VARARGS, ici_ICChooseConfig__doc__}, |
| 430 | {"ICChooseNewConfig", (PyCFunction)ici_ICChooseNewConfig, METH_VARARGS, ici_ICChooseNewConfig__doc__}, |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 431 | #endif /* TARGET_API_MAC_OS8 */ |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 432 | {"ICGetSeed", (PyCFunction)ici_ICGetSeed, METH_VARARGS, ici_ICGetSeed__doc__}, |
| 433 | {"ICBegin", (PyCFunction)ici_ICBegin, METH_VARARGS, ici_ICBegin__doc__}, |
| 434 | {"ICFindPrefHandle", (PyCFunction)ici_ICFindPrefHandle, METH_VARARGS, ici_ICFindPrefHandle__doc__}, |
| 435 | {"ICSetPref", (PyCFunction)ici_ICSetPref, METH_VARARGS, ici_ICSetPref__doc__}, |
| 436 | {"ICCountPref", (PyCFunction)ici_ICCountPref, METH_VARARGS, ici_ICCountPref__doc__}, |
| 437 | {"ICGetIndPref", (PyCFunction)ici_ICGetIndPref, METH_VARARGS, ici_ICGetIndPref__doc__}, |
| 438 | {"ICDeletePref", (PyCFunction)ici_ICDeletePref, METH_VARARGS, ici_ICDeletePref__doc__}, |
| 439 | {"ICEnd", (PyCFunction)ici_ICEnd, METH_VARARGS, ici_ICEnd__doc__}, |
| 440 | {"ICEditPreferences", (PyCFunction)ici_ICEditPreferences, METH_VARARGS, ici_ICEditPreferences__doc__}, |
| 441 | {"ICParseURL", (PyCFunction)ici_ICParseURL, METH_VARARGS, ici_ICParseURL__doc__}, |
| 442 | {"ICLaunchURL", (PyCFunction)ici_ICLaunchURL, METH_VARARGS, ici_ICLaunchURL__doc__}, |
| 443 | {"ICMapFilename", (PyCFunction)ici_ICMapFilename, METH_VARARGS, ici_ICMapFilename__doc__}, |
| 444 | {"ICMapTypeCreator", (PyCFunction)ici_ICMapTypeCreator, METH_VARARGS, ici_ICMapTypeCreator__doc__}, |
| 445 | |
| 446 | {NULL, NULL} /* sentinel */ |
| 447 | }; |
| 448 | |
| 449 | /* ---------- */ |
| 450 | |
| 451 | |
| 452 | static iciobject * |
| 453 | newiciobject(OSType creator) |
| 454 | { |
| 455 | iciobject *self; |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 456 | OSStatus err; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 457 | |
| 458 | self = PyObject_NEW(iciobject, &Icitype); |
| 459 | if (self == NULL) |
| 460 | return NULL; |
| 461 | if ((err=ICStart(&self->inst, creator)) != 0 ) { |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 462 | (void)PyMac_Error(err); |
Jack Jansen | 0e2f798 | 2002-05-22 14:31:48 +0000 | [diff] [blame] | 463 | PyObject_DEL(self); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 464 | return NULL; |
| 465 | } |
| 466 | return self; |
| 467 | } |
| 468 | |
| 469 | |
| 470 | static void |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 471 | ici_dealloc(iciobject *self) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 472 | { |
| 473 | (void)ICStop(self->inst); |
Jack Jansen | 0e2f798 | 2002-05-22 14:31:48 +0000 | [diff] [blame] | 474 | PyObject_DEL(self); |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 478 | ici_getattr(iciobject *self, char *name) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 479 | { |
| 480 | return Py_FindMethod(ici_methods, (PyObject *)self, name); |
| 481 | } |
| 482 | |
| 483 | static char Icitype__doc__[] = |
| 484 | "Internet Config instance" |
| 485 | ; |
| 486 | |
| 487 | static PyTypeObject Icitype = { |
| 488 | PyObject_HEAD_INIT(&PyType_Type) |
| 489 | 0, /*ob_size*/ |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame] | 490 | "icglue.ic_instance", /*tp_name*/ |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 491 | sizeof(iciobject), /*tp_basicsize*/ |
| 492 | 0, /*tp_itemsize*/ |
| 493 | /* methods */ |
| 494 | (destructor)ici_dealloc, /*tp_dealloc*/ |
| 495 | (printfunc)0, /*tp_print*/ |
| 496 | (getattrfunc)ici_getattr, /*tp_getattr*/ |
| 497 | (setattrfunc)0, /*tp_setattr*/ |
| 498 | (cmpfunc)0, /*tp_compare*/ |
| 499 | (reprfunc)0, /*tp_repr*/ |
| 500 | 0, /*tp_as_number*/ |
| 501 | 0, /*tp_as_sequence*/ |
| 502 | 0, /*tp_as_mapping*/ |
| 503 | (hashfunc)0, /*tp_hash*/ |
| 504 | (ternaryfunc)0, /*tp_call*/ |
| 505 | (reprfunc)0, /*tp_str*/ |
| 506 | |
| 507 | /* Space for future expansion */ |
| 508 | 0L,0L,0L,0L, |
| 509 | Icitype__doc__ /* Documentation string */ |
| 510 | }; |
| 511 | |
| 512 | /* End of code for ic_instance objects */ |
| 513 | /* -------------------------------------------------------- */ |
| 514 | |
| 515 | |
| 516 | static char ic_ICStart__doc__[] = |
| 517 | "(OSType)->ic_instance; Create an Internet Config instance" |
| 518 | ; |
| 519 | |
| 520 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 521 | ic_ICStart(PyObject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 522 | { |
| 523 | OSType creator; |
| 524 | |
| 525 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &creator)) |
| 526 | return NULL; |
| 527 | return (PyObject *)newiciobject(creator); |
| 528 | } |
| 529 | |
| 530 | /* List of methods defined in the module */ |
| 531 | |
| 532 | static struct PyMethodDef ic_methods[] = { |
| 533 | {"ICStart", (PyCFunction)ic_ICStart, METH_VARARGS, ic_ICStart__doc__}, |
| 534 | |
| 535 | {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */ |
| 536 | }; |
| 537 | |
| 538 | |
| 539 | /* Initialization function for the module (*must* be called initicglue) */ |
| 540 | |
| 541 | static char icglue_module_documentation[] = |
| 542 | "Implements low-level Internet Config interface" |
| 543 | ; |
| 544 | |
| 545 | void |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 546 | initicglue(void) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 547 | { |
| 548 | PyObject *m, *d; |
| 549 | |
| 550 | /* Create the module and add the functions */ |
| 551 | m = Py_InitModule4("icglue", ic_methods, |
| 552 | icglue_module_documentation, |
| 553 | (PyObject*)NULL,PYTHON_API_VERSION); |
| 554 | |
| 555 | /* Add some symbolic constants to the module */ |
| 556 | d = PyModule_GetDict(m); |
Jack Jansen | 8f54f2a | 2002-01-11 12:38:08 +0000 | [diff] [blame] | 557 | ErrorObject = PyMac_GetOSErrException(); |
| 558 | if (ErrorObject == NULL || |
| 559 | PyDict_SetItemString(d, "error", ErrorObject) != 0) |
| 560 | return; |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 561 | |
| 562 | /* XXXX Add constants here */ |
| 563 | |
| 564 | /* Check for errors */ |
| 565 | if (PyErr_Occurred()) |
| 566 | Py_FatalError("can't initialize module icglue"); |
| 567 | } |
| 568 | |