4256620b5c8c036d785dcac726c51444974c65a9
[openafs.git] / src / util / afsutil.h
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 #include <stdio.h>
26 #include <stdarg.h>
27 extern int LogLevel;
28 #ifndef AFS_NT40_ENV
29 extern int serverLogSyslog;
30 extern int serverLogSyslogFacility;
31 #endif
32 extern void FSLog(const char *format, ...);
33 #define ViceLog(level, str)  if ((level) <= LogLevel) (FSLog str)
34
35 extern int OpenLog(const char *filename);
36 extern int ReOpenLog(const char *fileName);
37 extern void SetupLogSignals(void);
38
39
40 /* special version of ctime that clobbers a *different static variable, so
41  * that ViceLog can call ctime and not cause buffer confusion.
42  */
43 extern char *vctime(const time_t *atime);
44
45 /* Need a thead safe ctime for pthread builds. Use std ctime for LWP */
46 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
47 #ifdef AFS_SUN5_ENV
48 #define afs_ctime(C, B, L) ctime_r(C, B, L)
49 #else
50 /* Cast is for platforms which do not prototype ctime_r */
51 #define afs_ctime(C, B, L) (char*)ctime_r(C, B)
52 #endif /* AFS_SUN5_ENV */
53 #else /* AFS_PTHREAD_ENV && !AFS_NT40_ENV */
54 #define afs_ctime(C, B, S) \
55         ((void)strncpy(B, ctime(C), (S-1)), (B)[S-1] = '\0', (B))
56 #endif  /* AFS_PTHREAD_ENV && !AFS_NT40_ENV */
57
58
59 /* Convert a 4 byte integer to a text string. */
60 extern char*    afs_inet_ntoa(afs_int32 addr);
61
62
63 /* copy strings, converting case along the way. */
64 extern char *lcstring(char *d, char *s, int n);
65 extern char *ucstring(char *d, char *s, int n);
66 extern char *strcompose(char *buf, size_t len, ...);
67
68 /* abort the current process. */
69 #ifdef AFS_NT40_ENV
70 #define afs_abort() afs_NTAbort()
71 #else
72 #define afs_abort() abort()
73 #endif
74
75
76 #ifdef AFS_NT40_ENV
77 #include <winsock2.h>
78
79 /* Initialize the windows sockets before calling networking routines. */
80 extern int afs_winsockInit(void);
81
82 struct timezone {
83     int  tz_minuteswest;     /* of Greenwich */
84     int  tz_dsttime;    /* type of dst correction to apply */
85 };
86 #define gettimeofday afs_gettimeofday
87 int afs_gettimeofday(struct timeval *tv, struct timezone *tz);
88
89 /* Unbuffer output when Un*x would do line buffering. */
90 #define setlinebuf(S) setvbuf(S, NULL, _IONBF, 0)
91
92 /* regular expression parser for NT */
93 extern char *re_comp(char *sp);
94 extern int rc_exec(char *p);
95
96 /* Abort on error, possibly trapping to debugger or dumping a trace. */
97 void afs_NTAbort(void);
98 #endif
99
100 /* get temp dir path */
101 char *gettmpdir(void);
102
103 /* Base 32 conversions used for NT since directory names are
104  * case-insensitive.
105  */
106 typedef char b32_string_t[8];
107 char *int_to_base32(b32_string_t s, int a);
108 int base32_to_int(char *s);
109
110 #if defined(AFS_NAMEI_ENV) && !defined(AFS_NT40_ENV)
111 /* base 64 converters for namei interface. Flip bits to differences are
112  * early in name.
113  */
114 typedef char lb64_string_t[12];
115 #ifdef AFS_64BIT_ENV
116 #define int32_to_flipbase64(S, A) int64_to_flipbase64(S, (afs_int64)(A))
117 char *int64_to_flipbase64(b64_string_t s, afs_int64 a);
118 afs_int64 flipbase64_to_int64(char *s);
119 #else
120 #define int32_to_flipbase64(S, A) int64_to_flipbase64(S, (u_int64_t)(A))
121 char *int64_to_flipbase64(b64_string_t s, u_int64_t a);
122 int64_t flipbase64_to_int64(char *s);
123 #endif
124 #endif
125
126 /* This message preserves our ability to license AFS to the U.S. Government
127  * more than once.
128  */
129
130 #define AFS_GOVERNMENT_MESSAGE \
131 "===================== U.S. Government Restricted Rights ======================\n\
132 If you are licensing the Software on behalf of the U.S. Government\n\
133 (\"Government\"), the following provisions apply to you.  If the Software is\n\
134 supplied to the Department of Defense (\"DoD\"), it is classified as \"Commercial\n\
135 Computer Software\" under paragraph 252.227-7014 of the DoD Supplement to the\n\
136 Federal Acquisition Regulations (\"DFARS\") (or any successor regulations)\n\
137 and the Government is acquiring only the license rights granted herein (the\n\
138 license rights customarily provided to non-Government users).  If the Software\n\
139 is supplied to any unit or agency of the Government other than DoD, it is\n\
140 classified as \"Restricted Computer Software\" and the Government's rights in\n\
141 the Software are defined in paragraph 52.227-19 of the Federal Acquisition\n\
142 Regulations (\"FAR\") (or any successor regulations) or, in the case of NASA,\n\
143 in paragraph 18.52.227-86 of the NASA Supplement in the FAR (or any successor\n\
144 regulations).\n"
145
146 #endif /* _AFSUTIL_H_ */