This commit is contained in:
elvis
2022-04-24 13:03:00 +02:00

View File

@ -34,6 +34,31 @@
// #define ME "52" // not used // #define ME "52" // not used
#define MESE "55" // server error #define MESE "55" // server error
#define printOpenedFiles(str) \
fprintf(stdout, "\nInside of function: %s\n", __func__); \
fprintf(stdout, "\t[%s]\n", str); \
fprintf(stdout, "\tcreatedAndlocked: %s\n", openedFiles->createdAndLocked); \
fprintf(stdout, "\tf: %p\n", (void *)openedFiles->f); \
fprintf(stdout, "\tnumOfFiles: %d\n", openedFiles->numOfFiles); \
fprintf(stdout, "\tout: %p\n", (void *)openedFiles->out); \
fprintf(stdout, "\tvalidrDir: %d\n", openedFiles->validrDir); \
fprintf(stdout, "\trDir: %p\n", (void *)openedFiles->rDir); \
fprintf(stdout, "\tvalidwDir: %d\n", openedFiles->validwDir); \
fprintf(stdout, "\twDir: %p\n", (void *)openedFiles->wDir); \
fflush(stdout); \
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/* structs */ /* structs */
typedef struct files_s { typedef struct files_s {
@ -98,6 +123,9 @@ int createOpenedFiles(void);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
int openConnection(const char* sockname, int msec, const struct timespec abstime) { int openConnection(const char* sockname, int msec, const struct timespec abstime) {
printOpenedFiles("before");
if(!sockname){ if(!sockname){
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -150,10 +178,14 @@ int openConnection(const char* sockname, int msec, const struct timespec abstime
} }
strncpy(socketName, sockname, sizeof(socketName)-1); strncpy(socketName, sockname, sizeof(socketName)-1);
printOpenedFiles("after");
return 0; return 0;
} }
int closeConnection(const char* sockname) { int closeConnection(const char* sockname) {
printOpenedFiles("before");
if (!sockname || strncmp(socketName, sockname, sizeof(socketName)) != 0) { if (!sockname || strncmp(socketName, sockname, sizeof(socketName)) != 0) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -174,6 +206,9 @@ int closeConnection(const char* sockname) {
} }
int openFile(const char* pathname, int flags) { int openFile(const char* pathname, int flags) {
printOpenedFiles("before");
if(!pathname){ if(!pathname){
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -291,10 +326,15 @@ int openFile(const char* pathname, int flags) {
free(res); free(res);
free(cmd); free(cmd);
printOpenedFiles("after");
return 0; return 0;
} }
int readFile(const char* pathname, void** buf, size_t* size) { int readFile(const char* pathname, void** buf, size_t* size) {
printOpenedFiles("before");
if(!pathname) { if(!pathname) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -413,6 +453,9 @@ int readFile(const char* pathname, void** buf, size_t* size) {
} }
int readNFiles(int N, const char* dirname) { int readNFiles(int N, const char* dirname) {
printOpenedFiles("before");
if(!dirname) { if(!dirname) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -493,6 +536,7 @@ int readNFiles(int N, const char* dirname) {
} }
int writeFile(const char* pathname, const char* dirname) { int writeFile(const char* pathname, const char* dirname) {
printOpenedFiles("before");
if(!pathname) { if(!pathname) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -674,10 +718,14 @@ int writeFile(const char* pathname, const char* dirname) {
free(cmd); free(cmd);
free(content); free(content);
printOpenedFiles("after");
return 0; return 0;
} }
int appendToFile(const char* pathname, void* buf, size_t size, const char* dirname) { int appendToFile(const char* pathname, void* buf, size_t size, const char* dirname) {
printOpenedFiles("before");
if(!pathname || !buf) { if(!pathname || !buf) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -796,6 +844,7 @@ int appendToFile(const char* pathname, void* buf, size_t size, const char* dirna
} }
int lockFile(const char* pathname) { int lockFile(const char* pathname) {
printOpenedFiles("before");
if(!pathname){ if(!pathname){
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -893,6 +942,7 @@ _unlockFile: {
} }
int unlockFile(const char* pathname) { int unlockFile(const char* pathname) {
printOpenedFiles("before");
if(!pathname){ if(!pathname){
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -966,6 +1016,7 @@ int unlockFile(const char* pathname) {
} }
int closeFile(const char *pathname) { int closeFile(const char *pathname) {
printOpenedFiles("before");
if(!pathname){ if(!pathname){
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -1043,10 +1094,12 @@ int closeFile(const char *pathname) {
free(res); free(res);
free(cmd); free(cmd);
printOpenedFiles("after");
return 0; return 0;
} }
int removeFile(const char* pathname) { int removeFile(const char* pathname) {
printOpenedFiles("before");
if(!pathname){ if(!pathname){
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -1121,12 +1174,14 @@ int removeFile(const char* pathname) {
} }
free(cmd); free(cmd);
printOpenedFiles("after");
return 0; return 0;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
int setDirectory(char* Dir, int rw) { int setDirectory(char* Dir, int rw) {
printOpenedFiles("before");
if (!Dir) { if (!Dir) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -1149,6 +1204,7 @@ int setDirectory(char* Dir, int rw) {
openedFiles->rDir = malloc(strlen(Dir)+1); openedFiles->rDir = malloc(strlen(Dir)+1);
strncpy(openedFiles->rDir, Dir, strlen(Dir)+1); strncpy(openedFiles->rDir, Dir, strlen(Dir)+1);
} }
printOpenedFiles("after");
return 0; return 0;
} }
@ -1162,12 +1218,14 @@ void printInfo(int p, FILE *stream) {
} }
openedFiles->print = (p)? 1: 0; openedFiles->print = (p)? 1: 0;
openedFiles->out = stream; openedFiles->out = stream;
printOpenedFiles("after");
return; return;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
int reciveData(response_t *res, int expected) { int reciveData(response_t *res, int expected) {
printOpenedFiles("before");
if(!res) { if(!res) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -1415,6 +1473,7 @@ _nofile:
} }
int storeFilesInDirectory(const char *dirname, int n, recivedFile_t *rf) { int storeFilesInDirectory(const char *dirname, int n, recivedFile_t *rf) {
printOpenedFiles("before");
if(!dirname || strcmp(dirname, "") || !rf || n<0) { if(!dirname || strcmp(dirname, "") || !rf || n<0) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -1470,6 +1529,7 @@ int storeFilesInDirectory(const char *dirname, int n, recivedFile_t *rf) {
} }
free(basepath); free(basepath);
printOpenedFiles("after");
return 0; return 0;
} }
@ -1511,6 +1571,7 @@ int isOpen(const char *pathname) {
} }
int addOpenFile(const char *pathname) { int addOpenFile(const char *pathname) {
printOpenedFiles("before");
if(!pathname) { if(!pathname) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -1545,10 +1606,12 @@ int addOpenFile(const char *pathname) {
} }
tail->next = new; tail->next = new;
openedFiles->numOfFiles++; openedFiles->numOfFiles++;
printOpenedFiles("after");
return 0; return 0;
} }
int removeOpenFile(const char *pathname) { int removeOpenFile(const char *pathname) {
printOpenedFiles("before");
if(!pathname) { if(!pathname) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
@ -1588,6 +1651,7 @@ int removeOpenFile(const char *pathname) {
} }
int closeEveryFile() { int closeEveryFile() {
printOpenedFiles("before");
if (openedFiles == NULL) if (openedFiles == NULL)
return 0; return 0;
@ -1606,6 +1670,7 @@ int closeEveryFile() {
} }
} }
} }
if(openedFiles->createdAndLocked) { if(openedFiles->createdAndLocked) {
free(openedFiles->createdAndLocked); free(openedFiles->createdAndLocked);
openedFiles->createdAndLocked = NULL; openedFiles->createdAndLocked = NULL;
@ -1621,9 +1686,7 @@ int closeEveryFile() {
openedFiles->wDir = NULL; openedFiles->wDir = NULL;
} }
fprintf(stdout, "\nhere\n"); printOpenedFiles("after");
fflush(stdout);
return 0; return 0;
} }
@ -1642,5 +1705,7 @@ int createOpenedFiles(void) {
openedFiles->wDir = NULL; openedFiles->wDir = NULL;
openedFiles->print = 0; openedFiles->print = 0;
openedFiles->out = NULL; openedFiles->out = NULL;
printOpenedFiles("after");
return 0; return 0;
} }