-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader.h
executable file
·107 lines (90 loc) · 2.12 KB
/
header.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
_ _
/_ /_ _ /_/_ _/_ _ _/_/_
(_//_// // / / \/_'/_//_//_|/ / / *
/
(John Redpath)
01:198:352
SP2011
Lab 1
header.h
*/
#ifndef helper_H__
#define helper_H_
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <openssl/evp.h>
#include <dirent.h>
#include <time.h>
#include <signal.h>
#include <pthread.h>
#include <errno.h>
#define MAXFNLEN 256
#define MAXDIRLEN 256
#define HEADERSZ 24
#define MD5SZ 16
#define CODESZ 4
pthread_cond_t condition_cond = PTHREAD_COND_INITIALIZER;
char STOK [4] = {2,0,1,0};
char RSND[4]= {2,0,2,0};
char ABT[4]= {2,0,4,0};
char FIN[4]= {2,0,8,0};
void error(const char *msg)
{
perror(msg);
exit(1);
}
int code_cmp(char *str1, char *str2)
{
if(str1[0]==str2[0]&& str1[1]==str2[1]&& str1[2]==str2[2]&& str1[3]==str2[3])
return 0;
else
return -1;
}
char* convertmd5(char* string)
{
EVP_MD_CTX md5ctx;
unsigned char md5str[EVP_MAX_MD_SIZE];
int c = 0;
unsigned int md5strlen = MD5SZ;
char *output;
const EVP_MD *md;
if((output = (char*)malloc(sizeof(char)*MD5SZ))==NULL) err("MD5 memory\n");
OpenSSL_add_all_digests();
md = EVP_get_digestbyname("MD5");
EVP_MD_CTX_init(&md5ctx);
EVP_DigestInit_ex(&md5ctx, md, NULL);
EVP_DigestUpdate(&md5ctx, string, strlen(string));
EVP_DigestFinal_ex(&md5ctx, md5str, &md5strlen);
for(c = 0; c < md5strlen; c++)
output[c]=md5str[c];
EVP_MD_CTX_cleanup(&md5ctx);
return output;
}
typedef struct Meta_Struct
{
int filenamesz;
char filename[200];
int file_size;
time_t modified_time;
unsigned char update_status; // 1: Updated ; 0: Not updated
pthread_mutex_t mutex;
}MetaStruct;
typedef struct File_Time_Node { // A node used in keeping track of file updates. DW: Added mutex for updating.
char * filename;
time_t time;
int new;
pthread_mutex_t mutex;
struct File_Time_Node * next;
}FileTimeNode;
typedef struct File_Times_List { // Linked list comprised of above nodes
FileTimeNode * head;
}FileTimesList;
#endif