169570cc8Sopenharmony_ci/*
269570cc8Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
369570cc8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
469570cc8Sopenharmony_ci * you may not use this file except in compliance with the License.
569570cc8Sopenharmony_ci * You may obtain a copy of the License at
669570cc8Sopenharmony_ci *
769570cc8Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
869570cc8Sopenharmony_ci *
969570cc8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1069570cc8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1169570cc8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1269570cc8Sopenharmony_ci * See the License for the specific language governing permissions and
1369570cc8Sopenharmony_ci * limitations under the License.
1469570cc8Sopenharmony_ci */
1569570cc8Sopenharmony_ci
1669570cc8Sopenharmony_ci#ifndef APPSPAWN_CLIENT_MSG_H
1769570cc8Sopenharmony_ci#define APPSPAWN_CLIENT_MSG_H
1869570cc8Sopenharmony_ci
1969570cc8Sopenharmony_ci#include <stdint.h>
2069570cc8Sopenharmony_ci#include <stdio.h>
2169570cc8Sopenharmony_ci#include <stdlib.h>
2269570cc8Sopenharmony_ci
2369570cc8Sopenharmony_ci#include "appspawn.h"
2469570cc8Sopenharmony_ci
2569570cc8Sopenharmony_ci#ifdef __cplusplus
2669570cc8Sopenharmony_ciextern "C" {
2769570cc8Sopenharmony_ci#endif
2869570cc8Sopenharmony_ci
2969570cc8Sopenharmony_ci#define NWEBSPAWN_SOCKET_NAME "NWebSpawn"
3069570cc8Sopenharmony_ci#define APPSPAWN_SOCKET_NAME "AppSpawn"
3169570cc8Sopenharmony_ci#define CJAPPSPAWN_SOCKET_NAME "CJAppSpawn"
3269570cc8Sopenharmony_ci#define KEEPALIVE_NAME "keepalive"
3369570cc8Sopenharmony_ci#define NATIVESPAWN_SOCKET_NAME "NativeSpawn"
3469570cc8Sopenharmony_ci
3569570cc8Sopenharmony_ci#define APPSPAWN_ALIGN(len) (((len) + 0x03) & (~0x03))
3669570cc8Sopenharmony_ci#define APPSPAWN_TLV_NAME_LEN 32
3769570cc8Sopenharmony_ci#define MAX_MSG_BLOCK_LEN (4 * 1024)
3869570cc8Sopenharmony_ci#define RECV_BLOCK_LEN 1024
3969570cc8Sopenharmony_ci#define MAX_MSG_TOTAL_LENGTH (64 * 1024)
4069570cc8Sopenharmony_ci#define EXTRAINFO_TOTAL_LENGTH_MAX (32 * 1024)
4169570cc8Sopenharmony_ci#define MAX_TLV_COUNT 128
4269570cc8Sopenharmony_ci#define APPSPAWN_MSG_MAGIC 0xEF201234
4369570cc8Sopenharmony_ci
4469570cc8Sopenharmony_ci#define APP_LEN_PROC_NAME 256    // process name length
4569570cc8Sopenharmony_ci#define APP_LEN_BUNDLE_NAME 256  // bundle name length
4669570cc8Sopenharmony_ci#define APP_LEN_SO_PATH 256      // load so lib
4769570cc8Sopenharmony_ci#define APP_APL_MAX_LEN 32
4869570cc8Sopenharmony_ci#define APP_RENDER_CMD_MAX_LEN 2048
4969570cc8Sopenharmony_ci#define APP_OWNER_ID_LEN 64
5069570cc8Sopenharmony_ci
5169570cc8Sopenharmony_citypedef enum {
5269570cc8Sopenharmony_ci    TLV_BUNDLE_INFO = 0,
5369570cc8Sopenharmony_ci    TLV_MSG_FLAGS,
5469570cc8Sopenharmony_ci    TLV_DAC_INFO,
5569570cc8Sopenharmony_ci    TLV_DOMAIN_INFO,
5669570cc8Sopenharmony_ci    TLV_OWNER_INFO,
5769570cc8Sopenharmony_ci    TLV_ACCESS_TOKEN_INFO,
5869570cc8Sopenharmony_ci    TLV_PERMISSION,
5969570cc8Sopenharmony_ci    TLV_INTERNET_INFO,
6069570cc8Sopenharmony_ci    TLV_RENDER_TERMINATION_INFO,
6169570cc8Sopenharmony_ci    TLV_MAX
6269570cc8Sopenharmony_ci} AppSpawnMsgTlvType;
6369570cc8Sopenharmony_ci
6469570cc8Sopenharmony_ci#define DATA_TYPE_STRING 1
6569570cc8Sopenharmony_ci
6669570cc8Sopenharmony_ci#if defined(__clang__)
6769570cc8Sopenharmony_ci#    pragma clang diagnostic push
6869570cc8Sopenharmony_ci#    pragma clang diagnostic ignored "-Wextern-c-compat"
6969570cc8Sopenharmony_ci#elif defined(__GNUC__)
7069570cc8Sopenharmony_ci#    pragma GCC diagnostic push
7169570cc8Sopenharmony_ci#    pragma GCC diagnostic ignored "-Wextern-c-compat"
7269570cc8Sopenharmony_ci#elif defined(_MSC_VER)
7369570cc8Sopenharmony_ci#    pragma warning(push)
7469570cc8Sopenharmony_ci#endif
7569570cc8Sopenharmony_ci
7669570cc8Sopenharmony_ci#pragma pack(4)
7769570cc8Sopenharmony_citypedef AppDacInfo AppSpawnMsgDacInfo;
7869570cc8Sopenharmony_ci
7969570cc8Sopenharmony_citypedef struct {
8069570cc8Sopenharmony_ci    uint16_t tlvLen;
8169570cc8Sopenharmony_ci    uint16_t tlvType;
8269570cc8Sopenharmony_ci} AppSpawnTlv;
8369570cc8Sopenharmony_ci
8469570cc8Sopenharmony_citypedef struct {
8569570cc8Sopenharmony_ci    uint16_t tlvLen;  // 对齐后的长度
8669570cc8Sopenharmony_ci    uint16_t tlvType;
8769570cc8Sopenharmony_ci    uint16_t dataLen;  // 数据的长度
8869570cc8Sopenharmony_ci    uint16_t dataType;
8969570cc8Sopenharmony_ci    char tlvName[APPSPAWN_TLV_NAME_LEN];
9069570cc8Sopenharmony_ci} AppSpawnTlvExt;
9169570cc8Sopenharmony_ci
9269570cc8Sopenharmony_citypedef struct {
9369570cc8Sopenharmony_ci    uint32_t count;
9469570cc8Sopenharmony_ci    uint32_t flags[0];
9569570cc8Sopenharmony_ci} AppSpawnMsgFlags;
9669570cc8Sopenharmony_ci
9769570cc8Sopenharmony_citypedef struct {
9869570cc8Sopenharmony_ci    uint64_t accessTokenIdEx;
9969570cc8Sopenharmony_ci} AppSpawnMsgAccessToken;
10069570cc8Sopenharmony_ci
10169570cc8Sopenharmony_citypedef struct {
10269570cc8Sopenharmony_ci    char ownerId[0];  // app identifier id
10369570cc8Sopenharmony_ci} AppSpawnMsgOwnerId;
10469570cc8Sopenharmony_ci
10569570cc8Sopenharmony_citypedef struct {
10669570cc8Sopenharmony_ci    uint8_t setAllowInternet;
10769570cc8Sopenharmony_ci    uint8_t allowInternet;  // hap sockect allowed
10869570cc8Sopenharmony_ci    uint8_t res[2];
10969570cc8Sopenharmony_ci} AppSpawnMsgInternetInfo;
11069570cc8Sopenharmony_ci
11169570cc8Sopenharmony_citypedef struct {
11269570cc8Sopenharmony_ci    uint32_t hapFlags;
11369570cc8Sopenharmony_ci    char apl[0];
11469570cc8Sopenharmony_ci} AppSpawnMsgDomainInfo;
11569570cc8Sopenharmony_ci
11669570cc8Sopenharmony_citypedef struct {
11769570cc8Sopenharmony_ci    uint32_t bundleIndex;
11869570cc8Sopenharmony_ci    char bundleName[0];  // process name
11969570cc8Sopenharmony_ci} AppSpawnMsgBundleInfo;
12069570cc8Sopenharmony_ci
12169570cc8Sopenharmony_citypedef struct TagAppSpawnMsg {
12269570cc8Sopenharmony_ci    uint32_t magic;
12369570cc8Sopenharmony_ci    uint32_t msgType;
12469570cc8Sopenharmony_ci    uint32_t msgLen;
12569570cc8Sopenharmony_ci    uint32_t msgId;
12669570cc8Sopenharmony_ci    uint32_t tlvCount;
12769570cc8Sopenharmony_ci    char processName[APP_LEN_PROC_NAME];
12869570cc8Sopenharmony_ci} AppSpawnMsg;
12969570cc8Sopenharmony_ci
13069570cc8Sopenharmony_citypedef struct {
13169570cc8Sopenharmony_ci    AppSpawnMsg msgHdr;
13269570cc8Sopenharmony_ci    AppSpawnResult result;
13369570cc8Sopenharmony_ci} AppSpawnResponseMsg;
13469570cc8Sopenharmony_ci#pragma pack()
13569570cc8Sopenharmony_ci
13669570cc8Sopenharmony_ci#if defined(__clang__)
13769570cc8Sopenharmony_ci#    pragma clang diagnostic pop
13869570cc8Sopenharmony_ci#elif defined(__GNUC__)
13969570cc8Sopenharmony_ci#    pragma GCC diagnostic pop
14069570cc8Sopenharmony_ci#elif defined(_MSC_VER)
14169570cc8Sopenharmony_ci#    pragma warning(pop)
14269570cc8Sopenharmony_ci#endif
14369570cc8Sopenharmony_ci
14469570cc8Sopenharmony_ci#ifdef __cplusplus
14569570cc8Sopenharmony_ci}
14669570cc8Sopenharmony_ci#endif
14769570cc8Sopenharmony_ci#endif  // APPSPAWN_CLIENT_MSG_H
148