Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include "config.h"
//creates new Domains and returns it
DOMAINS new_domains (){
DOMAINS ptr;
ptr=(DOMAINS) malloc (sizeof(Domains));
ptr->domain[0]='\0';
ptr->next=NULL;
return ptr;
}
//adds a new element at the end of ptr and returns it (returns NULL if ptr==NULL)
DOMAINS expand_domains (DOMAINS ptr){
if (ptr!=NULL){
while (ptr->next!=NULL){
printf("I'm a pointer!\n");
ptr=ptr->next;
}
ptr->next=new_domains(ptr->next);
return(ptr->next);
}
else{
return NULL;
}
}
void config_read(Config* p_config){
int i = 0;
char temp[256];
DOMAINS p_domains;
FILE *f = fopen("config.txt", "r");
//reading the number of threads
fscanf(f, "Threads = %d\n;", &(p_config->n_threads));
//just moving the scanner
fscanf(f, "Domains = ");
fgets(temp,256,f);
//reading the whitelisted domains
char* token = strtok(temp, "; ");
while(token!=NULL){
if (p_config->domain_list==NULL){
p_config->domain_list=new_domains();
p_domains=p_config->domain_list;
printf("There is no spoon\n");
}
else if (p_domains->next==NULL){
expand_domains(p_domains);
p_domains=p_domains->next;
printf("is this even working?\n");
}
strcpy(p_domains->domain, token);
token = strtok(NULL, "; ");
}
while(p_domains->domain[i] != '\n'){
i++;
}
p_domains->domain[i] = '\0';
fscanf(f, "LocalDomain = %[^\n]\n", p_config->local_domain);
fscanf(f, "NamedPipeEstatisticas = %[^\n]", p_config->Named_Pipe_Statistics);
fclose(f);
}
void config_start(){
Config* p_config=(Config*)malloc(sizeof(Config));
p_config->domain_list=NULL;
config_read(p_config);
printf("%d\n", p_config->n_threads);
printf("%s\n", p_config->domain_list->domain);
printf("%s\n", p_config->domain_list->next->domain);
printf("%s\n", p_config->local_domain);
printf("%s\n", p_config->Named_Pipe_Statistics);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.