]> git.ipfire.org Git - thirdparty/squid.git/blame - src/Parsing.h
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / Parsing.h
CommitLineData
c8f4eac4 1/*
f70aedc4 2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
c8f4eac4 3 *
bbc27441
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
c8f4eac4 7 */
8
bbc27441
AJ
9/* DEBUG: section 03 Configuration File Parsing */
10
c8f4eac4 11#ifndef SQUID_PARSING_H
12#define SQUID_PARSING_H
13
582c2af2 14#include "ip/Address.h"
c8f4eac4 15
8a648e8d
FC
16double xatof(const char *token);
17int xatoi(const char *token);
e398d16e 18unsigned int xatoui(const char *token, char eov = '\0');
8a648e8d 19long xatol(const char *token);
e398d16e 20int64_t xatoll(const char *token, int base, char eov = '\0');
8a648e8d 21unsigned short xatos(const char *token);
b1fb3348
AJ
22
23/**
24 * Parse a 64-bit integer value.
25 */
8a648e8d 26int64_t GetInteger64(void);
b1fb3348
AJ
27
28/**
29 * Parses an integer value.
30 * Uses a method that obeys hexadecimal 0xN syntax needed for certain bitmasks.
54a063a2 31 * self_destruct() will be called to abort when invalid tokens are encountered.
b1fb3348 32 */
8a648e8d 33int GetInteger(void);
b1fb3348 34
54a063a2
TX
35/**
36 * Parse a percentage value, e.g., 20%.
37 * The behavior of this function is similar as GetInteger().
38 * The difference is that the token might contain '%' as percentage symbol (%),
1454480a 39 * and we may further check whether the value is in the range of [0, 100].
54a063a2 40 * For example, 20% and 20 are both valid tokens, while 101%, 101, -1 are invalid.
1454480a
AJ
41 *
42 * \param limit whether to check the value is within 0-100% limit
43 *
44 * \return the percentage as a decimal number. ie 100% = 1.00, 50% = 0.5
54a063a2 45 */
1454480a 46double GetPercentage(bool limit = true);
54a063a2 47
8a648e8d 48unsigned short GetShort(void);
c8f4eac4 49
053b1f59 50// on success, returns true and sets *p (if any) to the end of the integer
8a648e8d
FC
51bool StringToInt(const char *str, int &result, const char **p, int base);
52bool StringToInt64(const char *str, int64_t &result, const char **p, int base);
053b1f59 53
82b7abe3 54/**
b7ac5457 55 * Parse a socket address (host:port), fill the given Ip::Address object
82b7abe3
AJ
56 * \retval false Failure.
57 * \retval true Success.
58 * Destroys token during parse.
59 */
8a648e8d 60bool GetHostWithPort(char *token, Ip::Address *ipa);
82b7abe3 61
c8f4eac4 62#endif /* SQUID_PARSING_H */
f53969cc 63