-
/*
* DEBUG: section 25 MIME Parsing and Internal Icons
* AUTHOR: Harvest Derived
{
public:
- MimeIcon ();
- ~MimeIcon ();
- void setName (char const *);
- char const * getName () const;
+ MimeIcon(const char *aName);
+ ~MimeIcon();
+ void setName(char const *);
+ char const * getName() const;
void load();
- void created (StoreEntry *newEntry);
+ void created(StoreEntry *newEntry);
private:
+ MimeIcon();
const char *icon;
char *url;
};
-class mimeEntry
+class MimeEntry
{
public:
- mimeEntry() : pattern(NULL), content_type(NULL),
- content_encoding(NULL), transfer_mode('I'), view_option(false),
- download_option(false), next(NULL), theIcon() {}
-
- mimeEntry(const char *aPattern, const regex_t &compiledPattern,
+ MimeEntry(const char *aPattern, const regex_t &compiledPattern,
const char *aContentType,
const char *aContentEncoding, const char *aTransferMode,
bool optionViewEnable, bool optionDownloadEnable,
content_encoding(xstrdup(aContentEncoding)),
view_option(optionViewEnable),
download_option(optionViewEnable),
- next(NULL)
+ next(NULL), theIcon(anIconName)
{
if (!strcasecmp(aTransferMode, "ascii"))
transfer_mode = 'A';
transfer_mode = 'A';
else
transfer_mode = 'I';
-
- theIcon.setName(anIconName);
}
-
-
-
- //void *operator new (size_t byteCount);
- //void operator delete (void *address);
+ ~MimeEntry();
const char *pattern;
regex_t compiled_pattern;
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);
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 ()
{
char const *
mimeGetIcon(const char *fn)
{
- mimeEntry *m = mimeGetEntry(fn, 1);
+ MimeEntry *m = mimeGetEntry(fn, 1);
if (m == NULL)
return NULL;
const char *
mimeGetContentType(const char *fn)
{
- mimeEntry *m = mimeGetEntry(fn, 1);
+ MimeEntry *m = mimeGetEntry(fn, 1);
if (m == NULL)
return NULL;
const char *
mimeGetContentEncoding(const char *fn)
{
- mimeEntry *m = mimeGetEntry(fn, 0);
+ MimeEntry *m = mimeGetEntry(fn, 0);
if (m == NULL)
return NULL;
char
mimeGetTransferMode(const char *fn)
{
- mimeEntry *m = mimeGetEntry(fn, 0);
+ MimeEntry *m = mimeGetEntry(fn, 0);
return m ? m->transfer_mode : 'I';
}
bool
mimeGetDownloadOption(const char *fn)
{
- mimeEntry *m = mimeGetEntry(fn, 1);
+ MimeEntry *m = mimeGetEntry(fn, 1);
return m ? m->download_option : 0;
}
bool
mimeGetViewOption(const char *fn)
{
- mimeEntry *m = mimeGetEntry(fn, 0);
+ MimeEntry *m = mimeGetEntry(fn, 0);
return m != 0 ? m->view_option : false;
}
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)
continue;
}
- m = new mimeEntry(pattern,re,type,encoding,mode,view_option,
+ m = new MimeEntry(pattern,re,type,encoding,mode,view_option,
download_option,icon);
*MimeTableTail = m;
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->content_encoding);
- regfree(&m->compiled_pattern);
delete m;
}
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);
+}