Commit cc4740a5 authored by Dafydd Harries's avatar Dafydd Harries
Browse files

nice_candidate_{to,from}_string: include username/password in string

darcs-hash:20070202080905-c9803-643ef6ed43ed78483617800bfaefdab7d5a43d74.gz
parent 8ce18832
#include <string.h>
#include <arpa/inet.h>
#include <glib.h>
#include <udp.h>
#include <agent.h>
#include <util.h>
#include "agent.h"
#include "util.h"
int
main (void)
......@@ -21,13 +15,15 @@ main (void)
g_assert (candidate == NULL);
g_assert (nice_address_set_ipv4_from_string (&addr, "192.168.0.1"));
candidate = nice_candidate_from_string ("H/192.168.0.1/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 (candidate->port == 1234);
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"));
g_assert (0 == strcmp (str, "H/192.168.0.1/1234/foo/bar"));
g_free (str);
nice_candidate_free (candidate);
......
#include <stdlib.h>
#include <string.h>
#include "agent.h"
/* format is:
* type/ip/port
* type/ip/port/username/password
*/
NiceCandidate *
nice_candidate_from_string (const gchar *s)
......@@ -18,9 +19,9 @@ nice_candidate_from_string (const gchar *s)
if (s == NULL || s[0] == '\0')
return NULL;
bits = g_strsplit (s, "/", 3);
bits = g_strsplit (s, "/", 5);
if (g_strv_length (bits) != 3)
if (g_strv_length (bits) != 5)
goto ERROR;
switch (bits[0][0])
......@@ -54,6 +55,11 @@ nice_candidate_from_string (const gchar *s)
nice_address_set_ipv4 (&candidate->addr, ntohl (ip));
candidate->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;
......@@ -88,7 +94,8 @@ nice_candidate_to_string (NiceCandidate *candidate)
}
addr_tmp = nice_address_to_string (&(candidate->addr));
ret = g_strdup_printf ("%c/%s/%d", type, addr_tmp, candidate->port);
ret = g_strdup_printf ("%c/%s/%d/%s/%s", type, addr_tmp, candidate->port,
candidate->username, candidate->password);
g_free (addr_tmp);
return ret;
}
......
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