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/>.
17 #include "lib/util/debug.h"
18 #include "notifyd_private.h"
21 * Parse an entry in the notifyd_context->entries database
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
,
41 struct notifyd_watcher
*watcher
,
42 struct notifyd_instance
**instances
,
43 size_t *pnum_instances
)
47 if (data_len
< sizeof(struct notifyd_watcher
)) {
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) {
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. */
66 (struct notifyd_instance
*)(uintptr_t)
67 (data
+ sizeof(struct notifyd_watcher
));