diff options
Diffstat (limited to 'libtest/callbacks-example-filename.c')
-rwxr-xr-x | libtest/callbacks-example-filename.c | 70 |
1 files changed, 46 insertions, 24 deletions
diff --git a/libtest/callbacks-example-filename.c b/libtest/callbacks-example-filename.c index 0755b4d..a6c7fa1 100755 --- a/libtest/callbacks-example-filename.c +++ b/libtest/callbacks-example-filename.c @@ -2,30 +2,35 @@ HTTrack external callbacks example : changing the destination filename
.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-filename.c
- or (with visual c++)
- cl -LD -nologo -W3 -Zi -Zp4 -DWIN32 -Fe"callback.dll" callbacks-example-filename.c
- - use the --wrapper option in httrack:
- httrack --wrapper save-name=callback:mysavename
+ httrack --wrapper mycallback ..
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-/* "External" */
-#ifdef _WIN32
-#define EXTERNAL_FUNCTION __declspec(dllexport)
-#else
-#define EXTERNAL_FUNCTION
-#endif
+/* Standard httrack module includes */
+#include "httrack-library.h"
+#include "htsopt.h"
+#include "htsdefines.h"
+
+/* Local function definitions */
+static int mysavename(t_hts_callbackarg *carg, httrackp *opt, const char* adr_complete, const char* fil_complete, const char* referer_adr, const char* referer_fil, char* save);
+
+/* external functions */
+EXTERNAL_FUNCTION int hts_plug(httrackp *opt, const char* argv);
-/* Function definitions */
-EXTERNAL_FUNCTION int mysavename(char* adr_complete, char* fil_complete, char* referer_adr, char* referer_fil, char* save);
+/* Options settings */
+#include "htsopt.h"
/* TOLOWER */
#define TOLOWER_(a) (a >= 'A' && a <= 'Z') ? (a + ('a' - 'A')) : a
@@ -46,18 +51,35 @@ EXTERNAL_FUNCTION int mysavename(char* adr_complete, char* fil_complete, char* r This sample can be improved, for example, to make a map of a website.
*/
-/*
-"check-html" callback
-from htsdefines.h:
-typedef int (* t_hts_htmlcheck_savename)(char* adr_complete,char* fil_complete,char* referer_adr,char* referer_fil,char* save);
+/*
+module entry point
*/
-EXTERNAL_FUNCTION int mysavename(char* adr_complete, char* fil_complete, char* referer_adr, char* referer_fil, char* save) {
- char* a = save;
- while(*a) {
+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, savename, mysavename, NULL);
+
+ return 1; /* success */
+}
+
+static int mysavename(t_hts_callbackarg *carg, httrackp *opt, const char* adr_complete, const char* fil_complete, const char* referer_adr, const char* referer_fil, char* save) {
+ char* a;
+
+ /* Call parent functions if multiple callbacks are chained. */
+ if (CALLBACKARG_PREV_FUN(carg, savename) != NULL) {
+ if (!CALLBACKARG_PREV_FUN(carg, savename)(CALLBACKARG_PREV_CARG(carg), opt, adr_complete, fil_complete, referer_adr, referer_fil, save)) {
+ return 0; /* Abort */
+ }
+ }
+
+ /* Process */
+ for(a = save ; *a != 0 ; a++) {
char c = TOLOWER(*a);
if (c >= 'a' && c <= 'z')
*a = ( ( ( c - 'a' ) + 13 ) % 26 ) + 'a'; // ROT-13
- a++;
}
return 1; /* success */
|