[Approved] Ignore whitespace when parsing SOAP messages (1 Viewer)

McGoober

Retired Team Member
  • Premium Supporter
  • August 13, 2006
    122
    105
    Cambridge, UK
    Home Country
    United Kingdom United Kingdom
    When parsing SOAP messages from UPNP subsystem ignore whitespace.
    Found this whilst attempting to use Device Spy from "UPNP Developer Tools".
    Another code change is also required to get this program to work with MediaPortal UPNP, since no USER-AGENT header is set by this client, which isn't included with this patch. I wanted to start small :)

    Whoops... noticed that I was using old SVN, fortunately the file hadn't changed in GIT, phew.
     

    Attachments

    • 0001-Fix-for-SOAP-messages-that-contain-whitespace.patch
      1,023 bytes

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    AW: Ignore whitespace when parsing SOAP messages

    :D for your patch! Any improvements to UPNP compatibility are very welcome :)

    we will evaluate it and I'm quite sure it will be included ;)
     

    McGoober

    Retired Team Member
  • Premium Supporter
  • August 13, 2006
    122
    105
    Cambridge, UK
    Home Country
    United Kingdom United Kingdom
    Thanks morpheus_xx, I'm doing a bit of investigation around UPNP, specifically MediaServer compatibility with DLNA devices. I just wanted to be sure that the process I'm going through for patches is the correct one.

    Little background... I recently bought a DLNA compliant TV, and wanted some open source software that could serve up content to it. I tried Serviio but it doesn't seem to work correctly, hogs way to much processor time (increasing the temp of my CPU, etc), and generally rubbish. MediaPortal seems to be the way forward, but is missing the DLNA compliant stuff, so I thought it high time to roll up the sleeves.
     

    Albert

    MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    45
    Freiburg im Breisgau, Germany
    Home Country
    Germany Germany
    AW: Ignore whitespace when parsing SOAP messages

    When parsing SOAP messages from UPNP subsystem ignore whitespace.
    Found this whilst attempting to use Device Spy from "UPNP Developer Tools".
    Another code change is also required to get this program to work with MediaPortal UPNP, since no USER-AGENT header is set by this client, which isn't included with this patch. I wanted to start small :)

    Whoops... noticed that I was using old SVN, fortunately the file hadn't changed in GIT, phew.

    Hi McGoober, thanks very much for the patch!
    In fact, I didn't know why the device spy doesn't recognize my UPnP implementation.
    I'm currently in vacation. When I'm back, I'll check the patch.
     

    Albert

    MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    45
    Freiburg im Breisgau, Germany
    Home Country
    Germany Germany
    AW: Ignore whitespace when parsing SOAP messages

    McGoober, I just committed and pushed your change to the master branch.

    About your other comment: Where is no USER-AGENT header present but should be sent? Can you specify your statement a bit please? If I understand you correctly, the UPnP developer tools don't send that header field but MP2 tries to read it, is that correct? Or is it the other way, MP2 doesn't send that field but the UPnP developer tools need it? Can you tell me in which of the messages and maybe in which of the UPnP sub protocols (SSDP, SOAP, GENA)? And in the control point part or in the device part of MP2?
    Could you maybe point me to the point in MP2 code and/or to the code in the UPnP developer tools where the communication fails?

    Thanks!
    Albert
     

    McGoober

    Retired Team Member
  • Premium Supporter
  • August 13, 2006
    122
    105
    Cambridge, UK
    Home Country
    United Kingdom United Kingdom
    Hey Albert, I was going to submit another patch for this once I understood according to the UPNP specs, but yeah, the UPNP developer tools don't set a USER-AGENT header. I suspect this is because UPNP/1.0 doesn't specify the need for USER-AGENT, however UPNP/1.1 does. I guess this means that we can safely assume that no USER-AGENT = UPNP/1.0.

    Around line 353 of UPNP/Infrastructure/Dv/UPNPServer.cs you extract the version information from the USER-AGENT header, but if one doesn't exist we get an null pointer exception thrown from ParserHelper.ParseUserAgentUPnP1MinorVersion() due to calling Split on a null string object.

    My current private fix works by setting minorVersion initially to 0 and adding a check to the if for a null userAgentStr. However an equally valid fix would be to patch ParserHelper.ParseUserAgentUPnP1MinorVersion() to accept null for userAgentStr.

    Which do you fancy? :)

    Hope this helps.
     

    Albert

    MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    45
    Freiburg im Breisgau, Germany
    Home Country
    Germany Germany
    AW: Ignore whitespace when parsing SOAP messages

    Thanks McGoober, I just tested that fix and I think you're right, in case a UPnP 1.0 control point sends messages, my code really threw a NRE. I just fixed both pieces of code; In UPnPServer.cs #351, I added a check for string.IsNullOrEmpty(userAgentStr) and I patched the ParserHelper.ParseUserAgentUPnP1MinorVersion method to return false if a null value is passed. But the DeviceSpy still doesn't find my MP2 client :-/
    Line 351 in UPnPServer.cs handles POST UPnP control messages. But I guess something goes wrong earlier in the advertisement or in the description phase.
    Does your DeviceSpy find MP2 in your network?
    My fixes are not pushed to our public git repository yet.
    I use DeviceSpy Version 0.0.52.
     

    McGoober

    Retired Team Member
  • Premium Supporter
  • August 13, 2006
    122
    105
    Cambridge, UK
    Home Country
    United Kingdom United Kingdom
    Yeah I found this... In the end I used another computer on the same network, which caused DeviceSpy throws up a bunch of open dialogs looking for reference files to XMLSchemas for various things, but closing all those allows mediaportal to be shown.

    I did a bunch of debugging to try and find out why, but drew a blank.
     

    Albert

    MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    45
    Freiburg im Breisgau, Germany
    Home Country
    Germany Germany
    AW: Ignore whitespace when parsing SOAP messages

    When I debug MP2, I see that when DeviceSpy starts, it asks MP2 for its description documents, so the advertisement process seems to work. MP2 then delivers description documents which seem ok to me, I extracted and attached the returned description documents.

    I guess as a next step, we should debug DeviceSpy to find out why it doesn't recognize MP2.
     

    Attachments

    • MP2-UPnP-root-device-description.xml
      2.1 KB
    • MP2-UPnP-clientcontroller-service-description.xml
      1.9 KB
    • MP2-UPnP-resourceinformation-service-description.xml
      10.2 KB

    McGoober

    Retired Team Member
  • Premium Supporter
  • August 13, 2006
    122
    105
    Cambridge, UK
    Home Country
    United Kingdom United Kingdom
    Right, I've just had sometime to debug. DeviceSpy seems to be falling over two things, but both are having the same effect.

    The first is that the xmlns:xsi namespace is being added to all scpd documents.
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    Line 220: UPnP/Infrastructure/Dv/DeviceTree/DvService.cs
    This namespace for scpd documents isn't mentioned in the UPNP/1.1 or 1.0 specs and probably shouldn't be there.

    The second is that all extended data types used in the MediaPortal upnp services add extra namespaces (xmlns:dt?) to the scpd documents.

    In both of these cases DeviceSpy attempts to load the schema for all extra namespaces, but will only attempt to load from the file system as there is a TODO comment in the code where the network loading code would go. The part that really doesn't work and seems to be a bug in the DeviceSpy program is that it attempts to show a fileopen dialog to load the schema from the file system. This works fine on Windows XP, but the call to OLE fails on Windows 7 because an exception is thrown stating that calls to the OLE object aren't allowed on the current thread. This means DeviceSpy never shows the dialog and just throws the device away.

    I removed line 220 for xsi namespace above and sure enough my new upnp device shows up in DeviceSpy, but I'm not using extended data types in my device. MediaPortal's device still isn't shown. I guess we need to look into whether the xmlns:dt? namespaces are being added to the scpd documents correctly, I haven't looked into this yet.
     

    Users who are viewing this thread

    Top Bottom