Added add_site_entries

Added the function for adding static sites
Also remembered to close the files before exiting the download_entries
function
stable
Justin Reichardt 2021-08-26 15:58:35 -05:00
parent 20da1348fa
commit 7de6403f27
2 changed files with 44 additions and 0 deletions

View File

@ -22,6 +22,11 @@ int main(int argc, char *argv[]){
printf("%d - download_entries failed",rc);
return rc;
}
rc = add_site_entries(&entries);
if (rc != 0){
printf("%d - download_entries failed",rc);
return rc;
}
return 0;
}
@ -193,6 +198,44 @@ int download_entries(struct entry **entries){
// Here is where the download func should be called
}
}
fclose(tmpf);
fclose(tmpdf);
remove(TMPDOWNLOADLOCATION);
return 0;
}
int add_site_entries(struct entry **entries){
int i = (*entries)[0].entrytype;
int rc = 0;
FILE *tmpf;
tmpf = fopen(TMPLOCATION,"a");
if (tmpf == NULL){
return 1;
}
rc = fputs("# rhosts - static begin\n", tmpf);
if (rc == EOF){
printf("Failed to write to tmp file\n");
fclose(tmpf);
return 1;
}
for (;i >0 ; i--){
if ((*entries)[i].entrytype == CONTENTTYPE_SITE){
fprintf(tmpf, "0.0.0.0 %s\n:: %s\n", \
(*entries)[i].entry, \
(*entries)[i].entry);
}
}
rc = fputs("# rhosts - static end\n# rhosts end\n", tmpf);
if (rc == EOF){
printf("Failed to write to tmp file\n");
fclose(tmpf);
return 1;
}
fclose(tmpf);
return 0;
}

View File

@ -40,4 +40,5 @@ int closefile(FILE **file, char *location);
short int determine_config_entry_value(char *buff);
int preserve_static_entries();
int download_entries(struct entry **entries);
int add_site_entries(struct entry **entries);
#endif