Skip to content

Commit

Permalink
Chaned it to remove quote characters from path and fixed library
Browse files Browse the repository at this point in the history
  • Loading branch information
Black-Speedy committed Dec 21, 2023
1 parent 842eefe commit 4840abc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
2 changes: 2 additions & 0 deletions WebShare-Connect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions WebShare-Connect/WebShare-Connect.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "WebShare-Connect.h"
#include "server.h"
#include "client.h"
#include "removeQuotes.h"

int main(int argc, char const* argv[])
{
Expand All @@ -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
Expand Down
37 changes: 37 additions & 0 deletions WebShare-Connect/removeQuotes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <stdlib.h>
#include <stdio.h>
#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;
}
2 changes: 2 additions & 0 deletions WebShare-Connect/removeQuotes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
int containsQuotes(const char* str);
char *removeQuotes(char* str);

0 comments on commit 4840abc

Please sign in to comment.