diff --git a/KeyMaster b/KeyMaster new file mode 100755 index 0000000..bf03246 Binary files /dev/null and b/KeyMaster differ diff --git a/bin/KeyMaster b/bin/KeyMaster index ff08639..bf03246 100755 Binary files a/bin/KeyMaster and b/bin/KeyMaster differ diff --git a/build/CMakeFiles/KeyMaster.dir/src/main.c.o b/build/CMakeFiles/KeyMaster.dir/src/main.c.o index c2a1a16..17f6400 100644 Binary files a/build/CMakeFiles/KeyMaster.dir/src/main.c.o and b/build/CMakeFiles/KeyMaster.dir/src/main.c.o differ diff --git a/include/ui/ui.c b/include/ui/ui.c index 5494b98..a790bac 100644 --- a/include/ui/ui.c +++ b/include/ui/ui.c @@ -40,7 +40,7 @@ char *prompNormalRequest(char *message) temp = size(temp, 256); - printf("%s\n", message); + printf("%s", message); scanf("%s", temp); return temp; diff --git a/src/main.c b/src/main.c index 845d0f3..528058e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ #include #include #include +#include // Include libcurl header #include "herror.h" #include "dynmem.h" @@ -15,6 +16,49 @@ void clear_input_buffer(void) ; } +// Function to perform a GET request +void perform_get_request(const char *url) +{ + CURL *curl; + CURLcode res; + + curl_global_init(CURL_GLOBAL_DEFAULT); + curl = curl_easy_init(); + if (curl) + { + curl_easy_setopt(curl, CURLOPT_URL, url); + res = curl_easy_perform(curl); + if (res != CURLE_OK) + { + fprintf(stderr, "GET request failed: %s\n", curl_easy_strerror(res)); + } + curl_easy_cleanup(curl); + } + curl_global_cleanup(); +} + +// Function to perform a POST request +void perform_post_request(const char *url, const char *post_fields) +{ + CURL *curl; + CURLcode res; + + curl_global_init(CURL_GLOBAL_DEFAULT); + curl = curl_easy_init(); + if (curl) + { + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_fields); + res = curl_easy_perform(curl); + if (res != CURLE_OK) + { + fprintf(stderr, "POST request failed: %s\n", curl_easy_strerror(res)); + } + curl_easy_cleanup(curl); + } + curl_global_cleanup(); +} + int main(void) { char *password = create(char); @@ -109,32 +153,18 @@ int main(void) return 1; } end_try; - free(password); + + // Example usage of GET and POST requests + const char *get_url = "http://148.71.10.137:51820/"; + const char *post_fields = "field1=value1&field2=value2"; // Menu loop while (1) { - printf("1. Add a new password\n2. Show all passwords\n3. Exit\n"); - char *choice = prompNormalRequest("Enter your choice: "); - if (strcmp(choice, "1") == 0) - { - printf("Adding a new password\n"); - } - else if (strcmp(choice, "2") == 0) - { - printf("Showing all passwords\n"); - } - else if (strcmp(choice, "3") == 0) - { - printf("Exiting...\n"); - break; - } - else - { - printf("Invalid choice\n"); - } + + // Connect to the server and get the list of passwords tro HTTP GET free(choice); } - + free(password); return 0; } \ No newline at end of file