Begging of the menu
This commit is contained in:
parent
e933eec9d4
commit
afce4819d1
BIN
bin/KeyMaster
BIN
bin/KeyMaster
Binary file not shown.
Binary file not shown.
@ -40,7 +40,7 @@ char *prompNormalRequest(char *message)
|
||||
|
||||
temp = size(temp, 256);
|
||||
|
||||
printf("%s\n", message);
|
||||
printf("%s", message);
|
||||
scanf("%s", temp);
|
||||
|
||||
return temp;
|
||||
|
||||
72
src/main.c
72
src/main.c
@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <termios.h>
|
||||
#include <curl/curl.h> // 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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user