diff --git a/.gitignore b/.gitignore index c133d04c..e559102b 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ stamp-h1 valgrind.out core bugs/ +*.pyc +TODO diff --git a/Makefile.am b/Makefile.am index f7c3f825..c328cfbd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,7 +21,8 @@ profanity_SOURCES = \ src/tools/tinyurl.c src/tools/tinyurl.h \ src/config/accounts.c src/config/accounts.h \ src/config/preferences.c src/config/preferences.h \ - src/config/theme.c src/config/theme.h + src/config/theme.c src/config/theme.h \ + src/api/apu.h src/api/api.c TESTS = tests/testsuite check_PROGRAMS = tests/testsuite @@ -48,6 +49,7 @@ tests_testsuite_SOURCES = \ src/config/accounts.c src/config/accounts.h \ src/config/preferences.c src/config/preferences.h \ src/config/theme.c src/config/theme.h \ + src/api/apu.h src/api/api.c tests/test_roster.c tests/test_common.c tests/test_history.c \ tests/test_autocomplete.c tests/testsuite.c tests/test_parser.c \ tests/test_jid.c diff --git a/configure.ac b/configure.ac index ceaf1751..b3cbb793 100644 --- a/configure.ac +++ b/configure.ac @@ -88,11 +88,11 @@ if test "x$enable_notifications" != xno; then fi # Default parameters -AM_CFLAGS="-Wall" +AM_CFLAGS="-Wall -I/usr/include/python2.7 -I/usr/include/python2.7 -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -L/usr/lib/python2.7/config -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions" if test "x$PACKAGE_STATUS" = xdevelopment; then AM_CFLAGS="$AM_CFLAGS -Wunused -Werror" fi -LIBS="$LIBS $DEPS_LIBS $NOTIFY_LIBS" +LIBS="$LIBS $DEPS_LIBS $NOTIFY_LIBS -lpthread -ldl -lutil -lm -lpython2.7" AM_CPPFLAGS="$DEPS_CFLAGS $NOTIFY_CFLAGS" diff --git a/plugins/test.py b/plugins/test.py new file mode 100644 index 00000000..a01e01e0 --- /dev/null +++ b/plugins/test.py @@ -0,0 +1,2 @@ +def plugin_name(): + return "plugin james" diff --git a/src/api/api.c b/src/api/api.c new file mode 100644 index 00000000..674f0f9b --- /dev/null +++ b/src/api/api.c @@ -0,0 +1,81 @@ +/* + * api.c + * + * Copyright (C) 2012, 2013 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + */ + +#include + +#include "ui/ui.h" + +void +api_init(void) +{ + PyObject *pName, *pModule, *pFunc; + PyObject *pValue; + + Py_Initialize(); + pName = PyString_FromString("test"); + pModule = PyImport_Import(pName); + Py_DECREF(pName); + + if (pModule != NULL) { + pFunc = PyObject_GetAttrString(pModule, "pluginname"); + + if (pFunc == NULL) { + cons_show("NULL pfunc"); + } + + if (pFunc && PyCallable_Check(pFunc)) { + pValue = PyObject_CallObject(pFunc, NULL); + if (pValue != NULL) { + cons_show("Plugin loaded"); + cons_show("Result of call: %s", PyString_AsString(pValue)); + Py_DECREF(pValue); + } + else { + Py_DECREF(pFunc); + Py_DECREF(pModule); + cons_show("Error loading plugin"); + return; + } + } + else { + if (PyErr_Occurred()) + cons_show("PyErr occurred"); + cons_show("Could not find function"); + } + Py_XDECREF(pFunc); + Py_DECREF(pModule); + } + else { + cons_show("Failed to load plugin"); + return ; + } + Py_Finalize(); + return; +} + +void +api_prof_cons_show(const char *message) +{ + if (message != NULL) { + cons_show("%s", message); + } +} diff --git a/src/api/api.h b/src/api/api.h new file mode 100644 index 00000000..38f77dfe --- /dev/null +++ b/src/api/api.h @@ -0,0 +1,28 @@ +/* + * api.h + * + * Copyright (C) 2012, 2013 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + */ + +#ifndef API_H +#define API_H + +void api_init(void); + +#endif diff --git a/src/profanity.c b/src/profanity.c index 9c729ca1..5a6d4836 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -31,6 +31,7 @@ #include "profanity.h" +#include "api/api.h" #include "chat_session.h" #include "config/accounts.h" #include "config/preferences.h" @@ -633,6 +634,7 @@ _init(const int disable_tls, char *log_level) roster_init(); muc_init(); atexit(_shutdown); + api_init(); } static void diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 85ddfa45..168e4cfa 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -71,11 +71,11 @@ static struct { static GTimer *reconnect_timer; static log_level_t _get_log_level(xmpp_log_level_t xmpp_level); -static xmpp_log_level_t _get_xmpp_log_level(); +static xmpp_log_level_t _get_xmpp_log_level(void); static void _xmpp_file_logger(void * const userdata, const xmpp_log_level_t level, const char * const area, const char * const msg); -static xmpp_log_t * _xmpp_get_file_logger(); +static xmpp_log_t * _xmpp_get_file_logger(void); static jabber_conn_status_t _jabber_connect(const char * const fulljid, const char * const passwd, const char * const altdomain); diff --git a/test.py b/test.py new file mode 100644 index 00000000..ac14ed84 --- /dev/null +++ b/test.py @@ -0,0 +1,2 @@ +def pluginname(): + return "plugin james"