|
Click
|
Support for parsing configuration strings. More...
Go to the source code of this file.
Functions | |
Argument Manipulation | |
| const char * | cp_skip_space (const char *begin, const char *end) |
| Find the first nonspace character in the string [begin, end). | |
| const char * | cp_skip_comment_space (const char *begin, const char *end) |
| Find the first nonspace, noncomment character in the string [begin, end). | |
| const char * | cp_skip_double_quote (const char *begin, const char *end) |
| Return the first character after a double-quoted string starting at begin. | |
| bool | cp_eat_space (String &str) |
| Remove spaces from the beginning of str. | |
| bool | cp_is_space (const String &str) |
| Test if str is all spaces. | |
| bool | cp_is_word (const String &str) |
| Test whether str is a valid "word". | |
| bool | cp_is_click_id (const String &str) |
| Test if str is a valid Click identifier. | |
| String | cp_uncomment (const String &str) |
| Simplify str's whitespace and replace comments by spaces, returning the result. | |
| String | cp_unquote (const String &str) |
| Remove one level of quoting from str, returning the result. | |
| const char * | cp_process_backslash (const char *begin, const char *end, StringAccum &sa) |
| Process a backslash escape, appending results to sa. | |
| String | cp_quote (const String &str, bool allow_newlines=false) |
| Return a quoted version of str. | |
| void | cp_argvec (const String &str, Vector< String > &conf) |
| Separate a configuration string into arguments at commas. | |
| String | cp_unargvec (const Vector< String > &conf) |
| Join the strings of conf with commas and return the result. | |
| void | cp_spacevec (const String &str, Vector< String > &conf) |
| Separate a configuration string into arguments at unquoted spaces. | |
| String | cp_shift_spacevec (String &str) |
| Remove and return the first space-separated argument from str. | |
| String | cp_unspacevec (const String *begin, const String *end) |
| Join the strings in [begin, end) with spaces and return the result. | |
| String | cp_unspacevec (const Vector< String > &conf) |
| Join the strings in conf with spaces and return the result. | |
| String | cp_shift_delimiter (String &str, char delim) |
| Remove and return the first delimiter-separated argument from str. | |
Unparsing | |
| String | cp_unparse_bool (bool value) |
| String | cp_unparse_real2 (int32_t value, int frac_bits) |
| String | cp_unparse_real2 (uint32_t value, int frac_bits) |
| String | cp_unparse_real2 (int64_t value, int frac_bits) |
| String | cp_unparse_real2 (uint64_t value, int frac_bits) |
| String | cp_unparse_real10 (int32_t value, int frac_digits) |
| String | cp_unparse_real10 (uint32_t value, int frac_digits) |
| String | cp_unparse_milliseconds (uint32_t value) |
| String | cp_unparse_microseconds (uint32_t value) |
| String | cp_unparse_interval (const Timestamp &value) |
| String | cp_unparse_interval (const struct timeval &value) |
| String | cp_unparse_bandwidth (uint32_t value) |
Legacy Functions | |
| int | cp_va_parse (const Vector< String > &conf, const Element *context, ErrorHandler *errh,...) |
| Legacy function for parsing a list of arguments. | |
| int | cp_va_parse (const String &str, const Element *context, ErrorHandler *errh,...) |
| Legacy function for parsing a comma-separated argument string. | |
| int | cp_va_space_parse (const String &str, const Element *context, ErrorHandler *errh,...) |
| Legacy function for parsing a space-separated argument string. | |
| int | cp_va_parse_keyword (const String &str, const Element *context, ErrorHandler *errh,...) |
| Legacy function for parsing a single argument. | |
| int | cp_va_parse_remove_keywords (Vector< String > &conf, int first, const Element *context, ErrorHandler *errh,...) |
| Legacy function for parsing and removing matching arguments from conf. | |
Direct Parsing Functions | |
| #define | CP_REAL2_MAX_FRAC_BITS 28 |
| enum | CpErrors { CPE_OK = 0 , CPE_FORMAT , CPE_NEGATIVE , CPE_OVERFLOW , CPE_INVALID , CPE_MEMORY , CPE_NOUNITS } |
| enum | { cp_basic_integer_whole = 64 } |
| int | cp_errno |
| bool | cp_string (const String &str, String *result, String *rest=0) |
| Parse a string from str. | |
| bool | cp_word (const String &str, String *result, String *rest=0) |
| Parse a word from str. | |
| bool | cp_keyword (const String &str, String *result, String *rest=0) |
| Parse a keyword from str. | |
| bool | cp_bool (const String &str, bool *result) |
| Parse a boolean from str. | |
| const char * | cp_basic_integer (const char *begin, const char *end, int flags, int size, void *result) |
| const char * | cp_integer (const char *begin, const char *end, int base, int *result) |
| Parse an integer from [begin, end) in base base. | |
| const char * | cp_integer (const char *begin, const char *end, int base, unsigned *result) |
| const char * | cp_integer (const char *begin, const char *end, int base, long *result) |
| const char * | cp_integer (const char *begin, const char *end, int base, unsigned long *result) |
| const char * | cp_integer (const char *begin, const char *end, int base, int64_t *result) |
| const char * | cp_integer (const char *begin, const char *end, int base, uint64_t *result) |
| bool | cp_integer (const String &str, int base, int *result) |
| Parse an integer from str in base base. | |
| bool | cp_integer (const String &str, int base, unsigned int *result) |
| bool | cp_integer (const String &str, int base, long *result) |
| bool | cp_integer (const String &str, int base, unsigned long *result) |
| bool | cp_integer (const String &str, int base, int64_t *result) |
| bool | cp_integer (const String &str, int base, uint64_t *result) |
| bool | cp_integer (const String &str, int *result) |
| Parse an integer from str in base 0. | |
| bool | cp_integer (const String &str, unsigned int *result) |
| bool | cp_integer (const String &str, long *result) |
| bool | cp_integer (const String &str, unsigned long *result) |
| bool | cp_integer (const String &str, int64_t *result) |
| bool | cp_integer (const String &str, uint64_t *result) |
| bool | cp_real2 (const String &str, int frac_bits, int32_t *result) |
| Parse a fixed-point number from str. | |
| bool | cp_real2 (const String &str, int frac_bits, uint32_t *result) |
| bool | cp_real10 (const String &str, int frac_digits, int32_t *result) |
| Parse a real number from str, representing the result as an integer with frac_digits decimal digits of fraction. | |
| bool | cp_real10 (const String &str, int frac_digits, uint32_t *result) |
| bool | cp_real10 (const String &str, int frac_digits, uint32_t *result_int, uint32_t *result_frac) |
| Parse a real number from str, representing the result as an integer with frac_digits decimal digits of fraction. | |
| bool | cp_double (const String &str, double *result) |
| Parse a real number from str. | |
| bool | cp_seconds_as (const String &str, int frac_digits, uint32_t *result) |
| Parse an amount of time from str. | |
| bool | cp_seconds_as_milli (const String &str, uint32_t *result) |
| Parse an amount of time in milliseconds from str. | |
| bool | cp_seconds_as_micro (const String &str, uint32_t *result) |
| Parse an amount of time in microseconds from str. | |
| bool | cp_seconds (const String &str, double *result) |
| Parse an amount of time from str. | |
| bool | cp_time (const String &str, Timestamp *result, bool allow_negative=false) |
| Parse a timestamp from str. | |
| bool | cp_time (const String &str, struct timeval *result) |
| bool | cp_bandwidth (const String &str, uint64_t *result) |
| Parse a bandwidth value from str. | |
| bool | cp_ip_address (const String &str, IPAddress *result, const Element *context=0) |
| Parse an IP address from str. | |
| bool | cp_ip_address (const String &str, struct in_addr *result, const Element *context=0) |
| bool | cp_ip_address (const String &str, unsigned char *result, const Element *context=0) |
| bool | cp_ip_prefix (const String &str, IPAddress *result_addr, IPAddress *result_mask, bool allow_bare_address, const Element *context=0) |
| Parse an IP address or prefix from str. | |
| bool | cp_ip_prefix (const String &str, unsigned char *result_addr, unsigned char *result_mask, bool allow_bare_address, const Element *context=0) |
| bool | cp_ip_prefix (const String &str, IPAddress *result_addr, IPAddress *result_mask, const Element *context=0) |
| bool | cp_ip_prefix (const String &str, unsigned char *result_addr, unsigned char *result_mask, const Element *context=0) |
| bool | cp_ip_address_list (const String &str, Vector< IPAddress > *result, const Element *context=0) |
| Parse a space-separated list of IP addresses from str. | |
| bool | cp_ip6_address (const String &str, IP6Address *result, const Element *context=0) |
| Parse an IPv6 address from str. | |
| bool | cp_ip6_address (const String &str, struct in6_addr *result, const Element *context=0) |
| bool | cp_ip6_address (const String &str, unsigned char *result, const Element *context=0) |
| bool | cp_ip6_prefix (const String &str, IP6Address *result_addr, int *result_prefix, bool allow_bare_address, const Element *context=0) |
| Parse an IPv6 address or prefix from str. | |
| bool | cp_ip6_prefix (const String &str, unsigned char *result_addr, int *result_prefix, bool allow_bare_address, const Element *context=0) |
| bool | cp_ip6_prefix (const String &str, unsigned char *result_addr, unsigned char *result_mask, bool allow_bare_address, const Element *context=0) |
| bool | cp_ip6_prefix (const String &str, IP6Address *result_addr, IP6Address *result_mask, bool allow_bare_address, const Element *context=0) |
| bool | cp_ethernet_address (const String &str, EtherAddress *result, const Element *context=0) |
| Parse an Ethernet address from str. | |
| bool | cp_ethernet_address (const String &str, unsigned char *result, const Element *context=0) |
| bool | cp_tcpudp_port (const String &str, int proto, uint16_t *result, const Element *context=0) |
| Parse a TCP, UDP, etc. port number from str. | |
| Element * | cp_element (const String &str, const Element *context, ErrorHandler *errh=0, const char *argname=0) |
| Parse an element reference from str. | |
| Element * | cp_element (const String &str, Router *router, ErrorHandler *errh=0, const char *argname=0) |
| Parse an element reference from str. | |
| bool | cp_handler_name (const String &str, Element **result_element, String *result_hname, const Element *context, ErrorHandler *errh=0) |
| Parse a handler name from str. | |
| bool | cp_handler (const String &str, int flags, Element **result_element, const Handler **result_handler, const Element *context, ErrorHandler *errh=0) |
| Parse a handler reference from str. | |
| bool | cp_filename (const String &str, String *result) |
| Parse a filename string from str. | |
| bool | cp_file_offset (const String &str, off_t *result) |
| Parse a file offset from str. | |
| bool | cp_anno (const String &str, int size, int *result, const Element *context=0) |
| Parse a packet annotation value from str. | |
cp_va_kparse | |
| enum | CpKparseFlags { cpkN = 0 , cpkM = 1 , cpkP = 2 , cpkC = 4 , cpkD = 8 , cpkNormal = cpkN , cpkMandatory = cpkM , cpkPositional = cpkP , cpkConfirm = cpkC , cpkDeprecated = cpkD } |
| Type of flags for cp_va_kparse() items. More... | |
| typedef const char * | CpVaParseCmd |
| Type of argument type names for cp_va_kparse() items. | |
| const CpVaParseCmd | cpEnd |
| Use as argument name. Ends cp_va argument list. | |
| const CpVaParseCmd | cpIgnoreRest |
| Use as argument name. No result storage; causes cp_va_kparse() to ignore unparsed arguments and any remaining items. | |
| const CpVaParseCmd | cpIgnore |
| No result storage, ignores this argument. | |
| const CpVaParseCmd | cpArgument |
| Result storage String*, accepts any argument. | |
| const CpVaParseCmd | cpArguments |
| Result storage Vector<String>*, accepts any number of arguments with the same keyword. | |
| const CpVaParseCmd | cpString |
| Result storage String*, parsed by cp_string(). | |
| const CpVaParseCmd | cpWord |
| Result storage String*, parsed by cp_word(). | |
| const CpVaParseCmd | cpKeyword |
| Result storage String*, parsed by cp_keyword(). | |
| const CpVaParseCmd | cpBool |
| Result storage bool*, parsed by cp_bool(). | |
| const CpVaParseCmd | cpByte |
| Result storage unsigned char*, parsed by cp_integer(). | |
| const CpVaParseCmd | cpShort |
| Result storage short*, parsed by cp_integer(). | |
| const CpVaParseCmd | cpUnsignedShort |
| Result storage unsigned short*, parsed by cp_integer(). | |
| const CpVaParseCmd | cpInteger |
| Result storage int32_t*, parsed by cp_integer(). | |
| const CpVaParseCmd | cpUnsigned |
| Result storage uint32_t*, parsed by cp_integer(). | |
| const CpVaParseCmd | cpSize |
| Result storage size_t*, parsed by cp_integer(). | |
| const CpVaParseCmd | cpNamedInteger |
| Parse parameter uint32_t nameinfo_type, result storage int32_t*, parsed by NameInfo::query_int. | |
| const CpVaParseCmd | cpInteger64 |
| Result storage int64_t*, parsed by cp_integer(). | |
| const CpVaParseCmd | cpUnsigned64 |
| Result storage uint64_t*, parsed by cp_integer(). | |
| const CpVaParseCmd | cpUnsignedReal2 |
| Parse parameter int frac_bits, result storage uint32_t*, parsed by cp_real2(). | |
| const CpVaParseCmd | cpReal10 |
| Parse parameter int frac_digits, result storage int32_t*, parsed by cp_real10(). | |
| const CpVaParseCmd | cpUnsignedReal10 |
| Parse parameter int frac_digits, result storage uint32_t*, parsed by cp_real10(). | |
| const CpVaParseCmd | cpDouble |
| Result storage double*, parsed by cp_double(). | |
| const CpVaParseCmd | cpSeconds |
| Result storage uint32_t*, parsed by cp_seconds_as() with frac_digits 0. | |
| const CpVaParseCmd | cpSecondsAsMilli |
| Result storage uint32_t*, parsed by cp_seconds_as_milli(). | |
| const CpVaParseCmd | cpSecondsAsMicro |
| Result storage uint32_t*, parsed by cp_seconds_as_micro(). | |
| const CpVaParseCmd | cpTimestamp |
| Result storage Timestamp*, parsed by cp_time(). | |
| const CpVaParseCmd | cpTimestampSigned |
| Result storage Timestamp*, parsed by cp_time(). | |
| const CpVaParseCmd | cpTimeval |
| Result storage struct timeval*, parsed by cp_time(). | |
| const CpVaParseCmd | cpBandwidth |
| Result storage uint32_t*, parsed by cp_bandwidth(). | |
| const CpVaParseCmd | cpIPAddress |
| Result storage IPAddress* or equivalent, parsed by cp_ip_address(). | |
| const CpVaParseCmd | cpIPPrefix |
| Result storage IPAddress* addr and IPAddress *mask, parsed by cp_ip_prefix(). | |
| const CpVaParseCmd | cpIPAddressOrPrefix |
| Result storage IPAddress* addr and IPAddress *mask, parsed by cp_ip_prefix(). | |
| const CpVaParseCmd | cpIPAddressList |
| Result storage Vector<IPAddress>*, parsed by cp_ip_address_list(). | |
| const CpVaParseCmd | cpEtherAddress |
| Result storage EtherAddress*, parsed by cp_ethernet_address(). | |
| const CpVaParseCmd | cpEthernetAddress |
| Result storage EtherAddress*, parsed by cp_ethernet_address(). Synonym for cpEtherAddress. | |
| const CpVaParseCmd | cpTCPPort |
| Result storage uint16_t*, parsed by cp_tcpudp_port(). | |
| const CpVaParseCmd | cpUDPPort |
| Result storage uint16_t*, parsed by cp_tcpudp_port(). | |
| const CpVaParseCmd | cpElement |
| Result storage Element**, parsed by cp_element(). | |
| const CpVaParseCmd | cpElementCast |
| Parse parameter const char*, result storage void**, parsed by cp_element() and Element::cast(). | |
| const CpVaParseCmd | cpHandlerName |
| Result storage Element** and String*, parsed by cp_handler_name(). | |
| const CpVaParseCmd | cpHandlerCallRead |
| Result storage HandlerCall*, parsed by HandlerCall. | |
| const CpVaParseCmd | cpHandlerCallWrite |
| Result storage HandlerCall*, parsed by HandlerCall. | |
| const CpVaParseCmd | cpHandlerCallPtrRead |
| Result storage HandlerCall**, parsed by HandlerCall::reset_read. | |
| const CpVaParseCmd | cpHandlerCallPtrWrite |
| Result storage HandlerCall**, parsed by HandlerCall::reset_write. | |
| const CpVaParseCmd | cpIP6Address |
| Result storage IP6Address* or equivalent, parsed by cp_ip6_address(). | |
| const CpVaParseCmd | cpIP6Prefix |
| Result storage IP6Address* addr and IP6Address* mask, parsed by cp_ip6_prefix(). | |
| const CpVaParseCmd | cpIP6PrefixLen |
| Result storage IP6Address* addr and int* prefix_len, parsed by cp_ip6_prefix(). | |
| const CpVaParseCmd | cpIP6AddressOrPrefix |
| Result storage IP6Address* addr and IP6Address* mask, parsed by cp_ip6_prefix(). | |
| const CpVaParseCmd | cpFilename |
| Result storage String*, parsed by cp_filename(). | |
| const CpVaParseCmd | cpFileOffset |
| Result storage off_t*, parsed by cp_integer(). | |
| const CpVaParseCmd | cpAnno |
| Parse parameter int annotation_size, result storage int*, parsed by cp_anno(). | |
| const CpVaParseCmd | cpOptional |
| cp_va_parse only: Following arguments are optional. | |
| const CpVaParseCmd | cpKeywords |
| cp_va_parse only: Following arguments are keywords. | |
| const CpVaParseCmd | cpConfirmKeywords |
| cp_va_parse only: Following arguments are confirmed keywords. | |
| const CpVaParseCmd | cpMandatoryKeywords |
| cp_va_parse only: Following arguments are mandatory keywords. | |
| const CpVaParseCmd cpInterval | CLICK_CONFPARSE_DEPRECATED |
| int | cp_va_kparse (const Vector< String > &conf, const Element *context, ErrorHandler *errh,...) CP_SENTINEL |
| Parse a list of arguments. | |
| int | cp_va_kparse (const String &str, const Element *context, ErrorHandler *errh,...) CP_SENTINEL |
| Parse a comma-separated argument string. | |
| int | cp_va_space_kparse (const String &str, const Element *context, ErrorHandler *errh,...) CP_SENTINEL |
| Parse a space-separated argument string. | |
| int | cp_va_kparse_keyword (const String &str, const Element *context, ErrorHandler *errh,...) CP_SENTINEL |
| Parse a single argument. | |
| int | cp_va_kparse_remove_keywords (Vector< String > &conf, const Element *context, ErrorHandler *errh,...) CP_SENTINEL |
| Parse and remove matching arguments from conf. | |
| int | cp_assign_arguments (const Vector< String > &argv, const String *param_begin, const String *param_end, Vector< String > *values=0) |
| Assign arguments from argv to values. | |
| void | cp_va_static_initialize () |
| Initialize the cp_va_kparse() implementation. | |
| void | cp_va_static_cleanup () |
| Clean up the cp_va_kparse() implementation. | |
Argument Types for cp_va_kparse() | |
| enum | { cpArgNormal = 0 , cpArgStore2 = 1 , cpArgExtraInt = 2 , cpArgExtraCStr = 4 , cpArgAllowNumbers = 8 } |
| typedef void(* | cp_parsefunc) (cp_value *value, const String &arg, ErrorHandler *errh, const char *argdesc, const Element *context) |
| typedef void(* | cp_storefunc) (cp_value *value, const Element *context) |
| int | cp_register_argtype (const char *name, const char *description, int flags, cp_parsefunc parsefunc, cp_storefunc storefunc, void *user_data=0) |
| void | cp_unregister_argtype (const char *name) |
| int | cp_register_stringlist_argtype (const char *name, const char *description, int flags) |
| int | cp_extend_stringlist_argtype (const char *name,...) |
Support for parsing configuration strings.
Defines functions and helpers for parsing configuration strings into numbers, IP addresses, and other useful types.
Most elements that take configuration strings parse them using the cp_va_kparse() function and friends. These functions take a variable argument list describing the desired arguments and result slots. They parse the configuration, store the results in the slots, report any errors, and return the number of arguments successfully assigned on success or a negative value on failure.
Here are some cp_va_kparse() examples.
This element supports three arguments, DATA (a string), LIMIT (an unsigned integer), and STOP (a boolean). Here are some example element definitions:
An item in a cp_va_kparse() argument list consists of:
"DATA". This example uses more of these features.
This element supports two arguments, P (a fixed-point number with 16 bits of fraction) and NETWORK (an IP prefix, defined by address and mask). Here are some example element definitions:
cp_va_kparse() argument types are defined by CpVaParseCmd constants. For example, the cpInteger argument type parses a 32-bit signed integer. See CpVaParseCmd for more. Elements may also define their own argument types with cp_register_argtype().
You may also call parsing functions directly if cp_va_kparse() doesn't match your needs. These functions have names like cp_bool(), cp_string(), cp_integer(), cp_ip_address(), and so forth, and share a basic interface:
Finally, functions like cp_uncomment(), cp_unquote(), cp_quote(), cp_argvec(), and cp_is_space() manipulate arguments as strings. cp_uncomment() removes comments and simplifies white space; cp_unquote() removes quotation marks and expands backslash escapes; cp_argvec() splits a configuration string at commas; and so forth.
| typedef const char* CpVaParseCmd |
Type of argument type names for cp_va_kparse() items.
| enum CpKparseFlags |
Type of flags for cp_va_kparse() items.
| Enumerator | |
|---|---|
| cpkN | Default flags. |
| cpkM | Argument is mandatory. |
| cpkP | Argument may be specified positionally. |
| cpkC | Argument presence should be confirmed. |
| cpkD | Argument is deprecated. |
| const char * cp_skip_space | ( | const char * | begin, |
| const char * | end | ||
| ) |
Find the first nonspace character in the string [begin, end).
| begin | beginning of string |
| end | one past end of string |
Space characters are defined as by isspace() in the "C" locale, and consist of the characters in [ \f\n\r\t\v].
| const char * cp_skip_comment_space | ( | const char * | begin, |
| const char * | end | ||
| ) |
Find the first nonspace, noncomment character in the string [begin, end).
| begin | beginning of string |
| end | one past end of string |
This function recognizes C-style and C++-style comments:
In C++-style comments, the character sequences "\n", "\r", and "\r\n" are recognized as newlines. The newline is considered part of the comment.
| const char * cp_skip_double_quote | ( | const char * | begin, |
| const char * | end | ||
| ) |
Return the first character after a double-quoted string starting at begin.
| begin | beginning of double-quoted string |
| end | one past end of string |
cp_skip_double_quote() understands all the backslash escapes processed by cp_process_backslash().
| bool cp_eat_space | ( | String & | str | ) |
Remove spaces from the beginning of str.
| [in,out] | str | string |
|
inline |
Test if str is all spaces.
| bool cp_is_word | ( | const String & | str | ) |
Test whether str is a valid "word".
A "word" in Click consists of one or more characters in the ASCII range '!' through '~', inclusive, except for the quote characters '"' and ''', the backslash '\', and the comma ','.
| bool cp_is_click_id | ( | const String & | str | ) |
Test if str is a valid Click identifier.
A Click identifier consists of one or more characters in the set [A-Za-z0-9/_@], with restrictions on where / may appear (it cannot be the first character or the last character, and two adjacent slashes aren't allowed either).
Simplify str's whitespace and replace comments by spaces, returning the result.
Adjacent space characters are preserved in the output unless they appear next to a comment. For example:
Comment characters inside double or single quotes are ignored:
Remove one level of quoting from str, returning the result.
This function acts as cp_uncomment, plus removing one level of quoting. "..." and '...' sequences are replaced by their contents. Backslash escapes are expanded inside double quotes (see cp_process_backslash). Additionally, "\<...>" sequences are expanded outside of any quotes. For example:
| const char * cp_process_backslash | ( | const char * | begin, |
| const char * | end, | ||
| StringAccum & | sa | ||
| ) |
Process a backslash escape, appending results to sa.
| begin | beginning of string |
| end | end of string |
| sa | string accumulator |
This function understands the following backslash escapes.
"\[newline]" is ignored (it adds no characters to sa), where [newline] is one of the sequences "\n", "\r", or "\r\n". "\[C escape]" is processed as in C, where [C escape] is one of the characters in [abfnrtv]. "\\"</tt> expands to a single backslash. Similarly,
<tt>"$"</tt>, <tt>"\'"</tt>, <tt>"\"", and "\," expand to the escaped character. "\[1-3 octal digits]" expands to the given character. "\x[hex digits]" expands to the given character. "\<[hex digits, spaces, and comments]>" expands to the binary string indicated by the hex digits. Spaces and comments are removed. For example, "\<"; it may not because of Doxygen problems.) Return a quoted version of str.
| str | string |
| allow_newlines | If true, then newline sequences are allowed in in the result. If false, then newline sequences should be translated to their backslash escape equivalents. Default is false. |
Returns a double-quoted string that, when unquoted by cp_unquote(), will equal str. The returned string consists of a single double-quoted string, and in particular is never empty.
Separate a configuration string into arguments at commas.
| str | configuration string | |
| [out] | conf | arguments |
The configuration string is broken into arguments at unquoted commas. Each argument is passed through cp_uncomment(), then appended to conf. If the final argument is empty, it is ignored. For example:
Join the strings of conf with commas and return the result.
This function does not quote or otherwise protect the strings in conf. The caller should do that if necessary.
Separate a configuration string into arguments at unquoted spaces.
| str | configuration string | |
| [out] | conf | arguments |
The configuration string is broken into arguments at unquoted spaces. Each argument is passed through cp_uncomment(), then appended to conf. If the final argument is empty, it is ignored. For example:
Remove and return the first space-separated argument from str.
| [in,out] | str | space-separated configuration string |
The first space-separated argument in the configuration string is removed and returned. The returned argument is passed through cp_uncomment(). str is set to the remaining portion of the string, with any preceding spaces and comments removed. If the input string is all spaces and comments, then both the returned string and str will be empty.
Join the strings in [begin, end) with spaces and return the result.
| begin | first string in range |
| end | one past last string in range |
This function does not quote or otherwise protect the strings in [begin, end). The caller should do that if necessary.
Join the strings in conf with spaces and return the result.
This function does not quote or otherwise protect the strings in conf. The caller should do that if necessary.
Remove and return the first delimiter-separated argument from str.
| [in,out] | str | delimiter-separated string |
| [in] | delim | delimiter |
All characters up to the first delimiter character are removed and returned. str is set to the remaining portion of the string, with up to one delimiter character removed.
Parse a string from str.
| str | string | |
| [out] | result | stores parsed result |
| [out] | rest | (optional) stores unparsed portion of str |
Parses a string from str. The first unquoted space encountered ends the string, but spaces are allowed within single or double quotes. Unquoted empty strings are not accepted. If the string fully parses, then the result is unquoted by cp_unquote() and stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.
If rest is nonnull, then the string doesn't need to fully parse; the part of the string starting with the first unquoted space is stored in *rest and the function returns true.
Parse a word from str.
| str | string | |
| [out] | result | stores parsed result |
| [out] | rest | (optional) stores unparsed portion of str |
Parses a word from str. The first unquoted space encountered ends the word. Single and double quotes are removed as by cp_unquote, but the unquoted string must satisfy cp_is_word. If the string fully parses, then the resulting value is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.
If rest is nonnull, then the string doesn't need to fully parse; the part of the string starting with the first unquoted space is stored in *rest and the function returns true (assuming cp_is_word succeeds on the initial portion).
Parse a keyword from str.
| str | string | |
| [out] | result | stores parsed result |
| [out] | rest | (optional) stores unparsed portion of str |
Parses a keyword from str. Keywords consist of characters in [A-Za-z0-9_.:?!]. Quotes and spaces are not allowed; neither is the empty string. If the string fully parses as a keyword, then the resulting value is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.
If rest is nonnull, then the string doesn't need to fully parse; the part of the string starting with the first unquoted space is stored in *rest and the function returns true (assuming the initial portion is a valid keyword).
| bool cp_bool | ( | const String & | str, |
| bool * | result | ||
| ) |
Parse a boolean from str.
| str | string | |
| [out] | result | stores parsed result |
Parses a boolean from str. The following strings are the valid representations for booleans:
If the string fully parses, then the resulting value is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.
|
inline |
Parse an integer from [begin, end) in base base.
| begin | first character in string | |
| end | one past last character in string | |
| base | base of integer: 0 or 2-36 | |
| [out] | result | stores parsed result |
This function parses an integer from the initial characters of a string. The resulting integer is stored in *result.
The integer format consists of an optional initial sign +/-, followed by one or more digits. A negative sign is only accepted if result has a signed type. Digits may be separated by underscores (to make numbers easier to read), but the first and last characters in the integer cannot be underscores, and two underscores can't appear in a row. Some examples:
Digits are numbered from 0-9, then A-Z/a-z. base determines which digits are legal. If base is 0, then a leading 0x or 0X may precede the digits, indicating base 16; a leading 0 indicates base 8; anything else is base 10.
Returns the first character that can't be parsed as part of the integer. If there is no valid integer at the beginning of the string, then returns begin; *result is unchanged.
This function checks for overflow. If an integer is too large for result, then the maximum possible value is stored in result and the cp_errno variable is set to CPE_OVERFLOW. Otherwise, cp_errno is set to CPE_FORMAT (for no valid integer) or CPE_OK (if all was well).
Overloaded versions of this function are available for int, unsigned int, long, unsigned long, and (depending on configuration) long long and unsigned long long result values.
|
inline |
Parse an integer from str in base base.
| str | string | |
| base | base of integer: 0 or 2-36 | |
| [out] | result | stores parsed result |
Parses an integer from an input string. If the string correctly parses as an integer, then the resulting value is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.
Overloaded versions are available for int, unsigned int, long, unsigned long, and (depending on configuration) long long and unsigned long long result values.
|
inline |
Parse an integer from str in base 0.
Same as cp_integer(str, 0, result).
| bool cp_real2 | ( | const String & | str, |
| int | frac_bits, | ||
| int32_t * | result | ||
| ) |
Parse a fixed-point number from str.
| str | string | |
| frac_bits | number of bits of fraction, 0-CP_REAL2_MAX_FRAC_BITS | |
| [out] | result | stores parsed result |
Parses a real number from an input string. The result is represented as a fixed-point number with frac_bits bits of fraction. For example, the number 0.5 would be represented as 0x1 if frac_bits == 1, or 0x8000 if frac_bits == 16. If the string fully parses, then the resulting value is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.
The real number format is the familiar decimal format parsed by, for example, C's strtod() function. It consists of, in order:
+ or - sign. E<digits>, E+<digits>, or E-<digits>).There must be at least one digit in either the integer part or the fraction part. As with cp_integer, digits can be separated by underscores to make large numbers easier to read. Some examples:
This function checks for overflow. If a number is too large for result, then the maximum possible value is stored in result and the cp_errno variable is set to CPE_OVERFLOW. Otherwise, cp_errno is set to CPE_FORMAT (unparsable input) or CPE_OK (if all was well). Underflow is handled by rounding the result to the nearest representable number.
The following invariant always holds for all values x and fraction bits frac_bits:
An overloaded version of this function is available for uint32_t result values; it doesn't accept negative numbers.
| bool cp_real10 | ( | const String & | str, |
| int | frac_digits, | ||
| int32_t * | result | ||
| ) |
Parse a real number from str, representing the result as an integer with frac_digits decimal digits of fraction.
| str | string | |
| frac_digits | number of decimal digits of fraction, 0-9 | |
| [out] | result | stores parsed result |
Parses a real number from an input string. The result is represented as an integer with frac_digits decimal digits of fraction. For example, the number 0.5 would be represented as 5 if frac_digits == 1, or 5000 if frac_digits == 4. If the string fully parses, then the resulting value is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.
The real number format and error conditions are the same as for cp_real2().
An overloaded version of this function is available for uint32_t result values; it doesn't accept negative numbers.
| bool cp_real10 | ( | const String & | str, |
| int | frac_digits, | ||
| uint32_t * | result_int_part, | ||
| uint32_t * | result_frac_part | ||
| ) |
Parse a real number from str, representing the result as an integer with frac_digits decimal digits of fraction.
| str | string | |
| frac_digits | number of decimal digits of fraction, 0-9 | |
| [out] | result_int_part | stores integer portion of parsed result |
| [out] | result_frac_part | stores fractional portion of parsed result |
Parses an unsigned real number from an input string. The result is represented with frac_digits decimal digits of fraction. The integer and fraction parts of the result are stored in two separate integers, result_int_part and result_frac_part. For example, the number 10.5 would be represented as 10 and 5 if frac_digits == 1, or 10 and 5000 if frac_digits == 4. If the string fully parses, then the resulting value is stored in the result variables and the function returns true. Otherwise, the result variables remains unchanged and the function returns false.
The real number format and error conditions are the same as for cp_real2(). (Negative numbers are not allowed.)
| bool cp_double | ( | const String & | str, |
| double * | result | ||
| ) |
Parse a real number from str.
| str | string | |
| [out] | result | stores parsed result |
Parses a real number from an input string in double format. It is basically equivalent to C's strtod(), but follows Click's configuration parsing conventions: If the string fully parses, then the resulting value is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false. If a number is too large for result, then the maximum possible value is stored in result and the cp_errno variable is set to CPE_OVERFLOW; otherwise, cp_errno is set to CPE_FORMAT (unparsable) or CPE_OK (if all was well).
This function is not available in the kernel, since double objects cannot be used there.
| bool cp_seconds_as | ( | const String & | str, |
| int | frac_digits, | ||
| uint32_t * | result | ||
| ) |
Parse an amount of time from str.
| str | string | |
| frac_digits | number of decimal digits of fraction, 0-9 | |
| [out] | result | stores parsed result |
Parses an amount of time, measured in seconds, from str. frac_digits is the number of decimal digits of fraction returned in the result. For example, to measure the result in milliseconds, set frac_digits == 3; for microseconds, set frac_digits == 6. Does not handle negative amounts of time.
The input string is a real number (as in cp_real2) followed by an optional unit suffix. Units are:
The default unit suffix is seconds. Thus, "3600", "3600s", "3.6e6 msec", "60m", and "1 hr" all parse to the same result, 3600 seconds.
If the string fully parses, then the resulting value is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.
If a number is too large for result, then the maximum possible value is stored in result and the cp_errno variable is set to CPE_OVERFLOW; otherwise, cp_errno is set to CPE_FORMAT (unparsable) or CPE_OK (if all was well).
| bool cp_seconds_as_milli | ( | const String & | str, |
| uint32_t * | result | ||
| ) |
Parse an amount of time in milliseconds from str.
| str | string | |
| [out] | result | stores parsed result |
Parses an amount of time, measured in milliseconds, from str. Equivalent to cp_seconds_as(str, 3, result).
| bool cp_seconds_as_micro | ( | const String & | str, |
| uint32_t * | result | ||
| ) |
Parse an amount of time in microseconds from str.
| str | string | |
| [out] | result | stores parsed result |
Parses an amount of time, measured in microseconds, from str. Equivalent to cp_seconds_as(str, 6, result).
| bool cp_seconds | ( | const String & | str, |
| double * | result | ||
| ) |
Parse an amount of time from str.
| str | string | |
| [out] | result | stores parsed result |
Parses an amount of time, measured in seconds, from str. As in cp_seconds_as(), the input string is a real number followed by an optional unit suffix which defaults to seconds.
If the string fully parses, then the resulting value is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.
Parse a timestamp from str.
| str | string | |
| [out] | result | stores parsed result |
| allow_negative | allow negative timestamps if true |
Parses a timestamp from str. Timestamps are expressed as fractional amounts of seconds, usually measured in Unix time, such as "1189383079.180265331". The input format accepts the unit suffixes described at cp_seconds_as. If the string fully parses, then the resulting value is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.
If a number is too large for result, then the maximum possible value is stored in result and the cp_errno variable is set to CPE_OVERFLOW; otherwise, cp_errno is set to CPE_FORMAT (unparsable) or CPE_OK (if all was well).
An overloaded version of this function is available for struct timeval result values.
| bool cp_bandwidth | ( | const String & | str, |
| uint64_t * | result | ||
| ) |
Parse a bandwidth value from str.
| str | string | |
| [out] | result | stores parsed result |
Parses a bandwidth value from str. The input format is a real number followed by an optional unit suffix. Units are:
The default unit suffix is bytes per second.
If a number is too large for result, then the maximum possible value is stored in result and the cp_errno variable is set to CPE_OVERFLOW; otherwise, cp_errno is set to CPE_FORMAT (unparsable) or CPE_OK (if all was well).
Parse an IP address from str.
| str | string | |
| [out] | result | stores parsed result |
| context | optional context for AddressInfo |
Parses an IP address from str. The input format is the usual dotted-quad format, as in "18.26.4.9", where each number is a decimal number from 0-255. The AddressInfo element can be used to register shorthand names for other IP addresses. If the string fully parses, then the resulting value is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.
Overloaded versions of this function are available for unsigned char[4] and struct in_addr * result types.
| bool cp_ip_prefix | ( | const String & | str, |
| IPAddress * | result_addr, | ||
| IPAddress * | result_mask, | ||
| bool | allow_bare_address, | ||
| const Element * | context | ||
| ) |
Parse an IP address or prefix from str.
| str | string | |
| [out] | result_addr | stores parsed address result |
| [out] | result_mask | stores parsed address mask result |
| allow_bare_address | optional: if true, allow raw IP addresses; defaults to false | |
| context | optional context for AddressInfo |
Parses an IP prefix description from str. The input format is the usual CIDR format with some additions. Allowed examples:
"18.26.4.0/24": the default CIDR format. The prefix length, here 24, is a number between 0 and 32. This stores the equivalents of 18.26.4.0 in *result_addr and 255.255.255.0 in *result_mask. "18.26.4/24": it is OK to leave off irrelevant parts of the address. However, "18.26/24" will not parse. "18.26.4.0/255.255.255.0": the mask may be specified directly. This is the only way to define a non-prefix mask. "a/24" is parseable as an IP prefix. The address part need not fit entirely within the prefix. "18.26.4.9/24" will parse into address 18.26.4.9 and mask 255.255.255.0.
If allow_bare_address is true, then a raw IP address is also acceptable input. The resulting mask will equal 255.255.255.255. Raw IP addresses take precedence over networks, so given AddressInfo(a 18.26.4.9/24), "a" will parse as 18.26.4.9/32, not 18.26.4/24. allow_bare_address defaults to false.
If the string fully parses, then the resulting address is stored in *result_addr, the resulting mask is stored in *result_mask, and the function returns true. Otherwise, the results remain unchanged and the function returns false.
Overloaded versions of this function are available for unsigned char[4] result types.
| bool cp_ip_address_list | ( | const String & | str, |
| Vector< IPAddress > * | result, | ||
| const Element * | context | ||
| ) |
Parse a space-separated list of IP addresses from str.
| str | string | |
| [out] | result | stores parsed result |
| context | optional context for AddressInfo |
Parses a space-separated list of IP addresses from str. Each individual IP address is parsed as by cp_ip_address(). If the string fully parses, then *result is set to the resulting values in order. Otherwise, *result remains unchanged and the function returns false.
In addition to errors from cp_ip_address(), this function might run out of memory for *result, which produces a CPE_MEMORY error.
Parse an IPv6 address from str.
| str | string | |
| [out] | result | stores parsed result |
| context | optional context for AddressInfo |
Parses an IPv6 address from str. The input format may be any of the forms allowed by RFC2373:
"1080:0:0:0:8:800:200C:417a"."1080::8:800:200C:417A"."::13.1.68.3", "::FFFF:129.144.52.38", and (assuming the appropriate AddressInfo information) "0::ip4_addr".The AddressInfo element can be used to register shorthand names for other IPv6 addresses. If the string fully parses, then the resulting value is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.
An overloaded version of this function is available for unsigned char[16] result type.
| bool cp_ip6_prefix | ( | const String & | str, |
| IP6Address * | result_addr, | ||
| int * | result_prefix, | ||
| bool | allow_bare_address, | ||
| const Element * | context | ||
| ) |
Parse an IPv6 address or prefix from str.
| str | string | |
| [out] | result_addr | stores parsed address result |
| [out] | result_prefix | stores parsed prefix length result |
| allow_bare_address | if true, allow raw IPv6 addresses | |
| context | optional context for AddressInfo |
Parses an IPv6 prefix description from str. The input format is the usual CIDR format: an IPv6 address, followed by "/prefixlen", where prefixlen is a number between 0 and 128. As an extension, the format "addr/mask" is supported, where both addr and mask are valid IPv6 addresses. However, unlike cp_ip_prefix(), mask must correspond to a valid prefix length – some number of one bits, followed by all zero bits. For example, "::/::1" will not parse. Finally, AddressInfo names may be used to specify the address part or the whole prefix.
The address part need not fit entirely within the prefix. "::1/32" will parse into address ::1 and prefix length 32.
If allow_bare_address is true, then a raw IPv6 address is also acceptable input. The resulting prefix will equal 128.
If the string fully parses, then the resulting address is stored in *result_addr, the resulting prefix length is stored in *result_prefix, and the function returns true. Otherwise, the results remain unchanged and the function returns false.
Overloaded versions of this function are available for unsigned char[16] result address type, and for IP6Address or unsigned char[16] result masks (instead of result prefix lengths).
| bool cp_ethernet_address | ( | const String & | str, |
| EtherAddress * | result, | ||
| const Element * | context | ||
| ) |
Parse an Ethernet address from str.
| str | string | |
| [out] | result | stores parsed result |
| context | optional context for AddressInfo |
Parses an Ethernet address from str. The input format is the IEEE standard format, as in "00-15-58-2D-FB-8F": six dash-separated 8-bit hexadecimal numbers in transmission order. Colons are also accepted as separators. The AddressInfo element can be used to register shorthand names for other Ethernet addresses. If the string fully parses, then the resulting value is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.
An overloaded version of this function is available for unsigned char[6] result type.
Parse a TCP, UDP, etc. port number from str.
| str | string | |
| proto | protocol number, e.g. IP_PROTO_TCP == 6 | |
| [out] | result | stores parsed result |
| context | optional context for IPNameInfo |
Parses a port number for IP protocol proto from str. The input may be a 16-bit number parsable by cp_integer(), as in "80". It may also be a port name, such as "www". Several port names are defined by default, including auth, chargen, echo, finger, ftp, https, ntp, and www. The PortInfo element can be used to define additional names, and at user level, cp_tcpudp_port() will consult the /etc/services database using getservbyname() as a last resort. If the string fully parses, then the resulting value is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.
| Element * cp_element | ( | const String & | str, |
| const Element * | context, | ||
| ErrorHandler * | errh, | ||
| const char * | argname | ||
| ) |
Parse an element reference from str.
| str | string |
| context | element context |
| errh | optional error handler |
| argname | optional argument name (used for error messages) |
Parses an element reference from str. The input must be a single (possibly quoted) string acceptable to cp_string(). The unquoted value should be an element name. The name may be relative to a compound element; for instance, if context is an element named a/b/c/xxx, and str was "yyy", then cp_element() would search for elements named a/b/c/yyy, a/b/yyy, a/yyy, and finally yyy, returning the first one found. (See Router::find().) If no element is found, reports an error to errh and returns null. If errh is null, no error is reported.
| Element * cp_element | ( | const String & | str, |
| Router * | router, | ||
| ErrorHandler * | errh, | ||
| const char * | argname | ||
| ) |
Parse an element reference from str.
| str | string |
| router | router |
| errh | optional error handler |
| argname | optional argument name (used for error messages) |
Parses an element reference from str. The input must be a single (possibly quoted) string acceptable to cp_string(). The unquoted value should be a fully qualified element name corresponding to an element in router. If no element is found, reports an error to errh and returns null. If errh is null, no error is reported.
| bool cp_handler_name | ( | const String & | str, |
| Element ** | result_element, | ||
| String * | result_hname, | ||
| const Element * | context, | ||
| ErrorHandler * | errh | ||
| ) |
Parse a handler name from str.
| str | string | |
| [out] | result_element | stores parsed element result |
| [out] | result_hname | stores parsed handler name result |
| context | element context | |
| errh | optional error handler |
Parses a handler name from str. Three formats are supported:
"elementname.handlername", for a handler on a named element. The named element must exist; it is looked up as by cp_element() in the compound element context specified by context.".handlername", for a global handler on context's router."handlername", for a handler on the context element (if such a handler exists), or a global handler on context's router.The handler name must contain at least one character. Although the named element must exist, this function does not check whether the named handler exists. The input string may contain quotes; it is unquoted by cp_string().
If the string fully parses, then the resulting element is stored in *result_element, the resulting handler name is stored in *result_hname, and the function returns true. For global handlers, *result_element is set to Router::root_element(). If the string does not fully parse, the results remain unchanged and the function returns false.
| bool cp_handler | ( | const String & | str, |
| int | flags, | ||
| Element ** | result_element, | ||
| const Handler ** | result_handler, | ||
| const Element * | context, | ||
| ErrorHandler * | errh | ||
| ) |
Parse a handler reference from str.
| str | string | |
| flags | zero or more of Handler::f_read, Handler::f_write, and HandlerCall::f_preinitialize | |
| [out] | result_element | stores parsed element result |
| [out] | result_handler | stores parsed handler result |
| context | element context | |
| errh | optional error handler |
Parses a handler reference from str. The input format is as in cp_handler_name(), but the named handler must actually exist. The flags argument lets the caller check for read and/or write handlers; its values are as for HandlerCall::initialize(). If the string fully parses, then the resulting element is stored in *result_element, the resulting handler is stored in *result_handler, and the function returns true. For global handlers, *result_element is set to Router::root_element(). If the string does not fully parse, the results remain unchanged and the function returns false.
Parse a filename string from str.
| str | string | |
| [out] | result | stores parsed result |
Parses a filename from str. This behaves like cp_string() plus shell-style tilde expansion. Thus, ~/ at the beginning of a string is replaced with the value of the HOME environment variable (if it exists), and ~username/ is replaced with the given user's home directory as returned by getpwnam() (if the given user exists). Additionally, double slashes are replaced by single slashes. Thus, "~//myfile.txt~" might parse to "/home/kohler/myfile.txt~". Empty strings are not accepted. If the string fully parses, then the result is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.
This function is only available at user level.
| bool cp_file_offset | ( | const String & | str, |
| off_t * | result | ||
| ) |
Parse a file offset from str.
| str | string | |
| [out] | result | stores parsed result |
Parses an unsigned integer from str, similarly to cp_integer(str, result).
Parse a packet annotation value from str.
| str | string | |
| size | annotation size, or <= 0 to not check size | |
| [out] | result | stores parsed result |
| context | element context |
Parses a packet annotation value from str. This is either a predefined annotation name, such as PAINT or ICMP_PARAM_PROB (all names from <click/packet_anno.hh> are defined by default); a user-defined name (see the AnnotationInfo element); or an integer indicating the byte offset into the annotation area.
If size <= 0, then the annotation value is returned as is. Use the ANNOTATIONINFO_OFFSET and ANNOTATIONINFO_SIZE macros to extract the offset and size portions. If size > 0, then the annotation value is checked to ensure that the sizes are compatible. For instance, if size == 1, then the "DST_IP" annotation is rejected since it has the wrong size. In this case, the value stored in *result equals the annotation offset – the size is masked off.
Values that extend past the end of the annotation area are rejected.
If the string fully parses, then the result is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.
| int cp_va_kparse | ( | const Vector< String > & | conf, |
| const Element * | context, | ||
| ErrorHandler * | errh, | ||
| ... | |||
| ) |
Parse a list of arguments.
| conf | argument list |
| context | element context |
| errh | error handler |
| ... | zero or more parameter items, terminated by cpEnd |
The arguments in conf are parsed according to the items. Each supplied argument must match one of the items, and at least one argument must match each mandatory item. Any errors are reported to errh. If no error occurs, then the item results are assigned appropriately, and the function returns the number of assigned items, which might be 0. If any error occurs, then the item results are left unchanged and the function returns a negative error code.
The context argument is passed to any parsing functions that require element context. See above for more information on cp_va_kparse() items.
The item list must be terminated with cpEnd. An error message such as "warning: missing sentinel in function call" indicates that you terminated the list with 0 instead. Fix it by replacing the 0 with cpEnd.
| int cp_va_kparse | ( | const String & | str, |
| const Element * | context, | ||
| ErrorHandler * | errh, | ||
| ... | |||
| ) |
Parse a comma-separated argument string.
| str | comma-separated argument string |
| context | element context |
| errh | error handler |
| ... | zero or more parameter items, terminated by cpEnd |
The argument string is separated into an argument list by cp_argvec(), after which the function behaves like cp_va_kparse(const Vector<String>&, Element *, ErrorHandler *, ...).
| int cp_va_space_kparse | ( | const String & | str, |
| const Element * | context, | ||
| ErrorHandler * | errh, | ||
| ... | |||
| ) |
Parse a space-separated argument string.
| str | space-separated argument string |
| context | element context |
| errh | error handler |
| ... | zero or more parameter items, terminated by cpEnd |
The argument string is separated into an argument list by cp_spacevec(), after which the function behaves like cp_va_kparse(const Vector<String>&, Element *, ErrorHandler *, ...).
| int cp_va_kparse_keyword | ( | const String & | str, |
| const Element * | context, | ||
| ErrorHandler * | errh, | ||
| ... | |||
| ) |
Parse a single argument.
| str | argument |
| context | element context |
| errh | error handler |
| ... | zero or more parameter items, terminated by cpEnd |
An argument list consisting of the single argument str is formed, after which this function behaves like cp_va_kparse(const Vector<String>&, Element *, ErrorHandler *, ...).
| int cp_va_kparse_remove_keywords | ( | Vector< String > & | conf, |
| const Element * | context, | ||
| ErrorHandler * | errh, | ||
| ... | |||
| ) |
Parse and remove matching arguments from conf.
| conf | argument list |
| context | element context |
| errh | error handler |
| ... | zero or more parameter items, terminated by cpEnd |
The arguments in conf are parsed according to the items. At least one argument must correspond to each mandatory item, but extra arguments are not errors. If no error occurs, then the item results are assigned appropriately; any arguments that successfully matched are removed from conf; and the function returns the number of assigned items, which might be 0. If any error occurs, then conf and the item results are left unchanged and the function returns a negative error code. Errors are reported to errh.
The context argument is passed to any parsing functions that require element context.
| int cp_assign_arguments | ( | const Vector< String > & | argv, |
| const String * | param_begin, | ||
| const String * | param_end, | ||
| Vector< String > * | values | ||
| ) |
Assign arguments from argv to values.
| argv | argument array |
| param_begin | start iterator for parameter list |
| param_end | end iterator for parameter list |
| values | value storage (may equal null or &argv) |
This function is used to resolve an argument array. The range [param_begin, param_end) defines the parameter names. This range begins with zero or more empty strings, which define mandatory positional arguments. It continues with zero or more nonempty strings, which define optional keyword arguments with the corresponding names. It may optionally conclude with "__REST__", which says that the last value should collect all unassigned arguments.
cp_assign_arguments attempts to assign the arguments in argv to the corresponding parameters. This succeeds if all mandatory positional arguments are present and all other arguments are accounted for, either by keywords or by "__REST__". On success, returns >= 0. On failure because the argument list is invalid, returns -EINVAL. On other failure cases, such as out of memory, returns another negative error code.
On success, cp_assign_arguments also optionally assigns *values to the resulting value list. *values is resized to size (param_end - param_begin), and *values[i] is set to the argument corresponding to param_begin[i]. If values is null this step is skipped and the function has no side effects. It is safe to set values to &argv.
| void cp_va_static_initialize | ( | ) |
Initialize the cp_va_kparse() implementation.
This function must be called before any cp_va function is called. It is safe to call it multiple times.
| void cp_va_static_cleanup | ( | ) |
Clean up the cp_va_kparse() implementation.
Call this function to release any memory allocated by the cp_va implementation. As a side effect, this function unregisters all argument types registered by cp_register_argtype().
| int cp_va_parse | ( | const Vector< String > & | conf, |
| const Element * | context, | ||
| ErrorHandler * | errh, | ||
| ... | |||
| ) |
Legacy function for parsing a list of arguments.
never
| conf | argument list |
| context | element context |
| errh | error handler |
| ... | zero or more parameter descriptions, terminated by cpEnd |
Older versions of Click used cp_va_parse() instead of the current cp_va_kparse(). This guide shows how to transition cp_va_parse() calls into cp_va_kparse().
There are two major differences between the variants. First, every argument to cp_va_kparse() must have a keyword name, including arguments that are normally specified by position. Second, each cp_va_parse() argument includes an "argument description string" used to improve error messages. cp_va_kparse() arguments do not take such a string; the keyword generates better, more concise messages.
The following examples, taken from Click elements, show how to change concrete cp_va_parse() calls into cp_va_kparse() calls.
| int cp_va_parse | ( | const String & | str, |
| const Element * | context, | ||
| ErrorHandler * | errh, | ||
| ... | |||
| ) |
Legacy function for parsing a comma-separated argument string.
| str | comma-separated argument string |
| context | element context |
| errh | error handler |
| ... | zero or more parameter descriptions, terminated by cpEnd |
| int cp_va_space_parse | ( | const String & | str, |
| const Element * | context, | ||
| ErrorHandler * | errh, | ||
| ... | |||
| ) |
Legacy function for parsing a space-separated argument string.
| str | space-separated argument string |
| context | element context |
| errh | error handler |
| ... | zero or more parameter descriptions, terminated by cpEnd |
| int cp_va_parse_keyword | ( | const String & | str, |
| const Element * | context, | ||
| ErrorHandler * | errh, | ||
| ... | |||
| ) |
Legacy function for parsing a single argument.
| str | argument |
| context | element context |
| errh | error handler |
| ... | zero or more parameter descriptions, terminated by cpEnd |
| int cp_va_parse_remove_keywords | ( | Vector< String > & | conf, |
| int | first, | ||
| const Element * | context, | ||
| ErrorHandler * | errh, | ||
| ... | |||
| ) |
Legacy function for parsing and removing matching arguments from conf.
| conf | argument list |
| first | index of first non-mandatory argument |
| context | element context |
| errh | error handler |
| ... | zero or more parameter descriptions, terminated by cpEnd |
|
extern |
Use as argument name. Ends cp_va argument list.
| const CpVaParseCmd cpIgnoreRest |
Use as argument name. No result storage; causes cp_va_kparse() to ignore unparsed arguments and any remaining items.
| const CpVaParseCmd cpIgnore |
No result storage, ignores this argument.
| const CpVaParseCmd cpArgument |
Result storage String*, accepts any argument.
| const CpVaParseCmd cpArguments |
Result storage Vector<String>*, accepts any number of arguments with the same keyword.
| const CpVaParseCmd cpString |
Result storage String*, parsed by cp_string().
| const CpVaParseCmd cpWord |
Result storage String*, parsed by cp_word().
| const CpVaParseCmd cpKeyword |
Result storage String*, parsed by cp_keyword().
| const CpVaParseCmd cpBool |
Result storage bool*, parsed by cp_bool().
| const CpVaParseCmd cpByte |
Result storage unsigned char*, parsed by cp_integer().
| const CpVaParseCmd cpShort |
Result storage short*, parsed by cp_integer().
| const CpVaParseCmd cpUnsignedShort |
Result storage unsigned short*, parsed by cp_integer().
| const CpVaParseCmd cpInteger |
Result storage int32_t*, parsed by cp_integer().
| const CpVaParseCmd cpUnsigned |
Result storage uint32_t*, parsed by cp_integer().
| const CpVaParseCmd cpSize |
Result storage size_t*, parsed by cp_integer().
| const CpVaParseCmd cpNamedInteger |
Parse parameter uint32_t nameinfo_type, result storage int32_t*, parsed by NameInfo::query_int.
| const CpVaParseCmd cpInteger64 |
Result storage int64_t*, parsed by cp_integer().
| const CpVaParseCmd cpUnsigned64 |
Result storage uint64_t*, parsed by cp_integer().
| const CpVaParseCmd cpUnsignedReal2 |
Parse parameter int frac_bits, result storage uint32_t*, parsed by cp_real2().
| const CpVaParseCmd cpReal10 |
Parse parameter int frac_digits, result storage int32_t*, parsed by cp_real10().
| const CpVaParseCmd cpUnsignedReal10 |
Parse parameter int frac_digits, result storage uint32_t*, parsed by cp_real10().
| const CpVaParseCmd cpDouble |
Result storage double*, parsed by cp_double().
| const CpVaParseCmd cpSeconds |
Result storage uint32_t*, parsed by cp_seconds_as() with frac_digits 0.
| const CpVaParseCmd cpSecondsAsMilli |
Result storage uint32_t*, parsed by cp_seconds_as_milli().
| const CpVaParseCmd cpSecondsAsMicro |
Result storage uint32_t*, parsed by cp_seconds_as_micro().
| const CpVaParseCmd cpTimestamp |
Result storage Timestamp*, parsed by cp_time().
| const CpVaParseCmd cpTimestampSigned |
Result storage Timestamp*, parsed by cp_time().
| const CpVaParseCmd cpTimeval |
Result storage struct timeval*, parsed by cp_time().
| const CpVaParseCmd cpBandwidth |
Result storage uint32_t*, parsed by cp_bandwidth().
| const CpVaParseCmd cpIPAddress |
Result storage IPAddress* or equivalent, parsed by cp_ip_address().
| const CpVaParseCmd cpIPPrefix |
Result storage IPAddress* addr and IPAddress *mask, parsed by cp_ip_prefix().
| const CpVaParseCmd cpIPAddressOrPrefix |
Result storage IPAddress* addr and IPAddress *mask, parsed by cp_ip_prefix().
| const CpVaParseCmd cpIPAddressList |
Result storage Vector<IPAddress>*, parsed by cp_ip_address_list().
| const CpVaParseCmd cpEtherAddress |
Result storage EtherAddress*, parsed by cp_ethernet_address().
| const CpVaParseCmd cpEthernetAddress |
Result storage EtherAddress*, parsed by cp_ethernet_address(). Synonym for cpEtherAddress.
| const CpVaParseCmd cpTCPPort |
Result storage uint16_t*, parsed by cp_tcpudp_port().
| const CpVaParseCmd cpUDPPort |
Result storage uint16_t*, parsed by cp_tcpudp_port().
| const CpVaParseCmd cpElement |
Result storage Element**, parsed by cp_element().
| const CpVaParseCmd cpElementCast |
Parse parameter const char*, result storage void**, parsed by cp_element() and Element::cast().
| const CpVaParseCmd cpHandlerName |
Result storage Element** and String*, parsed by cp_handler_name().
| const CpVaParseCmd cpHandlerCallRead |
Result storage HandlerCall*, parsed by HandlerCall.
| const CpVaParseCmd cpHandlerCallWrite |
Result storage HandlerCall*, parsed by HandlerCall.
| const CpVaParseCmd cpHandlerCallPtrRead |
Result storage HandlerCall**, parsed by HandlerCall::reset_read.
| const CpVaParseCmd cpHandlerCallPtrWrite |
Result storage HandlerCall**, parsed by HandlerCall::reset_write.
| const CpVaParseCmd cpIP6Address |
Result storage IP6Address* or equivalent, parsed by cp_ip6_address().
| const CpVaParseCmd cpIP6Prefix |
Result storage IP6Address* addr and IP6Address* mask, parsed by cp_ip6_prefix().
| const CpVaParseCmd cpIP6PrefixLen |
Result storage IP6Address* addr and int* prefix_len, parsed by cp_ip6_prefix().
| const CpVaParseCmd cpIP6AddressOrPrefix |
Result storage IP6Address* addr and IP6Address* mask, parsed by cp_ip6_prefix().
| const CpVaParseCmd cpFilename |
Result storage String*, parsed by cp_filename().
| const CpVaParseCmd cpFileOffset |
Result storage off_t*, parsed by cp_integer().
| const CpVaParseCmd cpAnno |
Parse parameter int annotation_size, result storage int*, parsed by cp_anno().
| const CpVaParseCmd cpOptional |
cp_va_parse only: Following arguments are optional.
| const CpVaParseCmd cpKeywords |
cp_va_parse only: Following arguments are keywords.
| const CpVaParseCmd cpConfirmKeywords |
cp_va_parse only: Following arguments are confirmed keywords.
| const CpVaParseCmd cpMandatoryKeywords |
cp_va_parse only: Following arguments are mandatory keywords.