summaryrefslogtreecommitdiff
path: root/src/htsparse.h
blob: 561ae68645508f3cca89621b261ce084c472c932 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* ------------------------------------------------------------ */
/*
HTTrack Website Copier, Offline Browser for Windows and Unix
Copyright (C) Xavier Roche and other contributors

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


Important notes:

- We hereby ask people using this source NOT to use it in purpose of grabbing
emails addresses, or collecting any other private information on persons.
This would disgrace our work, and spoil the many hours we spent on it.


Please visit our Website: http://www.httrack.com
*/


/* ------------------------------------------------------------ */
/* File: htsparse.h parser                                      */
/*       html/javascript/css parser                             */
/*       and other parser routines                              */
/* Author: Xavier Roche                                         */
/* ------------------------------------------------------------ */


typedef struct htsmoduleStructExtended {
  /* Main object */
  htsblk* r_;

  /* Error handling */
  int* error_;
  int* exit_xh_;
  int* store_errpage_;

  /* Structural */
  int* filptr_;
  char*** filters_;
  robots_wizard* robots_;
  hash_struct* hash_;
  int* lien_max_;

  /* Base & codebase */
  char* base;
  char* codebase;

  /* Index */
  int* makeindex_done_;
  FILE** makeindex_fp_;
  int* makeindex_links_;
  char* makeindex_firstlink_;

  /* Html templates */
  char *template_header_;
  char *template_body_;
  char *template_footer_;

  /* Specific to downloads */
  LLint* stat_fragment_;
  TStamp makestat_time;
  FILE* makestat_fp;
  LLint* makestat_total_;
  int* makestat_lnk_;
  FILE* maketrack_fp;

  /* Function-dependant */
  char* loc_;
  TStamp* last_info_shell_;
  int* info_shell_;

} htsmoduleStructExtended;


/* Library internal definictions */
#ifdef HTS_INTERNAL_BYTECODE

/*
  Main parser, attempt to scan links inside the html/css/js file
  Parameters: The public module structure, and the private module variables
*/
int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre);

/*
  Check for 301,302.. errors ("moved") and handle them; re-isuue requests, make
  rediretc file, handle filters considerations..
  Parameters: The public module structure, and the private module variables
  Returns 0 upon success
*/
int hts_mirror_check_moved(htsmoduleStruct* str, htsmoduleStructExtended* stre);

/*
  Get the next file on the queue, waiting for it, handling other files in background..
  Parameters: The public module structure, and the private module variables
  Returns 0 upon success
*/
int hts_mirror_wait_for_next_file(htsmoduleStruct* str, htsmoduleStructExtended* stre);

/*
  Wair for (adr, fil, save) to be started, that is, 
  to be ready for naming, having its header MIME type
  If the final URL is to be forbidden, sets 'forbidden_url' to the corresponding value
*/
int hts_wait_delayed(htsmoduleStruct* str, 
                     char* adr, char* fil, char* save, 
                     char* former_adr, char* former_fil, 
                     int* forbidden_url);


/* Context state */

#define ENGINE_LOAD_CONTEXT_BASE() \
  lien_url** liens = (lien_url**) str->liens; \
  httrackp* opt = (httrackp*) str->opt; \
  struct_back* sback = (struct_back*) str->sback; \
  lien_back* const back = sback->lnk; \
  const int back_max = sback->count; \
  cache_back* cache = (cache_back*) str->cache; \
  hash_struct* hashptr = (hash_struct*) str->hashptr; \
  int numero_passe = str->numero_passe; \
  int add_tab_alloc = str->add_tab_alloc; \
  /* */ \
  int lien_tot = * ( (int*) (str->lien_tot_) ); \
  int ptr = * ( (int*) (str->ptr_) ); \
  int lien_size = * ( (int*) (str->lien_size_) ); \
  char* lien_buffer = * ( (char**) (str->lien_buffer_) )

#define ENGINE_SAVE_CONTEXT_BASE() \
  /* Apply changes */ \
  * ( (int*) (str->lien_tot_) ) = lien_tot; \
  * ( (int*) (str->ptr_) ) = ptr; \
  * ( (int*) (str->lien_size_) ) = lien_size; \
  * ( (char**) (str->lien_buffer_) ) = lien_buffer

#define WAIT_FOR_AVAILABLE_SOCKET() do { \
  int prev = _hts_in_html_parsing; \
  while(back_pluggable_sockets_strict(sback, opt) <= 0) { \
    _hts_in_html_parsing = 6; \
    /* Wait .. */ \
    back_wait(sback,opt,cache,0); \
    /* Transfer rate */ \
    engine_stats(); \
    /* Refresh various stats */ \
    HTS_STAT.stat_nsocket=back_nsoc(sback); \
    HTS_STAT.stat_errors=fspc(NULL,"error"); \
    HTS_STAT.stat_warnings=fspc(NULL,"warning"); \
    HTS_STAT.stat_infos=fspc(NULL,"info"); \
    HTS_STAT.nbk=backlinks_done(sback,liens,lien_tot,ptr); \
    HTS_STAT.nb=back_transfered(HTS_STAT.stat_bytes,sback); \
    /* Check */ \
    if (!hts_htmlcheck_loop(sback->lnk, sback->count, -1,ptr,lien_tot,(int) (time_local()-HTS_STAT.stat_timestart),&HTS_STAT)) { \
      return -1; \
    } \
  } \
  _hts_in_html_parsing = prev; \
} while(0)

#endif