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 SMS_WAP_PUSH_CONTENT_TYPE_H 17 #define SMS_WAP_PUSH_CONTENT_TYPE_H 18 19 #include <map> 20 21 #include "sms_wap_push_buffer.h" 22 23 namespace OHOS { 24 namespace Telephony { 25 enum class WapPushContentTypes { 26 X_X = 0x00, 27 TEXT_X = 0x01, 28 TEXT_HTML = 0x02, 29 TEXT_PLAIN = 0x03, 30 TEXT_X_HDML = 0x04, 31 TEXT_X_TTML = 0x05, 32 TEXT_X_VCALENDAR = 0x06, 33 TEXT_X_VCARD = 0x07, 34 TEXT_VND_WAP_WML = 0x08, 35 TEXT_VND_WAP_WMLSCRIPT = 0x09, 36 TEXT_VND_WAP_WTA_EVENT = 0x0A, 37 MULTIPART_X = 0x0B, 38 MULTIPART_MIXED = 0x0C, 39 MULTIPART_FORM_DATA = 0x0D, 40 MULTIPART_BYTERANTES = 0x0E, 41 MULTIPART_ALTERNATIVE = 0x0F, 42 APPLICATION_X = 0x10, 43 APPLICATION_JAVA_VM = 0x11, 44 APPLICATION_X_WWW_FORM_URLENCODED = 0x12, 45 APPLICATION_X_HDMLC = 0x13, 46 APPLICATION_VND_WAP_WMLC = 0x14, 47 APPLICATION_VND_WAP_WMLSCRIPTC = 0x15, 48 APPLICATION_VND_WAP_WTA_EVENTC = 0x16, 49 APPLICATION_VND_WAP_UAPROF = 0x17, 50 APPLICATION_VND_WAP_WTLS_CA_CERTIFICATE = 0x18, 51 APPLICATION_VND_WAP_WTLS_USER_CERTIFICATE = 0x19, 52 APPLICATION_X_X509_CA_CERT = 0x1A, 53 APPLICATION_X_X509_USER_CERT = 0x1B, 54 IMAGE_X = 0x1C, 55 IMAGE_GIF = 0x1D, 56 IMAGE_JPEG = 0x1E, 57 IMAGE_TIFF = 0x1F, 58 IMAGE_PNG = 0x20, 59 IMAGE_VND_WAP_WBMP = 0x21, 60 APPLICATION_VND_WAP_MULTIPART_X = 0x22, 61 APPLICATION_VND_WAP_MULTIPART_MIXED = 0x23, 62 APPLICATION_VND_WAP_MULTIPART_FORM_DATA = 0x24, 63 APPLICATION_VND_WAP_MULTIPART_BYTERANGES = 0x25, 64 APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE = 0x26, 65 APPLICATION_XML = 0x27, 66 TEXT_XML = 0x28, 67 APPLICATION_VND_WAP_WBXML = 0x29, 68 APPLICATION_X_X968_CROSS_CERT = 0x2A, 69 APPLICATION_X_X968_CA_CERT = 0x2B, 70 APPLICATION_X_X968_USER_CERT = 0x2C, 71 TEXT_VND_WAP_SI = 0x2D, 72 APPLICATION_VND_WAP_SIC = 0x2E, 73 TEXT_VND_WAP_SL = 0x2F, 74 APPLICATION_VND_WAP_SLC = 0x30, 75 TEXT_VND_WAP_CO = 0x31, 76 APPLICATION_VND_WAP_COC = 0x32, 77 APPLICATION_VND_WAP_MULTIPART_RELATED = 0x33, 78 APPLICATION_VND_WAP_SIA = 0x34, 79 TEXT_VND_WAP_CONNECTIVITY_XML = 0x35, 80 APPLICATION_VND_WAP_CONNECTIVITY_WBXML = 0x36, 81 APPLICATION_PKCS7_MIME = 0x37, 82 APPLICATION_VND_WAP_HASHED_CERTIFICATE = 0x38, 83 APPLICATION_VND_WAP_SIGNED_CERTIFICATE = 0x39, 84 APPLICATION_VND_WAP_CERT_RESPONSE = 0x3A, 85 APPLICATION_XHTML_XML = 0x3B, 86 APPLICATION_WML_XML = 0x3C, 87 TEXT_CSS = 0x3D, 88 APPLICATION_VND_WAP_MMS_MESSAGE = 0x3E, 89 APPLICATION_VND_WAP_ROLLOVER_CERTIFICATE = 0x3F, 90 APPLICATION_VND_WAP_LOCC_WBXML = 0x40, 91 APPLICATION_VND_WAP_LOC_XML = 0x41, 92 APPLICATION_VND_SYNCML_DM_WBXML = 0x42, 93 APPLICATION_VND_SYNCML_DM_XML = 0x43, 94 APPLICATION_VND_SYNCML_NOTIFICATION = 0x44, 95 APPLICATION_VND_WAP_XHTML_XML = 0x45, 96 APPLICATION_VND_WV_CSP_CIR = 0x46, 97 APPLICATION_VND_OMA_DD_XML = 0x47, 98 APPLICATION_VND_OMA_DRM_MESSAGE = 0x48, 99 APPLICATION_VND_OMA_DRM_CONTENT = 0x49, 100 APPLICATION_VND_OMA_DRM_RIGHTS_XML = 0x4A, 101 APPLICATION_VND_OMA_DRM_RIGHTS_WBXML = 0x4B, 102 APPLICATION_VND_WV_CSP_XML = 0x4C, 103 APPLICATION_VND_WV_CSP_WBXML = 0x4D, 104 APPLICATION_VND_SYNCML_DS_NOTIFICATION = 0x4E, 105 AUDIO_X = 0x4F, 106 VIDEO_X = 0x50, 107 APPLICATION_VND_OMA_DD2_XML = 0x51, 108 APPLICATION_MIKEY = 0x52, 109 APPLICATION_VND_OMA_DCD = 0x53, 110 APPLICATION_VND_OMA_DCDC = 0x54, 111 CONTENT_TYPE_UNDOWN = 0xFF 112 }; 113 114 struct WapKeyValue { 115 WapPushContentTypes key = WapPushContentTypes::X_X; 116 const char *value = nullptr; 117 }; 118 119 static const WapKeyValue wapContentNames[] = { 120 { WapPushContentTypes::X_X, "*/*" }, 121 { WapPushContentTypes::TEXT_X, "text/*" }, 122 { WapPushContentTypes::TEXT_HTML, "text/html" }, 123 { WapPushContentTypes::TEXT_PLAIN, "text/plain" }, 124 { WapPushContentTypes::TEXT_X_HDML, "text/x-hdml" }, 125 { WapPushContentTypes::TEXT_X_TTML, "text/x-ttml" }, 126 { WapPushContentTypes::TEXT_X_VCALENDAR, "text/x-vCalendar" }, 127 { WapPushContentTypes::TEXT_X_VCARD, "text/x-vCard" }, 128 { WapPushContentTypes::TEXT_VND_WAP_WML, "text/vnd.wap.wml" }, 129 { WapPushContentTypes::TEXT_VND_WAP_WMLSCRIPT, "text/vnd.wap.wmlscript" }, 130 { WapPushContentTypes::TEXT_VND_WAP_WTA_EVENT, "text/vnd.wap.wta-event" }, 131 { WapPushContentTypes::MULTIPART_X, "multipart/*" }, 132 { WapPushContentTypes::MULTIPART_MIXED, "multipart/mixed" }, 133 { WapPushContentTypes::MULTIPART_FORM_DATA, "multipart/form-data" }, 134 { WapPushContentTypes::MULTIPART_BYTERANTES, "multipart/byterantes" }, 135 { WapPushContentTypes::MULTIPART_ALTERNATIVE, "multipart/alternative" }, 136 { WapPushContentTypes::APPLICATION_X, "application/*" }, 137 { WapPushContentTypes::APPLICATION_JAVA_VM, "application/java-vm" }, 138 { WapPushContentTypes::APPLICATION_X_WWW_FORM_URLENCODED, "application/x-www-form-urlencoded" }, 139 { WapPushContentTypes::APPLICATION_X_HDMLC, "application/x-hdmlc" }, 140 { WapPushContentTypes::APPLICATION_VND_WAP_WMLC, "application/vnd.wap.wmlc" }, 141 { WapPushContentTypes::APPLICATION_VND_WAP_WMLSCRIPTC, "application/vnd.wap.wmlscriptc" }, 142 { WapPushContentTypes::APPLICATION_VND_WAP_WTA_EVENTC, "application/vnd.wap.wta-eventc" }, 143 { WapPushContentTypes::APPLICATION_VND_WAP_UAPROF, "application/vnd.wap.uaprof" }, 144 { WapPushContentTypes::APPLICATION_VND_WAP_WTLS_CA_CERTIFICATE, "application/vnd.wap.wtls-ca-certificate" }, 145 { WapPushContentTypes::APPLICATION_VND_WAP_WTLS_USER_CERTIFICATE, "application/vnd.wap.wtls-user-certificate" }, 146 { WapPushContentTypes::APPLICATION_X_X509_CA_CERT, "application/x-x509-ca-cert" }, 147 { WapPushContentTypes::APPLICATION_X_X509_USER_CERT, "application/x-x509-user-cert" }, 148 { WapPushContentTypes::IMAGE_X, "image/*" }, 149 { WapPushContentTypes::IMAGE_GIF, "image/gif" }, 150 { WapPushContentTypes::IMAGE_JPEG, "image/jpeg" }, 151 { WapPushContentTypes::IMAGE_TIFF, "image/tiff" }, 152 { WapPushContentTypes::IMAGE_PNG, "image/png" }, 153 { WapPushContentTypes::IMAGE_VND_WAP_WBMP, "image/vnd.wap.wbmp" }, 154 { WapPushContentTypes::APPLICATION_VND_WAP_MULTIPART_X, "application/vnd.wap.multipart.*" }, 155 { WapPushContentTypes::APPLICATION_VND_WAP_MULTIPART_MIXED, "application/vnd.wap.multipart.mixed" }, 156 { WapPushContentTypes::APPLICATION_VND_WAP_MULTIPART_FORM_DATA, "application/vnd.wap.multipart.form-data" }, 157 { WapPushContentTypes::APPLICATION_VND_WAP_MULTIPART_BYTERANGES, "application/vnd.wap.multipart.byteranges" }, 158 { WapPushContentTypes::APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE, "application/vnd.wap.multipart.alternative" }, 159 { WapPushContentTypes::APPLICATION_XML, "application/xml" }, 160 { WapPushContentTypes::TEXT_XML, "text/xml" }, 161 { WapPushContentTypes::APPLICATION_VND_WAP_WBXML, "application/vnd.wap.wbxml" }, 162 { WapPushContentTypes::APPLICATION_X_X968_CROSS_CERT, "application/x-x968-cross-cert" }, 163 { WapPushContentTypes::APPLICATION_X_X968_CA_CERT, "application/x-x968-ca-cert" }, 164 { WapPushContentTypes::APPLICATION_X_X968_USER_CERT, "application/x-x968-user-cert" }, 165 { WapPushContentTypes::TEXT_VND_WAP_SI, "text/vnd.wap.si" }, 166 { WapPushContentTypes::APPLICATION_VND_WAP_SIC, "application/vnd.wap.sic" }, 167 { WapPushContentTypes::TEXT_VND_WAP_SL, "text/vnd.wap.sl" }, 168 { WapPushContentTypes::APPLICATION_VND_WAP_SLC, "application/vnd.wap.slc" }, 169 { WapPushContentTypes::TEXT_VND_WAP_CO, "text/vnd.wap.co" }, 170 { WapPushContentTypes::APPLICATION_VND_WAP_COC, "application/vnd.wap.coc" }, 171 { WapPushContentTypes::APPLICATION_VND_WAP_MULTIPART_RELATED, "application/vnd.wap.multipart.related" }, 172 { WapPushContentTypes::APPLICATION_VND_WAP_SIA, "application/vnd.wap.sia" }, 173 { WapPushContentTypes::TEXT_VND_WAP_CONNECTIVITY_XML, "text/vnd.wap.connectivity-xml" }, 174 { WapPushContentTypes::APPLICATION_VND_WAP_CONNECTIVITY_WBXML, "application/vnd.wap.connectivity-wbxml" }, 175 { WapPushContentTypes::APPLICATION_PKCS7_MIME, "application/pkcs7-mime" }, 176 { WapPushContentTypes::APPLICATION_VND_WAP_HASHED_CERTIFICATE, "application/vnd.wap.hashed-certificate" }, 177 { WapPushContentTypes::APPLICATION_VND_WAP_SIGNED_CERTIFICATE, "application/vnd.wap.signed-certificate" }, 178 { WapPushContentTypes::APPLICATION_VND_WAP_CERT_RESPONSE, "application/vnd.wap.cert-response" }, 179 { WapPushContentTypes::APPLICATION_XHTML_XML, "application/xhtml+xml" }, 180 { WapPushContentTypes::APPLICATION_WML_XML, "application/wml+xml" }, 181 { WapPushContentTypes::TEXT_CSS, "text/css" }, 182 { WapPushContentTypes::APPLICATION_VND_WAP_MMS_MESSAGE, "application/vnd.wap.mms-message" }, 183 { WapPushContentTypes::APPLICATION_VND_WAP_ROLLOVER_CERTIFICATE, "application/vnd.wap.rollover-certificate" }, 184 { WapPushContentTypes::APPLICATION_VND_WAP_LOCC_WBXML, "application/vnd.wap.locc+wbxml" }, 185 { WapPushContentTypes::APPLICATION_VND_WAP_LOC_XML, "application/vnd.wap.loc+xml" }, 186 { WapPushContentTypes::APPLICATION_VND_SYNCML_DM_WBXML, "application/vnd.syncml.dm+wbxml" }, 187 { WapPushContentTypes::APPLICATION_VND_SYNCML_DM_XML, "application/vnd.syncml.dm+xml" }, 188 { WapPushContentTypes::APPLICATION_VND_SYNCML_NOTIFICATION, "application/vnd.syncml.notification" }, 189 { WapPushContentTypes::APPLICATION_VND_WAP_XHTML_XML, "application/vnd.wap.xhtml+xml" }, 190 { WapPushContentTypes::APPLICATION_VND_WV_CSP_CIR, "application/vnd.wv.csp.cir" }, 191 { WapPushContentTypes::APPLICATION_VND_OMA_DD_XML, "application/vnd.oma.dd+xml" }, 192 { WapPushContentTypes::APPLICATION_VND_OMA_DRM_MESSAGE, "application/vnd.oma.drm.message" }, 193 { WapPushContentTypes::APPLICATION_VND_OMA_DRM_CONTENT, "application/vnd.oma.drm.content" }, 194 { WapPushContentTypes::APPLICATION_VND_OMA_DRM_RIGHTS_XML, "application/vnd.oma.drm.rights+xml" }, 195 { WapPushContentTypes::APPLICATION_VND_OMA_DRM_RIGHTS_WBXML, "application/vnd.oma.drm.rights+wbxml" }, 196 { WapPushContentTypes::APPLICATION_VND_WV_CSP_XML, "application/vnd.wv.csp+xml" }, 197 { WapPushContentTypes::APPLICATION_VND_WV_CSP_WBXML, "application/vnd.wv.csp+wbxml" }, 198 { WapPushContentTypes::APPLICATION_VND_SYNCML_DS_NOTIFICATION, "application/vnd.syncml.ds.notification" }, 199 { WapPushContentTypes::AUDIO_X, "audio/*" }, 200 { WapPushContentTypes::VIDEO_X, "video/*" }, 201 { WapPushContentTypes::APPLICATION_VND_OMA_DD2_XML, "application/vnd.oma.dd2+xml" }, 202 { WapPushContentTypes::APPLICATION_MIKEY, "application/mikey" }, 203 { WapPushContentTypes::APPLICATION_VND_OMA_DCD, "application/vnd.oma.dcd" }, 204 { WapPushContentTypes::APPLICATION_VND_OMA_DCDC, "application/vnd.oma.dcdc" }, 205 }; 206 207 /** 208 * wap-230-wsp-20010705-a section:Table 38. Well-Known Parameter Assignments 209 */ 210 enum class WapContentParam { 211 // Encoding Version 1.1 212 CT_P_Q = 0x80, /* Q */ 213 CT_P_CHARSET = 0x81, /* Charset */ 214 CT_P_LEVEL = 0x82, /* Level */ 215 CT_P_TYPE = 0x83, /* Type */ 216 CT_P_NAME = 0x85, /* Name */ 217 CT_P_FILENAME = 0x86, /* Filename */ 218 CT_P_DIFFERENCES = 0x87, /* Differences */ 219 CT_P_PADDING = 0x88, /* Padding */ 220 // Encoding Version 1.2 221 CT_P_TYPE_STRING = 0x89, /* Type */ 222 CT_P_START = 0x8A, /* Start Text-string */ 223 CT_P_START_INFO = 0x8B, /* Start-info Text-string */ 224 // Encoding Version 1.3 225 CT_P_COMMENT = 0x8C, /* Comment */ 226 CT_P_DOMAIN = 0x8D, /* Domain */ 227 CT_P_MAX_AGE = 0x8E, /* Max-Age */ 228 CT_P_PATH = 0x8F, /* Path */ 229 CT_P_SECURE = 0x90, /* Secure */ 230 // Encoding Version 1.4 231 CT_P_SEC = 0x91, /* SEC */ 232 CT_P_MAC = 0x92, /* MAC */ 233 CT_P_CREATION_DATE = 0x93, /* Creation-date */ 234 CT_P_MODIFICATION_DATE = 0x94, /* Modification-date */ 235 CT_P_READ_DATE = 0x95, /* Read-date */ 236 CT_P_SIZE = 0x96, /* Size */ 237 CT_P_NAME_VALUE = 0x97, /* Name */ 238 CT_P_FILENAME_VALUE = 0x98, /* Filename */ 239 CT_P_START_VALUE = 0x99, /* Start Text-value */ 240 CT_P_START_INFO_VALUE = 0x9A, /* Start-info Text-value */ 241 CT_P_COMMENT_VALUE = 0x9B, /* Comment */ 242 CT_P_DOMAIN_VALUE = 0x9C, /* Domain */ 243 CT_P_PATH_VALUE = 0x9D, /* Path */ 244 }; 245 246 class SmsWapPushContentType { 247 public: 248 SmsWapPushContentType(); 249 ~SmsWapPushContentType() = default; 250 bool DecodeContentType(SmsWapPushBuffer &decodeBuffer, int32_t &len); 251 bool DecodeCTGeneralForm(SmsWapPushBuffer &decodeBuffer, int32_t &contentLength); 252 bool DecodeParameter(SmsWapPushBuffer &decodeBuffer, int32_t valueLength); 253 bool DecodeTextField(SmsWapPushBuffer &decodeBuffer, uint8_t field, int32_t &valueLength); 254 bool DecodeCharsetField(SmsWapPushBuffer &decodeBuffer, int32_t &valueLength); 255 bool DecodeTypeField(SmsWapPushBuffer &decodeBuffer, int32_t &valueLength); 256 257 public: 258 bool GetCharSetIntFromString(uint32_t &charSet, const std::string &strCharSet); 259 static std::string GetContentTypeFromInt(uint8_t type); 260 std::string GetContentType(); 261 bool SetContentType(std::string str); 262 263 private: 264 std::string contentType_ = ""; 265 uint32_t charset_ = 0; 266 std::string type_ = ""; 267 std::map<uint8_t, std::string> textParameterMap_; 268 std::map<std::string, uint32_t> mapCharSet_; 269 }; 270 } // namespace Telephony 271 } // namespace OHOS 272 #endif 273