diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d460a7..d857e78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) -project(libprozilla VERSION 1.2.1 LANGUAGES C) +project(libprozilla VERSION 1.2.2 LANGUAGES C) include(CTest) diff --git a/src/connection.c b/src/connection.c index bf020a6..dbc27c4 100644 --- a/src/connection.c +++ b/src/connection.c @@ -434,9 +434,7 @@ void proz_get_url_info_loop(connection_t * connection, pthread_t *thread) assert(connection); assert(thread); connection->running = TRUE; - pthread_create(thread, NULL, - (void *(*)(void *))get_url_info_loop, - (void *)connection); + pthread_create(thread, NULL, get_url_info_loop, connection); } /************************************************************************ @@ -444,8 +442,9 @@ void proz_get_url_info_loop(connection_t * connection, pthread_t *thread) handling conditions like redirection from http to ftp etc *************************************************************************/ -void get_url_info_loop(connection_t * connection) +void *get_url_info_loop(void *opaque) { + connection_t *connection = opaque; pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); /*TODO Should we try to make it broadcast a condition to the other threads? */ @@ -497,7 +496,7 @@ void get_url_info_loop(connection_t * connection) pthread_mutex_unlock(&connection->access_mutex); kfree(constructed_newloc); connection->err = HERR; - return; + return NULL; } else connection_show_message(connection, _("Redirected to => %s"), @@ -512,7 +511,7 @@ void get_url_info_loop(connection_t * connection) connection->running = FALSE; pthread_mutex_unlock(&connection->access_mutex); - return; + return NULL; } diff --git a/src/connection.h b/src/connection.h index f95f368..e05f0ac 100644 --- a/src/connection.h +++ b/src/connection.h @@ -54,7 +54,7 @@ void connection_show_message(connection_t * connection, const char *format, ...); void connection_calc_ratebps(connection_t * connection); void connection_throttle_bps(connection_t * connection); -void get_url_info_loop(connection_t * connection); +void *get_url_info_loop(void *opaque); size_t write_data_with_lock(connection_t *connection, const void *ptr, size_t size, size_t nmemb); #ifdef __cplusplus diff --git a/src/download.c b/src/download.c index 008ea59..490c22a 100644 --- a/src/download.c +++ b/src/download.c @@ -51,12 +51,9 @@ download_t *proz_download_init(urlinfo * u) memcpy(&download->u, u, sizeof(urlinfo)); - download->dl_dir = kmalloc(PATH_MAX); - download->output_dir = kmalloc(PATH_MAX); - download->log_dir = kmalloc(PATH_MAX); - strcpy(download->dl_dir, libprozrtinfo.dl_dir); - strcpy(download->output_dir, libprozrtinfo.output_dir); - strcpy(download->log_dir, libprozrtinfo.log_dir); + download->dl_dir = kstrdup(libprozrtinfo.dl_dir); + download->output_dir = kstrdup(libprozrtinfo.output_dir); + download->log_dir = kstrdup(libprozrtinfo.log_dir); download->resume_mode = FALSE; download->max_simul_connections = 0; @@ -188,8 +185,7 @@ int proz_download_setup_connections_no_ftpsearch(download_t * download, sizeof(http_stat_t)); - download->pconnections[i]->localfile = kmalloc(PATH_MAX); - strcpy(out_file, download->pconnections[i]->localfile); + download->pconnections[i]->localfile = kstrdup(out_file); download->pconnections[i]->fp = fp; @@ -839,17 +835,18 @@ void proz_download_join_downloads(download_t * download) { download->building = TRUE; pthread_create(&download->join_thread, NULL, - (void *(*)(void *))download_join_downloads, - (void *)download); + download_join_downloads, download); } /*This function will call download_join_downloads with a handler to join the downloaded files*/ -void download_join_downloads(download_t * download) +void *download_join_downloads(void *opaque) { + download_t *download = opaque; // pthread_cleanup_push(cleanup_joining_thread, (void *) download); join_downloads(download); // pthread_cleanup_pop(0); + return NULL; } /*This function will join the downloaded files*/ @@ -2067,8 +2064,7 @@ int proz_download_setup_connections_ftpsearch(download_t * download, - download->pconnections[i]->localfile = kmalloc(PATH_MAX); - strcpy(out_file, download->pconnections[i]->localfile); + download->pconnections[i]->localfile = kstrdup(out_file); download->pconnections[i]->fp = fp; diff --git a/src/download.h b/src/download.h index e0c53dd..0836fc0 100644 --- a/src/download.h +++ b/src/download.h @@ -40,7 +40,7 @@ void download_show_message(download_t * download, const char *format, int download_query_conns_status_count(download_t * download, dl_status status, char *server); -void download_join_downloads(download_t * download); +void *download_join_downloads(void *opaque); void join_downloads(download_t * download); void download_calc_throttle_factor(download_t * download); uerr_t download_handle_threads_ftpsearch(download_t * download); diff --git a/src/url.c b/src/url.c index 9b9a082..df9d72d 100644 --- a/src/url.c +++ b/src/url.c @@ -383,7 +383,7 @@ void path_simplify(char *path) break; } if (i) - strcpy(path, path + i - ddot); + memmove(path, path + i - ddot, strlen(path + i - ddot) + 1); /* Replace single `.' or `..' with `/'. */ if ((path[0] == '.' && path[1] == '\0') @@ -415,7 +415,7 @@ void path_simplify(char *path) if ((start + 1) != i) { - strcpy(path + start + 1, path + i); + memmove(path + start + 1, path + i, strlen(path + i) + 1); i = start + 1; } @@ -437,7 +437,7 @@ zero_last: /* Handle `./'. */ if (path[i + 1] == '/') { - strcpy(path + i, path + i + 1); + memmove(path + i, path + i + 1, strlen(path + i + 1) + 1); i = (start < 0) ? 0 : start; continue; } @@ -447,7 +447,8 @@ zero_last: { while (--start > -1 && path[start] != '/') ; - strcpy(path + start + 1, path + i + 2); + memmove(path + start + 1, path + i + 2, + strlen(path + i + 2) + 1); i = (start < 0) ? 0 : start; continue; } @@ -830,7 +831,7 @@ uerr_t proz_parse_url(const char *url, urlinfo * u, int strict) path_simplify(u->dir); /* Remove the leading `/' in HTTP. */ if ((type == URLHTTP || type == URLHTTPS) && *u->dir == '/') - strcpy(u->dir, u->dir + 1); + memmove(u->dir, u->dir + 1, strlen(u->dir + 1) + 1); /* Strip trailing `/'. */ l = strlen(u->dir); if (l > 1 && u->dir[l - 1] == '/')