@@ -37,7 +37,7 @@ Let's look at some simple examples of sessions to get a feel for the protocol.
3737Sending files to the terminal emulator
3838^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3939
40- The client starts by sending a start command command::
40+ The client starts by sending a start send command::
4141
4242 → action=send id=someid
4343
@@ -110,10 +110,115 @@ such as::
110110 ← action=status id=someid status=Some error occurred
111111
112112
113+ Receiving files to the terminal emulator
114+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115+
116+ The client starts by sending a start receive command::
117+
118+ → action=receive id=someid size=num_of_paths
119+
120+ It then sends a list of ``num_of_paths `` paths it is interested in
121+ receiving::
122+
123+ → action=file id=someid file_id=f1 name=/some/path
124+ → action=file id=someid file_id=f2 name=/some/path2
125+ ...
126+
127+ The client must then wait for responses from the terminal emulator. It
128+ is an error to send anymore commands to to the terminal until an ``OK ``
129+ response is received from the terminal. The terminal wait for the user to accept
130+ the request. If accepted, it sends::
131+
132+ ← action=status id=someid status=OK
133+
134+ If permission is denied it sends::
135+
136+ ← action=status id=someid status=EPERM:User refused the transfer
137+
138+ The terminal then sends the metadata for all requested files. If any of them
139+ are directories, it traverses the directories recursively, listing all files.
140+ Note that symlinks must not be followed, but sent as symlinks::
141+
142+ ← action=file id=someid file_id=f1 mtime=XXX permissions=XXX name=/absolute/path status=file_id1 size=size_in_bytes file_type=type parent=file_id of parent
143+ ← action=file id=someid file_id=f1 mtime=XXX permissions=XXX name=/absolute/path2 status=file_id2 size=size_in_bytes file_type=type parent=file_id of parent
144+ ...
145+
146+ Here the ``file_id `` field is set to the ``file_id `` value sent from the client
147+ and the ``status `` field is set to the actual file id for each file. This is
148+ because a file query sent from the client can result in multiple actual files if
149+ it is a directory. The ``parent `` field is the actual ``file_id `` of the directory
150+ containing this file and is set for entries that are generated from client
151+ requests that match directories. This allows the client to build an unambiguous picture
152+ of the file tree.
153+
154+ Once all the files are listed, the terminal sends an ``OK `` response that also
155+ specifies the absolute path to the home directory for the user account running
156+ the terminal::
157+
158+ ← action=status id=someid status=OK name=/path/to/home
159+
160+ If an error occurs while listing any of the files asked for by the client,
161+ the terminal will send an error response like::
162+
163+ ← action=status id=someid file_id=f1 status=ENOENT: Does not exist
164+
165+ Here, ``file_id `` is the same as was sent by the client in its initial query.
166+
167+ Now, the client can send requests for file data using the paths sent by the
168+ terminal emulator::
169+
170+ → action=file id=someid file_id=f1 name=/some/path
171+ ...
172+
173+ The terminal emulator replies with the data for the files, as a sequence of
174+ ``data `` commands for each file (the terminal emulator should send the data for
175+ one file at a time)::
176+
177+
178+ ← action=data id=someid file_id=f1 data=chunk of bytes
179+ ...
180+ ← action=end_data id=someid file_id=f1 data=chunk of bytes
181+
182+ If any errors occur reading file data, the terminal emulator sends an error
183+ message for the file, for example::
184+
185+ ← action=status id=someid file_id=f1 status=EIO:Could not read
186+
187+ Once the client is done reading data for all the files it expects, it
188+ terminates the session with::
189+
190+ → action=finished id=someid
191+
192+ Quieting response from the terminal
193+ -------------------------------------
194+
195+ TODO:
196+
197+ File metadata
198+ -----------------
199+
200+ TODO:
201+
202+ Transmitting binary deltas
203+ -----------------------------
204+
205+ TODO:
206+
207+ Compression
208+ --------------
209+
210+ TODO:
211+
212+
213+ Bypassing explicit user authorization
214+ ------------------------------------------
215+
216+ TODO:
217+
113218Encoding of transfer commands as escape codes
114219------------------------------------------------
115220
116- Transfer commands are encoded as OSC escape codes of the form::
221+ Transfer commands are encoded as `` OSC `` escape codes of the form::
117222
118223 <OSC> 5113 ; key=value ; key=value ... <ST>
119224
0 commit comments