Package: bozohttpd
Version: 20050410-4
Severity: normal
Tags: patch

The directory index (-X) layout does not "line up" items. The time and
date format would better be ISO 8601 for international use. Patch
that implements both is attached.

Changes:

    1. Print "Parent directory" always first. It was printed in random
       order in the listing
    2. Line up items
    3. Use ISO time and data notation.

ChangeLog entry:

2006-06-06  Jari Aalto  <jari aalto A T cante net>

        * dir-index-bozo.c (directory_index): Moved functionality
        to directory_print().
        (directory_print): New function. Make index listing to "line up"
        nicely.
        (dir_separator): New function.

BEFORE patch (Debian 20050410-4 version)

    _________________________________________________________________


    pkg-lintian.log                               02-Mar-2006 22:44
                                    0kB
    bbweather/                               02-Mar-2006 19:22
                               4kB
    stegsnow/                               02-Mar-2006 11:30
                              4kB
    procmail-lib/                               14-Jan-2006 17:27
                                  4kB
    TODO.txt                               02-Mar-2006 10:26
                             0kB
    edb/                               04-Apr-2006 12:38
                         4kB
    mfm/                               02-Mar-2006 20:36
                         4kB
    jwm/                               21-Apr-2006 17:18
                         4kB
    find++/                               02-Mar-2006 21:48
                            4kB
    gt5/                               02-Mar-2006 11:07
                         4kB
    wmitime/                               02-Mar-2006 11:31
                             4kB
    fspanel/                               02-Mar-2006 11:27
                             4kB
    wmfrog/                               02-Mar-2006 11:29
                            4kB
    swm/                               09-Mar-2006 18:00
                         4kB
    ace-of-penguins/                               28-Mar-2006 09:28
    ...


AFTER patch:

    Name                             Last modified        Size
    _________________________________________________________________

    Parent Directory
    bbweather/                       2006-03-02 19:22      4kB
    stegsnow/                        2006-03-02 11:30      4kB
    procmail-lib/                    2006-01-14 17:27      4kB
    TODO.txt                         2006-03-02 10:26      0kB
    edb/                             2006-04-04 12:38      4kB
    mfm/                             2006-03-02 20:36      4kB
    jwm/                             2006-04-21 17:18      4kB
    find++/                          2006-03-02 21:48      4kB
    gt5/                             2006-03-02 11:07      4kB
    wmitime/                         2006-03-02 11:31      4kB
    fspanel/                         2006-03-02 11:27      4kB
    wmfrog/                          2006-03-02 11:29      4kB
    swm/                             2006-03-09 18:00      4kB
    ace-of-penguins/                 2006-03-28 09:28      4kB
    xsnap/                           2006-04-04 13:35      4kB
    miwm/                            2006-04-25 10:50      4kB
    ultimate-othello/                2006-03-02 22:28      4kB
    xarchiver/                       2006-02-14 18:08      4kB
    pkg-pbuilder.log                 2006-03-02 22:44     23kB
    pkg-svn-build.log                2006-03-02 22:44     13kB
    bugs/                            2006-02-25 08:14      4kB
    ghostmail/                       2006-03-02 11:18      4kB
    wmshutdown/                      2006-03-02 11:11      4kB
    _________________________________________________________________

=== modified file 'dir-index-bozo.c'
--- dir-index-bozo.c    
+++ dir-index-bozo.c    
@@ -44,7 +44,67 @@
 #include "bozohttpd.h"
 
        int     Xflag;          /* do directory indexing */
-       int     Hflag;          /* hide .* */
+       int     Hflag;          /* hide .* (dot-files)   */
+
+
+int
+directory_print(const char *dirname, const char *name, struct stat sb)
+{
+    struct tm *tm;
+    char buf[MAXPATHLEN];
+    int nostat = 0;
+    int extra  = 0;
+    
+    snprintf(buf, sizeof buf, "%s/%s", dirname, name);
+
+    if (stat(buf, &sb))
+       nostat = 1;
+
+    if (strcmp(name, "..") == 0) {
+       return 0;
+    } else if (S_ISDIR(sb.st_mode)) {
+       bozoprintf("<a href=\"%s/\">", name);
+       bozoprintf("%s/", name);
+       extra = 1;
+    } else {
+       bozoprintf("<a href=\"%s\">", name);
+       bozoprintf("%s", name);
+    }
+    bozoprintf("</a>");
+    
+    /* 31 spaces minus size of name */
+    const char whitespace[] = "                                 ";
+    char string[40] = "";
+    size_t len = strlen(whitespace) - strlen(name) - extra;
+    
+    if ( len > 0 ) {
+       strncpy(string, whitespace, len);
+       string[len] = '\0';
+    }
+    
+    bozoprintf(string);
+
+    if (nostat) {
+       bozoprintf("?                         ?");
+    } else {
+       tm = gmtime(&sb.st_mtime);
+
+       // ISO ISO 8601 time
+       strftime(buf, sizeof buf, "%Y-%m-%d %R", tm);
+       bozoprintf("%s", buf);
+       
+       bozoprintf("%7ukB",
+                  ((unsigned int)(sb.st_size >> 10)));
+    }
+    
+    return 0;
+}
+
+void
+dir_separator(void)
+{
+    bozoprintf("<hr noshade align=\"left\" width=\"80%%\">\r\n");
+}
 
 /*
  * output a directory index.  return 1 if it actually did something..
@@ -54,7 +114,6 @@
 {
        struct stat sb;
        struct dirent *de;
-       struct tm *tm;
        DIR *dp;
        char buf[MAXPATHLEN];
        int l;
@@ -101,58 +160,43 @@
        bozoprintf("<body><h1>Index of %s</h1>\r\n", request->hr_url);
        bozoprintf("<pre>\r\n");
        bozoprintf("Name                             "
-           "Last modified          "
+           "Last modified        "
            "Size\n");
-       bozoprintf("<hr noshade align=\"left\" width=\"80%%\">\r\n\r\n");
+
+       dir_separator();
+
+       int parent = 0;
 
        while ((de = readdir(dp)) != NULL) {
                int nostat = 0;
                char *name = de->d_name;
 
-               if (strcmp(name, ".") == 0 || 
-                   (strcmp(name, "..") != 0 && Hflag && name[0] == '.'))
-                       continue;
-
-               snprintf(buf, sizeof buf, "%s/%s", dirname, name);
-               if (stat(buf, &sb))
-                       nostat = 1;
-
-               l = 0;
-
-               if (strcmp(name, "..") == 0) {
-                       bozoprintf("<a href=\"../\">");
-                       l += bozoprintf("Parent Directory");
-               } else if (S_ISDIR(sb.st_mode)) {
-                       bozoprintf("<a href=\"%s/\">", name);
-                       l += bozoprintf("%s/", name);
+               if (strcmp(name, ".") == 0 || (strcmp(name, "..") == 0 ))
+                   continue;
+
+               /*  Do not print "hidden" files if options is set */
+               if ( Hflag && name[0] == '.')
+                   continue;
+
+               /*  Print parent directory always first in the listing. */
+               if ( ! parent ) {
+                   bozoprintf("<a href=\"../\">");
+                   bozoprintf("Parent Directory");
+                   parent = 1;
                } else {
-                       bozoprintf("<a href=\"%s\">", name);
-                       l += bozoprintf("%s", name);
+                   directory_print(dirname, name, sb);
                }
-               bozoprintf("</a>");
-
-               /* 31 spaces */
-               bozoprintf("                               ");
-
-               if (nostat)
-                       bozoprintf("?                         ?");
-               else {
-                       tm = gmtime(&sb.st_mtime);
-                       strftime(buf, sizeof buf, "%d-%b-%Y %R", tm);
-                       l += bozoprintf("%s", buf);
-
-                       /* 45 spaces */
-                       bozoprintf(
-                           "                                             ");
-
-                       bozoprintf("%7ukB",
-                           ((unsigned int)(sb.st_size >> 10)));
-               }
+
                bozoprintf("\r\n");
        }
 
-       closedir(dp);
-       bozoprintf("</pre><hr></body></html>\r\n");
+       if ( dp != NULL )
+           closedir(dp);
+
+       dir_separator();
+       bozoprintf("</pre>\r\n");
+       bozoprintf("</body></html>\r\n");
+
        bozoflush(stdout);
        
        return 1;



-- System Information:
Debian Release: testing/unstable
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'stable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/dash
Kernel: Linux 2.6.16-2-686
Locale: LANG=C, LC_CTYPE=C (charmap=ISO-8859-1) (ignored: LC_ALL set to en_US)

Versions of packages bozohttpd depends on:
ii  libc6                         2.3.6-13   GNU C Library: Shared libraries
ii  libssl0.9.8                   0.9.8b-2   SSL shared libraries
ii  netbase                       4.25       Basic TCP/IP networking system

bozohttpd recommends no packages.

-- debconf-show failed


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to