=== modified file 'src/mime.cc'
--- src/mime.cc	2013-01-28 16:56:05 +0000
+++ src/mime.cc	2013-02-04 07:26:53 +0000
@@ -1,4 +1,3 @@
-
 /*
  * DEBUG: section 25    MIME Parsing and Internal Icons
  * AUTHOR: Harvest Derived
@@ -42,7 +41,6 @@
 #include "Mem.h"
 #include "MemBuf.h"
 #include "mime.h"
-#include "MemObject.h"
 #include "RequestFlags.h"
 #include "SquidConfig.h"
 #include "Store.h"
@@ -62,59 +60,53 @@
 {
 
 public:
-    MimeIcon ();
-    ~MimeIcon ();
-    void setName (char const *);
-    char const * getName () const;
-    void _free();
+    MimeIcon(const char *aName);
+    ~MimeIcon();
+    void setName(char const *);
+    char const * getName() const;
     void load();
-    void created (StoreEntry *newEntry);
+    void created(StoreEntry *newEntry);
 
 private:
-    char *icon;
+    MimeIcon();
+    const char *icon;
     char *url;
 };
 
-class mimeEntry
+class MimeEntry
 {
-
 public:
-    void *operator new (size_t byteCount);
-    void operator delete (void *address);
+    MimeEntry(const char *aPattern, const regex_t &compiledPattern,
+              const char *aContentType,
+              const char *aContentEncoding, const char *aTransferMode,
+              bool optionViewEnable, bool optionDownloadEnable,
+              const char *anIconName);
+    ~MimeEntry();
 
-    char *pattern;
+    const char *pattern;
     regex_t compiled_pattern;
-    char *icon;
-    char *content_type;
-    char *content_encoding;
+    const char *content_type;
+    const char *content_encoding;
     char transfer_mode;
 
-    unsigned int view_option:1;
-    unsigned int download_option:1;
+    bool view_option;
+    bool download_option;
 
-    mimeEntry *next;
+    MimeEntry *next;
     MimeIcon theIcon;
+private:
+    MimeEntry();
+
+
 };
 
-static mimeEntry *MimeTable = NULL;
-static mimeEntry **MimeTableTail = &MimeTable;
-
-void *
-mimeEntry::operator new (size_t byteCount)
-{
-    return xcalloc(1, byteCount);
-}
-
-void
-mimeEntry::operator delete (void *address)
-{
-    safe_free (address);
-}
-
-static mimeEntry *
+static MimeEntry *MimeTable = NULL;
+static MimeEntry **MimeTableTail = &MimeTable;
+
+static MimeEntry *
 mimeGetEntry(const char *fn, int skip_encodings)
 {
-    mimeEntry *m;
+    MimeEntry *m;
     char *t;
     char *name = xstrdup(fn);
 
@@ -149,16 +141,20 @@
     return m;
 }
 
-MimeIcon::MimeIcon () : icon (NULL), url (NULL)
-{}
+MimeIcon::MimeIcon(const char *aName) :
+                icon(xstrdup(aName))
+{
+    url = xstrdup(internalLocalUri("/squid-internal-static/icons/", icon));
+}
 
-MimeIcon::~MimeIcon ()
+MimeIcon::~MimeIcon()
 {
-    _free();
+    safe_free (icon);
+    safe_free (url);
 }
 
 void
-MimeIcon::setName (char const *aString)
+MimeIcon::setName(char const *aString)
 {
     safe_free (icon);
     safe_free (url);
@@ -167,22 +163,15 @@
 }
 
 char const *
-MimeIcon::getName () const
+MimeIcon::getName() const
 {
     return icon;
 }
 
-void
-MimeIcon::_free()
-{
-    safe_free (icon);
-    safe_free (url);
-}
-
 char const *
 mimeGetIcon(const char *fn)
 {
-    mimeEntry *m = mimeGetEntry(fn, 1);
+    MimeEntry *m = mimeGetEntry(fn, 1);
 
     if (m == NULL)
         return NULL;
@@ -211,10 +200,10 @@
     }
 }
 
-char *
+const char *
 mimeGetContentType(const char *fn)
 {
-    mimeEntry *m = mimeGetEntry(fn, 1);
+    MimeEntry *m = mimeGetEntry(fn, 1);
 
     if (m == NULL)
         return NULL;
@@ -225,10 +214,10 @@
     return m->content_type;
 }
 
-char *
+const char *
 mimeGetContentEncoding(const char *fn)
 {
-    mimeEntry *m = mimeGetEntry(fn, 0);
+    MimeEntry *m = mimeGetEntry(fn, 0);
 
     if (m == NULL)
         return NULL;
@@ -242,22 +231,22 @@
 char
 mimeGetTransferMode(const char *fn)
 {
-    mimeEntry *m = mimeGetEntry(fn, 0);
+    MimeEntry *m = mimeGetEntry(fn, 0);
     return m ? m->transfer_mode : 'I';
 }
 
-int
+bool
 mimeGetDownloadOption(const char *fn)
 {
-    mimeEntry *m = mimeGetEntry(fn, 1);
+    MimeEntry *m = mimeGetEntry(fn, 1);
     return m ? m->download_option : 0;
 }
 
-int
+bool
 mimeGetViewOption(const char *fn)
 {
-    mimeEntry *m = mimeGetEntry(fn, 0);
-    return m ? m->view_option : 0;
+    MimeEntry *m = mimeGetEntry(fn, 0);
+    return m != 0 ? m->view_option : false;
 }
 
 /* Initializes/reloads the mime table
@@ -281,7 +270,7 @@
     int view_option;
     int download_option;
     regex_t re;
-    mimeEntry *m;
+    MimeEntry *m;
     int re_flags = REG_EXTENDED | REG_NOSUB | REG_ICASE;
 
     if (filename == NULL)
@@ -355,23 +344,8 @@
             continue;
         }
 
-        m = new mimeEntry;
-        m->pattern = xstrdup(pattern);
-        m->content_type = xstrdup(type);
-        m->theIcon.setName(icon);
-        m->content_encoding = xstrdup(encoding);
-        m->compiled_pattern = re;
-
-        if (!strcasecmp(mode, "ascii"))
-            m->transfer_mode = 'A';
-        else if (!strcasecmp(mode, "text"))
-            m->transfer_mode = 'A';
-        else
-            m->transfer_mode = 'I';
-
-        m->view_option = view_option;
-
-        m->download_option = download_option;
+        m = new MimeEntry(pattern,re,type,encoding,mode,view_option,
+            download_option,icon);
 
         *MimeTableTail = m;
 
@@ -381,28 +355,19 @@
     }
 
     fclose(fp);
-    /*
-     * Create Icon StoreEntry's
-     */
 
     for (m = MimeTable; m != NULL; m = m->next)
         m->theIcon.load();
-
-    debugs(25, DBG_IMPORTANT, "Loaded Icons.");
+    debugs(25, DBG_IMPORTANT, "Finished loading MIME types and icons.");
 }
 
 void
 mimeFreeMemory(void)
 {
-    mimeEntry *m;
+    MimeEntry *m;
 
     while ((m = MimeTable)) {
         MimeTable = m->next;
-        safe_free(m->pattern);
-        safe_free(m->content_type);
-        safe_free(m->icon);
-        safe_free(m->content_encoding);
-        regfree(&m->compiled_pattern);
         delete m;
     }
 
@@ -423,34 +388,28 @@
 void
 MimeIcon::created (StoreEntry *newEntry)
 {
-    /* is already in the store, do nothing */
-
+    /* if the icon is already in the store, do nothing */
     if (!newEntry->isNull())
         return;
 
     int fd;
-
     int n;
-
     RequestFlags flags;
-
     struct stat sb;
-
     LOCAL_ARRAY(char, path, MAXPATHLEN);
-
     char *buf;
 
     snprintf(path, MAXPATHLEN, "%s/%s", Config.icons.directory, icon);
 
     fd = file_open(path, O_RDONLY | O_BINARY);
-
     if (fd < 0) {
-        debugs(25, DBG_CRITICAL, "mimeLoadIconFile: " << path << ": " << xstrerror());
+        debugs(25, DBG_CRITICAL, "mimeLoadIconFile: " << path << ": "
+                        << xstrerror());
         return;
     }
-
     if (fstat(fd, &sb) < 0) {
-        debugs(25, DBG_CRITICAL, "mimeLoadIconFile: FD " << fd << ": fstat: " << xstrerror());
+        debugs(25, DBG_CRITICAL, "mimeLoadIconFile: FD " << fd << ": fstat: "
+                        << xstrerror());
         file_close(fd);
         return;
     }
@@ -470,33 +429,50 @@
 
     HttpReply *reply = new HttpReply;
 
-    reply->setHeaders(HTTP_OK, NULL, mimeGetContentType(icon), sb.st_size, sb.st_mtime, -1);
-
+    reply->setHeaders(HTTP_OK, NULL, mimeGetContentType(icon), sb.st_size,
+                    sb.st_mtime, -1);
     reply->cache_control = new HttpHdrCc();
-
     reply->cache_control->maxAge(86400);
-
     reply->header.putCc(reply->cache_control);
-
     e->replaceHttpReply(reply);
 
     /* read the file into the buffer and append it to store */
     buf = (char *)memAllocate(MEM_4K_BUF);
-
     while ((n = FD_READ_METHOD(fd, buf, 4096)) > 0)
         e->append(buf, n);
 
     file_close(fd);
-
     e->flush();
-
     e->complete();
-
     e->timestampsSet();
-
-    debugs(25, 3, "Loaded icon " << url);
-
     e->unlock();
-
     memFree(buf, MEM_4K_BUF);
+    debugs(25, 3, "Loaded icon " << url);
+}
+
+MimeEntry::~MimeEntry() {
+    safe_free(pattern);
+    safe_free(content_type);
+    safe_free(content_encoding);
+    regfree(&compiled_pattern);
+}
+
+MimeEntry::MimeEntry(const char *aPattern, const regex_t &compiledPattern,
+                const char *aContentType, const char *aContentEncoding,
+                const char *aTransferMode, bool optionViewEnable,
+                bool optionDownloadEnable, const char *anIconName) :
+                                    pattern(xstrdup(aPattern)),
+                                    compiled_pattern(compiledPattern),
+                                    content_type(xstrdup(aContentType)),
+                                    content_encoding(xstrdup(aContentEncoding)),
+                                    view_option(optionViewEnable),
+                                    download_option(optionViewEnable),
+                                    next(NULL), theIcon(anIconName)
+{
+    if (!strcasecmp(aTransferMode, "ascii"))
+        transfer_mode = 'A';
+    else if (!strcasecmp(aTransferMode, "text"))
+        transfer_mode = 'A';
+    else
+        transfer_mode = 'I';
 }

=== modified file 'src/mime.h'
--- src/mime.h	2012-09-22 10:56:48 +0000
+++ src/mime.h	2013-02-01 17:05:58 +0000
@@ -34,11 +34,11 @@
 #define SQUID_MIME_H_
 
 void mimeInit(char *filename);
-char *mimeGetContentEncoding(const char *fn);
-char *mimeGetContentType(const char *fn);
+const char *mimeGetContentEncoding(const char *fn);
+const char *mimeGetContentType(const char *fn);
 const char *mimeGetIconURL(const char *fn);
 char mimeGetTransferMode(const char *fn);
-int mimeGetDownloadOption(const char *fn);
-int mimeGetViewOption(const char *fn);
+bool mimeGetDownloadOption(const char *fn);
+bool mimeGetViewOption(const char *fn);
 
 #endif /* SQUID_MIME_H_ */

