summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-09-30 17:23:18 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-09-30 17:23:18 +0800
commitb3c064e52a5b1ef26a7c79033a4e79cf11cca770 (patch)
tree13afafd17d1350a6f1dd19ec4a1a6926a184e95d
parent813bf434512409f323b1b1d3b6fdcd70ab2cc9e2 (diff)
downloadpttbbs-b3c064e52a5b1ef26a7c79033a4e79cf11cca770.tar
pttbbs-b3c064e52a5b1ef26a7c79033a4e79cf11cca770.tar.gz
pttbbs-b3c064e52a5b1ef26a7c79033a4e79cf11cca770.tar.bz2
pttbbs-b3c064e52a5b1ef26a7c79033a4e79cf11cca770.tar.lz
pttbbs-b3c064e52a5b1ef26a7c79033a4e79cf11cca770.tar.xz
pttbbs-b3c064e52a5b1ef26a7c79033a4e79cf11cca770.tar.zst
pttbbs-b3c064e52a5b1ef26a7c79033a4e79cf11cca770.zip
* add termtype call back (although we don't really trust it at this moment...)
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4896 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--common/sys/telnet.c34
-rw-r--r--include/cmsys.h11
2 files changed, 33 insertions, 12 deletions
diff --git a/common/sys/telnet.c b/common/sys/telnet.c
index 7d3d0eea..931ac526 100644
--- a/common/sys/telnet.c
+++ b/common/sys/telnet.c
@@ -4,6 +4,7 @@
* Improved by Kuang 2009
*/
+// #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
@@ -56,26 +57,32 @@ void telnet_ctx_init(TelnetCtx *ctx, const struct TelnetCallback *callback, int
ctx->fd = fd;
}
-void telnet_ctx_set_cc_arg(TelnetCtx *ctx, void *cc_arg)
+void telnet_ctx_set_cc_arg(TelnetCtx *ctx, void *arg)
{
- ctx->cc_arg = cc_arg;
+ ctx->cc_arg = arg;
}
-void telnet_ctx_set_write_arg(TelnetCtx *ctx, void *write_arg)
+void telnet_ctx_set_write_arg(TelnetCtx *ctx, void *arg)
{
- ctx->write_arg = write_arg;
+ ctx->write_arg = arg;
}
-void telnet_ctx_set_resize_arg(TelnetCtx *ctx, void *resize_arg)
+void telnet_ctx_set_resize_arg(TelnetCtx *ctx, void *arg)
{
- ctx->resize_arg = resize_arg;
+ ctx->resize_arg = arg;
}
-void telnet_ctx_set_ayt_arg(TelnetCtx *ctx, void *ayt_arg)
+void telnet_ctx_set_ayt_arg(TelnetCtx *ctx, void *arg)
{
- ctx->ayt_arg = ayt_arg;
+ ctx->ayt_arg = arg;
}
+void telnet_ctx_set_ttype_arg (TelnetCtx *ctx, void *arg)
+{
+ ctx->ttype_arg = 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.
@@ -313,6 +320,8 @@ telnet_handler(TelnetCtx *ctx, unsigned char c)
ctx->iac_buf[ctx->iac_buflen++] = c;
/* no need to convert state because previous quoting will do. */
+ // XXX BUG max length of TERMTYPE is 40 characters...
+ // (and one extra NUL for prefix 'IS')
if(ctx->iac_buflen == TELNET_IAC_MAXLEN) {
/* may be broken protocol?
* whether finished or not, break for safety
@@ -360,6 +369,15 @@ telnet_handler(TelnetCtx *ctx, unsigned char c)
}
break;
+ case TELOPT_TTYPE:
+ // XXX termtype is in ctx->iac_buf+2
+ // iac_buf: TTYPE=24 IS=0 NVT_ASCII ...
+ if (ctx->callback->ttype && ctx->iac_buflen > 2)
+ ctx->callback->ttype(
+ ctx->ttype_arg,
+ (char*)ctx->iac_buf+2,
+ ctx->iac_buflen-2);
+ // no break here, let's also update termtype to cc.
default:
if (ctx->cc_arg &&
ctx->callback->update_client_code) {
diff --git a/include/cmsys.h b/include/cmsys.h
index 4574f74b..89ad93d5 100644
--- a/include/cmsys.h
+++ b/include/cmsys.h
@@ -183,6 +183,7 @@ struct TelnetCallback {
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);
+ void (*ttype) (void *ttype_arg, char *ttype, int ttype_len);
};
#define TELNET_IAC_MAXLEN (16)
@@ -204,6 +205,7 @@ struct TelnetCtx {
void *resize_arg; // term_resize
void *cc_arg; // update_client_code
void *ayt_arg; // send_ayt
+ void *ttype_arg; // term_type (ttype)
};
typedef struct TelnetCtx TelnetCtx;
@@ -213,10 +215,11 @@ extern void telnet_free_context (TelnetCtx *ctx);
extern void telnet_ctx_init (TelnetCtx *ctx, const struct TelnetCallback *callback, int fd);
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 void telnet_ctx_set_cc_arg (TelnetCtx *ctx, void *arg);
+extern void telnet_ctx_set_write_arg (TelnetCtx *ctx, void *arg);
+extern void telnet_ctx_set_resize_arg(TelnetCtx *ctx, void *arg);
+extern void telnet_ctx_set_ayt_arg (TelnetCtx *ctx, void *arg);
+extern void telnet_ctx_set_ttype_arg (TelnetCtx *ctx, void *arg);
extern ssize_t telnet_process (TelnetCtx *ctx, unsigned char *buf, ssize_t size);