ctdb-server: Remove duplicate logic
[samba4-gss.git] / source3 / smbd / notifyd / notifyd_entry.c
blobf3b0e908136b0dd044c803868bf90b89e5c02846
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 3 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #include "replace.h"
17 #include "lib/util/debug.h"
18 #include "notifyd_private.h"
21 * Parse an entry in the notifyd_context->entries database
24 /**
25 * @brief Parse a notifyd database entry.
27 * The memory we pass down needs to be aligned. If it isn't aligned we can run
28 * into obscure errors as we just point into the data buffer.
30 * @param data The data to parse
31 * @param data_len The length of the data to parse
32 * @param watcher A pointer to store the watcher data or NULL.
33 * @param instances A pointer to store the array of notify instances or NULL.
34 * @param pnum_instances The number of elements in the array. If you just want
35 * the number of elements pass NULL for the watcher and instances pointers.
37 * @return true on success, false if an error occurred.
39 bool notifyd_parse_entry(uint8_t *data,
40 size_t data_len,
41 struct notifyd_watcher *watcher,
42 struct notifyd_instance **instances,
43 size_t *pnum_instances)
45 size_t ilen;
47 if (data_len < sizeof(struct notifyd_watcher)) {
48 return false;
51 if (watcher != NULL) {
52 *watcher = *((struct notifyd_watcher *)(uintptr_t)data);
55 ilen = data_len - sizeof(struct notifyd_watcher);
56 if ((ilen % sizeof(struct notifyd_instance)) != 0) {
57 return false;
60 if (pnum_instances != NULL) {
61 *pnum_instances = ilen / sizeof(struct notifyd_instance);
63 if (instances != NULL) {
64 /* The (uintptr_t) cast removes a warning from -Wcast-align. */
65 *instances =
66 (struct notifyd_instance *)(uintptr_t)
67 (data + sizeof(struct notifyd_watcher));
70 return true;