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] [Host]
Hostname = https://5ccppi.org:4433 Hostname = https://5ccppi.org:4433
[Services] [Services]

View File

@ -3,7 +3,7 @@
#include<stdlib.h> #include<stdlib.h>
#include<string.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; int i=0;
FILE *f_config; FILE *f_config;
@ -16,32 +16,19 @@ int loadConfig(char *str_file, char **str_entry,char **host,int *intervall,int s
while(fgets(temp_str,256,f_config)!=NULL) while(fgets(temp_str,256,f_config)!=NULL)
{ {
temp_str[strcspn(temp_str,"\n")]=0; temp_str[strcspn(temp_str,"\n")]=0;
printf("first temp_str:%s\n",temp_str);
if(strcmp(temp_str,"[Host]")==0) if(strcmp(temp_str,"[Host]")==0)
{ {
printf("temp_str host:%s\n",temp_str); if(fgets(temp_str,256,f_config)!=NULL)
while(fgets(temp_str,256,f_config)!=NULL)
{ {
printf("temp_str:%s\n",temp_str); char *ptr_host = strrchr(temp_str,'=')+1;//Without =
if(strchr(temp_str,'[')==NULL) ptr_host[strcspn(ptr_host,"\n")]=0;
while(ptr_host[0]==' ')
{ {
printf("strchr\n"); ptr_host = ptr_host + 1;
if(strstr(temp_str,"Hostname")!=NULL)
{
char *ptr_host = strrchr(temp_str,'=')+1;//Without =
ptr_host[strcspn(ptr_host,"\n")]=0;
while(ptr_host[0]==' ')
{
ptr_host = ptr_host + 1;
}
*host = strdup(ptr_host);
printf("my host is:%s\n",*host);
}else{
fprintf(stderr,"keyword Hostname not found in config");
}
}else{
break;
} }
*host = strdup(ptr_host);
//strncpy(host,ptr_host,256);
printf("my host is:%s\n",*host);
} }
} }
else if(strcmp(temp_str,"[Services]")==0) 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 else
{ {
break; break;
} fclose(f_config);
}
}
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;
} }
} }
} }

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