backport to buster
[hcoop/debian/openafs.git] / src / util / afsutil.h
CommitLineData
805e021f
CE
1/*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10#ifndef _AFSUTIL_H_
11#define _AFSUTIL_H_
12
13#include <time.h>
14/* Include afs installation dir retrieval routines */
15#include <afs/dirpath.h>
16
17/* These macros are return values from extractAddr. They do not represent
18 * any valid IP address and so can indicate a failure.
19 */
20#define AFS_IPINVALID 0xffffffff /* invalid IP address */
21#define AFS_IPINVALIDIGNORE 0xfffffffe /* no input given to extractAddr */
22
23/* logging defines
24 */
25#ifndef AFS_NT40_ENV
26#include <sys/types.h>
27#include <sys/socket.h>
28#include <netinet/in.h>
29#include <arpa/inet.h> /* for inet_ntoa() */
30#endif
31
32#include <stdio.h>
33#include <stdarg.h>
34#include <string.h>
35
36enum logDest {
37 logDest_file,
38#ifdef HAVE_SYSLOG
39 logDest_syslog,
40#endif
41};
42
43enum logRotateStyle {
44 logRotate_none = 0,
45 logRotate_old, /**< Rename log file by adding .old to the file name. */
46 logRotate_timestamp, /**< Rename log file to a timestamped file name. */
47};
48
49struct logOptions {
50 int logLevel; /**< The initial log level. */
51 enum logDest dest; /**< Log destination */
52 union {
53 struct fileOptions {
54 const char *filename; /**< Log filename (may be a named pipe). */
55 int rotateOnOpen; /**< Rotate the log file during OpenLog. */
56 int rotateOnReset; /**< Rotate the log file when the SIGHUP is caught. */
57 enum logRotateStyle rotateStyle; /**< Specifies how logs are renamed. */
58 } fileOpts;
59#ifdef HAVE_SYSLOG
60 struct syslogOptions {
61 int facility; /**< The syslog facility. */
62 char *tag; /**< The syslog identification. */
63 } syslogOpts;
64#endif
65 } opts;
66};
67#define lopt_logLevel logLevel
68#define lopt_dest dest
69#define lopt_filename opts.fileOpts.filename
70#define lopt_rotateOnOpen opts.fileOpts.rotateOnOpen
71#define lopt_rotateOnReset opts.fileOpts.rotateOnReset
72#define lopt_rotateStyle opts.fileOpts.rotateStyle
73#define lopt_facility opts.syslogOpts.facility
74#define lopt_tag opts.syslogOpts.tag
75
76extern void vFSLog(const char *format, va_list args)
77 AFS_ATTRIBUTE_FORMAT(__printf__, 1, 0);
78
79extern void SetLogThreadNumProgram(int (*func) (void) );
80
81extern void FSLog(const char *format, ...)
82 AFS_ATTRIBUTE_FORMAT(__printf__, 1, 2);
83
84
85extern int LogLevel; /* For logging macros only. */
86
87#define ViceLog(level, str) do { if ((level) <= LogLevel) (FSLog str); } while (0)
88#define vViceLog(level, str) do { if ((level) <= LogLevel) (vFSLog str); } while (0)
89#define ViceLogThenPanic(level, str) \
90 do { ViceLog(level, str); osi_Panic str; } while(0);
91
92extern int OpenLog(struct logOptions *opts);
93extern int ReOpenLog(void);
94extern void SetupLogSignals(void);
95extern void CloseLog(void);
96extern void SetupLogSoftSignals(void);
97extern int GetLogLevel(void);
98extern enum logDest GetLogDest(void);
99extern const char *GetLogFilename(void);
100
101#ifdef AFS_NT40_ENV
102#ifndef _MFC_VER
103#include <winsock2.h>
104#endif /* _MFC_VER */
105
106/* Initialize the windows sockets before calling networking routines. */
107 extern int afs_winsockInit(void);
108 extern void afs_winsockCleanup(void);
109
110/* Unbuffer output when Un*x would do line buffering. */
111#define setlinebuf(S) setvbuf(S, NULL, _IONBF, 0)
112
113#endif /* AFS_NT40_ENV */
114
115#ifndef HAVE_POSIX_REGEX
116extern char *re_comp(const char *sp);
117extern int re_exec(const char *p1);
118#endif
119
120 typedef char b32_string_t[8];
121/* b64_string_t is 8 bytes, in stds.h */
122 typedef char lb64_string_t[12];
123
124/* A simple macro to help show the value of #define'd constants. e.g. If 'FOO'
125 * is defined as 5, then AFS_STRINGIZE(FOO) expands to "5" */
126#define AFS_STRINGIZE_(s) #s
127#define AFS_STRINGIZE(s) AFS_STRINGIZE_(s)
128
129#include <afs/ktime.h>
130#include "afsutil_prototypes.h"
131
132#endif /* _AFSUTIL_H_ */