Let it compile again

This commit is contained in:
Pierre Pronchery 2014-04-27 02:23:37 +08:00
parent cbfaf2e265
commit b80ef56ab0
5 changed files with 45 additions and 56 deletions

View File

@ -1,6 +1,5 @@
#$Id$ #$Id$
service=VPN service=VPN
port=4246
[constants] [constants]
#protocols #protocols

View File

@ -6,7 +6,7 @@
# define VPN_VPN_H # define VPN_VPN_H
# include <stdint.h> # include <stdint.h>
# include <System.h> # include <System/App.h>
/* types */ /* types */
@ -48,9 +48,9 @@ typedef String ** STRING_INOUT;
/* calls */ /* calls */
INT32 VPN_close(INT32 fd); INT32 VPN_close(AppServerClient * client, INT32 fd);
INT32 VPN_connect(UINT32 protocol, STRING name); INT32 VPN_connect(AppServerClient * client, UINT32 protocol, STRING name);
INT32 VPN_recv(INT32 fd, BUFFER_IN buf, UINT32 size, UINT32 flags); INT32 VPN_recv(AppServerClient * client, INT32 fd, BUFFER_IN buf, UINT32 size, UINT32 flags);
INT32 VPN_send(INT32 fd, BUFFER_OUT buf, UINT32 size, UINT32 flags); INT32 VPN_send(AppServerClient * client, INT32 fd, BUFFER_OUT buf, UINT32 size, UINT32 flags);
#endif /* !VPN_VPN_H */ #endif /* !VPN_VPN_H */

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $Id$ */
/* Copyright (c) 2010 Pierre Pronchery <khorben@defora.org> */ /* Copyright (c) 2010-2014 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System VPN */ /* This file is part of DeforaOS System VPN */
/* This program is free software: you can redistribute it and/or modify /* 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 * it under the terms of the GNU General Public License as published by
@ -24,7 +24,7 @@
/* usage */ /* usage */
static int _usage(void) static int _usage(void)
{ {
fputs("Usage: " PACKAGE " [-L|-R]\n", stderr); fputs("Usage: " PACKAGE " [-R]\n", stderr);
return 1; return 1;
} }
@ -33,16 +33,13 @@ static int _usage(void)
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
int o; int o;
AppServerOptions options = ASO_LOCAL; AppServerOptions options = 0;
while((o = getopt(argc, argv, "LR")) != -1) while((o = getopt(argc, argv, "R")) != -1)
switch(o) switch(o)
{ {
case 'L':
options = ASO_LOCAL;
break;
case 'R': case 'R':
options = ASO_REMOTE; options |= ASO_REGISTER;
break; break;
default: default:
return _usage(); return _usage();

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $Id$ */
/* Copyright (c) 2010-2012 Pierre Pronchery <khorben@defora.org> */ /* Copyright (c) 2010-2014 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System VPN */ /* This file is part of DeforaOS System VPN */
/* This program is free software: you can redistribute it and/or modify /* 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 * it under the terms of the GNU General Public License as published by
@ -33,7 +33,7 @@
/* types */ /* types */
typedef struct _VPNClient typedef struct _VPNClient
{ {
void * id; AppServerClient * id;
int32_t * sockets; int32_t * sockets;
size_t sockets_cnt; size_t sockets_cnt;
} VPNClient; } VPNClient;
@ -56,12 +56,12 @@ static void _client_init(void);
static void _client_destroy(void); static void _client_destroy(void);
/* accessors */ /* accessors */
static VPNClient * _client_get(void); static VPNClient * _client_get(AppServerClient * asc);
static VPNClient * _client_check(VPNClient * client, int32_t fd); static VPNClient * _client_check(AppServerClient * asc, int32_t fd);
/* useful */ /* useful */
static VPNClient * _client_add(VPNClient * client); static VPNClient * _client_add(AppServerClient * asc);
static VPNClient * _client_add_socket(VPNClient * client, int32_t fd); static VPNClient * _client_add_socket(AppServerClient * asc, int32_t fd);
static VPNClient * _client_remove_socket(VPNClient * client, int32_t fd); static VPNClient * _client_remove_socket(VPNClient * client, int32_t fd);
@ -70,7 +70,7 @@ static VPNClient * _client_remove_socket(VPNClient * client, int32_t fd);
/* vpn */ /* vpn */
int vpn(AppServerOptions options) int vpn(AppServerOptions options)
{ {
if((_appserver = appserver_new("VPN", options)) == NULL) if((_appserver = appserver_new(options, "VPN", NULL)) == NULL)
{ {
error_print(PACKAGE); error_print(PACKAGE);
return 1; return 1;
@ -85,24 +85,26 @@ int vpn(AppServerOptions options)
/* interface */ /* interface */
/* VPN_close */ /* VPN_close */
int32_t VPN_close(int32_t fd) int32_t VPN_close(AppServerClient * asc, int32_t fd)
{ {
VPNClient * client; VPNClient * client;
int32_t ret; int32_t ret;
if((client = _client_check(NULL, fd)) == NULL) if((client = _client_check(asc, fd)) == NULL)
return -1; return -1;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(%d)\n", __func__, fd); fprintf(stderr, "DEBUG: %s(%d)\n", __func__, fd);
#endif #endif
if((ret = close(fd)) == 0) if((ret = close(fd)) == 0)
/* XXX ignore errors */
_client_remove_socket(client, fd); _client_remove_socket(client, fd);
return ret; return ret;
} }
/* VPN_connect */ /* VPN_connect */
int32_t VPN_connect(uint32_t protocol, String const * uri) int32_t VPN_connect(AppServerClient * asc, uint32_t protocol,
String const * uri)
{ {
int32_t ret; int32_t ret;
VPNProtocol vprotocol = protocol; VPNProtocol vprotocol = protocol;
@ -131,7 +133,7 @@ int32_t VPN_connect(uint32_t protocol, String const * uri)
if((ret = socket(sdomain, stype, sprotocol)) == -1) if((ret = socket(sdomain, stype, sprotocol)) == -1)
return -1; return -1;
if(connect(ret, sockaddr, ssize) != 0 if(connect(ret, sockaddr, ssize) != 0
|| _client_add_socket(NULL, ret) == NULL) || _client_add_socket(asc, ret) != 0)
{ {
close(ret); /* XXX necessary when connect() failed? */ close(ret); /* XXX necessary when connect() failed? */
return -1; return -1;
@ -141,11 +143,12 @@ int32_t VPN_connect(uint32_t protocol, String const * uri)
/* VPN_recv */ /* VPN_recv */
int32_t VPN_recv(int32_t fd, Buffer * buffer, uint32_t size, uint32_t flags) int32_t VPN_recv(AppServerClient * asc, int32_t fd, Buffer * buffer,
uint32_t size, uint32_t flags)
{ {
int32_t ret; int32_t ret;
if(_client_check(NULL, fd) == NULL) if(_client_check(asc, fd) == NULL)
return -1; return -1;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(%d, buf, %u, %u)\n", __func__, fd, size, fprintf(stderr, "DEBUG: %s(%d, buf, %u, %u)\n", __func__, fd, size,
@ -169,9 +172,10 @@ int32_t VPN_recv(int32_t fd, Buffer * buffer, uint32_t size, uint32_t flags)
/* VPN_send */ /* VPN_send */
int32_t VPN_send(int32_t fd, Buffer * buffer, uint32_t size, uint32_t flags) int32_t VPN_send(AppServerClient * asc, int32_t fd, Buffer * buffer,
uint32_t size, uint32_t flags)
{ {
if(_client_check(NULL, fd) == NULL) if(_client_check(asc, fd) == NULL)
return -1; return -1;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(%d, buf, %u, %u)\n", __func__, fd, size, fprintf(stderr, "DEBUG: %s(%d, buf, %u, %u)\n", __func__, fd, size,
@ -206,29 +210,24 @@ static void _client_destroy(void)
/* accessors */ /* accessors */
/* client_get */ /* client_get */
static VPNClient * _client_get(void) static VPNClient * _client_get(AppServerClient * client)
{ {
void * id;
size_t i; size_t i;
if((id = appserver_get_client_id(_appserver)) == NULL)
{
error_print(PACKAGE);
return NULL;
}
for(i = 0; i < _clients_cnt; i++) for(i = 0; i < _clients_cnt; i++)
if(_clients[i].id == id) if(_clients[i].id == client)
return &_clients[i]; return &_clients[i];
return NULL; return NULL;
} }
/* client_check */ /* client_check */
static VPNClient * _client_check(VPNClient * client, int32_t fd) static VPNClient * _client_check(AppServerClient * asc, int32_t fd)
{ {
VPNClient * client;
size_t i; size_t i;
if(client == NULL && (client = _client_get()) == NULL) if((client = _client_get(asc)) == NULL)
return NULL; return NULL;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(%d)\n", __func__, fd); fprintf(stderr, "DEBUG: %s(%d)\n", __func__, fd);
@ -242,18 +241,12 @@ static VPNClient * _client_check(VPNClient * client, int32_t fd)
/* useful */ /* useful */
/* client_add */ /* client_add */
static VPNClient * _client_add(VPNClient * client) static VPNClient * _client_add(AppServerClient * asc)
{ {
void * id;
VPNClient * p; VPNClient * p;
if(client == NULL && (client = _client_get()) != NULL) if((p = _client_get(asc)) != NULL)
return client; return p;
if((id = appserver_get_client_id(_appserver)) == NULL)
{
error_print(PACKAGE);
return NULL;
}
if((p = realloc(_clients, sizeof(*p) * (_clients_cnt + 1))) == NULL) if((p = realloc(_clients, sizeof(*p) * (_clients_cnt + 1))) == NULL)
{ {
error_set_print(PACKAGE, 1, "%s", strerror(errno)); error_set_print(PACKAGE, 1, "%s", strerror(errno));
@ -261,7 +254,7 @@ static VPNClient * _client_add(VPNClient * client)
} }
_clients = p; _clients = p;
p = &_clients[_clients_cnt++]; p = &_clients[_clients_cnt++];
p->id = id; p->id = asc;
p->sockets = NULL; p->sockets = NULL;
p->sockets_cnt = 0; p->sockets_cnt = 0;
return p; return p;
@ -269,11 +262,12 @@ static VPNClient * _client_add(VPNClient * client)
/* client_add_socket */ /* client_add_socket */
static VPNClient * _client_add_socket(VPNClient * client, int32_t fd) static VPNClient * _client_add_socket(AppServerClient * asc, int32_t fd)
{ {
VPNClient * client;
int32_t * p; int32_t * p;
if((client = _client_add(client)) == NULL) if((client = _client_add(asc)) == NULL)
return NULL; return NULL;
if((p = realloc(client->sockets, sizeof(*p) if((p = realloc(client->sockets, sizeof(*p)
* (client->sockets_cnt + 1))) == NULL) * (client->sockets_cnt + 1))) == NULL)
@ -298,8 +292,6 @@ static VPNClient * _client_remove_socket(VPNClient * client, int32_t fd)
error_set_print(PACKAGE, 1, "%s", strerror(EINVAL)); error_set_print(PACKAGE, 1, "%s", strerror(EINVAL));
return NULL; return NULL;
} }
if(client == NULL && (client = _client_get()) == NULL)
return NULL;
for(i = 0; i < client->sockets_cnt; i++) for(i = 0; i < client->sockets_cnt; i++)
if(client->sockets[i] == fd) if(client->sockets[i] == fd)
break; break;

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $Id$ */
/* Copyright (c) 2011 Pierre Pronchery <khorben@defora.org> */ /* Copyright (c) 2011-2014 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System VPN */ /* This file is part of DeforaOS System VPN */
/* This program is free software: you can redistribute it and/or modify /* 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 * it under the terms of the GNU General Public License as published by
@ -76,7 +76,7 @@ static void _libvpn_init(void)
exit(1); exit(1);
} }
dlclose(hdl); dlclose(hdl);
if((_appclient = appclient_new("VPN")) == NULL) if((_appclient = appclient_new("VPN", NULL)) == NULL)
{ {
error_print(PROGNAME); error_print(PROGNAME);
exit(1); exit(1);
@ -94,7 +94,8 @@ int connect(int fd, const struct sockaddr * name, socklen_t namelen)
_libvpn_init(); _libvpn_init();
if(fd < VPN_OFFSET) if(fd < VPN_OFFSET)
return old_connect(fd, name, namelen); return old_connect(fd, name, namelen);
if(appclient_call(_appclient, &ret, "connect", fd - VPN_OFFSET) != 0) if(appclient_call(_appclient, (void **)&ret, "connect", fd - VPN_OFFSET)
!= 0)
return -1; return -1;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: connect(%d) => %d\n", fd - VFS_OFFSET, ret); fprintf(stderr, "DEBUG: connect(%d) => %d\n", fd - VFS_OFFSET, ret);