Lines Matching refs:sess
61 #define address_expr ctl_sa_ntop((struct sockaddr *)&sess->sa, \
112 LIST(struct ctl_sess) sess;
202 INIT_LIST(ctx->sess); in ctl_server()
275 me, ctx, ctx->sock, ctx->acID.opaque, ctx->sess); in ctl_endserver()
284 for (this = HEAD(ctx->sess); this != NULL; this = next) { in ctl_endserver()
296 ctl_response(struct ctl_sess *sess, u_int code, const char *text, in ctl_response() argument
302 struct ctl_sctx *ctx = sess->ctx; in ctl_response()
306 REQUIRE(sess->state == initializing || in ctl_response()
307 sess->state == processing || in ctl_response()
308 sess->state == reading_data || in ctl_response()
309 sess->state == writing); in ctl_response()
310 REQUIRE(sess->wrtiID.opaque == NULL); in ctl_response()
311 REQUIRE(sess->wrID.opaque == NULL); in ctl_response()
312 ctl_new_state(sess, writing, me); in ctl_response()
313 sess->donefunc = donefunc; in ctl_response()
314 sess->uap = uap; in ctl_response()
315 if (!allocated_p(sess->outbuf) && in ctl_response()
316 ctl_bufget(&sess->outbuf, ctx->logger) < 0) { in ctl_response()
326 sess->outbuf.used = SPRINTF((sess->outbuf.text, "%03d%c%s\r\n", in ctl_response()
329 for (pc = sess->outbuf.text, n = 0; in ctl_response()
330 n < (int)sess->outbuf.used-2; pc++, n++) in ctl_response()
334 *iovp++ = evConsIovec(sess->outbuf.text, sess->outbuf.used); in ctl_response()
343 sess->outbuf.used, sess->outbuf.text); in ctl_response()
344 if (evWrite(ctx->ev, sess->sock, iov, iovp - iov, in ctl_response()
345 ctl_writedone, sess, &sess->wrID) < 0) { in ctl_response()
350 if (evSetIdleTimer(ctx->ev, ctl_wrtimeout, sess, ctx->timeout, in ctl_response()
351 &sess->wrtiID) < 0) in ctl_response()
357 if (evTimeRW(ctx->ev, sess->wrID, sess->wrtiID) < 0) { in ctl_response()
361 ctl_signal_done(ctx, sess); in ctl_response()
362 ctl_close(sess); in ctl_response()
365 sess->respctx = respctx; in ctl_response()
366 sess->respflags = flags; in ctl_response()
370 ctl_sendhelp(struct ctl_sess *sess, u_int code) { in ctl_sendhelp() argument
372 struct ctl_sctx *ctx = sess->ctx; in ctl_sendhelp()
374 sess->helpcode = code; in ctl_sendhelp()
375 sess->verb = &fakehelpverb; in ctl_sendhelp()
376 ctl_morehelp(ctx, sess, NULL, me, CTL_MORE, in ctl_sendhelp()
381 ctl_getcsctx(struct ctl_sess *sess) { in ctl_getcsctx() argument
382 return (sess->csctx); in ctl_getcsctx()
386 ctl_setcsctx(struct ctl_sess *sess, void *csctx) { in ctl_setcsctx() argument
387 void *old = sess->csctx; in ctl_setcsctx()
389 sess->csctx = csctx; in ctl_setcsctx()
402 struct ctl_sess *sess = NULL; in ctl_accept() local
422 sess = memget(sizeof *sess); in ctl_accept()
423 if (sess == NULL) { in ctl_accept()
434 INIT_LINK(sess, link); in ctl_accept()
435 APPEND(ctx->sess, sess, link); in ctl_accept()
436 sess->ctx = ctx; in ctl_accept()
437 sess->sock = fd; in ctl_accept()
438 sess->wrID.opaque = NULL; in ctl_accept()
439 sess->rdID.opaque = NULL; in ctl_accept()
440 sess->wrtiID.opaque = NULL; in ctl_accept()
441 sess->rdtiID.opaque = NULL; in ctl_accept()
442 sess->respctx = NULL; in ctl_accept()
443 sess->csctx = NULL; in ctl_accept()
446 (struct sockaddr *)&sess->sa); in ctl_accept()
449 (struct sockaddr *)&sess->sa); in ctl_accept()
450 sess->donefunc = NULL; in ctl_accept()
451 buffer_init(sess->inbuf); in ctl_accept()
452 buffer_init(sess->outbuf); in ctl_accept()
453 sess->state = available; in ctl_accept()
454 ctl_new_state(sess, initializing, me); in ctl_accept()
455 sess->verb = ctx->connverb; in ctl_accept()
457 me, address_expr, sess->sock); in ctl_accept()
458 (*ctx->connverb->func)(ctx, sess, ctx->connverb, "", 0, in ctl_accept()
463 ctl_new_state(struct ctl_sess *sess, enum state new_state, const char *reason) in ctl_new_state() argument
466 struct ctl_sctx *ctx = sess->ctx; in ctl_new_state()
471 state_names[sess->state], in ctl_new_state()
473 sess->state = new_state; in ctl_new_state()
477 ctl_close(struct ctl_sess *sess) { in ctl_close() argument
479 struct ctl_sctx *ctx = sess->ctx; in ctl_close()
482 REQUIRE(sess->state == initializing || in ctl_close()
483 sess->state == writing || in ctl_close()
484 sess->state == reading || in ctl_close()
485 sess->state == processing || in ctl_close()
486 sess->state == reading_data || in ctl_close()
487 sess->state == idling); in ctl_close()
488 REQUIRE(sess->sock != -1); in ctl_close()
489 if (sess->state == reading || sess->state == reading_data) in ctl_close()
490 ctl_stop_read(sess); in ctl_close()
491 else if (sess->state == writing) { in ctl_close()
492 if (sess->wrID.opaque != NULL) { in ctl_close()
493 (void) evCancelRW(ctx->ev, sess->wrID); in ctl_close()
494 sess->wrID.opaque = NULL; in ctl_close()
496 if (sess->wrtiID.opaque != NULL) { in ctl_close()
497 (void) evClearIdleTimer(ctx->ev, sess->wrtiID); in ctl_close()
498 sess->wrtiID.opaque = NULL; in ctl_close()
501 ctl_new_state(sess, closing, me); in ctl_close()
502 (void) close(sess->sock); in ctl_close()
503 if (allocated_p(sess->inbuf)) in ctl_close()
504 ctl_bufput(&sess->inbuf); in ctl_close()
505 if (allocated_p(sess->outbuf)) in ctl_close()
506 ctl_bufput(&sess->outbuf); in ctl_close()
508 me, address_expr, sess->sock); in ctl_close()
509 UNLINK(ctx->sess, sess, link); in ctl_close()
510 memput(sess, sizeof *sess); in ctl_close()
515 ctl_start_read(struct ctl_sess *sess) { in ctl_start_read() argument
517 struct ctl_sctx *ctx = sess->ctx; in ctl_start_read()
520 REQUIRE(sess->state == initializing || in ctl_start_read()
521 sess->state == writing || in ctl_start_read()
522 sess->state == processing || in ctl_start_read()
523 sess->state == idling); in ctl_start_read()
524 REQUIRE(sess->rdtiID.opaque == NULL); in ctl_start_read()
525 REQUIRE(sess->rdID.opaque == NULL); in ctl_start_read()
526 sess->inbuf.used = 0; in ctl_start_read()
527 if (evSetIdleTimer(ctx->ev, ctl_rdtimeout, sess, ctx->timeout, in ctl_start_read()
528 &sess->rdtiID) < 0) in ctl_start_read()
532 ctl_close(sess); in ctl_start_read()
535 if (evSelectFD(ctx->ev, sess->sock, EV_READ, in ctl_start_read()
536 ctl_readable, sess, &sess->rdID) < 0) { in ctl_start_read()
541 ctl_new_state(sess, reading, me); in ctl_start_read()
545 ctl_stop_read(struct ctl_sess *sess) { in ctl_stop_read() argument
547 struct ctl_sctx *ctx = sess->ctx; in ctl_stop_read()
549 REQUIRE(sess->state == reading || sess->state == reading_data); in ctl_stop_read()
550 REQUIRE(sess->rdID.opaque != NULL); in ctl_stop_read()
551 (void) evDeselectFD(ctx->ev, sess->rdID); in ctl_stop_read()
552 sess->rdID.opaque = NULL; in ctl_stop_read()
553 if (sess->rdtiID.opaque != NULL) { in ctl_stop_read()
554 (void) evClearIdleTimer(ctx->ev, sess->rdtiID); in ctl_stop_read()
555 sess->rdtiID.opaque = NULL; in ctl_stop_read()
557 ctl_new_state(sess, idling, me); in ctl_stop_read()
563 struct ctl_sess *sess = uap; in ctl_readable() local
568 REQUIRE(sess != NULL); in ctl_readable()
571 REQUIRE(sess->state == reading || sess->state == reading_data); in ctl_readable()
573 ctx = sess->ctx; in ctl_readable()
574 evTouchIdleTimer(lev, sess->rdtiID); in ctl_readable()
575 if (!allocated_p(sess->inbuf) && in ctl_readable()
576 ctl_bufget(&sess->inbuf, ctx->logger) < 0) { in ctl_readable()
579 ctl_close(sess); in ctl_readable()
582 n = read(sess->sock, sess->inbuf.text + sess->inbuf.used, in ctl_readable()
583 MAX_LINELEN - sess->inbuf.used); in ctl_readable()
588 ctl_close(sess); in ctl_readable()
591 sess->inbuf.used += n; in ctl_readable()
592 eos = memchr(sess->inbuf.text, '\n', sess->inbuf.used); in ctl_readable()
593 if (eos != NULL && eos != sess->inbuf.text && eos[-1] == '\r') { in ctl_readable()
595 if ((sess->respflags & CTL_DATA) != 0) { in ctl_readable()
596 INSIST(sess->verb != NULL); in ctl_readable()
597 (*sess->verb->func)(sess->ctx, sess, sess->verb, in ctl_readable()
598 sess->inbuf.text, in ctl_readable()
599 CTL_DATA, sess->respctx, in ctl_readable()
600 sess->ctx->uctx); in ctl_readable()
602 ctl_stop_read(sess); in ctl_readable()
603 ctl_docommand(sess); in ctl_readable()
605 sess->inbuf.used -= ((eos - sess->inbuf.text) + 1); in ctl_readable()
606 if (sess->inbuf.used == 0U) in ctl_readable()
607 ctl_bufput(&sess->inbuf); in ctl_readable()
609 memmove(sess->inbuf.text, eos + 1, sess->inbuf.used); in ctl_readable()
612 if (sess->inbuf.used == (size_t)MAX_LINELEN) { in ctl_readable()
615 ctl_close(sess); in ctl_readable()
625 struct ctl_sess *sess = uap; in ctl_wrtimeout() local
626 struct ctl_sctx *ctx = sess->ctx; in ctl_wrtimeout()
633 REQUIRE(sess->state == writing); in ctl_wrtimeout()
634 sess->wrtiID.opaque = NULL; in ctl_wrtimeout()
637 if (sess->wrID.opaque != NULL) { in ctl_wrtimeout()
638 (void) evCancelRW(ctx->ev, sess->wrID); in ctl_wrtimeout()
639 sess->wrID.opaque = NULL; in ctl_wrtimeout()
641 ctl_signal_done(ctx, sess); in ctl_wrtimeout()
642 ctl_new_state(sess, processing, me); in ctl_wrtimeout()
643 ctl_close(sess); in ctl_wrtimeout()
652 struct ctl_sess *sess = uap; in ctl_rdtimeout() local
653 struct ctl_sctx *ctx = sess->ctx; in ctl_rdtimeout()
660 REQUIRE(sess->state == reading); in ctl_rdtimeout()
661 sess->rdtiID.opaque = NULL; in ctl_rdtimeout()
664 if (sess->state == reading || sess->state == reading_data) in ctl_rdtimeout()
665 ctl_stop_read(sess); in ctl_rdtimeout()
666 ctl_signal_done(ctx, sess); in ctl_rdtimeout()
667 ctl_new_state(sess, processing, me); in ctl_rdtimeout()
668 ctl_response(sess, ctx->timeoutcode, "Timeout.", CTL_EXIT, NULL, in ctl_rdtimeout()
673 ctl_docommand(struct ctl_sess *sess) { in ctl_docommand() argument
676 struct ctl_sctx *ctx = sess->ctx; in ctl_docommand()
679 REQUIRE(allocated_p(sess->inbuf)); in ctl_docommand()
682 sess->inbuf.text, (u_int)sess->inbuf.used); in ctl_docommand()
683 ctl_new_state(sess, processing, me); in ctl_docommand()
684 name = sess->inbuf.text + strspn(sess->inbuf.text, space); in ctl_docommand()
696 sess->verb = verb; in ctl_docommand()
697 (*verb->func)(ctx, sess, verb, rest, 0, NULL, ctx->uctx); in ctl_docommand()
708 ctl_response(sess, ctx->unkncode, buf, 0, NULL, NULL, NULL, in ctl_docommand()
716 struct ctl_sess *sess = uap; in ctl_writedone() local
717 struct ctl_sctx *ctx = sess->ctx; in ctl_writedone()
724 REQUIRE(sess->state == writing); in ctl_writedone()
725 REQUIRE(fd == sess->sock); in ctl_writedone()
726 REQUIRE(sess->wrtiID.opaque != NULL); in ctl_writedone()
727 sess->wrID.opaque = NULL; in ctl_writedone()
728 (void) evClearIdleTimer(ctx->ev, sess->wrtiID); in ctl_writedone()
729 sess->wrtiID.opaque = NULL; in ctl_writedone()
733 ctl_close(sess); in ctl_writedone()
737 INSIST(allocated_p(sess->outbuf)); in ctl_writedone()
738 ctl_bufput(&sess->outbuf); in ctl_writedone()
739 if ((sess->respflags & CTL_EXIT) != 0) { in ctl_writedone()
740 ctl_signal_done(ctx, sess); in ctl_writedone()
741 ctl_close(sess); in ctl_writedone()
743 } else if ((sess->respflags & CTL_MORE) != 0) { in ctl_writedone()
744 INSIST(sess->verb != NULL); in ctl_writedone()
745 (*sess->verb->func)(sess->ctx, sess, sess->verb, "", in ctl_writedone()
746 CTL_MORE, sess->respctx, sess->ctx->uctx); in ctl_writedone()
748 ctl_signal_done(ctx, sess); in ctl_writedone()
749 ctl_start_read(sess); in ctl_writedone()
754 ctl_morehelp(struct ctl_sctx *ctx, struct ctl_sess *sess, in ctl_morehelp() argument
769 ctl_response(sess, sess->helpcode, this->help, respflags, next, in ctl_morehelp()
774 ctl_signal_done(struct ctl_sctx *ctx, struct ctl_sess *sess) { in ctl_signal_done() argument
775 if (sess->donefunc != NULL) { in ctl_signal_done()
776 (*sess->donefunc)(ctx, sess, sess->uap); in ctl_signal_done()
777 sess->donefunc = NULL; in ctl_signal_done()