Commit d0d79894 authored by rswindell's avatar rswindell
Browse files

Converted from ctrl/mime_types.cfg to ctrl/mime_types.ini

Greatly simplified the parsing, allocation, and freeing of MIME types.
parent 6d19fda6
; This is a comment. I love comments.
; This file controls what Internet media types are sent to the client for
; given file extension(s). Sending the correct media type to the client
; is important so they know how to handle the content of the file.
; Extra types can either be added here
; The Internet media type
; registry is at <ftp://ftp.iana.org/in-notes/iana/assignments/media-types/>.
; Extension MIME-type
htm text/html
html text/html
hqx application/mac-binhex40
cpt application/mac-compactpro
doc application/msword
lha application/octet-stream
lzh application/octet-stream
exe application/octet-stream
class application/octet-stream
pdf application/pdf
ps application/postscript
eps application/postscript
xls application/vnd.ms-excel
ppt application/vnd.ms-powerpoint
csh application/x-csh
js application/x-javascript
latex application/x-latex
sh application/x-sh
shar application/x-shar
swf application/x-shockwave-flash
sit application/x-stuffit
tar application/x-tar
zip application/zip
mid audio/midi
midi audio/midi
mpga audio/mpeg
mp2 audio/mpeg
mp3 audio/mpeg
aif audio/x-aiff
aiff audio/x-aiff
aifc audio/x-aiff
m3u audio/x-mpegurl
rm audio/x-pn-realaudio
ram audio/x-pn-realaudio
rpm audio/x-pn-realaudio-plugin
ra audio/x-realaudio
wav audio/x-wav
bmp image/bmp
gif image/gif
ief image/ief
jpeg image/jpeg
jpg image/jpeg
jpe image/jpeg
png image/png
tif image/tiff
tiff image/tiff
wbmp image/vnd.wap.wbmp
ras image/x-cmu-raster
pnm image/x-portable-anymap
pbm image/x-portable-bitmap
pgm image/x-portable-graymap
ppm image/x-portable-pixmap
rgb image/x-rgb
xbm image/x-xbitmap
xpm image/x-xpixmap
xwd image/x-xwindowdump
wrl model/vrml
vrml model/vrml
css text/css
asc text/plain
txt text/plain
rtx text/richtext
rtf text/rtf
sgml text/sgml
sgm text/sgml
tsv text/tab-separated-values
wml text/vnd.wap.wml
wmls text/vnd.wap.wmlscript
xml text/xml
xsl text/xml
mpg video/mpeg
mpe video/mpeg
mpeg video/mpeg
qt video/quicktime
mov video/quicktime
mxu video/vnd.mpegurl
avi video/x-msvideo
movie video/x-sgi-movie
ice x-conference/x-cooltalk
; mime_types.ini
; $Id$
; This is a comment. I love comments.
; This file controls what Internet media types are sent to the client for
; given file extension(s). Sending the correct media type to the client
; is important so they know how to handle the content of the file.
; Extra types can either be added here
; The Internet media type
; registry is at <ftp://ftp.iana.org/in-notes/iana/assignments/media-types/>.
; Extension = MIME-type
htm = text/html
html = text/html
hqx = application/mac-binhex40
cpt = application/mac-compactpro
doc = application/msword
lha = application/octet-stream
lzh = application/octet-stream
exe = application/octet-stream
class = application/octet-stream
pdf = application/pdf
ps = application/postscript
eps = application/postscript
xls = application/vnd.ms-excel
ppt = application/vnd.ms-powerpoint
csh = application/x-csh
js = application/x-javascript
latex = application/x-latex
sh = application/x-sh
shar = application/x-shar
swf = application/x-shockwave-flash
sit = application/x-stuffit
tar = application/x-tar
zip = application/zip
mid = audio/midi
midi = audio/midi
mpga = audio/mpeg
mp2 = audio/mpeg
mp3 = audio/mpeg
aif = audio/x-aiff
aiff = audio/x-aiff
aifc = audio/x-aiff
m3u = audio/x-mpegurl
rm = audio/x-pn-realaudio
ram = audio/x-pn-realaudio
rpm = audio/x-pn-realaudio-plugin
ra = audio/x-realaudio
wav = audio/x-wav
bmp = image/bmp
gif = image/gif
ief = image/ief
jpeg = image/jpeg
jpg = image/jpeg
jpe = image/jpeg
png = image/png
tif = image/tiff
tiff = image/tiff
wbmp = image/vnd.wap.wbmp
ras = image/x-cmu-raster
pnm = image/x-portable-anymap
pbm = image/x-portable-bitmap
pgm = image/x-portable-graymap
ppm = image/x-portable-pixmap
rgb = image/x-rgb
xbm = image/x-xbitmap
xpm = image/x-xpixmap
xwd = image/x-xwindowdump
wrl = model/vrml
vrml = model/vrml
css = text/css
asc = text/plain
txt = text/plain
rtx = text/richtext
rtf = text/rtf
sgml = text/sgml
sgm = text/sgml
tsv = text/tab-separated-values
wml = text/vnd.wap.wml
wmls = text/vnd.wap.wmlscript
xml = text/xml
xsl = text/xml
mpg = video/mpeg
mpe = video/mpeg
mpeg = video/mpeg
qt = video/quicktime
mov = video/quicktime
mxu = video/vnd.mpegurl
avi = video/x-msvideo
movie = video/x-sgi-movie
ice = x-conference/x-cooltalk
......@@ -2593,7 +2593,7 @@ object MainForm: TMainForm
Caption = 'Edit'
object WebEditMimeTypesMenuItem: TMenuItem
Caption = 'MIME Types'
Hint = 'mime_types.cfg'
Hint = 'mime_types.ini'
OnClick = CtrlMenuItemEditClick
end
end
......
......@@ -116,7 +116,6 @@ static const char* unknown="<unknown>";
extern const uchar* nular;
#define TIMEOUT_THREAD_WAIT 60 /* Seconds */
#define MAX_MIME_TYPES 128
#define MAX_REQUEST_LINE 1024 /* NOT including terminator */
#define MAX_HEADERS_SIZE 16384 /* Maximum total size of all headers
(Including terminator )*/
......@@ -131,7 +130,6 @@ static BOOL terminate_server=FALSE;
static BOOL terminate_http_logging_thread=FALSE;
static uint thread_count=0;
static SOCKET server_socket=INVALID_SOCKET;
static ulong mime_count=0;
static char revision[16];
static char root_dir[MAX_PATH+1];
static char error_dir[MAX_PATH+1];
......@@ -143,6 +141,8 @@ static js_server_props_t js_server_props;
static link_list_t recycle_semfiles;
static link_list_t shutdown_semfiles;
static named_string_t** mime_types;
/* Logging stuff */
sem_t log_sem;
pthread_mutex_t log_mutex;
......@@ -218,13 +218,6 @@ typedef struct {
client_t client;
} http_session_t;
typedef struct {
char ext[16];
char type[128];
} mime_types_t;
static mime_types_t mime_types[MAX_MIME_TYPES];
enum {
HTTP_0_9
,HTTP_1_0
......@@ -820,9 +813,9 @@ static const char* get_mime_type(char *ext)
if(ext==NULL)
return(unknown_mime_type);
for(i=0;i<mime_count;i++)
if(!stricmp(ext+1,mime_types[i].ext))
return(mime_types[i].type);
for(i=0;mime_types[i]!=NULL;i++)
if(!stricmp(ext+1,mime_types[i]->name))
return(mime_types[i]->value);
return(unknown_mime_type);
}
......@@ -1114,36 +1107,20 @@ static BOOL check_ars(http_session_t * session)
static BOOL read_mime_types(char* fname)
{
char str[1024];
char * ext;
char * type;
FILE* mime_config;
int mime_count;
FILE* fp;
mime_count=0;
mime_types=iniFreeNamedStringList(mime_types);
if((mime_config=fopen(fname,"r"))==NULL)
lprintf(LOG_DEBUG,"Reading %s",fname);
if((fp=iniOpenFile(fname))==NULL) {
lprintf(LOG_WARNING,"Error %d opening %s",errno,fname);
return(FALSE);
while (!feof(mime_config)&&mime_count<MAX_MIME_TYPES) {
if(fgets(str,sizeof(str),mime_config)!=NULL) {
truncsp(str);
ext=strtok(str," \t");
if(ext!=NULL) {
while(*ext && *ext<=' ') ext++;
if(*ext!=';') {
type=strtok(NULL," \t");
if(type!=NULL) {
while(*type && *type<=' ') type++;
if(strlen(ext)>0 && strlen(type)>0) {
SAFECOPY((mime_types[mime_count]).ext,ext);
SAFECOPY((mime_types[mime_count++]).type,type);
}
}
}
}
}
}
fclose(mime_config);
mime_types=iniReadNamedStringList(fp,NULL /* root section */);
iniCloseFile(fp);
COUNT_LIST_ITEMS(mime_types,mime_count);
lprintf(LOG_DEBUG,"Loaded %d mime types", mime_count);
return(mime_count>0);
}
......@@ -2687,6 +2664,8 @@ static void cleanup(int code)
listFree(&log_list);
mime_types=iniFreeNamedStringList(mime_types);
semfile_list_free(&recycle_semfiles);
semfile_list_free(&shutdown_semfiles);
......@@ -2950,9 +2929,8 @@ void DLLCALL web_server(void* arg)
}
scfg_reloaded=TRUE;
sprintf(path,"%smime_types.cfg",scfg.ctrl_dir);
iniFileName(path,sizeof(path),scfg.ctrl_dir,"mime_types.ini");
if(!read_mime_types(path)) {
lprintf(LOG_ERR,"!ERROR %d reading %s", errno,path);
cleanup(1);
return;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment