convert fs publish to MQ
[oweals/gnunet.git] / src / dns / dnsparser.c
index 97f47333b5727614b78e9250bfe019289b89c756..5041d29a8a1adc9fb77428c10fd40392b1804de0 100644 (file)
@@ -1,6 +1,6 @@
 /*
       This file is part of GNUnet
-      (C) 2010-2014 Christian Grothoff (and other contributing authors)
+      Copyright (C) 2010-2014 GNUnet e.V.
 
       GNUnet is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
       You should have received a copy of the GNU General Public License
       along with GNUnet; see the file COPYING.  If not, write to the
-      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-      Boston, MA 02111-1307, USA.
+      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+      Boston, MA 02110-1301, USA.
  */
 
 /**
@@ -548,7 +548,7 @@ GNUNET_DNSPARSER_parse_cert (const char *udp_payload,
     return NULL;
   }
   memcpy (&dcert, &udp_payload[*off], sizeof (struct GNUNET_TUN_DnsCertRecord));
-  (*off) += sizeof (sizeof (struct GNUNET_TUN_DnsCertRecord));
+  (*off) += sizeof (struct GNUNET_TUN_DnsCertRecord);
   cert = GNUNET_new (struct GNUNET_DNSPARSER_CertRecord);
   cert->cert_type = ntohs (dcert.cert_type);
   cert->cert_tag = ntohs (dcert.cert_tag);
@@ -1241,8 +1241,17 @@ char *
 GNUNET_DNSPARSER_bin_to_hex (const void *data,
                              size_t data_size)
 {
-  GNUNET_break (0); // FIXME: not implemented
-  return NULL;
+  char *ret;
+  size_t off;
+  const uint8_t *idata;
+
+  idata = data;
+  ret = GNUNET_malloc (data_size * 2 + 1);
+  for (off = 0; off < data_size; off++)
+    sprintf (&ret[off * 2],
+             "%02x",
+             idata[off]);
+  return ret;
 }
 
 
@@ -1258,10 +1267,25 @@ size_t
 GNUNET_DNSPARSER_hex_to_bin (const char *hex,
                              void *data)
 {
-  GNUNET_break (0);  // FIXME: not implemented
-  return 0;
+  size_t data_size;
+  size_t off;
+  uint8_t *idata;
+  unsigned int h;
+  char in[3];
+
+  data_size = strlen (hex) / 2;
+  idata = data;
+  in[2] = '\0';
+  for (off = 0; off < data_size; off++)
+  {
+    in[0] = tolower ((int) hex[off * 2]);
+    in[1] = tolower ((int) hex[off * 2 + 1]);
+    if (1 != sscanf (in, "%x", &h))
+      return off;
+    idata[off] = (uint8_t) h;
+  }
+  return off;
 }
 
 
-
 /* end of dnsparser.c */