libssh  0.10.6
The SSH library
Loading...
Searching...
No Matches
misc.h
1/*
2 * This file is part of the SSH Library
3 *
4 * Copyright (c) 2009 by Aris Adamantiadis
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef MISC_H_
22#define MISC_H_
23
24#include <stdio.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/* in misc.c */
31/* gets the user home dir. */
32char *ssh_get_user_home_dir(void);
33char *ssh_get_local_username(void);
34int ssh_file_readaccess_ok(const char *file);
35int ssh_dir_writeable(const char *path);
36
37char *ssh_path_expand_tilde(const char *d);
38char *ssh_path_expand_escape(ssh_session session, const char *s);
39int ssh_analyze_banner(ssh_session session, int server);
40int ssh_is_ipaddr_v4(const char *str);
41int ssh_is_ipaddr(const char *str);
42
43/* list processing */
44
45struct ssh_list {
46 struct ssh_iterator *root;
47 struct ssh_iterator *end;
48};
49
51 struct ssh_iterator *next;
52 const void *data;
53};
54
56 long seconds;
57 long useconds;
58};
59
60enum ssh_quote_state_e {
61 NO_QUOTE,
62 SINGLE_QUOTE,
63 DOUBLE_QUOTE
64};
65
66struct ssh_list *ssh_list_new(void);
67void ssh_list_free(struct ssh_list *list);
68struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list);
69struct ssh_iterator *ssh_list_find(const struct ssh_list *list, void *value);
70size_t ssh_list_count(const struct ssh_list *list);
71int ssh_list_append(struct ssh_list *list, const void *data);
72int ssh_list_prepend(struct ssh_list *list, const void *data);
73void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator);
74char *ssh_lowercase(const char* str);
75char *ssh_hostport(const char *host, int port);
76
77const void *_ssh_list_pop_head(struct ssh_list *list);
78
79#define ssh_iterator_value(type, iterator)\
80 ((type)((iterator)->data))
81
87#define ssh_list_pop_head(type, ssh_list)\
88 ((type)_ssh_list_pop_head(ssh_list))
89
90int ssh_make_milliseconds(unsigned long sec, unsigned long usec);
91void ssh_timestamp_init(struct ssh_timestamp *ts);
92int ssh_timeout_elapsed(struct ssh_timestamp *ts, int timeout);
93int ssh_timeout_update(struct ssh_timestamp *ts, int timeout);
94
95int ssh_match_group(const char *group, const char *object);
96
97void uint64_inc(unsigned char *counter);
98
99void ssh_log_hexdump(const char *descr, const unsigned char *what, size_t len);
100
101int ssh_mkdirs(const char *pathname, mode_t mode);
102
103int ssh_quote_file_name(const char *file_name, char *buf, size_t buf_len);
104int ssh_newline_vis(const char *string, char *buf, size_t buf_len);
105int ssh_tmpname(char *name);
106
107char *ssh_strreplace(const char *src, const char *pattern, const char *repl);
108
109int ssh_check_hostname_syntax(const char *hostname);
110
111FILE *ssh_strict_fopen(const char *filename, size_t max_file_size);
112
113#ifdef __cplusplus
114}
115#endif
116
117#endif /* MISC_H_ */
void ssh_log_hexdump(const char *descr, const unsigned char *what, size_t len)
Log the content of a buffer in hexadecimal format, similar to the output of 'hexdump -C' command.
Definition misc.c:514
int ssh_mkdirs(const char *pathname, mode_t mode)
Attempts to create a directory with the given pathname. The missing directories in the given pathname...
Definition misc.c:1044
size_t ssh_list_count(const struct ssh_list *list)
Get the number of elements in the list.
Definition misc.c:756
int ssh_check_hostname_syntax(const char *hostname)
Checks syntax of a domain name.
Definition misc.c:2029
char * ssh_path_expand_tilde(const char *d)
Expand a directory starting with a tilde '~'.
Definition misc.c:1107
int ssh_timeout_update(struct ssh_timestamp *ts, int timeout)
updates a timeout value so it reflects the remaining time
Definition misc.c:1550
int ssh_dir_writeable(const char *path)
Check if the given path is an existing directory and that is accessible for writing.
Definition misc.c:309
Definition misc.h:50
Definition misc.h:45
Definition session.h:127
Definition misc.h:55