aboutsummaryrefslogtreecommitdiff
path: root/src/gns/plugin_gnsrecord_gns.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-11-06 15:25:55 +0000
committerChristian Grothoff <christian@grothoff.org>2013-11-06 15:25:55 +0000
commitd29d71d43da08c8e75a30b91d97ebcd7e3a78a6c (patch)
tree06a261163debe3831d1ac5388fffd2790942ad71 /src/gns/plugin_gnsrecord_gns.c
parent8f59cc052c7f0cc2297cb9d056e24d99f003a448 (diff)
downloadgnunet-d29d71d43da08c8e75a30b91d97ebcd7e3a78a6c.tar.gz
gnunet-d29d71d43da08c8e75a30b91d97ebcd7e3a78a6c.zip
-implementing updated GNS plugin code for new GNS2DNS records (#3093)
Diffstat (limited to 'src/gns/plugin_gnsrecord_gns.c')
-rw-r--r--src/gns/plugin_gnsrecord_gns.c65
1 files changed, 48 insertions, 17 deletions
diff --git a/src/gns/plugin_gnsrecord_gns.c b/src/gns/plugin_gnsrecord_gns.c
index 87238498a..96ad0aa8d 100644
--- a/src/gns/plugin_gnsrecord_gns.c
+++ b/src/gns/plugin_gnsrecord_gns.c
@@ -64,20 +64,33 @@ gns_value_to_string (void *cls,
64 case GNUNET_GNSRECORD_TYPE_GNS2DNS: 64 case GNUNET_GNSRECORD_TYPE_GNS2DNS:
65 { 65 {
66 char *ns; 66 char *ns;
67 char *ip;
67 size_t off; 68 size_t off;
69 char *nstr;
68 70
69 off = 0; 71 off = 0;
70 ns = GNUNET_DNSPARSER_parse_name (data, 72 ns = GNUNET_DNSPARSER_parse_name (data,
71 data_size, 73 data_size,
72 &off); 74 &off);
75 ip = GNUNET_DNSPARSER_parse_name (data,
76 data_size,
77 &off);
73 if ( (NULL == ns) || 78 if ( (NULL == ns) ||
79 (NULL == ip) ||
74 (off != data_size) ) 80 (off != data_size) )
75 { 81 {
76 GNUNET_break_op (0); 82 GNUNET_break_op (0);
77 GNUNET_free_non_null (ns); 83 GNUNET_free_non_null (ns);
84 GNUNET_free_non_null (ip);
78 return NULL; 85 return NULL;
79 } 86 }
80 return ns; 87 GNUNET_asprintf (&nstr,
88 "%s@%s",
89 ns,
90 ip);
91 GNUNET_free_non_null (ns);
92 GNUNET_free_non_null (ip);
93 return nstr;
81 } 94 }
82 case GNUNET_GNSRECORD_TYPE_VPN: 95 case GNUNET_GNSRECORD_TYPE_VPN:
83 { 96 {
@@ -89,14 +102,10 @@ gns_value_to_string (void *cls,
89 ('\0' != cdata[data_size - 1]) ) 102 ('\0' != cdata[data_size - 1]) )
90 return NULL; /* malformed */ 103 return NULL; /* malformed */
91 vpn = data; 104 vpn = data;
92 if (0 == GNUNET_asprintf (&vpn_str, "%u %s %s", 105 GNUNET_asprintf (&vpn_str, "%u %s %s",
93 (unsigned int) ntohs (vpn->proto), 106 (unsigned int) ntohs (vpn->proto),
94 (const char*) GNUNET_i2s_full (&vpn->peer), 107 (const char*) GNUNET_i2s_full (&vpn->peer),
95 (const char*) &vpn[1])) 108 (const char*) &vpn[1]);
96 {
97 GNUNET_free (vpn_str);
98 return NULL;
99 }
100 return vpn_str; 109 return vpn_str;
101 } 110 }
102 default: 111 default:
@@ -158,21 +167,43 @@ gns_string_to_value (void *cls,
158 return GNUNET_OK; 167 return GNUNET_OK;
159 case GNUNET_GNSRECORD_TYPE_GNS2DNS: 168 case GNUNET_GNSRECORD_TYPE_GNS2DNS:
160 { 169 {
161 char nsbuf[256]; 170 char nsbuf[514];
171 char *cpy;
172 char *at;
162 size_t off; 173 size_t off;
163 174
175 cpy = GNUNET_strdup (s);
176 at = strchr (cpy, '@');
177 if (NULL == at)
178 {
179 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
180 _("Unable to parse GNS2DNS record `%s'\n"),
181 s);
182 GNUNET_free (cpy);
183 return GNUNET_SYSERR;
184 }
185 *at = '\0';
186 at++;
187
164 off = 0; 188 off = 0;
165 if (GNUNET_OK != 189 if ( (GNUNET_OK !=
166 GNUNET_DNSPARSER_builder_add_name (nsbuf, 190 GNUNET_DNSPARSER_builder_add_name (nsbuf,
167 sizeof (nsbuf), 191 sizeof (nsbuf),
168 &off, 192 &off,
169 s)) 193 cpy)) ||
194 (GNUNET_OK !=
195 GNUNET_DNSPARSER_builder_add_name (nsbuf,
196 sizeof (nsbuf),
197 &off,
198 at)) )
170 { 199 {
171 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
172 _("Failed to serialize GNS2DNS record with value `%s'\n"), 201 _("Failed to serialize GNS2DNS record with value `%s'\n"),
173 s); 202 s);
203 GNUNET_free (cpy);
174 return GNUNET_SYSERR; 204 return GNUNET_SYSERR;
175 } 205 }
206 GNUNET_free (cpy);
176 *data_size = off; 207 *data_size = off;
177 *data = GNUNET_malloc (off); 208 *data = GNUNET_malloc (off);
178 memcpy (*data, nsbuf, off); 209 memcpy (*data, nsbuf, off);