summaryrefslogtreecommitdiff
path: root/src/dbus/dlt-dbus-options.c
diff options
context:
space:
mode:
authorLutz Helwing <lutz_helwing@mentor.com>2015-07-15 14:14:19 +0200
committerAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>2015-10-07 10:40:33 +0200
commit1236195e9b93aeb6bfa625956fa027f96003756d (patch)
tree07b08c892a486f9f97c1674e0d253099eb3388f3 /src/dbus/dlt-dbus-options.c
parent033a69218af3490f6be409f66f350c1568655f61 (diff)
downloadDLT-daemon-1236195e9b93aeb6bfa625956fa027f96003756d.tar.gz
DLT daemon improvement - dlt_init()-check
DLT daemon improvement - parameter value range check Adapt unit tests to check for enum return values Changed C version to gnu99 and C++ version to gnu++0c Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
Diffstat (limited to 'src/dbus/dlt-dbus-options.c')
-rw-r--r--src/dbus/dlt-dbus-options.c360
1 files changed, 180 insertions, 180 deletions
diff --git a/src/dbus/dlt-dbus-options.c b/src/dbus/dlt-dbus-options.c
index 3c75c62..27bf4f4 100644
--- a/src/dbus/dlt-dbus-options.c
+++ b/src/dbus/dlt-dbus-options.c
@@ -36,20 +36,20 @@
*/
void usage(char *prog_name)
{
- char version[255];
- dlt_get_version(version,255);
-
- printf("Usage: %s [options]\n", prog_name);
- printf("Application to forward dbus messages to DLT.\n");
- printf("%s\n", version);
- printf("Options:\n");
- printf(" -d Daemonize. Detach from terminal and run in background.\n");
- printf(" -c filename Use configuration file. \n");
- printf(" -a appid Used application id. \n");
- printf(" Default: %s\n", DEFAULT_CONF_FILE);
- printf(" -b type Used bus type. \n");
- printf(" Session = 0, System = 1.\n");
- printf(" -h This help message.\n");
+ char version[255];
+ dlt_get_version(version,255);
+
+ printf("Usage: %s [options]\n", prog_name);
+ printf("Application to forward dbus messages to DLT.\n");
+ printf("%s\n", version);
+ printf("Options:\n");
+ printf(" -d Daemonize. Detach from terminal and run in background.\n");
+ printf(" -c filename Use configuration file. \n");
+ printf(" -a appid Used application id. \n");
+ printf(" Default: %s\n", DEFAULT_CONF_FILE);
+ printf(" -b type Used bus type. \n");
+ printf(" Session = 0, System = 1.\n");
+ printf(" -h This help message.\n");
}
/**
@@ -57,10 +57,10 @@ void usage(char *prog_name)
*/
void init_cli_options(DltDBusCliOptions *options)
{
- options->ConfigurationFileName = DEFAULT_CONF_FILE;
- options->ApplicationId = 0;
- options->BusType = 0;
- options->Daemonize = 0;
+ options->ConfigurationFileName = DEFAULT_CONF_FILE;
+ options->ApplicationId = 0;
+ options->BusType = 0;
+ options->Daemonize = 0;
}
/**
@@ -68,53 +68,53 @@ void init_cli_options(DltDBusCliOptions *options)
*/
int read_command_line(DltDBusCliOptions *options, int argc, char *argv[])
{
- init_cli_options(options);
- int opt;
-
- while((opt = getopt(argc, argv, "c:b:a:hd")) != -1)
- {
- switch(opt) {
- case 'd':
- {
- options->Daemonize = 1;
- break;
- }
- case 'b':
- {
- options->BusType = malloc(strlen(optarg)+1);
- MALLOC_ASSERT(options->BusType);
- strcpy(options->BusType, optarg); /* strcpy unritical here, because size matches exactly the size to be copied */
- break;
- }
- case 'a':
- {
- options->ApplicationId = malloc(strlen(optarg)+1);
- MALLOC_ASSERT(options->ApplicationId);
- strcpy(options->ApplicationId, optarg); /* strcpy unritical here, because size matches exactly the size to be copied */
- break;
- }
- case 'c':
- {
- options->ConfigurationFileName = malloc(strlen(optarg)+1);
- MALLOC_ASSERT(options->ConfigurationFileName);
- strcpy(options->ConfigurationFileName, optarg); /* strcpy unritical here, because size matches exactly the size to be copied */
- break;
- }
- case 'h':
- {
- usage(argv[0]);
- exit(0);
+ init_cli_options(options);
+ int opt;
+
+ while((opt = getopt(argc, argv, "c:b:a:hd")) != -1)
+ {
+ switch(opt) {
+ case 'd':
+ {
+ options->Daemonize = 1;
+ break;
+ }
+ case 'b':
+ {
+ options->BusType = malloc(strlen(optarg)+1);
+ MALLOC_ASSERT(options->BusType);
+ strcpy(options->BusType, optarg); /* strcpy unritical here, because size matches exactly the size to be copied */
+ break;
+ }
+ case 'a':
+ {
+ options->ApplicationId = malloc(strlen(optarg)+1);
+ MALLOC_ASSERT(options->ApplicationId);
+ strcpy(options->ApplicationId, optarg); /* strcpy unritical here, because size matches exactly the size to be copied */
+ break;
+ }
+ case 'c':
+ {
+ options->ConfigurationFileName = malloc(strlen(optarg)+1);
+ MALLOC_ASSERT(options->ConfigurationFileName);
+ strcpy(options->ConfigurationFileName, optarg); /* strcpy unritical here, because size matches exactly the size to be copied */
+ break;
+ }
+ case 'h':
+ {
+ usage(argv[0]);
+ exit(0);
return -1;//for parasoft
- }
- default:
- {
- fprintf(stderr, "Unknown option '%c'\n", optopt);
- usage(argv[0]);
- return -1;
- }
- }
- }
- return 0;
+ }
+ default:
+ {
+ fprintf(stderr, "Unknown option '%c'\n", optopt);
+ usage(argv[0]);
+ return -1;
+ }
+ }
+ }
+ return 0;
}
/**
@@ -122,13 +122,13 @@ int read_command_line(DltDBusCliOptions *options, int argc, char *argv[])
*/
void init_configuration(DltDBusConfiguration *config)
{
- // Common
- config->ApplicationId = "IPC0";
+ // Common
+ config->ApplicationId = "IPC0";
- // DBus
- config->DBus.ContextId = "ALL";
- config->DBus.BusType = 0;
- config->DBus.FilterCount = 0;
+ // DBus
+ config->DBus.ContextId = "ALL";
+ config->DBus.BusType = 0;
+ config->DBus.FilterCount = 0;
}
@@ -137,114 +137,114 @@ void init_configuration(DltDBusConfiguration *config)
*/
int read_configuration_file(DltDBusConfiguration *config, char *file_name)
{
- FILE *file;
- char *line, *token, *value, *filter, *pch;
- int ret = 0;
- char *filterBegin,*filterEnd;
-
- init_configuration(config);
-
- file = fopen(file_name, "r");
-
- if(file == NULL)
- {
- fprintf(stderr, "dlt-dbus-options, could not open configuration file.\n");
- return -1;
- }
-
- line = malloc(MAX_LINE);
- token = malloc(MAX_LINE);
- value = malloc(MAX_LINE);
- filter = malloc(MAX_LINE);
-
- MALLOC_ASSERT(line);
- MALLOC_ASSERT(token);
- MALLOC_ASSERT(value);
- MALLOC_ASSERT(filter);
-
- while(fgets(line, MAX_LINE, file) != NULL)
- {
- token[0] = 0;
- value[0] = 0;
- filter[0] = 0;
-
- filterBegin = strchr(line,'=');
- filterEnd = strpbrk (line,"\r\n");
-
- if(filterBegin)
- {
- if(filterEnd && (filterEnd>filterBegin))
- {
- strncpy(filter,filterBegin+1,filterEnd-filterBegin-1);
- filter[filterEnd-filterBegin-1]=0;
- }
- else
- {
- strcpy(filter,filterBegin+1);
- }
- }
-
- pch = strtok (line, " =\r\n");
- while(pch != NULL)
- {
- if(pch[0] == '#')
- break;
-
- if(token[0] == 0)
- {
- strncpy(token, pch, MAX_LINE-1);
- token[MAX_LINE-1]=0;
- }
- else
- {
- strncpy(value, pch, MAX_LINE);
- value[MAX_LINE-1]=0;
- break;
- }
-
- pch = strtok (NULL, " =\r\n");
- }
-
- if(token[0] && value[0])
- {
- // Common
- if(strcmp(token, "ApplicationId") == 0)
- {
- config->ApplicationId = malloc(strlen(value)+1);
- MALLOC_ASSERT(config->ApplicationId);
- strcpy(config->ApplicationId, value); /* strcpy unritical here, because size matches exactly the size to be copied */
- }
- // ContextId
- else if(strcmp(token, "ContextId") == 0)
- {
- config->DBus.ContextId = malloc(strlen(value)+1);
- MALLOC_ASSERT(config->DBus.ContextId);
- strcpy(config->DBus.ContextId, value); /* strcpy unritical here, because size matches exactly the size to be copied */
- }
- // BusType
- else if(strcmp(token, "BusType") == 0)
- {
- config->DBus.BusType = malloc(strlen(value)+1);
- MALLOC_ASSERT(config->DBus.BusType);
- strcpy(config->DBus.BusType, value); /* strcpy unritical here, because size matches exactly the size to be copied */
- }
- // BusType
- else if(strcmp(token, "FilterMatch") == 0)
- {
- if(config->DBus.FilterCount<DLT_DBUS_FILTER_MAX)
- {
- config->DBus.FilterMatch[config->DBus.FilterCount]= malloc(strlen(filter)+1);
- MALLOC_ASSERT(config->DBus.FilterMatch[config->DBus.FilterCount]);
- strcpy(config->DBus.FilterMatch[config->DBus.FilterCount], filter);
- config->DBus.FilterCount++;
- }
- }
- }
- }
- fclose(file);
- free(value);
- free(token);
- free(filter);
- free(line);
- return ret;
+ FILE *file;
+ char *line, *token, *value, *filter, *pch;
+ int ret = 0;
+ char *filterBegin,*filterEnd;
+
+ init_configuration(config);
+
+ file = fopen(file_name, "r");
+
+ if(file == NULL)
+ {
+ fprintf(stderr, "dlt-dbus-options, could not open configuration file.\n");
+ return -1;
+ }
+
+ line = malloc(MAX_LINE);
+ token = malloc(MAX_LINE);
+ value = malloc(MAX_LINE);
+ filter = malloc(MAX_LINE);
+
+ MALLOC_ASSERT(line);
+ MALLOC_ASSERT(token);
+ MALLOC_ASSERT(value);
+ MALLOC_ASSERT(filter);
+
+ while(fgets(line, MAX_LINE, file) != NULL)
+ {
+ token[0] = 0;
+ value[0] = 0;
+ filter[0] = 0;
+
+ filterBegin = strchr(line,'=');
+ filterEnd = strpbrk (line,"\r\n");
+
+ if(filterBegin)
+ {
+ if(filterEnd && (filterEnd>filterBegin))
+ {
+ strncpy(filter,filterBegin+1,filterEnd-filterBegin-1);
+ filter[filterEnd-filterBegin-1]=0;
+ }
+ else
+ {
+ strcpy(filter,filterBegin+1);
+ }
+ }
+
+ pch = strtok (line, " =\r\n");
+ while(pch != NULL)
+ {
+ if(pch[0] == '#')
+ break;
+
+ if(token[0] == 0)
+ {
+ strncpy(token, pch, MAX_LINE-1);
+ token[MAX_LINE-1]=0;
+ }
+ else
+ {
+ strncpy(value, pch, MAX_LINE);
+ value[MAX_LINE-1]=0;
+ break;
+ }
+
+ pch = strtok (NULL, " =\r\n");
+ }
+
+ if(token[0] && value[0])
+ {
+ // Common
+ if(strcmp(token, "ApplicationId") == 0)
+ {
+ config->ApplicationId = malloc(strlen(value)+1);
+ MALLOC_ASSERT(config->ApplicationId);
+ strcpy(config->ApplicationId, value); /* strcpy unritical here, because size matches exactly the size to be copied */
+ }
+ // ContextId
+ else if(strcmp(token, "ContextId") == 0)
+ {
+ config->DBus.ContextId = malloc(strlen(value)+1);
+ MALLOC_ASSERT(config->DBus.ContextId);
+ strcpy(config->DBus.ContextId, value); /* strcpy unritical here, because size matches exactly the size to be copied */
+ }
+ // BusType
+ else if(strcmp(token, "BusType") == 0)
+ {
+ config->DBus.BusType = malloc(strlen(value)+1);
+ MALLOC_ASSERT(config->DBus.BusType);
+ strcpy(config->DBus.BusType, value); /* strcpy unritical here, because size matches exactly the size to be copied */
+ }
+ // BusType
+ else if(strcmp(token, "FilterMatch") == 0)
+ {
+ if(config->DBus.FilterCount<DLT_DBUS_FILTER_MAX)
+ {
+ config->DBus.FilterMatch[config->DBus.FilterCount]= malloc(strlen(filter)+1);
+ MALLOC_ASSERT(config->DBus.FilterMatch[config->DBus.FilterCount]);
+ strcpy(config->DBus.FilterMatch[config->DBus.FilterCount], filter);
+ config->DBus.FilterCount++;
+ }
+ }
+ }
+ }
+ fclose(file);
+ free(value);
+ free(token);
+ free(filter);
+ free(line);
+ return ret;
}