1 #ifndef MIMETYPE_H
 2 #define MIMETYPE_H
 3 
 4 #include "rh_buffer.h"
 5 #include "queue.h"
 6 
 7 typedef struct mimetype         mimetype_t;
 8 typedef struct mimetype_entry   mimetype_entry_t;
 9 typedef struct mimetype_base    mimetype_base_t;
10 
11 LIST_HEAD(mimetype_list, mimetype_entry);
12 
13 enum mimetype_type {
14         MIMETYPE_CONTENT,
15         MIMETYPE_ENCODING,
16         MIMETYPE_LANG,
17 
18         MIMETYPE_MAX,
19 };
20 
21 #if 0
22 enum {
23         MIMETYPE_ENCODING_GZ    = 0x01
24 };
25 #endif
26 
27 struct mimetype_entry {
28         mimetype_base_t                 *base;
29         
30         enum mimetype_type              type;
31 
32         int                             removed;
33         
34         size_t                          used;
35         
36         rh_buffer_t                     key;    /* txt        */
37         rh_buffer_t                     value;  /* text/plain */
38         
39         LIST_ENTRY(mimetype_entry)      list;
40 };
41 
42 /* this struct is stored at user side */
43 struct mimetype {
44         unsigned int            initialized;
45 
46         /* this pointers are from the backend and must be push'd
47          * back if its no more needed */
48         const mimetype_entry_t  *entries[MIMETYPE_MAX];
49 };
50 
51 /* hash against the strings: "de", "html" etc. */
52 struct mimetype_base {
53         struct mimetype_list    *buckets;
54         size_t                  nbuckets;
55         size_t                  elements;
56         size_t                  max_typelength;
57 };
58 
59 void mimetype_base_init    (mimetype_base_t *base);
60 void mimetype_base_destroy (mimetype_base_t *base);
61 
62 int mimetype_load          (mimetype_base_t *base, enum mimetype_type type,
63                             const char *filename);
64 
65 
66 #define MIMETYPE_EXISTS(_type,_mime)                            \
67         ( (_mime)->entries[MIMETYPE_ ## _type] &&               \
68           (_mime)->initialized &&                               \
69           (_mime)->entries[MIMETYPE_ ## _type]->value.used )
70 
71 #define MIMETYPE_VALUE(_type,_mime)                             \
72         &((_mime)->entries[MIMETYPE_ ## _type]->value)
73 
74 
75 void mimetype_dump (const mimetype_t *mime);
76 
77 
78 int mimetype_insert (mimetype_base_t *base,
79                      enum mimetype_type type,
80                      const char *key, size_t nkey,
81                      const char *value, size_t nvalue);
82 
83 int mimetype_remove  (mimetype_base_t *base, const char *key, size_t nkey);
84 
85 
86 
87 int  mimetype_pop  (mimetype_base_t *base, mimetype_t *mime,
88                     const char *filename, size_t nfilename);
89 
90 void mimetype_push (mimetype_t *mime);
91 
92 #endif /* MIMETYPE_H */


syntax highlighted by Code2HTML, v. 0.9.1