From 660b569b0980fc8f71b03ed666dd02eec8388b4c Mon Sep 17 00:00:00 2001 From: Xavier Roche Date: Mon, 19 Mar 2012 12:59:03 +0000 Subject: httrack 3.41.2 --- libtest/callbacks-example-displayheader.c | 79 +++++++++++++++++-------------- 1 file changed, 44 insertions(+), 35 deletions(-) (limited to 'libtest/callbacks-example-displayheader.c') diff --git a/libtest/callbacks-example-displayheader.c b/libtest/callbacks-example-displayheader.c index 1f9c471..a8333b3 100755 --- a/libtest/callbacks-example-displayheader.c +++ b/libtest/callbacks-example-displayheader.c @@ -3,55 +3,64 @@ Example of _init and _exit call (httrack >> 3.31) .c file + How to build: (callback.so or callback.dll) + With GNU-GCC: + gcc -O -g3 -Wall -D_REENTRANT -shared -o mycallback.so callbacks-example.c -lhttrack1 + With MS-Visual C++: + cl -LD -nologo -W3 -Zi -Zp4 -DWIN32 -Fe"mycallback.dll" callbacks-example.c libhttrack1.lib + + Note: the httrack library linker option is only necessary when using libhttrack's functions inside the callback + How to use: - - compile this file as a module (callback.so or callback.dll) - example: - (with gcc) - gcc -O -g3 -Wall -D_REENTRANT -DINET6 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -shared -o callback.so callbacks-example-contentfilter.c - or (with visual c++) - cl -LD -nologo -W3 -Zi -Zp4 -DWIN32 -Fe"callback.dll" callbacks-example-displayheader.c - - use the --wrapper option in httrack: - httrack --wrapper save-name=callback:process,string[,string..] + httrack --wrapper mycallback .. */ #include #include #include +/* Standard httrack module includes */ #include "httrack-library.h" +#include "htsopt.h" +#include "htsdefines.h" -/* "External" */ -#ifdef _WIN32 -#define EXTERNAL_FUNCTION __declspec(dllexport) -#else -#define EXTERNAL_FUNCTION -#endif +/* Local function definitions */ +static int process(t_hts_callbackarg *carg, httrackp *opt, + char* buff, const char* adr, const char* fil, + const char* referer_adr, const char* referer_fil, + htsblk* incoming); -/* Function definitions */ -EXTERNAL_FUNCTION int process(char* buff, char* adr, char* fil, char* referer_adr, char* referer_fil, void* incoming); -EXTERNAL_FUNCTION int wrapper_init(char* module, char* initString); -EXTERNAL_FUNCTION int wrapper_exit(void); +/* external functions */ +EXTERNAL_FUNCTION int hts_plug(httrackp *opt, const char* argv); -/* -"receive-header" callback -from htsdefines.h: -typedef int (* t_hts_htmlcheck_receivehead)(char* buff, char* adr, char* fil, char* referer_adr, char* referer_fil, htsblk* incoming); +/* +module entry point */ -EXTERNAL_FUNCTION int process(char* buff, char* adr, char* fil, char* referer_adr, char* referer_fil, void* incoming) { - printf("[ %s%s ]\n%s\n", adr, fil, buff); - return 1; /* success */ -} +EXTERNAL_FUNCTION int hts_plug(httrackp *opt, const char* argv) { + const char *arg = strchr(argv, ','); + if (arg != NULL) + arg++; + + /* Plug callback functions */ + CHAIN_FUNCTION(opt, receivehead, process, NULL); -/* _init() will be called, if exists, upon startup */ -static char* thisModule = NULL; -EXTERNAL_FUNCTION int wrapper_init(char* module, char* initString) { - fprintf(stderr, "Plugged %s\n", module); - thisModule = module; return 1; /* success */ } -/* _exit() will be called, if exists, upon exit */ -EXTERNAL_FUNCTION int wrapper_exit(void) { - fprintf(stderr, "Unplugged %s\n", thisModule); - return 1; /* success (result ignored anyway in xx_exit) */ +static int process(t_hts_callbackarg *carg, httrackp *opt, + char* buff, const char* adr, const char* fil, + const char* referer_adr, const char* referer_fil, + htsblk* incoming) { + + /* Call parent functions if multiple callbacks are chained. */ + if (CALLBACKARG_PREV_FUN(carg, receivehead) != NULL) { + if (!CALLBACKARG_PREV_FUN(carg, receivehead)(CALLBACKARG_PREV_CARG(carg), opt, buff, adr, fil, referer_adr, referer_fil, incoming)) { + return 0; /* Abort */ + } + } + + /* Process */ + printf("[ %s%s ]\n%s\n", adr, fil, buff); + + return 1; /* success */ } -- cgit v1.2.3