From c71fc10b5fd7cfcac5b8621ba14f800885ec5833 Mon Sep 17 00:00:00 2001 From: Nishi Date: Wed, 21 Aug 2024 05:05:19 +0000 Subject: [PATCH] works git-svn-id: file:///raid/svn-personal/repoview/trunk@12 7e8b2a19-8934-dd40-8cb3-db22cdd5a80f --- CGI/repo.c | 31 ++++++++++++++++++------- CGI/theme/modern.c | 58 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 76 insertions(+), 13 deletions(-) diff --git a/CGI/repo.c b/CGI/repo.c index d802430..7d323e5 100644 --- a/CGI/repo.c +++ b/CGI/repo.c @@ -15,6 +15,7 @@ #include #include #include +#include char* rv_construct_repouser(const char* reponame, const char* username) { char cbuf[2]; @@ -209,7 +210,7 @@ bool rv_get_list(const char* repouser, const char* path, void (*handler)(const c char oldc = d[i]; d[i] = 0; count++; - if(count > 1 && strlen(d + incr + 1) > 0 && d[incr] != 0) { + if(count > 1 && d[incr] != 0 && strlen(d + incr + 1) > 0) { char* pathname = d + incr + 1; if(phase == 0 && pathname[strlen(pathname) - 1] == '/') { handler(d + incr + 1); @@ -226,6 +227,8 @@ bool rv_get_list(const char* repouser, const char* path, void (*handler)(const c } } phase++; + incr = 0; + count = 0; if(phase == 1) goto repeat; free(d); } @@ -234,6 +237,7 @@ bool rv_get_list(const char* repouser, const char* path, void (*handler)(const c } char* rv_read_file(const char* repouser, char* path) { + if(rv_get_filesize(repouser, path) > 1024 * 128) return NULL; char* svnpath = rv_strcat3(SVN_ROOT, "/", repouser); int pipes[2]; pipe(pipes); @@ -246,16 +250,21 @@ char* rv_read_file(const char* repouser, char* path) { _exit(0); } else { close(pipes[1]); - char cbuf[2]; - cbuf[1] = 0; - char* d = malloc(1); - d[0] = 0; + char cbuf[1024]; + char* d = malloc(1024 * 128); + int incr = 0; + bool bin = false; while(1) { - int n = read(pipes[0], cbuf, 1); + int n = read(pipes[0], cbuf, 1024); + if(cbuf[0] == 0) { + bin = true; + kill(pid, SIGKILL); + break; + } if(n == 0) break; - char* tmp = d; - d = rv_strcat(tmp, cbuf); - free(tmp); + memcpy(d + incr, cbuf, n); + d[incr + n] = 0; + incr += n; } int status; waitpid(pid, &status, 0); @@ -264,6 +273,10 @@ char* rv_read_file(const char* repouser, char* path) { free(svnpath); return NULL; } + if(bin) { + free(d); + return NULL; + } return d; } } diff --git a/CGI/theme/modern.c b/CGI/theme/modern.c index b834646..675b926 100644 --- a/CGI/theme/modern.c +++ b/CGI/theme/modern.c @@ -116,6 +116,50 @@ void list_files(const char* pathname) { add_data(&nav, "
  • File List
  • \n"); add_data(&page, "

    File List

    \n"); add_data(&page, "NameSize\n"); + char* path = rv_get_query("path"); + if(path == NULL) path = "/"; + if(strcmp(path, "/") != 0) { + char* query = rv_strdup("?page=repo&reponame="); + char* esc; + esc = url_escape(rv_get_query("reponame")); + add_data(&query, esc); + free(esc); + add_data(&query, "&username="); + esc = url_escape(user); + add_data(&query, esc); + free(esc); + add_data(&query, "&path="); + + char* urlpath = rv_strdup(path); + int i; + int counter = 0; + int rep = urlpath[strlen(urlpath) - 1] == '/' ? 2 : 1; + for(i = strlen(urlpath) - 1; i >= 0; i--) { + char oldc = urlpath[i]; + urlpath[i] = 0; + if(oldc == '/') { + counter++; + if(counter == 2) { + break; + } + } + } + + if(strlen(urlpath) == 0) { + free(urlpath); + urlpath = rv_strdup("/"); + } + + esc = url_escape(urlpath); + add_data(&query, esc); + free(esc); + + add_data(&page, "../<DIR>\n"); + fcounter++; + free(query); + } } fcounter++; add_data(&page, "Content\n"); add_data(&page, "
    ");
     					char* data = rv_read_file(repouser, path);
    -					char* esc = html_escape_nl_to_br(data);
    -					add_data(&page, esc);
    -					free(esc);
    -					free(data);
    +					if(data != NULL) {
    +						char* esc = html_escape_nl_to_br(data);
    +						add_data(&page, esc);
    +						free(esc);
    +						free(data);
    +					} else {
    +						add_data(&page, "Cannot open the file.\n");
    +					}
     					add_data(&page, "
    "); } } else { @@ -482,6 +530,8 @@ void render_stuff(void) { add_data(&buffer, "pre {\n"); add_data(&buffer, " background-color: #dddddd;\n"); add_data(&buffer, " border: solid 2px #bbbbbb;\n"); + add_data(&buffer, " padding: 8px;\n"); + add_data(&buffer, " overflow: scroll;\n"); add_data(&buffer, "}\n"); add_data(&buffer, "#index {\n"); add_data(&buffer, " list-style: none;\n"); -- 2.45.2