1 /***********************************************************
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
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
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.
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.
30 ******************************************************************/
35 extern int ResObj_Convert(PyObject
*, Handle
*); /* From Resmodule.c */
37 #ifdef WITHOUT_FRAMEWORKS
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.
43 #undef PRAGMA_ALIGN_SUPPORTED
44 #define PRAGMA_ALIGN_SUPPORTED 0
45 #endif /* !TARGET_API_MAC_OS8 */
49 #include <Carbon/Carbon.h>
50 typedef OSStatus ICError
;
51 /* Some fields in ICMapEntry have changed names. */
52 #define file_type fileType
53 #define file_creator fileCreator
54 #define post_creator postCreator
55 #define creator_app_name creatorAppName
56 #define post_app_name postAppName
57 #define MIME_type MIMEType
58 #define entry_name entryName
61 static PyObject
*ErrorObject
;
64 ici_error(ICError err
)
66 PyErr_SetObject(ErrorObject
, PyInt_FromLong((long)err
));
70 /* ----------------------------------------------------- */
72 /* Declarations for objects of type ic_instance */
79 staticforward PyTypeObject Icitype
;
83 /* ---------------------------------------------------------------- */
85 #if TARGET_API_MAC_OS8
86 static char ici_ICFindConfigFile__doc__
[] =
87 "()->None; Find config file in standard places"
91 ici_ICFindConfigFile(self
, args
)
97 if (!PyArg_ParseTuple(args
, ""))
99 if ((err
=ICFindConfigFile(self
->inst
, 0, NULL
)) != 0 )
100 return ici_error(err
);
106 static char ici_ICFindUserConfigFile__doc__
[] =
107 "(vRefNum, dirID)->None; Find config file in specified place"
111 ici_ICFindUserConfigFile(self
, args
)
118 if (!PyArg_ParseTuple(args
, "sl", &where
.vRefNum
, &where
.dirID
))
120 if ((err
=ICFindUserConfigFile(self
->inst
, &where
)) != 0 )
121 return ici_error(err
);
127 static char ici_ICChooseConfig__doc__
[] =
128 "()->None; Let the user choose a config file"
132 ici_ICChooseConfig(self
, args
)
138 if (!PyArg_ParseTuple(args
, ""))
140 if ((err
=ICChooseConfig(self
->inst
)) != 0 )
141 return ici_error(err
);
146 static char ici_ICChooseNewConfig__doc__
[] =
147 "()->None; Let the user choose a new config file"
151 ici_ICChooseNewConfig(self
, args
)
157 if (!PyArg_ParseTuple(args
, ""))
159 if ((err
=ICChooseNewConfig(self
->inst
)) != 0 )
160 return ici_error(err
);
164 #endif /* TARGET_API_MAC_OS8 */
167 static char ici_ICGetSeed__doc__
[] =
168 "()->int; Returns int that changes when configuration does"
172 ici_ICGetSeed(self
, args
)
179 if (!PyArg_ParseTuple(args
, ""))
181 if ((err
=ICGetSeed(self
->inst
, &seed
)) != 0 )
182 return ici_error(err
);
183 return Py_BuildValue("i", (int)seed
);
187 static char ici_ICBegin__doc__
[] =
188 "(perm)->None; Lock config file for read/write"
192 ici_ICBegin(self
, args
)
199 if (!PyArg_ParseTuple(args
, "i", &perm
))
201 if ((err
=ICBegin(self
->inst
, (ICPerm
)perm
)) != 0 )
202 return ici_error(err
);
208 static char ici_ICFindPrefHandle__doc__
[] =
209 "(key, handle)->attrs; Lookup key, store result in handle, return attributes"
213 ici_ICFindPrefHandle(self
, args
)
222 if (!PyArg_ParseTuple(args
, "O&O&", PyMac_GetStr255
, &key
, ResObj_Convert
, &h
))
224 if ((err
=ICFindPrefHandle(self
->inst
, key
, &attr
, h
)) != 0 )
225 return ici_error(err
);
226 return Py_BuildValue("i", (int)attr
);
230 static char ici_ICSetPref__doc__
[] =
231 "(key, attr, data)->None; Set preference key to data with attributes"
235 ici_ICSetPref(self
, args
)
245 if (!PyArg_ParseTuple(args
, "O&is#", PyMac_GetStr255
, &key
, &attr
,
248 if ((err
=ICSetPref(self
->inst
, key
, (ICAttr
)attr
, (Ptr
)data
,
249 (long)datalen
)) != 0)
250 return ici_error(err
);
256 static char ici_ICCountPref__doc__
[] =
257 "()->int; Return number of preferences"
261 ici_ICCountPref(self
, args
)
268 if (!PyArg_ParseTuple(args
, ""))
270 if ((err
=ICCountPref(self
->inst
, &count
)) != 0 )
271 return ici_error(err
);
272 return Py_BuildValue("i", (int)count
);
276 static char ici_ICGetIndPref__doc__
[] =
277 "(num)->key; Return key of preference with given index"
281 ici_ICGetIndPref(self
, args
)
289 if (!PyArg_ParseTuple(args
, "l", &num
))
291 if ((err
=ICGetIndPref(self
->inst
, num
, key
)) != 0 )
292 return ici_error(err
);
293 return Py_BuildValue("O&", PyMac_BuildStr255
, key
);
297 static char ici_ICDeletePref__doc__
[] =
298 "(key)->None; Delete preference"
302 ici_ICDeletePref(self
, args
)
309 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, key
))
311 if ((err
=ICDeletePref(self
->inst
, key
)) != 0 )
312 return ici_error(err
);
318 static char ici_ICEnd__doc__
[] =
319 "()->None; Unlock file after ICBegin call"
323 ici_ICEnd(self
, args
)
329 if (!PyArg_ParseTuple(args
, ""))
331 if ((err
=ICEnd(self
->inst
)) != 0 )
332 return ici_error(err
);
338 static char ici_ICEditPreferences__doc__
[] =
339 "(key)->None; Ask user to edit preferences, staring with key"
343 ici_ICEditPreferences(self
, args
)
350 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, key
))
352 if ((err
=ICEditPreferences(self
->inst
, key
)) != 0 )
353 return ici_error(err
);
359 static char ici_ICParseURL__doc__
[] =
360 "(hint, data, selStart, selEnd, handle)->selStart, selEnd; Find an URL, return in handle"
364 ici_ICParseURL(self
, args
)
372 long selStart
, selEnd
;
375 if (!PyArg_ParseTuple(args
, "O&s#llO&", PyMac_GetStr255
, hint
, &data
, &datalen
,
376 &selStart
, &selEnd
, ResObj_Convert
, &h
))
378 if ((err
=ICParseURL(self
->inst
, hint
, (Ptr
)data
, (long)datalen
,
379 &selStart
, &selEnd
, h
)) != 0 )
380 return ici_error(err
);
381 return Py_BuildValue("ii", (int)selStart
, (int)selEnd
);
385 static char ici_ICLaunchURL__doc__
[] =
386 "(hint, data, selStart, selEnd)->None; Find an URL and launch the correct app"
390 ici_ICLaunchURL(self
, args
)
398 long selStart
, selEnd
;
400 if (!PyArg_ParseTuple(args
, "O&s#ll", PyMac_GetStr255
, hint
, &data
, &datalen
,
403 if ((err
=ICLaunchURL(self
->inst
, hint
, (Ptr
)data
, (long)datalen
,
404 &selStart
, &selEnd
)) != 0 )
405 return ici_error(err
);
406 return Py_BuildValue("ii", (int)selStart
, (int)selEnd
);
410 static char ici_ICMapFilename__doc__
[] =
411 "(filename)->mapinfo; Get filemap info for given filename"
415 ici_ICMapFilename(self
, args
)
423 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, filename
))
425 if ((err
=ICMapFilename(self
->inst
, filename
, &entry
)) != 0 )
426 return ici_error(err
);
427 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry
.version
,
428 PyMac_BuildOSType
, entry
.file_type
,
429 PyMac_BuildOSType
, entry
.file_creator
,
430 PyMac_BuildOSType
, entry
.post_creator
,
432 PyMac_BuildStr255
, entry
.extension
,
433 PyMac_BuildStr255
, entry
.creator_app_name
,
434 PyMac_BuildStr255
, entry
.post_app_name
,
435 PyMac_BuildStr255
, entry
.MIME_type
,
436 PyMac_BuildStr255
, entry
.entry_name
);
440 static char ici_ICMapTypeCreator__doc__
[] =
441 "(type, creator, filename)->mapinfo; Get filemap info for given tp/cr/filename"
445 ici_ICMapTypeCreator(self
, args
)
450 OSType type
, creator
;
454 if (!PyArg_ParseTuple(args
, "O&O&O&",
455 PyMac_GetOSType
, &type
,
456 PyMac_GetOSType
, &creator
,
457 PyMac_GetStr255
, filename
))
459 if ((err
=ICMapTypeCreator(self
->inst
, type
, creator
, filename
, &entry
)) != 0 )
460 return ici_error(err
);
461 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry
.version
,
462 PyMac_BuildOSType
, entry
.file_type
,
463 PyMac_BuildOSType
, entry
.file_creator
,
464 PyMac_BuildOSType
, entry
.post_creator
,
466 PyMac_BuildStr255
, entry
.extension
,
467 PyMac_BuildStr255
, entry
.creator_app_name
,
468 PyMac_BuildStr255
, entry
.post_app_name
,
469 PyMac_BuildStr255
, entry
.MIME_type
,
470 PyMac_BuildStr255
, entry
.entry_name
);
474 static struct PyMethodDef ici_methods
[] = {
475 #if TARGET_API_MAC_OS8
476 {"ICFindConfigFile", (PyCFunction
)ici_ICFindConfigFile
, METH_VARARGS
, ici_ICFindConfigFile__doc__
},
477 {"ICFindUserConfigFile", (PyCFunction
)ici_ICFindUserConfigFile
, METH_VARARGS
, ici_ICFindUserConfigFile__doc__
},
478 {"ICChooseConfig", (PyCFunction
)ici_ICChooseConfig
, METH_VARARGS
, ici_ICChooseConfig__doc__
},
479 {"ICChooseNewConfig", (PyCFunction
)ici_ICChooseNewConfig
, METH_VARARGS
, ici_ICChooseNewConfig__doc__
},
480 #endif /* TARGET_API_MAC_OS8 */
481 {"ICGetSeed", (PyCFunction
)ici_ICGetSeed
, METH_VARARGS
, ici_ICGetSeed__doc__
},
482 {"ICBegin", (PyCFunction
)ici_ICBegin
, METH_VARARGS
, ici_ICBegin__doc__
},
483 {"ICFindPrefHandle", (PyCFunction
)ici_ICFindPrefHandle
, METH_VARARGS
, ici_ICFindPrefHandle__doc__
},
484 {"ICSetPref", (PyCFunction
)ici_ICSetPref
, METH_VARARGS
, ici_ICSetPref__doc__
},
485 {"ICCountPref", (PyCFunction
)ici_ICCountPref
, METH_VARARGS
, ici_ICCountPref__doc__
},
486 {"ICGetIndPref", (PyCFunction
)ici_ICGetIndPref
, METH_VARARGS
, ici_ICGetIndPref__doc__
},
487 {"ICDeletePref", (PyCFunction
)ici_ICDeletePref
, METH_VARARGS
, ici_ICDeletePref__doc__
},
488 {"ICEnd", (PyCFunction
)ici_ICEnd
, METH_VARARGS
, ici_ICEnd__doc__
},
489 {"ICEditPreferences", (PyCFunction
)ici_ICEditPreferences
, METH_VARARGS
, ici_ICEditPreferences__doc__
},
490 {"ICParseURL", (PyCFunction
)ici_ICParseURL
, METH_VARARGS
, ici_ICParseURL__doc__
},
491 {"ICLaunchURL", (PyCFunction
)ici_ICLaunchURL
, METH_VARARGS
, ici_ICLaunchURL__doc__
},
492 {"ICMapFilename", (PyCFunction
)ici_ICMapFilename
, METH_VARARGS
, ici_ICMapFilename__doc__
},
493 {"ICMapTypeCreator", (PyCFunction
)ici_ICMapTypeCreator
, METH_VARARGS
, ici_ICMapTypeCreator__doc__
},
495 {NULL
, NULL
} /* sentinel */
502 newiciobject(OSType creator
)
507 self
= PyObject_NEW(iciobject
, &Icitype
);
510 if ((err
=ICStart(&self
->inst
, creator
)) != 0 ) {
511 (void)ici_error(err
);
523 (void)ICStop(self
->inst
);
528 ici_getattr(self
, name
)
532 return Py_FindMethod(ici_methods
, (PyObject
*)self
, name
);
535 static char Icitype__doc__
[] =
536 "Internet Config instance"
539 static PyTypeObject Icitype
= {
540 PyObject_HEAD_INIT(&PyType_Type
)
542 "ic_instance", /*tp_name*/
543 sizeof(iciobject
), /*tp_basicsize*/
546 (destructor
)ici_dealloc
, /*tp_dealloc*/
547 (printfunc
)0, /*tp_print*/
548 (getattrfunc
)ici_getattr
, /*tp_getattr*/
549 (setattrfunc
)0, /*tp_setattr*/
550 (cmpfunc
)0, /*tp_compare*/
551 (reprfunc
)0, /*tp_repr*/
553 0, /*tp_as_sequence*/
555 (hashfunc
)0, /*tp_hash*/
556 (ternaryfunc
)0, /*tp_call*/
557 (reprfunc
)0, /*tp_str*/
559 /* Space for future expansion */
561 Icitype__doc__
/* Documentation string */
564 /* End of code for ic_instance objects */
565 /* -------------------------------------------------------- */
568 static char ic_ICStart__doc__
[] =
569 "(OSType)->ic_instance; Create an Internet Config instance"
573 ic_ICStart(self
, args
)
574 PyObject
*self
; /* Not used */
579 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetOSType
, &creator
))
581 return (PyObject
*)newiciobject(creator
);
584 /* List of methods defined in the module */
586 static struct PyMethodDef ic_methods
[] = {
587 {"ICStart", (PyCFunction
)ic_ICStart
, METH_VARARGS
, ic_ICStart__doc__
},
589 {NULL
, (PyCFunction
)NULL
, 0, NULL
} /* sentinel */
593 /* Initialization function for the module (*must* be called initicglue) */
595 static char icglue_module_documentation
[] =
596 "Implements low-level Internet Config interface"
604 /* Create the module and add the functions */
605 m
= Py_InitModule4("icglue", ic_methods
,
606 icglue_module_documentation
,
607 (PyObject
*)NULL
,PYTHON_API_VERSION
);
609 /* Add some symbolic constants to the module */
610 d
= PyModule_GetDict(m
);
611 ErrorObject
= PyString_FromString("icglue.error");
612 PyDict_SetItemString(d
, "error", ErrorObject
);
614 /* XXXX Add constants here */
616 /* Check for errors */
617 if (PyErr_Occurred())
618 Py_FatalError("can't initialize module icglue");