|
35 | 35 | #include "msg-format.h"
|
36 | 36 | #include "scratch-buffers.h"
|
37 | 37 | #include "cfg.h"
|
| 38 | +#include "gsockaddr.h" |
38 | 39 |
|
39 | 40 | #include <datetime.h>
|
40 | 41 |
|
@@ -352,6 +353,28 @@ py_log_message_get_pri(PyLogMessage *self, PyObject *args, PyObject *kwrds)
|
352 | 353 | return PyLong_FromLong(self->msg->pri);
|
353 | 354 | }
|
354 | 355 |
|
| 356 | +static PyObject * |
| 357 | +py_log_message_set_source_ipaddress(PyLogMessage *self, PyObject *args, PyObject *kwrds) |
| 358 | +{ |
| 359 | + const gchar *ip; |
| 360 | + Py_ssize_t ip_length; |
| 361 | + guint port = 0; |
| 362 | + |
| 363 | + static const gchar *kwlist[] = {"ip", "port", NULL}; |
| 364 | + if (!PyArg_ParseTupleAndKeywords(args, kwrds, "z#|I", (gchar **) kwlist, &ip, &ip_length, &port)) |
| 365 | + return NULL; |
| 366 | + |
| 367 | + if (!ip) |
| 368 | + Py_RETURN_FALSE; |
| 369 | + |
| 370 | + GSockAddr *saddr = g_sockaddr_inet_or_inet6_new(ip, (guint16) port); |
| 371 | + if (!saddr) |
| 372 | + Py_RETURN_FALSE; |
| 373 | + |
| 374 | + log_msg_set_saddr(self->msg, saddr); |
| 375 | + Py_RETURN_TRUE; |
| 376 | +} |
| 377 | + |
355 | 378 | static PyObject *
|
356 | 379 | py_log_message_set_timestamp(PyLogMessage *self, PyObject *args, PyObject *kwrds)
|
357 | 380 | {
|
@@ -442,6 +465,7 @@ static PyMethodDef py_log_message_methods[] =
|
442 | 465 | { "get_as_str", (PyCFunction)py_log_message_get_as_str, METH_VARARGS | METH_KEYWORDS, "Get value as string" },
|
443 | 466 | { "set_pri", (PyCFunction)py_log_message_set_pri, METH_VARARGS | METH_KEYWORDS, "Set syslog priority" },
|
444 | 467 | { "get_pri", (PyCFunction)py_log_message_get_pri, METH_VARARGS | METH_KEYWORDS, "Get syslog priority" },
|
| 468 | + { "set_source_ipaddress", (PyCFunction)py_log_message_set_source_ipaddress, METH_VARARGS | METH_KEYWORDS, "Set source address" }, |
445 | 469 | { "set_timestamp", (PyCFunction)py_log_message_set_timestamp, METH_VARARGS | METH_KEYWORDS, "Set timestamp" },
|
446 | 470 | { "get_timestamp", (PyCFunction)py_log_message_get_timestamp, METH_VARARGS | METH_KEYWORDS, "Get timestamp" },
|
447 | 471 | { "set_bookmark", (PyCFunction)py_log_message_set_bookmark, METH_VARARGS | METH_KEYWORDS, "Set bookmark" },
|
|
0 commit comments