diff --git a/WebShare-Connect/CMakeLists.txt b/WebShare-Connect/CMakeLists.txt index a5a8c27..2b3318b 100644 --- a/WebShare-Connect/CMakeLists.txt +++ b/WebShare-Connect/CMakeLists.txt @@ -7,6 +7,7 @@ add_executable (WebShare-Connect "WebShare-Connect.c" "WebShare-Connect.h") # Ad add_library (sha512 "sha512.c" "sha512.h") add_library (server "server.c" "server.h") add_library (client "client.c" "client.h") +add_library (removeQuotes "removeQuotes.c" "removeQuotes.h") find_package(czmq CONFIG REQUIRED) find_package(ZeroMQ CONFIG REQUIRED) @@ -19,6 +20,7 @@ target_link_libraries(WebShare-Connect PRIVATE sha512) target_link_libraries(WebShare-Connect PRIVATE server) target_link_libraries(WebShare-Connect PRIVATE client) target_link_libraries(WebShare-Connect PRIVATE OpenSSL::SSL OpenSSL::Crypto) +target_link_libraries(WebShare-Connect PRIVATE removeQuotes) target_link_libraries(server PRIVATE czmq) target_link_libraries(server PRIVATE libzmq) target_link_libraries(sha512 PRIVATE OpenSSL::SSL OpenSSL::Crypto) diff --git a/WebShare-Connect/WebShare-Connect.c b/WebShare-Connect/WebShare-Connect.c index 5f7f6ce..5f04a3c 100644 --- a/WebShare-Connect/WebShare-Connect.c +++ b/WebShare-Connect/WebShare-Connect.c @@ -1,6 +1,7 @@ #include "WebShare-Connect.h" #include "server.h" #include "client.h" +#include "removeQuotes.h" int main(int argc, char const* argv[]) { @@ -21,14 +22,21 @@ int main(int argc, char const* argv[]) scanf("%3s", threads); printf("What is the file path?\n"); - char filePath[256]; // Adjust size according to your requirements + char filePath[256]; scanf("%255s", filePath); user_argv[0] = strdup(argv[0]); // Program name user_argv[1] = strdup(mode); user_argv[2] = strdup(port); user_argv[3] = strdup(threads); - user_argv[4] = strdup(filePath); + + if (containsQuotes(filePath)) { + printf("contains quotes and removing them\n"); + char* newFilePath = removeQuotes(filePath); + user_argv[4] = strdup(newFilePath); + } + else user_argv[4] = strdup(filePath); + if (strcmp(mode, "server") == 0) { return server_main(4, user_argv + 1); // 4 is the number of arguments in user_argv diff --git a/WebShare-Connect/removeQuotes.c b/WebShare-Connect/removeQuotes.c new file mode 100644 index 0000000..3b18dbc --- /dev/null +++ b/WebShare-Connect/removeQuotes.c @@ -0,0 +1,37 @@ +#include +#include +#include "removeQuotes.h" + + +int containsQuotes(const char* str) { + while (*str != '\0') { + if (*str == '"' || *str == '\'') { + return 1; + } + str++; + } + return 0; +} + +char* removeQuotes(const char* str) { + size_t len = strlen(str); + char* newStr = (char*)malloc(len + 1); // Allocate memory for the modified string + if (newStr == NULL) { + fprintf(stderr, "Memory allocation failed\n"); + exit(EXIT_FAILURE); + } + + const char* current = str; // Pointer for iteration + char* newStrPtr = newStr; // Pointer to build the modified string + + while (*current != '\0') { + if (*current != '"' && *current != '\'') { + *newStrPtr = *current; + newStrPtr++; + } + current++; + } + *newStrPtr = '\0'; // Null-terminate the modified string + + return newStr; +} \ No newline at end of file diff --git a/WebShare-Connect/removeQuotes.h b/WebShare-Connect/removeQuotes.h new file mode 100644 index 0000000..2518ee8 --- /dev/null +++ b/WebShare-Connect/removeQuotes.h @@ -0,0 +1,2 @@ +int containsQuotes(const char* str); +char *removeQuotes(char* str); \ No newline at end of file