author | Nicolas Cornu <nicolas.cornu@ensi-bourges.fr> |
Sat, 21 Aug 2010 14:44:03 +0200 | |
changeset 155 | 35e603b584a3 |
parent 154 | 1ffa1733d4b6 |
child 156 | 653fa009fea3 |
permissions | -rw-r--r-- |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
1 |
/* |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
2 |
* socks5.c |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
3 |
* |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
4 |
* Copyrigth (C) 2010 Nicolas Cornu <nicolas.cornu@ensi-bourges.fr> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
5 |
* |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
6 |
* This program is free software; you can redistribute it and/or modify |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
7 |
* it under the terms of the GNU General Public License as published by |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
8 |
* the Free Software Foundation; either version 2 of the License, or (at |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
9 |
* your option) any later version. |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
10 |
* |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
11 |
* This program is distributed in the hope that it will be useful, but |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
12 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
14 |
* General Public License for more details. |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
15 |
* |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
16 |
* You should have received a copy of the GNU General Public License |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
17 |
* along with this program; if not, write to the Free Software |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
19 |
* USA |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
20 |
*/ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
21 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
22 |
#include "config.h" |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
23 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
24 |
#include <glib.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
25 |
#include <gio/gio.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
26 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
27 |
#include <sys/types.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
28 |
#include <ifaddrs.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
29 |
#include <net/if.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
30 |
#include <netinet/in.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
31 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
32 |
#include <mcabber/xmpp.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
33 |
#include <mcabber/modules.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
34 |
#include <mcabber/utils.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
35 |
#include <mcabber/xmpp_helper.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
36 |
#include <mcabber/logprint.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
37 |
#include <mcabber/hooks.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
38 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
39 |
#include <jingle/jingle.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
40 |
#include <jingle/check.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
41 |
#include <jingle/register.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
42 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
43 |
#include "socks5.h" |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
44 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
45 |
static gconstpointer check(JingleContent *cn, GError **err); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
46 |
static void tomessage(gconstpointer data, LmMessageNode *node); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
47 |
// static void _send(session_content *sc, gconstpointer data, gchar *buf, gsize size); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
48 |
static void init(session_content *sc, gconstpointer data); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
49 |
static void end(session_content *sc, gconstpointer data); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
50 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
51 |
static void handle_sock_io(GSocket *sock, GIOCondition cond, gpointer data); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
52 |
static GSList *get_all_local_ips(); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
53 |
static void jingle_socks5_init(void); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
54 |
static void jingle_socks5_uninit(void); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
55 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
56 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
57 |
const gchar *deps[] = { "jingle", NULL }; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
58 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
59 |
static JingleTransportFuncs funcs = { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
60 |
.check = check, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
61 |
.tomessage = tomessage, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
62 |
.new = NULL, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
63 |
.send = NULL, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
64 |
.init = init, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
65 |
.end = end |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
66 |
}; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
67 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
68 |
module_info_t info_jingle_s5b = { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
69 |
.branch = MCABBER_BRANCH, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
70 |
.api = MCABBER_API_VERSION, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
71 |
.version = PROJECT_VERSION, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
72 |
.description = "Jingle SOCKS5 Bytestream (XEP-0260)\n", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
73 |
.requires = deps, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
74 |
.init = jingle_socks5_init, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
75 |
.uninit = jingle_socks5_uninit, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
76 |
.next = NULL, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
77 |
}; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
78 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
79 |
static const gchar *jingle_s5b_types[] = { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
80 |
"assisted", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
81 |
"direct", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
82 |
"proxy", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
83 |
"tunnel", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
84 |
NULL |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
85 |
}; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
86 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
87 |
static const gchar *jingle_s5b_modes[] = { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
88 |
"tcp", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
89 |
"udp", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
90 |
NULL |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
91 |
}; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
92 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
93 |
/** |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
94 |
* @brief Linked list of candidates to send on session-initiate |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
95 |
*/ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
96 |
GSList *local_candidates = NULL; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
97 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
98 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
99 |
static gint index_in_array(const gchar *str, const gchar **array) |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
100 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
101 |
gint i; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
102 |
for (i = 0; array[i]; i++) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
103 |
if (!g_strcmp0(array[i], str)) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
104 |
return i; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
105 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
106 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
107 |
return -1; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
108 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
109 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
110 |
static gint prioritycmp(gconstpointer a, gconstpointer b) |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
111 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
112 |
S5BCandidate *s1 = (S5BCandidate *)a, *s2 = (S5BCandidate *)b; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
113 |
if (s1->priority < s2->priority) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
114 |
return 1; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
115 |
} else if (s1->priority > s2->priority) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
116 |
return -1; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
117 |
} else { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
118 |
return 0; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
119 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
120 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
121 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
122 |
static gconstpointer check(JingleContent *cn, GError **err) |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
123 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
124 |
JingleS5B *js5b; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
125 |
LmMessageNode *node = cn->transport, *node2; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
126 |
const gchar *modestr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
127 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
128 |
js5b = g_new0(JingleS5B, 1); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
129 |
modestr = lm_message_node_get_attribute(node, "mode"); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
130 |
js5b->mode = index_in_array(modestr, jingle_s5b_modes); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
131 |
js5b->sid = g_strdup(lm_message_node_get_attribute(node, "sid")); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
132 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
133 |
if (!js5b->sid) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
134 |
g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_MISSING, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
135 |
"an attribute of the transport element is missing"); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
136 |
g_free(js5b); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
137 |
return NULL; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
138 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
139 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
140 |
for (node2 = node->children; node2; node2 = node2->next) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
141 |
if (!g_strcmp0(node->name, "candidate")) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
142 |
const gchar *portstr, *prioritystr, *typestr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
143 |
S5BCandidate *jc = g_new0(S5BCandidate, 1); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
144 |
jc->cid = g_strdup(lm_message_node_get_attribute(node2, "cid")); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
145 |
jc->host = g_strdup(lm_message_node_get_attribute(node2, "host")); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
146 |
jc->jid = g_strdup(lm_message_node_get_attribute(node2, "jid")); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
147 |
portstr = lm_message_node_get_attribute(node2, "port"); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
148 |
prioritystr = lm_message_node_get_attribute(node2, "priority"); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
149 |
typestr = lm_message_node_get_attribute(node2, "type"); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
150 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
151 |
if (!jc->cid || !jc->host || !jc->jid || !prioritystr) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
152 |
g_free(jc); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
153 |
continue; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
154 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
155 |
jc->port = g_ascii_strtoull(portstr, NULL, 10); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
156 |
jc->priority = g_ascii_strtoull(prioritystr, NULL, 10); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
157 |
jc->type = index_in_array(typestr, jingle_s5b_types); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
158 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
159 |
if (jc->type == -1) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
160 |
g_free(jc); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
161 |
continue; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
162 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
163 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
164 |
js5b->candidates = g_slist_prepend(js5b->candidates, jc); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
165 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
166 |
js5b->candidates = g_slist_sort(js5b->candidates, prioritycmp); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
167 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
168 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
169 |
return (gconstpointer) js5b; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
170 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
171 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
172 |
static void tomessage(gconstpointer data, LmMessageNode *node) |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
173 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
174 |
JingleS5B *js5 = (JingleS5B *)data; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
175 |
S5BCandidate *js5c; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
176 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
177 |
LmMessageNode *node2, *node3; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
178 |
gchar *port; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
179 |
gchar *priority; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
180 |
GSList *el; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
181 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
182 |
if (lm_message_node_get_child(node, "transport") != NULL) |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
183 |
return; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
184 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
185 |
node2 = lm_message_node_add_child(node, "transport", NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
186 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
187 |
lm_message_node_set_attributes(node2, "xmlns", NS_JINGLE_TRANSPORT_SOCKS5, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
188 |
"sid", js5->sid, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
189 |
"mode", jingle_s5b_modes[js5->mode], |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
190 |
NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
191 |
for (el = js5->candidates; el; el = el->next) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
192 |
js5c = (S5BCandidate*) el->data; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
193 |
node3 = lm_message_node_add_child(node2, "candidate", NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
194 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
195 |
port = g_strdup_printf("%" G_GUINT16_FORMAT, js5c->port); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
196 |
priority = g_strdup_printf("%" G_GUINT64_FORMAT, js5c->priority); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
197 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
198 |
lm_message_node_set_attributes(node3, "cid", js5c->cid, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
199 |
"host", js5c->host, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
200 |
"jid", js5c->jid, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
201 |
"port", port, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
202 |
"priority", priority, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
203 |
"type", jingle_s5b_types[js5c->type], |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
204 |
NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
205 |
g_free(port); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
206 |
g_free(priority); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
207 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
208 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
209 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
210 |
static void init(session_content *sc, gconstpointer data) |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
211 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
212 |
JingleS5B *js5 = (JingleS5B *)data; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
213 |
GInetAddress *addr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
214 |
GSocketAddress *saddr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
215 |
GSource *socksource; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
216 |
GError *err = NULL; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
217 |
g_assert(js5->sock == NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
218 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
219 |
addr = g_inet_address_new_from_string(((S5BCandidate *)js5->candidates->data)->host); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
220 |
js5->sock = g_socket_new(g_inet_address_get_family(addr), G_SOCKET_TYPE_STREAM, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
221 |
G_SOCKET_PROTOCOL_TCP, &err); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
222 |
if (js5->sock == NULL) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
223 |
scr_LogPrint(LPRINT_LOGNORM, "Jingle SOCKS5: Error while creating a new socket: %s", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
224 |
err->message != NULL ? err->message : "(no message)"); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
225 |
return; // TODO: we need a way to return errors... |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
226 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
227 |
g_socket_set_blocking(js5->sock, FALSE); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
228 |
socksource = g_socket_create_source(js5->sock, ~0, NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
229 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
230 |
g_source_set_callback(socksource, (GSourceFunc)handle_sock_io, NULL, NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
231 |
g_source_attach(socksource, NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
232 |
g_source_unref(socksource); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
233 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
234 |
saddr = g_inet_socket_address_new(addr, 31337); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
235 |
if (!g_socket_connect(js5->sock, saddr, NULL, &err)) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
236 |
scr_LogPrint(LPRINT_LOGNORM, "Jingle SOCKS5: Error while connecting to the host: %s", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
237 |
err->message != NULL ? err->message : "(no message)"); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
238 |
return; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
239 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
240 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
241 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
242 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
243 |
/** |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
244 |
* Handle any event on a sock |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
245 |
*/ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
246 |
static void handle_sock_io(GSocket *sock, GIOCondition cond, gpointer data) |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
247 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
248 |
switch (cond) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
249 |
case G_IO_IN: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
250 |
break; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
251 |
case G_IO_OUT: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
252 |
break; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
253 |
case G_IO_ERR: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
254 |
break; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
255 |
case G_IO_HUP: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
256 |
break; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
257 |
default: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
258 |
; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
259 |
// ?! |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
260 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
261 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
262 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
263 |
/** |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
264 |
* @brief Discover all IPs of this computer |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
265 |
* @return A linked list of GInetAddress |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
266 |
*/ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
267 |
static GSList *get_all_local_ips() { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
268 |
GSList *addresses = NULL; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
269 |
GInetAddress *thisaddr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
270 |
GSocketFamily family; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
271 |
struct ifaddrs *first, *ifaddr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
272 |
struct sockaddr_in *native; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
273 |
struct sockaddr_in6 *native6; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
274 |
const guint8 *addrdata; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
275 |
int rval; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
276 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
277 |
rval = getifaddrs(&first); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
278 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
279 |
for (ifaddr = first; ifaddr; ifaddr = ifaddr->ifa_next) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
280 |
if (!(ifaddr->ifa_flags & IFF_UP) || ifaddr->ifa_flags & IFF_LOOPBACK) |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
281 |
continue; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
282 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
283 |
if (ifaddr->ifa_addr->sa_family == AF_INET) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
284 |
native = (struct sockaddr_in *)ifaddr->ifa_addr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
285 |
addrdata = (const guint8 *)&native->sin_addr.s_addr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
286 |
family = G_SOCKET_FAMILY_IPV4; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
287 |
} else if (ifaddr->ifa_addr->sa_family == AF_INET6) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
288 |
native6 = (struct sockaddr_in6 *)ifaddr->ifa_addr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
289 |
addrdata = (const guint8 *)&native6->sin6_addr.s6_addr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
290 |
family = G_SOCKET_FAMILY_IPV6; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
291 |
} else |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
292 |
continue; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
293 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
294 |
thisaddr = g_inet_address_new_from_bytes(addrdata, family); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
295 |
if (g_inet_address_get_is_link_local(thisaddr)) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
296 |
g_object_unref(thisaddr); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
297 |
continue; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
298 |
}/* else if (g_inset_address_get_is_site_local(thisaddr)) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
299 |
// TODO: should we offer a way the offer of LAN ips ? |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
300 |
} */ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
301 |
addresses = g_slist_prepend(addresses, thisaddr); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
302 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
303 |
return addresses; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
304 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
305 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
306 |
static void jingle_socks5_init(void) |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
307 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
308 |
g_type_init(); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
309 |
jingle_register_transport(NS_JINGLE_TRANSPORT_SOCKS5, &funcs, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
310 |
JINGLE_TRANSPORT_STREAMING, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
311 |
JINGLE_TRANSPORT_PRIO_HIGH); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
312 |
xmpp_add_feature(NS_JINGLE_TRANSPORT_SOCKS5); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
313 |
local_candidates = get_all_local_ips(); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
314 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
315 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
316 |
static void jingle_socks5_uninit(void) |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
317 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
318 |
xmpp_del_feature(NS_JINGLE_TRANSPORT_SOCKS5); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
319 |
jingle_unregister_transport(NS_JINGLE_TRANSPORT_SOCKS5); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
320 |
g_slist_foreach(local_candidates, (GFunc)g_object_unref, NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
321 |
} |