blob: 3061f9827f8bb4cbe77939eceb0f0ba9619c331b [file] [log] [blame]
Jack Jansen8ce72f51997-01-07 16:18:32 +00001/***********************************************************
Jack Jansen42218ce1997-01-31 16:15:11 +00002Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
Jack Jansen8ce72f51997-01-07 16:18:32 +00003The Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI or Corporation for National Research Initiatives or
13CNRI not be used in advertising or publicity pertaining to
14distribution of the software without specific, written prior
15permission.
16
17While CWI is the initial source for this software, a modified version
18is made available by the Corporation for National Research Initiatives
19(CNRI) at the Internet address ftp://ftp.python.org.
20
21STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28PERFORMANCE OF THIS SOFTWARE.
29
30******************************************************************/
31
32#include "Python.h"
33#include "macglue.h"
34
35extern int ResObj_Convert(PyObject *, Handle *); /* From Resmodule.c */
36
Jack Jansen6143d532001-05-19 12:34:59 +000037#ifdef WITHOUT_FRAMEWORKS
Jack Jansen8f54f2a2002-01-11 12:38:08 +000038// #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 Jansen8ce72f51997-01-07 16:18:32 +000046
Jack Jansen8f54f2a2002-01-11 12:38:08 +000047// #include "ICAPI.h"
48#include <InternetConfig.h>
Jack Jansen6143d532001-05-19 12:34:59 +000049#else
50#include <Carbon/Carbon.h>
Jack Jansen6143d532001-05-19 12:34:59 +000051#endif
Jack Jansen8ce72f51997-01-07 16:18:32 +000052
53static PyObject *ErrorObject;
54
Jack Jansen8ce72f51997-01-07 16:18:32 +000055/* ----------------------------------------------------- */
56
57/* Declarations for objects of type ic_instance */
58
59typedef struct {
60 PyObject_HEAD
61 ICInstance inst;
62} iciobject;
63
64staticforward PyTypeObject Icitype;
65
66
67
68/* ---------------------------------------------------------------- */
69
Jack Jansen6143d532001-05-19 12:34:59 +000070#if TARGET_API_MAC_OS8
Jack Jansen8ce72f51997-01-07 16:18:32 +000071static char ici_ICFindConfigFile__doc__[] =
72"()->None; Find config file in standard places"
73;
74
75static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +000076ici_ICFindConfigFile(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +000077{
Jack Jansen8f54f2a2002-01-11 12:38:08 +000078 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +000079
80 if (!PyArg_ParseTuple(args, ""))
81 return NULL;
82 if ((err=ICFindConfigFile(self->inst, 0, NULL)) != 0 )
Jack Jansen8f54f2a2002-01-11 12:38:08 +000083 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +000084 Py_INCREF(Py_None);
85 return Py_None;
86}
87
88
89static char ici_ICFindUserConfigFile__doc__[] =
90"(vRefNum, dirID)->None; Find config file in specified place"
91;
92
93static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +000094ici_ICFindUserConfigFile(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +000095{
Jack Jansen8f54f2a2002-01-11 12:38:08 +000096 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +000097 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 Jansen8f54f2a2002-01-11 12:38:08 +0000102 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000103 Py_INCREF(Py_None);
104 return Py_None;
105}
106
107
108static char ici_ICChooseConfig__doc__[] =
109"()->None; Let the user choose a config file"
110;
111
112static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000113ici_ICChooseConfig(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000114{
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000115 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000116
117 if (!PyArg_ParseTuple(args, ""))
118 return NULL;
119 if ((err=ICChooseConfig(self->inst)) != 0 )
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000120 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000121 Py_INCREF(Py_None);
122 return Py_None;
123}
Jack Jansen8ce72f51997-01-07 16:18:32 +0000124
125static char ici_ICChooseNewConfig__doc__[] =
126"()->None; Let the user choose a new config file"
127;
128
129static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000130ici_ICChooseNewConfig(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000131{
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000132 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000133
134 if (!PyArg_ParseTuple(args, ""))
135 return NULL;
136 if ((err=ICChooseNewConfig(self->inst)) != 0 )
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000137 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000138 Py_INCREF(Py_None);
139 return Py_None;
140}
Jack Jansen6143d532001-05-19 12:34:59 +0000141#endif /* TARGET_API_MAC_OS8 */
Jack Jansen8ce72f51997-01-07 16:18:32 +0000142
143
144static char ici_ICGetSeed__doc__[] =
145"()->int; Returns int that changes when configuration does"
146;
147
148static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000149ici_ICGetSeed(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000150{
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000151 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000152 long seed;
153
154 if (!PyArg_ParseTuple(args, ""))
155 return NULL;
156 if ((err=ICGetSeed(self->inst, &seed)) != 0 )
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000157 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000158 return Py_BuildValue("i", (int)seed);
159}
160
161
162static char ici_ICBegin__doc__[] =
163"(perm)->None; Lock config file for read/write"
164;
165
166static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000167ici_ICBegin(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000168{
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000169 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000170 int perm;
171
172 if (!PyArg_ParseTuple(args, "i", &perm))
173 return NULL;
174 if ((err=ICBegin(self->inst, (ICPerm)perm)) != 0 )
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000175 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000176 Py_INCREF(Py_None);
177 return Py_None;
178}
179
180
181static char ici_ICFindPrefHandle__doc__[] =
182"(key, handle)->attrs; Lookup key, store result in handle, return attributes"
183;
184
185static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000186ici_ICFindPrefHandle(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000187{
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000188 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000189 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 Jansen8f54f2a2002-01-11 12:38:08 +0000196 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000197 return Py_BuildValue("i", (int)attr);
198}
199
200
201static char ici_ICSetPref__doc__[] =
202"(key, attr, data)->None; Set preference key to data with attributes"
203;
204
205static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000206ici_ICSetPref(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000207{
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000208 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000209 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 Jansen8f54f2a2002-01-11 12:38:08 +0000219 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000220 Py_INCREF(Py_None);
221 return Py_None;
222}
223
224
225static char ici_ICCountPref__doc__[] =
226"()->int; Return number of preferences"
227;
228
229static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000230ici_ICCountPref(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000231{
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000232 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000233 long count;
234
235 if (!PyArg_ParseTuple(args, ""))
236 return NULL;
237 if ((err=ICCountPref(self->inst, &count)) != 0 )
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000238 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000239 return Py_BuildValue("i", (int)count);
240}
241
242
243static char ici_ICGetIndPref__doc__[] =
244"(num)->key; Return key of preference with given index"
245;
246
247static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000248ici_ICGetIndPref(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000249{
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000250 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000251 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 Jansen8f54f2a2002-01-11 12:38:08 +0000257 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000258 return Py_BuildValue("O&", PyMac_BuildStr255, key);
259}
260
261
262static char ici_ICDeletePref__doc__[] =
263"(key)->None; Delete preference"
264;
265
266static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000267ici_ICDeletePref(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000268{
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000269 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000270 Str255 key;
271
272 if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, key))
273 return NULL;
274 if ((err=ICDeletePref(self->inst, key)) != 0 )
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000275 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000276 Py_INCREF(Py_None);
277 return Py_None;
278}
279
280
281static char ici_ICEnd__doc__[] =
282"()->None; Unlock file after ICBegin call"
283;
284
285static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000286ici_ICEnd(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000287{
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000288 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000289
290 if (!PyArg_ParseTuple(args, ""))
291 return NULL;
292 if ((err=ICEnd(self->inst)) != 0 )
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000293 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000294 Py_INCREF(Py_None);
295 return Py_None;
296}
297
298
299static char ici_ICEditPreferences__doc__[] =
300"(key)->None; Ask user to edit preferences, staring with key"
301;
302
303static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000304ici_ICEditPreferences(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000305{
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000306 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000307 Str255 key;
308
309 if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, key))
310 return NULL;
311 if ((err=ICEditPreferences(self->inst, key)) != 0 )
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000312 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000313 Py_INCREF(Py_None);
314 return Py_None;
315}
316
317
318static char ici_ICParseURL__doc__[] =
319"(hint, data, selStart, selEnd, handle)->selStart, selEnd; Find an URL, return in handle"
320;
321
322static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000323ici_ICParseURL(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000324{
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000325 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000326 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 Jansen8f54f2a2002-01-11 12:38:08 +0000337 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000338 return Py_BuildValue("ii", (int)selStart, (int)selEnd);
339}
340
341
342static char ici_ICLaunchURL__doc__[] =
343"(hint, data, selStart, selEnd)->None; Find an URL and launch the correct app"
344;
345
346static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000347ici_ICLaunchURL(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000348{
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000349 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000350 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 Jansen8f54f2a2002-01-11 12:38:08 +0000360 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000361 return Py_BuildValue("ii", (int)selStart, (int)selEnd);
362}
363
364
365static char ici_ICMapFilename__doc__[] =
366"(filename)->mapinfo; Get filemap info for given filename"
367;
368
369static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000370ici_ICMapFilename(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000371{
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000372 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000373 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 Jansen8f54f2a2002-01-11 12:38:08 +0000379 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000380 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry.version,
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000381 PyMac_BuildOSType, entry.fileType,
382 PyMac_BuildOSType, entry.fileCreator,
383 PyMac_BuildOSType, entry.postCreator,
Jack Jansen8ce72f51997-01-07 16:18:32 +0000384 entry.flags,
385 PyMac_BuildStr255, entry.extension,
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000386 PyMac_BuildStr255, entry.creatorAppName,
387 PyMac_BuildStr255, entry.postAppName,
388 PyMac_BuildStr255, entry.MIMEType,
389 PyMac_BuildStr255, entry.entryName);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000390}
391
392
393static char ici_ICMapTypeCreator__doc__[] =
394"(type, creator, filename)->mapinfo; Get filemap info for given tp/cr/filename"
395;
396
397static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000398ici_ICMapTypeCreator(iciobject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000399{
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000400 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000401 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 Jansen8f54f2a2002-01-11 12:38:08 +0000411 return PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000412 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry.version,
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000413 PyMac_BuildOSType, entry.fileType,
414 PyMac_BuildOSType, entry.fileCreator,
415 PyMac_BuildOSType, entry.postCreator,
Jack Jansen8ce72f51997-01-07 16:18:32 +0000416 entry.flags,
417 PyMac_BuildStr255, entry.extension,
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000418 PyMac_BuildStr255, entry.creatorAppName,
419 PyMac_BuildStr255, entry.postAppName,
420 PyMac_BuildStr255, entry.MIMEType,
421 PyMac_BuildStr255, entry.entryName);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000422}
423
424
425static struct PyMethodDef ici_methods[] = {
Jack Jansen6143d532001-05-19 12:34:59 +0000426#if TARGET_API_MAC_OS8
Jack Jansen5a8115c2001-01-29 13:27:46 +0000427 {"ICFindConfigFile", (PyCFunction)ici_ICFindConfigFile, METH_VARARGS, ici_ICFindConfigFile__doc__},
Jack Jansen8ce72f51997-01-07 16:18:32 +0000428 {"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 Jansen6143d532001-05-19 12:34:59 +0000431#endif /* TARGET_API_MAC_OS8 */
Jack Jansen8ce72f51997-01-07 16:18:32 +0000432 {"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
452static iciobject *
453newiciobject(OSType creator)
454{
455 iciobject *self;
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000456 OSStatus err;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000457
458 self = PyObject_NEW(iciobject, &Icitype);
459 if (self == NULL)
460 return NULL;
461 if ((err=ICStart(&self->inst, creator)) != 0 ) {
Jack Jansen8f54f2a2002-01-11 12:38:08 +0000462 (void)PyMac_Error(err);
Jack Jansen8ce72f51997-01-07 16:18:32 +0000463 PyMem_DEL(self);
464 return NULL;
465 }
466 return self;
467}
468
469
470static void
Jack Jansen1767f932001-09-04 22:20:39 +0000471ici_dealloc(iciobject *self)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000472{
473 (void)ICStop(self->inst);
474 PyMem_DEL(self);
475}
476
477static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000478ici_getattr(iciobject *self, char *name)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000479{
480 return Py_FindMethod(ici_methods, (PyObject *)self, name);
481}
482
483static char Icitype__doc__[] =
484"Internet Config instance"
485;
486
487static PyTypeObject Icitype = {
488 PyObject_HEAD_INIT(&PyType_Type)
489 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +0000490 "icglue.ic_instance", /*tp_name*/
Jack Jansen8ce72f51997-01-07 16:18:32 +0000491 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
516static char ic_ICStart__doc__[] =
517"(OSType)->ic_instance; Create an Internet Config instance"
518;
519
520static PyObject *
Jack Jansen1767f932001-09-04 22:20:39 +0000521ic_ICStart(PyObject *self, PyObject *args)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000522{
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
532static 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
541static char icglue_module_documentation[] =
542"Implements low-level Internet Config interface"
543;
544
545void
Jack Jansen1767f932001-09-04 22:20:39 +0000546initicglue(void)
Jack Jansen8ce72f51997-01-07 16:18:32 +0000547{
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 Jansen8f54f2a2002-01-11 12:38:08 +0000557 ErrorObject = PyMac_GetOSErrException();
558 if (ErrorObject == NULL ||
559 PyDict_SetItemString(d, "error", ErrorObject) != 0)
560 return;
Jack Jansen8ce72f51997-01-07 16:18:32 +0000561
562 /* XXXX Add constants here */
563
564 /* Check for errors */
565 if (PyErr_Occurred())
566 Py_FatalError("can't initialize module icglue");
567}
568