automotive-dlt
|
#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"
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) |
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.
For further information see http://www.genivi.org/. end@
Definition in file dlt_offline_logstorage.c.
#define DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR 1 |
Definition at line 38 of file dlt_offline_logstorage.c.
Referenced by dlt_daemon_setup_filter_properties(), and dlt_logstorage_store_filters().
#define DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR 2 |
Definition at line 39 of file dlt_offline_logstorage.c.
Referenced by dlt_daemon_setup_filter_properties(), and dlt_logstorage_store_filters().
#define GENERAL_BASE_NAME "General" |
Definition at line 41 of file dlt_offline_logstorage.c.
Referenced by dlt_logstorage_store_filters().
int dlt_daemon_setup_filter_properties | ( | DltLogStorage * | handle, |
DltConfigFile * | config_file, | ||
char * | sec_name | ||
) |
Definition at line 916 of file dlt_offline_logstorage.c.
References DLT_CONFIG_FILE_ENTRY_MAX_LEN, dlt_config_file_get_value(), dlt_log(), dlt_logstorage_filter_set_strategy(), dlt_logstorage_prepare_table(), DLT_LOGSTORAGE_SYNC_ON_MSG, dlt_logstorage_validate_filter_value(), DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR, DLT_OFFLINE_LOGSTORAGE_FILTER_INITIALIZED, DLT_OFFLINE_LOGSTORAGE_FILTER_PRESENT, DLT_OFFLINE_LOGSTORAGE_FILTER_UNINIT, DLT_OFFLINE_LOGSTORAGE_IS_FILTER_PRESENT, DLT_OFFLINE_LOGSTORAGE_MAX_KEY_NUM, DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR, DltLogStorageConfigData::ecuid, DltLogStorageConfigData::file_name, NULL, and DltLogStorageConfigData::sync.
Referenced by dlt_logstorage_store_filters().
int dlt_logstorage_count_ids | ( | const char * | str | ) |
Definition at line 89 of file dlt_offline_logstorage.c.
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
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".
[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 | ||
) |
dlt_logstorage_device_connected
Initializes DLT Offline Logstorage with respect to device status
handle | DLT Logstorage handle |
mount_point | Device mount path |
Definition at line 561 of file dlt_offline_logstorage.c.
References DltLogStorage::config_data, DltLogStorage::config_status, DltLogStorage::connection_type, DltLogStorage::device_mount_point, dlt_log(), dlt_logstorage_device_disconnected(), DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT, DLT_MOUNT_PATH_MAX, DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED, DltLogStorage::filter_keys, NULL, DltLogStorage::num_filter_keys, and DltLogStorage::write_errors.
Referenced by dlt_daemon_control_service_logstorage(), and dlt_daemon_logstorage_setup_internal_storage().
int dlt_logstorage_device_disconnected | ( | DltLogStorage * | handle, |
int | reason | ||
) |
dlt_logstorage_device_disconnected
De-Initializes DLT Offline Logstorage with respect to device status
handle | DLT Logstorage handle |
reason | Reason for disconnect |
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
appid | application id |
ctxid | context id |
log_level | Log level of message |
ecuid | EcuID given in the message |
num | Number of found configurations |
Definition at line 1275 of file dlt_offline_logstorage.c.
References config, dlt_logstorage_get_config(), and NULL.
Referenced by dlt_logstorage_write().
void dlt_logstorage_filter_set_strategy | ( | DltLogStorageConfigData * | config, |
int | strategy | ||
) |
Definition at line 889 of file dlt_offline_logstorage.c.
References DltLogStorageConfigData::dlt_logstorage_prepare, dlt_logstorage_prepare_msg_cache(), dlt_logstorage_prepare_on_msg(), DltLogStorageConfigData::dlt_logstorage_sync, dlt_logstorage_sync_msg_cache(), DLT_LOGSTORAGE_SYNC_ON_MSG, dlt_logstorage_sync_on_msg(), DltLogStorageConfigData::dlt_logstorage_write, dlt_logstorage_write_msg_cache(), dlt_logstorage_write_on_msg(), and NULL.
Referenced by dlt_daemon_setup_filter_properties().
void dlt_logstorage_free | ( | DltLogStorage * | handle, |
int | reason | ||
) |
dlt_logstorage_free
Free all allocated memory used in log storage handle
handle | DLT Logstorage handle |
reason | Reason for freeing the device |
Definition at line 600 of file dlt_offline_logstorage.c.
References DltLogStorageConfigData::cache, DltLogStorage::config_data, DltLogStorage::config_htab, DltLogStorageConfig::data, dlt_logstorage_hash_destroy(), DltLogStorageConfigData::dlt_logstorage_sync, DltLogStorageConfigData::ecuid, DltLogStorageConfigData::file_name, DltLogStorage::filter_keys, DltLogStorageConfigData::log, DltLogStorageFileList::name, DltLogStorageFileList::next, NULL, DltLogStorage::num_filter_keys, and DltLogStorageConfigData::records.
Referenced by dlt_logstorage_device_disconnected(), and dlt_logstorage_prepare_table().
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
handle | DltLogStorage handle |
appid | application id |
ctxid | context id |
num_config | (o/p) contains the number of filter configration data obtained |
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
handle | DltLogstorage handle |
key | key to search for in Hash MAP |
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 |
Definition at line 61 of file dlt_offline_logstorage.c.
Referenced by dlt_logstorage_prepare_table().
|
static |
Definition at line 44 of file dlt_offline_logstorage.c.
Referenced by dlt_logstorage_load_config().
|
static |
Definition at line 54 of file dlt_offline_logstorage.c.
Referenced by dlt_logstorage_free().
|
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.
input_file | pointer to configuration file stored on device |
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
handle | DLT Logstorage handle |
appid | Application ID value provided in configuration file |
appid | Context ID value provided in configuration file |
tmp_data | Holds all other configuration values |
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
file_name | string to store the file name |
value | string given in config file |
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".
names | to store the list of names |
value | string given in config file |
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
log_level | to store the log level |
value | string given in config file |
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.
file_name | string to store the file name |
value | string given in config file |
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
ecuid | string to store the ecuid name |
value | string given in config file |
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.
file_name | int to store the sync strategy |
value | string given in config file |
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
handle | DLT Logstorage handle |
config_file_name | Configuration file name |
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.
handle | DltLogStorage handle |
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>]
name | Filter name |
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
filter_key | Filter key read from configuration file |
filter_value | Filter value read from configuration file |
appid | Application ID value provided in configuration file |
ctxid | Context ID value provided in configuration file |
tmp_data | Holds all other configuration values |
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.
handle | DltLogStorage handle |
config | User configurations for log file |
data1 | Data buffer of message header |
size1 | Size of message header buffer |
data2 | Data buffer of message body |
size2 | Size of message body |
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().