moved test files and fixed namestore
[oweals/gnunet.git] / src / identity / identity_api.c
index 3c8dc49b1f62880a0b8de4c4ffdca02469544443..30a6fb23d9998e2081da42fdf72b766f34e53e85 100644 (file)
@@ -2,20 +2,18 @@
      This file is part of GNUnet.
      Copyright (C) 2013, 2016 GNUnet e.V.
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public Liceidentity as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public Liceidentity for more details.
-
-     You should have received a copy of the GNU General Public Liceidentity
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-     Boston, MA 02110-1301, USA.
+     Affero General Public License for more details.
+    
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /**
@@ -304,14 +302,14 @@ mq_error_handler (void *cls,
  */
 static int
 check_identity_result_code (void *cls,
-                            const struct GNUNET_IDENTITY_ResultCodeMessage *rcm)
+                            const struct ResultCodeMessage *rcm)
 {
   uint16_t size = ntohs (rcm->header.size) - sizeof (*rcm);
   const char *str = (const char *) &rcm[1];
 
   if (0 == size)
     return GNUNET_OK;
-  if ('\0' != str[size - sizeof (*rcm) - 1])
+  if ('\0' != str[size - 1])
   {
     GNUNET_break (0);
     return GNUNET_SYSERR;
@@ -328,7 +326,7 @@ check_identity_result_code (void *cls,
  */
 static void
 handle_identity_result_code (void *cls,
-                             const struct GNUNET_IDENTITY_ResultCodeMessage *rcm)
+                             const struct ResultCodeMessage *rcm)
 {
   struct GNUNET_IDENTITY_Handle *h = cls;
   struct GNUNET_IDENTITY_Operation *op;
@@ -363,13 +361,13 @@ handle_identity_result_code (void *cls,
  */
 static int
 check_identity_update (void *cls,
-                        const struct GNUNET_IDENTITY_UpdateMessage *um)
+                        const struct UpdateMessage *um)
 {
   uint16_t size = ntohs (um->header.size);
   uint16_t name_len = ntohs (um->name_len);
   const char *str = (const char *) &um[1];
 
-  if ( (size != name_len + sizeof (struct GNUNET_IDENTITY_UpdateMessage)) ||
+  if ( (size != name_len + sizeof (struct UpdateMessage)) ||
        ( (0 != name_len) &&
          ('\0' != str[name_len - 1])) )
   {
@@ -388,7 +386,7 @@ check_identity_update (void *cls,
  */
 static void
 handle_identity_update (void *cls,
-                        const struct GNUNET_IDENTITY_UpdateMessage *um)
+                        const struct UpdateMessage *um)
 {
   struct GNUNET_IDENTITY_Handle *h = cls;
   uint16_t name_len = ntohs (um->name_len);
@@ -475,13 +473,13 @@ handle_identity_update (void *cls,
  */
 static int
 check_identity_set_default (void *cls,
-                            const struct GNUNET_IDENTITY_SetDefaultMessage *sdm)
+                            const struct SetDefaultMessage *sdm)
 {
-  uint16_t size = ntohs (sdm->header.size);
+  uint16_t size = ntohs (sdm->header.size) - sizeof (*sdm);
   uint16_t name_len = ntohs (sdm->name_len);
   const char *str = (const char *) &sdm[1];
 
-  if ( (size != name_len + sizeof (struct GNUNET_IDENTITY_SetDefaultMessage)) ||
+  if ( (size != name_len) ||
        ( (0 != name_len) &&
          ('\0' != str[name_len - 1]) ) )
   {
@@ -502,7 +500,7 @@ check_identity_set_default (void *cls,
  */
 static void
 handle_identity_set_default (void *cls,
-                             const struct GNUNET_IDENTITY_SetDefaultMessage *sdm)
+                             const struct SetDefaultMessage *sdm)
 {
   struct GNUNET_IDENTITY_Handle *h = cls;
   struct GNUNET_IDENTITY_Operation *op;
@@ -552,20 +550,20 @@ handle_identity_set_default (void *cls,
 static void
 reconnect (void *cls)
 {
-  GNUNET_MQ_hd_var_size (identity_result_code,
-                         GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE,
-                         struct GNUNET_IDENTITY_ResultCodeMessage);
-  GNUNET_MQ_hd_var_size (identity_update,
-                         GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE,
-                         struct GNUNET_IDENTITY_UpdateMessage);
-  GNUNET_MQ_hd_var_size (identity_set_default,
-                         GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
-                         struct GNUNET_IDENTITY_SetDefaultMessage);
   struct GNUNET_IDENTITY_Handle *h = cls;
   struct GNUNET_MQ_MessageHandler handlers[] = {
-    make_identity_result_code_handler (h),
-    make_identity_update_handler (h),
-    make_identity_set_default_handler (h),
+    GNUNET_MQ_hd_var_size (identity_result_code,
+                           GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE,
+                           struct ResultCodeMessage,
+                           h),
+    GNUNET_MQ_hd_var_size (identity_update,
+                           GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE,
+                           struct UpdateMessage,
+                           h),
+    GNUNET_MQ_hd_var_size (identity_set_default,
+                           GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
+                           struct SetDefaultMessage,
+                           h),
     GNUNET_MQ_handler_end ()
   };
   struct GNUNET_MQ_Envelope *env;
@@ -575,7 +573,7 @@ reconnect (void *cls)
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Connecting to identity service.\n");
   GNUNET_assert (NULL == h->mq);
-  h->mq = GNUNET_CLIENT_connecT (h->cfg,
+  h->mq = GNUNET_CLIENT_connect (h->cfg,
                                  "identity",
                                  handlers,
                                  &mq_error_handler,
@@ -665,13 +663,13 @@ GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h,
 {
   struct GNUNET_IDENTITY_Operation *op;
   struct GNUNET_MQ_Envelope *env;
-  struct GNUNET_IDENTITY_GetDefaultMessage *gdm;
+  struct GetDefaultMessage *gdm;
   size_t slen;
 
   if (NULL == h->mq)
     return NULL;
   slen = strlen (service_name) + 1;
-  if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_GetDefaultMessage))
+  if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct GetDefaultMessage))
   {
     GNUNET_break (0);
     return NULL;
@@ -688,7 +686,7 @@ GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h,
                              GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT);
   gdm->name_len = htons (slen);
   gdm->reserved = htons (0);
-  memcpy (&gdm[1],
+  GNUNET_memcpy (&gdm[1],
           service_name,
           slen);
   GNUNET_MQ_send (h->mq,
@@ -716,13 +714,13 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h,
 {
   struct GNUNET_IDENTITY_Operation *op;
   struct GNUNET_MQ_Envelope *env;
-  struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
+  struct SetDefaultMessage *sdm;
   size_t slen;
 
   if (NULL == h->mq)
     return NULL;
   slen = strlen (service_name) + 1;
-  if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_SetDefaultMessage))
+  if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct SetDefaultMessage))
   {
     GNUNET_break (0);
     return NULL;
@@ -740,7 +738,7 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h,
   sdm->name_len = htons (slen);
   sdm->reserved = htons (0);
   sdm->private_key = *ego->pk;
-  memcpy (&sdm[1],
+  GNUNET_memcpy (&sdm[1],
           service_name,
           slen);
   GNUNET_MQ_send (h->mq,
@@ -766,14 +764,14 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
 {
   struct GNUNET_IDENTITY_Operation *op;
   struct GNUNET_MQ_Envelope *env;
-  struct GNUNET_IDENTITY_CreateRequestMessage *crm;
+  struct CreateRequestMessage *crm;
   struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
   size_t slen;
 
   if (NULL == h->mq)
     return NULL;
   slen = strlen (name) + 1;
-  if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_CreateRequestMessage))
+  if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct CreateRequestMessage))
   {
     GNUNET_break (0);
     return NULL;
@@ -793,7 +791,7 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
   pk = GNUNET_CRYPTO_ecdsa_key_create ();
   crm->private_key = *pk;
   GNUNET_free (pk);
-  memcpy (&crm[1],
+  GNUNET_memcpy (&crm[1],
           name,
           slen);
   GNUNET_MQ_send (h->mq,
@@ -821,7 +819,7 @@ GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h,
 {
   struct GNUNET_IDENTITY_Operation *op;
   struct GNUNET_MQ_Envelope *env;
-  struct GNUNET_IDENTITY_RenameMessage *grm;
+  struct RenameMessage *grm;
   size_t slen_old;
   size_t slen_new;
   char *dst;
@@ -830,9 +828,9 @@ GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h,
     return NULL;
   slen_old = strlen (old_name) + 1;
   slen_new = strlen (new_name) + 1;
-  if ( (slen_old >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
-       (slen_new >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
-       (slen_old + slen_new >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_RenameMessage)) )
+  if ( (slen_old >= GNUNET_MAX_MESSAGE_SIZE) ||
+       (slen_new >= GNUNET_MAX_MESSAGE_SIZE) ||
+       (slen_old + slen_new >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct RenameMessage)) )
   {
     GNUNET_break (0);
     return NULL;
@@ -850,10 +848,10 @@ GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h,
   grm->old_name_len = htons (slen_old);
   grm->new_name_len = htons (slen_new);
   dst = (char *) &grm[1];
-  memcpy (dst,
+  GNUNET_memcpy (dst,
           old_name,
           slen_old);
-  memcpy (&dst[slen_old],
+  GNUNET_memcpy (&dst[slen_old],
           new_name,
           slen_new);
   GNUNET_MQ_send (h->mq,
@@ -879,13 +877,13 @@ GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *h,
 {
   struct GNUNET_IDENTITY_Operation *op;
   struct GNUNET_MQ_Envelope *env;
-  struct GNUNET_IDENTITY_DeleteMessage *gdm;
+  struct DeleteMessage *gdm;
   size_t slen;
 
   if (NULL == h->mq)
     return NULL;
   slen = strlen (name) + 1;
-  if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_DeleteMessage))
+  if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct DeleteMessage))
   {
     GNUNET_break (0);
     return NULL;
@@ -902,7 +900,7 @@ GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *h,
                              GNUNET_MESSAGE_TYPE_IDENTITY_DELETE);
   gdm->name_len = htons (slen);
   gdm->reserved = htons (0);
-  memcpy (&gdm[1],
+  GNUNET_memcpy (&gdm[1],
           name,
           slen);
   GNUNET_MQ_send (h->mq,