X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=client_common.c;h=64f6c67612a5c665b87dcdb8d3e051bc7500b455;hb=be5daec66f163725489f42d512659a8af5c3fd59;hp=94a6e86544e63824664b114cc400161d4e223684;hpb=27e8c0dca96754834fcc358cfbab548e0be69eb6;p=paraslash.git diff --git a/client_common.c b/client_common.c index 94a6e865..64f6c676 100644 --- a/client_common.c +++ b/client_common.c @@ -57,7 +57,7 @@ void client_close(struct client_task *ct) * The context pointer is assumed to refer to a client task structure that was * initialized earlier by client_open(). */ -static void client_pre_select(struct sched *s, void *context) +static void client_pre_monitor(struct sched *s, void *context) { int ret; struct client_task *ct = context; @@ -68,13 +68,13 @@ static void client_pre_select(struct sched *s, void *context) case CL_CONNECTED: case CL_SENT_AUTH: case CL_SENT_CH_RESPONSE: - para_fd_set(ct->scc.fd, &s->rfds, &s->max_fileno); + sched_monitor_readfd(ct->scc.fd, s); return; case CL_RECEIVED_WELCOME: case CL_RECEIVED_PROCEED: case CL_RECEIVED_CHALLENGE: - para_fd_set(ct->scc.fd, &s->wfds, &s->max_fileno); + sched_monitor_writefd(ct->scc.fd, s); return; case CL_SENDING: @@ -83,7 +83,7 @@ static void client_pre_select(struct sched *s, void *context) if (ret < 0) sched_min_delay(s); else if (ret > 0) - para_fd_set(ct->scc.fd, &s->wfds, &s->max_fileno); + sched_monitor_writefd(ct->scc.fd, s); } __attribute__ ((fallthrough)); case CL_EXECUTING: @@ -92,7 +92,7 @@ static void client_pre_select(struct sched *s, void *context) if (ret < 0) sched_min_delay(s); else if (ret > 0) - para_fd_set(ct->scc.fd, &s->rfds, &s->max_fileno); + sched_monitor_readfd(ct->scc.fd, s); } return; } @@ -125,8 +125,7 @@ static int send_sb(struct client_task *ct, int channel, void *buf, size_t numbyt return 0; } -static int recv_sb(struct client_task *ct, fd_set *rfds, - struct sb_buffer *result) +static int recv_sb(struct client_task *ct, struct sb_buffer *result) { int ret; size_t n; @@ -134,8 +133,6 @@ static int recv_sb(struct client_task *ct, fd_set *rfds, void *trafo_context; struct iovec iov; - if (!FD_ISSET(ct->scc.fd, rfds)) - return 0; if (ct->status < CL_SENT_CH_RESPONSE) trafo = trafo_context = NULL; else { @@ -146,7 +143,7 @@ static int recv_sb(struct client_task *ct, fd_set *rfds, ct->sbc[0] = sb_new_recv(0, trafo, trafo_context); again: sb_get_recv_buffer(ct->sbc[0], &iov); - ret = read_nonblock(ct->scc.fd, iov.iov_base, iov.iov_len, rfds, &n); + ret = read_nonblock(ct->scc.fd, iov.iov_base, iov.iov_len, &n); if (ret < 0) { sb_free(ct->sbc[0]); ct->sbc[0] = NULL; @@ -248,7 +245,7 @@ static int send_sb_command(struct client_task *ct) for (i = 0; i < num_inputs; i++) len += strlen(lls_input(i, ct->lpr)) + 1; - p = command = para_malloc(len); + p = command = alloc(len); for (i = 0; i < num_inputs; i++) { const char *str = lls_input(i, ct->lpr); strcpy(p, str); @@ -258,9 +255,15 @@ static int send_sb_command(struct client_task *ct) return send_sb(ct, 0, command, len, SBD_COMMAND, false); } +/* Find out if the given string is contained in the features vector. */ static bool has_feature(const char *feature, struct client_task *ct) { - return find_arg(feature, ct->features) >= 0? true : false; + if (!ct->features) + return false; + for (int i = 0; ct->features[i]; i++) + if (strcmp(feature, ct->features[i]) == 0) + return i; + return false; } /* @@ -274,7 +277,7 @@ static bool has_feature(const char *feature, struct client_task *ct) * The context pointer refers to a client task structure that was initialized * earlier by client_open(). */ -static int client_post_select(struct sched *s, void *context) +static int client_post_monitor(struct sched *s, void *context) { struct client_task *ct = context; int ret = 0; @@ -288,7 +291,7 @@ static int client_post_select(struct sched *s, void *context) return 0; switch (ct->status) { case CL_CONNECTED: /* receive welcome message */ - ret = read_nonblock(ct->scc.fd, buf, sizeof(buf), &s->rfds, &n); + ret = read_nonblock(ct->scc.fd, buf, sizeof(buf), &n); if (ret < 0 || n == 0) goto out; ct->features = parse_features(buf); @@ -302,7 +305,7 @@ static int client_post_select(struct sched *s, void *context) * 0.8.0 we no longer need to request the feature. */ bool has_sha256; - if (!FD_ISSET(ct->scc.fd, &s->wfds)) + if (!sched_write_ok(ct->scc.fd, s)) return 0; has_sha256 = has_feature("sha256", ct); sprintf(buf, AUTH_REQUEST_MSG "%s%s", ct->user, has_sha256? @@ -324,7 +327,7 @@ static int client_post_select(struct sched *s, void *context) unsigned char crypt_buf[1024]; struct sb_buffer sbb; - ret = recv_sb(ct, &s->rfds, &sbb); + ret = recv_sb(ct, &sbb); if (ret <= 0) goto out; if (sbb.band != SBD_CHALLENGE) { @@ -339,8 +342,7 @@ static int client_post_select(struct sched *s, void *context) free(sbb.iov.iov_base); if (ret < 0) goto out; - ct->challenge_hash = para_malloc(HASH2_SIZE); - + ct->challenge_hash = alloc(HASH2_SIZE); if (has_feature("sha256", ct)) { hash2_function((char *)crypt_buf, APC_CHALLENGE_SIZE, ct->challenge_hash); hash2_to_asc(ct->challenge_hash, buf); @@ -371,7 +373,7 @@ static int client_post_select(struct sched *s, void *context) case CL_SENT_CH_RESPONSE: /* read server response */ { struct sb_buffer sbb; - ret = recv_sb(ct, &s->rfds, &sbb); + ret = recv_sb(ct, &sbb); if (ret <= 0) goto out; free(sbb.iov.iov_base); @@ -383,7 +385,7 @@ static int client_post_select(struct sched *s, void *context) } case CL_RECEIVED_PROCEED: /* concat args and send command */ { - if (!FD_ISSET(ct->scc.fd, &s->wfds)) + if (!sched_write_ok(ct->scc.fd, s)) return 0; ret = send_sb_command(ct); if (ret <= 0) @@ -405,7 +407,7 @@ static int client_post_select(struct sched *s, void *context) } if (ret < 0) goto close1; - if (ret > 0 && FD_ISSET(ct->scc.fd, &s->wfds)) { + if (ret > 0 && sched_write_ok(ct->scc.fd, s)) { sz = btr_next_buffer(ct->btrn[1], &buf2); assert(sz); ret = send_sb(ct, 1, buf2, sz, SBD_BLOB_DATA, true); @@ -421,9 +423,9 @@ static int client_post_select(struct sched *s, void *context) ret = btr_node_status(ct->btrn[0], 0, BTR_NT_ROOT); if (ret < 0) goto close0; - if (ret > 0 && FD_ISSET(ct->scc.fd, &s->rfds)) { + if (ret > 0 && sched_read_ok(ct->scc.fd, s)) { struct sb_buffer sbb; - ret = recv_sb(ct, &s->rfds, &sbb); + ret = recv_sb(ct, &sbb); if (ret < 0) goto close0; if (ret > 0) { @@ -452,8 +454,7 @@ out: return 0; btr_remove_node(&ct->btrn[0]); btr_remove_node(&ct->btrn[1]); - if (ret != -E_SERVER_CMD_SUCCESS && ret != -E_SERVER_CMD_FAILURE) - PARA_ERROR_LOG("%s\n", para_strerror(-ret)); + PARA_NOTICE_LOG("closing connection (%s)\n", para_strerror(-ret)); if (ct->scc.fd >= 0) { close(ct->scc.fd); ct->scc.fd = -1; @@ -504,8 +505,8 @@ int client_connect(struct client_task *ct, struct sched *s, ct->task = task_register(&(struct task_info) { .name = "client", - .pre_select = client_pre_select, - .post_select = client_post_select, + .pre_monitor = client_pre_monitor, + .post_monitor = client_post_monitor, .context = ct, }, s); return 1; @@ -586,7 +587,7 @@ int client_parse_config(int argc, char *argv[], struct client_task **ct_ptr, PARA_INFO_LOG("user: %s\n", user); PARA_INFO_LOG("key file: %s\n", kf); PARA_INFO_LOG("loglevel: %d\n", ll); - ct = para_calloc(sizeof(*ct)); + ct = zalloc(sizeof(*ct)); ct->scc.fd = -1; ct->lpr = lpr; ct->key_file = kf;