I can't see your test program, Ian, (I wasn't subscribed to the mailing list 
in the time you sent the email unfortunatelly) but in my test program the
  "service:device-drivers:ftp://x3.bean.org/drivers/diskdrivers.drv";
  "service:device-drivers:http://www.bean.org/drivers/drivpak.drv";
  "service:weather.nasa:wtp://weather.nasa.com:12000"
  "service:weather.nasa:swtp://weather.nasa.com:12001"
  "service:chat.superchat://chat.superchat.com"
addresses are correctly accepted.

The "service:x.:/x" address is correctly rejected.

As I understand the http://tools.ietf.org/html/rfc2609#section-2.1, these 
addresses are IMHO invalid:
  "service:x-private.name.authority:protocol://address:8888"
  "service:x-my-fancy-service.norton.ian:http://this.is.my.server";
I don't see how could more than one '.' characters get between the first and 
second ':' character.

(As there is a ':' character between "service:" and "://", the first variant 
in <service-type> had to be used which is:
      <abstract-type> ":" <url-scheme>
  that is:
      <type-name> [ "." <naming-auth> ] ":" <url-scheme>
  that is:
      <resname> [ "." <resname> ] ":" <resname>
)

However if the multiple dots in <abstract-type> are commonly used, I'll update 
my patch to allow them.

Attaching my test program.

Thank you,
Michal Srb

> -----Original Message-----
> From: Ian Norton [mailto:inorton@...]
> Sent: Monday, December 19, 2011 1:30 AM
> To: John Calcote
> Subject: Re: [Openslp-devel] proposed patch for OpenSLP
> 
> Running this up in the attached test program I've not been able to find any
> addresses that are accepted.
> 
> According to the RFC, here are some valid addresses.
> 
> service:device-drivers:ftp://x3.bean.org/drivers/diskdrivers.drv
> service:device-drivers:http://www.bean.org/drivers/drivpak.drv
> 
> and the openslp docs
> 
> service:weather.nasa:wtp://weather.nasa.com:12000
> service:weather.nasa:swtp://weather.nasa.com:12001
> service:chat.superchat://chat.superchat.com
> 
> And going by how naming authority stuff goes. the following should be valid
> too:
> 
> service:x-private.name.authority:protocol://address:8888
> service:x-my-fancy-service.norton.ian:http://this.is.my.server
> 
> Regards
> 
> Ian
#include <string.h>
#include <ctype.h>
#include <assert.h>

#ifdef _WIN32
#else
#ifndef HAVE_STRNCASECMP
int
strncasecmp(const char *s1, const char *s2, size_t len)
{
    while ( *s1 && (*s1 == *s2 || tolower(*s1) == tolower(*s2)) )
    {
        len--;
        if(len == 0) return 0;
        s1++;
        s2++;
    }
    return(int) *(unsigned char *)s1 - (int) *(unsigned char *)s2;
}
#endif
#endif

int SLPCheckServiceUrlSyntax(const char * srvurl, size_t srvurllen)
{
    int curpos;
    int state;

    if(srvurllen < 8)
        return 1;

    if(strncasecmp(srvurl, "service:", 8))
        return 1;

    /* The service url ABNF as defined in section 2.1 in rfc 2609 can be simplified
     * into this form:
     *
     *   service: URL   =   "service:" resname [ "." resname ] [ ":" resname ] ":/" the-rest
     *   resname        =   ALPHA [ 1*(ALPHA / DIGIT / "+" / "-") ]
     *   the-rest    ; we don't check the rest
     *
     * Following code is simple state machine using this three states:
     *     "service:" resname [ "." resname ] [ ":" resname ] ":/" the-rest
     * state:         ^ 0           ^ 1             ^ 2
     */

    curpos = 8;
    for(state = 0; state < 3; state ++)
    {
        // Non-optional fist alpha character of resname:
        if(curpos >= srvurllen || !isalpha(srvurl[curpos]))
            return 1;

        // The rest of resname:
        for(; ; curpos ++)
        {
            if(curpos == srvurllen)
                return 1;

            if(srvurl[curpos] == '.' && state == 0)
                break;

            if(srvurl[curpos] == ':') {
                if(curpos + 1 < srvurllen && srvurl[curpos+1] == '/')
                    return 0;

                if(state == 0)
                    state ++;
                if(state == 1)
                    break;
            }

            if(!isalnum(srvurl[curpos]) && srvurl[curpos] != '-' && srvurl[curpos] != '+')
                return 1;
        }

        curpos ++;
    }

    return 0;
}

#define TEST(result, string) {\
  char* a = string; \
  assert(SLPCheckServiceUrlSyntax(a, strlen(a)) == result);\
}

int main(int argc, char** argv) {
    TEST(1, "service:x.:/x")

    TEST(0, "service:device-drivers:ftp://x3.bean.org/drivers/diskdrivers.drv";)
    TEST(0, "service:device-drivers:http://www.bean.org/drivers/drivpak.drv";)

    TEST(0, "service:weather.nasa:wtp://weather.nasa.com:12000")
    TEST(0, "service:weather.nasa:swtp://weather.nasa.com:12001")
    TEST(0, "service:chat.superchat://chat.superchat.com")

    TEST(1, "service:x-private.name.authority:protocol://address:8888")
    TEST(1, "service:x-my-fancy-service.norton.ian:http://this.is.my.server";)

//     return SLPCheckServiceUrlSyntax(argv[1], strlen(argv[1]));
    return 0;
}
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Openslp-devel mailing list
Openslp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openslp-devel

Reply via email to