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