Diff for /libaitcli/src/telnet.c between versions 1.3 and 1.4

version 1.3, 2012/07/22 22:37:08 version 1.4, 2013/05/30 09:16:42
Line 12  terms: Line 12  terms:
 All of the documentation and software included in the ELWIX and AITNET  All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>  Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
   
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
         by Michael Pounov <misho@elwix.org>.  All rights reserved.          by Michael Pounov <misho@elwix.org>.  All rights reserved.
   
 Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
Line 51  SUCH DAMAGE. Line 51  SUCH DAMAGE.
   
   
 /*  /*
 * cli_telnetRecv() Telnet receive commands, negotiate with telnet peer * cli_telnetRecv() - Telnet receive commands, negotiate with telnet peer
  *
  * @sock = socket for communication   * @sock = socket for communication
  * @attr = received attributes list, must be free after use, but if NULL receive in binary mode   * @attr = received attributes list, must be free after use, but if NULL receive in binary mode
  * @nAttr = received attributes list size, if is NULL receive in binary mode   * @nAttr = received attributes list size, if is NULL receive in binary mode
Line 137  cli_telnetRecv(int sock, struct telnetAttrs **attr, in Line 138  cli_telnetRecv(int sock, struct telnetAttrs **attr, in
                                 ta.ta_cmd = buf[i];                                  ta.ta_cmd = buf[i];
                         if (SB > ta.ta_cmd) {                          if (SB > ta.ta_cmd) {
                                 (*nAttr)++;                                  (*nAttr)++;
                                *attr = io_realloc(*attr, sizeof(struct telnetAttrs) * *nAttr);                                *attr = e_realloc(*attr, sizeof(struct telnetAttrs) * *nAttr);
                                 if (!*attr) {                                  if (!*attr) {
                                         LOGERR;                                          LOGERR;
                                         return -1;                                          return -1;
Line 167  cmd_exit: Line 168  cmd_exit:
                                 ta.ta_opt = buf[i];                                  ta.ta_opt = buf[i];
                         if (SB != ta.ta_cmd) {                          if (SB != ta.ta_cmd) {
                                 (*nAttr)++;                                  (*nAttr)++;
                                *attr = io_realloc(*attr, sizeof(struct telnetAttrs) * *nAttr);                                *attr = e_realloc(*attr, sizeof(struct telnetAttrs) * *nAttr);
                                 if (!*attr) {                                  if (!*attr) {
                                         LOGERR;                                          LOGERR;
                                         return -1;                                          return -1;
Line 192  opt_exit: Line 193  opt_exit:
                                         ta.ta_sub[ta.ta_sublen] = 0;                                          ta.ta_sub[ta.ta_sublen] = 0;
   
                                         (*nAttr)++;                                          (*nAttr)++;
                                        *attr = io_realloc(*attr, sizeof(struct telnetAttrs) * *nAttr);                                        *attr = e_realloc(*attr, sizeof(struct telnetAttrs) * *nAttr);
                                         if (!*attr) {                                          if (!*attr) {
                                                 LOGERR;                                                  LOGERR;
                                                 return -1;                                                  return -1;
Line 203  opt_exit: Line 204  opt_exit:
                                         ta.ta_sub[ta.ta_sublen++] = buf[i];                                          ta.ta_sub[ta.ta_sublen++] = buf[i];
                         } else {                          } else {
                                 cli_SetErr(EPROTONOSUPPORT, "Protocol limitation in sub-option to %d!", MAX_SUB_LEN);                                  cli_SetErr(EPROTONOSUPPORT, "Protocol limitation in sub-option to %d!", MAX_SUB_LEN);
                                io_free(*attr);                                e_free(*attr);
                                 *nAttr = 0;                                  *nAttr = 0;
                                 return -1;                                  return -1;
                         }                          }
Line 216  opt_exit: Line 217  opt_exit:
 #ifndef NDEBUG  #ifndef NDEBUG
   
 /*  /*
 * cli_telnet_DumpAttrs() Telnet debug attributes list, if NDEBUG defined not include * cli_telnet_DumpAttrs() - Telnet debug attributes list, if NDEBUG defined not include
  *
  * @attr = attributes list   * @attr = attributes list
  * @nAttr = attributes list size   * @nAttr = attributes list size
  * return: none   * return: none
Line 236  cli_telnet_DumpAttrs(struct telnetAttrs *attr, int nAt Line 238  cli_telnet_DumpAttrs(struct telnetAttrs *attr, int nAt
 #endif  #endif
   
 /*  /*
 * cli_telnetSend() Telnet send commands, negotiate with telnet peer * cli_telnetSend() - Telnet send commands, negotiate with telnet peer
  *
  * @sock = socket for communication   * @sock = socket for communication
  * @attr = send attributes list   * @attr = send attributes list
  * @nAttr = send attributes list size   * @nAttr = send attributes list size
Line 266  cli_telnetSend(int sock, struct telnetAttrs *attr, int Line 269  cli_telnetSend(int sock, struct telnetAttrs *attr, int
                                 }                                  }
                         }                          }
   
                        buf = io_realloc(buf, pos + len);                        buf = e_realloc(buf, pos + len);
                         if (!buf) {                          if (!buf) {
                                 LOGERR;                                  LOGERR;
                                 return -1;                                  return -1;
Line 290  cli_telnetSend(int sock, struct telnetAttrs *attr, int Line 293  cli_telnetSend(int sock, struct telnetAttrs *attr, int
         /* add data */          /* add data */
   
         if (data && datLen) {          if (data && datLen) {
                buf = io_realloc(buf, pos + datLen);                buf = e_realloc(buf, pos + datLen);
                 if (!buf) {                  if (!buf) {
                         LOGERR;                          LOGERR;
                         return -1;                          return -1;
Line 303  cli_telnetSend(int sock, struct telnetAttrs *attr, int Line 306  cli_telnetSend(int sock, struct telnetAttrs *attr, int
         /* add GA after end of all */          /* add GA after end of all */
   
         if (Term) {          if (Term) {
                buf = io_realloc(buf, pos + 2);                buf = e_realloc(buf, pos + 2);
                 if (!buf) {                  if (!buf) {
                         LOGERR;                          LOGERR;
                         return -1;                          return -1;
Line 318  cli_telnetSend(int sock, struct telnetAttrs *attr, int Line 321  cli_telnetSend(int sock, struct telnetAttrs *attr, int
                 LOGERR;                  LOGERR;
   
         if (buf)          if (buf)
                io_free(buf);                e_free(buf);
         return writeLen;          return writeLen;
 }  }
   
   
 /*  /*
 * cli_telnet_Get_SubOpt() Telnet get sub option function * cli_telnet_Get_SubOpt() - Telnet get sub option function
  *
  * @attr = input attribute   * @attr = input attribute
  * @code = sub-option code for opt   * @code = sub-option code for opt
  * @data = sub-option data   * @data = sub-option data
  * @datLen = data size set max size in input, output return copy size   * @datLen = data size set max size in input, output return copy size
  * return: -1 can`t get option; !=-1 option code   * return: -1 can`t get option; !=-1 option code
 */  */
inline intint
 cli_telnet_Get_SubOpt(struct telnetAttrs *attr, u_char *code, void *data, u_char *datLen)  cli_telnet_Get_SubOpt(struct telnetAttrs *attr, u_char *code, void *data, u_char *datLen)
 {  {
         u_char *pos, len;          u_char *pos, len;
Line 359  cli_telnet_Get_SubOpt(struct telnetAttrs *attr, u_char Line 363  cli_telnet_Get_SubOpt(struct telnetAttrs *attr, u_char
 }  }
   
 /*  /*
 * cli_telnet_Set_SubOpt() Telnet set sub option function * cli_telnet_Set_SubOpt() - Telnet set sub option function
  *
  * @attr = output attribute   * @attr = output attribute
  * @opt = attribute option   * @opt = attribute option
  * @code = sub-option code for opt, if 0xff not specified   * @code = sub-option code for opt, if 0xff not specified
Line 367  cli_telnet_Get_SubOpt(struct telnetAttrs *attr, u_char Line 372  cli_telnet_Get_SubOpt(struct telnetAttrs *attr, u_char
  * @datLen = data size, if 0 not specified   * @datLen = data size, if 0 not specified
  * return: -1 can`t set sub-otion; 0 ok   * return: -1 can`t set sub-otion; 0 ok
 */  */
inline intint
 cli_telnet_Set_SubOpt(struct telnetAttrs *attr, u_char opt, u_char code, void *data, u_char datLen)  cli_telnet_Set_SubOpt(struct telnetAttrs *attr, u_char opt, u_char code, void *data, u_char datLen)
 {  {
         u_char len;          u_char len;
Line 398  cli_telnet_Set_SubOpt(struct telnetAttrs *attr, u_char Line 403  cli_telnet_Set_SubOpt(struct telnetAttrs *attr, u_char
 }  }
   
 /*  /*
 * cli_telnet_GetCmd() Telnet get command * cli_telnet_GetCmd() - Telnet get command
  *
  * @attr = input attribute   * @attr = input attribute
  * return: -1 can`t get command; !=-1 command <<24 return sublen, <<8 return option, <<0 command   * return: -1 can`t get command; !=-1 command <<24 return sublen, <<8 return option, <<0 command
 */  */
inline u_intu_int
 cli_telnet_GetCmd(struct telnetAttrs *attr)  cli_telnet_GetCmd(struct telnetAttrs *attr)
 {  {
         u_int ret = 0;          u_int ret = 0;
Line 426  cli_telnet_GetCmd(struct telnetAttrs *attr) Line 432  cli_telnet_GetCmd(struct telnetAttrs *attr)
 }  }
   
 /*  /*
 * cli_telnet_SetCmd() Telnet set command * cli_telnet_SetCmd() - Telnet set command
  *
  * @attr = input attribute   * @attr = input attribute
  * @cmd = command   * @cmd = command
  * @opt = option, if 0xff not specified   * @opt = option, if 0xff not specified
Line 435  cli_telnet_GetCmd(struct telnetAttrs *attr) Line 442  cli_telnet_GetCmd(struct telnetAttrs *attr)
  * @arg3 = sub-option data size, if 0 not specified data   * @arg3 = sub-option data size, if 0 not specified data
  * return: -1 can`t set command; !=-1 ok   * return: -1 can`t set command; !=-1 ok
 */  */
inline intint
 cli_telnet_SetCmd(struct telnetAttrs *attr, u_char cmd, u_char opt, ...)  cli_telnet_SetCmd(struct telnetAttrs *attr, u_char cmd, u_char opt, ...)
 {  {
         va_list lst;          va_list lst;
Line 480  cli_telnet_SetCmd(struct telnetAttrs *attr, u_char cmd Line 487  cli_telnet_SetCmd(struct telnetAttrs *attr, u_char cmd
   
   
 /*  /*
 * cli_telnet_Answer() Automatic generate commands answer to send from telnet * cli_telnet_Answer() - Automatic generate commands answer to send from telnet
  *
  * @caps = Array of capability options   * @caps = Array of capability options
  * @nCaps = number of capability options   * @nCaps = number of capability options
  * @attr = input attribute   * @attr = input attribute
  * @nAttr = number of input attributes   * @nAttr = number of input attributes
 * @ans = output answered attributes, must be io_free() after use * @ans = output answered attributes, must be e_free() after use
  * @Ans = number of output answered attributes   * @Ans = number of output answered attributes
  * return: -1 can`t answer; !=-1 ok   * return: -1 can`t answer; !=-1 ok
 */  */
Line 521  cli_telnet_Answer(u_char *caps, int nCaps, struct teln Line 529  cli_telnet_Answer(u_char *caps, int nCaps, struct teln
                 // make attribute ...                  // make attribute ...
                 if (flg > -1) {                  if (flg > -1) {
                         (*Ans)++;                          (*Ans)++;
                        *ans = io_realloc(*ans, sizeof(struct telnetAttrs) * *Ans);                        *ans = e_realloc(*ans, sizeof(struct telnetAttrs) * *Ans);
                         if (!*ans) {                          if (!*ans) {
                                 LOGERR;                                  LOGERR;
                                 return -1;                                  return -1;

Removed from v.1.3  
changed lines
  Added in v.1.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>