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 OH_CJ_REQUEST_FFI_H
17 #define OH_CJ_REQUEST_FFI_H
18 
19 #include <cstdint>
20 
21 #ifndef FFI_EXPORT
22 #ifndef WINDOWS_PLATFORM
23 #define FFI_EXPORT __attribute__((visibility("default")))
24 #else
25 #define FFI_EXPORT __declspec(dllexport)
26 #endif
27 #endif
28 
29 extern "C" {
30 typedef struct {
31     char *key;
32     char *value;
33 } CHashStrPair;
34 
35 typedef struct {
36     CHashStrPair *headers;
37     int64_t size;
38 } CHashStrArr;
39 
40 typedef struct {
41     char *path;
42     char *mimeType;
43     char *filename;
44     CHashStrArr extras;
45 } CFileSpec;
46 
47 typedef struct {
48     CFileSpec *head;
49     int64_t size;
50 } CFileSpecArr;
51 
52 enum CFormItemValueType {
53     CFORM_ITEM_VALUE_TYPE_STRING = 0U,
54     CFORM_ITEM_VALUE_TYPE_FILE,
55     CFORM_ITEM_VALUE_TYPE_FILES,
56 };
57 
58 typedef struct {
59     char *str;
60     CFileSpec file;
61     CFileSpecArr files;
62     uint32_t type;
63 } CFormItemValueTypeUion;
64 
65 typedef struct {
66     char *name;
67     CFormItemValueTypeUion value;
68 } CFormItem;
69 
70 typedef struct {
71     CFormItem *head;
72     int64_t size;
73 } CFormItemArr;
74 
75 typedef struct {
76     char *str;
77     CFormItemArr formItems;
78 } CConfigDataTypeUion;
79 
80 typedef struct {
81     uint32_t action;
82     char *url;
83     char *title;
84     char *description;
85     uint32_t mode;
86     bool overwrite;
87     char *method;
88     CHashStrArr headers;
89     CConfigDataTypeUion data;
90     char *saveas;
91     uint32_t network;
92     bool metered;
93     bool roaming;
94     bool retry;
95     bool redirect;
96     uint32_t index;
97     int64_t begins;
98     int64_t ends;
99     bool gauge;
100     bool precise;
101     char *token;
102     uint32_t priority;
103     CHashStrArr extras;
104 } CConfig;
105 
106 typedef struct {
107     uint32_t state;
108     uint32_t index;
109     int64_t processed;
110     int64_t *sizeArr;
111     int64_t sizeArrLen;
112     CHashStrArr extras;
113 } CProgress;
114 
115 typedef struct {
116     int32_t errCode;
117     char *errMsg;
118 } RetError;
119 
120 typedef struct {
121     int64_t instanceId;
122     const char *taskId;
123     RetError err;
124 } RetReqData;
125 
126 FFI_EXPORT void FfiOHOSRequestFreeTask(const char *taskId);
127 FFI_EXPORT RetError FfiOHOSRequestTaskProgressOn(char *event, const char *taskId, void (*callback)(CProgress progress));
128 FFI_EXPORT RetError FfiOHOSRequestTaskProgressOff(char *event, const char *taskId, void *callback);
129 FFI_EXPORT RetError FfiOHOSRequestTaskStart(const char *taskId);
130 FFI_EXPORT RetError FfiOHOSRequestTaskPause(const char *taskId);
131 FFI_EXPORT RetError FfiOHOSRequestTaskResume(const char *taskId);
132 FFI_EXPORT RetError FfiOHOSRequestTaskStop(const char *taskId);
133 FFI_EXPORT RetReqData FfiOHOSRequestCreateTask(void* context, CConfig config);
134 FFI_EXPORT RetError FfiOHOSRequestRemoveTask(const char *taskId);
135 }
136 #endif