#ifndef __ASL_COMMON_H__
#define __ASL_COMMON_H__
#include <stdio.h>
#include <xpc/xpc.h>
#include <asl_msg.h>
#define ASL_MODULE_NAME "com.apple.asl"
#define _PATH_CRASHREPORTER "/Library/Logs/CrashReporter"
#define _PATH_CRASHREPORTER_MOBILE_1 "/var/mobile/Library/Logs/CrashReporter"
#define _PATH_CRASHREPORTER_MOBILE_2 "/private/var/mobile/Library/Logs/CrashReporter"
#define ASL_INTERNAL_LOGS_DIR "Logs"
#define ASL_SERVICE_NAME "com.apple.system.logger"
#define CRASH_MOVER_WILL_START_NOTIFICATION "CrashMoverWillStart"
#define SECONDS_PER_DAY 86400
#define DEFAULT_TTL (7 * SECONDS_PER_DAY)
#define ACTION_NONE 0
#define ACTION_SET_PARAM 1
#define ACTION_OUT_DEST 2
#define ACTION_IGNORE 3
#define ACTION_SKIP 4
#define ACTION_CLAIM 5
#define ACTION_NOTIFY 6
#define ACTION_BROADCAST 7
#define ACTION_ACCESS 8
#define ACTION_SET_KEY 9
#define ACTION_UNSET_KEY 10
#define ACTION_ASL_STORE 11
#define ACTION_ASL_FILE 12
#define ACTION_ASL_DIR 13
#define ACTION_FILE 14
#define ACTION_FORWARD 15
#define ACTION_CONTROL 16
#define ACTION_SET_FILE 17
#define ACTION_SET_PLIST 18
#define ACTION_SET_PROF 19
#define STYLE_SEC_PREFIX_CHAR 'T'
#define MODULE_FLAG_HAS_LOGGED 0x80000000
#define MODULE_FLAG_CLEAR_LOGGED 0x7fffffff
#define MODULE_FLAG_ENABLED 0x00000001
#define MODULE_FLAG_LOCAL 0x00000002
#define MODULE_FLAG_ROTATE 0x00000004
#define MODULE_FLAG_COALESCE 0x00000008
#define MODULE_FLAG_COMPRESS 0x00000010
#define MODULE_FLAG_NONSTD_DIR 0x00000020
#define MODULE_FLAG_EXTERNAL 0x00000040
#define MODULE_FLAG_TRUNCATE 0x00000080
#define MODULE_FLAG_BASESTAMP 0x00000100
#define MODULE_FLAG_SYMLINK 0x00000200
#define MODULE_FLAG_CRASHLOG 0x00000400
#define MODULE_FLAG_SOFT_WRITE 0x00000800
#define MODULE_FLAG_TYPE_ASL 0x00001000
#define MODULE_FLAG_TYPE_ASL_DIR 0x00002000
#define MODULE_FLAG_STD_BSD_MSG 0x00004000
#define MODULE_FLAG_SIZE_ONLY 0x00008000
#define MODULE_NAME_STYLE_FORMAT_MASK 0xf0000000
#define MODULE_NAME_STYLE_FORMAT_BS 0x10000000
#define MODULE_NAME_STYLE_FORMAT_BES 0x20000000
#define MODULE_NAME_STYLE_FORMAT_BSE 0x40000000
#define MODULE_NAME_STYLE_STAMP_MASK 0x000000ff
#define MODULE_NAME_STYLE_STAMP_SEC 0x00000001
#define MODULE_NAME_STYLE_STAMP_SEQ 0x00000002
#define MODULE_NAME_STYLE_STAMP_UTC 0x00000004
#define MODULE_NAME_STYLE_STAMP_UTC_B 0x00000008
#define MODULE_NAME_STYLE_STAMP_LCL 0x00000010
#define MODULE_NAME_STYLE_STAMP_LCL_B 0x00000020
#define STAMP_STYLE_INVALID -1
#define STAMP_STYLE_NULL 0
#define STAMP_STYLE_SEC 1
#define STAMP_STYLE_SEQ 2
#define STAMP_STYLE_ISO8601 3
#define CHECKPOINT_TEST 0x00000000
#define CHECKPOINT_FORCE 0x00000001
#define LEVEL_ALL 8
typedef struct
{
char *dir;
char *path;
char *current_name;
char *fmt;
char *rotate_dir;
char *base;
char *ext;
const char *tfmt;
uint32_t style_flags;
uint32_t pvt_flags;
uint32_t flags;
uint32_t fails;
uint32_t ttl[9];
mode_t mode;
#if !TARGET_OS_SIMULATOR
uid_t *uid;
uint32_t nuid;
gid_t *gid;
uint32_t ngid;
#endif
size_t file_max;
size_t all_max;
uint32_t refcount;
time_t timestamp;
size_t size;
void *private;
} asl_out_dst_data_t;
typedef struct asl_out_rule_s
{
asl_msg_t *query;
uint32_t action;
char *options;
asl_out_dst_data_t *dst;
void *private;
struct asl_out_rule_s *next;
} asl_out_rule_t;
typedef struct asl_out_module_s
{
char *name;
uint32_t flags;
asl_out_rule_t *ruleset;
struct asl_out_module_s *next;
} asl_out_module_t;
typedef struct asl_out_file_list_s
{
char *name;
uint32_t stamp;
time_t ftime;
uint32_t seq;
size_t size;
struct asl_out_file_list_s *next;
struct asl_out_file_list_s *prev;
} asl_out_file_list_t;
char **explode(const char *s, const char *delim);
void free_string_list(char **l);
char *get_line_from_file(FILE *f);
char *next_word_from_string(char **s);
size_t asl_str_to_size(char *s);
asl_msg_t *xpc_object_to_asl_msg(xpc_object_t xobj);
int asl_check_option(asl_msg_t *msg, const char *opt);
asl_out_module_t *asl_out_module_new(const char *name);
void asl_out_module_free(asl_out_module_t *m);
asl_out_module_t *asl_out_module_init(void);
asl_out_module_t *asl_out_module_init_from_file(const char *name, FILE *f);
asl_out_rule_t *asl_out_module_parse_line(asl_out_module_t *m, char *s);
void asl_out_module_print(FILE *f, asl_out_module_t *m);
char *asl_out_module_rule_to_string(asl_out_rule_t *r);
int asl_out_mkpath(asl_out_module_t *mlist, asl_out_rule_t *r);
int asl_make_database_dir(const char *dir, char **out);
int asl_out_dst_checkpoint(asl_out_dst_data_t *dst, uint32_t force);
int asl_out_dst_file_create_open(asl_out_dst_data_t *dst, char **pathp);
int asl_out_dst_set_access(int fd, asl_out_dst_data_t *dst);
void asl_make_timestamp(time_t stamp, uint32_t flags, char *buf, size_t len);
void asl_dst_make_current_name(asl_out_dst_data_t *dst, uint32_t xflags, char *buf, size_t len);
asl_out_dst_data_t *asl_out_dst_data_retain(asl_out_dst_data_t *dst);
void asl_out_dst_data_release(asl_out_dst_data_t *dst);
asl_out_file_list_t *asl_list_log_files(const char *dir, const char *base, const char *ext, uint32_t flags, bool src);
asl_out_file_list_t * asl_list_src_files(asl_out_dst_data_t *dst);
asl_out_file_list_t * asl_list_dst_files(asl_out_dst_data_t *dst);
void asl_out_file_list_free(asl_out_file_list_t *l);
asl_out_dst_data_t *asl_out_dest_for_path(asl_out_module_t *m, const char *path);
asl_msg_t *configuration_profile_to_asl_msg(const char *ident);
int asl_secure_chown_chmod_dir(const char *path, uid_t uid, gid_t gid, mode_t mode);
#endif