Scary looking python patch; separate the C-module stuff from pure python for the benefit of OSes which keep them separately.

This commit is contained in:
alexhudson
2007-07-13 21:17:21 +00:00
parent 1764749c58
commit fb042f0ac5
52 changed files with 140 additions and 123 deletions
+79
View File
@@ -0,0 +1,79 @@
# -*- Makefile -*-
pkgpyexecdir = $(pyexecdir)/libbongo
pkgpyexec_PYTHON := \
src/libs/python/libbongo/__init__.py
pkgpyexec_LTLIBRARIES := \
libs.la \
bootstrap.la
libs_la_SOURCES := \
src/libs/python/libbongo/cal.c \
src/libs/python/libbongo/calcmd.c \
src/libs/python/libbongo/libs.c \
src/libs/python/libbongo/libs.h \
src/libs/python/libbongo/mdb.c \
src/libs/python/libbongo/msgapi.c \
src/libs/python/libbongo/msgapi-defs.c \
src/libs/python/libbongo/msgapi-defs.h \
src/libs/python/libbongo/pybongo.c \
src/libs/python/libbongo/pybongo.h \
src/libs/python/libbongo/streamio.c \
src/libs/python/libbongo/json.c \
src/libs/python/libbongo/json.h \
src/libs/python/libbongo/bongoutil.c
libs_la_CPPFLAGS := $(AM_CPPFLAGS) \
$(PYTHON_CPPFLAGS) \
$(bongo_CFLAGS)
libs_la_LDFLAGS := -avoid-version -module
libs_la_LIBADD := \
$(PYTHON_LIBS) \
libbongocal.la \
libbongocalcmd.la \
libbongoutil.la \
libbongo-json.la \
libbongomdb.la \
libbongomsgapi.la \
libbongostreamio.la
bootstrap_la_SOURCES := \
src/libs/python/libbongo/bootstrap.c \
src/libs/python/libbongo/bootstrap.h \
src/libs/python/libbongo/mdb.c \
src/libs/python/libbongo/msgapi-defs.c \
src/libs/python/libbongo/msgapi-defs.h \
src/libs/python/libbongo/pybongo.c \
src/libs/python/libbongo/pybongo.h
bootstrap_la_CPPFLAGS := $(AM_CPPFLAGS) \
$(PYTHON_CPPFLAGS) \
$(bongo_CFLAGS)
bootstrap_la_LDFLAGS := -avoid-version -module
bootstrap_la_LIBADD := \
$(PYTHON_LIBS) \
libbongomdb.la \
libbongomsgapi.la
src/libs/python/libbongo/libs.so: libs.la
cp .libs/libs.so $@
src/libs/python/libbongo/bootstrap.so: bootstrap.la
cp .libs/bootstrap.so $@
noinst_DATA += \
src/libs/python/libbongo/libs.so \
src/libs/python/libbongo/bootstrap.so
CLEANFILES += \
src/libs/python/libbongo/libs.so \
src/libs/python/libbongo/bootstrap.so
src/libs/python/libbongo/all: \
src/libs/python/libbongo/libs.so \
src/libs/python/libbongo/bootstrap.so
src/libs/python/bongo/clean: clean
+17
View File
@@ -0,0 +1,17 @@
# -*- Makefile -*-
#
# Do not edit!
#
# (unless this is Makefile.am.subdir)
#
# This file is a copy of the toplevel Makefile.am.subdir. If changes
# need to be made, edit that file, and make update-makefiles, and
# check the new files in.
#
# This is a skeletal automake file. The real automake fules for
# building the targets for this directory can be found in the
# Bongo.rules file. This file is simply here so that 'make all' can
# work in each subdirectory.
all clean install:
@cd $(top_builddir) && $(MAKE) $(MFLAGS) $(subdir)/$@
+74
View File
@@ -0,0 +1,74 @@
/****************************************************************************
*
* Copyright (c) 2006 Novell, Inc.
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, contact Novell, Inc.
*
* To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com
*
****************************************************************************/
#include <Python.h>
#include <bongo-config.h>
#include <xpl.h>
#include <bongoutil.h>
#include <string.h>
#include "libs.h"
#ifdef __cplusplus
extern "C" {
#endif
PyDoc_STRVAR(ModifiedUtf7ToUtf8_doc,
"ModifiedUtf7ToUtf8(s) -> string response\n\
\n\
Converts modified UTF-7 as described in IMAP (RFC 3501) into UTF-8.\n");
static PyObject *
bongoutil_ModifiedUtf7ToUtf8(PyObject *self, PyObject *args)
{
char *utf7;
unsigned int utf7Len;
char utf8[XPL_MAX_PATH];
unsigned int utf8Len;
if (!PyArg_ParseTuple(args, "s", &utf7)) {
return NULL;
}
utf7Len = strlen(utf7);
utf8Len = ModifiedUtf7ToUtf8(utf7, utf7Len, utf8, XPL_MAX_PATH);
if(utf8Len < 0) {
Py_INCREF(Py_None);
return Py_None;
}
utf8[utf8Len] = 0;
return Py_BuildValue("s", utf8);
}
PyMethodDef BongoUtilMethods[] = {
{"ModifiedUtf7ToUtf8", bongoutil_ModifiedUtf7ToUtf8, METH_VARARGS | METH_STATIC, ModifiedUtf7ToUtf8_doc},
{NULL, NULL, 0, NULL}
};
#ifdef __cplusplus
}
#endif
+77
View File
@@ -0,0 +1,77 @@
/****************************************************************************
*
* Copyright (c) 2006 Novell, Inc.
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, contact Novell, Inc.
*
* To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com
*
****************************************************************************/
/*
* The bootstrap library is a very stripped-down version of "libs".
* For bootstrapping the directory or doing other tasks before Bongo has
* been set up, this library (which does only minimal initialization) may
* be imported instead of the full "libs".
*/
#include <Python.h>
#include "bootstrap.h"
#include "msgapi-defs.h"
#include <bongo-config.h>
#include <mdb.h>
#include <memmgr.h>
#include <msgapi.h>
#ifdef __cplusplus
extern "C" {
#endif
static PyMethodDef ModuleMethods[] = { {NULL} };
extern EnumItemDef MdbEnums[];
extern PyMethodDef MdbMethods[];
extern EnumItemDef MsgApiEnums[];
PyMethodDef MsgApiMethods[] = {
{"GetConfigProperty", msgapi_GetConfigProperty,
METH_VARARGS | METH_STATIC, GetConfigProperty_doc},
{"GetUnprivilegedUser", msgapi_GetUnprivilegedUser,
METH_VARARGS | METH_STATIC, GetUnprivilegedUser_doc},
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC
initbootstrap()
{
MDBHandle directoryHandle=NULL;
char dbfdir[PATH_MAX];
/* Initialize the various bongo libraries */
if (!MemoryManagerOpen((unsigned char*)"pybongo")) {
PyErr_SetString(PyExc_ImportError,
"bongo.libs error: MemoryManagerOpen() failed");
return;
}
/* Create the libs module */
PyObject *module = Py_InitModule("bootstrap", ModuleMethods);
/* Add the Bongo libs */
AddLibrary(module, "mdb", MdbMethods, MdbEnums);
AddLibrary(module, "msgapi", MsgApiMethods, MsgApiEnums);
}
#ifdef __cplusplus
}
#endif
+36
View File
@@ -0,0 +1,36 @@
/****************************************************************************
*
* Copyright (c) 2006 Novell, Inc.
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, contact Novell, Inc.
*
* To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com
*
****************************************************************************/
#ifndef PYBONGO_BOOTSTRAP_H
#define PYBONGO_BOOTSTRAP_H
#ifdef __cplusplus
extern "C" {
#endif
#include "pybongo.h"
#ifdef __cplusplus
}
#endif
#endif /* PYBONGO_LIBS_H */
+328
View File
@@ -0,0 +1,328 @@
#include <Python.h>
#include <datetime.h>
#include <bongo-config.h>
#include <bongojson.h>
#include <bongocal.h>
#include "libs.h"
#ifdef __cplusplus
extern "C" {
#endif
static PyObject *
cal_Merge(PyObject *self, PyObject *args)
{
JsonObject *a;
JsonObject *b;
JsonObject *ret;
if (!PyArg_ParseTuple(args, "OO", &a, &b)) {
PyErr_SetString(PyExc_TypeError, "Merge() takes 2 arguments");
return NULL;
}
BongoCalMerge(a->obj, b->obj);
/* caller shouldn't use the old objects anymore */
a->own = FALSE;
a->valid = FALSE;
b->own = FALSE;
b->valid = FALSE;
ret = PyObject_New(JsonObject, &JsonObjectType);
ret->obj = a->obj;
ret->own = TRUE;
ret->valid = TRUE;
return (PyObject*)ret;
}
static int
GetIntAttr(PyObject *obj, char *attrname, int defval)
{
PyObject *attr;
int ret;
attr = PyObject_GetAttrString(obj, attrname);
if (PyInt_Check(attr)) {
ret = PyInt_AsLong(attr);
} else if (PyLong_Check(attr)) {
ret = PyLong_AsLong(attr);
} else {
ret = defval;
}
Py_DECREF(attr);
return ret;
}
static BongoCalTime
CalTimeFromPy(PyObject *dt)
{
BongoCalTime t;
t = BongoCalTimeEmpty();
t.year = GetIntAttr(dt, "year", 1970);
t.month = GetIntAttr(dt, "month", 1) - 1;
t.day = GetIntAttr(dt, "day", 1);
t.hour = GetIntAttr(dt, "hour", 0);
t.minute = GetIntAttr(dt, "minute", 0);
t.second = GetIntAttr(dt, "second", 0);
return t;
}
static PyObject *
cal_PrimaryOccurrence(PyObject *self, PyObject *args)
{
JsonObject *json;
const char *tzid;
BongoCalObject *cal;
BongoCalOccurrence occ;
BongoCalTimezone *tz;
BongoJsonObject *occJson;
if (!PyArg_ParseTuple(args, "Oz", &json, &tzid)) {
PyErr_SetString(PyExc_TypeError, "PrimaryOccurrence() takes 2 arguments");
return NULL;
}
cal = BongoCalObjectNew(json->obj);
tz = BongoCalObjectGetTimezone(cal, tzid);
occ = BongoCalObjectPrimaryOccurrence(cal, tz);
if (BongoCalTimeIsEmpty(occ.start)) {
Py_INCREF(Py_None);
return Py_None;
}
occJson = BongoCalOccurrenceToJson(occ, tz);
return JsonObjectToPy(occJson, TRUE);
}
static PyObject *
cal_Collect(PyObject *self, PyObject *args)
{
JsonObject *json;
BongoCalObject *cal;
BongoArray *occs;
PyObject *dtstart;
PyObject *dtend;
const char *tzid;
BongoCalTime start;
BongoCalTime end;
if (!PyArg_ParseTuple(args, "OOOs", &json, &dtstart, &dtend, &tzid)) {
PyErr_SetString(PyExc_TypeError, "Collect() takes 4 arguments");
return NULL;
}
if (!dtstart || !dtend) {
PyErr_SetString(PyExc_TypeError, "Collect() requires a start and end time");
return NULL;
}
#ifdef PyDateTime_IMPORT
if (!PyDate_Check(dtstart) || !PyDate_Check(dtend)) {
PyErr_SetString(PyExc_TypeError, "Invalid type for dtstart or dtend (needs DateTime)");
return NULL;
}
#endif
start = CalTimeFromPy(dtstart);
end = CalTimeFromPy(dtend);
cal = BongoCalObjectNew(json->obj);
occs = BongoArrayNew(sizeof(BongoCalOccurrence), 16);
if (BongoCalObjectCollect(cal, start, end, NULL, TRUE, occs)) {
JsonArray *ret;
BongoArray *occsJson;
occsJson = BongoCalOccurrencesToJson(occs, BongoCalObjectGetTimezone(cal, tzid));
BongoArrayFree(occs, TRUE);
ret = PyObject_New(JsonArray, &JsonArrayType);
ret->array = occsJson;
ret->own = TRUE;
return (PyObject*)ret;
} else {
BongoArrayFree(occs, TRUE);
Py_INCREF(Py_None);
return Py_None;
}
}
static PyObject *
cal_JsonToIcal(PyObject *self, PyObject *args)
{
JsonObject *a;
BongoCalObject *cal;
icalcomponent *comp;
if (!PyArg_ParseTuple(args, "O", &a)) {
PyErr_SetString(PyExc_TypeError, "JsonToIcal() takes 2 arguments");
return NULL;
}
cal = BongoCalObjectNew(a->obj);
BongoCalObjectResolveSystemTimezones(cal);
BongoCalObjectFree(cal, FALSE);
comp = BongoCalJsonToIcal(a->obj);
if (comp) {
PyObject *ret;
ret = Py_BuildValue("s", icalcomponent_as_ical_string(comp));
icalcomponent_free(comp);
return ret;
} else {
PyErr_SetString(PyExc_ValueError, "Couldn't convert json object");
return NULL;
}
}
static PyObject *
cal_IcalToJson(PyObject *self, PyObject *args)
{
BongoJsonObject *json;
icalcomponent *comp;
char *str;
if (!PyArg_ParseTuple(args, "s", &str)) {
PyErr_SetString(PyExc_TypeError, "IcalToJson() takes 2 arguments");
return NULL;
}
comp = icalparser_parse_string(str);
json = BongoCalIcalToJson(comp);
icalcomponent_free(comp);
return JsonObjectToPy(json, TRUE);
}
static PyObject *
cal_BongoCalTimeToStringConcise(PyObject *self, PyObject *args)
{
BongoCalTime t;
char *str;
char buf[128];
if (!PyArg_ParseTuple(args, "s", &str)) {
PyErr_SetString(PyExc_TypeError, "BongoCalTimeToStringConcise() takes 1 arguments");
return NULL;
}
t = BongoCalTimeParseIcal(str);
if (BongoCalTimeIsEmpty(t)) {
PyErr_SetString(PyExc_ValueError, "could not parse ical time");
return NULL;
}
BongoCalTimeToStringConcise(t, buf, sizeof(buf));
return Py_BuildValue("s", buf);
}
static BongoCalTimezone *
GetTz(const char *tzid, BongoCalObject **cal, const char *json)
{
if (!strcmp(tzid, "/bongo/UTC")) {
return BongoCalTimezoneGetUtc();
}
if (!strncmp(tzid, "/bongo/", 6)) {
return BongoCalTimezoneGetSystem(tzid);
}
if (*cal == NULL) {
*cal = BongoCalObjectParseString(json);
}
if (*cal == NULL) {
return NULL;
}
return BongoCalObjectGetTimezone(*cal, tzid);
}
static PyObject *
cal_ConvertTzid(PyObject *self, PyObject *args)
{
BongoCalTime t;
const char *json;
const char *timestr;
const char *tzidFrom;
const char *tzidTo;
BongoCalObject *cal = NULL;
char buf[BONGO_CAL_TIME_BUFSIZE + 1];
BongoCalTimezone *tzFrom;
BongoCalTimezone *tzTo;
if (!PyArg_ParseTuple(args, "ssss", &json, &timestr, &tzidFrom, &tzidTo)) {
PyErr_SetString(PyExc_TypeError, "ConvertTzid() takes 4 arguments");
return NULL;
}
tzFrom = GetTz(tzidFrom, &cal, json);
tzTo = GetTz(tzidTo, &cal, json);
if (!tzFrom) {
PyErr_SetString(PyExc_RuntimeError, "Couldn't find tzid");
return NULL;
}
if (!tzTo) {
PyErr_SetString(PyExc_RuntimeError, "Couldn't find tzid");
return NULL;
}
t = BongoCalTimeParseIcal(timestr);
if (BongoCalTimeIsEmpty(t)) {
PyErr_SetString(PyExc_RuntimeError, "Couldn't parse time");
return NULL;
}
t = BongoCalTimeSetTimezone(t, tzFrom);
t = BongoCalTimezoneConvertTime(t, tzTo);
BongoCalTimeToIcal(t, buf, BONGO_CAL_TIME_BUFSIZE);
if (cal) {
BongoCalObjectFree(cal, TRUE);
}
return Py_BuildValue("s", buf);
}
int
BongoCalPostInit(PyObject *module)
{
#ifdef PyDateTime_IMPORT
PyDateTime_IMPORT;
#endif
return 0;
}
PyMethodDef CalMethods[] = {
{"Merge", cal_Merge, METH_VARARGS | METH_STATIC},
{"Collect", cal_Collect, METH_VARARGS | METH_STATIC},
{"IcalToJson", cal_IcalToJson, METH_VARARGS | METH_STATIC},
{"JsonToIcal", cal_JsonToIcal, METH_VARARGS | METH_STATIC},
{"PrimaryOccurrence", cal_PrimaryOccurrence, METH_VARARGS | METH_STATIC},
{"TimeToStringConcise", cal_BongoCalTimeToStringConcise, METH_VARARGS | METH_STATIC },
{"ConvertTzid", cal_ConvertTzid, METH_VARARGS | METH_STATIC },
{NULL, NULL, 0, NULL}
};
#ifdef __cplusplus
}
#endif
+207
View File
@@ -0,0 +1,207 @@
#include <Python.h>
#include <bongo-config.h>
#include <calcmd.h>
#include <msgapi.h>
#include "libs.h"
#include <connio.h>
#ifdef __cplusplus
extern "C" {
#endif
static PyObject *
calcmd_CalCmdNew(PyObject *self, PyObject *args)
{
char *cmdstr;
char *tzid;
CalCmdCommand *cmd;
if (!PyArg_ParseTuple(args, "sz", &cmdstr, &tzid)) {
return NULL;
}
cmd = CalCmdNew(cmdstr, BongoCalTimezoneGetSystem(tzid));
if (cmd == NULL) {
PyErr_SetString(PyExc_ValueError, "could not parse calendar command");
return NULL;
}
return PyCObject_FromVoidPtr(cmd, (void *)CalCmdFree);
}
static PyObject *
PyTuple_FromCalTime(BongoCalTime time)
{
return Py_BuildValue("(iiiiii)",
time.second, time.minute,
time.hour, time.day,
time.month + 1, time.year);
}
static PyObject *
calcmd_CalCmdGetBegin(PyObject *self, PyObject *args)
{
CalCmdCommand *cmd;
PyObject *cmdObj;
if (!PyArg_ParseTuple(args, "O", &cmdObj)) {
return NULL;
}
if (cmdObj == Py_None) {
PyErr_SetString(PyExc_ValueError, "calcmd object is None");
return NULL;
}
cmd = PyCObject_AsVoidPtr(cmdObj);
return PyTuple_FromCalTime(cmd->begin);
}
static PyObject *
calcmd_CalCmdGetData(PyObject *self, PyObject *args)
{
CalCmdCommand *cmd;
PyObject *cmdObj;
if (!PyArg_ParseTuple(args, "O", &cmdObj)) {
return NULL;
}
if (cmdObj == Py_None) {
PyErr_SetString(PyExc_ValueError, "calcmd object is None");
return NULL;
}
cmd = PyCObject_AsVoidPtr(cmdObj);
return Py_BuildValue("s", cmd->data);
}
static PyObject *
calcmd_CalCmdGetEnd(PyObject *self, PyObject *args)
{
CalCmdCommand *cmd;
PyObject *cmdObj;
if (!PyArg_ParseTuple(args, "O", &cmdObj)) {
return NULL;
}
if (cmdObj == Py_None) {
PyErr_SetString(PyExc_ValueError, "calcmd object is None");
return NULL;
}
cmd = PyCObject_AsVoidPtr(cmdObj);
return PyTuple_FromCalTime(cmd->end);
}
static PyObject *
calcmd_CalCmdGetType(PyObject *self, PyObject *args)
{
CalCmdCommand *cmd;
PyObject *cmdObj;
int type;
if (!PyArg_ParseTuple(args, "O", &cmdObj)) {
return NULL;
}
if (cmdObj == Py_None) {
PyErr_SetString(PyExc_ValueError, "calcmd object is None");
return NULL;
}
cmd = PyCObject_AsVoidPtr(cmdObj);
type = CalCmdGetType(cmd);
return Py_BuildValue("i", type);
}
static PyObject *
calcmd_CalCmdGetJson(PyObject *self, PyObject *args)
{
CalCmdCommand *cmd;
PyObject *cmdObj;
PyObject *ret;
BongoCalObject *cal;
char uid[CONN_BUFSIZE];
if (!PyArg_ParseTuple(args, "O", &cmdObj)) {
return NULL;
}
if (cmdObj == Py_None) {
PyErr_SetString(PyExc_ValueError, "calcmd object is None");
return NULL;
}
cmd = PyCObject_AsVoidPtr(cmdObj);
MsgGetUid(uid, CONN_BUFSIZE);
cal = CalCmdProcessNewAppt(cmd, uid);
if (!cal) {
PyErr_SetString(PyExc_ValueError, "couldn't create calendar object");
return NULL;
}
printf("cal is %s\n", BongoJsonObjectToString(BongoCalObjectGetJson(cal)));
ret = JsonObjectToPy(BongoCalObjectGetJson(cal), TRUE);
BongoCalObjectFree(cal, FALSE);
return ret;
}
static PyObject *
calcmd_CalCmdGetConciseDateTimeRange(PyObject *self, PyObject *args)
{
CalCmdCommand *cmd;
PyObject *cmdObj;
char buf[128];
if (!PyArg_ParseTuple(args, "O", &cmdObj)) {
return NULL;
}
if (cmdObj == Py_None) {
PyErr_SetString(PyExc_ValueError, "calcmd object is None");
return NULL;
}
cmd = PyCObject_AsVoidPtr(cmdObj);
CalCmdPrintConciseDateTimeRange(cmd, buf, sizeof(buf));
return Py_BuildValue("s", buf);
}
PyMethodDef CalCmdMethods[] = {
{"New", calcmd_CalCmdNew, METH_VARARGS | METH_STATIC},
{"GetBegin", calcmd_CalCmdGetBegin, METH_VARARGS | METH_STATIC},
{"GetData", calcmd_CalCmdGetData, METH_VARARGS | METH_STATIC},
{"GetEnd", calcmd_CalCmdGetEnd, METH_VARARGS | METH_STATIC},
{"GetType", calcmd_CalCmdGetType, METH_VARARGS | METH_STATIC},
{"GetJson", calcmd_CalCmdGetJson, METH_VARARGS | METH_STATIC},
{"GetConciseDateTimeRange",
calcmd_CalCmdGetConciseDateTimeRange, METH_VARARGS | METH_STATIC },
{NULL, NULL, 0, NULL}
};
EnumItemDef CalCmdEnums[] = {
{"ERROR", CALCMD_ERROR, NULL},
{"QUERY", CALCMD_QUERY, NULL},
{"QUERY_CONFLICTS", CALCMD_QUERY_CONFLICTS, NULL},
{"NEW_APPT", CALCMD_NEW_APPT, NULL},
{"HELP", CALCMD_HELP, NULL},
{NULL, 0, NULL}
};
#ifdef __cplusplus
}
#endif
+684
View File
@@ -0,0 +1,684 @@
#include <Python.h>
#include "structmember.h"
#include <bongo-config.h>
#include <bongojson.h>
#include <bongocal.h>
#include "libs.h"
XPL_BEGIN_C_LINKAGE
static PyMemberDef JsonObject_members[] = {
{NULL}
};
static PyMethodDef JsonObject_methods[] = {
{NULL}
};
static PyMappingMethods JsonObject_mapping = {
JsonObject_length,
JsonObject_subscript,
JsonObject_subscript_assign
};
PyTypeObject JsonObjectType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
"libs.JsonObject",
sizeof(JsonObject),
0, /*tp_itemsize*/
(destructor)JsonObject_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
&JsonObject_mapping, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
JsonObject_str, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"Bongo Json Object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
JsonObject_methods, /* tp_methods */
JsonObject_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)JsonObject_init, /* tp_init */
0, /* tp_alloc */
JsonObject_new, /* tp_new */
};
static PyMemberDef JsonArray_members[] = {
{NULL}
};
static PyMethodDef JsonArray_methods[] = {
{"append", JsonArray_append, METH_VARARGS, "Add a json object"},
{NULL}
};
static PySequenceMethods JsonArray_sequence = {
JsonArray_length,
JsonArray_concat,
JsonArray_repeat,
JsonArray_item,
JsonArray_slice,
JsonArray_assign,
JsonArray_assign_slice,
JsonArray_contains,
JsonArray_inplace_concat,
JsonArray_inplace_repeat
};
PyTypeObject JsonArrayType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
"libs.JsonArray",
sizeof(JsonArray),
0, /*tp_itemsize*/
(destructor)JsonArray_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
&JsonArray_sequence, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
JsonArray_str, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"Bongo Json Array", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
JsonArray_methods, /* tp_methods */
JsonArray_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)JsonArray_init, /* tp_init */
0, /* tp_alloc */
JsonArray_new, /* tp_new */
};
static void
RaiseJsonError(BongoJsonResult res)
{
PyErr_Format(PyExc_ValueError, "Error parsing json: %d", res);
}
static BongoJsonNode *
JsonPyToNode(PyObject *obj)
{
BongoJsonNode *node;
if (obj == Py_None) {
return BongoJsonNodeNewNull();
} else if (PyBool_Check(obj)) {
if (obj == Py_False) {
node = BongoJsonNodeNewBool(FALSE);
} else {
node = BongoJsonNodeNewBool(TRUE);
}
} else if (PyInt_Check(obj)) {
node = BongoJsonNodeNewInt(PyInt_AsLong(obj));
} else if (PyLong_Check(obj)) {
node = BongoJsonNodeNewInt(PyLong_AsLong(obj));
} else if (PyFloat_Check(obj)) {
node = BongoJsonNodeNewDouble(PyFloat_AsDouble(obj));
} else if (PyString_Check(obj)) {
node = BongoJsonNodeNewString(PyString_AsString(obj));
} else if (PyUnicode_Check(obj)) {
PyObject *utf8 = PyUnicode_AsUTF8String(obj);
node = BongoJsonNodeNewString(PyString_AsString(utf8));
Py_DECREF(utf8);
} else if (PyList_Check(obj)) {
BongoArray *array;
int len = PyList_Size(obj);
int i;
array = BongoArrayNew(sizeof(BongoJsonNode*), len);
for (i=0; i<len; i++) {
BongoJsonNode *item = JsonPyToNode(PyList_GetItem(obj, i));
BongoArrayAppendValue(array, item);
}
node = BongoJsonNodeNewArray(array);
} else if (PyObject_IsInstance(obj, (PyObject*)&JsonObjectType)) {
JsonObject *json = ((JsonObject*)obj);
node = BongoJsonNodeNewObject(json->obj);
json->own = FALSE;
} else if (PyObject_IsInstance(obj, (PyObject*)&JsonArrayType)) {
JsonArray *json = ((JsonArray*)obj);
node = BongoJsonNodeNewArray(json->array);
json->own = FALSE;
} else {
node = NULL;
}
if (node == NULL) {
PyErr_SetString(PyExc_TypeError, "Creating JSON node from unsupported type");
}
return node;
}
PyObject *
JsonObjectToPy(BongoJsonObject *object, BOOL own)
{
PyObject *ret = (PyObject*)PyObject_New(JsonObject, &JsonObjectType);
((JsonObject*)ret)->obj = object;
((JsonObject*)ret)->own = own;
((JsonObject*)ret)->valid = TRUE;
return ret;
}
static PyObject *
JsonObjectToPyNative(BongoJsonObject *obj)
{
PyObject *ret;
ret = PyDict_New();
BongoJsonObjectIter iter;
for (BongoJsonObjectIterFirst(obj, &iter);
iter.key != NULL;
BongoJsonObjectIterNext(obj, &iter)) {
PyObject *child;
child = JsonNodeToPy(iter.value, FALSE, TRUE);
if (!child) {
Py_DECREF(ret);
return NULL;
}
if (PyDict_SetItemString (ret, iter.key, child) == -1) {
Py_DECREF(ret);
return NULL;
}
}
return ret;
}
static PyObject *
JsonArrayToPyNative(BongoArray *array)
{
PyObject *ret;
unsigned int i;
ret = PyList_New(0);
for (i = 0; i < array->len; i++) {
PyObject *child;
child = JsonNodeToPy (BongoJsonArrayGet(array, i), FALSE, TRUE);
if (!child) {
Py_DECREF(ret);
return NULL;
}
if (PyList_Append (ret, child) == -1) {
Py_DECREF(ret);
return NULL;
}
}
return ret;
}
PyObject *
JsonNodeToPy(BongoJsonNode *node, BOOL own, BOOL native)
{
PyObject *ret;
char *str;
switch(node->type) {
case BONGO_JSON_OBJECT :
if (native) {
return JsonObjectToPyNative(BongoJsonNodeAsObject(node));
} else {
ret = JsonObjectToPy(BongoJsonNodeAsObject(node), own);
}
break;
case BONGO_JSON_ARRAY :
if (native) {
return JsonArrayToPyNative(BongoJsonNodeAsArray (node));
} else {
ret = (PyObject*)PyObject_New(JsonArray, &JsonArrayType);
((JsonArray*)ret)->own = own;
((JsonArray*)ret)->array = BongoJsonNodeAsArray(node);
}
case BONGO_JSON_BOOL :
if (BongoJsonNodeAsBool(node)) {
ret = Py_True;
} else {
ret = Py_False;
}
Py_INCREF(ret);
break;
case BONGO_JSON_DOUBLE :
ret = Py_BuildValue("d", BongoJsonNodeAsDouble(node));
break;
case BONGO_JSON_INT :
ret = Py_BuildValue("i", BongoJsonNodeAsInt(node));
break;
case BONGO_JSON_STRING :
str = BongoJsonNodeAsString(node);
ret = PyUnicode_DecodeUTF8(str, strlen(str), NULL);
break;
default :
PyErr_Format(PyExc_ValueError, "Unknown node type: %d", node->type);
ret = NULL;
}
return ret;
}
/*** JsonArray ***/
void
JsonArray_dealloc(JsonArray *self)
{
if (self->own) {
BongoJsonArrayFree(self->array);
}
self->ob_type->tp_free((PyObject*)self);
}
PyObject *
JsonArray_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
JsonArray *self;
self = (JsonArray*)type->tp_alloc(type, 0);
self->own = FALSE;
self->array = NULL;
return self;
}
int
JsonArray_init(JsonArray *self, PyObject *args, PyObject *kwds)
{
self->own = TRUE;
self->array = BongoArrayNew(sizeof(BongoJsonNode*), 16);
return 0;
}
PyObject *
JsonArray_append(PyObject *selfp, PyObject *args)
{
JsonArray *self = (JsonArray*)selfp;
PyObject *obj;
BongoJsonNode *node;
if (!PyArg_ParseTuple(args, "O", &obj)) {
PyErr_SetString(PyExc_TypeError, "append() takes 1 argument");
return NULL;
}
node = JsonPyToNode(obj);
if (!node) {
return NULL;
}
BongoJsonArrayAppend(self->array, node);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *
JsonArray_str(PyObject *selfp)
{
JsonArray *self = (JsonArray *)selfp;
PyObject *ret;
char *str;
str = BongoJsonArrayToString(self->array);
ret = Py_BuildValue("s", str);
MemFree(str);
return ret;
}
int
JsonArray_length(PyObject *selfp)
{
JsonArray *self = (JsonArray *)selfp;
return self->array->len;
}
PyObject *
JsonArray_concat(PyObject *selfp, PyObject *b)
{
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
return NULL;
}
PyObject *
JsonArray_repeat(PyObject *selfp, int i)
{
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
return NULL;
}
PyObject *
JsonArray_item(PyObject *selfp, int i)
{
JsonArray *self = (JsonArray *)selfp;
BongoJsonNode *node;
if (i < 0 || i >= self->array->len) {
PyErr_SetString(PyExc_IndexError, "Out of bounds");
return NULL;
}
node = BongoJsonArrayGet(self->array, i);
return JsonNodeToPy(node, FALSE, FALSE);
}
PyObject *
JsonArray_slice(PyObject *selfp, int i1, int i2)
{
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
return NULL;
}
int
JsonArray_assign(PyObject *selfp, int i, PyObject *obj)
{
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
return 0;
}
int
JsonArray_assign_slice(PyObject *selfp, int i1, int i2, PyObject *obj)
{
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
return 0;
}
int
JsonArray_contains(PyObject *selfp, PyObject *b)
{
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
return 0;
}
PyObject *
JsonArray_inplace_concat(PyObject *selfp, PyObject *b)
{
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
return NULL;
}
PyObject *
JsonArray_inplace_repeat(PyObject *selfp, int i)
{
PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
return NULL;
}
/*** JsonObject ***/
void
JsonObject_dealloc(JsonObject *self)
{
#if 0
if (self->obj) {
BongoJsonObjectFree(self->obj);
}
#endif
self->ob_type->tp_free((PyObject*)self);
}
PyObject *
JsonObject_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
JsonObject *self;
self = (JsonObject*)type->tp_alloc(type, 0);
self->obj = NULL;
self->own = FALSE;
self->valid = TRUE;
return self;
}
int
JsonObject_init(JsonObject *self, PyObject *args, PyObject *kwds)
{
self->obj = BongoJsonObjectNew();
self->own = TRUE;
self->valid = TRUE;
return 0;
}
PyObject *
JsonObject_str(PyObject *selfp)
{
JsonObject *self = (JsonObject *)selfp;
PyObject *ret;
char *str;
str = BongoJsonObjectToString(self->obj);
ret = Py_BuildValue("s", str);
MemFree(str);
return ret;
}
int
JsonObject_length(PyObject *self)
{
/* FIXME */
return 1;
}
PyObject *
JsonObject_subscript(PyObject *selfp, PyObject *key)
{
JsonObject *self = (JsonObject*)selfp;
char *str;
BongoJsonNode *node;
BongoJsonResult res;
if (!PyString_Check(key)) {
PyErr_SetString(PyExc_KeyError, "Key must be a string");
return NULL;
}
str = PyString_AsString(key);
res = BongoJsonObjectGet(self->obj, str, &node);
if (res != BONGO_JSON_OK) {
RaiseJsonError(res);
return NULL;
}
return JsonNodeToPy(node, FALSE, FALSE);
}
int
JsonObject_subscript_assign(PyObject *selfp, PyObject *key, PyObject *value)
{
JsonObject *self = (JsonObject*)selfp;
BongoJsonNode *node;
BongoJsonResult res;
node = JsonPyToNode(value);
if (!node) {
return 0;
}
if (!PyString_Check(key)) {
PyErr_SetString(PyExc_KeyError, "Key must be a string");
return 0;
}
res = BongoJsonObjectPut(self->obj, PyString_AsString(key), node);
if (res != BONGO_JSON_OK) {
RaiseJsonError(res);
return 0;
}
return 0;
}
/* Static */
BOOL
BongoJsonPreInit(void)
{
JsonObjectType.tp_new = PyType_GenericNew;
if (PyType_Ready(&JsonObjectType) < 0) {
return FALSE;
}
JsonArrayType.tp_new = PyType_GenericNew;
if (PyType_Ready(&JsonArrayType) < 0) {
return FALSE;
}
return TRUE;
}
BOOL
BongoJsonPostInit(PyObject *module)
{
Py_INCREF(&JsonObjectType);
PyModule_AddObject(module, "JsonObject", (PyObject *)&JsonObjectType);
Py_INCREF(&JsonArrayType);
PyModule_AddObject(module, "JsonArray", (PyObject *)&JsonArrayType);
return TRUE;
}
static PyObject *
bongojson_BongoJsonParseString(PyObject *self, PyObject *args)
{
char *jsonStr;
BongoJsonNode *node;
BongoJsonResult res;
PyObject *ret;
PyObject *obj;
PyObject *strObj = NULL;
if (!PyArg_ParseTuple(args, "O", &obj)) {
PyErr_SetString(PyExc_TypeError, "ParseString takes one argument");
return NULL;
}
if (PyString_Check(obj)) {
jsonStr = PyString_AsString(obj);
} else if (PyUnicode_Check(obj)) {
strObj = PyUnicode_AsUTF8String(obj);
jsonStr = PyString_AsString(strObj);
} else {
PyErr_SetString(PyExc_TypeError, "Argument 1 must be a string or unicode object");
return NULL;
}
res = BongoJsonParseString(jsonStr, &node);
if (strObj) {
Py_DECREF(strObj);
}
if (res != BONGO_JSON_OK) {
RaiseJsonError(res);
return NULL;
}
/* Pull out the value and throw away the node */
ret = JsonNodeToPy(node, FALSE, FALSE);
if (node->type == BONGO_JSON_STRING) {
BongoJsonNodeFree(node);
} else {
BongoJsonNodeFreeSteal(node);
}
return ret;
}
static PyObject *
bongojson_ToPy(PyObject *self, PyObject *args)
{
PyObject *obj;
PyObject *ret;
if (!PyArg_ParseTuple(args, "O", &obj)) {
PyErr_SetString(PyExc_TypeError, "ToPy takes one argument");
return NULL;
}
if (PyObject_IsInstance(obj, (PyObject*)&JsonObjectType)) {
JsonObject *json = ((JsonObject*)obj);
ret = JsonObjectToPyNative(json->obj);
if (!ret) {
PyErr_SetString(PyExc_RuntimeError, "Couldn't convert json to python");
return NULL;
}
return ret;
} else if (PyObject_IsInstance(obj, (PyObject*)&JsonArrayType)) {
JsonArray *json = ((JsonArray*)obj);
ret = JsonArrayToPyNative(json->array);
if (!ret) {
PyErr_SetString(PyExc_RuntimeError, "Couldn't convert json to python");
return NULL;
}
return ret;
} else {
PyErr_SetString(PyExc_TypeError, "Argument 1 must be a bongojson object or array");
return NULL;
}
}
PyMethodDef BongoJsonMethods[] = {
{"ParseString", bongojson_BongoJsonParseString, METH_VARARGS | METH_STATIC, "Parse a json string"},
{"ToPy", bongojson_ToPy, METH_VARARGS | METH_STATIC, "Convert a json object to a native python object"},
{NULL, NULL, 0, NULL}
};
XPL_END_C_LINKAGE
+81
View File
@@ -0,0 +1,81 @@
#ifndef PYBONGO_JSON_H
#define PYBONGO_JSON_H
#include <Python.h>
#include <structmember.h>
#include <bongojson.h>
#include <bongocal.h>
#ifdef __cplusplus
extern "C" {
#endif
BOOL BongoJsonPreInit(void);
BOOL BongoJsonPostInit(PyObject *module);
/*** JsonObject ***/
typedef struct {
PyObject_HEAD
BongoJsonObject *obj;
BOOL own;
BOOL valid;
} JsonObject;
/*** JsonArray ***/
typedef struct {
PyObject_HEAD
BOOL own;
BongoArray *array;
} JsonArray;
/* Object protocol */
PyObject *JsonObject_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
int JsonObject_init(JsonObject *self, PyObject *args, PyObject *kwds);
void JsonObject_dealloc(JsonObject *self);
PyObject *JsonObject_str(PyObject *selfp);
/* Mapping protocol */
int JsonObject_length(PyObject *self);
PyObject *JsonObject_subscript(PyObject *self, PyObject *key);
int JsonObject_subscript_assign(PyObject *self, PyObject *key, PyObject *value);
extern PyTypeObject JsonObjectType;
/* Object protocol */
PyObject *JsonArray_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
int JsonArray_init(JsonArray *self, PyObject *args, PyObject *kwds);
void JsonArray_dealloc(JsonArray *self);
PyObject *JsonArray_str(PyObject *selfp);
/* Methods */
PyObject *JsonArray_append(PyObject *selfp, PyObject *args);
extern PyTypeObject JsonArrayType;
/* Sequence protocol */
int JsonArray_length(PyObject *selfp);
PyObject *JsonArray_concat(PyObject *selfp, PyObject *b);
PyObject *JsonArray_repeat(PyObject *selfp, int i);
PyObject *JsonArray_item(PyObject *selfp, int i);
PyObject *JsonArray_slice(PyObject *selfp, int i1, int i2);
int JsonArray_assign(PyObject *selfp, int i, PyObject *obj);
int JsonArray_assign_slice(PyObject *selfp, int i1, int i2, PyObject *obj);
int JsonArray_contains(PyObject *selfp, PyObject *b);
PyObject *JsonArray_inplace_concat(PyObject *selfp, PyObject *b);
PyObject *JsonArray_inplace_repeat(PyObject *selfp, int i);
PyObject *JsonObjectToPy(BongoJsonObject *object, BOOL own);
PyObject *JsonNodeToPy(BongoJsonNode *node, BOOL own, BOOL native);
#ifdef __cplusplus
}
#endif
#endif /* PYBONGO_JSON_H */
+125
View File
@@ -0,0 +1,125 @@
/****************************************************************************
*
* Copyright (c) 2006 Novell, Inc.
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, contact Novell, Inc.
*
* To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com
*
****************************************************************************/
#include <Python.h>
#include "libs.h"
#include "pybongo.h"
#include <bongo-config.h>
#include <xpl.h>
#include <mdb.h>
#include <connio.h>
#include <memmgr.h>
#include <msgapi.h>
#include <nmlib.h>
#include <streamio.h>
#include <bongojson.h>
#ifdef __cplusplus
extern "C" {
#endif
static PyMethodDef ModuleMethods[] = { {NULL} };
/* Pull in the methods from the bindings */
extern PyMethodDef CalCmdMethods[];
extern EnumItemDef CalCmdEnums[];
extern PyMethodDef CalMethods[];
extern PyMethodDef MdbMethods[];
extern EnumItemDef MdbEnums[];
extern PyMethodDef MsgApiMethods[];
extern EnumItemDef MsgApiEnums[];
extern PyMethodDef StreamIOMethods[];
extern PyMethodDef BongoJsonMethods[];
extern PyMethodDef BongoUtilMethods[];
PyMODINIT_FUNC
initlibs()
{
MDBHandle directoryHandle=NULL;
char dbfdir[PATH_MAX];
/* Initialize the various bongo libraries */
if (!MemoryManagerOpen((unsigned char*)"pybongo")) {
PyErr_SetString(PyExc_ImportError,
"bongo.libs error: MemoryManagerOpen() failed");
return;
}
if (!ConnStartup(DEFAULT_CONNECTION_TIMEOUT, TRUE)) {
PyErr_SetString(PyExc_ImportError,
"bongo.libs error: ConnStartup() failed");
return;
}
directoryHandle = MsgInit();
if (!directoryHandle) {
PyErr_SetString(PyExc_ImportError,
"bongo.libs error: MsgInit() failed");
return;
}
MsgGetDBFDir(dbfdir);
if (!BongoCalInit(dbfdir)) {
PyErr_SetString(PyExc_ImportError,
"bongo.libs error: BongoCalInit() failed");
return;
}
if (!NMAPInitialize(directoryHandle)) {
PyErr_SetString(PyExc_ImportError,
"bongo.libs error: NMAPInitialize() failed");
return;
}
if (!StreamioInit()) {
PyErr_SetString(PyExc_ImportError,
"bongo.libs error: StreamioInit() failed");
return;
}
if (!BongoJsonPreInit()) {
PyErr_SetString(PyExc_ImportError,
"bongo.libs error: BongoJsonPreInit() failed");
return;
}
/* Create the libs module */
PyObject *module = Py_InitModule("libs", ModuleMethods);
/* Add the Bongo libs */
AddLibrary(module, "cal", CalMethods, NULL);
AddLibrary(module, "calcmd", CalCmdMethods, CalCmdEnums);
AddLibrary(module, "mdb", MdbMethods, MdbEnums);
AddLibrary(module, "msgapi", MsgApiMethods, MsgApiEnums);
AddLibrary(module, "streamio", StreamIOMethods, NULL);
AddLibrary(module, "bongojson", BongoJsonMethods, NULL);
AddLibrary(module, "bongoutil", BongoUtilMethods, NULL);
BongoJsonPostInit(module);
BongoCalPostInit(module);
}
#ifdef __cplusplus
}
#endif
+30
View File
@@ -0,0 +1,30 @@
/****************************************************************************
*
* Copyright (c) 2006 Novell, Inc.
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, contact Novell, Inc.
*
* To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com
*
****************************************************************************/
#ifndef PYBONGO_LIBS_H
#define PYBONGO_LIBS_H
#include "pybongo.h"
#include "json.h"
#include <bongocal.h>
#endif /* PYBONGO_LIBS_H */
File diff suppressed because it is too large Load Diff
+294
View File
@@ -0,0 +1,294 @@
#include <Python.h>
#include "msgapi-defs.h"
PyObject *
msgapi_GetConfigProperty(PyObject *self, PyObject *args)
{
unsigned char *property;
unsigned char buf[256]; //MSGSRV_CONFIG_MAX_PROP_CHARS + 1
if (!PyArg_ParseTuple(args, "s", &property)) {
return NULL;
}
if(MsgGetConfigProperty(buf, property)) {
return Py_BuildValue("s", buf);
}
return NULL;
}
PyObject *
msgapi_GetUnprivilegedUser(PyObject *self, PyObject *args)
{
return Py_BuildValue("z", MsgGetUnprivilegedUser());
}
EnumItemDef MsgApiEnums[] = {
{"MAX_PROP_CHARS", MSGSRV_CONFIG_MAX_PROP_CHARS, NULL},
{"MESSAGING_SERVER", 0, MSGSRV_CONFIG_PROP_MESSAGING_SERVER},
{"WEB_ADMIN_SERVER", 0, MSGSRV_CONFIG_PROP_WEB_ADMIN_SERVER},
{"DEFAULT_CONTEXT", 0, MSGSRV_CONFIG_PROP_DEFAULT_CONTEXT},
{"BONGO_SERVICES", 0, MSGSRV_CONFIG_PROP_BONGO_SERVICES},
{"CONFIG_FILENAME", 0, MSGSRV_CONFIG_FILENAME},
{"ROOT", 0, MSGSRV_ROOT},
{"USER_SETTINGS_ROOT", 0, MSGSRV_USER_SETTINGS_ROOT},
{"C_ROOT", 0, MSGSRV_C_ROOT},
{"C_SERVER", 0, MSGSRV_C_SERVER},
{"C_WEBADMIN", 0, MSGSRV_C_WEBADMIN},
{"C_ADDRESSBOOK", 0, MSGSRV_C_ADDRESSBOOK},
{"C_AGENT", 0, MSGSRV_C_AGENT},
{"C_ALIAS", 0, MSGSRV_C_ALIAS},
{"C_ANTISPAM", 0, MSGSRV_C_ANTISPAM},
{"C_FINGER", 0, MSGSRV_C_FINGER},
{"C_GATEKEEPER", 0, MSGSRV_C_GATEKEEPER},
{"C_CONNMGR", 0, MSGSRV_C_CONNMGR},
{"C_IMAP", 0, MSGSRV_C_IMAP},
{"C_LIST", 0, MSGSRV_C_LIST},
{"C_NDSLIST", 0, MSGSRV_C_NDSLIST},
{"C_LISTCONTAINER", 0, MSGSRV_C_LISTCONTAINER},
{"C_LISTUSER", 0, MSGSRV_C_LISTUSER},
{"C_LISTAGENT", 0, MSGSRV_C_LISTAGENT},
{"C_STORE", 0, MSGSRV_C_STORE},
{"C_QUEUE", 0, MSGSRV_C_QUEUE},
{"C_POP", 0, MSGSRV_C_POP},
{"C_PROXY", 0, MSGSRV_C_PROXY},
{"C_RULESRV", 0, MSGSRV_C_RULESRV},
{"C_SIGNUP", 0, MSGSRV_C_SIGNUP},
{"C_SMTP", 0, MSGSRV_C_SMTP},
{"C_PARENTCONTAINER", 0, MSGSRV_C_PARENTCONTAINER},
{"C_PARENTOBJECT", 0, MSGSRV_C_PARENTOBJECT},
{"C_TEMPLATECONTAINER", 0, MSGSRV_C_TEMPLATECONTAINER},
{"C_ITIP", 0, MSGSRV_C_ITIP},
{"C_ANTIVIRUS", 0, MSGSRV_C_ANTIVIRUS},
{"C_RESOURCE", 0, MSGSRV_C_RESOURCE},
{"C_CONNMGR_MODULE", 0, MSGSRV_C_CONNMGR_MODULE},
{"C_CM_USER_MODULE", 0, MSGSRV_C_CM_USER_MODULE},
{"C_CM_LISTS_MODULE", 0, MSGSRV_C_CM_LISTS_MODULE},
{"C_CM_RBL_MODULE", 0, MSGSRV_C_CM_RBL_MODULE},
{"C_CM_RDNS_MODULE", 0, MSGSRV_C_CM_RDNS_MODULE},
{"C_CALCMD", 0, MSGSRV_C_CALCMD},
{"C_COLLECTOR", 0, MSGSRV_C_COLLECTOR},
{"C_USER", 0, MSGSRV_C_USER},
{"C_ORGANIZATIONAL_ROLE", 0, MSGSRV_C_ORGANIZATIONAL_ROLE},
{"C_ORGANIZATION", 0, MSGSRV_C_ORGANIZATION},
{"C_ORGANIZATIONAL_UNIT", 0, MSGSRV_C_ORGANIZATIONAL_UNIT},
{"C_GROUP", 0, MSGSRV_C_GROUP},
{"C_USER_SETTINGS_CONTAINER", 0, MSGSRV_C_USER_SETTINGS_CONTAINER},
{"C_USER_SETTINGS", 0, MSGSRV_C_USER_SETTINGS},
{"AGENT_ADDRESSBOOK", 0, MSGSRV_AGENT_ADDRESSBOOK},
{"AGENT_ALIAS", 0, MSGSRV_AGENT_ALIAS},
{"AGENT_ANTISPAM", 0, MSGSRV_AGENT_ANTISPAM},
{"AGENT_FINGER", 0, MSGSRV_AGENT_FINGER},
{"AGENT_GATEKEEPER", 0, MSGSRV_AGENT_GATEKEEPER},
{"AGENT_CALCMD", 0, MSGSRV_AGENT_CALCMD},
{"AGENT_CONNMGR", 0, MSGSRV_AGENT_CONNMGR},
{"AGENT_IMAP", 0, MSGSRV_AGENT_IMAP},
{"AGENT_LIST", 0, MSGSRV_AGENT_LIST},
{"AGENT_STORE", 0, MSGSRV_AGENT_STORE},
{"AGENT_QUEUE", 0, MSGSRV_AGENT_QUEUE},
{"AGENT_POP", 0, MSGSRV_AGENT_POP},
{"AGENT_PROXY", 0, MSGSRV_AGENT_PROXY},
{"AGENT_RULESRV", 0, MSGSRV_AGENT_RULESRV},
{"AGENT_SIGNUP", 0, MSGSRV_AGENT_SIGNUP},
{"AGENT_SMTP", 0, MSGSRV_AGENT_SMTP},
{"AGENT_ITIP", 0, MSGSRV_AGENT_ITIP},
{"AGENT_ANTIVIRUS", 0, MSGSRV_AGENT_ANTIVIRUS},
{"AGENT_DMC", 0, MSGSRV_AGENT_DMC},
{"AGENT_CMUSER", 0, MSGSRV_AGENT_CMUSER},
{"AGENT_CMLISTS", 0, MSGSRV_AGENT_CMLISTS},
{"AGENT_CMRBL", 0, MSGSRV_AGENT_CMRBL},
{"AGENT_CMRDNS", 0, MSGSRV_AGENT_CMRDNS},
{"AGENT_COLLECTOR", 0, MSGSRV_AGENT_COLLECTOR},
{"A_AGENT_STATUS", 0, MSGSRV_A_AGENT_STATUS},
{"A_ALIAS", 0, MSGSRV_A_ALIAS},
{"A_AUTHENTICATION_REQUIRED", 0, MSGSRV_A_AUTHENTICATION_REQUIRED},
{"A_CONFIGURATION", 0, MSGSRV_A_CONFIGURATION},
{"A_CLIENT", 0, MSGSRV_A_CLIENT},
{"A_CONTEXT", 0, MSGSRV_A_CONTEXT},
{"A_DOMAIN", 0, MSGSRV_A_DOMAIN},
{"A_EMAIL_ADDRESS", 0, MSGSRV_A_EMAIL_ADDRESS},
{"A_DISABLED", 0, MSGSRV_A_DISABLED},
{"A_FINGER_MESSAGE", 0, MSGSRV_A_FINGER_MESSAGE},
{"A_HOST", 0, MSGSRV_A_HOST},
{"A_IP_ADDRESS", 0, MSGSRV_A_IP_ADDRESS},
{"A_LDAP_SERVER", 0, MSGSRV_A_LDAP_SERVER},
{"A_LDAP_NMAP_SERVER", 0, MSGSRV_A_LDAP_NMAP_SERVER},
{"A_LDAP_SEARCH_DN", 0, MSGSRV_A_LDAP_SEARCH_DN},
{"A_MESSAGE_LIMIT", 0, MSGSRV_A_MESSAGE_LIMIT},
{"A_MESSAGING_SERVER", 0, MSGSRV_A_MESSAGING_SERVER},
{"A_MODULE_NAME", 0, MSGSRV_A_MODULE_NAME},
{"A_MODULE_VERSION", 0, MSGSRV_A_MODULE_VERSION},
{"A_MONITORED_QUEUE", 0, MSGSRV_A_MONITORED_QUEUE},
{"A_QUEUE_SERVER", 0, MSGSRV_A_QUEUE_SERVER},
{"A_STORE_SERVER", 0, MSGSRV_A_STORE_SERVER},
{"A_OFFICIAL_NAME", 0, MSGSRV_A_OFFICIAL_NAME},
{"A_QUOTA_MESSAGE", 0, MSGSRV_A_QUOTA_MESSAGE},
{"A_POSTMASTER", 0, MSGSRV_A_POSTMASTER},
{"A_REPLY_MESSAGE", 0, MSGSRV_A_REPLY_MESSAGE},
{"A_URL", 0, MSGSRV_A_URL},
{"A_RESOLVER", 0, MSGSRV_A_RESOLVER},
{"A_ROUTING", 0, MSGSRV_A_ROUTING},
{"A_SERVER_STATUS", 0, MSGSRV_A_SERVER_STATUS},
{"A_QUEUE_INTERVAL", 0, MSGSRV_A_QUEUE_INTERVAL},
{"A_QUEUE_TIMEOUT", 0, MSGSRV_A_QUEUE_TIMEOUT},
{"A_UID", 0, MSGSRV_A_UID},
{"A_VACATION_MESSAGE", 0, MSGSRV_A_VACATION_MESSAGE},
{"A_WORD", 0, MSGSRV_A_WORD},
{"A_MESSAGE_STORE", 0, MSGSRV_A_MESSAGE_STORE},
{"A_FORWARDING_ADDRESS", 0, MSGSRV_A_FORWARDING_ADDRESS},
{"A_FORWARDING_ENABLED", 0, MSGSRV_A_FORWARDING_ENABLED},
{"A_AUTOREPLY_ENABLED", 0, MSGSRV_A_AUTOREPLY_ENABLED},
{"A_AUTOREPLY_MESSAGE", 0, MSGSRV_A_AUTOREPLY_MESSAGE},
{"A_PORT", 0, MSGSRV_A_PORT},
{"A_SSL_PORT", 0, MSGSRV_A_SSL_PORT},
{"A_SNMP_DESCRIPTION", 0, MSGSRV_A_SNMP_DESCRIPTION},
{"A_SNMP_VERSION", 0, MSGSRV_A_SNMP_VERSION},
{"A_SNMP_ORGANIZATION", 0, MSGSRV_A_SNMP_ORGANIZATION},
{"A_SNMP_LOCATION", 0, MSGSRV_A_SNMP_LOCATION},
{"A_SNMP_CONTACT", 0, MSGSRV_A_SNMP_CONTACT},
{"A_SNMP_NAME", 0, MSGSRV_A_SNMP_NAME},
{"A_MESSAGING_DISABLED", 0, MSGSRV_A_MESSAGING_DISABLED},
{"A_STORE_TRUSTED_HOSTS", 0, MSGSRV_A_STORE_TRUSTED_HOSTS},
{"A_QUOTA_VALUE", 0, MSGSRV_A_QUOTA_VALUE},
{"A_SCMS_USER_THRESHOLD", 0, MSGSRV_A_SCMS_USER_THRESHOLD},
{"A_SCMS_SIZE_THRESHOLD", 0, MSGSRV_A_SCMS_SIZE_THRESHOLD},
{"A_SMTP_VERIFY_ADDRESS", 0, MSGSRV_A_SMTP_VERIFY_ADDRESS},
{"A_SMTP_ALLOW_AUTH", 0, MSGSRV_A_SMTP_ALLOW_AUTH},
{"A_SMTP_ALLOW_VRFY", 0, MSGSRV_A_SMTP_ALLOW_VRFY},
{"A_SMTP_ALLOW_EXPN", 0, MSGSRV_A_SMTP_ALLOW_EXPN},
{"A_WORK_DIRECTORY", 0, MSGSRV_A_WORK_DIRECTORY},
{"A_LOGLEVEL", 0, MSGSRV_A_LOGLEVEL},
{"A_MINIMUM_SPACE", 0, MSGSRV_A_MINIMUM_SPACE},
{"A_SMTP_SEND_ETRN", 0, MSGSRV_A_SMTP_SEND_ETRN},
{"A_SMTP_ACCEPT_ETRN", 0, MSGSRV_A_SMTP_ACCEPT_ETRN},
{"A_LIMIT_REMOTE_PROCESSING", 0, MSGSRV_A_LIMIT_REMOTE_PROCESSING},
{"A_LIMIT_REMOTE_START_WD", 0, MSGSRV_A_LIMIT_REMOTE_START_WD},
{"A_LIMIT_REMOTE_END_WD", 0, MSGSRV_A_LIMIT_REMOTE_END_WD},
{"A_LIMIT_REMOTE_START_WE", 0, MSGSRV_A_LIMIT_REMOTE_START_WE},
{"A_LIMIT_REMOTE_END_WE", 0, MSGSRV_A_LIMIT_REMOTE_END_WE},
{"A_PRODUCT_VERSION", 0, MSGSRV_A_PRODUCT_VERSION},
{"A_PROXY_LIST", 0, MSGSRV_A_PROXY_LIST},
{"A_MAXIMUM_ITEMS", 0, MSGSRV_A_MAXIMUM_ITEMS},
{"A_TIME_INTERVAL", 0, MSGSRV_A_TIME_INTERVAL},
{"A_RELAYHOST", 0, MSGSRV_A_RELAYHOST},
{"A_ALIAS_OPTIONS", 0, MSGSRV_A_ALIAS_OPTIONS},
{"A_LDAP_OPTIONS", 0, MSGSRV_A_LDAP_OPTIONS},
{"A_CUSTOM_ALIAS", 0, MSGSRV_A_CUSTOM_ALIAS},
{"A_ADVERTISING_CONFIG", 0, MSGSRV_A_ADVERTISING_CONFIG},
{"A_LANGUAGE", 0, MSGSRV_A_LANGUAGE},
{"A_PREFERENCES", 0, MSGSRV_A_PREFERENCES},
{"A_QUOTA_WARNING", 0, MSGSRV_A_QUOTA_WARNING},
{"A_QUEUE_TUNING", 0, MSGSRV_A_QUEUE_TUNING},
{"A_TIMEOUT", 0, MSGSRV_A_TIMEOUT},
{"A_PRIVACY", 0, MSGSRV_A_PRIVACY},
{"A_THREAD_LIMIT", 0, MSGSRV_A_THREAD_LIMIT},
{"A_DBF_PAGESIZE", 0, MSGSRV_A_DBF_PAGESIZE},
{"A_DBF_KEYSIZE", 0, MSGSRV_A_DBF_KEYSIZE},
{"A_ADDRESSBOOK_CONFIG", 0, MSGSRV_A_ADDRESSBOOK_CONFIG},
{"A_ADDRESSBOOK_URL_SYSTEM", 0, MSGSRV_A_ADDRESSBOOK_URL_SYSTEM},
{"A_ADDRESSBOOK_URL_PUBLIC", 0, MSGSRV_A_ADDRESSBOOK_URL_PUBLIC},
{"A_ADDRESSBOOK", 0, MSGSRV_A_ADDRESSBOOK},
{"A_SERVER_STANDALONE", 0, MSGSRV_A_SERVER_STANDALONE},
{"A_FORWARD_UNDELIVERABLE", 0, MSGSRV_A_FORWARD_UNDELIVERABLE},
{"A_PHRASE", 0, MSGSRV_A_PHRASE},
{"A_ACCOUNTING_ENABLED", 0, MSGSRV_A_ACCOUNTING_ENABLED},
{"A_ACCOUNTING_DATA", 0, MSGSRV_A_ACCOUNTING_DATA},
{"A_BILLING_DATA", 0, MSGSRV_A_BILLING_DATA},
{"A_BLOCKED_ADDRESS", 0, MSGSRV_A_BLOCKED_ADDRESS},
{"A_ALLOWED_ADDRESS", 0, MSGSRV_A_ALLOWED_ADDRESS},
{"A_RECIPIENT_LIMIT", 0, MSGSRV_A_RECIPIENT_LIMIT},
{"A_RBL_HOST", 0, MSGSRV_A_RBL_HOST},
{"A_SIGNATURE", 0, MSGSRV_A_SIGNATURE},
{"A_CONNMGR", 0, MSGSRV_A_CONNMGR},
{"A_CONNMGR_CONFIG", 0, MSGSRV_A_CONNMGR_CONFIG},
{"A_USER_DOMAIN", 0, MSGSRV_A_USER_DOMAIN},
{"A_RTS_ANTISPAM_CONFIG", 0, MSGSRV_A_RTS_ANTISPAM_CONFIG},
{"A_SPOOL_DIRECTORY", 0, MSGSRV_A_SPOOL_DIRECTORY},
{"A_SCMS_DIRECTORY", 0, MSGSRV_A_SCMS_DIRECTORY},
{"A_DBF_DIRECTORY", 0, MSGSRV_A_DBF_DIRECTORY},
{"A_NLS_DIRECTORY", 0, MSGSRV_A_NLS_DIRECTORY},
{"A_BIN_DIRECTORY", 0, MSGSRV_A_BIN_DIRECTORY},
{"A_LIB_DIRECTORY", 0, MSGSRV_A_LIB_DIRECTORY},
{"A_DEFAULT_CHARSET", 0, MSGSRV_A_DEFAULT_CHARSET},
{"A_RULE", 0, MSGSRV_A_RULE},
{"A_RELAY_DOMAIN", 0, MSGSRV_A_RELAY_DOMAIN},
{"A_LIST_DIGESTTIME", 0, MSGSRV_A_LIST_DIGESTTIME},
{"A_LIST_ABSTRACT", 0, MSGSRV_A_LIST_ABSTRACT},
{"A_LIST_DESCRIPTION", 0, MSGSRV_A_LIST_DESCRIPTION},
{"A_LIST_CONFIGURATION", 0, MSGSRV_A_LIST_CONFIGURATION},
{"A_LIST_STORE", 0, MSGSRV_A_LIST_STORE},
{"A_LIST_NMAPSTORE", 0, MSGSRV_A_LIST_NMAPSTORE},
{"A_LIST_MODERATOR", 0, MSGSRV_A_LIST_MODERATOR},
{"A_LIST_OWNER", 0, MSGSRV_A_LIST_OWNER},
{"A_LIST_SIGNATURE", 0, MSGSRV_A_LIST_SIGNATURE},
{"A_LIST_SIGNATURE_HTML", 0, MSGSRV_A_LIST_SIGNATURE_HTML},
{"A_LIST_DIGEST_VERSION", 0, MSGSRV_A_LIST_DIGEST_VERSION},
{"A_LIST_MEMBERS", 0, MSGSRV_A_LIST_MEMBERS},
{"A_LISTUSER_OPTIONS", 0, MSGSRV_A_LISTUSER_OPTIONS},
{"A_LISTUSER_ADMINOPTIONS", 0, MSGSRV_A_LISTUSER_ADMINOPTIONS},
{"A_LISTUSER_PASSWORD", 0, MSGSRV_A_LISTUSER_PASSWORD},
{"A_FEATURE_SET", 0, MSGSRV_A_FEATURE_SET},
{"A_PRIVATE_KEY_LOCATION", 0, MSGSRV_A_PRIVATE_KEY_LOCATION},
{"A_CERTIFICATE_LOCATION", 0, MSGSRV_A_CERTIFICATE_LOCATION},
{"A_CONFIG_CHANGED", 0, MSGSRV_A_CONFIG_CHANGED},
{"A_LISTSERVER_NAME", 0, MSGSRV_A_LISTSERVER_NAME},
{"A_LIST_WELCOME_MESSAGE", 0, MSGSRV_A_LIST_WELCOME_MESSAGE},
{"A_PARENT_OBJECT", 0, MSGSRV_A_PARENT_OBJECT},
{"A_FEATURE_INHERITANCE", 0, MSGSRV_A_FEATURE_INHERITANCE},
{"A_TEMPLATE", 0, MSGSRV_A_TEMPLATE},
{"A_TIMEZONE", 0, MSGSRV_A_TIMEZONE},
{"A_LOCALE", 0, MSGSRV_A_LOCALE},
{"A_PASSWORD_CONFIGURATION", 0, MSGSRV_A_PASSWORD_CONFIGURATION},
{"A_TITLE", 0, MSGSRV_A_TITLE},
{"A_DEFAULT_TEMPLATE", 0, MSGSRV_A_DEFAULT_TEMPLATE},
{"A_TOM_MANAGER", 0, MSGSRV_A_TOM_MANAGER},
{"A_TOM_CONTEXTS", 0, MSGSRV_A_TOM_CONTEXTS},
{"A_TOM_DOMAINS", 0, MSGSRV_A_TOM_DOMAINS},
{"A_TOM_OPTIONS", 0, MSGSRV_A_TOM_OPTIONS},
{"A_DESCRIPTION", 0, MSGSRV_A_DESCRIPTION},
{"A_STATSERVER_1", 0, MSGSRV_A_STATSERVER_1},
{"A_STATSERVER_2", 0, MSGSRV_A_STATSERVER_2},
{"A_STATSERVER_3", 0, MSGSRV_A_STATSERVER_3},
{"A_STATSERVER_4", 0, MSGSRV_A_STATSERVER_4},
{"A_STATSERVER_5", 0, MSGSRV_A_STATSERVER_5},
{"A_STATSERVER_6", 0, MSGSRV_A_STATSERVER_6},
{"A_NEWS", 0, MSGSRV_A_NEWS},
{"A_MANAGER", 0, MSGSRV_A_MANAGER},
{"A_AVAILABLE_SHARES", 0, MSGSRV_A_AVAILABLE_SHARES},
{"A_OWNED_SHARES", 0, MSGSRV_A_OWNED_SHARES},
{"A_NEW_SHARE_MESSAGE", 0, MSGSRV_A_NEW_SHARE_MESSAGE},
{"A_AVAILABLE_PROXIES", 0, MSGSRV_A_AVAILABLE_PROXIES},
{"A_OWNED_PROXIES", 0, MSGSRV_A_OWNED_PROXIES},
{"A_RESOURCE_MANAGER", 0, MSGSRV_A_RESOURCE_MANAGER},
{"A_BONGO_MESSAGING_SERVER", 0, MSGSRV_A_BONGO_MESSAGING_SERVER},
{"A_ACL", 0, MSGSRV_A_ACL},
{"A_WA_DEFAULT_TEMPLATE", 0, MSGSRV_A_WA_DEFAULT_TEMPLATE},
{"A_WA_ALLOWED_TEMPLATES", 0, MSGSRV_A_WA_ALLOWED_TEMPLATES},
{"A_WA_DISALLOWED_TEMPLATES", 0, MSGSRV_A_WA_DISALLOWED_TEMPLATES},
{"A_SMS_AUTHORIZED_PHONES", 0, MSGSRV_A_SMS_AUTHORIZED_PHONES},
{"A_CALCMD_ADDRESS_SUFFIX", 0, MSGSRV_A_CALCMD_ADDRESS_SUFFIX},
{"A_MAX_LOAD", 0, MSGSRV_A_MAX_LOAD},
{"A_ACL_ENABLED", 0, MSGSRV_A_ACL_ENABLED},
{"A_UBE_SMTP_AFTER_POP", 0, MSGSRV_A_UBE_SMTP_AFTER_POP},
{"A_UBE_REMOTE_AUTH_ONLY", 0, MSGSRV_A_UBE_REMOTE_AUTH_ONLY},
{"A_MAX_FLOOD_COUNT", 0, MSGSRV_A_MAX_FLOOD_COUNT},
{"A_MAX_NULL_SENDER_RECIPS", 0, MSGSRV_A_MAX_NULL_SENDER_RECIPS},
{"A_MAX_MX_SERVERS", 0, MSGSRV_A_MAX_MX_SERVERS},
{"A_RELAY_LOCAL_MAIL", 0, MSGSRV_A_RELAY_LOCAL_MAIL},
{"A_CLUSTERED", 0, MSGSRV_A_CLUSTERED},
{"A_FORCE_BIND", 0, MSGSRV_A_FORCE_BIND},
{"A_SSL_TLS", 0, MSGSRV_A_SSL_TLS},
{"A_SSL_ALLOW_CHAINED", 0, MSGSRV_A_SSL_ALLOW_CHAINED},
{"A_BOUNCE_RETURN", 0, MSGSRV_A_BOUNCE_RETURN},
{"A_BOUNCE_CC_POSTMASTER", 0, MSGSRV_A_BOUNCE_CC_POSTMASTER},
{"A_QUOTA_USER", 0, MSGSRV_A_QUOTA_USER},
{"A_QUOTA_SYSTEM", 0, MSGSRV_A_QUOTA_SYSTEM},
{"A_REGISTER_QUEUE", 0, MSGSRV_A_REGISTER_QUEUE},
{"A_QUEUE_LIMIT_BOUNCES", 0, MSGSRV_A_QUEUE_LIMIT_BOUNCES},
{"A_LIMIT_BOUNCE_ENTRIES", 0, MSGSRV_A_LIMIT_BOUNCE_ENTRIES},
{"A_LIMIT_BOUNCE_INTERVAL", 0, MSGSRV_A_LIMIT_BOUNCE_INTERVAL},
{"A_DOMAIN_ROUTING", 0, MSGSRV_A_DOMAIN_ROUTING},
{"A_MONITOR_INTERVAL", 0, MSGSRV_A_MONITOR_INTERVAL},
{"A_MANAGER_PORT", 0, MSGSRV_A_MANAGER_PORT},
{"A_MANAGER_SSL_PORT", 0, MSGSRV_A_MANAGER_SSL_PORT},
{NULL, 0, NULL}
};
+29
View File
@@ -0,0 +1,29 @@
#ifndef PYBONGO_MSGAPI_DEFS_H
#define PYBONGO_MSGAPI_DEFS_H
#include "pybongo.h"
#include <bongo-config.h>
#include <xpl.h>
#include <msgapi.h>
#ifdef __cplusplus
extern "C" {
#endif
PyDoc_STRVAR(GetConfigProperty_doc,
"GetConfigProperty(s) -> string response\n\
\n\
Return the value for configuration property s..");
PyObject *msgapi_GetConfigProperty(PyObject *, PyObject *);
PyDoc_STRVAR(GetUnprivilegedUser_doc,
"GetUnprivilegedUser() -> string response\n\
\n\
Return the name of the unprivileged user if configured --with-user=.");
PyObject *msgapi_GetUnprivilegedUser(PyObject *, PyObject *);
#ifdef __cplusplus
}
#endif
#endif /* PYBONGO_MSGAPI_DEFS_H */
+638
View File
@@ -0,0 +1,638 @@
/****************************************************************************
*
* Copyright (c) 2006 Novell, Inc.
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, contact Novell, Inc.
*
* To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com
*
****************************************************************************/
#include <Python.h>
#include <bongo-config.h>
#include <xpl.h>
#include <msgapi.h>
#include <connio.h>
#include "libs.h"
#include "msgapi-defs.h"
#ifdef __cplusplus
extern "C" {
#endif
PyDoc_STRVAR(CollectAllUsers_doc,
"CollectAllUsers() -> None\n\
\n\
Collect and import the calendars subscribed to by all users.");
static PyObject *
msgapi_CollectAllUsers(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, "")) {
return NULL;
}
MsgCollectAllUsers();
Py_INCREF(Py_None);
return Py_None;
}
PyDoc_STRVAR(CollectUser_doc,
"CollectUser(user) -> None\n\
\n\
Collect and import the calendars subscribed to by user.");
static PyObject *
msgapi_CollectUser(PyObject *self, PyObject *args)
{
char *user;
if (!PyArg_ParseTuple(args, "s", &user)) {
return NULL;
}
MsgCollectUser(user);
Py_INCREF(Py_None);
return Py_None;
}
PyDoc_STRVAR(DirectoryHandle_doc,
"DirectoryHandle() -> handle\n\
\n\
Return the directory handle used by libmsgapi.");
static PyObject *
msgapi_DirectoryHandle(PyObject *self, PyObject *args)
{
MDBHandle handle;
if (!PyArg_ParseTuple(args, "")) {
return NULL;
}
handle = (MDBHandle)MsgDirectoryHandle();
if (handle == NULL) {
Py_INCREF(Py_None);
return Py_None;
}
return PyCObject_FromVoidPtr(handle, NULL);
}
PyDoc_STRVAR(FindObject_doc,
"FindObject(u) -> string dn\n\
\n\
Return a string containing the dn of user u.");
static PyObject *
msgapi_FindObject(PyObject *self, PyObject *args)
{
unsigned char *user;
unsigned int len=MDB_MAX_OBJECT_CHARS+1;
unsigned char buf[len];
if (!PyArg_ParseTuple(args, "s", &user)) {
return NULL;
}
if (!MsgFindObject(user, buf, NULL, NULL, NULL)) {
Py_INCREF(Py_None);
return Py_None;
}
return Py_BuildValue("s", buf);
}
PyDoc_STRVAR(FindUserNmap_doc,
"FindUserNmap(u) -> (string host, int port) tuple\n\
\n\
Return the ip address and port of user u's document store.");
static PyObject *
msgapi_FindUserNmap(PyObject *self, PyObject *args)
{
unsigned char *user;
unsigned int len=33;
unsigned char buf[len];
unsigned short port;
if (!PyArg_ParseTuple(args, "s", &user)) {
return NULL;
}
if (!MsgFindUserNmap(user, buf, len, &port)) {
Py_INCREF(Py_None);
return Py_None;
}
return Py_BuildValue("si", buf, port);
}
PyDoc_STRVAR(GetUserFeature_doc,
"GetUserFeature(dn, featurename, ) -> array of strings\n\
\n\
Return a string containing the ip address of user u's document store.");
static const char *features[] = {
"",
"imap",
"pop",
"addressbook",
"proxy",
"forward",
"autoreply",
"rules",
"finger",
"smtp_send_count_limit",
"smtp_send_size_limit",
"nmap_quota",
"nmap_store",
"webmail",
"modweb",
"mwmail_addressbook_personal",
"mwmail_addressbook_system",
"mwmail_addressbook_global",
"modweb_wap",
"calagent",
"calendar",
"antivirus",
"shared_folders",
NULL
};
PyDoc_STRVAR(GetUserSetting_doc, "GetUserSetting(user, attribute)\n");
static PyObject *
msgapi_GetUserSetting(PyObject *self, PyObject *args)
{
unsigned char *user;
char *attribute;
MDBValueStruct *v;
PyObject *ret = Py_None;
int i;
if (!PyArg_ParseTuple(args, "ss", &user, &attribute)) {
return NULL;
}
v = MDBCreateValueStruct(MsgDirectoryHandle(), NULL);
if (v) {
if (MsgGetUserSetting(user, attribute, v)) {
ret = PyList_New(v->Used);
for (i = 0; i < v->Used; i++) {
PyList_SetItem(ret, i, PyString_FromString(v->Value[i]));
}
} else {
ret = PyList_New(0);
}
MDBDestroyValueStruct(v);
} else {
Py_INCREF(Py_None);
}
return ret;
}
PyDoc_STRVAR(SetUserSetting_doc, "SetUserSetting(user, attribute, values)\n");
static PyObject *
msgapi_SetUserSetting(PyObject *self, PyObject *args)
{
unsigned char *user;
char *attribute;
char *val;
void *vals;
MDBValueStruct *v;
PyObject *item;
PyObject *ret = Py_False;
int i, size;
if (!PyArg_ParseTuple(args, "ssO", &user, &attribute, &vals)) {
return NULL;
}
v = MDBCreateValueStruct(MsgDirectoryHandle(), NULL);
if (v) {
size = PyList_Size(vals);
for (i = 0; i < size; i++) {
item = PyList_GetItem(vals, i);
PyArg_Parse(item, "s", &val);
if (!MDBAddValue(val, v)) {
break;
}
}
if (i == size && MsgSetUserSetting(user, attribute, v)) {
ret = Py_True;
}
MDBDestroyValueStruct(v);
}
Py_INCREF(ret);
return ret;
}
PyDoc_STRVAR(AddUserSetting_doc, "AddUserSetting(user, attribute, value)\n");
static PyObject *
msgapi_AddUserSetting(PyObject *self, PyObject *args)
{
unsigned char *user;
char *attribute;
char *value;
MDBValueStruct *v;
PyObject *ret = Py_False;
if (!PyArg_ParseTuple(args, "sss", &user, &attribute, &value)) {
return NULL;
}
v = MDBCreateValueStruct(MsgDirectoryHandle(), NULL);
if (v) {
if (MsgAddUserSetting(user, attribute, value, v)) {
ret = Py_True;
}
MDBDestroyValueStruct(v);
}
Py_INCREF(ret);
return ret;
}
PyDoc_STRVAR(GetUserDisplayName_doc,
"GetUserDisplayName(user) -> string\n\
\n\
Return a string containing the display name of the user.");
static PyObject *
msgapi_GetUserDisplayName(PyObject *self, PyObject *args)
{
unsigned char *userDN;
unsigned char *name;
MDBValueStruct *v;
PyObject *ret;
if (!PyArg_ParseTuple(args, "s", &userDN)) {
return NULL;
}
v = MDBCreateValueStruct(MsgDirectoryHandle(), NULL);
if (v) {
name = MsgGetUserDisplayName(userDN, v);
MDBDestroyValueStruct(v);
ret = Py_BuildValue("s", name);
MemFree(name);
} else {
Py_INCREF(Py_None);
ret = Py_None;
}
return ret;
}
PyDoc_STRVAR(GetUserEmailAddress_doc,
"GetUserEmailAddress(user) -> string\n\
\n\
Return a string containing the email address of the user.");
static PyObject *
msgapi_GetUserEmailAddress(PyObject *self, PyObject *args)
{
unsigned char *userDN;
unsigned char email[400]; /* according to RFC2821, the maximum length of a
user name is 64 chars. A domain name can be
255. */
MDBValueStruct *v;
PyObject *ret;
if (!PyArg_ParseTuple(args, "s", &userDN)) {
return NULL;
}
v = MDBCreateValueStruct(MsgDirectoryHandle(), NULL);
if (v) {
MsgGetUserEmailAddress(userDN, v, email, sizeof(email)-1);
MDBDestroyValueStruct(v);
ret = Py_BuildValue("s", email);
} else {
Py_INCREF(Py_None);
ret = Py_None;
}
return ret;
}
static PyObject *
msgapi_GetUserFeature(PyObject *self, PyObject *args)
{
unsigned char *user;
char *feature;
char *attribute;
unsigned int len=33;
unsigned char buf[len];
char row;
int col;
if (!PyArg_ParseTuple(args, "sss", &user, &feature, &attribute)) {
return NULL;
}
row = 'A';
for (col = 0; features[col] != NULL; col++) {
if (!strcmp(features[col], feature)) {
break;
}
}
if (features[col]) {
MDBValueStruct *v;
PyObject *ret;
v = MDBCreateValueStruct(MsgDirectoryHandle(), NULL);
if (MsgGetUserFeature(user, row, col, attribute, v)) {
int i;
ret = PyList_New(v->Used);
for (i = 0; i < v->Used; i++) {
PyList_SetItem(ret, i, PyString_FromString(v->Value[i]));
}
} else {
Py_INCREF(Py_None);
ret = Py_None;
}
MDBDestroyValueStruct(v);
return ret;
} else {
Py_INCREF(Py_None);
return Py_None;
}
}
static void
ThrowImportException(int code)
{
char *msg;
switch(code) {
case MSG_COLLECT_ERROR_URL :
msg = "Invalid URL";
break;
case MSG_COLLECT_ERROR_DOWNLOAD :
msg = "Unable to download calendar";
break;
case MSG_COLLECT_ERROR_AUTH :
msg = "Invalid username and password";
break;
case MSG_COLLECT_ERROR_PARSE :
msg = "Unable to parse calendar";
break;
case MSG_COLLECT_ERROR_STORE :
msg = "Error saving calendar";
break;
default :
msg = "Error importing calendar";
break;
}
PyErr_SetString(PyExc_RuntimeError, msg);
}
PyDoc_STRVAR(ImportIcsUrl_doc,
"ImportIcs(user, calName, url, urlUsername, urlPassword)\n\
\n\
Import the specified url into the calendar calName.\n\
The calendar with that name must already exist.");
static PyObject *
msgapi_ImportIcsUrl(PyObject *self, PyObject *args)
{
char *user;
char *calName;
char *url;
char *urlUsername;
char *urlPassword;
char *color;
int ret;
if (!PyArg_ParseTuple(args, "sszszz", &user, &calName, &color, &url, &urlUsername, &urlPassword)) {
return NULL;
}
ret = MsgImportIcsUrl(user, calName, color, url, urlUsername, urlPassword, NULL);
if (ret < 0) {
ThrowImportException(ret);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
PyDoc_STRVAR(ImportIcs_doc,
"ImportIcs(fileHandle, user, calName, color)\n\
\n\
Import from the specified open file into the calendar calName.\n\
The calendar with that name must already exist.");
static PyObject *
msgapi_ImportIcs(PyObject *self, PyObject *args)
{
PyObject *pyfile = NULL;
FILE *file = NULL;
char *user;
char *calName;
char *color;
int ret;
if (!PyArg_ParseTuple(args, "Ossz", &pyfile, &user, &calName, &color)) {
return NULL;
}
if(!PyFile_Check(pyfile))
return NULL;
file = PyFile_AsFile(pyfile);
ret = MsgImportIcs(file, user, calName, color, NULL);
if (ret < 0) {
ThrowImportException(ret);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
PyDoc_STRVAR(IcsImport_doc,
"IcsImport(user, name, color, url, urlUsername, urlPassword) -> guid\n\
\n\
Import the specified calendar url.");
static PyObject *
msgapi_IcsImport(PyObject *self, PyObject *args)
{
char *user;
char *name;
char *url;
char *urlUsername;
char *urlPassword;
char *color;
int ret;
uint64_t guid;
if (!PyArg_ParseTuple(args, "sszszz", &user, &name, &color, &url, &urlUsername, &urlPassword)) {
return NULL;
}
ret = MsgIcsImport(user, name, color, url, urlUsername, urlPassword, &guid);
if (ret < 0) {
ThrowImportException(ret);
return NULL;
}
return PyLong_FromUnsignedLong(guid);
}
PyDoc_STRVAR(IcsSubscribe_doc,
"IcsSubscribe(user, name, color, url, urlUsername, urlPassword) -> guid\n\
\n\
Subscribe user to the specified calendar url.");
static PyObject *
msgapi_IcsSubscribe(PyObject *self, PyObject *args)
{
char *user;
char *name;
char *url;
char *urlUsername;
char *urlPassword;
char *color;
uint64_t guid;
int ret;
if (!PyArg_ParseTuple(args, "sszszz", &user, &name, &color, &url, &urlUsername, &urlPassword)) {
return NULL;
}
ret = MsgIcsSubscribe(user, name, color, url, urlUsername, urlPassword, &guid);
if (ret < 0) {
ThrowImportException(ret);
return NULL;
}
return PyLong_FromUnsignedLong(guid);
}
PyDoc_STRVAR(NmapChallenge_doc,
"NmapChallenge(s) -> string response\n\
\n\
Return the response string for an NMAP challenge string s.\n\
s is of the format \"NMAP <40c0cbb0hostname441444a4>\".");
static PyObject *
msgapi_NmapChallenge(PyObject *self, PyObject *args)
{
unsigned char *salt;
unsigned int len=33;
unsigned char buf[len];
if (!PyArg_ParseTuple(args, "s", &salt)) {
return NULL;
}
MsgNmapChallenge(salt, buf, len);
return Py_BuildValue("s", buf);
}
PyDoc_STRVAR(GetBuildVersion_doc,
"GetBuildVersion() -> (integer, boolean)\n \
\n\
Returns a tuple containing version number and whether the build is custom.\n\
");
static PyObject *
msgapi_GetBuildVersion(PyObject *self, PyObject *args)
{
int version;
BOOL custom;
MsgGetBuildVersion (&version, &custom);
return Py_BuildValue("ib", version, custom);
}
PyDoc_STRVAR(GetAvailableVersion_doc,
"GetBuildVersion() -> integer response\n \
\n\
Returns the version of the latest software on this branch.\n\
");
static PyObject *
msgapi_GetAvailableVersion(PyObject *self, PyObject *args)
{
int version;
if (MsgGetAvailableVersion (&version)) {
return Py_BuildValue("i", version);
} else {
return Py_BuildValue("i", 0);
}
}
extern PyObject *msgapi_GetConfigProperty(PyObject *, PyObject *);
PyMethodDef MsgApiMethods[] = {
{"CollectAllUsers", msgapi_CollectAllUsers, METH_VARARGS | METH_STATIC, CollectAllUsers_doc},
{"CollectUser", msgapi_CollectUser, METH_VARARGS | METH_STATIC, CollectUser_doc},
{"DirectoryHandle", msgapi_DirectoryHandle, METH_VARARGS | METH_STATIC, DirectoryHandle_doc},
{"FindObject", msgapi_FindObject, METH_VARARGS | METH_STATIC, FindObject_doc},
{"FindUserNmap", msgapi_FindUserNmap, METH_VARARGS | METH_STATIC, FindUserNmap_doc},
{"GetUserSetting", msgapi_GetUserSetting, METH_VARARGS | METH_STATIC, GetUserSetting_doc},
{"SetUserSetting", msgapi_SetUserSetting, METH_VARARGS | METH_STATIC, SetUserSetting_doc},
{"GetUserDisplayName", msgapi_GetUserDisplayName, METH_VARARGS | METH_STATIC, GetUserDisplayName_doc},
{"GetUserEmailAddress", msgapi_GetUserEmailAddress, METH_VARARGS | METH_STATIC, GetUserEmailAddress_doc},
{"GetUserFeature", msgapi_GetUserFeature, METH_VARARGS | METH_STATIC, GetUserFeature_doc},
{"ImportIcsUrl", msgapi_ImportIcsUrl, METH_VARARGS | METH_STATIC, ImportIcsUrl_doc},
{"ImportIcs", msgapi_ImportIcs, METH_VARARGS | METH_STATIC, ImportIcs_doc},
{"IcsSubscribe", msgapi_IcsSubscribe, METH_VARARGS | METH_STATIC, IcsSubscribe_doc},
{"IcsImport", msgapi_IcsImport, METH_VARARGS | METH_STATIC, IcsImport_doc},
{"NmapChallenge", msgapi_NmapChallenge, METH_VARARGS | METH_STATIC, NmapChallenge_doc},
{"GetConfigProperty", msgapi_GetConfigProperty, METH_VARARGS | METH_STATIC, GetConfigProperty_doc},
{"GetUnprivilegedUser", msgapi_GetUnprivilegedUser, METH_VARARGS | METH_STATIC, GetUnprivilegedUser_doc},
{"GetBuildVersion", msgapi_GetBuildVersion, METH_VARARGS | METH_STATIC, GetBuildVersion_doc},
{"GetAvailableVersion", msgapi_GetAvailableVersion, METH_VARARGS | METH_STATIC, GetAvailableVersion_doc},
{NULL, NULL, 0, NULL}
};
#ifdef __cplusplus
}
#endif
+56
View File
@@ -0,0 +1,56 @@
#include "pybongo.h"
#ifdef __cplusplus
extern "C" {
#endif
void
AddLibrary(PyObject *module, char *name, PyMethodDef *classMethods,
EnumItemDef *enumItems)
{
PyMethodDef *def;
EnumItemDef *item;
/* Create the new class object and add it to the module */
PyObject *moduleDict = PyModule_GetDict(module);
PyObject *classDict = PyDict_New();
PyObject *className = PyString_FromString(name);
PyObject *classObj = PyClass_New(NULL, classDict, className);
PyDict_SetItemString(moduleDict, name, classObj);
/* Add the class's methods to its dict */
for (def = classMethods; def->ml_name != NULL; def++) {
PyObject *func = PyCFunction_New(def, NULL);
PyObject *method;
if (def->ml_flags & METH_STATIC) {
method = PyStaticMethod_New(func);
} else {
method = PyMethod_New(func, NULL, classObj);
}
PyDict_SetItemString(classDict, def->ml_name, method);
Py_DECREF(func);
Py_DECREF(method);
}
if (enumItems != NULL) {
for (item = enumItems; item->name != NULL; item++) {
PyObject *value;
if(item->strvalue) {
value = PyString_FromString(item->strvalue);
} else {
value = PyInt_FromLong(item->value);
}
PyDict_SetItemString(classDict, item->name, value);
Py_DECREF(value);
}
}
Py_DECREF(classDict);
Py_DECREF(className);
Py_DECREF(classObj);
}
#ifdef __cplusplus
}
#endif
+28
View File
@@ -0,0 +1,28 @@
#ifndef PYBONGO_H
#define PYBONGO_H
#include <Python.h>
#ifdef __cplusplus
extern "C" {
#endif
struct EnumItemDef {
char *name;
long value;
char *strvalue;
};
typedef struct EnumItemDef EnumItemDef;
void AddLibrary(PyObject *, char *, PyMethodDef *, EnumItemDef *);
extern int BongoCalPostInit(PyObject *module);
#ifdef __cplusplus
}
#endif
#endif /* PYBONGO_H */
+192
View File
@@ -0,0 +1,192 @@
#include <Python.h>
#include <bongo-config.h>
#include <streamio.h>
#include <bongostream.h>
#ifdef __cplusplus
extern "C" {
#endif
PyDoc_STRVAR(BongoStreamAddCodec_doc,
"BongoStreamAddCodec(stream, codec, encode)\n\
\n\
Add a codec to a stream.");
static PyObject *
streamio_BongoStreamAddCodec(PyObject *self, PyObject *args)
{
PyObject *pystream = NULL;
BongoStream *stream = NULL;
char *codec = NULL;
PyObject *pyencode = NULL;
int ret;
PyObject *pyret;
if (!PyArg_ParseTuple(args, "OsO", &pystream, &codec, &pyencode)) {
return NULL;
}
stream = PyCObject_AsVoidPtr(pystream);
if (!PyBool_Check(pyencode)) {
PyErr_SetString(PyExc_TypeError,
"BongoStreamCreate: arg 2 must be bool");
return NULL;
}
ret = BongoStreamAddCodec(stream, codec, (pyencode == Py_True));
/* returns zero on success */
pyret = (!ret ? Py_True : Py_False);
Py_INCREF(pyret);
return pyret;
}
PyDoc_STRVAR(BongoStreamCreate_doc,
"BongoStreamCreate(codecs, encode) -> stream\n\
\n\
Return a pointer to a BongoStream.");
static PyObject *
streamio_BongoStreamCreate(PyObject *self, PyObject *args)
{
PyObject *pycodecs = NULL;
PyObject *pyencode = NULL;
BongoStream *stream = NULL;
char **codecs = NULL;
int codecsLen = 0;
int i;
if (!PyArg_ParseTuple(args, "OO", &pycodecs, &pyencode)) {
return NULL;
}
if (!PyList_Check(pycodecs)) {
PyErr_SetString(PyExc_TypeError,
"BongoStreamCreate: arg 1 must be list");
return NULL;
}
if (!PyBool_Check(pyencode)) {
PyErr_SetString(PyExc_TypeError,
"BongoStreamCreate: arg 2 must be bool");
return NULL;
}
codecsLen = PyList_Size(pycodecs);
codecs = MemMalloc(sizeof(char *) * codecsLen);
for (i=0; i<codecsLen; i++) {
codecs[i] = PyString_AsString(PyList_GetItem(pycodecs, i));
if (codecs[i] == NULL) {
MemFree(codecs);
return NULL;
}
}
stream = BongoStreamCreate(codecs, codecsLen, (pyencode == Py_True));
MemFree(codecs);
if (stream == NULL) {
Py_INCREF(Py_None);
return Py_None;
}
return PyCObject_FromVoidPtr(stream, (void *)BongoStreamFree);
}
PyDoc_STRVAR(BongoStreamEos_doc,
"BongoStreamEos(stream)\n\
\n\
Close down a stream.");
static PyObject *
streamio_BongoStreamEos(PyObject *self, PyObject *args)
{
PyObject *pystream = NULL;
BongoStream *stream = NULL;
if (!PyArg_ParseTuple(args, "O", &pystream)) {
return NULL;
}
stream = PyCObject_AsVoidPtr(pystream);
BongoStreamEos(stream);
Py_INCREF(Py_None);
return Py_None;
}
PyDoc_STRVAR(BongoStreamGet_doc,
"BongoStreamGet(stream, buffer) -> count\n\
\n\
Read as many bytes as possible from the stream, and put them in buffer.\
Return the number of bytes read.");
static PyObject *
streamio_BongoStreamGet(PyObject *self, PyObject *args)
{
PyObject *pystream = NULL;
BongoStream *stream = NULL;
PyObject *pybuf = NULL;
char *buf;
int bufLen;
int read = 0;
if (!PyArg_ParseTuple(args, "OO", &pystream, &pybuf)) {
return NULL;
}
stream = PyCObject_AsVoidPtr(pystream);
if (PyObject_AsCharBuffer(pybuf, (const char**)&buf, &bufLen)) {
PyErr_SetString(PyExc_TypeError, "BongoStreamGet() buffer must be a string");
return NULL;
}
read = BongoStreamGet(stream, buf, bufLen);
return Py_BuildValue("i", read);
}
PyDoc_STRVAR(BongoStreamPut_doc,
"BongoStreamPut(stream, buffer)\n\
\n\
Put as many bytes possible from buffer into the stream.");
static PyObject *
streamio_BongoStreamPut(PyObject *self, PyObject *args)
{
PyObject *pystream = NULL;
BongoStream *stream = NULL;
PyObject *pybuf = NULL;
const char *buf;
int bufLen;
if (!PyArg_ParseTuple(args, "OO", &pystream, &pybuf)) {
return NULL;
}
stream = PyCObject_AsVoidPtr(pystream);
if (PyObject_AsCharBuffer(pybuf, &buf, &bufLen)) {
PyErr_SetString(PyExc_TypeError, "BongoStreamPut() buffer must be a string");
return NULL;
}
BongoStreamPut(stream, buf, bufLen);
Py_INCREF(Py_None);
return Py_None;
}
PyMethodDef StreamIOMethods[] = {
{"BongoStreamAddCodec", streamio_BongoStreamAddCodec, METH_VARARGS | METH_STATIC, BongoStreamAddCodec_doc},
{"BongoStreamCreate", streamio_BongoStreamCreate, METH_VARARGS | METH_STATIC, BongoStreamCreate_doc},
{"BongoStreamEos", streamio_BongoStreamEos, METH_VARARGS | METH_STATIC, BongoStreamEos_doc},
{"BongoStreamGet", streamio_BongoStreamGet, METH_VARARGS | METH_STATIC, BongoStreamGet_doc},
{"BongoStreamPut", streamio_BongoStreamPut, METH_VARARGS | METH_STATIC, BongoStreamPut_doc},
{NULL, NULL, 0, NULL}
};
#ifdef __cplusplus
}
#endif