Mailing List Archive

Validating a domain-spec.
I am stumbling here.

How can I validate a domain-spec?

Here's what PySPF does:

PAT_CHAR = r'%(%|_|-|(\{[^\}]*\}))'
RE_TOPLAB = re.compile(r'\.(?:[0-9a-z]*[a-z][0-9a-z]*|
[0-9a-z]+-[0-9a-z-]*[0-9a-z])\.?$|%s'
% PAT_CHAR, re.IGNORECASE)

if RE_TOPLAB.split(arg)[-1]:
raise PermError('Invalid domain found (use FQDN)', arg)

Simple, right? Except for this:

I can't reproduce this in C. I have been trying for hours, but translating
this into a POSIX regexp, and then using my limited implementation of split()
just doesn't seem to cut it (either the translation or my split() is surely
wrong).

Anyone knows where I can find a nice, simple, C implementation of this
validation? Or at least one without regexps? If I get that, RASPF should pass
142 of the 145 tests...

--
 ("\''/").__..-''"`-. .         Roberto Alsina
 `9_ 9  )   `-. (    ).`-._.`)  ralsina@kde.org
 (_Y_.)' ._   ) `._`.  " -.-'   KDE Developer (MFCH)
  _..`-'_..-_/ /-'_.'
(l)-'' ((i).' ((!.'   Buenos Aires - Argentina

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it. --Brian W. Kernighan

-------
To unsubscribe, change your address, or temporarily deactivate your subscription,
please go to http://v2.listbox.com/member/?list_id=1007
Re: Validating a domain-spec. [ In reply to ]
On Sat, 3 Mar 2007, Roberto Alsina wrote:

> Anyone knows where I can find a nice, simple, C implementation of this
> validation? Or at least one without regexps? If I get that, RASPF should pass
> 142 of the 145 tests...

No specific code, but...

If I were doing it in C, I would start with the ABNF in 4408 for such
validations, not PySPF. In some cases, the ABNF can be mirrored with
recursive evaluation (limit string length to limit max recursion), in others
you'll need a state machine (which regex libraries do for you automatically).

Use a C unit testing framework that tests internal parts such as this. I use
check [http://check.sourceforge.net/].

Specific code - how did libspf2 do it? (Or did they?)

--
Stuart D. Gathman <stuart@bmsi.com>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flammis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.

-------
To unsubscribe, change your address, or temporarily deactivate your subscription,
please go to http://v2.listbox.com/member/?list_id=1007
Re: Validating a domain-spec. [ In reply to ]
On Sat 03 Mar 2007 22:50:18 Stuart D. Gathman wrote:
> On Sat, 3 Mar 2007, Roberto Alsina wrote:
> > Anyone knows where I can find a nice, simple, C implementation of this
> > validation? Or at least one without regexps? If I get that, RASPF should
> > pass 142 of the 145 tests...
>
> No specific code, but...
>
> If I were doing it in C, I would start with the ABNF in 4408 for such
> validations, not PySPF. In some cases, the ABNF can be mirrored with
> recursive evaluation (limit string length to limit max recursion), in
> others you'll need a state machine (which regex libraries do for you
> automatically).

I'll check that. I am not sure I am up to it. And in Python it's a
three-liner, there must be a way :-)

> Use a C unit testing framework that tests internal parts such as this. I
> use check [http://check.sourceforge.net/].

I am already using it. In fact, without check and the nice unit testing in
PySPF, I would never have been able to get this far. It's nice knowing when
what you do actually works, and if it breaks.

This project has made me a unit testing believer out of me!

> Specific code - how did libspf2 do it? (Or did they?)

I can't say I found it.
 
--
 ("\''/").__..-''"`-. .         Roberto Alsina
 `9_ 9  )   `-. (    ).`-._.`)  ralsina@kde.org
 (_Y_.)' ._   ) `._`.  " -.-'   KDE Developer (MFCH)
  _..`-'_..-_/ /-'_.'
(l)-'' ((i).' ((!.'   Buenos Aires - Argentina

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it. --Brian W. Kernighan

-------
To unsubscribe, change your address, or temporarily deactivate your subscription,
please go to http://v2.listbox.com/member/?list_id=1007