forked from VoIP-co-uk/sftf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SipReply.py
70 lines (65 loc) · 2.28 KB
/
SipReply.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#
# Copyright (C) 2004 SIPfoundry Inc.
# Licensed by SIPfoundry under the GPL license.
#
# Copyright (C) 2004 SIP Forum
# Licensed to SIPfoundry under a Contributor Agreement.
#
#
# This file is part of SIP Forum Test Framework.
#
# SIP Forum Test Framework is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# SIP Forum Test Framework is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SIP Forum Test Framework; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: SipReply.py,v 1.7 2004/03/19 18:37:25 lando Exp $
#
from SipMessage import SipMessage
class SipReply (SipMessage):
"""This class inherits all code from SipMessage and implements all
required functions to handle SIP reply messages.
"""
def __init__(self):
SipMessage.__init__(self)
self.isRequest = False
self.code = None
self.reason = None
self.request = None
def __str__(self):
return '[' + SipMessage.__str__(self) \
+ ', code:\'' + str(self.code) + '\', ' \
+ 'reason:\'' + str(self.reason) + '\' ' \
+ 'request:\'' + str(self.request) + '\']'
def parseFirstLine(self, fLine):
"""Tries to parse the given first line from the message. Returns
True on success and False on error.
"""
try:
if (fLine.lower().startswith("sip")):
index = fLine.index('/')
self.protocol = fLine[0:index]
fLine = fLine[index+1:]
index = fLine.index(' ')
self.version = fLine[0:index]
fLine = fLine[index+1:]
self.code = int(fLine[0:3])
self.reason = fLine[4:].replace("\n", "").replace("\r", "").rstrip()
return True
else:
return False
except:
return False
def createFirstLine(self):
"""Creates and inserts the first line of the reply into the event.
"""
self.event.headers.insert(0, self.protocol + "/" + str(self.version) + " " + str(self.code) + " " + self.reason + "\r\n")