Commit 62380831 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Put the C/C++ wrapper functions in a specific file.

parent e2693c4c
......@@ -60,8 +60,9 @@ libbellesip_la_SOURCES= \
transports/stream_listeningpoint.c \
transports/tls_listeningpoint_polarssl.c \
transports/tls_channel_polarssl.c \
transports/tunnel_listeningpoint.cc \
transports/tunnel_channel.cc \
transports/tunnel_listeningpoint.c \
transports/tunnel_channel.c \
transports/tunnel_wrapper.cc \
refresher.c refresher-helper.h \
dns.c dns.h
......
......@@ -16,17 +16,18 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define DNS_H /* do not include dns.h in a CPP file! */
#include "belle_sip_internal.h"
#include "channel.h"
#ifdef HAVE_TUNNEL
#include <tunnel/client.hh>
#define TUNNEL_POLLING_DURATION 20 /* in ms */
using namespace belledonnecomm;
void * tunnel_client_create_socket(void *tunnelclient, int minLocalPort, int maxLocalPort);
void tunnel_client_close_socket(void *tunnelclient, void *tunnelsocket);
int tunnel_socket_has_data(void *tunnelsocket);
int tunnel_socket_sendto(void *tunnelsocket, const void *buffer, size_t bufsize, const struct sockaddr *dest, socklen_t socklen);
int tunnel_socket_recvfrom(void *tunnelsocket, void *buffer, size_t bufsize, struct sockaddr *src, socklen_t socklen);
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_tunnel_channel_t, belle_sip_channel_t)
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
......@@ -34,27 +35,23 @@ BELLE_SIP_DECLARE_CUSTOM_VPTR_END
struct belle_sip_tunnel_channel {
belle_sip_channel_t base;
belle_sip_source_t *pollingtimer;
TunnelClient *tunnelclient;
TunnelSocket *tunnelsocket;
void *tunnelclient;
void *tunnelsocket;
};
typedef struct belle_sip_tunnel_channel belle_sip_tunnel_channel_t;
static int tunnel_channel_send(belle_sip_channel_t *obj, const void *buf, size_t buflen) {
belle_sip_tunnel_channel_t *chan = reinterpret_cast<belle_sip_tunnel_channel_t *>(obj);
int err;
err = chan->tunnelsocket->sendto(buf, buflen, obj->peer->ai_addr, obj->peer->ai_addrlen);
return err;
belle_sip_tunnel_channel_t *chan = (belle_sip_tunnel_channel_t *)obj;
return tunnel_socket_sendto(chan->tunnelsocket, buf, buflen, obj->peer->ai_addr, obj->peer->ai_addrlen);
}
static int tunnel_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen) {
belle_sip_tunnel_channel_t *chan = reinterpret_cast<belle_sip_tunnel_channel_t *>(obj);
int err;
belle_sip_tunnel_channel_t *chan = (belle_sip_tunnel_channel_t *)obj;
struct sockaddr_storage addr;
socklen_t addrlen = sizeof(addr);
err = chan->tunnelsocket->recvfrom(buf, buflen, (struct sockaddr *)&addr, addrlen);
return err;
return tunnel_socket_recvfrom(chan->tunnelsocket, buf, buflen, (struct sockaddr *)&addr, addrlen);
}
static int tunnel_channel_connect(belle_sip_channel_t *obj, const struct addrinfo *ai) {
......@@ -69,13 +66,13 @@ static int tunnel_channel_connect(belle_sip_channel_t *obj, const struct addrinf
}
static void tunnel_channel_close(belle_sip_channel_t *obj) {
belle_sip_tunnel_channel_t *chan = reinterpret_cast<belle_sip_tunnel_channel_t *>(obj);
chan->tunnelclient->closeSocket(chan->tunnelsocket);
belle_sip_tunnel_channel_t *chan = (belle_sip_tunnel_channel_t *)obj;
tunnel_client_close_socket(chan->tunnelclient, chan->tunnelsocket);
chan->tunnelsocket = NULL;
}
static void tunnel_channel_uninit(belle_sip_channel_t *obj) {
belle_sip_tunnel_channel_t *chan = reinterpret_cast<belle_sip_tunnel_channel_t *>(obj);
belle_sip_tunnel_channel_t *chan = (belle_sip_tunnel_channel_t *)obj;
if (chan->tunnelsocket != NULL) {
tunnel_channel_close(obj);
}
......@@ -87,8 +84,8 @@ static void tunnel_channel_uninit(belle_sip_channel_t *obj) {
}
static int tunnel_polling_timer(belle_sip_tunnel_channel_t *chan) {
if ((chan->tunnelsocket != NULL) && chan->tunnelsocket->hasData()) {
belle_sip_channel_process_data(reinterpret_cast<belle_sip_channel_t *>(chan), BELLE_SIP_EVENT_READ);
if ((chan->tunnelsocket != NULL) && tunnel_socket_has_data(chan->tunnelsocket)) {
belle_sip_channel_process_data((belle_sip_channel_t *)chan, BELLE_SIP_EVENT_READ);
}
return BELLE_SIP_CONTINUE;
}
......@@ -116,8 +113,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_tunnel_channel_t)=
belle_sip_channel_t * belle_sip_channel_new_tunnel(belle_sip_stack_t *stack, void *tunnelclient, const char *bindip, int localport, const char *dest, int port){
belle_sip_tunnel_channel_t *obj = belle_sip_object_new(belle_sip_tunnel_channel_t);
belle_sip_channel_init((belle_sip_channel_t*)obj, stack, bindip, localport, NULL, dest, port);
obj->tunnelclient = static_cast<TunnelClient *>(tunnelclient);
obj->tunnelsocket = obj->tunnelclient->createSocket(5060, 6060);
obj->tunnelclient = tunnelclient;
obj->tunnelsocket = tunnel_client_create_socket(tunnelclient, 5060, 6060);
obj->pollingtimer = belle_sip_timeout_source_new((belle_sip_source_func_t)tunnel_polling_timer, obj, TUNNEL_POLLING_DURATION);
belle_sip_object_set_name((belle_sip_object_t*)obj->pollingtimer, "tunnel_polling_timer");
belle_sip_main_loop_add_source(stack->ml, obj->pollingtimer);
......
......@@ -16,18 +16,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define DNS_H /* do not include dns.h in a CPP file! */
#include "belle_sip_internal.h"
#ifdef HAVE_TUNNEL
#include <tunnel/client.hh>
using namespace belledonnecomm;
struct belle_sip_tunnel_listening_point{
belle_sip_listening_point_t base;
TunnelClient *tunnelclient;
void *tunnelclient;
};
......@@ -53,7 +48,7 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_tunnel_listening_point_t)={
};
static void belle_sip_tunnel_listening_point_init(belle_sip_tunnel_listening_point_t *lp, belle_sip_stack_t *s, TunnelClient *tunnelclient) {
static void belle_sip_tunnel_listening_point_init(belle_sip_tunnel_listening_point_t *lp, belle_sip_stack_t *s, void *tunnelclient) {
belle_sip_listening_point_init((belle_sip_listening_point_t*)lp,s,"0.0.0.0",5060);
lp->tunnelclient = tunnelclient;
}
......@@ -61,7 +56,7 @@ static void belle_sip_tunnel_listening_point_init(belle_sip_tunnel_listening_poi
belle_sip_listening_point_t * belle_sip_tunnel_listening_point_new(belle_sip_stack_t *s, void *tunnelclient){
belle_sip_tunnel_listening_point_t *lp=belle_sip_object_new(belle_sip_tunnel_listening_point_t);
belle_sip_tunnel_listening_point_init(lp,s,static_cast<TunnelClient *>(tunnelclient));
belle_sip_tunnel_listening_point_init(lp,s,tunnelclient);
return (belle_sip_listening_point_t*)lp;
}
......
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010-2013 Belledonne Communications SARL
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, either version 3 of the License, or
(at your option) any later version.
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/>.
*/
#ifdef HAVE_TUNNEL
#include <tunnel/client.hh>
using namespace belledonnecomm;
extern "C" void * tunnel_client_create_socket(void *tunnelclient, int minLocalPort, int maxLocalPort) {
TunnelClient *tc = static_cast<TunnelClient *>(tunnelclient);
return tc->createSocket(minLocalPort, maxLocalPort);
}
extern "C" void tunnel_client_close_socket(void *tunnelclient, void *tunnelsocket) {
TunnelClient *tc = static_cast<TunnelClient *>(tunnelclient);
TunnelSocket *ts = static_cast<TunnelSocket *>(tunnelsocket);
tc->closeSocket(ts);
}
extern "C" int tunnel_socket_has_data(void *tunnelsocket) {
TunnelSocket *ts = static_cast<TunnelSocket *>(tunnelsocket);
return ts->hasData();
}
extern "C" int tunnel_socket_sendto(void *tunnelsocket, const void *buffer, size_t bufsize, const struct sockaddr *dest, socklen_t socklen) {
TunnelSocket *ts = static_cast<TunnelSocket *>(tunnelsocket);
return ts->sendto(buffer, bufsize, dest, socklen);
}
extern "C" int tunnel_socket_recvfrom(void *tunnelsocket, void *buffer, size_t bufsize, struct sockaddr *src, socklen_t socklen) {
TunnelSocket *ts = static_cast<TunnelSocket *>(tunnelsocket);
return ts->recvfrom(buffer, bufsize, src, socklen);
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment