2
/* GnomeMeeting -- A Video-Conferencing application
3
* Copyright (C) 2000-2006 Damien Sandras
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
* GnomeMeting is licensed under the GPL license and as a special exception,
21
* you have permission to link or otherwise combine this program with the
22
* programs OpenH323 and Pwlib, and distribute the combination, without
23
* applying the requirements of the GNU GPL to the OpenH323 program, as long
24
* as you do follow the requirements of the GNU GPL for all the rest of the
25
* software thus combined.
30
* stunclient.cpp - description
31
* ------------------------------
32
* begin : Thu Sep 30 2004
33
* copyright : (C) 2000-2006 by Damien Sandras
34
* description : Multithreaded class for the stun client.
39
#include "../../config.h"
50
#include <ptclib/pstun.h>
57
* BEHAVIOR : Create a dialog that presents the result of the STUN test.
58
* If the NAT type permits it, ask to the user if he wants
59
* to enable STUN support or not.
63
gm_sw_stun_result_window_new (GtkWidget *parent,
69
/* DESCRIPTION : This callback is called when the user validates an answer
71
* BEHAVIOR : Destroy the dialog and set/unset the STUN server.
74
static void stun_dialog_response_cb (GtkDialog *dialog,
81
stun_dialog_response_cb (GtkDialog *dialog,
87
GtkWidget *history_window = NULL;
90
ep = GnomeMeeting::Process ()->GetManager ();
91
history_window = GnomeMeeting::Process ()->GetHistoryWindow ();
95
case GTK_RESPONSE_YES:
97
gm_conf_set_string (NAT_KEY "stun_server", "stun.ekiga.net");
98
gm_conf_set_int (NAT_KEY "method", 1);
100
gm_history_window_insert (history_window,
101
_("STUN server set to %s"),
106
case GTK_RESPONSE_NO:
108
((OpalManager *) ep)->SetSTUNServer (PString ());
110
gm_history_window_insert (history_window, _("Removed STUN server"));
115
gtk_widget_destroy (GTK_WIDGET (dialog));
120
gm_sw_stun_result_window_new (GtkWidget *parent,
123
GtkWidget *dialog = NULL;
124
GtkWidget *dialog_label = NULL;
126
gchar *prefered_method = NULL;
127
gchar *primary_text = NULL;
128
gchar *dialog_text = NULL;
130
gboolean stun_dialog = TRUE;
132
PString nat_type = GMStunClient::GetNatName (nat_type_index);
134
switch (nat_type_index)
139
prefered_method = g_strdup_printf (_("STUN test result: %s.\n\nEkiga could not detect the type of NAT you are using. The most appropriate method, if your router does not natively support SIP or H.323, is probably to forward the required ports to your internal machine and use IP translation if you are behind a NAT router. Please also make sure you are not running a local firewall."), (const char *) nat_type);
145
prefered_method = g_strdup_printf (_("STUN test result: %s.\n\nYour system does not need any specific configuration as long as you do not have a local firewall blocking the ports required by Ekiga."), (const char *) nat_type);
150
prefered_method = g_strdup_printf (_("Ekiga detected Symmetric NAT. The most appropriate method, if your router does not natively support SIP or H.323, is to forward the required ports to your internal machine in order to change your Symmetric NAT into Cone NAT. Running this test again after the port forwarding has been done should report Cone NAT and allow Ekiga to be used with STUN support enabled. If it does not report Cone NAT, then it means that there is a problem in your forwarding rules."));
155
prefered_method = g_strdup_printf (_("STUN test result: %s.\n\nUsing a STUN server is most probably the most appropriate method if your router does not natively support SIP or H.323.\n\nEnable STUN Support?"), (const char *) nat_type);
164
gtk_dialog_new_with_buttons (_("NAT Detection Finished"),
172
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
177
gtk_dialog_new_with_buttons (_("NAT Detection Finished"),
183
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
187
g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>",
188
_("The detection of your NAT type is finished"));
191
g_strdup_printf ("%s\n\n%s", primary_text, prefered_method);
193
gtk_window_set_title (GTK_WINDOW (dialog), "");
194
dialog_label = gtk_label_new (NULL);
195
gtk_label_set_markup (GTK_LABEL (dialog_label),
197
gtk_label_set_line_wrap (GTK_LABEL (dialog_label), TRUE);
198
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
201
g_signal_connect (GTK_WINDOW (dialog), "response",
202
G_CALLBACK (stun_dialog_response_cb), NULL);
204
g_free (prefered_method);
205
g_free (primary_text);
206
g_free (dialog_text);
213
GMStunClient::GMStunClient (BOOL d,
216
GtkWidget *parent_window,
217
GMManager & endpoint)
218
:PThread (1000, NoAutoDeleteThread),
221
gchar *conf_string = NULL;
224
gnomemeeting_threads_enter ();
225
nat_method = gm_conf_get_int (NAT_KEY "method");
226
conf_string = gm_conf_get_string (NAT_KEY "stun_server");
227
stun_host = conf_string;
228
gnomemeeting_threads_leave ();
230
display_progress = d;
231
display_config_dialog = c;
234
parent = parent_window;
240
g_free (conf_string);
244
GMStunClient::~GMStunClient ()
246
/* Nothing to do here */
247
PWaitAndSignal m(quit_mutex);
251
PString GMStunClient::GetNatName (int i)
258
N_("Restricted NAT"),
259
N_("Port Restricted NAT"),
261
N_("Symmetric Firewall"),
263
N_("Partially Blocked"),
267
return PString (gettext (name [i]));
271
void GMStunClient::Main ()
273
GtkWidget *history_window = NULL;
274
GtkWidget *main_window = NULL;
276
PSTUNClient *stun = NULL;
278
int nat_type_index = 0;
280
main_window = GnomeMeeting::Process ()->GetMainWindow ();
281
history_window = GnomeMeeting::Process ()->GetHistoryWindow ();
283
GtkWidget *progress_dialog = NULL;
284
GtkWidget *dialog = NULL;
287
PWaitAndSignal m(quit_mutex);
289
/* Async remove the current stun server setting */
290
if (stun_host.IsEmpty ()) {
295
((OpalManager *) &ep)->SetSTUNServer (PString ());
300
/* Display a progress dialog */
301
if (display_progress) {
303
gnomemeeting_threads_enter ();
305
gnomemeeting_progress_dialog (GTK_WINDOW (parent),
306
_("Detection in progress"),
307
_("Please wait while your type of NAT is being detected."));
308
gnomemeeting_threads_dialog_show_all (progress_dialog);
309
gnomemeeting_threads_leave ();
312
/* Set the STUN server for the endpoint */
313
((OpalManager *) &ep)->SetSTUNServer (stun_host);
315
stun = ep.GetSTUN ();
319
nat_type_index = stun->GetNatType ();
320
nat_type = GetNatName (nat_type_index);
324
if (!display_config_dialog) {
326
gnomemeeting_threads_enter ();
327
gm_history_window_insert (history_window, _("Set STUN server to %s (%s)"), (const char *) stun_host, (const char *) nat_type);
328
gnomemeeting_threads_leave ();
332
/* Show the config dialog */
333
gnomemeeting_threads_enter ();
334
if (display_config_dialog) {
336
dialog = gm_sw_stun_result_window_new (parent, nat_type_index);
337
gnomemeeting_threads_dialog_show_all (dialog);
339
gnomemeeting_threads_leave ();
342
/* Delete the progress if any */
343
gnomemeeting_threads_enter ();
344
if (display_progress)
345
gnomemeeting_threads_widget_destroy (progress_dialog);
346
gnomemeeting_threads_leave ();