From fd19e39d3a8a0a1ae9a8f1fda8ea8691c8fb98b3 Mon Sep 17 00:00:00 2001 From: tenox7 Date: Sun, 8 Jul 2018 02:46:53 -0700 Subject: paths in to a struct --- dialogs.c | 45 +++++++++++++------------ dir.c | 102 ++++++++++++++++++++++++++++---------------------------- fileio.c | 112 +++++++++++++++++++++++++++++++------------------------------- wfm.c | 82 +++++++++++++++++++++------------------------ wfm.h | 34 ++++++++----------- 5 files changed, 181 insertions(+), 194 deletions(-) diff --git a/dialogs.c b/dialogs.c index 763e707..7c26cbd 100644 --- a/dialogs.c +++ b/dialogs.c @@ -45,22 +45,22 @@ void multiprompt_ui(char *m_action) { if(res == cgiFormNotFound) { checkfilename(NULL); - if(stat(phys_filename, &fileinfo)==0) { - fprintf(cgiOut, "\n", virt_filename); - fprintf(cgiOut, "
  • %s", virt_filename); + if(stat(wp.phys_filename, &fileinfo)==0) { + fprintf(cgiOut, "\n", wp.virt_filename); + fprintf(cgiOut, "
  • %s", wp.virt_filename); if(S_ISDIR(fileinfo.st_mode)) - fprintf(cgiOut, " [directory %s]\n", buprintf(du(phys_filename), FALSE)); + fprintf(cgiOut, " [directory %s]\n", buprintf(du(wp.phys_filename), FALSE)); else fprintf(cgiOut, " [file %s]\n", buprintf(fileinfo.st_size, FALSE)); } } else { for(i=0; responses[i]; i++) { checkfilename(responses[i]); - if(stat(phys_filename, &fileinfo)==0) { - fprintf(cgiOut, "\n", virt_filename); - fprintf(cgiOut, "
  • %s", virt_filename); + if(stat(wp.phys_filename, &fileinfo)==0) { + fprintf(cgiOut, "\n", wp.virt_filename); + fprintf(cgiOut, "
  • %s", wp.virt_filename); if(S_ISDIR(fileinfo.st_mode)) - fprintf(cgiOut, "/ [directory %s]\n", buprintf(du(phys_filename), FALSE)); + fprintf(cgiOut, "/ [directory %s]\n", buprintf(du(wp.phys_filename), FALSE)); else fprintf(cgiOut, " [file %s]\n", buprintf(fileinfo.st_size, FALSE)); } @@ -71,11 +71,11 @@ void multiprompt_ui(char *m_action) { // move needs a destination... if(strcmp(m_action, "move")==0) { - fprintf(cgiOut, "

    Source: %s

    Destination: \n", wp.virt_dirname); fprintf(cgiOut, "\n"); if(cfg.largeset) { - level=re_dir_up(virt_dirname); - re_dir_ui(virt_dirname, level); + level=re_dir_up(wp.virt_dirname); + re_dir_ui(wp.virt_dirname, level); } else { re_dir_ui("/", 1); @@ -96,7 +96,7 @@ void multiprompt_ui(char *m_action) { " \n" "\n\n" "\n" - "\n\n", m_action, virt_dirname, rt.token); + "\n\n", m_action, wp.virt_dirname, rt.token); cgiStringArrayFree(responses); @@ -138,7 +138,7 @@ void singleprompt_ui(char *m_action) { " Enter new name:

    \n" " \n" " \n", - virt_filename, virt_filename, virt_filename); + wp.virt_filename, wp.virt_filename, wp.virt_filename); else if(strcmp(m_action, "mkfile")==0) fprintf(cgiOut, @@ -163,7 +163,7 @@ void singleprompt_ui(char *m_action) { " \n" "\n\n" "\n" - "\n\n", m_action, virt_dirname, rt.token); + "\n\n", m_action, wp.virt_dirname, rt.token); } @@ -215,7 +215,7 @@ void error(char *msg, ...) { " \n" "\n" "\n\n", - buff, cgiScriptName, virt_dirname, rt.token); + buff, cgiScriptName, wp.virt_dirname, rt.token); } else { cgiHeaderContentType("text/plain"); @@ -269,6 +269,7 @@ void about(void) { "Server: %s
    \n" "User Agent: %s
    \n" "NAME_MAX: %d
    \n" + "PATH_MAX: %d
    \n" "JavaScript Level: %d
    \n" "Change Control: %s (%s)
    \n" " 

    \n" @@ -287,14 +288,14 @@ void about(void) { " \n" "\n" "\n\n", - rt.iconsurl, cfg.tagline, VERSION, __DATE__, __TIME__, __VERSION__, cgiServerSoftware, cgiUserAgent, NAME_MAX, rt.js, + rt.iconsurl, cfg.tagline, VERSION, __DATE__, __TIME__, __VERSION__, cgiServerSoftware, cgiUserAgent, NAME_MAX, PATH_MAX, rt.js, #ifdef WFMGIT "Git" #else "None" #endif , (repo_check()) ? "No Repo Present" : "Repo OK", - cgiScriptName, virt_dirname, rt.token); + cgiScriptName, wp.virt_dirname, rt.token); } @@ -335,11 +336,11 @@ void login_ui(void) { " \n" " \n" " =2) fprintf(cgiOut, "onClick=\"self.location='%s?directory=%s&login=client&rt.token=' + hex_md5('%s:' + hex_md5(document.wfm.username.value + ':' + document.wfm.password.value)); return false;\"", - cgiScriptName, virt_dirname_urlencoded, cgiRemoteAddr); + cgiScriptName, wp.virt_dirname_urlencoded, cgiRemoteAddr); fputs( ">\n" @@ -375,7 +376,7 @@ void edit_ui(void) { bkcolor="background-color:#EEEEEE; color:#000000;"; #endif - input=fopen(phys_filename, "r"); + input=fopen(wp.phys_filename, "r"); if(input==NULL) error("Unable to open file.
    %s", strerror(errno)); @@ -442,7 +443,7 @@ void edit_ui(void) { "File Editor: %s\n" "\n" "", - cgiScriptName, (strncmp(cgiUserAgent, "Mozilla/4.0 (compatible; MSIE 6", 31)==0) ? "80" : "100", rt.iconsurl, virt_filename); + cgiScriptName, (strncmp(cgiUserAgent, "Mozilla/4.0 (compatible; MSIE 6", 31)==0) ? "80" : "100", rt.iconsurl, wp.virt_filename); #ifndef WFMGIT if(rt.js) fprintf(cgiOut, " \n", bkcolor); @@ -478,7 +479,7 @@ void edit_ui(void) { "\n" "\n" "\n", - virt_filename, virt_dirname, rt.token, backup); + wp.virt_filename, wp.virt_dirname, rt.token, backup); free(buff); diff --git a/dir.c b/dir.c index 323fb66..039630a 100644 --- a/dir.c +++ b/dir.c @@ -58,7 +58,7 @@ void dir_icoinita(void) { void dirlist(void) { ASDIR *direntry; off_t size, totalsize=0; - char highlight[VIRT_FILENAME_SIZE]={0}; + char highlight[sizeof(wp.virt_filename)]={0}; char namepfx[1024], sizepfx[1024], datepfx[1024]; char rtime[64], mtime[64], atime[64]; char *stime; @@ -74,7 +74,7 @@ void dirlist(void) { if(upload_id<1) upload_id=now; // holy shit - cgiFormStringNoNewlines("highlight", highlight, VIRT_FILENAME_SIZE-1); //TODO: urlencode ? + cgiFormStringNoNewlines("highlight", highlight, sizeof(wp.virt_filename)-1); //TODO: urlencode ? cgiFormStringNoNewlines("sortby", sortby, 63); if(strlen(sortby)<4) snprintf(sortby, 63, "name"); @@ -82,13 +82,13 @@ void dirlist(void) { // // Get and Print Directory Entries // - if(strcmp(sortby, "name")==0) nentr=asscandir(phys_dirname, &direntry, namesort); - else if(strcmp(sortby, "rname")==0) nentr=asscandir(phys_dirname, &direntry, rnamesort); - else if(strcmp(sortby, "size")==0) nentr=asscandir(phys_dirname, &direntry, sizesort); - else if(strcmp(sortby, "rsize")==0) nentr=asscandir(phys_dirname, &direntry, rsizesort); - else if(strcmp(sortby, "date")==0) nentr=asscandir(phys_dirname, &direntry, timesort); - else if(strcmp(sortby, "rdate")==0) nentr=asscandir(phys_dirname, &direntry, rtimesort); - else nentr=asscandir(phys_dirname, &direntry, namesort); + if(strcmp(sortby, "name")==0) nentr=asscandir(wp.phys_dirname, &direntry, namesort); + else if(strcmp(sortby, "rname")==0) nentr=asscandir(wp.phys_dirname, &direntry, rnamesort); + else if(strcmp(sortby, "size")==0) nentr=asscandir(wp.phys_dirname, &direntry, sizesort); + else if(strcmp(sortby, "rsize")==0) nentr=asscandir(wp.phys_dirname, &direntry, rsizesort); + else if(strcmp(sortby, "date")==0) nentr=asscandir(wp.phys_dirname, &direntry, timesort); + else if(strcmp(sortby, "rdate")==0) nentr=asscandir(wp.phys_dirname, &direntry, rtimesort); + else nentr=asscandir(wp.phys_dirname, &direntry, namesort); dir_icoinita(); @@ -103,7 +103,7 @@ void dirlist(void) { "\n" "\n" "%s : %c%s\n", - COPYRIGHT, cfg.tagline, (strlen(virt_dirname)>0) ? ' ' : '/', virt_dirname); + COPYRIGHT, cfg.tagline, (strlen(wp.virt_dirname)>0) ? ' ' : '/', wp.virt_dirname); if(rt.js) fprintf(cgiOut, "