bnf  1.12.11devel
Macros | Enumerations | Functions | Variables
bnf.h File Reference

Parsing macros and prototypes for HTTP-like protocols. More...

#include <sofia-sip/su_types.h>
#include <string.h>
Include dependency graph for bnf.h:

Go to the source code of this file.

Macros

#define BNF_H
 Defined when <sofia-sip/bnf.h> has been included. More...
 
#define CTL
 Control characters. More...
 
#define SP   " "
 Space.
 
#define HT   "\t"
 Horizontal tab.
 
#define CR   "\r"
 Carriage return.
 
#define LF   "\n"
 Line feed.
 
#define CRLF   CR LF
 Line-ending characters.
 
#define WS   SP HT
 Whitespace.
 
#define LWS   SP HT CR LF
 Linear whitespace.
 
#define LOALPHA   "abcdefghijklmnopqrstuvwxyz"
 Lower-case alphabetic characters.
 
#define UPALPHA   "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 Upper-case alphabetic characters.
 
#define ALPHA   LOALPHA UPALPHA
 Alphabetic characters.
 
#define DIGIT   "0123456789"
 Digits.
 
#define SAFE   "$-_." /* RTSP stuff */
 RTSP safe characters.
 
#define SIP_TOKEN   ALPHANUM "-.!%*_+`'~"
 SIP token characters. More...
 
#define SIP_SEPARATOR   "()<>@,;:\\\"/[]?={}" SP HT
 SIP separator characters.
 
#define SIP_WORD   "()<>:\\\"/[]?{}"
 SIP Word characters (that are not token characters)
 
#define skip_ws(ss)   (*(ss) += span_ws(*(ss)))
 Skip whitespace (SP HT)
 
#define skip_lws(ss)   (*(ss) += span_lws(*(ss)))
 Skip linear whitespace (SP HT CR LF)
 
#define skip_alpha(ss)   (*(ss) += span_alpha(*(ss)))
 Skip [a-zA-Z].
 
#define skip_digit(ss)   (*(ss) += span_digit(*(ss)))
 Skip digits.
 
#define skip_alpha_digit_safe(ss)   (*(ss) += span_alpha_digit_safe(*(ss)))
 Skip characters belonging to an RTSP token. More...
 
#define skip_token(ss)   (*(ss) += span_token(*(ss)))
 Skip characters belonging to a SIP token. More...
 
#define skip_param(ss)   (*(ss) += span_param(*(ss)))
 Skip characters belonging to a SIP parameter value. More...
 
#define skip_word(ss)   (*(ss) += span_word(*(ss)))
 Skip characters belonging to a SIP word. More...
 
#define IS_CRLF(c)   ((c) == '\r' || (c) == '\n')
 Test if is CR or LF.
 
#define IS_LWS(c)   ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n')
 Test if is linear whitespace.
 
#define IS_WS(c)   ((c) == ' ' || (c) == '\t')
 Test if is normal whitespace.
 
#define IS_NON_WS(c)   (c && !IS_WS(c))
 Test if is not whitespace (and not NUL). More...
 
#define IS_NON_LWS(c)   (c && !IS_LWS(c))
 Test if is not linear whitespace (and not NUL). More...
 
#define IS_DIGIT(c)   ((c) >= '0' && (c) <= '9')
 Test if is a digit. More...
 
#define IS_ALPHA(c)   (c && ((_bnf_table[(unsigned char)c] & bnf_alpha)))
 Test if is alphabetic. More...
 
#define IS_ALPHANUM(c)   (c && (IS_DIGIT(c) || IS_ALPHA(c)))
 Test if is alphanumeric. More...
 
#define IS_UNRESERVED(c)   ((_bnf_table[(unsigned char)c] & bnf_unreserved))
 Test if is URL-unreserved. More...
 
#define IS_RESERVED(c)   (c && !(_bnf_table[(unsigned char)c] & bnf_unreserved))
 Test if is URL-reserved. More...
 
#define IS_TOKEN(c)   ((_bnf_table[(unsigned char)c] & bnf_token))
 Test if is valid in tokens. More...
 
#define IS_PARAM(c)   ((_bnf_table[(unsigned char)c] & (bnf_token|bnf_param)))
 Test if is valid for SIP parameter value. More...
 
#define IS_HEX(c)   (((c) >= '0' && (c) <= '9') || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f'))
 Test if is a hex digit. More...
 
#define IS_TOKENLWS(c)   ((_bnf_table[(unsigned char)c] & (bnf_token|bn_lws)))
 Test if is a linear whitespace or valid in tokens. More...
 
#define span_non_crlf(s)   strcspn(s, CR LF)
 Get number of characters before CRLF.
 
#define span_non_ws(s)   strcspn(s, WS)
 Get number of characters before whitespace.
 
#define span_ws(s)   strspn(s, WS)
 Get number of whitespace characters.
 
#define span_non_lws(s)   strcspn(s, LWS)
 Get number of characters before linear whitespace.
 
#define URL_RESERVED   ";/?:=+$,"
 Reserved in URLs.
 
#define URL_MARK   "-_.!~*'()"
 Non-alphanumeric characters without syntactical meaning. More...
 
#define URL_UNRESERVED   ALPHANUM URL_MARK
 Unreserved characters. More...
 
#define URL_ESCAPED   "%"
 URL hex escape. More...
 
#define span_url_scheme(s)   strspn(s, URL_SCHEME)
 Get number of characters belonging to url scheme.
 

Enumerations

enum  {
  bnf_ws = 1,
  bnf_crlf = 2,
  bnf_lws = 3,
  bnf_alpha = 4,
  bnf_safe = 8,
  bnf_mark = 16,
  bnf_unreserved = bnf_alpha | bnf_mark,
  bnf_separator = 32,
  bnf_token0 = 64 | bnf_safe,
  bnf_token = bnf_token0 | bnf_alpha,
  bnf_param0 = 128,
  bnf_param = bnf_token | bnf_param0
}
 

Functions

isize_t span_lws (char const *s)
 Calculate span of a linear whitespace. More...
 
isize_t span_token_lws (char const *s)
 Calculate span of a token or linear whitespace characters. More...
 
isize_t span_token (char const *s)
 Calculate span of a token characters. More...
 
isize_t span_alpha (char const *s)
 Calculate span of a alphabetic characters. More...
 
isize_t span_digit (char const *s)
 Calculate span of a digits. More...
 
isize_t span_hexdigit (char const *s)
 Calculate span of a hex. More...
 
isize_t span_alpha_digit_safe (char const *s)
 Calculate span of characters belonging to an RTSP token.
 
isize_t span_param (char const *s)
 Calculate span of a characters valid in parameters. More...
 
isize_t span_word (char const *s)
 Calculate span of a SIP word. More...
 
isize_t span_unreserved (char const *s)
 Calculate span of a unreserved characters. More...
 
isize_t span_quoted (char const *s)
 Calculate span of a double quoted string (with escaped chars inside)
 
int span_ip4_address (char const *host)
 Return length of valid IP4 address. More...
 
int span_ip6_address (char const *host)
 Return length of valid IP6 address.
 
int span_ip6_reference (char const *host)
 Return length of valid IP6 reference. More...
 
int span_ip_address (char const *host)
 Return length of valid IP4 or IP6 address. More...
 
isize_t span_domain (char const *host)
 Return length of a valid domain name. More...
 
isize_t span_host (char const *host)
 Return length of a valid domain name or IP address. More...
 
int scan_ip4_address (char **inout_host)
 Scan and canonize a valid IP4 address. More...
 
int scan_ip6_address (char **inout_host)
 Scan and canonize valid IP6 address. More...
 
int scan_ip6_reference (char **inout_host)
 Scan valid IP6 reference. More...
 
int scan_ip_address (char **inout_host)
 Scan valid IP4/IP6 address. More...
 
issize_t scan_domain (char **inout_host)
 Scan valid domain name. More...
 
issize_t scan_host (char **inout_host)
 Scan valid domain name or IP address. More...
 

Variables

unsigned char const _bnf_table [256]
 Table for determining class of a character. More...
 

Detailed Description

Parsing macros and prototypes for HTTP-like protocols.

Author
Pekka Pessi Pekka.nosp@m..Pes.nosp@m.si@no.nosp@m.kia..nosp@m.com
Date
Created: Tue Jun 06 10:59:34 2000 ppessi

Macro Definition Documentation

◆ BNF_H

#define BNF_H

Defined when <sofia-sip/bnf.h> has been included.

◆ CTL

#define CTL

Control characters.

◆ IS_ALPHA

#define IS_ALPHA (   c)    (c && ((_bnf_table[(unsigned char)c] & bnf_alpha)))

Test if is alphabetic.

◆ IS_ALPHANUM

#define IS_ALPHANUM (   c)    (c && (IS_DIGIT(c) || IS_ALPHA(c)))

Test if is alphanumeric.

◆ IS_DIGIT

#define IS_DIGIT (   c)    ((c) >= '0' && (c) <= '9')

Test if is a digit.

◆ IS_HEX

#define IS_HEX (   c)    (((c) >= '0' && (c) <= '9') || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f'))

Test if is a hex digit.

◆ IS_NON_LWS

#define IS_NON_LWS (   c)    (c && !IS_LWS(c))

Test if is not linear whitespace (and not NUL).

◆ IS_NON_WS

#define IS_NON_WS (   c)    (c && !IS_WS(c))

Test if is not whitespace (and not NUL).

◆ IS_PARAM

#define IS_PARAM (   c)    ((_bnf_table[(unsigned char)c] & (bnf_token|bnf_param)))

Test if is valid for SIP parameter value.

◆ IS_RESERVED

#define IS_RESERVED (   c)    (c && !(_bnf_table[(unsigned char)c] & bnf_unreserved))

Test if is URL-reserved.

◆ IS_TOKEN

#define IS_TOKEN (   c)    ((_bnf_table[(unsigned char)c] & bnf_token))

Test if is valid in tokens.

◆ IS_TOKENLWS

#define IS_TOKENLWS (   c)    ((_bnf_table[(unsigned char)c] & (bnf_token|bn_lws)))

Test if is a linear whitespace or valid in tokens.

◆ IS_UNRESERVED

#define IS_UNRESERVED (   c)    ((_bnf_table[(unsigned char)c] & bnf_unreserved))

Test if is URL-unreserved.

◆ SIP_TOKEN

#define SIP_TOKEN   ALPHANUM "-.!%*_+`'~"

SIP token characters.

Note
$|&^# were token chars in RFC 2543, but no more in RFC 3261.

◆ skip_alpha_digit_safe

#define skip_alpha_digit_safe (   ss)    (*(ss) += span_alpha_digit_safe(*(ss)))

Skip characters belonging to an RTSP token.

◆ skip_param

#define skip_param (   ss)    (*(ss) += span_param(*(ss)))

Skip characters belonging to a SIP parameter value.

◆ skip_token

#define skip_token (   ss)    (*(ss) += span_token(*(ss)))

Skip characters belonging to a SIP token.

◆ skip_word

#define skip_word (   ss)    (*(ss) += span_word(*(ss)))

Skip characters belonging to a SIP word.

◆ URL_ESCAPED

#define URL_ESCAPED   "%"

URL hex escape.

◆ URL_MARK

#define URL_MARK   "-_.!~*'()"

Non-alphanumeric characters without syntactical meaning.

◆ URL_UNRESERVED

#define URL_UNRESERVED   ALPHANUM URL_MARK

Unreserved characters.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
bnf_ws 

Whitespace character.

bnf_crlf 

Line end character.

bnf_lws 

Linear whitespace.

bnf_alpha 

Alphabetic.

bnf_safe 

RTSP safe.

bnf_mark 

URL mark.

bnf_unreserved 

URL unreserved.

bnf_separator 

SIP separator.

bnf_token0 

SIP token, not alphabetic (0123456789-.

!%*_+`'~)

bnf_token 

SIP token.

bnf_param0 

SIP parameter, not token.

bnf_param 

SIP/HTTP parameter.

Function Documentation

◆ scan_domain()

issize_t scan_domain ( char **  inout_host)

Scan valid domain name.

◆ scan_host()

issize_t scan_host ( char **  inout_host)

Scan valid domain name or IP address.

◆ scan_ip4_address()

int scan_ip4_address ( char **  inout_host)

Scan and canonize a valid IP4 address.

◆ scan_ip6_address()

int scan_ip6_address ( char **  inout_host)

Scan and canonize valid IP6 address.

Parameters
inout_hostinput pointer to string to scan output pointer to first character after valid IP6 address
Return values
Lengthof valid IP6 address or -1 upon an error.
Note
Scanned IP6 is not always NUL-terminated.

◆ scan_ip6_reference()

int scan_ip6_reference ( char **  inout_host)

Scan valid IP6 reference.

◆ scan_ip_address()

int scan_ip_address ( char **  inout_host)

Scan valid IP4/IP6 address.

◆ span_alpha()

isize_t span_alpha ( char const *  s)
inline

Calculate span of a alphabetic characters.

◆ span_digit()

isize_t span_digit ( char const *  s)
inline

Calculate span of a digits.

◆ span_domain()

isize_t span_domain ( char const *  host)

Return length of a valid domain name.

hostname = *( domainlabel "." ) toplabel [ "." ]
domainlabel = alphanum
/ alphanum *( alphanum / "-" ) alphanum
toplabel = ALPHA / ALPHA *( alphanum / "-" ) alphanum

◆ span_hexdigit()

isize_t span_hexdigit ( char const *  s)
inline

Calculate span of a hex.

◆ span_host()

isize_t span_host ( char const *  host)

Return length of a valid domain name or IP address.

◆ span_ip4_address()

int span_ip4_address ( char const *  host)

Return length of valid IP4 address.

Note that we accept here up to two leading zeroes which makes "dotted decimal" notation ambiguous: 127.000.000.001 is interpreted same as 127.0.0.1

Note that traditionally IP address octets starting with zero have been interpreted as octal: 172.055.055.001 has been same as 172.45.45.1

However, we interpret them as decimal, 172.055.055.001 is same as 172.55.55.1.

◆ span_ip6_reference()

int span_ip6_reference ( char const *  host)

Return length of valid IP6 reference.

◆ span_ip_address()

int span_ip_address ( char const *  host)

Return length of valid IP4 or IP6 address.

◆ span_lws()

isize_t span_lws ( char const *  s)
inline

Calculate span of a linear whitespace.

LWS = [*WSP CRLF] 1*WSP

◆ span_param()

isize_t span_param ( char const *  s)
inline

Calculate span of a characters valid in parameters.

◆ span_token()

isize_t span_token ( char const *  s)
inline

Calculate span of a token characters.

◆ span_token_lws()

isize_t span_token_lws ( char const *  s)
inline

Calculate span of a token or linear whitespace characters.

◆ span_unreserved()

isize_t span_unreserved ( char const *  s)
inline

Calculate span of a unreserved characters.

◆ span_word()

isize_t span_word ( char const *  s)
inline

Calculate span of a SIP word.

Variable Documentation

◆ _bnf_table

unsigned char const _bnf_table[256]

Table for determining class of a character.


Sofia-SIP 1.12.11devel - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.