libsmb: Implement smbc_notify
[Samba.git] / examples / libsmbclient / testnotify.c
blob68513af05023d957a08663949a786267f434a7ca
1 #include <sys/types.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <time.h>
6 #include <errno.h>
7 #include <libsmbclient.h>
8 #include <inttypes.h>
9 #include "get_auth_data_fn.h"
11 static int notify_cb(const struct smbc_notify_callback_action *actions,
12 size_t num_actions, void *private_data)
14 int *count = private_data;
15 size_t i;
17 printf("%zu\n", num_actions);
19 for (i=0; i<num_actions; i++) {
20 const struct smbc_notify_callback_action *a = &actions[i];
21 printf("%s: %"PRIu32"\n", a->filename, a->action);
24 *count -= 1;
25 if (*count < 0) {
26 return 1;
29 return 0;
32 int main(int argc, char * argv[])
34 int fd;
35 int ret;
36 int debug = 0;
37 int saved_errno;
38 char path[2048];
39 char * p;
40 int count = 1000;
42 smbc_init(get_auth_data_fn, debug);
44 fprintf(stdout, "Path: ");
45 *path = '\0';
46 fgets(path, sizeof(path) - 1, stdin);
47 if (strlen(path) == 0) {
48 return 0;
51 p = path + strlen(path) - 1;
52 if (*p == '\n') {
53 *p = '\0';
56 fd = smbc_opendir(path);
57 if (fd < 0) {
58 perror("smbc_open");
59 return 1;
62 ret = smbc_notify(fd, 1,
63 SMBC_NOTIFY_CHANGE_SECURITY|
64 SMBC_NOTIFY_CHANGE_FILE_NAME,
65 1000, notify_cb, &count);
66 if (ret < 0) {
67 saved_errno = errno;
70 smbc_close(fd);
72 if (ret < 0) {
73 errno = saved_errno;
74 perror("notify");
77 return 0;