Skip to content

Commit

Permalink
Add update system for store | Bug fix for curl and fat32
Browse files Browse the repository at this point in the history
  • Loading branch information
konect-V committed Jun 17, 2024
1 parent 475fa4e commit bae92d8
Show file tree
Hide file tree
Showing 17 changed files with 337 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@
"curl_memory.h": "c",
"apps.h": "c",
"download.h": "c",
"stdlib.h": "c"
"stdlib.h": "c",
"update.h": "c"
},
"files.exclude": {
"bundled": true,
Expand Down
93 changes: 86 additions & 7 deletions patches/curl/curl.patch
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
From 09dd7f9cdae6821aa50fee1e70054021b6e3d2fa Mon Sep 17 00:00:00 2001
From 7696a5a455df17e54a74f2508b289c340f46c928 Mon Sep 17 00:00:00 2001
From: konect-V <[email protected]>
Date: Fri, 31 May 2024 16:03:34 +0200
Subject: [PATCH 1/1] Port curl to kot
Date: Mon, 17 Jun 2024 13:11:56 +0200
Subject: [PATCH 1/1] Port to Kot

---
config.sub | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
config.sub | 2 +-
lib/vtls/openssl.c | 68 ----------------------------------------------
2 files changed, 1 insertion(+), 69 deletions(-)

diff --git a/config.sub b/config.sub
index dba16e8..dc0d387 100755
Expand All @@ -20,6 +21,84 @@ index dba16e8..dc0d387 100755
| bitrig* | openbsd* | secbsd* | solidbsd* | libertybsd* | os108* \
| ekkobsd* | freebsd* | riscix* | lynxos* | os400* \
| bosx* | nextstep* | cxux* | aout* | elf* | oabi* \
diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c
index a3953f6..f805048 100644
--- a/lib/vtls/openssl.c
+++ b/lib/vtls/openssl.c
@@ -1890,74 +1890,6 @@ static void ossl_close(struct Curl_cfilter *cf, struct Curl_easy *data)
DEBUGASSERT(backend);

if(backend->handle) {
- /* Send the TLS shutdown if we are still connected *and* if
- * the peer did not already close the connection. */
- if(cf->next && cf->next->connected && !connssl->peer_closed) {
- char buf[1024];
- int nread, err;
- long sslerr;
-
- /* Maybe the server has already sent a close notify alert.
- Read it to avoid an RST on the TCP connection. */
- ERR_clear_error();
- nread = SSL_read(backend->handle, buf, (int)sizeof(buf));
- err = SSL_get_error(backend->handle, nread);
- if(!nread && err == SSL_ERROR_ZERO_RETURN) {
- CURLcode result;
- ssize_t n;
- size_t blen = sizeof(buf);
- CURL_TRC_CF(data, cf, "peer has shutdown TLS");
- /* SSL_read() will not longer touch the socket, let's receive
- * directly from the next filter to see if the underlying
- * connection has also been closed. */
- n = Curl_conn_cf_recv(cf->next, data, buf, blen, &result);
- if(!n) {
- connssl->peer_closed = TRUE;
- CURL_TRC_CF(data, cf, "peer closed connection");
- }
- }
- ERR_clear_error();
- if(connssl->peer_closed) {
- /* As the peer closed, we do not expect it to read anything more we
- * may send. It may be harmful, leading to TCP RST and delaying
- * a lingering close. Just leave. */
- CURL_TRC_CF(data, cf, "not from sending TLS shutdown on "
- "connection closed by peer");
- }
- else if(SSL_shutdown(backend->handle) == 1) {
- CURL_TRC_CF(data, cf, "SSL shutdown finished");
- }
- else {
- nread = SSL_read(backend->handle, buf, (int)sizeof(buf));
- err = SSL_get_error(backend->handle, nread);
- switch(err) {
- case SSL_ERROR_NONE: /* this is not an error */
- case SSL_ERROR_ZERO_RETURN: /* no more data */
- CURL_TRC_CF(data, cf, "SSL shutdown, EOF from server");
- break;
- case SSL_ERROR_WANT_READ:
- /* SSL has send its notify and now wants to read the reply
- * from the server. We are not really interested in that. */
- CURL_TRC_CF(data, cf, "SSL shutdown sent");
- break;
- case SSL_ERROR_WANT_WRITE:
- CURL_TRC_CF(data, cf, "SSL shutdown send blocked");
- break;
- default:
- sslerr = ERR_get_error();
- CURL_TRC_CF(data, cf, "SSL shutdown, error: '%s', errno %d",
- (sslerr ?
- ossl_strerror(sslerr, buf, sizeof(buf)) :
- SSL_ERROR_to_str(err)),
- SOCKERRNO);
- break;
- }
- }
-
- ERR_clear_error();
- SSL_set_connect_state(backend->handle);
- }
-
SSL_free(backend->handle);
backend->handle = NULL;
}
--
2.34.1

2.43.0
2 changes: 1 addition & 1 deletion sources/core/apps/datetime/target/amd64/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ BIN = bin/usr/bin
LIB = lib

# Tools Config
CFLAGS =
CFLAGS = -Werror

LDFLAGS = -Wall \
-lc
Expand Down
2 changes: 1 addition & 1 deletion sources/core/apps/init/target/amd64/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ BIN = bin/system/init
LIB = lib

# Tools Config
CFLAGS =
CFLAGS = -Werror

LDFLAGS = -Wall \
-lc
Expand Down
2 changes: 1 addition & 1 deletion sources/core/apps/ip/target/amd64/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ BIN = bin/usr/bin
LIB = lib

# Tools Config
CFLAGS =
CFLAGS = -Werror

LDFLAGS = -Wall \
-lc
Expand Down
2 changes: 1 addition & 1 deletion sources/core/apps/llm/target/amd64/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ BIN = bin/usr/bin
LIB = lib

# Tools Config
CFLAGS =
CFLAGS = -Werror

LDFLAGS = -Wall \
-lc
Expand Down
11 changes: 8 additions & 3 deletions sources/core/apps/store/source/core/core.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <curl/curl.h>

#include "../apps/apps.h"
#include "../update/update.h"
#include "../install/install.h"

void print_help(){
Expand Down Expand Up @@ -54,7 +56,7 @@ int main(int argc, char *argv[]){
fgets(allow_install, sizeof(allow_install), stdin);
allow_install[strcspn(allow_install, "\n")] = 0;
if(!strcmp("Y", allow_install)){
install_app(curl, apps_available[index_to_install]->url, apps_available[index_to_install]->name);
install_app(curl, apps_available[index_to_install]->url, apps_available[index_to_install]->name, false);
}else{
printf("Cancel the installation\n");
}
Expand All @@ -80,7 +82,7 @@ int main(int argc, char *argv[]){
fgets(allow_install, sizeof(allow_install), stdin);
allow_install[strcspn(allow_install, "\n")] = 0;
if(!strcmp("Y", allow_install)){
install_app(curl, url, name);
install_app(curl, url, name, false);
}else{
printf("Cancel the installation\n");
}
Expand All @@ -102,14 +104,17 @@ int main(int argc, char *argv[]){
fgets(allow_install, sizeof(allow_install), stdin);
allow_install[strcspn(allow_install, "\n")] = 0;
if(!strcmp("Y", allow_install)){
install_app(curl, url, name);
install_app(curl, url, name, false);
}else{
printf("Cancel the installation\n");
}
free(url);
}else{
printf("Can't find %s in the store. Did you spell it correctly?\n", name);
}
}else if(!strcmp(argv[1], "--update") && argc == 3){
char* name = argv[2];
update_app(curl, name);
}else{
print_help();
}
Expand Down
4 changes: 2 additions & 2 deletions sources/core/apps/store/source/download/download.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ static int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow
}


int download_file(CURL* curl, char* url, char* path){
if(!is_file_exists(path)){
int download_file(CURL* curl, char* url, char* path, bool force_download){
if(!is_file_exists(path) || force_download){
printf("Initiating download of `%s` to `%s`\n", url, path);
int r = -1;
FILE* fp = fopen(path, "wb");
Expand Down
2 changes: 1 addition & 1 deletion sources/core/apps/store/source/download/download.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#include <stddef.h>
#include <curl/curl.h>

int download_file(CURL* curl, char* url, char* path);
int download_file(CURL* curl, char* url, char* path, bool force_download);

#endif // DOWNLOAD_H
6 changes: 3 additions & 3 deletions sources/core/apps/store/source/install/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static int create_dir_if_not_exist(char* path){
return 0;
}

int install_app(CURL* curl, char* url, char* name){
int install_app(CURL* curl, char* url, char* name, bool reinstall){
char* path_store = getenv("PATHSTORE");
create_dir_if_not_exist(path_store);

Expand All @@ -37,7 +37,7 @@ int install_app(CURL* curl, char* url, char* name){
strcpy(path_store_app_info_json, path_store_app);
strcat(path_store_app_info_json, "app-info.json");

if(download_file(curl, url, path_store_app_info_json)){
if(download_file(curl, url, path_store_app_info_json, reinstall)){
printf("Error: Aborting installation of %s!\n", name);

free(path_store_app_info_json);
Expand Down Expand Up @@ -82,7 +82,7 @@ int install_app(CURL* curl, char* url, char* name){
strcpy(path_store_installation_file, path_store_app);
strcat(path_store_installation_file, installation_file_name);

if(download_file(curl, installation_file_url, path_store_installation_file)){
if(download_file(curl, installation_file_url, path_store_installation_file, reinstall)){
printf("Error: Aborting installation of %s!\n", name);

remove(path_store_app_info_json);
Expand Down
2 changes: 1 addition & 1 deletion sources/core/apps/store/source/install/install.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#include <stddef.h>
#include <curl/curl.h>

int install_app(CURL* curl, char* url, char* name);
int install_app(CURL* curl, char* url, char* name, bool reinstall);

#endif // INSTALL_H
4 changes: 4 additions & 0 deletions sources/core/apps/store/source/untar/untar.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>

static int parseoct(const char *p, size_t n){
int i = 0;
Expand Down
Loading

0 comments on commit bae92d8

Please sign in to comment.