1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
5 * Copyright (C) 2001-2010, Eduardo Silva P. <edsiper@gmail.com>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include <netinet/in.h>
38 /* Carga en estructura los mimetypes */
39 void mk_mimetype_read_config()
44 snprintf(path
, MAX_PATH
, "%s/monkey.mime", config
->serverconf
);
45 c
= mk_config_create(path
);
48 if (mk_mimetype_add(c
->key
, c
->val
, NULL
) != 0) {
49 puts("Error loading Mime Types");
56 /* Set default mime type */
57 mimetype_default
= mk_mem_malloc_z(sizeof(struct mimetype
));
58 mimetype_default
->name
= MIMETYPE_DEFAULT_NAME
;
59 mk_pointer_set(&mimetype_default
->type
, MIMETYPE_DEFAULT_TYPE
);
60 mimetype_default
->script_bin_path
= NULL
;
61 mimetype_default
->next
= NULL
;
64 int mk_mimetype_add(char *name
, char *type
, char *bin_path
)
67 struct mimetype
*new_mime
, *aux_mime
;
69 new_mime
= mk_mem_malloc_z(sizeof(struct mimetype
));
71 new_mime
->name
= name
;
74 len
= strlen(type
) + 3;
75 new_mime
->type
.data
= mk_mem_malloc(len
);
76 new_mime
->type
.len
= len
- 1;
78 /* Copy mime type and add CRLF */
79 strcpy(new_mime
->type
.data
, type
);
80 strcat(new_mime
->type
.data
, MK_CRLF
);
81 new_mime
->type
.data
[len
-1] = '\0';
82 new_mime
->next
= NULL
;
84 /* Free incoming type, 'name' is not freed as it's used in
85 * the main mimetype list
89 if (first_mime
== NULL
) {
90 first_mime
= new_mime
;
93 aux_mime
= first_mime
;
94 while (aux_mime
->next
!= NULL
) {
95 aux_mime
= aux_mime
->next
;
97 aux_mime
->next
= new_mime
;
102 struct mimetype
*mk_mimetype_find(mk_pointer
* filename
)
106 j
= len
= filename
->len
;
108 /* looking for extension */
109 while (filename
->data
[j
] != '.' && j
>= 0)
116 return mk_mimetype_cmp(filename
->data
+ j
+ 1);
119 /* Busca mime type segun Request */
120 struct mimetype
*mk_mimetype_cmp(char *name
)
122 struct mimetype
*aux_mime
;
124 aux_mime
= first_mime
;
125 while (aux_mime
!= NULL
) {
126 if (strcasecmp(aux_mime
->name
, name
) == 0) {
130 aux_mime
= aux_mime
->next
;
136 int mk_mimetype_free(char **arr
)