NULL terminate strncpy destination string
[dockapps/wmnotify.git] / src / configfile.c
index 1bd42e1..303ae16 100644 (file)
@@ -88,6 +88,10 @@ static void CreateDefaultConfigurationFile(char *file)
                "# Mail Check Interval (in minutes, default is 5 minutes).\n");
        fprintf(fp, "#mailcheckdelay 5\n\n");
        fprintf(fp, "# Default mail client (optional).\n");
+       fprintf(fp,
+               "# Manual mail check: 0=double-click, 1=single-click (optional, default is "
+               "1).\n");
+       fprintf(fp, "mailcheck_single_click 1\n\n");
        fprintf(fp, "#mailclient sylpheed\n\n");
        fprintf(fp,
                "# Audio notification, 0=disable, 1=enable (optional, default is "
@@ -198,6 +202,7 @@ static void ParseConfigurationFile(FILE *file)
        wmnotify_infos.mail_check_interval = 60; /* 1 minute interval. */
        wmnotify_infos.audible_notification = false; /* Disabled. */
        wmnotify_infos.use_ssl = false; /* Disabled. */
+       wmnotify_infos.mailcheck_single_click = 1;
        wmnotify_infos.mail_client_argv[0] = NULL; /* No default command. */
        wmnotify_infos.audiofile[0] = '\0'; /* No default audio file. */
        wmnotify_infos.volume = 100; /* 100% volume. */
@@ -266,8 +271,9 @@ static void ParseConfigurationFile(FILE *file)
                        }
                } else if (STREQ(token, "server")) {
                        token = GetArguments("server", true);
-                       strncpy(wmnotify_infos.server_name, token,
-                               MAX_STR_LEN);
+                       strncpy(wmnotify_infos.server_name, token, MAX_STR_LEN - 1);
+                        wmnotify_infos.server_name[
+                            sizeof(wmnotify_infos.server_name) - 1] = '\0';
                        server_found = true;
                } else if (STREQ(token, "port")) {
                        token = GetArguments("port", true);
@@ -277,13 +283,15 @@ static void ParseConfigurationFile(FILE *file)
 
                else if (STREQ(token, "username")) {
                        token = GetArguments("username", true);
-                       strncpy(wmnotify_infos.username, token,
-                               MAX_STR_LEN);
+                       strncpy(wmnotify_infos.username, token, MAX_STR_LEN - 1);
+                        wmnotify_infos.username[
+                            sizeof(wmnotify_infos.username) - 1] = '\0';
                        username_found = true;
                } else if (STREQ(token, "password")) {
                        token = GetArguments("password", true);
-                       strncpy(wmnotify_infos.password, token,
-                               MAX_STR_LEN);
+                       strncpy(wmnotify_infos.password, token, MAX_STR_LEN - 1);
+                        wmnotify_infos.password[
+                            sizeof(wmnotify_infos.password) - 1] = '\0';
                        password_found = true;
                } else if (STREQ(token, "mailcheckdelay")) {
                        int delay;      /* delay in minutes. */
@@ -302,6 +310,20 @@ static void ParseConfigurationFile(FILE *file)
                        }
                        wmnotify_infos.mail_check_interval =
                                (unsigned int)delay * 60;
+               } else if (STREQ(token, "mailcheck_single_click")) {
+                       int number;
+
+                       token = GetArguments("mailcheck_single_click", true);
+                       number = GetNumber(token, "mailcheck_single_click");
+                       if ((number == 0) || (number == 1)) {
+                               wmnotify_infos.mailcheck_single_click = number;
+                       } else {
+                               fprintf(stderr,
+                                       "%s: Invalid value for for parameter 'mailcheck_single_click' in\n"
+                                       "configuration file (must be 0 or 1): %d\n",
+                                       PACKAGE, number);
+                               exit(EXIT_FAILURE);
+                       }
                } else if (STREQ(token, "mailclient")) {
                        /* Multiple arguments */
                        token = GetArguments("mailclient", false);