1994-07-14 15:56:50 +02:00
|
|
|
/***********************************************************
|
1994-08-30 14:25:20 +02:00
|
|
|
Copyright 1994 by Lance Ellinghouse,
|
|
|
|
Cathedral City, California Republic, United States of America.
|
1994-07-14 15:56:50 +02:00
|
|
|
|
|
|
|
All Rights Reserved
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted,
|
|
|
|
provided that the above copyright notice appear in all copies and that
|
|
|
|
both that copyright notice and this permission notice appear in
|
1994-08-30 14:25:20 +02:00
|
|
|
supporting documentation, and that the name of Lance Ellinghouse
|
|
|
|
not be used in advertising or publicity pertaining to distribution
|
|
|
|
of the software without specific, written prior permission.
|
1994-07-14 15:56:50 +02:00
|
|
|
|
1994-08-30 14:25:20 +02:00
|
|
|
LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
1994-07-14 15:56:50 +02:00
|
|
|
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
1994-08-30 14:25:20 +02:00
|
|
|
FITNESS, IN NO EVENT SHALL LANCE ELLINGHOUSE BE LIABLE FOR ANY SPECIAL,
|
|
|
|
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
|
|
|
FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
|
|
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
1994-07-14 15:56:50 +02:00
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
/* syslog module */
|
|
|
|
|
|
|
|
#include "allobjects.h"
|
|
|
|
#include "modsupport.h"
|
|
|
|
|
|
|
|
#include <syslog.h>
|
|
|
|
|
1994-08-30 14:25:20 +02:00
|
|
|
#include "rename1.h"
|
|
|
|
|
|
|
|
static PyObject *
|
1994-07-14 15:56:50 +02:00
|
|
|
syslog_openlog(self, args)
|
1994-08-30 14:25:20 +02:00
|
|
|
PyObject * self;
|
|
|
|
PyObject * args;
|
1994-07-14 15:56:50 +02:00
|
|
|
{
|
|
|
|
char *ident = "";
|
1994-08-30 14:25:20 +02:00
|
|
|
PyObject * ident_o;
|
1994-07-14 15:56:50 +02:00
|
|
|
long logopt = LOG_PID;
|
|
|
|
long facility = LOG_USER;
|
1994-08-30 14:25:20 +02:00
|
|
|
if (!PyArg_Parse(args, "(Sll);ident string, logoption, facility", &ident_o, &logopt, &facility))
|
|
|
|
if (!PyArg_Parse(args, "(Sl);ident string, logoption", &ident_o, &logopt))
|
|
|
|
if (!PyArg_Parse(args, "S;ident string", &ident_o))
|
1994-07-14 15:56:50 +02:00
|
|
|
return NULL;
|
1994-08-30 14:25:20 +02:00
|
|
|
Py_INCREF(ident_o); /* This is needed because openlog() does NOT make a copy
|
1994-07-14 15:56:50 +02:00
|
|
|
and syslog() later uses it.. cannot trash it. */
|
1994-08-30 14:25:20 +02:00
|
|
|
ident = PyString_AsString(ident_o);
|
1994-07-14 15:56:50 +02:00
|
|
|
openlog(ident,logopt,facility);
|
1994-08-30 14:25:20 +02:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1994-07-14 15:56:50 +02:00
|
|
|
}
|
|
|
|
|
1994-08-30 14:25:20 +02:00
|
|
|
static PyObject *
|
1994-07-14 15:56:50 +02:00
|
|
|
syslog_syslog(self, args)
|
1994-08-30 14:25:20 +02:00
|
|
|
PyObject * self;
|
|
|
|
PyObject * args;
|
1994-07-14 15:56:50 +02:00
|
|
|
{
|
|
|
|
int priority = LOG_INFO;
|
|
|
|
char *message;
|
|
|
|
|
1994-08-30 14:25:20 +02:00
|
|
|
if (!PyArg_Parse(args,"(is);priority, message string",&priority,&message))
|
|
|
|
if (!PyArg_Parse(args,"s;message string",&message))
|
1994-07-14 15:56:50 +02:00
|
|
|
return NULL;
|
|
|
|
syslog(priority, message);
|
1994-08-30 14:25:20 +02:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1994-07-14 15:56:50 +02:00
|
|
|
}
|
|
|
|
|
1994-08-30 14:25:20 +02:00
|
|
|
static PyObject *
|
1994-07-14 15:56:50 +02:00
|
|
|
syslog_closelog(self, args)
|
1994-08-30 14:25:20 +02:00
|
|
|
PyObject * self;
|
|
|
|
PyObject * args;
|
1994-07-14 15:56:50 +02:00
|
|
|
{
|
1994-08-30 14:25:20 +02:00
|
|
|
if (!PyArg_NoArgs(args))
|
1994-07-14 15:56:50 +02:00
|
|
|
return NULL;
|
|
|
|
closelog();
|
1994-08-30 14:25:20 +02:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1994-07-14 15:56:50 +02:00
|
|
|
}
|
|
|
|
|
1994-08-30 14:25:20 +02:00
|
|
|
static PyObject *
|
1994-07-14 15:56:50 +02:00
|
|
|
syslog_setlogmask(self, args)
|
1994-08-30 14:25:20 +02:00
|
|
|
PyObject * self;
|
|
|
|
PyObject * args;
|
1994-07-14 15:56:50 +02:00
|
|
|
{
|
|
|
|
long maskpri;
|
1994-08-30 14:25:20 +02:00
|
|
|
if (!PyArg_Parse(args,"l;mask for priority",&maskpri))
|
1994-07-14 15:56:50 +02:00
|
|
|
return NULL;
|
|
|
|
setlogmask(maskpri);
|
1994-08-30 14:25:20 +02:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1994-07-14 15:56:50 +02:00
|
|
|
}
|
|
|
|
|
1994-08-30 14:25:20 +02:00
|
|
|
static PyObject *
|
1994-07-14 15:56:50 +02:00
|
|
|
syslog_log_mask(self, args)
|
1994-08-30 14:25:20 +02:00
|
|
|
PyObject * self;
|
|
|
|
PyObject * args;
|
1994-07-14 15:56:50 +02:00
|
|
|
{
|
|
|
|
long mask;
|
|
|
|
long pri;
|
1994-08-30 14:25:20 +02:00
|
|
|
if (!PyArg_Parse(args,"l",&pri))
|
1994-07-14 15:56:50 +02:00
|
|
|
return NULL;
|
|
|
|
mask = LOG_MASK(pri);
|
1994-08-30 14:25:20 +02:00
|
|
|
return PyInt_FromLong(mask);
|
1994-07-14 15:56:50 +02:00
|
|
|
}
|
|
|
|
|
1994-08-30 14:25:20 +02:00
|
|
|
static PyObject *
|
1994-07-14 15:56:50 +02:00
|
|
|
syslog_log_upto(self, args)
|
1994-08-30 14:25:20 +02:00
|
|
|
PyObject * self;
|
|
|
|
PyObject * args;
|
1994-07-14 15:56:50 +02:00
|
|
|
{
|
|
|
|
long mask;
|
|
|
|
long pri;
|
1994-08-30 14:25:20 +02:00
|
|
|
if (!PyArg_Parse(args,"l",&pri))
|
1994-07-14 15:56:50 +02:00
|
|
|
return NULL;
|
|
|
|
mask = LOG_UPTO(pri);
|
1994-08-30 14:25:20 +02:00
|
|
|
return PyInt_FromLong(mask);
|
1994-07-14 15:56:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* List of functions defined in the module */
|
|
|
|
|
1994-08-30 14:25:20 +02:00
|
|
|
static PyMethodDef syslog_methods[] = {
|
|
|
|
{"openlog", (PyCFunction)syslog_openlog},
|
|
|
|
{"closelog", (PyCFunction)syslog_closelog},
|
|
|
|
{"syslog", (PyCFunction)syslog_syslog},
|
|
|
|
{"setlogmask", (PyCFunction)syslog_setlogmask},
|
|
|
|
{"LOG_MASK", (PyCFunction)syslog_log_mask},
|
|
|
|
{"LOG_UPTO", (PyCFunction)syslog_log_upto},
|
1994-07-14 15:56:50 +02:00
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization function for the module */
|
|
|
|
|
|
|
|
void
|
|
|
|
initsyslog()
|
|
|
|
{
|
1994-08-30 14:25:20 +02:00
|
|
|
PyObject *m, *d, *x;
|
1994-07-14 15:56:50 +02:00
|
|
|
|
|
|
|
/* Create the module and add the functions */
|
1994-08-30 14:25:20 +02:00
|
|
|
m = Py_InitModule("syslog", syslog_methods);
|
1994-07-14 15:56:50 +02:00
|
|
|
|
|
|
|
/* Add some symbolic constants to the module */
|
1994-08-30 14:25:20 +02:00
|
|
|
d = PyModule_GetDict(m);
|
|
|
|
x = PyInt_FromLong(LOG_EMERG);
|
|
|
|
PyDict_SetItemString(d, "LOG_EMERG", x);
|
|
|
|
x = PyInt_FromLong(LOG_ALERT);
|
|
|
|
PyDict_SetItemString(d, "LOG_ALERT", x);
|
|
|
|
x = PyInt_FromLong(LOG_CRIT);
|
|
|
|
PyDict_SetItemString(d, "LOG_CRIT", x);
|
|
|
|
x = PyInt_FromLong(LOG_ERR);
|
|
|
|
PyDict_SetItemString(d, "LOG_ERR", x);
|
|
|
|
x = PyInt_FromLong(LOG_WARNING);
|
|
|
|
PyDict_SetItemString(d, "LOG_WARNING", x);
|
|
|
|
x = PyInt_FromLong(LOG_NOTICE);
|
|
|
|
PyDict_SetItemString(d, "LOG_NOTICE", x);
|
|
|
|
x = PyInt_FromLong(LOG_INFO);
|
|
|
|
PyDict_SetItemString(d, "LOG_INFO", x);
|
|
|
|
x = PyInt_FromLong(LOG_DEBUG);
|
|
|
|
PyDict_SetItemString(d, "LOG_DEBUG", x);
|
|
|
|
x = PyInt_FromLong(LOG_PID);
|
|
|
|
PyDict_SetItemString(d, "LOG_PID", x);
|
|
|
|
x = PyInt_FromLong(LOG_CONS);
|
|
|
|
PyDict_SetItemString(d, "LOG_CONS", x);
|
|
|
|
x = PyInt_FromLong(LOG_NDELAY);
|
|
|
|
PyDict_SetItemString(d, "LOG_NDELAY", x);
|
|
|
|
x = PyInt_FromLong(LOG_NOWAIT);
|
|
|
|
PyDict_SetItemString(d, "LOG_NOWAIT", x);
|
|
|
|
x = PyInt_FromLong(LOG_KERN);
|
|
|
|
PyDict_SetItemString(d, "LOG_KERN", x);
|
|
|
|
x = PyInt_FromLong(LOG_USER);
|
|
|
|
PyDict_SetItemString(d, "LOG_USER", x);
|
|
|
|
x = PyInt_FromLong(LOG_MAIL);
|
|
|
|
PyDict_SetItemString(d, "LOG_MAIL", x);
|
|
|
|
x = PyInt_FromLong(LOG_DAEMON);
|
|
|
|
PyDict_SetItemString(d, "LOG_DAEMON", x);
|
|
|
|
x = PyInt_FromLong(LOG_LPR);
|
|
|
|
PyDict_SetItemString(d, "LOG_LPR", x);
|
|
|
|
x = PyInt_FromLong(LOG_LOCAL0);
|
|
|
|
PyDict_SetItemString(d, "LOG_LOCAL0", x);
|
|
|
|
x = PyInt_FromLong(LOG_LOCAL1);
|
|
|
|
PyDict_SetItemString(d, "LOG_LOCAL1", x);
|
|
|
|
x = PyInt_FromLong(LOG_LOCAL2);
|
|
|
|
PyDict_SetItemString(d, "LOG_LOCAL2", x);
|
|
|
|
x = PyInt_FromLong(LOG_LOCAL3);
|
|
|
|
PyDict_SetItemString(d, "LOG_LOCAL3", x);
|
|
|
|
x = PyInt_FromLong(LOG_LOCAL4);
|
|
|
|
PyDict_SetItemString(d, "LOG_LOCAL4", x);
|
|
|
|
x = PyInt_FromLong(LOG_LOCAL5);
|
|
|
|
PyDict_SetItemString(d, "LOG_LOCAL5", x);
|
|
|
|
x = PyInt_FromLong(LOG_LOCAL6);
|
|
|
|
PyDict_SetItemString(d, "LOG_LOCAL6", x);
|
|
|
|
x = PyInt_FromLong(LOG_LOCAL7);
|
|
|
|
PyDict_SetItemString(d, "LOG_LOCAL7", x);
|
1994-07-14 15:56:50 +02:00
|
|
|
|
|
|
|
/* Check for errors */
|
1994-08-30 14:25:20 +02:00
|
|
|
if (PyErr_Occurred())
|
|
|
|
Py_FatalError("can't initialize module syslog");
|
1994-07-14 15:56:50 +02:00
|
|
|
}
|