Working on the modularization of libApp
This commit is contained in:
parent
b5be1d03be
commit
ca4e92eb8e
9
Makefile
9
Makefile
|
@ -1,6 +1,6 @@
|
||||||
PACKAGE = libApp
|
PACKAGE = libApp
|
||||||
VERSION = 0.1.5
|
VERSION = 0.1.5
|
||||||
SUBDIRS = data doc include src tools
|
SUBDIRS = data doc include src src/transport tools
|
||||||
RM ?= rm -f
|
RM ?= rm -f
|
||||||
LN ?= ln -f
|
LN ?= ln -f
|
||||||
TAR ?= tar -czvf
|
TAR ?= tar -czvf
|
||||||
|
@ -40,12 +40,19 @@ dist:
|
||||||
$(PACKAGE)-$(VERSION)/include/App/project.conf \
|
$(PACKAGE)-$(VERSION)/include/App/project.conf \
|
||||||
$(PACKAGE)-$(VERSION)/src/appclient.c \
|
$(PACKAGE)-$(VERSION)/src/appclient.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/appinterface.c \
|
$(PACKAGE)-$(VERSION)/src/appinterface.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/appmessage.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/appserver.c \
|
$(PACKAGE)-$(VERSION)/src/appserver.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/apptransport.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/common.c \
|
$(PACKAGE)-$(VERSION)/src/common.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/Makefile \
|
$(PACKAGE)-$(VERSION)/src/Makefile \
|
||||||
$(PACKAGE)-$(VERSION)/src/appinterface.h \
|
$(PACKAGE)-$(VERSION)/src/appinterface.h \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/apptransport.h \
|
||||||
$(PACKAGE)-$(VERSION)/src/common.h \
|
$(PACKAGE)-$(VERSION)/src/common.h \
|
||||||
$(PACKAGE)-$(VERSION)/src/project.conf \
|
$(PACKAGE)-$(VERSION)/src/project.conf \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/transport/openssl.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/transport/tcp.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/transport/udp.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/transport/project.conf \
|
||||||
$(PACKAGE)-$(VERSION)/tools/appbroker.c \
|
$(PACKAGE)-$(VERSION)/tools/appbroker.c \
|
||||||
$(PACKAGE)-$(VERSION)/tools/appclient.c \
|
$(PACKAGE)-$(VERSION)/tools/appclient.c \
|
||||||
$(PACKAGE)-$(VERSION)/tools/Makefile \
|
$(PACKAGE)-$(VERSION)/tools/Makefile \
|
||||||
|
|
|
@ -19,7 +19,10 @@
|
||||||
# define LIBAPP_APP_H
|
# define LIBAPP_APP_H
|
||||||
|
|
||||||
|
|
||||||
|
# include "App/app.h"
|
||||||
# include "App/appclient.h"
|
# include "App/appclient.h"
|
||||||
# include "App/appserver.h"
|
# include "App/appserver.h"
|
||||||
|
# include "App/appmessage.h"
|
||||||
|
# include "App/apptransport.h"
|
||||||
|
|
||||||
#endif /* !LIBAPP_APP_H */
|
#endif /* !LIBAPP_APP_H */
|
||||||
|
|
26
include/App/app.h
Normal file
26
include/App/app.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* Copyright (c) 2012 Pierre Pronchery <khorben@defora.org> */
|
||||||
|
/* This file is part of DeforaOS System libApp */
|
||||||
|
/* This program 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, version 3 of the License.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef LIBAPP_APP_APP_H
|
||||||
|
# define LIBAPP_APP_APP_H
|
||||||
|
|
||||||
|
|
||||||
|
/* App */
|
||||||
|
/* types */
|
||||||
|
typedef struct _AppMessage AppMessage;
|
||||||
|
|
||||||
|
#endif /* !LIBAPP_APP_APP_H */
|
|
@ -15,8 +15,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef LIBAPP_APPCLIENT_H
|
#ifndef LIBAPP_APP_APPCLIENT_H
|
||||||
# define LIBAPP_APPCLIENT_H
|
# define LIBAPP_APP_APPCLIENT_H
|
||||||
|
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
# include <System/event.h>
|
# include <System/event.h>
|
||||||
|
@ -36,4 +36,4 @@ void appclient_delete(AppClient * appclient);
|
||||||
int appclient_call(AppClient * appclient, int32_t * ret, char const * function,
|
int appclient_call(AppClient * appclient, int32_t * ret, char const * function,
|
||||||
...);
|
...);
|
||||||
|
|
||||||
#endif /* !LIBAPP_APPCLIENT_H */
|
#endif /* !LIBAPP_APP_APPCLIENT_H */
|
||||||
|
|
45
include/App/appmessage.h
Normal file
45
include/App/appmessage.h
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* Copyright (c) 2012 Pierre Pronchery <khorben@defora.org> */
|
||||||
|
/* This file is part of DeforaOS System libApp */
|
||||||
|
/* This program 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, version 3 of the License.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef LIBAPP_APP_APPMESSAGE_H
|
||||||
|
# define LIBAPP_APP_APPMESSAGE_H
|
||||||
|
|
||||||
|
# include <System/buffer.h>
|
||||||
|
# include "app.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* AppMessage */
|
||||||
|
/* type */
|
||||||
|
typedef enum _AppMessageType
|
||||||
|
{
|
||||||
|
AMT_CALL = 0
|
||||||
|
} AppMessageType;
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
|
AppMessage * appmessage_new_call(char const * method, ...);
|
||||||
|
AppMessage * appmessage_new_deserialize(Buffer * buffer);
|
||||||
|
void appmessage_delete(AppMessage * appmessage);
|
||||||
|
|
||||||
|
/* accessors */
|
||||||
|
String const * appmessage_get_method(AppMessage * message);
|
||||||
|
AppMessageType appmessage_get_type(AppMessage * message);
|
||||||
|
|
||||||
|
/* useful */
|
||||||
|
int appmessage_serialize(AppMessage * message, Buffer * buffer);
|
||||||
|
|
||||||
|
#endif /* !LIBAPP_APP_APPMESSAGE_H */
|
|
@ -15,8 +15,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef LIBAPP_APPSERVER_H
|
#ifndef LIBAPP_APP_APPSERVER_H
|
||||||
# define LIBAPP_APPSERVER_H
|
# define LIBAPP_APP_APPSERVER_H
|
||||||
|
|
||||||
# include <System/event.h>
|
# include <System/event.h>
|
||||||
|
|
||||||
|
@ -46,4 +46,4 @@ void * appserver_get_client_id(AppServer * appserver);
|
||||||
/* useful */
|
/* useful */
|
||||||
int appserver_loop(AppServer * appserver);
|
int appserver_loop(AppServer * appserver);
|
||||||
|
|
||||||
#endif /* !LIBAPP_APPSERVER_H */
|
#endif /* !LIBAPP_APP_APPSERVER_H */
|
||||||
|
|
77
include/App/apptransport.h
Normal file
77
include/App/apptransport.h
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* Copyright (c) 2012 Pierre Pronchery <khorben@defora.org> */
|
||||||
|
/* This file is part of DeforaOS System libApp */
|
||||||
|
/* This program 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, version 3 of the License.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef LIBAPP_APP_APPTRANSPORT_H
|
||||||
|
# define LIBAPP_APP_APPTRANSPORT_H
|
||||||
|
|
||||||
|
# include <System/event.h>
|
||||||
|
# include "app.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* AppTransport */
|
||||||
|
/* types */
|
||||||
|
typedef struct _AppTransport AppTransport;
|
||||||
|
|
||||||
|
typedef struct _AppTransportClient * AppTransportClient;
|
||||||
|
|
||||||
|
typedef enum _AppTransportMode
|
||||||
|
{
|
||||||
|
ATM_SERVER = 0,
|
||||||
|
ATM_CLIENT
|
||||||
|
} AppTransportMode;
|
||||||
|
|
||||||
|
typedef enum _AppTransportStatus
|
||||||
|
{
|
||||||
|
ATS_INIT = 0,
|
||||||
|
ATS_CONNECTED,
|
||||||
|
ATS_INFO,
|
||||||
|
ATS_WARNING,
|
||||||
|
ATS_ERROR,
|
||||||
|
ATS_ERROR_FATAL
|
||||||
|
} AppTransportStatus;
|
||||||
|
|
||||||
|
typedef struct _AppTransportPlugin AppTransportPlugin;
|
||||||
|
|
||||||
|
typedef struct _AppTransportPluginDefinition AppTransportPluginDefinition;
|
||||||
|
|
||||||
|
typedef struct _AppTransportPluginHelper
|
||||||
|
{
|
||||||
|
AppTransport * apptransport;
|
||||||
|
Event * event;
|
||||||
|
/* callbacks */
|
||||||
|
int (*status)(AppTransport * transport, AppTransportStatus status,
|
||||||
|
unsigned int code, char const * message);
|
||||||
|
/* clients */
|
||||||
|
AppTransportClient * (*client_new)(AppTransport * transport);
|
||||||
|
void (*client_delete)(AppTransport * transport,
|
||||||
|
AppTransportClient * client);
|
||||||
|
int (*client_receive)(AppTransport * transport,
|
||||||
|
AppTransportClient * client, AppMessage * message);
|
||||||
|
} AppTransportPluginHelper;
|
||||||
|
|
||||||
|
struct _AppTransportPluginDefinition
|
||||||
|
{
|
||||||
|
char const * name;
|
||||||
|
char const * description;
|
||||||
|
AppTransportPlugin * (*init)(AppTransportPluginHelper * helper,
|
||||||
|
AppTransportMode mode, char const * name);
|
||||||
|
void (*destroy)(AppTransportPlugin * transport);
|
||||||
|
int (*send)(AppTransportPlugin * transport, AppMessage * message,
|
||||||
|
int acknowledge);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* !LIBAPP_APP_APPTRANSPORT_H */
|
|
@ -3,4 +3,4 @@ version=0.1.5
|
||||||
config=h,sh
|
config=h,sh
|
||||||
dist=Makefile,COPYING,config.h,config.sh
|
dist=Makefile,COPYING,config.h,config.sh
|
||||||
|
|
||||||
subdirs=data,doc,include,src,tools
|
subdirs=data,doc,include,src,src/transport,tools
|
||||||
|
|
14
src/Makefile
14
src/Makefile
|
@ -4,11 +4,11 @@ DESTDIR =
|
||||||
LIBDIR = $(PREFIX)/lib
|
LIBDIR = $(PREFIX)/lib
|
||||||
CC ?= cc
|
CC ?= cc
|
||||||
CPPFLAGSF= -I ../include
|
CPPFLAGSF= -I ../include
|
||||||
CPPFLAGS= -I $(PREFIX)/include -D WITH_SSL
|
CPPFLAGS= -I $(PREFIX)/include
|
||||||
CFLAGSF = -W -fPIC `pkg-config --cflags libSystem`
|
CFLAGSF = -W -fPIC `pkg-config --cflags libSystem`
|
||||||
CFLAGS = -Wall -g -O2 -pedantic
|
CFLAGS = -Wall -g -O2 -pedantic
|
||||||
LDFLAGSF= `pkg-config --libs libSystem`
|
LDFLAGSF= `pkg-config --libs libSystem`
|
||||||
LDFLAGS = -lssl
|
LDFLAGS =
|
||||||
AR ?= ar
|
AR ?= ar
|
||||||
RANLIB ?= ranlib
|
RANLIB ?= ranlib
|
||||||
CCSHARED?= $(CC) -shared
|
CCSHARED?= $(CC) -shared
|
||||||
|
@ -20,9 +20,9 @@ INSTALL ?= install
|
||||||
|
|
||||||
all: $(TARGETS)
|
all: $(TARGETS)
|
||||||
|
|
||||||
libApp_OBJS = appclient.o appinterface.o appserver.o common.o
|
libApp_OBJS = appclient.o appinterface.o appmessage.o appserver.o apptransport.o common.o
|
||||||
libApp_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
libApp_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||||
libApp_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) `pkg-config --libs openssl` -lssl
|
libApp_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||||
|
|
||||||
libApp.a: $(libApp_OBJS)
|
libApp.a: $(libApp_OBJS)
|
||||||
$(AR) -rc libApp.a $(libApp_OBJS)
|
$(AR) -rc libApp.a $(libApp_OBJS)
|
||||||
|
@ -39,9 +39,15 @@ appclient.o: appclient.c appinterface.h ../include/App/appclient.h common.h
|
||||||
appinterface.o: appinterface.c ../include/App/appserver.h ../config.h
|
appinterface.o: appinterface.c ../include/App/appserver.h ../config.h
|
||||||
$(CC) $(libApp_CFLAGS) -c appinterface.c
|
$(CC) $(libApp_CFLAGS) -c appinterface.c
|
||||||
|
|
||||||
|
appmessage.o: appmessage.c
|
||||||
|
$(CC) $(libApp_CFLAGS) -c appmessage.c
|
||||||
|
|
||||||
appserver.o: appserver.c appinterface.h ../include/App/appserver.h ../config.h
|
appserver.o: appserver.c appinterface.h ../include/App/appserver.h ../config.h
|
||||||
$(CC) $(libApp_CFLAGS) -c appserver.c
|
$(CC) $(libApp_CFLAGS) -c appserver.c
|
||||||
|
|
||||||
|
apptransport.o: apptransport.c apptransport.h ../include/App/apptransport.h ../config.h
|
||||||
|
$(CC) $(libApp_CFLAGS) -c apptransport.c
|
||||||
|
|
||||||
common.o: common.c
|
common.o: common.c
|
||||||
$(CC) $(libApp_CFLAGS) -c common.c
|
$(CC) $(libApp_CFLAGS) -c common.c
|
||||||
|
|
||||||
|
|
91
src/appmessage.c
Normal file
91
src/appmessage.c
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* Copyright (c) 2012 Pierre Pronchery <khorben@defora.org> */
|
||||||
|
/* This file is part of DeforaOS System libApp */
|
||||||
|
/* This program 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, version 3 of the License.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <System.h>
|
||||||
|
#include "App/appmessage.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* AppMessage */
|
||||||
|
/* private */
|
||||||
|
/* types */
|
||||||
|
struct _AppMessage
|
||||||
|
{
|
||||||
|
AppMessageType type;
|
||||||
|
|
||||||
|
union
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
char * method;
|
||||||
|
Variable * var;
|
||||||
|
size_t var_cnt;
|
||||||
|
} call;
|
||||||
|
} t;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* private */
|
||||||
|
/* prototypes */
|
||||||
|
|
||||||
|
|
||||||
|
/* public */
|
||||||
|
/* functions */
|
||||||
|
/* appmessage_new_call */
|
||||||
|
AppMessage * appmessage_new_call(char const * method, ...)
|
||||||
|
{
|
||||||
|
AppMessage * message;
|
||||||
|
va_list ap;
|
||||||
|
Variable * v;
|
||||||
|
|
||||||
|
if((message = object_new(sizeof(*message))) == NULL)
|
||||||
|
return NULL;
|
||||||
|
message->type = AMT_CALL;
|
||||||
|
message->t.call.method = string_new(method);
|
||||||
|
/* copy the arguments */
|
||||||
|
va_start(ap, method);
|
||||||
|
while((v = va_arg(ap, Variable *)) != NULL)
|
||||||
|
;
|
||||||
|
va_end(ap);
|
||||||
|
/* check for errors */
|
||||||
|
if(message->t.call.method == NULL)
|
||||||
|
{
|
||||||
|
appmessage_delete(message);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* appmessage_delete */
|
||||||
|
static void _delete_call(AppMessage * message);
|
||||||
|
|
||||||
|
void appmessage_delete(AppMessage * message)
|
||||||
|
{
|
||||||
|
switch(message->type)
|
||||||
|
{
|
||||||
|
case AMT_CALL:
|
||||||
|
_delete_call(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
object_delete(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _delete_call(AppMessage * message)
|
||||||
|
{
|
||||||
|
string_delete(message->t.call.method);
|
||||||
|
}
|
83
src/apptransport.c
Normal file
83
src/apptransport.c
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* Copyright (c) 2012 Pierre Pronchery <khorben@defora.org> */
|
||||||
|
/* This file is part of DeforaOS System libApp */
|
||||||
|
/* This program 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, version 3 of the License.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <System.h>
|
||||||
|
#include "apptransport.h"
|
||||||
|
#include "../config.h"
|
||||||
|
|
||||||
|
#ifndef PREFIX
|
||||||
|
# define PREFIX "/usr/local"
|
||||||
|
#endif
|
||||||
|
#ifndef LIBDIR
|
||||||
|
# define LIBDIR PREFIX "/lib"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* AppTransport */
|
||||||
|
/* private */
|
||||||
|
/* types */
|
||||||
|
struct _AppTransport
|
||||||
|
{
|
||||||
|
AppTransportPluginHelper helper;
|
||||||
|
Plugin * plugin;
|
||||||
|
AppTransportPlugin * tplugin;
|
||||||
|
AppTransportPluginDefinition * definition;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* protected */
|
||||||
|
/* functions */
|
||||||
|
/* apptransport_new */
|
||||||
|
AppTransport * apptransport_new(AppTransportMode mode, char const * plugin,
|
||||||
|
char const * name)
|
||||||
|
{
|
||||||
|
AppTransport * transport;
|
||||||
|
|
||||||
|
/* allocate the transport */
|
||||||
|
if((transport = object_new(sizeof(*transport))) == NULL)
|
||||||
|
return NULL;
|
||||||
|
memset(transport, 0, sizeof(*transport));
|
||||||
|
/* initialize the helper */
|
||||||
|
/* FIXME implement */
|
||||||
|
/* load the transport plug-in */
|
||||||
|
if((transport->plugin = plugin_new(LIBDIR, "App", "transport", plugin))
|
||||||
|
== NULL
|
||||||
|
|| (transport->definition = plugin_lookup(
|
||||||
|
transport->plugin, "transport")) == NULL
|
||||||
|
|| transport->definition->init == NULL
|
||||||
|
|| transport->definition->destroy == NULL
|
||||||
|
|| (transport->tplugin = transport->definition->init(
|
||||||
|
&transport->helper, mode, name))
|
||||||
|
== NULL)
|
||||||
|
{
|
||||||
|
apptransport_delete(transport);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return transport;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* apptransport_delete */
|
||||||
|
void apptransport_delete(AppTransport * transport)
|
||||||
|
{
|
||||||
|
if(transport->tplugin != NULL)
|
||||||
|
transport->definition->destroy(transport->tplugin);
|
||||||
|
if(transport->plugin != NULL)
|
||||||
|
plugin_delete(transport->plugin);
|
||||||
|
object_delete(transport);
|
||||||
|
}
|
31
src/apptransport.h
Normal file
31
src/apptransport.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* Copyright (c) 2012 Pierre Pronchery <khorben@defora.org> */
|
||||||
|
/* This file is part of DeforaOS System libApp */
|
||||||
|
/* This program 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, version 3 of the License.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef LIBAPP_APPTRANSPORT_H
|
||||||
|
# define LIBAPP_APPTRANSPORT_H
|
||||||
|
|
||||||
|
#include "App/apptransport.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* AppTransport */
|
||||||
|
/* protected */
|
||||||
|
/* functions */
|
||||||
|
AppTransport * apptransport_new(AppTransportMode mode, char const * plugin,
|
||||||
|
char const * name);
|
||||||
|
void apptransport_delete(AppTransport * transport);
|
||||||
|
|
||||||
|
#endif /* !LIBAPP_APPTRANSPORT_H */
|
|
@ -1,18 +1,16 @@
|
||||||
targets=libApp
|
targets=libApp
|
||||||
cppflags_force=-I ../include
|
cppflags_force=-I ../include
|
||||||
cppflags=-I $(PREFIX)/include -D WITH_SSL
|
cppflags=-I $(PREFIX)/include
|
||||||
#cppflags=-I $(PREFIX)/include
|
|
||||||
cflags_force=-W -fPIC `pkg-config --cflags libSystem`
|
cflags_force=-W -fPIC `pkg-config --cflags libSystem`
|
||||||
cflags=-Wall -g -O2 -pedantic
|
cflags=-Wall -g -O2 -pedantic
|
||||||
ldflags_force=`pkg-config --libs libSystem`
|
ldflags_force=`pkg-config --libs libSystem`
|
||||||
ldflags=-lssl
|
ldflags=
|
||||||
dist=Makefile,appinterface.h,common.h
|
dist=Makefile,appinterface.h,apptransport.h,common.h
|
||||||
|
|
||||||
[libApp]
|
[libApp]
|
||||||
type=library
|
type=library
|
||||||
sources=appclient.c,appinterface.c,appserver.c,common.c
|
sources=appclient.c,appinterface.c,appmessage.c,appserver.c,apptransport.c,common.c
|
||||||
ldflags=`pkg-config --libs openssl` -lssl -lsocket -lws2_32
|
ldflags=-lsocket -lws2_32
|
||||||
#ldflags=-lsocket -lws2_32
|
|
||||||
install=$(LIBDIR)
|
install=$(LIBDIR)
|
||||||
|
|
||||||
[appclient.c]
|
[appclient.c]
|
||||||
|
@ -21,5 +19,11 @@ depends=appinterface.h,../include/App/appclient.h,common.h
|
||||||
[appinterface.c]
|
[appinterface.c]
|
||||||
depends=../include/App/appserver.h,../config.h
|
depends=../include/App/appserver.h,../config.h
|
||||||
|
|
||||||
|
[apptransport.c]
|
||||||
|
depends=../include/App/appmessage.h,../config.h
|
||||||
|
|
||||||
[appserver.c]
|
[appserver.c]
|
||||||
depends=appinterface.h,../include/App/appserver.h,../config.h
|
depends=appinterface.h,../include/App/appserver.h,../config.h
|
||||||
|
|
||||||
|
[apptransport.c]
|
||||||
|
depends=apptransport.h,../include/App/apptransport.h,../config.h
|
||||||
|
|
61
src/transport/Makefile
Normal file
61
src/transport/Makefile
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
TARGETS = openssl.so tcp.so udp.so
|
||||||
|
PREFIX = /usr/local
|
||||||
|
DESTDIR =
|
||||||
|
LIBDIR = $(PREFIX)/lib
|
||||||
|
CC ?= cc
|
||||||
|
CPPFLAGSF?=
|
||||||
|
CPPFLAGS= -I ../../include
|
||||||
|
CFLAGSF = -W
|
||||||
|
CFLAGS = -Wall -g -O2 -pedantic -fPIC
|
||||||
|
AR ?= ar
|
||||||
|
RANLIB ?= ranlib
|
||||||
|
CCSHARED?= $(CC) -shared
|
||||||
|
RM ?= rm -f
|
||||||
|
LN ?= ln -f
|
||||||
|
MKDIR ?= mkdir -p
|
||||||
|
INSTALL ?= install
|
||||||
|
|
||||||
|
|
||||||
|
all: $(TARGETS)
|
||||||
|
|
||||||
|
openssl_OBJS = openssl.o
|
||||||
|
openssl_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||||
|
openssl_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||||
|
|
||||||
|
openssl.so: $(openssl_OBJS)
|
||||||
|
$(CCSHARED) -o openssl.so $(openssl_OBJS) $(openssl_LDFLAGS)
|
||||||
|
|
||||||
|
tcp_OBJS = tcp.o
|
||||||
|
tcp_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||||
|
tcp_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||||
|
|
||||||
|
tcp.so: $(tcp_OBJS)
|
||||||
|
$(CCSHARED) -o tcp.so $(tcp_OBJS) $(tcp_LDFLAGS)
|
||||||
|
|
||||||
|
udp_OBJS = udp.o
|
||||||
|
udp_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||||
|
udp_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||||
|
|
||||||
|
udp.so: $(udp_OBJS)
|
||||||
|
$(CCSHARED) -o udp.so $(udp_OBJS) $(udp_LDFLAGS)
|
||||||
|
|
||||||
|
openssl.o: openssl.c
|
||||||
|
$(CC) $(openssl_CFLAGS) -c openssl.c
|
||||||
|
|
||||||
|
tcp.o: tcp.c
|
||||||
|
$(CC) $(tcp_CFLAGS) -c tcp.c
|
||||||
|
|
||||||
|
udp.o: udp.c
|
||||||
|
$(CC) $(udp_CFLAGS) -c udp.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) -- $(openssl_OBJS) $(tcp_OBJS) $(udp_OBJS)
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
$(RM) -- $(TARGETS)
|
||||||
|
|
||||||
|
install: $(TARGETS)
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
|
||||||
|
.PHONY: all clean distclean install uninstall
|
78
src/transport/openssl.c
Normal file
78
src/transport/openssl.c
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* Copyright (c) 2012 Pierre Pronchery <khorben@defora.org> */
|
||||||
|
/* This file is part of DeforaOS System libApp */
|
||||||
|
/* This program 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, version 3 of the License.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <System.h>
|
||||||
|
#include "App/apptransport.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* OpenSSL */
|
||||||
|
/* private */
|
||||||
|
/* types */
|
||||||
|
typedef struct _AppTransportPlugin OpenSSL;
|
||||||
|
|
||||||
|
struct _AppTransportPlugin
|
||||||
|
{
|
||||||
|
AppTransportPluginHelper * helper;
|
||||||
|
int fd;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* protected */
|
||||||
|
/* prototypes */
|
||||||
|
/* plug-in */
|
||||||
|
static OpenSSL * _openssl_init(AppTransportPluginHelper * helper,
|
||||||
|
AppTransportMode mode, char const * name);
|
||||||
|
static void _openssl_destroy(OpenSSL * openssl);
|
||||||
|
|
||||||
|
|
||||||
|
/* public */
|
||||||
|
/* constants */
|
||||||
|
/* plug-in */
|
||||||
|
AppTransportPluginDefinition definition =
|
||||||
|
{
|
||||||
|
"OpenSSL",
|
||||||
|
NULL,
|
||||||
|
_openssl_init,
|
||||||
|
_openssl_destroy,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* protected */
|
||||||
|
/* functions */
|
||||||
|
/* plug-in */
|
||||||
|
/* openssl_init */
|
||||||
|
static OpenSSL * _openssl_init(AppTransportPluginHelper * helper,
|
||||||
|
AppTransportMode mode, char const * name)
|
||||||
|
{
|
||||||
|
OpenSSL * openssl;
|
||||||
|
|
||||||
|
if((openssl = object_new(sizeof(*openssl))) == NULL)
|
||||||
|
return NULL;
|
||||||
|
openssl->helper = helper;
|
||||||
|
openssl->fd = -1;
|
||||||
|
/* FIXME really implement */
|
||||||
|
return openssl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* openssl_destroy */
|
||||||
|
static void _openssl_destroy(OpenSSL * openssl)
|
||||||
|
{
|
||||||
|
/* FIXME really implement */
|
||||||
|
object_delete(openssl);
|
||||||
|
}
|
16
src/transport/project.conf
Normal file
16
src/transport/project.conf
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
targets=openssl,tcp,udp
|
||||||
|
cppflags=-I ../../include
|
||||||
|
cflags_force=-W
|
||||||
|
cflags=-Wall -g -O2 -pedantic -fPIC
|
||||||
|
|
||||||
|
[openssl]
|
||||||
|
type=plugin
|
||||||
|
sources=openssl.c
|
||||||
|
|
||||||
|
[tcp]
|
||||||
|
type=plugin
|
||||||
|
sources=tcp.c
|
||||||
|
|
||||||
|
[udp]
|
||||||
|
type=plugin
|
||||||
|
sources=udp.c
|
78
src/transport/tcp.c
Normal file
78
src/transport/tcp.c
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* Copyright (c) 2012 Pierre Pronchery <khorben@defora.org> */
|
||||||
|
/* This file is part of DeforaOS System libApp */
|
||||||
|
/* This program 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, version 3 of the License.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <System.h>
|
||||||
|
#include "App/apptransport.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* TCP */
|
||||||
|
/* private */
|
||||||
|
/* types */
|
||||||
|
typedef struct _AppTransportPlugin TCP;
|
||||||
|
|
||||||
|
struct _AppTransportPlugin
|
||||||
|
{
|
||||||
|
AppTransportPluginHelper * helper;
|
||||||
|
int fd;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* protected */
|
||||||
|
/* prototypes */
|
||||||
|
/* plug-in */
|
||||||
|
static TCP * _tcp_init(AppTransportPluginHelper * helper,
|
||||||
|
AppTransportMode mode, char const * name);
|
||||||
|
static void _tcp_destroy(TCP * tcp);
|
||||||
|
|
||||||
|
|
||||||
|
/* public */
|
||||||
|
/* constants */
|
||||||
|
/* plug-in */
|
||||||
|
AppTransportPluginDefinition definition =
|
||||||
|
{
|
||||||
|
"TCP",
|
||||||
|
NULL,
|
||||||
|
_tcp_init,
|
||||||
|
_tcp_destroy,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* protected */
|
||||||
|
/* functions */
|
||||||
|
/* plug-in */
|
||||||
|
/* tcp_init */
|
||||||
|
static TCP * _tcp_init(AppTransportPluginHelper * helper,
|
||||||
|
AppTransportMode mode, char const * name)
|
||||||
|
{
|
||||||
|
TCP * tcp;
|
||||||
|
|
||||||
|
if((tcp = object_new(sizeof(*tcp))) == NULL)
|
||||||
|
return NULL;
|
||||||
|
tcp->helper = helper;
|
||||||
|
tcp->fd = -1;
|
||||||
|
/* FIXME really implement */
|
||||||
|
return tcp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* tcp_destroy */
|
||||||
|
static void _tcp_destroy(TCP * tcp)
|
||||||
|
{
|
||||||
|
/* FIXME really implement */
|
||||||
|
object_delete(tcp);
|
||||||
|
}
|
78
src/transport/udp.c
Normal file
78
src/transport/udp.c
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* Copyright (c) 2012 Pierre Pronchery <khorben@defora.org> */
|
||||||
|
/* This file is part of DeforaOS System libApp */
|
||||||
|
/* This program 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, version 3 of the License.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <System.h>
|
||||||
|
#include "App/apptransport.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* UDP */
|
||||||
|
/* private */
|
||||||
|
/* types */
|
||||||
|
typedef struct _AppTransportPlugin UDP;
|
||||||
|
|
||||||
|
struct _AppTransportPlugin
|
||||||
|
{
|
||||||
|
AppTransportPluginHelper * helper;
|
||||||
|
int fd;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* protected */
|
||||||
|
/* prototypes */
|
||||||
|
/* plug-in */
|
||||||
|
static UDP * _udp_init(AppTransportPluginHelper * helper,
|
||||||
|
AppTransportMode mode, char const * name);
|
||||||
|
static void _udp_destroy(UDP * udp);
|
||||||
|
|
||||||
|
|
||||||
|
/* public */
|
||||||
|
/* constants */
|
||||||
|
/* plug-in */
|
||||||
|
AppTransportPluginDefinition definition =
|
||||||
|
{
|
||||||
|
"UDP",
|
||||||
|
NULL,
|
||||||
|
_udp_init,
|
||||||
|
_udp_destroy,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* protected */
|
||||||
|
/* functions */
|
||||||
|
/* plug-in */
|
||||||
|
/* udp_init */
|
||||||
|
static UDP * _udp_init(AppTransportPluginHelper * helper,
|
||||||
|
AppTransportMode mode, char const * name)
|
||||||
|
{
|
||||||
|
UDP * udp;
|
||||||
|
|
||||||
|
if((udp = object_new(sizeof(*udp))) == NULL)
|
||||||
|
return NULL;
|
||||||
|
udp->helper = helper;
|
||||||
|
udp->fd = -1;
|
||||||
|
/* FIXME really implement */
|
||||||
|
return udp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* udp_destroy */
|
||||||
|
static void _udp_destroy(UDP * udp)
|
||||||
|
{
|
||||||
|
/* FIXME really implement */
|
||||||
|
object_delete(udp);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user