1/* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License as 4 * published by the Free Software Foundation; either version 2 of 5 * the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software 14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 15 * MA 02111-1307 USA 16 */ 17#ifndef VSFTP_STR_H 18#define VSFTP_STR_H 19 20/* TODO - document these functions ;-) */ 21 22#ifndef VSF_FILESIZE_H 23#include "filesize.h" 24#endif 25 26struct mystr 27{ 28 char *PRIVATE_HANDS_OFF_p_buf; 29 /* Internally, EXCLUDES trailing null */ 30 unsigned int PRIVATE_HANDS_OFF_len; 31 unsigned int PRIVATE_HANDS_OFF_alloc_bytes; 32}; 33 34#define INIT_MYSTR \ 35 { (void*)0, 0, 0 } 36 37#ifdef VSFTP_STRING_HELPER 38#define str_alloc_memchunk private_str_alloc_memchunk 39#endif 40void private_str_alloc_memchunk(struct mystr* p_str, const char* p_src, 41 unsigned int len); 42 43void str_alloc_text(struct mystr* p_str, const char* p_src); 44/* NOTE: String buffer data does NOT include terminating character */ 45void str_alloc_alt_term(struct mystr* p_str, const char* p_src, char term); 46void str_alloc_ulong(struct mystr* p_str, unsigned long the_ulong); 47void str_alloc_filesize_t(struct mystr* p_str, filesize_t the_filesize); 48void str_copy(struct mystr* p_dest, const struct mystr* p_src); 49const char* str_strdup(const struct mystr* p_str); 50void str_empty(struct mystr* p_str); 51void str_free(struct mystr* p_str); 52void str_trunc(struct mystr* p_str, unsigned int trunc_len); 53void str_reserve(struct mystr* p_str, unsigned int res_len); 54 55int str_isempty(const struct mystr* p_str); 56unsigned int str_getlen(const struct mystr* p_str); 57const char* str_getbuf(const struct mystr* p_str); 58 59int str_strcmp(const struct mystr* p_str1, const struct mystr* p_str2); 60int str_equal(const struct mystr* p_str1, const struct mystr* p_str2); 61int str_equal_text(const struct mystr* p_str, const char* p_text); 62 63void str_append_str(struct mystr* p_str, const struct mystr* p_other); 64void str_append_text(struct mystr* p_str, const char* p_src); 65void str_append_ulong(struct mystr* p_str, unsigned long the_long); 66void str_append_filesize_t(struct mystr* p_str, filesize_t the_filesize); 67void str_append_char(struct mystr* p_str, char the_char); 68void str_append_double(struct mystr* p_str, double the_double); 69 70void str_upper(struct mystr* p_str); 71void str_rpad(struct mystr* p_str, const unsigned int min_width); 72void str_lpad(struct mystr* p_str, const unsigned int min_width); 73void str_replace_char(struct mystr* p_str, char from, char to); 74void str_replace_text(struct mystr* p_str, const char* p_from, 75 const char* p_to); 76 77void str_split_char(struct mystr* p_src, struct mystr* p_rhs, char c); 78void str_split_char_reverse(struct mystr* p_src, struct mystr* p_rhs, char c); 79void str_split_text(struct mystr* p_src, struct mystr* p_rhs, 80 const char* p_text); 81void str_split_text_reverse(struct mystr* p_src, struct mystr* p_rhs, 82 const char* p_text); 83 84struct str_locate_result 85{ 86 int found; 87 unsigned int index; 88 char char_found; 89}; 90 91struct str_locate_result str_locate_char( 92 const struct mystr* p_str, char look_char); 93struct str_locate_result str_locate_str( 94 const struct mystr* p_str, const struct mystr* p_look_str); 95struct str_locate_result str_locate_str_reverse( 96 const struct mystr* p_str, const struct mystr* p_look_str); 97struct str_locate_result str_locate_text( 98 const struct mystr* p_str, const char* p_text); 99struct str_locate_result str_locate_text_reverse( 100 const struct mystr* p_str, const char* p_text); 101struct str_locate_result str_locate_chars( 102 const struct mystr* p_str, const char* p_chars); 103 104void str_left(const struct mystr* p_str, struct mystr* p_out, 105 unsigned int chars); 106void str_right(const struct mystr* p_str, struct mystr* p_out, 107 unsigned int chars); 108void str_mid_to_end(const struct mystr* p_str, struct mystr* p_out, 109 unsigned int indexx); 110 111char str_get_char_at(const struct mystr* p_str, const unsigned int indexx); 112int str_contains_space(const struct mystr* p_str); 113int str_contains_unprintable(const struct mystr* p_str); 114void str_replace_unprintable(struct mystr* p_str, char new_char); 115int str_atoi(const struct mystr* p_str); 116filesize_t str_a_to_filesize_t(const struct mystr* p_str); 117unsigned int str_octal_to_uint(const struct mystr* p_str); 118 119/* PURPOSE: Extract a line of text (delimited by \n or EOF) from a string 120 * buffer, starting at character position 'p_pos'. The extracted line will 121 * not contain the '\n' terminator. 122 * 123 * RETURNS: 0 if no more lines are available, 1 otherwise. 124 * The extracted text line is stored in 'p_line_str', which is 125 * emptied if there are no more lines. 'p_pos' is updated to point to the 126 * first character after the end of the line just extracted. 127 */ 128int str_getline(const struct mystr* p_str, struct mystr* p_line_str, 129 unsigned int* p_pos); 130 131/* PURPOSE: Detect whether or not a string buffer contains a specific line 132 * of text (delimited by \n or EOF). 133 * 134 * RETURNS: 1 if there is a matching line, 0 otherwise. 135 */ 136int str_contains_line(const struct mystr* p_str, 137 const struct mystr* p_line_str); 138 139#endif /* VSFTP_STR_H */ 140 141