From 866a24e211c253dc1deb3bd45a3aef0b21a5f779 Mon Sep 17 00:00:00 2001 From: nishi Date: Wed, 14 Feb 2024 05:47:04 +0000 Subject: [PATCH] nntp git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@218 d27a3e52-49c5-7645-884c-6793ebffc270 --- Example/Makefile | 3 ++ Example/nntp-list/Makefile | 18 +++++++++ Example/nntp-list/nntp-list.c | 69 +++++++++++++++++++++++++++++++++++ W3Version.h.p | 2 +- 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 Example/nntp-list/Makefile create mode 100644 Example/nntp-list/nntp-list.c diff --git a/Example/Makefile b/Example/Makefile index a75b6c5..aa9ea91 100644 --- a/Example/Makefile +++ b/Example/Makefile @@ -11,6 +11,7 @@ examples: $(MAKE) -C ./pop3-list CC=$(CC) SUFFIX=$(SUFFIX) $(MAKE) -C ./w3b CC=$(CC) SUFFIX=$(SUFFIX) $(MAKE) -C ./ftp-list CC=$(CC) SUFFIX=$(SUFFIX) + $(MAKE) -C ./nntp-list CC=$(CC) SUFFIX=$(SUFFIX) ifeq ($(TCL),YES) $(MAKE) -C ./tclw3 CC=$(CC) TCL_LIBS="$(TCL_LIBS)" TCL_CFLAGS="$(TCL_CFLAGS)" SUFFIX=$(SUFFIX) endif @@ -21,6 +22,7 @@ install: $(MAKE) -C ./pop3-list CC=$(CC) PREFIX=$(PREFIX) SUFFIX=$(SUFFIX) install $(MAKE) -C ./w3b CC=$(CC) PREFIX=$(PREFIX) SUFFIX=$(SUFFIX) install $(MAKE) -C ./ftp-list CC=$(CC) PREFIX=$(PREFIX) SUFFIX=$(SUFFIX) install + $(MAKE) -C ./nntp-list CC=$(CC) PREFIX=$(PREFIX) SUFFIX=$(SUFFIX) install ifeq ($(TCL),YES) $(MAKE) -C ./tclw3 CC=$(CC) PREFIX=$(PREFIX) SUFFIX=$(SUFFIX) install endif @@ -32,6 +34,7 @@ clean: $(MAKE) -C ./pop3-list SUFFIX=$(SUFFIX) clean $(MAKE) -C ./w3b SUFFIX=$(SUFFIX) clean $(MAKE) -C ./ftp-list SUFFIX=$(SUFFIX) clean + $(MAKE) -c ./nntp-list SUFFIX=$(SUFFIX) clean ifeq ($(TCL),YES) $(MAKE) -C ./tclw3 CC=$(CC) SUFFIX=$(SUFFIX) clean endif diff --git a/Example/nntp-list/Makefile b/Example/nntp-list/Makefile new file mode 100644 index 0000000..4dc4737 --- /dev/null +++ b/Example/nntp-list/Makefile @@ -0,0 +1,18 @@ +# $Id$ +.PHONY: clean install + +./nntp-list$(SUFFIX): ./nntp-list.o $(RESFILE) + $(CC) -g -o $@ -L ../../Library $^ -lw3 + +./%.o: ./%.c + $(CC) -g -c -o $@ -I ../../Library $< + +../libw3.res: + $(MAKE) -C .. ./libw3.res WINDRES=$(WINDRES) + +clean: + rm -f nntp-list *.o *.so *.core *~ *.exe *.res + +install: ./nntp-list + mkdir -p $(PREFIX)/bin + cp ./nntp-list $(PREFIX)/bin/w3-nntp-list diff --git a/Example/nntp-list/nntp-list.c b/Example/nntp-list/nntp-list.c new file mode 100644 index 0000000..10201b7 --- /dev/null +++ b/Example/nntp-list/nntp-list.c @@ -0,0 +1,69 @@ +/* + * $Id$ + * + * Lists the FTP files + */ + +#include +#include + +#include +#include /* It has some useful functions, you know */ + +#include +#include +#include +#include +#include +#include + +struct W3URL* w3url; + +void resp_handler(struct W3* w3, int status, char* data) { + printf("%d\n%s\n", status, data); + if(status == 230) { + W3_Set_Method(w3, "CWD"); + W3_Set_Path(w3, w3url->path); + W3_FTP_Send_Request(w3); + W3_Set_Method(w3, "LIST"); + W3_Set_Path(w3, "/"); + W3_FTP_Send_Request(w3); + } else if(status == 226) { + W3_FTP_Disconnect(w3); + } +} + +void data_handler(struct W3* w3, char* data, size_t size) { write(1, data, size); } + +int main(int argc, char** argv) { + if(argc < 2) { + fprintf(stderr, "%s: usage: %s url\n", argv[0], argv[0]); + return 1; + } + W3_Library_Init(); + w3url = W3_Parse_URL(argv[1]); + if(w3url != NULL) { + bool err = false; + if(w3url->username == NULL) { + err = true; + fprintf(stderr, "%s: missing username\n", argv[0]); + } + if(w3url->password == NULL) { + err = true; + fprintf(stderr, "%s: missing password\n", argv[0]); + } + if(err) { + W3_Free_URL(w3url); + return 1; + } + struct W3* w3 = W3_Create("ftp", w3url->host, w3url->port); + W3_FTP_Set_Username(w3, w3url->username); + W3_FTP_Set_Password(w3, w3url->password); + W3_On(w3, "ftpresp", resp_handler); + W3_On(w3, "data", data_handler); + W3_Send_Request(w3); + W3_Free_URL(w3url); + } else { + return 1; + } +} diff --git a/W3Version.h.p b/W3Version.h.p index 27b71be..00c9918 100644 --- a/W3Version.h.p +++ b/W3Version.h.p @@ -6,7 +6,7 @@ extern "C" { #endif -#define LIBW3_VERSION "2.12B" \ +#define LIBW3_VERSION "2.12C" \ SUFFIX #ifdef __cplusplus -- 2.43.0