1f8307e12SArchie Cobbs 2f8307e12SArchie Cobbs /* 3f8307e12SArchie Cobbs * ng_parse.h 4f8307e12SArchie Cobbs * 5f8307e12SArchie Cobbs * Copyright (c) 1999 Whistle Communications, Inc. 6f8307e12SArchie Cobbs * All rights reserved. 7f8307e12SArchie Cobbs * 8f8307e12SArchie Cobbs * Subject to the following obligations and disclaimer of warranty, use and 9f8307e12SArchie Cobbs * redistribution of this software, in source or object code forms, with or 10f8307e12SArchie Cobbs * without modifications are expressly permitted by Whistle Communications; 11f8307e12SArchie Cobbs * provided, however, that: 12f8307e12SArchie Cobbs * 1. Any and all reproductions of the source or object code must include the 13f8307e12SArchie Cobbs * copyright notice above and the following disclaimer of warranties; and 14f8307e12SArchie Cobbs * 2. No rights are granted, in any manner or form, to use Whistle 15f8307e12SArchie Cobbs * Communications, Inc. trademarks, including the mark "WHISTLE 16f8307e12SArchie Cobbs * COMMUNICATIONS" on advertising, endorsements, or otherwise except as 17f8307e12SArchie Cobbs * such appears in the above copyright notice or in the software. 18f8307e12SArchie Cobbs * 19f8307e12SArchie Cobbs * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 20f8307e12SArchie Cobbs * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 21f8307e12SArchie Cobbs * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 22f8307e12SArchie Cobbs * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 23f8307e12SArchie Cobbs * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 24f8307e12SArchie Cobbs * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 25f8307e12SArchie Cobbs * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 26f8307e12SArchie Cobbs * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 27f8307e12SArchie Cobbs * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 28f8307e12SArchie Cobbs * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 29f8307e12SArchie Cobbs * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 30f8307e12SArchie Cobbs * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 31f8307e12SArchie Cobbs * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 32f8307e12SArchie Cobbs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33f8307e12SArchie Cobbs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34f8307e12SArchie Cobbs * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 35f8307e12SArchie Cobbs * OF SUCH DAMAGE. 36f8307e12SArchie Cobbs * 37f8307e12SArchie Cobbs * Author: Archie Cobbs <archie@whistle.com> 38f8307e12SArchie Cobbs * 39f8307e12SArchie Cobbs * $Whistle: ng_parse.h,v 1.2 1999/11/29 01:43:48 archie Exp $ 40f8307e12SArchie Cobbs * $FreeBSD$ 41f8307e12SArchie Cobbs */ 42f8307e12SArchie Cobbs 43f8307e12SArchie Cobbs #ifndef _NETGRAPH_PARSE_H_ 44f8307e12SArchie Cobbs #define _NETGRAPH_PARSE_H_ 45f8307e12SArchie Cobbs 46f8307e12SArchie Cobbs /* 47f8307e12SArchie Cobbs 48f8307e12SArchie Cobbs This defines a library of routines for converting between various C 49f8307e12SArchie Cobbs language types in binary form and ASCII strings. Types are user 50f8307e12SArchie Cobbs definable. Several pre-defined types are supplied, for some 51f8307e12SArchie Cobbs common C types: structures, variable and fixed length arrays, 52f8307e12SArchie Cobbs integer types, variable and fixed length strings, IP addresses, 53f8307e12SArchie Cobbs etc. 54f8307e12SArchie Cobbs 55f8307e12SArchie Cobbs Syntax 56f8307e12SArchie Cobbs ------ 57f8307e12SArchie Cobbs 58f8307e12SArchie Cobbs Structures: 59f8307e12SArchie Cobbs 60f8307e12SArchie Cobbs '{' [ <name>=<value> ... ] '}' 61f8307e12SArchie Cobbs 62f8307e12SArchie Cobbs Omitted fields have their default values by implication. 63f8307e12SArchie Cobbs The order in which the fields are specified does not matter. 64f8307e12SArchie Cobbs 65f8307e12SArchie Cobbs Arrays: 66f8307e12SArchie Cobbs 67f8307e12SArchie Cobbs '[' [ [index=]<value> ... ] ']' 68f8307e12SArchie Cobbs 69f8307e12SArchie Cobbs Element value may be specified with or without the "<index>=" prefix; 70f8307e12SArchie Cobbs If omitted, the index after the previous element is used. 71f8307e12SArchie Cobbs Omitted fields have their default values by implication. 72f8307e12SArchie Cobbs 73f8307e12SArchie Cobbs Strings: 74f8307e12SArchie Cobbs 75f8307e12SArchie Cobbs "foo bar blah\r\n" 76f8307e12SArchie Cobbs 77f8307e12SArchie Cobbs That is, strings are specified just like C strings. The usual 78f8307e12SArchie Cobbs backslash escapes are accepted. 79f8307e12SArchie Cobbs 80f8307e12SArchie Cobbs Other simple types have their obvious ASCII forms. 81f8307e12SArchie Cobbs 82f8307e12SArchie Cobbs Example 83f8307e12SArchie Cobbs ------- 84f8307e12SArchie Cobbs 85f8307e12SArchie Cobbs Structure Binary (big endian) 86f8307e12SArchie Cobbs --------- ------------------- 87f8307e12SArchie Cobbs 88f8307e12SArchie Cobbs struct foo { 89f8307e12SArchie Cobbs struct in_addr ip; 03 03 03 03 90f8307e12SArchie Cobbs int bar; 00 00 00 00 91f8307e12SArchie Cobbs u_char num; 02 00 92f8307e12SArchie Cobbs short ary[0]; 00 05 00 00 00 0a 93f8307e12SArchie Cobbs }; 94f8307e12SArchie Cobbs 95f8307e12SArchie Cobbs ASCII form: "{ ip=3.3.3.3 num=3 ary=[ 5 2=10 ] }" 96f8307e12SArchie Cobbs 97f8307e12SArchie Cobbs Note that omitted fields or array elements get their default values 98f8307e12SArchie Cobbs ("bar" and ary[2]), and that the alignment is handled automatically 99f8307e12SArchie Cobbs (the extra 00 byte after "num"). 100f8307e12SArchie Cobbs 101f8307e12SArchie Cobbs To define a type, you can define it as a sub-type of a predefined 102f8307e12SArchie Cobbs type, overriding some of the predefined type's methods and/or its 103f8307e12SArchie Cobbs alignment, or define your own syntax, with the restriction that 104f8307e12SArchie Cobbs the ASCII representation must not contain any whitespace or these 105f8307e12SArchie Cobbs characters: { } [ ] = " 106f8307e12SArchie Cobbs 107f8307e12SArchie Cobbs */ 108f8307e12SArchie Cobbs 109f8307e12SArchie Cobbs /************************************************************************ 110f8307e12SArchie Cobbs METHODS REQUIRED BY A TYPE 111f8307e12SArchie Cobbs ************************************************************************/ 112f8307e12SArchie Cobbs 113f8307e12SArchie Cobbs /* 114f8307e12SArchie Cobbs * Three methods are required for a type. These may be given explicitly 115f8307e12SArchie Cobbs * or, if NULL, inherited from the super-type. 116f8307e12SArchie Cobbs */ 117f8307e12SArchie Cobbs 118f8307e12SArchie Cobbs struct ng_parse_type; 119f8307e12SArchie Cobbs 120f8307e12SArchie Cobbs /* 121f8307e12SArchie Cobbs * Convert ASCII to binary according to the supplied type. 122f8307e12SArchie Cobbs * 123f8307e12SArchie Cobbs * The ASCII characters begin at offset *off in 'string'. The binary 124f8307e12SArchie Cobbs * representation is put into 'buf', which has at least *buflen bytes. 125f8307e12SArchie Cobbs * 'start' points to the first byte output by ng_parse() (ie, start <= buf). 126f8307e12SArchie Cobbs * 127f8307e12SArchie Cobbs * Upon return, *buflen contains the length of the new binary data, and 128f8307e12SArchie Cobbs * *off is updated to point just past the end of the parsed range of 129f8307e12SArchie Cobbs * characters, or, in the case of an error, to the offending character(s). 130f8307e12SArchie Cobbs * 131f8307e12SArchie Cobbs * Return values: 132f8307e12SArchie Cobbs * 0 Success; *buflen holds the length of the data 133f8307e12SArchie Cobbs * and *off points just past the last char parsed. 134f8307e12SArchie Cobbs * EALREADY Field specified twice 135f8307e12SArchie Cobbs * ENOENT Unknown field 136f8307e12SArchie Cobbs * E2BIG Array or character string overflow 137f8307e12SArchie Cobbs * ERANGE Output was longer than *buflen bytes 138f8307e12SArchie Cobbs * EINVAL Parse failure or other invalid content 139f8307e12SArchie Cobbs * ENOMEM Out of memory 140f8307e12SArchie Cobbs * EOPNOTSUPP Mandatory array/structure element missing 141f8307e12SArchie Cobbs */ 142f8307e12SArchie Cobbs typedef int ng_parse_t(const struct ng_parse_type *type, const char *string, 143f8307e12SArchie Cobbs int *off, const u_char *start, 144f8307e12SArchie Cobbs u_char *buf, int *buflen); 145f8307e12SArchie Cobbs 146f8307e12SArchie Cobbs /* 147f8307e12SArchie Cobbs * Convert binary to ASCII according to the supplied type. 148f8307e12SArchie Cobbs * 149f8307e12SArchie Cobbs * The results are put into 'buf', which is at least buflen bytes long. 150f8307e12SArchie Cobbs * *off points to the current byte in 'data' and should be updated 151f8307e12SArchie Cobbs * before return to point just past the last byte unparsed. 152f8307e12SArchie Cobbs * 153f8307e12SArchie Cobbs * Returns: 154f8307e12SArchie Cobbs * 0 Success 155f8307e12SArchie Cobbs * ERANGE Output was longer than buflen bytes 156f8307e12SArchie Cobbs */ 157f8307e12SArchie Cobbs typedef int ng_unparse_t(const struct ng_parse_type *type, 158f8307e12SArchie Cobbs const u_char *data, int *off, char *buf, int buflen); 159f8307e12SArchie Cobbs 160f8307e12SArchie Cobbs /* 161f8307e12SArchie Cobbs * Compute the default value according to the supplied type. 162f8307e12SArchie Cobbs * 163f8307e12SArchie Cobbs * Store the result in 'buf', which is at least *buflen bytes long. 164f8307e12SArchie Cobbs * Upon return *buflen contains the length of the output. 165f8307e12SArchie Cobbs * 166f8307e12SArchie Cobbs * Returns: 167f8307e12SArchie Cobbs * 0 Success 168f8307e12SArchie Cobbs * ERANGE Output was longer than *buflen bytes 169f8307e12SArchie Cobbs * EOPNOTSUPP Default value is not specified for this type 170f8307e12SArchie Cobbs */ 171f8307e12SArchie Cobbs typedef int ng_getDefault_t(const struct ng_parse_type *type, 172f8307e12SArchie Cobbs const u_char *start, u_char *buf, int *buflen); 173f8307e12SArchie Cobbs 174f8307e12SArchie Cobbs /* 175f8307e12SArchie Cobbs * Return the alignment requirement of this type. Zero is same as one. 176f8307e12SArchie Cobbs */ 177f8307e12SArchie Cobbs typedef int ng_getAlign_t(const struct ng_parse_type *type); 178f8307e12SArchie Cobbs 179f8307e12SArchie Cobbs /************************************************************************ 180f8307e12SArchie Cobbs TYPE DEFINITION 181f8307e12SArchie Cobbs ************************************************************************/ 182f8307e12SArchie Cobbs 183f8307e12SArchie Cobbs /* 184f8307e12SArchie Cobbs * This structure describes a type, which may be a sub-type of another 185f8307e12SArchie Cobbs * type by pointing to it with 'supertype' and omitting one or more methods. 186f8307e12SArchie Cobbs */ 187f8307e12SArchie Cobbs struct ng_parse_type { 188f8307e12SArchie Cobbs const struct ng_parse_type *supertype; /* super-type, if any */ 189f8307e12SArchie Cobbs const void *info; /* type-specific info */ 190f8307e12SArchie Cobbs void *private; /* client private info */ 191f8307e12SArchie Cobbs ng_parse_t *parse; /* parse method */ 192f8307e12SArchie Cobbs ng_unparse_t *unparse; /* unparse method */ 193f8307e12SArchie Cobbs ng_getDefault_t *getDefault; /* get default value method */ 194f8307e12SArchie Cobbs ng_getAlign_t *getAlign; /* get alignment */ 195f8307e12SArchie Cobbs }; 196f8307e12SArchie Cobbs 197f8307e12SArchie Cobbs /************************************************************************ 198f8307e12SArchie Cobbs PRE-DEFINED TYPES 199f8307e12SArchie Cobbs ************************************************************************/ 200f8307e12SArchie Cobbs 201f8307e12SArchie Cobbs /* 202f8307e12SArchie Cobbs * Structures 203f8307e12SArchie Cobbs * 204f8307e12SArchie Cobbs * Default value: Determined on a per-field basis 205f8307e12SArchie Cobbs * Additional info: struct ng_parse_struct_info * 206f8307e12SArchie Cobbs */ 207f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_struct_type; 208f8307e12SArchie Cobbs 209f8307e12SArchie Cobbs /* Each field has a name, type, and optional alignment override. If the 210f8307e12SArchie Cobbs override is non-zero, the alignment is determined from the field type. 211f8307e12SArchie Cobbs Note: add an extra struct ng_parse_struct_field with name == NULL 212f8307e12SArchie Cobbs to indicate the end of the list. */ 213f8307e12SArchie Cobbs struct ng_parse_struct_info { 214f8307e12SArchie Cobbs struct ng_parse_struct_field { 215f8307e12SArchie Cobbs const char *name; /* field name */ 216f8307e12SArchie Cobbs const struct ng_parse_type 217f8307e12SArchie Cobbs *type; /* field type */ 218f8307e12SArchie Cobbs int alignment; /* override alignment */ 219f8307e12SArchie Cobbs } fields[0]; 220f8307e12SArchie Cobbs }; 221f8307e12SArchie Cobbs 222f8307e12SArchie Cobbs /* 223f8307e12SArchie Cobbs * Fixed length arrays 224f8307e12SArchie Cobbs * 225f8307e12SArchie Cobbs * Default value: See below 226f8307e12SArchie Cobbs * Additional info: struct ng_parse_fixedarray_info * 227f8307e12SArchie Cobbs */ 228f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_fixedarray_type; 229f8307e12SArchie Cobbs 230f8307e12SArchie Cobbs typedef int ng_parse_array_getLength_t(const struct ng_parse_type *type, 231f8307e12SArchie Cobbs const u_char *start, const u_char *buf); 232f8307e12SArchie Cobbs typedef int ng_parse_array_getDefault_t(const struct ng_parse_type *type, 233f8307e12SArchie Cobbs int index, const u_char *start, 234f8307e12SArchie Cobbs u_char *buf, int *buflen); 235f8307e12SArchie Cobbs 236f8307e12SArchie Cobbs /* The 'getDefault' method may be NULL, in which case the default value 237f8307e12SArchie Cobbs is computed from the element type. If not, it should fill in the 238f8307e12SArchie Cobbs default value at *buf (having size *buflen) and update *buflen to the 239f8307e12SArchie Cobbs length of the filled-in value before return. */ 240f8307e12SArchie Cobbs struct ng_parse_fixedarray_info { 241f8307e12SArchie Cobbs const struct ng_parse_type *elementType; 242f8307e12SArchie Cobbs int length; 243f8307e12SArchie Cobbs ng_parse_array_getDefault_t *getDefault; 244f8307e12SArchie Cobbs }; 245f8307e12SArchie Cobbs 246f8307e12SArchie Cobbs /* 247f8307e12SArchie Cobbs * Variable length arrays 248f8307e12SArchie Cobbs * 249f8307e12SArchie Cobbs * Default value: Same as with fixed length arrays 250f8307e12SArchie Cobbs * Additional info: struct ng_parse_array_info * 251f8307e12SArchie Cobbs */ 252f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_array_type; 253f8307e12SArchie Cobbs 254f8307e12SArchie Cobbs struct ng_parse_array_info { 255f8307e12SArchie Cobbs const struct ng_parse_type *elementType; 256f8307e12SArchie Cobbs ng_parse_array_getLength_t *getLength; 257f8307e12SArchie Cobbs ng_parse_array_getDefault_t *getDefault; 258f8307e12SArchie Cobbs }; 259f8307e12SArchie Cobbs 260f8307e12SArchie Cobbs /* 261f8307e12SArchie Cobbs * Arbitrary length strings 262f8307e12SArchie Cobbs * 263f8307e12SArchie Cobbs * Default value: Empty string 264f8307e12SArchie Cobbs * Additional info: None required 265f8307e12SArchie Cobbs */ 266f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_string_type; 267f8307e12SArchie Cobbs 268f8307e12SArchie Cobbs /* 269f8307e12SArchie Cobbs * Bounded length strings. These are strings that have a fixed-size 270f8307e12SArchie Cobbs * buffer, and always include a terminating NUL character. 271f8307e12SArchie Cobbs * 272f8307e12SArchie Cobbs * Default value: Empty string 273f8307e12SArchie Cobbs * Additional info: struct ng_parse_fixedsstring_info * 274f8307e12SArchie Cobbs */ 275f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_fixedstring_type; 276f8307e12SArchie Cobbs 277f8307e12SArchie Cobbs struct ng_parse_fixedsstring_info { 278f8307e12SArchie Cobbs int bufSize; /* size of buffer (including NUL) */ 279f8307e12SArchie Cobbs }; 280f8307e12SArchie Cobbs 281f8307e12SArchie Cobbs /* 282f8307e12SArchie Cobbs * Some commonly used bounded length string types 283f8307e12SArchie Cobbs */ 284f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_nodebuf_type; /* NG_NODELEN + 1 */ 285f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_hookbuf_type; /* NG_HOOKLEN + 1 */ 286f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_pathbuf_type; /* NG_PATHLEN + 1 */ 287f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_typebuf_type; /* NG_TYPELEN + 1 */ 288f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_cmdbuf_type; /* NG_CMDSTRLEN + 1 */ 289f8307e12SArchie Cobbs 290f8307e12SArchie Cobbs /* 291f8307e12SArchie Cobbs * Integer types 292f8307e12SArchie Cobbs * 293f8307e12SArchie Cobbs * Default value: 0 294f8307e12SArchie Cobbs * Additional info: None required 295f8307e12SArchie Cobbs */ 296f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_int8_type; 297f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_int16_type; 298f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_int32_type; 299f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_int64_type; 300f8307e12SArchie Cobbs 301f8307e12SArchie Cobbs /* 302f8307e12SArchie Cobbs * IP address type 303f8307e12SArchie Cobbs * 304f8307e12SArchie Cobbs * Default value: 0.0.0.0 305f8307e12SArchie Cobbs * Additional info: None required 306f8307e12SArchie Cobbs */ 307f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_ipaddr_type; 308f8307e12SArchie Cobbs 309f8307e12SArchie Cobbs /* 310f8307e12SArchie Cobbs * Variable length byte array. The bytes are displayed in hex. 311f8307e12SArchie Cobbs * ASCII form may be either an array of bytes or a string constant, 312f8307e12SArchie Cobbs * in which case the array is zero-filled after the string bytes. 313f8307e12SArchie Cobbs * 314f8307e12SArchie Cobbs * Default value: All bytes are zero 315f8307e12SArchie Cobbs * Additional info: ng_parse_array_getLength_t * 316f8307e12SArchie Cobbs */ 317f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_bytearray_type; 318f8307e12SArchie Cobbs 319f8307e12SArchie Cobbs /* 320f8307e12SArchie Cobbs * Netgraph control message type 321f8307e12SArchie Cobbs * 322f8307e12SArchie Cobbs * Default value: All fields zero 323f8307e12SArchie Cobbs * Additional info: None required 324f8307e12SArchie Cobbs */ 325f8307e12SArchie Cobbs extern const struct ng_parse_type ng_parse_ng_mesg_type; 326f8307e12SArchie Cobbs 327f8307e12SArchie Cobbs /************************************************************************ 328f8307e12SArchie Cobbs CONVERSTION AND PARSING ROUTINES 329f8307e12SArchie Cobbs ************************************************************************/ 330f8307e12SArchie Cobbs 331f8307e12SArchie Cobbs /* Tokens for parsing structs and arrays */ 332f8307e12SArchie Cobbs enum ng_parse_token { 333f8307e12SArchie Cobbs T_LBRACE, /* '{' */ 334f8307e12SArchie Cobbs T_RBRACE, /* '}' */ 335f8307e12SArchie Cobbs T_LBRACKET, /* '[' */ 336f8307e12SArchie Cobbs T_RBRACKET, /* ']' */ 337f8307e12SArchie Cobbs T_EQUALS, /* '=' */ 338f8307e12SArchie Cobbs T_STRING, /* string in double quotes */ 339f8307e12SArchie Cobbs T_ERROR, /* error parsing string in double quotes */ 340f8307e12SArchie Cobbs T_WORD, /* anything else containing no whitespace */ 341f8307e12SArchie Cobbs T_EOF, /* end of string reached */ 342f8307e12SArchie Cobbs }; 343f8307e12SArchie Cobbs 344f8307e12SArchie Cobbs /* 345f8307e12SArchie Cobbs * See typedef ng_parse_t for definition 346f8307e12SArchie Cobbs */ 347f8307e12SArchie Cobbs extern int ng_parse(const struct ng_parse_type *type, const char *string, 348f8307e12SArchie Cobbs int *off, u_char *buf, int *buflen); 349f8307e12SArchie Cobbs 350f8307e12SArchie Cobbs /* 351f8307e12SArchie Cobbs * See typedef ng_unparse_t for definition (*off assumed to be zero). 352f8307e12SArchie Cobbs */ 353f8307e12SArchie Cobbs extern int ng_unparse(const struct ng_parse_type *type, 354f8307e12SArchie Cobbs const u_char *data, char *buf, int buflen); 355f8307e12SArchie Cobbs 356f8307e12SArchie Cobbs /* 357f8307e12SArchie Cobbs * See typedef ng_getDefault_t for definition 358f8307e12SArchie Cobbs */ 359f8307e12SArchie Cobbs extern int ng_parse_getDefault(const struct ng_parse_type *type, 360f8307e12SArchie Cobbs u_char *buf, int *buflen); 361f8307e12SArchie Cobbs 362f8307e12SArchie Cobbs /* 363f8307e12SArchie Cobbs * Parse a token: '*startp' is the offset to start looking. Upon 364f8307e12SArchie Cobbs * successful return, '*startp' equals the beginning of the token 365f8307e12SArchie Cobbs * and '*lenp' the length. If error, '*startp' points at the 366f8307e12SArchie Cobbs * offending character(s). 367f8307e12SArchie Cobbs */ 368f8307e12SArchie Cobbs extern enum ng_parse_token ng_parse_get_token(const char *s, 369f8307e12SArchie Cobbs int *startp, int *lenp); 370f8307e12SArchie Cobbs 371f8307e12SArchie Cobbs /* 372f8307e12SArchie Cobbs * Like above, but specifically for getting a string token and returning 373f8307e12SArchie Cobbs * the string value. The string token must be enclosed in double quotes 374f8307e12SArchie Cobbs * and the normal C backslash escapes are recognized. The caller must 375f8307e12SArchie Cobbs * eventually free() the returned result. Returns NULL if token is 376f8307e12SArchie Cobbs * not a string token, or parse or other error. 377f8307e12SArchie Cobbs */ 378f8307e12SArchie Cobbs extern char *ng_get_string_token(const char *s, int *startp, int *lenp); 379f8307e12SArchie Cobbs 380f8307e12SArchie Cobbs /* 381f8307e12SArchie Cobbs * Convert a raw string into a doubly-quoted string including any 382f8307e12SArchie Cobbs * necessary backslash escapes. Caller must free the result. 383f8307e12SArchie Cobbs * Returns NULL if ENOMEM. 384f8307e12SArchie Cobbs */ 385f8307e12SArchie Cobbs extern char *ng_encode_string(const char *s); 386f8307e12SArchie Cobbs 387f8307e12SArchie Cobbs #endif /* _NETGRAPH_PARSE_H_ */ 388f8307e12SArchie Cobbs 389