Skip to content

Commit

Permalink
googlefs: error handling
Browse files Browse the repository at this point in the history
Damn this code is ugly!

Also dump the header we get to /tmp
  • Loading branch information
mmuman committed Nov 8, 2015
1 parent 25472bc commit 49d3cc2
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/add-ons/kernel/file_systems/googlefs/http_cnx.c
Expand Up @@ -128,9 +128,10 @@ status_t http_get(struct http_cnx *cnx, const char *url)
long contentlen = 0;
if (strlen(url) > 4096 - 128)
return EINVAL;
req = malloc(4096);
req = malloc(4096+1);
if (!req)
return B_NO_MEMORY;
req[4096] = '\0';
/* no snprintf in kernel :( */
sprintf(req, "GET %s HTTP/"HTTPVER"\r\nUser-Agent: " GOOGLEFS_UA "\r\nAccept: */*\r\n\r\n", url);
reqlen = strlen(req);
Expand All @@ -140,10 +141,24 @@ status_t http_get(struct http_cnx *cnx, const char *url)
reqlen = 4096;
err = len = read(cnx->sock, req, reqlen);
printf("read(sock) = %d\n", len);
if (err < 0)
goto err0;
//write(1, req, len);
err = B_NO_MEMORY;
{
int fd;
// debug output
fd = open("/tmp/google.html_", O_CREAT|O_TRUNC|O_RDWR, 0644);
write(fd, req, len);
close(fd);
}

err = EINVAL;
if (len < 10)
goto err0;
if (!strstr(req, "HTTP/1.0 200"))
goto err0;

err = B_NO_MEMORY;
if (!strstr(req, "\r\n\r\n")) {
if (!strstr(req, "\n\n")) /* shouldn't happen */
goto err0;
Expand Down

0 comments on commit 49d3cc2

Please sign in to comment.