libtelnet.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /*!
  2. * \brief libtelnet - TELNET protocol handling library
  3. *
  4. * SUMMARY:
  5. *
  6. * libtelnet is a library for handling the TELNET protocol. It includes
  7. * routines for parsing incoming data from a remote peer as well as formatting
  8. * data to send to the remote peer.
  9. *
  10. * libtelnet uses a callback-oriented API, allowing application-specific
  11. * handling of various events. The callback system is also used for buffering
  12. * outgoing protocol data, allowing the application to maintain control over
  13. * the actual socket connection.
  14. *
  15. * Features supported include the full TELNET protocol, Q-method option
  16. * negotiation, ZMP, MCCP2, MSSP, and NEW-ENVIRON.
  17. *
  18. * CONFORMS TO:
  19. *
  20. * RFC854 - http://www.faqs.org/rfcs/rfc854.html
  21. * RFC855 - http://www.faqs.org/rfcs/rfc855.html
  22. * RFC1091 - http://www.faqs.org/rfcs/rfc1091.html
  23. * RFC1143 - http://www.faqs.org/rfcs/rfc1143.html
  24. * RFC1408 - http://www.faqs.org/rfcs/rfc1408.html
  25. * RFC1572 - http://www.faqs.org/rfcs/rfc1572.html
  26. *
  27. * LICENSE:
  28. *
  29. * The author or authors of this code dedicate any and all copyright interest
  30. * in this code to the public domain. We make this dedication for the benefit
  31. * of the public at large and to the detriment of our heirs and successors. We
  32. * intend this dedication to be an overt act of relinquishment in perpetuity of
  33. * all present and future rights to this code under copyright law.
  34. *
  35. * \file libtelnet.h
  36. *
  37. * \version 0.21
  38. *
  39. * \author Sean Middleditch <sean@sourcemud.org>
  40. */
  41. #if !defined(LIBTELNET_INCLUDE)
  42. #define LIBTELNET_INCLUDE 1
  43. /* standard C headers necessary for the libtelnet API */
  44. #include <stdarg.h>
  45. /* C++ support */
  46. #if defined(__cplusplus)
  47. extern "C" {
  48. #endif
  49. /* printf type checking feature in GCC and some other compilers */
  50. #if __GNUC__
  51. # define TELNET_GNU_PRINTF(f,a) __attribute__((format(printf, f, a))) /*!< internal helper */
  52. # define TELNET_GNU_SENTINEL __attribute__((sentinel)) /*!< internal helper */
  53. #else
  54. # define TELNET_GNU_PRINTF(f,a) /*!< internal helper */
  55. # define TELNET_GNU_SENTINEL /*!< internal helper */
  56. #endif
  57. /*! Telnet state tracker object type. */
  58. typedef struct telnet_t telnet_t;
  59. /*! Telnet event object type. */
  60. typedef union telnet_event_t telnet_event_t;
  61. /*! Telnet option table element type. */
  62. typedef struct telnet_telopt_t telnet_telopt_t;
  63. /*! \name Telnet commands */
  64. /*@{*/
  65. /*! Telnet commands and special values. */
  66. #define TELNET_IAC 255
  67. #define TELNET_DONT 254
  68. #define TELNET_DO 253
  69. #define TELNET_WONT 252
  70. #define TELNET_WILL 251
  71. #define TELNET_SB 250
  72. #define TELNET_GA 249
  73. #define TELNET_EL 248
  74. #define TELNET_EC 247
  75. #define TELNET_AYT 246
  76. #define TELNET_AO 245
  77. #define TELNET_IP 244
  78. #define TELNET_BREAK 243
  79. #define TELNET_DM 242
  80. #define TELNET_NOP 241
  81. #define TELNET_SE 240
  82. #define TELNET_EOR 239
  83. #define TELNET_ABORT 238
  84. #define TELNET_SUSP 237
  85. #define TELNET_EOF 236
  86. /*@}*/
  87. /*! \name Telnet option values. */
  88. /*@{*/
  89. /*! Telnet options. */
  90. #define TELNET_TELOPT_BINARY 0
  91. #define TELNET_TELOPT_ECHO 1
  92. #define TELNET_TELOPT_RCP 2
  93. #define TELNET_TELOPT_SGA 3
  94. #define TELNET_TELOPT_NAMS 4
  95. #define TELNET_TELOPT_STATUS 5
  96. #define TELNET_TELOPT_TM 6
  97. #define TELNET_TELOPT_RCTE 7
  98. #define TELNET_TELOPT_NAOL 8
  99. #define TELNET_TELOPT_NAOP 9
  100. #define TELNET_TELOPT_NAOCRD 10
  101. #define TELNET_TELOPT_NAOHTS 11
  102. #define TELNET_TELOPT_NAOHTD 12
  103. #define TELNET_TELOPT_NAOFFD 13
  104. #define TELNET_TELOPT_NAOVTS 14
  105. #define TELNET_TELOPT_NAOVTD 15
  106. #define TELNET_TELOPT_NAOLFD 16
  107. #define TELNET_TELOPT_XASCII 17
  108. #define TELNET_TELOPT_LOGOUT 18
  109. #define TELNET_TELOPT_BM 19
  110. #define TELNET_TELOPT_DET 20
  111. #define TELNET_TELOPT_SUPDUP 21
  112. #define TELNET_TELOPT_SUPDUPOUTPUT 22
  113. #define TELNET_TELOPT_SNDLOC 23
  114. #define TELNET_TELOPT_TTYPE 24
  115. #define TELNET_TELOPT_EOR 25
  116. #define TELNET_TELOPT_TUID 26
  117. #define TELNET_TELOPT_OUTMRK 27
  118. #define TELNET_TELOPT_TTYLOC 28
  119. #define TELNET_TELOPT_3270REGIME 29
  120. #define TELNET_TELOPT_X3PAD 30
  121. #define TELNET_TELOPT_NAWS 31
  122. #define TELNET_TELOPT_TSPEED 32
  123. #define TELNET_TELOPT_LFLOW 33
  124. #define TELNET_TELOPT_LINEMODE 34
  125. #define TELNET_TELOPT_XDISPLOC 35
  126. #define TELNET_TELOPT_ENVIRON 36
  127. #define TELNET_TELOPT_AUTHENTICATION 37
  128. #define TELNET_TELOPT_ENCRYPT 38
  129. #define TELNET_TELOPT_NEW_ENVIRON 39
  130. #define TELNET_TELOPT_MSSP 70
  131. #define TELNET_TELOPT_COMPRESS 85
  132. #define TELNET_TELOPT_COMPRESS2 86
  133. #define TELNET_TELOPT_ZMP 93
  134. #define TELNET_TELOPT_EXOPL 255
  135. #define TELNET_TELOPT_MCCP2 86
  136. /*@}*/
  137. /*! \name Protocol codes for TERMINAL-TYPE commands. */
  138. /*@{*/
  139. /*! TERMINAL-TYPE codes. */
  140. #define TELNET_TTYPE_IS 0
  141. #define TELNET_TTYPE_SEND 1
  142. /*@}*/
  143. /*! \name Protocol codes for NEW-ENVIRON/ENVIRON commands. */
  144. /*@{*/
  145. /*! NEW-ENVIRON/ENVIRON codes. */
  146. #define TELNET_ENVIRON_IS 0
  147. #define TELNET_ENVIRON_SEND 1
  148. #define TELNET_ENVIRON_INFO 2
  149. #define TELNET_ENVIRON_VAR 0
  150. #define TELNET_ENVIRON_VALUE 1
  151. #define TELNET_ENVIRON_ESC 2
  152. #define TELNET_ENVIRON_USERVAR 3
  153. /*@}*/
  154. /*! \name Protocol codes for MSSP commands. */
  155. /*@{*/
  156. /*! MSSP codes. */
  157. #define TELNET_MSSP_VAR 1
  158. #define TELNET_MSSP_VAL 2
  159. /*@}*/
  160. /*! \name Telnet state tracker flags. */
  161. /*@{*/
  162. /*! Control behavior of telnet state tracker. */
  163. #define TELNET_FLAG_PROXY (1<<0)
  164. #define TELNET_PFLAG_DEFLATE (1<<7)
  165. /*@}*/
  166. /*!
  167. * error codes
  168. */
  169. enum telnet_error_t {
  170. TELNET_EOK = 0, /*!< no error */
  171. TELNET_EBADVAL, /*!< invalid parameter, or API misuse */
  172. TELNET_ENOMEM, /*!< memory allocation failure */
  173. TELNET_EOVERFLOW, /*!< data exceeds buffer size */
  174. TELNET_EPROTOCOL, /*!< invalid sequence of special bytes */
  175. TELNET_ECOMPRESS /*!< error handling compressed streams */
  176. };
  177. typedef enum telnet_error_t telnet_error_t; /*!< Error code type. */
  178. /*!
  179. * event codes
  180. */
  181. enum telnet_event_type_t {
  182. TELNET_EV_DATA = 0, /*!< raw text data has been received */
  183. TELNET_EV_SEND, /*!< data needs to be sent to the peer */
  184. TELNET_EV_IAC, /*!< generic IAC code received */
  185. TELNET_EV_WILL, /*!< WILL option negotiation received */
  186. TELNET_EV_WONT, /*!< WONT option neogitation received */
  187. TELNET_EV_DO, /*!< DO option negotiation received */
  188. TELNET_EV_DONT, /*!< DONT option negotiation received */
  189. TELNET_EV_SUBNEGOTIATION, /*!< sub-negotiation data received */
  190. TELNET_EV_COMPRESS, /*!< compression has been enabled */
  191. TELNET_EV_ZMP, /*!< ZMP command has been received */
  192. TELNET_EV_TTYPE, /*!< TTYPE command has been received */
  193. TELNET_EV_ENVIRON, /*!< ENVIRON command has been received */
  194. TELNET_EV_MSSP, /*!< MSSP command has been received */
  195. TELNET_EV_WARNING, /*!< recoverable error has occured */
  196. TELNET_EV_ERROR /*!< non-recoverable error has occured */
  197. };
  198. typedef enum telnet_event_type_t telnet_event_type_t; /*!< Telnet event type. */
  199. /*!
  200. * environ/MSSP command information
  201. */
  202. struct telnet_environ_t {
  203. unsigned char type; /*!< either TELNET_ENVIRON_VAR or TELNET_ENVIRON_USERVAR */
  204. char *var; /*!< name of the variable being set */
  205. char *value; /*!< value of variable being set; empty string if no value */
  206. };
  207. /*!
  208. * event information
  209. */
  210. union telnet_event_t {
  211. /*!
  212. * \brief Event type
  213. *
  214. * The type field will determine which of the other event structure fields
  215. * have been filled in. For instance, if the event type is TELNET_EV_ZMP,
  216. * then the zmp event field (and ONLY the zmp event field) will be filled
  217. * in.
  218. */
  219. enum telnet_event_type_t type;
  220. /*!
  221. * data event: for DATA and SEND events
  222. */
  223. struct data_t {
  224. enum telnet_event_type_t _type; /*!< alias for type */
  225. const char *buffer; /*!< byte buffer */
  226. size_t size; /*!< number of bytes in buffer */
  227. } data;
  228. /*!
  229. * WARNING and ERROR events
  230. */
  231. struct error_t {
  232. enum telnet_event_type_t _type; /*!< alias for type */
  233. const char *file; /*!< file the error occured in */
  234. const char *func; /*!< function the error occured in */
  235. const char *msg; /*!< error message string */
  236. int line; /*!< line of file error occured on */
  237. telnet_error_t errcode; /*!< error code */
  238. } error;
  239. /*!
  240. * command event: for IAC
  241. */
  242. struct iac_t {
  243. enum telnet_event_type_t _type; /*!< alias for type */
  244. unsigned char cmd; /*!< telnet command received */
  245. } iac;
  246. /*!
  247. * negotiation event: WILL, WONT, DO, DONT
  248. */
  249. struct negotiate_t {
  250. enum telnet_event_type_t _type; /*!< alias for type */
  251. unsigned char telopt; /*!< option being negotiated */
  252. } neg;
  253. /*!
  254. * subnegotiation event
  255. */
  256. struct subnegotiate_t {
  257. enum telnet_event_type_t _type; /*!< alias for type */
  258. const char *buffer; /*!< data of sub-negotiation */
  259. size_t size; /*!< number of bytes in buffer */
  260. unsigned char telopt; /*!< option code for negotiation */
  261. } sub;
  262. /*!
  263. * ZMP event
  264. */
  265. struct zmp_t {
  266. enum telnet_event_type_t _type; /*!< alias for type */
  267. const char **argv; /*!< array of argument string */
  268. size_t argc; /*!< number of elements in argv */
  269. } zmp;
  270. /*!
  271. * TTYPE event
  272. */
  273. struct ttype_t {
  274. enum telnet_event_type_t _type; /*!< alias for type */
  275. unsigned char cmd; /*!< TELNET_TTYPE_IS or TELNET_TTYPE_SEND */
  276. const char* name; /*!< terminal type name (IS only) */
  277. } ttype;
  278. /*!
  279. * COMPRESS event
  280. */
  281. struct compress_t {
  282. enum telnet_event_type_t _type; /*!< alias for type */
  283. unsigned char state; /*!< 1 if compression is enabled,
  284. 0 if disabled */
  285. } compress;
  286. /*!
  287. * ENVIRON/NEW-ENVIRON event
  288. */
  289. struct environ_t {
  290. enum telnet_event_type_t _type; /*!< alias for type */
  291. const struct telnet_environ_t *values; /*!< array of variable values */
  292. size_t size; /*!< number of elements in values */
  293. unsigned char cmd; /*!< SEND, IS, or INFO */
  294. } environ;
  295. /*!
  296. * MSSP event
  297. */
  298. struct mssp_t {
  299. enum telnet_event_type_t _type; /*!< alias for type */
  300. const struct telnet_environ_t *values; /*!< array of variable values */
  301. size_t size; /*!< number of elements in values */
  302. } mssp;
  303. };
  304. /*!
  305. * \brief event handler
  306. *
  307. * This is the type of function that must be passed to
  308. * telnet_init() when creating a new telnet object. The
  309. * function will be invoked once for every event generated
  310. * by the libtelnet protocol parser.
  311. *
  312. * \param telnet The telnet object that generated the event
  313. * \param event Event structure with details about the event
  314. * \param user_data User-supplied pointer
  315. */
  316. typedef void (*telnet_event_handler_t)(telnet_t *telnet,
  317. telnet_event_t *event, void *user_data);
  318. /*!
  319. * telopt support table element; use telopt of -1 for end marker
  320. */
  321. struct telnet_telopt_t {
  322. short telopt; /*!< one of the TELOPT codes or -1 */
  323. unsigned char us; /*!< TELNET_WILL or TELNET_WONT */
  324. unsigned char him; /*!< TELNET_DO or TELNET_DONT */
  325. };
  326. /*!
  327. * state tracker -- private data structure
  328. */
  329. struct telnet_t;
  330. /*!
  331. * \brief Initialize a telnet state tracker.
  332. *
  333. * This function initializes a new state tracker, which is used for all
  334. * other libtelnet functions. Each connection must have its own
  335. * telnet state tracker object.
  336. *
  337. * \param telopts Table of TELNET options the application supports.
  338. * \param eh Event handler function called for every event.
  339. * \param flags 0 or TELNET_FLAG_PROXY.
  340. * \param user_data Optional data pointer that will be passsed to eh.
  341. * \return Telent state tracker object.
  342. */
  343. extern telnet_t* telnet_init(const telnet_telopt_t *telopts,
  344. telnet_event_handler_t eh, unsigned char flags, void *user_data);
  345. /*!
  346. * \brief Free up any memory allocated by a state tracker.
  347. *
  348. * This function must be called when a telnet state tracker is no
  349. * longer needed (such as after the connection has been closed) to
  350. * release any memory resources used by the state tracker.
  351. *
  352. * \param telnet Telnet state tracker object.
  353. */
  354. extern void telnet_free(telnet_t *telnet);
  355. /*!
  356. * \brief Push a byte buffer into the state tracker.
  357. *
  358. * Passes one or more bytes to the telnet state tracker for
  359. * protocol parsing. The byte buffer is most often going to be
  360. * the buffer that recv() was called for while handling the
  361. * connection.
  362. *
  363. * \param telnet Telnet state tracker object.
  364. * \param buffer Pointer to byte buffer.
  365. * \param size Number of bytes pointed to by buffer.
  366. */
  367. extern void telnet_recv(telnet_t *telnet, const char *buffer,
  368. size_t size);
  369. /*!
  370. * \brief Send a telnet command.
  371. *
  372. * \param telnet Telnet state tracker object.
  373. * \param cmd Command to send.
  374. */
  375. extern void telnet_iac(telnet_t *telnet, unsigned char cmd);
  376. /*!
  377. * \brief Send negotiation command.
  378. *
  379. * Internally, libtelnet uses RFC1143 option negotiation rules.
  380. * The negotiation commands sent with this function may be ignored
  381. * if they are determined to be redundant.
  382. *
  383. * \param telnet Telnet state tracker object.
  384. * \param cmd TELNET_WILL, TELNET_WONT, TELNET_DO, or TELNET_DONT.
  385. * \param opt One of the TELNET_TELOPT_* values.
  386. */
  387. extern void telnet_negotiate(telnet_t *telnet, unsigned char cmd,
  388. unsigned char opt);
  389. /*!
  390. * Send non-command data (escapes IAC bytes).
  391. *
  392. * \param telnet Telnet state tracker object.
  393. * \param buffer Buffer of bytes to send.
  394. * \param size Number of bytes to send.
  395. */
  396. extern void telnet_send(telnet_t *telnet,
  397. const char *buffer, size_t size);
  398. /*!
  399. * \brief Begin a sub-negotiation command.
  400. *
  401. * Sends IAC SB followed by the telopt code. All following data sent
  402. * will be part of the sub-negotiation, until telnet_finish_sb() is
  403. * called.
  404. *
  405. * \param telnet Telnet state tracker object.
  406. * \param telopt One of the TELNET_TELOPT_* values.
  407. */
  408. extern void telnet_begin_sb(telnet_t *telnet,
  409. unsigned char telopt);
  410. /*!
  411. * \brief Finish a sub-negotiation command.
  412. *
  413. * This must be called after a call to telnet_begin_sb() to finish a
  414. * sub-negotiation command.
  415. *
  416. * \param telnet Telnet state tracker object.
  417. */
  418. #define telnet_finish_sb(telnet) telnet_iac((telnet), TELNET_SE)
  419. /*!
  420. * \brief Shortcut for sending a complete subnegotiation buffer.
  421. *
  422. * Equivalent to:
  423. * telnet_begin_sb(telnet, telopt);
  424. * telnet_send(telnet, buffer, size);
  425. * telnet_finish_sb(telnet);
  426. *
  427. * \param telnet Telnet state tracker format.
  428. * \param telopt One of the TELNET_TELOPT_* values.
  429. * \param buffer Byte buffer for sub-negotiation data.
  430. * \param size Number of bytes to use for sub-negotiation data.
  431. */
  432. extern void telnet_subnegotiation(telnet_t *telnet, unsigned char telopt,
  433. const char *buffer, size_t size);
  434. /*!
  435. * \brief Begin sending compressed data.
  436. *
  437. * This function will begein sending data using the COMPRESS2 option,
  438. * which enables the use of zlib to compress data sent to the client.
  439. * The client must offer support for COMPRESS2 with option negotiation,
  440. * and zlib support must be compiled into libtelnet.
  441. *
  442. * Only the server may call this command.
  443. *
  444. * \param telnet Telnet state tracker object.
  445. */
  446. extern void telnet_begin_compress2(telnet_t *telnet);
  447. /*!
  448. * \brief Send formatted data.
  449. *
  450. * This function is a wrapper around telnet_send(). It allows using
  451. * printf-style formatting.
  452. *
  453. * Additionally, this function will translate \\r to the CR NUL construct and
  454. * \\n with CR LF, as well as automatically escaping IAC bytes like
  455. * telnet_send().
  456. *
  457. * \param telnet Telnet state tracker object.
  458. * \param fmt Format string.
  459. * \return Number of bytes sent.
  460. */
  461. extern int telnet_printf(telnet_t *telnet, const char *fmt, ...)
  462. TELNET_GNU_PRINTF(2, 3);
  463. /*!
  464. * \brief Send formatted data.
  465. *
  466. * See telnet_printf().
  467. */
  468. extern int telnet_vprintf(telnet_t *telnet, const char *fmt, va_list va);
  469. /*!
  470. * \brief Send formatted data (no newline escaping).
  471. *
  472. * This behaves identically to telnet_printf(), except that the \\r and \\n
  473. * characters are not translated. The IAC byte is still escaped as normal
  474. * with telnet_send().
  475. *
  476. * \param telnet Telnet state tracker object.
  477. * \param fmt Format string.
  478. * \return Number of bytes sent.
  479. */
  480. extern int telnet_raw_printf(telnet_t *telnet, const char *fmt, ...)
  481. TELNET_GNU_PRINTF(2, 3);
  482. /*!
  483. * \brief Send formatted data (no newline escaping).
  484. *
  485. * See telnet_raw_printf().
  486. */
  487. extern int telnet_raw_vprintf(telnet_t *telnet, const char *fmt, va_list va);
  488. /*!
  489. * \brief Begin a new set of NEW-ENVIRON values to request or send.
  490. *
  491. * This function will begin the sub-negotiation block for sending or
  492. * requesting NEW-ENVIRON values.
  493. *
  494. * The telnet_finish_newenviron() macro must be called after this
  495. * function to terminate the NEW-ENVIRON command.
  496. *
  497. * \param telnet Telnet state tracker object.
  498. * \param type One of TELNET_ENVIRON_SEND, TELNET_ENVIRON_IS, or
  499. * TELNET_ENVIRON_INFO.
  500. */
  501. extern void telnet_begin_newenviron(telnet_t *telnet, unsigned char type);
  502. /*!
  503. * \brief Send a NEW-ENVIRON variable name or value.
  504. *
  505. * This can only be called between calls to telnet_begin_newenviron() and
  506. * telnet_finish_newenviron().
  507. *
  508. * \param telnet Telnet state tracker object.
  509. * \param type One of TELNET_ENVIRON_VAR, TELNET_ENVIRON_USERVAR, or
  510. * TELNET_ENVIRON_VALUE.
  511. * \param string Variable name or value.
  512. */
  513. extern void telnet_newenviron_value(telnet_t* telnet, unsigned char type,
  514. const char *string);
  515. /*!
  516. * \brief Finish a NEW-ENVIRON command.
  517. *
  518. * This must be called after a call to telnet_begin_newenviron() to finish a
  519. * NEW-ENVIRON variable list.
  520. *
  521. * \param telnet Telnet state tracker object.
  522. */
  523. #define telnet_finish_newenviron(telnet) telnet_finish_sb((telnet))
  524. /*!
  525. * \brief Send the TERMINAL-TYPE SEND command.
  526. *
  527. * Sends the sequence IAC TERMINAL-TYPE SEND.
  528. *
  529. * \param telnet Telnet state tracker object.
  530. */
  531. extern void telnet_ttype_send(telnet_t *telnet);
  532. /*!
  533. * \brief Send the TERMINAL-TYPE IS command.
  534. *
  535. * Sends the sequence IAC TERMINAL-TYPE IS "string".
  536. *
  537. * According to the RFC, the recipient of a TERMINAL-TYPE SEND shall
  538. * send the next possible terminal-type the client supports. Upon sending
  539. * the type, the client should switch modes to begin acting as the terminal
  540. * type is just sent.
  541. *
  542. * The server may continue sending TERMINAL-TYPE IS until it receives a
  543. * terminal type is understands. To indicate to the server that it has
  544. * reached the end of the available optoins, the client must send the last
  545. * terminal type a second time. When the server receives the same terminal
  546. * type twice in a row, it knows it has seen all available terminal types.
  547. *
  548. * After the last terminal type is sent, if the client receives another
  549. * TERMINAL-TYPE SEND command, it must begin enumerating the available
  550. * terminal types from the very beginning. This allows the server to
  551. * scan the available types for a preferred terminal type and, if none
  552. * is found, to then ask the client to switch to an acceptable
  553. * alternative.
  554. *
  555. * Note that if the client only supports a single terminal type, then
  556. * simply sending that one type in response to every SEND will satisfy
  557. * the behavior requirements.
  558. *
  559. * \param telnet Telnet state tracker object.
  560. * \param ttype Name of the terminal-type being sent.
  561. */
  562. extern void telnet_ttype_is(telnet_t *telnet, const char* ttype);
  563. /*!
  564. * \brief Send a ZMP command.
  565. *
  566. * \param telnet Telnet state tracker object.
  567. * \param argc Number of ZMP commands being sent.
  568. * \param argv Array of argument strings.
  569. */
  570. extern void telnet_send_zmp(telnet_t *telnet, size_t argc, const char **argv);
  571. /*!
  572. * \brief Send a ZMP command.
  573. *
  574. * Arguments are listed out in var-args style. After the last argument, a
  575. * NULL pointer must be passed in as a sentinel value.
  576. *
  577. * \param telnet Telnet state tracker object.
  578. */
  579. extern void telnet_send_zmpv(telnet_t *telnet, ...) TELNET_GNU_SENTINEL;
  580. /*!
  581. * \brief Send a ZMP command.
  582. *
  583. * See telnet_send_zmpv().
  584. */
  585. extern void telnet_send_vzmpv(telnet_t *telnet, va_list va);
  586. /*!
  587. * \brief Begin sending a ZMP command
  588. *
  589. * \param telnet Telnet state tracker object.
  590. * \param cmd The first argument (command name) for the ZMP command.
  591. */
  592. extern void telnet_begin_zmp(telnet_t *telnet, const char *cmd);
  593. /*!
  594. * \brief Send a ZMP command argument.
  595. *
  596. * \param telnet Telnet state tracker object.
  597. * \param arg Telnet argument string.
  598. */
  599. extern void telnet_zmp_arg(telnet_t *telnet, const char *arg);
  600. /*!
  601. * \brief Finish a ZMP command.
  602. *
  603. * This must be called after a call to telnet_begin_zmp() to finish a
  604. * ZMP argument list.
  605. *
  606. * \param telnet Telnet state tracker object.
  607. */
  608. #define telnet_finish_zmp(telnet) telnet_finish_sb((telnet))
  609. /* C++ support */
  610. #if defined(__cplusplus)
  611. } /* extern "C" */
  612. #endif
  613. #endif /* !defined(LIBTELNET_INCLUDE) */