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 #include <InternetConfig.h>
40 #include <Carbon/Carbon.h>
43 static PyObject
*ErrorObject
;
45 /* ----------------------------------------------------- */
47 /* Declarations for objects of type ic_instance */
54 static PyTypeObject Icitype
;
58 /* ---------------------------------------------------------------- */
61 static char ici_ICGetSeed__doc__
[] =
62 "()->int; Returns int that changes when configuration does"
66 ici_ICGetSeed(iciobject
*self
, PyObject
*args
)
71 if (!PyArg_ParseTuple(args
, ""))
73 if ((err
=ICGetSeed(self
->inst
, &seed
)) != 0 )
74 return PyMac_Error(err
);
75 return Py_BuildValue("i", (int)seed
);
79 static char ici_ICBegin__doc__
[] =
80 "(perm)->None; Lock config file for read/write"
84 ici_ICBegin(iciobject
*self
, PyObject
*args
)
89 if (!PyArg_ParseTuple(args
, "i", &perm
))
91 if ((err
=ICBegin(self
->inst
, (ICPerm
)perm
)) != 0 )
92 return PyMac_Error(err
);
98 static char ici_ICFindPrefHandle__doc__
[] =
99 "(key, handle)->attrs; Lookup key, store result in handle, return attributes"
103 ici_ICFindPrefHandle(iciobject
*self
, PyObject
*args
)
110 if (!PyArg_ParseTuple(args
, "O&O&", PyMac_GetStr255
, &key
, ResObj_Convert
, &h
))
112 if ((err
=ICFindPrefHandle(self
->inst
, key
, &attr
, h
)) != 0 )
113 return PyMac_Error(err
);
114 return Py_BuildValue("i", (int)attr
);
118 static char ici_ICSetPref__doc__
[] =
119 "(key, attr, data)->None; Set preference key to data with attributes"
123 ici_ICSetPref(iciobject
*self
, PyObject
*args
)
131 if (!PyArg_ParseTuple(args
, "O&is#", PyMac_GetStr255
, &key
, &attr
,
134 if ((err
=ICSetPref(self
->inst
, key
, (ICAttr
)attr
, (Ptr
)data
,
135 (long)datalen
)) != 0)
136 return PyMac_Error(err
);
142 static char ici_ICCountPref__doc__
[] =
143 "()->int; Return number of preferences"
147 ici_ICCountPref(iciobject
*self
, PyObject
*args
)
152 if (!PyArg_ParseTuple(args
, ""))
154 if ((err
=ICCountPref(self
->inst
, &count
)) != 0 )
155 return PyMac_Error(err
);
156 return Py_BuildValue("i", (int)count
);
160 static char ici_ICGetIndPref__doc__
[] =
161 "(num)->key; Return key of preference with given index"
165 ici_ICGetIndPref(iciobject
*self
, PyObject
*args
)
171 if (!PyArg_ParseTuple(args
, "l", &num
))
173 if ((err
=ICGetIndPref(self
->inst
, num
, key
)) != 0 )
174 return PyMac_Error(err
);
175 return Py_BuildValue("O&", PyMac_BuildStr255
, key
);
179 static char ici_ICDeletePref__doc__
[] =
180 "(key)->None; Delete preference"
184 ici_ICDeletePref(iciobject
*self
, PyObject
*args
)
189 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, key
))
191 if ((err
=ICDeletePref(self
->inst
, key
)) != 0 )
192 return PyMac_Error(err
);
198 static char ici_ICEnd__doc__
[] =
199 "()->None; Unlock file after ICBegin call"
203 ici_ICEnd(iciobject
*self
, PyObject
*args
)
207 if (!PyArg_ParseTuple(args
, ""))
209 if ((err
=ICEnd(self
->inst
)) != 0 )
210 return PyMac_Error(err
);
216 static char ici_ICEditPreferences__doc__
[] =
217 "(key)->None; Ask user to edit preferences, staring with key"
221 ici_ICEditPreferences(iciobject
*self
, PyObject
*args
)
226 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, key
))
228 if ((err
=ICEditPreferences(self
->inst
, key
)) != 0 )
229 return PyMac_Error(err
);
235 static char ici_ICParseURL__doc__
[] =
236 "(hint, data, selStart, selEnd, handle)->selStart, selEnd; Find an URL, return in handle"
240 ici_ICParseURL(iciobject
*self
, PyObject
*args
)
246 long selStart
, selEnd
;
249 if (!PyArg_ParseTuple(args
, "O&s#llO&", PyMac_GetStr255
, hint
, &data
, &datalen
,
250 &selStart
, &selEnd
, ResObj_Convert
, &h
))
252 if ((err
=ICParseURL(self
->inst
, hint
, (Ptr
)data
, (long)datalen
,
253 &selStart
, &selEnd
, h
)) != 0 )
254 return PyMac_Error(err
);
255 return Py_BuildValue("ii", (int)selStart
, (int)selEnd
);
259 static char ici_ICLaunchURL__doc__
[] =
260 "(hint, data, selStart, selEnd)->None; Find an URL and launch the correct app"
264 ici_ICLaunchURL(iciobject
*self
, PyObject
*args
)
270 long selStart
, selEnd
;
272 if (!PyArg_ParseTuple(args
, "O&s#ll", PyMac_GetStr255
, hint
, &data
, &datalen
,
275 if ((err
=ICLaunchURL(self
->inst
, hint
, (Ptr
)data
, (long)datalen
,
276 &selStart
, &selEnd
)) != 0 )
277 return PyMac_Error(err
);
278 return Py_BuildValue("ii", (int)selStart
, (int)selEnd
);
282 static char ici_ICMapFilename__doc__
[] =
283 "(filename)->mapinfo; Get filemap info for given filename"
287 ici_ICMapFilename(iciobject
*self
, PyObject
*args
)
293 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, filename
))
295 if ((err
=ICMapFilename(self
->inst
, filename
, &entry
)) != 0 )
296 return PyMac_Error(err
);
297 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry
.version
,
298 PyMac_BuildOSType
, entry
.fileType
,
299 PyMac_BuildOSType
, entry
.fileCreator
,
300 PyMac_BuildOSType
, entry
.postCreator
,
302 PyMac_BuildStr255
, entry
.extension
,
303 PyMac_BuildStr255
, entry
.creatorAppName
,
304 PyMac_BuildStr255
, entry
.postAppName
,
305 PyMac_BuildStr255
, entry
.MIMEType
,
306 PyMac_BuildStr255
, entry
.entryName
);
310 static char ici_ICMapTypeCreator__doc__
[] =
311 "(type, creator, filename)->mapinfo; Get filemap info for given tp/cr/filename"
315 ici_ICMapTypeCreator(iciobject
*self
, PyObject
*args
)
318 OSType type
, creator
;
322 if (!PyArg_ParseTuple(args
, "O&O&O&",
323 PyMac_GetOSType
, &type
,
324 PyMac_GetOSType
, &creator
,
325 PyMac_GetStr255
, filename
))
327 if ((err
=ICMapTypeCreator(self
->inst
, type
, creator
, filename
, &entry
)) != 0 )
328 return PyMac_Error(err
);
329 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry
.version
,
330 PyMac_BuildOSType
, entry
.fileType
,
331 PyMac_BuildOSType
, entry
.fileCreator
,
332 PyMac_BuildOSType
, entry
.postCreator
,
334 PyMac_BuildStr255
, entry
.extension
,
335 PyMac_BuildStr255
, entry
.creatorAppName
,
336 PyMac_BuildStr255
, entry
.postAppName
,
337 PyMac_BuildStr255
, entry
.MIMEType
,
338 PyMac_BuildStr255
, entry
.entryName
);
342 static struct PyMethodDef ici_methods
[] = {
343 {"ICGetSeed", (PyCFunction
)ici_ICGetSeed
, METH_VARARGS
, ici_ICGetSeed__doc__
},
344 {"ICBegin", (PyCFunction
)ici_ICBegin
, METH_VARARGS
, ici_ICBegin__doc__
},
345 {"ICFindPrefHandle", (PyCFunction
)ici_ICFindPrefHandle
, METH_VARARGS
, ici_ICFindPrefHandle__doc__
},
346 {"ICSetPref", (PyCFunction
)ici_ICSetPref
, METH_VARARGS
, ici_ICSetPref__doc__
},
347 {"ICCountPref", (PyCFunction
)ici_ICCountPref
, METH_VARARGS
, ici_ICCountPref__doc__
},
348 {"ICGetIndPref", (PyCFunction
)ici_ICGetIndPref
, METH_VARARGS
, ici_ICGetIndPref__doc__
},
349 {"ICDeletePref", (PyCFunction
)ici_ICDeletePref
, METH_VARARGS
, ici_ICDeletePref__doc__
},
350 {"ICEnd", (PyCFunction
)ici_ICEnd
, METH_VARARGS
, ici_ICEnd__doc__
},
351 {"ICEditPreferences", (PyCFunction
)ici_ICEditPreferences
, METH_VARARGS
, ici_ICEditPreferences__doc__
},
352 {"ICParseURL", (PyCFunction
)ici_ICParseURL
, METH_VARARGS
, ici_ICParseURL__doc__
},
353 {"ICLaunchURL", (PyCFunction
)ici_ICLaunchURL
, METH_VARARGS
, ici_ICLaunchURL__doc__
},
354 {"ICMapFilename", (PyCFunction
)ici_ICMapFilename
, METH_VARARGS
, ici_ICMapFilename__doc__
},
355 {"ICMapTypeCreator", (PyCFunction
)ici_ICMapTypeCreator
, METH_VARARGS
, ici_ICMapTypeCreator__doc__
},
357 {NULL
, NULL
} /* sentinel */
364 newiciobject(OSType creator
)
369 self
= PyObject_NEW(iciobject
, &Icitype
);
372 if ((err
=ICStart(&self
->inst
, creator
)) != 0 ) {
373 (void)PyMac_Error(err
);
382 ici_dealloc(iciobject
*self
)
384 (void)ICStop(self
->inst
);
389 ici_getattr(iciobject
*self
, char *name
)
391 return Py_FindMethod(ici_methods
, (PyObject
*)self
, name
);
394 static char Icitype__doc__
[] =
395 "Internet Config instance"
398 static PyTypeObject Icitype
= {
399 PyObject_HEAD_INIT(&PyType_Type
)
401 "icglue.ic_instance", /*tp_name*/
402 sizeof(iciobject
), /*tp_basicsize*/
405 (destructor
)ici_dealloc
, /*tp_dealloc*/
406 (printfunc
)0, /*tp_print*/
407 (getattrfunc
)ici_getattr
, /*tp_getattr*/
408 (setattrfunc
)0, /*tp_setattr*/
409 (cmpfunc
)0, /*tp_compare*/
410 (reprfunc
)0, /*tp_repr*/
412 0, /*tp_as_sequence*/
414 (hashfunc
)0, /*tp_hash*/
415 (ternaryfunc
)0, /*tp_call*/
416 (reprfunc
)0, /*tp_str*/
418 /* Space for future expansion */
420 Icitype__doc__
/* Documentation string */
423 /* End of code for ic_instance objects */
424 /* -------------------------------------------------------- */
427 static char ic_ICStart__doc__
[] =
428 "(OSType)->ic_instance; Create an Internet Config instance"
432 ic_ICStart(PyObject
*self
, PyObject
*args
)
436 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetOSType
, &creator
))
438 return (PyObject
*)newiciobject(creator
);
441 /* List of methods defined in the module */
443 static struct PyMethodDef ic_methods
[] = {
444 {"ICStart", (PyCFunction
)ic_ICStart
, METH_VARARGS
, ic_ICStart__doc__
},
446 {NULL
, (PyCFunction
)NULL
, 0, NULL
} /* sentinel */
450 /* Initialization function for the module (*must* be called initicglue) */
452 static char icglue_module_documentation
[] =
453 "Implements low-level Internet Config interface"
461 /* Create the module and add the functions */
462 m
= Py_InitModule4("icglue", ic_methods
,
463 icglue_module_documentation
,
464 (PyObject
*)NULL
,PYTHON_API_VERSION
);
466 /* Add some symbolic constants to the module */
467 d
= PyModule_GetDict(m
);
468 ErrorObject
= PyMac_GetOSErrException();
469 if (ErrorObject
== NULL
||
470 PyDict_SetItemString(d
, "error", ErrorObject
) != 0)
473 /* XXXX Add constants here */
475 /* Check for errors */
476 if (PyErr_Occurred())
477 Py_FatalError("can't initialize module icglue");