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 */
48 #include <InternetConfig.h>
50 #include <Carbon/Carbon.h>
53 static PyObject
*ErrorObject
;
55 /* ----------------------------------------------------- */
57 /* Declarations for objects of type ic_instance */
64 staticforward PyTypeObject Icitype
;
68 /* ---------------------------------------------------------------- */
70 #if TARGET_API_MAC_OS8
71 static char ici_ICFindConfigFile__doc__
[] =
72 "()->None; Find config file in standard places"
76 ici_ICFindConfigFile(iciobject
*self
, PyObject
*args
)
80 if (!PyArg_ParseTuple(args
, ""))
82 if ((err
=ICFindConfigFile(self
->inst
, 0, NULL
)) != 0 )
83 return PyMac_Error(err
);
89 static char ici_ICFindUserConfigFile__doc__
[] =
90 "(vRefNum, dirID)->None; Find config file in specified place"
94 ici_ICFindUserConfigFile(iciobject
*self
, PyObject
*args
)
99 if (!PyArg_ParseTuple(args
, "sl", &where
.vRefNum
, &where
.dirID
))
101 if ((err
=ICFindUserConfigFile(self
->inst
, &where
)) != 0 )
102 return PyMac_Error(err
);
108 static char ici_ICChooseConfig__doc__
[] =
109 "()->None; Let the user choose a config file"
113 ici_ICChooseConfig(iciobject
*self
, PyObject
*args
)
117 if (!PyArg_ParseTuple(args
, ""))
119 if ((err
=ICChooseConfig(self
->inst
)) != 0 )
120 return PyMac_Error(err
);
125 static char ici_ICChooseNewConfig__doc__
[] =
126 "()->None; Let the user choose a new config file"
130 ici_ICChooseNewConfig(iciobject
*self
, PyObject
*args
)
134 if (!PyArg_ParseTuple(args
, ""))
136 if ((err
=ICChooseNewConfig(self
->inst
)) != 0 )
137 return PyMac_Error(err
);
141 #endif /* TARGET_API_MAC_OS8 */
144 static char ici_ICGetSeed__doc__
[] =
145 "()->int; Returns int that changes when configuration does"
149 ici_ICGetSeed(iciobject
*self
, PyObject
*args
)
154 if (!PyArg_ParseTuple(args
, ""))
156 if ((err
=ICGetSeed(self
->inst
, &seed
)) != 0 )
157 return PyMac_Error(err
);
158 return Py_BuildValue("i", (int)seed
);
162 static char ici_ICBegin__doc__
[] =
163 "(perm)->None; Lock config file for read/write"
167 ici_ICBegin(iciobject
*self
, PyObject
*args
)
172 if (!PyArg_ParseTuple(args
, "i", &perm
))
174 if ((err
=ICBegin(self
->inst
, (ICPerm
)perm
)) != 0 )
175 return PyMac_Error(err
);
181 static char ici_ICFindPrefHandle__doc__
[] =
182 "(key, handle)->attrs; Lookup key, store result in handle, return attributes"
186 ici_ICFindPrefHandle(iciobject
*self
, PyObject
*args
)
193 if (!PyArg_ParseTuple(args
, "O&O&", PyMac_GetStr255
, &key
, ResObj_Convert
, &h
))
195 if ((err
=ICFindPrefHandle(self
->inst
, key
, &attr
, h
)) != 0 )
196 return PyMac_Error(err
);
197 return Py_BuildValue("i", (int)attr
);
201 static char ici_ICSetPref__doc__
[] =
202 "(key, attr, data)->None; Set preference key to data with attributes"
206 ici_ICSetPref(iciobject
*self
, PyObject
*args
)
214 if (!PyArg_ParseTuple(args
, "O&is#", PyMac_GetStr255
, &key
, &attr
,
217 if ((err
=ICSetPref(self
->inst
, key
, (ICAttr
)attr
, (Ptr
)data
,
218 (long)datalen
)) != 0)
219 return PyMac_Error(err
);
225 static char ici_ICCountPref__doc__
[] =
226 "()->int; Return number of preferences"
230 ici_ICCountPref(iciobject
*self
, PyObject
*args
)
235 if (!PyArg_ParseTuple(args
, ""))
237 if ((err
=ICCountPref(self
->inst
, &count
)) != 0 )
238 return PyMac_Error(err
);
239 return Py_BuildValue("i", (int)count
);
243 static char ici_ICGetIndPref__doc__
[] =
244 "(num)->key; Return key of preference with given index"
248 ici_ICGetIndPref(iciobject
*self
, PyObject
*args
)
254 if (!PyArg_ParseTuple(args
, "l", &num
))
256 if ((err
=ICGetIndPref(self
->inst
, num
, key
)) != 0 )
257 return PyMac_Error(err
);
258 return Py_BuildValue("O&", PyMac_BuildStr255
, key
);
262 static char ici_ICDeletePref__doc__
[] =
263 "(key)->None; Delete preference"
267 ici_ICDeletePref(iciobject
*self
, PyObject
*args
)
272 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, key
))
274 if ((err
=ICDeletePref(self
->inst
, key
)) != 0 )
275 return PyMac_Error(err
);
281 static char ici_ICEnd__doc__
[] =
282 "()->None; Unlock file after ICBegin call"
286 ici_ICEnd(iciobject
*self
, PyObject
*args
)
290 if (!PyArg_ParseTuple(args
, ""))
292 if ((err
=ICEnd(self
->inst
)) != 0 )
293 return PyMac_Error(err
);
299 static char ici_ICEditPreferences__doc__
[] =
300 "(key)->None; Ask user to edit preferences, staring with key"
304 ici_ICEditPreferences(iciobject
*self
, PyObject
*args
)
309 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, key
))
311 if ((err
=ICEditPreferences(self
->inst
, key
)) != 0 )
312 return PyMac_Error(err
);
318 static char ici_ICParseURL__doc__
[] =
319 "(hint, data, selStart, selEnd, handle)->selStart, selEnd; Find an URL, return in handle"
323 ici_ICParseURL(iciobject
*self
, PyObject
*args
)
329 long selStart
, selEnd
;
332 if (!PyArg_ParseTuple(args
, "O&s#llO&", PyMac_GetStr255
, hint
, &data
, &datalen
,
333 &selStart
, &selEnd
, ResObj_Convert
, &h
))
335 if ((err
=ICParseURL(self
->inst
, hint
, (Ptr
)data
, (long)datalen
,
336 &selStart
, &selEnd
, h
)) != 0 )
337 return PyMac_Error(err
);
338 return Py_BuildValue("ii", (int)selStart
, (int)selEnd
);
342 static char ici_ICLaunchURL__doc__
[] =
343 "(hint, data, selStart, selEnd)->None; Find an URL and launch the correct app"
347 ici_ICLaunchURL(iciobject
*self
, PyObject
*args
)
353 long selStart
, selEnd
;
355 if (!PyArg_ParseTuple(args
, "O&s#ll", PyMac_GetStr255
, hint
, &data
, &datalen
,
358 if ((err
=ICLaunchURL(self
->inst
, hint
, (Ptr
)data
, (long)datalen
,
359 &selStart
, &selEnd
)) != 0 )
360 return PyMac_Error(err
);
361 return Py_BuildValue("ii", (int)selStart
, (int)selEnd
);
365 static char ici_ICMapFilename__doc__
[] =
366 "(filename)->mapinfo; Get filemap info for given filename"
370 ici_ICMapFilename(iciobject
*self
, PyObject
*args
)
376 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, filename
))
378 if ((err
=ICMapFilename(self
->inst
, filename
, &entry
)) != 0 )
379 return PyMac_Error(err
);
380 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry
.version
,
381 PyMac_BuildOSType
, entry
.fileType
,
382 PyMac_BuildOSType
, entry
.fileCreator
,
383 PyMac_BuildOSType
, entry
.postCreator
,
385 PyMac_BuildStr255
, entry
.extension
,
386 PyMac_BuildStr255
, entry
.creatorAppName
,
387 PyMac_BuildStr255
, entry
.postAppName
,
388 PyMac_BuildStr255
, entry
.MIMEType
,
389 PyMac_BuildStr255
, entry
.entryName
);
393 static char ici_ICMapTypeCreator__doc__
[] =
394 "(type, creator, filename)->mapinfo; Get filemap info for given tp/cr/filename"
398 ici_ICMapTypeCreator(iciobject
*self
, PyObject
*args
)
401 OSType type
, creator
;
405 if (!PyArg_ParseTuple(args
, "O&O&O&",
406 PyMac_GetOSType
, &type
,
407 PyMac_GetOSType
, &creator
,
408 PyMac_GetStr255
, filename
))
410 if ((err
=ICMapTypeCreator(self
->inst
, type
, creator
, filename
, &entry
)) != 0 )
411 return PyMac_Error(err
);
412 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry
.version
,
413 PyMac_BuildOSType
, entry
.fileType
,
414 PyMac_BuildOSType
, entry
.fileCreator
,
415 PyMac_BuildOSType
, entry
.postCreator
,
417 PyMac_BuildStr255
, entry
.extension
,
418 PyMac_BuildStr255
, entry
.creatorAppName
,
419 PyMac_BuildStr255
, entry
.postAppName
,
420 PyMac_BuildStr255
, entry
.MIMEType
,
421 PyMac_BuildStr255
, entry
.entryName
);
425 static struct PyMethodDef ici_methods
[] = {
426 #if TARGET_API_MAC_OS8
427 {"ICFindConfigFile", (PyCFunction
)ici_ICFindConfigFile
, METH_VARARGS
, ici_ICFindConfigFile__doc__
},
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__
},
431 #endif /* TARGET_API_MAC_OS8 */
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__
},
446 {NULL
, NULL
} /* sentinel */
453 newiciobject(OSType creator
)
458 self
= PyObject_NEW(iciobject
, &Icitype
);
461 if ((err
=ICStart(&self
->inst
, creator
)) != 0 ) {
462 (void)PyMac_Error(err
);
471 ici_dealloc(iciobject
*self
)
473 (void)ICStop(self
->inst
);
478 ici_getattr(iciobject
*self
, char *name
)
480 return Py_FindMethod(ici_methods
, (PyObject
*)self
, name
);
483 static char Icitype__doc__
[] =
484 "Internet Config instance"
487 static PyTypeObject Icitype
= {
488 PyObject_HEAD_INIT(&PyType_Type
)
490 "icglue.ic_instance", /*tp_name*/
491 sizeof(iciobject
), /*tp_basicsize*/
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*/
501 0, /*tp_as_sequence*/
503 (hashfunc
)0, /*tp_hash*/
504 (ternaryfunc
)0, /*tp_call*/
505 (reprfunc
)0, /*tp_str*/
507 /* Space for future expansion */
509 Icitype__doc__
/* Documentation string */
512 /* End of code for ic_instance objects */
513 /* -------------------------------------------------------- */
516 static char ic_ICStart__doc__
[] =
517 "(OSType)->ic_instance; Create an Internet Config instance"
521 ic_ICStart(PyObject
*self
, PyObject
*args
)
525 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetOSType
, &creator
))
527 return (PyObject
*)newiciobject(creator
);
530 /* List of methods defined in the module */
532 static struct PyMethodDef ic_methods
[] = {
533 {"ICStart", (PyCFunction
)ic_ICStart
, METH_VARARGS
, ic_ICStart__doc__
},
535 {NULL
, (PyCFunction
)NULL
, 0, NULL
} /* sentinel */
539 /* Initialization function for the module (*must* be called initicglue) */
541 static char icglue_module_documentation
[] =
542 "Implements low-level Internet Config interface"
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
);
555 /* Add some symbolic constants to the module */
556 d
= PyModule_GetDict(m
);
557 ErrorObject
= PyMac_GetOSErrException();
558 if (ErrorObject
== NULL
||
559 PyDict_SetItemString(d
, "error", ErrorObject
) != 0)
562 /* XXXX Add constants here */
564 /* Check for errors */
565 if (PyErr_Occurred())
566 Py_FatalError("can't initialize module icglue");