2024-09-11 08:14:55 +00:00
|
|
|
#include"config.h"
|
|
|
|
#include<stdio.h>
|
|
|
|
#include<stdlib.h>
|
|
|
|
#include<string.h>
|
|
|
|
|
2024-09-18 11:18:29 +00:00
|
|
|
int loadConfig(char *str_file, char **str_entry,char **host,int *intervall,int size)
|
2024-09-11 08:14:55 +00:00
|
|
|
{
|
|
|
|
int i=0;
|
2024-10-08 15:07:08 +00:00
|
|
|
FILE *f_config;
|
2024-09-11 09:31:04 +00:00
|
|
|
char temp_str[256];
|
2024-09-19 06:46:57 +00:00
|
|
|
char *ret = NULL;
|
2024-09-11 08:14:55 +00:00
|
|
|
|
2024-10-08 15:07:08 +00:00
|
|
|
printf("\nopening config file\n");
|
|
|
|
f_config = fopen(str_file,"r");
|
|
|
|
if(f_config != NULL)
|
|
|
|
{
|
2024-09-19 06:46:57 +00:00
|
|
|
ret = fgets(temp_str,256,f_config);
|
|
|
|
while(ret!=NULL)
|
2024-09-16 10:39:50 +00:00
|
|
|
{
|
2024-09-16 11:10:54 +00:00
|
|
|
temp_str[strcspn(temp_str,"\n")]=0;
|
2024-09-18 11:18:29 +00:00
|
|
|
printf("first temp_str:%s\n",temp_str);
|
2024-09-16 11:10:54 +00:00
|
|
|
if(strcmp(temp_str,"[Host]")==0)
|
|
|
|
{
|
2024-09-18 11:18:29 +00:00
|
|
|
printf("temp_str host:%s\n",temp_str);
|
2024-09-19 06:46:57 +00:00
|
|
|
while(ret!=NULL)
|
2024-09-16 11:10:54 +00:00
|
|
|
{
|
2024-09-18 11:18:29 +00:00
|
|
|
printf("temp_str:%s\n",temp_str);
|
2024-09-19 06:46:57 +00:00
|
|
|
ret = fgets(temp_str,256,f_config);
|
2024-09-18 11:18:29 +00:00
|
|
|
if(strchr(temp_str,'[')==NULL)
|
2024-09-17 06:33:53 +00:00
|
|
|
{
|
2024-09-18 11:18:29 +00:00
|
|
|
printf("strchr\n");
|
|
|
|
if(strstr(temp_str,"Hostname")!=NULL)
|
|
|
|
{
|
|
|
|
char *ptr_host = strrchr(temp_str,'=')+1;//Without =
|
|
|
|
ptr_host[strcspn(ptr_host,"\n")]=0;
|
2024-10-08 15:02:53 +00:00
|
|
|
while(ptr_host[0]==' ') //Potential segfault??
|
2024-09-18 11:18:29 +00:00
|
|
|
{
|
2024-10-08 15:07:08 +00:00
|
|
|
if(ptr_host < (temp_str + strlen(temp_str)))
|
|
|
|
{
|
|
|
|
ptr_host = ptr_host + 1;
|
|
|
|
}else{
|
|
|
|
break;
|
|
|
|
}
|
2024-09-18 11:18:29 +00:00
|
|
|
}
|
|
|
|
*host = strdup(ptr_host);
|
|
|
|
printf("my host is:%s\n",*host);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
break;
|
2024-09-17 06:33:53 +00:00
|
|
|
}
|
2024-09-16 11:10:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(strcmp(temp_str,"[Services]")==0)
|
|
|
|
{
|
|
|
|
for(i=0;i<size;i++)
|
|
|
|
{
|
2024-09-19 06:46:57 +00:00
|
|
|
ret=fgets(temp_str,256,f_config);
|
2024-09-16 11:10:54 +00:00
|
|
|
printf("for loop:%d\n",i);
|
2024-09-19 06:46:57 +00:00
|
|
|
if(ret!=NULL)
|
2024-09-16 11:10:54 +00:00
|
|
|
{
|
|
|
|
if(strchr(temp_str,'[')==NULL)
|
|
|
|
{
|
|
|
|
temp_str[strcspn(temp_str,"\n")]=0;
|
|
|
|
str_entry[i]=strdup(temp_str);
|
|
|
|
printf("module path:%s",str_entry[i]);
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
2024-09-18 11:18:29 +00:00
|
|
|
}
|
2024-09-19 06:46:57 +00:00
|
|
|
|
2024-09-18 11:18:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(strcmp(temp_str,"[APP]")==0)
|
|
|
|
{
|
2024-09-19 06:46:57 +00:00
|
|
|
while(ret!=NULL)
|
2024-09-18 11:18:29 +00:00
|
|
|
{
|
2024-09-19 06:46:57 +00:00
|
|
|
ret = fgets(temp_str,256,f_config);
|
|
|
|
printf("temp_str:%s\n",temp_str);
|
2024-09-18 11:18:29 +00:00
|
|
|
if(strchr(temp_str,'[')==NULL)
|
|
|
|
{
|
|
|
|
if(strstr(temp_str,"Intervall")!=NULL)
|
|
|
|
{
|
|
|
|
char *ptr_intervall = strrchr(temp_str,'=')+1;//Without =
|
2024-09-19 06:46:57 +00:00
|
|
|
ptr_intervall[strcspn(ptr_intervall,"\n")]=0;
|
2024-09-18 11:18:29 +00:00
|
|
|
while(ptr_intervall[0]==' ')
|
|
|
|
{
|
|
|
|
ptr_intervall = ptr_intervall + 1;
|
|
|
|
}
|
|
|
|
*intervall = atoi(ptr_intervall);
|
|
|
|
printf("intervall:%d\n",*intervall);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
break;
|
2024-09-16 11:10:54 +00:00
|
|
|
}
|
|
|
|
}
|
2024-09-19 06:46:57 +00:00
|
|
|
}else{
|
|
|
|
ret = fgets(temp_str,256,f_config);
|
2024-09-16 11:10:54 +00:00
|
|
|
}
|
2024-10-08 15:07:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr,"error opening file[%s]\n",str_file);
|
|
|
|
}
|
2024-09-17 06:33:53 +00:00
|
|
|
printf("Done reading config file\n");
|
2024-10-08 15:07:08 +00:00
|
|
|
return 0;
|
2024-09-11 08:14:55 +00:00
|
|
|
}
|
2024-09-11 15:45:08 +00:00
|
|
|
/*int parseConfig(File *file, char *str_entry)
|
|
|
|
{
|
2024-10-08 15:07:08 +00:00
|
|
|
char sub_str[256];
|
|
|
|
if(strcmp(str_entry,"[Host]")==0)//section
|
|
|
|
{
|
|
|
|
fgets(sub_str,256,file);
|
2024-09-11 15:45:08 +00:00
|
|
|
|
2024-10-08 15:07:08 +00:00
|
|
|
//do sub parsing
|
|
|
|
}
|
2024-09-11 15:45:08 +00:00
|
|
|
}*/
|