-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrun.h
129 lines (109 loc) · 2.72 KB
/
srun.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Copyright © 2023-2024 45gfg9 <[email protected]>
* This work is free. You can redistribute it and/or modify it under the
* terms of the Do What The Fuck You Want To Public License, Version 2,
* as published by Sam Hocevar. See the LICENSE file for more details.
*/
#ifndef __SRUN_H__
#define __SRUN_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct srun_context *srun_handle;
typedef enum srun_option {
/**
* Authentication server URL. Required.
* Type: char *
*/
SRUNOPT_AUTH_SERVER,
/**
* Username. Required for login.
* Type: char *
*/
SRUNOPT_USERNAME,
/**
* Password. Required for login.
* Type: char *
*/
SRUNOPT_PASSWORD,
/**
* Server certificate. PEM format. This field is NOT copied.
* Required if the server uses HTTPS.
* On ESP32, see also SRUNOPT_USE_ESP_CRT_BUNDLE.
* Type: const char *
*/
SRUNOPT_SERVER_CERT,
/**
* Set to 1 to use ESP x509 certificate bundle.
* This option is ignored, if SRUNOPT_SERVER_CERT is set.
* Setting this option on non-ESP platforms will have no effect.
* Type: int
*/
SRUNOPT_USE_ESP_CRT_BUNDLE,
/**
* Client IP. Optional for login.
* Leave unset to use the default assigned IP.
* Type: char *
*/
SRUNOPT_CLIENT_IP,
/**
* Verbose mode. Optional. Default to 0.
* Type: int
*/
SRUNOPT_VERBOSITY,
} srun_option;
/**
* Success.
*/
#define SRUNE_OK 0
/**
* Network error.
*/
#define SRUNE_NETWORK (-1)
/**
* Invalid context (missing fields).
*/
#define SRUNE_INVALID_CTX (-2)
/**
* Create a new Srun handle. This handle must be freed by `srun_cleanup`.
*
* @return A new Srun handle
*/
srun_handle srun_create();
void srun_setopt(srun_handle handle, srun_option option, ...);
/**
* Set option of Srun handle.
*
* @param context Srun context
* @param option
* @param value
*/
#define srun_setopt(handle, option, value) srun_setopt(handle, option, value)
/**
* Perform login. The username, password and auth server must be set.
*
* @param handle Srun handle
* @return SRUNE_OK if logged in successfully or device already online;
* gateway error code or library defined error code otherwise
*/
int srun_login(srun_handle handle);
/**
* Logout from this session.
*
* Auth server needs to be set; the certificate must be set too if the server uses HTTPS.
* No other fields are required.
*
* @param handle Srun handle
* @return SRUNE_OK if logged out successfully;
* SRUNE_NETWORK if network error
*/
int srun_logout(srun_handle handle);
/**
* Free all allocated resources held by this handle. You are encouraged to set handle to NULL after this call.
*
* @param context Srun context
*/
void srun_cleanup(srun_handle context);
#ifdef __cplusplus
}
#endif
#endif