-indentation
[oweals/gnunet.git] / src / datastore / plugin_datastore_postgres.c
index 98109d4da9852a7eba7059f226d8e63d0f0d3ab5..54e5df375af42f4d70b8aeef1992a2e4be15b1ab 100644 (file)
@@ -65,7 +65,7 @@ struct Plugin
  * @brief Get a database handle
  *
  * @param plugin global context
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  */
 static int
 init_connection (struct Plugin *plugin)
@@ -75,6 +75,7 @@ init_connection (struct Plugin *plugin)
   plugin->dbh = GNUNET_POSTGRES_connect (plugin->env->cfg, "datastore-postgres");
   if (NULL == plugin->dbh)
     return GNUNET_SYSERR;
+
   ret =
       PQexec (plugin->dbh,
               "CREATE TABLE gn090 (" "  repl INTEGER NOT NULL DEFAULT 0,"
@@ -86,16 +87,23 @@ init_connection (struct Plugin *plugin)
               "  hash BYTEA NOT NULL DEFAULT '',"
               "  vhash BYTEA NOT NULL DEFAULT '',"
               "  value BYTEA NOT NULL DEFAULT '')" "WITH OIDS");
-  if ((ret == NULL) || ((PQresultStatus (ret) != PGRES_COMMAND_OK) && (0 != strcmp ("42P07",    /* duplicate table */
-                                                                                    PQresultErrorField
-                                                                                    (ret,
-                                                                                     PG_DIAG_SQLSTATE)))))
+  if ( (NULL == ret) ||
+       ((PQresultStatus (ret) != PGRES_COMMAND_OK) &&
+        (0 != strcmp ("42P07",    /* duplicate table */
+                      PQresultErrorField
+                      (ret,
+                       PG_DIAG_SQLSTATE)))))
   {
-    (void) GNUNET_POSTGRES_check_result (plugin->dbh, ret, PGRES_COMMAND_OK, "CREATE TABLE", "gn090");
+    (void) GNUNET_POSTGRES_check_result (plugin->dbh,
+                                         ret,
+                                         PGRES_COMMAND_OK,
+                                         "CREATE TABLE",
+                                         "gn090");
     PQfinish (plugin->dbh);
     plugin->dbh = NULL;
     return GNUNET_SYSERR;
   }
+
   if (PQresultStatus (ret) == PGRES_COMMAND_OK)
   {
     if ((GNUNET_OK !=
@@ -124,6 +132,7 @@ init_connection (struct Plugin *plugin)
     }
   }
   PQclear (ret);
+
   ret =
       PQexec (plugin->dbh,
               "ALTER TABLE gn090 ALTER value SET STORAGE EXTERNAL");
@@ -217,7 +226,7 @@ init_connection (struct Plugin *plugin)
  * Get an estimate of how much space the database is
  * currently using.
  *
- * @param cls our "struct Plugin*"
+ * @param cls our `struct Plugin *`
  * @return number of bytes used on disk
  */
 static unsigned long long
@@ -257,7 +266,7 @@ postgres_plugin_estimate_size (void *cls)
 /**
  * Store an item in the datastore.
  *
- * @param cls closure with the 'struct Plugin' 
+ * @param cls closure with the `struct Plugin`
  * @param key key for the item
  * @param size number of bytes in data
  * @param data content stored
@@ -267,7 +276,7 @@ postgres_plugin_estimate_size (void *cls)
  * @param replication replication-level for the content
  * @param expiration expiration time for the content
  * @param msg set to error message
- * @return GNUNET_OK on success
+ * @return #GNUNET_OK on success
  */
 static int
 postgres_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
@@ -335,7 +344,7 @@ postgres_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t siz
  */
 static void
 process_result (struct Plugin *plugin, PluginDatumProcessor proc,
-                void *proc_cls, PGresult * res, 
+                void *proc_cls, PGresult * res,
                const char *filename, int line)
 {
   int iret;
@@ -802,7 +811,7 @@ postgres_plugin_get_keys (void *cls,
     if (sizeof (struct GNUNET_HashCode) != PQgetlength (res, i, 0))
     {
       memcpy (&key, PQgetvalue (res, i, 0), sizeof (struct GNUNET_HashCode));
-      proc (proc_cls, &key, 1);    
+      proc (proc_cls, &key, 1);
     }
   }
   PQclear (res);
@@ -819,7 +828,7 @@ static void
 postgres_plugin_drop (void *cls)
 {
   struct Plugin *plugin = cls;
-  
+
   if (GNUNET_OK != GNUNET_POSTGRES_exec (plugin->dbh, "DROP TABLE gn090"))
     GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "postgres", _("Failed to drop table from database.\n"));
 }
@@ -838,14 +847,14 @@ libgnunet_plugin_datastore_postgres_init (void *cls)
   struct GNUNET_DATASTORE_PluginFunctions *api;
   struct Plugin *plugin;
 
-  plugin = GNUNET_malloc (sizeof (struct Plugin));
+  plugin = GNUNET_new (struct Plugin);
   plugin->env = env;
   if (GNUNET_OK != init_connection (plugin))
   {
     GNUNET_free (plugin);
     return NULL;
   }
-  api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions));
+  api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions);
   api->cls = plugin;
   api->estimate_size = &postgres_plugin_estimate_size;
   api->put = &postgres_plugin_put;