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