From 39bb44d1bc2adfa32a4cacdbeb79772981c3bf9d Mon Sep 17 00:00:00 2001 From: nishi Date: Fri, 16 Feb 2024 05:25:44 +0000 Subject: [PATCH] fixing w3b git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@232 d27a3e52-49c5-7645-884c-6793ebffc270 --- Example/w3b/w3b.c | 41 +++++++++++++++++++++++++++++++++++++++++ W3Version.h.m4 | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Example/w3b/w3b.c b/Example/w3b/w3b.c index 70b2e19..58c20d9 100644 --- a/Example/w3b/w3b.c +++ b/Example/w3b/w3b.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -106,8 +107,47 @@ void data_handler(struct W3* w3, char* data, size_t size) { } } +struct W3URL* global_u; +void nntpresp_handler(struct W3* w3, int status, char* data){ + if(status == 200){ + if(databuf == NULL){ + databuf = malloc(1); + databuf[0] = 0; + } + char* tmp = databuf; + char* hyp = malloc(2 + strlen(data) + 3 + 1); + hyp[0] = '\n'; + int i; + for(i = 0; data[i] != 0; i++){ + hyp[i + 1] = '-'; + } + for(i = 0; i < 3; i++) hyp[strlen(data) + i + 1] = '-'; + hyp[strlen(data) + 3 + 1] = '\n'; + hyp[strlen(data) + 3 + 2] = 0; + databuf = __W3_Concat3(tmp, data, hyp); + free(hyp); + free(tmp); + datalen = strlen(databuf); + + W3_Set_Method(w3, "GROUP"); + W3_Set_Path(w3, global_u->path + 1); + W3_NNTP_Send_Request(w3); + }else if(status == 211 || status == 223){ + W3_Set_Method(w3, "HEAD"); + W3_NNTP_Send_Request(w3); + }else if(status == 221){ + printf("%s\n", data); + exit(0); + W3_Set_Method(w3, "NEXT"); + W3_NNTP_Send_Request(w3); + }else{ + W3_NNTP_Disconnect(w3); + } +} + void access_site(const char* url) { struct W3URL* u = W3_Parse_URL(url); + global_u = u; if(u != NULL) { struct W3* w3 = W3_Create(u->protocol, u->host, u->port); if(w3 != NULL) { @@ -122,6 +162,7 @@ void access_site(const char* url) { W3_HTTP_Enable_Redirect(w3); W3_On(w3, "status", (void*)status_handler); W3_On(w3, "header", (void*)header_handler); + W3_On(w3, "nntpresp", (void*)nntpresp_handler); W3_On(w3, "data", (void*)data_handler); if(ctype != NULL) free(ctype); ctype = NULL; diff --git a/W3Version.h.m4 b/W3Version.h.m4 index 9b97c18..dbd5c51 100644 --- a/W3Version.h.m4 +++ b/W3Version.h.m4 @@ -6,7 +6,7 @@ extern "C" { #endif -#define LIBW3_VERSION "2.15C" \ +#define LIBW3_VERSION "2.15D" \ SUFFIX ifdef(`HTTP_SUPPORT', `#define LIBW3_HTTP_SUPPORT', `') -- 2.43.0