#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>

#ifndef WIN32
#include <unistd.h>
#endif

#include <dboxpath.h>
#include <config.h>

configt config;

void makepath(const std::string &_path)
 {
  char *path, *tptr;

  std::string checkpath=_path+".";
  if(access(checkpath.c_str(), 00)!=0)
   {
    path=strdup(_path.c_str());
    tptr=strrchr(path, DIRCHAR[0]);
    if(tptr!=NULL)
     {
      if(tptr[1]!=0) tptr[0]=0;
     }

    mkdir(path, 0700);

    free(path);
   }
 }

bool configt::read(const char *forcedboxname)
 {
  strmaxcpy(dboxdir, DKIMAP4DIR, TEXTLEN-1);

  midcount=0;
 
  if(forcedboxname[0]==0)
   {
    if(gethostname(boxname, TEXTLEN-1)!=0)
      boxname[0]=0;
   }
  else
    strmaxcpy(boxname, forcedboxname, TEXTLEN-1);

  domain[0]=0;
  boxdir[0]=0;

  umask(077);

  std::string path;
  makepath(config.dboxdir);
  getdboxsystemdir(path, config.dboxdir); makepath(path);
  getdboxtempdir(path, config.dboxdir); makepath(path);
  getdboxboxdir(path, config.dboxdir, config.boxname); makepath(path);
  strmaxcpy(config.boxdir, path.c_str(), DIRLEN-1);
  //getboxlogdir(path, config.boxdir); makepath(path);
  getboxlockdir(path, config.boxdir); makepath(path);
  getboxuserdir(path, config.boxdir, ""); makepath(path);

  return FALSE;
 }



syntax highlighted by Code2HTML, v. 0.9.1