1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef MMS_CONTENT_TYPE_H 17 #define MMS_CONTENT_TYPE_H 18 19 #include "mms_decode_buffer.h" 20 #include "mms_content_param.h" 21 22 namespace OHOS { 23 namespace Telephony { 24 enum class ContentTypes { 25 X_X = 0x00, 26 TEXT_X = 0x01, 27 TEXT_HTML = 0x02, 28 TEXT_PLAIN = 0x03, 29 TEXT_X_HDML = 0x04, 30 TEXT_X_TTML = 0x05, 31 TEXT_X_VCALENDAR = 0x06, 32 TEXT_X_VCARD = 0x07, 33 TEXT_VND_WAP_WML = 0x08, 34 TEXT_VND_WAP_WMLSCRIPT = 0x09, 35 TEXT_VND_WAP_WTA_EVENT = 0x0A, 36 MULTIPART_X = 0x0B, 37 MULTIPART_MIXED = 0x0C, 38 MULTIPART_FORM_DATA = 0x0D, 39 MULTIPART_BYTERANTES = 0x0E, 40 MULTIPART_ALTERNATIVE = 0x0F, 41 APPLICATION_X = 0x10, 42 APPLICATION_JAVA_VM = 0x11, 43 APPLICATION_X_WWW_FORM_URLENCODED = 0x12, 44 APPLICATION_X_HDMLC = 0x13, 45 APPLICATION_VND_WAP_WMLC = 0x14, 46 APPLICATION_VND_WAP_WMLSCRIPTC = 0x15, 47 APPLICATION_VND_WAP_WTA_EVENTC = 0x16, 48 APPLICATION_VND_WAP_UAPROF = 0x17, 49 APPLICATION_VND_WAP_WTLS_CA_CERTIFICATE = 0x18, 50 APPLICATION_VND_WAP_WTLS_USER_CERTIFICATE = 0x19, 51 APPLICATION_X_X509_CA_CERT = 0x1A, 52 APPLICATION_X_X509_USER_CERT = 0x1B, 53 IMAGE_X = 0x1C, 54 IMAGE_GIF = 0x1D, 55 IMAGE_JPEG = 0x1E, 56 IMAGE_TIFF = 0x1F, 57 IMAGE_PNG = 0x20, 58 IMAGE_VND_WAP_WBMP = 0x21, 59 APPLICATION_VND_WAP_MULTIPART_X = 0x22, 60 APPLICATION_VND_WAP_MULTIPART_MIXED = 0x23, 61 APPLICATION_VND_WAP_MULTIPART_FORM_DATA = 0x24, 62 APPLICATION_VND_WAP_MULTIPART_BYTERANGES = 0x25, 63 APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE = 0x26, 64 APPLICATION_XML = 0x27, 65 TEXT_XML = 0x28, 66 APPLICATION_VND_WAP_WBXML = 0x29, 67 APPLICATION_X_X968_CROSS_CERT = 0x2A, 68 APPLICATION_X_X968_CA_CERT = 0x2B, 69 APPLICATION_X_X968_USER_CERT = 0x2C, 70 TEXT_VND_WAP_SI = 0x2D, 71 APPLICATION_VND_WAP_SIC = 0x2E, 72 TEXT_VND_WAP_SL = 0x2F, 73 APPLICATION_VND_WAP_SLC = 0x30, 74 TEXT_VND_WAP_CO = 0x31, 75 APPLICATION_VND_WAP_COC = 0x32, 76 APPLICATION_VND_WAP_MULTIPART_RELATED = 0x33, 77 APPLICATION_VND_WAP_SIA = 0x34, 78 TEXT_VND_WAP_CONNECTIVITY_XML = 0x35, 79 APPLICATION_VND_WAP_CONNECTIVITY_WBXML = 0x36, 80 APPLICATION_PKCS7_MIME = 0x37, 81 APPLICATION_VND_WAP_HASHED_CERTIFICATE = 0x38, 82 APPLICATION_VND_WAP_SIGNED_CERTIFICATE = 0x39, 83 APPLICATION_VND_WAP_CERT_RESPONSE = 0x3A, 84 APPLICATION_XHTML_XML = 0x3B, 85 APPLICATION_WML_XML = 0x3C, 86 TEXT_CSS = 0x3D, 87 APPLICATION_VND_WAP_MMS_MESSAGE = 0x3E, 88 APPLICATION_VND_WAP_ROLLOVER_CERTIFICATE = 0x3F, 89 APPLICATION_VND_WAP_LOCC_WBXML = 0x40, 90 APPLICATION_VND_WAP_LOC_XML = 0x41, 91 APPLICATION_VND_SYNCML_DM_WBXML = 0x42, 92 APPLICATION_VND_SYNCML_DM_XML = 0x43, 93 APPLICATION_VND_SYNCML_NOTIFICATION = 0x44, 94 APPLICATION_VND_WAP_XHTML_XML = 0x45, 95 APPLICATION_VND_WV_CSP_CIR = 0x46, 96 APPLICATION_VND_OMA_DD_XML = 0x47, 97 APPLICATION_VND_OMA_DRM_MESSAGE = 0x48, 98 APPLICATION_VND_OMA_DRM_CONTENT = 0x49, 99 APPLICATION_VND_OMA_DRM_RIGHTS_XML = 0x4A, 100 APPLICATION_VND_OMA_DRM_RIGHTS_WBXML = 0x4B, 101 APPLICATION_VND_WV_CSP_XML = 0x4C, 102 APPLICATION_VND_WV_CSP_WBXML = 0x4D, 103 APPLICATION_VND_SYNCML_DS_NOTIFICATION = 0x4E, 104 AUDIO_X = 0x4F, 105 VIDEO_X = 0x50, 106 APPLICATION_VND_OMA_DD2_XML = 0x51, 107 APPLICATION_MIKEY = 0x52, 108 APPLICATION_VND_OMA_DCD = 0x53, 109 APPLICATION_VND_OMA_DCDC = 0x54, 110 CONTENT_TYPE_UNDOWN = 0xFF 111 }; 112 113 struct KeyValue { 114 ContentTypes key = ContentTypes::X_X; 115 const char *value = nullptr; 116 }; 117 118 static const KeyValue mmsContentNames[] = { 119 { ContentTypes::X_X, "*/*" }, 120 { ContentTypes::TEXT_X, "text/*" }, 121 { ContentTypes::TEXT_HTML, "text/html" }, 122 { ContentTypes::TEXT_PLAIN, "text/plain" }, 123 { ContentTypes::TEXT_X_HDML, "text/x-hdml" }, 124 { ContentTypes::TEXT_X_TTML, "text/x-ttml" }, 125 { ContentTypes::TEXT_X_VCALENDAR, "text/x-vCalendar" }, 126 { ContentTypes::TEXT_X_VCARD, "text/x-vCard" }, 127 { ContentTypes::TEXT_VND_WAP_WML, "text/vnd.wap.wml" }, 128 { ContentTypes::TEXT_VND_WAP_WMLSCRIPT, "text/vnd.wap.wmlscript" }, 129 { ContentTypes::TEXT_VND_WAP_WTA_EVENT, "text/vnd.wap.wta-event" }, 130 { ContentTypes::MULTIPART_X, "multipart/*" }, 131 { ContentTypes::MULTIPART_MIXED, "multipart/mixed" }, 132 { ContentTypes::MULTIPART_FORM_DATA, "multipart/form-data" }, 133 { ContentTypes::MULTIPART_BYTERANTES, "multipart/byterantes" }, 134 { ContentTypes::MULTIPART_ALTERNATIVE, "multipart/alternative" }, 135 { ContentTypes::APPLICATION_X, "application/*" }, 136 { ContentTypes::APPLICATION_JAVA_VM, "application/java-vm" }, 137 { ContentTypes::APPLICATION_X_WWW_FORM_URLENCODED, "application/x-www-form-urlencoded" }, 138 { ContentTypes::APPLICATION_X_HDMLC, "application/x-hdmlc" }, 139 { ContentTypes::APPLICATION_VND_WAP_WMLC, "application/vnd.wap.wmlc" }, 140 { ContentTypes::APPLICATION_VND_WAP_WMLSCRIPTC, "application/vnd.wap.wmlscriptc" }, 141 { ContentTypes::APPLICATION_VND_WAP_WTA_EVENTC, "application/vnd.wap.wta-eventc" }, 142 { ContentTypes::APPLICATION_VND_WAP_UAPROF, "application/vnd.wap.uaprof" }, 143 { ContentTypes::APPLICATION_VND_WAP_WTLS_CA_CERTIFICATE, "application/vnd.wap.wtls-ca-certificate" }, 144 { ContentTypes::APPLICATION_VND_WAP_WTLS_USER_CERTIFICATE, "application/vnd.wap.wtls-user-certificate" }, 145 { ContentTypes::APPLICATION_X_X509_CA_CERT, "application/x-x509-ca-cert" }, 146 { ContentTypes::APPLICATION_X_X509_USER_CERT, "application/x-x509-user-cert" }, 147 { ContentTypes::IMAGE_X, "image/*" }, 148 { ContentTypes::IMAGE_GIF, "image/gif" }, 149 { ContentTypes::IMAGE_JPEG, "image/jpeg" }, 150 { ContentTypes::IMAGE_TIFF, "image/tiff" }, 151 { ContentTypes::IMAGE_PNG, "image/png" }, 152 { ContentTypes::IMAGE_VND_WAP_WBMP, "image/vnd.wap.wbmp" }, 153 { ContentTypes::APPLICATION_VND_WAP_MULTIPART_X, "application/vnd.wap.multipart.*" }, 154 { ContentTypes::APPLICATION_VND_WAP_MULTIPART_MIXED, "application/vnd.wap.multipart.mixed" }, 155 { ContentTypes::APPLICATION_VND_WAP_MULTIPART_FORM_DATA, "application/vnd.wap.multipart.form-data" }, 156 { ContentTypes::APPLICATION_VND_WAP_MULTIPART_BYTERANGES, "application/vnd.wap.multipart.byteranges" }, 157 { ContentTypes::APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE, "application/vnd.wap.multipart.alternative" }, 158 { ContentTypes::APPLICATION_XML, "application/xml" }, 159 { ContentTypes::TEXT_XML, "text/xml" }, 160 { ContentTypes::APPLICATION_VND_WAP_WBXML, "application/vnd.wap.wbxml" }, 161 { ContentTypes::APPLICATION_X_X968_CROSS_CERT, "application/x-x968-cross-cert" }, 162 { ContentTypes::APPLICATION_X_X968_CA_CERT, "application/x-x968-ca-cert" }, 163 { ContentTypes::APPLICATION_X_X968_USER_CERT, "application/x-x968-user-cert" }, 164 { ContentTypes::TEXT_VND_WAP_SI, "text/vnd.wap.si" }, 165 { ContentTypes::APPLICATION_VND_WAP_SIC, "application/vnd.wap.sic" }, 166 { ContentTypes::TEXT_VND_WAP_SL, "text/vnd.wap.sl" }, 167 { ContentTypes::APPLICATION_VND_WAP_SLC, "application/vnd.wap.slc" }, 168 { ContentTypes::TEXT_VND_WAP_CO, "text/vnd.wap.co" }, 169 { ContentTypes::APPLICATION_VND_WAP_COC, "application/vnd.wap.coc" }, 170 { ContentTypes::APPLICATION_VND_WAP_MULTIPART_RELATED, "application/vnd.wap.multipart.related" }, 171 { ContentTypes::APPLICATION_VND_WAP_SIA, "application/vnd.wap.sia" }, 172 { ContentTypes::TEXT_VND_WAP_CONNECTIVITY_XML, "text/vnd.wap.connectivity-xml" }, 173 { ContentTypes::APPLICATION_VND_WAP_CONNECTIVITY_WBXML, "application/vnd.wap.connectivity-wbxml" }, 174 { ContentTypes::APPLICATION_PKCS7_MIME, "application/pkcs7-mime" }, 175 { ContentTypes::APPLICATION_VND_WAP_HASHED_CERTIFICATE, "application/vnd.wap.hashed-certificate" }, 176 { ContentTypes::APPLICATION_VND_WAP_SIGNED_CERTIFICATE, "application/vnd.wap.signed-certificate" }, 177 { ContentTypes::APPLICATION_VND_WAP_CERT_RESPONSE, "application/vnd.wap.cert-response" }, 178 { ContentTypes::APPLICATION_XHTML_XML, "application/xhtml+xml" }, 179 { ContentTypes::APPLICATION_WML_XML, "application/wml+xml" }, 180 { ContentTypes::TEXT_CSS, "text/css" }, 181 { ContentTypes::APPLICATION_VND_WAP_MMS_MESSAGE, "application/vnd.wap.mms-message" }, 182 { ContentTypes::APPLICATION_VND_WAP_ROLLOVER_CERTIFICATE, "application/vnd.wap.rollover-certificate" }, 183 { ContentTypes::APPLICATION_VND_WAP_LOCC_WBXML, "application/vnd.wap.locc+wbxml" }, 184 { ContentTypes::APPLICATION_VND_WAP_LOC_XML, "application/vnd.wap.loc+xml" }, 185 { ContentTypes::APPLICATION_VND_SYNCML_DM_WBXML, "application/vnd.syncml.dm+wbxml" }, 186 { ContentTypes::APPLICATION_VND_SYNCML_DM_XML, "application/vnd.syncml.dm+xml" }, 187 { ContentTypes::APPLICATION_VND_SYNCML_NOTIFICATION, "application/vnd.syncml.notification" }, 188 { ContentTypes::APPLICATION_VND_WAP_XHTML_XML, "application/vnd.wap.xhtml+xml" }, 189 { ContentTypes::APPLICATION_VND_WV_CSP_CIR, "application/vnd.wv.csp.cir" }, 190 { ContentTypes::APPLICATION_VND_OMA_DD_XML, "application/vnd.oma.dd+xml" }, 191 { ContentTypes::APPLICATION_VND_OMA_DRM_MESSAGE, "application/vnd.oma.drm.message" }, 192 { ContentTypes::APPLICATION_VND_OMA_DRM_CONTENT, "application/vnd.oma.drm.content" }, 193 { ContentTypes::APPLICATION_VND_OMA_DRM_RIGHTS_XML, "application/vnd.oma.drm.rights+xml" }, 194 { ContentTypes::APPLICATION_VND_OMA_DRM_RIGHTS_WBXML, "application/vnd.oma.drm.rights+wbxml" }, 195 { ContentTypes::APPLICATION_VND_WV_CSP_XML, "application/vnd.wv.csp+xml" }, 196 { ContentTypes::APPLICATION_VND_WV_CSP_WBXML, "application/vnd.wv.csp+wbxml" }, 197 { ContentTypes::APPLICATION_VND_SYNCML_DS_NOTIFICATION, "application/vnd.syncml.ds.notification" }, 198 { ContentTypes::AUDIO_X, "audio/*" }, 199 { ContentTypes::VIDEO_X, "video/*" }, 200 { ContentTypes::APPLICATION_VND_OMA_DD2_XML, "application/vnd.oma.dd2+xml" }, 201 { ContentTypes::APPLICATION_MIKEY, "application/mikey" }, 202 { ContentTypes::APPLICATION_VND_OMA_DCD, "application/vnd.oma.dcd" }, 203 { ContentTypes::APPLICATION_VND_OMA_DCDC, "application/vnd.oma.dcdc" }, 204 }; 205 206 class MmsContentType { 207 public: 208 MmsContentType() = default; 209 ~MmsContentType() = default; 210 MmsContentType(const MmsContentType &srcContentType); 211 MmsContentType& operator=(const MmsContentType& srcContentType); 212 void DumpMmsContentType(); 213 bool DecodeMmsContentType(MmsDecodeBuffer &decodeBuffer, int32_t &len); 214 bool DecodeMmsCTGeneralForm(MmsDecodeBuffer &decodeBuffer, int32_t &contentLength); 215 bool DecodeParameter(MmsDecodeBuffer &decodeBuffer, int32_t valueLength); 216 bool DecodeTextField(MmsDecodeBuffer &decodeBuffer, uint8_t field, int32_t &valueLength); 217 bool DecodeCharsetField(MmsDecodeBuffer &decodeBuffer, int32_t &valueLength); 218 bool DecodeTypeField(MmsDecodeBuffer &decodeBuffer, int32_t &valueLength); 219 220 bool EncodeTextField(MmsEncodeBuffer &encodeBuffer); 221 bool EncodeCharsetField(MmsEncodeBuffer &encodeBuffer); 222 bool EncodeTypeField(MmsEncodeBuffer &encodeBuffer); 223 bool EncodeMmsBodyPartContentType(MmsEncodeBuffer &encodeBuffer); 224 bool EncodeMmsBodyPartContentParam(MmsEncodeBuffer &encodeBuffer); 225 public: 226 static int8_t GetContentTypeFromString(std::string str); 227 static std::string GetContentTypeFromInt(uint8_t type); 228 bool GetContentType(std::string &str); 229 bool SetContentType(std::string str); 230 bool SetContentParam(MmsContentParam &contentParam); 231 MmsContentParam &GetContentParam(); 232 private: 233 std::string contentType_; 234 MmsContentParam msgContentParm_; 235 }; 236 } // namespace Telephony 237 } // namespace OHOS 238 #endif 239