author | Nicolas Cornu <nicolas.cornu@ensi-bourges.fr> |
Wed, 01 Sep 2010 01:19:40 +0200 | |
changeset 165 | 763c26abd99d |
parent 164 | 6866328b34bd |
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> |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
36 |
#include <mcabber/settings.h> |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
37 |
#include <mcabber/logprint.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
38 |
#include <mcabber/hooks.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
39 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
40 |
#include <jingle/jingle.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
41 |
#include <jingle/check.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
42 |
#include <jingle/register.h> |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
43 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
44 |
#include "socks5.h" |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
45 |
|
156
653fa009fea3
Rename ->check() to newfrommessage and call it only on session-initiate.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
154
diff
changeset
|
46 |
static gconstpointer newfrommessage(JingleContent *cn, GError **err); |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
47 |
static JingleHandleStatus handle(JingleAction action, gconstpointer data, |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
48 |
LmMessageNode *node, GError **err); |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
49 |
static void tomessage(gconstpointer data, LmMessageNode *node); |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
50 |
static gconstpointer new(void); |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
51 |
static void _send(session_content *sc, gconstpointer data, gchar *buf, gsize size); |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
52 |
static void init(session_content *sc, gconstpointer data); |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
53 |
static void end(session_content *sc, gconstpointer data); |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
54 |
static gchar *info(gconstpointer data); |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
55 |
|
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
56 |
static void connect_candidate(JingleS5B *js5b, S5BCandidate *cand); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
57 |
static void connect_next_candidate(JingleS5B *js5b, S5BCandidate *cand); |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
58 |
static void |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
59 |
handle_listener_accept(GObject *_listener, GAsyncResult *res, gpointer data); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
60 |
static void |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
61 |
handle_client_connect(GObject *_client, GAsyncResult *res, gpointer data); |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
62 |
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
|
63 |
static GSList *get_all_local_ips(); |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
64 |
static gchar *gen_random_sid(void); |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
65 |
static gchar *gen_random_cid(void); |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
69 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
70 |
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
|
71 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
72 |
static JingleTransportFuncs funcs = { |
156
653fa009fea3
Rename ->check() to newfrommessage and call it only on session-initiate.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
154
diff
changeset
|
73 |
.newfrommessage = newfrommessage, |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
74 |
.handle = handle, |
156
653fa009fea3
Rename ->check() to newfrommessage and call it only on session-initiate.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
154
diff
changeset
|
75 |
.tomessage = tomessage, |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
76 |
.new = new, |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
77 |
.send = _send, |
156
653fa009fea3
Rename ->check() to newfrommessage and call it only on session-initiate.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
154
diff
changeset
|
78 |
.init = init, |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
79 |
.end = end, |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
80 |
.info = info |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
81 |
}; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
82 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
83 |
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
|
84 |
.branch = MCABBER_BRANCH, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
85 |
.api = MCABBER_API_VERSION, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
86 |
.version = PROJECT_VERSION, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
87 |
.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
|
88 |
.requires = deps, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
89 |
.init = jingle_socks5_init, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
90 |
.uninit = jingle_socks5_uninit, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
91 |
.next = NULL, |
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 |
static const gchar *jingle_s5b_types[] = { |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
95 |
"direct", |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
96 |
"assisted", |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
97 |
"tunnel", |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
98 |
"proxy", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
99 |
NULL |
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 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
102 |
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
|
103 |
"tcp", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
104 |
"udp", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
105 |
NULL |
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 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
108 |
typedef struct { |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
109 |
GInetAddress *address; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
110 |
guint32 priority; |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
111 |
JingleS5BType type; |
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
112 |
} LocalIP; |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
113 |
|
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
114 |
/** |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
115 |
* @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
|
116 |
*/ |
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
117 |
static GSList *local_ips = NULL; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
118 |
|
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 |
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
|
121 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
122 |
gint i; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
123 |
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
|
124 |
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
|
125 |
return i; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
126 |
} |
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 |
return -1; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
129 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
130 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
131 |
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
|
132 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
133 |
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
|
134 |
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
|
135 |
return 1; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
136 |
} 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
|
137 |
return -1; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
138 |
} else { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
139 |
return 0; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
140 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
141 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
142 |
|
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
143 |
/** |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
144 |
* @brief Parse a list of <candidate> elements |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
145 |
* @return a list of S5BCandidate |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
146 |
*/ |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
147 |
static GSList *parse_candidates(LmMessageNode *node) |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
148 |
{ |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
149 |
LmMessageNode *node2; |
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
150 |
GSList *list = NULL; |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
151 |
|
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
152 |
for (node2 = node->children; node2; node2 = node2->next) { |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
153 |
if (g_strcmp0(node->name, "candidate")) |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
154 |
continue; |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
155 |
const gchar *hoststr, *portstr, *prioritystr, *typestr; |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
156 |
S5BCandidate *cand = g_new0(S5BCandidate, 1); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
157 |
cand->cid = g_strdup(lm_message_node_get_attribute(node2, "cid")); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
158 |
cand->jid = g_strdup(lm_message_node_get_attribute(node2, "jid")); |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
159 |
hoststr = lm_message_node_get_attribute(node2, "host"); |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
160 |
portstr = lm_message_node_get_attribute(node2, "port"); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
161 |
prioritystr = lm_message_node_get_attribute(node2, "priority"); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
162 |
typestr = lm_message_node_get_attribute(node2, "type"); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
163 |
|
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
164 |
if (!cand->cid || !hoststr || !cand->jid || !prioritystr) { |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
165 |
g_free(cand); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
166 |
continue; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
167 |
} |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
168 |
cand->host = g_inet_address_new_from_string(hoststr); |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
169 |
cand->port = g_ascii_strtoull(portstr, NULL, 10); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
170 |
cand->priority = g_ascii_strtoull(prioritystr, NULL, 10); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
171 |
cand->type = index_in_array(typestr, jingle_s5b_types); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
172 |
|
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
173 |
if (cand->type == -1 || cand->host == NULL) { |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
174 |
g_free(cand); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
175 |
continue; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
176 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
177 |
|
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
178 |
list = g_slist_prepend(list, cand); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
179 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
180 |
list = g_slist_sort(list, prioritycmp); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
181 |
return list; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
182 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
183 |
|
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
184 |
static GSList *get_our_candidates(guint16 port) |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
185 |
{ |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
186 |
GSList *our_candidates = NULL, *entry; |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
187 |
|
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
188 |
for (entry = local_ips; entry; entry = entry->next) { |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
189 |
LocalIP *lcand = (LocalIP *)entry->data; |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
190 |
S5BCandidate *cand = g_new0(S5BCandidate, 1); |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
191 |
cand->cid = gen_random_cid(); |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
192 |
cand->host = g_object_ref(lcand->address); |
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
193 |
cand->jid = g_strdup(lm_connection_get_jid(lconnection)); |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
194 |
cand->port = port; |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
195 |
cand->priority = lcand->priority; |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
196 |
|
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
197 |
our_candidates = g_slist_prepend(our_candidates, cand); |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
198 |
} |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
199 |
our_candidates = g_slist_sort(our_candidates, prioritycmp); |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
200 |
return our_candidates; |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
201 |
} |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
202 |
|
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
203 |
/** |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
204 |
* @brief Get a port number by settings or randomly |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
205 |
* @return A guint16 containing the port number |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
206 |
* */ |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
207 |
static guint16 get_port(void) |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
208 |
{ |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
209 |
// TODO: find a way to make sure the port is not already used |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
210 |
guint64 portstart, portend; |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
211 |
guint16 port; |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
212 |
const gchar *port_range = settings_opt_get("js5b_portrange"); |
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
213 |
|
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
214 |
if (port_range != NULL) { |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
215 |
sscanf(port_range, "%" G_GUINT64_FORMAT "-%" G_GUINT64_FORMAT, &portstart, &portend); |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
216 |
|
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
217 |
if ((portstart >= 1024 && portstart <= (guint16)~0) && |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
218 |
(portend >= 1024 && portend <= (guint16)~0) && portstart <= portend) { |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
219 |
port = g_random_int_range(portstart, portend); |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
220 |
} else { |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
221 |
scr_LogPrint(LPRINT_LOGNORM, "Jingle S5B: Invalid port range specified"); |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
222 |
port = g_random_int_range(1024, (guint16)~0); |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
223 |
} |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
224 |
} else { |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
225 |
port = g_random_int_range(1024, (guint16)~0); |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
226 |
} |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
227 |
|
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
228 |
return port; |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
229 |
} |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
230 |
|
156
653fa009fea3
Rename ->check() to newfrommessage and call it only on session-initiate.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
154
diff
changeset
|
231 |
static gconstpointer newfrommessage(JingleContent *cn, GError **err) |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
232 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
233 |
JingleS5B *js5b; |
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
234 |
LmMessageNode *node = cn->transport; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
235 |
const gchar *modestr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
236 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
237 |
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
|
238 |
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
|
239 |
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
|
240 |
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
|
241 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
242 |
if (!js5b->sid) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
243 |
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
|
244 |
"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
|
245 |
g_free(js5b); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
246 |
return NULL; |
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 |
|
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
249 |
js5b->candidates = parse_candidates(node); |
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
250 |
js5b->ourcandidates = get_our_candidates(get_port()); |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
251 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
252 |
return (gconstpointer) js5b; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
253 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
254 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
255 |
static gconstpointer new(void) |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
256 |
{ |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
257 |
JingleS5B *js5b = g_new0(JingleS5B, 1); |
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
258 |
|
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
259 |
js5b->mode = JINGLE_S5B_TCP; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
260 |
js5b->sid = gen_random_sid(); |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
261 |
|
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
262 |
js5b->ourcandidates = get_our_candidates(get_port()); |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
263 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
264 |
return js5b; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
265 |
} |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
266 |
|
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
267 |
static JingleHandleStatus handle(JingleAction action, gconstpointer data, |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
268 |
LmMessageNode *node, GError **err) |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
269 |
{ |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
270 |
JingleS5B *js5b = (JingleS5B *)data; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
271 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
272 |
if (action == JINGLE_SESSION_ACCEPT) { |
165
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
273 |
js5b->candidates = parse_candidates(node); |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
274 |
return JINGLE_STATUS_HANDLED; |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
275 |
} else if (action == JINGLE_TRANSPORT_INFO) { |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
276 |
LmMessageNode *errorn, *usedn; |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
277 |
if (g_strcmp0(lm_message_node_get_attribute(node, "sid"), js5b->sid)) |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
278 |
return JINGLE_STATUS_HANDLED; // huh.. not the same socks5 sid ? |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
279 |
|
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
280 |
errorn = lm_message_node_get_child(node, "candidate-error"); |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
281 |
usedn = lm_message_node_get_child(node, "candidate-used"); |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
282 |
if (errorn != FALSE) { |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
283 |
//got_candidate_error |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
284 |
} else if (usedn != FALSE) { |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
285 |
//got_candidate_used |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
286 |
} |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
287 |
return JINGLE_STATUS_HANDLED; |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
288 |
} |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
289 |
return JINGLE_STATUS_NOT_HANDLED; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
290 |
} |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
291 |
|
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
292 |
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
|
293 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
294 |
JingleS5B *js5 = (JingleS5B *)data; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
295 |
S5BCandidate *js5c; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
296 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
297 |
LmMessageNode *node2, *node3; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
298 |
gchar *port; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
299 |
gchar *priority; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
300 |
GSList *el; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
301 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
302 |
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
|
303 |
return; |
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 |
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
|
306 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
307 |
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
|
308 |
"sid", js5->sid, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
309 |
"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
|
310 |
NULL); |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
311 |
for (el = js5->ourcandidates; el; el = el->next) { |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
312 |
js5c = (S5BCandidate*) el->data; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
313 |
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
|
314 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
315 |
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
|
316 |
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
|
317 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
318 |
lm_message_node_set_attributes(node3, "cid", js5c->cid, |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
319 |
"host", g_inet_address_to_string(js5c->host), |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
320 |
"jid", js5c->jid, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
321 |
"port", port, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
322 |
"priority", priority, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
323 |
"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
|
324 |
NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
325 |
g_free(port); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
326 |
g_free(priority); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
327 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
328 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
329 |
|
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
330 |
static void init(session_content *sc, gconstpointer data) |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
331 |
{ |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
332 |
JingleS5B *js5b = (JingleS5B *)data; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
333 |
GSocketAddress *saddr; |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
334 |
guint numlistening = 0; // number of addresses we are listening to |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
335 |
GSList *entry; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
336 |
GError *err = NULL; |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
337 |
GSocket *sock; |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
338 |
|
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
339 |
// First, we listen on all ips |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
340 |
js5b->listener = g_socket_listener_new(); |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
341 |
for (entry = js5b->ourcandidates; entry; entry = entry->next) { |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
342 |
S5BCandidate *cand = (S5BCandidate *)entry->data; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
343 |
|
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
344 |
sock = g_socket_new(g_inet_address_get_family(cand->host), |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
345 |
G_SOCKET_TYPE_STREAM, |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
346 |
G_SOCKET_PROTOCOL_TCP, &err); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
347 |
if (sock == NULL) { |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
348 |
scr_LogPrint(LPRINT_LOGNORM, "Jingle S5B: Error while creating a new socket: %s", |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
349 |
err->message ? err->message : "(no message)"); |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
350 |
continue; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
351 |
} |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
352 |
g_socket_set_blocking(sock, FALSE); |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
353 |
|
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
354 |
saddr = g_inet_socket_address_new(cand->host, cand->port); |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
355 |
if (!g_socket_bind(sock, saddr, TRUE, &err)) { |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
356 |
scr_LogPrint(LPRINT_LOGNORM, "Jingle S5B: Unable to bind a socket on %s port %u: %s", |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
357 |
g_inet_address_to_string(cand->host), |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
358 |
cand->port, |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
359 |
err->message ? err->message : "(no message)"); |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
360 |
goto cleancontinue; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
361 |
} |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
362 |
|
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
363 |
if (!g_socket_listen(sock, &err)) { |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
364 |
scr_LogPrint(LPRINT_LOGNORM, "Jingle S5B: Unable to listen on %s port %u: %s", |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
365 |
g_inet_address_to_string(cand->host), |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
366 |
cand->port, |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
367 |
err->message ? err->message : "(no message)"); |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
368 |
goto cleancontinue; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
369 |
} |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
370 |
|
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
371 |
if (!g_socket_listener_add_socket(js5b->listener, sock, NULL, &err)) { |
162
6afab419ff88
Fix out of source build. Set build profiles options.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
161
diff
changeset
|
372 |
scr_LogPrint(LPRINT_LOGNORM, "Jingle S5B: Unable to add our socket to the" |
6afab419ff88
Fix out of source build. Set build profiles options.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
161
diff
changeset
|
373 |
" GSocketListener: %s", |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
374 |
err->message ? err->message : "(no message)"); |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
375 |
goto cleancontinue; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
376 |
} |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
377 |
|
162
6afab419ff88
Fix out of source build. Set build profiles options.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
161
diff
changeset
|
378 |
scr_LogPrint(LPRINT_LOGNORM, "Jingle S5B: Listening on %s:%u", |
6afab419ff88
Fix out of source build. Set build profiles options.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
161
diff
changeset
|
379 |
g_inet_address_to_string(cand->host), |
6afab419ff88
Fix out of source build. Set build profiles options.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
161
diff
changeset
|
380 |
cand->port); |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
381 |
++numlistening; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
382 |
|
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
383 |
cleancontinue: |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
384 |
if (err != NULL) g_clear_error(&err); |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
385 |
g_object_unref(saddr); |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
386 |
g_object_unref(sock); |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
387 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
388 |
|
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
389 |
if (numlistening > 0) { |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
390 |
g_socket_listener_accept_async(js5b->listener, NULL, handle_listener_accept, NULL); |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
391 |
} else { |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
392 |
g_object_unref(js5b->listener); |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
393 |
} |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
394 |
|
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
395 |
// Then, we start connecting to the other entity's candidates, if any. |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
396 |
if (js5b->candidates) { |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
397 |
js5b->client = g_socket_client_new(); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
398 |
S5BCandidate *cand = (S5BCandidate *)js5b->candidates->data; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
399 |
connect_candidate(js5b, cand); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
400 |
} |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
401 |
} |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
402 |
|
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
403 |
/** |
165
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
404 |
* @brief Called when a connection was established |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
405 |
* |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
406 |
* This function free/unref everything created by init like |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
407 |
* the GSocketListener and GClientSocket objects. |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
408 |
*/ |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
409 |
static void free_after_connection(JingleS5B *js5b) |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
410 |
{ |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
411 |
g_socket_listener_close(js5b->listener); |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
412 |
g_object_unref(js5b->listener); |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
413 |
g_object_unref(js5b->client); |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
414 |
} |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
415 |
|
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
416 |
/** |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
417 |
* @brief Cancel an ongoing connection after 5 seconds |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
418 |
* @param data A GPtrArray |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
419 |
* |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
420 |
* "A client SHOULD NOT wait for a TCP timeout on connect. |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
421 |
* If it is unable to connect to any candidate within 5 seconds |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
422 |
* it SHOULD send a candidate-error to the other party." |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
423 |
*/ |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
424 |
static gboolean connect_cancel_timeout(gpointer data) |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
425 |
{ |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
426 |
GPtrArray *args = (GPtrArray *)data; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
427 |
JingleS5B *js5b = g_ptr_array_index(args, 0); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
428 |
//S5BCandidate *cand = g_ptr_array_index(args, 1); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
429 |
g_ptr_array_unref(args); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
430 |
|
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
431 |
g_cancellable_cancel(js5b->cancelconnect); |
165
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
432 |
// we need to send a candidate-error in case we cannot connect. |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
433 |
return FALSE; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
434 |
} |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
435 |
|
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
436 |
static void connect_candidate(JingleS5B *js5b, S5BCandidate *cand) |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
437 |
{ |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
438 |
GSocketAddress *saddr; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
439 |
GPtrArray *args; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
440 |
guint eventid; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
441 |
|
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
442 |
args = g_ptr_array_sized_new(2); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
443 |
g_ptr_array_add(args, js5b); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
444 |
g_ptr_array_add(args, cand); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
445 |
|
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
446 |
saddr = g_inet_socket_address_new(cand->host, cand->port); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
447 |
js5b->cancelconnect = g_cancellable_new(); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
448 |
|
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
449 |
eventid = g_timeout_add_seconds(5, connect_cancel_timeout, g_ptr_array_ref(args)); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
450 |
g_ptr_array_add(args, GUINT_TO_POINTER(eventid)); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
451 |
g_socket_client_connect_async(js5b->client, G_SOCKET_CONNECTABLE(saddr), |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
452 |
js5b->cancelconnect, handle_client_connect, args); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
453 |
g_object_unref(saddr); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
454 |
} |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
455 |
|
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
456 |
/** |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
457 |
* Convenience function that find the next candidate to try and |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
458 |
* call connect_candidate |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
459 |
*/ |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
460 |
static void connect_next_candidate(JingleS5B *js5b, S5BCandidate *cand) |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
461 |
{ |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
462 |
GSList *link = g_slist_find(js5b->candidates, cand); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
463 |
if (js5b->cancelconnect != NULL) |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
464 |
g_object_unref(js5b->cancelconnect); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
465 |
g_assert(link != NULL); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
466 |
if (link->next == NULL) { |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
467 |
// there is no next candidate to try. |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
468 |
} |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
469 |
connect_candidate(js5b, (S5BCandidate *)link->next->data); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
470 |
return; |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
471 |
} |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
472 |
|
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
473 |
static gchar *info(gconstpointer data) |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
474 |
{ |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
475 |
//JingleS5B *js5b = (JingleS5B *)data; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
476 |
gchar *info = g_strdup_printf("S5B"); |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
477 |
return info; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
478 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
479 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
480 |
static void end(session_content *sc, gconstpointer data) { |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
481 |
return; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
482 |
} |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
483 |
|
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
484 |
/** |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
485 |
* @brief Handle incoming connections |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
486 |
*/ |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
487 |
static void |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
488 |
handle_listener_accept(GObject *_listener, GAsyncResult *res, gpointer data) |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
489 |
{ |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
490 |
GError *err = NULL; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
491 |
GSocketConnection *conn; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
492 |
//scr_LogPrint(LPRINT_LOGNORM, "Jingle S5B: Got Incoming Connection"); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
493 |
conn = g_socket_listener_accept_finish(G_SOCKET_LISTENER(_listener), res, NULL, &err); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
494 |
} |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
495 |
|
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
496 |
/** |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
497 |
* @brief Handle outgoing connections |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
498 |
*/ |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
499 |
static void |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
500 |
handle_client_connect(GObject *_client, GAsyncResult *res, gpointer data) |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
501 |
{ |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
502 |
GError *err = NULL; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
503 |
GSocketConnection *conn; |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
504 |
GPtrArray *args; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
505 |
JingleS5B *js5b; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
506 |
S5BCandidate *cand; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
507 |
//scr_LogPrint(LPRINT_LOGNORM, "Jingle S5B: Got Outgoing Connection"); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
508 |
|
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
509 |
args = (GPtrArray *)data; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
510 |
js5b = g_ptr_array_index(args, 0); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
511 |
cand = g_ptr_array_index(args, 1); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
512 |
g_ptr_array_unref(args); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
513 |
|
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
514 |
conn = g_socket_client_connect_finish(G_SOCKET_CLIENT(_client), res, &err); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
515 |
|
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
516 |
if (!g_error_matches(err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
517 |
// if we did not received a CANCELLED error, then the time limit was not |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
518 |
// reached and we need to clean up the GSource and unref args a second time. |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
519 |
guint eventid = GPOINTER_TO_UINT(g_ptr_array_index(args, 2)); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
520 |
GSource *s = g_main_context_find_source_by_id(NULL, eventid); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
521 |
g_source_destroy(s); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
522 |
g_ptr_array_unref(args); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
523 |
connect_next_candidate(js5b, cand); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
524 |
return; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
525 |
} |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
526 |
|
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
527 |
if (err != NULL) { |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
528 |
if (err->domain == G_IO_ERROR) |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
529 |
scr_LogPrint(LPRINT_DEBUG, "Jingle S5B: IO Error (%s)", |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
530 |
err->message ? err->message : "no message"); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
531 |
else |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
532 |
scr_LogPrint(LPRINT_DEBUG, "Jingle S5B: %s Error (%s)", |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
533 |
g_quark_to_string (err->domain), |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
534 |
err->message ? err->message : "no message"); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
535 |
|
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
536 |
g_error_free(err); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
537 |
connect_next_candidate(js5b, cand); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
538 |
return; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
539 |
} |
165
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
540 |
js5b->connection = conn; // we have a valid connection |
763c26abd99d
Handle incoming transport-info messages
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
164
diff
changeset
|
541 |
// TODO: send transport-info activated IQ |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
542 |
} |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
543 |
|
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
544 |
/** |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
545 |
* @brief Handle any event on a sock |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
546 |
*/ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
547 |
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
|
548 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
549 |
switch (cond) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
550 |
case G_IO_IN: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
551 |
break; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
552 |
case G_IO_OUT: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
553 |
break; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
554 |
case G_IO_ERR: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
555 |
break; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
556 |
case G_IO_HUP: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
557 |
break; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
558 |
default: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
559 |
; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
560 |
// ?! |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
561 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
562 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
563 |
|
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
564 |
static void _send(session_content *sc, gconstpointer data, gchar *buf, gsize size) |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
565 |
{ |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
566 |
return; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
567 |
} |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
568 |
|
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
569 |
/** |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
570 |
* @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
|
571 |
* @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
|
572 |
*/ |
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
573 |
static GSList *get_all_local_ips(void) { |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
574 |
GSList *addresses = NULL; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
575 |
GInetAddress *thisaddr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
576 |
GSocketFamily family; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
577 |
struct ifaddrs *first, *ifaddr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
578 |
struct sockaddr_in *native; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
579 |
struct sockaddr_in6 *native6; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
580 |
const guint8 *addrdata; |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
581 |
guint16 ifacecounter = 0; // for lack of a better method |
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
582 |
LocalIP *candidate; |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
583 |
gchar **ifblacklist; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
584 |
guint ifblkcnt; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
585 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
586 |
gint rval = getifaddrs(&first); |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
587 |
if (rval != 0) { |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
588 |
scr_LogPrint(LPRINT_LOGNORM, "Jingle S5B: Unable to retreive local ip addresses"); |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
589 |
return NULL; |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
590 |
} |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
591 |
|
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
592 |
if (settings_opt_get("js5b_iface_blacklist") != NULL) { |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
593 |
ifblacklist = g_strsplit(settings_opt_get("js5b_iface_blacklist"), ",", 0); |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
594 |
} else { |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
595 |
ifblacklist = (gchar*[]){NULL}; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
596 |
} |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
597 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
598 |
for (ifaddr = first; ifaddr; ifaddr = ifaddr->ifa_next) { |
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
599 |
gboolean continueloop = FALSE; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
600 |
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
|
601 |
continue; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
602 |
|
164
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
603 |
for (ifblkcnt = 0; ifblacklist[ifblkcnt]; ifblkcnt++) |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
604 |
if (!g_strcmp0(ifaddr->ifa_name, ifblacklist[ifblkcnt])) { |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
605 |
continueloop = TRUE; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
606 |
break; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
607 |
} |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
608 |
|
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
609 |
if (continueloop) continue; |
6866328b34bd
S5B: Add functions to connect to a candidate
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
163
diff
changeset
|
610 |
|
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
611 |
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
|
612 |
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
|
613 |
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
|
614 |
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
|
615 |
} 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
|
616 |
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
|
617 |
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
|
618 |
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
|
619 |
} else |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
620 |
continue; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
621 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
622 |
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
|
623 |
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
|
624 |
g_object_unref(thisaddr); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
625 |
continue; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
626 |
}/* else if (g_inset_address_get_is_site_local(thisaddr)) { |
156
653fa009fea3
Rename ->check() to newfrommessage and call it only on session-initiate.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
154
diff
changeset
|
627 |
// TODO: should we offer a way to filter the offer of LAN ips ? |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
628 |
} */ |
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
629 |
candidate = g_new0(LocalIP, 1); |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
630 |
candidate->address = thisaddr; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
631 |
candidate->priority = (1<<16)*126+ifacecounter; |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
632 |
candidate->type = JINGLE_S5B_DIRECT; |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
633 |
addresses = g_slist_prepend(addresses, candidate); |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
634 |
++ifacecounter; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
635 |
} |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
636 |
freeifaddrs(first); |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
637 |
|
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
638 |
return addresses; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
639 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
640 |
|
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
641 |
static gchar *random_str(guint len) |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
642 |
{ |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
643 |
gchar *str; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
644 |
gchar car[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
645 |
gint i; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
646 |
str = g_new0(gchar, 8); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
647 |
for (i = 0; i < len; i++) |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
648 |
str[i] = car[g_random_int_range(0, sizeof(car)/sizeof(car[0])-1)]; |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
649 |
|
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
650 |
str[len] = '\0'; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
651 |
return str; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
652 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
653 |
|
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
654 |
static gchar *gen_random_sid(void) |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
655 |
{ |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
656 |
return random_str(7); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
657 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
658 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
659 |
static gchar *gen_random_cid(void) |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
660 |
{ |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
661 |
return random_str(7); |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
662 |
} |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
663 |
|
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
664 |
static void free_localip(LocalIP *l) { |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
665 |
g_object_unref(l->address); |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
666 |
g_free(l); |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
667 |
} |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
668 |
|
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
669 |
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
|
670 |
{ |
163
a4c75fe75869
Fix the segfault when unloading the S5B module, by loading gio manually
Gu1 <gu1@aeroxteam.fr>
parents:
162
diff
changeset
|
671 |
// ugly hack to fix the segfault when quitting: |
a4c75fe75869
Fix the segfault when unloading the S5B module, by loading gio manually
Gu1 <gu1@aeroxteam.fr>
parents:
162
diff
changeset
|
672 |
// mcabber doesn't load gthread or gobject but they are required by gio, |
a4c75fe75869
Fix the segfault when unloading the S5B module, by loading gio manually
Gu1 <gu1@aeroxteam.fr>
parents:
162
diff
changeset
|
673 |
// and cannot be unloaded once they are loaded or a segfault occur. |
a4c75fe75869
Fix the segfault when unloading the S5B module, by loading gio manually
Gu1 <gu1@aeroxteam.fr>
parents:
162
diff
changeset
|
674 |
// We dlopen gio with global | nodelete flags. This will also load gobject |
a4c75fe75869
Fix the segfault when unloading the S5B module, by loading gio manually
Gu1 <gu1@aeroxteam.fr>
parents:
162
diff
changeset
|
675 |
// and gthread as dependencies. g_type_init will init gobject/gthread (and |
a4c75fe75869
Fix the segfault when unloading the S5B module, by loading gio manually
Gu1 <gu1@aeroxteam.fr>
parents:
162
diff
changeset
|
676 |
// set threads_got_initialized to true). |
a4c75fe75869
Fix the segfault when unloading the S5B module, by loading gio manually
Gu1 <gu1@aeroxteam.fr>
parents:
162
diff
changeset
|
677 |
if (g_threads_got_initialized == FALSE) { |
a4c75fe75869
Fix the segfault when unloading the S5B module, by loading gio manually
Gu1 <gu1@aeroxteam.fr>
parents:
162
diff
changeset
|
678 |
void *dlopen(const char *filename, int flag); |
a4c75fe75869
Fix the segfault when unloading the S5B module, by loading gio manually
Gu1 <gu1@aeroxteam.fr>
parents:
162
diff
changeset
|
679 |
// RTLD_LAZY | RTLD_GLOBAL | RTLD_NODELETE |
a4c75fe75869
Fix the segfault when unloading the S5B module, by loading gio manually
Gu1 <gu1@aeroxteam.fr>
parents:
162
diff
changeset
|
680 |
dlopen("libgio-2.0.so", 0x00001 | 0x00100 | 0x01000); |
a4c75fe75869
Fix the segfault when unloading the S5B module, by loading gio manually
Gu1 <gu1@aeroxteam.fr>
parents:
162
diff
changeset
|
681 |
g_type_init(); |
a4c75fe75869
Fix the segfault when unloading the S5B module, by loading gio manually
Gu1 <gu1@aeroxteam.fr>
parents:
162
diff
changeset
|
682 |
} |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
683 |
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
|
684 |
JINGLE_TRANSPORT_STREAMING, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
685 |
JINGLE_TRANSPORT_PRIO_HIGH); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
686 |
xmpp_add_feature(NS_JINGLE_TRANSPORT_SOCKS5); |
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
687 |
local_ips = get_all_local_ips(); |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
688 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
689 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
690 |
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
|
691 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
692 |
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
|
693 |
jingle_unregister_transport(NS_JINGLE_TRANSPORT_SOCKS5); |
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
694 |
g_slist_foreach(local_ips, (GFunc)free_localip, NULL); |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
695 |
g_slist_free(local_ips); |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
696 |
} |