Google
Web alhem.net
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Mime.cpp

Go to the documentation of this file.
00001 00005 /* 00006 Copyright (C) 2004 Anders Hedstrom 00007 00008 This program is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU General Public License 00010 as published by the Free Software Foundation; either version 2 00011 of the License, or (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 //#include <stdio.h> 00023 00024 #include <libcgi++.h> 00025 #include "Mime.h" 00026 00027 00028 00029 00030 Mime::Mime(const std::string& filename) 00031 { 00032 FILE *fil; 00033 if ((fil = fopen(filename.c_str(),"rt")) != NULL) 00034 { 00035 char slask[1000]; 00036 fgets(slask,1000,fil); 00037 while (!feof(fil)) 00038 { 00039 while (strlen(slask) && (slask[strlen(slask) - 1] == 13 || slask[strlen(slask) - 1] == 10)) 00040 { 00041 slask[strlen(slask) - 1] = 0; 00042 } 00043 cgi::Parse pa(slask); 00044 pa.getword(slask); 00045 std::string mime_type = slask; //pa.getword(); 00046 pa.getword(slask); 00047 std::string ext = slask; //pa.getword(); 00048 while (ext.size()) 00049 { 00050 m_mime[ext] = mime_type; 00051 pa.getword(slask); 00052 ext = slask; //pa.getword(); 00053 } 00054 // 00055 fgets(slask,1000,fil); 00056 } 00057 fclose(fil); 00058 } 00059 else 00060 { 00061 // fprintf(stderr,"Couldn't open file '%s'...\n",filename.c_str()); 00062 } 00063 } 00064 00065 00066 Mime::~Mime() 00067 { 00068 } 00069 00070 00071 std::string Mime::GetMimeFromExtension(const std::string& ext) 00072 { 00073 std::string mime = m_mime[ext]; 00074 return mime; 00075 } 00076 00077 00078 std::string Mime::GetMimeFromFile(const std::string& name) 00079 { 00080 size_t x = 0; 00081 for (size_t i = 0; i < name.size(); i++) 00082 if (name[i] == '.') 00083 x = i; 00084 std::string ext = name.substr(x + 1); 00085 00086 return GetMimeFromExtension(ext); 00087 } 00088 00089

Generated on Thu Feb 10 22:42:34 2005 for Distributed URL Classification Tool by doxygen 1.3.7