taskrambler  0.1.9
Web server and task management solution.
mime_type.c File Reference
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include "hash.h"
#include "class.h"
#include "commons.h"
+ Include dependency graph for mime_type.c:

Go to the source code of this file.

Functions

void readMimeTypes (void)
 
char * getMimeType (const char *ext, size_t len)
 
void clearMimeTypes (void)
 

Variables

Hash mime_types = NULL
 

Detailed Description

Author
Georg Hopp

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file mime_type.c.

Function Documentation

void clearMimeTypes ( void  )

Definition at line 106 of file mime_type.c.

References mime_types.

Referenced by main().

107 {
108  delete(mime_types);
109 }
Hash mime_types
Definition: mime_type.c:36

+ Here is the caller graph for this function:

char* getMimeType ( const char *  ext,
size_t  len 
)

Definition at line 84 of file mime_type.c.

References hashGet(), mime_types, and readMimeTypes().

Referenced by assetCtor(), and httpWorkerProcess().

85 {
86  HashValue type;
87 
88  if (NULL == mime_types) {
89  readMimeTypes();
90 
91  if (NULL == mime_types) {
92  return NULL;
93  }
94  }
95 
96  type = hashGet(mime_types, ext, len);
97 
98  if (NULL == type) {
99  return NULL;
100  }
101 
102  return (char *)type->value;
103 }
void readMimeTypes(void)
Definition: mime_type.c:39
void * hashGet(Hash, const char *, size_t)
Definition: hash/get.c:51
Hash mime_types
Definition: mime_type.c:36

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void readMimeTypes ( void  )

Definition at line 39 of file mime_type.c.

References hashAdd(), and mime_types.

Referenced by getMimeType().

40 {
41  if (0 == access(CONFIGDIR "/mime.types", O_RDONLY)) {
42  FILE * handle = fopen(CONFIGDIR "/mime.types", "r");
43 
44  if (NULL != handle) {
45  char buffer[512];
46 
47  buffer[511] = '\0';
48  mime_types = new(Hash);
49 
50  while (NULL != fgets(buffer, 511, handle)) {
51  char * tmp;
52  char * key = buffer;
53  char * value;
54  size_t nkey;
55  size_t nvalue;
56 
57  tmp = memchr(key, ' ', 512);
58 
59  if (NULL != tmp) {
60  *tmp = '\0';
61  }
62  nkey = tmp - buffer;
63 
64  value = tmp + 1;
65  for (; *value == ' ' && value < buffer+511; value++);
66 
67  nvalue = strlen(value);
68 
69  if ('\n' == value[nvalue-1]) {
70  nvalue--;
71  value[nvalue] = '\0';
72  }
73 
75  new(HashValue, key, nkey, value, nvalue));
76  }
77 
78  fclose(handle);
79  }
80  }
81 }
void * hashAdd(Hash, void *)
Definition: add.c:48
Hash mime_types
Definition: mime_type.c:36

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

Hash mime_types = NULL

Definition at line 36 of file mime_type.c.

Referenced by clearMimeTypes(), getMimeType(), and readMimeTypes().