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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
use crate::AccountNumber;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct RegisterServerRequest {
pub service: AccountNumber,
pub server: AccountNumber,
}
#[crate::service(name = "x-http", dispatch = false, psibase_mod = "crate")]
#[allow(non_snake_case, unused_variables)]
mod service {
use crate::{AccountNumber, HttpReply, HttpRequest, MethodNumber, SocketEndpoint, TLSInfo};
/// Sends a message to a socket. HTTP sockets should use sendReply, instead.
#[action]
fn send(socket: i32, data: Vec<u8>, flags: u32) {
unimplemented!()
}
/// Sends an HTTP request and returns the new socket.
///
/// Must be followed by `setCallback(socket, callback, err)`, or the
/// socket will be closed when the current context exits. When the response
/// is available, it will be passed to `sender::callback(socket, reply)`.
/// If the the request fails without a response, calls `sender::err(socket)`
#[action]
fn sendRequest(
request: HttpRequest,
tls: Option<TLSInfo>,
endpoint: Option<SocketEndpoint>,
) -> i32 {
unimplemented!()
}
/// Opens a websocket connection and returns the new socket.
///
/// Must be followed by `setCallback(socket, callback, err)`, or the
/// socket will be closed when the current context exits. The
/// request method must be GET. The required headers for the websocket
/// handshake will be added to the request if they are not already
/// provided. If the connection is successfully established, calls
/// `sender::callback(socket, reply)`. If the request fails without
/// a response, calls `sender::err(socket, nullopt)`. If the response
/// does not complete a websocket handshake, calls
/// `sender::err(socket, optional(reply))`
#[action]
fn websocket(
request: HttpRequest,
tls: Option<TLSInfo>,
endpoint: Option<SocketEndpoint>,
) -> i32 {
unimplemented!();
}
/// Enables or disables automatic closing of the socket
/// when the transaction context exits.
///
/// Can be called inside `PSIBASE_SUBJECTIVE_TX`
#[action]
fn autoClose(socket: i32, value: bool) {
unimplemented!()
}
/// Allow another service to send a response to a socket
///
/// Auto-close must be enabled and the current owner of the
/// socket must be the sender. If local is false, then the
/// reply is expected to come through http-server.
#[action]
fn giveSocket(socket: i32, account: AccountNumber, local: bool) {
unimplemented!()
}
/// Take back ownership of a socket
///
/// autoClose must not have been disabled after the sender called
/// `giveSocket`. local must be true if it was true for the corresponding
/// call to `giveSocket`.
///
/// Returns true if taking ownership was successful
#[action]
fn takeSocket(socket: i32, local: bool) -> bool {
unimplemented!()
}
/// Sends an HTTP response. The socket must have autoClose enabled.
#[action]
fn sendReply(socket: i32, response: HttpReply) {
unimplemented!()
}
/// Accepts a websocket connection. The response must be a
/// valid websocket handshake for the request.
///
/// Must be followed by `setCallback(socket, callback, err)`, or the
/// socket will be closed when the current context exits.
#[action]
fn accept(socket: i32, reply: HttpReply) {
unimplemented!()
}
/// Changes the callback for a socket. The sender must be the owner
/// of the socket.
#[action]
fn setCallback(socket: i32, callback: MethodNumber, err: MethodNumber) {
unimplemented!()
}
/// Close a socket. The socket should be either a websocket
/// or a pending http request. The regular close notification
/// will be called.
#[action]
fn asyncClose(socket: i32) {
unimplemented!()
}
/// Writes a message to the server log
#[action]
fn log(severity: u32, msg: String) {
unimplemented!()
}
/// Returns the root host for a given host
#[action]
fn rootHost(host: String) -> String {
unimplemented!()
}
#[action]
fn serveSys(req: HttpRequest, socket: Option<i32>) -> Option<HttpReply> {
unimplemented!()
}
/// Called by the host at the beginning of a session
#[action]
fn startSession() {
unimplemented!()
}
/// Returns true if the socket is over a secure connection (e.g. https)
/// The sender must be the current owner of the socket.
#[action]
fn isSecure(socket: i32) -> bool {
unimplemented!()
}
}
#[test]
fn verify_schema() {
crate::assert_schema_matches_package::<Wrapper>();
}