diff options
author | Xavier Roche <xroche@users.noreply.github.com> | 2014-05-14 20:12:42 +0000 |
---|---|---|
committer | Xavier Roche <xroche@users.noreply.github.com> | 2014-05-14 20:12:42 +0000 |
commit | c05f54ae04c8b905ce31b66f136df578f868d9e6 (patch) | |
tree | b212cbe5650e4be66987ea8e98f847e91fa2da50 /src | |
parent | ae1db762e79326b07a57301ad252f8e0ae0b42a2 (diff) |
Clean hts_set_error_callback() and hts_get_error_callback()
Diffstat (limited to 'src')
-rw-r--r-- | src/htslib.c | 8 | ||||
-rw-r--r-- | src/htssafe.h | 23 | ||||
-rw-r--r-- | src/httrack-library.h | 8 |
3 files changed, 32 insertions, 7 deletions
diff --git a/src/htslib.c b/src/htslib.c index fbea649..08297bf 100644 --- a/src/htslib.c +++ b/src/htslib.c @@ -5116,6 +5116,14 @@ static int ssl_vulnerable(const char *version) { /* user abort callback */ htsErrorCallback htsCallbackErr = NULL; +HTSEXT_API void hts_set_error_callback(htsErrorCallback handler) { + htsCallbackErr = handler; +} + +HTSEXT_API htsErrorCallback hts_get_error_callback() { + return htsCallbackErr; +} + static void default_inthash_asserthandler(void *arg, const char* exp, const char* file, int line) { abortf_(exp, file, line); } diff --git a/src/htssafe.h b/src/htssafe.h index 004b068..8551c7a 100644 --- a/src/htssafe.h +++ b/src/htssafe.h @@ -36,16 +36,25 @@ Please visit our Website: http://www.httrack.com #include "htsglobal.h" /** - * Optional user-defined callback upon fatal error. - */ -typedef void (*htsErrorCallback) (const char *msg, const char *file, int line); - -/** * Emergency logging. + * Default is to use libhttrack one. */ #ifndef HTSSAFE_ABORT_FUNCTION -HTSEXT_API htsErrorCallback htsCallbackErr; -#define HTSSAFE_ABORT_FUNCTION(A,B,C) do { if (htsCallbackErr != NULL) { htsCallbackErr(A,B,C); } } while(0) + +/** Assert error callback. **/ +#ifndef HTS_DEF_FWSTRUCT_htsErrorCallback +#define HTS_DEF_FWSTRUCT_htsErrorCallback +typedef void (*htsErrorCallback) (const char *msg, const char *file, int line); +HTSEXT_API htsErrorCallback hts_get_error_callback(void); +#endif + +#define HTSSAFE_ABORT_FUNCTION(A,B,C) do { \ + htsErrorCallback callback = hts_get_error_callback(); \ + if (callback != NULL) { \ + callback(A,B,C); \ + } \ +} while(0) + #endif /** diff --git a/src/httrack-library.h b/src/httrack-library.h index 405e4fd..e15f3ce 100644 --- a/src/httrack-library.h +++ b/src/httrack-library.h @@ -66,6 +66,12 @@ typedef enum hts_log_type { typedef struct hts_stat_struct hts_stat_struct; #endif +/** Assert error callback. **/ +#ifndef HTS_DEF_FWSTRUCT_htsErrorCallback +#define HTS_DEF_FWSTRUCT_htsErrorCallback +typedef void (*htsErrorCallback) (const char *msg, const char *file, int line); +#endif + /* Helpers for plugging callbacks requires: htsdefines.h */ @@ -112,6 +118,8 @@ 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 void hts_set_error_callback(htsErrorCallback handler); +HTSEXT_API htsErrorCallback hts_get_error_callback(void); /* Logging */ HTSEXT_API int hts_log(httrackp * opt, const char *prefix, const char *msg); |