libssh  0.7.2
include/libssh/misc.h
00001 /*
00002  * This file is part of the SSH Library
00003  *
00004  * Copyright (c) 2009 by Aris Adamantiadis
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #ifndef MISC_H_
00022 #define MISC_H_
00023 
00024 /* in misc.c */
00025 /* gets the user home dir. */
00026 char *ssh_get_user_home_dir(void);
00027 char *ssh_get_local_username(void);
00028 int ssh_file_readaccess_ok(const char *file);
00029 
00030 char *ssh_path_expand_tilde(const char *d);
00031 char *ssh_path_expand_escape(ssh_session session, const char *s);
00032 int ssh_analyze_banner(ssh_session session, int server, int *ssh1, int *ssh2);
00033 int ssh_is_ipaddr_v4(const char *str);
00034 int ssh_is_ipaddr(const char *str);
00035 
00036 #ifndef HAVE_NTOHLL
00037 /* macro for byte ordering */
00038 uint64_t ntohll(uint64_t);
00039 #endif
00040 
00041 #ifndef HAVE_HTONLL
00042 #define htonll(x) ntohll((x))
00043 #endif
00044 
00045 /* list processing */
00046 
00047 struct ssh_list {
00048   struct ssh_iterator *root;
00049   struct ssh_iterator *end;
00050 };
00051 
00052 struct ssh_iterator {
00053   struct ssh_iterator *next;
00054   const void *data;
00055 };
00056 
00057 struct ssh_timestamp {
00058   long seconds;
00059   long useconds;
00060 };
00061 
00062 struct ssh_list *ssh_list_new(void);
00063 void ssh_list_free(struct ssh_list *list);
00064 struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list);
00065 struct ssh_iterator *ssh_list_find(const struct ssh_list *list, void *value);
00066 int ssh_list_append(struct ssh_list *list, const void *data);
00067 int ssh_list_prepend(struct ssh_list *list, const void *data);
00068 void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator);
00069 char *ssh_lowercase(const char* str);
00070 char *ssh_hostport(const char *host, int port);
00071 
00072 const void *_ssh_list_pop_head(struct ssh_list *list);
00073 
00074 #define ssh_iterator_value(type, iterator)\
00075   ((type)((iterator)->data))
00076 
00082 #define ssh_list_pop_head(type, ssh_list)\
00083   ((type)_ssh_list_pop_head(ssh_list))
00084 
00085 int ssh_make_milliseconds(long sec, long usec);
00086 void ssh_timestamp_init(struct ssh_timestamp *ts);
00087 int ssh_timeout_elapsed(struct ssh_timestamp *ts, int timeout);
00088 int ssh_timeout_update(struct ssh_timestamp *ts, int timeout);
00089 
00090 int ssh_match_group(const char *group, const char *object);
00091 
00092 #endif /* MISC_H_ */