svnno****@sourc*****
svnno****@sourc*****
2017年 7月 5日 (水) 00:02:45 JST
Revision: 6842 http://sourceforge.jp/projects/ttssh2/scm/svn/commits/6842 Author: doda Date: 2017-07-05 00:02:44 +0900 (Wed, 05 Jul 2017) Log Message: ----------- ポート転送関連のコード整理 ・デバッグし易さの為に enum に変更 ・forward filter のリソース開放の判断を FWD_FILTER_CLEANUP で呼ばれた時に変更 ・インデントおよび改行位置を一部修正 Modified Paths: -------------- trunk/ttssh2/ttxssh/fwd.c trunk/ttssh2/ttxssh/fwd.h trunk/ttssh2/ttxssh/x11util.c trunk/ttssh2/ttxssh/x11util.h -------------- next part -------------- Modified: trunk/ttssh2/ttxssh/fwd.c =================================================================== --- trunk/ttssh2/ttxssh/fwd.c 2017-07-04 15:02:28 UTC (rev 6841) +++ trunk/ttssh2/ttxssh/fwd.c 2017-07-04 15:02:44 UTC (rev 6842) @@ -279,7 +279,7 @@ else { // TYPE_PORTFWD UTIL_destroy_sock_write_buf(&channel->writebuf); if (channel->filter != NULL) { - channel->filter(channel->filter_closure, 0, NULL, NULL); + channel->filter(channel->filter_closure, FWD_FILTER_CLEANUP, NULL, NULL); channel->filter = NULL; channel->filter_closure = NULL; } @@ -665,25 +665,20 @@ if (amount > 0) { char *new_buf = buf; - int action = FWD_FILTER_RETAIN; + FwdFilterResult action = FWD_FILTER_RETAIN; if (channel->filter != NULL) { - action = - channel->filter(channel->filter_closure, - FWD_FILTER_FROM_CLIENT, &amount, - &new_buf); + action = channel->filter(channel->filter_closure, FWD_FILTER_FROM_CLIENT, &amount, &new_buf); } - if (amount > 0 - && (channel->status & FWD_CLOSED_REMOTE_OUT) == 0) { + if (amount > 0 && (channel->status & FWD_CLOSED_REMOTE_OUT) == 0) { // \x83|\x81[\x83g\x83t\x83H\x83\x8F\x81[\x83f\x83B\x83\x93\x83O\x82ɂ\xA8\x82\xA2\x82ăN\x83\x89\x83C\x83A\x83\x93\x83g\x82\xA9\x82\xE7\x82̑\x97\x90M\x97v\x8B\x81\x82\xF0\x81ASSH\x92ʐM\x82ɏ悹\x82ăT\x81[\x83o\x82܂ő\x97\x82\xE8\x93͂\xAF\x82\xE9\x81B - SSH_channel_send(pvar, channel_num, channel->remote_num, new_buf, - amount, 0); + SSH_channel_send(pvar, channel_num, channel->remote_num, new_buf, amount, 0); } switch (action) { case FWD_FILTER_REMOVE: - channel->filter(channel->filter_closure, 0, NULL, NULL); + channel->filter(channel->filter_closure, FWD_FILTER_CLEANUP, NULL, NULL); channel->filter = NULL; channel->filter_closure = NULL; break; @@ -691,8 +686,7 @@ closed_local_connection(pvar, channel_num); break; } - } else if (amount == 0 - || (err = WSAGetLastError()) == WSAEWOULDBLOCK) { + } else if (amount == 0 || (err = WSAGetLastError()) == WSAEWOULDBLOCK) { return; } else { channel_error(pvar, "reading", channel_num, err); @@ -1584,7 +1578,7 @@ { SOCKET s; FWDChannel *channel; - int action = FWD_FILTER_RETAIN; + FwdFilterResult action = FWD_FILTER_RETAIN; if (!FWD_check_local_channel_num(pvar, local_channel_num)) return; @@ -1592,9 +1586,7 @@ channel = pvar->fwd_state.channels + local_channel_num; if (channel->filter != NULL) { - action = - channel->filter(channel->filter_closure, - FWD_FILTER_FROM_SERVER, &length, &data); + action = channel->filter(channel->filter_closure, FWD_FILTER_FROM_SERVER, &length, &data); } s = channel->local_socket; @@ -1604,8 +1596,7 @@ // \x91\x97\x90M\x82\xB7\x82\xE9\x81B // X\x83T\x81[\x83o\x82ɑ\x97\x90M\x8E\x9E\x82ɔ\xAD\x90\xB6\x82\xB7\x82\xE9 FD_WRITE \x82́A\x8F\x88\x97\x9D\x82\xB7\x82\xE9\x95K\x97v\x82\xAA\x82Ȃ\xA2\x82\xBD\x82ߖ\xB3\x8E\x8B\x82\xB7\x82\xE9\x81B //OutputDebugPrintf("%s: send %d\n", __FUNCTION__, length); - if (!UTIL_sock_buffered_write - (pvar, &channel->writebuf, blocking_write, s, data, length)) { + if (!UTIL_sock_buffered_write(pvar, &channel->writebuf, blocking_write, s, data, length)) { closed_local_connection(pvar, local_channel_num); // \x83|\x83b\x83v\x83A\x83b\x83v\x97}\x8E~\x8Ew\x92肠\x82\xEA\x82A\x8A\x94\x82\xF0\x8CĂяo\x82\xB3\x82Ȃ\xA2\x81B @@ -1612,8 +1603,8 @@ // (2014.6.26 yutaka) if ((pvar->settings.DisablePopupMessage & POPUP_MSG_FWD_received_data) == 0) { UTIL_get_lang_msg("MSG_FWD_COMM_ERROR", pvar, - "A communications error occurred while sending forwarded data to a local port.\n" - "The forwarded connection will be closed."); + "A communications error occurred while sending forwarded data to a local port.\n" + "The forwarded connection will be closed."); notify_nonfatal_error(pvar, pvar->ts->UIMsg); } } @@ -1621,7 +1612,7 @@ switch (action) { case FWD_FILTER_REMOVE: - channel->filter(channel->filter_closure, 0, NULL, NULL); + channel->filter(channel->filter_closure, FWD_FILTER_CLEANUP, NULL, NULL); channel->filter = NULL; channel->filter_closure = NULL; break; Modified: trunk/ttssh2/ttxssh/fwd.h =================================================================== --- trunk/ttssh2/ttxssh/fwd.h 2017-07-04 15:02:28 UTC (rev 6841) +++ trunk/ttssh2/ttxssh/fwd.h 2017-07-04 15:02:44 UTC (rev 6842) @@ -44,17 +44,18 @@ #define FWD_CLOSED_LOCAL_OUT 0x20 #define FWD_AGENT_DUMMY 0x40 -#define FWD_FILTER_REMOVE 0 -#define FWD_FILTER_RETAIN 1 -#define FWD_FILTER_CLOSECHANNEL 2 +typedef enum { + FWD_FILTER_REMOVE, FWD_FILTER_RETAIN, FWD_FILTER_CLOSECHANNEL +} FwdFilterResult; -#define FWD_FILTER_FROM_CLIENT 0 -#define FWD_FILTER_FROM_SERVER 1 +typedef enum { + FWD_FILTER_CLEANUP, + FWD_FILTER_FROM_CLIENT, + FWD_FILTER_FROM_SERVER +} FwdFilterEvent; -/* a length == 0 means that we're killing the channel and the filter - should deallocate */ -typedef int (* FWDFilter)(void *closure, int direction, - int *length, unsigned char **buf); +/* a length == 0 means that we're killing the channel and the filter should deallocate */ +typedef FwdFilterResult (* FWDFilter)(void *closure, FwdFilterEvent event, int *length, unsigned char **buf); typedef struct { int status; Modified: trunk/ttssh2/ttxssh/x11util.c =================================================================== --- trunk/ttssh2/ttxssh/x11util.c 2017-07-04 15:02:28 UTC (rev 6841) +++ trunk/ttssh2/ttxssh/x11util.c 2017-07-04 15:02:44 UTC (rev 6842) @@ -249,17 +249,18 @@ data_len); } -int X11_unspoofing_filter(void *void_closure, int direction, - int *length, unsigned char **buf) +FwdFilterResult X11_unspoofing_filter(void *void_closure, FwdFilterEvent event, int *length, unsigned char **buf) { X11UnspoofingFilterClosure *closure = (X11UnspoofingFilterClosure *) void_closure; - if (length == NULL) { + switch (event) { + case FWD_FILTER_CLEANUP: buf_destroy(&closure->init_buf, &closure->init_buf_len); free(closure); return FWD_FILTER_REMOVE; - } else if (direction == FWD_FILTER_FROM_SERVER) { + + case FWD_FILTER_FROM_SERVER: switch (merge_into_X11_init_packet(closure, *length, *buf)) { case MERGE_NEED_MORE: *length = 0; @@ -276,7 +277,8 @@ *length = 0; return FWD_FILTER_CLOSECHANNEL; } - } else { - return FWD_FILTER_RETAIN; + break; } + + return FWD_FILTER_RETAIN; } Modified: trunk/ttssh2/ttxssh/x11util.h =================================================================== --- trunk/ttssh2/ttxssh/x11util.h 2017-07-04 15:02:28 UTC (rev 6841) +++ trunk/ttssh2/ttxssh/x11util.h 2017-07-04 15:02:44 UTC (rev 6842) @@ -52,10 +52,8 @@ void X11_get_DISPLAY_info(PTInstVar pvar, char *name_buf, int name_buf_len, int *port, int *screen); X11AuthData *X11_load_local_auth_data(int screen_num); -void *X11_init_unspoofing_filter(struct _TInstVar *pvar, - X11AuthData *auth_data); -int X11_unspoofing_filter(void *closure, int direction, - int *length, unsigned char **buf); +void *X11_init_unspoofing_filter(struct _TInstVar *pvar, X11AuthData *auth_data); +FwdFilterResult X11_unspoofing_filter(void *closure, FwdFilterEvent event, int *length, unsigned char **buf); void X11_dispose_auth_data(X11AuthData *auth_data); #endif