#include <sys/socket.h>
#include <unistd.h>
#include <poll.h>
+#include <sys/stat.h>
+#include <stdbool.h>
#include <atalk/unicode.h>
#include <atalk/bstrlib.h>
+#include <atalk/cnid.h>
/* exit error codes */
#define EXITERR_CLNT 1 /* client related error */
#define EXITERR_CONF 2 /* error in config files/cmd line parameters */
#define EXITERR_SYS 3 /* local system error */
+#define EXITERR_CLOSED 4 /* connection was immediately closed after TCP handshake */
/* Print a SBT and exit */
#define AFP_PANIC(why) \
#define MIN(a,b) ((a) < (b) ? a : b)
#endif
-#if BYTE_ORDER == BIG_ENDIAN
+#ifdef WORDS_BIGENDIAN
#define hton64(x) (x)
#define ntoh64(x) (x)
-#else /* BYTE_ORDER == BIG_ENDIAN */
+#else
#define hton64(x) ((uint64_t) (htonl(((x) >> 32) & 0xffffffffLL)) | \
(uint64_t) ((htonl(x) & 0xffffffffLL) << 32))
#define ntoh64(x) (hton64(x))
-#endif /* BYTE_ORDER == BIG_ENDIAN */
+#endif
+
+#ifndef SAFE_FREE
+#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
+#endif
#ifdef WITH_SENDFILE
extern ssize_t sys_sendfile (int __out_fd, int __in_fd, off_t *__offset,size_t __count);
#define mod_close(a) dlclose(a)
#endif /* ! HAVE_DLFCN_H */
+#ifndef strequal
+#define strequal(a,b) (strcmp((a),(b)) == 0)
+#endif
+
/******************************************************************
* locking.c
******************************************************************/
extern unsigned int getip_port(const struct sockaddr *sa);
extern void apply_ip_mask(struct sockaddr *ai, int maskbits);
extern int compare_ip(const struct sockaddr *sa1, const struct sockaddr *sa2);
+extern int tokenize_ip_port(const char *ipurl, char **address, char **port);
/* Structures and functions dealing with dynamic pollfd arrays */
-enum fdtype {IPC_FD, LISTEN_FD, DISASOCIATED_IPC_FD};
-struct polldata {
- enum fdtype fdtype; /* IPC fd or listening socket fd */
- void *data; /* pointer to AFPconfig for listening socket and *
- * pointer to afp_child_t for IPC fd */
+
+enum asev_fdtype {IPC_FD, LISTEN_FD};
+
+/**
+ * atalk socket event data
+ **/
+struct asev_data {
+ enum asev_fdtype fdtype; /* IPC fd or listening socket fd */
+ void *private; /* pointer to AFPconfig for listening socket and *
+ * pointer to afp_child_t for IPC fd */
};
-extern void fdset_add_fd(int maxconns,
- struct pollfd **fdsetp,
- struct polldata **polldatap,
- int *fdset_usedp,
- int *fdset_sizep,
- int fd,
- enum fdtype fdtype,
- void *data);
-extern void fdset_del_fd(struct pollfd **fdsetp,
- struct polldata **polldatap,
- int *fdset_usedp,
- int *fdset_sizep,
- int fd);
+/**
+ * atalk socket event
+ **/
+struct asev {
+ struct pollfd *fdset; /* struct pollfd array for poll() */
+ struct asev_data *data; /* associated array of data */
+ int max;
+ int used;
+};
+
+extern struct asev *asev_init(int max);
+extern bool asev_add_fd(struct asev *sev, int fd, enum asev_fdtype fdtype, void *private);
+extern bool asev_del_fd(struct asev *sev, int fd);
+
extern int send_fd(int socket, int fd);
extern int recv_fd(int fd, int nonblocking);
extern const char *getcwdpath(void);
extern const char *fullpathname(const char *);
extern char *stripped_slashes_basename(char *p);
-extern int lchdir(const char *dir);
extern void randombytes(void *buf, int n);
extern int daemonize(int nochdir, int noclose);
+extern int run_cmd(const char *cmd, char **cmd_argv);
+extern char *realpath_safe(const char *path);
+extern const char *basename_safe(const char *path);
+extern char *strtok_quote (char *s, const char *delim);
+
+extern int ochdir(const char *dir, int options);
+extern int ostat(const char *path, struct stat *buf, int options);
+extern int ostatat(int dirfd, const char *path, struct stat *st, int options);
+extern int ochown(const char *path, uid_t owner, gid_t group, int options);
+extern int ochmod(char *path, mode_t mode, const struct stat *st, int options);
/******************************************************************
* cnid.c
*****************************************************************/
extern bstring rel_path_in_vol(const char *path, const char *volpath);
+extern cnid_t cnid_for_path(struct _cnid_db *cdb, const char *volpath, const char *path, cnid_t *did);
+
+/******************************************************************
+ * cnid.c
+ *****************************************************************/
+
+extern void initline (int, char *);
+extern int parseline (int, char *);
#endif /* _ATALK_UTIL_H */