diff options
author | Xavier Roche <xroche@users.noreply.github.com> | 2012-03-19 12:59:03 +0000 |
---|---|---|
committer | Xavier Roche <xroche@users.noreply.github.com> | 2012-03-19 12:59:03 +0000 |
commit | 660b569b0980fc8f71b03ed666dd02eec8388b4c (patch) | |
tree | 8ad02b5f0bebdd4cd1d2ba01005d6f3f71a0a7fb /libtest/callbacks-example-changecontent.c | |
parent | 64cc4a88da8887ef1f7f4d90be0158d2cc76222d (diff) |
httrack 3.41.2
Diffstat (limited to 'libtest/callbacks-example-changecontent.c')
-rwxr-xr-x | libtest/callbacks-example-changecontent.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/libtest/callbacks-example-changecontent.c b/libtest/callbacks-example-changecontent.c new file mode 100755 index 0000000..7e0e0a9 --- /dev/null +++ b/libtest/callbacks-example-changecontent.c @@ -0,0 +1,65 @@ +/*
+ HTTrack external callbacks example : display all incoming request headers
+ Example of <wrappername>_init and <wrappername>_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:
+ httrack --wrapper mycallback ..
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* Standard httrack module includes */
+#include "httrack-library.h"
+#include "htsopt.h"
+#include "htsdefines.h"
+
+/* Local function definitions */
+static int postprocess(t_hts_callbackarg *carg, httrackp *opt,
+ char** html, int* len,
+ const char* url_address, const char* url_file);
+
+/* external functions */
+EXTERNAL_FUNCTION int hts_plug(httrackp *opt, const char* argv);
+
+/*
+module entry point
+*/
+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, postprocess, postprocess, NULL); + + return 1; /* success */
+}
+
+static int postprocess(t_hts_callbackarg *carg, httrackp *opt, char** html,int* len,const char* url_address,const char* url_file) {
+ char *old = *html;
+
+ /* Call parent functions if multiple callbacks are chained. */
+ if (CALLBACKARG_PREV_FUN(carg, postprocess) != NULL) {
+ if (CALLBACKARG_PREV_FUN(carg, postprocess)(CALLBACKARG_PREV_CARG(carg), opt, html, len, url_address, url_file)) {
+ /* Modified *html */
+ old = *html;
+ }
+ }
+
+ /* Process */
+ *html = strdup(*html);
+ hts_free(old);
+
+ return 1;
+}
|