Skip to content

Commit

Permalink
Merge pull request #14 from pbertera/development
Browse files Browse the repository at this point in the history
  • Loading branch information
pbertera committed Jun 8, 2015
2 parents 46fe1b0 + 8d4a1a8 commit c84187e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
43 changes: 27 additions & 16 deletions proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,36 +161,45 @@ def changeRequestUri(self):
else:
self.server.main_logger.debug("SIP: URI not found in Registrar: %s leaving the URI unchanged" % uri)

def removeHeader(self, regex):
def removeHeader(self, regex, data=None):
"""
remove a SIP header.
- `regex`contains the regex to extract the header
- if `data` is defined the `regex`is searched into data, otherwise in self.data
"""
if data == None:
read_data = self.data
else:
read_data = data
self.server.main_logger.debug("SIP: Removing header with regex %s" % regex.pattern)
data = []
for line in self.data:
for line in read_data:
if not regex.search(line):
data.append(line)
else:
self.server.main_logger.debug("SIP: Removed %s" % line)
return data

def removeMaxForward(self):
return self.removeHeader(rx_maxforward)
def removeMaxForward(self, data=None):
return self.removeHeader(rx_maxforward, data)

def removeRouteHeader(self):
return self.removeHeader(rx_route)
def removeRouteHeader(self, data=None):
return self.removeHeader(rx_route, data)

def removeContact(self):
return self.removeHeader(rx_contact)
def removeContact(self, data=None):
return self.removeHeader(rx_contact, data)

def removeContentType(self):
return self.removeHeader(rx_contenttype)
def removeContentType(self, data=None):
return self.removeHeader(rx_contenttype, data)

def removeUserAgent(self):
return self.removeHeader(rx_useragent)
def removeUserAgent(self, data=None):
return self.removeHeader(rx_useragent, data)

def removeSessionExpires(self):
return self.removeHeader(rx_sessionexpires)
def removeSessionExpires(self, data=None):
return self.removeHeader(rx_sessionexpires, data)

def removeSupported(self):
return self.removeHeader(rx_supported)
def removeSupported(self, data=None):
return self.removeHeader(rx_supported, data)

def removeContentDisposition(self):
return self.removeHeader(rx_contentdisposition)
Expand Down Expand Up @@ -473,7 +482,9 @@ def processInvite(self):
self.changeRequestUri()
self.data = self.addTopVia()
data = self.removeRouteHeader()
#data = self.removeSupported(data)
data.insert(1, self.server.recordroute)
#data.insert(2, "Route: <sip:%s;transport=UDP;lr>" % destination)
text = string.join(data,"\r\n")
self.sendTo(text , claddr, socket)
self.server.main_logger.debug("SIP: Forwarding INVITE to %s:%d" % (claddr[0], claddr[1]))
Expand Down
7 changes: 4 additions & 3 deletions pypxe/tftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def __init__(self, mainsock, parent):
self.fh = None
self.netboot_directory = parent.netboot_directory
self.filename = ''
self.wrap = -1
self.wrap = 0
self.arm_wrap = False

# message from the main socket
self.handle()
Expand All @@ -53,6 +54,7 @@ def send_block(self):
Sends the next block of data, setting the timeout and retry
variables accordingly.
'''
self.fh.seek(self.blksize * (self.block - 1))
data = self.fh.read(self.blksize)
# opcode 3 == DATA, wraparound block number
response = struct.pack('!HH', 3, self.block % 65536)
Expand Down Expand Up @@ -202,7 +204,7 @@ def handle(self):
elif opcode == 4:
[block] = struct.unpack('!H', self.message[2:4])
a = block + self.wrap * 65536
if block == 0:
if block == 0 and self.arm_wrap:
self.wrap += 1
if block < self.block % 65536:
self.logger.warning('Ignoring duplicated ACK received for block {0}'.format(self.block))
Expand Down Expand Up @@ -285,7 +287,6 @@ def listen(self):
for client in self.ongoing:
if client.no_ack():
self.logger.warning("Retransmission of block {0}".format(client.block))
client.fh.seek(-client.blksize, 1)
client.send_block()
# if we have run out of retries, kill the client
for client in self.ongoing:
Expand Down

0 comments on commit c84187e

Please sign in to comment.