diff options
Diffstat (limited to 'browse.c')
| -rw-r--r-- | browse.c | 44 | 
1 files changed, 11 insertions, 33 deletions
| @@ -241,7 +241,11 @@ file_template_callback(size_t index, void *arg)  		K_OK(khtml_puts(html, data->f->action_url), r);  		break;  	case 3: -		/* size, print as human readable */ +		/* size, only for files, print as human readable */ +		if (data->f->is_dir) { +			break; +		} +  		file_size = data->f->size;  		i = 0;  		while (file_size > 1024 && i < 3) { @@ -275,12 +279,11 @@ file_template_callback(size_t index, void *arg)  	return 1;  } -struct http_ret +void  browse(struct kreq * r)  {  	struct file *file;  	struct page_template *tmpl; -	struct http_ret ret;  	struct khtmlreq html;  	struct ktemplate template;  	struct template_data data; @@ -289,53 +292,30 @@ browse(struct kreq * r)  	file = NULL;  	tmpl = NULL; -	/* initialize return structure for success */ -	ret = (struct http_ret) { -		KHTTP_200, "" -	}; -  	/* list requested directory content */  	file = file_new(r->path);  	if (file == NULL) { -		ret = (struct http_ret) { -			KHTTP_404, -			"browse: Unable to build data file" -		}; +		http_exit(r, KHTTP_404, "browse: Unable to build data file");  		goto end;  	}  	if (!file->is_dir) { -		ret = (struct http_ret) { -			KHTTP_404, -			"browse: Invalid data file" -		}; +		http_exit(r, KHTTP_404, "browse: Invalid data file");  		goto end;  	}  	if (build_upload_url(r, file) == 0) { -		ret = (struct http_ret) { -			KHTTP_500, -			"browse: Can't build upload url" -		}; +		http_exit(r, KHTTP_500, "browse: Can't build upload url");  		goto end;  	} -  	if (build_file_list(r, file) < 0) { -		ret = (struct http_ret) { -			KHTTP_500, -			"browse: Unable to build file list" -		}; +		http_exit(r, KHTTP_500, "browse: Unable to build file list");  		goto end;  	} -  	/* read template */  	tmpl = page_template_new(BROWSE_URL);  	if (tmpl == NULL) { -		ret = (struct http_ret) { -			KHTTP_500, -			"browse: Unable to read template" -		}; +		http_exit(r, KHTTP_500, "browse: Unable to read template");  		goto end;  	} -  	/* we have all the data we need, we can start to write output page */  	http_open(r, KHTTP_200, KMIME_TEXT_HTML); @@ -383,6 +363,4 @@ end:  		file_free(file);  		file = NULL;  	} - -	return ret;  } | 
