#include <string.h>
#include <unistd.h>
+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);
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) {
break;
case 'p':
if(acc){
+ write(1, databuf, datalen);
}
break;
case '\n':