Skip to content

Commit cecf738

Browse files
authored
Remove knet. (PR samtools#1200)
There's little benefit to keeping it (basically FTP and unsecured http), while curl is already required for htsget, refget (CRAM ref cache), AWS S3 and GCS protocols. Curl is available on all platforms we support. The public API in htslib/knetfile.h is retained for compatibility. The knet_* functions have been replaced by stubs that use hFILE internally. htslib/knetfile.h has HTS_DEPRECATED markers for these functions, so anyone compiling against the new code will get a warning that we intend to delete them in the future. The knet_tell macro does direct access of knetFile::offset so we cannot simply wrap up htell as we'd like. Similarly knet_fileno directly queries knetFile::fd. However the only use I've found of this was in old copies of bgzf and bcftools main which then did fstat on it so it's only filled out for local files. (That's good because getting it out of curl isn't supported by our code.)
1 parent c7c433f commit cecf738

13 files changed

+125
-815
lines changed

INSTALL

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ a development ('-dev' or '-devel') package separate from the main library.
4141
Disabling libbzip2 and liblzma will make some CRAM files unreadable, so
4242
is not recommended.
4343

44-
Using libcurl provides HTSlib with better network protocol support, for
45-
example it enables the use of https:// URLs. It is also required if
46-
direct access to Amazon S3 or Google Cloud Storage is enabled.
44+
Using libcurl provides HTSlib with network protocol support, for
45+
example it enables the use of ftp://, http://, and https:// URLs.
46+
It is also required if direct access to Amazon S3 or Google Cloud
47+
Storage is enabled.
4748

4849
Amazon S3 support requires an HMAC function to calculate a message
4950
authentication code. On MacOS, the CCHmac function from the standard
@@ -131,8 +132,7 @@ various features and specify further optional external requirements:
131132

132133
--enable-libcurl
133134
Use libcurl (<http://curl.haxx.se/>) to implement network access to
134-
remote files via FTP, HTTP, HTTPS, etc. By default, HTSlib uses its
135-
own simple networking code to provide access via FTP and HTTP only.
135+
remote files via FTP, HTTP, HTTPS, etc.
136136

137137
--enable-gcs
138138
Implement network access to Google Cloud Storage. By default or with

Makefile

+1-6
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,13 @@ show-version:
144144

145145
LIBHTS_OBJS = \
146146
kfunc.o \
147-
knetfile.o \
148147
kstring.o \
149148
bcf_sr_sort.o \
150149
bgzf.o \
151150
errmod.o \
152151
faidx.o \
153152
header.o \
154153
hfile.o \
155-
hfile_net.o \
156154
hts.o \
157155
hts_expr.o \
158156
hts_os.o\
@@ -334,12 +332,10 @@ hts-object-files: $(LIBHTS_OBJS)
334332
bgzf.o bgzf.pico: bgzf.c config.h $(htslib_hts_h) $(htslib_bgzf_h) $(htslib_hfile_h) $(htslib_thread_pool_h) $(htslib_hts_endian_h) cram/pooled_alloc.h $(hts_internal_h) $(htslib_khash_h)
335333
errmod.o errmod.pico: errmod.c config.h $(htslib_hts_h) $(htslib_ksort_h) $(htslib_hts_os_h)
336334
kstring.o kstring.pico: kstring.c config.h $(htslib_kstring_h)
337-
knetfile.o knetfile.pico: knetfile.c config.h $(htslib_hts_log_h) $(htslib_knetfile_h)
338335
header.o header.pico: header.c config.h $(textutils_internal_h) $(header_h)
339336
hfile.o hfile.pico: hfile.c config.h $(htslib_hfile_h) $(hfile_internal_h) $(htslib_kstring_h) $(hts_internal_h) $(htslib_khash_h)
340337
hfile_gcs.o hfile_gcs.pico: hfile_gcs.c config.h $(htslib_hts_h) $(htslib_kstring_h) $(hfile_internal_h)
341338
hfile_libcurl.o hfile_libcurl.pico: hfile_libcurl.c config.h $(hfile_internal_h) $(htslib_hts_h) $(htslib_kstring_h) $(htslib_khash_h)
342-
hfile_net.o hfile_net.pico: hfile_net.c config.h $(hfile_internal_h) $(htslib_knetfile_h)
343339
hfile_s3_write.o hfile_s3_write.pico: hfile_s3_write.c config.h $(hfile_internal_h) $(htslib_hts_h) $(htslib_kstring_h) $(htslib_khash_h)
344340
hfile_s3.o hfile_s3.pico: hfile_s3.c config.h $(hfile_internal_h) $(htslib_hts_h) $(htslib_kstring_h)
345341
hts.o hts.pico: hts.c config.h $(htslib_hts_expr_h) $(htslib_hts_h) $(htslib_bgzf_h) $(cram_h) $(htslib_hfile_h) $(htslib_hts_endian_h) version.h $(hts_internal_h) $(hfile_internal_h) $(sam_internal_h) $(htslib_hts_os_h) $(htslib_khash_h) $(htslib_kseq_h) $(htslib_ksort_h) $(htslib_tbx_h)
@@ -544,8 +540,7 @@ test-shlib-exports: header-exports.txt shlib-exports-$(SHLIB_FLAVOUR).txt
544540
( echo "Error: Found unexported symbols (listed above)" ; false )
545541

546542
# Extract symbols that should be exported from public headers using ctags
547-
# Filter out macros in htslib/hts_defs.h, and knet_win32_ functions that
548-
# aren't needed on non-Windows platforms.
543+
# Filter out macros in htslib/hts_defs.h.
549544
header-exports.txt: test/header_syms.pl htslib/*.h
550545
test/header_syms.pl htslib/*.h | sort -u -o $@
551546

NEWS

+6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
Noteworthy changes in release a.b
22
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33

4+
* The knet networking code has been removed. It only supported the http
5+
and ftp protocols, and a better and safer alternative using libcurl
6+
has been available since release 1.3. If you need access to ftp:// and
7+
http:// URLs, HTSlib should be built with libcurl support. (#1200)
48

9+
* The old htslib/knetfile.h interfaces have been marked as deprecated. Any
10+
code still using them should be updated to use hFILE instead. (#1200)
511

612
Noteworthy changes in release 1.11 (22nd September 2020)
713
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

hfile.c

+79-1
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,6 @@ static int load_hfile_plugins()
10611061
hfile_add_scheme_handler("data", &data);
10621062
hfile_add_scheme_handler("file", &file);
10631063
hfile_add_scheme_handler("preload", &preload);
1064-
init_add_plugin(NULL, hfile_plugin_init_net, "knetfile");
10651064
init_add_plugin(NULL, hfile_plugin_init_mem, "mem");
10661065
init_add_plugin(NULL, hfile_plugin_init_crypt4gh_needed, "crypt4gh-needed");
10671066

@@ -1213,3 +1212,82 @@ char *haddextension(struct kstring_t *buffer, const char *filename,
12131212
kputs(trailing, buffer) >= 0) return buffer->s;
12141213
else return NULL;
12151214
}
1215+
1216+
1217+
/*
1218+
* ----------------------------------------------------------------------
1219+
* Minimal stub functions for knet, added after the removal of
1220+
* hfile_net.c and knetfile.c.
1221+
*
1222+
* They exist purely for ABI compatibility, but are simply wrappers to
1223+
* hFILE. API should be compatible except knet_fileno (unused?).
1224+
*
1225+
* CULL THESE and knetfile.h at the next .so version bump.
1226+
*/
1227+
typedef struct knetFile_s {
1228+
// As per htslib/knetfile.h. Duplicated here as we don't wish to
1229+
// have any dependence on the deprecated knetfile.h interface, plus
1230+
// it's hopefully only temporary.
1231+
int type, fd;
1232+
int64_t offset;
1233+
char *host, *port;
1234+
int ctrl_fd, pasv_ip[4], pasv_port, max_response, no_reconnect, is_ready;
1235+
char *response, *retr, *size_cmd;
1236+
int64_t seek_offset;
1237+
int64_t file_size;
1238+
char *path, *http_host;
1239+
1240+
// Our local addition
1241+
hFILE *hf;
1242+
} knetFile;
1243+
1244+
HTSLIB_EXPORT
1245+
knetFile *knet_open(const char *fn, const char *mode) {
1246+
knetFile *fp = calloc(1, sizeof(*fp));
1247+
if (!fp) return NULL;
1248+
if (!(fp->hf = hopen(fn, mode))) {
1249+
free(fp);
1250+
fp = NULL;
1251+
}
1252+
1253+
// FD backend is the only one implementing knet_fileno
1254+
fp->fd = fp->hf->backend == &fd_backend
1255+
? ((hFILE_fd *)fp->hf)->fd
1256+
: -1;
1257+
1258+
return fp;
1259+
}
1260+
1261+
HTSLIB_EXPORT
1262+
knetFile *knet_dopen(int fd, const char *mode) {
1263+
knetFile *fp = calloc(1, sizeof(*fp));
1264+
if (!fp) return NULL;
1265+
if (!(fp->hf = hdopen(fd, mode))) {
1266+
free(fp);
1267+
fp = NULL;
1268+
}
1269+
fp->fd = fd;
1270+
return fp;
1271+
}
1272+
1273+
HTSLIB_EXPORT
1274+
ssize_t knet_read(knetFile *fp, void *buf, size_t len) {
1275+
ssize_t r = hread(fp->hf, buf, len);
1276+
fp->offset += r>0?r:0;
1277+
return r;
1278+
}
1279+
1280+
HTSLIB_EXPORT
1281+
off_t knet_seek(knetFile *fp, off_t off, int whence) {
1282+
off_t r = hseek(fp->hf, off, whence);
1283+
if (r >= 0)
1284+
fp->offset = r;
1285+
return r;
1286+
}
1287+
1288+
HTSLIB_EXPORT
1289+
int knet_close(knetFile *fp) {
1290+
int r = hclose(fp->hf);
1291+
free(fp);
1292+
return r;
1293+
}

hfile_internal.h

-3
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,6 @@ extern int hfile_plugin_init_s3(struct hFILE_plugin *self);
179179
extern int hfile_plugin_init_s3_write(struct hFILE_plugin *self);
180180
#endif
181181

182-
/* This one is never built as a separate plugin. */
183-
extern int hfile_plugin_init_net(struct hFILE_plugin *self);
184-
185182
// Callback to allow headers to be set in http connections. Currently used
186183
// to allow s3 to renew tokens when seeking. Kept internal for now,
187184
// although we may consider exposing it in the API later.

hfile_libcurl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ libcurl_open(const char *url, const char *modes, http_headers *headers)
12211221
err = curl_easy_setopt(fp->easy, CURLOPT_PRIVATE, fp);
12221222

12231223
// Avoid many repeated CWD calls with FTP, instead requesting the filename
1224-
// by full path (as done in knet, but not strictly compliant with RFC1738).
1224+
// by full path (but not strictly compliant with RFC1738).
12251225
err |= curl_easy_setopt(fp->easy, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_NOCWD);
12261226

12271227
if (mode == 'r') {

hfile_net.c

-112
This file was deleted.

htslib.mk

-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ HTSLIB_PUBLIC_HEADERS = \
6262
$(HTSDIR)/htslib/khash.h \
6363
$(HTSDIR)/htslib/khash_str2int.h \
6464
$(HTSDIR)/htslib/klist.h \
65-
$(HTSDIR)/htslib/knetfile.h \
6665
$(HTSDIR)/htslib/kseq.h \
6766
$(HTSDIR)/htslib/ksort.h \
6867
$(HTSDIR)/htslib/kstring.h \
@@ -89,15 +88,13 @@ HTSLIB_ALL = \
8988
$(HTSDIR)/hfile.c \
9089
$(HTSDIR)/hfile_gcs.c \
9190
$(HTSDIR)/hfile_libcurl.c \
92-
$(HTSDIR)/hfile_net.c \
9391
$(HTSDIR)/hfile_s3.c \
9492
$(HTSDIR)/hfile_s3_write.c \
9593
$(HTSDIR)/hts.c \
9694
$(HTSDIR)/hts_expr.c \
9795
$(HTSDIR)/hts_internal.h \
9896
$(HTSDIR)/hts_os.c \
9997
$(HTSDIR)/kfunc.c \
100-
$(HTSDIR)/knetfile.c \
10198
$(HTSDIR)/kstring.c \
10299
$(HTSDIR)/md5.c \
103100
$(HTSDIR)/multipart.c \

0 commit comments

Comments
 (0)