author | Gu1 <gu1@aeroxteam.fr> |
Fri, 27 Aug 2010 11:19:32 +0200 | |
changeset 163 | a4c75fe75869 |
parent 162 | 6afab419ff88 |
child 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); |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
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 |
|
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
56 |
static void |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
57 |
handle_listener_accept(GObject *_listener, GAsyncResult *res, gpointer userdata); |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
58 |
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
|
59 |
static GSList *get_all_local_ips(); |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
65 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
66 |
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
|
67 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
68 |
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
|
69 |
.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
|
70 |
.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
|
71 |
.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
|
72 |
.new = new, |
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 |
.send = NULL, |
653fa009fea3
Rename ->check() to newfrommessage and call it only on session-initiate.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
154
diff
changeset
|
74 |
.init = init, |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
75 |
.end = end, |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
76 |
.info = info |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
77 |
}; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
78 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
79 |
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
|
80 |
.branch = MCABBER_BRANCH, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
81 |
.api = MCABBER_API_VERSION, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
82 |
.version = PROJECT_VERSION, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
83 |
.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
|
84 |
.requires = deps, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
85 |
.init = jingle_socks5_init, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
86 |
.uninit = jingle_socks5_uninit, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
87 |
.next = NULL, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
88 |
}; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
89 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
90 |
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
|
91 |
"direct", |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
92 |
"assisted", |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
93 |
"tunnel", |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
94 |
"proxy", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
95 |
NULL |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
96 |
}; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
97 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
98 |
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
|
99 |
"tcp", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
100 |
"udp", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
101 |
NULL |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
102 |
}; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
103 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
104 |
typedef struct { |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
105 |
GInetAddress *address; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
106 |
guint32 priority; |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
107 |
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
|
108 |
} LocalIP; |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
109 |
|
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
110 |
/** |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
111 |
* @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
|
112 |
*/ |
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
113 |
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
|
114 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
115 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
116 |
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
|
117 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
118 |
gint i; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
119 |
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
|
120 |
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
|
121 |
return i; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
122 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
123 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
124 |
return -1; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
125 |
} |
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 |
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
|
128 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
129 |
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
|
130 |
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
|
131 |
return 1; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
132 |
} 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
|
133 |
return -1; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
134 |
} else { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
135 |
return 0; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
136 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
137 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
138 |
|
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
139 |
/** |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
140 |
* @brief Parse a list of <candidate> elements |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
141 |
* @return a list of S5BCandidate |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
142 |
*/ |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
143 |
static GSList *parse_candidates(LmMessageNode *node) |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
144 |
{ |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
145 |
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
|
146 |
GSList *list = NULL; |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
147 |
|
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
148 |
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
|
149 |
if (g_strcmp0(node->name, "candidate")) |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
150 |
continue; |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
151 |
const gchar *hoststr, *portstr, *prioritystr, *typestr; |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
152 |
S5BCandidate *cand = g_new0(S5BCandidate, 1); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
|
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
160 |
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
|
161 |
g_free(cand); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
162 |
continue; |
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 |
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
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
|
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
169 |
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
|
170 |
g_free(cand); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
171 |
continue; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
172 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
173 |
|
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
174 |
list = g_slist_prepend(list, cand); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
175 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
176 |
list = g_slist_sort(list, prioritycmp); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
177 |
return list; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
178 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
179 |
|
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
180 |
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
|
181 |
{ |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
182 |
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
|
183 |
|
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
184 |
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
|
185 |
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
|
186 |
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
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
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
|
191 |
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
|
192 |
|
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
193 |
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
|
194 |
} |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
195 |
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
|
196 |
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
|
197 |
} |
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 |
/** |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
200 |
* @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
|
201 |
* @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
|
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 |
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
|
204 |
{ |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
205 |
// 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
|
206 |
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
|
207 |
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
|
208 |
const gchar *port_range = settings_opt_get("jingle_s5b_portrange"); |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
209 |
|
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
210 |
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
|
211 |
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
|
212 |
|
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
213 |
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
|
214 |
(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
|
215 |
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
|
216 |
} else { |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
217 |
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
|
218 |
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
|
219 |
} |
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 |
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
|
222 |
} |
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 |
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
|
225 |
} |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
226 |
|
156
653fa009fea3
Rename ->check() to newfrommessage and call it only on session-initiate.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
154
diff
changeset
|
227 |
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
|
228 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
229 |
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
|
230 |
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
|
231 |
const gchar *modestr; |
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 |
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
|
234 |
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
|
235 |
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
|
236 |
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
|
237 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
238 |
if (!js5b->sid) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
239 |
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
|
240 |
"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
|
241 |
g_free(js5b); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
242 |
return NULL; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
243 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
244 |
|
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
245 |
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
|
246 |
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
|
247 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
248 |
return (gconstpointer) js5b; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
249 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
250 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
251 |
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
|
252 |
{ |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
253 |
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
|
254 |
|
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
255 |
js5b->mode = JINGLE_S5B_TCP; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
256 |
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
|
257 |
|
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 |
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
|
259 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
260 |
return js5b; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
261 |
} |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
262 |
|
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
263 |
static JingleHandleStatus |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
264 |
handle_session_accept(JingleS5B *js5b, LmMessageNode *node, GError **err) |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
265 |
{ |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
266 |
js5b->candidates = parse_candidates(node); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
267 |
return JINGLE_STATUS_HANDLED; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
268 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
269 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
270 |
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
|
271 |
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
|
272 |
{ |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
273 |
JingleS5B *js5b = (JingleS5B *)data; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
274 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
275 |
if (action == JINGLE_SESSION_ACCEPT) { |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
276 |
return handle_session_accept(js5b, node, err); |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
277 |
} |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
278 |
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
|
279 |
} |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
280 |
|
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
281 |
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
|
282 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
283 |
JingleS5B *js5 = (JingleS5B *)data; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
284 |
S5BCandidate *js5c; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
285 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
286 |
LmMessageNode *node2, *node3; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
287 |
gchar *port; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
288 |
gchar *priority; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
289 |
GSList *el; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
290 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
291 |
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
|
292 |
return; |
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 |
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
|
295 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
296 |
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
|
297 |
"sid", js5->sid, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
298 |
"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
|
299 |
NULL); |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
300 |
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
|
301 |
js5c = (S5BCandidate*) el->data; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
302 |
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
|
303 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
304 |
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
|
305 |
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
|
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(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
|
308 |
"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
|
309 |
"jid", js5c->jid, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
310 |
"port", port, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
311 |
"priority", priority, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
312 |
"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
|
313 |
NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
314 |
g_free(port); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
315 |
g_free(priority); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
316 |
} |
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 |
|
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
319 |
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
|
320 |
{ |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
321 |
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
|
322 |
GSocketAddress *saddr; |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
323 |
//GSource *socksource; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
324 |
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
|
325 |
GSList *entry; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
326 |
GError *err = NULL; |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
327 |
|
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
328 |
// 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
|
329 |
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
|
330 |
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
|
331 |
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
|
332 |
|
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
333 |
cand->sock = g_socket_new(g_inet_address_get_family(cand->host), |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
334 |
G_SOCKET_TYPE_STREAM, |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
335 |
G_SOCKET_PROTOCOL_TCP, &err); |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
336 |
if (cand->sock == NULL) { |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
337 |
scr_LogPrint(LPRINT_LOGNORM, "Jingle S5B: Error while creating a new socket: %s", |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
338 |
err->message != NULL ? err->message : "(no message)"); |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
339 |
continue; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
340 |
} |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
341 |
g_socket_set_blocking(cand->sock, FALSE); |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
342 |
|
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
343 |
saddr = g_inet_socket_address_new(cand->host, cand->port); |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
344 |
if (!g_socket_bind(cand->sock, saddr, TRUE, &err)) { |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
345 |
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
|
346 |
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
|
347 |
cand->port, |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
348 |
err->message != NULL ? err->message : "(no message)"); |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
349 |
goto cleancontinue; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
350 |
} |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
351 |
|
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
352 |
if (!g_socket_listen(cand->sock, &err)) { |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
353 |
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
|
354 |
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
|
355 |
cand->port, |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
356 |
err->message != NULL ? err->message : "(no message)"); |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
357 |
goto cleancontinue; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
358 |
} |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
359 |
|
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
360 |
if (!g_socket_listener_add_socket(js5b->listener, cand->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
|
361 |
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
|
362 |
" GSocketListener: %s", |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
363 |
err->message != NULL ? err->message : "(no message)"); |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
364 |
goto cleancontinue; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
365 |
} |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
366 |
|
162
6afab419ff88
Fix out of source build. Set build profiles options.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
161
diff
changeset
|
367 |
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
|
368 |
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
|
369 |
cand->port); |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
370 |
++numlistening; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
371 |
|
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
372 |
cleancontinue: |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
373 |
g_object_unref(saddr); |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
374 |
g_object_unref(cand->sock); |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
375 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
376 |
|
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
377 |
if (numlistening > 0) { |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
378 |
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
|
379 |
} else { |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
380 |
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
|
381 |
} |
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 |
// Then, we start connecting to the other entity's candidates, if any. |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
384 |
} |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
385 |
|
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
386 |
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
|
387 |
{ |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
388 |
//JingleS5B *js5b = (JingleS5B *)data; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
389 |
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
|
390 |
return info; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
391 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
392 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
393 |
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
|
394 |
return; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
395 |
} |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
396 |
|
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
397 |
|
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
398 |
/** |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
399 |
* @brief Handle incoming connections |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
400 |
*/ |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
401 |
static void |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
402 |
handle_listener_accept(GObject *_listener, GAsyncResult *res, gpointer userdata) |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
403 |
{ |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
404 |
GError *err = NULL; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
405 |
GSocketConnection *conn; |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
406 |
conn = g_socket_listener_accept_finish((GSocketListener *) _listener, res, NULL, &err); |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
407 |
} |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
408 |
|
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
409 |
/** |
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
410 |
* @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
|
411 |
*/ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
412 |
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
|
413 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
414 |
switch (cond) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
415 |
case G_IO_IN: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
416 |
break; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
417 |
case G_IO_OUT: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
418 |
break; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
419 |
case G_IO_ERR: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
420 |
break; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
421 |
case G_IO_HUP: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
422 |
break; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
423 |
default: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
424 |
; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
425 |
// ?! |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
426 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
427 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
428 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
429 |
/** |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
430 |
* @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
|
431 |
* @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
|
432 |
*/ |
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
433 |
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
|
434 |
GSList *addresses = NULL; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
435 |
GInetAddress *thisaddr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
436 |
GSocketFamily family; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
437 |
struct ifaddrs *first, *ifaddr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
438 |
struct sockaddr_in *native; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
439 |
struct sockaddr_in6 *native6; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
440 |
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
|
441 |
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
|
442 |
LocalIP *candidate; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
443 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
444 |
gint rval = getifaddrs(&first); |
161
fa1d993d05b6
S5B: Use a GSocketListener to manage listener sockets.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
159
diff
changeset
|
445 |
if (rval != 0) |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
446 |
return NULL; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
447 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
448 |
for (ifaddr = first; ifaddr; ifaddr = ifaddr->ifa_next) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
449 |
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
|
450 |
continue; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
451 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
452 |
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
|
453 |
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
|
454 |
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
|
455 |
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
|
456 |
} 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
|
457 |
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
|
458 |
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
|
459 |
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
|
460 |
} else |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
461 |
continue; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
462 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
463 |
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
|
464 |
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
|
465 |
g_object_unref(thisaddr); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
466 |
continue; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
467 |
}/* 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
|
468 |
// 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
|
469 |
} */ |
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
470 |
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
|
471 |
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
|
472 |
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
|
473 |
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
|
474 |
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
|
475 |
++ifacecounter; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
476 |
} |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
477 |
freeifaddrs(first); |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
478 |
|
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
479 |
return addresses; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
480 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
481 |
|
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
482 |
static gchar *random_str(guint len) |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
483 |
{ |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
484 |
gchar *str; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
485 |
gchar car[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
486 |
gint i; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
487 |
str = g_new0(gchar, 8); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
488 |
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
|
489 |
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
|
490 |
|
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
491 |
str[len] = '\0'; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
492 |
return str; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
493 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
494 |
|
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
495 |
static gchar *gen_random_sid(void) |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
496 |
{ |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
497 |
return random_str(7); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
498 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
499 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
500 |
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
|
501 |
{ |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
502 |
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
|
503 |
} |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
504 |
|
159
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
505 |
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
|
506 |
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
|
507 |
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
|
508 |
} |
1df5f5e3f1e7
Fix the segfault when quitting in IBB and various other bugs.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
158
diff
changeset
|
509 |
|
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
510 |
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
|
511 |
{ |
163
a4c75fe75869
Fix the segfault when unloading the S5B module, by loading gio manually
Gu1 <gu1@aeroxteam.fr>
parents:
162
diff
changeset
|
512 |
// 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
|
513 |
// 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
|
514 |
// 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
|
515 |
// 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
|
516 |
// 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
|
517 |
// 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
|
518 |
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
|
519 |
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
|
520 |
// 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
|
521 |
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
|
522 |
g_type_init(); |
a4c75fe75869
Fix the segfault when unloading the S5B module, by loading gio manually
Gu1 <gu1@aeroxteam.fr>
parents:
162
diff
changeset
|
523 |
} |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
524 |
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
|
525 |
JINGLE_TRANSPORT_STREAMING, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
526 |
JINGLE_TRANSPORT_PRIO_HIGH); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
527 |
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
|
528 |
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
|
529 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
530 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
531 |
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
|
532 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
533 |
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
|
534 |
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
|
535 |
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
|
536 |
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
|
537 |
} |