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 NAPI_MMS_H 17 #define NAPI_MMS_H 18 #include <codecvt> 19 #include <locale> 20 #include <string> 21 #include <vector> 22 #include <cstring> 23 #include <memory> 24 25 #include "napi/native_api.h" 26 #include "napi/native_node_api.h" 27 #include "i_sms_service_interface.h" 28 #include "base_context.h" 29 #include "short_message.h" 30 #include "napi_sms.h" 31 32 #include "mms_msg.h" 33 #include "mms_address.h" 34 #include "mms_attachment.h" 35 #include "telephony_log_wrapper.h" 36 #include "napi_util.h" 37 #include "mms_codec_type.h" 38 #include "mms_header.h" 39 40 namespace OHOS { 41 namespace Telephony { 42 enum MessageType { 43 TYPE_MMS_SEND_REQ = 128, 44 TYPE_MMS_SEND_CONF, 45 TYPE_MMS_NOTIFICATION_IND, 46 TYPE_MMS_RESP_IND, 47 TYPE_MMS_RETRIEVE_CONF, 48 TYPE_MMS_ACKNOWLEDGE_IND, 49 TYPE_MMS_DELIVERY_IND, 50 TYPE_MMS_READ_REC_IND, 51 TYPE_MMS_READ_ORIG_IND, 52 }; 53 54 enum DispositionValue { 55 FROM_DATA = 0, 56 ATTACHMENT, 57 INLINE, 58 }; 59 60 struct MmsAddressContext { 61 std::string address; 62 int32_t charset = DEFAULT_ERROR; 63 }; 64 65 struct MmsAttachmentContext { 66 std::string path; 67 std::string fileName; 68 std::string contentId; 69 std::string contentLocation; 70 std::string contentDisposition; 71 std::string contentTransferEncoding; 72 std::string contentType; 73 bool isSmil = false; 74 uint32_t inBuffLen; 75 std::unique_ptr<char[]> inBuff; 76 int32_t charset = DEFAULT_ERROR; 77 }; 78 79 struct MmsSendConfContext { 80 uint8_t responseState; 81 std::string transactionId; 82 uint16_t version; 83 std::string messageId; 84 }; 85 86 struct MmsSendReqContext { 87 MmsAddress from; 88 std::vector<MmsAddress> to; 89 std::string transactionId; 90 uint16_t version = DEFAULT_ERROR; 91 int64_t date; 92 std::vector<MmsAddress> cc; 93 std::vector<MmsAddress> bcc; 94 std::string subject; 95 uint8_t messageClass; 96 int32_t expiry = DEFAULT_ERROR; 97 uint8_t priority = DEFAULT_ERROR; 98 uint8_t senderVisibility; 99 uint8_t deliveryReport; 100 uint8_t readReport; 101 std::string contentType; 102 }; 103 104 struct MmsNotificationIndContext { 105 std::string transactionId; 106 uint8_t messageClass; 107 int64_t messageSize; 108 int32_t expiry; 109 uint16_t version; 110 MmsAddress from; 111 std::string subject; 112 uint8_t deliveryReport; 113 std::string contentLocation; 114 uint8_t contentClass; 115 uint32_t charset; 116 }; 117 118 struct MmsRespIndContext { 119 std::string transactionId; 120 uint8_t status; 121 uint16_t version; 122 uint8_t reportAllowed; 123 }; 124 125 struct MmsRetrieveConfContext { 126 std::string transactionId; 127 std::string messageId; 128 int64_t date; 129 uint16_t version; 130 std::vector<MmsAddress> to; 131 MmsAddress from; 132 std::vector<MmsAddress> cc; 133 std::string subject; 134 uint8_t priority; 135 uint8_t deliveryReport; 136 uint8_t readReport; 137 uint8_t retrieveStatus; 138 std::string retrieveText; 139 std::string contentType; 140 int32_t message; 141 }; 142 143 struct MmsAcknowledgeIndContext { 144 std::string transactionId; 145 uint16_t version; 146 uint8_t reportAllowed; 147 }; 148 149 struct MmsDeliveryIndContext { 150 std::string messageId; 151 int64_t date; 152 std::vector<MmsAddress> to; 153 uint8_t status; 154 uint16_t version; 155 }; 156 157 struct MmsReadOrigIndContext { 158 uint16_t version; 159 std::string messageId; 160 std::vector<MmsAddress> to; 161 MmsAddress from; 162 int64_t date; 163 uint8_t readStatus; 164 }; 165 166 struct MmsReadRecIndContext { 167 uint16_t version; 168 std::string messageId; 169 std::vector<MmsAddress> to; 170 MmsAddress from; 171 int64_t date; 172 uint8_t readStatus; 173 }; 174 175 struct DecodeMmsContext : BaseContext { 176 int32_t messageType = DEFAULT_ERROR; 177 int32_t messageMatchResult; 178 std::string textFilePath = ""; 179 std::unique_ptr<char[]> inBuffer = nullptr; 180 uint32_t inLen; 181 std::vector<MmsAttachmentContext> attachment; 182 struct MmsSendConfContext sendConf; 183 struct MmsSendReqContext sendReq; 184 struct MmsNotificationIndContext notificationInd; 185 struct MmsRespIndContext respInd; 186 struct MmsRetrieveConfContext retrieveConf; 187 struct MmsAcknowledgeIndContext acknowledgeInd; 188 struct MmsDeliveryIndContext deliveryInd; 189 struct MmsReadOrigIndContext readOrigInd; 190 struct MmsReadRecIndContext readRecInd; 191 }; 192 193 struct EncodeMmsContext : BaseContext { 194 int32_t messageType = DEFAULT_ERROR; 195 std::unique_ptr<char[]> outBuffer = nullptr; 196 uint32_t bufferLen; 197 std::vector<MmsAttachmentContext> attachment; 198 struct MmsSendConfContext sendConf; 199 struct MmsSendReqContext sendReq; 200 struct MmsNotificationIndContext notificationInd; 201 struct MmsRespIndContext respInd; 202 struct MmsRetrieveConfContext retrieveConf; 203 struct MmsAcknowledgeIndContext acknowledgeInd; 204 struct MmsDeliveryIndContext deliveryInd; 205 struct MmsReadOrigIndContext readOrigInd; 206 struct MmsReadRecIndContext readRecInd; 207 }; 208 209 class NapiMms { 210 public: 211 NapiMms(); 212 ~NapiMms() = default; 213 214 static napi_value DecodeMms(napi_env env, napi_callback_info info); 215 static napi_value EncodeMms(napi_env env, napi_callback_info info); 216 static napi_value InitEnumMmsCharSets(napi_env env, napi_value exports); 217 static napi_value InitEnumMessageType(napi_env env, napi_value exports); 218 static napi_value InitEnumPriorityType(napi_env env, napi_value exports); 219 static napi_value InitEnumVersionType(napi_env env, napi_value exports); 220 static napi_value InitEnumDispositionType(napi_env env, napi_value exports); 221 static napi_value InitEnumReportAllowedType(napi_env env, napi_value exports); 222 static napi_value InitSupportEnumMmsCharSets(napi_env env, napi_value exports); 223 static napi_value InitSupportEnumMessageType(napi_env env, napi_value exports); 224 static napi_value InitSupportEnumPriorityType(napi_env env, napi_value exports); 225 static napi_value InitSupportEnumVersionType(napi_env env, napi_value exports); 226 static napi_value InitSupportEnumDispositionType(napi_env env, napi_value exports); 227 static napi_value InitSupportEnumReportAllowedType(napi_env env, napi_value exports); 228 }; 229 } // namespace Telephony 230 } // namespace OHOS 231 #endif // NAPI_SMS_H