GNUnet  0.10.x
Functions
pq_connect.c File Reference

functions to connect to libpq (PostGres) More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_pq_lib.h"
Include dependency graph for pq_connect.c:

Go to the source code of this file.

Functions

static void pq_notice_receiver_cb (void *arg, const PGresult *res)
 Function called by libpq whenever it wants to log something. More...
 
static void pq_notice_processor_cb (void *arg, const char *message)
 Function called by libpq whenever it wants to log something. More...
 
PGconn * GNUNET_PQ_connect (const char *config_str)
 Create a connection to the Postgres database using config_str for the configuration. More...
 
PGconn * GNUNET_PQ_connect_with_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
 Connect to a postgres database using the configuration option "CONFIG" in section. More...
 

Detailed Description

functions to connect to libpq (PostGres)

Author
Christian Grothoff

Definition in file pq_connect.c.

Function Documentation

◆ pq_notice_receiver_cb()

static void pq_notice_receiver_cb ( void *  arg,
const PGresult *  res 
)
static

Function called by libpq whenever it wants to log something.

We already log whenever we care, so this function does nothing and merely exists to silence the libpq logging.

Parameters
argthe SQL connection that was used
resinformation about some libpq event

Definition at line 39 of file pq_connect.c.

Referenced by GNUNET_PQ_connect().

41 {
42  /* do nothing, intentionally */
43 }
Here is the caller graph for this function:

◆ pq_notice_processor_cb()

static void pq_notice_processor_cb ( void *  arg,
const char *  message 
)
static

Function called by libpq whenever it wants to log something.

We log those using the Taler logger.

Parameters
argthe SQL connection that was used
messageinformation about some libpq event

Definition at line 54 of file pq_connect.c.

References GNUNET_ERROR_TYPE_INFO, and GNUNET_log_from.

Referenced by GNUNET_PQ_connect().

56 {
58  "pq",
59  "%s",
60  message);
61 }
#define GNUNET_log_from(kind, comp,...)
Here is the caller graph for this function:

◆ GNUNET_PQ_connect()

PGconn* GNUNET_PQ_connect ( const char *  config_str)

Create a connection to the Postgres database using config_str for the configuration.

Initialize logging via GNUnet's log routines and disable Postgres's logger.

Parameters
config_strconfiguration to use
Returns
NULL on error

Definition at line 73 of file pq_connect.c.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_log_from, pq_notice_processor_cb(), and pq_notice_receiver_cb().

Referenced by GNUNET_PQ_connect_with_cfg().

74 {
75  PGconn *conn;
76 
77  conn = PQconnectdb (config_str);
78  if ( (NULL == conn) ||
79  (CONNECTION_OK !=
80  PQstatus (conn)) )
81  {
83  "pq",
84  "Database connection to '%s' failed: %s\n",
85  config_str,
86  (NULL != conn) ?
87  PQerrorMessage (conn)
88  : "PQconnectdb returned NULL");
89  if (NULL != conn)
90  PQfinish (conn);
91  return NULL;
92  }
93  PQsetNoticeReceiver (conn,
95  conn);
96  PQsetNoticeProcessor (conn,
98  conn);
99  return conn;
100 }
static void pq_notice_receiver_cb(void *arg, const PGresult *res)
Function called by libpq whenever it wants to log something.
Definition: pq_connect.c:39
static void pq_notice_processor_cb(void *arg, const char *message)
Function called by libpq whenever it wants to log something.
Definition: pq_connect.c:54
#define GNUNET_log_from(kind, comp,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_connect_with_cfg()

PGconn* GNUNET_PQ_connect_with_cfg ( const struct GNUNET_CONFIGURATION_Handle cfg,
const char *  section 
)

Connect to a postgres database using the configuration option "CONFIG" in section.

Parameters
cfgconfiguration
sectionconfiguration section to use to get Postgres configuration options
Returns
the postgres handle, NULL on error

Definition at line 112 of file pq_connect.c.

References GNUNET_CONFIGURATION_get_value_string(), GNUNET_free_non_null, GNUNET_OK, and GNUNET_PQ_connect().

Referenced by database_setup(), and init_connection().

114 {
115  PGconn *dbh;
116  char *conninfo;
117 
118  /* Open database and precompile statements */
119  if (GNUNET_OK !=
121  section,
122  "CONFIG",
123  &conninfo))
124  conninfo = NULL;
125  dbh = GNUNET_PQ_connect (conninfo == NULL ? "" : conninfo);
126  GNUNET_free_non_null (conninfo);
127  return dbh;
128 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static char * section
Name of the section.
Definition: gnunet-config.c:33
PGconn * GNUNET_PQ_connect(const char *config_str)
Create a connection to the Postgres database using config_str for the configuration.
Definition: pq_connect.c:73
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
Here is the call graph for this function:
Here is the caller graph for this function: