1 /*
2  * Copyright (C) 2015-2018 Alibaba Group Holding Limited
3  */
4 
5 #ifndef _HTTP2_UPLOAD_API_H_
6 #define _HTTP2_UPLOAD_API_H_
7 
8 #include "linkkit/infra/infra_types.h"
9 #include "linkkit/infra/infra_defs.h"
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 /* bit define of file override option */
16 #define UPLOAD_FILE_OPT_BIT_OVERWRITE    (0x00000001)
17 #define UPLOAD_FILE_OPT_BIT_RESUME       (0x00000002)
18 #define UPLOAD_FILE_OPT_BIT_SPECIFIC_LEN (0x00000004)
19 
20 /* http2 connect information */
21 typedef struct {
22     char *product_key;
23     char *device_name;
24     char *device_secret;
25     char *url;
26     int port;
27 } http2_upload_conn_info_t;
28 
29 /* file upload option define */
30 typedef struct {
31     const char *file_path; /* file path, filename must be ASCII string and
32                               strlen < 2014 */
33     uint32_t part_len; /* maximum content len of one http2 request, must be in
34                           range of 100KB ~ 100MB */
35     const char
36         *upload_id; /* a specific id used to indicate one upload session, only
37                        required when UPLOAD_FILE_OPT_BIT_RESUME option set */
38     uint32_t upload_len; /* used to indicate the upload length, only required
39                             when UPLOAD_FILE_OPT_BIT_SPECIFIC_LEN option set */
40     uint32_t
41         opt_bit_map; /* option bit map, support UPLOAD_FILE_OPT_BIT_OVERWRITE,
42                         UPLOAD_FILE_OPT_BIT_RESUME and
43                         UPLOAD_FILE_OPT_BIT_SPECIFIC_LEN */
44 } http2_upload_params_t;
45 
46 /* error code for file upload */
47 typedef enum {
48     UPLOAD_STOP_BY_IOCTL = -14,
49     UPLOAD_HTTP2_HANDLE_NULL = -13,
50     UPLOAD_LEN_IS_ZERO = -12,
51     UPLOAD_FILE_PATH_IS_NULL = -11,
52     UPLOAD_ID_IS_NULL = -10,
53     UPLOAD_FILE_NOT_EXIST = -9,
54     UPLOAD_FILE_READ_FAILED = -8,
55     UPLOAD_STREAM_OPEN_FAILED = -7,
56     UPLOAD_STREAM_SEND_FAILED = -6,
57     UPLOAD_MALLOC_FAILED = -5,
58     UPLOAD_NULL_POINT = -2,
59     UPLOAD_ERROR_COMMON = -1,
60     UPLOAD_SUCCESS = 0,
61 } http2_file_upload_result_t;
62 
63 /* gerneral callback function, this callback will be invoke when http2
64  * disconnected */
65 typedef void (*http2_disconnect_cb_t)(void);
66 
67 /* gerneral callback function, this callback will be invoke when http2
68  * reconnected */
69 typedef void (*http2_reconnect_cb_t)(void);
70 
71 /* callback function type define, this callback will be invoke when upload
72  * completed */
73 typedef void (*http2_upload_completed_cb_t)(const char *file_path, int result,
74                                             void *user_data);
75 
76 /* callback funciton type define, this callback will be invoke when upload_id
77  * received */
78 typedef void (*http2_upload_id_received_cb_t)(const char *file_path,
79                                               const char *upload_id,
80                                               void *user_data);
81 
82 /* http2 connect status callback define */
83 typedef struct {
84     http2_disconnect_cb_t on_disconnect_cb;
85     http2_reconnect_cb_t on_reconnect_cb;
86 } http2_status_cb_t;
87 
88 /* http2 upload result callback define */
89 typedef struct {
90     http2_upload_id_received_cb_t upload_id_received_cb;
91     http2_upload_completed_cb_t upload_completed_cb;
92 } http2_upload_result_cb_t;
93 
94 /* http2 uploadfile connect api, http2 handle returned */
95 void *IOT_HTTP2_UploadFile_Connect(http2_upload_conn_info_t *conn_info,
96                                    http2_status_cb_t *cb);
97 
98 /* http2 uploadfile start api */
99 int IOT_HTTP2_UploadFile_Request(void *http2_handle,
100                                  http2_upload_params_t *params,
101                                  http2_upload_result_cb_t *cb, void *user_data);
102 
103 /* http2 uploadfile disconnect api */
104 int IOT_HTTP2_UploadFile_Disconnect(void *handle);
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif /* #ifndef _HTTP2_UPLOAD_API_H_ */
111