11/*
2- * API that is common between all network libraries… however requires network
3- * libs included first
2+ * Networking helper API
3+ *
4+ * Provides minimal networking-related helpers used throughout libacquire.
5+ * Does NOT implement fileutils functions (moved to acquire_fileutils.h).
46 * */
57
68#ifndef LIBACQUIRE_ACQUIRE_NET_COMMON_H
1012extern "C" {
1113#endif /* __cplusplus */
1214
13- #include "acquire_download.h"
14- #include "acquire_string_extras.h"
1515#include "acquire_common_defs.h"
1616
17- bool LIBACQUIRE_LIB_EXPORT is_downloaded (const char * url ,
17+ /**
18+ * Check if a file represented by URL is already downloaded locally and matches the checksum.
19+ *
20+ * @param url URL or filename
21+ * @param checksum checksum enum type, e.g., LIBACQUIRE_SHA256
22+ * @param hash expected hash string to verify
23+ * @param target_location directory to check in (if NULL, defaults to ".downloads")
24+ * @return true if already downloaded and checksum verifies, else false
25+ */
26+ extern LIBACQUIRE_LIB_EXPORT bool is_downloaded (const char * url ,
1827 enum Checksum checksum ,
1928 const char * hash ,
2029 const char * target_location );
@@ -26,34 +35,43 @@ bool LIBACQUIRE_LIB_EXPORT is_downloaded(const char *url,
2635const char * get_download_dir () { return ".downloads" ; }
2736#endif /* !DOWNLOAD_DIR_IMPL */
2837
38+ /**
39+ * Implementation of is_downloaded.
40+ * Uses fileutils functions for existence checks and checksum functions for verification.
41+ */
2942bool is_downloaded (const char * url , enum Checksum checksum , const char * hash ,
3043 const char * target_location ) {
3144 char full_local_fname [NAME_MAX + 1 ];
3245 const char * filename = is_url (url ) ? get_path_from_url (url ) : url ;
3346
34- if (target_location == NULL )
47+ if (target_location == NULL ) {
3548 target_location = get_download_dir ();
49+ }
3650
3751 if (filename == NULL || strlen (filename ) == 0 ||
38- !is_directory (target_location ))
52+ !is_directory (target_location )) {
3953 return false;
54+ }
4055
4156 snprintf (full_local_fname , NAME_MAX + 1 , "%s" PATH_SEP "%s" , target_location ,
4257 filename );
4358
44- if (!is_file (full_local_fname ))
59+ if (!is_file (full_local_fname )) {
4560 return false;
61+ }
4662
4763 switch (checksum ) {
4864 case LIBACQUIRE_SHA256 :
4965 return sha256 (full_local_fname , hash );
5066 case LIBACQUIRE_SHA512 :
51- /* return sha512(full_local_fname, hash); */
67+ // TODO: can add sha512 once implemented and enabled
68+ return false;
5269 case LIBACQUIRE_UNSUPPORTED_CHECKSUM :
5370 default :
5471 return false;
5572 }
5673}
74+
5775#endif /* LIBACQUIRE_IMPLEMENTATION */
5876
5977#ifdef __cplusplus
0 commit comments