File: plugin_tunnel.h

package info (click to toggle)
gsql 0.2.2-1.2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 4,804 kB
  • sloc: ansic: 31,966; sh: 6,690; makefile: 866; xml: 706
file content (155 lines) | stat: -rw-r--r-- 3,482 bytes parent folder | download
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* 
 * GSQL - database development tool for GNOME
 *
 * Copyright (C) 2006-2010  Taras Halturin  halturin@gmail.com
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program 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 Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
 */

 
#ifndef _PLUGIN_TUNNEL_H
#define _PLUGIN_TUNNEL_H

#include <glib.h>
#include <libgsql/sqleditor.h>
#include <libgsql/session.h>

#include <libssh/libssh.h>
#include <libssh/sftp.h>

#define GSQLP_TUNNEL_STOCK_ICON "gsql-plugin-tunnel-icon"

#define GSQLP_TUNNEL_ERR_LEN	512

#define GSQLP_TUNNEL_SET_ERROR(tunnel, params...) \
		memset (tunnel->err, 0, 512); \
		g_snprintf (tunnel->err, 512, params)


typedef struct _GSQLPTunnel GSQLPTunnel;
typedef struct _GSQLPTunnelClass GSQLPTunnelClass;
typedef struct _GSQLPTunnelPrivate GSQLPTunnelPrivate;

typedef struct _GSQLPChannel	GSQLPChannel;


typedef enum {
	GSQLP_TUNNEL_STATE_NONE,
	GSQLP_TUNNEL_STATE_ERROR,
	GSQLP_TUNNEL_STATE_CONNECTED,
	GSQLP_TUNNEL_STATE_CONNECTING
} GSQLPTunnelState;

typedef enum {
	GSQLP_TUNNEL_AUTH_PASS = 1,
	GSQLP_TUNNEL_AUTH_PUB,
} GSQLPTunnelAuthType;

#define GSQLP_TUNNEL_TYPE 			(gsqlp_tunnel_get_type ())
#define GSQLP_TUNNEL(obj)			(G_TYPE_CHECK_INSTANCE_CAST ((obj), GSQLP_TUNNEL_TYPE, GSQLPTunnel))
#define GSQLP_TUNNEL_CLASS(klass)	(G_TYPE_CHECK_INSTANCE_CAST ((klass), GSQLP_TUNNEL_TYPE, GSQLPTunnelClass))

#define GSQLP_IS_TUNNEL(obj)			(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSQLP_TUNNEL_TYPE))
#define GSQLP_IS_TUNNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSQLP_TUNNEL_TYPE))

#define GSQLP_TUNNEL_LOCK(tunnel)	pthread_mutex_lock (&tunnel->mutex);
#define GSQLP_TUNNEL_UNLOCK(tunnel)	pthread_mutex_unlock (&tunnel->mutex);

struct _GSQLPTunnel {

	GObject parent;
	
	gchar name[128];
	gchar confname[32];

	/* connect to */
	gchar hostname[128];
	gchar username[128];
	gchar password[64];
	guint		port;

	GSQLPTunnelAuthType auth_type;
	
	ssh_session ssh;
	sftp_session sftp;
	pthread_mutex_t mutex;

	/* listen on */
	gchar		localname[128];
	guint			localport;

	int			sock;

	/* forwarded from */
	gchar		fwdhost[128];
	guint			fwdport;

	/* list of GSQLPChannel */
	GList		*channel_list;

	gboolean	autoconnect;
	
	gchar		err[GSQLP_TUNNEL_ERR_LEN];

	GSQLPTunnelPrivate	*private;
	
};

struct _GSQLPTunnelClass
{
	GObjectClass parent;
	
	/* Signals */
	void (*state_changed) (GSQLPTunnel *tunnel);
};


struct _GSQLPChannel {

	ssh_channel	channel;

	gint sock;

	guint64		rx; // we count this 
	guint64		tx; // for the future 
	
	GSQLSession *session; // is it possible to get it right here? check it!

};


G_BEGIN_DECLS

GType
gsqlp_tunnel_get_type ();

GSQLPTunnelState
gsqlp_tunnel_get_state (GSQLPTunnel *tunnel);

GSQLPTunnel *
gsqlp_tunnel_new (void);

void
gsqlp_tunnel_do_connect (GSQLPTunnel *tunnel);

void
gsqlp_tunnel_do_disconnect (GSQLPTunnel *tunnel);

G_END_DECLS

#endif /* _PLUGIN_TUNNEL_H */