[fixed] UPNP fails when USER-AGENT is comma+space separated (1 Viewer)

McGoober

Retired Team Member
  • Premium Supporter
  • August 13, 2006
    122
    105
    Cambridge, UK
    Home Country
    United Kingdom United Kingdom
    Found when using MediaConnect (iPhone app from app store) and my DLNA UPNP plugin.
    MediaConnect POST's with the following USER-AGENT HTTP header

    USER-AGENT: iPhoneOS/5.0.1, UPnP/1.0, MediaConnect/2.0

    According to HTTP 1.1 RFC - User-Agent section. (HTTP/1.1: Header Field Definitions)
    The comma isn't used when separating product tokens, but is used for separating other field tokens, which is where possible spec confusion has occurred.

    The failure occurs in UPnP/Infrastructure/Common/UPnPVersion.cs in method TryParse()
    Once the string has been split up we end up processing the token as follows...
    versionStr = "UPnP/1.0,"

    This causes a problem with the following if...

    if (!int.TryParse(versionStr.Substring(dotIndex + 1), out verMin))
    return false;

    Int.TryParse gets given "0," and throws an exception. My temp fix for this is as follows...

    if (!int.TryParse(versionStr.Substring(dotIndex + 1).TrimEnd(','), out verMin))
    return false;

    It's crude, but works for now. A better fix is probably needed.
     

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    AW: UPNP fails when USER-AGENT is comma+space separated

    I can confirm this issue: I have here a Buffalo LinkStation with an UPnP/AV server that sends the header
    Code:
    Linux/2.x.x, UPnP/1.0, pvConnect UPnP SDK/1.0

    I suggest another solution inside SSDPClientController.cs, line 646:
    Code:
            string[] splitStrings = server.Contains(", ") ? new string[] { ", " } : new string[] { " " };
            string[] versionInfos = server.Split(splitStrings, StringSplitOptions.RemoveEmptyEntries);
    This checks if the ", " is used for separator and uses it as valid split string. Your version would not deal well with spaces inside the ", " separated values (see "pvConnect UPnP SDK/1.0", would be splitted as well)
     

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    AW: UPNP fails when USER-AGENT is comma+space separated

    I pushed the changes to "dev" branch, can you confirm that this is fixed properly?
     

    Albert

    MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    46
    Freiburg im Breisgau, Germany
    Home Country
    Germany Germany
    AW: UPNP fails when USER-AGENT is comma+space separated

    I would like to change in SSDPClientController.cs:

    Code:
            string[] splitStrings = server.Contains(", ") ? new string[] { ", " } : new string[] { " " };
            string[] versionInfos = server.Split(splitStrings, StringSplitOptions.RemoveEmptyEntries);

    to this:

    Code:
            string[] versionInfos = server.Split(new char[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);

    Can you both (McGoober and morpheus_xx) please confirn that it works?
    Thanks!
     

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,073
    7,459
    Home Country
    Germany Germany
    AW: UPNP fails when USER-AGENT is comma+space separated

    this was my first try, but it is not giving the correct results. I.e.:
    Linux/2.x.x, UPnP/1.0, pvConnect UPnP SDK/1.0
    returns 5 header parts, besause the last part "pvConnect UPnP SDK/1.0" is splitted on spaces.

    The commited version results in only 3 parts, which is correct IMO
     

    Albert

    MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    46
    Freiburg im Breisgau, Germany
    Home Country
    Germany Germany
    AW: UPNP fails when USER-AGENT is comma+space separated

    It's no solution to search for ", ". What if another client uses a comma and two spaces? We can use a code which first looks for a comma in the whole string and if there is a comma, then use only the comma as separator. The result strings must then be trimmed.
     

    Albert

    MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    46
    Freiburg im Breisgau, Germany
    Home Country
    Germany Germany
    AW: UPNP fails when USER-AGENT is comma+space separated

    I think I'll use the variation I suggested above:

    Code:
            string[] versionInfos = server.Split(new char[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);

    It doesn't matter if the other tokens are not parsed correctly as the only relevant token here is the UPnP/1.1 token
     

    McGoober

    Retired Team Member
  • Premium Supporter
  • August 13, 2006
    122
    105
    Cambridge, UK
    Home Country
    United Kingdom United Kingdom
    Thanks guys. I've just tested the change, but it hasn't worked as expected. I should probably have included the call stack for the exceptions.

    Code:
    [2012-01-01 22:12:36,685] [34038  ] [12       ] [WARN ] - GENAServerController: Error in event subscription
    UPnP.Infrastructure.UnsupportedRequestException: Unsupported USER-AGENT header entry 'iPhoneOS/5.0.1, UPnP/1.0, MediaConnect/2.0'
       at UPnP.Infrastructure.Utils.ParserHelper.ParseUserAgentUPnP1MinorVersion(String userAgentStr, Int32& minorVersion) in e:\Users\Jason Leonard\Work\MP2\dev\MediaPortal-2\MediaPortal\Source\Core\UPnP\Infrastructure\Utils\ParserHelper.cs:line 56
       at UPnP.Infrastructure.Dv.GENA.GENAServerController.HandleHTTPRequest(IHttpRequest request, IHttpClientContext context, EndpointConfiguration config) in e:\Users\Jason Leonard\Work\MP2\dev\MediaPortal-2\MediaPortal\Source\Core\UPnP\Infrastructure\Dv\GENA\GENAServerController.cs:line 338
    [2012-01-01 22:12:36,720] [34073  ] [12       ] [ERROR] - UPnPServer: Error handling HTTP request 'http://192.168.0.133:1686/upnphost/control/uuid:45f2c54d-8c0a-4736-aa04-e6f91cd45457/urn:schemas-upnp-org:service:ContentDirectory:1'
    UPnP.Infrastructure.UnsupportedRequestException: Unsupported USER-AGENT header entry 'iPhoneOS/5.0.1, UPnP/1.0, MediaConnect/2.0'
       at UPnP.Infrastructure.Utils.ParserHelper.ParseUserAgentUPnP1MinorVersion(String userAgentStr, Int32& minorVersion) in e:\Users\Jason Leonard\Work\MP2\dev\MediaPortal-2\MediaPortal\Source\Core\UPnP\Infrastructure\Utils\ParserHelper.cs:line 56
       at UPnP.Infrastructure.Dv.UPnPServer.HandleHTTPRequest(IHttpClientContext context, IHttpRequest request) in e:\Users\Jason Leonard\Work\MP2\dev\MediaPortal-2\MediaPortal\Source\Core\UPnP\Infrastructure\Dv\UPnPServer.cs:line 356

    These are the two exceptions I'm getting.
     

    Albert

    MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    46
    Freiburg im Breisgau, Germany
    Home Country
    Germany Germany
    AW: UPNP fails when USER-AGENT is comma+space separated

    Thanks McGoober. I'll check it tonight.
    Seems I forgot to remove that check+exception, which is obsolete now.
     

    Albert

    MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    46
    Freiburg im Breisgau, Germany
    Home Country
    Germany Germany
    AW: Re: UPNP fails when USER-AGENT is comma+space separated

    That stack trace does not fit to the newest version from yesterday evening, it's from the revision before. Did you check the dev branch or do you try the master branch?
    The latest fixes are only on the dev branch.

    Thanks guys. I've just tested the change, but it hasn't worked as expected. I should probably have included the call stack for the exceptions.

    Code:
    [2012-01-01 22:12:36,685] [34038  ] [12       ] [WARN ] - GENAServerController: Error in event subscription
    UPnP.Infrastructure.UnsupportedRequestException: Unsupported USER-AGENT header entry 'iPhoneOS/5.0.1, UPnP/1.0, MediaConnect/2.0'
       at UPnP.Infrastructure.Utils.ParserHelper.ParseUserAgentUPnP1MinorVersion(String userAgentStr, Int32& minorVersion) in e:\Users\Jason Leonard\Work\MP2\dev\MediaPortal-2\MediaPortal\Source\Core\UPnP\Infrastructure\Utils\ParserHelper.cs:line 56
       at UPnP.Infrastructure.Dv.GENA.GENAServerController.HandleHTTPRequest(IHttpRequest request, IHttpClientContext context, EndpointConfiguration config) in e:\Users\Jason Leonard\Work\MP2\dev\MediaPortal-2\MediaPortal\Source\Core\UPnP\Infrastructure\Dv\GENA\GENAServerController.cs:line 338
    [2012-01-01 22:12:36,720] [34073  ] [12       ] [ERROR] - UPnPServer: Error handling HTTP request 'http://192.168.0.133:1686/upnphost/control/uuid:45f2c54d-8c0a-4736-aa04-e6f91cd45457/urn:schemas-upnp-org:service:ContentDirectory:1'
    UPnP.Infrastructure.UnsupportedRequestException: Unsupported USER-AGENT header entry 'iPhoneOS/5.0.1, UPnP/1.0, MediaConnect/2.0'
       at UPnP.Infrastructure.Utils.ParserHelper.ParseUserAgentUPnP1MinorVersion(String userAgentStr, Int32& minorVersion) in e:\Users\Jason Leonard\Work\MP2\dev\MediaPortal-2\MediaPortal\Source\Core\UPnP\Infrastructure\Utils\ParserHelper.cs:line 56
       at UPnP.Infrastructure.Dv.UPnPServer.HandleHTTPRequest(IHttpClientContext context, IHttpRequest request) in e:\Users\Jason Leonard\Work\MP2\dev\MediaPortal-2\MediaPortal\Source\Core\UPnP\Infrastructure\Dv\UPnPServer.cs:line 356

    These are the two exceptions I'm getting.
     

    Users who are viewing this thread

    Top Bottom