]> Nishi Git Mirror - libw3.git/commitdiff
nntp
authornishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Wed, 14 Feb 2024 05:47:04 +0000 (05:47 +0000)
committernishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Wed, 14 Feb 2024 05:47:04 +0000 (05:47 +0000)
git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@218 d27a3e52-49c5-7645-884c-6793ebffc270

Example/Makefile
Example/nntp-list/Makefile [new file with mode: 0644]
Example/nntp-list/nntp-list.c [new file with mode: 0644]
W3Version.h.p

index a75b6c564ca7cd6c022b0f4a90fff5b7cc76b1a0..aa9ea914624267c287c4fb8dc2572ad51cfc790c 100644 (file)
@@ -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 (file)
index 0000000..4dc4737
--- /dev/null
@@ -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 (file)
index 0000000..10201b7
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * $Id$
+ *
+ * Lists the FTP files
+ */
+
+#include <W3Core.h>
+#include <W3FTP.h>
+
+#include <W3URL.h>
+#include <W3Util.h> /* It has some useful functions, you know */
+
+#include <ctype.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+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;
+       }
+}
index 27b71be1d68c2f659ed313da772990f48b3f7bb4..00c99186ce99081b6486a2ff7f5e7c5beeb742d0 100644 (file)
@@ -6,7 +6,7 @@
 extern "C" {
 #endif
 
-#define LIBW3_VERSION "2.12B" \
+#define LIBW3_VERSION "2.12C" \
 SUFFIX
 
 #ifdef __cplusplus