From 2560d7179fd4de6be9e019afa23679bda537d1b0 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 11 Apr 2008 12:39:07 +0000 Subject: [PATCH] Added Plugin helpers --- Makefile | 2 ++ include/Makefile | 2 ++ include/System.h | 1 + include/System/plugin.h | 32 +++++++++++++++++++++ include/project.conf | 2 +- src/Makefile | 5 +++- src/plugin.c | 63 +++++++++++++++++++++++++++++++++++++++++ src/project.conf | 2 +- 8 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 include/System/plugin.h create mode 100644 src/plugin.c diff --git a/Makefile b/Makefile index ac62544..10a2e3c 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,7 @@ dist: $(PACKAGE)-$(VERSION)/src/hash.c \ $(PACKAGE)-$(VERSION)/src/object.c \ $(PACKAGE)-$(VERSION)/src/parser.c \ + $(PACKAGE)-$(VERSION)/src/plugin.c \ $(PACKAGE)-$(VERSION)/src/string.c \ $(PACKAGE)-$(VERSION)/src/token.c \ $(PACKAGE)-$(VERSION)/src/Makefile \ @@ -50,6 +51,7 @@ dist: $(PACKAGE)-$(VERSION)/include/System/hash.h \ $(PACKAGE)-$(VERSION)/include/System/object.h \ $(PACKAGE)-$(VERSION)/include/System/parser.h \ + $(PACKAGE)-$(VERSION)/include/System/plugin.h \ $(PACKAGE)-$(VERSION)/include/System/string.h \ $(PACKAGE)-$(VERSION)/include/System/token.h \ $(PACKAGE)-$(VERSION)/include/Makefile \ diff --git a/include/Makefile b/include/Makefile index 362f7a2..94a2ea7 100644 --- a/include/Makefile +++ b/include/Makefile @@ -33,6 +33,7 @@ install: all $(INSTALL) -m 0644 System/hash.h $(DESTDIR)$(INCLUDEDIR)/System/hash.h $(INSTALL) -m 0644 System/object.h $(DESTDIR)$(INCLUDEDIR)/System/object.h $(INSTALL) -m 0644 System/parser.h $(DESTDIR)$(INCLUDEDIR)/System/parser.h + $(INSTALL) -m 0644 System/plugin.h $(DESTDIR)$(INCLUDEDIR)/System/plugin.h $(INSTALL) -m 0644 System/string.h $(DESTDIR)$(INCLUDEDIR)/System/string.h $(INSTALL) -m 0644 System/token.h $(DESTDIR)$(INCLUDEDIR)/System/token.h @@ -50,6 +51,7 @@ uninstall: $(RM) $(DESTDIR)$(INCLUDEDIR)/System/hash.h $(RM) $(DESTDIR)$(INCLUDEDIR)/System/object.h $(RM) $(DESTDIR)$(INCLUDEDIR)/System/parser.h + $(RM) $(DESTDIR)$(INCLUDEDIR)/System/plugin.h $(RM) $(DESTDIR)$(INCLUDEDIR)/System/string.h $(RM) $(DESTDIR)$(INCLUDEDIR)/System/token.h diff --git a/include/System.h b/include/System.h index b72cd9c..b7e4831 100644 --- a/include/System.h +++ b/include/System.h @@ -31,6 +31,7 @@ # include "System/file.h" # include "System/object.h" # include "System/parser.h" +# include "System/plugin.h" # include "System/string.h" #endif /* !LIBSYSTEM_SYSTEM_H */ diff --git a/include/System/plugin.h b/include/System/plugin.h new file mode 100644 index 0000000..2242b5f --- /dev/null +++ b/include/System/plugin.h @@ -0,0 +1,32 @@ +/* $Id$ */ +/* Copyright (c) 2008 Pierre Pronchery */ +/* This file is part of DeforaOS System libSystem */ +/* libSystem is not free software; you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike + * 3.0 Unported as published by the Creative Commons organization. + * + * libSystem 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 Creative Commons Attribution-NonCommercial- + * ShareAlike 3.0 Unported license for more details. + * + * You should have received a copy of the Creative Commons Attribution- + * NonCommercial-ShareAlike 3.0 along with libSystem; if not, browse to + * http://creativecommons.org/licenses/by-nc-sa/3.0/ */ + + + +#ifndef LIBSYSTEM_PLUGIN_H +# define LIBSYSTEM_PLUGIN_H + + +/* Object */ +typedef void Plugin; + + +/* functions */ +Plugin * plugin_new(char const * libdir, char const * package, + char const * type, char const * name); +void plugin_delete(Plugin * plugin); + +#endif /* !LIBSYSTEM_PLUGIN_H */ diff --git a/include/project.conf b/include/project.conf index a028e04..1f80904 100644 --- a/include/project.conf +++ b/include/project.conf @@ -1,3 +1,3 @@ subdirs=System -includes=System.h,System/appclient.h,System/appserver.h,System/array.h,System/buffer.h,System/config.h,System/error.h,System/event.h,System/file.h,System/hash.h,System/object.h,System/parser.h,System/string.h,System/token.h +includes=System.h,System/appclient.h,System/appserver.h,System/array.h,System/buffer.h,System/config.h,System/error.h,System/event.h,System/file.h,System/hash.h,System/object.h,System/parser.h,System/plugin.h,System/string.h,System/token.h dist=Makefile diff --git a/src/Makefile b/src/Makefile index cd74198..0d652c8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -16,7 +16,7 @@ INSTALL = install all: $(TARGETS) -libSystem_OBJS = appclient.o appinterface.o appserver.o array.o buffer.o config.o error.o event.o hash.o object.o parser.o string.o token.o +libSystem_OBJS = appclient.o appinterface.o appserver.o array.o buffer.o config.o error.o event.o hash.o object.o parser.o plugin.o string.o token.o libSystem_CFLAGS = $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) libSystem.a: $(libSystem_OBJS) @@ -59,6 +59,9 @@ object.o: object.c parser.o: parser.c token.h $(CC) $(libSystem_CFLAGS) -c parser.c +plugin.o: plugin.c + $(CC) $(libSystem_CFLAGS) -c plugin.c + string.o: string.c $(CC) $(libSystem_CFLAGS) -c string.c diff --git a/src/plugin.c b/src/plugin.c new file mode 100644 index 0000000..5a2e38e --- /dev/null +++ b/src/plugin.c @@ -0,0 +1,63 @@ +/* $Id$ */ +/* Copyright (c) 2008 Pierre Pronchery */ +/* This file is part of DeforaOS System libSystem */ +/* libSystem is not free software; you can redistribute it and/or modify it + * under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike + * 3.0 Unported as published by the Creative Commons organization. + * + * libSystem 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 Creative Commons Attribution-NonCommercial- + * ShareAlike 3.0 Unported license for more details. + * + * You should have received a copy of the Creative Commons Attribution- + * NonCommercial-ShareAlike 3.0 along with libSystem; if not, browse to + * http://creativecommons.org/licenses/by-nc-sa/3.0/ */ + + + +#include +#include +#include +#include +#include +#include "System.h" + + +/* Plugin */ +/* private */ +/* constants */ +#define PLUGIN_EXTENSION ".so" + + +/* public */ +/* functions */ +/* plugin_new */ +Plugin * plugin_new(char const * libdir, char const * package, + char const * type, char const * name) +{ + Plugin * plugin; + size_t len; + char * filename; + + len = strlen(libdir) + 1 + strlen(package) + 1 + strlen(type) + 1 + + strlen(name) + strlen(PLUGIN_EXTENSION) + 1; + if((filename = malloc(len)) == NULL) + { + error_set_code(1, "%s", strerror(errno)); + return NULL; + } + snprintf(filename, len, "%s/%s/%s/%s%s", libdir, package, type, name, + PLUGIN_EXTENSION); + if((plugin = dlopen(filename, RTLD_LAZY)) == NULL) + error_set_code(1, "%s: %s", filename, dlerror()); + free(filename); + return plugin; +} + + +/* plugin_delete */ +void plugin_delete(Plugin * plugin) +{ + dlclose(plugin); +} diff --git a/src/project.conf b/src/project.conf index 64b8cad..fafef9c 100644 --- a/src/project.conf +++ b/src/project.conf @@ -7,7 +7,7 @@ dist=Makefile,appinterface.h,token.h [libSystem] type=library -sources=appclient.c,appinterface.c,appserver.c,array.c,buffer.c,config.c,error.c,event.c,hash.c,object.c,parser.c,string.c,token.c +sources=appclient.c,appinterface.c,appserver.c,array.c,buffer.c,config.c,error.c,event.c,hash.c,object.c,parser.c,plugin.c,string.c,token.c ldflags=-l ssl [appclient.c]