// Dupelist.C - list text output of dupefile
// 02-24-99
// evilution @ EFnet

#include <strings.h>
#include <stdio.h>
#include <sys/time.h>
#include <errno.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>

struct dupefile {
  char filename[255];
  time_t timeup;
  char uploader[25];
};

char * read_conf_datapath ( char *rootpath ) {
  FILE *fp;
  char datapath[255];
  char temp[255];
  int size;
  if((fp = fopen("/etc/glftpd.conf", "r")) == NULL)
    return 0;

  while (fscanf(fp, "%s", temp) == 1) {
    if (strcmp(temp, "rootpath") == 0) {
      fscanf(fp, "%s", rootpath);
    }
    if (strcmp(temp, "datapath") == 0) {
      fscanf(fp, "%s", datapath);
      strcat(rootpath, datapath);
      return rootpath;
    }
  }
fclose(fp);
return 0;
}

int main (int argc, char *argv[]) {
  FILE *fp;
  char dupename[255], dupefile[255], Temp[255];
  struct dupefile buffer;
    
  read_conf_datapath(Temp);
  sprintf(dupefile, "%s/logs/dupefile", Temp);
  
  
  if((fp = fopen(dupefile, "r")) == NULL)
    return 0;

  while (!feof(fp)) {
    if (fread(&buffer, sizeof(struct dupefile), 1, fp) < 1)
      break;
    printf("%s\t%d\t%s\n", buffer.filename,buffer.timeup,buffer.uploader);
  }
fclose(fp);
return 0;
}
