|
From: <s-v...@us...> - 2013-09-03 16:26:33
|
Revision: 239
http://sourceforge.net/p/turnserver/code/239
Author: s-vincent
Date: 2013-09-03 16:26:29 +0000 (Tue, 03 Sep 2013)
Log Message:
-----------
Move to new vsutils source files and change code accordingly.
Modified Paths:
--------------
trunk/ChangeLog
trunk/extra/turnserver.debian.initd
trunk/src/Makefile.am
trunk/src/account.c
trunk/src/allocation.c
trunk/src/conf.c
trunk/src/dbg.c
trunk/src/dbg.h
trunk/src/list.h
trunk/src/mod_tmpuser.c
trunk/src/protocol.c
trunk/src/test_echo_server.c
trunk/src/test_turn_client.c
trunk/src/tls_peer.c
trunk/src/tls_peer.h
trunk/src/turnserver.c
trunk/src/util_crypto.c
trunk/src/util_crypto.h
trunk/src/util_sys.c
trunk/src/util_sys.h
Added Paths:
-----------
trunk/src/util_net.c
trunk/src/util_net.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2013-06-14 16:27:09 UTC (rev 238)
+++ trunk/ChangeLog 2013-09-03 16:26:29 UTC (rev 239)
@@ -1,18 +1,18 @@
-2013-xx-xx Sebastien Vincent <seb...@tu...>
+2013-xx-xx Sebastien Vincent <seb...@tu...>
- * Version 0.8 -
+ * Version 0.8 - Move to a new vsutils source files (list, util_sys, ...).
-2013-06-14 Sebastien Vincent <seb...@tu...>
+2013-06-14 Sebastien Vincent <seb...@tu...>
- * Version 0.7.3 - Minor fix to be able to compile with recent glibc.
+ * Version 0.7.3 - Minor fix to be able to compile with recent glibc.
-2012-11-19 Daniel Pocock <da...@po...>
+2012-11-19 Daniel Pocock <da...@po...>
- * Version 0.7.2 - Further tweaks to autotools
+ * Version 0.7.2 - Further tweaks to autotools.
-2012-10-17 Sebastien Vincent <seb...@tu...>
+2012-10-17 Sebastien Vincent <seb...@tu...>
- * Version 0.7.1 - Minor modifications to ease Debian package integration.
+ * Version 0.7.1 - Minor modifications to ease Debian package integration.
2012-10-01 Sebastien Vincent <seb...@tu...>
Modified: trunk/extra/turnserver.debian.initd
===================================================================
--- trunk/extra/turnserver.debian.initd 2013-06-14 16:27:09 UTC (rev 238)
+++ trunk/extra/turnserver.debian.initd 2013-09-03 16:26:29 UTC (rev 239)
@@ -9,6 +9,8 @@
# Description: Enable service provided by turnserver.
### END INIT INFO
+. /lib/lsb/init-functions
+
set -e
DAEMON=/usr/local/sbin/turnserver
@@ -17,8 +19,6 @@
test -x $DAEMON || exit 0
-. /lib/lsb/init-functions
-
case "$1" in
start)
echo "Starting $NAME"
Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am 2013-06-14 16:27:09 UTC (rev 238)
+++ trunk/src/Makefile.am 2013-09-03 16:26:29 UTC (rev 239)
@@ -14,6 +14,7 @@
protocol.h \
dbg.h \
util_sys.h \
+ util_net.h \
util_crypto.h \
list.h \
tls_peer.h \
@@ -26,6 +27,7 @@
protocol.c \
dbg.c \
util_sys.c \
+ util_net.c \
util_crypto.c \
tls_peer.c \
allocation.c \
@@ -35,11 +37,13 @@
test_turn_client_SOURCES = test_turn_client.c \
protocol.c \
+ util_net.c \
util_crypto.c \
tls_peer.c \
util_sys.c
test_echo_server_SOURCES = test_echo_server.c \
+ util_net.c \
tls_peer.c
valgrind-run:
Modified: trunk/src/account.c
===================================================================
--- trunk/src/account.c 2013-06-14 16:27:09 UTC (rev 238)
+++ trunk/src/account.c 2013-09-03 16:26:29 UTC (rev 239)
@@ -96,9 +96,9 @@
struct list_head* get = NULL;
struct list_head* n = NULL;
- list_iterate_safe(get, n, list)
+ list_head_iterate_safe(list, get, n)
{
- struct account_desc* tmp = list_get(get, struct account_desc, list);
+ struct account_desc* tmp = list_head_get(get, struct account_desc, list);
if(!strncmp(tmp->username, username, sizeof(tmp->username) - 1))
{
@@ -119,25 +119,22 @@
struct list_head* get = NULL;
struct list_head* n = NULL;
- list_iterate_safe(get, n, list)
+ list_head_iterate_safe(list, get, n)
{
- struct account_desc* tmp = list_get(get, struct account_desc, list);
- LIST_DEL(&tmp->list);
+ struct account_desc* tmp = list_head_get(get, struct account_desc, list);
+ list_head_remove(list, &tmp->list);
account_desc_free(&tmp);
}
}
void account_list_add(struct list_head* list, struct account_desc* desc)
{
- LIST_ADD(&desc->list, list);
+ list_head_add(&desc->list, list);
}
void account_list_remove(struct list_head* list, struct account_desc* desc)
{
- /* to avoid compilation warning */
- (void)list;
-
- LIST_DEL(&desc->list);
+ list_head_remove(list, &desc->list);
}
int account_parse_file(struct list_head* list, const char* file)
Modified: trunk/src/allocation.c
===================================================================
--- trunk/src/allocation.c 2013-06-14 16:27:09 UTC (rev 238)
+++ trunk/src/allocation.c 2013-09-03 16:26:29 UTC (rev 239)
@@ -116,17 +116,17 @@
ret->bucket_tokendown = 0;
/* list of permissions */
- INIT_LIST(ret->peers_permissions);
+ list_head_init(&ret->peers_permissions);
/* list of channels */
- INIT_LIST(ret->peers_channels);
+ list_head_init(&ret->peers_channels);
/* list of TCP relays */
- INIT_LIST(ret->tcp_relays);
+ list_head_init(&ret->tcp_relays);
/* linked lists, second ones used when timer has expired */
- INIT_LIST(ret->list);
- INIT_LIST(ret->list2);
+ list_head_init(&ret->list);
+ list_head_init(&ret->list2);
/* timer */
memset(&event, 0x00, sizeof(struct sigevent));
@@ -164,29 +164,29 @@
free(ret->username);
/* free up the lists */
- list_iterate_safe(get, n, &ret->peers_channels)
+ list_head_iterate_safe(&ret->peers_channels, get, n)
{
- struct allocation_channel* tmp = list_get(get, struct allocation_channel,
+ struct allocation_channel* tmp = list_head_get(get, struct allocation_channel,
list);
timer_delete(tmp->expire_timer);
- LIST_DEL(&tmp->list);
- LIST_DEL(&tmp->list2);
+ list_head_remove(&tmp->list, &tmp->list);
+ list_head_remove(&tmp->list2, &tmp->list2);
free(tmp);
}
- list_iterate_safe(get, n, &ret->peers_permissions)
+ list_head_iterate_safe(&ret->peers_permissions, get, n)
{
- struct allocation_permission* tmp = list_get(get,
+ struct allocation_permission* tmp = list_head_get(get,
struct allocation_permission, list);
timer_delete(tmp->expire_timer);
- LIST_DEL(&tmp->list);
- LIST_DEL(&tmp->list2);
+ list_head_remove(&tmp->list, &tmp->list);
+ list_head_remove(&tmp->list2, &tmp->list2);
free(tmp);
}
- list_iterate_safe(get, n, &ret->tcp_relays)
+ list_head_iterate_safe(&ret->tcp_relays, get, n)
{
- struct allocation_tcp_relay* tmp = list_get(get,
+ struct allocation_tcp_relay* tmp = list_head_get(get,
struct allocation_tcp_relay, list);
allocation_tcp_relay_list_remove(&ret->tcp_relays, tmp);
}
@@ -241,9 +241,9 @@
struct list_head* get = NULL;
struct list_head* n = NULL;
- list_iterate_safe(get, n, &desc->peers_permissions)
+ list_head_iterate_safe(&desc->peers_permissions, get, n)
{
- struct allocation_permission* tmp = list_get(get,
+ struct allocation_permission* tmp = list_head_get(get,
struct allocation_permission, list);
/* check only the network address (not the port) */
@@ -268,9 +268,9 @@
struct list_head* get = NULL;
struct list_head* n = NULL;
- list_iterate_safe(get, n, &desc->peers_permissions)
+ list_head_iterate_safe(&desc->peers_permissions, get, n)
{
- struct allocation_permission* tmp = list_get(get,
+ struct allocation_permission* tmp = list_head_get(get,
struct allocation_permission, list);
/* check only the network address (not the port) */
@@ -341,8 +341,8 @@
allocation_permission_set_timer(ret, lifetime);
/* add to the list */
- LIST_ADD(&ret->list, &desc->peers_permissions);
- INIT_LIST(ret->list2);
+ list_head_add(&ret->list, &desc->peers_permissions);
+ list_head_init(&ret->list2);
return 0;
}
@@ -352,9 +352,9 @@
struct list_head* get = NULL;
struct list_head* n = NULL;
- list_iterate_safe(get, n, &desc->peers_channels)
+ list_head_iterate_safe(&desc->peers_channels, get, n)
{
- struct allocation_channel* tmp = list_get(get, struct allocation_channel,
+ struct allocation_channel* tmp = list_head_get(get, struct allocation_channel,
list);
if(tmp->family == family && !memcmp(&tmp->peer_addr, peer_addr,
@@ -374,9 +374,9 @@
struct list_head* get = NULL;
struct list_head* n = NULL;
- list_iterate_safe(get, n, &desc->peers_channels)
+ list_head_iterate_safe(&desc->peers_channels, get, n)
{
- struct allocation_channel* tmp = list_get(get, struct allocation_channel,
+ struct allocation_channel* tmp = list_head_get(get, struct allocation_channel,
list);
if(tmp->channel_number == channel)
@@ -421,8 +421,8 @@
allocation_channel_set_timer(ret, lifetime);
/* add to the list */
- LIST_ADD(&ret->list, &desc->peers_channels);
- INIT_LIST(ret->list2);
+ list_head_add(&ret->list, &desc->peers_channels);
+ list_head_init(&ret->list2);
return 0;
}
@@ -471,26 +471,23 @@
struct list_head* get = NULL;
struct list_head* n = NULL;
- list_iterate_safe(get, n, list)
+ list_head_iterate_safe(list, get, n)
{
- struct allocation_desc* tmp = list_get(get, struct allocation_desc, list);
- LIST_DEL(&tmp->list);
+ struct allocation_desc* tmp = list_head_get(get, struct allocation_desc, list);
+ list_head_remove(&tmp->list, &tmp->list);
allocation_desc_free(&tmp);
}
}
void allocation_list_add(struct list_head* list, struct allocation_desc* desc)
{
- LIST_ADD_TAIL(&desc->list, list);
+ list_head_add_tail(&desc->list, list);
}
void allocation_list_remove(struct list_head* list,
struct allocation_desc* desc)
{
- /* to avoid compilation warning */
- (void)list;
-
- LIST_DEL(&desc->list);
+ list_head_remove(list, &desc->list);
allocation_desc_free(&desc);
}
@@ -500,9 +497,9 @@
struct list_head* get = NULL;
struct list_head* n = NULL;
- list_iterate_safe(get, n, list)
+ list_head_iterate_safe(list, get, n)
{
- struct allocation_desc* tmp = list_get(get, struct allocation_desc, list);
+ struct allocation_desc* tmp = list_head_get(get, struct allocation_desc, list);
if(!strcmp(tmp->username, username) && !strcmp(tmp->realm, realm))
{
return tmp;
@@ -519,9 +516,9 @@
struct list_head* get = NULL;
struct list_head* n = NULL;
- list_iterate_safe(get, n, list)
+ list_head_iterate_safe(list, get, n)
{
- struct allocation_desc* tmp = list_get(get, struct allocation_desc, list);
+ struct allocation_desc* tmp = list_head_get(get, struct allocation_desc, list);
if(!memcmp(tmp->transaction_id, id, 12))
{
return tmp;
@@ -539,9 +536,9 @@
struct list_head* get = NULL;
struct list_head* n = NULL;
- list_iterate_safe(get, n, list)
+ list_head_iterate_safe(list, get, n)
{
- struct allocation_desc* tmp = list_get(get, struct allocation_desc, list);
+ struct allocation_desc* tmp = list_head_get(get, struct allocation_desc, list);
if(tmp->tuple.transport_protocol == transport_protocol &&
!memcmp(&tmp->tuple.server_addr, server_addr, addr_size) &&
@@ -561,9 +558,9 @@
struct list_head* get = NULL;
struct list_head* n = NULL;
- list_iterate_safe(get, n, list)
+ list_head_iterate_safe(list, get, n)
{
- struct allocation_desc* tmp = list_get(get, struct allocation_desc, list);
+ struct allocation_desc* tmp = list_head_get(get, struct allocation_desc, list);
if(!memcmp(&tmp->relayed_addr, relayed_addr, addr_size))
{
@@ -645,19 +642,17 @@
allocation_tcp_relay_set_timer(ret, timeout);
/* add to the list */
- LIST_ADD(&ret->list, &desc->tcp_relays);
- INIT_LIST(ret->list2);
+ list_head_add(&ret->list, &desc->tcp_relays);
+ list_head_init(&ret->list2);
return 0;
}
void allocation_tcp_relay_list_remove(struct list_head* list,
struct allocation_tcp_relay* relay)
{
- (void)list; /* not used */
+ list_head_remove(list, &relay->list);
+ list_head_remove(&relay->list2, &relay->list2);
- LIST_DEL(&relay->list);
- LIST_DEL(&relay->list2);
-
/* close socket */
if(relay->peer_sock > 0)
{
@@ -686,9 +681,9 @@
struct list_head* get = NULL;
struct list_head* n = NULL;
- list_iterate_safe(get, n, &desc->tcp_relays)
+ list_head_iterate_safe(&desc->tcp_relays, get, n)
{
- struct allocation_tcp_relay* tmp = list_get(get,
+ struct allocation_tcp_relay* tmp = list_head_get(get,
struct allocation_tcp_relay, list);
if(tmp->connection_id == id)
@@ -708,9 +703,9 @@
struct list_head* get = NULL;
struct list_head* n = NULL;
- list_iterate_safe(get, n, &desc->tcp_relays)
+ list_head_iterate_safe(&desc->tcp_relays, get, n)
{
- struct allocation_tcp_relay* tmp = list_get(get,
+ struct allocation_tcp_relay* tmp = list_head_get(get,
struct allocation_tcp_relay, list);
if(tmp->family != family)
@@ -775,8 +770,8 @@
allocation_token_set_timer(ret, lifetime);
- INIT_LIST(ret->list);
- INIT_LIST(ret->list2);
+ list_head_init(&ret->list);
+ list_head_init(&ret->list2);
return ret;
}
@@ -784,8 +779,8 @@
void allocation_token_free(struct allocation_token** token)
{
timer_delete((*token)->expire_timer);
- LIST_DEL(&(*token)->list);
- LIST_DEL(&(*token)->list2);
+ list_head_remove(&(*token)->list, &(*token)->list);
+ list_head_remove(&(*token)->list2, &(*token)->list2);
free(*token);
*token = NULL;
}
@@ -811,15 +806,13 @@
void allocation_token_list_add(struct list_head* list,
struct allocation_token* token)
{
- LIST_ADD(&token->list, list);
+ list_head_add(&token->list, list);
}
void allocation_token_list_remove(struct list_head* list,
struct allocation_token* token)
{
- (void)list; /* not used */
-
- LIST_DEL(&token->list);
+ list_head_remove(list, &token->list);
allocation_token_free(&token);
}
@@ -829,9 +822,9 @@
struct list_head* get = NULL;
struct list_head* n = NULL;
- list_iterate_safe(get, n, list)
+ list_head_iterate_safe(list, get, n)
{
- struct allocation_token* tmp = list_get(get, struct allocation_token, list);
+ struct allocation_token* tmp = list_head_get(get, struct allocation_token, list);
if(!memcmp(tmp->id, id, 8))
{
@@ -848,10 +841,10 @@
struct list_head* get = NULL;
struct list_head* n = NULL;
- list_iterate_safe(get, n, list)
+ list_head_iterate_safe(list, get, n)
{
- struct allocation_token* tmp = list_get(get, struct allocation_token, list);
- LIST_DEL(&tmp->list);
+ struct allocation_token* tmp = list_head_get(get, struct allocation_token, list);
+ list_head_remove(&tmp->list, &tmp->list);
/* this function will probably be a cleanup so close the relayed socket */
close(tmp->sock);
allocation_token_free(&tmp);
Modified: trunk/src/conf.c
===================================================================
--- trunk/src/conf.c 2013-06-14 16:27:09 UTC (rev 238)
+++ trunk/src/conf.c 2013-09-03 16:26:29 UTC (rev 239)
@@ -218,7 +218,7 @@
}
/* add to the list */
- LIST_ADD(&denied->list, denied_address_list);
+ list_head_add(&denied->list, denied_address_list);
}
return 0;
Modified: trunk/src/dbg.c
===================================================================
--- trunk/src/dbg.c 2013-06-14 16:27:09 UTC (rev 238)
+++ trunk/src/dbg.c 2013-09-03 16:26:29 UTC (rev 239)
@@ -1,6 +1,6 @@
/*
* TurnServer - TURN server implementation.
- * Copyright (C) 2008-2011 Sebastien Vincent <seb...@tu...>
+ * Copyright (C) 2008-2013 Sebastien Vincent <seb...@tu...>
*
* 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
@@ -30,7 +30,7 @@
*/
/*
- * Copyright (C) 2006-2011 Sebastien Vincent.
+ * Copyright (C) 2006-2013 Sebastien Vincent.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -49,7 +49,7 @@
* \file dbg.c
* \brief Some routines to print debug message.
* \author Sebastien Vincent
- * \date 2006-2011
+ * \date 2006-2013
*/
#ifdef HAVE_CONFIG_H
@@ -60,19 +60,12 @@
#include <stdarg.h>
#include <stdlib.h>
+#include <stdint.h>
+
#ifdef _MSC_VER
+#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-/* replacement for stdint.h */
-typedef __int8 int8_t;
-typedef unsigned __int8 uint8_t;
-typedef __int16 int16_t;
-typedef unsigned __int16 uint16_t;
-typedef __int32 int32_t;
-typedef unsigned __int32 uint32_t;
-typedef __int64 int64_t;
-typedef unsigned __int64 uint64_t;
#else
-#include <stdint.h>
#include <sys/time.h>
#endif
@@ -106,21 +99,8 @@
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
-
- /*
- fprintf(stderr, "%02d:%02d:%02d.%06u [%s:%d] %s", tlt->tm_hour,
- tlt->tm_min, tlt->tm_sec, (uint32_t)lt.tv_usec, file, line, msg);
- */
}
-void dbg_print_null(const char* f, int line, const char* format, ...)
-{
- /* to avoid compilation warnings */
- (void)f;
- (void)line;
- (void)format;
-}
-
void dbg_print_hexa(const char* f, int line, const char* buf, size_t len,
const char* format, ...)
{
Modified: trunk/src/dbg.h
===================================================================
--- trunk/src/dbg.h 2013-06-14 16:27:09 UTC (rev 238)
+++ trunk/src/dbg.h 2013-09-03 16:26:29 UTC (rev 239)
@@ -1,6 +1,6 @@
/*
* TurnServer - TURN server implementation.
- * Copyright (C) 2008-2011 Sebastien Vincent <seb...@tu...>
+ * Copyright (C) 2008-2013 Sebastien Vincent <seb...@tu...>
*
* 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
@@ -30,7 +30,7 @@
*/
/*
- * Copyright (C) 2006-2011 Sebastien Vincent.
+ * Copyright (C) 2006-2013 Sebastien Vincent.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -49,11 +49,11 @@
* \file dbg.h
* \brief Some routines to print debug message.
* \author Sebastien Vincent
- * \date 2006-2011
+ * \date 2006-2013
*/
-#ifndef DBG_H
-#define DBG_H
+#ifndef VSUTILS_DBG_H
+#define VSUTILS_DBG_H
#ifdef HAVE_CONFIG_H
#include <config.h>
@@ -67,39 +67,49 @@
#include <sys/types.h>
/**
+ * \def DBG_ATTR_FILE
+ * \brief Current file and line seperated with a comma.
+ */
+#define DBG_ATTR_FILE __FILE__, __LINE__
+
+#if __STDC_VERSION__ >= 199901L /* C99 */
+/**
+ * \def DBG_ATTR_FUNC
+ * \brief Current file and line seperated with a comma.
+ */
+#define DBG_ATTR_FUNC __func__, __LINE__
+
+/**
* \def DBG_ATTR
* \brief Current file and line seperated with a comma.
*/
-#define DBG_ATTR __FILE__, __LINE__
+#define DBG_ATTR DBG_ATTR_FUNC
+#else
+/**
+ * \def DBG_ATTR
+ * \brief Current file and line seperated with a comma.
+ */
+#define DBG_ATTR DBG_ATTR_FILE
+#endif
/**
* \brief Print a debug message on stderr.
- * \param f filename
- * \param line line number
- * \param format format of the output (similary to printf param)
- * \param ... list of arguments
+ * \param f filename.
+ * \param line line number.
+ * \param format format of the output (similary to printf param).
+ * \param ... list of arguments.
* \author Sebastien Vincent
*/
void dbg_print(const char* f, int line, const char* format, ...);
/**
- * \brief Print nothing!
- * \param f filename
- * \param line line number
- * \param format format of the output (similary to printf param)
- * \param ... list of arguments
- * \author Sebastien Vincent
- */
-void dbg_print_null(const char* f, int line, const char* format, ...);
-
-/**
* \brief Print the content of a buffer in hexadecimal.
- * \param f filename
- * \param line line number
- * \param buf buffer to print
- * \param len size of the buffer
- * \param format format of the output (similary to printf param)
- * \param ... list of arguments
+ * \param f filename.
+ * \param line line number.
+ * \param buf buffer to print.
+ * \param len size of the buffer.
+ * \param format format of the output (similary to printf param).
+ * \param ... list of arguments.
* \author Sebastien Vincent
* \warning Remember to pass pointer when you cast an integer for buf param.
*/
@@ -139,8 +149,8 @@
/**
* \def pthread_mutex_lock
* \brief Print a debug message when pthread_mutex_lock function is used.
- * \param x thread id (pthread_t type)
- * \return 0 if success, a non nul value otherwise
+ * \param x thread id (pthread_t type).
+ * \return 0 if success, a non nul value otherwise.
*/
#define pthread_mutex_lock(x) \
do \
@@ -152,8 +162,8 @@
/**
* \def pthread_mutex_unlock
* \brief Print a debug message when pthread_mutex_unlock function is used.
- * \param x thread id (pthread_t type)
- * \return 0 if success, a non nul value otherwise
+ * \param x thread id (pthread_t type).
+ * \return 0 if success, a non nul value otherwise.
*/
#define pthread_mutex_unlock(x) \
do \
@@ -165,9 +175,9 @@
/**
* \def pthread_join
* \brief Print a debug message when pthread_join function is used.
- * \param x thread id (pthread_t type)
- * \param r return value of thread is stored in r (void** type)
- * \return 0 if success, a non nul value otherwise
+ * \param x thread id (pthread_t type).
+ * \param r return value of thread is stored in r (void** type).
+ * \return 0 if success, a non nul value otherwise.
*/
#define pthread_join(x, r) \
do \
@@ -180,7 +190,7 @@
/**
* \def pthread_exit
* \brief Print a debug message when pthread_exit function is used.
- * \param x thread id (pthread_t type)
+ * \param x thread id (pthread_t type).
*/
#define pthread_exit(x) \
do \
@@ -192,8 +202,8 @@
/**
* \def pthread_cancel
* \brief Print a debug message when pthread_exit function is used.
- * \param x thread id (pthread_t type)
- * \return 0 if success, a non nul value otherwise
+ * \param x thread id (pthread_t type).
+ * \return 0 if success, a non nul value otherwise.
*/
#define pthread_cancel(x) \
do \
@@ -207,5 +217,5 @@
}
#endif
-#endif /* DBG_H */
+#endif /* VSUTILS_DBG_H */
Modified: trunk/src/list.h
===================================================================
--- trunk/src/list.h 2013-06-14 16:27:09 UTC (rev 238)
+++ trunk/src/list.h 2013-09-03 16:26:29 UTC (rev 239)
@@ -1,6 +1,6 @@
/*
* TurnServer - TURN server implementation.
- * Copyright (C) 2008-2010 Sebastien Vincent <seb...@tu...>
+ * Copyright (C) 2008-2013 Sebastien Vincent <seb...@tu...>
*
* 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
@@ -30,7 +30,7 @@
*/
/*
- * Copyright (C) 2006-2010 Sebastien Vincent.
+ * Copyright (C) 2006-2013 Sebastien Vincent.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -49,20 +49,18 @@
* \file list.h
* \brief Doubly linked list management.
* \author Sebastien Vincent
- * \date 2006-2010
+ * \date 2006-2013
*/
-#ifndef LIST_H
-#define LIST_H
+#ifndef VSUTILS_LIST_H
+#define VSUTILS_LIST_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#if defined(_MSC_VER) && !defined(__cplusplus)
-/* Microsoft compiler does not know inline
- * keyword in a pure C program
- */
+/* Microsoft compiler does not know inline keyword in a pure C program */
#define inline __inline
#endif
@@ -73,130 +71,191 @@
* \brief Doubly linked list implementation.
*
* Simple doubly linked list implementation inspired by include/linux/list.h.
- * \note To use it: LIST_HEAD(name_variable) to declare the variable
- * then always do INIT_LIST(name_variable).
+ * \code
+ * struct element
+ * {
+ * int id;
+ * struct list_head list;
+ * }
+ *
+ * struct list_head list;
+ * struct list_head* tmp = NULL;
+ * struct list_head* pos = NULL;
+ * struct element* el = (struct element*)malloc(sizeof(struct element));
+ * struct element* el2 = (struct element*)malloc(sizeof(struct element));
+ * struct element* el3 = (struct element*)malloc(sizeof(struct element));
+ *
+ * if(!el || !el2 || !el3)
+ * {
+ * free(el);
+ * free(el2);
+ * free(el3);
+ * return;
+ * }
+ *
+ * el->id = 1;
+ * el2->id = 2;
+ * el3->id = 3;
+ *
+ * list_head_init(&list);
+ * list_head_add_tail(&list, &el->list);
+ * list_head_add_tail(&list, &el2->list);
+ * list_head_add_tail(&list, &el3->list);
+ *
+ * fprintf(stdout, "Size: %u\n", list_head_size(&list));
+ * list_head_iterate_safe(&list, pos, tmp)
+ * {
+ * struct element* e = list_head_get(pos, struct element, list);
+ * fprintf(stdout, "Id: %d\n", e->id);
+ * }
+ *
+ * list_head_remove(&list, &el->list);
+ * free(el);
+ * fprintf(stdout, "Size: %u\n", list_head_size(&list));
+ *
+ * list_head_iterate_safe(&list, pos, tmp)
+ * {
+ * struct element* e = list_head_get(pos, struct element, list);
+ * fprintf(stdout, "Id: %d\n", e->id);
+ * list_head_remove(&list, &e->list);
+ * free(e);
+ * }
+ * \endcode
+ * \note To use it simply: VSUTILS_LIST_HEAD(name_variable) to declare the variable.
*/
-typedef struct list_head
+struct list_head
{
- struct list_head *next; /**< Next element in the list */
- struct list_head *prev; /**< Previous element in the list */
-}list_head;
+ struct list_head *next; /**< Next element in the list. */
+ struct list_head *prev; /**< Previous element in the list. */
+};
/**
- * \def INIT_LIST
- * \brief Initialize a list.
- * \param name the list to initialize
+ * \def VSUTILS_LIST_HEAD
+ * \brief Static initializer for a list head.
+ * \param name the variable name to initialize.
*/
-#define INIT_LIST(name) do { \
- (name).prev = &(name); \
- (name).next = &(name); \
-}while(0);
+#define VSUTILS_LIST_HEAD(name) struct list_head name = {&name, &name}
/**
- * \def LIST_HEAD
- * \brief Used to declare a doubly linked list.
- * \param name name of list_head struct
+ * \def list_head_get
+ * \brief Get the element.
+ * \param item the list_head pointer item.
+ * \param type the type of the struct this is embedded in.
+ * \param member the name of the list_head struct within the struct.
+ * \return pointer on the structure for this entry.
*/
-#define LIST_HEAD(name) struct list_head name
+#define list_head_get(item, type, member) \
+ (type *)((char *)(item) - offsetof(type, member))
/**
- * \def LIST_ADD
- * \brief Add a new entry after the specified head.
- * \param new_entry new entry to be added
- * \param head list head to add it after
+ * \def list_head_iterate
+ * \brief Iterate over a list.
+ * \param list the list.
+ * \param pos a struct list_head pointer to use as a loop counter.
*/
-#define LIST_ADD(new_entry, head) do { \
- struct list_head* next = (head)->next; \
- next->prev = (new_entry); \
- (new_entry)->next = next; \
- (new_entry)->prev = (head); \
- (head)->next = (new_entry); \
-}while(0);
+#define list_head_iterate(list, pos) \
+ for((pos) = (list)->next ; (pos) != (list) ; (pos) = (pos)->next)
/**
- * \def LIST_ADD_TAIL
- * \brief Add a new entry before the specified head.
- * \param new_entry new entry to be added
- * \param head list head to add it before
+ * \def list_head_iterate_safe
+ * \brief Thread safe version to iterate over a list.
+ * \param list the list.
+ * \param pos a struct list_head pointer to use as loop counter.
+ * \param n temporary variable.
*/
-#define LIST_ADD_TAIL(new_entry, head) do { \
- struct list_head* prev = (head)->prev; \
- (head)->prev = (new_entry); \
- (new_entry)->next = (head); \
- (new_entry)->prev = prev; \
- prev->next = (new_entry); \
-}while(0);
+#define list_head_iterate_safe(list, pos, n) \
+ for((pos) = (list)->next, (n) = (pos)->next ; (pos) != (list) ; \
+ (pos) = (n), (n) = (pos)->next)
/**
- * \def LIST_DEL
- * \brief Delete entry from list.
- * \param rem pointer of the element to delete from the list
- * \note list_empty on entry does not return true after this, the entry is
- * in an undefined state.
+ * \brief Initialize list.
+ * \param list The list to initialize.
*/
-#define LIST_DEL(rem) do { \
- (rem)->next->prev = (rem)->prev; \
- (rem)->prev->next = (rem)->next; \
- (rem)->next = (rem); \
- (rem)->prev = (rem); \
-}while(0);
+static inline void list_head_init(struct list_head* list)
+{
+ list->prev = list;
+ list->next = list;
+}
/**
- * \def LIST_EMPTY
- * \brief Return whether or not the list is empty.
- * \param head pointer on the list to test
- * \return 1 if empty, 0 otherwise
+ * \brief Add a new entry after the specified list.
+ * \param list the list.
+ * \param item new entry to be added.
+ * \note in case several entries are added in the same list, they will
+ * be added in reverse order: 1, 2, 3 are added but iterate over the list will
+ * show 3, 2, 1.
*/
-#define LIST_EMPTY(head) \
- ((head)->next == (head))
+static inline void list_head_add(struct list_head* list,
+ struct list_head* item)
+{
+ struct list_head* next = list->next;
+ next->prev = item;
+ item->next = next;
+ item->prev = list;
+ list->next = item;
+}
/**
- * \def list_get
- * \brief Get the element.
- * \param ptr the list_head pointer
- * \param type the type of the struct this is embedded in
- * \param member the name of the list_struct within the struct
- * \return pointer on the structure for this entry
+ * \brief Add a new entry before the specified head.
+ * \param list the list.
+ * \param item new entry to be added.
+ * \note in case several entries are added in the same list, they will
+ * be added in same order: 1, 2, 3 are added and iterate over the list will
+ * show 1, 2, 3.
*/
-#define list_get(ptr, type, member) \
- (type *)((char *)(ptr) - offsetof(type, member))
+static inline void list_head_add_tail(struct list_head* list,
+ struct list_head* item)
+{
+ struct list_head* prev = list->prev;
+ list->prev = item;
+ item->next = list;
+ item->prev = prev;
+ prev->next = item;
+}
/**
- * \def list_iterate
- * \brief Iterate over a list.
- * \param pos the &struct list_head to use as a loop counter
- * \param head the head for your list
+ * \brief Remove entry from list.
+ * \param list the list.
+ * \param item pointer of the element to remove from the list.
+ * \note list_head_empty on item does not return true after this, the entry is
+ * in an undefined state.
*/
-#define list_iterate(pos, head) \
- for((pos) = (head)->next ; (pos) != (head) ; (pos) = (pos)->next)
+static inline void list_head_remove(struct list_head* list,
+ struct list_head* item)
+{
+ (void)list;
+ item->next->prev = item->prev;
+ item->prev->next = item->next;
+ item->next = item;
+ item->prev = item;
+}
/**
- * \def list_iterate_safe
- * \brief Thread safe version to iterate over a list.
- * \param pos pointer on a list_head struct
- * \param n temporary variable
- * \param head the list.
+ * \brief Return whether or not the list is empty.
+ * \param list the list.
+ * \return 1 if empty, 0 otherwise.
*/
-#define list_iterate_safe(pos, n, head) \
- for((pos) = (head)->next, (n) = (pos)->next ; (pos) != (head) ; \
- (pos) = (n), (n) = (pos)->next)
+static inline int list_head_is_empty(struct list_head* list)
+{
+ return list->next == list;
+}
/**
* \brief Get the number of element in the list.
- * \param head the list
+ * \param list the list
* \return size of the list
*/
-static inline unsigned int list_size(struct list_head* head)
+static inline unsigned int list_head_size(struct list_head* list)
{
struct list_head* lp = NULL;
unsigned int size = 0;
- list_iterate(lp, head)
+ list_head_iterate(list, lp)
{
size++;
}
return size;
}
-#endif /* LIST_H */
+#endif /* VSUTILS_LIST_H */
Modified: trunk/src/mod_tmpuser.c
===================================================================
--- trunk/src/mod_tmpuser.c 2013-06-14 16:27:09 UTC (rev 238)
+++ trunk/src/mod_tmpuser.c 2013-09-03 16:26:29 UTC (rev 239)
@@ -137,10 +137,10 @@
int tmpuser_init(struct list_head* account_list)
{
- INIT_LIST(g_tmpuser.client_list);
+ list_head_init(&g_tmpuser.client_list);
g_tmpuser.account_list = NULL;
- g_tmpuser.sock = socket_create(TCP, "localhost", 8086, 0, 1);
+ g_tmpuser.sock = net_socket_create(TCP, "localhost", 8086, 0, 1);
if(g_tmpuser.sock == -1)
{
@@ -172,13 +172,13 @@
void tmpuser_add_tcp_client(struct socket_desc* desc)
{
struct list_head* l = (struct list_head*)&desc->list;
- LIST_ADD(l, &g_tmpuser.client_list);
+ list_head_add(l, &g_tmpuser.client_list);
}
void tmpuser_remove_tcp_client(struct socket_desc* desc)
{
struct list_head* l = (struct list_head*)&desc->list;
- LIST_DEL(l);
+ list_head_remove(l, l);
}
int tmpuser_process_msg(const char* buf, ssize_t len)
@@ -290,9 +290,9 @@
close(g_tmpuser.sock);
}
- list_iterate_safe(get, n, &g_tmpuser.client_list)
+ list_head_iterate_safe(&g_tmpuser.client_list, get, n)
{
- struct socket_desc* tmp = list_get(get, struct socket_desc, list);
+ struct socket_desc* tmp = list_head_get(get, struct socket_desc, list);
if(tmp->sock)
{
@@ -308,6 +308,6 @@
*/
g_tmpuser.account_list = NULL;
- INIT_LIST(g_tmpuser.client_list);
+ list_head_init(&g_tmpuser.client_list);
}
Modified: trunk/src/protocol.c
===================================================================
--- trunk/src/protocol.c 2013-06-14 16:27:09 UTC (rev 238)
+++ trunk/src/protocol.c 2013-09-03 16:26:29 UTC (rev 239)
@@ -48,6 +48,7 @@
#include <openssl/hmac.h>
#include "util_sys.h"
+#include "util_net.h"
#include "util_crypto.h"
#include "protocol.h"
@@ -520,7 +521,7 @@
ret->turn_attr_type = htons(STUN_ATTR_ERROR_CODE);
ret->turn_attr_len = htons(4 + real_len);
- if(is_little_endian())
+ if(sys_is_little_endian())
{
ret->turn_attr_reserved_class = class << 16;
}
@@ -945,7 +946,7 @@
/* error-code */
if(!(attr = turn_attr_error_create(400, STUN_ERROR_400, sizeof(STUN_ERROR_400), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -972,7 +973,7 @@
if(!(attr = turn_attr_error_create(401, STUN_ERROR_401,
sizeof(STUN_ERROR_401), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -981,7 +982,7 @@
/* realm */
if(!(attr = turn_attr_realm_create(realm, strlen(realm), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -990,7 +991,7 @@
/* nonce */
if(!(attr = turn_attr_nonce_create(nonce, nonce_len, &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -1017,7 +1018,7 @@
if(!(attr = turn_attr_error_create(420, STUN_ERROR_420,
sizeof(STUN_ERROR_420), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -1052,7 +1053,7 @@
if(!(attr = turn_attr_error_create(438, STUN_ERROR_438,
sizeof(STUN_ERROR_438), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -1061,7 +1062,7 @@
/* realm */
if(!(attr = turn_attr_realm_create(realm, strlen(realm), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -1070,7 +1071,7 @@
/* nonce */
if(!(attr = turn_attr_nonce_create(nonce, nonce_len, &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -1096,7 +1097,7 @@
if(!(attr = turn_attr_error_create(500, STUN_ERROR_500,
sizeof(STUN_ERROR_500), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -1122,7 +1123,7 @@
if(!(attr = turn_attr_error_create(403, TURN_ERROR_403,
sizeof(TURN_ERROR_403), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -1148,7 +1149,7 @@
if(!(attr = turn_attr_error_create(437, TURN_ERROR_437,
sizeof(TURN_ERROR_437), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -1174,7 +1175,7 @@
if(!(attr = turn_attr_error_create(440, TURN_ERROR_440,
sizeof(TURN_ERROR_440), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -1200,7 +1201,7 @@
if(!(attr = turn_attr_error_create(441, TURN_ERROR_441,
sizeof(TURN_ERROR_441), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -1226,7 +1227,7 @@
if(!(attr = turn_attr_error_create(442, TURN_ERROR_442,
sizeof(TURN_ERROR_442), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -1252,7 +1253,7 @@
if(!(attr = turn_attr_error_create(443, TURN_ERROR_443,
sizeof(TURN_ERROR_443), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -1278,7 +1279,7 @@
if(!(attr = turn_attr_error_create(446, TURN_ERROR_446,
sizeof(TURN_ERROR_446), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -1304,7 +1305,7 @@
if(!(attr = turn_attr_error_create(447, TURN_ERROR_447,
sizeof(TURN_ERROR_447), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -1330,7 +1331,7 @@
if(!(attr = turn_attr_error_create(486, TURN_ERROR_486,
sizeof(TURN_ERROR_486), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -1356,7 +1357,7 @@
if(!(attr = turn_attr_error_create(508, TURN_ERROR_508,
sizeof(TURN_ERROR_508), &iov[*idx])))
{
- iovec_free_data(iov, *idx);
+ net_iovec_free_data(iov, *idx);
return NULL;
}
error->turn_msg_len += iov[*idx].iov_len;
@@ -1456,7 +1457,7 @@
int turn_generate_transaction_id(uint8_t* id)
{
/* 96 bit transaction ID */
- return random_bytes_generate(id, 12);
+ return crypto_random_bytes_generate(id, 12);
}
int turn_calculate_authentication_key(const char* username, const char* realm,
@@ -1541,7 +1542,7 @@
t += TURN_DEFAULT_NONCE_LIFETIME;
t = (time_t)htonl((uint32_t)t);
- hex_convert((unsigned char*)&t, sizeof(time_t), nonce, sizeof(time_t) * 2);
+ sys_convert_to_hex((unsigned char*)&t, sizeof(time_t), nonce, sizeof(time_t) * 2);
if(sizeof(time_t) == 4) /* 32 bit */
{
@@ -1554,7 +1555,7 @@
MD5_Final(md_buf, &ctx);
/* add MD5 at the end of the nonce */
- hex_convert(md_buf, MD5_DIGEST_LENGTH, nonce + 16, len - 16);
+ sys_convert_to_hex(md_buf, MD5_DIGEST_LENGTH, nonce + 16, len - 16);
return 0;
}
@@ -1577,12 +1578,12 @@
if(sizeof(time_t) == 4) /* 32 bits */
{
- uint32_convert(nonce, sizeof(time_t) * 2, &ct);
+ sys_convert_to_uint32(nonce, sizeof(time_t) * 2, &ct);
memcpy(&t, &ct, 4);
}
else
{
- uint64_convert(nonce, sizeof(time_t) * 2, &ct64);
+ sys_convert_to_uint64(nonce, sizeof(time_t) * 2, &ct64);
memcpy(&t, &ct64, 8);
}
@@ -1592,7 +1593,7 @@
MD5_Update(&ctx, key, key_len);
MD5_Final(md_buf, &ctx);
- hex_convert(md_buf, MD5_DIGEST_LENGTH, md_txt, sizeof(md_txt));
+ sys_convert_to_hex(md_buf, MD5_DIGEST_LENGTH, md_txt, sizeof(md_txt));
if(memcmp(md_txt, nonce + 16, (MD5_DIGEST_LENGTH * 2)) != 0)
{
@@ -1616,7 +1617,7 @@
for(i = 0 ; i < iovlen ; i++)
{
- crc = crc32_generate(iov[i].iov_base, iov[i].iov_len, crc);
+ crc = crypto_crc32_generate(iov[i].iov_base, iov[i].iov_len, crc);
}
return crc;
Modified: trunk/src/test_echo_server.c
===================================================================
--- trunk/src/test_echo_server.c 2013-06-14 16:27:09 UTC (rev 238)
+++ trunk/src/test_echo_server.c 2013-09-03 16:26:29 UTC (rev 239)
@@ -45,6 +45,7 @@
#include <sys/socket.h>
#include <sys/select.h>
+#include "util_net.h"
#include "tls_peer.h"
/**
@@ -107,13 +108,13 @@
}
/* try to bind on all addresses (IPv6+IPv4 mode) */
- sock = socket_create(IPPROTO_UDP, "::", port, 0, 0);
+ sock = net_socket_create(IPPROTO_UDP, "::", port, 0, 0);
if(sock == -1)
{
perror("socket");
fprintf(stderr, "Maybe IPv6 is not available, try IPv4 only mode\n");
- sock = socket_create(IPPROTO_UDP, "0.0.0.0", port, 0, 1);
+ sock = net_socket_create(IPPROTO_UDP, "0.0.0.0", port, 0, 1);
}
if(sock == -1)
Modified: trunk/src/test_turn_client.c
===================================================================
--- trunk/src/test_turn_client.c 2013-06-14 16:27:09 UTC (rev 238)
+++ trunk/src/test_turn_client.c 2013-09-03 16:26:29 UTC (rev 239)
@@ -81,6 +81,7 @@
#include "util_sys.h"
#include "util_crypto.h"
+#include "util_net.h"
#include "protocol.h"
#include "tls_peer.h"
@@ -332,7 +333,7 @@
}
else if(sock)
{
- *sock = socket_create(transport_protocol, addr, port, 0, 1);
+ *sock = net_socket_create(transport_protocol, addr, port, 0, 1);
return (*sock != -1) ? 0 : -1;
}
@@ -481,7 +482,7 @@
/* MESSAGE-INTEGRITY option has to be in message, so
* deallocate ressources and return
*/
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
}
@@ -493,11 +494,11 @@
{
fprintf(stderr, "Send failed!\n");
perror("send");
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
nb = client_recv_message(transport_protocol, sock, speer, buf, sizeof(buf));
@@ -591,7 +592,7 @@
/* MESSAGE-INTEGRITY option has to be in message, so
* deallocate ressources and return
*/
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
@@ -601,11 +602,11 @@
{
fprintf(stderr, "Send failed!\n");
perror("send");
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
nb = client_recv_message(transport_protocol, sock, speer, buf, sizeof(buf));
@@ -692,7 +693,7 @@
/* MESSAGE-INTEGRITY option has to be in message, so
* deallocate ressources and return
*/
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
@@ -702,11 +703,11 @@
{
fprintf(stderr, "Send failed!\n");
perror("send");
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
nb = client_recv_message(transport_protocol, sock, speer, buf, sizeof(buf));
@@ -801,7 +802,7 @@
/* MESSAGE-INTEGRITY option has to be in message, so
* deallocate ressources and return
*/
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
@@ -811,11 +812,11 @@
{
fprintf(stderr, "Send failed!\n");
perror("send");
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
nb = client_recv_message(transport_protocol, sock, speer, buf, sizeof(buf));
@@ -914,7 +915,7 @@
/* MESSAGE-INTEGRITY option has to be in message, so
* deallocate ressources and return
*/
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
@@ -924,11 +925,11 @@
{
fprintf(stderr, "Send failed!\n");
perror("send");
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
nb = client_recv_message(transport_protocol, sock, speer, buf, sizeof(buf));
@@ -985,7 +986,7 @@
{
fprintf(stderr, "Send failed!\n");
perror("send");
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
@@ -1070,7 +1071,7 @@
/* MESSAGE-INTEGRITY option has to be in message, so
* deallocate ressources and return
*/
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
@@ -1080,11 +1081,11 @@
{
fprintf(stderr, "Send failed!\n");
perror("send");
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
index = 0;
nb = client_recv_message(transport_protocol, sock, speer, buf, sizeof(buf));
@@ -1159,7 +1160,7 @@
/* MESSAGE-INTEGRITY option has to be in message, so
* deallocate ressources and return
*/
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
@@ -1169,10 +1170,10 @@
{
fprintf(stderr, "Send failed!\n");
perror("send");
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
nb = client_recv_message(transport_protocol, *sock_tcp, NULL, buf, sizeof(buf));
@@ -1229,8 +1230,8 @@
tv.tv_sec = 10; /* 10 seconds before timeout */
tv.tv_usec = 0;
- SFD_ZERO(&fdsr);
- SFD_SET(sock, &fdsr);
+ NET_SFD_ZERO(&fdsr);
+ NET_SFD_SET(sock, &fdsr);
nsock = sock + 1;
@@ -1317,7 +1318,7 @@
/* MESSAGE-INTEGRITY option has to be in message, so
* deallocate ressources and return
*/
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
@@ -1327,11 +1328,11 @@
{
fprintf(stderr, "Send failed!\n");
perror("send");
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return -1;
}
- iovec_free_data(iov, index);
+ net_iovec_free_data(iov, index);
return 0;
}
@@ -1561,8 +1562,9 @@
exit(EXIT_FAILURE);
}
- snprintf((char*)userdomainpass, userdomainpass_len, "%s:%s:%s", user, domain, password);
- md5_generate(md_buf, userdomainpass, userdomainpass_len - 1);
+ snprintf((char*)userdomainpass, userdomainpass_len, "%s:%s:%s", user, domain,
+ password);
+ crypto_md5_generate(md_buf, userdomainpass, userdomainpass_len - 1);
/* client connected and can send TURN message */
fprintf(stdout, "sock: %d speer: %p connected!\n", sock, (void*)speer);
Modified: trunk/src/tls_peer.c
===================================================================
--- trunk/src/tls_peer.c 2013-06-14 16:27:09 UTC (rev 238)
+++ trunk/src/tls_peer.c 2013-09-03 16:26:29 UTC (rev 239)
@@ -1,6 +1,6 @@
/*
* TurnServer - TURN server implementation.
- * Copyright (C) 2008-2011 Sebastien Vincent <seb...@tu...>
+ * Copyright (C) 2008-2013 Sebastien Vincent <seb...@tu...>
*
* 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
@@ -30,7 +30,7 @@
*/
/*
- * Copyright (C) 2008-2011 Sebastien Vincent.
+ * Copyright (C) 2008-2013 Sebastien Vincent.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -52,7 +52,7 @@
* \file tls_peer.c
* \brief TLS and DTLS peer implementation.
* \author Sebastien Vincent
- * \date 2008-2011
+ * \date 2008-2013
*/
#ifdef HAVE_CONFIG_H
@@ -73,11 +73,6 @@
#include <arpa/inet.h>
#include <netdb.h>
-#elif defined(_MSC_VER)
-/* Microsoft compiler does not want users
- * to use snprintf directly...
- */
-#define snprintf _snprintf
#endif
#include <openssl/evp.h>
@@ -86,20 +81,9 @@
#include <openssl/pkcs7.h>
#include <openssl/x509v3.h>
+#include "util_net.h"
#include "tls_peer.h"
-/* macro should be declared in netinet/in.h even in POSIX compilation
- * but it appeared that it is not defined on some BSD system
- */
-#ifndef IPPROTO_IPV6
-#define IPPROTO_IPV6 41
-#endif
-
-/* MinGW does not define IPV6_V6ONLY */
-#ifndef IPV6_V6ONLY
-#define IPV6_V6ONLY 27
-#endif
-
#ifdef __cplusplus
extern "C"
{ /* } */
@@ -115,15 +99,15 @@
*/
struct ssl_peer
{
- SSL* ssl; /**< The remote peer */
- int handshake_complete; /**< State of the handshake */
- struct sockaddr_storage addr; /**< Socket address */
- struct list_head list; /**< For list management */
+ SSL* ssl; /**< The remote peer. */
+ int handshake_complete; /**< State of the handshake. */
+ struct sockaddr_storage addr; /**< Socket address. */
+ struct list_head list; /**< For list management. */
};
/**
* \brief Free a SSL peer.
- * \param peer the SSL peer
+ * \param peer the SSL peer.
*/
static void ssl_peer_free(struct ssl_peer** peer)
{
@@ -138,10 +122,10 @@
/**
* \brief Create a new SSL peer.
- * \param addr socket address
- * \param addrlen sizeof address
+ * \param addr socket address.
+ * \param addrlen sizeof address.
* \param ssl SSL instance
- * \return valid pointer on ssl_peer, NULL if failure
+ * \return valid pointer on ssl_peer, NULL if failure.
*/
static struct ssl_peer* ssl_peer_new(struct sockaddr* addr, socklen_t addrlen,
SSL* ssl)
@@ -163,10 +147,10 @@
/**
* \brief Find the specified ssl_peer that match address.
- * \param peer (D)TLS peer instance
- * \param addr socket address client to find
- * \param addrlen sizeof addr
- * \return a valid ssl_peer pointer or NULL if not found
+ * \param peer (D)TLS peer instance.
+ * \param addr socket address client to find.
+ * \param addrlen sizeof addr.
+ * \return a valid ssl_peer pointer or NULL if not found.
*/
static struct ssl_peer* tls_peer_find_connection(struct tls_peer* peer,
const struct sockaddr* addr, socklen_t addrlen)
@@ -174,11 +158,11 @@
struct list_head* n = NULL;
struct list_head* get = NULL;
- list_iterate_safe(get, n, &peer->remote_peers)
+ list_head_iterate_safe(&peer->remote_peers, get, n)
{
struct ssl_peer* tmp = NULL;
- tmp = list_get(get, struct ssl_peer, list);
+ tmp = list_head_get(get, struct ssl_peer, list);
if(!memcmp(&tmp->addr, addr, addrlen))
{
return tmp;
@@ -189,13 +173,13 @@
/**
* \brief Add a ssl_peer.
- * \param peer (D)TLS peer
- * \param speer ssl_peer client
+ * \param peer (D)TLS peer.
+ * \param speer ssl_peer client.
*/
static void tls_peer_add_connection(struct tls_peer* peer,
struct ssl_peer* speer)
{
- LIST_ADD_TAIL(&speer->list, &peer->remote_peers);
+ list_head_add_tail(&peer->remote_peers, &speer->list);
}
/**
@@ -206,26 +190,23 @@
static void tls_peer_remove_connection(struct tls_peer* peer,
struct ssl_peer* ssl)
{
- /* to avoid compilation warnings */
- (void)peer;
-
- LIST_DEL(&ssl->list);
+ list_head_remove(&peer->remote_peers, &ssl->list);
ssl_peer_free(&ssl);
}
/**
* \brief Remove (and free) all connections from the peer.
- * \param peer (D)TLS peer
+ * \param peer (D)TLS peer.
*/
static void tls_peer_clear_connection(struct tls_peer* peer)
{
struct list_head* n = NULL;
struct list_head* get = NULL;
- list_iterate_safe(get, n, &peer->remote_peers)
+ list_head_iterate_safe(&peer->remote_peers, get, n)
{
struct ssl_peer* tmp = NULL;
- tmp = list_get(get, struct ssl_peer, list);
+ tmp = list_head_get(get, struct ssl_peer, list);
tls_peer_remove_connection(peer, tmp);
return;
}
@@ -233,9 +214,9 @@
/**
* \brief Manage (D)TLS peer according to the error.
- * \param peer (D)TLS peer
- * \param ssl SSL peer concerned
- * \param err the error number
+ * \param peer (D)TLS peer.
+ * \param ssl SSL peer concerned.
+ * \param err the error number.
*/
static void tls_peer_manage_error(struct tls_peer* peer, struct ssl_peer* ssl,
int err)
@@ -245,7 +226,7 @@
case SSL_ERROR_NONE:
break;
case SSL_ERROR_SSL:
- fprintf(stderr, "SSL_ERROR_SSL: %s\n",
+ fprintf(stderr, "SSL_ERROR_SSL: %s\n",
ERR_reason_error_string(ERR_get_error()));
/* big problem, remove the connection */
tls_peer_remove_connection(peer, ssl);
@@ -279,15 +260,15 @@
/**
* \brief Load the certificates material in a context.
- * \param ctx the context
- * \param ca_file Certification Authority file
- * \param cert_file certificate file
- * \param key_file private key file
- * \param verify_callback certificate verification callback
- * \return 0 if success, -1 otherwise
+ * \param ctx the context.
+ * \param ca_file Certification Authority file.
+ * \param cert_file certificate file.
+ * \param key_file private key file.
+ * \param verify_callback certificate verification callback.
+ * \return 0 if success, -1 otherwise.
*/
static int tls_peer_load_certificates(SSL_CTX* ctx, const char* ca_file,
- const char* cert_file, const char* key_file,
+ const char* cert_file, const char* key_file,
int (*verify_callback)(int, X509_STORE_CTX *))
{
if(SSL_CTX_set_cipher_list(ctx, "DEFAULT") != 1)
@@ -320,16 +301,16 @@
/**
* \brief Setup a (D)TLS peer.
- * \param peer tls_peer instance to setup
- * \param type UDP or TCP
- * \param addr Network address
- * \param port port
- * \param ca_file certification authorities file
- * \param cert_file certificate file
- * \param key_file private key file
- * \return 0 if success, -1 otherwise
+ * \param peer tls_peer instance to setup.
+ * \param type UDP or TCP.
+ * \param addr Network address.
+ * \param port port.
+ * \param ca_file certification authorities file.
+ * \param cert_file certificate file.
+ * \param key_file private key file.
+ * \return 0 if success, -1 otherwise.
* \note If returns -1, the caller must call tls_peer_free() as some memory
- * could be allocated
+ * could be allocated.
*/
static int tls_peer_setup(struct tls_peer* peer, enum protocol_type type,
const char* addr, uint16_t port, const char* ca_file, const char* cert_file,
@@ -340,7 +321,7 @@
SSL_METHOD* method_client = NULL;
/* initialize list */
- INIT_LIST(peer->remote_peers);
+ list_head_init(&peer->remote_peers);
if(type == UDP)
{
@@ -393,7 +374,7 @@
SSL_CTX_set_client_CA_list(peer->ctx_server, calist);
}
- peer->sock = socket_create(type, addr, port, 0, 0);
+ peer->sock = net_socket_create(type, addr, port, 0, 0);
peer->type = type;
return (peer->sock > 0) ? 0 : -1;
@@ -401,13 +382,13 @@
/**
* \brief Read a (D)TLS message.
- * \param peer (D)TLS peer
- * \param buf in buffer
- * \param buflen in buffer length
- * \param bufout out buffer
- * \param bufoutlen out buffer length
- * \param speer SSL peer
- * \return number of bytes read or -1 if error or handshake not finalized
+ * \param peer (D)TLS peer.
+ * \param buf in buffer.
+ * \param buflen in buffer length.
+ * \param bufout out buffer.
+ * \param bufoutlen out buffer length.
+ * \param speer SSL peer.
+ * \return number of bytes read or -1 if error or handshake not finalized.
*/
static ssize_t tls_peer_read(struct tls_peer* peer, char* buf, ssize_t buflen,
char* bufout, ssize_t bufoutlen, struct ssl_peer* speer)
@@ -444,13 +425,13 @@
/**
* \brief Verify certificate chain.
- * \param ssl SSL pointer
- * \return 1 if certificate verification is OK, 0 otherwise
+ * \param ssl SSL pointer.
+ * \return 1 if certificate verification is OK, 0 otherwise.
*/
static int verify_certificate(SSL* ssl)
{
X509* x509 = SSL_get_peer_certificate(ssl);
-
+
if(x509)
{
if(SSL_get_verify_result(ssl) != X509_V_OK)
@@ -461,7 +442,7 @@
return 1;
}
-
+
return 1;
}
@@ -471,12 +452,12 @@
struct list_head* get = NULL;
char buf[INET6_ADDRSTRLEN];
- fprintf(stdout, "Current peer information (List size = %u)\n",
- list_size(&peer->remote_peers));
+ fprintf(stdout, "Current peer informations (List size = %u)\n",
+ list_head_size(&peer->remote_peers));
- list_iterate_safe(get, n, &peer->remote_peers)
+ list_head_iterate_safe(&peer->remote_peers, get, n)
{
- struct ssl_peer* tmp = list_get(get, struct ssl_peer, list);
+ struct ssl_peer* tmp = list_head_get(get, struct ssl_peer, list);
if(getnameinfo((struct sockaddr*)&tmp->addr, sizeof(tmp->addr), buf,
INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST) != 0)
@@ -515,8 +496,8 @@
FD_ZERO(&fdsr);
FD_SET(peer->sock, &fdsr);
- /* 4 seconds of timeout */
- tv.tv_sec = 4;
+ /* 5 seconds of timeout */
+ tv.tv_sec = 5;
tv.tv_usec = 0;
nsock = peer->sock;
@@ -692,7 +673,7 @@
SSL* ssl = SSL_new(peer->ctx_client);
SSL_set_connect_state(ssl);
-
+
if(!verify_certificate(ssl))
{
SSL_free(ssl);
@@ -778,70 +759,6 @@
return 0;
}
-int socket_create(enum protocol_type type, const char* addr, uint16_t port,
- int reuse, int nodelay)
-{
- int sock = -1;
- struct addrinfo hints;
- struct addrinfo* res = NULL;
- struct addrinfo* p = NULL;
- char service[8];
-
- snprintf(service, sizeof(service), "%u", port);
- service[sizeof(service)-1] = 0x00;
-
- memset(&hints, 0, sizeof(struct addrinfo));
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = (type == TCP ? SOCK_STREAM : SOCK_DGRAM);
- hints.ai_protocol = (type == TCP ? IPPROTO_TCP : IPPROTO_UDP);
- hints.ai_flags = AI_PASSIVE;
-
- if(getaddrinfo(addr, service, &hints, &res) != 0)
- {
- return -1;
- }
-
- for(p = res ; p ; p = p->ai_next)
- {
- int on = 1;
-
- sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
- if(sock == -1)
- {
- continue;
- }
-
- if(reuse)
- {
- setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(int));
- }
-
- if (type == TCP && nodelay)
- {
- setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(int));
- }
-
- /* accept IPv6 and IPv4 on the same socket */
- on = 0;
- setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(int));
-
- if(bind(sock, p->ai_addr, p->ai_addrlen) == -1)
- {
- close(sock);
- sock = -1;
- continue;
- }
-
- /* socket bound, break the loop */
- break;
- }
-
- freeaddrinfo(res);
- p = NULL;
-
- return sock;
-}
-
void tls_peer_free(struct tls_peer** peer)
{
struct tls_peer* ret = *peer;
Modified: trunk/src/tls_peer.h
===================================================================
--- trunk/src/tls_peer.h 2013-06-14 16:27:09 UTC (rev 238)
+++ trunk/src/tls_peer.h 2013-09-03 16:26:29 UTC (rev 239)
@@ -1,6 +1,6 @@
/*
* TurnServer - TURN server implementation.
- * Copyright (C) 2008-2011 Sebastien Vincent <seb...@tu...>
+ * Copyright (C) 2008-2013 Sebastien Vincent <seb...@tu...>
*
* This program is free software: you can redistribute it...
[truncated message content] |