From a1a01b8cd4743fdfce5683617fecb4a8728cc619 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 18 Aug 2013 16:20:52 +0100 Subject: [PATCH] Started adding ruby api --- .gitignore | 5 + Makefile.am | 6 +- configure.ac | 12 ++- plugins/ruby-test.rb | 15 +++ src/common.c | 4 +- src/config/preferences.c | 6 +- src/config/preferences.h | 6 +- src/config/theme.c | 6 +- src/config/theme.h | 6 +- src/main.c | 6 +- src/plugins/plugins.c | 17 +++- src/plugins/python_api.h | 2 +- src/plugins/python_plugins.c | 2 +- src/plugins/ruby_api.c | 183 +++++++++++++++++++++++++++++++++++ src/plugins/ruby_api.h | 33 +++++++ src/plugins/ruby_plugins.c | 155 +++++++++++++++++++++++++++++ src/plugins/ruby_plugins.h | 37 +++++++ src/profanity.c | 8 +- src/ui/console.c | 20 ++-- src/ui/core.c | 18 ++-- src/ui/inputwin.c | 6 +- src/ui/notifier.c | 14 +-- src/ui/notifier.h | 5 + src/ui/statusbar.c | 6 +- src/ui/ui.h | 6 +- src/ui/window.c | 6 +- src/xmpp/capabilities.c | 6 +- src/xmpp/iq.c | 6 +- 28 files changed, 528 insertions(+), 74 deletions(-) create mode 100644 plugins/ruby-test.rb create mode 100644 src/plugins/ruby_api.c create mode 100644 src/plugins/ruby_api.h create mode 100644 src/plugins/ruby_plugins.c create mode 100644 src/plugins/ruby_plugins.h diff --git a/.gitignore b/.gitignore index e559102b..26eeccba 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ Makefile.in aclocal.m4 autom4te.cache/ src/config.h +src/prof_config.h src/config.h.in config.status configure @@ -30,3 +31,7 @@ core bugs/ *.pyc TODO +_configs.sed +gource.sh +*_fingerprints.txt +*_key.txt diff --git a/Makefile.am b/Makefile.am index 92dc7a94..828f78f8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -26,8 +26,10 @@ profanity_SOURCES = \ src/plugins/api.h src/plugins/api.c \ src/plugins/callbacks.h src/plugins/callbacks.c \ src/plugins/python_plugins.h src/plugins/python_plugins.c \ + src/plugins/python_api.h src/plugins/python_api.c \ src/plugins/c_plugins.h src/plugins/c_plugins.c \ - src/plugins/python_api.h src/plugins/python_api.c + src/plugins/ruby_plugins.h src/plugins/ruby_plugins.c \ + src/plugins/ruby_api.h src/plugins/ruby_api.c TESTS = tests/testsuite check_PROGRAMS = tests/testsuite @@ -60,6 +62,8 @@ tests_testsuite_SOURCES = \ src/plugins/python_plugins.h src/plugins/python_plugins.c \ src/plugins/c_plugins.h src/plugins/c_plugins.c \ src/plugins/python_api.h src/plugins/python_api.c \ + src/plugins/ruby_plugins.h src/plugins/ruby_plugins.c \ + src/plugins/ruby_api.h src/plugins/ruby_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 c08973a2..4ff2338a 100644 --- a/configure.ac +++ b/configure.ac @@ -9,6 +9,7 @@ AC_CONFIG_SRCDIR([src/main.c]) AC_CONFIG_HEADERS([src/config.h]) AC_CONFIG_AUX_DIR([build-aux]) AM_INIT_AUTOMAKE([foreign subdir-objects]) +AX_PREFIX_CONFIG_H([src/prof_config.h], [PROF], [src/config.h]) # Checks for programs. AC_PROG_CC @@ -88,12 +89,19 @@ if test "x$enable_notifications" != xno; then fi # Default parameters -AM_CFLAGS="-Wall -I/usr/include/python2.7 -I/usr/include/python2.7 -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -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" +AM_CFLAGS="-Wall" + +# Python +AM_CFLAGS="$AM_CFLAGS -I/usr/include/python2.7 -I/usr/include/python2.7 -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -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" + +# Ruby +AM_CFLAGS="$AM_CFLAGS -I/usr/lib/ruby/1.8/x86_64-linux -L/usr/lib/ruby/1.8/x86_64-linux" + if test "x$PACKAGE_STATUS" = xdevelopment; then # AM_CFLAGS="$AM_CFLAGS -Wunused -Werror" AM_CFLAGS="$AM_CFLAGS -Wunused" fi -LIBS="$LIBS $DEPS_LIBS $NOTIFY_LIBS -lpthread -ldl -lutil -lm -lpython2.7" +LIBS="$LIBS $DEPS_LIBS $NOTIFY_LIBS -lpthread -ldl -lutil -lm -lpython2.7 -lruby1.8" AM_CPPFLAGS="$DEPS_CFLAGS $NOTIFY_CFLAGS" diff --git a/plugins/ruby-test.rb b/plugins/ruby-test.rb new file mode 100644 index 00000000..4f264e64 --- /dev/null +++ b/plugins/ruby-test.rb @@ -0,0 +1,15 @@ +module RubyTest + include prof + + prof_version = "" + prof_status = "" + + def prof_init(version, status) + prof_version = version + prof_status = status + end + + def prof_on_start() + prof.cons_show("RubyTest: " + prof_version + " " + prof_status) + end +end diff --git a/src/common.c b/src/common.c index 2d1ac3d7..aae0122d 100644 --- a/src/common.c +++ b/src/common.c @@ -19,7 +19,7 @@ * along with Profanity. If not, see . * */ -#include "config.h" +#include "prof_config.h" #include #include @@ -269,7 +269,7 @@ release_is_new(char *found_version) { int curr_maj, curr_min, curr_patch, found_maj, found_min, found_patch; - int parse_curr = sscanf(PACKAGE_VERSION, "%d.%d.%d", &curr_maj, &curr_min, + int parse_curr = sscanf(PROF_PACKAGE_VERSION, "%d.%d.%d", &curr_maj, &curr_min, &curr_patch); int parse_found = sscanf(found_version, "%d.%d.%d", &found_maj, &found_min, &found_patch); diff --git a/src/config/preferences.c b/src/config/preferences.c index 0192765a..99d748b8 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -20,15 +20,15 @@ * */ -#include "config.h" +#include "prof_config.h" #include #include #include -#ifdef HAVE_NCURSESW_NCURSES_H +#ifdef PROF_HAVE_NCURSESW_NCURSES_H #include -#elif HAVE_NCURSES_H +#elif PROF_HAVE_NCURSES_H #include #endif diff --git a/src/config/preferences.h b/src/config/preferences.h index 023db038..ec1d9f0a 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -23,12 +23,12 @@ #ifndef PREFERENCES_H #define PREFERENCES_H -#include "config.h" +#include "prof_config.h" #include -#ifdef HAVE_NCURSESW_NCURSES_H +#ifdef PROF_HAVE_NCURSESW_NCURSES_H #include -#elif HAVE_NCURSES_H +#elif PROF_HAVE_NCURSES_H #include #endif diff --git a/src/config/theme.c b/src/config/theme.c index 1c0d176a..3efb6afb 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -20,15 +20,15 @@ * */ -#include "config.h" +#include "prof_config.h" #include #include #include -#ifdef HAVE_NCURSESW_NCURSES_H +#ifdef PROF_HAVE_NCURSESW_NCURSES_H #include -#elif HAVE_NCURSES_H +#elif PROF_HAVE_NCURSES_H #include #endif diff --git a/src/config/theme.h b/src/config/theme.h index 8878d7b2..18977648 100644 --- a/src/config/theme.h +++ b/src/config/theme.h @@ -23,12 +23,12 @@ #ifndef THEME_H #define THEME_H -#include "config.h" +#include "prof_config.h" #include -#ifdef HAVE_NCURSESW_NCURSES_H +#ifdef PROF_HAVE_NCURSESW_NCURSES_H #include -#elif HAVE_NCURSES_H +#elif PROF_HAVE_NCURSES_H #include #endif diff --git a/src/main.c b/src/main.c index 99f71351..028f849e 100644 --- a/src/main.c +++ b/src/main.c @@ -22,7 +22,7 @@ #include -#include "config.h" +#include "prof_config.h" #include "profanity.h" @@ -55,8 +55,8 @@ main(int argc, char **argv) g_option_context_free(context); if (version == TRUE) { - g_print("Profanity, version %s\n", PACKAGE_VERSION); - g_print("Copyright (C) 2012, 2013 James Booth <%s>.\n", PACKAGE_BUGREPORT); + g_print("Profanity, version %s\n", PROF_PACKAGE_VERSION); + g_print("Copyright (C) 2012, 2013 James Booth <%s>.\n", PROF_PACKAGE_BUGREPORT); g_print("License GPLv3+: GNU GPL version 3 or later \n"); g_print("\n"); g_print("This is free software; you are free to change and redistribute it.\n"); diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index 730b59ad..a71147a0 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -23,9 +23,11 @@ #include "config/preferences.h" #include "plugins/callbacks.h" #include "plugins/plugins.h" -#include "plugins/python_api.h" #include "plugins/python_plugins.h" #include "plugins/c_plugins.h" +#include "plugins/python_api.h" +#include "plugins/ruby_plugins.h" +#include "plugins/ruby_api.h" #include "ui/ui.h" @@ -37,7 +39,8 @@ plugins_init(void) { plugins = NULL; - python_init(); + python_env_init(); + ruby_env_init(); // load plugins gchar **plugins_load = prefs_get_plugins(); @@ -46,6 +49,7 @@ plugins_init(void) for (i = 0; i < g_strv_length(plugins_load); i++) { gchar *filename = plugins_load[i]; + ProfPlugin *plugin = NULL; if (g_str_has_suffix(filename, ".py")) { ProfPlugin *plugin = python_plugin_create(filename); if (plugin != NULL) { @@ -61,6 +65,12 @@ plugins_init(void) plugins = g_slist_append(plugins, plugin); cons_show("Loaded C plugin: %s", filename); } + } else if (g_str_has_suffix(filename, ".rb")) { + ProfPlugin *plugin = ruby_plugin_create(filename); + if (plugin != NULL) { + plugins = g_slist_append(plugins, plugin); + cons_show("Loaded Ruby plugin: %s", filename); + } } } @@ -68,8 +78,7 @@ plugins_init(void) GSList *curr = plugins; while (curr != NULL) { ProfPlugin *plugin = curr->data; - - plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS); + plugin->init_func(plugin, PROF_PACKAGE_VERSION, PROF_PACKAGE_STATUS); // TODO well, it should be more of a generic check error here python_check_error(); curr = g_slist_next(curr); diff --git a/src/plugins/python_api.h b/src/plugins/python_api.h index 68025845..b3116125 100644 --- a/src/plugins/python_api.h +++ b/src/plugins/python_api.h @@ -23,7 +23,7 @@ #ifndef PYTHON_API_H #define PYTHON_API_H -void python_init(void); +void python_env_init(void); void python_api_init(void); void python_shutdown(void); diff --git a/src/plugins/python_plugins.c b/src/plugins/python_plugins.c index 40946f83..be0ddf0c 100644 --- a/src/plugins/python_plugins.c +++ b/src/plugins/python_plugins.c @@ -31,7 +31,7 @@ #include "ui/ui.h" void -python_init(void) +python_env_init(void) { Py_Initialize(); python_check_error(); diff --git a/src/plugins/ruby_api.c b/src/plugins/ruby_api.c new file mode 100644 index 00000000..327ba934 --- /dev/null +++ b/src/plugins/ruby_api.c @@ -0,0 +1,183 @@ +/* + * ruby_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 + +#include + +#include "plugins/api.h" +#include "plugins/ruby_api.h" +#include "plugins/callbacks.h" + +static PyObject* +ruby_api_cons_alert(PyObject *self, PyObject *args) +{ + api_cons_alert(); + return Py_BuildValue(""); +} + +static VALUE +ruby_api_cons_show(VALUE self, const char * const message) +{ + if (message != NULL) { + api_cons_show(message); + } + return self; +} + +static PyObject* +ruby_api_register_command(PyObject *self, PyObject *args) +{ + const char *command_name = NULL; + int min_args = 0; + int max_args = 0; + const char *usage = NULL; + const char *short_help = NULL; + const char *long_help = NULL; + PyObject *p_callback = NULL; + + if (!PyArg_ParseTuple(args, "siisssO", &command_name, &min_args, &max_args, + &usage, &short_help, &long_help, &p_callback)) { + return NULL; + } + + if (p_callback && PyCallable_Check(p_callback)) { + api_register_command(command_name, min_args, max_args, usage, + short_help, long_help, p_callback, ruby_command_callback); + } + + return Py_BuildValue(""); +} + +static PyObject * +ruby_api_register_timed(PyObject *self, PyObject *args) +{ + PyObject *p_callback = NULL; + int interval_seconds = 0; + + if (!PyArg_ParseTuple(args, "Oi", &p_callback, &interval_seconds)) { + return NULL; + } + + if (p_callback && PyCallable_Check(p_callback)) { + api_register_timed(p_callback, interval_seconds, ruby_timed_callback); + } + + return Py_BuildValue(""); +} + +static PyObject* +ruby_api_notify(PyObject *self, PyObject *args) +{ + const char *message = NULL; + const char *category = NULL; + int timeout_ms = 5000; + + if (!PyArg_ParseTuple(args, "sis", &message, &timeout_ms, &category)) { + return NULL; + } + + api_notify(message, category, timeout_ms); + + return Py_BuildValue(""); +} + +static PyObject* +ruby_api_send_line(PyObject *self, PyObject *args) +{ + char *line = NULL; + if (!PyArg_ParseTuple(args, "s", &line)) { + return NULL; + } + + api_send_line(line); + + return Py_BuildValue(""); +} + +static PyObject * +ruby_api_get_current_recipient(PyObject *self, PyObject *args) +{ + char *recipient = api_get_current_recipient(); + if (recipient != NULL) { + return Py_BuildValue("s", recipient); + } else { + return Py_BuildValue(""); + } +} + +void +ruby_command_callback(PluginCommand *command, gchar **args) +{ + PyObject *p_args = NULL; + int num_args = g_strv_length(args); + if (num_args == 0) { + if (command->max_args == 1) { + p_args = Py_BuildValue("(O)", Py_BuildValue("")); + PyObject_CallObject(command->callback, p_args); + Py_XDECREF(p_args); + } else { + PyObject_CallObject(command->callback, p_args); + } + } else if (num_args == 1) { + p_args = Py_BuildValue("(s)", args[0]); + PyObject_CallObject(command->callback, p_args); + Py_XDECREF(p_args); + } else if (num_args == 2) { + p_args = Py_BuildValue("ss", args[0], args[1]); + PyObject_CallObject(command->callback, p_args); + Py_XDECREF(p_args); + } else if (num_args == 3) { + p_args = Py_BuildValue("sss", args[0], args[1], args[2]); + PyObject_CallObject(command->callback, p_args); + Py_XDECREF(p_args); + } else if (num_args == 4) { + p_args = Py_BuildValue("ssss", args[0], args[1], args[2], args[3]); + PyObject_CallObject(command->callback, p_args); + Py_XDECREF(p_args); + } else if (num_args == 5) { + p_args = Py_BuildValue("sssss", args[0], args[1], args[2], args[3], args[4]); + PyObject_CallObject(command->callback, p_args); + Py_XDECREF(p_args); + } + + if (PyErr_Occurred()) { + PyErr_Print(); + PyErr_Clear(); + } +} + +void +ruby_timed_callback(PluginTimedFunction *timed_function) +{ + PyObject_CallObject(timed_function->callback, NULL); +} + +static VALUE prof_module; + +void +ruby_api_init(void) +{ + prof_module = rb_define_module("prof"); + rb_define_module_function(prof_module, "cons_show", RUBY_METHOD_FUNC(ruby_api_cons_show), 1); +} diff --git a/src/plugins/ruby_api.h b/src/plugins/ruby_api.h new file mode 100644 index 00000000..a3c5b4ad --- /dev/null +++ b/src/plugins/ruby_api.h @@ -0,0 +1,33 @@ +/* + * ruby_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 RUBY_API_H +#define RUBY_API_H + +void ruby_env_init(void); +void ruby_api_init(void); +void ruby_shutdown(void); + +void ruby_command_callback(PluginCommand *command, gchar **args); +void ruby_timed_callback(PluginTimedFunction *timed_function); + +#endif diff --git a/src/plugins/ruby_plugins.c b/src/plugins/ruby_plugins.c new file mode 100644 index 00000000..ae978efe --- /dev/null +++ b/src/plugins/ruby_plugins.c @@ -0,0 +1,155 @@ +/* + * ruby_plugins.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 + +#include "config/preferences.h" +#include "plugins/api.h" +#include "plugins/callbacks.h" +#include "plugins/plugins.h" +#include "plugins/ruby_api.h" +#include "plugins/ruby_plugins.h" +#include "ui/ui.h" + +void +ruby_env_init(void) +{ + ruby_init(); + ruby_check_error(); + ruby_api_init(); + ruby_check_error(); + // TODO change to use XDG spec + GString *path = g_string_new(Py_GetPath()); + g_string_append(path, ":./plugins/"); + PySys_SetPath(path->str); + ruby_check_error(); + g_string_free(path, TRUE); +} + +ProfPlugin * +ruby_plugin_create(const char * const filename) +{ + gchar *module_name = g_strndup(filename, strlen(filename) - 3); + PyObject *p_module = PyImport_ImportModule(module_name); + ruby_check_error(); + if (p_module != NULL) { + ProfPlugin *plugin = malloc(sizeof(ProfPlugin)); + plugin->name = module_name; + plugin->lang = PYTHON; + plugin->module = p_module; + plugin->init_func = ruby_init_hook; + plugin->on_start_func = ruby_on_start_hook; + plugin->on_connect_func = ruby_on_connect_hook; + plugin->on_message_received_func = ruby_on_message_received_hook; + g_free(module_name); + return plugin; + } else { + g_free(module_name); + return NULL; + } +} + +void +ruby_init_hook(ProfPlugin *plugin, const char * const version, const char * const status) +{ + PyObject *p_args = Py_BuildValue("ss", version, status); + PyObject *p_function; + + PyObject *p_module = plugin->module; + if (PyObject_HasAttrString(p_module, "prof_init")) { + p_function = PyObject_GetAttrString(p_module, "prof_init"); + ruby_check_error(); + if (p_function && PyCallable_Check(p_function)) { + PyObject_CallObject(p_function, p_args); + ruby_check_error(); + Py_XDECREF(p_function); + } + } +} + +void +ruby_on_start_hook(ProfPlugin *plugin) +{ + PyObject *p_function; + + PyObject *p_module = plugin->module; + if (PyObject_HasAttrString(p_module, "prof_on_start")) { + p_function = PyObject_GetAttrString(p_module, "prof_on_start"); + ruby_check_error(); + if (p_function && PyCallable_Check(p_function)) { + PyObject_CallObject(p_function, NULL); + ruby_check_error(); + Py_XDECREF(p_function); + } + } +} + +void +ruby_on_connect_hook(ProfPlugin *plugin) +{ + PyObject *p_function; + + PyObject *p_module = plugin->module; + if (PyObject_HasAttrString(p_module, "prof_on_connect")) { + p_function = PyObject_GetAttrString(p_module, "prof_on_connect"); + ruby_check_error(); + if (p_function && PyCallable_Check(p_function)) { + PyObject_CallObject(p_function, NULL); + ruby_check_error(); + Py_XDECREF(p_function); + } + } +} + +void +ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char * const message) +{ + PyObject *p_args = Py_BuildValue("ss", jid, message); + PyObject *p_function; + + PyObject *p_module = plugin->module; + if (PyObject_HasAttrString(p_module, "prof_on_message_received")) { + p_function = PyObject_GetAttrString(p_module, "prof_on_message_received"); + ruby_check_error(); + if (p_function && PyCallable_Check(p_function)) { + PyObject_CallObject(p_function, p_args); + ruby_check_error(); + Py_XDECREF(p_function); + } + } +} + +void +ruby_check_error(void) +{ + if (PyErr_Occurred()) { + PyErr_Print(); + PyErr_Clear(); + } +} + +void +ruby_shutdown(void) +{ + Py_Finalize(); +} diff --git a/src/plugins/ruby_plugins.h b/src/plugins/ruby_plugins.h new file mode 100644 index 00000000..9a2d00d5 --- /dev/null +++ b/src/plugins/ruby_plugins.h @@ -0,0 +1,37 @@ +/* + * ruby_plugins.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 RUBY_PLUGINS_H +#define RUBY_PLUGINS_H + +#include "plugins/plugins.h" + +ProfPlugin* ruby_plugin_create(const char * const filename); + +void ruby_init_hook(ProfPlugin *plugin, const char * const version, const char * const status); +void ruby_on_start_hook(ProfPlugin *plugin); +void ruby_on_connect_hook(ProfPlugin *plugin); +void ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char * const message); + +void ruby_check_error(void); + +#endif diff --git a/src/profanity.c b/src/profanity.c index 30bc560f..9ef6aef5 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -20,7 +20,7 @@ * */ -#include "config.h" +#include "prof_config.h" #include #include @@ -623,10 +623,10 @@ _init(const int disable_tls, char *log_level) _create_directories(); log_level_t prof_log_level = log_level_from_string(log_level); log_init(prof_log_level); - if (strcmp(PACKAGE_STATUS, "development") == 0) { - log_info("Starting Profanity (%sdev)...", PACKAGE_VERSION); + if (strcmp(PROF_PACKAGE_STATUS, "development") == 0) { + log_info("Starting Profanity (%sdev)...", PROF_PACKAGE_VERSION); } else { - log_info("Starting Profanity (%s)...", PACKAGE_VERSION); + log_info("Starting Profanity (%s)...", PROF_PACKAGE_VERSION); } chat_log_init(); groupchat_log_init(); diff --git a/src/ui/console.c b/src/ui/console.c index ee5ad221..0def588c 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -23,9 +23,9 @@ #include #include -#ifdef HAVE_NCURSESW_NCURSES_H +#ifdef PROF_HAVE_NCURSESW_NCURSES_H #include -#elif HAVE_NCURSES_H +#elif PROF_HAVE_NCURSES_H #include #endif @@ -70,7 +70,7 @@ cons_show_word(const char * const word) void cons_debug(const char * const msg, ...) { - if (strcmp(PACKAGE_STATUS, "development") == 0) { + if (strcmp(PROF_PACKAGE_STATUS, "development") == 0) { va_list arg; va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); @@ -167,15 +167,15 @@ cons_about(void) } else { win_print_time(console, '-'); - if (strcmp(PACKAGE_STATUS, "development") == 0) { - wprintw(console->win, "Welcome to Profanity, version %sdev\n", PACKAGE_VERSION); + if (strcmp(PROF_PACKAGE_STATUS, "development") == 0) { + wprintw(console->win, "Welcome to Profanity, version %sdev\n", PROF_PACKAGE_VERSION); } else { - wprintw(console->win, "Welcome to Profanity, version %s\n", PACKAGE_VERSION); + wprintw(console->win, "Welcome to Profanity, version %s\n", PROF_PACKAGE_VERSION); } } win_print_time(console, '-'); - wprintw(console->win, "Copyright (C) 2012, 2013 James Booth <%s>.\n", PACKAGE_BUGREPORT); + wprintw(console->win, "Copyright (C) 2012, 2013 James Booth <%s>.\n", PROF_PACKAGE_BUGREPORT); win_print_time(console, '-'); wprintw(console->win, "License GPLv3+: GNU GPL version 3 or later \n"); win_print_time(console, '-'); @@ -1479,9 +1479,9 @@ _cons_splash_logo(void) win_print_time(console, '-'); wprintw(console->win, "\n"); win_print_time(console, '-'); - if (strcmp(PACKAGE_STATUS, "development") == 0) { - wprintw(console->win, "Version %sdev\n", PACKAGE_VERSION); + if (strcmp(PROF_PACKAGE_STATUS, "development") == 0) { + wprintw(console->win, "Version %sdev\n", PROF_PACKAGE_VERSION); } else { - wprintw(console->win, "Version %s\n", PACKAGE_VERSION); + wprintw(console->win, "Version %s\n", PROF_PACKAGE_VERSION); } } diff --git a/src/ui/core.c b/src/ui/core.c index 83839952..bcfb5c3a 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -20,17 +20,17 @@ * */ -#include "config.h" +#include "prof_config.h" #include #include -#ifdef HAVE_LIBXSS +#ifdef PROF_HAVE_LIBXSS #include #endif #include -#ifdef HAVE_NCURSESW_NCURSES_H +#ifdef PROF_HAVE_NCURSESW_NCURSES_H #include -#elif HAVE_NCURSES_H +#elif PROF_HAVE_NCURSES_H #include #endif @@ -61,7 +61,7 @@ static int max_cols = 0; static char *win_title; -#ifdef HAVE_LIBXSS +#ifdef PROF_HAVE_LIBXSS static Display *display; #endif @@ -109,7 +109,7 @@ ui_init(void) current = console; cons_about(); notifier_init(); -#ifdef HAVE_LIBXSS +#ifdef PROF_HAVE_LIBXSS display = XOpenDisplay(0); #endif ui_idle_time = g_timer_new(); @@ -144,7 +144,7 @@ unsigned long ui_get_idle_time(void) { // if compiled with libxss, get the x sessions idle time -#ifdef HAVE_LIBXSS +#ifdef PROF_HAVE_LIBXSS XScreenSaverInfo *info = XScreenSaverAllocInfo(); if (info != NULL && display != NULL) { XScreenSaverQueryInfo(display, DefaultRootWindow(display), info); @@ -1416,8 +1416,8 @@ _ui_draw_win_title(void) if (prefs_get_boolean(PREF_TITLEBARVERSION)) { g_string_append(version_str, " "); - g_string_append(version_str, PACKAGE_VERSION); - if (strcmp(PACKAGE_STATUS, "development") == 0) { + g_string_append(version_str, PROF_PACKAGE_VERSION); + if (strcmp(PROF_PACKAGE_STATUS, "development") == 0) { g_string_append(version_str, "dev"); } } diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 0ab53131..652347cc 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -21,15 +21,15 @@ */ #define _XOPEN_SOURCE_EXTENDED -#include "config.h" +#include "prof_config.h" #include #include #include -#ifdef HAVE_NCURSESW_NCURSES_H +#ifdef PROF_HAVE_NCURSESW_NCURSES_H #include -#elif HAVE_NCURSES_H +#elif PROF_HAVE_NCURSES_H #include #endif diff --git a/src/ui/notifier.c b/src/ui/notifier.c index 3a72dd83..b4d65e80 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -19,16 +19,16 @@ * along with Profanity. If not, see . * */ -#include "config.h" +#include "prof_config.h" #include #include #include -#ifdef HAVE_LIBNOTIFY +#ifdef PROF_HAVE_LIBNOTIFY #include #endif -#ifdef PLATFORM_CYGWIN +#ifdef PROF_PLATFORM_CYGWIN #include #endif @@ -40,7 +40,7 @@ void notifier_init(void) { -#ifdef HAVE_LIBNOTIFY +#ifdef PROF_HAVE_LIBNOTIFY notify_init("Profanity"); #endif } @@ -48,7 +48,7 @@ notifier_init(void) void notifier_uninit(void) { -#ifdef HAVE_LIBNOTIFY +#ifdef PROF_HAVE_LIBNOTIFY if (notify_is_initted()) { notify_uninit(); } @@ -161,7 +161,7 @@ void notify(const char * const message, int timeout, const char * const category) { -#ifdef HAVE_LIBNOTIFY +#ifdef PROF_HAVE_LIBNOTIFY if (notify_is_initted()) { NotifyNotification *notification; @@ -182,7 +182,7 @@ notify(const char * const message, int timeout, log_error("Libnotify initialisation error."); } #endif -#ifdef PLATFORM_CYGWIN +#ifdef PROF_PLATFORM_CYGWIN NOTIFYICONDATA nid; nid.cbSize = sizeof(NOTIFYICONDATA); //nid.hWnd = hWnd; diff --git a/src/ui/notifier.h b/src/ui/notifier.h index d7e08aa5..1cec9b5e 100644 --- a/src/ui/notifier.h +++ b/src/ui/notifier.h @@ -20,6 +20,9 @@ * */ +#ifndef NOTIFIER_H +#define NOTIFIER_H + void notifier_init(void); void notifier_uninit(void); @@ -34,3 +37,5 @@ void notify_subscription(const char * const from); void notify(const char * const message, int timeout, const char * const category); + +#endif diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 3f0798d3..8bc71776 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -20,14 +20,14 @@ * */ -#include "config.h" +#include "prof_config.h" #include #include -#ifdef HAVE_NCURSESW_NCURSES_H +#ifdef PROF_HAVE_NCURSESW_NCURSES_H #include -#elif HAVE_NCURSES_H +#elif PROF_HAVE_NCURSES_H #include #endif diff --git a/src/ui/ui.h b/src/ui/ui.h index d8ac22fa..75adbd8f 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -23,14 +23,14 @@ #ifndef UI_H #define UI_H -#include "config.h" +#include "prof_config.h" #include #include -#ifdef HAVE_NCURSESW_NCURSES_H +#ifdef PROF_HAVE_NCURSESW_NCURSES_H #include -#elif HAVE_NCURSES_H +#elif PROF_HAVE_NCURSES_H #include #endif diff --git a/src/ui/window.c b/src/ui/window.c index e2e03340..e92b7cf7 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -20,15 +20,15 @@ * */ -#include "config.h" +#include "prof_config.h" #include #include #include -#ifdef HAVE_NCURSESW_NCURSES_H +#ifdef PROF_HAVE_NCURSESW_NCURSES_H #include -#elif HAVE_NCURSES_H +#elif PROF_HAVE_NCURSES_H #include #endif diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index 10aa8a38..9fae6838 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -20,7 +20,7 @@ * */ -#include "config.h" +#include "prof_config.h" #include #include @@ -236,8 +236,8 @@ caps_create_query_response_stanza(xmpp_ctx_t * const ctx) xmpp_stanza_set_attribute(identity, "type", "console"); GString *name_str = g_string_new("Profanity "); - g_string_append(name_str, PACKAGE_VERSION); - if (strcmp(PACKAGE_STATUS, "development") == 0) { + g_string_append(name_str, PROF_PACKAGE_VERSION); + if (strcmp(PROF_PACKAGE_STATUS, "development") == 0) { g_string_append(name_str, "dev"); } xmpp_stanza_set_attribute(identity, "name", name_str->str); diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 48b561f0..92b20197 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -20,7 +20,7 @@ * */ -#include "config.h" +#include "prof_config.h" #include #include @@ -234,8 +234,8 @@ _iq_handle_version_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, xmpp_stanza_t *version = xmpp_stanza_new(ctx); xmpp_stanza_set_name(version, "version"); xmpp_stanza_t *version_txt = xmpp_stanza_new(ctx); - GString *version_str = g_string_new(PACKAGE_VERSION); - if (strcmp(PACKAGE_STATUS, "development") == 0) { + GString *version_str = g_string_new(PROF_PACKAGE_VERSION); + if (strcmp(PROF_PACKAGE_STATUS, "development") == 0) { g_string_append(version_str, "dev"); } xmpp_stanza_set_text(version_txt, version_str->str);