segfault/memleak on incorrect data fixed
[elliptics.git] / library / notify_common.c
blob5ee46047f2409df3387d810f6810013aec2d69ef
1 /*
2 * 2008+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
3 * All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <sys/socket.h>
19 #include <sys/mman.h>
20 #include <sys/wait.h>
22 #include <ctype.h>
23 #include <fcntl.h>
24 #include <limits.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
29 #include "elliptics.h"
31 #include "elliptics/packet.h"
32 #include "elliptics/interface.h"
34 static int dnet_request_notification_raw(struct dnet_session *s, struct dnet_id *id,
35 int (* complete)(struct dnet_net_state *state,
36 struct dnet_cmd *cmd,
37 void *priv),
38 void *priv, uint64_t cflags)
40 struct dnet_trans_control ctl;
42 memset(&ctl, 0, sizeof(struct dnet_trans_control));
44 memcpy(&ctl.id, id, sizeof(struct dnet_id));
45 ctl.cmd = DNET_CMD_NOTIFY;
46 ctl.complete = complete;
47 ctl.priv = priv;
48 ctl.cflags = DNET_FLAGS_NEED_ACK | cflags;
50 return dnet_trans_alloc_send(s, &ctl);
53 int dnet_request_notification(struct dnet_session *s, struct dnet_id *id,
54 int (* complete)(struct dnet_net_state *state,
55 struct dnet_cmd *cmd,
56 void *priv),
57 void *priv)
59 uint64_t cflags = 0;
61 if (!complete || !id)
62 return -EINVAL;
64 return dnet_request_notification_raw(s, id, complete, priv, cflags);
67 int dnet_drop_notification(struct dnet_session *s, struct dnet_id *id)
69 uint64_t cflags = DNET_ATTR_DROP_NOTIFICATION;
70 if (!id)
71 return -EINVAL;
73 return dnet_request_notification_raw(s, id, NULL, NULL, cflags);