home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Internet / WinHTTrack 3.41-2 / httrack-3.41-2.exe / {app} / libtest / callbacks-example-filename.c < prev    next >
Encoding:
C/C++ Source or Header  |  2006-06-04  |  2.4 KB  |  84 lines

  1. /*
  2.     HTTrack external callbacks example : changing the destination filename
  3.     .c file
  4.  
  5.     How to build: (callback.so or callback.dll)
  6.       With GNU-GCC:
  7.         gcc -O -g3 -Wall -D_REENTRANT -shared -o mycallback.so callbacks-example.c -lhttrack1
  8.       With MS-Visual C++:
  9.         cl -LD -nologo -W3 -Zi -Zp4 -DWIN32 -Fe"mycallback.dll" callbacks-example.c libhttrack1.lib
  10.  
  11.       Note: the httrack library linker option is only necessary when using libhttrack's functions inside the callback
  12.  
  13.     How to use:
  14.       httrack --wrapper mycallback ..
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20.  
  21. /* Standard httrack module includes */
  22. #include "httrack-library.h"
  23. #include "htsopt.h"
  24. #include "htsdefines.h"
  25.  
  26. /* Local function definitions */
  27. 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);
  28.  
  29. /* Options settings */
  30. #include "htsopt.h"
  31.  
  32. /* TOLOWER */
  33. #define TOLOWER_(a) (a >= 'A' && a <= 'Z') ? (a + ('a' - 'A')) : a
  34. #define TOLOWER(a) ( TOLOWER_( (a) ) )
  35.  
  36. /*
  37.   This sample just changes the destination filenames to ROT-13 equivalent ; that is,
  38.   a -> n
  39.   b -> o
  40.   c -> p
  41.   d -> q
  42.   ..
  43.   n -> a
  44.   o -> b
  45.   ..
  46.  
  47.   <parent> -> <link>
  48.   This sample can be improved, for example, to make a map of a website.
  49. */
  50.  
  51. /* 
  52. module entry point 
  53. */
  54. EXTERNAL_FUNCTION int hts_plug(httrackp *opt, const char* argv) {
  55.   const char *arg = strchr(argv, ',');
  56.   if (arg != NULL)
  57.     arg++;
  58.  
  59.   /* Plug callback functions */
  60.   CHAIN_FUNCTION(opt, savename, mysavename, NULL);
  61.  
  62.   return 1;  /* success */
  63. }
  64.  
  65. 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) {
  66.   char* a;
  67.  
  68.   /* Call parent functions if multiple callbacks are chained. */
  69.   if (CALLBACKARG_PREV_FUN(carg, savename) != NULL) {
  70.     if (!CALLBACKARG_PREV_FUN(carg, savename)(CALLBACKARG_PREV_CARG(carg), opt, adr_complete, fil_complete, referer_adr, referer_fil, save)) {
  71.       return 0;  /* Abort */
  72.     }
  73.   }
  74.  
  75.   /* Process */
  76.   for(a = save ; *a != 0 ; a++) {
  77.     char c = TOLOWER(*a);
  78.     if (c >= 'a' && c <= 'z')
  79.       *a = ( ( ( c - 'a' ) + 13 ) % 26 ) + 'a';     // ROT-13
  80.   }
  81.   
  82.   return 1;  /* success */
  83. }
  84.