uncrustify as demanded.
[oweals/gnunet.git] / src / regex / gnunet-service-regex.c
index a866288a3f23bd280a086a7d4fecfba37d3aa7fa..90ea91780e38dc9334fbc4f23e58f66ce5500f8e 100644 (file)
@@ -16,7 +16,7 @@
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file regex/gnunet-service-regex.c
@@ -33,9 +33,7 @@
 /**
  * Information about one of our clients.
  */
-struct ClientEntry
-{
-
+struct ClientEntry {
   /**
    * Queue for transmissions to @e client.
    */
@@ -65,7 +63,6 @@ struct ClientEntry
    * Task for re-announcing.
    */
   struct GNUNET_SCHEDULER_Task *refresh_task;
-
 };
 
 
@@ -91,14 +88,14 @@ static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
  * @param cls unused
  */
 static void
-cleanup_task (void *cls)
+cleanup_task(void *cls)
 {
-  GNUNET_DHT_disconnect (dht);
+  GNUNET_DHT_disconnect(dht);
   dht = NULL;
-  GNUNET_STATISTICS_destroy (stats,
-                             GNUNET_NO);
+  GNUNET_STATISTICS_destroy(stats,
+                            GNUNET_NO);
   stats = NULL;
-  GNUNET_free (my_private_key);
+  GNUNET_free(my_private_key);
   my_private_key = NULL;
 }
 
@@ -110,14 +107,14 @@ cleanup_task (void *cls)
  *        announcement
  */
 static void
-reannounce (void *cls)
+reannounce(void *cls)
 {
   struct ClientEntry *ce = cls;
 
-  REGEX_INTERNAL_reannounce (ce->ah);
-  ce->refresh_task = GNUNET_SCHEDULER_add_delayed (ce->frequency,
-                                                  &reannounce,
-                                                  ce);
+  REGEX_INTERNAL_reannounce(ce->ah);
+  ce->refresh_task = GNUNET_SCHEDULER_add_delayed(ce->frequency,
+                                                  &reannounce,
+                                                  ce);
 }
 
 
@@ -129,18 +126,18 @@ reannounce (void *cls)
  * @return #GNUNET_OK if @am is well-formed
  */
 static int
-check_announce (void *cls,
-                const struct AnnounceMessage *am)
+check_announce(void *cls,
+               const struct AnnounceMessage *am)
 {
   struct ClientEntry *ce = cls;
 
-  GNUNET_MQ_check_zero_termination (am);
+  GNUNET_MQ_check_zero_termination(am);
   if (NULL != ce->ah)
-  {
-    /* only one announcement per client allowed */
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+    {
+      /* only one announcement per client allowed */
+      GNUNET_break(0);
+      return GNUNET_SYSERR;
+    }
   return GNUNET_OK;
 }
 
@@ -152,36 +149,36 @@ check_announce (void *cls,
  * @param am the actual message
  */
 static void
-handle_announce (void *cls,
-                const struct AnnounceMessage *am)
+handle_announce(void *cls,
+                const struct AnnounceMessage *am)
 {
   struct ClientEntry *ce = cls;
   const char *regex;
 
-  regex = (const char *) &am[1];
-  ce->frequency = GNUNET_TIME_relative_ntoh (am->refresh_delay);
-  ce->refresh_task = GNUNET_SCHEDULER_add_delayed (ce->frequency,
-                                                  &reannounce,
-                                                  ce);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Starting to announce regex `%s' every %s\n",
-             regex,
-             GNUNET_STRINGS_relative_time_to_string (ce->frequency,
-                                                     GNUNET_NO));
-  ce->ah = REGEX_INTERNAL_announce (dht,
-                                   my_private_key,
-                                   regex,
-                                   ntohs (am->compression),
-                                   stats);
+  regex = (const char *)&am[1];
+  ce->frequency = GNUNET_TIME_relative_ntoh(am->refresh_delay);
+  ce->refresh_task = GNUNET_SCHEDULER_add_delayed(ce->frequency,
+                                                  &reannounce,
+                                                  ce);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Starting to announce regex `%s' every %s\n",
+             regex,
+             GNUNET_STRINGS_relative_time_to_string(ce->frequency,
+                                                    GNUNET_NO));
+  ce->ah = REGEX_INTERNAL_announce(dht,
+                                   my_private_key,
+                                   regex,
+                                   ntohs(am->compression),
+                                   stats);
   if (NULL == ce->ah)
-  {
-    GNUNET_break (0);
-    GNUNET_SCHEDULER_cancel (ce->refresh_task);
-    ce->refresh_task = NULL;
-    GNUNET_SERVICE_client_drop (ce->client);
-    return;
-  }
-  GNUNET_SERVICE_client_continue (ce->client);
+    {
+      GNUNET_break(0);
+      GNUNET_SCHEDULER_cancel(ce->refresh_task);
+      ce->refresh_task = NULL;
+      GNUNET_SERVICE_client_drop(ce->client);
+      return;
+    }
+  GNUNET_SERVICE_client_continue(ce->client);
 }
 
 
@@ -196,12 +193,12 @@ handle_announce (void *cls,
  * @param put_path_length Length of the @a put_path.
  */
 static void
-handle_search_result (void *cls,
-                     const struct GNUNET_PeerIdentity *id,
-                     const struct GNUNET_PeerIdentity *get_path,
-                     unsigned int get_path_length,
-                     const struct GNUNET_PeerIdentity *put_path,
-                     unsigned int put_path_length)
+handle_search_result(void *cls,
+                     const struct GNUNET_PeerIdentity *id,
+                     const struct GNUNET_PeerIdentity *get_path,
+                     unsigned int get_path_length,
+                     const struct GNUNET_PeerIdentity *put_path,
+                     unsigned int put_path_length)
 {
   struct ClientEntry *ce = cls;
   struct GNUNET_MQ_Envelope *env;
@@ -209,30 +206,30 @@ handle_search_result (void *cls,
   struct GNUNET_PeerIdentity *gp;
   uint16_t size;
 
-  if ( (get_path_length >= 65536) ||
-       (put_path_length >= 65536) ||
-       ( (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity))
-       + sizeof (struct ResultMessage) >= GNUNET_MAX_MESSAGE_SIZE)
-  {
-    GNUNET_break (0);
-    return;
-  }
-  size = (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity);
-  env = GNUNET_MQ_msg_extra (result,
-                             size,
-                             GNUNET_MESSAGE_TYPE_REGEX_RESULT);
-  result->get_path_length = htons ((uint16_t) get_path_length);
-  result->put_path_length = htons ((uint16_t) put_path_length);
+  if ((get_path_length >= 65536) ||
+      (put_path_length >= 65536) ||
+      ((get_path_length + put_path_length) * sizeof(struct GNUNET_PeerIdentity))
+      + sizeof(struct ResultMessage) >= GNUNET_MAX_MESSAGE_SIZE)
+    {
+      GNUNET_break(0);
+      return;
+    }
+  size = (get_path_length + put_path_length) * sizeof(struct GNUNET_PeerIdentity);
+  env = GNUNET_MQ_msg_extra(result,
+                            size,
+                            GNUNET_MESSAGE_TYPE_REGEX_RESULT);
+  result->get_path_length = htons((uint16_t)get_path_length);
+  result->put_path_length = htons((uint16_t)put_path_length);
   result->id = *id;
   gp = &result->id;
-  GNUNET_memcpy (&gp[1],
-                 get_path,
-                 get_path_length * sizeof (struct GNUNET_PeerIdentity));
-  GNUNET_memcpy (&gp[1 + get_path_length],
-                 put_path,
-                 put_path_length * sizeof (struct GNUNET_PeerIdentity));
-  GNUNET_MQ_send (ce->mq,
-                  env);
+  GNUNET_memcpy(&gp[1],
+                get_path,
+                get_path_length * sizeof(struct GNUNET_PeerIdentity));
+  GNUNET_memcpy(&gp[1 + get_path_length],
+                put_path,
+                put_path_length * sizeof(struct GNUNET_PeerIdentity));
+  GNUNET_MQ_send(ce->mq,
+                 env);
 }
 
 
@@ -243,26 +240,26 @@ handle_search_result (void *cls,
  * @param message the actual message
  */
 static int
-check_search (void *cls,
-              const struct RegexSearchMessage *sm)
+check_search(void *cls,
+             const struct RegexSearchMessage *sm)
 {
   struct ClientEntry *ce = cls;
   const char *string;
   uint16_t size;
 
-  size = ntohs (sm->header.size) - sizeof (*sm);
-  string = (const char *) &sm[1];
+  size = ntohs(sm->header.size) - sizeof(*sm);
+  string = (const char *)&sm[1];
   if ('\0' != string[size - 1])
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+    {
+      GNUNET_break(0);
+      return GNUNET_SYSERR;
+    }
   if (NULL != ce->sh)
-  {
-    /* only one search allowed per client */
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
+    {
+      /* only one search allowed per client */
+      GNUNET_break(0);
+      return GNUNET_SYSERR;
+    }
   return GNUNET_OK;
 }
 
@@ -274,28 +271,28 @@ check_search (void *cls,
  * @param message the actual message
  */
 static void
-handle_search (void *cls,
-              const struct RegexSearchMessage *sm)
+handle_search(void *cls,
+              const struct RegexSearchMessage *sm)
 {
   struct ClientEntry *ce = cls;
   const char *string;
 
-  string = (const char *) &sm[1];
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Starting to search for `%s'\n",
-             string);
-  ce->sh = REGEX_INTERNAL_search (dht,
-                                  string,
-                                  &handle_search_result,
-                                  ce,
-                                  stats);
+  string = (const char *)&sm[1];
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Starting to search for `%s'\n",
+             string);
+  ce->sh = REGEX_INTERNAL_search(dht,
+                                 string,
+                                 &handle_search_result,
+                                 ce,
+                                 stats);
   if (NULL == ce->sh)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVICE_client_drop (ce->client);
-    return;
-  }
-  GNUNET_SERVICE_client_continue (ce->client);
+    {
+      GNUNET_break(0);
+      GNUNET_SERVICE_client_drop(ce->client);
+      return;
+    }
+  GNUNET_SERVICE_client_continue(ce->client);
 }
 
 
@@ -307,27 +304,27 @@ handle_search (void *cls,
  * @param service the initialized service
  */
 static void
-run (void *cls,
-     const struct GNUNET_CONFIGURATION_Handle *cfg,
-     struct GNUNET_SERVICE_Handle *service)
+run(void *cls,
+    const struct GNUNET_CONFIGURATION_Handle *cfg,
+    struct GNUNET_SERVICE_Handle *service)
 {
-  my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
+  my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg);
   if (NULL == my_private_key)
-  {
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-  dht = GNUNET_DHT_connect (cfg, 1024);
+    {
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
+  dht = GNUNET_DHT_connect(cfg, 1024);
   if (NULL == dht)
-  {
-    GNUNET_free (my_private_key);
-    my_private_key = NULL;
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-  GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
-                                NULL);
-  stats = GNUNET_STATISTICS_create ("regex", cfg);
+    {
+      GNUNET_free(my_private_key);
+      my_private_key = NULL;
+      GNUNET_SCHEDULER_shutdown();
+      return;
+    }
+  GNUNET_SCHEDULER_add_shutdown(&cleanup_task,
+                                NULL);
+  stats = GNUNET_STATISTICS_create("regex", cfg);
 }
 
 
@@ -340,13 +337,13 @@ run (void *cls,
  * @return @a c
  */
 static void *
-client_connect_cb (void *cls,
-                  struct GNUNET_SERVICE_Client *c,
-                  struct GNUNET_MQ_Handle *mq)
+client_connect_cb(void *cls,
+                  struct GNUNET_SERVICE_Client *c,
+                  struct GNUNET_MQ_Handle *mq)
 {
   struct ClientEntry *ce;
 
-  ce = GNUNET_new (struct ClientEntry);
+  ce = GNUNET_new(struct ClientEntry);
   ce->client = c;
   ce->mq = mq;
   return ce;
@@ -361,28 +358,28 @@ client_connect_cb (void *cls,
  * @param internal_cls should be equal to @a c
  */
 static void
-client_disconnect_cb (void *cls,
-                     struct GNUNET_SERVICE_Client *c,
-                     void *internal_cls)
+client_disconnect_cb(void *cls,
+                     struct GNUNET_SERVICE_Client *c,
+                     void *internal_cls)
 {
   struct ClientEntry *ce = internal_cls;
 
   if (NULL != ce->refresh_task)
-  {
-    GNUNET_SCHEDULER_cancel (ce->refresh_task);
-    ce->refresh_task = NULL;
-  }
+    {
+      GNUNET_SCHEDULER_cancel(ce->refresh_task);
+      ce->refresh_task = NULL;
+    }
   if (NULL != ce->ah)
-  {
-    REGEX_INTERNAL_announce_cancel (ce->ah);
-    ce->ah = NULL;
-  }
+    {
+      REGEX_INTERNAL_announce_cancel(ce->ah);
+      ce->ah = NULL;
+    }
   if (NULL != ce->sh)
-  {
-    REGEX_INTERNAL_search_cancel (ce->sh);
-    ce->sh = NULL;
-  }
-  GNUNET_free (ce);
+    {
+      REGEX_INTERNAL_search_cancel(ce->sh);
+      ce->sh = NULL;
+    }
+  GNUNET_free(ce);
 }
 
 
@@ -390,21 +387,21 @@ client_disconnect_cb (void *cls,
  * Define "main" method using service macro.
  */
 GNUNET_SERVICE_MAIN
-("regex",
- GNUNET_SERVICE_OPTION_NONE,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
GNUNET_MQ_hd_var_size (announce,
+  ("regex",
 GNUNET_SERVICE_OPTION_NONE,
 &run,
 &client_connect_cb,
 &client_disconnect_cb,
 NULL,
 GNUNET_MQ_hd_var_size(announce,
                         GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE,
                         struct AnnounceMessage,
                         NULL),
GNUNET_MQ_hd_var_size (search,
 GNUNET_MQ_hd_var_size(search,
                         GNUNET_MESSAGE_TYPE_REGEX_SEARCH,
                         struct RegexSearchMessage,
                         NULL),
GNUNET_MQ_handler_end ());
 GNUNET_MQ_handler_end());
 
 
 /* end of gnunet-service-regex.c */