Minor changes

This commit is contained in:
Loic Guegan 2023-07-15 15:27:34 +02:00
parent 0c0a6ebf44
commit ffbd3d0067
4 changed files with 42 additions and 8 deletions

5
.gitignore vendored
View file

@ -3,5 +3,6 @@
/publisher
/client
# Logs
/logs
# Caches
/logs
/cdata

View file

@ -8,7 +8,7 @@ all: publisher client logger
publisher: src/publisher.c src/utils.c
$(CC) -lzmq $^ -o $@
client: src/client.c
client: src/client.c src/utils.c
$(CC) -lzmq $^ -o $@
logger: src/logger.c src/utils.c

View file

@ -10,14 +10,18 @@
int main (int argc, char *argv [])
{
if(argc != 3){
printf("Usage: %s <address> <port>",argv[0]);
if(argc != 4){
printf("Usage: %s <address> <port> <cdatadir>",argv[0]);
exit(1);
}
//----- Arguments
char *ip=argv[1];
int port=atoi(argv[2]);
char *cdatadir=argv[3];
//----- Various inits
mkdirp(cdatadir);
//----- Init ZMQ
void *context = zmq_ctx_new ();
@ -38,7 +42,36 @@ int main (int argc, char *argv [])
while(1){
size=zmq_recv (subscriber, buffer, ZMQ_MSG_SIZE-1, 0);
buffer[size < ZMQ_MSG_SIZE ? size : ZMQ_MSG_SIZE - 1] = '\0';
printf("Received: %s\n",buffer);
//----- Read buffer
char *token = strtok(buffer, "\n");
char key[255];
char client[255];
long int interval;
FILE *fptr;
int line=1;
while(token != NULL){
if(line==2)
strcpy(key,token);
else if(line==3)
strcpy(client,token);
else if(line==4)
interval=atoi(token);
if(line==4){
char path[255]="";
sprintf(path,"%s/%s_%s_%ld",cdatadir,key,client,interval);
fptr=fopen(path,"a");
}
if(line>4){
fwrite(token, strlen(token), 1, fptr);
fwrite("\n",2,1,fptr);
}
token=strtok(NULL, "\n");
line++;
}
fclose(fptr);
}

View file

@ -79,7 +79,7 @@ int main (int argc, char *argv [])
void publish(void *publisher, char *filepath, char* client, long int interval){
printf("Publish!\n");
char buffer[ZMQ_MSG_SIZE];
sprintf(buffer,"%s\n%s\n%ld\n",ZMQ_TOKEN,__key,interval);
sprintf(buffer,"%s\n%s\n%s\n%ld\n",ZMQ_TOKEN,__key,client,interval);
int msglen=strlen(buffer);
FILE *fptr;
@ -93,7 +93,7 @@ void publish(void *publisher, char *filepath, char* client, long int interval){
msglen+=read;
} else {
zmq_send (publisher, buffer, ZMQ_MSG_SIZE, 0);
sprintf(buffer,"%s\n%s\n%ld\n",ZMQ_TOKEN,__key,interval);
sprintf(buffer,"%s\n%s\n%s\n%ld\n",ZMQ_TOKEN,__key,client,interval);
strcat(buffer,line);
msglen=strlen(buffer);
}