1d9574bb8SFrançois Revol /*******************************************************************************
2d9574bb8SFrançois Revol /
3d9574bb8SFrançois Revol / File: mime_table.c
4d9574bb8SFrançois Revol /
5d9574bb8SFrançois Revol / Description: Kernel module implementing kernel-space mime_table API
6d9574bb8SFrançois Revol /
7*a583b8b5SFrançois Revol / Copyright 2004, François Revol.
8d9574bb8SFrançois Revol /
9d9574bb8SFrançois Revol *******************************************************************************/
10d9574bb8SFrançois Revol
11d9574bb8SFrançois Revol #include <Drivers.h>
12d9574bb8SFrançois Revol #include <KernelExport.h>
13d9574bb8SFrançois Revol #include <string.h>
14d9574bb8SFrançois Revol #include <stdlib.h>
15d9574bb8SFrançois Revol
16d9574bb8SFrançois Revol #include <mime_table.h>
17d9574bb8SFrançois Revol extern struct ext_mime mimes[];
18d9574bb8SFrançois Revol
19d9574bb8SFrançois Revol #if DEBUG > 0
20d9574bb8SFrançois Revol #define ddprintf(x) dprintf x
21d9574bb8SFrançois Revol #else
22d9574bb8SFrançois Revol #define ddprintf(x)
23d9574bb8SFrançois Revol #endif
24d9574bb8SFrançois Revol
25d9574bb8SFrançois Revol /* Module static data */
26d9574bb8SFrançois Revol const char mime_table_module_name[] = B_MIME_TABLE_MODULE_NAME;
27d9574bb8SFrançois Revol
28d9574bb8SFrançois Revol static status_t
std_ops(int32 op,...)29d9574bb8SFrançois Revol std_ops(int32 op, ...)
30d9574bb8SFrançois Revol {
31d9574bb8SFrançois Revol switch(op) {
32d9574bb8SFrançois Revol case B_MODULE_INIT:
33d9574bb8SFrançois Revol return B_OK;
34d9574bb8SFrançois Revol case B_MODULE_UNINIT:
35d9574bb8SFrançois Revol return B_OK;
36d9574bb8SFrançois Revol default:
37d9574bb8SFrançois Revol /* do nothing */
38d9574bb8SFrançois Revol ;
39d9574bb8SFrançois Revol }
40d9574bb8SFrançois Revol return -1;
41d9574bb8SFrançois Revol }
42d9574bb8SFrançois Revol
get_table(struct ext_mime ** table)43d9574bb8SFrançois Revol status_t get_table(struct ext_mime **table)
44d9574bb8SFrançois Revol {
45d9574bb8SFrançois Revol if (!table)
46d9574bb8SFrançois Revol return EINVAL;
47d9574bb8SFrançois Revol /* no need to malloc & copy yet */
48d9574bb8SFrançois Revol *table = mimes;
49d9574bb8SFrançois Revol return B_OK;
50d9574bb8SFrançois Revol }
51d9574bb8SFrançois Revol
free_table(struct ext_mime * table)52d9574bb8SFrançois Revol void free_table(struct ext_mime *table)
53d9574bb8SFrançois Revol {
54d9574bb8SFrançois Revol /* do nothing yet */
55d9574bb8SFrançois Revol }
56d9574bb8SFrançois Revol
mime_for_ext(const char * ext)57d9574bb8SFrançois Revol const char *mime_for_ext(const char *ext)
58d9574bb8SFrançois Revol {
59d9574bb8SFrançois Revol int i;
60d9574bb8SFrançois Revol /* should probably be optimized */
61d9574bb8SFrançois Revol for (i = 0; mimes[i].extension; i++) {
62d9574bb8SFrançois Revol if (!strcmp(ext, mimes[i].extension))
63d9574bb8SFrançois Revol return mimes[i].mime;
64d9574bb8SFrançois Revol }
65d9574bb8SFrançois Revol return NULL;
66d9574bb8SFrançois Revol }
67d9574bb8SFrançois Revol
ext_for_mime(const char * mime)68d9574bb8SFrançois Revol const char *ext_for_mime(const char *mime)
69d9574bb8SFrançois Revol {
70d9574bb8SFrançois Revol int i;
71d9574bb8SFrançois Revol /* should probably be optimized */
72d9574bb8SFrançois Revol for (i = 0; mimes[i].mime; i++) {
73d9574bb8SFrançois Revol if (!strcmp(mime, mimes[i].mime))
74d9574bb8SFrançois Revol return mimes[i].extension;
75d9574bb8SFrançois Revol }
76d9574bb8SFrançois Revol return NULL;
77d9574bb8SFrançois Revol }
78d9574bb8SFrançois Revol
79d9574bb8SFrançois Revol static mime_table_module_info mime_table = {
80d9574bb8SFrançois Revol {
81d9574bb8SFrançois Revol mime_table_module_name,
82d9574bb8SFrançois Revol 0,
83d9574bb8SFrançois Revol std_ops
84d9574bb8SFrançois Revol },
85d9574bb8SFrançois Revol get_table,
86d9574bb8SFrançois Revol free_table,
87d9574bb8SFrançois Revol mime_for_ext,
88d9574bb8SFrançois Revol ext_for_mime
89d9574bb8SFrançois Revol };
90d9574bb8SFrançois Revol
91d9574bb8SFrançois Revol _EXPORT mime_table_module_info *modules[] = {
92d9574bb8SFrançois Revol &mime_table,
93d9574bb8SFrançois Revol NULL
94d9574bb8SFrançois Revol };
95d9574bb8SFrançois Revol
96