UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
webserver.cpp
Go to the documentation of this file.
1// Copyright (C) 2022+ GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
2// Redistribution only with this Copyright remark. Last modified: 2024-08-18
9#include <UPnPsdk/port.hpp>
11#include <array>
13
14namespace {
15
23const std::array<UPnPsdk::Document_meta, 70> mediatype_list{
24 {// file-ext, media-type, media-subtype
25 {"aif", "audio", "aiff"},
26 {"aifc", "audio", "aiff"},
27 {"aiff", "audio", "aiff"},
28 {"asf", "video", "x-ms-asf"},
29 {"asx", "video", "x-ms-asf"},
30 {"au", "audio", "basic"},
31 {"avi", "video", "msvideo"},
32 {"bmp", "image", "bmp"},
33 {"css", "text", "css"},
34 {"dcr", "application", "x-director"},
35 {"dib", "image", "bmp"},
36 {"dir", "application", "x-director"},
37 {"dxr", "application", "x-director"},
38 {"gif", "image", "gif"},
39 {"hta", "text", "hta"},
40 {"htm", "text", "html"},
41 {"html", "text", "html"},
42 {"jar", "application", "java-archive"},
43 {"jfif", "image", "pjpeg"},
44 {"jpe", "image", "jpeg"},
45 {"jpeg", "image", "jpeg"},
46 {"jpg", "image", "jpeg"},
47 {"js", "application", "x-javascript"},
48 {"kar", "audio", "midi"},
49 {"m3u", "audio", "mpegurl"},
50 {"mid", "audio", "midi"},
51 {"midi", "audio", "midi"},
52 {"mov", "video", "quicktime"},
53 {"mp2v", "video", "x-mpeg2"},
54 {"mp3", "audio", "mpeg"},
55 {"mpe", "video", "mpeg"},
56 {"mpeg", "video", "mpeg"},
57 {"mpg", "video", "mpeg"},
58 {"mpv", "video", "mpeg"},
59 {"mpv2", "video", "x-mpeg2"},
60 {"pdf", "application", "pdf"},
61 {"pjp", "image", "jpeg"},
62 {"pjpeg", "image", "jpeg"},
63 {"plg", "text", "html"},
64 {"pls", "audio", "scpls"},
65 {"png", "image", "png"},
66 {"qt", "video", "quicktime"},
67 {"ram", "audio", "x-pn-realaudio"},
68 {"rmi", "audio", "mid"},
69 {"rmm", "audio", "x-pn-realaudio"},
70 {"rtf", "application", "rtf"},
71 {"shtml", "text", "html"},
72 {"smf", "audio", "midi"},
73 {"snd", "audio", "basic"},
74 {"spl", "application", "futuresplash"},
75 {"ssm", "application", "streamingmedia"},
76 {"swf", "application", "x-shockwave-flash"},
77 {"tar", "application", "tar"},
78 {"tcl", "application", "x-tcl"},
79 {"text", "text", "plain"},
80 {"tif", "image", "tiff"},
81 {"tiff", "image", "tiff"},
82 {"txt", "text", "plain"},
83 {"ulw", "audio", "basic"},
84 {"wav", "audio", "wav"},
85 {"wax", "audio", "x-ms-wax"},
86 {"wm", "video", "x-ms-wm"},
87 {"wma", "audio", "x-ms-wma"},
88 {"wmv", "video", "x-ms-wmv"},
89 {"wvx", "video", "x-ms-wvx"},
90 {"xbm", "image", "x-xbitmap"},
91 {"xml", "text", "xml"},
92 {"xsl", "text", "xml"},
93 {"z", "application", "x-compress"},
94 {"zip", "application", "zip"}}};
95
96} // anonymous namespace
97
98namespace UPnPsdk {
99
101const Document_meta* select_filetype(std::string_view a_extension) {
102
103 ssize_t top = 0;
104 ssize_t bot = mediatype_list.size() - 1;
105
106 // Using effective binary search on the sorted list.
107 while (top <= bot) {
108 ssize_t mid = (top + bot) / 2;
109 int cmp = a_extension.compare(
110 // need type cast: mid cannot become negative
111 mediatype_list[(size_t)mid].extension);
112 if (cmp > 0) {
113 /* look below mid. */
114 top = mid + 1;
115 } else if (cmp < 0) {
116 /* look above mid. */
117 bot = mid - 1;
118 } else {
119 /* cmp == 0 */
120 // need type cast: mid cannot become negative
121 return &mediatype_list[(size_t)mid];
122 }
123 }
124 return nullptr;
125}
126
127} // namespace UPnPsdk
Declarations to manage the builtin Webserver.
Reengineered Object Oriented UPnP+ program code.
UPnPsdk_VIS const Document_meta * select_filetype(std::string_view a_extension)
Based on the extension, returns the content type and content subtype.
Mapping of file extension to content-type of document.
Definition webserver.hpp:18
const std::array< UPnPsdk::Document_meta, 70 > mediatype_list
This table maps the file extension to the associated media type and its subtype.
Definition webserver.cpp:23
Specifications to be portable between different platforms.