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 ******************************************************************/
33 #include "pymactoolbox.h"
35 extern int ResObj_Convert(PyObject
*, Handle
*); /* From Resmodule.c */
37 #include <Carbon/Carbon.h>
39 static PyObject
*ErrorObject
;
41 /* ----------------------------------------------------- */
43 /* Declarations for objects of type ic_instance */
50 static PyTypeObject Icitype
;
54 /* ---------------------------------------------------------------- */
57 static char ici_ICGetSeed__doc__
[] =
58 "()->int; Returns int that changes when configuration does"
62 ici_ICGetSeed(iciobject
*self
, PyObject
*args
)
67 if (!PyArg_ParseTuple(args
, ""))
69 if ((err
=ICGetSeed(self
->inst
, &seed
)) != 0 )
70 return PyMac_Error(err
);
71 return Py_BuildValue("i", (int)seed
);
75 static char ici_ICBegin__doc__
[] =
76 "(perm)->None; Lock config file for read/write"
80 ici_ICBegin(iciobject
*self
, PyObject
*args
)
85 if (!PyArg_ParseTuple(args
, "i", &perm
))
87 if ((err
=ICBegin(self
->inst
, (ICPerm
)perm
)) != 0 )
88 return PyMac_Error(err
);
94 static char ici_ICFindPrefHandle__doc__
[] =
95 "(key, handle)->attrs; Lookup key, store result in handle, return attributes"
99 ici_ICFindPrefHandle(iciobject
*self
, PyObject
*args
)
106 if (!PyArg_ParseTuple(args
, "O&O&", PyMac_GetStr255
, &key
, ResObj_Convert
, &h
))
108 if ((err
=ICFindPrefHandle(self
->inst
, key
, &attr
, h
)) != 0 )
109 return PyMac_Error(err
);
110 return Py_BuildValue("i", (int)attr
);
114 static char ici_ICSetPref__doc__
[] =
115 "(key, attr, data)->None; Set preference key to data with attributes"
119 ici_ICSetPref(iciobject
*self
, PyObject
*args
)
127 if (!PyArg_ParseTuple(args
, "O&is#", PyMac_GetStr255
, &key
, &attr
,
130 if ((err
=ICSetPref(self
->inst
, key
, (ICAttr
)attr
, (Ptr
)data
,
131 (long)datalen
)) != 0)
132 return PyMac_Error(err
);
138 static char ici_ICCountPref__doc__
[] =
139 "()->int; Return number of preferences"
143 ici_ICCountPref(iciobject
*self
, PyObject
*args
)
148 if (!PyArg_ParseTuple(args
, ""))
150 if ((err
=ICCountPref(self
->inst
, &count
)) != 0 )
151 return PyMac_Error(err
);
152 return Py_BuildValue("i", (int)count
);
156 static char ici_ICGetIndPref__doc__
[] =
157 "(num)->key; Return key of preference with given index"
161 ici_ICGetIndPref(iciobject
*self
, PyObject
*args
)
167 if (!PyArg_ParseTuple(args
, "l", &num
))
169 if ((err
=ICGetIndPref(self
->inst
, num
, key
)) != 0 )
170 return PyMac_Error(err
);
171 return Py_BuildValue("O&", PyMac_BuildStr255
, key
);
175 static char ici_ICDeletePref__doc__
[] =
176 "(key)->None; Delete preference"
180 ici_ICDeletePref(iciobject
*self
, PyObject
*args
)
185 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, key
))
187 if ((err
=ICDeletePref(self
->inst
, key
)) != 0 )
188 return PyMac_Error(err
);
194 static char ici_ICEnd__doc__
[] =
195 "()->None; Unlock file after ICBegin call"
199 ici_ICEnd(iciobject
*self
, PyObject
*args
)
203 if (!PyArg_ParseTuple(args
, ""))
205 if ((err
=ICEnd(self
->inst
)) != 0 )
206 return PyMac_Error(err
);
212 static char ici_ICEditPreferences__doc__
[] =
213 "(key)->None; Ask user to edit preferences, staring with key"
217 ici_ICEditPreferences(iciobject
*self
, PyObject
*args
)
222 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, key
))
224 if ((err
=ICEditPreferences(self
->inst
, key
)) != 0 )
225 return PyMac_Error(err
);
231 static char ici_ICParseURL__doc__
[] =
232 "(hint, data, selStart, selEnd, handle)->selStart, selEnd; Find an URL, return in handle"
236 ici_ICParseURL(iciobject
*self
, PyObject
*args
)
242 long selStart
, selEnd
;
245 if (!PyArg_ParseTuple(args
, "O&s#llO&", PyMac_GetStr255
, hint
, &data
, &datalen
,
246 &selStart
, &selEnd
, ResObj_Convert
, &h
))
248 if ((err
=ICParseURL(self
->inst
, hint
, (Ptr
)data
, (long)datalen
,
249 &selStart
, &selEnd
, h
)) != 0 )
250 return PyMac_Error(err
);
251 return Py_BuildValue("ii", (int)selStart
, (int)selEnd
);
255 static char ici_ICLaunchURL__doc__
[] =
256 "(hint, data, selStart, selEnd)->None; Find an URL and launch the correct app"
260 ici_ICLaunchURL(iciobject
*self
, PyObject
*args
)
266 long selStart
, selEnd
;
268 if (!PyArg_ParseTuple(args
, "O&s#ll", PyMac_GetStr255
, hint
, &data
, &datalen
,
271 if ((err
=ICLaunchURL(self
->inst
, hint
, (Ptr
)data
, (long)datalen
,
272 &selStart
, &selEnd
)) != 0 )
273 return PyMac_Error(err
);
274 return Py_BuildValue("ii", (int)selStart
, (int)selEnd
);
278 static char ici_ICMapFilename__doc__
[] =
279 "(filename)->mapinfo; Get filemap info for given filename"
283 ici_ICMapFilename(iciobject
*self
, PyObject
*args
)
289 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, filename
))
291 if ((err
=ICMapFilename(self
->inst
, filename
, &entry
)) != 0 )
292 return PyMac_Error(err
);
293 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry
.version
,
294 PyMac_BuildOSType
, entry
.fileType
,
295 PyMac_BuildOSType
, entry
.fileCreator
,
296 PyMac_BuildOSType
, entry
.postCreator
,
298 PyMac_BuildStr255
, entry
.extension
,
299 PyMac_BuildStr255
, entry
.creatorAppName
,
300 PyMac_BuildStr255
, entry
.postAppName
,
301 PyMac_BuildStr255
, entry
.MIMEType
,
302 PyMac_BuildStr255
, entry
.entryName
);
306 static char ici_ICMapTypeCreator__doc__
[] =
307 "(type, creator, filename)->mapinfo; Get filemap info for given tp/cr/filename"
311 ici_ICMapTypeCreator(iciobject
*self
, PyObject
*args
)
314 OSType type
, creator
;
318 if (!PyArg_ParseTuple(args
, "O&O&O&",
319 PyMac_GetOSType
, &type
,
320 PyMac_GetOSType
, &creator
,
321 PyMac_GetStr255
, filename
))
323 if ((err
=ICMapTypeCreator(self
->inst
, type
, creator
, filename
, &entry
)) != 0 )
324 return PyMac_Error(err
);
325 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry
.version
,
326 PyMac_BuildOSType
, entry
.fileType
,
327 PyMac_BuildOSType
, entry
.fileCreator
,
328 PyMac_BuildOSType
, entry
.postCreator
,
330 PyMac_BuildStr255
, entry
.extension
,
331 PyMac_BuildStr255
, entry
.creatorAppName
,
332 PyMac_BuildStr255
, entry
.postAppName
,
333 PyMac_BuildStr255
, entry
.MIMEType
,
334 PyMac_BuildStr255
, entry
.entryName
);
338 static struct PyMethodDef ici_methods
[] = {
339 {"ICGetSeed", (PyCFunction
)ici_ICGetSeed
, METH_VARARGS
, ici_ICGetSeed__doc__
},
340 {"ICBegin", (PyCFunction
)ici_ICBegin
, METH_VARARGS
, ici_ICBegin__doc__
},
341 {"ICFindPrefHandle", (PyCFunction
)ici_ICFindPrefHandle
, METH_VARARGS
, ici_ICFindPrefHandle__doc__
},
342 {"ICSetPref", (PyCFunction
)ici_ICSetPref
, METH_VARARGS
, ici_ICSetPref__doc__
},
343 {"ICCountPref", (PyCFunction
)ici_ICCountPref
, METH_VARARGS
, ici_ICCountPref__doc__
},
344 {"ICGetIndPref", (PyCFunction
)ici_ICGetIndPref
, METH_VARARGS
, ici_ICGetIndPref__doc__
},
345 {"ICDeletePref", (PyCFunction
)ici_ICDeletePref
, METH_VARARGS
, ici_ICDeletePref__doc__
},
346 {"ICEnd", (PyCFunction
)ici_ICEnd
, METH_VARARGS
, ici_ICEnd__doc__
},
347 {"ICEditPreferences", (PyCFunction
)ici_ICEditPreferences
, METH_VARARGS
, ici_ICEditPreferences__doc__
},
348 {"ICParseURL", (PyCFunction
)ici_ICParseURL
, METH_VARARGS
, ici_ICParseURL__doc__
},
349 {"ICLaunchURL", (PyCFunction
)ici_ICLaunchURL
, METH_VARARGS
, ici_ICLaunchURL__doc__
},
350 {"ICMapFilename", (PyCFunction
)ici_ICMapFilename
, METH_VARARGS
, ici_ICMapFilename__doc__
},
351 {"ICMapTypeCreator", (PyCFunction
)ici_ICMapTypeCreator
, METH_VARARGS
, ici_ICMapTypeCreator__doc__
},
353 {NULL
, NULL
} /* sentinel */
360 newiciobject(OSType creator
)
365 self
= PyObject_NEW(iciobject
, &Icitype
);
368 if ((err
=ICStart(&self
->inst
, creator
)) != 0 ) {
369 (void)PyMac_Error(err
);
378 ici_dealloc(iciobject
*self
)
380 (void)ICStop(self
->inst
);
385 ici_getattr(iciobject
*self
, char *name
)
387 return Py_FindMethod(ici_methods
, (PyObject
*)self
, name
);
390 static char Icitype__doc__
[] =
391 "Internet Config instance"
394 static PyTypeObject Icitype
= {
395 PyObject_HEAD_INIT(&PyType_Type
)
397 "icglue.ic_instance", /*tp_name*/
398 sizeof(iciobject
), /*tp_basicsize*/
401 (destructor
)ici_dealloc
, /*tp_dealloc*/
402 (printfunc
)0, /*tp_print*/
403 (getattrfunc
)ici_getattr
, /*tp_getattr*/
404 (setattrfunc
)0, /*tp_setattr*/
405 (cmpfunc
)0, /*tp_compare*/
406 (reprfunc
)0, /*tp_repr*/
408 0, /*tp_as_sequence*/
410 (hashfunc
)0, /*tp_hash*/
411 (ternaryfunc
)0, /*tp_call*/
412 (reprfunc
)0, /*tp_str*/
414 /* Space for future expansion */
416 Icitype__doc__
/* Documentation string */
419 /* End of code for ic_instance objects */
420 /* -------------------------------------------------------- */
423 static char ic_ICStart__doc__
[] =
424 "(OSType)->ic_instance; Create an Internet Config instance"
428 ic_ICStart(PyObject
*self
, PyObject
*args
)
432 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetOSType
, &creator
))
434 return (PyObject
*)newiciobject(creator
);
437 /* List of methods defined in the module */
439 static struct PyMethodDef ic_methods
[] = {
440 {"ICStart", (PyCFunction
)ic_ICStart
, METH_VARARGS
, ic_ICStart__doc__
},
442 {NULL
, (PyCFunction
)NULL
, 0, NULL
} /* sentinel */
446 /* Initialization function for the module (*must* be called initicglue) */
448 static char icglue_module_documentation
[] =
449 "Implements low-level Internet Config interface"
457 if (PyErr_WarnPy3k("In 3.x, icglue is removed.", 1))
460 /* Create the module and add the functions */
461 m
= Py_InitModule4("icglue", ic_methods
,
462 icglue_module_documentation
,
463 (PyObject
*)NULL
,PYTHON_API_VERSION
);
465 /* Add some symbolic constants to the module */
466 d
= PyModule_GetDict(m
);
467 ErrorObject
= PyMac_GetOSErrException();
468 if (ErrorObject
== NULL
||
469 PyDict_SetItemString(d
, "error", ErrorObject
) != 0)
472 /* XXXX Add constants here */
474 /* Check for errors */
475 if (PyErr_Occurred())
476 Py_FatalError("can't initialize module icglue");