Blame


1 13b2bc37 2022-10-23 stsp /*
2 13b2bc37 2022-10-23 stsp * Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
3 13b2bc37 2022-10-23 stsp *
4 13b2bc37 2022-10-23 stsp * Permission to use, copy, modify, and distribute this software for any
5 13b2bc37 2022-10-23 stsp * purpose with or without fee is hereby granted, provided that the above
6 13b2bc37 2022-10-23 stsp * copyright notice and this permission notice appear in all copies.
7 13b2bc37 2022-10-23 stsp *
8 13b2bc37 2022-10-23 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 13b2bc37 2022-10-23 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 13b2bc37 2022-10-23 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 13b2bc37 2022-10-23 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 13b2bc37 2022-10-23 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 13b2bc37 2022-10-23 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 13b2bc37 2022-10-23 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 13b2bc37 2022-10-23 stsp */
16 13b2bc37 2022-10-23 stsp
17 13b2bc37 2022-10-23 stsp
18 13b2bc37 2022-10-23 stsp #define GOTD_UNIX_SOCKET "/var/run/gotd.sock"
19 13b2bc37 2022-10-23 stsp #define GOTD_UNIX_SOCKET_BACKLOG 10
20 13b2bc37 2022-10-23 stsp #define GOTD_UNIX_GROUP "_gotsh"
21 13b2bc37 2022-10-23 stsp #define GOTD_USER "_gotd"
22 13b2bc37 2022-10-23 stsp #define GOTD_CONF_PATH "/etc/gotd.conf"
23 13b2bc37 2022-10-23 stsp
24 13b2bc37 2022-10-23 stsp #define GOTD_MAXCLIENTS 1024
25 13b2bc37 2022-10-23 stsp #define GOTD_FD_RESERVE 5
26 13b2bc37 2022-10-23 stsp #define GOTD_FD_NEEDED 6
27 13b2bc37 2022-10-23 stsp #define GOTD_SOCK_FILENO 3
28 13b2bc37 2022-10-23 stsp
29 13b2bc37 2022-10-23 stsp /* Client hash tables need some extra room. */
30 13b2bc37 2022-10-23 stsp #define GOTD_CLIENT_TABLE_SIZE (GOTD_MAXCLIENTS * 4)
31 13b2bc37 2022-10-23 stsp
32 13b2bc37 2022-10-23 stsp enum gotd_procid {
33 13b2bc37 2022-10-23 stsp PROC_GOTD = 0,
34 13b2bc37 2022-10-23 stsp PROC_REPO_READ,
35 13b2bc37 2022-10-23 stsp PROC_REPO_WRITE,
36 13b2bc37 2022-10-23 stsp PROC_MAX,
37 13b2bc37 2022-10-23 stsp };
38 13b2bc37 2022-10-23 stsp
39 13b2bc37 2022-10-23 stsp struct gotd_imsgev {
40 13b2bc37 2022-10-23 stsp struct imsgbuf ibuf;
41 13b2bc37 2022-10-23 stsp void (*handler)(int, short, void *);
42 13b2bc37 2022-10-23 stsp void *handler_arg;
43 13b2bc37 2022-10-23 stsp struct event ev;
44 13b2bc37 2022-10-23 stsp short events;
45 13b2bc37 2022-10-23 stsp };
46 13b2bc37 2022-10-23 stsp
47 13b2bc37 2022-10-23 stsp struct gotd_child_proc {
48 13b2bc37 2022-10-23 stsp pid_t pid;
49 13b2bc37 2022-10-23 stsp enum gotd_procid type;
50 13b2bc37 2022-10-23 stsp char repo_name[NAME_MAX];
51 13b2bc37 2022-10-23 stsp char chroot_path[PATH_MAX];
52 13b2bc37 2022-10-23 stsp int pipe[2];
53 13b2bc37 2022-10-23 stsp struct gotd_imsgev iev;
54 13b2bc37 2022-10-23 stsp size_t nhelpers;
55 13b2bc37 2022-10-23 stsp };
56 13b2bc37 2022-10-23 stsp
57 13b2bc37 2022-10-23 stsp struct gotd_repo {
58 13b2bc37 2022-10-23 stsp TAILQ_ENTRY(gotd_repo) entry;
59 13b2bc37 2022-10-23 stsp
60 13b2bc37 2022-10-23 stsp char name[NAME_MAX];
61 13b2bc37 2022-10-23 stsp char path[PATH_MAX];
62 13b2bc37 2022-10-23 stsp };
63 13b2bc37 2022-10-23 stsp TAILQ_HEAD(gotd_repolist, gotd_repo);
64 13b2bc37 2022-10-23 stsp
65 13b2bc37 2022-10-23 stsp enum gotd_client_state {
66 13b2bc37 2022-10-23 stsp GOTD_STATE_EXPECT_LIST_REFS,
67 13b2bc37 2022-10-23 stsp GOTD_STATE_EXPECT_CAPABILITIES,
68 13b2bc37 2022-10-23 stsp GOTD_STATE_EXPECT_WANT,
69 13b2bc37 2022-10-23 stsp GOTD_STATE_EXPECT_REF_UPDATE,
70 13b2bc37 2022-10-23 stsp GOTD_STATE_EXPECT_MORE_REF_UPDATES,
71 13b2bc37 2022-10-23 stsp GOTD_STATE_EXPECT_HAVE,
72 13b2bc37 2022-10-23 stsp GOTD_STATE_EXPECT_PACKFILE,
73 13b2bc37 2022-10-23 stsp GOTD_STATE_EXPECT_DONE,
74 13b2bc37 2022-10-23 stsp GOTD_STATE_DONE,
75 13b2bc37 2022-10-23 stsp };
76 13b2bc37 2022-10-23 stsp
77 13b2bc37 2022-10-23 stsp struct gotd_client_capability {
78 13b2bc37 2022-10-23 stsp char *key;
79 13b2bc37 2022-10-23 stsp char *value;
80 13b2bc37 2022-10-23 stsp };
81 13b2bc37 2022-10-23 stsp
82 13b2bc37 2022-10-23 stsp struct gotd_object_id_array {
83 13b2bc37 2022-10-23 stsp struct got_object_id **ids;
84 13b2bc37 2022-10-23 stsp size_t nalloc;
85 13b2bc37 2022-10-23 stsp size_t nids;
86 13b2bc37 2022-10-23 stsp };
87 13b2bc37 2022-10-23 stsp
88 13b2bc37 2022-10-23 stsp struct gotd {
89 13b2bc37 2022-10-23 stsp pid_t pid;
90 13b2bc37 2022-10-23 stsp char unix_socket_path[PATH_MAX];
91 13b2bc37 2022-10-23 stsp char unix_group_name[32];
92 13b2bc37 2022-10-23 stsp char user_name[32];
93 13b2bc37 2022-10-23 stsp struct gotd_repolist repos;
94 13b2bc37 2022-10-23 stsp int nrepos;
95 13b2bc37 2022-10-23 stsp int verbosity;
96 13b2bc37 2022-10-23 stsp struct event ev;
97 13b2bc37 2022-10-23 stsp struct event pause;
98 13b2bc37 2022-10-23 stsp struct gotd_child_proc *procs;
99 13b2bc37 2022-10-23 stsp int nprocs;
100 13b2bc37 2022-10-23 stsp };
101 13b2bc37 2022-10-23 stsp
102 13b2bc37 2022-10-23 stsp enum gotd_imsg_type {
103 13b2bc37 2022-10-23 stsp /* An error occured while processing a request. */
104 13b2bc37 2022-10-23 stsp GOTD_IMSG_ERROR,
105 13b2bc37 2022-10-23 stsp
106 f1752522 2022-10-29 stsp /* Commands used by gotctl(8). */
107 f1752522 2022-10-29 stsp GOTD_IMSG_INFO,
108 f1752522 2022-10-29 stsp GOTD_IMSG_INFO_REPO,
109 f1752522 2022-10-29 stsp GOTD_IMSG_INFO_CLIENT,
110 f1752522 2022-10-29 stsp GOTD_IMSG_STOP,
111 f1752522 2022-10-29 stsp
112 13b2bc37 2022-10-23 stsp /* Request a list of references. */
113 13b2bc37 2022-10-23 stsp GOTD_IMSG_LIST_REFS,
114 13b2bc37 2022-10-23 stsp GOTD_IMSG_LIST_REFS_INTERNAL,
115 13b2bc37 2022-10-23 stsp
116 13b2bc37 2022-10-23 stsp /* References. */
117 13b2bc37 2022-10-23 stsp GOTD_IMSG_REFLIST,
118 13b2bc37 2022-10-23 stsp GOTD_IMSG_REF,
119 13b2bc37 2022-10-23 stsp GOTD_IMSG_SYMREF,
120 13b2bc37 2022-10-23 stsp
121 13b2bc37 2022-10-23 stsp /* Git protocol capabilities. */
122 13b2bc37 2022-10-23 stsp GOTD_IMSG_CAPABILITIES,
123 13b2bc37 2022-10-23 stsp GOTD_IMSG_CAPABILITY,
124 13b2bc37 2022-10-23 stsp
125 13b2bc37 2022-10-23 stsp /* Git protocol chatter. */
126 13b2bc37 2022-10-23 stsp GOTD_IMSG_WANT, /* The client wants an object. */
127 13b2bc37 2022-10-23 stsp GOTD_IMSG_HAVE, /* The client has an object. */
128 13b2bc37 2022-10-23 stsp GOTD_IMSG_ACK, /* The server has an object or a reference. */
129 13b2bc37 2022-10-23 stsp GOTD_IMSG_NAK, /* The server does not have an object/ref. */
130 13b2bc37 2022-10-23 stsp GOTD_IMSG_REF_UPDATE, /* The client wants to update a reference. */
131 13b2bc37 2022-10-23 stsp GOTD_IMSG_REF_DELETE, /* The client wants to delete a reference. */
132 13b2bc37 2022-10-23 stsp GOTD_IMSG_FLUSH, /* The client sent a flush packet. */
133 13b2bc37 2022-10-23 stsp GOTD_IMSG_DONE, /* The client is done chatting. */
134 13b2bc37 2022-10-23 stsp
135 13b2bc37 2022-10-23 stsp /* Sending or receiving a pack file. */
136 13b2bc37 2022-10-23 stsp GOTD_IMSG_SEND_PACKFILE, /* The server is sending a pack file. */
137 13b2bc37 2022-10-23 stsp GOTD_IMSG_RECV_PACKFILE, /* The server is receiving a pack file. */
138 13b2bc37 2022-10-23 stsp GOTD_IMSG_PACKIDX_FILE, /* Temporary file handle for new pack index. */
139 13b2bc37 2022-10-23 stsp GOTD_IMSG_PACKFILE_PIPE, /* Pipe to send/receive a pack file stream. */
140 13b2bc37 2022-10-23 stsp GOTD_IMSG_PACKFILE_PROGRESS, /* Progress reporting. */
141 13b2bc37 2022-10-23 stsp GOTD_IMSG_PACKFILE_READY, /* Pack file is ready to be sent. */
142 13b2bc37 2022-10-23 stsp GOTD_IMSG_PACKFILE_STATUS, /* Received pack success/failure status. */
143 13b2bc37 2022-10-23 stsp GOTD_IMSG_PACKFILE_INSTALL, /* Received pack file can be installed. */
144 13b2bc37 2022-10-23 stsp GOTD_IMSG_PACKFILE_DONE, /* Pack file has been sent/received. */
145 13b2bc37 2022-10-23 stsp
146 13b2bc37 2022-10-23 stsp /* Reference updates. */
147 13b2bc37 2022-10-23 stsp GOTD_IMSG_REF_UPDATES_START, /* Ref updates starting. */
148 13b2bc37 2022-10-23 stsp GOTD_IMSG_REF_UPDATE_OK, /* Update went OK. */
149 13b2bc37 2022-10-23 stsp GOTD_IMSG_REF_UPDATE_NG, /* Update was not good. */
150 13b2bc37 2022-10-23 stsp GOTD_IMSG_REFS_UPDATED, /* The server proccessed all ref updates. */
151 13b2bc37 2022-10-23 stsp
152 13b2bc37 2022-10-23 stsp /* Client is disconnecting. */
153 13b2bc37 2022-10-23 stsp GOTD_IMSG_DISCONNECT,
154 13b2bc37 2022-10-23 stsp };
155 13b2bc37 2022-10-23 stsp
156 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_ERROR. */
157 13b2bc37 2022-10-23 stsp struct gotd_imsg_error {
158 13b2bc37 2022-10-23 stsp int code; /* an error code from got_error.h */
159 13b2bc37 2022-10-23 stsp int errno_code; /* in case code equals GOT_ERR_ERRNO */
160 13b2bc37 2022-10-23 stsp uint32_t client_id;
161 13b2bc37 2022-10-23 stsp char msg[GOT_ERR_MAX_MSG_SIZE];
162 13b2bc37 2022-10-23 stsp } __attribute__((__packed__));
163 13b2bc37 2022-10-23 stsp
164 f1752522 2022-10-29 stsp /* Structure for GOTD_IMSG_INFO. */
165 f1752522 2022-10-29 stsp struct gotd_imsg_info {
166 f1752522 2022-10-29 stsp pid_t pid;
167 f1752522 2022-10-29 stsp int verbosity;
168 f1752522 2022-10-29 stsp int nrepos;
169 f1752522 2022-10-29 stsp int nclients;
170 f1752522 2022-10-29 stsp
171 f1752522 2022-10-29 stsp /* Followed by nrepos GOTD_IMSG_INFO_REPO messages. */
172 f1752522 2022-10-29 stsp /* Followed by nclients GOTD_IMSG_INFO_CLIENT messages. */
173 f1752522 2022-10-29 stsp };
174 f1752522 2022-10-29 stsp
175 f1752522 2022-10-29 stsp /* Structure for GOTD_IMSG_INFO_REPO. */
176 f1752522 2022-10-29 stsp struct gotd_imsg_info_repo {
177 f1752522 2022-10-29 stsp char repo_name[NAME_MAX];
178 f1752522 2022-10-29 stsp char repo_path[PATH_MAX];
179 f1752522 2022-10-29 stsp };
180 f1752522 2022-10-29 stsp
181 f1752522 2022-10-29 stsp /* Structure for GOTD_IMSG_INFO_CLIENT */
182 f1752522 2022-10-29 stsp struct gotd_imsg_info_client {
183 f1752522 2022-10-29 stsp uid_t euid;
184 f1752522 2022-10-29 stsp gid_t egid;
185 f1752522 2022-10-29 stsp char repo_name[NAME_MAX];
186 f1752522 2022-10-29 stsp int is_writing;
187 f1752522 2022-10-29 stsp enum gotd_client_state state;
188 f1752522 2022-10-29 stsp size_t ncapabilities;
189 f1752522 2022-10-29 stsp
190 f1752522 2022-10-29 stsp /* Followed by ncapabilities GOTD_IMSG_CAPABILITY. */
191 f1752522 2022-10-29 stsp };
192 f1752522 2022-10-29 stsp
193 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_LIST_REFS. */
194 13b2bc37 2022-10-23 stsp struct gotd_imsg_list_refs {
195 13b2bc37 2022-10-23 stsp char repo_name[NAME_MAX];
196 13b2bc37 2022-10-23 stsp int client_is_reading; /* 1 if reading, 0 if writing */
197 13b2bc37 2022-10-23 stsp };
198 13b2bc37 2022-10-23 stsp
199 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_LIST_REFS_INTERNAL. */
200 13b2bc37 2022-10-23 stsp struct gotd_imsg_list_refs_internal {
201 13b2bc37 2022-10-23 stsp uint32_t client_id;
202 13b2bc37 2022-10-23 stsp };
203 13b2bc37 2022-10-23 stsp
204 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_REFLIST. */
205 13b2bc37 2022-10-23 stsp struct gotd_imsg_reflist {
206 13b2bc37 2022-10-23 stsp size_t nrefs;
207 13b2bc37 2022-10-23 stsp
208 13b2bc37 2022-10-23 stsp /* Followed by nrefs times of gotd_imsg_ref/gotd_imsg_symref data. */
209 13b2bc37 2022-10-23 stsp } __attribute__((__packed__));
210 13b2bc37 2022-10-23 stsp
211 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_REF data. */
212 13b2bc37 2022-10-23 stsp struct gotd_imsg_ref {
213 13b2bc37 2022-10-23 stsp uint8_t id[SHA1_DIGEST_LENGTH];
214 13b2bc37 2022-10-23 stsp size_t name_len;
215 13b2bc37 2022-10-23 stsp /* Followed by name_len data bytes. */
216 13b2bc37 2022-10-23 stsp } __attribute__((__packed__));
217 13b2bc37 2022-10-23 stsp
218 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_SYMREF data. */
219 13b2bc37 2022-10-23 stsp struct gotd_imsg_symref {
220 13b2bc37 2022-10-23 stsp size_t name_len;
221 13b2bc37 2022-10-23 stsp size_t target_len;
222 13b2bc37 2022-10-23 stsp uint8_t target_id[SHA1_DIGEST_LENGTH];
223 13b2bc37 2022-10-23 stsp
224 13b2bc37 2022-10-23 stsp /*
225 13b2bc37 2022-10-23 stsp * Followed by name_len + target_len data bytes.
226 13b2bc37 2022-10-23 stsp */
227 13b2bc37 2022-10-23 stsp } __attribute__((__packed__));
228 13b2bc37 2022-10-23 stsp
229 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_CAPABILITIES data. */
230 13b2bc37 2022-10-23 stsp struct gotd_imsg_capabilities {
231 13b2bc37 2022-10-23 stsp size_t ncapabilities;
232 13b2bc37 2022-10-23 stsp
233 13b2bc37 2022-10-23 stsp /*
234 13b2bc37 2022-10-23 stsp * Followed by ncapabilities * GOTD_IMSG_CAPABILITY.
235 13b2bc37 2022-10-23 stsp */
236 13b2bc37 2022-10-23 stsp } __attribute__((__packed__));
237 13b2bc37 2022-10-23 stsp
238 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_CAPABILITY data. */
239 13b2bc37 2022-10-23 stsp struct gotd_imsg_capability {
240 13b2bc37 2022-10-23 stsp size_t key_len;
241 13b2bc37 2022-10-23 stsp size_t value_len;
242 13b2bc37 2022-10-23 stsp
243 13b2bc37 2022-10-23 stsp /*
244 13b2bc37 2022-10-23 stsp * Followed by key_len + value_len data bytes.
245 13b2bc37 2022-10-23 stsp */
246 13b2bc37 2022-10-23 stsp } __attribute__((__packed__));
247 13b2bc37 2022-10-23 stsp
248 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_WANT data. */
249 13b2bc37 2022-10-23 stsp struct gotd_imsg_want {
250 13b2bc37 2022-10-23 stsp uint8_t object_id[SHA1_DIGEST_LENGTH];
251 13b2bc37 2022-10-23 stsp uint32_t client_id;
252 13b2bc37 2022-10-23 stsp } __attribute__((__packed__));
253 13b2bc37 2022-10-23 stsp
254 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_HAVE data. */
255 13b2bc37 2022-10-23 stsp struct gotd_imsg_have {
256 13b2bc37 2022-10-23 stsp uint8_t object_id[SHA1_DIGEST_LENGTH];
257 13b2bc37 2022-10-23 stsp uint32_t client_id;
258 13b2bc37 2022-10-23 stsp } __attribute__((__packed__));
259 13b2bc37 2022-10-23 stsp
260 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_ACK data. */
261 13b2bc37 2022-10-23 stsp struct gotd_imsg_ack {
262 13b2bc37 2022-10-23 stsp uint8_t object_id[SHA1_DIGEST_LENGTH];
263 13b2bc37 2022-10-23 stsp uint32_t client_id;
264 13b2bc37 2022-10-23 stsp } __attribute__((__packed__));
265 13b2bc37 2022-10-23 stsp
266 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_NAK data. */
267 13b2bc37 2022-10-23 stsp struct gotd_imsg_nak {
268 13b2bc37 2022-10-23 stsp uint8_t object_id[SHA1_DIGEST_LENGTH];
269 13b2bc37 2022-10-23 stsp uint32_t client_id;
270 13b2bc37 2022-10-23 stsp } __attribute__((__packed__));
271 13b2bc37 2022-10-23 stsp
272 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_PACKFILE_STATUS data. */
273 13b2bc37 2022-10-23 stsp struct gotd_imsg_packfile_status {
274 13b2bc37 2022-10-23 stsp size_t reason_len;
275 13b2bc37 2022-10-23 stsp
276 13b2bc37 2022-10-23 stsp /* Followed by reason_len data bytes. */
277 13b2bc37 2022-10-23 stsp } __attribute__((__packed__));
278 13b2bc37 2022-10-23 stsp
279 13b2bc37 2022-10-23 stsp
280 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_REF_UPDATE data. */
281 13b2bc37 2022-10-23 stsp struct gotd_imsg_ref_update {
282 13b2bc37 2022-10-23 stsp uint8_t old_id[SHA1_DIGEST_LENGTH];
283 13b2bc37 2022-10-23 stsp uint8_t new_id[SHA1_DIGEST_LENGTH];
284 13b2bc37 2022-10-23 stsp int ref_is_new;
285 13b2bc37 2022-10-23 stsp uint32_t client_id;
286 13b2bc37 2022-10-23 stsp size_t name_len;
287 13b2bc37 2022-10-23 stsp
288 13b2bc37 2022-10-23 stsp /* Followed by name_len data bytes. */
289 13b2bc37 2022-10-23 stsp } __attribute__((__packed__));
290 13b2bc37 2022-10-23 stsp
291 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_REF_UPDATES_START data. */
292 13b2bc37 2022-10-23 stsp struct gotd_imsg_ref_updates_start {
293 13b2bc37 2022-10-23 stsp int nref_updates;
294 13b2bc37 2022-10-23 stsp uint32_t client_id;
295 13b2bc37 2022-10-23 stsp
296 13b2bc37 2022-10-23 stsp /* Followed by nref_updates GOT_IMSG_REF_UPDATE_OK/NG messages. */
297 13b2bc37 2022-10-23 stsp };
298 13b2bc37 2022-10-23 stsp
299 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_REF_UPDATE_OK data. */
300 13b2bc37 2022-10-23 stsp struct gotd_imsg_ref_update_ok {
301 13b2bc37 2022-10-23 stsp uint8_t old_id[SHA1_DIGEST_LENGTH];
302 13b2bc37 2022-10-23 stsp uint8_t new_id[SHA1_DIGEST_LENGTH];
303 13b2bc37 2022-10-23 stsp int ref_is_new;
304 13b2bc37 2022-10-23 stsp uint32_t client_id;
305 13b2bc37 2022-10-23 stsp size_t name_len;
306 13b2bc37 2022-10-23 stsp
307 13b2bc37 2022-10-23 stsp /* Followed by name_len data bytes. */
308 13b2bc37 2022-10-23 stsp } __attribute__((__packed__));
309 13b2bc37 2022-10-23 stsp
310 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_REF_UPDATE_NG data. */
311 13b2bc37 2022-10-23 stsp struct gotd_imsg_ref_update_ng {
312 13b2bc37 2022-10-23 stsp uint8_t old_id[SHA1_DIGEST_LENGTH];
313 13b2bc37 2022-10-23 stsp uint8_t new_id[SHA1_DIGEST_LENGTH];
314 13b2bc37 2022-10-23 stsp uint32_t client_id;
315 13b2bc37 2022-10-23 stsp size_t name_len;
316 13b2bc37 2022-10-23 stsp size_t reason_len;
317 13b2bc37 2022-10-23 stsp
318 13b2bc37 2022-10-23 stsp /* Followed by name_len + reason_len data bytes. */
319 13b2bc37 2022-10-23 stsp } __attribute__((__packed__));
320 13b2bc37 2022-10-23 stsp
321 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_SEND_PACKFILE data. */
322 13b2bc37 2022-10-23 stsp struct gotd_imsg_send_packfile {
323 13b2bc37 2022-10-23 stsp uint32_t client_id;
324 13b2bc37 2022-10-23 stsp int report_progress;
325 13b2bc37 2022-10-23 stsp
326 13b2bc37 2022-10-23 stsp /* delta cache file is sent as a file descriptor */
327 13b2bc37 2022-10-23 stsp
328 13b2bc37 2022-10-23 stsp /* followed by two GOTD_IMSG_PACKFILE_PIPE messages */
329 13b2bc37 2022-10-23 stsp };
330 13b2bc37 2022-10-23 stsp
331 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_RECV_PACKFILE data. */
332 13b2bc37 2022-10-23 stsp struct gotd_imsg_recv_packfile {
333 13b2bc37 2022-10-23 stsp uint32_t client_id;
334 13b2bc37 2022-10-23 stsp int report_status;
335 13b2bc37 2022-10-23 stsp
336 13b2bc37 2022-10-23 stsp /* pack destination temp file is sent as a file descriptor */
337 13b2bc37 2022-10-23 stsp };
338 13b2bc37 2022-10-23 stsp
339 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_PACKFILE_PIPE data. */
340 13b2bc37 2022-10-23 stsp struct gotd_imsg_packfile_pipe {
341 13b2bc37 2022-10-23 stsp uint32_t client_id;
342 13b2bc37 2022-10-23 stsp };
343 13b2bc37 2022-10-23 stsp
344 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_PACKIDX_FILE data. */
345 13b2bc37 2022-10-23 stsp struct gotd_imsg_packidx_file {
346 13b2bc37 2022-10-23 stsp uint32_t client_id;
347 13b2bc37 2022-10-23 stsp };
348 13b2bc37 2022-10-23 stsp
349 13b2bc37 2022-10-23 stsp
350 13b2bc37 2022-10-23 stsp /*
351 13b2bc37 2022-10-23 stsp * Structure for GOTD_IMSG_PACKFILE_PROGRESS and
352 13b2bc37 2022-10-23 stsp * GOTD_IMSG_PACKFILE_READY data.
353 13b2bc37 2022-10-23 stsp */
354 13b2bc37 2022-10-23 stsp struct gotd_imsg_packfile_progress {
355 13b2bc37 2022-10-23 stsp uint32_t client_id;
356 13b2bc37 2022-10-23 stsp int ncolored;
357 13b2bc37 2022-10-23 stsp int nfound;
358 13b2bc37 2022-10-23 stsp int ntrees;
359 13b2bc37 2022-10-23 stsp off_t packfile_size;
360 13b2bc37 2022-10-23 stsp int ncommits;
361 13b2bc37 2022-10-23 stsp int nobj_total;
362 13b2bc37 2022-10-23 stsp int nobj_deltify;
363 13b2bc37 2022-10-23 stsp int nobj_written;
364 13b2bc37 2022-10-23 stsp };
365 13b2bc37 2022-10-23 stsp
366 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_PACKFILE_INSTALL. */
367 13b2bc37 2022-10-23 stsp struct gotd_imsg_packfile_install {
368 13b2bc37 2022-10-23 stsp uint32_t client_id;
369 13b2bc37 2022-10-23 stsp uint8_t pack_sha1[SHA1_DIGEST_LENGTH];
370 13b2bc37 2022-10-23 stsp };
371 13b2bc37 2022-10-23 stsp
372 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_PACKFILE_DONE data. */
373 13b2bc37 2022-10-23 stsp struct gotd_imsg_packfile_done {
374 13b2bc37 2022-10-23 stsp uint32_t client_id;
375 13b2bc37 2022-10-23 stsp };
376 13b2bc37 2022-10-23 stsp
377 13b2bc37 2022-10-23 stsp /* Structure for GOTD_IMSG_DISCONNECT data. */
378 13b2bc37 2022-10-23 stsp struct gotd_imsg_disconnect {
379 13b2bc37 2022-10-23 stsp uint32_t client_id;
380 13b2bc37 2022-10-23 stsp };
381 13b2bc37 2022-10-23 stsp
382 13b2bc37 2022-10-23 stsp int parse_config(const char *, enum gotd_procid, struct gotd *);
383 13b2bc37 2022-10-23 stsp
384 13b2bc37 2022-10-23 stsp /* imsg.c */
385 13b2bc37 2022-10-23 stsp const struct got_error *gotd_imsg_flush(struct imsgbuf *);
386 13b2bc37 2022-10-23 stsp const struct got_error *gotd_imsg_recv(struct imsg *, struct imsgbuf *, size_t);
387 13b2bc37 2022-10-23 stsp const struct got_error *gotd_imsg_poll_recv(struct imsg *, struct imsgbuf *,
388 13b2bc37 2022-10-23 stsp size_t);
389 13b2bc37 2022-10-23 stsp const struct got_error *gotd_imsg_recv_error(uint32_t *client_id,
390 13b2bc37 2022-10-23 stsp struct imsg *imsg);
391 13b2bc37 2022-10-23 stsp int gotd_imsg_send_error(struct imsgbuf *ibuf, uint32_t, uint32_t,
392 13b2bc37 2022-10-23 stsp const struct got_error *);
393 13b2bc37 2022-10-23 stsp int gotd_imsg_send_error_event(struct gotd_imsgev *, uint32_t, uint32_t,
394 13b2bc37 2022-10-23 stsp const struct got_error *);
395 13b2bc37 2022-10-23 stsp void gotd_imsg_event_add(struct gotd_imsgev *);
396 13b2bc37 2022-10-23 stsp int gotd_imsg_compose_event(struct gotd_imsgev *, uint16_t, uint32_t, int,
397 13b2bc37 2022-10-23 stsp void *, uint16_t);
398 13b2bc37 2022-10-23 stsp int gotd_imsg_forward(struct gotd_imsgev *, struct imsg *, int);
399 13b2bc37 2022-10-23 stsp
400 13b2bc37 2022-10-23 stsp void gotd_imsg_send_ack(struct got_object_id *, struct imsgbuf *,
401 13b2bc37 2022-10-23 stsp uint32_t, pid_t);
402 13b2bc37 2022-10-23 stsp void gotd_imsg_send_nak(struct got_object_id *, struct imsgbuf *,
403 13b2bc37 2022-10-23 stsp uint32_t, pid_t);