Commit ab1c212d authored by Youness Alaoui's avatar Youness Alaoui

Remove useless files

parent fc9cbd90
......@@ -35,48 +35,7 @@ AM_CFLAGS = \
-I $(top_srcdir)/socket \
-I $(top_srcdir)/stun
EXTRA_PROGRAMS = \
ice-test-client \
ice-test-server \
jingle-test-server
COMMON_LDADD = libnice.la $(GLIB_LIBS)
ice_test_client_SOURCES = \
ice-test-client.c \
readline.h \
readline.c \
util.h \
util.c
ice_test_client_LDADD = $(top_builddir)/stun/libstun.la $(COMMON_LDADD)
ice_test_server_SOURCES = \
ice-test-server.c \
readline.h \
readline.c \
util.h \
util.c
ice_test_server_LDADD = $(COMMON_LDADD)
jingle_test_server_LDADD = $(COMMON_LDADD)
check_PROGRAMS = \
test-readline
# XXX: test programs disabled due to changes in API
EXTRA_PROGRAMS += \
test-util
test_readline_SOURCES = test-readline.c readline.h readline.c
test_readline_LDADD = $(COMMON_LDADD)
test_util_SOURCES = test-util.c util.h util.c
test_util_LDADD = $(COMMON_LDADD)
test-symbols.sh::
chmod +x $(srcdir)/$@
......@@ -89,7 +48,7 @@ CLEANFILES += libnice.symbols
check_SCRIPTS = test-symbols.sh
check_DATA = libnice.symbols
TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
TESTS = $(check_SCRIPTS)
EXTRA_DIST = $(check_SCRIPTS) libnice.sym
......
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2006, 2007 Collabora Ltd.
* Contact: Dafydd Harries
* (C) 2006, 2007 Nokia Corporation. All rights reserved.
* Contact: Kai Vehmanen
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Dafydd Harries, Collabora Ltd.
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <glib/gprintf.h>
#include "nice.h"
#include "readline.h"
#include "util.h"
#include "stun.h"
static void
send_stun (NiceUDPSocket *udpsock, NiceAddress addr, gchar *username)
{
gchar *packed;
guint packed_len;
gchar buf[1024];
StunMessage *msg;
msg = stun_message_new (STUN_MESSAGE_BINDING_REQUEST, NULL, 1);
msg->attributes[0] = stun_attribute_username_new (username);
{
gchar *dump;
dump = stun_message_dump (msg);
g_debug ("sending message:\n%s", dump);
g_free (dump);
}
packed_len = stun_message_pack (msg, &packed);
nice_udp_socket_send (udpsock, &addr, packed_len, packed);
g_free (packed);
stun_message_free (msg);
packed_len = nice_udp_socket_recv (udpsock, &addr, 1024, buf);
g_assert (packed_len > 0);
msg = stun_message_unpack (packed_len, buf);
g_assert (msg);
{
gchar *dump;
dump = stun_message_dump (msg);
g_debug ("got response:\n%s", dump);
g_free (dump);
}
stun_message_free (msg);
}
static void
handle_connection (guint sock)
{
gchar *line;
NiceUDPSocketFactory man;
NiceUDPSocket udpsock;
NiceCandidate *candidate;
// recieve and parse remote candidate
line = readline (sock);
if (line == NULL)
return;
candidate = nice_candidate_from_string (line);
if (candidate == NULL)
return;
g_debug ("got candidate: %s", line);
g_free (line);
// create local UDP port
nice_udp_bsd_socket_factory_init (&man);
if (!nice_udp_socket_factory_make (&man, &udpsock, NULL))
goto OUT;
// send local candidate
line = g_strdup_printf ("H/127.0.0.1/%d/lala/titi\n",
ntohs (udpsock.addr.port));
if (write (sock, line, strlen (line)) != (gint) strlen (line))
g_assert_not_reached ();
g_free (line);
// agent doesn't initiate connectivity checks, so make our own for now
{
gchar *username;
username = g_strdup_printf ("%slala", candidate->username);
send_stun (&udpsock, candidate->addr, username);
g_free (username);
}
nice_udp_socket_send (&udpsock, &candidate->addr, 6, "\x80hello");
nice_udp_socket_close (&udpsock);
OUT:
nice_udp_socket_factory_close (&man);
nice_candidate_free (candidate);
}
int
main (gint argc, gchar *argv[])
{
struct sockaddr_in sin;
gint sock;
memset (&sin, 0, sizeof (sin));
sock = socket (AF_INET, SOCK_STREAM, 0);
if (argc != 2)
{
g_print ("usage: %s server\n", argv[0]);
return 1;
}
if (sock < 0)
{
g_print ("failed to create socket\n");
return 1;
}
if (inet_pton (AF_INET, argv[1], &sin.sin_addr) < 1)
{
g_print ("invalid address\n");
return 1;
}
sin.sin_family = AF_INET;
sin.sin_port = htons (7899);
if (connect (sock, (struct sockaddr *) &sin, sizeof (sin)) != 0)
{
g_print ("failed to connect\n");
return 1;
}
handle_connection (sock);
close (sock);
return 0;
}
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2006, 2007 Collabora Ltd.
* Contact: Dafydd Harries
* (C) 2006, 2007 Nokia Corporation. All rights reserved.
* Contact: Kai Vehmanen
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Dafydd Harries, Collabora Ltd.
* Kai Vehmanen, Nokia
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <string.h>
#include <arpa/inet.h>
#include <errno.h>
#include <unistd.h>
#include "nice.h"
#include "readline.h"
#include "util.h"
static void
handle_recv (
NiceAgent *agent,
guint stream_id,
guint component_id,
guint len,
gchar *buf, gpointer user_data)
{
g_debug ("got media");
(void)agent; (void)stream_id; (void)component_id; (void)len; (void)buf;
(void)user_data;
}
/* create an agent and give it one fixed local IP address */
static gboolean
make_agent (
gchar *ip,
NiceUDPSocketFactory *factory,
NiceAgent **ret_agent,
NiceUDPSocket **ret_sock)
{
NiceAgent *agent;
NiceAddress addr_local;
NiceCandidate *candidate;
GSList *candidates;
agent = nice_agent_new (factory);
if (!nice_address_set_from_string (&addr_local, ip))
g_assert_not_reached ();
nice_agent_add_local_address (agent, &addr_local);
nice_agent_add_stream (agent, 1);
candidates = nice_agent_get_local_candidates (agent, 1, 1);
g_assert (candidates != NULL);
candidate = candidates->data;
g_debug ("allocated socket %d port %d for candidate %s",
candidate->sockptr->fileno, candidate->sockptr->addr.port, candidate->foundation);
g_slist_free (candidates);
*ret_agent = agent;
*ret_sock = candidate->sockptr;
return TRUE;
}
static gboolean
handle_tcp_read (guint fileno, NiceAgent *agent)
{
NiceCandidate *candidate;
gchar *line;
line = readline (fileno);
if (line == NULL)
/* EOF */
return FALSE;
candidate = nice_candidate_from_string (line);
if (candidate == NULL)
/* invalid candidate string */
return FALSE;
g_debug ("got remote candidate: %s", line);
nice_agent_add_remote_candidate (agent, 1, 1, candidate->type,
&candidate->addr, candidate->username, candidate->password);
nice_candidate_free (candidate);
g_free (line);
return TRUE;
}
static void
handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data)
{
NiceAgent *agent;
NiceUDPSocketFactory factory;
NiceUDPSocket *sock;
gchar ip_str[INET_ADDRSTRLEN];
gchar *candidate_str;
GSList *in_fds = NULL;
inet_ntop (AF_INET, &(sin->sin_addr), ip_str, INET_ADDRSTRLEN);
g_debug ("got connection from %s:%d", ip_str, ntohs (sin->sin_port));
nice_udp_bsd_socket_factory_init (&factory);
if (!make_agent ((gchar *) data, &factory, &agent, &sock))
return;
{
GSList *candidates;
/* send first local candidate to remote end */
candidates = nice_agent_get_local_candidates (agent, 1, 1);
candidate_str = nice_candidate_to_string (candidates->data);
send (fileno, candidate_str, strlen (candidate_str), 0);
send (fileno, "\n", 1, 0);
g_free (candidate_str);
g_slist_free (candidates);
}
/* event loop */
in_fds = g_slist_append (in_fds, GUINT_TO_POINTER (fileno));
for (;;)
{
GSList *out_fds;
GSList *i;
out_fds = nice_agent_poll_read (agent, in_fds, handle_recv, NULL);
for (i = out_fds; i; i = i->next)
if (GPOINTER_TO_UINT (i->data) == fileno)
{
/* TCP data */
g_debug ("got TCP data");
if (!handle_tcp_read (fileno, agent))
goto END;
}
g_slist_free (out_fds);
}
END:
g_debug ("-- connection closed --");
g_slist_free (in_fds);
nice_udp_socket_factory_close (&factory);
g_object_unref (agent);
}
static gboolean
tcp_listen_loop (
guint port,
void (*handler) (guint sock, const struct sockaddr_in *sin, gpointer data),
gpointer data)
{
gint sock;
struct sockaddr_in sin;
sock = socket (AF_INET, SOCK_STREAM, 0);
if (sock < 0)
{
g_print ("socket() failed: %s\n", g_strerror (errno));
return FALSE;
}
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons (port);
if (bind (sock, (struct sockaddr *) &sin, sizeof (sin)) < 0)
{
g_print ("bind() failed: %s\n", g_strerror (errno));
return 1;
}
if (listen (sock, 5) < 0)
{
g_print ("listen() failed: %s\n", g_strerror (errno));
return FALSE;
}
for (;;)
{
gint conn;
struct sockaddr_in from;
guint from_len = sizeof (from);
conn = accept (sock, (struct sockaddr *) &from, &from_len);
if (conn < 0)
{
g_print ("accept() failed: %s\n", g_strerror (errno));
return FALSE;
}
handler (conn, &from, data);
close (conn);
}
return TRUE;
}
int
main (int argc, char **argv)
{
g_type_init ();
if (argc != 2)
{
g_print ("usage: %s interface\n", argv[0]);
return 1;
}
if (!tcp_listen_loop (7899, handle_connection, argv[1]))
return 1;
return 0;
}
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2006, 2007 Collabora Ltd.
* Contact: Dafydd Harries
* (C) 2006, 2007 Nokia Corporation. All rights reserved.
* Contact: Kai Vehmanen
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Dafydd Harries, Collabora Ltd.
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
/*
* This program interoperates with the test-rtp-jingle program from the
* Farsight tests/ directory. It echoes received media to the sender.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include <nice/nice.h>
static void
recv_cb (
NiceAgent *agent,
guint stream_id,
guint candidate_id,
guint len,
gchar *buf,
G_GNUC_UNUSED
gpointer user_data)
{
nice_agent_send (agent, stream_id, candidate_id, len, buf);
}
static NiceAgent *
make_agent (NiceUDPSocketFactory *factory)
{
NiceAgent *agent;
NiceAddress addr;
agent = nice_agent_new (factory);
if (!nice_address_set_from_string (&addr, "127.0.0.1"))
g_assert_not_reached ();
nice_agent_add_local_address (agent, &addr);
nice_agent_add_stream (agent, 1);
return agent;
}
static guint
accept_connection (
NiceUDPSocketFactory *factory,
NiceUDPSocket *sock)
{
NiceAgent *agent;
NiceAddress recv_addr;
NiceAddress send_addr;
guint len;
gchar buf[1024];
guint ret = 0;
GSList *fds = NULL;
agent = make_agent (factory);
// accept incoming handshake
len = nice_udp_socket_recv (sock, &recv_addr, 1, buf);
if (len != 1)
{
ret = 1;
goto OUT;
}
if (buf[0] != '2')
{
ret = 2;
goto OUT;
}
g_debug ("got handshake packet");
// send handshake reply
send_addr = recv_addr;
send_addr.port = 1235;
nice_udp_socket_send (sock, &send_addr, 1, buf);
// send codec
strcpy (buf, "1 0 PCMU 0 8000 0");
nice_udp_socket_send (sock, &send_addr, strlen (buf), buf);
strcpy (buf, "1 0 LAST 0 0 0");
nice_udp_socket_send (sock, &send_addr, strlen (buf), buf);
// send candidate
{
NiceCandidate *candidate;
GSList *candidates;
candidates = nice_agent_get_local_candidates (agent, 1, 1);
candidate = candidates->data;
len = g_snprintf (buf, 1024, "0 0 X1 127.0.0.1 %d %s %s",
candidate->addr.port, candidate->username, candidate->password);
nice_udp_socket_send (sock, &send_addr, len, buf);
g_slist_free (candidates);
}
// IO loop
fds = g_slist_append (fds, GUINT_TO_POINTER (sock->fileno));
for (;;)
{
gchar **bits;
NiceAddress addr;
if (nice_agent_poll_read (agent, fds, recv_cb, NULL) == NULL)
continue;
len = nice_udp_socket_recv (sock, &recv_addr, 1024, buf);
buf[len] = '\0';
g_debug ("%s", buf);
if (buf[0] != '0')
continue;
bits = g_strsplit (buf, " ", 7);
if (g_strv_length (bits) != 7)
{
g_strfreev (bits);
return 3;
}
if (!nice_address_set_from_string (&addr, bits[3]))
g_assert_not_reached ();
addr.port = atoi (bits[4]);
g_debug ("username = %s", bits[5]);
g_debug ("password = %s", bits[6]);
nice_agent_add_remote_candidate (agent, 1, 1, NICE_CANDIDATE_TYPE_HOST,
&addr, bits[5], bits[6]);
}
OUT:
g_slist_free (fds);
g_object_unref (agent);
return ret;
}
int
main (void)
{
NiceUDPSocketFactory factory;
NiceUDPSocket sock;
NiceAddress addr;
guint ret;
memset (&addr, 0, sizeof (addr));
g_type_init ();
addr.port = 1234;
nice_udp_bsd_socket_factory_init (&factory);
if (!nice_udp_socket_factory_make (&factory, &sock, &addr))
g_assert_not_reached ();
ret = accept_connection (&factory, &sock);
nice_udp_socket_close (&sock);
nice_udp_socket_factory_close (&factory);
return ret;
}
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2006, 2007 Collabora Ltd.
* Contact: Dafydd Harries
* (C) 2006, 2007 Nokia Corporation. All rights reserved.
* Contact: Kai Vehmanen
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Dafydd Harries, Collabora Ltd.
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <unistd.h>
#include <glib.h>
#include "readline.h"
gchar *
readline (guint fileno)
{
gchar buf[1024];
guint i;
for (i = 0; i < sizeof (buf); i++)
{
gint ret;
ret = read (fileno, buf + i, 1);
if (ret == -1)
break;
if (ret == 0 && i == 0)
{
/* EOF on first read */
break;
}
else if (ret == 0 || buf[i] == '\n')
{
buf[i] = '\0';
return g_strdup (buf);
}
}
return NULL;
}
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2006, 2007 Collabora Ltd.
* Contact: Dafydd Harries
* (C) 2006, 2007 Nokia Corporation. All rights reserved.
* Contact: Kai Vehmanen
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Dafydd Harries, Collabora Ltd.
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifndef _READLINE_H
#define _READLINE_H
#include <glib.h>
G_BEGIN_DECLS
gchar *
readline (guint fileno);
G_END_DECLS
#endif /* _READLINE_H */
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2006, 2007 Collabora Ltd.
* Contact: Dafydd Harries
* (C) 2006, 2007 Nokia Corporation. All rights reserved.
* Contact: Kai Vehmanen
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Dafydd Harries, Collabora Ltd.
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <string.h>
#include <unistd.h>
#include <glib.h>
#include "readline.h"
/* this overrides libc read() -- is this reliable? */
ssize_t
read (
G_GNUC_UNUSED
int fd,
void *buf,
size_t count)
{
static int offset = 0;
const gchar *line = "test\n";
g_assert (count == 1);
if (offset < 5)
{
* (gchar *) buf = line[offset++];
return 1;
}
else
{
return 0;
}
}
int
main (void)
{
gchar *line;
line = readline (0);
g_assert (0 == strcmp (line, "test"));
g_free (line);
line = readline (0);
g_assert (line == NULL);
return 0;
}
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2006, 2007 Collabora Ltd.
* Contact: Dafydd Harries
* (C) 2006, 2007 Nokia Corporation. All rights reserved.
* Contact: Kai Vehmanen
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Dafydd Harries, Collabora Ltd.
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <string.h>
#include "agent.h"
#include "util.h"
int
main (void)
{
NiceAddress addr;
NiceCandidate *candidate;
gchar *str;
memset (&addr, 0, sizeof (addr));
candidate = nice_candidate_from_string ("x");
g_assert (candidate == NULL);
g_assert (nice_address_set_from_string (&addr, "192.168.0.1"));
addr.port = 1234;
candidate = nice_candidate_from_string ("H/192.168.0.1/1234/foo/bar");
g_assert (candidate != NULL);
g_assert (nice_address_equal (&addr, &(candidate->addr)));
g_assert (0 == strcmp (candidate->username, "foo"));
g_assert (0 == strcmp (candidate->password, "bar"));
str = nice_candidate_to_string (candidate);
g_assert (0 == strcmp (str, "H/192.168.0.1/1234/foo/bar"));
g_free (str);
nice_candidate_free (candidate);
return 0;
}
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2006, 2007 Collabora Ltd.
* Contact: Dafydd Harries
* (C) 2006, 2007 Nokia Corporation. All rights reserved.
* Contact: Kai Vehmanen
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Dafydd Harries, Collabora Ltd.
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <arpa/inet.h>
#include <stdlib.h>
#include <string.h>
#include "agent.h"
#include "util.h"
/* format is:
* type/ip/port/username/password
*/
NiceCandidate *
nice_candidate_from_string (const gchar *s)
{
NiceCandidateType type;
NiceCandidate *candidate;
guint32 ip;
guint16 port;
gchar **bits;
if (s == NULL || s[0] == '\0')
return NULL;
bits = g_strsplit (s, "/", 5);
if (g_strv_length (bits) != 5)
goto ERROR;
switch (bits[0][0])
{
case 'H':
type = NICE_CANDIDATE_TYPE_HOST;
break;
case 'S':
type = NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE;
break;
case 'P':
type = NICE_CANDIDATE_TYPE_PEER_REFLEXIVE;
break;
case 'R':
type = NICE_CANDIDATE_TYPE_RELAYED;
break;
default:
goto ERROR;
}
/* extract IP address */
if (inet_pton (AF_INET, bits[1], &ip) < 1)
goto ERROR;
/* extract port */
port = strtol (bits[2], NULL, 10);
candidate = nice_candidate_new (type);
nice_address_set_ipv4 (&candidate->addr, ntohl (ip));
candidate->addr.port = port;
memcpy (candidate->username, bits[3],
MIN (strlen (bits[3]), sizeof (candidate->username)));
memcpy (candidate->password, bits[4],
MIN (strlen (bits[4]), sizeof (candidate->password)));
g_strfreev (bits);
return candidate;
ERROR:
g_strfreev (bits);
return NULL;
}
gchar *
nice_candidate_to_string (NiceCandidate *candidate)
{
gchar addr_tmp[NICE_ADDRESS_STRING_LEN];
gchar *ret;
gchar type;
switch (candidate->type)
{
case NICE_CANDIDATE_TYPE_HOST:
type = 'H';
break;
case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE:
type = 'S';
break;
case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE:
type = 'P';
break;
case NICE_CANDIDATE_TYPE_RELAYED:
type = 'R';
break;
default:
return NULL;
}
nice_address_to_string (&(candidate->addr), addr_tmp);
ret = g_strdup_printf ("%c/%s/%d/%s/%s", type, addr_tmp,
candidate->addr.port, candidate->username, candidate->password);
return ret;
}
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2006, 2007 Collabora Ltd.
* Contact: Dafydd Harries
* (C) 2006, 2007 Nokia Corporation. All rights reserved.
* Contact: Kai Vehmanen
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Dafydd Harries, Collabora Ltd.
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifndef _UTIL_H
#define _UTIL_H
#include <glib.h>
#include "agent.h"
G_BEGIN_DECLS
NiceCandidate *
nice_candidate_from_string (const gchar *s);
gchar *
nice_candidate_to_string (NiceCandidate *candidate);
G_END_DECLS
#endif /* _UTIL_H */
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