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 #if TARGET_API_MAC_CARBON
38 /* The Carbon headers define PRAGMA_ALIGN_SUPPORT to something illegal,
39 ** because you shouldn't use it for Carbon. All good and well, but portable
40 ** code still needs it. So, we undefine it here.
42 #undef PRAGMA_ALIGN_SUPPORTED
43 #define PRAGMA_ALIGN_SUPPORTED 0
44 #endif /* TARGET_API_MAC_CARBON */
48 static PyObject
*ErrorObject
;
51 ici_error(ICError err
)
53 PyErr_SetObject(ErrorObject
, PyInt_FromLong((long)err
));
57 /* ----------------------------------------------------- */
59 /* Declarations for objects of type ic_instance */
66 staticforward PyTypeObject Icitype
;
70 /* ---------------------------------------------------------------- */
72 #if !TARGET_API_MAC_CARBON
73 static char ici_ICFindConfigFile__doc__
[] =
74 "()->None; Find config file in standard places"
78 ici_ICFindConfigFile(self
, args
)
84 if (!PyArg_ParseTuple(args
, ""))
86 if ((err
=ICFindConfigFile(self
->inst
, 0, NULL
)) != 0 )
87 return ici_error(err
);
93 static char ici_ICFindUserConfigFile__doc__
[] =
94 "(vRefNum, dirID)->None; Find config file in specified place"
98 ici_ICFindUserConfigFile(self
, args
)
105 if (!PyArg_ParseTuple(args
, "sl", &where
.vRefNum
, &where
.dirID
))
107 if ((err
=ICFindUserConfigFile(self
->inst
, &where
)) != 0 )
108 return ici_error(err
);
114 static char ici_ICChooseConfig__doc__
[] =
115 "()->None; Let the user choose a config file"
119 ici_ICChooseConfig(self
, args
)
125 if (!PyArg_ParseTuple(args
, ""))
127 if ((err
=ICChooseConfig(self
->inst
)) != 0 )
128 return ici_error(err
);
132 #endif /* !TARGET_API_MAC_CARBON */
135 static char ici_ICChooseNewConfig__doc__
[] =
136 "()->None; Let the user choose a new config file"
140 ici_ICChooseNewConfig(self
, args
)
146 if (!PyArg_ParseTuple(args
, ""))
148 if ((err
=ICChooseNewConfig(self
->inst
)) != 0 )
149 return ici_error(err
);
155 static char ici_ICGetSeed__doc__
[] =
156 "()->int; Returns int that changes when configuration does"
160 ici_ICGetSeed(self
, args
)
167 if (!PyArg_ParseTuple(args
, ""))
169 if ((err
=ICGetSeed(self
->inst
, &seed
)) != 0 )
170 return ici_error(err
);
171 return Py_BuildValue("i", (int)seed
);
175 static char ici_ICBegin__doc__
[] =
176 "(perm)->None; Lock config file for read/write"
180 ici_ICBegin(self
, args
)
187 if (!PyArg_ParseTuple(args
, "i", &perm
))
189 if ((err
=ICBegin(self
->inst
, (ICPerm
)perm
)) != 0 )
190 return ici_error(err
);
196 static char ici_ICFindPrefHandle__doc__
[] =
197 "(key, handle)->attrs; Lookup key, store result in handle, return attributes"
201 ici_ICFindPrefHandle(self
, args
)
210 if (!PyArg_ParseTuple(args
, "O&O&", PyMac_GetStr255
, &key
, ResObj_Convert
, &h
))
212 if ((err
=ICFindPrefHandle(self
->inst
, key
, &attr
, h
)) != 0 )
213 return ici_error(err
);
214 return Py_BuildValue("i", (int)attr
);
218 static char ici_ICSetPref__doc__
[] =
219 "(key, attr, data)->None; Set preference key to data with attributes"
223 ici_ICSetPref(self
, args
)
233 if (!PyArg_ParseTuple(args
, "O&is#", PyMac_GetStr255
, &key
, &attr
,
236 if ((err
=ICSetPref(self
->inst
, key
, (ICAttr
)attr
, (Ptr
)data
,
237 (long)datalen
)) != 0)
238 return ici_error(err
);
244 static char ici_ICCountPref__doc__
[] =
245 "()->int; Return number of preferences"
249 ici_ICCountPref(self
, args
)
256 if (!PyArg_ParseTuple(args
, ""))
258 if ((err
=ICCountPref(self
->inst
, &count
)) != 0 )
259 return ici_error(err
);
260 return Py_BuildValue("i", (int)count
);
264 static char ici_ICGetIndPref__doc__
[] =
265 "(num)->key; Return key of preference with given index"
269 ici_ICGetIndPref(self
, args
)
277 if (!PyArg_ParseTuple(args
, "l", &num
))
279 if ((err
=ICGetIndPref(self
->inst
, num
, key
)) != 0 )
280 return ici_error(err
);
281 return Py_BuildValue("O&", PyMac_BuildStr255
, key
);
285 static char ici_ICDeletePref__doc__
[] =
286 "(key)->None; Delete preference"
290 ici_ICDeletePref(self
, args
)
297 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, key
))
299 if ((err
=ICDeletePref(self
->inst
, key
)) != 0 )
300 return ici_error(err
);
306 static char ici_ICEnd__doc__
[] =
307 "()->None; Unlock file after ICBegin call"
311 ici_ICEnd(self
, args
)
317 if (!PyArg_ParseTuple(args
, ""))
319 if ((err
=ICEnd(self
->inst
)) != 0 )
320 return ici_error(err
);
326 static char ici_ICEditPreferences__doc__
[] =
327 "(key)->None; Ask user to edit preferences, staring with key"
331 ici_ICEditPreferences(self
, args
)
338 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, key
))
340 if ((err
=ICEditPreferences(self
->inst
, key
)) != 0 )
341 return ici_error(err
);
347 static char ici_ICParseURL__doc__
[] =
348 "(hint, data, selStart, selEnd, handle)->selStart, selEnd; Find an URL, return in handle"
352 ici_ICParseURL(self
, args
)
360 long selStart
, selEnd
;
363 if (!PyArg_ParseTuple(args
, "O&s#llO&", PyMac_GetStr255
, hint
, &data
, &datalen
,
364 &selStart
, &selEnd
, ResObj_Convert
, &h
))
366 if ((err
=ICParseURL(self
->inst
, hint
, (Ptr
)data
, (long)datalen
,
367 &selStart
, &selEnd
, h
)) != 0 )
368 return ici_error(err
);
369 return Py_BuildValue("ii", (int)selStart
, (int)selEnd
);
373 static char ici_ICLaunchURL__doc__
[] =
374 "(hint, data, selStart, selEnd)->None; Find an URL and launch the correct app"
378 ici_ICLaunchURL(self
, args
)
386 long selStart
, selEnd
;
388 if (!PyArg_ParseTuple(args
, "O&s#ll", PyMac_GetStr255
, hint
, &data
, &datalen
,
391 if ((err
=ICLaunchURL(self
->inst
, hint
, (Ptr
)data
, (long)datalen
,
392 &selStart
, &selEnd
)) != 0 )
393 return ici_error(err
);
394 return Py_BuildValue("ii", (int)selStart
, (int)selEnd
);
398 static char ici_ICMapFilename__doc__
[] =
399 "(filename)->mapinfo; Get filemap info for given filename"
403 ici_ICMapFilename(self
, args
)
411 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, filename
))
413 if ((err
=ICMapFilename(self
->inst
, filename
, &entry
)) != 0 )
414 return ici_error(err
);
415 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry
.version
,
416 PyMac_BuildOSType
, entry
.file_type
,
417 PyMac_BuildOSType
, entry
.file_creator
,
418 PyMac_BuildOSType
, entry
.post_creator
,
420 PyMac_BuildStr255
, entry
.extension
,
421 PyMac_BuildStr255
, entry
.creator_app_name
,
422 PyMac_BuildStr255
, entry
.post_app_name
,
423 PyMac_BuildStr255
, entry
.MIME_type
,
424 PyMac_BuildStr255
, entry
.entry_name
);
428 static char ici_ICMapTypeCreator__doc__
[] =
429 "(type, creator, filename)->mapinfo; Get filemap info for given tp/cr/filename"
433 ici_ICMapTypeCreator(self
, args
)
438 OSType type
, creator
;
442 if (!PyArg_ParseTuple(args
, "O&O&O&",
443 PyMac_GetOSType
, &type
,
444 PyMac_GetOSType
, &creator
,
445 PyMac_GetStr255
, filename
))
447 if ((err
=ICMapTypeCreator(self
->inst
, type
, creator
, filename
, &entry
)) != 0 )
448 return ici_error(err
);
449 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry
.version
,
450 PyMac_BuildOSType
, entry
.file_type
,
451 PyMac_BuildOSType
, entry
.file_creator
,
452 PyMac_BuildOSType
, entry
.post_creator
,
454 PyMac_BuildStr255
, entry
.extension
,
455 PyMac_BuildStr255
, entry
.creator_app_name
,
456 PyMac_BuildStr255
, entry
.post_app_name
,
457 PyMac_BuildStr255
, entry
.MIME_type
,
458 PyMac_BuildStr255
, entry
.entry_name
);
462 static struct PyMethodDef ici_methods
[] = {
463 #if !TARGET_API_MAC_CARBON
464 {"ICFindConfigFile", (PyCFunction
)ici_ICFindConfigFile
, METH_VARARGS
, ici_ICFindConfigFile__doc__
},
465 {"ICFindUserConfigFile", (PyCFunction
)ici_ICFindUserConfigFile
, METH_VARARGS
, ici_ICFindUserConfigFile__doc__
},
466 {"ICChooseConfig", (PyCFunction
)ici_ICChooseConfig
, METH_VARARGS
, ici_ICChooseConfig__doc__
},
467 {"ICChooseNewConfig", (PyCFunction
)ici_ICChooseNewConfig
, METH_VARARGS
, ici_ICChooseNewConfig__doc__
},
468 #endif /* !TARGET_API_MAC_CARBON */
469 {"ICGetSeed", (PyCFunction
)ici_ICGetSeed
, METH_VARARGS
, ici_ICGetSeed__doc__
},
470 {"ICBegin", (PyCFunction
)ici_ICBegin
, METH_VARARGS
, ici_ICBegin__doc__
},
471 {"ICFindPrefHandle", (PyCFunction
)ici_ICFindPrefHandle
, METH_VARARGS
, ici_ICFindPrefHandle__doc__
},
472 {"ICSetPref", (PyCFunction
)ici_ICSetPref
, METH_VARARGS
, ici_ICSetPref__doc__
},
473 {"ICCountPref", (PyCFunction
)ici_ICCountPref
, METH_VARARGS
, ici_ICCountPref__doc__
},
474 {"ICGetIndPref", (PyCFunction
)ici_ICGetIndPref
, METH_VARARGS
, ici_ICGetIndPref__doc__
},
475 {"ICDeletePref", (PyCFunction
)ici_ICDeletePref
, METH_VARARGS
, ici_ICDeletePref__doc__
},
476 {"ICEnd", (PyCFunction
)ici_ICEnd
, METH_VARARGS
, ici_ICEnd__doc__
},
477 {"ICEditPreferences", (PyCFunction
)ici_ICEditPreferences
, METH_VARARGS
, ici_ICEditPreferences__doc__
},
478 {"ICParseURL", (PyCFunction
)ici_ICParseURL
, METH_VARARGS
, ici_ICParseURL__doc__
},
479 {"ICLaunchURL", (PyCFunction
)ici_ICLaunchURL
, METH_VARARGS
, ici_ICLaunchURL__doc__
},
480 {"ICMapFilename", (PyCFunction
)ici_ICMapFilename
, METH_VARARGS
, ici_ICMapFilename__doc__
},
481 {"ICMapTypeCreator", (PyCFunction
)ici_ICMapTypeCreator
, METH_VARARGS
, ici_ICMapTypeCreator__doc__
},
483 {NULL
, NULL
} /* sentinel */
490 newiciobject(OSType creator
)
495 self
= PyObject_NEW(iciobject
, &Icitype
);
498 if ((err
=ICStart(&self
->inst
, creator
)) != 0 ) {
499 (void)ici_error(err
);
511 (void)ICStop(self
->inst
);
516 ici_getattr(self
, name
)
520 return Py_FindMethod(ici_methods
, (PyObject
*)self
, name
);
523 static char Icitype__doc__
[] =
524 "Internet Config instance"
527 static PyTypeObject Icitype
= {
528 PyObject_HEAD_INIT(&PyType_Type
)
530 "ic_instance", /*tp_name*/
531 sizeof(iciobject
), /*tp_basicsize*/
534 (destructor
)ici_dealloc
, /*tp_dealloc*/
535 (printfunc
)0, /*tp_print*/
536 (getattrfunc
)ici_getattr
, /*tp_getattr*/
537 (setattrfunc
)0, /*tp_setattr*/
538 (cmpfunc
)0, /*tp_compare*/
539 (reprfunc
)0, /*tp_repr*/
541 0, /*tp_as_sequence*/
543 (hashfunc
)0, /*tp_hash*/
544 (ternaryfunc
)0, /*tp_call*/
545 (reprfunc
)0, /*tp_str*/
547 /* Space for future expansion */
549 Icitype__doc__
/* Documentation string */
552 /* End of code for ic_instance objects */
553 /* -------------------------------------------------------- */
556 static char ic_ICStart__doc__
[] =
557 "(OSType)->ic_instance; Create an Internet Config instance"
561 ic_ICStart(self
, args
)
562 PyObject
*self
; /* Not used */
567 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetOSType
, &creator
))
569 return (PyObject
*)newiciobject(creator
);
572 /* List of methods defined in the module */
574 static struct PyMethodDef ic_methods
[] = {
575 {"ICStart", (PyCFunction
)ic_ICStart
, METH_VARARGS
, ic_ICStart__doc__
},
577 {NULL
, (PyCFunction
)NULL
, 0, NULL
} /* sentinel */
581 /* Initialization function for the module (*must* be called initicglue) */
583 static char icglue_module_documentation
[] =
584 "Implements low-level Internet Config interface"
592 /* Create the module and add the functions */
593 m
= Py_InitModule4("icglue", ic_methods
,
594 icglue_module_documentation
,
595 (PyObject
*)NULL
,PYTHON_API_VERSION
);
597 /* Add some symbolic constants to the module */
598 d
= PyModule_GetDict(m
);
599 ErrorObject
= PyString_FromString("icglue.error");
600 PyDict_SetItemString(d
, "error", ErrorObject
);
602 /* XXXX Add constants here */
604 /* Check for errors */
605 if (PyErr_Occurred())
606 Py_FatalError("can't initialize module icglue");