commit - 09486e84b6094ffcb4dca9ecd2dea72a982a1fa9
commit + 818f96befdf8fe0b407ab7fec236b71d57bc3597
blob - 163f482824dd1bbb39949c76de672eb8682b553a
blob + 1565134cdf2580a8d8ad95a1e62986080575bce4
--- gotd/session.c
+++ gotd/session.c
struct gotd_imsgev notifier_iev;
struct timeval request_timeout;
enum gotd_procid proc_id;
+ enum gotd_session_state state;
} gotd_session;
static struct gotd_session_client {
- enum gotd_session_state state;
int is_writing;
struct gotd_client_capability *capabilities;
size_t ncapa_alloc;
send_refs_updated(client);
notif = STAILQ_FIRST(¬ifications);
if (notif) {
- client->state = GOTD_STATE_NOTIFY;
+ gotd_session.state = GOTD_STATE_NOTIFY;
err = request_notification(notif);
if (err) {
log_warn("could not send notification: "
if (err->code == GOT_ERR_PRIVSEP_READ)
err = NULL;
else if (err->code == GOT_ERR_EOF &&
- client->state == GOTD_STATE_EXPECT_CAPABILITIES) {
+ gotd_session.state ==
+ GOTD_STATE_EXPECT_CAPABILITIES) {
/*
* The client has closed its socket before
* sending its capability announcement.
switch (imsg.hdr.type) {
case GOTD_IMSG_CAPABILITIES:
- if (client->state != GOTD_STATE_EXPECT_CAPABILITIES) {
+ if (gotd_session.state !=
+ GOTD_STATE_EXPECT_CAPABILITIES) {
err = got_error_msg(GOT_ERR_BAD_REQUEST,
"unexpected capabilities received");
break;
err = recv_capabilities(client, &imsg);
break;
case GOTD_IMSG_CAPABILITY:
- if (client->state != GOTD_STATE_EXPECT_CAPABILITIES) {
+ if (gotd_session.state != GOTD_STATE_EXPECT_CAPABILITIES) {
err = got_error_msg(GOT_ERR_BAD_REQUEST,
"unexpected capability received");
break;
if (err || client->ncapabilities < client->ncapa_alloc)
break;
if (!client->is_writing) {
- client->state = GOTD_STATE_EXPECT_WANT;
+ gotd_session.state = GOTD_STATE_EXPECT_WANT;
client->accept_flush_pkt = 1;
log_debug("uid %d: expecting want-lines",
client->euid);
} else if (client->is_writing) {
- client->state = GOTD_STATE_EXPECT_REF_UPDATE;
+ gotd_session.state = GOTD_STATE_EXPECT_REF_UPDATE;
client->accept_flush_pkt = 1;
log_debug("uid %d: expecting ref-update-lines",
client->euid);
client->euid);
break;
case GOTD_IMSG_WANT:
- if (client->state != GOTD_STATE_EXPECT_WANT) {
+ if (gotd_session.state != GOTD_STATE_EXPECT_WANT) {
err = got_error_msg(GOT_ERR_BAD_REQUEST,
"unexpected want-line received");
break;
err = forward_want(client, &imsg);
break;
case GOTD_IMSG_REF_UPDATE:
- if (client->state != GOTD_STATE_EXPECT_REF_UPDATE &&
- client->state !=
+ if (gotd_session.state != GOTD_STATE_EXPECT_REF_UPDATE &&
+ gotd_session.state !=
GOTD_STATE_EXPECT_MORE_REF_UPDATES) {
err = got_error_msg(GOT_ERR_BAD_REQUEST,
"unexpected ref-update-line received");
err = forward_ref_update(client, &imsg);
if (err)
break;
- client->state = GOTD_STATE_EXPECT_MORE_REF_UPDATES;
+ gotd_session.state = GOTD_STATE_EXPECT_MORE_REF_UPDATES;
client->accept_flush_pkt = 1;
break;
case GOTD_IMSG_HAVE:
- if (client->state != GOTD_STATE_EXPECT_HAVE) {
+ if (gotd_session.state != GOTD_STATE_EXPECT_HAVE) {
err = got_error_msg(GOT_ERR_BAD_REQUEST,
"unexpected have-line received");
break;
client->accept_flush_pkt = 1;
break;
case GOTD_IMSG_FLUSH:
- if (client->state == GOTD_STATE_EXPECT_WANT ||
- client->state == GOTD_STATE_EXPECT_HAVE) {
+ if (gotd_session.state == GOTD_STATE_EXPECT_WANT ||
+ gotd_session.state == GOTD_STATE_EXPECT_HAVE) {
err = ensure_client_is_reading(client);
if (err)
break;
- } else if (client->state ==
+ } else if (gotd_session.state ==
GOTD_STATE_EXPECT_MORE_REF_UPDATES) {
err = ensure_client_is_writing(client);
if (err)
break;
- } else if (client->state != GOTD_STATE_EXPECT_DONE) {
+ } else if (gotd_session.state != GOTD_STATE_EXPECT_DONE) {
err = got_error_msg(GOT_ERR_BAD_REQUEST,
"unexpected flush-pkt received");
break;
log_debug("received flush-pkt from uid %d",
client->euid);
- if (client->state == GOTD_STATE_EXPECT_WANT) {
- client->state = GOTD_STATE_EXPECT_HAVE;
+ if (gotd_session.state == GOTD_STATE_EXPECT_WANT) {
+ gotd_session.state = GOTD_STATE_EXPECT_HAVE;
log_debug("uid %d: expecting have-lines",
client->euid);
- } else if (client->state == GOTD_STATE_EXPECT_HAVE) {
- client->state = GOTD_STATE_EXPECT_DONE;
+ } else if (gotd_session.state == GOTD_STATE_EXPECT_HAVE) {
+ gotd_session.state = GOTD_STATE_EXPECT_DONE;
client->accept_flush_pkt = 1;
log_debug("uid %d: expecting 'done'",
client->euid);
- } else if (client->state ==
+ } else if (gotd_session.state ==
GOTD_STATE_EXPECT_MORE_REF_UPDATES) {
- client->state = GOTD_STATE_EXPECT_PACKFILE;
+ gotd_session.state = GOTD_STATE_EXPECT_PACKFILE;
log_debug("uid %d: expecting packfile",
client->euid);
err = recv_packfile(client);
- } else if (client->state != GOTD_STATE_EXPECT_DONE) {
+ } else if (gotd_session.state != GOTD_STATE_EXPECT_DONE) {
/* should not happen, see above */
err = got_error_msg(GOT_ERR_BAD_REQUEST,
"unexpected client state");
}
break;
case GOTD_IMSG_DONE:
- if (client->state != GOTD_STATE_EXPECT_HAVE &&
- client->state != GOTD_STATE_EXPECT_DONE) {
+ if (gotd_session.state != GOTD_STATE_EXPECT_HAVE &&
+ gotd_session.state != GOTD_STATE_EXPECT_DONE) {
err = got_error_msg(GOT_ERR_BAD_REQUEST,
"unexpected flush-pkt received");
break;
err = ensure_client_is_reading(client);
if (err)
break;
- client->state = GOTD_STATE_DONE;
+ gotd_session.state = GOTD_STATE_DONE;
client->accept_flush_pkt = 1;
err = send_packfile(client);
break;
if (err) {
if (err->code != GOT_ERR_EOF ||
- client->state != GOTD_STATE_EXPECT_PACKFILE)
+ gotd_session.state != GOTD_STATE_EXPECT_PACKFILE)
disconnect_on_error(client, err);
} else {
gotd_imsg_event_add(iev);
struct gotd_imsg_list_refs_internal ilref;
int fd;
- if (client->state != GOTD_STATE_EXPECT_LIST_REFS)
+ if (gotd_session.state != GOTD_STATE_EXPECT_LIST_REFS)
return got_error(GOT_ERR_PRIVSEP_MSG);
memset(&ilref, 0, sizeof(ilref));
return err;
}
- client->state = GOTD_STATE_EXPECT_CAPABILITIES;
+ gotd_session.state = GOTD_STATE_EXPECT_CAPABILITIES;
log_debug("uid %d: expecting capabilities", client->euid);
return NULL;
}
struct gotd_imsg_connect iconnect;
size_t datalen;
- if (client->state != GOTD_STATE_EXPECT_LIST_REFS)
+ if (gotd_session.state != GOTD_STATE_EXPECT_LIST_REFS)
return got_error(GOT_ERR_PRIVSEP_MSG);
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
switch (imsg.hdr.type) {
case GOTD_IMSG_NOTIFICATION_SENT:
- if (client->state != GOTD_STATE_NOTIFY) {
+ if (gotd_session.state != GOTD_STATE_NOTIFY) {
log_warn("unexpected imsg %d", imsg.hdr.type);
break;
}
size_t datalen;
int fd;
- if (client->state != GOTD_STATE_EXPECT_LIST_REFS)
+ if (gotd_session.state != GOTD_STATE_EXPECT_LIST_REFS)
return got_error(GOT_ERR_PRIVSEP_MSG);
/* We should already have received a pipe to the listener. */
size_t datalen;
int fd;
- if (client->state != GOTD_STATE_EXPECT_LIST_REFS)
+ if (gotd_session.state != GOTD_STATE_EXPECT_LIST_REFS)
return got_error(GOT_ERR_PRIVSEP_MSG);
/* We should already have received a pipe to the listener. */
signal_add(&evsighup, NULL);
signal_add(&evsigusr1, NULL);
- gotd_session_client.state = GOTD_STATE_EXPECT_LIST_REFS;
+ gotd_session.state = GOTD_STATE_EXPECT_LIST_REFS;
+
gotd_session_client.fd = -1;
gotd_session_client.nref_updates = -1;
gotd_session_client.delta_cache_fd = -1;