~ubuntu-branches/ubuntu/natty/ekiga/natty

« back to all changes in this revision

Viewing changes to src/endpoints/sip.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2008-12-07 10:30:45 UTC
  • mfrom: (1.2.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20081207103045-iaurrjo4p7d1nngo
Tags: 3.0.1-1ubuntu1
* Merge to Debian experimental, to get Ekiga 3. (LP: #274085) Remaining
  Ubuntu changes:
  - Launchpad Integration: (Ubuntu specific)
    + debian/control.in: Add liblaunchpad-integration-dev build dependency.
    + Add ubuntu_lpi.patch: Call launchpad_integration_add_items() in main() and
      check for the launchpad-integration pkg-config module.
    + Add autoconf.patch: autoconf changes from above patch.
  - Add ubuntu_desktop-file-onlyshowin.patch: Show ekiga in Mobile, too.
    (Ubuntu specific).
  - debian/control.in: Add missing fdupes build dependency for identical
    GNOME help file symlinking. (Debian #505536)
* Drop 42_change_pixmaps.dpatch: Many of the old icons do not exist any
  more, some have been replaced, and keeping the remaining three would make
  them look very inconsistent.
* Convert our dpatches to quilt patches and rewrite them for new upstream
  version.
* Add migrate_2.0_settings.patch: Properly migrate settings from
  2.0. Taken from upstream SVN, thanks to Damien Sandras!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/* Ekiga -- A VoIP and Video-Conferencing application
3
 
 * Copyright (C) 2000-2006 Damien Sandras
4
 
 *
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.
9
 
 *
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.
14
 
 *
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 Foundation,
17
 
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18
 
 *
19
 
 *
20
 
 * Ekiga 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 OPAL, OpenH323 and PWLIB, and distribute the combination,
23
 
 * without applying the requirements of the GNU GPL to the OPAL, OpenH323
24
 
 * and PWLIB programs, as long as you do follow the requirements of the
25
 
 * GNU GPL for all the rest of the software thus combined.
26
 
 */
27
 
 
28
 
 
29
 
/*
30
 
 *                         sipendpoint.cpp  -  description
31
 
 *                         --------------------------------
32
 
 *   begin                : Wed 8 Dec 2004
33
 
 *   copyright            : (C) 2000-2006 by Damien Sandras
34
 
 *   description          : This file contains the SIP Endpoint class.
35
 
 *
36
 
 */
37
 
 
38
 
 
39
 
#include "../../config.h"
40
 
 
41
 
#include "sip.h"
42
 
#include "pcss.h"
43
 
#include "ekiga.h"
44
 
 
45
 
#include "main.h"
46
 
#include "chat.h"
47
 
#include "preferences.h"
48
 
#include "history.h"
49
 
#include "statusicon.h"
50
 
#include "misc.h"
51
 
#ifdef HAS_DBUS
52
 
#include "dbus.h"
53
 
#endif
54
 
 
55
 
#include "gmconf.h"
56
 
#include "gmdialog.h"
57
 
 
58
 
#include <ptlib/ethsock.h>
59
 
 
60
 
#define new PNEW
61
 
 
62
 
 
63
 
/* The class */
64
 
GMSIPEndpoint::GMSIPEndpoint (GMManager & ep)
65
 
: SIPEndPoint (ep), endpoint (ep)
66
 
{
67
 
  NoAnswerTimer.SetNotifier (PCREATE_NOTIFIER (OnNoAnswerTimeout));
68
 
}
69
 
 
70
 
 
71
 
GMSIPEndpoint::~GMSIPEndpoint ()
72
 
{
73
 
}
74
 
 
75
 
 
76
 
void 
77
 
GMSIPEndpoint::Init ()
78
 
{
79
 
  GtkWidget *main_window = NULL;
80
 
 
81
 
  gchar *outbound_proxy_host = NULL;
82
 
  int binding_timeout = 60;
83
 
 
84
 
  main_window = GnomeMeeting::Process ()->GetMainWindow ();
85
 
 
86
 
  gnomemeeting_threads_enter ();
87
 
  outbound_proxy_host = gm_conf_get_string (SIP_KEY "outbound_proxy_host");
88
 
  binding_timeout = gm_conf_get_int (NAT_KEY "binding_timeout");
89
 
  gnomemeeting_threads_leave ();
90
 
 
91
 
 
92
 
  /* Timeouts */
93
 
  SetAckTimeout (PTimeInterval (0, 32));
94
 
  SetPduCleanUpTimeout (PTimeInterval (0, 1));
95
 
  SetInviteTimeout (PTimeInterval (0, 6));
96
 
  SetNonInviteTimeout (PTimeInterval (0, 6));
97
 
  SetNATBindingTimeout (PTimeInterval (0, binding_timeout));
98
 
  SetRetryTimeouts (500, 4000);
99
 
  SetMaxRetries (8);
100
 
 
101
 
 
102
 
  /* Update the User Agent */
103
 
  SetUserAgent ("Ekiga/" PACKAGE_VERSION);
104
 
  
105
 
 
106
 
  /* Initialise internal parameters */
107
 
  if (outbound_proxy_host && !PString (outbound_proxy_host).IsEmpty ())
108
 
    SetProxy (outbound_proxy_host);
109
 
  SetNATBindingRefreshMethod (SIPEndPoint::EmptyRequest);
110
 
 
111
 
 
112
 
  g_free (outbound_proxy_host);
113
 
}
114
 
 
115
 
 
116
 
BOOL 
117
 
GMSIPEndpoint::StartListener (PString iface, 
118
 
                              WORD port)
119
 
{
120
 
  PString iface_noip;
121
 
  PString ip;
122
 
  PIPSocket::InterfaceTable ifaces;
123
 
  PINDEX i = 0;
124
 
  PINDEX pos = 0;
125
 
  
126
 
  gboolean ok = FALSE;
127
 
  gboolean found = FALSE;
128
 
 
129
 
  gchar *listen_to = NULL;
130
 
 
131
 
  RemoveListener (NULL);
132
 
 
133
 
  /* Detect the valid interfaces */
134
 
  PIPSocket::GetInterfaceTable (ifaces);
135
 
 
136
 
  while (i < ifaces.GetSize ()) {
137
 
    
138
 
    ip = " [" + ifaces [i].GetAddress ().AsString () + "]";
139
 
    
140
 
    if (ifaces [i].GetName () + ip == iface) {
141
 
      listen_to = 
142
 
        g_strdup_printf ("udp$%s:%d", 
143
 
                         (const char *) ifaces [i].GetAddress().AsString(),
144
 
                         port);
145
 
      found = TRUE;
146
 
    }
147
 
      
148
 
    i++;
149
 
  }
150
 
 
151
 
  i = 0;
152
 
  pos = iface.Find("[");
153
 
  if (pos != P_MAX_INDEX)
154
 
    iface_noip = iface.Left (pos).Trim ();
155
 
  while (i < ifaces.GetSize() && !found) {
156
 
 
157
 
    if (ifaces [i].GetName () == iface_noip) {
158
 
      listen_to = 
159
 
        g_strdup_printf ("udp$%s:%d", 
160
 
                         (const char *) ifaces [i].GetAddress().AsString(),
161
 
                         port);
162
 
      found = TRUE;
163
 
    }
164
 
    
165
 
    i++;
166
 
  }
167
 
 
168
 
  /* Start the listener thread for incoming calls */
169
 
  if (!listen_to)
170
 
    return FALSE;
171
 
 
172
 
  ok = StartListeners (PStringArray (listen_to));
173
 
  g_free (listen_to);
174
 
 
175
 
  return ok;
176
 
}
177
 
 
178
 
 
179
 
void
180
 
GMSIPEndpoint::SetUserNameAndAlias ()
181
 
{
182
 
  PString default_local_name;
183
 
 
184
 
  default_local_name = endpoint.GetDefaultDisplayName ();
185
 
 
186
 
  if (!default_local_name.IsEmpty ()) {
187
 
 
188
 
    SetDefaultDisplayName (default_local_name);
189
 
  }
190
 
}
191
 
 
192
 
 
193
 
void 
194
 
GMSIPEndpoint::SetUserInputMode ()
195
 
{
196
 
  // Do nothing, only RFC2833 is supported.
197
 
}
198
 
 
199
 
 
200
 
void
201
 
GMSIPEndpoint::OnRegistered (const PString & domain,
202
 
                             const PString & username,
203
 
                             BOOL wasRegistering)
204
 
{
205
 
  GtkWidget *accounts_window = NULL;
206
 
  GtkWidget *history_window = NULL;
207
 
  GtkWidget *main_window = NULL;
208
 
#ifdef HAS_DBUS
209
 
  GObject   *dbus_component = NULL;
210
 
#endif
211
 
 
212
 
  gchar *msg = NULL;
213
 
 
214
 
  accounts_window = GnomeMeeting::Process ()->GetAccountsWindow ();
215
 
  main_window = GnomeMeeting::Process ()->GetMainWindow ();
216
 
  history_window = GnomeMeeting::Process ()->GetHistoryWindow ();
217
 
#ifdef HAS_DBUS
218
 
  dbus_component = GnomeMeeting::Process ()->GetDbusComponent ();
219
 
#endif
220
 
 
221
 
  gnomemeeting_threads_enter ();
222
 
  /* Registering is ok */
223
 
  if (wasRegistering) {
224
 
 
225
 
    msg = g_strdup_printf (_("Registered to %s"), 
226
 
                           (const char *) domain);
227
 
    gm_accounts_window_update_account_state (accounts_window, 
228
 
                                             FALSE,
229
 
                                             (const char *) domain, 
230
 
                                             (const char *) username, 
231
 
                                             _("Registered"),
232
 
                                             NULL);
233
 
  }
234
 
  else {
235
 
 
236
 
    msg = g_strdup_printf (_("Unregistered from %s"),
237
 
                           (const char *) domain); 
238
 
    gm_accounts_window_update_account_state (accounts_window, 
239
 
                                             FALSE,
240
 
                                             (const char *) domain, 
241
 
                                             (const char *) username, 
242
 
                                             _("Unregistered"),
243
 
                                             NULL);
244
 
  }
245
 
 
246
 
#ifdef HAS_DBUS
247
 
  gnomemeeting_dbus_component_account_registration (dbus_component,
248
 
                                                    username, domain,
249
 
                                                    wasRegistering);
250
 
#endif
251
 
 
252
 
  gm_history_window_insert (history_window, "%s", msg);
253
 
  gm_main_window_flash_message (main_window, "%s", msg);
254
 
  if (endpoint.GetCallingState() == GMManager::Standby)
255
 
    gm_main_window_set_account_info (main_window, 
256
 
                                     endpoint.GetRegisteredAccounts());
257
 
  gnomemeeting_threads_leave ();
258
 
 
259
 
  /* Signal the SIPEndpoint */
260
 
  SIPEndPoint::OnRegistered (domain, username, wasRegistering);
261
 
 
262
 
  g_free (msg);
263
 
}
264
 
 
265
 
 
266
 
void
267
 
GMSIPEndpoint::OnRegistrationFailed (const PString & host,
268
 
                                     const PString & user,
269
 
                                     SIP_PDU::StatusCodes r,
270
 
                                     BOOL wasRegistering)
271
 
{
272
 
  GtkWidget *accounts_window = NULL;
273
 
  GtkWidget *history_window = NULL;
274
 
  GtkWidget *main_window = NULL;
275
 
 
276
 
  gchar *msg_reason = NULL;
277
 
  gchar *msg = NULL;
278
 
 
279
 
  main_window = GnomeMeeting::Process ()->GetMainWindow ();
280
 
  accounts_window = GnomeMeeting::Process ()->GetAccountsWindow ();
281
 
  history_window = GnomeMeeting::Process ()->GetHistoryWindow ();
282
 
 
283
 
  gnomemeeting_threads_enter ();
284
 
  /* Registering is ok */
285
 
  switch (r) {
286
 
 
287
 
  case SIP_PDU::Failure_BadRequest:
288
 
    msg_reason = g_strdup (_("Bad request"));
289
 
    break;
290
 
 
291
 
  case SIP_PDU::Failure_PaymentRequired:
292
 
    msg_reason = g_strdup (_("Payment required"));
293
 
    break;
294
 
 
295
 
  case SIP_PDU::Failure_UnAuthorised:
296
 
  case SIP_PDU::Failure_Forbidden:
297
 
    msg_reason = g_strdup (_("Forbidden"));
298
 
    break;
299
 
 
300
 
  case SIP_PDU::Failure_RequestTimeout:
301
 
    msg_reason = g_strdup (_("Timeout"));
302
 
    break;
303
 
 
304
 
  case SIP_PDU::Failure_Conflict:
305
 
    msg_reason = g_strdup (_("Conflict"));
306
 
    break;
307
 
 
308
 
  case SIP_PDU::Failure_TemporarilyUnavailable:
309
 
    msg_reason = g_strdup (_("Temporarily unavailable"));
310
 
    break;
311
 
    
312
 
  case SIP_PDU::Failure_NotAcceptable:
313
 
    msg_reason = g_strdup (_("Not Acceptable"));
314
 
    break;
315
 
 
316
 
  default:
317
 
    msg_reason = g_strdup (_("Registration failed"));
318
 
  }
319
 
 
320
 
  if (wasRegistering) {
321
 
 
322
 
    msg = g_strdup_printf (_("Registration failed: %s"), 
323
 
                           msg_reason);
324
 
 
325
 
    gm_accounts_window_update_account_state (accounts_window, 
326
 
                                             FALSE,
327
 
                                             (const char *) host, 
328
 
                                             (const char *) user, 
329
 
                                             _("Registration failed"),
330
 
                                             NULL);
331
 
  }
332
 
  else {
333
 
 
334
 
    msg = g_strdup_printf (_("Unregistration failed: %s"), 
335
 
                           msg_reason);
336
 
 
337
 
    gm_accounts_window_update_account_state (accounts_window, 
338
 
                                             FALSE,
339
 
                                             (const char *) host, 
340
 
                                             (const char *) user, 
341
 
                                             _("Unregistration failed"),
342
 
                                             NULL);
343
 
  }
344
 
 
345
 
  gm_history_window_insert (history_window, "%s", msg);
346
 
  gm_main_window_push_message (main_window, "%s", msg);
347
 
  gnomemeeting_threads_leave ();
348
 
 
349
 
  /* Signal the SIP Endpoint */
350
 
  SIPEndPoint::OnRegistrationFailed (host, user, r, wasRegistering);
351
 
 
352
 
 
353
 
  g_free (msg);
354
 
}
355
 
 
356
 
 
357
 
BOOL 
358
 
GMSIPEndpoint::OnIncomingConnection (OpalConnection &connection)
359
 
{
360
 
  PSafePtr<OpalConnection> con = NULL;
361
 
  PSafePtr<OpalCall> call = NULL;
362
 
 
363
 
  gchar *forward_host = NULL;
364
 
 
365
 
  IncomingCallMode icm;
366
 
  gboolean busy_forward = FALSE;
367
 
  gboolean always_forward = FALSE;
368
 
  int no_answer_timeout = FALSE;
369
 
 
370
 
  BOOL res = FALSE;
371
 
 
372
 
  int reason = 0;
373
 
 
374
 
  PTRACE (3, "GMSIPEndpoint\tIncoming connection");
375
 
 
376
 
  gnomemeeting_threads_enter ();
377
 
  forward_host = gm_conf_get_string (SIP_KEY "forward_host");
378
 
  busy_forward = gm_conf_get_bool (CALL_FORWARDING_KEY "forward_on_busy");
379
 
  always_forward = gm_conf_get_bool (CALL_FORWARDING_KEY "always_forward");
380
 
  icm =
381
 
    (IncomingCallMode) gm_conf_get_int (CALL_OPTIONS_KEY "incoming_call_mode");
382
 
  no_answer_timeout =
383
 
    gm_conf_get_int (CALL_OPTIONS_KEY "no_answer_timeout");
384
 
  gnomemeeting_threads_leave ();
385
 
 
386
 
  call = endpoint.FindCallWithLock (endpoint.GetCurrentCallToken());
387
 
  if (call)
388
 
    con = endpoint.GetConnection (call, TRUE);
389
 
  if ((con && con->GetIdentifier () == connection.GetIdentifier())) {
390
 
    return TRUE;
391
 
  }
392
 
  
393
 
  if (icm == DO_NOT_DISTURB)
394
 
    reason = 1;
395
 
  else if (forward_host && always_forward)
396
 
    reason = 2; // Forward
397
 
  /* We are in a call */
398
 
  else if (endpoint.GetCallingState () != GMManager::Standby) {
399
 
 
400
 
    if (forward_host && busy_forward)
401
 
      reason = 2; // Forward
402
 
    else
403
 
      reason = 1; // Reject
404
 
  }
405
 
  else if (icm == AUTO_ANSWER)
406
 
    reason = 4; // Auto Answer
407
 
  else
408
 
    reason = 0; // Ask the user
409
 
 
410
 
  if (reason == 0)
411
 
    NoAnswerTimer.SetInterval (0, PMIN (no_answer_timeout, 60));
412
 
 
413
 
  res = endpoint.OnIncomingConnection (connection, reason, forward_host);
414
 
 
415
 
  g_free (forward_host);
416
 
 
417
 
  return res;
418
 
}
419
 
 
420
 
 
421
 
void 
422
 
GMSIPEndpoint::OnMWIReceived (const PString & remoteAddress,
423
 
                              const PString & user,
424
 
                              SIPMWISubscribe::MWIType type,
425
 
                              const PString & msgs)
426
 
{
427
 
  GMManager *ep = NULL;
428
 
  GMPCSSEndpoint *pcssEP = NULL;
429
 
  
430
 
  GtkWidget *main_window = NULL;
431
 
  GtkWidget *accounts_window = NULL;
432
 
 
433
 
  int total = 0;
434
 
  
435
 
  if (endpoint.GetMWI (remoteAddress, user) != msgs) {
436
 
 
437
 
    total = endpoint.GetMWI ().AsInteger ();
438
 
 
439
 
    /* Update UI */
440
 
    endpoint.AddMWI (remoteAddress, user, msgs);
441
 
 
442
 
    main_window = GnomeMeeting::Process ()->GetMainWindow ();
443
 
    accounts_window = GnomeMeeting::Process ()->GetAccountsWindow ();
444
 
 
445
 
    gnomemeeting_threads_enter ();
446
 
    gm_main_window_push_message (main_window, 
447
 
                                 endpoint.GetMissedCallsNumber (), 
448
 
                                 endpoint.GetMWI ());
449
 
    gm_accounts_window_update_account_state (accounts_window,
450
 
                                             FALSE,
451
 
                                             remoteAddress,
452
 
                                             user,
453
 
                                             NULL,
454
 
                                             (const char *) msgs);
455
 
    gnomemeeting_threads_leave ();
456
 
 
457
 
    /* Sound event if new voice mail */
458
 
    if (endpoint.GetMWI ().AsInteger () > total) {
459
 
 
460
 
      ep = GnomeMeeting::Process ()->GetManager ();
461
 
      pcssEP = ep->GetPCSSEndpoint ();
462
 
      pcssEP->PlaySoundEvent ("new_voicemail_sound");
463
 
    }
464
 
  }
465
 
}
466
 
 
467
 
 
468
 
void 
469
 
GMSIPEndpoint::OnReceivedMESSAGE (OpalTransport & transport,
470
 
                                  SIP_PDU & pdu)
471
 
{
472
 
  PString *last = NULL;
473
 
  PString *val = NULL;
474
 
  
475
 
  PString from = pdu.GetMIME().GetFrom();   
476
 
  PINDEX j = from.Find (';');
477
 
  if (j != P_MAX_INDEX)
478
 
    from = from.Left(j); // Remove all parameters
479
 
  j = from.Find ('<');
480
 
  if (j != P_MAX_INDEX && from.Find ('>') == P_MAX_INDEX)
481
 
    from += '>';
482
 
 
483
 
  PWaitAndSignal m(msgDataMutex);
484
 
  last = msgData.GetAt (SIPURL (from).AsString ());
485
 
  if (!last || *last != pdu.GetMIME ().GetCallID ()) {
486
 
 
487
 
    val = new PString (pdu.GetMIME ().GetCallID ());
488
 
    msgData.SetAt (SIPURL (from).AsString (), val);
489
 
    OnMessageReceived(from, pdu.GetEntityBody());
490
 
  }
491
 
}
492
 
 
493
 
 
494
 
void 
495
 
GMSIPEndpoint::OnMessageReceived (const SIPURL & from,
496
 
                                  const PString & body)
497
 
{
498
 
  GMManager *ep = NULL;
499
 
  GMPCSSEndpoint *pcssEP = NULL;
500
 
 
501
 
  GtkWidget *chat_window = NULL;
502
 
  GtkWidget *statusicon = NULL;
503
 
 
504
 
  gboolean chat_window_visible = FALSE;
505
 
  
506
 
  chat_window = GnomeMeeting::Process ()->GetChatWindow ();
507
 
  statusicon = GnomeMeeting::Process ()->GetStatusicon ();
508
 
 
509
 
  SIPEndPoint::OnMessageReceived (from, body);
510
 
 
511
 
  gnomemeeting_threads_enter ();
512
 
  gm_text_chat_window_insert (chat_window, from.AsString (), 
513
 
                              from.GetDisplayName (), (const char *) body, 1);  
514
 
  chat_window_visible = gnomemeeting_window_is_visible (chat_window);
515
 
  gnomemeeting_threads_leave ();
516
 
 
517
 
  if (!chat_window_visible) {
518
 
   
519
 
    gnomemeeting_threads_enter ();
520
 
    gm_statusicon_signal_message (statusicon, TRUE);
521
 
    gnomemeeting_threads_leave ();
522
 
 
523
 
    ep = GnomeMeeting::Process ()->GetManager ();
524
 
    pcssEP = ep->GetPCSSEndpoint ();
525
 
    pcssEP->PlaySoundEvent ("new_message_sound");
526
 
  }
527
 
}
528
 
 
529
 
 
530
 
void 
531
 
GMSIPEndpoint::OnMessageFailed (const SIPURL & messageUrl,
532
 
                                SIP_PDU::StatusCodes reason)
533
 
{
534
 
  GtkWidget *chat_window = NULL;
535
 
  gchar *msg = NULL;
536
 
 
537
 
  chat_window = GnomeMeeting::Process ()->GetChatWindow ();
538
 
  
539
 
  switch (reason) {
540
 
 
541
 
  case SIP_PDU::Failure_NotFound:
542
 
    msg = g_strdup (_("Error: User not found"));
543
 
    break;
544
 
 
545
 
  case SIP_PDU::Failure_TemporarilyUnavailable:
546
 
    msg = g_strdup (_("Error: User offline"));
547
 
    break;
548
 
 
549
 
  case SIP_PDU::Failure_UnAuthorised:
550
 
  case SIP_PDU::Failure_Forbidden:
551
 
    msg = g_strdup (_("Error: Forbidden"));
552
 
    break;
553
 
 
554
 
  case SIP_PDU::Failure_RequestTimeout:
555
 
    msg = g_strdup (_("Error: Timeout"));
556
 
    break;
557
 
 
558
 
  default:
559
 
    msg = g_strdup (_("Error: Failed to transmit message"));
560
 
  }
561
 
 
562
 
  gnomemeeting_threads_enter ();
563
 
  gm_text_chat_window_insert (chat_window, messageUrl.AsString (), 
564
 
                              NULL, msg, 2);
565
 
  gnomemeeting_threads_leave ();
566
 
 
567
 
  g_free (msg);
568
 
}
569
 
      
570
 
 
571
 
int
572
 
GMSIPEndpoint::GetRegisteredAccounts ()
573
 
{
574
 
  return SIPEndPoint::GetRegistrationsCount ();
575
 
}
576
 
 
577
 
 
578
 
SIPURL
579
 
GMSIPEndpoint::GetRegisteredPartyName (const PString & host)
580
 
{
581
 
  GmAccount *account = NULL;
582
 
 
583
 
  PString url;
584
 
  SIPURL registration_address;
585
 
 
586
 
  PSafePtr<SIPInfo> info = activeSIPInfo.FindSIPInfoByDomain(host, SIP_PDU::Method_REGISTER, PSafeReadOnly);
587
 
 
588
 
  if (info != NULL)
589
 
    registration_address = info->GetRegistrationAddress();
590
 
 
591
 
  account = gnomemeeting_get_default_account ("SIP");
592
 
  if (account && account->enabled) {
593
 
 
594
 
    if (info == NULL || registration_address.GetHostName () == account->host) {
595
 
 
596
 
      if (PString(account->username).Find("@") == P_MAX_INDEX)
597
 
        url = PString (account->username) + "@" + PString (account->host);
598
 
      else
599
 
        url = PString (account->username);
600
 
 
601
 
      return url;
602
 
    }
603
 
  }
604
 
  if (info != NULL) 
605
 
    return registration_address;
606
 
  else 
607
 
    return SIPEndPoint::GetDefaultRegisteredPartyName (); 
608
 
}
609
 
 
610
 
 
611
 
void 
612
 
GMSIPEndpoint::OnEstablished (OpalConnection &connection)
613
 
{
614
 
  NoAnswerTimer.Stop ();
615
 
 
616
 
  PTRACE (3, "GMSIPEndpoint\t SIP connection established");
617
 
  SIPEndPoint::OnEstablished (connection);
618
 
}
619
 
 
620
 
 
621
 
void 
622
 
GMSIPEndpoint::OnReleased (OpalConnection &connection)
623
 
{
624
 
  NoAnswerTimer.Stop ();
625
 
 
626
 
  PTRACE (3, "GMSIPEndpoint\t SIP connection released");
627
 
  SIPEndPoint::OnReleased (connection);
628
 
}
629
 
 
630
 
 
631
 
void
632
 
GMSIPEndpoint::OnNoAnswerTimeout (PTimer &,
633
 
                                  INT) 
634
 
{
635
 
  gchar *forward_host = NULL;
636
 
  gboolean forward_on_no_answer = FALSE;
637
 
  
638
 
  if (endpoint.GetCallingState () == GMManager::Called) {
639
 
   
640
 
    gnomemeeting_threads_enter ();
641
 
    forward_host = gm_conf_get_string (SIP_KEY "forward_host");
642
 
    forward_on_no_answer = 
643
 
      gm_conf_get_bool (CALL_FORWARDING_KEY "forward_on_no_answer");
644
 
    gnomemeeting_threads_leave ();
645
 
 
646
 
    if (forward_host && forward_on_no_answer) {
647
 
      
648
 
      PSafePtr<OpalCall> call = 
649
 
        endpoint.FindCallWithLock (endpoint.GetCurrentCallToken ());
650
 
      PSafePtr<OpalConnection> con = 
651
 
        endpoint.GetConnection (call, TRUE);
652
 
    
653
 
      con->ForwardCall (forward_host);
654
 
    }
655
 
    else
656
 
      ClearAllCalls (OpalConnection::EndedByNoAnswer, FALSE);
657
 
 
658
 
    g_free (forward_host);
659
 
  }
660
 
}
661
 
 
662