packet-ldap: fix regression for SASL handling
[wireshark-sm.git] / epan / range.h
blobed14bb23e58b82202179c8e3483e6b7e8bf0eecb
1 /* range.h
2 * Range routines
4 * Dick Gooris <gooris@lucent.com>
5 * Ulf Lamping <ulf.lamping@web.de>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
14 #ifndef __RANGE_H__
15 #define __RANGE_H__
17 #include <glib.h>
18 #include "ws_symbol_export.h"
19 #include <epan/wmem/wmem.h>
21 #ifdef __cplusplus
22 extern "C" {
23 #endif /* __cplusplus */
25 /** @file
26 * Range strings a variant of value_strings
29 /**@todo where's the best place for these? */
30 #define MAX_SCTP_PORT 65535
31 #define MAX_TCP_PORT 65535
32 #define MAX_UDP_PORT 65535
33 #define MAX_DCCP_PORT 65535
35 typedef struct range_admin_tag {
36 guint32 low;
37 guint32 high;
38 } range_admin_t;
39 #define RANGE_ADMIN_T_INITIALIZER { 0, 0 }
41 /** user specified range(s) */
42 typedef struct epan_range {
43 guint nranges; /**< number of entries in ranges */
44 range_admin_t ranges[1]; /**< variable-length array */
45 } range_t;
47 /**
48 * Return value from range_convert_str().
50 typedef enum {
51 CVT_NO_ERROR,
52 CVT_SYNTAX_ERROR,
53 CVT_NUMBER_TOO_BIG
54 } convert_ret_t;
56 WS_DLL_PUBLIC range_t *range_empty(wmem_allocator_t *scope);
59 /*** Converts a range string to a fast comparable array of ranges.
60 * This function allocates a range_t large enough to hold the number
61 * of ranges specified, and fills the array range->ranges containing
62 * low and high values with the number of ranges being range->nranges.
63 * After having called this function, the function value_is_in_range()
64 * determines whether a given number is within the range or not.<BR>
65 * In case of a single number, we make a range where low is equal to high.
66 * We take care on wrongly entered ranges; opposite order will be taken
67 * care of.
69 * The following syntax is accepted :
71 * 1-20,30-40 Range from 1 to 20, and packets 30 to 40
72 * -20,30 Range from 1 to 20, and packet 30
73 * 20,30,40- 20, 30, and the range from 40 to the end
74 * 20-10,30-25 Range from 10 to 20, and from 25 to 30
75 * - All values
76 * @param scope memory scope for the range
77 * @param range the range
78 * @param es points to the string to be converted.
79 * @param max_value specifies the maximum value in a range.
80 * @return convert_ret_t
82 WS_DLL_PUBLIC convert_ret_t range_convert_str(wmem_allocator_t *scope, range_t **range, const gchar *es,
83 guint32 max_value);
85 WS_DLL_PUBLIC convert_ret_t range_convert_str_work(wmem_allocator_t *scope, range_t **range, const gchar *es,
86 guint32 max_value, gboolean err_on_max);
88 /** This function returns TRUE if a given value is within one of the ranges
89 * stored in the ranges array.
90 * @param range the range
91 * @param val the value to check
92 * @return TRUE if the value is in range
94 WS_DLL_PUBLIC gboolean value_is_in_range(range_t *range, guint32 val);
96 /** This function returns TRUE if val has successfully been added to
97 * a range. This may extend an existing range or create a new one
98 * @param scope memory scope of range (in case of reallocation)
99 * @param range to add value
100 * @param val value to add to range
101 * @return TRUE if the value is successsfully added to range
103 WS_DLL_PUBLIC gboolean range_add_value(wmem_allocator_t *scope, range_t **range, guint32 val);
105 /** This function returns TRUE if val has successfully been removed from
106 * a range. This may remove an existing range.
107 * @param scope memory scope of range (in case of reallocation)
108 * @param range to remove value
109 * @param val value to remove within range
110 * @return TRUE if the value is successsfully removed to range
112 WS_DLL_PUBLIC gboolean range_remove_value(wmem_allocator_t *scope, range_t **range, guint32 val);
114 /** This function returns TRUE if the two given range_t's are equal.
115 * @param a first range
116 * @param b second range
117 * @return TRUE if the value is in range
119 WS_DLL_PUBLIC gboolean ranges_are_equal(range_t *a, range_t *b);
121 /** This function calls the provided callback function for each value in
122 * in the range. Takes a pointer argument, which is passed to the
123 * callback, along with the value in the range.
124 * @param range the range
125 * @param callback the callback function
126 * @param ptr pointer passed to the callback
128 WS_DLL_PUBLIC void range_foreach(range_t *range, void (*callback)(guint32 val, gpointer ptr), gpointer ptr);
131 * This function converts a range_t to a (wmem_alloc()-allocated) string.
133 WS_DLL_PUBLIC char *range_convert_range(wmem_allocator_t *scope, const range_t *range);
136 * Create a (wmem-alloc()ed) copy of a range
137 * @param scope memory scope for the copied range
138 * @param src the range to copy
139 * @return ep allocated copy of the range
141 WS_DLL_PUBLIC range_t *range_copy(wmem_allocator_t *scope, range_t *src);
143 #ifdef __cplusplus
145 #endif /* __cplusplus */
147 #endif /* __RANGE_H__ */