aboutsummaryrefslogtreecommitdiff
path: root/src/gns/plugin_gnsrecord_gns.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-06 11:40:48 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-06 11:40:48 +0000
commita5f7e9db370fa9db4b11a2be66888c348fdd395f (patch)
tree5065c4f92f6549d69e1563225c1bfed6f1a09bc3 /src/gns/plugin_gnsrecord_gns.c
parent552c240a850306b1ef4fc9cd831eedaf59995ddd (diff)
downloadgnunet-a5f7e9db370fa9db4b11a2be66888c348fdd395f.tar.gz
gnunet-a5f7e9db370fa9db4b11a2be66888c348fdd395f.zip
-box from/to string conversion
Diffstat (limited to 'src/gns/plugin_gnsrecord_gns.c')
-rw-r--r--src/gns/plugin_gnsrecord_gns.c120
1 files changed, 91 insertions, 29 deletions
diff --git a/src/gns/plugin_gnsrecord_gns.c b/src/gns/plugin_gnsrecord_gns.c
index 8247ff66d..2f460cadf 100644
--- a/src/gns/plugin_gnsrecord_gns.c
+++ b/src/gns/plugin_gnsrecord_gns.c
@@ -102,16 +102,38 @@ gns_value_to_string (void *cls,
102 ('\0' != cdata[data_size - 1]) ) 102 ('\0' != cdata[data_size - 1]) )
103 return NULL; /* malformed */ 103 return NULL; /* malformed */
104 vpn = data; 104 vpn = data;
105 GNUNET_asprintf (&vpn_str, "%u %s %s", 105 GNUNET_asprintf (&vpn_str,
106 "%u %s %s",
106 (unsigned int) ntohs (vpn->proto), 107 (unsigned int) ntohs (vpn->proto),
107 (const char*) GNUNET_i2s_full (&vpn->peer), 108 (const char*) GNUNET_i2s_full (&vpn->peer),
108 (const char*) &vpn[1]); 109 (const char*) &vpn[1]);
109 return vpn_str; 110 return vpn_str;
110 } 111 }
111 case GNUNET_GNSRECORD_TYPE_BOX: 112 case GNUNET_GNSRECORD_TYPE_BOX:
112 /* FIXME: to be implemented! */ 113 {
113 GNUNET_break (0); 114 const struct GNUNET_GNSRECORD_BoxRecord *box;
114 return NULL; 115 uint32_t rt;
116 char *box_str;
117 char *ival;
118
119 if (data_size < sizeof (struct GNUNET_GNSRECORD_BoxRecord))
120 return NULL; /* malformed */
121 box = data;
122 rt = ntohl (box->record_type);
123 ival = GNUNET_GNSRECORD_value_to_string (rt,
124 &box[1],
125 data_size - sizeof (struct GNUNET_GNSRECORD_BoxRecord));
126 if (NULL == ival)
127 return NULL; /* malformed */
128 GNUNET_asprintf (&box_str,
129 "%u %u %u %s",
130 (unsigned int) ntohs (box->protocol),
131 (unsigned int) ntohs (box->service),
132 (unsigned int) rt,
133 ival);
134 GNUNET_free (ival);
135 return box_str;
136 }
115 default: 137 default:
116 return NULL; 138 return NULL;
117 } 139 }
@@ -137,10 +159,6 @@ gns_string_to_value (void *cls,
137 size_t *data_size) 159 size_t *data_size)
138{ 160{
139 struct GNUNET_CRYPTO_EcdsaPublicKey pkey; 161 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
140 struct GNUNET_TUN_GnsVpnRecord *vpn;
141 char s_peer[103 + 1];
142 char s_serv[253 + 1];
143 unsigned int proto;
144 162
145 if (NULL == s) 163 if (NULL == s)
146 return GNUNET_SYSERR; 164 return GNUNET_SYSERR;
@@ -214,31 +232,75 @@ gns_string_to_value (void *cls,
214 return GNUNET_OK; 232 return GNUNET_OK;
215 } 233 }
216 case GNUNET_GNSRECORD_TYPE_VPN: 234 case GNUNET_GNSRECORD_TYPE_VPN:
217 if (3 != SSCANF (s,"%u %103s %253s",
218 &proto, s_peer, s_serv))
219 { 235 {
220 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 236 struct GNUNET_TUN_GnsVpnRecord *vpn;
221 _("Unable to parse VPN record string `%s'\n"), 237 char s_peer[103 + 1];
222 s); 238 char s_serv[253 + 1];
223 return GNUNET_SYSERR; 239 unsigned int proto;
240
241 if (3 != SSCANF (s,
242 "%u %103s %253s",
243 &proto, s_peer, s_serv))
244 {
245 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
246 _("Unable to parse VPN record string `%s'\n"),
247 s);
248 return GNUNET_SYSERR;
249 }
250 *data_size = sizeof (struct GNUNET_TUN_GnsVpnRecord) + strlen (s_serv) + 1;
251 *data = vpn = GNUNET_malloc (*data_size);
252 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string ((char*) s_peer,
253 strlen (s_peer),
254 &vpn->peer.public_key))
255 {
256 GNUNET_free (vpn);
257 *data_size = 0;
258 return GNUNET_SYSERR;
259 }
260 vpn->proto = htons ((uint16_t) proto);
261 strcpy ((char*)&vpn[1], s_serv);
262 return GNUNET_OK;
224 } 263 }
225 *data_size = sizeof (struct GNUNET_TUN_GnsVpnRecord) + strlen (s_serv) + 1; 264 case GNUNET_GNSRECORD_TYPE_BOX:
226 *data = vpn = GNUNET_malloc (*data_size);
227 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string ((char*) s_peer,
228 strlen (s_peer),
229 &vpn->peer.public_key))
230 { 265 {
231 GNUNET_free (vpn); 266 struct GNUNET_GNSRECORD_BoxRecord *box;
232 *data_size = 0; 267 size_t slen = strlen (s) + 1;
233 return GNUNET_SYSERR; 268 char rest[slen];
269 unsigned int protocol;
270 unsigned int service;
271 unsigned int record_type;
272 void *bval;
273 size_t bval_size;
274
275 if (4 != SSCANF (s,
276 "%u %u %u %s",
277 &protocol,
278 &service,
279 &record_type,
280 rest))
281 {
282 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
283 _("Unable to parse BOX record string `%s'\n"),
284 s);
285 return GNUNET_SYSERR;
286 }
287 if (GNUNET_OK !=
288 GNUNET_GNSRECORD_string_to_value (record_type,
289 rest,
290 &bval,
291 &bval_size))
292 return GNUNET_SYSERR;
293 *data_size = sizeof (struct GNUNET_GNSRECORD_BoxRecord) + bval_size;
294 *data = box = GNUNET_malloc (*data_size);
295 box->protocol = htons (protocol);
296 box->service = htons (service);
297 box->record_type = htonl (record_type);
298 memcpy (&box[1],
299 bval,
300 bval_size);
301 GNUNET_free (bval);
302 return GNUNET_OK;
234 } 303 }
235 vpn->proto = htons ((uint16_t) proto);
236 strcpy ((char*)&vpn[1], s_serv);
237 return GNUNET_OK;
238 case GNUNET_GNSRECORD_TYPE_BOX:
239 /* FIXME: to be implemented! */
240 GNUNET_break (0);
241 return GNUNET_SYSERR;
242 default: 304 default:
243 return GNUNET_SYSERR; 305 return GNUNET_SYSERR;
244 } 306 }