diff options
| -rw-r--r-- | src/licensing.c | 10 | ||||
| -rw-r--r-- | src/linux/platform.c | 92 |
2 files changed, 30 insertions, 72 deletions
diff --git a/src/licensing.c b/src/licensing.c index bcbca80..834313f 100644 --- a/src/licensing.c +++ b/src/licensing.c @@ -14,18 +14,10 @@ static void* validate_license_thread(void *arg) char response[MAX_INPUT_LENGTH]; if (platform_send_http_request("api.aldrik.org", params, response)) { - printf("yes\n"); cJSON *result = cJSON_Parse(response); - printf("%s\n", response); if (!result) return false; - printf("double yes\n"); cJSON *canRun = cJSON_GetObjectItem(result, "canRun"); license_is_valid = canRun->valueint; - printf("%s\n", response); - } - else - { - printf("failed to send request\n"); } return 0; @@ -36,7 +28,7 @@ void validate_license() license_is_valid = true; #ifdef MODE_DEVELOPER - //return; + return; #endif thread license_thread = thread_start(validate_license_thread, NULL); diff --git a/src/linux/platform.c b/src/linux/platform.c index eb3c55a..c775cf0 100644 --- a/src/linux/platform.c +++ b/src/linux/platform.c @@ -22,12 +22,6 @@ #include <sys/mman.h> #include <X11/cursorfont.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#include <openssl/ssl.h> - #define GET_ATOM(X) window.X = XInternAtom(window.display, #X, False) struct t_platform_window @@ -599,7 +593,6 @@ static void create_key_tables(platform_window window) XkbFreeKeyboard(desc, 0, True); } -SSL_CTX *ssl_ctx; inline void platform_init(int argc, char **argv) { #if 0 @@ -621,10 +614,6 @@ inline void platform_init(int argc, char **argv) get_directory_from_path(buf, binary_path); string_copyn(binary_path, buf, MAX_INPUT_LENGTH); - SSL_load_error_strings(); - SSL_library_init(); - ssl_ctx = SSL_CTX_new(SSLv23_client_method()); - assets_create(); } @@ -1612,60 +1601,37 @@ void platform_set_icon(platform_window *window, image *img) bool platform_send_http_request(char *url, char *params, char *response_buffer) { - // char *getRequest = "GET /path/to/server.aspx?Action=GetConfig&MachineName=node1 HTTP/1.1\n"; - // https://www.unix.com/programming/187337-c-http-get-request-using-sockets.html - // https://stackoverflow.com/questions/32738030/c-sending-http-get-request-in-linux - bool response = true; - - int sockfd, portno, n; - struct sockaddr_in serv_addr; - struct hostent *server; - - portno = 80; - sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (sockfd < 0) goto failure; + string_copyn(response_buffer, "", MAX_INPUT_LENGTH); + char buffer[128]; + FILE *fp = 0; + char command[MAX_INPUT_LENGTH]; - server = gethostbyname(url); - if (server == NULL) goto failure; + if (platform_file_exists("/bin/wget")) + { + sprintf(command, "/bin/wget -qO- https://%s/%s", url, params); + fp = popen(command, "r"); + } + else if (platform_file_exists("/usr/bin/wget")) + { + sprintf(command, "/usr/bin/wget -qO- https://%s/%s", url, params); + fp = popen(command, "r"); + } - bzero((char *) &serv_addr, sizeof(serv_addr)); - serv_addr.sin_family = AF_INET; - bcopy((char *)server->h_addr, - (char *)&serv_addr.sin_addr.s_addr, - server->h_length); - serv_addr.sin_port = htons(portno); - printf("1\n"); - if (connect(sockfd,(const struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0) goto failure; + if (fp == NULL) + { + return false; + } - SSL *conn = SSL_new(ssl_ctx); - SSL_set_fd(conn, sockfd); - printf("2\n"); - int err = SSL_connect(conn); - if (err != 1) goto failure; -printf("2.5\n"); - char buffer[MAX_INPUT_LENGTH]; - sprintf(buffer, "GET /%s HTTP/1.1\r\n" - "Host: %s\r\n" - "Connection: Keep-alive\r\n" - "Content-Type: application/json\r\n\r\n", params, url); - printf("%s\n", buffer); - n = SSL_write(conn,buffer,strlen(buffer)); - if (n < 0) goto failure; -printf("3\n"); - n = SSL_read(conn,response_buffer,MAX_INPUT_LENGTH); - if (n < 0) goto failure; -printf("4\n"); - goto done; - - failure: - printf("err %d\n", SSL_get_error(conn, err)); - printf("failure"); - response = false; - - done: - SSL_shutdown(conn); - SSL_free(conn); - close(sockfd); + while(!feof(fp)) + { + if (fgets(buffer, 128, fp) != NULL) + { + string_appendn(response_buffer, buffer, MAX_INPUT_LENGTH); + } + } - return response; + + /* close */ + pclose(fp); + return true; }
\ No newline at end of file |
