Coverage Report

Created: 2026-10-28 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/httrack/src/htsbasenet.h
Line
Count
Source
1
/* ------------------------------------------------------------ */
2
/*
3
HTTrack Website Copier, Offline Browser for Windows and Unix
4
Copyright (C) 1998 Xavier Roche and other contributors
5
6
SPDX-License-Identifier: GPL-3.0-or-later
7
8
This program is free software: you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation, either version 3 of the License, or
11
(at your option) any later version.
12
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
GNU General Public License for more details.
17
18
You should have received a copy of the GNU General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21
Ethical use: we kindly ask that you NOT use this software to harvest email
22
addresses or to collect any other private information about people. Doing so
23
would dishonor our work and waste the many hours we have spent on it.
24
25
Please visit our Website: http://www.httrack.com
26
*/
27
28
/* ------------------------------------------------------------ */
29
/* File: Basic net definitions                                  */
30
/*       Used in .c and .h files that needs hostent and so      */
31
/* Author: Xavier Roche                                         */
32
/* ------------------------------------------------------------ */
33
34
/** @file htsbasenet.h
35
    Base networking definitions: the platform socket headers, the process-wide
36
    OpenSSL context, and the codes held by htsblk.statuscode and
37
    lien_back.status. A consumer that interprets either field needs the names
38
    here. */
39
40
#ifndef HTS_DEFBASENETH
41
#define HTS_DEFBASENETH
42
43
/* Must precede the HTS_INET6 and HTS_USEOPENSSL tests below, which
44
   HTS_DEFBASENETH lets only the first include reach. */
45
#include "htsglobal.h"
46
47
/* Windows needs its socket headers here, for hostent and SOCKET. On POSIX they
48
   come from htsnet.h and only INVALID_SOCKET is defined below. */
49
#ifdef _WIN32
50
51
#if HTS_INET6 == 0
52
#include <winsock2.h>
53
#else
54
55
#undef HTS_USESCOPEID
56
#define WIN32_LEAN_AND_MEAN
57
// KB955045 (http://support.microsoft.com/kb/955045)
58
// To execute an application using this function on earlier versions of Windows
59
// (Windows 2000, Windows NT, and Windows Me/98/95), then it is mandatary to
60
// #include Ws2tcpip.h and also Wspiapi.h. When the Wspiapi.h header file is
61
// included, the 'getaddrinfo' function is #defined to the 'WspiapiGetAddrInfo'
62
// inline function in Wspiapi.h.
63
#include <ws2tcpip.h>
64
#include <Wspiapi.h>
65
66
#endif
67
68
#else
69
/** Defined on the POSIX build and cleared on the Windows IPv6 build, but
70
    nothing in the tree reads it. */
71
#define HTS_USESCOPEID
72
/** POSIX's invalid socket, spelled with Winsock's name so one test serves
73
    both platforms. */
74
#define INVALID_SOCKET -1
75
#endif
76
77
#ifdef __cplusplus
78
extern "C" {
79
#endif
80
81
/* HTS_USEOPENSSL adds two fields to htsblk, so a consumer must compile with
82
   the value the library was built with, and needs the OpenSSL headers too. */
83
#if HTS_USEOPENSSL
84
/*
85
   OpensSSL crypto routines by Eric Young (eay@cryptsoft.com)
86
   Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
87
   All rights reserved
88
*/
89
#ifndef HTS_OPENSSL_H_INCLUDED
90
#define HTS_OPENSSL_H_INCLUDED
91
92
/* OpenSSL definitions */
93
#include <openssl/ssl.h>
94
#include <openssl/crypto.h>
95
#include <openssl/err.h>
96
97
/* OpenSSL structure */
98
#include <openssl/bio.h>
99
100
/* Engine-only: not exported, so the installed header must not offer it. */
101
#ifdef HTS_INTERNAL_BYTECODE
102
/** Process-wide OpenSSL client context, shared by every TLS connection.
103
    hts_init() creates it, so it is NULL until then, and nothing frees it. */
104
extern SSL_CTX *openssl_ctx;
105
#endif
106
107
#endif
108
#endif
109
110
/** HTTP status codes as read off the wire, stored in htsblk.statuscode. */
111
typedef enum HTTPStatusCode {
112
  HTTP_CONTINUE = 100,
113
  HTTP_SWITCHING_PROTOCOLS = 101,
114
  HTTP_OK = 200,
115
  HTTP_CREATED = 201,
116
  HTTP_ACCEPTED = 202,
117
  HTTP_NON_AUTHORITATIVE_INFORMATION = 203,
118
  HTTP_NO_CONTENT = 204,
119
  HTTP_RESET_CONTENT = 205,
120
  HTTP_PARTIAL_CONTENT = 206,
121
  HTTP_MULTIPLE_CHOICES = 300,
122
  HTTP_MOVED_PERMANENTLY = 301,
123
  HTTP_FOUND = 302,
124
  HTTP_SEE_OTHER = 303,
125
  HTTP_NOT_MODIFIED = 304,
126
  HTTP_USE_PROXY = 305,
127
  HTTP_TEMPORARY_REDIRECT = 307,
128
  HTTP_BAD_REQUEST = 400,
129
  HTTP_UNAUTHORIZED = 401,
130
  HTTP_PAYMENT_REQUIRED = 402,
131
  HTTP_FORBIDDEN = 403,
132
  HTTP_NOT_FOUND = 404,
133
  HTTP_METHOD_NOT_ALLOWED = 405,
134
  HTTP_NOT_ACCEPTABLE = 406,
135
  HTTP_PROXY_AUTHENTICATION_REQUIRED = 407,
136
  HTTP_REQUEST_TIME_OUT = 408,
137
  HTTP_CONFLICT = 409,
138
  HTTP_GONE = 410,
139
  HTTP_LENGTH_REQUIRED = 411,
140
  HTTP_PRECONDITION_FAILED = 412,
141
  HTTP_REQUEST_ENTITY_TOO_LARGE = 413,
142
  HTTP_REQUEST_URI_TOO_LARGE = 414,
143
  HTTP_UNSUPPORTED_MEDIA_TYPE = 415,
144
  HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416,
145
  HTTP_EXPECTATION_FAILED = 417,
146
  HTTP_TOO_MANY_REQUESTS = 429,
147
  HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451,
148
  HTTP_INTERNAL_SERVER_ERROR = 500,
149
  HTTP_NOT_IMPLEMENTED = 501,
150
  HTTP_BAD_GATEWAY = 502,
151
  HTTP_SERVICE_UNAVAILABLE = 503,
152
  HTTP_GATEWAY_TIME_OUT = 504,
153
  HTTP_HTTP_VERSION_NOT_SUPPORTED = 505
154
} HTTPStatusCode;
155
156
/** HTTrack's own status codes, stored in htsblk.statuscode beside the HTTP
157
    ones. A fresh htsblk starts at STATUSCODE_INVALID. */
158
typedef enum BackStatusCode {
159
  STATUSCODE_INVALID = -1,       /**< no usable response, and no retry */
160
  STATUSCODE_TIMEOUT = -2,       /**< the slot ran out of --timeout */
161
  STATUSCODE_SLOW = -3,          /**< the transfer stayed under --min-rate */
162
  STATUSCODE_CONNERROR = -4,     /**< the connection failed, or died later */
163
  STATUSCODE_NON_FATAL = -5,     /**< another error, and a retry may follow */
164
  STATUSCODE_SSL_HANDSHAKE = -6, /**< the TLS handshake failed */
165
  STATUSCODE_TOO_BIG = -7,       /**< the body was too big, and no retry */
166
  STATUSCODE_TEST_OK = -10,      /**< --test found the link alive */
167
  STATUSCODE_EXCLUDED = -11,     /**< a -mime: filter refused the type */
168
  STATUSCODE_IO_FATAL = -12,     /**< a write failed, and the mirror stops */
169
  STATUSCODE_IO_ERROR = -13      /**< a write failed, but the mirror goes on */
170
} BackStatusCode;
171
172
/** Is code one of the two write-error classes? r.size counts bytes read, so it
173
    cannot tell a complete body from one a failed write cut short. */
174
0
static HTS_INLINE HTS_UNUSED hts_boolean statuscode_is_write_error(int code) {
175
0
  return code == STATUSCODE_IO_FATAL || code == STATUSCODE_IO_ERROR ? HTS_TRUE
176
0
                                                                    : HTS_FALSE;
177
0
}
Unexecuted instantiation: fuzz-codepage.c:statuscode_is_write_error
Unexecuted instantiation: htscharset.c:statuscode_is_write_error
178
179
/** Connection state of a backing slot, the 'status' member of lien_back. The
180
    numbers are ordered on purpose, because the engine tests ranges: above zero
181
    is a slot in flight, and 1000 or more an FTP one. A transfer ends at
182
    STATUS_READY, then the slot returns to STATUS_FREE once the crawler has
183
    taken the result. An HTTPS slot reaches STATUS_CONNECTING twice, once for
184
    connect() and once after the handshake, so that branch runs twice. */
185
typedef enum HTTrackStatus {
186
  STATUS_ALIVE = -103,             /**< keep-alive socket, no request on it */
187
  STATUS_FREE = -1,                /**< slot unused, and free to take */
188
  STATUS_READY = 0,                /**< transfer over, result not taken yet */
189
  STATUS_TRANSFER = 1,             /**< reading the body, or a local file */
190
  STATUS_CHUNK_CR = 97,            /**< reading the CRLF ending a chunk */
191
  STATUS_CHUNK_WAIT = 98,          /**< reading the next chunk's hex size */
192
  STATUS_WAIT_HEADERS = 99,        /**< request sent, headers still coming */
193
  STATUS_CONNECTING = 100,         /**< waiting for connect() to finish */
194
  STATUS_WAIT_DNS = 101,           /**< resolving the host name */
195
  STATUS_SSL_WAIT_HANDSHAKE = 102, /**< running the TLS handshake */
196
  STATUS_FTP_TRANSFER = 1000,      /**< an FTP worker owns slot and socket */
197
  STATUS_FTP_READY = 1001          /**< the FTP worker is done, so reap it */
198
} HTTrackStatus;
199
200
#ifdef __cplusplus
201
}
202
#endif
203
204
#endif