author | Nicolas Cornu <nicolas.cornu@ensi-bourges.fr> |
Wed, 25 Aug 2010 01:27:46 +0200 | |
changeset 158 | a068e5714120 |
parent 157 | 8ec7ce3ecaac |
child 159 | 1df5f5e3f1e7 |
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); |
156
653fa009fea3
Rename ->check() to newfrommessage and call it only on session-initiate.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
154
diff
changeset
|
52 |
static void init(session_content *sc); |
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); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
54 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
55 |
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
|
56 |
static GSList *get_all_local_ips(); |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
62 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
63 |
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
|
64 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
65 |
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
|
66 |
.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
|
67 |
.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
|
68 |
.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
|
69 |
.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
|
70 |
.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
|
71 |
.init = init, |
653fa009fea3
Rename ->check() to newfrommessage and call it only on session-initiate.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
154
diff
changeset
|
72 |
.end = end |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
73 |
}; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
74 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
75 |
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
|
76 |
.branch = MCABBER_BRANCH, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
77 |
.api = MCABBER_API_VERSION, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
78 |
.version = PROJECT_VERSION, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
79 |
.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
|
80 |
.requires = deps, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
81 |
.init = jingle_socks5_init, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
82 |
.uninit = jingle_socks5_uninit, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
83 |
.next = NULL, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
84 |
}; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
85 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
86 |
static const gchar *jingle_s5b_types[] = { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
87 |
"assisted", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
88 |
"direct", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
89 |
"proxy", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
90 |
"tunnel", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
91 |
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_modes[] = { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
95 |
"tcp", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
96 |
"udp", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
97 |
NULL |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
98 |
}; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
99 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
100 |
typedef struct { |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
101 |
GInetAddress *address; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
102 |
guint32 priority; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
103 |
} LocalCandidate; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
104 |
|
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
105 |
/** |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
106 |
* @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
|
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 |
static GSList *local_candidates = NULL; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
109 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
110 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
111 |
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
|
112 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
113 |
gint i; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
114 |
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
|
115 |
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
|
116 |
return i; |
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 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
119 |
return -1; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
120 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
121 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
122 |
static 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
|
123 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
124 |
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
|
125 |
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
|
126 |
return 1; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
127 |
} 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
|
128 |
return -1; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
129 |
} else { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
130 |
return 0; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
131 |
} |
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 |
|
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
134 |
/** |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
135 |
* @brief Parse a list of <candidate> elements |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
136 |
* @return a list of S5BCandidate |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
137 |
*/ |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
138 |
static GSList *parse_candidates(LmMessageNode *node) |
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 |
LmMessageNode *node2; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
141 |
GSList *list; |
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 |
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
|
144 |
if (g_strcmp0(node->name, "candidate")) |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
145 |
continue; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
146 |
const gchar *portstr, *prioritystr, *typestr; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
147 |
S5BCandidate *cand = g_new0(S5BCandidate, 1); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
148 |
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
|
149 |
cand->host = g_strdup(lm_message_node_get_attribute(node2, "host")); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
150 |
cand->jid = g_strdup(lm_message_node_get_attribute(node2, "jid")); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
151 |
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
|
152 |
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
|
153 |
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
|
154 |
|
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
155 |
if (!cand->cid || !cand->host || !cand->jid || !prioritystr) { |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
156 |
g_free(cand); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
157 |
continue; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
158 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
159 |
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
|
160 |
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
|
161 |
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
|
162 |
|
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
163 |
if (cand->type == -1) { |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
164 |
g_free(cand); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
165 |
continue; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
166 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
167 |
|
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
168 |
list = g_slist_prepend(list, cand); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
169 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
170 |
list = g_slist_sort(list, prioritycmp); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
171 |
return list; |
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 |
|
156
653fa009fea3
Rename ->check() to newfrommessage and call it only on session-initiate.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
154
diff
changeset
|
174 |
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
|
175 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
176 |
JingleS5B *js5b; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
177 |
LmMessageNode *node = cn->transport, *node2; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
178 |
const gchar *modestr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
179 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
185 |
if (!js5b->sid) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
186 |
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
|
187 |
"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
|
188 |
g_free(js5b); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
189 |
return NULL; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
190 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
191 |
|
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
192 |
js5b->candidates = parse_candidates(node); |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
193 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
194 |
return (gconstpointer) js5b; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
195 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
196 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
197 |
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
|
198 |
{ |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
199 |
JingleS5B *js5b = g_new0(JingleS5B, 1); |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
200 |
GSList *entry; |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
201 |
gint port; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
202 |
|
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
203 |
js5b->mode = JINGLE_S5B_TCP; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
204 |
js5b->sid = gen_random_sid(); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
205 |
port = settings_opt_get_int("jingle_s5b_dir"); |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
206 |
if (port < 1024 && port > (guint16)~0) { |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
207 |
port = g_random_int_range(1024, (guint16)~0); |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
208 |
} |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
209 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
210 |
for (entry = local_candidates; entry; entry = entry->next) { |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
211 |
LocalCandidate *lcand = (LocalCandidate *)entry->data; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
212 |
S5BCandidate *cand = g_new0(S5BCandidate, 1); |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
213 |
cand->cid = gen_random_cid(); |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
214 |
cand->host = g_inet_address_to_string(lcand->address); |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
215 |
cand->jid = g_strdup(lm_connection_get_jid(lconnection)); |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
216 |
cand->port = port; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
217 |
cand->priority = lcand->priority; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
218 |
|
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
219 |
js5b->ourcandidates = g_slist_prepend(js5b->ourcandidates, cand); |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
220 |
} |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
221 |
return js5b; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
222 |
} |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
223 |
|
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
224 |
static JingleHandleStatus |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
225 |
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
|
226 |
{ |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
227 |
js5b->candidates = parse_candidates(node); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
228 |
return JINGLE_STATUS_HANDLED; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
229 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
230 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
231 |
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
|
232 |
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
|
233 |
{ |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
234 |
JingleS5B *js5b = (JingleS5B *)data; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
235 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
236 |
if (action == JINGLE_SESSION_ACCEPT) { |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
237 |
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
|
238 |
} |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
239 |
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
|
240 |
} |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
241 |
|
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
242 |
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
|
243 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
244 |
JingleS5B *js5 = (JingleS5B *)data; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
245 |
S5BCandidate *js5c; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
246 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
247 |
LmMessageNode *node2, *node3; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
248 |
gchar *port; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
249 |
gchar *priority; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
250 |
GSList *el; |
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 |
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
|
253 |
return; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
254 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
255 |
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
|
256 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
257 |
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
|
258 |
"sid", js5->sid, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
259 |
"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
|
260 |
NULL); |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
261 |
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
|
262 |
js5c = (S5BCandidate*) el->data; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
263 |
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
|
264 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
265 |
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
|
266 |
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
|
267 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
268 |
lm_message_node_set_attributes(node3, "cid", js5c->cid, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
269 |
"host", js5c->host, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
270 |
"jid", js5c->jid, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
271 |
"port", port, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
272 |
"priority", priority, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
273 |
"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
|
274 |
NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
275 |
g_free(port); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
276 |
g_free(priority); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
277 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
278 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
279 |
|
156
653fa009fea3
Rename ->check() to newfrommessage and call it only on session-initiate.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
154
diff
changeset
|
280 |
static void init(session_content *sc) |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
281 |
{ |
156
653fa009fea3
Rename ->check() to newfrommessage and call it only on session-initiate.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
154
diff
changeset
|
282 |
JingleS5B *js5 = NULL; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
283 |
GInetAddress *addr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
284 |
GSocketAddress *saddr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
285 |
GSource *socksource; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
286 |
GError *err = NULL; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
287 |
g_assert(js5->sock == NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
288 |
|
156
653fa009fea3
Rename ->check() to newfrommessage and call it only on session-initiate.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
154
diff
changeset
|
289 |
addr = g_inet_address_new_from_string("127.0.0.1"); |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
290 |
js5->sock = g_socket_new(g_inet_address_get_family(addr), G_SOCKET_TYPE_STREAM, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
291 |
G_SOCKET_PROTOCOL_TCP, &err); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
292 |
if (js5->sock == NULL) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
293 |
scr_LogPrint(LPRINT_LOGNORM, "Jingle SOCKS5: Error while creating a new socket: %s", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
294 |
err->message != NULL ? err->message : "(no message)"); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
295 |
return; // TODO: we need a way to return errors... |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
296 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
297 |
g_socket_set_blocking(js5->sock, FALSE); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
298 |
socksource = g_socket_create_source(js5->sock, ~0, NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
299 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
300 |
g_source_set_callback(socksource, (GSourceFunc)handle_sock_io, NULL, NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
301 |
g_source_attach(socksource, NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
302 |
g_source_unref(socksource); |
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 |
saddr = g_inet_socket_address_new(addr, 31337); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
305 |
if (!g_socket_connect(js5->sock, saddr, NULL, &err)) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
306 |
scr_LogPrint(LPRINT_LOGNORM, "Jingle SOCKS5: Error while connecting to the host: %s", |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
307 |
err->message != NULL ? err->message : "(no message)"); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
308 |
return; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
309 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
310 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
311 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
312 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
313 |
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
|
314 |
return; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
315 |
} |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
316 |
|
154
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 |
* Handle any event on a sock |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
319 |
*/ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
320 |
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
|
321 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
322 |
switch (cond) { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
323 |
case G_IO_IN: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
324 |
break; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
325 |
case G_IO_OUT: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
326 |
break; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
327 |
case G_IO_ERR: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
328 |
break; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
329 |
case G_IO_HUP: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
330 |
break; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
331 |
default: |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
332 |
; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
333 |
// ?! |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
334 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
335 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
336 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
337 |
/** |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
338 |
* @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
|
339 |
* @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
|
340 |
*/ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
341 |
static GSList *get_all_local_ips() { |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
342 |
GSList *addresses = NULL; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
343 |
GInetAddress *thisaddr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
344 |
GSocketFamily family; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
345 |
struct ifaddrs *first, *ifaddr; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
346 |
struct sockaddr_in *native; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
347 |
struct sockaddr_in6 *native6; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
348 |
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
|
349 |
guint16 ifacecounter = 0; // for lack of a better method |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
350 |
LocalCandidate *candidate; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
351 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
352 |
gint rval = getifaddrs(&first); |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
353 |
if (!rval) |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
354 |
return NULL; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
355 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
356 |
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
|
357 |
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
|
358 |
continue; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
359 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
360 |
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
|
361 |
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
|
362 |
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
|
363 |
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
|
364 |
} 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
|
365 |
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
|
366 |
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
|
367 |
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
|
368 |
} else |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
369 |
continue; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
370 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
371 |
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
|
372 |
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
|
373 |
g_object_unref(thisaddr); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
374 |
continue; |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
375 |
}/* 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
|
376 |
// 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
|
377 |
} */ |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
378 |
candidate = g_new0(LocalCandidate, 1); |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
379 |
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
|
380 |
candidate->priority = (1<<16)*126+ifacecounter; |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
381 |
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
|
382 |
++ifacecounter; |
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
383 |
} |
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
384 |
freeifaddrs(first); |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
385 |
|
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
386 |
return addresses; |
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 |
|
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
389 |
static gchar *random_str(guint len) |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
390 |
{ |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
391 |
gchar *str; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
392 |
gchar car[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
393 |
gint i; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
394 |
str = g_new0(gchar, 8); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
395 |
for (i = 0; i < len; i++) |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
396 |
str[i] = car[g_random_int_range(0, sizeof(car)/sizeof(car[0]))]; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
397 |
|
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
398 |
str[len] = '\0'; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
399 |
return str; |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
400 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
401 |
|
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
402 |
static gchar *gen_random_sid(void) |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
403 |
{ |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
404 |
return random_str(7); |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
405 |
} |
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
406 |
|
157
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
407 |
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
|
408 |
{ |
158
a068e5714120
JS5B: Start the handle function
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
157
diff
changeset
|
409 |
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
|
410 |
} |
8ec7ce3ecaac
S5B: Start the "new" function that create a new JingleS5B.
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
156
diff
changeset
|
411 |
|
154
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
412 |
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
|
413 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
414 |
g_type_init(); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
415 |
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
|
416 |
JINGLE_TRANSPORT_STREAMING, |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
417 |
JINGLE_TRANSPORT_PRIO_HIGH); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
418 |
xmpp_add_feature(NS_JINGLE_TRANSPORT_SOCKS5); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
419 |
local_candidates = get_all_local_ips(); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
420 |
} |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
421 |
|
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
422 |
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
|
423 |
{ |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
424 |
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
|
425 |
jingle_unregister_transport(NS_JINGLE_TRANSPORT_SOCKS5); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
426 |
g_slist_foreach(local_candidates, (GFunc)g_object_unref, NULL); |
1ffa1733d4b6
Add a function to find local ips in S5B
Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
parents:
diff
changeset
|
427 |
} |