1
0
Fork 0

added mimetype generation file

This commit is contained in:
Jan Steemann 2013-03-27 10:11:56 +01:00
parent 9273ddcbad
commit 909c316e22
20 changed files with 722 additions and 45 deletions

View File

@ -310,6 +310,28 @@ BUILT_SOURCES += \
endif
################################################################################
### @brief mimetypes file
################################################################################
if ENABLE_MAINTAINER_MODE
BUILT_SOURCES += \
@top_srcdir@/lib/BasicsC/voc-mimetypes.h \
@top_srcdir@/lib/BasicsC/voc-mimetypes.c \
@top_srcdir@/js/common/modules/org/arangodb/mimetypes.js
@top_srcdir@/lib/BasicsC/voc-mimetypes.h: lib/BasicsC/mimetypes.dat
@top_srcdir@/config/build_mimetypes.sh @top_srcdir@/config/generateMimetypes.py lib/BasicsC/mimetypes.dat @top_srcdir@/lib/BasicsC/voc-mimetypes.h
@top_srcdir@/lib/BasicsC/voc-mimetypes.c: lib/BasicsC/mimetypes.dat
@top_srcdir@/config/build_mimetypes.sh @top_srcdir@/config/generateMimetypes.py lib/BasicsC/mimetypes.dat @top_srcdir@/lib/BasicsC/voc-mimetypes.c
@top_srcdir@/js/common/modules/org/arangodb/mimetypes.js: lib/BasicsC/mimetypes.dat
@top_srcdir@/config/build_mimetypes.sh @top_srcdir@/config/generateMimetypes.py lib/BasicsC/mimetypes.dat js/common/modules/org/arangodb/mimetypes.js
endif
################################################################################
## cleanup
################################################################################
@ -329,7 +351,8 @@ clean-local:
built-sources: \
build_posix.h \
@top_srcdir@/js/common/bootstrap/errors.js
@top_srcdir@/js/common/bootstrap/errors.js \
@top_srcdir@/js/common/modules/org/arangodb/mimetypes.js
################################################################################
### @brief tags file

11
config/build_mimetypes.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
SCRIPT="$1"
SOURCE="$2"
DEST="$3"
python "$SCRIPT" "$SOURCE" "$DEST.tmp"
if cmp -s $DEST ${DEST}.tmp; then
rm ${DEST}.tmp
else
mv ${DEST}.tmp $DEST
fi

View File

@ -102,8 +102,8 @@ def genCHeaderFile(errors):
+ "////////////////////////////////////////////////////////////////////////////////\n"
header = "\n"\
+ "#ifndef TRIAGENS_DURHAM_VOC_BASE_ERRORS_H\n"\
+ "#define TRIAGENS_DURHAM_VOC_BASE_ERRORS_H 1\n"\
+ "#ifndef TRIAGENS_BASICS_C_VOC_ERRORS_H\n"\
+ "#define TRIAGENS_BASICS_C_VOC_ERRORS_H 1\n"\
+ "\n"\
+ "#ifdef __cplusplus\n"\
+ "extern \"C\" {\n"\

172
config/generateMimetypes.py Normal file
View File

@ -0,0 +1,172 @@
import csv, sys, os.path, re
# wrap text after x characters
def wrap(string, width=80, ind1=0, ind2=0, prefix=''):
string = prefix + ind1 * " " + string
newstring = ""
string = string.replace("\n", " ")
while len(string) > width:
marker = width - 1
while not string[marker].isspace():
marker = marker - 1
newline = string[0:marker] + "\n"
newstring = newstring + newline
string = prefix + ind2 * " " + string[marker + 1:]
return newstring + string
# generate javascript file from mimetypes
def genJsFile(types):
jslint = "/*jslint indent: 2,\n"\
" nomen: true,\n"\
" maxlen: 240,\n"\
" sloppy: true,\n"\
" vars: true,\n"\
" white: true,\n"\
" plusplus: true */\n"\
"/*global exports */\n\n"
out = jslint \
+ prologue\
+ "exports.mimeTypes = {\n"
# print individual mimetypes
i = 0
for t in types:
out = out + " \"" + t[0] + "\": \"" + t[1] + "\""
i = i + 1
if i < len(types):
out = out + ", \n"
else:
out = out + "\n"
out = out + "};\n\n"
return out
# generate C header file from errors
def genCHeaderFile(types):
header = "\n"\
+ "#ifndef TRIAGENS_BASICS_C_VOC_MIMETYPES_H\n"\
+ "#define TRIAGENS_BASICS_C_VOC_MIMETYPES_H 1\n"\
+ "\n"\
+ "#ifdef __cplusplus\n"\
+ "extern \"C\" {\n"\
+ "#endif\n"\
+ "\n"\
+ docstart\
+ "////////////////////////////////////////////////////////////////////////////////\n"\
+ "/// @brief initialise mimetypes\n"\
+ "////////////////////////////////////////////////////////////////////////////////\n"\
+ "\n"\
+ "void TRI_InitialiseEntriesMimetypes (void);\n"\
+ docend\
+ "#ifdef __cplusplus\n"\
+ "}\n"\
+ "#endif\n"\
+ "\n"\
+ "#endif\n"\
+ "\n"
return header
# generate C implementation file from mimetypes
def genCFile(types, filename):
headerfile = os.path.splitext(filename)[0] + ".h"
impl = prologue\
+ "#include <BasicsC/common.h>\n"\
+ "#include \"" + headerfile + "\"\n"\
+ "\n"\
+ docstart\
+ "////////////////////////////////////////////////////////////////////////////////\n"\
+ "/// @brief initialise mimetypes\n"\
+ "////////////////////////////////////////////////////////////////////////////////\n"\
+ "\n"\
+ "void TRI_InitialiseEntriesMimetypes (void) {\n"
# print individual types
for t in types:
impl = impl + " TRI_RegisterMimetype(\"" + t[0] + "\", \"" + t[1] + "\");\n"
impl = impl\
+ "}\n"\
+ docend
return impl
# define some globals
prologue = "////////////////////////////////////////////////////////////////////////////////\n"\
+ "/// @brief auto-generated file generated from mimetypes.dat\n"\
+ "////////////////////////////////////////////////////////////////////////////////\n"\
+ "\n"
docstart = "////////////////////////////////////////////////////////////////////////////////\n"\
+ "/// @addtogroup Mimetypes\n"\
+ "/// @{\n"\
+ "////////////////////////////////////////////////////////////////////////////////\n"\
+ "\n"
docend = "\n"\
+ "////////////////////////////////////////////////////////////////////////////////\n"\
+ "/// @}\n"\
+ "////////////////////////////////////////////////////////////////////////////////\n"\
+ "\n"
if len(sys.argv) < 3:
print >> sys.stderr, "usage: %s <sourcefile> <outfile>" % sys.argv[0]
sys.exit()
source = sys.argv[1]
# read input file
mimetypes = csv.reader(open(source, "rb"))
types = []
r1 = re.compile(r'^#.*')
for t in mimetypes:
if len(t) == 0:
continue
if r1.match(t[0]):
continue
if t[0] == "" or t[1] == "":
print >> sys.stderr, "invalid mimetypes declaration file: %s (line %i)" % (source, i)
sys.exit()
types.append(t)
outfile = sys.argv[2]
extension = os.path.splitext(outfile)[1]
filename = outfile
if extension == ".tmp":
filename = os.path.splitext(outfile)[0]
extension = os.path.splitext(filename)[1]
if extension == ".js":
out = genJsFile(types)
elif extension == ".h":
out = genCHeaderFile(types)
elif extension == ".c":
out = genCFile(types, filename)
else:
print >> sys.stderr, "usage: %s <sourcefile> <outfile>" % sys.argv[0]
sys.exit()
outFile = open(outfile, "wb")
outFile.write(out);
outFile.close()

View File

@ -111,6 +111,7 @@
<script src="js/modules/org/arangodb/arangosh.js"></script>
<script src="js/modules/org/arangodb/graph-common.js"></script>
<script src="js/modules/org/arangodb/graph.js"></script>
<script src="js/modules/org/arangodb/mimetypes.js"></script>
<script src="js/modules/org/arangodb/simple-query-common.js"></script>
<script src="js/modules/org/arangodb/simple-query.js"></script>
<script src="js/modules/org/arangodb/graph/traversal.js"></script>

View File

@ -0,0 +1,30 @@
module.define("org/arangodb/mimetypes", function(exports, module) {
/*jslint indent: 2,
nomen: true,
maxlen: 240,
sloppy: true,
vars: true,
white: true,
plusplus: true */
/*global exports */
////////////////////////////////////////////////////////////////////////////////
/// @brief auto-generated file generated from mimetypes.dat
////////////////////////////////////////////////////////////////////////////////
exports.mimeTypes = {
"gif": "image/gif",
"jpg": "image/jpg",
"png": "image/png",
"ico": "image/x-icon",
"css": "text/css",
"js": "text/javascript",
"json": "application/json",
"html": "text/html",
"htm": "text/html",
"pdf": "application/pdf",
"text": "text/plain",
"xml": "application/xml"
};
});

View File

@ -25,6 +25,7 @@ JAVASCRIPT_BROWSER = \
html/admin/js/modules/org/arangodb/arango-statement-common.js \
html/admin/js/modules/org/arangodb/graph-common.js \
html/admin/js/modules/org/arangodb/graph/traversal.js \
html/admin/js/modules/org/arangodb/mimetypes.js \
html/admin/js/modules/org/arangodb/simple-query-common.js \
\
html/admin/js/bootstrap/errors.js \

View File

@ -59,7 +59,8 @@ function routing (req, res) {
execute = function () {
if (action.route === undefined) {
actions.resultNotFound(req, res, arangodb.ERROR_HTTP_NOT_FOUND, "unknown path '" + path + "'");
actions.resultNotFound(req, res, arangodb.ERROR_HTTP_NOT_FOUND,
"unknown path '" + path + "'");
return;
}

View File

@ -0,0 +1,28 @@
/*jslint indent: 2,
nomen: true,
maxlen: 240,
sloppy: true,
vars: true,
white: true,
plusplus: true */
/*global exports */
////////////////////////////////////////////////////////////////////////////////
/// @brief auto-generated file generated from mimetypes.dat
////////////////////////////////////////////////////////////////////////////////
exports.mimeTypes = {
"gif": "image/gif",
"jpg": "image/jpg",
"png": "image/png",
"ico": "image/x-icon",
"css": "text/css",
"js": "text/javascript",
"json": "application/json",
"html": "text/html",
"htm": "text/html",
"pdf": "application/pdf",
"text": "text/plain",
"xml": "application/xml"
};

View File

@ -140,6 +140,7 @@ typedef long suseconds_t;
#include "BasicsC/voc-errors.h"
#include "BasicsC/error.h"
#include "BasicsC/memory.h"
#include "BasicsC/mimetypes.h"
#include "BasicsC/structures.h"
#undef TRI_WITHIN_COMMON

View File

@ -235,7 +235,7 @@ char const* TRI_last_error () {
entry = (TRI_error_t*)
TRI_LookupByKeyAssociativePointer(&ErrorMessages, (void const*) &err);
if (!entry) {
if (entry == NULL) {
return "general error";
}
@ -392,11 +392,8 @@ void TRI_ShutdownError () {
for (i = 0; i < ErrorMessages._nrAlloc; i++) {
TRI_error_t* entry = ErrorMessages._table[i];
if (entry) {
if (entry->_message) {
TRI_Free(TRI_CORE_MEM_ZONE, entry->_message);
}
if (entry != NULL) {
TRI_Free(TRI_CORE_MEM_ZONE, entry->_message);
TRI_Free(TRI_CORE_MEM_ZONE, entry);
}
}

View File

@ -53,6 +53,7 @@ void TRI_InitialiseC (int argc, char* argv[]) {
TRI_InitialiseMemory();
TRI_InitialiseMersenneTwister();
TRI_InitialiseError();
TRI_InitialiseMimetypes();
TRI_InitialiseLogging(false);
TRI_InitialiseHashes();
TRI_InitialiseRandom();
@ -72,6 +73,7 @@ void TRI_ShutdownC () {
TRI_ShutdownRandom();
TRI_ShutdownHashes();
TRI_ShutdownLogging();
TRI_ShutdownMimetypes();
TRI_ShutdownError();
TRI_ShutdownMemory();
}

231
lib/BasicsC/mimetypes.c Normal file
View File

@ -0,0 +1,231 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief mimetypes
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2004-2013 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Jan Steemann
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#include "BasicsC/common.h"
#include "BasicsC/associative.h"
#include "BasicsC/hashes.h"
#include "BasicsC/strings.h"
#include "BasicsC/voc-mimetypes.h"
// -----------------------------------------------------------------------------
// --SECTION-- private variables
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Mimetypes
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief mimetype
////////////////////////////////////////////////////////////////////////////////
typedef struct mimetype_s {
char* _extension;
char* _mimetype;
}
mimetype_t;
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- private variables
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Mimetypes
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief already initialised
////////////////////////////////////////////////////////////////////////////////
static bool Initialised = false;
////////////////////////////////////////////////////////////////////////////////
/// @brief the array of mimetypes
////////////////////////////////////////////////////////////////////////////////
static TRI_associative_pointer_t Mimetypes;
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- private functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Mimetypes
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief Hash function used to hash errors messages (not used)
////////////////////////////////////////////////////////////////////////////////
static uint64_t HashMimetype (TRI_associative_pointer_t* array,
void const* element) {
mimetype_t* entry = (mimetype_t*) element;
return (uint64_t) TRI_FnvHashString(entry->_extension);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief Comparison function used to determine error equality
////////////////////////////////////////////////////////////////////////////////
static bool EqualMimetype (TRI_associative_pointer_t* array,
void const* key,
void const* element) {
mimetype_t* entry = (mimetype_t*) element;
return (strcmp((const char*) key, entry->_extension) == 0);
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- public functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Mimetypes
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief register a mimetype for an extension
////////////////////////////////////////////////////////////////////////////////
bool TRI_RegisterMimetype (const char* extension, const char* mimetype) {
mimetype_t* entry;
void* found;
entry = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(mimetype_t), false);
entry->_extension = TRI_DuplicateString(extension);
entry->_mimetype = TRI_DuplicateString(mimetype);
found = TRI_InsertKeyAssociativePointer(&Mimetypes, extension, entry, false);
return (found != NULL);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief gets the mimetype for an extension
////////////////////////////////////////////////////////////////////////////////
char* TRI_GetMimetype (const char* extension) {
mimetype_t* entry;
entry = TRI_LookupByKeyAssociativePointer(&Mimetypes, (void const*) extension);
if (entry == NULL) {
return NULL;
}
return entry->_mimetype;
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- MODULE
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// --SECTION-- public functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Mimetypes
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief initialises the mimetypes
////////////////////////////////////////////////////////////////////////////////
void TRI_InitialiseMimetypes () {
if (Initialised) {
return;
}
TRI_InitAssociativePointer(&Mimetypes,
TRI_CORE_MEM_ZONE,
&TRI_HashStringKeyAssociativePointer,
HashMimetype,
EqualMimetype,
0);
TRI_InitialiseEntriesMimetypes();
Initialised = true;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief shuts down the mimetypes
////////////////////////////////////////////////////////////////////////////////
void TRI_ShutdownMimetypes () {
size_t i;
if (! Initialised) {
return;
}
for (i = 0; i < Mimetypes._nrAlloc; i++) {
mimetype_t* mimetype = Mimetypes._table[i];
if (mimetype != NULL) {
TRI_Free(TRI_CORE_MEM_ZONE, mimetype->_extension);
TRI_Free(TRI_CORE_MEM_ZONE, mimetype->_mimetype);
TRI_Free(TRI_CORE_MEM_ZONE, mimetype);
}
}
TRI_DestroyAssociativePointer(&Mimetypes);
Initialised = false;
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End:

17
lib/BasicsC/mimetypes.dat Executable file
View File

@ -0,0 +1,17 @@
################################################################################
## mimetypes
################################################################################
"gif","image/gif"
"jpg","image/jpg"
"png","image/png"
"ico","image/x-icon"
"css","text/css"
"js","text/javascript"
"json","application/json"
"html","text/html"
"htm","text/html"
"pdf","application/pdf"
"text","text/plain"
"xml","application/xml"

115
lib/BasicsC/mimetypes.h Normal file
View File

@ -0,0 +1,115 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief mimetypes
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2004-2013 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Jan Steemann
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef TRIAGENS_BASICS_C_MIMETYPES_H
#define TRIAGENS_BASICS_C_MIMETYPES_H 1
#ifndef TRI_WITHIN_COMMON
#error use <BasicsC/common.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
// -----------------------------------------------------------------------------
// --SECTION-- public types
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Mimetypes
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- public functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Mimetypes
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief register a mimetype for an extension
////////////////////////////////////////////////////////////////////////////////
bool TRI_RegisterMimetype (const char*, const char*);
////////////////////////////////////////////////////////////////////////////////
/// @brief gets the mimetype for an extension
////////////////////////////////////////////////////////////////////////////////
char* TRI_GetMimetype (const char*);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- MODULE
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// --SECTION-- public functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Mimetypes
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief initialises mimetypes
////////////////////////////////////////////////////////////////////////////////
void TRI_InitialiseMimetypes (void);
////////////////////////////////////////////////////////////////////////////////
/// @brief shuts down mimetypes
////////////////////////////////////////////////////////////////////////////////
void TRI_ShutdownMimetypes (void);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif
#endif
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End:

View File

@ -1,6 +1,6 @@
#ifndef TRIAGENS_DURHAM_VOC_BASE_ERRORS_H
#define TRIAGENS_DURHAM_VOC_BASE_ERRORS_H 1
#ifndef TRIAGENS_BASICS_C_ERRORS_H
#define TRIAGENS_BASICS_C_ERRORS_H 1
#ifdef __cplusplus
extern "C" {

View File

@ -0,0 +1,35 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief auto-generated file generated from mimetypes.dat
////////////////////////////////////////////////////////////////////////////////
#include <BasicsC/common.h>
#include "./lib/BasicsC/voc-mimetypes.h"
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Mimetypes
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief initialise mimetypes
////////////////////////////////////////////////////////////////////////////////
void TRI_InitialiseEntriesMimetypes (void) {
TRI_RegisterMimetype("gif", "image/gif");
TRI_RegisterMimetype("jpg", "image/jpg");
TRI_RegisterMimetype("png", "image/png");
TRI_RegisterMimetype("ico", "image/x-icon");
TRI_RegisterMimetype("css", "text/css");
TRI_RegisterMimetype("js", "text/javascript");
TRI_RegisterMimetype("json", "application/json");
TRI_RegisterMimetype("html", "text/html");
TRI_RegisterMimetype("htm", "text/html");
TRI_RegisterMimetype("pdf", "application/pdf");
TRI_RegisterMimetype("text", "text/plain");
TRI_RegisterMimetype("xml", "application/xml");
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,29 @@
#ifndef TRIAGENS_BASICS_C_VOC_MIMETYPES_H
#define TRIAGENS_BASICS_C_VOC_MIMETYPES_H 1
#ifdef __cplusplus
extern "C" {
#endif
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Mimetypes
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief initialise mimetypes
////////////////////////////////////////////////////////////////////////////////
void TRI_InitialiseEntriesMimetypes (void);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif
#endif

View File

@ -32,6 +32,7 @@
#include "Basics/FileUtils.h"
#include "Logger/Logger.h"
#include "Basics/StringBuffer.h"
#include "BasicsC/mimetypes.h"
#include "Rest/HttpRequest.h"
#include "Rest/HttpResponse.h"
@ -41,7 +42,7 @@ namespace triagens {
namespace rest {
// -----------------------------------------------------------------------------
// constructors and destructores
// constructors and destructors
// -----------------------------------------------------------------------------
PathHandler::PathHandler (HttpRequest* request, Options const* options)
@ -166,45 +167,25 @@ namespace triagens {
string::size_type d = last.find_last_of('.');
if (d != string::npos) {
string suffix = last.substr(d);
string suffix = last.substr(d + 1);
if (suffix == ".jpg") {
_response->setContentType("image/jpg");
}
else if (suffix == ".js") {
_response->setContentType("text/javascript");
}
else if (suffix == ".gif") {
_response->setContentType("image/gif");
}
else if (suffix == ".png") {
_response->setContentType("image/png");
}
else if (suffix == ".css") {
_response->setContentType("text/css");
}
else if (suffix == ".html" || suffix == ".htm") {
_response->setContentType("text/html");
}
else if (suffix == ".ico") {
_response->setContentType("image/x-icon");
}
else if (suffix == ".pdf") {
_response->setContentType("application/pdf");
}
else if (suffix == ".txt") {
_response->setContentType("text/plain");
if (suffix.size() > 0) {
// look up the mimetype
const char* mimetype = TRI_GetMimetype(suffix.c_str());
if (mimetype != 0) {
_response->setContentType(mimetype);
return HANDLER_DONE;
}
}
else {
// note: changed the log level to debug. an unknown content-type does not justify a warning
LOGGER_TRACE("unknown suffix = " << suffix);
_response->setContentType(contentType);
}
}
else {
_response->setContentType(contentType);
}
_response->setContentType(contentType);
return HANDLER_DONE;
}

View File

@ -52,6 +52,7 @@ lib_libarango_a_SOURCES = \
lib/BasicsC/memory.c \
lib/BasicsC/memory-map-posix.c \
lib/BasicsC/mersenne.c \
lib/BasicsC/mimetypes.c \
lib/BasicsC/process-utils.c \
lib/BasicsC/random.c \
lib/BasicsC/socket-utils.c \
@ -65,6 +66,7 @@ lib_libarango_a_SOURCES = \
lib/BasicsC/utf8-helper.c \
lib/BasicsC/vector.c \
lib/BasicsC/voc-errors.c \
lib/BasicsC/voc-mimetypes.c \
lib/BasicsC/zip.c \
lib/JsonParser/json-parser.c \
lib/Logger/Logger.cpp \