1#ifndef VSFTP_STR_H
2#define VSFTP_STR_H
3
4/* TODO - document these functions ;-) */
5
6#ifndef VSF_FILESIZE_H
7#include "filesize.h"
8#endif
9
10struct mystr
11{
12  char *PRIVATE_HANDS_OFF_p_buf;
13  /* Internally, EXCLUDES trailing null */
14  unsigned int PRIVATE_HANDS_OFF_len;
15  unsigned int PRIVATE_HANDS_OFF_alloc_bytes;
16};
17
18#define INIT_MYSTR \
19  { (void*)0, 0, 0 }
20
21#ifdef VSFTP_STRING_HELPER
22#define str_alloc_memchunk private_str_alloc_memchunk
23#endif
24void private_str_alloc_memchunk(struct mystr* p_str, const char* p_src,
25                                unsigned int len);
26
27void str_alloc_text(struct mystr* p_str, const char* p_src);
28/* NOTE: String buffer data does NOT include terminating character */
29void str_alloc_alt_term(struct mystr* p_str, const char* p_src, char term);
30void str_alloc_ulong(struct mystr* p_str, unsigned long the_ulong);
31void str_alloc_filesize_t(struct mystr* p_str, filesize_t the_filesize);
32void str_copy(struct mystr* p_dest, const struct mystr* p_src);
33const char* str_strdup(const struct mystr* p_str);
34void str_empty(struct mystr* p_str);
35void str_free(struct mystr* p_str);
36void str_trunc(struct mystr* p_str, unsigned int trunc_len);
37void str_reserve(struct mystr* p_str, unsigned int res_len);
38
39int str_isempty(const struct mystr* p_str);
40unsigned int str_getlen(const struct mystr* p_str);
41const char* str_getbuf(const struct mystr* p_str);
42
43int str_strcmp(const struct mystr* p_str1, const struct mystr* p_str2);
44int str_equal(const struct mystr* p_str1, const struct mystr* p_str2);
45int str_equal_text(const struct mystr* p_str, const char* p_text);
46
47void str_append_str(struct mystr* p_str, const struct mystr* p_other);
48void str_append_text(struct mystr* p_str, const char* p_src);
49void str_append_ulong(struct mystr* p_str, unsigned long the_long);
50void str_append_filesize_t(struct mystr* p_str, filesize_t the_filesize);
51void str_append_char(struct mystr* p_str, char the_char);
52void str_append_double(struct mystr* p_str, double the_double);
53
54void str_upper(struct mystr* p_str);
55void str_rpad(struct mystr* p_str, const unsigned int min_width);
56void str_lpad(struct mystr* p_str, const unsigned int min_width);
57void str_replace_char(struct mystr* p_str, char from, char to);
58void str_replace_text(struct mystr* p_str, const char* p_from,
59                      const char* p_to);
60
61void str_split_char(struct mystr* p_src, struct mystr* p_rhs, char c);
62void str_split_char_reverse(struct mystr* p_src, struct mystr* p_rhs, char c);
63void str_split_text(struct mystr* p_src, struct mystr* p_rhs,
64                    const char* p_text);
65void str_split_text_reverse(struct mystr* p_src, struct mystr* p_rhs,
66                            const char* p_text);
67
68struct str_locate_result
69{
70  int found;
71  unsigned int index;
72  char char_found;
73};
74
75struct str_locate_result str_locate_char(
76  const struct mystr* p_str, char look_char);
77struct str_locate_result str_locate_str(
78  const struct mystr* p_str, const struct mystr* p_look_str);
79struct str_locate_result str_locate_str_reverse(
80  const struct mystr* p_str, const struct mystr* p_look_str);
81struct str_locate_result str_locate_text(
82  const struct mystr* p_str, const char* p_text);
83struct str_locate_result str_locate_text_reverse(
84  const struct mystr* p_str, const char* p_text);
85struct str_locate_result str_locate_chars(
86  const struct mystr* p_str, const char* p_chars);
87
88void str_left(const struct mystr* p_str, struct mystr* p_out,
89              unsigned int chars);
90void str_right(const struct mystr* p_str, struct mystr* p_out,
91               unsigned int chars);
92void str_mid_to_end(const struct mystr* p_str, struct mystr* p_out,
93                    unsigned int indexx);
94
95char str_get_char_at(const struct mystr* p_str, const unsigned int indexx);
96int str_contains_space(const struct mystr* p_str);
97int str_contains_unprintable(const struct mystr* p_str);
98void str_replace_unprintable(struct mystr* p_str, char new_char);
99int str_atoi(const struct mystr* p_str);
100filesize_t str_a_to_filesize_t(const struct mystr* p_str);
101unsigned int str_octal_to_uint(const struct mystr* p_str);
102
103/* PURPOSE: Extract a line of text (delimited by \n or EOF) from a string
104 * buffer, starting at character position 'p_pos'. The extracted line will
105 * not contain the '\n' terminator.
106 *
107 * RETURNS: 0 if no more lines are available, 1 otherwise.
108 * The extracted text line is stored in 'p_line_str', which is
109 * emptied if there are no more lines. 'p_pos' is updated to point to the
110 * first character after the end of the line just extracted.
111 */
112int str_getline(const struct mystr* p_str, struct mystr* p_line_str,
113                unsigned int* p_pos);
114
115/* PURPOSE: Detect whether or not a string buffer contains a specific line
116 * of text (delimited by \n or EOF).
117 *
118 * RETURNS: 1 if there is a matching line, 0 otherwise.
119 */
120int str_contains_line(const struct mystr* p_str,
121                      const struct mystr* p_line_str);
122
123#endif /* VSFTP_STR_H */
124
125