python_iface.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* $Id$
  2. *
  3. * Copyright (C) 2009 Sippy Software, Inc., http://www.sippysoft.com
  4. *
  5. * This file is part of SIP-Router, a free SIP server.
  6. *
  7. * SIP-Router is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version
  11. *
  12. * SIP-Router is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #include <Python.h>
  23. #include "../../action.h"
  24. #include "../../dprint.h"
  25. #include "../../route_struct.h"
  26. #include "python_exec.h"
  27. /*
  28. * Python method: LM_GEN1(self, int log_level, str msg)
  29. */
  30. static PyObject *router_LM_GEN1(PyObject *self, PyObject *args)
  31. {
  32. int log_level;
  33. char *msg;
  34. if (!PyArg_ParseTuple(args, "is:LM_GEN1", &log_level, &msg))
  35. return NULL;
  36. LM_GEN1(log_level, "%s", msg);
  37. Py_INCREF(Py_None);
  38. return Py_None;
  39. }
  40. /*
  41. * Python method: LM_GEN2(self, int log_facility, int log_level, str msg)
  42. */
  43. static PyObject *router_LM_GEN2(PyObject *self, PyObject *args)
  44. {
  45. int log_facility;
  46. int log_level;
  47. char *msg;
  48. if(!PyArg_ParseTuple(args, "iis:LM_GEN2", &log_facility, &log_level, &msg))
  49. return NULL;
  50. LM_GEN2(log_facility, log_level, "%s", msg);
  51. Py_INCREF(Py_None);
  52. return Py_None;
  53. }
  54. /*
  55. * Python method: LM_ALERT(self, str msg)
  56. */
  57. static PyObject *router_LM_ALERT(PyObject *self, PyObject *args)
  58. {
  59. char *msg;
  60. if(!PyArg_ParseTuple(args, "s:LM_ALERT", &msg))
  61. return NULL;
  62. LM_ALERT("%s", msg);
  63. Py_INCREF(Py_None);
  64. return Py_None;
  65. }
  66. /*
  67. * Python method: LM_CRIT(self, str msg)
  68. */
  69. static PyObject *router_LM_CRIT(PyObject *self, PyObject *args)
  70. {
  71. char *msg;
  72. if(!PyArg_ParseTuple(args, "s:LM_CRIT", &msg))
  73. return NULL;
  74. LM_CRIT("%s", msg);
  75. Py_INCREF(Py_None);
  76. return Py_None;
  77. }
  78. /*
  79. * Python method: LM_WARN(self, str msg)
  80. */
  81. static PyObject *router_LM_WARN(PyObject *self, PyObject *args)
  82. {
  83. char *msg;
  84. if(!PyArg_ParseTuple(args, "s:LM_WARN", &msg))
  85. return NULL;
  86. LM_WARN("%s", msg);
  87. Py_INCREF(Py_None);
  88. return Py_None;
  89. }
  90. /*
  91. * Python method: LM_NOTICE(self, str msg)
  92. */
  93. static PyObject *router_LM_NOTICE(PyObject *self, PyObject *args)
  94. {
  95. char *msg;
  96. if(!PyArg_ParseTuple(args, "s:LM_NOTICE", &msg))
  97. return NULL;
  98. LM_NOTICE("%s", msg);
  99. Py_INCREF(Py_None);
  100. return Py_None;
  101. }
  102. /*
  103. * Python method: LM_ERR(self, str msg)
  104. */
  105. static PyObject *router_LM_ERR(PyObject *self, PyObject *args)
  106. {
  107. char *msg;
  108. if(!PyArg_ParseTuple(args, "s:LM_ERR", &msg))
  109. return NULL;
  110. LM_ERR("%s", msg);
  111. Py_INCREF(Py_None);
  112. return Py_None;
  113. }
  114. /*
  115. * Python method: LM_INFO(self, str msg)
  116. */
  117. static PyObject *router_LM_INFO(PyObject *self, PyObject *args)
  118. {
  119. char *msg;
  120. if(!PyArg_ParseTuple(args, "s:LM_INFO", &msg))
  121. return NULL;
  122. LM_INFO("%s", msg);
  123. Py_INCREF(Py_None);
  124. return Py_None;
  125. }
  126. /*
  127. * Python method: LM_DBG(self, str msg)
  128. */
  129. static PyObject *router_LM_DBG(PyObject *self, PyObject *args)
  130. {
  131. char *msg;
  132. if(!PyArg_ParseTuple(args, "s:LM_DBG", &msg))
  133. return NULL;
  134. LM_DBG("%s", msg);
  135. Py_INCREF(Py_None);
  136. return Py_None;
  137. }
  138. PyMethodDef RouterMethods[] = {
  139. {"LM_GEN1", router_LM_GEN1, METH_VARARGS, "Print GEN1 message."},
  140. {"LM_GEN2", router_LM_GEN2, METH_VARARGS, "Print GEN2 message."},
  141. {"LM_ALERT", router_LM_ALERT, METH_VARARGS, "Print alert message."},
  142. {"LM_CRIT", router_LM_CRIT, METH_VARARGS, "Print critical message."},
  143. {"LM_ERR", router_LM_ERR, METH_VARARGS, "Print error message."},
  144. {"LM_WARN", router_LM_WARN, METH_VARARGS, "Print warning message."},
  145. {"LM_NOTICE", router_LM_NOTICE, METH_VARARGS, "Print notice message."},
  146. {"LM_INFO", router_LM_INFO, METH_VARARGS, "Print info message."},
  147. {"LM_DBG", router_LM_DBG, METH_VARARGS, "Print debug message."},
  148. {NULL, NULL, 0, NULL}
  149. };
  150. /*
  151. * Default module properties
  152. */
  153. void RouterAddProperties(PyObject *m)
  154. {
  155. /*
  156. * Log levels
  157. * Reference: dprint.h
  158. */
  159. PyModule_AddObject(m, "L_ALERT", PyInt_FromLong((long)L_ALERT));
  160. PyModule_AddObject(m, "L_BUG", PyInt_FromLong((long)L_BUG));
  161. PyModule_AddObject(m, "L_CRIT2", PyInt_FromLong((long)L_CRIT2)); /* like L_CRIT, but adds prefix */
  162. PyModule_AddObject(m, "L_CRIT", PyInt_FromLong((long)L_CRIT)); /* no prefix added */
  163. PyModule_AddObject(m, "L_ERR", PyInt_FromLong((long)L_ERR));
  164. PyModule_AddObject(m, "L_WARN", PyInt_FromLong((long)L_WARN));
  165. PyModule_AddObject(m, "L_NOTICE", PyInt_FromLong((long)L_NOTICE));
  166. PyModule_AddObject(m, "L_INFO", PyInt_FromLong((long)L_INFO));
  167. PyModule_AddObject(m, "L_DBG", PyInt_FromLong((long)L_DBG));
  168. /*
  169. * Facility
  170. * Reference: dprint.h
  171. */
  172. PyModule_AddObject(m, "DEFAULT_FACILITY", PyInt_FromLong((long)DEFAULT_FACILITY));
  173. }