Home | History | Annotate | Download | only in isc

Lines Matching refs:sess

69 #define	address_expr		ctl_sa_ntop((struct sockaddr *)&sess->sa, \
120 LIST(struct ctl_sess) sess;
210 INIT_LIST(ctx->sess);
282 (*ctx->logger)(ctl_debug, "%s: ctx %p, sock %d, acID %p, sess %p",
283 me, ctx, ctx->sock, ctx->acID.opaque, ctx->sess);
292 for (this = HEAD(ctx->sess); this != NULL; this = next) {
304 ctl_response(struct ctl_sess *sess, u_int code, const char *text,
310 struct ctl_sctx *ctx = sess->ctx;
314 REQUIRE(sess->state == initializing ||
315 sess->state == processing ||
316 sess->state == reading_data ||
317 sess->state == writing);
318 REQUIRE(sess->wrtiID.opaque == NULL);
319 REQUIRE(sess->wrID.opaque == NULL);
320 ctl_new_state(sess, writing, me);
321 sess->donefunc = donefunc;
322 sess->uap = uap;
323 if (!allocated_p(sess->outbuf) &&
324 ctl_bufget(&sess->outbuf, ctx->logger) < 0) {
334 sess->outbuf.used = SPRINTF((sess->outbuf.text, "%03d%c%s\r\n",
337 for (pc = sess->outbuf.text, n = 0;
338 n < (int)sess->outbuf.used-2; pc++, n++)
342 *iovp++ = evConsIovec(sess->outbuf.text, sess->outbuf.used);
351 sess->outbuf.used, sess->outbuf.text);
352 if (evWrite(ctx->ev, sess->sock, iov, iovp - iov,
353 ctl_writedone, sess, &sess->wrID) < 0) {
358 if (evSetIdleTimer(ctx->ev, ctl_wrtimeout, sess, ctx->timeout,
359 &sess->wrtiID) < 0)
365 if (evTimeRW(ctx->ev, sess->wrID, sess->wrtiID) < 0) {
369 ctl_signal_done(ctx, sess);
370 ctl_close(sess);
373 sess->respctx = respctx;
374 sess->respflags = flags;
378 ctl_sendhelp(struct ctl_sess *sess, u_int code) {
380 struct ctl_sctx *ctx = sess->ctx;
382 sess->helpcode = code;
383 sess->verb = &fakehelpverb;
384 ctl_morehelp(ctx, sess, NULL, me, CTL_MORE,
389 ctl_getcsctx(struct ctl_sess *sess) {
390 return (sess->csctx);
394 ctl_setcsctx(struct ctl_sess *sess, void *csctx) {
395 void *old = sess->csctx;
397 sess->csctx = csctx;
410 struct ctl_sess *sess = NULL;
430 sess = memget(sizeof *sess);
431 if (sess == NULL) {
442 INIT_LINK(sess, link);
443 APPEND(ctx->sess, sess, link);
444 sess->ctx = ctx;
445 sess->sock = fd;
446 sess->wrID.opaque = NULL;
447 sess->rdID.opaque = NULL;
448 sess->wrtiID.opaque = NULL;
449 sess->rdtiID.opaque = NULL;
450 sess->respctx = NULL;
451 sess->csctx = NULL;
454 (struct sockaddr *)&sess->sa);
457 (struct sockaddr *)&sess->sa);
458 sess->donefunc = NULL;
459 buffer_init(sess->inbuf);
460 buffer_init(sess->outbuf);
461 sess->state = available;
462 ctl_new_state(sess, initializing, me);
463 sess->verb = ctx->connverb;
465 me, address_expr, sess->sock);
466 (*ctx->connverb->func)(ctx, sess, ctx->connverb, "", 0,
471 ctl_new_state(struct ctl_sess *sess, enum state new_state, const char *reason)
474 struct ctl_sctx *ctx = sess->ctx;
479 state_names[sess->state],
481 sess->state = new_state;
485 ctl_close(struct ctl_sess *sess) {
487 struct ctl_sctx *ctx = sess->ctx;
490 REQUIRE(sess->state == initializing ||
491 sess->state == writing ||
492 sess->state == reading ||
493 sess->state == processing ||
494 sess->state == reading_data ||
495 sess->state == idling);
496 REQUIRE(sess->sock != -1);
497 if (sess->state == reading || sess->state == reading_data)
498 ctl_stop_read(sess);
499 else if (sess->state == writing) {
500 if (sess->wrID.opaque != NULL) {
501 (void) evCancelRW(ctx->ev, sess->wrID);
502 sess->wrID.opaque = NULL;
504 if (sess->wrtiID.opaque != NULL) {
505 (void) evClearIdleTimer(ctx->ev, sess->wrtiID);
506 sess->wrtiID.opaque = NULL;
509 ctl_new_state(sess, closing, me);
510 (void) close(sess->sock);
511 if (allocated_p(sess->inbuf))
512 ctl_bufput(&sess->inbuf);
513 if (allocated_p(sess->outbuf))
514 ctl_bufput(&sess->outbuf);
516 me, address_expr, sess->sock);
517 UNLINK(ctx->sess, sess, link);
518 memput(sess, sizeof *sess);
523 ctl_start_read(struct ctl_sess *sess) {
525 struct ctl_sctx *ctx = sess->ctx;
528 REQUIRE(sess->state == initializing ||
529 sess->state == writing ||
530 sess->state == processing ||
531 sess->state == idling);
532 REQUIRE(sess->rdtiID.opaque == NULL);
533 REQUIRE(sess->rdID.opaque == NULL);
534 sess->inbuf.used = 0;
535 if (evSetIdleTimer(ctx->ev, ctl_rdtimeout, sess, ctx->timeout,
536 &sess->rdtiID) < 0)
540 ctl_close(sess);
543 if (evSelectFD(ctx->ev, sess->sock, EV_READ,
544 ctl_readable, sess, &sess->rdID) < 0) {
549 ctl_new_state(sess, reading, me);
553 ctl_stop_read(struct ctl_sess *sess) {
555 struct ctl_sctx *ctx = sess->ctx;
557 REQUIRE(sess->state == reading || sess->state == reading_data);
558 REQUIRE(sess->rdID.opaque != NULL);
559 (void) evDeselectFD(ctx->ev, sess->rdID);
560 sess->rdID.opaque = NULL;
561 if (sess->rdtiID.opaque != NULL) {
562 (void) evClearIdleTimer(ctx->ev, sess->rdtiID);
563 sess->rdtiID.opaque = NULL;
565 ctl_new_state(sess, idling, me);
571 struct ctl_sess *sess = uap;
576 REQUIRE(sess != NULL);
579 REQUIRE(sess->state == reading || sess->state == reading_data);
581 ctx = sess->ctx;
582 evTouchIdleTimer(lev, sess->rdtiID);
583 if (!allocated_p(sess->inbuf) &&
584 ctl_bufget(&sess->inbuf, ctx->logger) < 0) {
587 ctl_close(sess);
590 n = read(sess->sock, sess->inbuf.text + sess->inbuf.used,
591 MAX_LINELEN - sess->inbuf.used);
596 ctl_close(sess);
599 sess->inbuf.used += n;
600 eos = memchr(sess->inbuf.text, '\n', sess->inbuf.used);
601 if (eos != NULL && eos != sess->inbuf.text && eos[-1] == '\r') {
603 if ((sess->respflags & CTL_DATA) != 0) {
604 sess->verb != NULL);
605 (*sess->verb->func)(sess->ctx, sess, sess->verb,
606 sess->inbuf.text,
607 CTL_DATA, sess->respctx,
608 sess->ctx->uctx);
610 ctl_stop_read(sess);
611 ctl_docommand(sess);
613 sess->inbuf.used -= ((eos - sess->inbuf.text) + 1);
614 if (sess->inbuf.used == 0U)
615 ctl_bufput(&sess->inbuf);
617 memmove(sess->inbuf.text, eos + 1, sess->inbuf.used);
620 if (sess->inbuf.used == (size_t)MAX_LINELEN) {
623 ctl_close(sess);
633 struct ctl_sess *sess = uap;
634 struct ctl_sctx *ctx = sess->ctx;
641 REQUIRE(sess->state == writing);
642 sess->wrtiID.opaque = NULL;
645 if (sess->wrID.opaque != NULL) {
646 (void) evCancelRW(ctx->ev, sess->wrID);
647 sess->wrID.opaque = NULL;
649 ctl_signal_done(ctx, sess);
650 ctl_new_state(sess, processing, me);
651 ctl_close(sess);
660 struct ctl_sess *sess = uap;
661 struct ctl_sctx *ctx = sess->ctx;
668 REQUIRE(sess->state == reading);
669 sess->rdtiID.opaque = NULL;
672 if (sess->state == reading || sess->state == reading_data)
673 ctl_stop_read(sess);
674 ctl_signal_done(ctx, sess);
675 ctl_new_state(sess, processing, me);
676 ctl_response(sess, ctx->timeoutcode, "Timeout.", CTL_EXIT, NULL,
681 ctl_docommand(struct ctl_sess *sess) {
684 struct ctl_sctx *ctx = sess->ctx;
687 REQUIRE(allocated_p(sess->inbuf));
690 sess->inbuf.text, (u_int)sess->inbuf.used);
691 ctl_new_state(sess, processing, me);
692 name = sess->inbuf.text + strspn(sess->inbuf.text, space);
704 sess->verb = verb;
705 (*verb->func)(ctx, sess, verb, rest, 0, NULL, ctx->uctx);
716 ctl_response(sess, ctx->unkncode, buf, 0, NULL, NULL, NULL,
724 struct ctl_sess *sess = uap;
725 struct ctl_sctx *ctx = sess->ctx;
732 REQUIRE(sess->state == writing);
733 REQUIRE(fd == sess->sock);
734 REQUIRE(sess->wrtiID.opaque != NULL);
735 sess->wrID.opaque = NULL;
736 (void) evClearIdleTimer(ctx->ev, sess->wrtiID);
737 sess->wrtiID.opaque = NULL;
741 ctl_close(sess);
745 INSIST(allocated_p(sess->outbuf));
746 ctl_bufput(&sess->outbuf);
747 if ((sess->respflags & CTL_EXIT) != 0) {
748 ctl_signal_done(ctx, sess);
749 ctl_close(sess);
751 } else if ((sess->respflags & CTL_MORE) != 0) {
752 INSIST(sess->verb != NULL);
753 (*sess->verb->func)(sess->ctx, sess, sess->verb, "",
754 CTL_MORE, sess->respctx, sess->ctx->uctx);
756 ctl_signal_done(ctx, sess);
757 ctl_start_read(sess);
762 ctl_morehelp(struct ctl_sctx *ctx, struct ctl_sess *sess,
777 ctl_response(sess, sess->helpcode, this->help, respflags, next,
782 ctl_signal_done(struct ctl_sctx *ctx, struct ctl_sess *sess) {
783 if (sess->donefunc != NULL) {
784 (*sess->donefunc)(ctx, sess, sess->uap);
785 sess->donefunc = NULL;