CPPMyth
Library to interoperate with MythTV server
wscontent.cpp
1 /*
2  * Copyright (C) 2014 Jean-Luc Barriere
3  *
4  * This library is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; either version 3, or (at your option)
7  * any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; see the file COPYING. If not, write to
16  * the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
17  * MA 02110-1301 USA
18  * http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21 
22 #include "wscontent.h"
23 
24 #include <cstring> // for strcmp
25 
26 using namespace NSROOT;
27 
28 struct mimetype
29 {
30  const char *content_type;
31  const char *extn;
32 };
33 
34 static struct mimetype mimetypes[] =
35 {
36  { "", "" },
37  { "application/x-www-form-urlencoded", "" },
38  { "application/soap+xml", "xml" },
39  { "application/json", "txt" },
40  { "text/xml", "xml" },
41  { "text/plain", "txt" },
42  { "image/gif", "gif" },
43  { "image/png", "png" },
44  { "image/jpeg", "jpg" },
45  { "application/octet-stream", "" }
46 };
47 
48 CT_t NSROOT::ContentTypeFromMime(const char *mime)
49 {
50  int i;
51  for (i = 0; i < CT_UNKNOWN; ++i)
52  {
53  if (0 == strcmp(mimetypes[i].content_type, mime))
54  return (CT_t)i;
55  }
56  return CT_UNKNOWN;
57 }
58 
59 const char* NSROOT::MimeFromContentType(CT_t ct)
60 {
61  if (ct >= 0 && ct < CT_UNKNOWN)
62  return mimetypes[ct].content_type;
63  return mimetypes[CT_UNKNOWN].content_type;
64 }
65 
66 const char* NSROOT::ExtnFromContentType(CT_t ct)
67 {
68  if (ct >= 0 && ct < CT_UNKNOWN)
69  return mimetypes[ct].extn;
70  return mimetypes[CT_UNKNOWN].extn;
71 }