libssh  0.6.3
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 /* in misc.c */
27 /* gets the user home dir. */
28 char *ssh_get_user_home_dir(void);
29 char *ssh_get_local_username(void);
30 int ssh_file_readaccess_ok(const char *file);
31 
32 char *ssh_path_expand_tilde(const char *d);
33 char *ssh_path_expand_escape(ssh_session session, const char *s);
34 int ssh_analyze_banner(ssh_session session, int server, int *ssh1, int *ssh2);
35 int ssh_is_ipaddr_v4(const char *str);
36 int ssh_is_ipaddr(const char *str);
37 
38 #ifndef HAVE_NTOHLL
39 /* macro for byte ordering */
40 uint64_t ntohll(uint64_t);
41 #endif
42 
43 #ifndef HAVE_HTONLL
44 #define htonll(x) ntohll((x))
45 #endif
46 
47 /* list processing */
48 
49 struct ssh_list {
50  struct ssh_iterator *root;
51  struct ssh_iterator *end;
52 };
53 
54 struct ssh_iterator {
55  struct ssh_iterator *next;
56  const void *data;
57 };
58 
59 struct ssh_timestamp {
60  long seconds;
61  long useconds;
62 };
63 
64 enum ssh_quote_state_e {
65  NO_QUOTE,
66  SINGLE_QUOTE,
67  DOUBLE_QUOTE
68 };
69 
70 struct ssh_list *ssh_list_new(void);
71 void ssh_list_free(struct ssh_list *list);
72 struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list);
73 struct ssh_iterator *ssh_list_find(const struct ssh_list *list, void *value);
74 int ssh_list_append(struct ssh_list *list, const void *data);
75 int ssh_list_prepend(struct ssh_list *list, const void *data);
76 void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator);
77 char *ssh_lowercase(const char* str);
78 char *ssh_hostport(const char *host, int port);
79 
80 const void *_ssh_list_pop_head(struct ssh_list *list);
81 
82 #define ssh_iterator_value(type, iterator)\
83  ((type)((iterator)->data))
84 
90 #define ssh_list_pop_head(type, ssh_list)\
91  ((type)_ssh_list_pop_head(ssh_list))
92 
93 int ssh_make_milliseconds(long sec, long usec);
94 void ssh_timestamp_init(struct ssh_timestamp *ts);
95 int ssh_timeout_elapsed(struct ssh_timestamp *ts, int timeout);
96 int ssh_timeout_update(struct ssh_timestamp *ts, int timeout);
97 
98 int ssh_match_group(const char *group, const char *object);
99 
100 int ssh_quote_file_name(const char *file_name, char *buf, size_t buf_len);
101 
102 int ssh_check_username_syntax(const char *username);
103 int ssh_check_hostname_syntax(const char *hostname);
104 
105 FILE *ssh_strict_fopen(const char *filename, size_t max_file_size);
106 
107 #endif /* MISC_H_ */
int ssh_check_username_syntax(const char *username)
Checks syntax of a username.
Definition: misc.c:1290
int ssh_timeout_update(struct ssh_timestamp *ts, int timeout)
updates a timeout value so it reflects the remaining time
Definition: misc.c:1056
char * ssh_path_expand_tilde(const char *d)
Expand a directory starting with a tilde &#39;~&#39;.
Definition: misc.c:683
int ssh_check_hostname_syntax(const char *hostname)
Checks syntax of a domain name.
Definition: misc.c:1329