/*

                                   _JNJ`                        
                               .JNMH`                           
                              JMMF`       `;.                   
                            .NMM)          `MN.                 
                            MMM)            (MML                
                           (MMM`             MMML               
                     M  I  D  N  I  G  H  T    C  o  D  E       
                           (NMMF             MHNH               
                            NMML            .MMM                
                             NMML          .NMH                 
                              4MMNL       .#F                   
                               `4HNNL_   `                      
                                   `"""`                        

                          Copyright (C) 2004-2007
       "Ian (Larry) Latter" <ian dot latter at midnightcode dot org>

    Midnight Code is a registered trademark of Ian Latter.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, and mirrored at the Midnight Code web
    site; as at version 2 of the License only.
  
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
  
    You should have received a copy of the GNU General Public License
    (version 2) along with this program; if not, write to the Free
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA, or see http://midnightcode.org/gplv2.txt

*/


/* midnightcode-abnf.h :: Midnight Code ABNF (RFC2234) library		*/

/* Includes software to support RFCs :: 2234 */


#ifndef __MIDNIGHTCODE_ABNF_H
#define __MIDNIGHTCODE_ABNF_H 1

/*
6.   APPENDIX A - CORE

   This Appendix is provided as a convenient core for specific grammars.
   The definitions may be used as a core set of rules.

6.1  Core Rules

   Certain  basic  rules  are  in uppercase, such as SP, HTAB, CRLF,
   DIGIT, ALPHA, etc.

        ALPHA          =  %x41-5A / %x61-7A   ; A-Z / a-z

        BIT            =  "0" / "1"

        CHAR           =  %x01-7F
                               ; any 7-bit US-ASCII character,
                                  excluding NUL

        CR             =  %x0D
                               ; carriage return

        CRLF           =  CR LF
                               ; Internet standard newline

        CTL            =  %x00-1F / %x7F
                               ; controls

        DIGIT          =  %x30-39
                               ; 0-9

        DQUOTE         =  %x22
                               ; " (Double Quote)

        HEXDIG         =  DIGIT / "A" / "B" / "C" / "D" / "E" / "F"

        HTAB           =  %x09
                               ; horizontal tab

        LF             =  %x0A
                               ; linefeed

        LWSP           =  *(WSP / CRLF WSP)
                               ; linear white space (past newline)

        OCTET          =  %x00-FF
                               ; 8 bits of data

        SP             =  %x20
                               ; space

        VCHAR          =  %x21-7E
                               ; visible (printing) characters

        WSP            =  SP / HTAB
                               ; white space
*/

enum midnightcode_parse_charset_t
{
  MIDNIGHTCODE_PARSE_CHARSET_NONE = 0,
  MIDNIGHTCODE_PARSE_CHARSET_ALPHA = 1,
  MIDNIGHTCODE_PARSE_CHARSET_NUMERIC = 2,
  MIDNIGHTCODE_PARSE_CHARSET_ALPHANUMERIC = 3,
  MIDNIGHTCODE_PARSE_CHARSET_ABNFVCHAR = 4,
  MIDNIGHTCODE_PARSE_CHARSET_PRINTABLE = 5
};

enum midnightcode_parse_type_t
{
  MIDNIGHTCODE_PARSE_TYPE_NONE = 1,
  MIDNIGHTCODE_PARSE_TYPE_STRING,
  MIDNIGHTCODE_PARSE_TYPE_INT,
  MIDNIGHTCODE_PARSE_TYPE_LONG,
  MIDNIGHTCODE_PARSE_TYPE_VAL,
  MIDNIGHTCODE_PARSE_TYPE_FLOAT,
  MIDNIGHTCODE_PARSE_TYPE_DOUBLE,
  MIDNIGHTCODE_PARSE_TYPE_LONGDOUBLE,
  MIDNIGHTCODE_PARSE_TYPE_HWADDR,
  MIDNIGHTCODE_PARSE_TYPE_HOST,
  MIDNIGHTCODE_PARSE_TYPE_IP
};

enum midnightcode_parse_ext_type_t
{
  MIDNIGHTCODE_PARSE_EXT_TYPE_NONE = 0,
  MIDNIGHTCODE_PARSE_EXT_TYPE_HTML = 1,
  MIDNIGHTCODE_PARSE_EXT_TYPE_DOCUMENT = 2,
  MIDNIGHTCODE_PARSE_EXT_TYPE_PICTURE = 3,
  MIDNIGHTCODE_PARSE_EXT_TYPE_VIDEO = 4,
  MIDNIGHTCODE_PARSE_EXT_TYPE_AUDIO = 5,
  MIDNIGHTCODE_PARSE_EXT_TYPE_ARCHIVE = 6
};

struct midnightcode_parse_extension_t
{
  const char * ext;
};

int midnightcode_parse_any(char *haystack, char *needle);
int midnightcode_parse_ascii(char *haystack, int charset);
int midnightcode_parse_yesno(char *string_buf, int default_return);
int midnightcode_parse_size(long double * capacity, char * scale,
                            int scale_len);
int midnightcode_parse_trim(char *string_buf, int string_buf_max);
int midnightcode_parse_extmatch(struct midnightcode_parse_extension_t * exts,
                            char * url, int url_len);
int midnightcode_parse_exttype(char *url, int url_len, int type);
int midnightcode_parse_strtoarg(char *string_buf, int string_buf_max,
                            char **args, int args_max);
int midnightcode_parse_strtovar(void * variable, char * buffer,
                            int length, int value, int type);
int midnightcode_parse_vartostr(char * buffer, void * variable,
                            int length, int value, int type);
int midnightcode_parse_unserialize(void * variable, char * buffer,
                            int length, int value, int type);
int midnightcode_parse_serialize(char * buffer, void * variable,
                            int length, int value, int type);


#endif
