diff options
author | Xavier Roche <xroche@users.noreply.github.com> | 2014-05-02 15:13:29 +0000 |
---|---|---|
committer | Xavier Roche <xroche@users.noreply.github.com> | 2014-05-02 15:13:29 +0000 |
commit | 5544f503bf0fcfd050b4e338e8ec7b22e2f53b9a (patch) | |
tree | 2d65f1fd285c450cbb1c676697ad13b5a47a835c | |
parent | b3fa8537c411e6e2d53044b1d5d20c361d2ad17d (diff) |
Big cleanup in functions writing to a char buffer without proper size boundary.
-rw-r--r-- | src/htsback.c | 57 | ||||
-rw-r--r-- | src/htsbauth.c | 16 | ||||
-rw-r--r-- | src/htscache.c | 196 | ||||
-rw-r--r-- | src/htsconcat.c | 128 | ||||
-rw-r--r-- | src/htscore.c | 92 | ||||
-rw-r--r-- | src/htscore.h | 32 | ||||
-rw-r--r-- | src/htscoremain.c | 267 | ||||
-rw-r--r-- | src/htsencoding.h | 5 | ||||
-rw-r--r-- | src/htsftp.c | 4 | ||||
-rw-r--r-- | src/htsglobal.h | 13 | ||||
-rw-r--r-- | src/htshelp.c | 2 | ||||
-rw-r--r-- | src/htsindex.c | 10 | ||||
-rw-r--r-- | src/htsjava.c | 4 | ||||
-rw-r--r-- | src/htslib.c | 495 | ||||
-rw-r--r-- | src/htslib.h | 172 | ||||
-rw-r--r-- | src/htsname.c | 9 | ||||
-rw-r--r-- | src/htsparse.c | 95 | ||||
-rw-r--r-- | src/htsserver.c | 12 | ||||
-rw-r--r-- | src/htstools.c | 47 | ||||
-rw-r--r-- | src/htszlib.c | 8 | ||||
-rw-r--r-- | src/httrack-library.h | 95 | ||||
-rwxr-xr-x | src/proxy/proxystrings.h | 42 | ||||
-rw-r--r-- | src/proxy/store.c | 4 |
23 files changed, 939 insertions, 866 deletions
diff --git a/src/htsback.c b/src/htsback.c index e1419c6..2eab7d9 100644 --- a/src/htsback.c +++ b/src/htsback.c @@ -195,7 +195,7 @@ static int back_index_ready(httrackp * opt, struct_back * sback, char *adr, char *fileback = (char *) ptr; char catbuff[CATBUFF_SIZE]; - if ((fp = FOPEN(fconv(catbuff, fileback), "rb")) != NULL) { + if ((fp = FOPEN(fconv(catbuff, sizeof(catbuff), fileback), "rb")) != NULL) { if (back_unserialize(fp, &itemback) != 0) { if (itemback != NULL) { back_clear_entry(itemback); @@ -640,7 +640,7 @@ int back_finalize(httrackp * opt, cache_back * cache, struct_back * sback, fclose(fp); fp = NULL; // remove (temporary) file! - UNLINK(fconv(catbuff, back[p].url_sav)); + UNLINK(fconv(catbuff, sizeof(catbuff), back[p].url_sav)); } if (fp) fclose(fp); @@ -765,27 +765,27 @@ int back_finalize(httrackp * opt, cache_back * cache, struct_back * sback, } } if (cache->txt) { +#undef ESC_URL +#define ESC_URL(S) escape_check_url_addr(S, OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt)) fprintf(cache->txt, "%d\t" "%s ('%s')\t" "%s\t" "%s%s\t" "%s%s%s\t%s\t" "(from %s%s%s)" LF, back[p].r.statuscode, state, - escape_check_url_addr(OPT_GET_BUFF(opt), back[p].r.msg), - escape_check_url_addr(OPT_GET_BUFF(opt), - back[p].r.contenttype), - ((back[p].r. - etag[0]) ? "etag:" : ((back[p].r. + ESC_URL(back[p].r.msg), + ESC_URL(back[p].r.contenttype), + ((back[p].r.etag[0]) ? "etag:" : ((back[p].r. lastmodified[0]) ? "date:" : "")), - escape_check_url_addr(OPT_GET_BUFF(opt), - (back[p].r.etag[0]) ? back[p].r. + ESC_URL((back[p].r.etag[0]) ? back[p].r. etag : (back[p].r.lastmodified)), (link_has_authority(back[p].url_adr) ? "" : "http://"), - escape_check_url_addr(OPT_GET_BUFF(opt), back[p].url_adr), - escape_check_url_addr(OPT_GET_BUFF(opt), back[p].url_fil), - escape_check_url_addr(OPT_GET_BUFF(opt), back[p].url_sav), + ESC_URL(back[p].url_adr), + ESC_URL(back[p].url_fil), + ESC_URL(back[p].url_sav), (link_has_authority(back[p].referer_adr) || !back[p].referer_adr[0]) ? "" : "http://", - escape_check_url_addr(OPT_GET_BUFF(opt), back[p].referer_adr), - escape_check_url_addr(OPT_GET_BUFF(opt), back[p].referer_fil) + ESC_URL(back[p].referer_adr), + ESC_URL(back[p].referer_fil) ); +#undef ESC_URL if (opt->flush) fflush(cache->txt); } @@ -985,7 +985,7 @@ int back_serialize_ref(httrackp * opt, const lien_back * src) { if (fp == NULL) { #ifdef _WIN32 if (mkdir - (fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), CACHE_REFNAME)) + (fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), CACHE_REFNAME)) == 0) #else if (mkdir @@ -1504,7 +1504,8 @@ int back_add(struct_back * sback, httrackp * opt, cache_back * cache, char *adr, if (cache->cached_tests != NULL) { intptr_t ptr = 0; - if (inthash_read(cache->cached_tests, concat(OPT_GET_BUFF(opt), adr, fil), &ptr)) { // gotcha + if (inthash_read(cache->cached_tests, + concat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), adr, fil), &ptr)) { // gotcha if (ptr != 0) { char *text = (char *) ptr; char *lf = strchr(text, '\n'); @@ -1571,7 +1572,7 @@ int back_add(struct_back * sback, httrackp * opt, cache_back * cache, char *adr, if (pos < 0) { // pas de mise en cache data, vérifier existence #endif /* note: no check with IS_DELAYED_EXT() enabled - postcheck by client please! */ - if (save[0] != '\0' && !IS_DELAYED_EXT(save) && fsize_utf8(fconv(catbuff, save)) <= 0) { // fichier final n'existe pas ou est vide! + if (save[0] != '\0' && !IS_DELAYED_EXT(save) && fsize_utf8(fconv(catbuff, sizeof(catbuff), save)) <= 0) { // fichier final n'existe pas ou est vide! int found = 0; /* It is possible that the file has been moved due to changes in build structure */ @@ -1589,10 +1590,10 @@ int back_add(struct_back * sback, httrackp * opt, cache_back * cache, char *adr, if (r.is_write && previous_save[0] != '\0') { /* Exists, but with another (old) filename: rename (almost) silently */ if (strcmp(previous_save, save) != 0 - && fexist_utf8(fconv(catbuff, previous_save))) { - rename(fconv(catbuff, previous_save), - fconv(catbuff2, save)); - if (fexist_utf8(fconv(catbuff, save))) { + && fexist_utf8(fconv(catbuff, sizeof(catbuff), previous_save))) { + rename(fconv(catbuff, sizeof(catbuff), previous_save), + fconv(catbuff2, sizeof(catbuff2), save)); + if (fexist_utf8(fconv(catbuff, sizeof(catbuff), save))) { found = 1; hts_log_print(opt, LOG_DEBUG, "File '%s' has been renamed since last mirror to '%s' ; applying changes", @@ -1618,8 +1619,8 @@ int back_add(struct_back * sback, httrackp * opt, cache_back * cache, char *adr, // sinon, le fichier est ok à priori, mais on renverra un if-modified-since pour // en être sûr if (opt->norecatch) { // tester norecatch - if (!fexist_utf8(fconv(catbuff, save))) { // fichier existe pas mais déclaré: on l'a effacé - FILE *fp = FOPEN(fconv(catbuff, save), "wb"); + if (!fexist_utf8(fconv(catbuff, sizeof(catbuff), save))) { // fichier existe pas mais déclaré: on l'a effacé + FILE *fp = FOPEN(fconv(catbuff, sizeof(catbuff), save), "wb"); if (fp) fclose(fp); @@ -2455,7 +2456,7 @@ void back_wait(struct_back * sback, httrackp * opt, cache_back * cache, #if HTS_WIDE_DEBUG DEBUG_W("select\n"); #endif - select(nfds, &fds, &fds_c, &fds_e, &tv); + select((int) nfds, &fds, &fds_c, &fds_e, &tv); #if HTS_WIDE_DEBUG DEBUG_W("select done\n"); #endif @@ -2533,7 +2534,7 @@ void back_wait(struct_back * sback, httrackp * opt, cache_back * cache, back[i].r.ssl_con = SSL_new(openssl_ctx); if (back[i].r.ssl_con) { SSL_clear(back[i].r.ssl_con); - if (SSL_set_fd(back[i].r.ssl_con, back[i].r.soc) == 1) { + if (SSL_set_fd(back[i].r.ssl_con, (int) back[i].r.soc) == 1) { SSL_set_connect_state(back[i].r.ssl_con); back[i].status = STATUS_SSL_WAIT_HANDSHAKE; /* handshake wait */ } else @@ -2778,7 +2779,7 @@ void back_wait(struct_back * sback, httrackp * opt, cache_back * cache, if (back[i].r.compressed && /* .gz are *NOT* depacked!! */ (strfield - (get_ext(catbuff, back[i].url_sav), "gz") == 0) + (get_ext(catbuff, sizeof(catbuff), back[i].url_sav), "gz") == 0) ) { if (create_back_tmpfile(opt, &back[i]) == 0) { assert(back[i].tmpfile != NULL); @@ -3656,7 +3657,7 @@ void back_wait(struct_back * sback, httrackp * opt, cache_back * cache, file_notify(opt, back[i].url_adr, back[i].url_fil, back[i].url_sav, 0, 1, back[i].r.notmodified); - back[i].r.out = FOPEN(fconv(catbuff, back[i].url_sav), "ab"); // append + back[i].r.out = FOPEN(fconv(catbuff, sizeof(catbuff), back[i].url_sav), "ab"); // append if (back[i].r.out && opt->cache != 0) { back[i].r.is_write = 1; // écrire back[i].r.size = sz; // déja écrit @@ -3682,7 +3683,7 @@ void back_wait(struct_back * sback, httrackp * opt, cache_back * cache, } } else { // mémoire FILE *fp = - FOPEN(fconv(catbuff, back[i].url_sav), "rb"); + FOPEN(fconv(catbuff, sizeof(catbuff), back[i].url_sav), "rb"); if (fp) { LLint alloc_mem = sz + 1; diff --git a/src/htsbauth.c b/src/htsbauth.c index b7a2373..da0ef1d 100644 --- a/src/htsbauth.c +++ b/src/htsbauth.c @@ -129,10 +129,10 @@ int cookie_del(t_cookie * cookie, char *cook_name, char *domain, char *path) { // chk_dom: the domain stored in the cookie (potentially wildcard). // domain: query domain static int cookie_cmp_wildcard_domain(char *chk_dom, char *domain) { - int n = strlen(chk_dom); - int m = strlen(domain); - int l = n < m ? n : m; - int i; + const size_t n = strlen(chk_dom); + const size_t m = strlen(domain); + const size_t l = n < m ? n : m; + size_t i; for (i = l - 1; i >= 0; i--) { if (chk_dom[n - i - 1] != domain[m - i - 1]) { return 1; @@ -222,7 +222,7 @@ int cookie_load(t_cookie * cookie, const char *fpath, const char *name) { do { if (!(find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) if (!(find.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)) { - FILE *fp = fopen(fconcat(catbuff, fpath, find.cFileName), "rb"); + FILE *fp = fopen(fconcat(catbuff, sizeof(catbuff), fpath, find.cFileName), "rb"); if (fp) { char cook_name[256]; @@ -264,7 +264,7 @@ int cookie_load(t_cookie * cookie, const char *fpath, const char *name) { } fclose(fp); if (cookie_merged) - remove(fconcat(catbuff, fpath, find.cFileName)); + remove(fconcat(catbuff, sizeof(catbuff), fpath, find.cFileName)); } // if fp } } while(FindNextFileA(h, &find)); @@ -275,7 +275,7 @@ int cookie_load(t_cookie * cookie, const char *fpath, const char *name) { // Ensuite, cookies.txt { - FILE *fp = fopen(fconcat(catbuff, fpath, name), "rb"); + FILE *fp = fopen(fconcat(catbuff, sizeof(catbuff), fpath, name), "rb"); if (fp) { char BIGSTK line[8192]; @@ -316,7 +316,7 @@ int cookie_save(t_cookie * cookie, char *name) { if (strnotempty(cookie->data)) { char BIGSTK line[8192]; - FILE *fp = fopen(fconv(catbuff, name), "wb"); + FILE *fp = fopen(fconv(catbuff, sizeof(catbuff), name), "wb"); if (fp) { char *a = cookie->data; diff --git a/src/htscache.c b/src/htscache.c index b0b4488..5cdcc3f 100644 --- a/src/htscache.c +++ b/src/htscache.c @@ -147,7 +147,7 @@ void cache_mayadd(httrackp * opt, cache_back * cache, htsblk * r, // cached "fast" header doesn't yet exists if (inthash_read (cache->cached_tests, - concat(OPT_GET_BUFF(opt), url_adr, url_fil), NULL) == 0) { + concat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), url_adr, url_fil), NULL) == 0) { char BIGSTK tempo[HTS_URLMAXSIZE * 2]; sprintf(tempo, "%d", (int) r->statuscode); @@ -159,7 +159,7 @@ void cache_mayadd(httrackp * opt, cache_back * cache, htsblk * r, "Cached fast-header response: %s%s is %d", url_adr, url_fil, (int) r->statuscode); inthash_add(cache->cached_tests, - concat(OPT_GET_BUFF(opt), url_adr, url_fil), + concat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), url_adr, url_fil), (intptr_t) strdupt(tempo)); } } @@ -366,10 +366,10 @@ void cache_add(httrackp * opt, cache_back * cache, const htsblk * r, FILE *fp; // On recopie le fichier->. - off_t file_size = fsize_utf8(fconv(catbuff, url_save)); + off_t file_size = fsize_utf8(fconv(catbuff, sizeof(catbuff), url_save)); if (file_size >= 0) { - fp = FOPEN(fconv(catbuff, url_save), "rb"); + fp = FOPEN(fconv(catbuff, sizeof(catbuff), url_save), "rb"); if (fp != NULL) { char BIGSTK buff[32768]; size_t nl; @@ -751,7 +751,7 @@ static htsblk cache_readex_new(httrackp * opt, cache_back * cache, /* Ensure the file is present, because returning a reference to a missing file is useless! */ if (!dataincache) { /* Data are supposed to be on disk */ - if (!fexist_utf8(fconv(catbuff, previous_save))) { // un fichier existe déja + if (!fexist_utf8(fconv(catbuff, sizeof(catbuff), previous_save))) { // un fichier existe déja if (!opt->norecatch) { hts_log_print(opt, LOG_DEBUG, "Cache: could not find %s", previous_save); @@ -775,10 +775,10 @@ static htsblk cache_readex_new(httrackp * opt, cache_back * cache, r.msg[0] = '\0'; // File exists on disk with declared cache name (this is expected!) - if (fexist_utf8(fconv(catbuff, previous_save))) { // un fichier existe déja + if (fexist_utf8(fconv(catbuff, sizeof(catbuff), previous_save))) { // un fichier existe déja // Expected size ? const size_t fsize = - fsize_utf8(fconv(catbuff, previous_save)); + fsize_utf8(fconv(catbuff, sizeof(catbuff), previous_save)); if (fsize == r.size) { // Target name is the previous name, and the file looks good: nothing to do! if (strcmp(previous_save, target_save) == 0) { @@ -790,8 +790,8 @@ static htsblk cache_readex_new(httrackp * opt, cache_back * cache, char catbuff2[CATBUFF_SIZE]; if (RENAME - (fconv(catbuff, previous_save), - fconv(catbuff2, target_save)) == 0) { + (fconv(catbuff, sizeof(catbuff), previous_save), + fconv(catbuff2, sizeof(catbuff2), target_save)) == 0) { // So far so good ok = 1; // plus rien à faire @@ -812,9 +812,9 @@ static htsblk cache_readex_new(httrackp * opt, cache_back * cache, } // File exists with the target name and not previous one ? // Suppose a broken mirror, with a file being renamed: OK - else if (fexist_utf8(fconv(catbuff, target_save))) { + else if (fexist_utf8(fconv(catbuff, sizeof(catbuff), target_save))) { // Expected size ? - const size_t fsize = fsize_utf8(fconv(catbuff, target_save)); + const size_t fsize = fsize_utf8(fconv(catbuff, sizeof(catbuff), target_save)); if (fsize == r.size) { // So far so good @@ -927,7 +927,7 @@ static htsblk cache_readex_new(httrackp * opt, cache_back * cache, "Previous cache file not found (empty filename)"); } } else { /* Read in memory from disk */ - FILE *const fp = FOPEN(fconv(catbuff, previous_save), "rb"); + FILE *const fp = FOPEN(fconv(catbuff, sizeof(catbuff), previous_save), "rb"); if (fp != NULL) { r.adr = (char *) malloct((int) r.size + 4); @@ -1159,7 +1159,7 @@ static htsblk cache_readex_old(httrackp * opt, cache_back * cache, int ok = 0; r.is_write = 1; // écrire - if (fexist_utf8(fconv(catbuff, save))) { // un fichier existe déja + if (fexist_utf8(fconv(catbuff, sizeof(catbuff), save))) { // un fichier existe déja //if (fsize_utf8(fconv(save))==r.size) { // même taille -- NON tant pis (taille mal declaree) ok = 1; // plus rien à faire filenote(&opt->state.strc, save, NULL); // noter comme connu @@ -1229,7 +1229,7 @@ static htsblk cache_readex_old(httrackp * opt, cache_back * cache, strcpybuff(r.msg, "Previous cache file not found (2)"); } else { /* Read in memory from cache */ if (strnotempty(return_save) && fexist_utf8(return_save)) { - FILE *fp = FOPEN(fconv(catbuff, return_save), "rb"); + FILE *fp = FOPEN(fconv(catbuff, sizeof(catbuff), return_save), "rb"); if (fp != NULL) { r.adr = (char *) malloct((size_t) r.size + 4); @@ -1397,7 +1397,7 @@ void cache_init(cache_back * cache, httrackp * opt) { // --- // utilisation du cache: renommer ancien éventuel et charger index hts_log_print(opt, LOG_DEBUG, "Cache: enabled=%d, base=%s, ro=%d", - (int) opt->cache, fconcat(OPT_GET_BUFF(opt), + (int) opt->cache, fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/"), (int) cache->ro); if (opt->cache) { @@ -1406,40 +1406,40 @@ void cache_init(cache_back * cache, httrackp * opt) { #endif if (!cache->ro) { #ifdef _WIN32 - mkdir(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache")); + mkdir(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache")); #else - mkdir(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache"), + mkdir(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache"), HTS_PROTECT_FOLDER); #endif - if ((fexist(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache/new.zip")))) { // il existe déja un cache précédent.. renommer + if ((fexist(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.zip")))) { // il existe déja un cache précédent.. renommer /* Previous cache from the previous cache version */ #if 0 /* No.. reuse with old httrack releases! */ if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.dat"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.dat")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.ndx"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.ndx")); #endif /* Previous cache version */ - if ((fexist(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache/new.dat"))) && (fexist(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache/new.ndx")))) { // il existe déja un cache précédent.. renommer + if ((fexist(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat"))) && (fexist(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx")))) { // il existe déja un cache précédent.. renommer rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/new.dat"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/new.dat"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.dat")); rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/new.ndx"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/new.ndx"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.ndx")); } @@ -1447,11 +1447,11 @@ void cache_init(cache_back * cache, httrackp * opt) { /* Remove OLD cache */ if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.zip"))) { if (remove (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.zip")) != 0) { hts_log_print(opt, LOG_WARNING | LOG_ERRNO, "Cache: error while moving previous cache"); @@ -1461,8 +1461,8 @@ void cache_init(cache_back * cache, httrackp * opt) { /* Rename */ if (hts_rename (opt, - fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/new.zip"), fconcat(OPT_GET_BUFF(opt), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/new.zip"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.zip")) != 0) { hts_log_print(opt, LOG_WARNING | LOG_ERRNO, @@ -1470,33 +1470,33 @@ void cache_init(cache_back * cache, httrackp * opt) { } else { hts_log_print(opt, LOG_DEBUG, "Cache: successfully renamed"); } - } else if ((fexist(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache/new.dat"))) && (fexist(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache/new.ndx")))) { // il existe déja un cache précédent.. renommer + } else if ((fexist(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat"))) && (fexist(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx")))) { // il existe déja un cache précédent.. renommer #if DEBUGCA printf("work with former cache\n"); #endif if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.dat"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.dat")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.ndx"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.ndx")); rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/new.dat"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/new.dat"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.dat")); rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/new.ndx"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/new.ndx"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.ndx")); } else { // un des deux (ou les deux) fichiers cache absents: effacer l'autre éventuel @@ -1505,17 +1505,17 @@ void cache_init(cache_back * cache, httrackp * opt) { #endif if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx")); } } else { @@ -1524,30 +1524,30 @@ void cache_init(cache_back * cache, httrackp * opt) { hts_log_print(opt, LOG_DEBUG, "Cache: size %d", (int) fsize(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.zip"))); // charger index cache précédent if ((!cache->ro && fsize(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.zip")) > 0) || (cache->ro && fsize(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.zip")) > 0) ) { if (!cache->ro) { cache->zipInput = unzOpen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.zip")); } else { cache->zipInput = unzOpen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.zip")); } @@ -1559,25 +1559,25 @@ void cache_init(cache_back * cache, httrackp * opt) { if (!cache->ro) { name = - fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.zip"); } else { name = - fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.zip"); } hts_log_print(opt, LOG_WARNING, "Cache: damaged cache, trying to repair"); if (unzRepair (name, - fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/repair.zip"), fconcat(OPT_GET_BUFF(opt), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/repair.zip"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/repair.tmp"), &repaired, &repairedBytes) == Z_OK) { unlink(name); rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/repair.zip"), name); cache->zipInput = unzOpen(name); hts_log_print(opt, LOG_WARNING, @@ -1679,20 +1679,20 @@ void cache_init(cache_back * cache, httrackp * opt) { if ((!cache->ro && fsize(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.dat")) >= 0 && fsize(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.ndx")) > 0) || (cache->ro && fsize(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat")) >= 0 && fsize(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx")) > 0) ) { FILE *oldndx = NULL; @@ -1703,20 +1703,20 @@ void cache_init(cache_back * cache, httrackp * opt) { if (!cache->ro) { cache->olddat = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.dat"), "rb"); oldndx = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.ndx"), "rb"); } else { cache->olddat = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat"), "rb"); oldndx = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx"), "rb"); } // les deux doivent être ouvrables @@ -1738,20 +1738,20 @@ void cache_init(cache_back * cache, httrackp * opt) { if (!cache->ro) { buffl = fsize(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.ndx")); cache->use = readfile(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.ndx")); } else { buffl = fsize(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx")); cache->use = readfile(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx")); } if (cache->use != NULL) { @@ -1822,7 +1822,7 @@ void cache_init(cache_back * cache, httrackp * opt) { } } else { hts_log_print(opt, LOG_DEBUG, "Cache: no cache found in %s", - fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/")); } @@ -1832,39 +1832,39 @@ void cache_init(cache_back * cache, httrackp * opt) { if (!cache->ro) { // ouvrir caches actuels structcheck(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache/")); + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/")); if (1) { /* Create ZIP file cache */ cache->zipOutput = (void *) zipOpen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.zip"), 0); if (cache->zipOutput != NULL) { // supprimer old.lst if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.lst"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.lst")); // renommer if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.lst"))) rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/new.lst"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/new.lst"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.lst")); // ouvrir cache->lst = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.lst"), "wb"); strcpybuff(opt->state.strc.path, StringBuff(opt->path_html)); opt->state.strc.lst = cache->lst; @@ -1878,25 +1878,25 @@ void cache_init(cache_back * cache, httrackp * opt) { // supprimer old.txt if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.txt"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.txt")); // renommer if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.txt"))) rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/new.txt"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/new.txt"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.txt")); // ouvrir cache->txt = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.txt"), "wb"); if (cache->txt) { fprintf(cache->txt, @@ -1909,11 +1909,11 @@ void cache_init(cache_back * cache, httrackp * opt) { } else { cache->dat = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat"), "wb"); cache->ndx = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx"), "wb"); // les deux doivent être ouvrables if ((cache->dat == NULL) && (cache->ndx != NULL)) { @@ -1940,25 +1940,25 @@ void cache_init(cache_back * cache, httrackp * opt) { // supprimer old.lst if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.lst"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.lst")); // renommer if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.lst"))) rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/new.lst"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/new.lst"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.lst")); // ouvrir cache->lst = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.lst"), "wb"); strcpybuff(opt->state.strc.path, StringBuff(opt->path_html)); opt->state.strc.lst = cache->lst; @@ -1972,25 +1972,25 @@ void cache_init(cache_back * cache, httrackp * opt) { // supprimer old.txt if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.txt"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.txt")); // renommer if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.txt"))) rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/new.txt"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/new.txt"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.txt")); // ouvrir cache->txt = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.txt"), "wb"); if (cache->txt) { fprintf(cache->txt, @@ -2030,7 +2030,7 @@ char *readfile2(char *fil, LLint * size) { if (len >= 0) { // exists FILE *fp; - fp = fopen(fconv(catbuff, fil), "rb"); + fp = fopen(fconv(catbuff, sizeof(catbuff), fil), "rb"); if (fp != NULL) { // n'existe pas (!) adr = (char *) malloct(len + 1); if (size != NULL) @@ -2055,7 +2055,7 @@ char *readfile_utf8(char *fil) { const off_t len = fsize_utf8(fil); if (len >= 0) { // exists - FILE *const fp = FOPEN(fconv(catbuff, fil), "rb"); + FILE *const fp = FOPEN(fconv(catbuff, sizeof(catbuff), fil), "rb"); if (fp != NULL) { // n'existe pas (!) adr = (char *) malloct(len + 1); @@ -2080,7 +2080,7 @@ char *readfile_or(char *fil, char *defaultdata) { char catbuff[CATBUFF_SIZE]; if (!fexist(fil)) - realfile = fconcat(catbuff, hts_rootdir(NULL), fil); + realfile = fconcat(catbuff, sizeof(catbuff), hts_rootdir(NULL), fil); ret = readfile(realfile); if (ret) return ret; diff --git a/src/htsconcat.c b/src/htsconcat.c new file mode 100644 index 0000000..c78513f --- /dev/null +++ b/src/htsconcat.c @@ -0,0 +1,128 @@ +/* ------------------------------------------------------------ */ +/* +HTTrack Website Copier, Offline Browser for Windows and Unix +Copyright (C) 1998-2013 Xavier Roche and other contributors + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +Important notes: + +- We hereby ask people using this source NOT to use it in purpose of grabbing +emails addresses, or collecting any other private information on persons. +This would disgrace our work, and spoil the many hours we spent on it. + +Please visit our Website: http://www.httrack.com +*/ + +/* ------------------------------------------------------------ */ +/* File: Subroutines */ +/* Author: Xavier Roche */ +/* ------------------------------------------------------------ */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "httrack.h" +#include "httrack-library.h" + +// concat, concatène deux chaines et renvoi le résultat +// permet d'alléger grandement le code +#undef concat +HTSEXT_API char *concat(char *catbuff, size_t size, const char *a, const char *b) { + size_t max = 0; + + RUNTIME_TIME_CHECK_SIZE(size); + + catbuff[0] = '\0'; + if (a != NULL && a[0] != '\0') { + max += strlen(a); + if (max + 1 >= size) { + return catbuff; + } + strcat(catbuff, a); + } + if (b != NULL && b[0] != '\0') { + max += strlen(b); + if (max + 1 >= size) { + return catbuff; + } + strcat(catbuff, b); + } + return catbuff; +} + +// conversion fichier / -> antislash +static char *__fconv(char *a) { +#if HTS_DOSNAME + int i; + + for(i = 0; a[i] != 0; i++) + if (a[i] == '/') // Unix-to-DOS style + a[i] = '\\'; +#endif + return a; +} + +#undef fconcat +#undef concat +HTSEXT_API char *fconcat(char *catbuff, size_t size, const char *a, const char *b) { + RUNTIME_TIME_CHECK_SIZE(size); + return __fconv(concat(catbuff, size, a, b)); +} + +#undef fconv +HTSEXT_API char *fconv(char *catbuff, size_t size, const char *a) { + RUNTIME_TIME_CHECK_SIZE(size); + return __fconv(concat(catbuff, size, a, "")); +} + +/* / et \\ en / */ +static char *__fslash(char *a) { + int i; + + for(i = 0; a[i] != 0; i++) + if (a[i] == '\\') // convertir + a[i] = '/'; + return a; +} + +#undef fslash +char *fslash(char *catbuff, size_t size, const char *a) { + RUNTIME_TIME_CHECK_SIZE(size); + return __fslash(concat(catbuff, size, a, NULL)); +} + +// extension : html,gif.. +HTSEXT_API char *get_ext(char *catbuff, size_t size, const char *fil) { + size_t i, last; + + RUNTIME_TIME_CHECK_SIZE(size); + + for(i = 0, last = 0 ; fil[i] != '\0' && fil[i] != '?' ; i++) { + if (fil[i] == '.') { + last = i + 1; + } + } + + if (last != 0 && i > last) { + const size_t len = i - last; + if (len < size) { + catbuff[0] = '\0'; + strncat(catbuff, &fil[last], size); + return catbuff; + } + } + return ""; +} diff --git a/src/htscore.c b/src/htscore.c index 70d4fbf..629d3f6 100644 --- a/src/htscore.c +++ b/src/htscore.c @@ -162,7 +162,7 @@ RUN_CALLBACK0(opt, end); \ if (opt->log != NULL) fflush(opt->log); \ if (makestat_fp) { fclose(makestat_fp); makestat_fp=NULL; } \ if (maketrack_fp){ fclose(maketrack_fp); maketrack_fp=NULL; } \ - if (opt->accept_cookie) cookie_save(opt->cookie,fconcat(OPT_GET_BUFF(opt),StringBuff(opt->path_log),"cookies.txt")); \ + if (opt->accept_cookie) cookie_save(opt->cookie,fconcat(OPT_GET_BUFF(opt),OPT_GET_BUFF_SIZE(opt),StringBuff(opt->path_log),"cookies.txt")); \ if (makeindex_fp) { fclose(makeindex_fp); makeindex_fp=NULL; } \ if (cache_hashtable) { inthash_delete(&cache_hashtable); } \ if (cache_tests) { inthash_delete(&cache_tests); } \ @@ -236,8 +236,7 @@ if (makeindex_fp) { \ char BIGSTK tempo[1024]; \ if (makeindex_links == 1) { \ char BIGSTK link_escaped[HTS_URLMAXSIZE*2]; \ - strcpybuff(link_escaped, makeindex_firstlink); \ - escape_uri_utf(link_escaped); \ + escape_uri_utf(makeindex_firstlink, link_escaped, sizeof(link_escaped)); \ sprintf(tempo,"<meta HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=%s\">"CRLF, link_escaped); \ } else \ tempo[0]='\0'; \ @@ -248,7 +247,7 @@ if (makeindex_fp) { \ fflush(makeindex_fp); \ fclose(makeindex_fp); /* à ne pas oublier sinon on passe une nuit blanche */ \ makeindex_fp=NULL; \ - usercommand(opt,0,NULL,fconcat(OPT_GET_BUFF(opt),StringBuff(opt->path_html_utf8),"index.html"),"",""); \ + usercommand(opt,0,NULL,fconcat(OPT_GET_BUFF(opt),OPT_GET_BUFF_SIZE(opt),StringBuff(opt->path_html_utf8),"index.html"),"",""); \ } \ } \ makeindex_done=1; /* ok c'est fait */ \ @@ -369,15 +368,15 @@ int httpmirror(char *url1, httrackp * opt) { // et templates html template_header = readfile_or(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_bin), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_bin), "templates/index-header.html"), HTS_INDEX_HEADER); template_body = readfile_or(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_bin), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_bin), "templates/index-body.html"), HTS_INDEX_BODY); template_footer = readfile_or(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_bin), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_bin), "templates/index-footer.html"), HTS_INDEX_FOOTER); // initialiser mimedefs @@ -628,8 +627,8 @@ int httpmirror(char *url1, httrackp * opt) { // lien primaire liens_record("primary", "/primary", - fslash(OPT_GET_BUFF(opt), - fconcat(OPT_GET_BUFF(opt), + fslash(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_html_utf8), "index.html")), "", "", opt->urlhack); if (liens[lien_tot] == NULL) { // erreur, pas de place réservée @@ -700,7 +699,7 @@ int httpmirror(char *url1, httrackp * opt) { if (opt->makestat) { makestat_fp = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-stats.txt"), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-stats.txt"), "wb"); if (makestat_fp != NULL) { fprintf(makestat_fp, "HTTrack statistics report, every minutes" LF LF); @@ -711,7 +710,7 @@ int httpmirror(char *url1, httrackp * opt) { if (opt->maketrack) { maketrack_fp = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-track.txt"), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-track.txt"), "wb"); if (maketrack_fp != NULL) { fprintf(maketrack_fp, "HTTrack tracking report, every minutes" LF LF); @@ -1452,7 +1451,7 @@ int httpmirror(char *url1, httrackp * opt) { /* Remove file if being processed */ if (is_loaded_from_file) { - (void) unlink(fconv(OPT_GET_BUFF(opt), savename)); + (void) unlink(fconv(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), savename)); is_loaded_from_file = 0; } @@ -1783,7 +1782,7 @@ int httpmirror(char *url1, httrackp * opt) { #ifndef _WIN32 chmod(tempo, HTS_ACCESS_FILE); #endif - usercommand(opt, 0, NULL, fconv(OPT_GET_BUFF(opt), tempo), "", + usercommand(opt, 0, NULL, fconv(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), tempo), "", ""); } @@ -1979,42 +1978,42 @@ int httpmirror(char *url1, httrackp * opt) { XH_uninit; if ((fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache/old.dat"))) + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.dat"))) && (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.ndx")))) { remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat")); remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx")); remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.lst")); remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.txt")); rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/old.dat"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/old.dat"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat")); rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/old.ndx"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/old.ndx"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx")); rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/old.lst"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/old.lst"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.lst")); rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/old.txt"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/old.txt"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.txt")); } @@ -2038,16 +2037,16 @@ int httpmirror(char *url1, httrackp * opt) { // old_lst = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.lst"), "rb"); if (old_lst) { off_t sz = fsize(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.lst")); new_lst = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.lst"), "rb"); if ((new_lst) && (sz > 0)) { char *adr = (char *) malloct(sz); @@ -2849,10 +2848,10 @@ int filenote(filenote_strc * strc, const char *s, filecreate_params * params) { char BIGSTK savelst[HTS_URLMAXSIZE * 2]; char catbuff[CATBUFF_SIZE]; - strcpybuff(savelst, fslash(catbuff, s)); + strcpybuff(savelst, fslash(catbuff, sizeof(catbuff), s)); // couper chemin? if (strnotempty(strc->path)) { - if (strncmp(fslash(catbuff, strc->path), savelst, strlen(strc->path)) == 0) { // couper + if (strncmp(fslash(catbuff, sizeof(catbuff), strc->path), savelst, strlen(strc->path)) == 0) { // couper strcpybuff(savelst, s + strlen(strc->path)); } } @@ -2938,8 +2937,9 @@ static void postprocess_file(httrackp * opt, const char *save, const char *adr, if (rsc_fil == NULL) rsc_fil = fil; if (strncmp - (fslash(OPT_GET_BUFF(opt), save), - fslash(OPT_GET_BUFF(opt), StringBuff(opt->path_html_utf8)), (n = + (fslash(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), save), + fslash(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_html_utf8)), (n = (int) strlen (StringBuff @@ -2953,13 +2953,15 @@ static void postprocess_file(httrackp * opt, const char *save, const char *adr, //first = 1; opt->state.mimefp = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_html), "index.mht"), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_html), "index.mht"), "wb"); - (void) unlink(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_html), + (void) unlink(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_html), "index.eml")); #ifndef _WIN32 if (symlink("index.mht", - fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_html), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_html), "index.eml")) != 0) { if (errno != EPERM) { hts_log_print(opt, LOG_WARNING | LOG_ERRNO, @@ -3005,17 +3007,7 @@ static void postprocess_file(httrackp * opt, const char *save, const char *adr, mimebuff[0] = '\0'; /* CID */ - strcpybuff(cid, adr); - strcatbuff(cid, fil); - escape_in_url(cid); - { - char *a = cid; - - while((a = strchr(a, '%'))) { - *a = 'X'; - a++; - } - } + make_content_id(adr, fil, cid, sizeof(cid)); guess_httptype(opt, mimebuff, save); fprintf(opt->state.mimefp, "--%s\r\n", @@ -3323,7 +3315,7 @@ int check_sockerror(T_SOC s) { FD_SET((T_SOC) s, &fds); tv.tv_sec = 0; tv.tv_usec = 0; - select(s + 1, NULL, NULL, &fds, &tv); + select((int) s + 1, NULL, NULL, &fds, &tv); return FD_ISSET(s, &fds); } @@ -3336,7 +3328,7 @@ int check_sockdata(T_SOC s) { FD_SET((T_SOC) s, &fds); tv.tv_sec = 0; tv.tv_usec = 0; - select(s + 1, &fds, NULL, NULL, &tv); + select((int) s + 1, &fds, NULL, NULL, &tv); return FD_ISSET(s, &fds); } diff --git a/src/htscore.h b/src/htscore.h index 4440564..f082d11 100644 --- a/src/htscore.h +++ b/src/htscore.h @@ -298,26 +298,6 @@ HTS_STATIC int cache_readable(cache_back * cache) { /* Library internal definictions */ #ifdef HTS_INTERNAL_BYTECODE -// -#ifndef HTTRACK_DEFLIB -HTSEXT_API int hts_is_parsing(httrackp * opt, int flag); -HTSEXT_API int hts_is_testing(httrackp * opt); -HTSEXT_API int hts_addurl(httrackp * opt, char **url); -HTSEXT_API int hts_resetaddurl(httrackp * opt); -HTSEXT_API int copy_htsopt(const httrackp * from, httrackp * to); -HTSEXT_API char *hts_errmsg(httrackp * opt); -HTSEXT_API int hts_setpause(httrackp * opt, int); - -// -HTSEXT_API int hts_is_exiting(httrackp * opt); -HTSEXT_API int hts_request_stop(httrackp * opt, int force); - -// -HTSEXT_API int hts_cancel_file_push(httrackp * opt, const char *url); -HTSEXT_API void hts_cancel_test(httrackp * opt); -HTSEXT_API void hts_cancel_parsing(httrackp * opt); -#endif - char *hts_cancel_file_pop(httrackp * opt); #endif @@ -345,11 +325,6 @@ void usercommand(httrackp * opt, int exe, const char *cmd, const char *file, void usercommand_exe(const char *cmd, const char *file); int filters_init(char ***ptrfilters, int maxfilter, int filterinc); -#ifndef HTTRACK_DEFLIB -HTSEXT_API int structcheck(const char *path); -HTSEXT_API int structcheck_utf8(const char *path); -HTSEXT_API int dir_exists(const char *path); -#endif int fspc(httrackp * opt, FILE * fp, const char *type); char *next_token(char *p, int flag); @@ -377,13 +352,6 @@ int backlinks_done(struct_back * sback, lien_url ** liens, int lien_tot, int back_fillmax(struct_back * sback, httrackp * opt, cache_back * cache, lien_url ** liens, int ptr, int numero_passe, int lien_tot); -// cancel file -#ifndef HTTRACK_DEFLIB -HTSEXT_API int hts_cancel_file_push(httrackp * opt, const char *url); -HTSEXT_API void hts_cancel_test(httrackp * opt); -HTSEXT_API void hts_cancel_parsing(httrackp * opt); -#endif - int ask_continue(httrackp * opt); int nombre_digit(int n); diff --git a/src/htscoremain.c b/src/htscoremain.c index 2f84319..38a4112 100644 --- a/src/htscoremain.c +++ b/src/htscoremain.c @@ -180,7 +180,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { #ifndef HTS_HTTRACKDIR { char catbuff[CATBUFF_SIZE]; - char *path = fslash(catbuff, argv[0]); + char *path = fslash(catbuff, sizeof(catbuff), argv[0]); char *a; if ((a = strrchr(path, '/'))) { @@ -451,15 +451,18 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { else { if ((!fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/doit.log"))) || (argv_url > 0)) { if (!optinclude_file (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), HTS_HTTRACKRC), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), HTS_HTTRACKRC), &argc, argv, x_argvblk, &x_ptr)) if (!optinclude_file(HTS_HTTRACKRC, &argc, argv, x_argvblk, &x_ptr)) { if (!optinclude_file - (fconcat(OPT_GET_BUFF(opt), hts_gethome(), "/" HTS_HTTRACKRC), + (fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + hts_gethome(), "/" HTS_HTTRACKRC), &argc, argv, x_argvblk, &x_ptr)) { #ifdef HTS_HTTRACKCNF optinclude_file(HTS_HTTRACKCNF, &argc, argv, x_argvblk, &x_ptr); @@ -478,11 +481,13 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { /* load doit.log and insert in current command line */ if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache/doit.log")) + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/doit.log")) && (argv_url <= 0)) { FILE *fp = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/doit.log"), "rb"); if (fp) { int insert_after = 1; /* insérer après nom au début */ @@ -529,48 +534,58 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { #endif if (!fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache/new.zip"))) { + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/new.zip"))) { if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache/old.zip"))) { + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/old.zip"))) { rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/old.zip"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), + "hts-cache/old.zip"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.zip")); } } else if ((!fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache/new.dat"))) + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/new.dat"))) || (!fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/new.ndx")))) { if ((fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache/old.dat"))) + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/old.dat"))) && (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/old.ndx")))) { remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/new.dat")); remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/new.ndx")); //remove(fconcat(StringBuff(opt->path_log),"hts-cache/new.lst")); rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/old.dat"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), + "hts-cache/old.dat"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat")); rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/old.ndx"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/old.ndx"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx")); //rename(fconcat(StringBuff(opt->path_log),"hts-cache/old.lst"),fconcat(StringBuff(opt->path_log),"hts-cache/new.lst")); @@ -581,17 +596,20 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { if (!opt->quiet) { if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-in_progress.lock"))) { /* Old cache */ if ((fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/old.dat"))) && (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/old.ndx")))) { if (opt->log != NULL) { fprintf(opt->log, "Warning!\n"); @@ -623,109 +641,109 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { strcpybuff(argv[i] + 1, ""); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-log.txt"))) + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-log.txt"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-log.txt")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-err.txt"))) + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-err.txt"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-err.txt")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_html), "index.html"))) + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_html), "index.html"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_html), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_html), "index.html")); /* */ if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.zip"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.zip")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.zip"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.zip")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.dat"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.dat")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.ndx"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.ndx")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.lst"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.lst")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.lst"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.lst")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.txt"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.txt")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.txt"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.txt")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/doit.log"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/doit.log")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-in_progress.lock"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-in_progress.lock")); rmdir(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache")); + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache")); // } else if (strfield2(argv[i] + 2, "catchurl")) { // capture d'URL via proxy temporaire! argv_url = 1; // forcer a passer les parametres @@ -879,22 +897,27 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { // Présence d'un cache, que faire?.. if ((fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache/new.zip"))) + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/new.zip"))) || (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache/new.dat")) + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/new.dat")) && fexist(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/new.ndx"))) ) { // il existe déja un cache précédent.. renommer - if (fexist(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache/doit.log"))) { // un cache est présent + if (fexist(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-cache/doit.log"))) { // un cache est présent if (x_argvblk != NULL) { int m; // établir mode - mode cache: 1 (cache valide) 2 (cache à vérifier) - if (fexist(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-in_progress.lock"))) { // cache prioritaire + if (fexist(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-in_progress.lock"))) { // cache prioritaire m = 1; } else { m = 2; @@ -952,23 +975,24 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { } } else { // plus de 2 paramètres // un fichier log existe? - if (fexist(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-in_progress.lock"))) { // fichier lock? + if (fexist(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-in_progress.lock"))) { // fichier lock? //char s[32]; opt->cache = 1; // cache prioritaire if (opt->quiet == 0) { if ((fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.zip"))) || (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat")) && fexist(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx"))) ) { HT_REQUEST_START; @@ -987,22 +1011,22 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { } else if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_html), "index.html"))) { + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_html), "index.html"))) { //char s[32]; opt->cache = 2; // cache vient après test de validité if (opt->quiet == 0) { if ((fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.zip"))) || (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat")) && fexist(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx"))) ) { HT_REQUEST_START; @@ -1991,7 +2015,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { int pos; char *cacheNdx = readfile(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx")); cache_init(&cache, opt); /* load cache */ if (cacheNdx != NULL) { @@ -2157,22 +2181,22 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.zip"))) { name = - fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.zip"); } else if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.zip"))) { name = - fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.zip"); } else { fprintf(stderr, "* error: no cache found in %s\n", - fconcat(OPT_GET_BUFF(opt), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.zip")); return 1; @@ -2180,14 +2204,14 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { fprintf(stderr, "Cache: trying to repair %s\n", name); if (unzRepair (name, - fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/repair.zip"), - fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/repair.tmp"), &repaired, &repairedBytes) == Z_OK) { unlink(name); rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/repair.zip"), name); fprintf(stderr, "Cache: %d bytes successfully recovered in %d entries\n", @@ -2487,7 +2511,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { } else { capa <<= 1; } - strings = realloc(strings, capa*sizeof(char*)); + strings = (const char **) realloc((void*) strings, capa*sizeof(char*)); } strings[count++] = &buff[last]; last = i + 1; @@ -2684,7 +2708,6 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { } else { // URL/filters char catbuff[CATBUFF_SIZE]; - char BIGSTK tempo[CATBUFF_SIZE]; const int urlSize = (int) strlen(argv[na]); const int capa = (int) (strlen(url) + urlSize + 32); @@ -2693,9 +2716,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { ensureUrlCapacity(url, url_sz, capa); if (strnotempty(url)) strcatbuff(url, " "); // espace de séparation - strcpybuff(tempo, unescape_http_unharm(catbuff, argv[na], 1)); - escape_spc_url(tempo); - strcatbuff(url, tempo); + append_escape_spc_url(unescape_http_unharm(catbuff, sizeof(catbuff), argv[na], 1), url, url_sz); } } // if argv=- etc. @@ -2737,37 +2758,37 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { // en cas de présence des deux versions, garder la version la plus avancée, // cad la version contenant le plus de fichiers if (opt->cache) { - if (fexist(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-in_progress.lock"))) { // problemes.. + if (fexist(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-in_progress.lock"))) { // problemes.. if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat"))) { if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.zip"))) { if (fsize (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.zip")) < 32768) { if (fsize (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.zip")) > 65536) { if (fsize (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/old.zip")) > fsize(fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/old.zip")) > fsize(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt-> path_log), "hts-cache/new.zip"))) { remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.zip")); rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/old.zip"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/old.zip"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.zip")); } @@ -2777,53 +2798,53 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { } else if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat")) && fexist(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx"))) { if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.dat")) && fexist(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.ndx"))) { // switcher si new<32Ko et old>65Ko (tailles arbitraires) ? // ce cas est peut être une erreur ou un crash d'un miroir ancien, prendre // alors l'ancien cache if (fsize (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat")) < 32768) { if (fsize (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/old.dat")) > 65536) { if (fsize (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/old.dat")) > fsize(fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/old.dat")) > fsize(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt-> path_log), "hts-cache/new.dat"))) { remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat")); remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx")); rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/old.dat"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/old.dat"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.dat")); rename(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), - "hts-cache/old.ndx"), fconcat(OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), + "hts-cache/old.ndx"), fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/new.ndx")); //} else { // ne rien faire @@ -2840,7 +2861,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { if (_DEBUG_HEAD) { ioinfo = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-ioinfo.txt"), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-ioinfo.txt"), "wb"); } @@ -2857,26 +2878,26 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { structcheck(StringBuff(opt->path_log)); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-log.txt"))) + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-log.txt"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-log.txt")); + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-log.txt")); if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-err.txt"))) + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-err.txt"))) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-err.txt")); + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-err.txt")); /* Check FS directory structure created */ structcheck(StringBuff(opt->path_log)); opt->log = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-log.txt"), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-log.txt"), "w"); if (httrack_logmode == 2) opt->errlog = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-err.txt"), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-err.txt"), "w"); else opt->errlog = opt->log; @@ -2884,7 +2905,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { char s[HTS_CDLMAXSIZE + 256]; sprintf(s, "Unable to create log file %s", - fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-log.txt")); HTS_PANIC_PRINTF(s); htsmain_free(); @@ -2893,7 +2914,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { char s[HTS_CDLMAXSIZE + 256]; sprintf(s, "Unable to create log file %s", - fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-err.txt")); HTS_PANIC_PRINTF(s); htsmain_free(); @@ -2918,7 +2939,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { { FILE *fp = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/readme.txt"), "wb"); if (fp) { fprintf(fp, "What's in this folder?" LF); @@ -2943,7 +2964,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { } strcpy(n_lock, - fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-in_progress.lock")); //sprintf(n_lock,fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-in_progress.lock"),n); /*do { @@ -2960,8 +2981,8 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { } */ // vérifier existence de la structure - structcheck(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_html), "/")); - structcheck(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), "/")); + structcheck(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_html), "/")); + structcheck(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "/")); // reprise/update if (opt->cache) { @@ -2970,7 +2991,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { #ifdef _WIN32 mkdir(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache")); + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache")); #else mkdir(fconcat (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-cache"), @@ -2978,7 +2999,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { #endif fp = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-cache/doit.log"), "wb"); if (fp) { for(i = 0 + 1; i < argc; i++) { @@ -3189,7 +3210,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { for(dir = opendir(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), CACHE_REFNAME)); dir != NULL && (entry = readdir(dir)) != NULL;) { if (entry->d_name[0] != '\0' && entry->d_name[0] != '.') { @@ -3197,7 +3218,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { sprintf(f, "%s/%s", CACHE_REFNAME, entry->d_name); (void) - unlink(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), f)); + unlink(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), f)); } } if (dir != NULL) { @@ -3205,7 +3226,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { } (void) rmdir(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), CACHE_REFNAME)); + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), CACHE_REFNAME)); } /* Info for wrappers */ diff --git a/src/htsencoding.h b/src/htsencoding.h index 01def33..ad5fee3 100644 --- a/src/htsencoding.h +++ b/src/htsencoding.h @@ -86,8 +86,7 @@ extern int hts_unescapeUrl(const char *src, char *dest, const size_t max); * Note: source and destination MUST NOT be the same. * Returns 0 upon success, -1 upon overflow or error. **/ -extern int hts_unescapeUrlSpecial(const char *src, - char *dest, const size_t max, - int flags); +extern int hts_unescapeUrlSpecial(const char *src, char *dest, const size_t max, + const int flags); #endif diff --git a/src/htsftp.c b/src/htsftp.c index a9605d3..5ea7f82 100644 --- a/src/htsftp.c +++ b/src/htsftp.c @@ -217,7 +217,7 @@ int run_launch_ftp(FTPDownloadStruct * pStruct) { ftp_filename = a; if (strnotempty(a)) { char catbuff[CATBUFF_SIZE]; - char *ua = unescape_http(catbuff, a); + char *ua = unescape_http(catbuff, sizeof(catbuff), a); int len_a = (int) strlen(ua); if (len_a > 0 && ua[len_a - 1] == '/') { /* obviously a directory listing */ @@ -528,7 +528,7 @@ int run_launch_ftp(FTPDownloadStruct * pStruct) { if (back->r.statuscode != -1) { if (!transfer_list) { char catbuff[CATBUFF_SIZE]; - char *ua = unescape_http(catbuff, ftp_filename); + char *ua = unescape_http(catbuff, sizeof(catbuff), ftp_filename); if ((strchr(ua, ' ')) || (strchr(ua, '\"')) diff --git a/src/htsglobal.h b/src/htsglobal.h index 3524f27..7c89ef6 100644 --- a/src/htsglobal.h +++ b/src/htsglobal.h @@ -57,6 +57,19 @@ Please visit our Website: http://www.httrack.com #endif #endif +/* GCC extension */ +#ifndef HTS_UNUSED +#ifdef __GNUC__ +#define HTS_UNUSED __attribute__ ((unused)) +#define HTS_STATIC static __attribute__ ((unused)) +#define HTS_PRINTF_FUN(fmt, arg) __attribute__ ((format (printf, fmt, arg))) +#else +#define HTS_UNUSED +#define HTS_STATIC static +#define HTS_PRINTF_FUN(fmt, arg) +#endif +#endif + // config.h #ifdef _WIN32 diff --git a/src/htshelp.c b/src/htshelp.c index c5eb955..165e2a7 100644 --- a/src/htshelp.c +++ b/src/htshelp.c @@ -401,7 +401,7 @@ void help_catchurl(const char *dest_path) { { char BIGSTK finalurl[HTS_URLMAXSIZE * 2]; - escape_check_url(dest); + inplace_escape_check_url(dest, sizeof(dest)); sprintf(finalurl, "%s" POSTTOK "file:%s", url, dest); printf("\nThe URL is: \"%s\"\n", finalurl); printf("You can capture it through: httrack \"%s\"\n", finalurl); diff --git a/src/htsindex.c b/src/htsindex.c index 4055ca6..1d08012 100644 --- a/src/htsindex.c +++ b/src/htsindex.c @@ -161,8 +161,8 @@ int index_keyword(const char *html_data, LLint size, const char *mime, // Init ? if (hts_index_init) { - UNLINK(concat(catbuff, indexpath, "index.txt")); - UNLINK(concat(catbuff, indexpath, "sindex.html")); + UNLINK(concat(catbuff, sizeof(catbuff), indexpath, "index.txt")); + UNLINK(concat(catbuff, sizeof(catbuff), indexpath, "sindex.html")); hts_index_init = 0; } // Check MIME type @@ -291,7 +291,7 @@ int index_keyword(const char *html_data, LLint size, const char *mime, e++; /* 0 means "once" */ - if (strncmp((const char *) fslash(catbuff, (char *) indexpath), filename, strlen(indexpath)) == 0) // couper + if (strncmp((const char *) fslash(catbuff, sizeof(catbuff), (char *) indexpath), filename, strlen(indexpath)) == 0) // couper strcpybuff(savelst, filename + strlen(indexpath)); else strcpybuff(savelst, filename); @@ -358,9 +358,9 @@ void index_finish(const char *indexpath, int mode) { // Write new file if (mode == 1) // TEXT - fp = fopen(concat(catbuff, indexpath, "index.txt"), "wb"); + fp = fopen(concat(catbuff, sizeof(catbuff), indexpath, "index.txt"), "wb"); else // HTML - fp = fopen(concat(catbuff, indexpath, "sindex.html"), "wb"); + fp = fopen(concat(catbuff, sizeof(catbuff), indexpath, "sindex.html"), "wb"); if (fp) { char current_word[KEYW_LEN + 32]; char word[KEYW_LEN + 32]; diff --git a/src/htsjava.c b/src/htsjava.c index 20faeee..0098994 100644 --- a/src/htsjava.c +++ b/src/htsjava.c @@ -172,7 +172,7 @@ static int hts_parse_java(t_hts_callbackarg * carg, httrackp * opt, #if JAVADEBUG printf("fopen\n"); #endif - if ((fpout = FOPEN(fconv(catbuff, file), "r+b")) == NULL) { + if ((fpout = FOPEN(fconv(catbuff, sizeof(catbuff), file), "r+b")) == NULL) { //fprintf(stderr, "Cannot open input file.\n"); sprintf(str->err_msg, "Unable to open file %s", file); return 0; // une erreur.. @@ -477,7 +477,7 @@ static int tris(httrackp * opt, char *buffer) { if (strnotempty(type)) // type reconnu! return 1; // ajout RX 05/2001 - else if (is_dyntype(get_ext(catbuff, buffer))) // asp,cgi... + else if (is_dyntype(get_ext(catbuff, sizeof(catbuff), buffer))) // asp,cgi... return 1; } return 0; diff --git a/src/htslib.c b/src/htslib.c index 8f89d52..b991ce2 100644 --- a/src/htslib.c +++ b/src/htslib.c @@ -685,17 +685,20 @@ T_SOC http_xfopen(httrackp * opt, int mode, int treat, int waitconnect, // Test en cas de file:///C|... if (!fexist - (fconv(OPT_GET_BUFF(opt), unescape_http(OPT_GET_BUFF(opt), fil)))) + (fconv(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + unescape_http(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), fil)))) if (fexist (fconv - (OPT_GET_BUFF(opt), unescape_http(OPT_GET_BUFF(opt), fil + 1)))) { + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + unescape_http(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), fil + 1)))) { char BIGSTK tempo[HTS_URLMAXSIZE * 2]; strcpybuff(tempo, fil + 1); strcpybuff(fil, tempo); } // Ouvrir - retour->totalsize = fsize(fconv(OPT_GET_BUFF(opt), unescape_http(OPT_GET_BUFF(opt), fil))); // taille du fichier + retour->totalsize = fsize(fconv(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + unescape_http(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), fil))); // taille du fichier retour->msg[0] = '\0'; soc = INVALID_SOCKET; if (retour->totalsize < 0) @@ -703,7 +706,8 @@ T_SOC http_xfopen(httrackp * opt, int mode, int treat, int waitconnect, else { // Note: On passe par un FILE* (plus propre) //soc=open(fil,O_RDONLY,0); // en lecture seule! - retour->fp = FOPEN(fconv(OPT_GET_BUFF(opt), unescape_http(OPT_GET_BUFF(opt), fil)), "rb"); // ouvrir + retour->fp = FOPEN(fconv(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + unescape_http(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), fil)), "rb"); // ouvrir if (retour->fp == NULL) soc = INVALID_SOCKET; else @@ -863,8 +867,8 @@ int http_sendhead(httrackp * opt, t_cookie * cookie, int mode, char *xsend, if (search_tag) { // postfile if (mode == 0) { // GET! FILE *fp = - FOPEN(unescape_http - (OPT_GET_BUFF(opt), search_tag + strlen(POSTTOK) + 5), "rb"); + FOPEN(unescape_http(OPT_GET_BUFF(opt), + OPT_GET_BUFF_SIZE(opt), search_tag + strlen(POSTTOK) + 5), "rb"); if (fp) { char BIGSTK line[1100]; char BIGSTK protocol[256], url[HTS_URLMAXSIZE * 2], method[256]; @@ -939,7 +943,7 @@ int http_sendhead(httrackp * opt, t_cookie * cookie, int mode, char *xsend, strncatbuff(tempo, fil, (int) (search_tag - fil)); else strcpybuff(tempo, fil); - escape_check_url(tempo); + inplace_escape_check_url(tempo, sizeof(tempo)); print_buffer(&bstr, "%s", tempo); // avec échappement } @@ -967,7 +971,7 @@ int http_sendhead(httrackp * opt, t_cookie * cookie, int mode, char *xsend, autorisation[0] = user_pass[0] = '\0'; // strncatbuff(user_pass, astart, (int) (a - astart) - 1); - strcpybuff(user_pass, unescape_http(OPT_GET_BUFF(opt), user_pass)); + strcpybuff(user_pass, unescape_http(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), user_pass)); code64((unsigned char *) user_pass, (int) strlen(user_pass), (unsigned char *) autorisation, 0); print_buffer(&bstr, "Proxy-Authorization: Basic %s"H_CRLF, @@ -1001,7 +1005,7 @@ int http_sendhead(httrackp * opt, t_cookie * cookie, int mode, char *xsend, print_buffer(&bstr, "Content-length: %d" H_CRLF, (int) (strlen (unescape_http - (OPT_GET_BUFF(opt), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), search_tag + strlen(POSTTOK) + 1)))); } } @@ -1099,7 +1103,8 @@ int http_sendhead(httrackp * opt, t_cookie * cookie, int mode, char *xsend, user_pass[0] = '\0'; strncatbuff(user_pass, astart, (int) (a - astart) - 1); - strcpybuff(user_pass, unescape_http(OPT_GET_BUFF(opt), user_pass)); + strcpybuff(user_pass, + unescape_http(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), user_pass)); code64((unsigned char *) user_pass, (int) strlen(user_pass), (unsigned char *) autorisation, 0); if (strcmp(fil, "/robots.txt")) /* pas robots.txt */ @@ -1128,7 +1133,7 @@ int http_sendhead(httrackp * opt, t_cookie * cookie, int mode, char *xsend, if (search_tag) if (mode == 0) // GET! print_buffer(&bstr, "%s", - unescape_http(OPT_GET_BUFF(opt), + unescape_http(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), search_tag + strlen(POSTTOK) + 1)); } #if HDEBUG @@ -2523,7 +2528,7 @@ void fil_simplifie(char *f) { } // fermer liaison fichier ou socket -HTS_INLINE void deletehttp(htsblk * r) { +void deletehttp(htsblk * r) { #if HTS_DEBUG_CLOSESOCK DEBUG_W("deletehttp: (htsblk*) 0x%p\n" _(void *)r); #endif @@ -2550,7 +2555,7 @@ HTS_INLINE void deletehttp(htsblk * r) { // free the addr buffer // always returns 1 -HTS_INLINE int deleteaddr(htsblk * r) { +int deleteaddr(htsblk * r) { if (r->adr != NULL) { freet(r->adr); r->adr = NULL; @@ -2563,7 +2568,7 @@ HTS_INLINE int deleteaddr(htsblk * r) { } // fermer une socket -HTS_INLINE void deletesoc(T_SOC soc) { +void deletesoc(T_SOC soc) { if (soc != INVALID_SOCKET && soc != LOCAL_SOCKET_ID) { #if HTS_WIDE_DEBUG DEBUG_W("close %d\n" _(int) soc); @@ -2588,7 +2593,7 @@ HTS_INLINE void deletesoc(T_SOC soc) { } /* Will also clean other things */ -HTS_INLINE void deletesoc_r(htsblk * r) { +void deletesoc_r(htsblk * r) { #if HTS_USEOPENSSL if (r->ssl_con) { SSL_shutdown(r->ssl_con); @@ -2604,12 +2609,12 @@ HTS_INLINE void deletesoc_r(htsblk * r) { } // renvoi le nombre de secondes depuis 1970 -HTS_INLINE TStamp time_local(void) { +TStamp time_local(void) { return ((TStamp) time(NULL)); } // number of millisec since 1970 -HTSEXT_API HTS_INLINE TStamp mtime_local(void) { +HTSEXT_API TStamp mtime_local(void) { #ifndef HTS_DO_NOT_USE_FTIME struct timeb B; @@ -2845,7 +2850,7 @@ int get_filetime_rfc822(const char *file, char *date) { } // heure au format rfc (taille buffer 256o) -HTS_INLINE void time_rfc822(char *s, struct tm *A) { +void time_rfc822(char *s, struct tm *A) { if (A == NULL) { int localtime_returned_null = 0; @@ -2855,7 +2860,7 @@ HTS_INLINE void time_rfc822(char *s, struct tm *A) { } // heure locale au format rfc (taille buffer 256o) -HTS_INLINE void time_rfc822_local(char *s, struct tm *A) { +void time_rfc822_local(char *s, struct tm *A) { if (A == NULL) { int localtime_returned_null = 0; @@ -2880,7 +2885,7 @@ HTSEXT_API char *int2bytessec(strc_int2bytes2 * strc, long int n) { strcpybuff(buff, a[0]); strcatbuff(buff, a[1]); - return concat(strc->catbuff, buff, "/s"); + return concat(strc->catbuff, sizeof(strc->catbuff), buff, "/s"); } HTSEXT_API char *int2char(strc_int2bytes2 * strc, int n) { sprintf(strc->buff2, "%d", n); @@ -2951,7 +2956,7 @@ int sig_ignore_flag(int setflag) { // flag ignore #endif // envoi de texte (en têtes généralement) sur la socket soc -HTS_INLINE int sendc(htsblk * r, const char *s) { +int sendc(htsblk * r, const char *s) { int n, ssz = (int) strlen(s); #ifdef _WIN32 @@ -3196,12 +3201,14 @@ typedef struct { // 0 : no // 1 : yes // -1: don't know -int is_unicode_utf8(const char *buffer_, size_t size) { +int is_unicode_utf8(const char *buffer_, const size_t size) { const unsigned char *buffer = (const unsigned char *) buffer_; t_auto_seq seq; size_t i; int is_utf = -1; + RUNTIME_TIME_CHECK_SIZE(size); + seq.pos = 0; for(i = 0; i < size; i++) { unsigned int ok = 0; @@ -3369,7 +3376,7 @@ int ishtml_ext(const char *a) { } // error (404,500..) -HTS_INLINE int ishttperror(int err) { +int ishttperror(int err) { switch (err / 100) { case 4: case 5: @@ -3545,7 +3552,7 @@ char *strstr_limit(const char *s, const char *sub, const char *limit) { } // retourner adr sans ftp:// -HTS_INLINE char *jump_protocol(const char *source) { +char *jump_protocol(const char *source) { int p; // scheme @@ -3653,10 +3660,12 @@ void unescape_amp(char *s) { // remplacer %20 par ' ', etc.. // buffer MAX 1Ko -HTSEXT_API char *unescape_http(char *catbuff, const char *s) { +HTSEXT_API char *unescape_http(char *const catbuff, const size_t size, const char *const s) { size_t i, j; - for(i = 0, j = 0; s[i] != '\0'; i++) { + RUNTIME_TIME_CHECK_SIZE(size); + + for(i = 0, j = 0; s[i] != '\0' && j + 1 < size ; i++) { int h; if (s[i] == '%' && (h = ehex(&s[i + 1])) >= 0) { catbuff[j++] = (char) h; @@ -3673,10 +3682,13 @@ HTSEXT_API char *unescape_http(char *catbuff, const char *s) { // DOES NOT DECODE %25 (part of CHAR_DELIM) // no_high & 1: decode high chars // no_high & 2: decode space -HTSEXT_API char *unescape_http_unharm(char *catbuff, const char *s, int no_high) { +HTSEXT_API char *unescape_http_unharm(char *const catbuff, const size_t size, + const char *s, const int no_high) { size_t i, j; - for(i = 0, j = 0; s[i] != '\0'; i++) { + RUNTIME_TIME_CHECK_SIZE(size); + + for(i = 0, j = 0; s[i] != '\0' && j + 1 < size ; i++) { if (s[i] == '%') { const int nchar = ehex(&s[i + 1]); @@ -3705,182 +3717,228 @@ HTSEXT_API char *unescape_http_unharm(char *catbuff, const char *s, int no_high) // remplacer " par %xx etc.. // buffer MAX 1Ko -HTSEXT_API void escape_spc_url(char *s) { - x_escape_http(s, 2); +HTSEXT_API size_t escape_spc_url(const char *const src, + char *const dest, const size_t size) { + return x_escape_http(src, dest, size, 2); } // smith / john -> smith%20%2f%20john -HTSEXT_API void escape_in_url(char *s) { - x_escape_http(s, 1); +HTSEXT_API size_t escape_in_url(const char *const src, + char *const dest, const size_t size) { + return x_escape_http(src, dest, size, 1); } // smith / john -> smith%20/%20john -HTSEXT_API void escape_uri(char *s) { - x_escape_http(s, 3); +HTSEXT_API size_t escape_uri(const char *const src, + char *const dest, const size_t size) { + return x_escape_http(src, dest, size, 3); } -HTSEXT_API void escape_uri_utf(char *s) { - x_escape_http(s, 30); + +HTSEXT_API size_t escape_uri_utf(const char *const src, + char *const dest, const size_t size) { + return x_escape_http(src, dest, size, 30); } -HTSEXT_API void escape_check_url(char *s) { - x_escape_http(s, 0); + +HTSEXT_API size_t escape_check_url(const char *const src, + char *const dest, const size_t size) { + return x_escape_http(src, dest, size, 0); } // same as escape_check_url, but returns char* -HTSEXT_API char *escape_check_url_addr(char *catbuff, const char *s) { - char *adr; +HTSEXT_API char *escape_check_url_addr(const char *const src, + char *const dest, const size_t size) { + escape_check_url(src, dest, size); + return dest; +} - escape_check_url(adr = concat(catbuff, s, "")); - return adr; +// Same as above, but appending to "dest" +#undef DECLARE_APPEND_ESCAPE_VERSION +#define DECLARE_APPEND_ESCAPE_VERSION(NAME) \ +HTSEXT_API size_t append_ ##NAME(const char *const src, char *const dest, const size_t size) { \ + const size_t len = strnlen(dest, size); \ + assert(len < size); \ + return NAME(src, dest + len, size - len); \ +} + +DECLARE_APPEND_ESCAPE_VERSION(escape_in_url) +DECLARE_APPEND_ESCAPE_VERSION(escape_spc_url) +DECLARE_APPEND_ESCAPE_VERSION(escape_uri_utf) +DECLARE_APPEND_ESCAPE_VERSION(escape_check_url) +DECLARE_APPEND_ESCAPE_VERSION(escape_uri) + +#undef DECLARE_APPEND_ESCAPE_VERSION + +// Same as above, but in-place +#undef DECLARE_INPLACE_ESCAPE_VERSION +#define DECLARE_INPLACE_ESCAPE_VERSION(NAME) \ +HTSEXT_API size_t inplace_ ##NAME(char *const dest, const size_t size) { \ + char buffer[256]; \ + const size_t len = strnlen(dest, size); \ + const int in_buffer = len + 1 < sizeof(buffer); \ + char *src = in_buffer ? buffer : malloct(len + 1); \ + size_t ret; \ + assert(src != NULL); \ + assert(len < size); \ + memcpy(src, dest, len + 1); \ + ret = NAME(src, dest, size); \ + if (!in_buffer) { \ + freet(src); \ + } \ + return ret; \ +} + +DECLARE_INPLACE_ESCAPE_VERSION(escape_in_url) +DECLARE_INPLACE_ESCAPE_VERSION(escape_spc_url) +DECLARE_INPLACE_ESCAPE_VERSION(escape_uri_utf) +DECLARE_INPLACE_ESCAPE_VERSION(escape_check_url) +DECLARE_INPLACE_ESCAPE_VERSION(escape_uri) + +#undef DECLARE_INPLACE_ESCAPE_VERSION + + +HTSEXT_API size_t make_content_id(const char *const adr, const char *const fil, + char *const dest, const size_t size) { + char *a; + size_t esc_size = escape_in_url(adr, dest, size); + esc_size += escape_in_url(fil, dest + esc_size, size - esc_size); + RUNTIME_TIME_CHECK_SIZE(size); + for(a = dest ; (a = strchr(a, '%')) != NULL ; a++) { + *a = 'X'; + } + return esc_size; } // strip all control characters -HTSEXT_API void escape_remove_control(char *s) { - unsigned char *ss = (unsigned char *) s; - - while(*ss) { - if (*ss < 32) { /* CONTROL characters go away! */ - char BIGSTK tmp[HTS_URLMAXSIZE * 2]; - - strcpybuff(tmp, (char *) ss + 1); - strcpybuff((char *) ss, tmp); - } else { - ss++; +HTSEXT_API void escape_remove_control(char *const s) { + size_t i, j; + for(i = 0, j = 0 ; s[i] != '\0' ; i++) { + const unsigned char c = (unsigned char) s[i]; + if (c >= 32) { + if (i != j) { + assert(j < i); + s[j] = s[i]; + } + j++; } } } -HTSEXT_API void x_escape_html(char *s) { - while(*s) { - int test = 0; +#undef ADD_CHAR +#define ADD_CHAR(C) do { \ + assert(j < size); \ + if (j + 1 == size) { \ + dest[j] = '\0'; \ + return size; \ + } \ + dest[j++] = (C); \ + } while(0) - test = (CHAR_HIG(*s) - || CHAR_XXAVOID(*s)); +/* Returns the number of characters written (not taking in account the terminating \0), or 'size' upon overflow. */ +HTSEXT_API size_t x_escape_http(const char *const s, char *const dest, + const size_t size, const int mode) { + static const char hex[] = "0123456789abcdef"; + size_t i, j; - if (test) { - char BIGSTK buffer[HTS_URLMAXSIZE * 3]; - int n; + RUNTIME_TIME_CHECK_SIZE(size); - n = (int) (unsigned char) *s; - strcpybuff(buffer, s + 1); - sprintf(s, "&#x%02x;", n); - strcatbuff(s, buffer); - } - s++; + // Out-of-bound. + // Previous character is supposed to be the terminating \0. + if (size == 0) { + return 0; } -} -HTSEXT_API void x_escape_http(char *s, int mode) { - while(*s) { + for(i = 0, j = 0 ; s[i] != '\0' ; i++) { + const unsigned char c = (unsigned char) s[i]; int test = 0; if (mode == 0) - test = (strchr("\" ", *s) != 0 || CHAR_SPECIAL(*s)); - else if (mode == 1) { - test = (CHAR_RESERVED(*s) - || CHAR_DELIM(*s) - || CHAR_UNWISE(*s) - || CHAR_SPECIAL(*s) - || CHAR_XXAVOID(*s) - || CHAR_MARK(*s)); - } else if (mode == 2) - test = (*s == ' '); // n'escaper que espace - else if (mode == 3) { // échapper que ce qui est nécessaire - test = (CHAR_SPECIAL(*s) - || CHAR_XXAVOID(*s)); - } else if (mode == 30) { // échapper que ce qui est nécessaire - test = (*s != '/' && CHAR_RESERVED(*s)) - || CHAR_DELIM(*s) - || CHAR_UNWISE(*s) - || CHAR_SPECIAL(*s) - || CHAR_XXAVOID(*s); - } - - if (test) { - char BIGSTK buffer[HTS_URLMAXSIZE * 3]; - int n; - - n = (int) (unsigned char) *s; - strcpybuff(buffer, s + 1); - sprintf(s, "%%%02x", n); - strcatbuff(s, buffer); + test = c == '"' || c == ' ' || CHAR_SPECIAL(c); + else if (mode == 1) + test = CHAR_RESERVED(c) + || CHAR_DELIM(c) + || CHAR_UNWISE(c) + || CHAR_SPECIAL(c) + || CHAR_XXAVOID(c) + || CHAR_MARK(c); + else if (mode == 2) + test = c == ' '; // n'escaper que espace + else if (mode == 3) // échapper que ce qui est nécessaire + test = CHAR_SPECIAL(c) + || CHAR_XXAVOID(c); + else if (mode == 30) // échapper que ce qui est nécessaire + test = (c != '/' && CHAR_RESERVED(c)) + || CHAR_DELIM(c) + || CHAR_UNWISE(c) + || CHAR_SPECIAL(c) + || CHAR_XXAVOID(c); + + if (!test) { + ADD_CHAR(c); + } else { + ADD_CHAR('%'); + ADD_CHAR(hex[c / 16]); + ADD_CHAR(hex[c % 16]); } - s++; } + + assert(j < size); + dest[j] = '\0'; + return j; } -HTSEXT_API void escape_for_html_print(char *s, char *d) { - for(; *s; s++) { - if (*s == '&') { - strcpybuff(d, "&"); - d += strlen(d); +HTSEXT_API size_t escape_for_html_print(const char *const s, char *const dest, const size_t size) { + size_t i, j; + + RUNTIME_TIME_CHECK_SIZE(size); + + for(i = 0, j = 0 ; s[i] != '\0' ; i++) { + const unsigned char c = (unsigned char) s[i]; + if (c == '&') { + ADD_CHAR('&'); + ADD_CHAR('a'); + ADD_CHAR('m'); + ADD_CHAR('p'); + ADD_CHAR(';'); } else { - *d++ = *s; + ADD_CHAR(c); } } - *d = '\0'; + assert(j < size); + dest[j] = '\0'; + return j; } -HTSEXT_API void escape_for_html_print_full(char *s, char *d) { - for(; *s; s++) { - if (*s == '&') { - strcpybuff(d, "&"); - d += strlen(d); - } else if (CHAR_HIG(*s)) { - sprintf(d, "&#x%02x;", (unsigned char) *s); - d += strlen(d); +HTSEXT_API size_t escape_for_html_print_full(const char *const s, char *const dest, const size_t size) { + static const char hex[] = "0123456789abcdef"; + size_t i, j; + + RUNTIME_TIME_CHECK_SIZE(size); + + for(i = 0, j = 0 ; s[i] != '\0' ; i++) { + const unsigned char c = (unsigned char) s[i]; + if (c == '&') { + ADD_CHAR('&'); + ADD_CHAR('a'); + ADD_CHAR('m'); + ADD_CHAR('p'); + ADD_CHAR(';'); + } else if (CHAR_HIG(c)) { + ADD_CHAR('&'); + ADD_CHAR('#'); + ADD_CHAR('x'); + ADD_CHAR(hex[c / 16]); + ADD_CHAR(hex[c % 16]); + ADD_CHAR(';'); } else { - *d++ = *s; + ADD_CHAR(c); } } - *d = '\0'; -} - -// concat, concatène deux chaines et renvoi le résultat -// permet d'alléger grandement le code -// il faut savoir qu'on ne peut mettre plus de 16 concat() dans une expression -HTSEXT_API char *concat(char *catbuff, const char *a, const char *b) { - if (a != NULL && a[0] != '\0') { - strcpybuff(catbuff, a); - } else { - catbuff[0] = '\0'; - } - if (b != NULL && b[0] != '\0') { - strcatbuff(catbuff, b); - } - return catbuff; -} - -// conversion fichier / -> antislash -static char *__fconv(char *a) { -#if HTS_DOSNAME - int i; - - for(i = 0; a[i] != 0; i++) - if (a[i] == '/') // Unix-to-DOS style - a[i] = '\\'; -#endif - return a; -} - -HTSEXT_API char *fconcat(char *catbuff, const char *a, const char *b) { - return __fconv(concat(catbuff, a, b)); -} -HTSEXT_API char *fconv(char *catbuff, const char *a) { - return __fconv(concat(catbuff, a, "")); + assert(j < size); + dest[j] = '\0'; + return j; } -/* / et \\ en / */ -static char *__fslash(char *a) { - int i; - - for(i = 0; a[i] != 0; i++) - if (a[i] == '\\') // convertir - a[i] = '/'; - return a; -} -char *fslash(char *catbuff, const char *a) { - return __fslash(concat(catbuff, a, NULL)); -} +#undef ADD_CHAR // conversion minuscules, avec buffer char *convtolower(char *catbuff, const char *a) { @@ -3899,7 +3957,7 @@ void hts_lowcase(char *s) { } // remplacer un caractère d'une chaîne dans une autre -HTS_INLINE void hts_replace(char *s, char from, char to) { +void hts_replace(char *s, char from, char to) { char *a; while((a = strchr(s, from)) != NULL) { @@ -3907,35 +3965,6 @@ HTS_INLINE void hts_replace(char *s, char from, char to) { } } -// caractère espace, guillemets, CR, LF etc.. -/* SECTION OPTIMISEE: - #define is_space(c) (strchr(" \"\x0d\x0a\x09'",c)!=NULL) - #define is_realspace(c) (strchr(" \x0d\x0a\x09\x0c",c)!=NULL) -*/ -/* -static HTS_INLINE int is_space(char c) { - if (c==' ') return 1; // spc - if (c=='"') return 1; // quote - if (c==10) return 1; // lf - if (c==13) return 1; // cr - if (c=='\'') return 1; // quote - //if (c=='`') return 1; // backquote << non - if (c==9) return 1; // tab - return 0; -} -*/ - -// caractère espace, CR, LF, TAB -/* -static HTS_INLINE int is_realspace(char c) { - if (c==' ') return 1; // spc - if (c==10) return 1; // lf - if (c==13) return 1; // cr - if (c==9) return 1; // tab - return 0; -} -*/ - // deviner type d'un fichier local.. // ex: fil="toto.gif" -> s="image/gif" void guess_httptype(httrackp * opt, char *s, const char *fil) { @@ -4138,7 +4167,7 @@ HTSEXT_API int is_knowntype(httrackp * opt, const char *fil) { if (!fil) return 0; - ext = get_ext(catbuff, fil); + ext = get_ext(catbuff, sizeof(catbuff), fil); while(strnotempty(hts_mime[j][1])) { if (strfield2(hts_mime[j][1], ext)) { if (is_html_mime_type(hts_mime[j][0])) @@ -4153,27 +4182,6 @@ HTSEXT_API int is_knowntype(httrackp * opt, const char *fil) { return (is_userknowntype(opt, fil)); } -// extension : html,gif.. -HTSEXT_API char *get_ext(char *catbuff, const char *fil) { - const char *a = fil + strlen(fil) - 1; - - while((*a != '.') && (*a != '/') && (a > fil)) - a--; - if (*a == '.') { - char fil_noquery[HTS_URLMAXSIZE * 2]; - char *b; - - fil_noquery[0] = '\0'; - a++; // pointer sur extension - strncatbuff(fil_noquery, a, HTS_URLMAXSIZE); - b = strchr(fil_noquery, '?'); - if (b) - *b = '\0'; - return concat(catbuff, fil_noquery, ""); - } else - return ""; -} - // known type?.. // 0 : no // 1 : yes @@ -4311,7 +4319,7 @@ int fexist(const char *s) { struct stat st; memset(&st, 0, sizeof(st)); - if (stat(fconv(catbuff, s), &st) == 0) { + if (stat(fconv(catbuff, sizeof(catbuff), s), &st) == 0) { if (S_ISREG(st.st_mode)) { return 1; } else { @@ -4331,7 +4339,7 @@ int fexist_utf8(const char *s) { STRUCT_STAT st; memset(&st, 0, sizeof(st)); - if (STAT(fconv(catbuff, s), &st) == 0) { + if (STAT(fconv(catbuff, sizeof(catbuff), s), &st) == 0) { if (S_ISREG(st.st_mode)) { return 1; } else { @@ -4606,28 +4614,13 @@ static t_hostent *hts_ghbn(const t_dnscache *cache, const char *const iadr, t_ho return NULL; } -HTSEXT_API t_hostent *vxgethostbyname2(const char *hostname, void *v_buffer, const char **error) { - char BIGSTK tempo[HTS_URLMAXSIZE * 2]; +static t_hostent *vxgethostbyname2_(const char *const hostname, + void *const v_buffer, const char **error) { t_fullhostent *buffer = (t_fullhostent *) v_buffer; /* Clear */ fullhostent_init(buffer); - /* Protection */ - if (!strnotempty(hostname)) { - return NULL; - } - - /* - Strip [] if any : [3ffe:b80:1234:1::1] - The resolver doesn't seem to handle IP6 addresses in brackets - */ - if ((hostname[0] == '[') && (hostname[strlen(hostname) - 1] == ']')) { - tempo[0] = '\0'; - strncatbuff(tempo, hostname + 1, strlen(hostname) - 2); - hostname = tempo; - } - { #if HTS_INET6==0 /* @@ -4688,11 +4681,37 @@ HTSEXT_API t_hostent *vxgethostbyname2(const char *hostname, void *v_buffer, con return NULL; } -HTSEXT_API t_hostent *vxgethostbyname(const char *hostname, void *v_buffer) { +HTSEXT_API t_hostent *vxgethostbyname2(const char *const hostname, + void *const v_buffer, const char **error) { + /* Protection */ + if (!strnotempty(hostname)) { + return NULL; + } + + /* + Strip [] if any : [3ffe:b80:1234:1::1] + The resolver doesn't seem to handle IP6 addresses in brackets + */ + if ((hostname[0] == '[') && (hostname[strlen(hostname) - 1] == ']')) { + t_hostent *ret; + size_t size = strlen(hostname); + char *copy = malloct(size + 1); + assert(copy != NULL); + copy[0] = '\0'; + strncat(copy, hostname + 1, size - 2); + ret = vxgethostbyname2_(copy, v_buffer, error); + freet(copy); + return ret; + } else { + return vxgethostbyname2_(hostname, v_buffer, error); + } +} + +HTSEXT_API t_hostent *vxgethostbyname(const char *const hostname, void *v_buffer) { return vxgethostbyname2(hostname, v_buffer, NULL); } -HTSEXT_API int check_hostname_dns(const char *hostname) { +HTSEXT_API int check_hostname_dns(const char *const hostname) { t_fullhostent buffer; return vxgethostbyname(hostname, &buffer) != NULL; } @@ -4790,7 +4809,7 @@ t_hostent *hts_gethostbyname(httrackp * opt, const char *_iadr, void *v_buffer) } #else -static HTS_INLINE t_hostent *hts_gethostbyname(httrackp * opt, const char *iadr, +static HTS_INLINE t_hostent *hts_gethostbyname(httrackp * opt, char *iadr, t_fullhostent * buffer) { t_hostent *retour; @@ -5823,7 +5842,7 @@ HTSEXT_API void *hts_malloc(size_t size) { return malloc(size); } -HTSEXT_API void *hts_realloc(void *data, size_t size) { +HTSEXT_API void *hts_realloc(void *const data, const size_t size) { return realloc(data, size); } diff --git a/src/htslib.h b/src/htslib.h index 1483ae3..e13dbeb 100644 --- a/src/htslib.h +++ b/src/htslib.h @@ -35,6 +35,8 @@ Please visit our Website: http://www.httrack.com #ifndef HTS_DEFH #define HTS_DEFH +#include "httrack-library.h" + /* Forward definitions */ #ifndef HTS_DEF_FWSTRUCT_htsrequest #define HTS_DEF_FWSTRUCT_htsrequest @@ -92,7 +94,8 @@ MSVC2003INLINEBUG HTS_STATIC char *getHtsOptBuff_(httrackp * opt) { } #undef MSVC2003INLINEBUG -#define OPT_GET_BUFF(OPT) ( getHtsOptBuff_(OPT) ) +#define OPT_GET_BUFF(OPT) ( getHtsOptBuff_(OPT) ) +#define OPT_GET_BUFF_SIZE(OPT) ( sizeof(opt->state.concat.buff[0]) ) // structure pour paramètres supplémentaires lors de la requête #ifndef HTS_DEF_FWSTRUCT_htsrequest_proxy @@ -240,24 +243,7 @@ int hts_read(htsblk * r, char *buff, int size); //int HTS_TOTAL_RECV_CHECK(int var); LLint check_downloadable_bytes(int rate); -#ifndef HTTRACK_DEFLIB -HTSEXT_API int hts_init(void); -HTSEXT_API int hts_uninit(void); HTSEXT_API int hts_uninit_module(void); -HTSEXT_API int hts_resetvar(void); /* dummy */ -HTSEXT_API void hts_debug(int level); -HTSEXT_API httrackp *hts_create_opt(void); -HTSEXT_API void hts_free_opt(httrackp * opt); -HTSEXT_API const hts_stat_struct* hts_get_stats(httrackp * opt); -HTSEXT_API void set_wrappers(httrackp * opt); /* LEGACY */ -HTSEXT_API int plug_wrapper(httrackp * opt, const char *moduleName, - const char *argv); - -HTSEXT_API char *hts_strdup(const char *string); -HTSEXT_API void *hts_malloc(size_t size); -HTSEXT_API void *hts_realloc(void *data, size_t size); -HTSEXT_API void hts_free(void *data); -#endif // fonctions principales T_SOC http_fopen(httrackp * opt, char *adr, char *fil, htsblk * retour); @@ -282,39 +268,28 @@ void treathead(t_cookie * cookie, char *adr, char *fil, htsblk * retour, char *rcvd); void treatfirstline(htsblk * retour, char *rcvd); -#ifndef HTTRACK_DEFLIB -HTSEXT_API void infostatuscode(char *msg, int statuscode); -#endif - // sous-fonctions LLint http_xfread1(htsblk * r, int bufl); HTS_INLINE t_hostent *hts_gethostbyname2(httrackp * opt, const char *iadr, void *v_buffer, const char **error); HTS_INLINE t_hostent *hts_gethostbyname(httrackp * opt, const char *iadr, void *v_buffer); -#ifndef HTTRACK_DEFLIB -HTSEXT_API t_hostent *vxgethostbyname2(const char *hostname, void *v_buffer, const char **error); -HTSEXT_API t_hostent *vxgethostbyname(const char *hostname, void *v_buffer); -HTSEXT_API int check_hostname_dns(const char *hostname); -#endif +HTSEXT_API t_hostent *vxgethostbyname2(const char *const hostname, void *v_buffer, const char **error); +HTSEXT_API t_hostent *vxgethostbyname(const char *const hostname, void *v_buffer); +HTSEXT_API int check_hostname_dns(const char *const hostname); + int ftp_available(void); #if HTS_DNSCACHE -void hts_cache_free(t_dnscache * cache); +void hts_cache_free(t_dnscache *const cache); t_dnscache *_hts_cache(httrackp * opt); #endif // outils divers HTS_INLINE TStamp time_local(void); -#ifndef HTTRACK_DEFLIB -HTSEXT_API HTS_INLINE TStamp mtime_local(void); -#endif void sec2str(char *s, TStamp t); -#ifndef HTTRACK_DEFLIB -HTSEXT_API void qsec2str(char *st, TStamp t); -#endif void time_gmt_rfc822(char *s); void time_local_rfc822(char *s); struct tm *convert_time_rfc822(struct tm *buffer, const char *s); @@ -324,12 +299,6 @@ int get_filetime_rfc822(const char *file, char *date); HTS_INLINE void time_rfc822(char *s, struct tm *A); HTS_INLINE void time_rfc822_local(char *s, struct tm *A); -#ifndef HTTRACK_DEFLIB -HTSEXT_API char *int2char(strc_int2bytes2 * strc, int n); -HTSEXT_API char *int2bytes(strc_int2bytes2 * strc, LLint n); -HTSEXT_API char *int2bytessec(strc_int2bytes2 * strc, long int n); -HTSEXT_API char **int2bytes2(strc_int2bytes2 * strc, LLint n); -#endif HTS_INLINE int sendc(htsblk * r, const char *s); int finput(int fd, char *s, int max); int binput(char *buff, char *s, int max); @@ -342,7 +311,7 @@ void rawlinput(FILE * fp, char *s, int max); char *strstrcase(char *s, char *o); int ident_url_absolute(const char *url, char *adr, char *fil); void fil_simplifie(char *f); -int is_unicode_utf8(const char *buffer, size_t size); +int is_unicode_utf8(const char *buffer, const size_t size); void map_characters(unsigned char *buffer, unsigned int size, unsigned int *map); int ishtml(httrackp * opt, const char *urlfil); @@ -357,118 +326,70 @@ HTSEXT_API void get_httptype(httrackp * opt, char *s, const char *fil, int get_userhttptype(httrackp * opt, char *s, const char *fil); void give_mimext(char *s, const char *st); -#ifndef HTTRACK_DEFLIB -HTSEXT_API int is_knowntype(httrackp * opt, const char *fil); -HTSEXT_API int is_userknowntype(httrackp * opt, const char *fil); -HTSEXT_API int is_dyntype(const char *fil); -HTSEXT_API char *get_ext(char *catbuff, const char *fil); -#endif int may_unknown(httrackp * opt, const char *st); int may_bogus_multiple(httrackp * opt, const char *mime, const char *filename); int may_unknown2(httrackp * opt, const char *mime, const char *filename); -#ifndef HTTRACK_DEFLIB -HTSEXT_API char *jump_identification(const char *); -HTSEXT_API char *jump_normalized(const char *); -HTSEXT_API char *jump_toport(const char *); -HTSEXT_API char *fil_normalized(const char *source, char *dest); -HTSEXT_API char *adr_normalized(const char *source, char *dest); -#endif char *strrchr_limit(const char *s, char c, const char *limit); char *strstr_limit(const char *s, const char *sub, const char *limit); HTS_INLINE char *jump_protocol(const char *source); void code64(unsigned char *a, int size_a, unsigned char *b, int crlf); -#ifndef HTTRACK_DEFLIB -HTSEXT_API void unescape_amp(char *s); -HTSEXT_API void escape_spc_url(char *s); -HTSEXT_API void escape_in_url(char *s); -HTSEXT_API void escape_uri(char *s); -HTSEXT_API void escape_uri_utf(char *s); -HTSEXT_API void escape_check_url(char *s); -HTSEXT_API char *escape_check_url_addr(char *catbuff, const char *s); -HTSEXT_API void x_escape_http(char *s, int mode); -HTSEXT_API void x_escape_html(char *s); -HTSEXT_API void escape_remove_control(char *s); -HTSEXT_API void escape_for_html_print(char *s, char *d); -HTSEXT_API void escape_for_html_print_full(char *s, char *d); -#endif -#ifndef HTTRACK_DEFLIB -HTSEXT_API char *unescape_http(char *catbuff, const char *s); -HTSEXT_API char *unescape_http_unharm(char *catbuff, const char *s, - int no_high); -HTSEXT_API char *antislash_unescaped(char *catbuff, const char *s); -HTSEXT_API char *concat(char *catbuff, const char *a, const char *b); -HTSEXT_API char *fconcat(char *catbuff, const char *a, const char *b); -HTSEXT_API char *fconv(char *catbuff, const char *a); -#endif #define copychar(catbuff,a) concat(catbuff,(a),NULL) -char *fslash(char *catbuff, const char *a); -#ifndef HTTRACK_DEFLIB -HTSEXT_API int hts_log(httrackp * opt, const char *prefix, const char *msg); -HTSEXT_API void hts_log_print(httrackp * opt, int type, const char *format, - ...) HTS_PRINTF_FUN(3, 4); -#endif - - char *convtolower(char *catbuff, const char *a); - void hts_lowcase(char *s); - void hts_replace(char *s, char from, char to); - int multipleStringMatch(const char *s, const char *match); +char *convtolower(char *catbuff, const char *a); +void hts_lowcase(char *s); +void hts_replace(char *s, char from, char to); +int multipleStringMatch(const char *s, const char *match); - void fprintfio(FILE * fp, char *buff, char *prefix); +void fprintfio(FILE * fp, char *buff, char *prefix); #ifdef _WIN32 #else - int sig_ignore_flag(int setflag); // flag ignore +int sig_ignore_flag(int setflag); // flag ignore #endif - void cut_path(char *fullpath, char *path, char *pname); - int fexist(const char *s); - int fexist_utf8(const char *s); +void cut_path(char *fullpath, char *path, char *pname); +int fexist(const char *s); +int fexist_utf8(const char *s); /*LLint fsize(const char* s); */ - off_t fpsize(FILE * fp); - off_t fsize(const char *s); - off_t fsize_utf8(const char *s); - -/* root dir */ -#ifndef HTTRACK_DEFLIB - HTSEXT_API char *hts_rootdir(char *file); -#endif +off_t fpsize(FILE * fp); +off_t fsize(const char *s); +off_t fsize_utf8(const char *s); // Threads - typedef void *(*beginthread_type) (void *); +typedef void *(*beginthread_type) (void *); /*unsigned long _beginthread( beginthread_type start_address, unsigned stack_size, void *arglist );*/ /* variables globales */ - extern HTSEXT_API hts_stat_struct HTS_STAT; - extern int _DEBUG_HEAD; - extern FILE *ioinfo; +extern HTSEXT_API hts_stat_struct HTS_STAT; +extern int _DEBUG_HEAD; +extern FILE *ioinfo; /* constantes */ - extern const char *hts_mime_keep[]; - extern const char *hts_mime[][2]; - extern const char *hts_main_mime[]; - extern const char *hts_detect[]; - extern const char *hts_detectbeg[]; - extern const char *hts_nodetect[]; - extern const char *hts_detectURL[]; - extern const char *hts_detectandleave[]; - extern const char *hts_detect_js[]; +extern const char *hts_mime_keep[]; +extern const char *hts_mime[][2]; +extern const char *hts_main_mime[]; +extern const char *hts_detect[]; +extern const char *hts_detectbeg[]; +extern const char *hts_nodetect[]; +extern const char *hts_detectURL[]; +extern const char *hts_detectandleave[]; +extern const char *hts_detect_js[]; // htsmodule.c definitions - extern void *openFunctionLib(const char *file_); - extern void *getFunctionPtr(void *handle, const char *fncname); - extern void closeFunctionLib(void *handle); +extern void *openFunctionLib(const char *file_); +extern void *getFunctionPtr(void *handle, const char *fncname); +extern void closeFunctionLib(void *handle); - extern void clearCallbacks(htscallbacks * chain); - extern size_t hts_get_callback_offs(const char *name); - int hts_set_callback(t_hts_htmlcheck_callbacks * callbacks, - const char *name, void *function); - void *hts_get_callback(t_hts_htmlcheck_callbacks * callbacks, - const char *name); +extern void clearCallbacks(htscallbacks * chain); +extern size_t hts_get_callback_offs(const char *name); +int hts_set_callback(t_hts_htmlcheck_callbacks * callbacks, + const char *name, void *function); +void *hts_get_callback(t_hts_htmlcheck_callbacks * callbacks, + const char *name); #define CBSTRUCT(OPT) ((t_hts_htmlcheck_callbacks*) ((OPT)->callbacks_fun)) #define GET_USERCALLBACK(OPT, NAME) ( CBSTRUCT(OPT)-> NAME .fun ) @@ -581,7 +502,7 @@ HTSEXT_API void hts_log_print(httrackp * opt, int type, const char *format, // compare le début de f avec s et retourne la position de la fin // 'A=a' (case insensitive) - HTS_STATIC int strfield(const char *f, const char *s) { +HTS_STATIC int strfield(const char *f, const char *s) { int r = 0; while(streql(*f, *s) && ((*f) != 0) && ((*s) != 0)) { @@ -593,7 +514,8 @@ HTSEXT_API void hts_log_print(httrackp * opt, int type, const char *format, return r; else return 0; - } +} + HTS_STATIC int strcmpnocase(char *a, char *b) { while(*a) { int cmp = hichar(*a) - hichar(*b); diff --git a/src/htsname.c b/src/htsname.c index 500e5a6..1a3ee47 100644 --- a/src/htsname.c +++ b/src/htsname.c @@ -328,8 +328,8 @@ int url_savename(char *adr_complete, char *fil_complete, char *save, is_html = ishtml(opt, fil); switch (is_html) { /* .html,.shtml,.. */ case 1: - if ((strfield2(get_ext(OPT_GET_BUFF(opt), fil), "html") == 0) - && (strfield2(get_ext(OPT_GET_BUFF(opt), fil), "htm") == 0) + if ((strfield2(get_ext(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), fil), "html") == 0) + && (strfield2(get_ext(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), fil), "htm") == 0) ) { strcpybuff(ext, "html"); ext_chg = 1; @@ -845,7 +845,7 @@ int url_savename(char *adr_complete, char *fil_complete, char *save, *d++ = *c++; } *d = '\0'; - d = unescape_http(catbuff, name[0]); + d = unescape_http(catbuff, sizeof(catbuff), name[0]); if (d && *d) { strcpybuff(b, d); /* value */ b += strlen(b); @@ -1714,7 +1714,8 @@ char *url_savename_refname_fullpath(httrackp * opt, const char *adr, char digest_filename[64]; url_savename_refname(adr, fil, digest_filename); - return fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), digest_filename); + return fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), digest_filename); } /* remove refname if any */ diff --git a/src/htsparse.c b/src/htsparse.c index 941a72c..6869293 100644 --- a/src/htsparse.c +++ b/src/htsparse.c @@ -106,7 +106,7 @@ Please visit our Website: http://www.httrack.com if ((opt->getmode & 1) && (ptr>0)) { \ size_t i_, j_; \ char BIGSTK tempo_[HTS_URLMAXSIZE*2]; \ - escape_for_html_print(A, tempo_); \ + escape_for_html_print(A, tempo_, sizeof(tempo_)); \ i_=strlen(tempo_); \ j_=ht_len; \ if (i_) { \ @@ -118,7 +118,7 @@ Please visit our Website: http://www.httrack.com if ((opt->getmode & 1) && (ptr>0)) { \ size_t i_, j_; \ char BIGSTK tempo_[HTS_URLMAXSIZE*2]; \ - escape_for_html_print_full(A, tempo_); \ + escape_for_html_print_full(A, tempo_, sizeof(tempo_)); \ i_=strlen(tempo_); \ j_=ht_len; \ if (i_) { \ @@ -144,7 +144,7 @@ Please visit our Website: http://www.httrack.com int ok=0;\ if (ht_buff) { \ char digest[32+2];\ - off_t fsize_old = fsize(fconv(OPT_GET_BUFF(opt),savename));\ + off_t fsize_old = fsize(fconv(OPT_GET_BUFF(opt),OPT_GET_BUFF_SIZE(opt),savename));\ digest[0]='\0';\ domd5mem(ht_buff,ht_len,digest,1);\ if (fsize_old==ht_len) { \ @@ -210,8 +210,7 @@ Please visit our Website: http://www.httrack.com char BIGSTK tempo[1024]; \ if (makeindex_links == 1) { \ char BIGSTK link_escaped[HTS_URLMAXSIZE*2]; \ - strcpybuff(link_escaped, makeindex_firstlink); \ - escape_uri_utf(link_escaped); \ + escape_uri_utf(makeindex_firstlink, link_escaped, sizeof(link_escaped)); \ sprintf(tempo,"<meta HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=%s\">"CRLF,link_escaped); \ } else \ tempo[0]='\0'; \ @@ -222,7 +221,7 @@ Please visit our Website: http://www.httrack.com fflush(makeindex_fp); \ fclose(makeindex_fp); /* à ne pas oublier sinon on passe une nuit blanche */ \ makeindex_fp=NULL; \ - usercommand(opt,0,NULL,fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_html_utf8),"index.html"),"primary","primary"); \ + usercommand(opt,0,NULL,fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_html_utf8),"index.html"),"primary","primary"); \ } \ } \ makeindex_done=1; /* ok c'est fait */ \ @@ -654,13 +653,13 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) { if (p) { // ok center if (makeindex_fp == NULL) { file_notify(opt, "", "", - fconcat(OPT_GET_BUFF(opt), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_html_utf8), "index.html"), 1, 1, 0); verif_backblue(opt, StringBuff(opt->path_html_utf8)); // générer gif makeindex_fp = filecreate(&opt->state.strc, - fconcat(OPT_GET_BUFF(opt), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_html_utf8), "index.html")); if (makeindex_fp != NULL) { @@ -692,7 +691,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) { } if (lienrelatif (tempo, liens[ptr]->sav, - concat(OPT_GET_BUFF(opt), + concat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_html_utf8), "index.html")) == 0) { detect_title = 1; // ok détecté pour cette page! @@ -729,7 +728,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) { } // Body - escape_uri_utf(tempo); + inplace_escape_uri_utf(tempo, sizeof(tempo)); fprintf(makeindex_fp, template_body, tempo, s); } } @@ -1720,7 +1719,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) { get_httptype(opt, type, tempo, 0); if (strnotempty(type)) // type reconnu! url_ok = 1; - else if (is_dyntype(get_ext(OPT_GET_BUFF(opt), tempo))) // reconnu php,cgi,asp.. + else if (is_dyntype(get_ext(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), tempo))) // reconnu php,cgi,asp.. url_ok = 1; // MAIS pas les foobar@aol.com !! if (strchr(tempo, '@')) @@ -2107,7 +2106,8 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) { } // Unescape %XX, but not yet high-chars (supposedly encoded with UTF-8) - strcpybuff(lien, unescape_http_unharm(catbuff, lien, 1 | 2)); /* note: '%' is still escaped */ + strcpybuff(lien, + unescape_http_unharm(catbuff, sizeof(catbuff), lien, 1 | 2)); /* note: '%' is still escaped */ // Force to encode non-printable chars (should never happend) escape_remove_control(lien); @@ -2155,7 +2155,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) { // we need to encode query string non-ascii chars, // leaving the encoding as-is (unlike the file part) - escape_check_url(query); + inplace_escape_check_url(query, sizeof(query)); // copy back query strcatbuff(lien, query); /* restore */ @@ -2778,7 +2778,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) { if (lienrelatif(tempo, save, relativesavename) == 0) { /* Never escape high-chars (we don't know the encoding!!) */ - escape_uri_utf(tempo); // escape with %xx + inplace_escape_uri_utf(tempo, sizeof(tempo)); // escape with %xx //if (!no_esc_utf) // escape_uri(tempo); // escape with %xx //else @@ -2825,7 +2825,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) { if (verif_external(opt, cat_nb, 1)) { FILE *fp = filecreate(&opt->state.strc, - fconcat(OPT_GET_BUFF(opt), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt-> path_html_utf8), cat_name)); @@ -2844,7 +2844,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) { } fclose(fp); usercommand(opt, 0, NULL, - fconcat(OPT_GET_BUFF(opt), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt-> path_html_utf8), cat_name), "", ""); @@ -2943,21 +2943,11 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) { } */ else if (opt->mimehtml) { - char BIGSTK buff[HTS_URLMAXSIZE * 3]; + char BIGSTK cid[HTS_URLMAXSIZE * 3]; HT_ADD("cid:"); - strcpybuff(buff, adr); - strcatbuff(buff, fil); - escape_in_url(buff); - { - char *a = buff; - - while((a = strchr(a, '%'))) { - *a = 'X'; - a++; - } - } - HT_ADD_HTMLESCAPED(buff); + make_content_id(adr, fil, cid, sizeof(cid)); + HT_ADD_HTMLESCAPED(cid); lastsaved = eadr - 1; // dernier écrit+1 (enfin euh apres on fait un ++ alors hein) } else if (opt->urlmode == 3) { // URI absolue / if ((opt->getmode & 1) && (ptr > 0)) { // ecrire les html @@ -3020,7 +3010,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) { if (lienrelatif(tempo, save, relativesavename) == 0) { if (!in_media) { // In media (such as real audio): don't patch /* Never escape high-chars (we don't know the encoding!!) */ - escape_uri_utf(tempo); + inplace_escape_uri_utf(tempo, sizeof(tempo)); //if (!no_esc_utf) // escape_uri(tempo); // escape with %xx @@ -3681,23 +3671,12 @@ int hts_mirror_check_moved(htsmoduleStruct * str, hts_log_print(opt, LOG_WARNING, "File has moved from %s%s to %s", urladr, urlfil, mov_url); if (!opt->mimehtml) { - escape_uri(mov_url); + inplace_escape_uri(mov_url, sizeof(mov_url)); } else { - char BIGSTK buff[HTS_URLMAXSIZE * 3]; - - strcpybuff(buff, mov_adr); - strcatbuff(buff, mov_fil); - escape_in_url(buff); - { - char *a = buff; - - while((a = strchr(a, '%'))) { - *a = 'X'; - a++; - } - } + char BIGSTK cid[HTS_URLMAXSIZE * 3]; + make_content_id(mov_adr, mov_fil, cid, sizeof(cid)); strcpybuff(mov_url, "cid:"); - strcatbuff(mov_url, buff); + strcatbuff(mov_url, cid); } // On prépare une page qui sautera immédiatement sur la bonne URL // Le scanner re-changera, ensuite, cette URL, pour la mirrorer! @@ -3968,13 +3947,16 @@ void hts_mirror_process_user_interaction(htsmoduleStruct * str, // user pause lockfile : create hts-paused.lock --> HTTrack will be paused if (fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-stop.lock"))) { + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-stop.lock"))) { // remove lockfile remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-stop.lock")); + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-stop.lock")); if (!fexist (fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-stop.lock"))) { + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-stop.lock"))) { do_pause = 1; } } @@ -4022,7 +4004,8 @@ void hts_mirror_process_user_interaction(htsmoduleStruct * str, { FILE *fp = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-paused.lock"), "wb"); if (fp) { fspc(NULL, fp, "info"); // dater @@ -4036,10 +4019,10 @@ void hts_mirror_process_user_interaction(htsmoduleStruct * str, stat_fragment = HTS_STAT.stat_bytes; /* Info for wrappers */ hts_log_print(opt, LOG_INFO, "engine: pause: %s", - fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-paused.lock")); RUN_CALLBACK1(opt, pause, - fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-paused.lock")); } // @@ -4375,15 +4358,17 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct * str, int a = 0; *stre->last_info_shell_ = tl; - if (fexist(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log), "hts-autopsy"))) { // débuggage: teste si le robot est vivant + if (fexist(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log), "hts-autopsy"))) { // débuggage: teste si le robot est vivant // (oui je sais un robot vivant.. mais bon.. il a le droit de vivre lui aussi) // (libérons les robots esclaves de l'internet!) remove(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-autopsy")); fp = fopen(fconcat - (OPT_GET_BUFF(opt), StringBuff(opt->path_log), + (OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), + StringBuff(opt->path_log), "hts-isalive"), "wb"); a = 1; } @@ -4786,7 +4771,7 @@ int hts_wait_delayed(htsmoduleStruct * str, char *adr, char *fil, char *save, strcpybuff(mov_url, back[b].r.location); // copier URL /* Remove (temporarily created) file if it was created */ - UNLINK(fconv(OPT_GET_BUFF(opt), back[b].url_sav)); + UNLINK(fconv(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), back[b].url_sav)); /* Remove slot! */ if (back[b].status == STATUS_READY) { diff --git a/src/htsserver.c b/src/htsserver.c index 354917b..1388110 100644 --- a/src/htsserver.c +++ b/src/htsserver.c @@ -964,7 +964,7 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) { if (pos2 != NULL) { *pos2 = '\0'; if (strstr(name, "..") == NULL) { - if (fexist(fconcat(catbuff, path, name))) { + if (fexist(fconcat(catbuff, sizeof(catbuff), path, name))) { langstr = pos2 + 1; } } @@ -994,20 +994,20 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) { } } else if (strcmp(name, "if-file-exists") == 0) { if (strstr(pos2, "..") == NULL) { - if (!fexist(fconcat(catbuff, path, pos2))) { + if (!fexist(fconcat(catbuff, sizeof(catbuff), path, pos2))) { outputmode = -1; } } } else if (strcmp(name, "if-project-file-exists") == 0) { if (strstr(pos2, "..") == NULL) { if (!fexist - (fconcat(catbuff, StringBuff(fspath), pos2))) { + (fconcat(catbuff, sizeof(catbuff), StringBuff(fspath), pos2))) { outputmode = -1; } } } else if (strcmp(name, "if-file-do-not-exists") == 0) { if (strstr(pos2, "..") == NULL) { - if (fexist(fconcat(catbuff, path, pos2))) { + if (fexist(fconcat(catbuff, sizeof(catbuff), path, pos2))) { outputmode = -1; } } @@ -1498,7 +1498,7 @@ static int htslang_load(char *limit_to, char *path) { /* Load master file (list of keys and internal keys) */ if (!limit_to) { char *mname = "lang.def"; - FILE *fp = fopen(fconcat(catbuff, path, mname), "rb"); + FILE *fp = fopen(fconcat(catbuff, sizeof(catbuff), path, mname), "rb"); if (fp) { char intkey[8192]; @@ -1579,7 +1579,7 @@ static int htslang_load(char *limit_to, char *path) { hashname = LANGINTKEY(name); } sprintf(lbasename, "lang/%s.txt", hashname); - fp = fopen(fconcat(catbuff, path, lbasename), "rb"); + fp = fopen(fconcat(catbuff, sizeof(catbuff), path, lbasename), "rb"); if (fp) { char extkey[8192]; char value[8192]; diff --git a/src/htstools.c b/src/htstools.c index 066e1d3..c176d26 100644 --- a/src/htstools.c +++ b/src/htstools.c @@ -68,16 +68,16 @@ struct find_handle_struct { char path[2048]; }; #endif -#ifndef HTS_DEF_FWSTRUCT_topindex_chain -#define HTS_DEF_FWSTRUCT_topindex_chain -typedef struct topindex_chain topindex_chain; -#endif -struct topindex_chain { - int level; /* sort level */ - char *category; /* category */ - char name[2048]; /* path */ - struct topindex_chain *next; /* next element */ -}; +//#ifndef HTS_DEF_FWSTRUCT_topindex_chain +//#define HTS_DEF_FWSTRUCT_topindex_chain +//typedef struct topindex_chain topindex_chain; +//#endif +//struct topindex_chain { +// int level; /* sort level */ +// char *category; /* category */ +// char name[2048]; /* path */ +// struct topindex_chain *next; /* next element */ +//}; /* Tools */ @@ -541,11 +541,11 @@ int verif_backblue(httrackp * opt, const char *base) { return 0; } if ((!*done) - || (fsize_utf8(fconcat(OPT_GET_BUFF(opt), base, "backblue.gif")) != + || (fsize_utf8(fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), base, "backblue.gif")) != HTS_DATA_BACK_GIF_LEN)) { FILE *fp = filecreate(&opt->state.strc, - fconcat(OPT_GET_BUFF(opt), base, "backblue.gif")); + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), base, "backblue.gif")); *done = 1; if (fp) { if (fwrite(HTS_DATA_BACK_GIF, HTS_DATA_BACK_GIF_LEN, 1, fp) != @@ -553,19 +553,19 @@ int verif_backblue(httrackp * opt, const char *base) { ret = 1; fclose(fp); usercommand(opt, 0, NULL, - fconcat(OPT_GET_BUFF(opt), base, "backblue.gif"), "", ""); + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), base, "backblue.gif"), "", ""); } else ret = 1; // fp = filecreate(&opt->state.strc, - fconcat(OPT_GET_BUFF(opt), base, "fade.gif")); + fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), base, "fade.gif")); if (fp) { if (fwrite(HTS_DATA_FADE_GIF, HTS_DATA_FADE_GIF_LEN, 1, fp) != HTS_DATA_FADE_GIF_LEN) ret = 1; fclose(fp); - usercommand(opt, 0, NULL, fconcat(OPT_GET_BUFF(opt), base, "fade.gif"), + usercommand(opt, 0, NULL, fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), base, "fade.gif"), "", ""); } else ret = 1; @@ -758,7 +758,7 @@ static int sortTopIndexFnc(const void *a_, const void *b_) { return cmp; } -HTSEXT_API char *hts_getcategory(const char *filename); +//HTSEXT_API char *hts_getcategory(const char *filename); /* Note: NOT utf-8 */ HTSEXT_API int hts_buildtopindex(httrackp * opt, const char *path, @@ -772,16 +772,16 @@ HTSEXT_API int hts_buildtopindex(httrackp * opt, const char *path, // et templates html toptemplate_header = - readfile_or(fconcat(catbuff, binpath, "templates/topindex-header.html"), + readfile_or(fconcat(catbuff, sizeof(catbuff), binpath, "templates/topindex-header.html"), HTS_INDEX_HEADER); toptemplate_body = - readfile_or(fconcat(catbuff, binpath, "templates/topindex-body.html"), + readfile_or(fconcat(catbuff, sizeof(catbuff), binpath, "templates/topindex-body.html"), HTS_INDEX_BODY); toptemplate_bodycat = - readfile_or(fconcat(catbuff, binpath, "templates/topindex-bodycat.html"), + readfile_or(fconcat(catbuff, sizeof(catbuff), binpath, "templates/topindex-bodycat.html"), HTS_INDEX_BODYCAT); toptemplate_footer = - readfile_or(fconcat(catbuff, binpath, "templates/topindex-footer.html"), + readfile_or(fconcat(catbuff, sizeof(catbuff), binpath, "templates/topindex-footer.html"), HTS_INDEX_FOOTER); if (toptemplate_header && toptemplate_body && toptemplate_footer @@ -793,11 +793,11 @@ HTSEXT_API int hts_buildtopindex(httrackp * opt, const char *path, rpath[strlen(rpath) - 1] = '\0'; } - fpo = fopen(fconcat(catbuff, rpath, "/index.html"), "wb"); + fpo = fopen(fconcat(catbuff, sizeof(catbuff), rpath, "/index.html"), "wb"); if (fpo) { find_handle h; - verif_backblue(opt, concat(catbuff, rpath, "/")); // générer gif + verif_backblue(opt, concat(catbuff, sizeof(catbuff), rpath, "/")); // générer gif // Header fprintf(fpo, toptemplate_header, "<!-- Mirror and index made by HTTrack Website Copier/" @@ -887,8 +887,7 @@ HTSEXT_API int hts_buildtopindex(httrackp * opt, const char *path, for(i = 0; i < chainSize; i++) { char BIGSTK hname[HTS_URLMAXSIZE * 2]; - strcpybuff(hname, sortedElts[i]->name); - escape_uri_utf(hname); + escape_uri_utf(sortedElts[i]->name, hname, sizeof(hname)); /* Changed category */ if (strcmp(category, sortedElts[i]->category) != 0) { diff --git a/src/htszlib.c b/src/htszlib.c index e184e27..5042910 100644 --- a/src/htszlib.c +++ b/src/htszlib.c @@ -57,13 +57,13 @@ int hts_zunpack(char *filename, char *newfile) { if (filename != NULL && newfile != NULL) { if (filename[0] && newfile[0]) { char catbuff[CATBUFF_SIZE]; - FILE *const in = FOPEN(fconv(catbuff, filename), "rb"); + FILE *const in = FOPEN(fconv(catbuff, sizeof(catbuff), filename), "rb"); const int fd = in != NULL ? fileno(in) : -1; // Note: we must dup to be able to flose cleanly. gzFile gz = fd != -1 ? gzdopen(dup(fd), "rb") : NULL; if (gz) { - FILE *const fpout = FOPEN(fconv(catbuff, newfile), "wb"); + FILE *const fpout = FOPEN(fconv(catbuff, sizeof(catbuff), newfile), "wb"); int size = 0; if (fpout) { @@ -95,8 +95,8 @@ int hts_zunpack(char *filename, char *newfile) { int hts_extract_meta(const char *path) { char catbuff[CATBUFF_SIZE]; - unzFile zFile = unzOpen(fconcat(catbuff, path, "hts-cache/new.zip")); - zipFile zFileOut = zipOpen(fconcat(catbuff, path, "hts-cache/meta.zip"), 0); + unzFile zFile = unzOpen(fconcat(catbuff, sizeof(catbuff), path, "hts-cache/new.zip")); + zipFile zFileOut = zipOpen(fconcat(catbuff, sizeof(catbuff), path, "hts-cache/meta.zip"), 0); if (zFile != NULL && zFileOut != NULL) { if (unzGoToFirstFile(zFile) == Z_OK) { diff --git a/src/httrack-library.h b/src/httrack-library.h index b3ba48a..c32a84f 100644 --- a/src/httrack-library.h +++ b/src/httrack-library.h @@ -103,14 +103,15 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt); /* Options handling */ HTSEXT_API httrackp *hts_create_opt(void); HTSEXT_API void hts_free_opt(httrackp * opt); -HTSEXT_API void set_wrappers(httrackp * opt); // DEPRECATED - DUMMY FUNCTION +HTSEXT_API const hts_stat_struct* hts_get_stats(httrackp * opt); +HTSEXT_API void set_wrappers(httrackp * opt); /* LEGACY */ HTSEXT_API int plug_wrapper(httrackp * opt, const char *moduleName, const char *argv); /* Logging */ HTSEXT_API int hts_log(httrackp * opt, const char *prefix, const char *msg); HTSEXT_API void hts_log_print(httrackp * opt, int type, const char *format, - ...); + ...) HTS_PRINTF_FUN(3, 4); /* Infos */ HTSEXT_API const char *hts_get_version_info(httrackp * opt); @@ -122,22 +123,22 @@ HTSEXT_API const hts_stat_struct* hts_get_stats(httrackp * opt); HTSEXT_API int htswrap_init(void); // DEPRECATED - DUMMY FUNCTION HTSEXT_API int htswrap_free(void); // DEPRECATED - DUMMY FUNCTION HTSEXT_API int htswrap_add(httrackp * opt, const char *name, void *fct); -HTSEXT_API unsigned long int htswrap_read(httrackp * opt, const char *name); +HTSEXT_API uintptr_t htswrap_read(httrackp * opt, const char *name); HTSEXT_API int htswrap_set_userdef(httrackp * opt, void *userdef); HTSEXT_API void *htswrap_get_userdef(httrackp * opt); /* Internal library allocators, if a different libc is being used by the client */ HTSEXT_API char *hts_strdup(const char *string); HTSEXT_API void *hts_malloc(size_t size); -HTSEXT_API void *hts_realloc(void *data, size_t size); +HTSEXT_API void *hts_realloc(void *const data, const size_t size); HTSEXT_API void hts_free(void *data); /* Other functions */ HTSEXT_API int hts_resetvar(void); // DEPRECATED - DUMMY FUNCTION HTSEXT_API int hts_buildtopindex(httrackp * opt, const char *path, const char *binpath); -HTSEXT_API const char *hts_getcategories(const char *path, int type); -HTSEXT_API const char *hts_getcategory(const char *filename); +HTSEXT_API char *hts_getcategories(char *path, int type); +HTSEXT_API char *hts_getcategory(const char *filename); /* Catch-URL */ HTSEXT_API T_SOC catch_url_init_std(int *port_prox, char *adr_prox); @@ -150,11 +151,12 @@ HTSEXT_API int hts_is_testing(httrackp * opt); HTSEXT_API int hts_is_exiting(httrackp * opt); /*HTSEXT_API int hts_setopt(httrackp* opt); DEPRECATED ; see copy_htsopt() */ + HTSEXT_API int hts_addurl(httrackp * opt, char **url); HTSEXT_API int hts_resetaddurl(httrackp * opt); -HTSEXT_API int copy_htsopt(httrackp * from, httrackp * to); +HTSEXT_API int copy_htsopt(const httrackp * from, httrackp * to); HTSEXT_API char *hts_errmsg(httrackp * opt); -HTSEXT_API int hts_setpause(httrackp * opt, int); // pause transfer +HTSEXT_API int hts_setpause(httrackp * opt, int); HTSEXT_API int hts_request_stop(httrackp * opt, int force); HTSEXT_API int hts_cancel_file_push(httrackp * opt, const char *url); HTSEXT_API void hts_cancel_test(httrackp * opt); @@ -164,46 +166,68 @@ HTSEXT_API void hts_cancel_parsing(httrackp * opt); /* Tools */ HTSEXT_API int structcheck(const char *path); +HTSEXT_API int structcheck_utf8(const char *path); HTSEXT_API int dir_exists(const char *path); HTSEXT_API void infostatuscode(char *msg, int statuscode); -HTSEXT_API HTS_INLINE TStamp mtime_local(void); +HTSEXT_API TStamp mtime_local(void); HTSEXT_API void qsec2str(char *st, TStamp t); HTSEXT_API char *int2char(strc_int2bytes2 * strc, int n); HTSEXT_API char *int2bytes(strc_int2bytes2 * strc, LLint n); HTSEXT_API char *int2bytessec(strc_int2bytes2 * strc, long int n); HTSEXT_API char **int2bytes2(strc_int2bytes2 * strc, LLint n); -HTSEXT_API char *jump_identification(char *); -HTSEXT_API char *jump_normalized(char *); -HTSEXT_API char *jump_toport(char *); -HTSEXT_API char *fil_normalized(char *source, char *dest); -HTSEXT_API char *adr_normalized(char *source, char *dest); +HTSEXT_API char *jump_identification(const char *); +HTSEXT_API char *jump_normalized(const char *); +HTSEXT_API char *jump_toport(const char *); +HTSEXT_API char *fil_normalized(const char *source, char *dest); +HTSEXT_API char *adr_normalized(const char *source, char *dest); HTSEXT_API char *hts_rootdir(char *file); /* Escaping URLs */ HTSEXT_API void unescape_amp(char *s); -HTSEXT_API void escape_spc_url(char *s); -HTSEXT_API void escape_in_url(char *s); -HTSEXT_API void escape_uri(char *s); -HTSEXT_API void escape_uri_utf(char *s); -HTSEXT_API void escape_check_url(char *s); -HTSEXT_API char *escape_check_url_addr(char *s); -HTSEXT_API void x_escape_http(char *s, int mode); -HTSEXT_API char *unescape_http(char *catbuff, const char *s); -HTSEXT_API char *unescape_http_unharm(char *catbuff, const char *s, - int no_high); + +HTSEXT_API size_t escape_spc_url(const char *const src, char *const dest, const size_t size); +HTSEXT_API size_t escape_in_url(const char *const src, char *const dest, const size_t size); +HTSEXT_API size_t escape_uri(const char *const src, char *const dest, const size_t size); +HTSEXT_API size_t escape_uri_utf(const char *const src, char *const dest, const size_t size); +HTSEXT_API size_t escape_check_url(const char *const src, char *const dest, const size_t size); + +HTSEXT_API size_t append_escape_spc_url(const char *const src, char *const dest, const size_t size); +HTSEXT_API size_t append_escape_in_url(const char *const src, char *const dest, const size_t size); +HTSEXT_API size_t append_escape_uri(const char *const src, char *const dest, const size_t size); +HTSEXT_API size_t append_escape_uri_utf(const char *const src, char *const dest, const size_t size); +HTSEXT_API size_t append_escape_check_url(const char *const src, char *const dest, const size_t size); + +HTSEXT_API size_t inplace_escape_spc_url(char *const dest, const size_t size); +HTSEXT_API size_t inplace_escape_in_url(char *const dest, const size_t size); +HTSEXT_API size_t inplace_escape_uri(char *const dest, const size_t size); +HTSEXT_API size_t inplace_escape_uri_utf(char *const dest, const size_t size); +HTSEXT_API size_t inplace_escape_check_url(char *const dest, const size_t size); + +HTSEXT_API char *escape_check_url_addr(const char *const src, char *const dest, const size_t size); +HTSEXT_API size_t make_content_id(const char *const adr, const char *const fil, char *const dest, const size_t size); + +HTSEXT_API size_t x_escape_http(const char *const s, char *const dest, const size_t max_size, const int mode); +HTSEXT_API void escape_remove_control(char *const s); +HTSEXT_API size_t escape_for_html_print(const char *const s, char *const dest, const size_t size); +HTSEXT_API size_t escape_for_html_print_full(const char *const s, char *const dest, const size_t size); + +HTSEXT_API char *unescape_http(char *const catbuff, const size_t size, const char *const s); +HTSEXT_API char *unescape_http_unharm(char *const catbuff, const size_t size, const char *s, const int no_high); HTSEXT_API char *antislash_unescaped(char *catbuff, const char *s); + HTSEXT_API void escape_remove_control(char *s); HTSEXT_API void get_httptype(httrackp * opt, char *s, const char *fil, int flag); HTSEXT_API int is_knowntype(httrackp * opt, const char *fil); HTSEXT_API int is_userknowntype(httrackp * opt, const char *fil); HTSEXT_API int is_dyntype(const char *fil); -HTSEXT_API char *get_ext(char *catbuff, const char *fil); +HTSEXT_API char *get_ext(char *catbuff, size_t size, const char *fil); /* Ugly string tools */ -HTSEXT_API char *concat(char *catbuff, const char *a, const char *b); -HTSEXT_API char *fconcat(char *catbuff, const char *a, const char *b); -HTSEXT_API char *fconv(char *catbuff, const char *a); +HTSEXT_API char *concat(char *catbuff, size_t size, const char *a, const char *b); +HTSEXT_API char *fconcat(char *catbuff, size_t size, const char *a, const char *b); +HTSEXT_API char *fconv(char *catbuff, size_t size, const char *a); +HTSEXT_API char *fslash(char *catbuff, size_t size, const char *a); /* Debugging */ HTSEXT_API void hts_debug(int level); @@ -273,4 +297,19 @@ typedef struct utimbuf STRUCT_UTIMBUF; #define HTS_DEF_FILEAPI #endif +/** Macro aimed to break at build-time if a size is not a sizeof() strictly + * greater than sizeof(char*). **/ +#undef COMPILE_TIME_CHECK_SIZE +#define COMPILE_TIME_CHECK_SIZE(A) ((void (*)(char[A - sizeof(char*) - 1])) NULL) + +/** Macro aimed to break at compile-time if a size is not a sizeof() strictly + * greater than sizeof(char*). **/ +#undef RUNTIME_TIME_CHECK_SIZE +#define RUNTIME_TIME_CHECK_SIZE(A) assert((A) != sizeof(void*)) + +#define fconv(A,B,C) (COMPILE_TIME_CHECK_SIZE(B), fconv(A,B,C)) +#define concat(A,B,C,D) (COMPILE_TIME_CHECK_SIZE(B), concat(A,B,C,D)) +#define fconcat(A,B,C,D) (COMPILE_TIME_CHECK_SIZE(B), fconcat(A,B,C,D)) +#define fslash(A,B,C) (COMPILE_TIME_CHECK_SIZE(B), fslash(A,B,C)) + #endif diff --git a/src/proxy/proxystrings.h b/src/proxy/proxystrings.h index 8dc371a..dc70286 100755 --- a/src/proxy/proxystrings.h +++ b/src/proxy/proxystrings.h @@ -85,35 +85,21 @@ HTS_UNUSED static void escapexml(const char *s, String * tempo) { } } -HTS_UNUSED static char *concat(char *catbuff, const char *a, const char *b) { - if (a != NULL && a[0] != '\0') { - strcpy(catbuff, a); - } else { - catbuff[0] = '\0'; - } - if (b != NULL && b[0] != '\0') { - strcat(catbuff, b); - } - return catbuff; -} - -HTS_UNUSED static char *__fconv(char *a) { -#ifdef WIN32 - int i; - - for(i = 0; a[i] != 0; i++) - if (a[i] == '/') // Unix-to-DOS style - a[i] = '\\'; +HTS_UNUSED static char* file_convert(char *dest, size_t size, const char *src) { + size_t i; + for(i = 0 ; src[i] != '\0' && i + 1 < size ; i++) { +#ifdef _WIN32 + if (src[i] == '/') { + dest[i] = '\\'; + } else { #endif - return a; -} - -HTS_UNUSED static char *fconcat(char *catbuff, const char *a, const char *b) { - return __fconv(concat(catbuff, a, b)); -} - -HTS_UNUSED static char *fconv(char *catbuff, const char *a) { - return __fconv(concat(catbuff, a, "")); + dest[i] = src[i]; +#ifdef _WIN32 + } +#endif + } + dest[i] = '\0'; + return dest; } #endif diff --git a/src/proxy/store.c b/src/proxy/store.c index 9475412..1702bc8 100644 --- a/src/proxy/store.c +++ b/src/proxy/store.c @@ -1157,7 +1157,7 @@ static PT_Element PT_ReadCache__New_u(PT_Index index_, const char *url, /* Read in memory from cache */ if (flags & FETCH_BODY) { if (strnotempty(previous_save)) { - FILE *fp = fopen(fconv(catbuff, previous_save), "rb"); + FILE *fp = fopen(file_convert(catbuff, sizeof(catbuff), previous_save), "rb"); if (fp != NULL) { r->adr = (char *) malloc(r->size + 4); @@ -1179,7 +1179,7 @@ static PT_Element PT_ReadCache__New_u(PT_Index index_, const char *url, } else { r->statuscode = STATUSCODE_INVALID; sprintf(r->msg, "Read error (can't open '%s') from cache", - fconv(catbuff, previous_save)); + file_convert(catbuff, sizeof(catbuff), previous_save)); } } else { r->statuscode = STATUSCODE_INVALID; |