<commit_before>#include "cloudbox.h"
#include "sglib.h"
/*
 * The list that holds all the current watched files.
 * 
 * It is very convenient this list to be shorted by the file name
 * in order to be able to find immediately inconsistencies,
 */
struct dir_files_status_list * watched_files;
char * watched_dir;

/*
 * Used to remove compiler warnings! 
 */
extern int alphasort();
extern char *strdup(const char *s);
extern int TCP_PORT;

/* Much more convenient to make the global
 * And share them between files using extern!
 */
int broadcast_port;
char *client_name;


#define UNUSED(x) (void)(x)
#define ILIST_COMPARATOR(e1, e2) (strcasecmp(e1->filename, e2->filename))
/*
 * Print mutex, for printing nicely the messages from different threads
 */
pthread_mutex_t print_mutex;


/* 
 * Mutex used to protect the accesses from different threads
 * of the file list of the watched directory
 */
pthread_mutex_t file_list_mutex;


/*
 * Decode UDP packet according to the given instructions!
 */
void udp_packet_decode(char * packet){
	struct dir_files_status_list *currTmp, *watchedTmp, *result;
	char pak[MAXBUF];
	char fileSHA[SHA1_BYTES_LEN];
	off_t file_len;
	off_t test; 
	time_t clk, mod_time;
	char client_name[255], file_name[255];
	uint16_t tcp_port;
	int count =3 , i=0;
	char tmp[2];
	
	/* First Decode each field and then print */
	memcpy(pak, packet,MAXBUF);
	tmp[0] = pak[0];
	tmp[1] = pak[1];
	
	if(pak[2] != 0)
		perror("Not a Valid Message Field Client_name\n");
	while(pak[count] != 0){
		client_name[i++] = pak[count++];
	}client_name[i] = '\0';
	count++;
	
	memcpy(&tcp_port, &pak[count], 2);
	count+=2;
	
	memcpy(&clk, &pak[count],8);
	count+=8;
	
	if( (tmp[0] >= 3) && (tmp[0] <= 7)){
		memcpy(&test, &pak[count], 8);
		mod_time = (time_t) test;
		count += 9;
		i=0;
		while(pak[count] != 0){
			file_name[i++] = pak[count++];
		}file_name[i] = '\0';
		count++;
		memcpy(fileSHA, &pak[count], SHA1_BYTES_LEN);
		count+=SHA1_BYTES_LEN;
		memcpy(&file_len, &pak[count], 8);
		count+=8;
		
	}
	/* Get the Lock and start printing!*/
	
	pthread_mutex_lock(&print_mutex);
	switch(tmp[0]){
		case(1):
			printf("\n\tSTATUS_MSG \n");
			break;
		case(2):
			printf("\n\tNO_CHANGES_MSG \n");
			break;
		case(3):
			printf("\n\tNEW_FILE_MSG \n");
			watchedTmp = watched_files;
			currTmp = (struct dir_files_status_list * ) malloc( sizeof (struct dir_files_status_list));
			currTmp->filename =strdup(file_name);
			SGLIB_LIST_FIND_MEMBER(struct dir_files_status_list, watchedTmp, currTmp, ILIST_COMPARATOR, next, result);
			if(result == NULL){
				printf("\n\tNOT FOUND\n");
			}
			
			break;
		case(4):
			printf("\n\tFILE_CHANGED_MSG \n");
			break;
		case(5):<commit_msg>Latest fixes<commit_after>#include "cloudbox.h"
#include "sglib.h"
/*
 * The list that holds all the current watched files.
 * 
 * It is very convenient this list to be shorted by the file name
 * in order to be able to find immediately inconsistencies,
 */
struct dir_files_status_list * watched_files;
char * watched_dir;

/*
 * Used to remove compiler warnings! 
 */
extern int alphasort();
extern char *strdup(const char *s);
extern int TCP_PORT;

/* Much more convenient to make the global
 * And share them between files using extern!
 */
int broadcast_port;
char *client_name;


#define UNUSED(x) (void)(x)
#define ILIST_COMPARATOR(e1, e2) (strcasecmp(e1->filename, e2->filename))
/*
 * Print mutex, for printing nicely the messages from different threads
 */
pthread_mutex_t print_mutex;


/* 
 * Mutex used to protect the accesses from different threads
 * of the file list of the watched directory
 */
pthread_mutex_t file_list_mutex;


/*
 * Decode UDP packet according to the given instructions!
 */
void udp_packet_decode(char * packet){
	struct dir_files_status_list *currTmp, *watchedTmp, *result;
	char pak[MAXBUF];
	char fileSHA[SHA1_BYTES_LEN];
	off_t file_len;
	off_t test; 
	time_t clk, mod_time;
	char client_name[255], file_name[255];
	uint16_t tcp_port;
	int count =3 , i=0;
	char tmp[2];
	
	/* First Decode each field and then print */
	memcpy(pak, packet,MAXBUF);
	tmp[0] = pak[0];
	tmp[1] = pak[1];
	
	if(pak[2] != 0)
		perror("Not a Valid Message Field Client_name\n");
	while(pak[count] != 0){
		client_name[i++] = pak[count++];
	}client_name[i] = '\0';
	count++;
	
	memcpy(&tcp_port, &pak[count], 2);
	count+=2;
	
	memcpy(&clk, &pak[count],8);
	count+=8;
	
	if( (tmp[0] >= 3) && (tmp[0] <= 7)){
		memcpy(&test, &pak[count], 8);
		mod_time = (time_t) test;
		count += 9;
		i=0;
		while(pak[count] != 0){
			file_name[i++] = pak[count++];
		}file_name[i] = '\0';
		count++;
		memcpy(fileSHA, &pak[count], SHA1_BYTES_LEN);
		count+=SHA1_BYTES_LEN;
		memcpy(&file_len, &pak[count], 8);
		count+=8;
		
	}
	/* Get the Lock and start printing!*/
	
	pthread_mutex_lock(&print_mutex);
	switch(tmp[0]){
		case(1):
			printf("\n\tSTATUS_MSG \n");
			break;
		case(2):
			printf("\n\tNO_CHANGES_MSG \n");
			break;
		case(3):
			printf("\n\tNEW_FILE_MSG \n");
			watchedTmp = watched_files;
			currTmp = (struct dir_files_status_list * ) malloc( sizeof (struct dir_files_status_list));
			currTmp->filename =strdup(file_name);
			SGLIB_LIST_FIND_MEMBER(struct dir_files_status_list, watchedTmp, currTmp, ILIST_COMPARATOR, next, result);
			if(result == NULL){
				printf("\n\tNOT FOUND\n");
				/* Ask for Transfer! */
				
			}
			free(currTmp);
			break;
		case(4):
			printf("\n\tFILE_CHANGED_MSG \n");
			break;
		case(5):
{'fraction_non_alphanumeric': 0.14816176470588235, 'fraction_numerical': 0.017279411764705883, 'mean_word_length': 4.241811175337187, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5469067', 'n_tokens_mistral': 2256, 'n_tokens_neox': 2058, 'n_words': 528}