aboutsummaryrefslogtreecommitdiff
path: root/include/libssh/callback.h
blob: f21b88ba1ae140b1d3890ddb13619b65c21358ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * This file is part of the SSH Library
 *
 * Copyright (c) 2009 Aris Adamantiadis <aris@0xbadc0de.be>
 *
 * The SSH Library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version.
 *
 * The SSH Library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with the SSH Library; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA.
 */

/* callback.h
 * This file includes the declarations for the libssh callback mechanism
 */

#ifndef _SSH_CALLBACK_H
#define _SSH_CALLBACK_H

#include <string.h>

#include "libssh.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief SSH authentication callback.
 *
 * @param prompt        Prompt to be displayed.
 * @param buf           Buffer to save the password. You should null-terminate it.
 * @param len           Length of the buffer.
 * @param echo          Enable or disable the echo of what you type.
 * @param verify        Should the password be verified?
 * @param userdata      Userdata to be passed to the callback function. Useful
 *                      for GUI applications.
 *
 * @return              0 on success, < 0 on error.
 */
typedef int (*ssh_auth_callback) (const char *prompt, char *buf, size_t len,
    int echo, int verify, void *userdata);
typedef void (*ssh_log_callback) (ssh_session session, int priority,
    const char *message, void *userdata);

struct ssh_callbacks_struct {
	size_t size;    /* size of this structure */
	void *userdata; /* User-provided data */
	ssh_auth_callback auth_function; /* this functions will be called if e.g. a keyphrase is needed. */
	ssh_log_callback log_function; //log callback
  void (*connect_status_function)(void *arg, float status); /* status callback function */
};

typedef struct ssh_callbacks_struct * ssh_callbacks;
#define ssh_callbacks_init(p) do {\
	memset(p,'\0',sizeof(*p)); \
	p->size=sizeof(*p); \
} while(0);

LIBSSH_API int ssh_options_set_auth_callback(ssh_options opt, ssh_auth_callback cb,
    void *userdata);
LIBSSH_API int ssh_options_set_log_function(ssh_options opt,
    ssh_log_callback cb, void *userdata);
LIBSSH_API int ssh_options_set_status_callback(ssh_options opt, void (*callback)
        (void *arg, float status), void *arg);

#ifdef __cplusplus
}
#endif

#endif /*_SSH_CALLBACK_H */