libssh  0.5.4
misc.h
1 /*
2  * This file is part of the SSH Library
3  *
4  * Copyright (c) 2009 by Aris Adamantiadis
5  *
6  * The SSH Library is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or (at your
9  * option) any later version.
10  *
11  * The SSH Library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with the SSH Library; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19  * MA 02111-1307, USA.
20  */
21 
22 #ifndef MISC_H_
23 #define MISC_H_
24 
25 /* in misc.c */
26 /* gets the user home dir. */
27 char *ssh_get_user_home_dir(void);
28 char *ssh_get_local_username(ssh_session session);
29 int ssh_file_readaccess_ok(const char *file);
30 
31 char *ssh_path_expand_tilde(const char *d);
32 char *ssh_path_expand_escape(ssh_session session, const char *s);
33 int ssh_analyze_banner(ssh_session session, int server, int *ssh1, int *ssh2);
34 int ssh_is_ipaddr_v4(const char *str);
35 int ssh_is_ipaddr(const char *str);
36 
37 /* macro for byte ordering */
38 uint64_t ntohll(uint64_t);
39 #define htonll(x) ntohll(x)
40 
41 /* list processing */
42 
43 struct ssh_list {
44  struct ssh_iterator *root;
45  struct ssh_iterator *end;
46 };
47 
48 struct ssh_iterator {
49  struct ssh_iterator *next;
50  const void *data;
51 };
52 
53 struct ssh_timestamp {
54  long seconds;
55  long useconds;
56 };
57 
58 struct ssh_list *ssh_list_new(void);
59 void ssh_list_free(struct ssh_list *list);
60 struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list);
61 struct ssh_iterator *ssh_list_find(const struct ssh_list *list, void *value);
62 int ssh_list_append(struct ssh_list *list, const void *data);
63 int ssh_list_prepend(struct ssh_list *list, const void *data);
64 void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator);
65 char *ssh_lowercase(const char* str);
66 char *ssh_hostport(const char *host, int port);
67 
68 const void *_ssh_list_pop_head(struct ssh_list *list);
69 
70 #define ssh_iterator_value(type, iterator)\
71  ((type)((iterator)->data))
72 
78 #define ssh_list_pop_head(type, ssh_list)\
79  ((type)_ssh_list_pop_head(ssh_list))
80 
81 int ssh_make_milliseconds(long sec, long usec);
82 void ssh_timestamp_init(struct ssh_timestamp *ts);
83 int ssh_timeout_elapsed(struct ssh_timestamp *ts, int timeout);
84 int ssh_timeout_update(struct ssh_timestamp *ts, int timeout);
85 
86 #endif /* MISC_H_ */