automotive-dlt
dlt_offline_logstorage.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
#include <syslog.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <time.h>
#include "dlt_offline_logstorage.h"
#include "dlt_offline_logstorage_behavior.h"
#include "dlt_config_file_parser.h"
Include dependency graph for dlt_offline_logstorage.c:

Go to the source code of this file.

Macros

#define DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR   1
 
#define DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR   2
 
#define GENERAL_BASE_NAME   "General"
 

Functions

static int dlt_logstorage_hash_create (int num_entries, struct hsearch_data *htab)
 
static int dlt_logstorage_hash_destroy (struct hsearch_data *htab)
 
static int dlt_logstorage_hash_add (char *key, void *value, struct hsearch_data *htab)
 
static void * dlt_logstorage_hash_find (char *key, struct hsearch_data *htab)
 
int dlt_logstorage_count_ids (const char *str)
 
int dlt_logstorage_read_list_of_names (char **names, char *value)
 
int dlt_logstorage_read_log_level (int *log_level, char *value)
 
int dlt_logstorage_read_file_name (char **file_name, char *value)
 
int dlt_logstorage_read_number (unsigned int *number, char *value)
 
int dlt_logstorage_set_sync_strategy (int *strategy, char *value)
 
int dlt_logstorage_set_ecuid (char **ecuid, char *value)
 
int dlt_logstorage_create_keys (char *appids, char *ctxids, char **keys, int *num_keys)
 
int dlt_logstorage_device_connected (DltLogStorage *handle, char *mount_point)
 
void dlt_logstorage_free (DltLogStorage *handle, int reason)
 
int dlt_logstorage_device_disconnected (DltLogStorage *handle, int reason)
 
int dlt_logstorage_prepare_table (DltLogStorage *handle, char *appid, char *ctxid, DltLogStorageConfigData *tmp_data)
 
int dlt_logstorage_validate_filter_value (char *filter_key, char *filter_value, char **appid, char **ctxid, DltLogStorageConfigData *tmp_data)
 
int dlt_logstorage_validate_filter_name (char *name)
 
void dlt_logstorage_filter_set_strategy (DltLogStorageConfigData *config, int strategy)
 
int dlt_daemon_setup_filter_properties (DltLogStorage *handle, DltConfigFile *config_file, char *sec_name)
 
int dlt_logstorage_store_filters (DltLogStorage *handle, char *config_file_name)
 
int dlt_logstorage_load_config (DltLogStorage *handle)
 
int dlt_logstorage_get_loglevel_by_key (DltLogStorage *handle, char *key)
 
DltLogStorageConfigData ** dlt_logstorage_get_config (DltLogStorage *handle, char *apid, char *ctid, int *num_config)
 
DltLogStorageConfigData ** dlt_logstorage_filter (DltLogStorage *handle, char *appid, char *ctxid, char *ecuid, int log_level, int *num)
 
int dlt_logstorage_write (DltLogStorage *handle, DltLogStorageUserConfig *uconfig, unsigned char *data1, int size1, unsigned char *data2, int size2, unsigned char *data3, int size3)
 
int dlt_logstorage_sync_caches (DltLogStorage *handle)
 

Detailed Description

app begin@ Copyright (C) 2013 - 2015 Advanced Driver Information Technology. This code is developed by Advanced Driver Information Technology. Copyright of Advanced Driver Information Technology, Bosch and DENSO.

DLT offline log storage functionality source file.

Author
Syed Hameed shame.nosp@m.ed@j.nosp@m.p.adi.nosp@m.t-jv.nosp@m..com ADIT 2013 - 2015
Christoph Lipka clipk.nosp@m.a@jp.nosp@m..adit.nosp@m.-jv..nosp@m.com ADIT 2015

For further information see http://www.genivi.org/. end@

Definition in file dlt_offline_logstorage.c.

Macro Definition Documentation

#define DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR   1
#define DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR   2
#define GENERAL_BASE_NAME   "General"

Definition at line 41 of file dlt_offline_logstorage.c.

Referenced by dlt_logstorage_store_filters().

Function Documentation

int dlt_logstorage_count_ids ( const char *  str)

Definition at line 89 of file dlt_offline_logstorage.c.

References NULL, and str.

Referenced by dlt_logstorage_create_keys(), and dlt_logstorage_read_list_of_names().

int dlt_logstorage_create_keys ( char *  appids,
char *  ctxids,
char **  keys,
int *  num_keys 
)

dlt_logstorage_create_keys

Create keys for hash table

From each section [filter] in offline logstorage configuration file, we receive application and context id strings. Application and context id can consist of

  • a 4char long name
  • a comma separated list of ids
  • a wildcard: .*

Not allowed is the combination of application id and context id set to wildcard. This will be rejected.

If lists given for application and/or context id, all possible combinations are returned as keys in a form "[appid][ctxid], e.g. "APP1:CTX1". If wildcards are used, the non-wildcard value becomes the key, e.g. "APP1:" or ":CTX2".

Parameters
[in]

Definition at line 425 of file dlt_offline_logstorage.c.

References dlt_log(), dlt_logstorage_count_ids(), DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN, and NULL.

Referenced by dlt_logstorage_prepare_table().

int dlt_logstorage_device_connected ( DltLogStorage handle,
char *  mount_point 
)
int dlt_logstorage_device_disconnected ( DltLogStorage handle,
int  reason 
)

dlt_logstorage_device_disconnected

De-Initializes DLT Offline Logstorage with respect to device status

Parameters
handleDLT Logstorage handle
reasonReason for disconnect
Returns
0 on success, -1 on error

Definition at line 659 of file dlt_offline_logstorage.c.

References DltLogStorage::config_status, DltLogStorage::connection_type, DltLogStorage::device_mount_point, dlt_logstorage_free(), DLT_MOUNT_PATH_MAX, DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE, DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED, NULL, DltLogStorage::num_filter_keys, and DltLogStorage::write_errors.

Referenced by dlt_daemon_control_service_logstorage(), dlt_daemon_logstorage_cleanup(), dlt_daemon_logstorage_write(), and dlt_logstorage_device_connected().

DltLogStorageConfigData** dlt_logstorage_filter ( DltLogStorage handle,
char *  appid,
char *  ctxid,
char *  ecuid,
int  log_level,
int *  num 
)

dlt_logstorage_filter

Check if log message need to be stored in a certain device based on filter config

  • get all DltLogStorageConfigData from hash table possible by given apid/ctid (apid:, :ctid, apid:ctid
  • for each found structure, compare message log level with configured one
Parameters
appidapplication id
ctxidcontext id
log_levelLog level of message
ecuidEcuID given in the message
numNumber of found configurations
Returns
list of filters received from hashmap or NULL

Definition at line 1275 of file dlt_offline_logstorage.c.

References config, dlt_logstorage_get_config(), and NULL.

Referenced by dlt_logstorage_write().

DltLogStorageConfigData** dlt_logstorage_get_config ( DltLogStorage handle,
char *  apid,
char *  ctid,
int *  num_config 
)

dlt_logstorage_get_config

Obtain the configuration data of all filters for provided apid and ctid For a given apid and ctid, there can be 3 possiblities of configuration data available in the Hash map, this function will return the address of configuration data for all these 3 combinations

Parameters
handleDltLogStorage handle
appidapplication id
ctxidcontext id
num_config(o/p) contains the number of filter configration data obtained
Returns
on success: address of configuration data, NULL on failure or no configuration data found

Definition at line 1195 of file dlt_offline_logstorage.c.

References config, DltLogStorage::config_htab, DltLogStorage::config_status, DltLogStorage::connection_type, DLT_ID_SIZE, dlt_logstorage_hash_find(), DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE, DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED, DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN, and NULL.

Referenced by dlt_daemon_logstorage_get_loglevel(), and dlt_logstorage_filter().

int dlt_logstorage_get_loglevel_by_key ( DltLogStorage handle,
char *  key 
)

dlt_logstorage_get_loglevel_by_key

Obtain the log level for the provided key This function can be used to obtain log level when the actual key stored in the Hash map is availble with the caller

Parameters
handleDltLogstorage handle
keykey to search for in Hash MAP
Returns
log level on success:, -1 on error

Definition at line 1165 of file dlt_offline_logstorage.c.

References config, DltLogStorage::config_htab, DltLogStorage::config_status, DltLogStorage::connection_type, dlt_logstorage_hash_find(), DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE, DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED, DltLogStorageConfigData::log_level, and NULL.

Referenced by dlt_daemon_logstorage_update_application_loglevel().

static int dlt_logstorage_hash_add ( char *  key,
void *  value,
struct hsearch_data *  htab 
)
static

Definition at line 61 of file dlt_offline_logstorage.c.

Referenced by dlt_logstorage_prepare_table().

static int dlt_logstorage_hash_create ( int  num_entries,
struct hsearch_data *  htab 
)
static

Definition at line 44 of file dlt_offline_logstorage.c.

Referenced by dlt_logstorage_load_config().

static int dlt_logstorage_hash_destroy ( struct hsearch_data *  htab)
static

Definition at line 54 of file dlt_offline_logstorage.c.

Referenced by dlt_logstorage_free().

static void* dlt_logstorage_hash_find ( char *  key,
struct hsearch_data *  htab 
)
static

Definition at line 75 of file dlt_offline_logstorage.c.

References NULL.

Referenced by dlt_logstorage_get_config(), and dlt_logstorage_get_loglevel_by_key().

int dlt_logstorage_load_config ( DltLogStorage handle)

dlt_logstorage_load_config

Read dlt_logstorage.conf file and setup filters in hash table Hash table key consists of "APPID:CTXID", e.g "APP1:CTX1". If wildcards used for application id or context id, the hash table key consists of none wildcard value, e.g. appid=.*, cxtid=CTX1 results in "CTX1".

Combination of two wildcards is not allowed.

Parameters
input_filepointer to configuration file stored on device
Returns
0 on success, -1 on error

Definition at line 1112 of file dlt_offline_logstorage.c.

References DltLogStorage::config_htab, DltLogStorage::config_status, DltLogStorage::connection_type, DltLogStorage::device_mount_point, dlt_log(), dlt_logstorage_hash_create(), dlt_logstorage_store_filters(), DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE, DLT_OFFLINE_LOGSTORAGE_CONFIG_FILE_NAME, DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED, DLT_OFFLINE_LOGSTORAGE_MAXFILTERS, and NULL.

Referenced by dlt_daemon_control_service_logstorage(), and dlt_daemon_logstorage_setup_internal_storage().

int dlt_logstorage_prepare_table ( DltLogStorage handle,
char *  appid,
char *  ctxid,
DltLogStorageConfigData tmp_data 
)

dlt_logstorage_prepare_table

Prepares hash table with keys and data

Parameters
handleDLT Logstorage handle
appidApplication ID value provided in configuration file
appidContext ID value provided in configuration file
tmp_dataHolds all other configuration values
Returns
0 on success, -1 on error

Definition at line 692 of file dlt_offline_logstorage.c.

References DltLogStorageConfigData::cache, DltLogStorage::config_data, DltLogStorage::config_htab, DltLogStorageConfig::data, dlt_log(), dlt_logstorage_create_keys(), dlt_logstorage_free(), dlt_logstorage_hash_add(), DLT_LOGSTORAGE_SYNC_ON_ERROR, DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN, DLT_OFFLINE_LOGSTORAGE_MAXFILTERS, DltLogStorageConfigData::ecuid, DltLogStorageConfigData::file_name, DltLogStorage::filter_keys, DltLogStorageConfig::key, DltLogStorageConfigData::log, NULL, DltLogStorage::num_filter_keys, and DltLogStorageConfigData::records.

Referenced by dlt_daemon_setup_filter_properties().

int dlt_logstorage_read_file_name ( char **  file_name,
char *  value 
)

dlt_logstorage_read_file_name

Evaluate if file name given in config file contains ".." , if not set file name

Parameters
file_namestring to store the file name
valuestring given in config file
Returns
0 on success, -1 on error

Definition at line 239 of file dlt_offline_logstorage.c.

References dlt_log(), and NULL.

Referenced by dlt_logstorage_validate_filter_value().

int dlt_logstorage_read_list_of_names ( char **  names,
char *  value 
)

dlt_logstorage_read_list_of_names

Evaluate app and ctx names given in config file and create a list of names acceptable by DLT Daemon When using SET_APPLICATION_NAME and SET_CONTEXT_NAME there is no constraint that these names have max 4 characters. Internally, these names are cutted down to max 4 chars. To have create valid keys, the internal representation of these names has to be considered. Therefore, a given configuration of "AppLogName = App1,Application2,A3" will be stored as "App1,Appl,A3".

Parameters
namesto store the list of names
valuestring given in config file
Returns
0 on success, -1 on error

Definition at line 125 of file dlt_offline_logstorage.c.

References dlt_logstorage_count_ids(), DLT_OFFLINE_LOGSTORAGE_MIN, and NULL.

Referenced by dlt_logstorage_validate_filter_value().

int dlt_logstorage_read_log_level ( int *  log_level,
char *  value 
)

dlt_logstorage_read_log_level

Evaluate log level given in config file and calculate log level as int

Parameters
log_levelto store the log level
valuestring given in config file
Returns
0 on success, -1 on error

Definition at line 189 of file dlt_offline_logstorage.c.

References dlt_log(), and NULL.

Referenced by dlt_logstorage_validate_filter_value().

int dlt_logstorage_read_number ( unsigned int *  number,
char *  value 
)

dlt_logstorage_read_number

Evaluate file size and number of files given in config file and set file size The file number is checked by converting a string to an unsigned integer width 0 > result < UINT_MAX (excludes 0!) Non-digit characters including spaces and out of boundary will lead to an error -1.

Parameters
file_namestring to store the file name
valuestring given in config file
Returns
0 on success, -1 on error

Definition at line 282 of file dlt_offline_logstorage.c.

References dlt_log(), and NULL.

Referenced by dlt_logstorage_validate_filter_value().

int dlt_logstorage_set_ecuid ( char **  ecuid,
char *  value 
)

dlt_logstorage_set_ecuid

Evaluate if ECU idenfifier given in config file

Parameters
ecuidstring to store the ecuid name
valuestring given in config file
Returns
0 on success, -1 on error

Definition at line 378 of file dlt_offline_logstorage.c.

References NULL.

Referenced by dlt_logstorage_validate_filter_value().

int dlt_logstorage_set_sync_strategy ( int *  strategy,
char *  value 
)

dlt_logstorage_set_sync_strategy

Evaluate sync strategy. The sync strategy is an optional filter configuration parameter. If the given value cannot be associated with a sync strategy, the default sync strategy will be assigned.

Parameters
file_nameint to store the sync strategy
valuestring given in config file
Returns
0 on success, -1 on error

Definition at line 331 of file dlt_offline_logstorage.c.

References dlt_log(), DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT, DLT_LOGSTORAGE_SYNC_ON_DEMAND, DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT, DLT_LOGSTORAGE_SYNC_ON_MSG, and NULL.

Referenced by dlt_logstorage_validate_filter_value().

int dlt_logstorage_store_filters ( DltLogStorage handle,
char *  config_file_name 
)

dlt_logstorage_store_filters

This function reads the filter keys and values and stores them into the hash map

Parameters
handleDLT Logstorage handle
config_file_nameConfiguration file name
Returns
0 on success, -1 on error

Definition at line 1030 of file dlt_offline_logstorage.c.

References config, DLT_CONFIG_FILE_ENTRY_MAX_LEN, dlt_config_file_get_num_sections(), dlt_config_file_get_section_name(), dlt_config_file_init(), dlt_config_file_release(), dlt_daemon_setup_filter_properties(), DLT_DAEMON_TEXTBUFSIZE, dlt_log(), dlt_logstorage_validate_filter_name(), DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR, DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR, GENERAL_BASE_NAME, and NULL.

Referenced by dlt_logstorage_load_config().

int dlt_logstorage_sync_caches ( DltLogStorage handle)

dlt_logstorage_sync_caches

Sync all caches inside the specified logstorage device.

Parameters
handleDltLogStorage handle
Returns
0 on success, -1 otherwise

Definition at line 1453 of file dlt_offline_logstorage.c.

References DltLogStorage::config_data, DltLogStorageConfig::data, dlt_log(), DltLogStorageConfigData::dlt_logstorage_sync, DLT_LOGSTORAGE_SYNC_ON_DEMAND, NULL, and DltLogStorage::num_filter_keys.

Referenced by dlt_daemon_logstorage_sync_cache().

int dlt_logstorage_validate_filter_name ( char *  name)

dlt_logstorage_validate_filter_name

Validates if the provided filter name is as required [FILTER<number>]

Parameters
nameFilter name
Returns
0 on success, -1 on error

Definition at line 860 of file dlt_offline_logstorage.c.

References DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION, and NULL.

Referenced by dlt_logstorage_store_filters().

int dlt_logstorage_validate_filter_value ( char *  filter_key,
char *  filter_value,
char **  appid,
char **  ctxid,
DltLogStorageConfigData tmp_data 
)

dlt_logstorage_validate_filter_value

This function analyzes the filter values and stores the values into provided input arguments Here appid and ctxid are used to hold application name and context name values provided in configuration file, all other configuration values are stored in tmp_data the caller can utilize the return values of this function to know when a complete filter set is read

Parameters
filter_keyFilter key read from configuration file
filter_valueFilter value read from configuration file
appidApplication ID value provided in configuration file
ctxidContext ID value provided in configuration file
tmp_dataHolds all other configuration values
Returns
Configuration value type on success, -1 on error

Definition at line 780 of file dlt_offline_logstorage.c.

References dlt_log(), dlt_logstorage_read_file_name(), dlt_logstorage_read_list_of_names(), dlt_logstorage_read_log_level(), dlt_logstorage_read_number(), dlt_logstorage_set_ecuid(), dlt_logstorage_set_sync_strategy(), DLT_OFFLINE_LOGSTORAGE_APP_INIT, DLT_OFFLINE_LOGSTORAGE_CTX_INIT, DLT_OFFLINE_LOGSTORAGE_ECUID, DLT_OFFLINE_LOGSTORAGE_LOG_LVL_INIT, DLT_OFFLINE_LOGSTORAGE_NAME_INIT, DLT_OFFLINE_LOGSTORAGE_NUM_INIT, DLT_OFFLINE_LOGSTORAGE_SIZE_INIT, DLT_OFFLINE_LOGSTORAGE_SYNC_BEHAVIOR, DltLogStorageConfigData::ecuid, DltLogStorageConfigData::file_name, DltLogStorageConfigData::file_size, DltLogStorageConfigData::log_level, DltLogStorageConfigData::num_files, and DltLogStorageConfigData::sync.

Referenced by dlt_daemon_setup_filter_properties().

int dlt_logstorage_write ( DltLogStorage handle,
DltLogStorageUserConfig uconfig,
unsigned char *  data1,
int  size1,
unsigned char *  data2,
int  size2,
unsigned char *  data3,
int  size3 
)

dlt_logstorage_write

Write a message to one or more configured log files, based on filter configuration.

Parameters
handleDltLogStorage handle
configUser configurations for log file
data1Data buffer of message header
size1Size of message header buffer
data2Data buffer of message body
size2Size of message body
Returns
0 on success or write errors < max write errors, -1 on error

Definition at line 1330 of file dlt_offline_logstorage.c.

References config, DltLogStorage::config_status, DltLogStorage::connection_type, DltLogStorage::device_mount_point, DLT_GET_MSIN_MTIN, DLT_ID_SIZE, DLT_IS_HTYP_WEID, DLT_IS_HTYP_WSID, DLT_IS_HTYP_WTMS, dlt_log(), dlt_logstorage_filter(), DltLogStorageConfigData::dlt_logstorage_prepare, DltLogStorageConfigData::dlt_logstorage_sync, DLT_LOGSTORAGE_SYNC_ON_MSG, DltLogStorageConfigData::dlt_logstorage_write, DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE, DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED, DLT_OFFLINE_LOGSTORAGE_MAX_WRITE_ERRORS, DLT_SIZE_WSID, DLT_SIZE_WTMS, NULL, and DltLogStorage::write_errors.

Referenced by dlt_daemon_logstorage_write().