1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 *
16 * Author : Richard GAYRAUD - 04 Nov 2003
17 * Olivier Jacques
18 * From Hewlett Packard Company.
19 * Shriram Natarajan
20 * Peter Higginson
21 * Eric Miller
22 * Venkatesh
23 * Enrico Hartung
24 * Nasir Khan
25 * Lee Ballard
26 * Guillaume Teissier from FTR&D
27 * Wolfgang Beck
28 * Venkatesh
29 * Vlad Troyanker
30 * Charles P Wright from IBM Research
31 * Amit On from Followap
32 * Jan Andres from Freenet
33 * Ben Evans from Open Cloud
34 * Marc Van Diest from Belgacom
35 * Michael Dwyer from Cibation
36 */
37
38 #include <iterator>
39 #include <algorithm>
40 #include <fstream>
41 #include <iostream>
42 #include <sys/types.h>
43 #include <sys/wait.h>
44
45 #ifdef PCAPPLAY
46 #include "send_packets.h"
47 #endif
48 #include "sipp.hpp"
49 #include "deadcall.hpp"
50 #include "assert.h"
51
52 /* Defined in call.cpp. */
53 extern timewheel paused_calls;
54
deadcall(const char * id,const char * reason)55 deadcall::deadcall(const char *id, const char *reason) : listener(id, true)
56 {
57 this->expiration = clock_tick + deadcall_wait;
58 this->reason = strdup(reason);
59 setPaused();
60 }
61
~deadcall()62 deadcall::~deadcall()
63 {
64 free(reason);
65 }
66
process_incoming(char * msg,struct sockaddr_storage *)67 bool deadcall::process_incoming(char * msg, struct sockaddr_storage * /*src*/)
68 {
69 char buffer[MAX_HEADER_LEN];
70
71 CStat::globalStat(CStat::E_DEAD_CALL_MSGS);
72
73 setRunning();
74
75 snprintf(buffer, MAX_HEADER_LEN, "Dead call %s (%s)", id, reason);
76
77 WARNING("%s, received '%s'", buffer, msg);
78
79 TRACE_MSG("-----------------------------------------------\n"
80 "Dead call %s received a %s message:\n\n%s\n",
81 id, TRANSPORT_TO_STRING(transport), msg);
82
83 expiration = clock_tick + deadcall_wait;
84 return run();
85 }
86
process_twinSippCom(char * msg)87 bool deadcall::process_twinSippCom(char * msg)
88 {
89 CStat::globalStat(CStat::E_DEAD_CALL_MSGS);
90 TRACE_MSG("Received twin message for dead (%s) call %s:%s\n", reason, id, msg);
91 return true;
92 }
93
run()94 bool deadcall::run()
95 {
96 if (clock_tick > expiration) {
97 delete this;
98 return false;
99 } else {
100 setPaused();
101 return true;
102 }
103 }
104
wake()105 unsigned int deadcall::wake()
106 {
107 return expiration;
108 }
109
110 /* Dump call info to error log. */
dump()111 void deadcall::dump()
112 {
113 WARNING("%s: Dead Call (%s) expiring at %lu", id, reason, expiration);
114 }
115