Пример #1
0
/* process a subnegotiation buffer; return non-zero if the current buffer
 * must be aborted and reprocessed due to COMPRESS2 being activated
 */
static int _subnegotiate(telnet_t *telnet) 
{
	telnet_event_t ev;

	/* standard subnegotiation event */
	ev.type = TELNET_EV_SUBNEGOTIATION;
	ev.sub.telopt = telnet->sb_telopt;
	ev.sub.buffer = telnet->buffer;
	ev.sub.size = telnet->buffer_pos;
	telnet->eh(telnet, &ev, telnet->ud);

	switch (telnet->sb_telopt) {
	/* specially handled subnegotiation telopt types */
	case TELNET_TELOPT_ZMP:
		return _zmp_telnet(telnet, telnet->buffer, telnet->buffer_pos);
	case TELNET_TELOPT_TTYPE:
		return _ttype_telnet(telnet, telnet->buffer, telnet->buffer_pos);
	case TELNET_TELOPT_ENVIRON:
	case TELNET_TELOPT_NEW_ENVIRON:
		return _environ_telnet(telnet, telnet->sb_telopt, telnet->buffer,
				telnet->buffer_pos);
	case TELNET_TELOPT_MSSP:
		return _mssp_telnet(telnet, telnet->buffer, telnet->buffer_pos);
	default:
		return 0;
	}
}
Пример #2
0
/* process a subnegotiation buffer; return non-zero if the current buffer
 * must be aborted and reprocessed due to COMPRESS2 being activated
 */
static int _subnegotiate(telnet_t *telnet) {
	telnet_event_t ev;

	/* standard subnegotiation event */
	ev.type = TELNET_EV_SUBNEGOTIATION;
	ev.sub.telopt = telnet->sb_telopt;
	ev.sub.buffer = telnet->buffer;
	ev.sub.size = telnet->buffer_pos;
	telnet->eh(telnet, &ev, telnet->ud);

	switch (telnet->sb_telopt) {
#if defined(HAVE_ZLIB)
	/* received COMPRESS2 begin marker, setup our zlib box and
	 * start handling the compressed stream if it's not already.
	 */
	case TELNET_TELOPT_COMPRESS2:
		if (telnet->sb_telopt == TELNET_TELOPT_COMPRESS2) {
			if (_init_zlib(telnet, 0, 1) != TELNET_EOK)
				return 0;

			/* notify app that compression was enabled */
			ev.type = TELNET_EV_COMPRESS;
			ev.compress.state = 1;
			telnet->eh(telnet, &ev, telnet->ud);
			return 1;
		}
		return 0;
#endif /* defined(HAVE_ZLIB) */

	/* specially handled subnegotiation telopt types */
	case TELNET_TELOPT_ZMP:
		return _zmp_telnet(telnet, telnet->buffer, telnet->buffer_pos);
	case TELNET_TELOPT_TTYPE:
		return _ttype_telnet(telnet, telnet->buffer, telnet->buffer_pos);
	case TELNET_TELOPT_ENVIRON:
	case TELNET_TELOPT_NEW_ENVIRON:
		return _environ_telnet(telnet, telnet->sb_telopt, telnet->buffer,
				telnet->buffer_pos);
	case TELNET_TELOPT_MSSP:
		return _mssp_telnet(telnet, telnet->buffer, telnet->buffer_pos);
	default:
		return 0;
	}
}