Compare commits

..

No commits in common. "363e4fb05d71c86e3309132e706bf2f4d34d76cd" and "c42379fad69c22b954e3646d4b763648d41742e1" have entirely different histories.

4 changed files with 25 additions and 61 deletions

2
config
View File

@ -1,5 +1,3 @@
[APP]
Intervall = 5
[Host]
Hostname = https://5ccppi.org:4433
[Services]

View File

@ -3,7 +3,7 @@
#include<stdlib.h>
#include<string.h>
int loadConfig(char *str_file, char **str_entry,char **host,int *intervall,int size)
int loadConfig(char *str_file, char **str_entry,char **host,int size)
{
int i=0;
FILE *f_config;
@ -16,17 +16,9 @@ int loadConfig(char *str_file, char **str_entry,char **host,int *intervall,int s
while(fgets(temp_str,256,f_config)!=NULL)
{
temp_str[strcspn(temp_str,"\n")]=0;
printf("first temp_str:%s\n",temp_str);
if(strcmp(temp_str,"[Host]")==0)
{
printf("temp_str host:%s\n",temp_str);
while(fgets(temp_str,256,f_config)!=NULL)
{
printf("temp_str:%s\n",temp_str);
if(strchr(temp_str,'[')==NULL)
{
printf("strchr\n");
if(strstr(temp_str,"Hostname")!=NULL)
if(fgets(temp_str,256,f_config)!=NULL)
{
char *ptr_host = strrchr(temp_str,'=')+1;//Without =
ptr_host[strcspn(ptr_host,"\n")]=0;
@ -35,13 +27,8 @@ int loadConfig(char *str_file, char **str_entry,char **host,int *intervall,int s
ptr_host = ptr_host + 1;
}
*host = strdup(ptr_host);
//strncpy(host,ptr_host,256);
printf("my host is:%s\n",*host);
}else{
fprintf(stderr,"keyword Hostname not found in config");
}
}else{
break;
}
}
}
else if(strcmp(temp_str,"[Services]")==0)
@ -64,30 +51,7 @@ int loadConfig(char *str_file, char **str_entry,char **host,int *intervall,int s
else
{
break;
}
}
}
else if(strcmp(temp_str,"[APP]")==0)
{
while(fgets(temp_str,256,f_config)!=NULL)
{
if(strchr(temp_str,'[')==NULL)
{
if(strstr(temp_str,"Intervall")!=NULL)
{
char *ptr_intervall = strrchr(temp_str,'=')+1;//Without =
ptr_intervall[strcspn(ptr_intervall,"p\n")]=0;
while(ptr_intervall[0]==' ')
{
ptr_intervall = ptr_intervall + 1;
}
*intervall = atoi(ptr_intervall);
printf("intervall:%d\n",*intervall);
}else{
fprintf(stderr,"keyword Intervall not found in config");
}
}else{
break;
fclose(f_config);
}
}
}

View File

@ -1,2 +1,2 @@
int loadConfig(char *file, char **str_entry,char **host,int *intervall,int size);
int loadConfig(char *file, char **str_entry,char **host,int size);

26
main.c
View File

@ -36,19 +36,13 @@ int getPath(char *configPath,int size);
//gotify_message("https://5ccppi.org:4433/message?token=","anothertitle","anothermessage");
* */
int main(int argc,char *argv[])
{
DBusConnection *connection=NULL;
DBusError error;
clock_t time;
char *str_entry[64]={'\0'};
char *host=NULL;
int i=0;
int intervall=10;
Service services[64]={'\0'};
char *ptr_name=NULL;
char path[256];
time = clock();
@ -93,8 +87,11 @@ int main(int argc,char *argv[])
{
if(argc==3 && strcmp(argv[2],"-d")!=0)
{
loadConfig(argv[2],str_entry,&host,&intervall,64);
printf("[main]intervall:%d\n",intervall);
char *str_entry[64]={'\0'};
char *host=NULL;
int i=0;
loadConfig(argv[2],str_entry,&host,64);
for(i=0;str_entry[i];i++)
{
printf("entry in config:%s\n",str_entry[i]);
@ -104,13 +101,18 @@ int main(int argc,char *argv[])
else if(argc==3 && strcmp(argv[2],"-d")==0)
{
printf("Running as a daemon\n");
char *str_entry[64]={'\0'};
int i=0;
Service services[64]={'\0'};
char *ptr_name=NULL;
char path[256];
char *host=NULL;
getPath(path,256);
printf("[main]configPath:%s\n",path);
loadConfig(path,str_entry,&host,&intervall,64);
loadConfig(path,str_entry,&host,64);
printf("[main]host:%s\n",host);
printf("[main]intervall:%d\n",intervall);
for(i=0;str_entry[i];i++)
{
services[i].targetPath = strdup(str_entry[i]);
@ -138,7 +140,7 @@ int main(int argc,char *argv[])
printf("entry in config:%s\n",services[i].name);
ServiceGetSendStatus(connection,&services[i]);
}
sleep(intervall);
sleep(10);
}
}else
{