--- libaitcli/src/telnet.c 2011/03/16 18:28:06 1.1.2.1 +++ libaitcli/src/telnet.c 2013/05/30 09:16:42 1.4 @@ -3,9 +3,46 @@ * by Michael Pounov * * $Author: misho $ -* $Id: telnet.c,v 1.1.2.1 2011/03/16 18:28:06 misho Exp $ +* $Id: telnet.c,v 1.4 2013/05/30 09:16:42 misho Exp $ * -*************************************************************************/ +************************************************************************** +The ELWIX and AITNET software is distributed under the following +terms: + +All of the documentation and software included in the ELWIX and AITNET +Releases is copyrighted by ELWIX - Sofia/Bulgaria + +Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 + by Michael Pounov . All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. All advertising materials mentioning features or use of this software + must display the following acknowledgement: +This product includes software developed by Michael Pounov +ELWIX - Embedded LightWeight unIX and its contributors. +4. Neither the name of AITNET nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. +*/ #ifndef NDEBUG #define TELOPTS #define TELCMDS @@ -14,7 +51,8 @@ /* - * cli_telnetRecv() Telnet receive commands, negotiate with telnet peer + * cli_telnetRecv() - Telnet receive commands, negotiate with telnet peer + * * @sock = socket for communication * @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 @@ -100,7 +138,7 @@ cli_telnetRecv(int sock, struct telnetAttrs **attr, in ta.ta_cmd = buf[i]; if (SB > ta.ta_cmd) { (*nAttr)++; - *attr = realloc(*attr, sizeof(struct telnetAttrs) * *nAttr); + *attr = e_realloc(*attr, sizeof(struct telnetAttrs) * *nAttr); if (!*attr) { LOGERR; return -1; @@ -130,7 +168,7 @@ cmd_exit: ta.ta_opt = buf[i]; if (SB != ta.ta_cmd) { (*nAttr)++; - *attr = realloc(*attr, sizeof(struct telnetAttrs) * *nAttr); + *attr = e_realloc(*attr, sizeof(struct telnetAttrs) * *nAttr); if (!*attr) { LOGERR; return -1; @@ -155,7 +193,7 @@ opt_exit: ta.ta_sub[ta.ta_sublen] = 0; (*nAttr)++; - *attr = realloc(*attr, sizeof(struct telnetAttrs) * *nAttr); + *attr = e_realloc(*attr, sizeof(struct telnetAttrs) * *nAttr); if (!*attr) { LOGERR; return -1; @@ -166,7 +204,7 @@ opt_exit: ta.ta_sub[ta.ta_sublen++] = buf[i]; } else { cli_SetErr(EPROTONOSUPPORT, "Protocol limitation in sub-option to %d!", MAX_SUB_LEN); - free(*attr); + e_free(*attr); *nAttr = 0; return -1; } @@ -179,7 +217,8 @@ opt_exit: #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 * @nAttr = attributes list size * return: none @@ -199,7 +238,8 @@ cli_telnet_DumpAttrs(struct telnetAttrs *attr, int nAt #endif /* - * cli_telnetSend() Telnet send commands, negotiate with telnet peer + * cli_telnetSend() - Telnet send commands, negotiate with telnet peer + * * @sock = socket for communication * @attr = send attributes list * @nAttr = send attributes list size @@ -229,7 +269,7 @@ cli_telnetSend(int sock, struct telnetAttrs *attr, int } } - buf = realloc(buf, pos + len); + buf = e_realloc(buf, pos + len); if (!buf) { LOGERR; return -1; @@ -253,7 +293,7 @@ cli_telnetSend(int sock, struct telnetAttrs *attr, int /* add data */ if (data && datLen) { - buf = realloc(buf, pos + datLen); + buf = e_realloc(buf, pos + datLen); if (!buf) { LOGERR; return -1; @@ -266,7 +306,7 @@ cli_telnetSend(int sock, struct telnetAttrs *attr, int /* add GA after end of all */ if (Term) { - buf = realloc(buf, pos + 2); + buf = e_realloc(buf, pos + 2); if (!buf) { LOGERR; return -1; @@ -281,20 +321,21 @@ cli_telnetSend(int sock, struct telnetAttrs *attr, int LOGERR; if (buf) - free(buf); + e_free(buf); return writeLen; } /* - * cli_telnet_Get_SubOpt() Telnet get sub option function + * cli_telnet_Get_SubOpt() - Telnet get sub option function + * * @attr = input attribute * @code = sub-option code for opt * @data = sub-option data * @datLen = data size set max size in input, output return copy size * return: -1 can`t get option; !=-1 option code */ -inline int +int cli_telnet_Get_SubOpt(struct telnetAttrs *attr, u_char *code, void *data, u_char *datLen) { u_char *pos, len; @@ -322,7 +363,8 @@ 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 * @opt = attribute option * @code = sub-option code for opt, if 0xff not specified @@ -330,7 +372,7 @@ cli_telnet_Get_SubOpt(struct telnetAttrs *attr, u_char * @datLen = data size, if 0 not specified * return: -1 can`t set sub-otion; 0 ok */ -inline int +int cli_telnet_Set_SubOpt(struct telnetAttrs *attr, u_char opt, u_char code, void *data, u_char datLen) { u_char len; @@ -361,11 +403,12 @@ cli_telnet_Set_SubOpt(struct telnetAttrs *attr, u_char } /* - * cli_telnet_GetCmd() Telnet get command + * cli_telnet_GetCmd() - Telnet get command + * * @attr = input attribute * return: -1 can`t get command; !=-1 command <<24 return sublen, <<8 return option, <<0 command */ -inline u_int +u_int cli_telnet_GetCmd(struct telnetAttrs *attr) { u_int ret = 0; @@ -389,7 +432,8 @@ cli_telnet_GetCmd(struct telnetAttrs *attr) } /* - * cli_telnet_SetCmd() Telnet set command + * cli_telnet_SetCmd() - Telnet set command + * * @attr = input attribute * @cmd = command * @opt = option, if 0xff not specified @@ -398,7 +442,7 @@ cli_telnet_GetCmd(struct telnetAttrs *attr) * @arg3 = sub-option data size, if 0 not specified data * return: -1 can`t set command; !=-1 ok */ -inline int +int cli_telnet_SetCmd(struct telnetAttrs *attr, u_char cmd, u_char opt, ...) { va_list lst; @@ -443,12 +487,13 @@ 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 * @nCaps = number of capability options * @attr = input attribute * @nAttr = number of input attributes - * @ans = output answered attributes, must be free() after use + * @ans = output answered attributes, must be e_free() after use * @Ans = number of output answered attributes * return: -1 can`t answer; !=-1 ok */ @@ -484,7 +529,7 @@ cli_telnet_Answer(u_char *caps, int nCaps, struct teln // make attribute ... if (flg > -1) { (*Ans)++; - *ans = realloc(*ans, sizeof(struct telnetAttrs) * *Ans); + *ans = e_realloc(*ans, sizeof(struct telnetAttrs) * *Ans); if (!*ans) { LOGERR; return -1;