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/* in misc.c */
25/* gets the user home dir. */
26char *ssh_get_user_home_dir(void);
27char *ssh_get_local_username(void);
28int ssh_file_readaccess_ok(const char *file);
29
30char *ssh_path_expand_tilde(const char *d);
31char *ssh_path_expand_escape(ssh_session session, const char *s);
32int ssh_analyze_banner(ssh_session session, int server, int *ssh1, int *ssh2);
33int ssh_is_ipaddr_v4(const char *str);
34int ssh_is_ipaddr(const char *str);
35
36/* list processing */
37
38struct ssh_list {
39 struct ssh_iterator *root;
40 struct ssh_iterator *end;
41};
42
43struct ssh_iterator {
44 struct ssh_iterator *next;
45 const void *data;
46};
47
48struct ssh_timestamp {
49 long seconds;
50 long useconds;
51};
52
53struct ssh_list *ssh_list_new(void);
54void ssh_list_free(struct ssh_list *list);
55struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list);
56struct ssh_iterator *ssh_list_find(const struct ssh_list *list, void *value);
57int ssh_list_append(struct ssh_list *list, const void *data);
58int ssh_list_prepend(struct ssh_list *list, const void *data);
59void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator);
60char *ssh_lowercase(const char* str);
61char *ssh_hostport(const char *host, int port);
62
63const void *_ssh_list_pop_head(struct ssh_list *list);
64
65#define ssh_iterator_value(type, iterator)\
66 ((type)((iterator)->data))
67
68/** @brief fetch the head element of a list and remove it from list
69 * @param type type of the element to return
70 * @param list the ssh_list to use
71 * @return the first element of the list, or NULL if the list is empty
72 */
73#define ssh_list_pop_head(type, ssh_list)\
74 ((type)_ssh_list_pop_head(ssh_list))
75
76int ssh_make_milliseconds(long sec, long usec);
77void ssh_timestamp_init(struct ssh_timestamp *ts);
78int ssh_timeout_elapsed(struct ssh_timestamp *ts, int timeout);
79int ssh_timeout_update(struct ssh_timestamp *ts, int timeout);
80
81int ssh_match_group(const char *group, const char *object);
82
83#endif /* MISC_H_ */
84