1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Build libprofanity and link with c plugin

This commit is contained in:
James Booth 2013-09-01 03:26:17 +01:00
parent 102dd8cbf3
commit 308e412ea3
14 changed files with 310 additions and 20 deletions

6
.gitignore vendored
View File

@ -35,3 +35,9 @@ _configs.sed
gource.sh gource.sh
*_fingerprints.txt *_fingerprints.txt
*_key.txt *_key.txt
.libs/
libprofanity.la
libtool
m4/
*.so
*.lo

View File

@ -31,9 +31,11 @@ profanity_SOURCES = \
src/plugins/python_api.h src/plugins/python_api.c \ src/plugins/python_api.h src/plugins/python_api.c \
src/plugins/c_plugins.h src/plugins/c_plugins.c \ src/plugins/c_plugins.h src/plugins/c_plugins.c \
src/plugins/ruby_plugins.h src/plugins/ruby_plugins.c \ src/plugins/ruby_plugins.h src/plugins/ruby_plugins.c \
src/plugins/ruby_api.h src/plugins/ruby_api.c src/plugins/ruby_api.h src/plugins/ruby_api.c \
src/plugins/c_api.h src/plugins/c_api.c
lib_LTLIBRARIES = libprofanity.la lib_LTLIBRARIES = libprofanity.la
libprofanity_la_LDFLAGS=-module -avoid-version -shared
libprofanity_la_SOURCES = src/plugins/profapi.c libprofanity_la_SOURCES = src/plugins/profapi.c
library_includedir=$(includedir) library_includedir=$(includedir)

View File

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
autoreconf -f -i -Wall,no-obsolete autoreconf -fiv

View File

@ -3,12 +3,12 @@
AC_PREREQ([2.65]) AC_PREREQ([2.65])
AC_INIT([profanity], [0.4.0], [boothj5web@gmail.com]) AC_INIT([profanity], [0.4.0], [boothj5web@gmail.com])
AC_CONFIG_AUX_DIR([build-aux])
LT_INIT LT_INIT
PACKAGE_STATUS="development" PACKAGE_STATUS="development"
AC_DEFINE_UNQUOTED([PACKAGE_STATUS], ["$PACKAGE_STATUS"], [Status of this build]) AC_DEFINE_UNQUOTED([PACKAGE_STATUS], ["$PACKAGE_STATUS"], [Status of this build])
AC_CONFIG_SRCDIR([src/main.c]) AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADERS([src/config.h]) AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([foreign subdir-objects]) AM_INIT_AUTOMAKE([foreign subdir-objects])
AX_PREFIX_CONFIG_H([src/prof_config.h], [PROF], [src/config.h]) AX_PREFIX_CONFIG_H([src/prof_config.h], [PROF], [src/config.h])

View File

@ -1,12 +1,11 @@
all: test-c-plugin.so all: test-c-plugin.so
%.so:%.o %.so:%.o
$(CC) -shared -fpic -o $@ $^ $(CC) -shared -fpic -lprofanity -o $@ $^
%.o:%.c %.o:%.c
$(CC) $(INCLUDE) -D_GNU_SOURCE -D_BSD_SOURCE -fpic -O3 -std=c99 \ $(CC) $(INCLUDE) -D_GNU_SOURCE -D_BSD_SOURCE -fpic -O3 -std=c99 \
-Wall -Wextra -pedantic -c -o $@ $< -Wall -Wextra -lprofanity -pedantic -c -o $@ $<
clean: clean:
$(RM) test-c-plugin.so $(RM) test-c-plugin.so

View File

@ -3,28 +3,73 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <profapi.h>
void void
prof_init (const char * const version, const char * const status) cmd_c(char **args)
{ {
fprintf (stderr, "called %s with args=<%s, %s>\n", __func__, version, status); if (args[0] != NULL) {
char *start = "c-test: /c command called, arg = ";
char buf[strlen(start) + strlen(args[0]) + 1];
sprintf(buf, "%s%s", start, args[0]);
prof_cons_show(buf);
} else {
prof_cons_show("c-test: /c command called with no arg");
}
prof_cons_alert();
prof_notify("c-test: notify", 2000, "Plugins");
prof_send_line("/about");
prof_cons_show("c-test: sent \"/about\" command");
} }
void void
prof_on_start (void) timer_test(void)
{ {
fprintf (stderr, "called %s with no args\n", __func__); prof_cons_show("c-test: timer fired.");
char *recipient = prof_get_current_recipient();
if (recipient != NULL) {
char *start = " current recipient = ";
char buf[strlen(start) + strlen(recipient) + 1];
sprintf(buf, "%s%s", start, recipient);
prof_cons_show(buf);
}
prof_cons_alert();
} }
void void
prof_on_connect (const char * const account_name, const char * const fulljid) prof_init(const char * const version, const char * const status)
{ {
fprintf (stderr, "called %s with args=<%s, %s>\n", __func__, account_name, fulljid); char *start = "c-test: init. ";
char buf[strlen(start) + strlen(version) + 2 + strlen(status) + 1];
sprintf(buf, "%s%s, %s", start, version, status);
prof_cons_show(buf);
prof_register_command("/c", 0, 1, "/c", "c test", "c test", cmd_c);
prof_register_timed(timer_test, 10);
}
void
prof_on_start(void)
{
prof_cons_show("c-test: on_start");
}
void
prof_on_connect(const char * const account_name, const char * const fulljid)
{
char *start = "c-test: on_connect, ";
char buf[strlen(start) + strlen(account_name) + 2 + strlen(fulljid) + 1];
sprintf(buf, "%s%s, %s", start, account_name, fulljid);
prof_cons_show(buf);
} }
char * char *
prof_on_message_received (const char * const jid, const char *message) prof_on_message_received(const char * const jid, const char *message)
{ {
fprintf (stderr, "called %s with args=<%s, %s>\n", __func__, jid, message); char *start = "c-test: on_message_received, ";
char buf[strlen(start) + strlen(jid) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s", start, jid, message);
prof_cons_show(buf);
prof_cons_alert();
char *result = malloc(strlen(message) + 4); char *result = malloc(strlen(message) + 4);
sprintf(result, "%s%s", message, "[C]"); sprintf(result, "%s%s", message, "[C]");
@ -32,9 +77,13 @@ prof_on_message_received (const char * const jid, const char *message)
} }
char * char *
prof_on_message_send (const char * const jid, const char *message) prof_on_message_send(const char * const jid, const char *message)
{ {
fprintf (stderr, "called %s with args=<%s, %s>\n", __func__, jid, message); char *start = "c-test: on_message_send, ";
char buf[strlen(start) + strlen(jid) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s", start, jid, message);
prof_cons_show(buf);
prof_cons_alert();
char *result = malloc(strlen(message) + 4); char *result = malloc(strlen(message) + 4);
sprintf(result, "%s%s", message, "[C]"); sprintf(result, "%s%s", message, "[C]");

View File

@ -58,7 +58,7 @@ api_register_command(const char *command_name, int min_args, int max_args,
command->short_help = short_help; command->short_help = short_help;
command->long_help = long_help; command->long_help = long_help;
command->callback = callback; command->callback = callback;
command->callback_func =callback_func; command->callback_func = callback_func;
callbacks_add_command(command); callbacks_add_command(command);
} }

116
src/plugins/c_api.c Normal file
View File

@ -0,0 +1,116 @@
/*
* c_api.c
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#include <stdlib.h>
#include <glib.h>
#include "log.h"
#include "plugins/api.h"
#include "plugins/c_api.h"
#include "plugins/callbacks.h"
#include "plugins/profapi.h"
typedef struct command_wrapper_t {
void(*func)(char **args);
} CommandWrapper;
typedef struct timed_wrapper_t {
void(*func)(void);
} TimedWrapper;
static void
c_api_cons_alert(void)
{
api_cons_alert();
}
static void
c_api_cons_show(const char * const message)
{
if (message != NULL) {
api_cons_show(message);
}
}
static void
c_api_register_command(const char *command_name, int min_args, int max_args,
const char *usage, const char *short_help, const char *long_help, void(*callback)(char **args))
{
CommandWrapper *wrapper = malloc(sizeof(CommandWrapper));
wrapper->func = callback;
api_register_command(command_name, min_args, max_args, usage,
short_help, long_help, wrapper, c_command_callback);
}
static void
c_api_register_timed(void(*callback)(void), int interval_seconds)
{
TimedWrapper *wrapper = malloc(sizeof(TimedWrapper));
wrapper->func = callback;
api_register_timed(wrapper, interval_seconds, c_timed_callback);
}
static void
c_api_notify(const char *message, int timeout_ms, const char *category)
{
api_notify(message, category, timeout_ms);
}
static void
c_api_send_line(char *line)
{
api_send_line(line);
}
static char *
c_api_get_current_recipient(void)
{
return api_get_current_recipient();
}
void
c_command_callback(PluginCommand *command, gchar **args)
{
CommandWrapper *wrapper = command->callback;
void(*f)(gchar **args) = wrapper->func;
f(args);
}
void
c_timed_callback(PluginTimedFunction *timed_function)
{
TimedWrapper *wrapper = timed_function->callback;
void(*f)(void) = wrapper->func;
f();
}
void
c_api_init(void)
{
prof_cons_alert = c_api_cons_alert;
prof_cons_show = c_api_cons_show;
prof_register_command = c_api_register_command;
prof_register_timed = c_api_register_timed;
prof_notify = c_api_notify;
prof_send_line = c_api_send_line;
prof_get_current_recipient = c_api_get_current_recipient;
}

28
src/plugins/c_api.h Normal file
View File

@ -0,0 +1,28 @@
/*
* c_api.h
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#include <glib.h>
void c_api_init(void);
void c_command_callback(PluginCommand *command, gchar **args);
void c_timed_callback(PluginTimedFunction *timed_function);

View File

@ -11,8 +11,15 @@
#include "plugins/callbacks.h" #include "plugins/callbacks.h"
#include "plugins/plugins.h" #include "plugins/plugins.h"
#include "plugins/c_plugins.h" #include "plugins/c_plugins.h"
#include "plugins/c_api.h"
#include "ui/ui.h" #include "ui/ui.h"
void
c_env_init(void)
{
c_api_init();
}
ProfPlugin * ProfPlugin *
c_plugin_create(const char * const filename) c_plugin_create(const char * const filename)
{ {

View File

@ -3,6 +3,8 @@
#include "plugins/plugins.h" #include "plugins/plugins.h"
void c_env_init(void);
ProfPlugin* c_plugin_create(const char * const filename); ProfPlugin* c_plugin_create(const char * const filename);
void c_init_hook(ProfPlugin *plugin, const char * const version, const char * const status); void c_init_hook(ProfPlugin *plugin, const char * const version, const char * const status);

View File

@ -27,14 +27,13 @@
#include "plugins/callbacks.h" #include "plugins/callbacks.h"
#include "plugins/plugins.h" #include "plugins/plugins.h"
#include "plugins/python_plugins.h" #include "plugins/python_plugins.h"
#include "plugins/c_plugins.h"
#include "plugins/python_api.h" #include "plugins/python_api.h"
#include "plugins/c_plugins.h"
#include "plugins/c_api.h"
#include "plugins/ruby_plugins.h" #include "plugins/ruby_plugins.h"
#include "plugins/ruby_api.h" #include "plugins/ruby_api.h"
#include "ui/ui.h" #include "ui/ui.h"
static GSList* plugins; static GSList* plugins;
void void
@ -44,6 +43,7 @@ plugins_init(void)
python_env_init(); python_env_init();
ruby_env_init(); ruby_env_init();
c_env_init();
// load plugins // load plugins
gchar **plugins_load = prefs_get_plugins(); gchar **plugins_load = prefs_get_plugins();

40
src/plugins/profapi.c Normal file
View File

@ -0,0 +1,40 @@
/*
* prof_api.c
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#include <stdlib.h>
#include "plugins/callbacks.h"
void (*prof_cons_alert)(void) = NULL;
void (*prof_cons_show)(const char * const message) = NULL;
void (*prof_register_command)(const char *command_name, int min_args, int max_args,
const char *usage, const char *short_help, const char *long_help, void(*callback)(char **args)) = NULL;
void (*prof_register_timed)(void(*callback)(void), int interval_seconds) = NULL;
void (*prof_notify)(const char *message, int timeout_ms, const char *category) = NULL;
void (*prof_send_line)(char *line) = NULL;
char* (*prof_get_current_recipient)(void) = NULL;

41
src/plugins/profapi.h Normal file
View File

@ -0,0 +1,41 @@
/*
* prof_api.h
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#ifndef PROF_API_H
#define PROF_API_H
void (*prof_cons_alert)(void);
void (*prof_cons_show)(const char * const message);
void (*prof_register_command)(const char *command_name, int min_args, int max_args,
const char *usage, const char *short_help, const char *long_help, void(*callback)(char **args));
void (*prof_register_timed)(void(*callback)(void), int interval_seconds);
void (*prof_notify)(const char *message, int timeout_ms, const char *category);
void (*prof_send_line)(char *line);
char* (*prof_get_current_recipient)(void);
#endif