sciter/capi/
screquest.rs

1/*! Handling all attributes of requests (GET/POST/PUT/DELETE) sent by
2[`Element.request()`](https://sciter.com/docs/content/sciter/Element.htm) and
3[`View.request()`](https://sciter.com/docs/content/sciter/View.htm)
4functions and other load requests.
5
6 */
7
8#![allow(non_camel_case_types, non_snake_case)]
9
10use capi::sctypes::{UINT, LPVOID, LPCBYTE, LPCSTR, LPCWSTR};
11use capi::scdef::{LPCSTR_RECEIVER, LPCWSTR_RECEIVER, LPCBYTE_RECEIVER};
12pub use capi::scdef::RESOURCE_TYPE;
13
14MAKE_HANDLE!(#[doc = "Request native handle."] HREQUEST, _HREQUEST);
15
16#[repr(C)]
17#[derive(Debug, PartialEq)]
18/// Type of the result value for Sciter Request functions.
19pub enum REQUEST_RESULT {
20	/// E.g. not enough memory.
21	PANIC = -1,
22	/// Success.
23	OK = 0,
24	/// Bad parameter.
25	BAD_PARAM = 1,
26	/// Operation failed, e.g. index out of bounds.
27	FAILURE = 2,
28	/// The platform does not support requested feature.
29  NOTSUPPORTED = 3,
30}
31
32impl std::error::Error for REQUEST_RESULT {}
33
34impl std::fmt::Display for REQUEST_RESULT {
35	fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
36		write!(f, "{:?}", self)
37	}
38}
39
40
41#[repr(C)]
42#[derive(Debug, PartialEq)]
43/// Request methods.
44pub enum REQUEST_METHOD {
45	/// Sends a plain HTTP GET request.
46	///
47	/// Url-encoded params (if any) are appended to the url in order to form the request.
48	GET = 1,
49	/// Sends an HTTP POST request.
50	///
51	/// The params are serialized as `Content-Type: application/x-www-form-urlencoded;charset=utf-8`.
52	POST = 2,
53	/// Sends an HTTP PUT request.
54	///
55	/// The params are serialized as `Content-Type: multipart/form-data; boundary= ...`.
56	PUT = 3,
57	/// Sends an HTTP DELETE request.
58	DELETE = 4,
59}
60
61#[repr(C)]
62#[derive(Debug, PartialEq)]
63/// HTTP methods for the [`Element::send_request`](../dom/struct.Element.html#method.send_request).
64pub enum REQUEST_TYPE {
65	/// Asynchronous GET.
66	AsyncGet,
67	/// Asynchronous POST.
68	AsyncPost,
69	/// Synchronous GET.
70	Get,
71	/// Synchronous POST.
72	Post,
73}
74
75
76#[repr(C)]
77#[derive(Debug, PartialEq)]
78/// Completion state of a request.
79pub enum REQUEST_STATE {
80	/// The request is pending.
81	PENDING = 0,
82	/// Completed successfully.
83	SUCCESS = 1,
84	/// Completed with failure.
85	FAILURE = 2,
86}
87
88#[repr(C)]
89#[derive(Debug)]
90pub struct REQUEST_PARAM {
91	pub name: LPCWSTR,
92	pub value: LPCWSTR,
93}
94
95
96#[repr(C)]
97#[allow(missing_docs)]
98pub struct SciterRequestAPI
99{
100  /// a.k.a AddRef()
101  pub RequestUse: extern "system" fn (rq: HREQUEST) -> REQUEST_RESULT,
102
103  /// a.k.a Release()
104  pub RequestUnUse: extern "system" fn (rq: HREQUEST) -> REQUEST_RESULT,
105
106  /// get requested URL
107  pub RequestUrl: extern "system" fn (rq: HREQUEST, rcv: LPCSTR_RECEIVER, rcv_param: LPVOID) -> REQUEST_RESULT,
108
109  /// get real, content URL (after possible redirection)
110  pub RequestContentUrl: extern "system" fn (rq: HREQUEST, rcv: LPCSTR_RECEIVER, rcv_param: LPVOID) -> REQUEST_RESULT,
111
112  /// get requested data type
113  pub RequestGetRequestType: extern "system" fn (rq: HREQUEST, pType: &mut REQUEST_METHOD) -> REQUEST_RESULT,
114
115  /// get requested data type
116  pub RequestGetRequestedDataType: extern "system" fn (rq: HREQUEST, pData: &mut RESOURCE_TYPE) -> REQUEST_RESULT,
117
118  /// get received data type, string, mime type
119  pub RequestGetReceivedDataType: extern "system" fn (rq: HREQUEST, rcv: LPCSTR_RECEIVER, rcv_param: LPVOID) -> REQUEST_RESULT,
120
121
122  /// get number of request parameters passed
123  pub RequestGetNumberOfParameters: extern "system" fn (rq: HREQUEST, pNumber: &mut UINT) -> REQUEST_RESULT,
124
125  /// get nth request parameter name
126  pub RequestGetNthParameterName: extern "system" fn (rq: HREQUEST, n: UINT, rcv: LPCWSTR_RECEIVER, rcv_param: LPVOID) -> REQUEST_RESULT,
127
128  /// get nth request parameter value
129  pub RequestGetNthParameterValue: extern "system" fn (rq: HREQUEST, n: UINT, rcv: LPCWSTR_RECEIVER, rcv_param: LPVOID) -> REQUEST_RESULT,
130
131  /// get request times , ended - started = milliseconds to get the requst
132  pub RequestGetTimes: extern "system" fn (rq: HREQUEST, pStarted: &mut UINT, pEnded: &mut UINT) -> REQUEST_RESULT,
133
134  /// get number of request headers
135  pub RequestGetNumberOfRqHeaders: extern "system" fn (rq: HREQUEST, pNumber: &mut UINT) -> REQUEST_RESULT,
136
137  /// get nth request header name
138  pub RequestGetNthRqHeaderName: extern "system" fn (rq: HREQUEST, n: UINT, rcv: LPCWSTR_RECEIVER, rcv_param: LPVOID) -> REQUEST_RESULT,
139
140  /// get nth request header value
141  pub RequestGetNthRqHeaderValue: extern "system" fn (rq: HREQUEST, n: UINT, rcv: LPCWSTR_RECEIVER, rcv_param: LPVOID) -> REQUEST_RESULT,
142
143  /// get number of response headers
144  pub RequestGetNumberOfRspHeaders: extern "system" fn (rq: HREQUEST, pNumber: &mut UINT) -> REQUEST_RESULT,
145
146  /// get nth response header name
147  pub RequestGetNthRspHeaderName: extern "system" fn (rq: HREQUEST, n: UINT, rcv: LPCWSTR_RECEIVER, rcv_param: LPVOID) -> REQUEST_RESULT,
148
149  /// get nth response header value
150  pub RequestGetNthRspHeaderValue: extern "system" fn (rq: HREQUEST, n: UINT, rcv: LPCWSTR_RECEIVER, rcv_param: LPVOID) -> REQUEST_RESULT,
151
152  /// get completion status (CompletionStatus - http response code : 200, 404, etc.)
153  pub RequestGetCompletionStatus: extern "system" fn (rq: HREQUEST, pState: &mut REQUEST_STATE, pCompletionStatus: &mut UINT) -> REQUEST_RESULT,
154
155  /// get proxy host
156  pub RequestGetProxyHost: extern "system" fn (rq: HREQUEST, rcv: LPCSTR_RECEIVER, rcv_param: LPVOID) -> REQUEST_RESULT,
157
158  /// get proxy port
159  pub RequestGetProxyPort: extern "system" fn (rq: HREQUEST, pPort: &mut UINT) -> REQUEST_RESULT,
160
161  /// mark reequest as complete with status and data
162  pub RequestSetSucceeded: extern "system" fn (rq: HREQUEST, status: UINT, dataOrNull: LPCBYTE, dataLength: UINT) -> REQUEST_RESULT,
163
164  /// mark reequest as complete with failure and optional data
165  pub RequestSetFailed: extern "system" fn (rq: HREQUEST, status: UINT, dataOrNull: LPCBYTE, dataLength: UINT) -> REQUEST_RESULT,
166
167  /// append received data chunk
168  pub RequestAppendDataChunk: extern "system" fn (rq: HREQUEST, data: LPCBYTE, dataLength: UINT) -> REQUEST_RESULT,
169
170  /// set request header (single item)
171  pub RequestSetRqHeader: extern "system" fn (rq: HREQUEST, name: LPCWSTR, value: LPCWSTR) -> REQUEST_RESULT,
172
173  /// set respone header (single item)
174  pub RequestSetRspHeader: extern "system" fn (rq: HREQUEST, name: LPCWSTR, value: LPCWSTR) -> REQUEST_RESULT,
175
176  /// set received data type, string, mime type
177  pub RequestSetReceivedDataType: extern "system" fn (rq: HREQUEST, _type: LPCSTR) -> REQUEST_RESULT,
178
179  /// set received data encoding, string
180  pub RequestSetReceivedDataEncoding: extern "system" fn (rq: HREQUEST, encoding: LPCSTR) -> REQUEST_RESULT,
181
182  /// get received (so far) data
183  pub RequestGetData: extern "system" fn (rq: HREQUEST, rcv: LPCBYTE_RECEIVER, rcv_param: LPVOID) -> REQUEST_RESULT,
184}