Logo Search packages:      
Sourcecode: nbsmtp version File versions  Download package

int fileconfig_parse_all ( bool_t  read_syswide,
bool_t  read_localconf,
servinfo_t serverinfo 
)

Parses a list of possible configuration files, this function is meant to avoid another modules (such as original) having to deal with several fileconfig calls.

Parameters:
[in] read_syswide Whether to read system-wide config file or not
[in] read_localconf Whether to read local config file or not
[out] serverinfo servinfo_t pointer to save data
Returns:
1 in case of error, otherwise 0

Definition at line 53 of file fileconfig.c.

References fileconfig_parse(), and osx_location().

Referenced by parse_options().

{
      struct passwd *user;
      char *relative_paths[] = {".nbsmtprc",".mutt/nbsmtprc",".nbsmtp/nbsmtprc",NULL};
      char **p;
      char *local_tmp_buf;
      int state = 2;          /* Initialize to 2 so it allows the for to be executed */
#ifdef HAVE_OSX
      char *osx_current_location;
#endif

      if (read_syswide)
      {
            /* First of all parse system-wide config file */
            asprintf(&local_tmp_buf,"%s/nbsmtprc",SYSCONFDIR);
            if (fileconfig_parse(local_tmp_buf,serverinfo)==1)
            {
                  perror("fileconfig_parse");
                  return 1;
            }
            free(local_tmp_buf);
      }

      if (read_localconf)
      {
            /* Initialize user info */
            user = getpwuid(getuid());

            /* Then read local config files */
            for ( p = relative_paths ; *p && state==2 ; p++ )
            {
                  asprintf(&local_tmp_buf,"%s/%s",user->pw_dir,*p);
                  state = fileconfig_parse(local_tmp_buf,serverinfo);
                  free(local_tmp_buf);

                  if (state==1)
                  {
                        perror("fileconfig_parse");
                        return 1;
                  }
            }

#ifdef HAVE_OSX
            /* Get current OSX network location */
            osx_current_location = osx_location();
            /* Build the path and parse the config */
            asprintf(&local_tmp_buf,"%s/.nbsmtp/%s",user->pw_dir,osx_current_location);
            state = fileconfig_parse(local_tmp_buf,serverinfo);
            
            /* Free the buffers */
            free(osx_current_location);
            free(local_tmp_buf);

            if (state==1)
            {
                  perror("fileconfig_parse");
                  return 1;
            }
            else if (state==2)
            {
                  /*
                   * No such file or directory so read the default config file.
                   * build the string,
                   * parse the file
                   * and free the buffer
                   */
                  asprintf(&local_tmp_buf,"%s/.nbsmtp/default",user->pw_dir);
                  state = fileconfig_parse(local_tmp_buf,serverinfo);
                  free(local_tmp_buf);

                  if (state==1)
                  {
                        perror("fileconfig_parse");
                  }
            }
#endif
      }

      return 0;
}


Generated by  Doxygen 1.6.0   Back to index