38 #define DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR 1 39 #define DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR 2 41 #define GENERAL_BASE_NAME "General" 46 memset(htab, 0,
sizeof(*htab));
48 if (hcreate_r(num_entries, htab) == 0)
65 memset(&e, 0,
sizeof(ENTRY));
69 if (hsearch_r(e, ENTER, &ep, htab) == 0)
81 if (hsearch_r(e, FIND, &ep, htab) != 0)
156 *(names) = (
char *)calloc(num * 5,
sizeof(
char));
158 tok = strtok(value,
",");
166 strncpy((*names + y), tok, len);
167 if (num > 1 && i < num)
169 strncpy((*names + y + len),
",", 1);
174 tok = strtok(
NULL,
",");
197 if (strcmp(value,
"DLT_LOG_FATAL") == 0)
201 else if (strcmp(value,
"DLT_LOG_ERROR") == 0)
205 else if (strcmp(value,
"DLT_LOG_WARN") == 0)
209 else if (strcmp(value,
"DLT_LOG_INFO") == 0)
213 else if (strcmp(value,
"DLT_LOG_DEBUG") == 0)
217 else if (strcmp(value,
"DLT_LOG_VERBOSE") == 0)
224 dlt_log(LOG_ERR,
"Invalid log level \n");
243 if (value ==
NULL || strcmp(value,
"") == 0)
248 if (*file_name !=
NULL)
256 if (strstr(value,
"..") ==
NULL)
258 *file_name = calloc((len+1),
sizeof(
char));
259 strncpy(*file_name, value, len);
263 dlt_log(LOG_ERR,
"Invalid filename, .. is not accepted due to security issues \n");
286 unsigned long size = 0;
297 for (i = 0; i < len; i++)
299 if (isdigit(value[i] == 0))
301 dlt_log(LOG_ERR,
"Invalid, is not a number \n");
306 size = strtoul(value,
NULL, 10);
308 if (size == 0 || size > UINT_MAX)
310 dlt_log(LOG_ERR,
"Invalid, is not a number \n");
314 *number = (
unsigned int) size;
333 if (value ==
NULL || strategy ==
NULL)
338 if (strcasestr(value,
"ON_MSG") !=
NULL)
341 dlt_log(LOG_DEBUG,
"ON_MSG found, ignore other if added\n");
345 if (strcasestr(value,
"ON_DAEMON_EXIT") !=
NULL)
350 if (strcasestr(value,
"ON_DEMAND") !=
NULL)
355 if (strcasestr(value,
"ON_DEVICE_DISCONNECT") !=
NULL)
362 dlt_log(LOG_WARNING,
"Unknown sync strategies. Set default ON_MSG\n");
382 if (ecuid ==
NULL || value ==
NULL || value[0] ==
'\0')
394 *ecuid = calloc((len+1),
sizeof(
char));
395 strncpy(*ecuid, value, len);
434 char *save_aids =
NULL;
435 char *save_cids =
NULL;
445 if (appids ==
NULL || ctxids ==
NULL)
449 if ( strncmp(appids,
".*", 2) == 0 && strncmp(ctxids,
".*", 2) == 0 )
451 dlt_log(LOG_ERR,
"Error: Not allowed combination of wildcards\n");
455 aids = strdup(appids);
457 cids = (
char *) calloc(strlen(ctxids)+1,
sizeof(char));
467 *(num_keys) = num_appids * num_ctxids;
479 for (i = 1; i <= num_appids; i++)
481 char *tok_aids =
NULL;
482 char *tok_cids =
NULL;
484 if (num_appids > 1 && i == 1)
486 tok_aids = strtok_r(aids,
",", &save_aids);
488 else if (num_appids > 1 && i > 0)
490 tok_aids = strtok_r(
NULL,
",", &save_aids);
497 for (j = 1; j <= num_ctxids; j++)
499 if (num_ctxids > 1 && j == 1)
502 memcpy(cids, ctxids, strlen(ctxids));
503 tok_cids = strtok_r(cids,
",", &save_cids);
505 else if (num_ctxids > 1 && j > 0)
507 tok_cids = strtok_r(
NULL,
",", &save_cids);
514 if (strncmp(tok_aids,
".*", 2) == 0)
516 char curr_str[10] = { 0 };
517 strncpy(curr_str,
":", 1);
518 curr_len = strlen(tok_cids);
519 strncat(curr_str, tok_cids, curr_len);
520 curr_len = strlen(curr_str);
521 strncpy((*keys + (curr_key * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), curr_str, curr_len);
523 else if (strncmp(tok_cids,
".*", 2) == 0)
525 char curr_str[10] = { 0 };
526 curr_len = strlen(tok_aids);
527 strncpy(curr_str, tok_aids, curr_len);
528 strncat(curr_str,
":", 1);
529 curr_len = strlen(curr_str);
530 strncpy((*keys + (curr_key * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), curr_str, curr_len);
534 char curr_str[10] = { 0 };
535 curr_len = strlen(tok_aids);
536 strncpy(curr_str, tok_aids, curr_len);
537 strncat(curr_str,
":", 1);
538 curr_len = strlen(tok_cids);
539 strncat(curr_str, tok_cids, curr_len);
540 curr_len = strlen(curr_str);
541 strncpy((*keys + (curr_key * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)), curr_str, curr_len);
563 if((handle ==
NULL) || (mount_point ==
NULL))
565 dlt_log(LOG_ERR,
"dlt_logstorage_device_connected Error : Handle error \n");
571 dlt_log(LOG_ERR,
"dlt_logstorage_device_connected Error : Device already connected, \n");
572 dlt_log(LOG_ERR,
"Send disconnect, connect request \n");
712 dlt_log(LOG_ERR,
"Not able to create keys for hash table\n");
717 for (idx=0; idx<num_keys; idx++)
723 dlt_log(LOG_ERR,
"MAX filters reached \n");
746 dlt_log(LOG_ERR,
"Adding to hash table failed, returning failure\n");
781 char **appid,
char **ctxid,
786 if (strncmp(filter_key,
"LogAppName", strlen(
"LogAppName")) == 0)
792 else if (strncmp(filter_key,
"ContextName", strlen(
"ContextName")) == 0)
798 else if (strncmp(filter_key,
"LogLevel", strlen(
"LogLevel")) == 0)
804 else if (strncmp(filter_key,
"FileSize", strlen(
"FileSize")) == 0)
810 else if (strncmp(filter_key,
"File", strlen(
"File")) == 0)
816 else if (strncmp(filter_key,
"NOFiles", strlen(
"NOFiles")) == 0)
822 else if (strncmp(filter_key,
"SyncBehavior", strlen (
"SyncBehavior")) == 0)
830 else if (strncmp(filter_key,
"EcuID", strlen(
"EcuID")) == 0)
842 dlt_log(LOG_ERR,
"Invalid filter key");
846 dlt_log(LOG_ERR,
"Error in configuration file\n");
877 for (idx=6; idx<len-1; idx++)
879 if (!isdigit(name[idx]))
943 for (j = 0; j < num_filter_keys; j++)
951 strncmp(filter_section_key[j],
"SyncBehavior", strlen(filter_section_key[j]))
953 strncmp(filter_section_key[j],
"EcuID", strlen(filter_section_key[j]))
958 dlt_log(LOG_ERR,
"dlt_logstorage_store_filters Error : Reading filter value failed\n");
968 is_filter_set |= ret;
982 "Sync strategy not given. Use default ON_MSG\n");
999 dlt_log(LOG_ERR,
"dlt_logstorage_store_filters Error : Storing filter values failed\n");
1013 free(tmp_data.
ecuid);
1044 dlt_log(LOG_CRIT,
"Failed to open filter configuration file\n");
1050 for (sec = 0; sec < num_sec; sec++)
1056 dlt_log(LOG_CRIT,
"Failed to read section name\n");
1062 dlt_log(LOG_CRIT,
"General configuration not supported \n");
1087 "Unknown section: %s",
1089 dlt_log(LOG_WARNING, error_msg);
1114 char config_file_name[PATH_MAX + 1] = {
'\0'};
1123 dlt_log(LOG_ERR,
"dlt_logstorage_load_config Error : Device already configured\n");
1124 dlt_log(LOG_ERR,
"Send disconnect, connect request to re-configure \n");
1128 if(snprintf(config_file_name, PATH_MAX,
"%s/%s",
1132 dlt_log(LOG_ERR,
"dlt_logstorage_load_config Error : Device already configured\n");
1133 dlt_log(LOG_ERR,
"Send disconnect, connect request to re-configure \n");
1139 dlt_log(LOG_ERR,
"dlt_logstorage_load_config Error : Hash creation failed\n");
1145 dlt_log(LOG_ERR,
"dlt_logstorage_load_config Error : Storing filters failed\n");
1209 if ((apid ==
NULL) || (ctid ==
NULL))
1213 if (*(num_config) !=0)
1218 apid_len = strlen(apid);
1222 strncpy(key[0], apid, apid_len);
1223 strncat(key[0],
":",1);
1225 ctid_len = strlen(ctid);
1229 strncpy(key[1],
":", 1);
1230 strncat(key[1], ctid, ctid_len);
1232 strncpy(key[2], apid, apid_len);
1233 strncat(key[2],
":", 1);
1234 strncat(key[2], ctid, ctid_len);
1245 if (ptr_config !=
NULL)
1247 config[*(num_config)] = ptr_config;
1252 if (*(num_config) == 0)
1294 for (i = 0; i < *num; i++)
1297 if (log_level > config[i]->log_level)
1304 if (config[i]->ecuid !=
NULL)
1306 if (strncmp(ecuid, config[i]->ecuid, strlen(ecuid)) != 0)
1332 unsigned char *data1,
1334 unsigned char *data2,
1336 unsigned char *data3,
1346 DltExtendedHeader *extendedHeader;
1347 DltStandardHeaderExtra *extraHeader;
1348 DltStandardHeader *standardHeader;
1349 int standardHeaderExtraLen = 0;
1353 if (handle ==
NULL || uconfig ==
NULL ||
1361 standardHeader = (DltStandardHeader *)data2;
1362 standardHeaderExtraLen =
sizeof(DltStandardHeaderExtra);
1376 extendedHeader = (DltExtendedHeader *)(data2 +
1377 sizeof(DltStandardHeader) +
1378 standardHeaderExtraLen);
1379 extraHeader = (DltStandardHeaderExtra *)(data2 +
sizeof(DltStandardHeader));
1386 extendedHeader->apid,
1387 extendedHeader->ctid,
1397 if(config[i] !=
NULL)
1403 size1 + size2 + size3);
1422 "dlt_logstorage_write: Unable to sync.\n");
1435 "dlt_logstorage_write: Unable to write.\n");
1441 "dlt_logstorage_write: Unable to prepare.\n");
1472 "dlt_logstorage_sync_caches: Sync failed." 1473 " Continue with next cache.\n");
int dlt_config_file_get_section_name(const DltConfigFile *file, int num, char *name)
#define DLT_OFFLINE_LOGSTORAGE_FILTER_PRESENT
int dlt_logstorage_load_config(DltLogStorage *handle)
struct hsearch_data config_htab
int(* dlt_logstorage_write)(DltLogStorageConfigData *config, unsigned char *data1, int size1, unsigned char *data2, int size2, unsigned char *data3, int size3)
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)(DltLogStorageConfigData *config, int status)
int dlt_config_file_get_num_sections(const DltConfigFile *file, int *num)
#define DLT_OFFLINE_LOGSTORAGE_SIZE_INIT
static int dlt_logstorage_hash_create(int num_entries, struct hsearch_data *htab)
#define DLT_GET_MSIN_MTIN(msin)
#define DLT_CONFIG_FILE_ENTRY_MAX_LEN
DltConfigFile * dlt_config_file_init(char *file_name)
unsigned int connection_type
int dlt_logstorage_prepare_msg_cache(DltLogStorageConfigData *config, DltLogStorageUserConfig *file_config, char *dev_path, int log_msg_size)
static int dlt_logstorage_hash_destroy(struct hsearch_data *htab)
#define DLT_OFFLINE_LOGSTORAGE_SYNC_BEHAVIOR
DltLogStorageConfig * config_data
int dlt_logstorage_device_disconnected(DltLogStorage *handle, int reason)
DltLogStorageConfigData ** dlt_logstorage_filter(DltLogStorage *handle, char *appid, char *ctxid, char *ecuid, int log_level, int *num)
#define DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION
DltReturnValue dlt_log(int prio, char *s)
int dlt_logstorage_sync_on_msg(DltLogStorageConfigData *config, int status)
#define DLT_OFFLINE_LOGSTORAGE_APP_INIT
int dlt_logstorage_validate_filter_value(char *filter_key, char *filter_value, char **appid, char **ctxid, DltLogStorageConfigData *tmp_data)
int dlt_logstorage_write_on_msg(DltLogStorageConfigData *config, unsigned char *data1, int size1, unsigned char *data2, int size2, unsigned char *data3, int size3)
int dlt_logstorage_create_keys(char *appids, char *ctxids, char **keys, int *num_keys)
DltLogStorageFileList * records
int dlt_logstorage_count_ids(const char *str)
void dlt_logstorage_free(DltLogStorage *handle, int reason)
int dlt_daemon_setup_filter_properties(DltLogStorage *handle, DltConfigFile *config_file, char *sec_name)
#define DLT_OFFLINE_LOGSTORAGE_IS_FILTER_PRESENT(A)
#define DLT_MOUNT_PATH_MAX
#define DLT_OFFLINE_LOGSTORAGE_FILTER_UNINIT
#define DLT_OFFLINE_LOGSTORAGE_STORE_FILTER_ERROR
#define DLT_OFFLINE_LOGSTORAGE_NAME_INIT
int dlt_logstorage_sync_msg_cache(DltLogStorageConfigData *config, int status)
int dlt_logstorage_prepare_on_msg(DltLogStorageConfigData *config, DltLogStorageUserConfig *file_config, char *dev_path, int log_msg_size)
static int dlt_logstorage_hash_add(char *key, void *value, struct hsearch_data *htab)
int dlt_logstorage_read_file_name(char **file_name, char *value)
#define DLT_OFFLINE_LOGSTORAGE_MAX_KEY_NUM
#define DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED
int dlt_logstorage_read_number(unsigned int *number, char *value)
#define DLT_OFFLINE_LOGSTORAGE_MAXFILTERS
#define DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED
int dlt_logstorage_read_log_level(int *log_level, char *value)
int dlt_logstorage_write_msg_cache(DltLogStorageConfigData *config, unsigned char *data1, int size1, unsigned char *data2, int size2, unsigned char *data3, int size3)
DltLogStorageConfigData ** dlt_logstorage_get_config(DltLogStorage *handle, char *apid, char *ctid, int *num_config)
char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN]
#define DLT_IS_HTYP_WEID(htyp)
#define DLT_OFFLINE_LOGSTORAGE_LOG_LVL_INIT
int dlt_logstorage_store_filters(DltLogStorage *handle, char *config_file_name)
#define DLT_LOGSTORAGE_SYNC_ON_DEMAND
int dlt_config_file_get_value(const DltConfigFile *file, const char *section, const char *key, char *value)
#define DLT_IS_HTYP_WSID(htyp)
int dlt_logstorage_set_sync_strategy(int *strategy, char *value)
#define DLT_OFFLINE_LOGSTORAGE_MIN(A, B)
#define DLT_OFFLINE_LOGSTORAGE_CONFIG_FILE_NAME
char device_mount_point[DLT_MOUNT_PATH_MAX]
#define DLT_OFFLINE_LOGSTORAGE_MAX_WRITE_ERRORS
int dlt_logstorage_read_list_of_names(char **names, char *value)
unsigned int config_status
DltLogStorageConfigData data
#define DLT_OFFLINE_LOGSTORAGE_ECUID
int dlt_logstorage_sync_caches(DltLogStorage *handle)
#define DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT
#define DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN
int(* dlt_logstorage_prepare)(DltLogStorageConfigData *config, DltLogStorageUserConfig *file_config, char *dev_path, int log_msg_size)
#define DLT_LOGSTORAGE_SYNC_ON_ERROR
#define DLT_OFFLINE_LOGSTORAGE_NUM_INIT
int dlt_logstorage_validate_filter_name(char *name)
struct DltLogStorageFileList * next
#define DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT
static char str[DLT_DAEMON_TEXTBUFSIZE]
#define DLT_OFFLINE_LOGSTORAGE_CTX_INIT
int dlt_logstorage_set_ecuid(char **ecuid, char *value)
#define DLT_OFFLINE_LOGSTORAGE_FILTER_INITIALIZED(A)
int dlt_logstorage_get_loglevel_by_key(DltLogStorage *handle, char *key)
#define DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR
#define DLT_IS_HTYP_WTMS(htyp)
int dlt_logstorage_prepare_table(DltLogStorage *handle, char *appid, char *ctxid, DltLogStorageConfigData *tmp_data)
int dlt_logstorage_device_connected(DltLogStorage *handle, char *mount_point)
#define DLT_LOGSTORAGE_SYNC_ON_MSG
#define DLT_DAEMON_TEXTBUFSIZE
void dlt_logstorage_filter_set_strategy(DltLogStorageConfigData *config, int strategy)
void dlt_config_file_release(DltConfigFile *file)
#define DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE
#define GENERAL_BASE_NAME
static void * dlt_logstorage_hash_find(char *key, struct hsearch_data *htab)