• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "cj_common_ffi.h"
22 
23 #ifndef FFI_EXPORT
24 #ifndef WINDOWS_PLATFORM
25 #define FFI_EXPORT __attribute__((visibility("default")))
26 #else
27 #define FFI_EXPORT __declspec(dllexport)
28 #endif
29 #endif
30 
31 extern "C" {
32 typedef struct {
33     char *key;
34     char *value;
35 } CHashStrPair;
36 
37 typedef struct {
38     CHashStrPair *headers;
39     int64_t size;
40 } CHashStrArr;
41 
42 typedef struct {
43     char *path;
44     char *mimeType;
45     char *filename;
46     CHashStrArr extras;
47 } CFileSpec;
48 
49 typedef struct {
50     CFileSpec *head;
51     int64_t size;
52 } CFileSpecArr;
53 
54 enum CFormItemValueType {
55     CFORM_ITEM_VALUE_TYPE_STRING = 0U,
56     CFORM_ITEM_VALUE_TYPE_FILE,
57     CFORM_ITEM_VALUE_TYPE_FILES,
58 };
59 
60 typedef struct {
61     char *str;
62     CFileSpec file;
63     CFileSpecArr files;
64     uint32_t type;
65 } CFormItemValueTypeUion;
66 
67 typedef struct {
68     char *name;
69     CFormItemValueTypeUion value;
70 } CFormItem;
71 
72 typedef struct {
73     CFormItem *head;
74     int64_t size;
75 } CFormItemArr;
76 
77 typedef struct {
78     char *str;
79     CFormItemArr formItems;
80 } CConfigDataTypeUion;
81 
82 typedef struct {
83     uint32_t action;
84     char *url;
85     char *title;
86     char *description;
87     uint32_t mode;
88     bool overwrite;
89     char *method;
90     CHashStrArr headers;
91     CConfigDataTypeUion data;
92     char *saveas;
93     uint32_t network;
94     bool metered;
95     bool roaming;
96     bool retry;
97     bool redirect;
98     uint32_t index;
99     int64_t begins;
100     int64_t ends;
101     bool gauge;
102     bool precise;
103     char *token;
104     uint32_t priority;
105     CHashStrArr extras;
106 } CConfig;
107 
108 typedef struct {
109     uint32_t state;
110     uint32_t index;
111     int64_t processed;
112     int64_t *sizeArr;
113     int64_t sizeArrLen;
114     CHashStrArr extras;
115 } CProgress;
116 
117 typedef struct {
118     char *key;
119     CArrString value;
120 } CHttpHeaderHashPair;
121 
122 typedef struct {
123     CHttpHeaderHashPair *hashHead;
124     int64_t size;
125 } CHttpHeader;
126 
127 typedef struct {
128     char *version;
129     int32_t statusCode;
130     char *reason;
131     CHttpHeader headers;
132 } CResponse;
133 
134 typedef struct {
135     char *uid;
136     char *bundle;
137     char *saveas;
138     char *url;
139     CConfigDataTypeUion data;
140     char *tid;
141     char *title;
142     char *description;
143     uint32_t action;
144     uint32_t mode;
145     uint32_t priority;
146     char *mimeType;
147     CProgress progress;
148     bool gauge;
149     uint64_t ctime;
150     uint64_t mtime;
151     bool retry;
152     uint32_t tries;
153     uint32_t faults;
154     char *reason;
155     CHashStrArr extras;
156 } CTaskInfo;
157 
158 typedef struct {
159     bool hasValue;
160     const char *value;
161 } RequestNativeOptionCString;
162 
163 typedef struct {
164     bool hasValue;
165     int64_t value;
166 } RequestNativeOptionInt64;
167 
168 typedef struct {
169     bool hasValue;
170     uint32_t value;
171 } RequestNativeOptionUInt32;
172 
173 typedef struct {
174     RequestNativeOptionCString bundle;
175     RequestNativeOptionInt64 before;
176     RequestNativeOptionInt64 after;
177     RequestNativeOptionUInt32 state;
178     RequestNativeOptionUInt32 action;
179     RequestNativeOptionUInt32 mode;
180 } CFilter;
181 
182 typedef struct {
183     char **head;
184     int64_t size;
185 } RequestCArrString;
186 
187 typedef struct {
188     int32_t errCode;
189     char *errMsg;
190 } RetError;
191 
192 typedef struct {
193     int64_t instanceId;
194     const char *taskId;
195     RetError err;
196 } RetReqData;
197 
198 typedef struct {
199     RetError err;
200     CTaskInfo task;
201 } RetTaskInfo;
202 
203 typedef struct {
204     RetError err;
205     RequestCArrString tasks;
206 } RetTaskArr;
207 
208 typedef struct {
209     const char *taskId;
210     CConfig config;
211 } CTask;
212 
213 typedef struct {
214     RetError err;
215     CTask tid;
216 } RetTask;
217 
218 FFI_EXPORT void FfiOHOSRequestFreeTask(const char *taskId);
219 FFI_EXPORT RetError FfiOHOSRequestTaskProgressOn(char *event, const char *taskId, void *callback);
220 FFI_EXPORT RetError FfiOHOSRequestTaskProgressOff(char *event, const char *taskId, void *callback);
221 FFI_EXPORT RetError FfiOHOSRequestTaskStart(const char *taskId);
222 FFI_EXPORT RetError FfiOHOSRequestTaskPause(const char *taskId);
223 FFI_EXPORT RetError FfiOHOSRequestTaskResume(const char *taskId);
224 FFI_EXPORT RetError FfiOHOSRequestTaskStop(const char *taskId);
225 FFI_EXPORT RetReqData FfiOHOSRequestCreateTask(void *context, CConfig config);
226 FFI_EXPORT RetTask FfiOHOSRequestGetTask(void *context, const char *taskId, RequestNativeOptionCString token);
227 FFI_EXPORT RetError FfiOHOSRequestRemoveTask(const char *taskId);
228 FFI_EXPORT RetTaskInfo FfiOHOSRequestShowTask(const char *taskId);
229 FFI_EXPORT RetTaskInfo FfiOHOSRequestTouchTask(const char *taskId, char *token);
230 FFI_EXPORT RetTaskArr FfiOHOSRequestSearchTask(CFilter filter);
231 }
232 #endif