diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2009-06-12 16:49:57 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2009-06-12 16:49:57 +0800 |
commit | ff9917405ba44a07abc4622201bbfa78c8b82137 (patch) | |
tree | 0da008d1ba37692615d9328950c228c3f2343272 | |
parent | 4bb43f558058ac73ad1a36d489c9deefc19eb869 (diff) | |
download | pttbbs-ff9917405ba44a07abc4622201bbfa78c8b82137.tar pttbbs-ff9917405ba44a07abc4622201bbfa78c8b82137.tar.gz pttbbs-ff9917405ba44a07abc4622201bbfa78c8b82137.tar.bz2 pttbbs-ff9917405ba44a07abc4622201bbfa78c8b82137.tar.lz pttbbs-ff9917405ba44a07abc4622201bbfa78c8b82137.tar.xz pttbbs-ff9917405ba44a07abc4622201bbfa78c8b82137.tar.zst pttbbs-ff9917405ba44a07abc4622201bbfa78c8b82137.zip |
* make AYT customizable
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4571 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | common/sys/telnet.c | 39 | ||||
-rw-r--r-- | include/cmsys.h | 17 |
2 files changed, 33 insertions, 23 deletions
diff --git a/common/sys/telnet.c b/common/sys/telnet.c index 7c1e12c1..7d3d0eea 100644 --- a/common/sys/telnet.c +++ b/common/sys/telnet.c @@ -71,6 +71,11 @@ void telnet_ctx_set_resize_arg(TelnetCtx *ctx, void *resize_arg) ctx->resize_arg = resize_arg; } +void telnet_ctx_set_ayt_arg(TelnetCtx *ctx, void *ayt_arg) +{ + ctx->ayt_arg = ayt_arg; +} + /* We are the boss. We don't respect to client. * It's client's responsibility to follow us. * Please write these codes in i-dont-care opt handlers. @@ -137,6 +142,23 @@ telnet_write (TelnetCtx *ctx, const void *buf, size_t nbytes) write(ctx->fd, buf, nbytes); } +#ifndef _TELNET_DEFAULT_AYT_STRING +#define _TELNET_DEFAULT_AYT_STRING "I'm still alive.\r\n" +#endif +static void +telnet_send_ayt (TelnetCtx *ctx) +{ + if (ctx->callback->send_ayt) + { + ctx->callback->send_ayt(ctx->ayt_arg, ctx->fd); + } + else + { + /* respond as fast as we can */ + telnet_write(ctx, _TELNET_DEFAULT_AYT_STRING, sizeof(_TELNET_DEFAULT_AYT_STRING)-1); + } +} + /* input: raw character * output: telnet command if c was handled, otherwise zero. */ @@ -221,22 +243,7 @@ telnet_handler(TelnetCtx *ctx, unsigned char c) /* good */ case AYT: /* are you there */ - { -#if 0 - const char *alive = " I'm still alive, loading: "; - char buf[STRLEN]; - - /* respond as fast as we can */ - telnet_write(ctx, alive, strlen(alive)); - cpuload(buf); - telnet_write(ctx, buf, strlen(buf)); - telnet_write(ctx, "\r\n", 2); -#else - const char *alive = " I'm still alive.\r\n"; - /* respond as fast as we can */ - telnet_write(ctx, alive, strlen(alive)); -#endif - } + telnet_send_ayt(ctx); return NOP; case DONT: /* you are not to use option */ diff --git a/include/cmsys.h b/include/cmsys.h index 88506039..ae7f6347 100644 --- a/include/cmsys.h +++ b/include/cmsys.h @@ -166,21 +166,22 @@ extern void Vector_init(struct Vector *self, const int size); extern void Vector_init_const(struct Vector *self, char * base, const int length, const int size); extern void Vector_delete(struct Vector *self); extern void Vector_clear(struct Vector *self, const int size); -extern int Vector_length(const struct Vector *self); +extern int Vector_length(const struct Vector *self); extern void Vector_resize(struct Vector *self, const int length); extern void Vector_add(struct Vector *self, const char *name); extern const char* Vector_get(const struct Vector *self, const int idx); -extern int Vector_MaxLen(const struct Vector *list, const int offset, const int count); -extern int Vector_match(const struct Vector *src, struct Vector *dst, const int key, const int pos); +extern int Vector_MaxLen(const struct Vector *list, const int offset, const int count); +extern int Vector_match(const struct Vector *src, struct Vector *dst, const int key, const int pos); extern void Vector_sublist(const struct Vector *src, struct Vector *dst, const char *tag); -extern int Vector_remove(struct Vector *self, const char *name); -extern int Vector_search(const struct Vector *self, const char *name); +extern int Vector_remove(struct Vector *self, const char *name); +extern int Vector_search(const struct Vector *self, const char *name); /* telnet.c */ struct TelnetCallback { void (*write_data) (void *write_arg, int fd, const void *buf, size_t nbytes); - void (*term_resize) (void *resize_arg, int w, int h); - void (*update_client_code) (void *cc_arg, unsigned char seq); + void (*term_resize) (void *resize_arg,int w, int h); + void (*update_client_code) (void *cc_arg, unsigned char seq); + void (*send_ayt) (void *ayt_arg, int fd); }; #define TELNET_IAC_MAXLEN (16) @@ -201,6 +202,7 @@ struct TelnetCtx { void *write_arg; // write_data void *resize_arg; // term_resize void *cc_arg; // update_client_code + void *ayt_arg; // send_ayt }; typedef struct TelnetCtx TelnetCtx; @@ -213,6 +215,7 @@ extern void telnet_ctx_send_init_cmds(TelnetCtx *ctx); extern void telnet_ctx_set_cc_arg (TelnetCtx *ctx, void *cc_arg); extern void telnet_ctx_set_write_arg (TelnetCtx *ctx, void *cc_arg); extern void telnet_ctx_set_resize_arg(TelnetCtx *ctx, void *cc_arg); +extern void telnet_ctx_set_ayt_arg (TelnetCtx *ctx, void *ayt_arg); extern ssize_t telnet_process (TelnetCtx *ctx, unsigned char *buf, ssize_t size); |