netatalk: fce_api.c File Reference

netatalk 4.5.1
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
fce_api.c File Reference

File change event API for netatalk. More...

`#include <arpa/inet.h>`
`#include <errno.h>`
`#include <netdb.h>`
`#include <netinet/in.h>`
`#include <stdbool.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <sys/param.h>`
`#include <sys/socket.h>`
`#include <time.h>`
`#include <unistd.h>`
`#include <atalk/adouble.h>`
`#include <atalk/afp.h>`
`#include <atalk/cnid.h>`
`#include <atalk/fce_api.h>`
`#include <atalk/globals.h>`
`#include <atalk/logger.h>`
`#include <atalk/unix.h>`
`#include <atalk/util.h>`
`#include <atalk/vfs.h>`
`#include "desktop.h"`
`#include "directory.h"`
`#include "file.h"`
`#include "fork.h"`
`#include "volume.h"`
`#include "fce_api_internal.h"`

## Macros
#define | MAXIOBUF 4096

## Functions
int | afprun_bg (char *cmd)
| Run a command in the background without waiting.
void | fce_init_udp (void)
| Initialize network structs for any listeners.
void | fce_cleanup (void)
static ssize_t | build_fce_packet (const AFPObj *obj, unsigned char *iobuf, fce_ev_t event, const char *path, const char *oldpath, pid_t pid, const char *user, uint32_t event_id)
static void | send_fce_event (const AFPObj *obj, int event, const char *path, const char *oldpath)
| Send the fce information to all (connected) listeners.
static int | add_udp_socket (const char *target_ip, const char *target_port)
static void | save_close_event (const AFPObj *obj, const char *path)
static void | fce_init_ign_paths (const char *ignores, const char ***dest_array, bool is_directory)
int | fce_register (const AFPObj *obj, fce_ev_t event, const char *path, const char *oldpath)
static void | check_saved_close_events (const AFPObj *obj)
void | fce_pending_events (const AFPObj *obj)
int | fce_add_udp_socket (const char *target)
| Extern connect to afpd parameter.
int | fce_set_events (const char *events)

## Variables
static struct udp_entry | udp_socket_list [FCE_MAX_UDP_SOCKS]
static int | udp_sockets = 0
static bool | udp_initialized = false
static unsigned long | fce_ev_enabled
static uint8_t | fce_ev_info
static unsigned char | iobuf [MAXIOBUF]
static const char ** | skip_files
static const char ** | skip_directories
static struct fce_close_event | last_close_event
static char * | fce_event_names []

## Detailed Description

File change event API for netatalk.

for every detected filesystem change a UDP packet is sent to an arbitrary list of listeners. Each packet contains unix path of modified filesystem element, event reason, and a consecutive event id (32 bit). Technically we are UDP client and are sending out packets synchronuosly as they are created by the afp functions. This should not affect performance measurably. The only delaying calls occur during initialization, if we have to resolve non-IP hostnames to IP. All numeric data inside the packet is network byte order, so use ntohs / ntohl to resolve length and event id. Ideally a listener receives every packet with no gaps in event ids, starting with event id 1 and mode FCE_CONN_START followed by data events from id 2 up to 0xFFFFFFFF, followed by 0 to 0xFFFFFFFF and so on.

A gap or not starting with 1 mode FCE_CONN_START or receiving mode FCE_CONN_BROKEN means that the listener has lost at least one filesystem event

## Macro Definition Documentation

## ◆ MAXIOBUF

#define MAXIOBUF 4096

## Function Documentation

## ◆ add_udp_socket()

int add_udp_socket | ( | const char * | target_ip,
|  | const char * | target_port )
| static

## ◆ afprun_bg()

int afprun_bg | ( | char * | cmd | ) |
| extern

Run a command in the background without waiting.

Note
  being careful about uid/gid handling

## ◆ build_fce_packet()

ssize_t build_fce_packet | ( | const AFPObj * | obj,
|  | unsigned char * | iobuf,
|  | fce_ev_t | event,
|  | const char * | path,
|  | const char * | oldpath,
|  | pid_t | pid,
|  | const char * | user,
|  | uint32_t | event_id )
| static

Construct a UDP packet for our listeners and return packet size

## ◆ check_saved_close_events()

void check_saved_close_events | ( | const AFPObj * | obj | ) |
| static

## ◆ fce_add_udp_socket()

int fce_add_udp_socket | ( | const char * | target | ) |

Extern connect to afpd parameter.

Note
  can be called multiple times for multiple listeners (up to MAX_UDP_SOCKS times)

## ◆ fce_cleanup()

void fce_cleanup | ( | void |  | ) |

## ◆ fce_init_ign_paths()

void fce_init_ign_paths | ( | const char * | ignores,
|  | const char *** | dest_array,
|  | bool | is_directory )
| static

## ◆ fce_init_udp()

void fce_init_udp | ( | void |  | ) |

Initialize network structs for any listeners.

Note
  We don't give return code because all errors are handled internally (I hope..)

## ◆ fce_pending_events()

void fce_pending_events | ( | const AFPObj * | obj | ) |

API-Calls for file change api, called from outside (file.c directory.c ofork.c filedir.c)

## ◆ fce_register()

int fce_register | ( | const AFPObj * | obj,
|  | fce_ev_t | event,
|  | const char * | path,
|  | const char * | oldpath )

Dispatcher for all incoming file change events

## ◆ fce_set_events()

int fce_set_events | ( | const char * | events | ) |

## ◆ save_close_event()

void save_close_event | ( | const AFPObj * | obj,
|  | const char * | path )
| static

## ◆ send_fce_event()

void send_fce_event | ( | const AFPObj * | obj,
|  | int | event,
|  | const char * | path,
|  | const char * | oldpath )
| static

Send the fce information to all (connected) listeners.

Note
  We don't give return code because all errors are handled internally (I hope..)

## Variable Documentation

## ◆ fce_ev_enabled

unsigned long fce_ev_enabled
| static

Initial value:
=
(1 << FCE_FILE_MODIFY) |
(1 << FCE_FILE_DELETE) |
(1 << FCE_DIR_DELETE) |
(1 << FCE_FILE_CREATE) |
(1 << FCE_DIR_CREATE) |
(1 << FCE_FILE_MOVE) |
(1 << FCE_DIR_MOVE) |
(1 << FCE_LOGIN) |
(1 << FCE_LOGOUT)

## ◆ fce_ev_info

uint8_t fce_ev_info
| static

## ◆ fce_event_names

char* fce_event_names[]
| static

Initial value:
= {
[FCE_FILE_MODIFY] = "FCE_FILE_MODIFY",
[FCE_FILE_DELETE] = "FCE_FILE_DELETE",
[FCE_DIR_DELETE] = "FCE_DIR_DELETE",
[FCE_FILE_CREATE] = "FCE_FILE_CREATE",
[FCE_DIR_CREATE] = "FCE_DIR_CREATE",
[FCE_FILE_MOVE] = "FCE_FILE_MOVE",
[FCE_DIR_MOVE] = "FCE_DIR_MOVE",
[FCE_LOGIN] = "FCE_LOGIN",
[FCE_LOGOUT] = "FCE_LOGOUT",
[FCE_CONN_START] = "FCE_CONN_START",
[FCE_CONN_BROKEN] = "FCE_CONN_BROKEN"
}

## ◆ iobuf

unsigned char iobuf[MAXIOBUF]
| static

## ◆ last_close_event

struct fce_close_event last_close_event
| static

## ◆ skip_directories

const char** skip_directories
| static

## ◆ skip_files

const char** skip_files
| static

## ◆ udp_initialized

bool udp_initialized = false
| static

## ◆ udp_socket_list

struct udp_entry udp_socket_list[FCE_MAX_UDP_SOCKS]
| static

## ◆ udp_sockets

int udp_sockets = 0
| static