From: nishi Date: Fri, 26 Jan 2024 05:52:35 +0000 (+0000) Subject: print all X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=e87d0224d50c11fd0f58531579d14181bda0a625;p=libw3.git print all git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@85 d27a3e52-49c5-7645-884c-6793ebffc270 --- diff --git a/Example/W3B/w3b.c b/Example/W3B/w3b.c index 120bd49..ec32d20 100644 --- a/Example/W3B/w3b.c +++ b/Example/W3B/w3b.c @@ -15,15 +15,35 @@ #include #include +char* databuf; +int datalen; + void status_handler(struct W3* w3, int status) { printf("Response code: %d\n", status); } -void data_handler(struct W3* w3, char* data, size_t size) {} +void data_handler(struct W3* w3, char* data, size_t size) { + if(databuf == NULL){ + databuf = malloc(size); + datalen = size; + memcpy(databuf, data, size); + }else{ + char* oldbuf = databuf; + databuf = malloc(datalen + size); + memcpy(databuf, oldbuf, datalen); + memcpy(databuf + datalen, data, size); + datalen += size; + } +} void access_site(const char* url) { struct W3URL* u = W3_Parse_URL(url); if(u != NULL) { struct W3* w3 = W3_Create(u->protocol, u->host, u->port); if(w3 != NULL) { + if(databuf != NULL){ + free(databuf); + } + databuf = NULL; + datalen = 0; W3_Set_Method(w3, "GET"); W3_Set_Path(w3, u->path); W3_On(w3, "status", (void*)status_handler); @@ -41,6 +61,8 @@ void access_site(const char* url) { int main(int argc, char** argv) { int i; + databuf = NULL; + datalen = 0; char* url = NULL; for(i = 1; i < argc; i++) { if(strcmp(argv[i], "--version") == 0) { @@ -87,6 +109,7 @@ int main(int argc, char** argv) { break; case 'p': if(acc){ + write(1, databuf, datalen); } break; case '\n':