Skip to content

Commit 46d4cee

Browse files
authored
Merge pull request #82 from bdraco/no_action
Handle no action being present in the SOAP message
2 parents 9317897 + 76d3073 commit 46d4cee

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

wsdiscovery/message.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
from .actions import *
66
from xml.dom import minidom
77

8+
import logging
9+
10+
logger = logging.getLogger(__name__)
811

912
def createSOAPMessage(env):
1013
"serialize SOAP envelopes into XML strings"
@@ -27,15 +30,20 @@ def parseSOAPMessage(data, ipAddr):
2730
"deserialize XML message strings into SOAP envelope objects"
2831
try:
2932
dom = minidom.parseString(data)
30-
except Exception:
31-
#print('Failed to parse message from %s\n"%s": %s' % (ipAddr, data, ex), file=sys.stderr)
33+
except Exception as ex:
34+
logger.debug('Failed to parse message from %s\n%s: %s', ipAddr, data, ex)
3235
return None
3336

3437
if dom.getElementsByTagNameNS(NS_SOAPENV, "Fault"):
35-
#print('Fault received from %s %s:' % (ipAddr, data), file=sys.stderr)
38+
logger.debug('Fault received from %s: %s', ipAddr, data)
39+
return None
40+
41+
actions = dom.getElementsByTagNameNS(NS_ADDRESSING, "Action")
42+
if len(actions) == 0:
43+
logger.warning('No action received from %s: %s', ipAddr, data)
3644
return None
3745

38-
soapAction = dom.getElementsByTagNameNS(NS_ADDRESSING, "Action")[0].firstChild.data.strip()
46+
soapAction = actions[0].firstChild.data.strip()
3947
if soapAction == NS_ACTION_PROBE:
4048
return parseProbeMessage(dom)
4149
elif soapAction == NS_ACTION_PROBE_MATCH:

0 commit comments

Comments
 (0)