ZOO-Project
sshapi.h
Go to the documentation of this file.
1 /*
2  *
3  * Author : GĂ©rald FENOY
4  *
5  * Copyright 2017 GeoLabs SARL. All rights reserved.
6  *
7  * This work was supported by public funds received in the framework of GEOSUD,
8  * a project (ANR-10-EQPX-20) of the program "Investissements d'Avenir" managed
9  * by the French National Research Agency
10  *
11  * permission is hereby granted, free of charge, to any person obtaining a copy
12  * of this software and associated documentation files (the "Software"), to deal
13  * in the Software without restriction, including without limitation the rights
14  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15  * copies of the Software, and to permit persons to whom the Software is
16  * furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27  * THE SOFTWARE.
28  */
29 
30 #ifndef SSHAPI_H
31 #define SSHAPI_H 1
32 
33 #pragma once
34 
35 #include <libssh2.h>
36 #include <libssh2_sftp.h>
37 
38 #ifdef HAVE_WINSOCK2_H
39 #include <winsock2.h>
40 #endif
41 #ifdef HAVE_SYS_SOCKET_H
42 #include <sys/socket.h>
43 #endif
44 #ifdef HAVE_NETINET_IN_H
45 #include <netinet/in.h>
46 #endif
47 #ifdef HAVE_SYS_SELECT_H
48 #include <sys/select.h>
49 #endif
50 #ifdef HAVE_UNISTD_H
51 #include <unistd.h>
52 #endif
53 #ifdef HAVE_ARPA_INET_H
54 #include <arpa/inet.h>
55 #endif
56 #ifdef HAVE_SYS_TIME_H
57 #include <sys/time.h>
58 #endif
59 
60 #include <netdb.h>
61 #include <arpa/inet.h>
62 #include <sys/types.h>
63 #include <fcntl.h>
64 #include <errno.h>
65 #include <stdio.h>
66 #include <ctype.h>
67 #include <time.h>
68 
69 #include "service.h"
70 
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
74 
75 #define MAX_PARALLEL_SSH_CON 128
76 
77  static int nb_sessions;
78 
79  typedef struct {
80  int sock_id;
81  int index;
82  LIBSSH2_SESSION *session;
83  LIBSSH2_SFTP *sftp_session;
84  } SSHCON;
85 
86 
88  ZOO_DLL_EXPORT bool ssh_copy(maps*,const char*,const char*,int);
90  ZOO_DLL_EXPORT int ssh_fetch(maps*,const char*,const char*,int);
91  ZOO_DLL_EXPORT int ssh_exec(maps*,const char*,int);
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif
ZOO_DLL_EXPORT int ssh_get_cnt(maps *)
Get the number of opened SSH connections.
Definition: sshapi.c:250
Definition: sshapi.h:79
ZOO_DLL_EXPORT bool runUpload(maps **)
Definition: sshapi.c:712
int index
Definition: sshapi.h:81
int sock_id
Definition: sshapi.h:80
ZOO_DLL_EXPORT bool ssh_close(maps *)
Close all the opened SSH connections.
Definition: sshapi.c:608
#define ZOO_DLL_EXPORT
linked list of map pointer
Definition: main_conf_read.y:285
ZOO_DLL_EXPORT int ssh_fetch(maps *, const char *, const char *, int)
Download a file over an opened SSH connection.
Definition: sshapi.c:414
LIBSSH2_SFTP * sftp_session
Definition: sshapi.h:83
ZOO_DLL_EXPORT bool addToUploadQueue(maps **, maps *)
Definition: sshapi.c:620
LIBSSH2_SESSION * session
Definition: sshapi.h:82
ZOO_DLL_EXPORT bool ssh_close_session(maps *, SSHCON *)
Close an opened SSH connection.
Definition: sshapi.c:588
ZOO_DLL_EXPORT bool ssh_copy(maps *, const char *, const char *, int)
Upload a file over an opened SSH connection.
Definition: sshapi.c:323
ZOO_DLL_EXPORT SSHCON * ssh_connect(maps *)
Connect to a remote host using SSH protocol.
Definition: sshapi.c:77
ZOO_DLL_EXPORT int ssh_exec(maps *, const char *, int)
Execute a command over an opened SSH connection.
Definition: sshapi.c:509
static int nb_sessions
Definition: sshapi.h:77