1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
5 * Copyright (C) 2001-2008, Eduardo Silva P.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include <netinet/in.h>
37 /* Carga en estructura los mimetypes */
38 void mk_mimetype_read_config()
40 char buffer
[255], path
[MAX_PATH
];
41 char *name
=0,*type
=0, *last
=0;
44 snprintf(path
,MAX_PATH
,"%s/monkey.mime", config
->serverconf
);
46 if((mime_file
=fopen(path
,"r"))==NULL
) {
47 puts("Error: I can't open monkey.mime file");
51 /* Rutina que carga en memoria los mime types */
52 while( fgets(buffer
,255,mime_file
) ) {
55 if(buffer
[len
-1] == '\n') {
57 if(len
&& buffer
[len
-1] == '\r')
61 name
= strtok_r(buffer
, "\"\t ", &last
);
62 type
= strtok_r(NULL
, "\"\t ", &last
);
64 if (!name
|| !type
) continue;
65 if (buffer
[0] == '#') continue;
67 if(mk_mimetype_add(name
,type
,NULL
)!=0)
68 puts("Error loading Mime Types");
72 /* Set default mime type */
73 mimetype_default
= mk_mem_malloc_z(sizeof(struct mimetype
));
74 mimetype_default
->name
= MIMETYPE_DEFAULT_NAME
;
75 mk_pointer_set(&mimetype_default
->type
, MIMETYPE_DEFAULT_TYPE
);
76 mimetype_default
->script_bin_path
= NULL
;
77 mimetype_default
->next
= NULL
;
80 int mk_mimetype_add(char *name
, char *type
, char *bin_path
)
83 struct mimetype
*new_mime
, *aux_mime
;
85 new_mime
= mk_mem_malloc_z(sizeof(struct mimetype
));
87 new_mime
->name
= mk_string_dup(name
);
88 mk_pointer_set(&new_mime
->type
, mk_string_dup(type
));
89 new_mime
->script_bin_path
= mk_string_dup(bin_path
);
97 while(aux_mime
->next
!=NULL
)
98 aux_mime
=aux_mime
->next
;
99 aux_mime
->next
= new_mime
;
104 struct mimetype
*mk_mimetype_find(mk_pointer
*filename
)
108 j
= len
= filename
->len
;
110 /* looking for extension */
111 while(filename
->data
[j
]!='.' && j
>=0)
118 return mk_mimetype_cmp(filename
->data
+j
+1);
121 /* Busca mime type segun Request */
122 struct mimetype
*mk_mimetype_cmp(char *name
)
124 struct mimetype
*aux_mime
;
127 while(aux_mime
!=NULL
) {
128 if(strcasecmp(aux_mime
->name
,name
)==0) {
132 aux_mime
=aux_mime
->next
;
138 int mk_mimetype_free(char **arr
)