DTNMA Reference Tools v2.0.0 - 9.gaff6489
Delay-Tolerant Networking Management Architecture (DTNMA) Tool Suite
Loading...
Searching...
No Matches
nm_sql.c File Reference

This file is only included in the build when either ::HAVE_POSTGRESQL or ::HAVE_MYSQL are defined. More...

#include "nm_sql.h"
#include <cace/ari/cbor.h>
#include <cace/amm/typing.h>
#include <cace/amm/semtype.h>
#include <cace/util/logging.h>
#include <cace/ari/text.h>
#include <cace/ari/text_util.h>
#include <string.h>
#include <arpa/inet.h>
#include <m-bstring.h>
+ Include dependency graph for nm_sql.c:

Enumerations

enum  db_con_t { DB_CTRL_CON , DB_RPT_CON , DB_REST_CON , MGR_NUM_SQL_CONNECTIONS }
 
enum  queries {
  ARI_RPTSET_INSERT , ARI_AGENT_INSERT , ARI_EXECSET_INSERT , REFDM_DB_LOG_MSG ,
  MGR_NUM_QUERIES
}
 

Functions

cace_ari_ac_tdb_query_ac (size_t dbidx, int ac_id)
 
void refdm_db_log_msg (const char *file, int line, const char *fun, int level, size_t dbidx, const char *format,...)
 Utility function to insert debug or error informational messages into the database.
 
static void db_mgt_txn_commit (int dbidx)
 
uint32_t refdm_db_mgt_init (refdm_db_t *parms, uint32_t clear, uint32_t log)
 
uint32_t refdm_db_mgt_init_con (size_t idx, refdm_db_t *parms)
 Initialize specified (thread-specific) SQL connection and prepared queries Prepared queries are connection specific.
 
 CACE_LOG_INFO ("refdm_db_mgt_init -->1")
 
void refdm_db_mgt_close (void)
 
void refdm__db_mgt_close_conn (size_t idx)
 
int refdm_db_mgt_connected (size_t idx)
 
 va_start (args, format)
 
 m_string_init_vprintf (query, format, args)
 
 va_end (args)
 
 CACE_LOG_INFO ("-->%d", RET_PASS)
 
int32_t refdm_db_mgt_query_insert (int db_idx, uint32_t *idx, char *format,...)
 
static int transform_cbor_str_to_cace_data (cace_ari_t *ari_item, char *cbor_str, char **errm)
 Takes a C string and returns the corresponding cace_ari_t.
 
refdm_agent_trefdm_db_fetch_agent (int32_t id)
 
int32_t refdm_db_fetch_agent_idx (const char *eid)
 Get the index of an Agent from its endpoint name.
 
uint32_t refdm_db_insert_rptset (const cace_ari_t *val, const refdm_agent_t *agent)
 
uint32_t refdm_db_insert_agent (const m_string_t eid)
 
uint32_t refdm_db_insert_execset (const cace_ari_t *val, const refdm_agent_t *agent)
 

Variables

const char * TBL_NAME_RPTSET = "ari_rptset"
 
const char * COL_NAME_REFERENCE_TIME = "reference_time"
 
const char * COL_NAME_AGENT_ID = "agent_id"
 
const char * COL_NAME_ARI_RPTSET_ID = "ari_rptset_id"
 
const char * COL_NAME_REPORT_LIST = "report_list"
 
const char * COL_NAME_REPORT_LIST_CBOR = "report_list_cbor"
 
const char * COL_NAME_NONCE_INT = "nonce_int"
 
const char * COL_NAME_NONCE_BYTES = "nonce_bytes"
 
static refdm_db_t * gParms
 
static pthread_mutex_t db_rest_con_use
 
 return
 
return result
 
m_string_t query
 
return RET_PASS
 

Detailed Description

This file is only included in the build when either ::HAVE_POSTGRESQL or ::HAVE_MYSQL are defined.

Enumeration Type Documentation

◆ db_con_t

enum db_con_t
Enumerator
DB_CTRL_CON 

Connection for receiving outgoing controls from database.

DB_RPT_CON 

Connection associated with DM RX thread.

All activities in this thread will execute within transactions.

DB_REST_CON 

Connection for REST API access.

MGR_NUM_SQL_CONNECTIONS 

Total number of connections.

Function Documentation

◆ refdm_db_fetch_agent_idx()

int32_t refdm_db_fetch_agent_idx ( const char *  eid)

Get the index of an Agent from its endpoint name.

Parameters
[in]senderThe agent EID.
Returns
The corresponding Index, or zero if unsuccessful

References CACE_FREE, CACE_LOG_ERR, CACE_LOG_INFO, CACE_MALLOC, DB_REST_CON, DB_RPT_CON, and RET_PASS.

◆ refdm_db_insert_agent()

uint32_t refdm_db_insert_agent ( const m_string_t  eid)
Parameters
eidagent eid being added
statusSet to 0 if parsing fails, but not modified on success
Returns
Report Set ID, or 0 on error

References CACE_LOG_INFO, and DB_RPT_CON.

◆ refdm_db_insert_rptset()

uint32_t refdm_db_insert_rptset ( const cace_ari_t val,
const refdm_agent_t agent 
)
Parameters
valReport
agentagent table set being inserted in
statusSet to 0 if parsing fails, but not modified on success
Returns
Set ID, or 0 on error

References cace_ari_cbor_encode(), cace_ari_text_encode(), cace_data_deinit(), cace_data_init(), CACE_DATA_INIT_NULL, CACE_LOG_DEBUG, CACE_LOG_ERR, CACE_LOG_INFO, cace_log_is_enabled_for(), DB_RPT_CON, refdm_agent_t::eid, cace_data_t::len, cace_ari_rptset_t::nonce, cace_data_t::ptr, and cace_ari_rptset_t::reftime.

◆ refdm_db_log_msg()

void refdm_db_log_msg ( const char *  filename,
int  lineno,
const char *  funcname,
int  level,
size_t  dbidx,
const char *  format,
  ... 
)

Utility function to insert debug or error informational messages into the database.

NOTE: If operating within a transaction, caller is responsible for committing transaction.

References MGR_NUM_SQL_CONNECTIONS.

◆ refdm_db_mgt_init_con()

uint32_t refdm_db_mgt_init_con ( size_t  idx,
refdm_db_t *  parms 
)

Initialize specified (thread-specific) SQL connection and prepared queries Prepared queries are connection specific.

While we may not use all prepared statements for all connections, initializing the same sets everywhere simplifies management.

References CACE_LOG_INFO, and CACE_LOG_WARNING.

◆ transform_cbor_str_to_cace_data()

static int transform_cbor_str_to_cace_data ( cace_ari_t ari_item,
char *  cbor_str,
char **  errm 
)
static

Takes a C string and returns the corresponding cace_ari_t.

Returns
Returns RET_PASS on success otherwise RET_FAIL_* on failure.
  • Parameters
    [out]ari_itemThe ARI to decode into.
  • Parameters
    [in]cbor_strThe string to decode from.
    [out]errmIf non-null, this will be set to a specific error message associated with any failure. When the return code is non-zero, if the pointed-to pointer is non-null it must be freed using CACE_FREE().

References cace_ari_cbor_decode(), cace_data_deinit(), cace_data_init_view(), errm, RET_FAIL_UNEXPECTED, and RET_PASS.