1 /* 2 * Copyright (c) 2024 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 APPSPAWN_CLIENT_MSG_H 17 #define APPSPAWN_CLIENT_MSG_H 18 19 #include <stdint.h> 20 #include <stdio.h> 21 #include <stdlib.h> 22 23 #include "appspawn.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #define NWEBSPAWN_SOCKET_NAME "NWebSpawn" 30 #define APPSPAWN_SOCKET_NAME "AppSpawn" 31 #define CJAPPSPAWN_SOCKET_NAME "CJAppSpawn" 32 #define KEEPALIVE_NAME "keepalive" 33 #define NATIVESPAWN_SOCKET_NAME "NativeSpawn" 34 #define SPAWN_LISTEN_FD_NAME "SpawnListenFd" 35 #define HYBRIDSPAWN_SOCKET_NAME "HybridSpawn" 36 37 #define APPSPAWN_ALIGN(len) (((len) + 0x03) & (~0x03)) 38 #define APPSPAWN_TLV_NAME_LEN 32 39 #define MAX_MSG_BLOCK_LEN (4 * 1024) 40 #define RECV_BLOCK_LEN 1024 41 #define MAX_MSG_TOTAL_LENGTH (64 * 1024) 42 #define EXTRAINFO_TOTAL_LENGTH_MAX (32 * 1024) 43 #define MAX_TLV_COUNT 128 44 #define APPSPAWN_MSG_MAGIC 0xEF201234 45 46 #define APP_LEN_PROC_NAME 256 // process name length 47 #define APP_LEN_BUNDLE_NAME 256 // bundle name length 48 #define APP_LEN_SO_PATH 256 // load so lib 49 #define APP_APL_MAX_LEN 32 50 #define APP_RENDER_CMD_MAX_LEN 2048 51 #define APP_OWNER_ID_LEN 64 52 53 typedef enum { 54 TLV_BUNDLE_INFO = 0, 55 TLV_MSG_FLAGS, 56 TLV_DAC_INFO, 57 TLV_DOMAIN_INFO, 58 TLV_OWNER_INFO, 59 TLV_ACCESS_TOKEN_INFO, 60 TLV_PERMISSION, 61 TLV_INTERNET_INFO, 62 TLV_RENDER_TERMINATION_INFO, 63 TLV_MAX 64 } AppSpawnMsgTlvType; 65 66 #define DATA_TYPE_STRING 1 67 68 #if defined(__clang__) 69 # pragma clang diagnostic push 70 # pragma clang diagnostic ignored "-Wextern-c-compat" 71 #elif defined(__GNUC__) 72 # pragma GCC diagnostic push 73 # pragma GCC diagnostic ignored "-Wextern-c-compat" 74 #elif defined(_MSC_VER) 75 # pragma warning(push) 76 #endif 77 78 #pragma pack(4) 79 typedef AppDacInfo AppSpawnMsgDacInfo; 80 81 typedef struct { 82 uint16_t tlvLen; 83 uint16_t tlvType; 84 } AppSpawnTlv; 85 86 typedef struct { 87 uint16_t tlvLen; // 对齐后的长度 88 uint16_t tlvType; 89 uint16_t dataLen; // 数据的长度 90 uint16_t dataType; 91 char tlvName[APPSPAWN_TLV_NAME_LEN]; 92 } AppSpawnTlvExt; 93 94 typedef struct { 95 uint32_t count; 96 uint32_t flags[0]; 97 } AppSpawnMsgFlags; 98 99 typedef struct { 100 uint64_t accessTokenIdEx; 101 } AppSpawnMsgAccessToken; 102 103 typedef struct { 104 char ownerId[0]; // app identifier id 105 } AppSpawnMsgOwnerId; 106 107 typedef struct { 108 uint8_t setAllowInternet; 109 uint8_t allowInternet; // hap sockect allowed 110 uint8_t res[2]; 111 } AppSpawnMsgInternetInfo; 112 113 typedef struct { 114 uint32_t hapFlags; 115 char apl[0]; 116 } AppSpawnMsgDomainInfo; 117 118 typedef struct { 119 uint32_t bundleIndex; 120 char bundleName[0]; // process name 121 } AppSpawnMsgBundleInfo; 122 123 typedef struct TagAppSpawnMsg { 124 uint32_t magic; 125 uint32_t msgType; 126 uint32_t msgLen; 127 uint32_t msgId; 128 uint32_t tlvCount; 129 char processName[APP_LEN_PROC_NAME]; 130 } AppSpawnMsg; 131 132 typedef struct { 133 AppSpawnMsg msgHdr; 134 AppSpawnResult result; 135 } AppSpawnResponseMsg; 136 #pragma pack() 137 138 #if defined(__clang__) 139 # pragma clang diagnostic pop 140 #elif defined(__GNUC__) 141 # pragma GCC diagnostic pop 142 #elif defined(_MSC_VER) 143 # pragma warning(pop) 144 #endif 145 146 #ifdef __cplusplus 147 } 148 #endif 149 #endif // APPSPAWN_CLIENT_MSG_H 150