Defines | Enumerations | Functions | Variables

sofia-sip/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.

Defines

#define BNF_H
 Defined when <sofia-sip/bnf.h> has been included.
#define CTL
 Control characters.
#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 safe characters.
#define SIP_TOKEN   ALPHANUM "-.!%*_+`'~"
 SIP token characters.
#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.
#define skip_token(ss)   (*(ss) += span_token(*(ss)))
 Skip characters belonging to a SIP token.
#define skip_param(ss)   (*(ss) += span_param(*(ss)))
 Skip characters belonging to a SIP parameter value.
#define skip_word(ss)   (*(ss) += span_word(*(ss)))
 Skip characters belonging to a SIP word.
#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).
#define IS_NON_LWS(c)   (c && !IS_LWS(c))
 Test if is not linear whitespace (and not NUL).
#define IS_DIGIT(c)   ((c) >= '0' && (c) <= '9')
 Test if is a digit.
#define IS_ALPHA(c)   (c && ((_bnf_table[(unsigned char)c] & bnf_alpha)))
 Test if is alphabetic.
#define IS_ALPHANUM(c)   (c && (IS_DIGIT(c) || IS_ALPHA(c)))
 Test if is alphanumeric.
#define IS_UNRESERVED(c)   ((_bnf_table[(unsigned char)c] & bnf_unreserved))
 Test if is URL-unreserved.
#define IS_RESERVED(c)   (c && !(_bnf_table[(unsigned char)c] & bnf_unreserved))
 Test if is URL-reserved.
#define IS_TOKEN(c)   ((_bnf_table[(unsigned char)c] & bnf_token))
 Test if is valid in tokens.
#define IS_PARAM(c)   ((_bnf_table[(unsigned char)c] & (bnf_token|bnf_param)))
 Test if is valid for SIP parameter value.
#define IS_HEX(c)   (((c) >= '0' && (c) <= '9') || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f'))
 Test if is a hex digit.
#define IS_TOKENLWS(c)   ((_bnf_table[(unsigned char)c] & (bnf_token|bn_lws)))
 Test if is a linear whitespace or valid in tokens.
#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.
#define URL_UNRESERVED   ALPHANUM URL_MARK
 Unreserved characters.
#define URL_ESCAPED   "%"
 URL hex escape.
#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.
isize_t span_token_lws (char const *s)
 Calculate span of a token or linear whitespace characters.
isize_t span_token (char const *s)
 Calculate span of a token characters.
isize_t span_alpha (char const *s)
 Calculate span of a alphabetic characters.
isize_t span_digit (char const *s)
 Calculate span of a digits.
isize_t span_hexdigit (char const *s)
 Calculate span of a hex.
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.
isize_t span_word (char const *s)
 Calculate span of a SIP word.
isize_t span_unreserved (char const *s)
 Calculate span of a unreserved characters.
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.
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.
int span_ip_address (char const *host)
 Return length of valid IP4 or IP6 address.
isize_t span_domain (char const *host)
 Return length of a valid domain name.
isize_t span_host (char const *host)
 Return length of a valid domain name or IP address.
int scan_ip4_address (char **inout_host)
 Scan and canonize a valid IP4 address.
int scan_ip6_address (char **inout_host)
 Scan and canonize valid IP6 address.
int scan_ip6_reference (char **inout_host)
 Scan valid IP6 reference.
int scan_ip_address (char **inout_host)
 Scan valid IP4/IP6 address.
issize_t scan_domain (char **inout_host)
 Scan valid domain name.
issize_t scan_host (char **inout_host)
 Scan valid domain name or IP address.

Variables

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

Detailed Description

Parsing macros and prototypes for HTTP-like protocols.

Author:
Pekka Pessi <Pekka.Pessi@nokia-email.address.hidden>
Date:
Created: Tue Jun 06 10:59:34 2000 ppessi

Define Documentation

#define BNF_H

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

#define CTL

Control characters.

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

Test if is alphabetic.

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

Test if is alphanumeric.

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

Test if is a digit.

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

Test if is a hex digit.

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

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

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

Test if is not whitespace (and not NUL).

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

Test if is valid for SIP parameter value.

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

Test if is URL-reserved.

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

Test if is valid in tokens.

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

Test if is a linear whitespace or valid in tokens.

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

Test if is URL-unreserved.

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

SIP token characters.

Note:
$|&^# were token chars in RFC 2543, but no more in RFC 3261.
#define skip_alpha_digit_safe (   ss  )     (*(ss) += span_alpha_digit_safe(*(ss)))

Skip characters belonging to an RTSP token.

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

Skip characters belonging to a SIP parameter value.

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

Skip characters belonging to a SIP token.

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

Skip characters belonging to a SIP word.

#define URL_ESCAPED   "%"

URL hex escape.

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

Non-alphanumeric characters without syntactical meaning.

#define URL_UNRESERVED   ALPHANUM URL_MARK

Unreserved characters.


Enumeration Type Documentation

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

issize_t scan_domain ( char **  inout_host  ) 

Scan valid domain name.

issize_t scan_host ( char **  inout_host  ) 

Scan valid domain name or IP address.

int scan_ip4_address ( char **  inout_host  ) 

Scan and canonize a valid IP4 address.

int scan_ip6_address ( char **  inout_host  ) 

Scan and canonize valid IP6 address.

Parameters:
inout_host input pointer to string to scan output pointer to first character after valid IP6 address
Return values:
Length of valid IP6 address or -1 upon an error.
Note:
Scanned IP6 is not always NUL-terminated.
int scan_ip6_reference ( char **  inout_host  ) 

Scan valid IP6 reference.

int scan_ip_address ( char **  inout_host  ) 

Scan valid IP4/IP6 address.

isize_t span_alpha ( char const *  s  )  [inline]

Calculate span of a alphabetic characters.

isize_t span_digit ( char const *  s  )  [inline]

Calculate span of a digits.

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
isize_t span_hexdigit ( char const *  s  )  [inline]

Calculate span of a hex.

isize_t span_host ( char const *  host  ) 

Return length of a valid domain name or IP 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.

int span_ip6_reference ( char const *  host  ) 

Return length of valid IP6 reference.

int span_ip_address ( char const *  host  ) 

Return length of valid IP4 or IP6 address.

isize_t span_lws ( char const *  s  )  [inline]

Calculate span of a linear whitespace.

LWS = [*WSP CRLF] 1*WSP

isize_t span_param ( char const *  s  )  [inline]

Calculate span of a characters valid in parameters.

isize_t span_token ( char const *  s  )  [inline]

Calculate span of a token characters.

isize_t span_token_lws ( char const *  s  )  [inline]

Calculate span of a token or linear whitespace characters.

isize_t span_unreserved ( char const *  s  )  [inline]

Calculate span of a unreserved characters.

isize_t span_word ( char const *  s  )  [inline]

Calculate span of a SIP word.


Variable Documentation

unsigned char const _bnf_table[256]

Table for determining class of a character.

 All Data Structures Files Functions Variables Enumerator Defines

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