-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.h
More file actions
98 lines (78 loc) · 2.73 KB
/
helper.h
File metadata and controls
98 lines (78 loc) · 2.73 KB
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
#ifndef MY_FUNCTIONS_H
#define MY_FUNCTIONS_H
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <pthread.h>
#include <sys/types.h>
#include <errno.h>
#include <stddef.h>
#define MAX_SIZE 1024
#define MAX_STORAGE 50 * 1024
#define MAX_FILES 100
#define MAX_FILENAME_SIZE 100
#define MAX_CONNECTIONS 2
typedef enum {
READ,
WRITE
} RequestType;
typedef struct {
RequestType type;
pthread_cond_t cond;
} Request;
typedef struct {
char userName[256];
int readCount;
int isWriting;
pthread_mutex_t mutex;
int connectionCount;
pthread_cond_t queueCond;
Request *requestQueue[MAX_CONNECTIONS];
int queueFront, queueBack;
} UserInfo;
extern UserInfo *users[MAX_CONNECTIONS];
extern int currentConnections;
extern pthread_mutex_t globalMutex;
extern pthread_cond_t connectionCond;
// queue structure
void enqueueRequest(UserInfo *user, Request *request);
Request *dequeueRequest(UserInfo *user);
void processQueue(UserInfo *user);
// user info funciton
UserInfo *getUserInfo(const char *userName);
// authenticate.c funcitons
void process_task_managment(int clientSocket, const char *userName);
void createUser(int clientSocket);
void authenticateUser(int clientSocket);
// queries.c funcitons
int viewFile(int clientSocket, const char *userName);
void sendFileToClient(int clientSocket, const char *userName);
void receiveFileFromClient(int clientSocket, const char *userName);
void delete_File_from_user_Config(int clientSocket, const char *userName, const char *fileName);
void receive_updated_file_content(int clientSocket, const char *userName);
// parsingData.c funcitons
int calculateSumOfSizes(int *sizes, int count);
int checkFileExists(char fileNames[MAX_FILES][MAX_FILENAME_SIZE], int fileCount, const char *inputFileName);
void receive_replace_able_file_content(int clientSocket, const char *userName, const char *fileNameParam);
void updateFileCount(int clientSocket, const char *userName, const char *targetFile);
void handleFileExists(int clientSocket, const char *fileName, const char *userName, const char *ActualFile);
int parseFileAfterAsterisk(const char *userName, char fileNames[MAX_FILES][MAX_FILENAME_SIZE], int *fileCount);
void write_FileInfo_to_user_Config(int clientSocket, const char *userName, const char *fileName, size_t fileSize);
// sync
void startRead(UserInfo *user);
void finishRead(UserInfo *user);
void startWrite(UserInfo *user);
void finishWrite(UserInfo *user);
// areena Memory
void *new_memory_request(int size);
int initialize_arena();
void *my_malloc(int size);
void free_memory(void *ptr);
void *my_remalloc(void *ptr, int size);
void collapse_free_memory();
#endif