Skip to content
Open

Vuk #137

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified src/Makefile
100644 → 100755
Empty file.
64 changes: 62 additions & 2 deletions src/client.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,35 @@ urlinfo_t *parse_url(char *url)

urlinfo_t *urlinfo = malloc(sizeof(urlinfo_t));

// char *placeholder = strstr(hostname, "://");


// if (placeholder != NULL) {
// hostname = placeholder;
// hostname += 3;
// }

// path = strchr(hostname, '/');
// *path = '\0';
// path++;
path = strchr(hostname, '/') + 1;
*(path - 1) = '\0';

// port = strchr(hostname, ':');
// *port = '\0';
// port++;
port = strchr(hostname, ':') + 1;
*(port - 1) = '\0';


urlinfo->hostname = hostname;
urlinfo->path = strdup(path);
urlinfo->port = strdup(port);

// urlinfo->hostname = strdup(hostname);
// urlinfo->path = strdup(path);
// urlinfo->port = strdup(port);

/*
We can parse the input URL by doing the following:

Expand All @@ -48,7 +77,8 @@ urlinfo_t *parse_url(char *url)
///////////////////
// IMPLEMENT ME! //
///////////////////


printf("\n\n%s%s%s\n\n", urlinfo->hostname, urlinfo->path, urlinfo->port);
return urlinfo;
}

Expand All @@ -72,7 +102,19 @@ int send_request(int fd, char *hostname, char *port, char *path)
// IMPLEMENT ME! //
///////////////////

return 0;
int request_length = sprintf(request,"GET /%s HTTP/1.1\nHost: %s:%s\nConnection:close\n\n",path,hostname,port);



rv = send(fd, request, request_length, 0);

if (rv < 0) {

perror("send");

}

return rv;
}

int main(int argc, char *argv[])
Expand All @@ -85,6 +127,24 @@ int main(int argc, char *argv[])
exit(1);
}

urlinfo_t *urlinfo = parse_url(argv[1]);

sockfd = get_socket(urlinfo->hostname, urlinfo->port);

send_request(sockfd, urlinfo->hostname, urlinfo->port, urlinfo->path);


while ((numbytes = recv(sockfd, buf, BUFSIZE - 1, 0)) > 0) {
printf("%s", buf);
}

close(sockfd);
free(urlinfo->hostname);
free(urlinfo->path);
free(urlinfo->port);
free(urlinfo);


/*
1. Parse the input URL
2. Initialize a socket by calling the `get_socket` function from lib.c
Expand Down
Empty file modified src/lib.c
100644 → 100755
Empty file.
Empty file modified src/lib.h
100644 → 100755
Empty file.