History log of /freebsd-current/lib/libfetch/common.h
Revision Date Author Comments
# b3e76948 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: two-line .h pattern

Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/


# c44be5aa 15-Feb-2020 Kyle Evans <kevans@FreeBSD.org>

fetch(3): Add SOCKS5 support

This change adds SOCKS5 support to the library fetch(3) and updates the man
page.

Details: Within the fetch_connect() function, fetch(3) checks if the
SOCKS5_PROXY environment variable is set. If so, it connects to this host
rather than the end-host. It then initializes the SOCKS5 connection in
accordance with RFC 1928 and returns the resulting conn_t (file descriptor)
for usage by the regular FTP/HTTP handlers.

Design Decision: This change defaults all DNS resolutions through the proxy
by sending all IPs as hostnames. Going forward, another feature might be to
create another environmental variable to toggle resolutions through the
proxy or not..

One may set the SOCKS5_PROXY environment variable in any of the formats:

SOCKS5_PROXY=proxy.example.com
SOCKS5_PROXY=proxy.example.com:1080
SOCKS5_PROXY=192.0.2.0
SOCKS5_PROXY=198.51.100.0:1080
SOCKS5_PROXY=[2001:db8::1]
SOCKS5_PROXY=[2001:db8::2]:1080

Then perform a request with fetch(1).

(note by kevans)
I've since been informed that Void Linux/xbps has a fork of libfetch that
also implements SOCKS5. I may compare/contrast the two in the mid-to-near
future.

Submitted by: Farhan Khan <farhan farhan codes>
Differential Revision: https://reviews.freebsd.org/D18908


# c5712d6d 29-May-2018 Dag-Erling Smørgrav <des@FreeBSD.org>

Use __VA_ARGS__ to simplify the DEBUG macro.

MFC after: 3 weeks


# 5e53a4f9 25-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

lib: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using mis-identified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# 64c42235 12-Mar-2017 Dag-Erling Smørgrav <des@FreeBSD.org>

Add a __printflike() that would have caught the bug fixed in r314396.


# 792ef1ae 22-Nov-2016 Dag-Erling Smørgrav <des@FreeBSD.org>

Refactor fetch_connect() and fetch_bind() to improve readability and avoid
repeating the same DNS lookups.

MFC after: 3 weeks


# c4199130 05-Jun-2014 Baptiste Daroussin <bapt@FreeBSD.org>

Add support for arbitrary http requests

Submitted by: Alex Hornung <alex@alexhornung.com>
Reviewed by: des
Obtained from: Dragonfly
MFC after: 3 week


# 4524013c 30-Jan-2014 Dag-Erling Smørgrav <des@FreeBSD.org>

Bump copyright dates


# 215a27f1 27-Jan-2014 Dag-Erling Smørgrav <des@FreeBSD.org>

Solve http buffering issues and hangs once and for all (hopefully!) by
simply not trying to return exactly what the caller asked for - just
return whatever we got and let the caller be the judge of whether it
was enough. If an error occurs or the connection times out after we
already received some data, return a short read, under the assumption
that the next call will fail or time out before we read anything.

As it turns out, none of the code that calls fetch_read() assumes an
all-or-nothing result anyway, except for a couple of lines where we
read the CR LF at the end of a hunk in HTTP hunked encoding, so the
changes outside of fetch_read() and http_readfn() are minimal.

While there, replace select(2) with poll(2).

MFC after: 3 days


# dcd47379 26-Jul-2013 Dag-Erling Smørgrav <des@FreeBSD.org>

Implement certificate verification, and many other SSL-related
imrovements; complete details in the PR.

PR: kern/175514
Submitted by: Michael Gmelin <freebsd@grem.de>
MFC after: 1 week


# 2a7daafe 18-Jan-2012 Dag-Erling Smørgrav <des@FreeBSD.org>

Fix two issues related to the use of SIGINFO in fetch(1) to display
progress information. The first is that fetch_read() (used in the HTTP
code but not the FTP code) can enter an infinite loop if it has previously
been interrupted by a signal. The second is that when it is interrupted,
fetch_read() will discard any data it may have read up to that point.
Luckily, both bugs are extremely timing-sensitive and therefore difficult
to trigger.

PR: bin/153240
Submitted by: Mark <markjdb@gmail.com>
MFC after: 3 weeks


# 578153f1 19-Oct-2011 Dag-Erling Smørgrav <des@FreeBSD.org>

latin1 -> utf8


# 6337341d 27-Sep-2011 Dag-Erling Smørgrav <des@FreeBSD.org>

Update copyright dates and strip my middle name.


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 62a2681c 18-Dec-2007 Dag-Erling Smørgrav <des@FreeBSD.org>

Add support for the NO_PROXY / no_proxy environment variable as used by
lynx, curl etc. Note that this patch differs significantly from that
in the PR, as the submitter refined it after submitting the PR.

PR: 110388
Submitted by: Alexander Pohoyda <alexander.pohoyda@gmx.net>
MFC after: 3 weeks


# a1b37df2 14-Dec-2007 Dag-Erling Smørgrav <des@FreeBSD.org>

Clean up namespace violations.

MFC after: 1 week


# 2cbbf9da 21-Sep-2004 Dag-Erling Smørgrav <des@FreeBSD.org>

Update copyright years.


# c42cb9d9 02-Mar-2003 Dag-Erling Smørgrav <des@FreeBSD.org>

Add and document support for a FETCH_BIND_ADDRESS environment variable
specifying a local address to bind sockets to. Caveat: lightly tested.

PR: bin/37572


# 07350d12 22-Jan-2003 Dag-Erling Smørgrav <des@FreeBSD.org>

Experimental support for .netrc.


# 2761348f 27-Oct-2002 Dag-Erling Smørgrav <des@FreeBSD.org>

Introduce _fetch_writev(), which is the conn_t version of writev(2). In
the SSL case, it is no different from the old _fetch_write(), but in the
non-SSL case it uses writev(2) to send the entire vector as a single
packet (provided it can fit in one packet). Implement _fetch_write()
and _fetch_putln() in terms of _fetch_writev().

This should improve performance in the non-SSL case (by reducing protocol
overhead) and solve the problem where too-smart-for-their-own-good
firewalls reject FTP packets that do not end in CRLF.

PR: bin/44123
Submitted by: fenner


# f606d589 11-Jun-2002 Dag-Erling Smørgrav <des@FreeBSD.org>

Add a reference count to struct fetchconn so we don't prematurely close and
free a cached FTP connection.


# 3070f6cb 05-Jun-2002 Dag-Erling Smørgrav <des@FreeBSD.org>

Make SSL support conditional on NOCRYPT.


# 111e2510 04-Jun-2002 Dag-Erling Smørgrav <des@FreeBSD.org>

Add SSL support + slight cleanup.

Submitted by: Henry Whincup <henry@techiebod.com> (in principle)


# 9601e333 04-Jun-2002 Dag-Erling Smørgrav <des@FreeBSD.org>

Wrap everything in struct connection, and enforce timeouts everywhere
(except for DNS operations). Always use funopen() for HTTP, to support
both timeouts and SSL.


# dea29ca1 05-Jun-2002 Dag-Erling Smørgrav <des@FreeBSD.org>

First step towards SSL support: wrap connections in a 'struct connection'
which contains the socket descriptor, the input buffer and (yet unused)
SSL state variables. This has the neat side effect of greatly improving
reentrance (though we're not *quite* there yet) and opening the door to
HTTP connection caching.

This commit is inspired by email conversations with and patches from
Henry Whincup <henry@techiebod.com> last fall.


# e19e6098 05-Feb-2002 Dag-Erling Smørgrav <des@FreeBSD.org>

Reindent, and add parentheses to return statements. Some functions in
ftp.c and http.c now have exceedingly long lines due to deep nesting;
this will be corrected by reorganizing the code in a later revision.


# 7eb2f34d 09-Dec-2001 Dag-Erling Smørgrav <des@FreeBSD.org>

Introduce a fetchDebug global. Change the DEBUG macro so it only runs the
debugging code if fetchDebug is set.

PR: bin/32615
MFC after: 1 week


# 89db7b8c 03-Dec-2001 Dag-Erling Smørgrav <des@FreeBSD.org>

Add prototype for _ftp_request().


# f573a5fc 18-Oct-2001 Dag-Erling Smørgrav <des@FreeBSD.org>

Tons of type, style and warning fixes that have been rotting in my tree for
ages - some of which wouldn't be necessary if gcc wasn't broken or TPTB were
willing to do something (-fno-builtin) about it.


# 38c7e4a6 23-Apr-2001 Archie Cobbs <archie@FreeBSD.org>

Apply 'const' liberally.

Fix some other minor glitches.


# e828ada7 10-Nov-2000 Dag-Erling Smørgrav <des@FreeBSD.org>

Use the documented (and historical) defaults. Centralize the decision logic
in order to avoid this bug in the future.

Submitted by: se


# 1c2598aa 29-Oct-2000 Dag-Erling Smørgrav <des@FreeBSD.org>

Add CHECK_FLAGS, a macro for (safely) checking if a particular flag is set.


# bbc5af0c 12-Oct-2000 Dag-Erling Smørgrav <des@FreeBSD.org>

ftp.c needs _http_request()


# 10851dc4 25-Jul-2000 Dag-Erling Smørgrav <des@FreeBSD.org>

Centralize the default port finding code.
Work around YA Apache bug: don't send port in Host: header if it's the
default port.


# a1763027 11-Jul-2000 Dag-Erling Smørgrav <des@FreeBSD.org>

Add _fetch_putln()


# ba101983 25-May-2000 Dag-Erling Smørgrav <des@FreeBSD.org>

Dump com_err, it's a stinking crock of shit.


# 28c645cf 20-May-2000 Hajimu UMEMOTO <ume@FreeBSD.org>

IPv6 support.


# fc6e9e65 06-Jan-2000 Dag-Erling Smørgrav <des@FreeBSD.org>

More old uncommitted patches: implement timeouts at the protocol level.
Currently only supported for ftp connections.


# 7f3dea24 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# ce71b736 21-Dec-1998 Dag-Erling Smørgrav <des@FreeBSD.org>

Implement and document file list retrieval.


# d941fd2d 18-Dec-1998 Dag-Erling Smørgrav <des@FreeBSD.org>

Don't specify a language to compile_et.
Rename fetchConnect to _fetch_connect since it's internal.


# 0fba3a00 16-Dec-1998 Dag-Erling Smørgrav <des@FreeBSD.org>

Add verbose flag, and support functions.
Brucify the Makefile.
Differentiate atime and mtime in fetch*Stat().
Fix a few pointer bugs.
Tweak some error messages.
Don't #include sys/param.h and stdio.h in fetch.h.
Document that sys/param.h and stdio.h must be #included before fetch.h.


# d8acd8dc 06-Nov-1998 Dag-Erling Smørgrav <des@FreeBSD.org>

Second of a series of cleanups to libfetch.

This commit introduces the following features:

a) the fetchStat*() functions, which return meta-information for a
document, such as size, modification time, etc.

b) the use of the com_err(3) facilities to report errors.

It also fixes a bunch of style bugs and a few logic bugs and somewhat
improves the man page.

Changed files, in alphabetical order:

Makefile:
Don't generate macros in {ftp,http}err.c.

Generate category fields for the error message lists.

Compile the error table.

Install fetch_err.h along with fetch.h.

common.c:
Remove the _netdb_errstring() macro, and add FETCH_ERR_NETDB to the
error code in the _netdb_seterr() macro.

Add categories to the _netdb_errlist table.

Report errors through the Common Error library.

common.h:
Add the DEBUG macros.

Add prototype for fetchConnect().

Remove the prototype for _fetch_errstring(), which is local to common.c

Add a categroy field to struct fetcherr, and define constants for
error categories.

Define macros for _{url,netdb,ftp,http}_seterr().

errors.et: (new file)
List error categories.

fetch.3:
Document the fetchStat*() functions.

Move the "unimplemented functionality" comments from NOTES to BUGS.

Document that applications which use libfetch must also use
libcom_err, and list existing error codes.

Undocument fetchLastErr{Code,String}.

Remove the (empty) DIAGNOSTICS section.

Mention Eugene Skepner in the AUTHORS section.

fetch.c:
Move the DEBUG macros to common.c

Add fetchStat() and fetchStatURL().

Generate error messages for URL parser errors, and fix a minor bug
in the parser.

Use 'struct url' instead of 'url_t'.

Remove fetchLastErr{Code,String}.

fetch.h:
Use 'struct url' instead of 'url_t', and remove the typedef.

Define struct url_stat (used by fetchStat()).

Add prototypes for fetchStat*().

Remove the declarations for fetchLastErr{Code,String}.

Include fetch_err.h.

fetch_err.et: (new file)
Error table for libfetch.

file.c:
Add fetchStatFile().

Use 'struct url' instead of 'url_t'.

ftp.c:
Add fetchStatFTP().

Use 'struct url' instead of 'url_t'.

Don't use fetchLastErrCode.

ftp.errors:
Add categories to all error messages.

http.c:
Add fetchStatHTTP().

Use 'struct url' instead of 'url_t'.

Don't use fetchLastErr{Code,Text}.

http.errors:
Add categories to all error messages.

Prompted by: jkh and Eugene Skepner
Numerous sugestions from: Garett Wollman and Eugene Skepner


# 842a95cc 05-Nov-1998 Dag-Erling Smørgrav <des@FreeBSD.org>

First of a series of cleanups to libfetch. Changed files, in
alphabetical order:

Makefile:
Add common.c to SRCS.

Make debugging easier by making 'CFLAGS += -DNDEBUG' conditional on DEBUG

Don't declare struct {ftp,http}err in {ftp,http}err.c; use struct fetcherr
instead.

README:
Remove the todo list, which is out of date anyway.

common.c: (new file)
Gather utility functions in this file.

Merge the error reporting functions intp _fetch_errstring(),
_fetch_seterr() and _fetch_syserr().

Set fetchLastErrCode and fetchLastErrText appropriately when fetchConnect
fails.

common.h: (new file)
Gather internal prototypes and structures in this files.

fetch.3:
Undocument fetchFreeURL().

Document a few more known bugs.

Document fetchLastErrCode and fetchLastErrText.

fetch.c:
Add descriptive comments to all functions that lacked them.

Move fetchConnect() to common.c.

Obviate the need for fetchFreeURL(), and remove it.

fetch.h:
Modify struct url_t so the document part is at the end.

ftp.c:
Remove code that is duplicated elsewhere.

http.c:
Remove code that is duplicated elsewhere.

Prompted by: jkh