libssh 0.11.1 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#ifdef _WIN32
25
26# ifdef _MSC_VER
27# ifndef _SSIZE_T_DEFINED
28# undef ssize_t
29# include <BaseTsd.h>
30 typedef _W64 SSIZE_T ssize_t;
31# define _SSIZE_T_DEFINED
32# endif /* _SSIZE_T_DEFINED */
33# endif /* _MSC_VER */
34
35#else
36#include <sys/types.h>
37#include <stdbool.h>
38#endif /* _WIN32 */
39
40#ifdef __cplusplus
41 extern "C" {
42#endif
43
44/* in misc.c */
45/* gets the user home dir. */
46 char *ssh_get_user_home_dir(void);
47 char *ssh_get_local_username(void);
48 int ssh_file_readaccess_ok(const char *file);
49 int ssh_dir_writeable(const char *path);
50
51 char *ssh_path_expand_tilde(const char *d);
52 char *ssh_path_expand_escape(ssh_session session, const char *s);
53 int ssh_analyze_banner(ssh_session session, int server);
54 int ssh_is_ipaddr_v4(const char *str);
55 int ssh_is_ipaddr(const char *str);
56
57/* list processing */
58
59 struct ssh_list {
60 struct ssh_iterator *root;
61 struct ssh_iterator *end;
62};
63
64 struct ssh_iterator {
65 struct ssh_iterator *next;
66 const void *data;
67};
68
69 struct ssh_jump_info_struct {
70 char *hostname;
71 char *username;
72 int port;
73};
74
75 struct ssh_timestamp {
76 long seconds;
77 long useconds;
78};
79
80 enum ssh_quote_state_e {
81 NO_QUOTE,
82 SINGLE_QUOTE,
83 DOUBLE_QUOTE
84};
85
86 struct ssh_list *ssh_list_new(void);
87 void ssh_list_free(struct ssh_list *list);
88 struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list);
89 struct ssh_iterator *ssh_list_find(const struct ssh_list *list, void *value);
90 size_t ssh_list_count(const struct ssh_list *list);
91 int ssh_list_append(struct ssh_list *list, const void *data);
92 int ssh_list_prepend(struct ssh_list *list, const void *data);
93 void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator);
94 char *ssh_lowercase(const char* str);
95 char *ssh_hostport(const char *host, int port);
96
97 const void *_ssh_list_pop_head(struct ssh_list *list);
98
99#define ssh_iterator_value(type, iterator)\
100 ((type)((iterator)->data))
101
107#define ssh_list_pop_head(type, ssh_list)\
108 ((type)_ssh_list_pop_head(ssh_list))
109
110#define SSH_LIST_FREE(x) \
111 do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
112
113 int ssh_make_milliseconds(unsigned long sec, unsigned long usec);
114 void ssh_timestamp_init(struct ssh_timestamp *ts);
115 int ssh_timeout_elapsed(struct ssh_timestamp *ts, int timeout);
116 int ssh_timeout_update(struct ssh_timestamp *ts, int timeout);
117
118 void uint64_inc(unsigned char *counter);
119
120 void ssh_log_hexdump(const char *descr, const unsigned char *what, size_t len);
121
122 int ssh_mkdirs(const char *pathname, mode_t mode);
123
124 int ssh_quote_file_name(const char *file_name, char *buf, size_t buf_len);
125 int ssh_newline_vis(const char *string, char *buf, size_t buf_len);
126 int ssh_tmpname(char *name);
127
128 char *ssh_strreplace(const char *src, const char *pattern, const char *repl);
129
130ssize_t ssh_readn(int fd, void *buf, size_t nbytes);
131ssize_t ssh_writen(int fd, const void *buf, size_t nbytes);
132
133 int ssh_check_hostname_syntax(const char *hostname);
134 int ssh_check_username_syntax(const char *username);
135
136 void ssh_proxyjumps_free(struct ssh_list *proxy_jump_list);
137 bool ssh_libssh_proxy_jumps(void);
138
139#ifdef __cplusplus
140}
141#endif
142
143#endif /* MISC_H_ */
ssh_libssh_proxy_jumps
bool ssh_libssh_proxy_jumps(void)
Check if libssh proxy jumps is enabled.
Definition misc.c:2238
ssh_writen
ssize_t ssh_writen(int fd, const void *buf, size_t nbytes)
Write the requested number of bytes to a local file.
Definition misc.c:2077
ssh_log_hexdump
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:521
ssh_mkdirs
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:1053
ssh_readn
ssize_t ssh_readn(int fd, void *buf, size_t nbytes)
Read the requested number of bytes from a local file.
Definition misc.c:2021
ssh_list_count
size_t ssh_list_count(const struct ssh_list *list)
Get the number of elements in the list.
Definition misc.c:764
ssh_proxyjumps_free
void ssh_proxyjumps_free(struct ssh_list *proxy_jump_list)
Free proxy jump list.
Definition misc.c:2213
ssh_check_hostname_syntax
int ssh_check_hostname_syntax(const char *hostname)
Checks syntax of a domain name.
Definition misc.c:2123
ssh_path_expand_tilde
char * ssh_path_expand_tilde(const char *d)
Expand a directory starting with a tilde '~'.
Definition misc.c:1116
ssh_check_username_syntax
int ssh_check_username_syntax(const char *username)
Checks syntax of a username.
Definition misc.c:2182
ssh_timeout_update
int ssh_timeout_update(struct ssh_timestamp *ts, int timeout)
updates a timeout value so it reflects the remaining time
Definition misc.c:1559
ssh_dir_writeable
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:314
ssh_jump_info_struct
Definition misc.h:69