/* ****************************************************************************** * SOURCE FILE * * Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipssh_list.c,v $ $Revision: 1.26 $ * $Source: /home/interpeak/CVSRoot/ipssh/src/ipssh_list.c,v $ * $Author: rboden $ $Date: 2010-09-21 11:49:19 $ * $State: Exp $ $Locker: $ * * INTERPEAK_COPYRIGHT_STRING * Design and implementation by Roger Boden ****************************************************************************** */ /* **************************************************************************** * 1 DESCRIPTION **************************************************************************** */ /* **************************************************************************** * 2 CONFIGURATION **************************************************************************** */ /* **************************************************************************** * 3 INCLUDE FILES **************************************************************************** */ #include "ipssh_h.h" #include "ipssh_list.h" #include #include #include #include #include #include #include /* **************************************************************************** * 4 EXTERN PROTOTYPES **************************************************************************** */ /* **************************************************************************** * 5 DEFINES **************************************************************************** */ /* **************************************************************************** * 6 TYPES **************************************************************************** */ /* **************************************************************************** * 7 LOCAL PROTOTYPES **************************************************************************** */ /* **************************************************************************** * 8 DATA **************************************************************************** */ /* **************************************************************************** * 9 LOCAL FUNCTIONS **************************************************************************** */ /* **************************************************************************** * 10 PUBLIC FUNCTIONS **************************************************************************** */ /* *=========================================================================== * ipssh_list_str_insert_last *=========================================================================== * Description: Inserts a string into the list. A terminating NULL is added. */ IP_GLOBAL Ip_err ipssh_list_str_insert_last(Ipssh_str_list* head, const char* ptr, Ip_size_t len) { Ipssh_str_list* entry; char* tmp_ptr; entry = ipcom_malloc(sizeof(Ipssh_str_list)); tmp_ptr = ipcom_malloc(len+1); if( !entry || !tmp_ptr ) { IPCOM_LOG0(ERR, "ipssh_list_insert_last :: out of memory"); if(entry) ipcom_free(entry); if(tmp_ptr) ipcom_free(tmp_ptr); return IPCOM_ERR_FAILED; } entry->str = tmp_ptr; ipcom_memcpy(entry->str, ptr, len); entry->str[len] = 0; ipcom_list_insert_last((Ipcom_list*) head, (Ipcom_list*) entry); return IPCOM_SUCCESS; } /* *=========================================================================== * ipssh_list_buf_insert_last *=========================================================================== * Description: A buffer is added. The length is prepended to the inserted buffer * Parameters: * Returns: * */ IP_GLOBAL Ip_err ipssh_list_buf_insert_last(Ipcom_list* head, const char* ptr, Ip_size_t len) { Ipssh_str_list* entry; char* tmp_ptr; entry = ipcom_malloc(sizeof(Ipssh_str_list)); tmp_ptr = ipcom_malloc(len+4); if( !entry || !tmp_ptr ) { IPCOM_LOG0(ERR, "ipssh_list_insert_last :: out of memory"); if(entry) ipcom_free(entry); if(tmp_ptr) ipcom_free(tmp_ptr); return IPCOM_ERR_FAILED; } entry->str = tmp_ptr; *((Ip_s32*)entry->str) = (Ip_s32)len; IP_PANIC(); ipcom_memcpy(entry->str+4, ptr, len); ipcom_list_insert_last((Ipcom_list*) head, (Ipcom_list*) entry); return IPCOM_SUCCESS; } /* *=========================================================================== * ipssh_str2list *=========================================================================== * Description: * Parameters: * Returns: * */ IP_GLOBAL Ip_err ipssh_str2list(Ipssh_str_list* list, const char* str, const char* delim) { char* buf; char* item, *last; buf = ipcom_malloc(ipcom_strlen(str)+1); if(!buf) return IPCOM_ERR_FAILED; ipcom_strcpy(buf, str); for( item = ipcom_strtok_r(buf, delim, &last); item; item = ipcom_strtok_r(IP_NULL, delim, &last) ) { if( ipssh_list_str_insert_last(list, item, ipcom_strlen(item)) ) { IPCOM_LOG0(DEBUG2, "ipssh_string2list :: ipssh_list_insert_last() failed"); ipcom_free(buf); return IPCOM_ERR_FAILED; } } ipcom_free(buf); return IPCOM_SUCCESS; } /* *=========================================================================== * ipssh_list_free *=========================================================================== * Description: * Parameters: * Returns: * */ IP_GLOBAL void ipssh_list_free(Ipcom_list* head) { Ipcom_list* entry; for(entry = ipcom_list_first(head); entry; entry = ipcom_list_first(head)) { ipcom_list_remove(entry); ipcom_free(entry); } } IP_GLOBAL void ipssh_str_list_free(Ipssh_str_list* head) { Ipcom_list* entry; for(entry = ipcom_list_first((Ipcom_list*)head); entry; entry = ipcom_list_first((Ipcom_list*)head)) { Ipssh_str_list* str_entry = (Ipssh_str_list*) entry; ipcom_list_remove((Ipcom_list*)entry); if( str_entry->str ) ipcom_free(str_entry->str); ipcom_free(str_entry); } } /* **************************************************************************** * END OF FILE **************************************************************************** */