ReactOS 0.4.15-dev-8207-gd73a838
trace.c File Reference
#include "syshdrs.h"
#include "trace.h"
#include "util.h"
Include dependency graph for trace.c:

Go to the source code of this file.

Functions

void Trace (const int level, const char *const fmt,...)
 
void ErrorHook (const FTPCIPtr UNUSED(cipUnused), char *msg)
 
void DebugHook (const FTPCIPtr UNUSED(cipUnused), char *msg)
 
void SetDebug (int i)
 
void UseTrace (void)
 
void OpenTrace (void)
 
void CloseTrace (void)
 

Variables

time_t gTraceTime
 
FILEgTraceFile = NULL
 
char gTraceLBuf [256]
 
int gDebug = 0
 
FTPLibraryInfo gLib
 
FTPConnectionInfo gConn
 
char gVersion []
 
char gOS []
 
char gOurDirectoryPath []
 

Function Documentation

◆ CloseTrace()

void CloseTrace ( void  )

Definition at line 159 of file trace.c.

160{
161 char pathName[256];
162 char pathName2[256];
163 char tName[32];
164
165 if ((gOurDirectoryPath[0] == '\0') || (gTraceFile == NULL))
166 return;
167
168 (void) sprintf(tName, "trace.%u", (unsigned int) getpid());
169 (void) OurDirectoryPath(pathName, sizeof(pathName), tName);
170 (void) OurDirectoryPath(pathName2, sizeof(pathName2), kTraceFileName);
171
172 (void) time(&gTraceTime);
173 (void) fprintf(gTraceFile, "SESSION ENDED at: %s", ctime(&gTraceTime));
175
176 (void) unlink(pathName2);
177 (void) rename(pathName, pathName2);
178} /* CloseTrace */
#define kTraceFileName
Definition: trace.h:11
#define NULL
Definition: types.h:112
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define unlink
Definition: syshdrs.h:54
__u16 ctime
Definition: mkdosfs.c:4
__u16 time
Definition: mkdosfs.c:8
FILE * gTraceFile
Definition: trace.c:17
time_t gTraceTime
Definition: trace.c:16
char gOurDirectoryPath[]
Definition: util.c:17
char * OurDirectoryPath(char *const dst, const size_t siz, const char *const fname)
Definition: util.c:486
#define sprintf(buf, format,...)
Definition: sprintf.c:55
_Check_return_ int __cdecl rename(_In_z_ const char *_OldFilename, _In_z_ const char *_NewFilename)
#define getpid
Definition: wintirpc.h:52

Referenced by PostShell().

◆ DebugHook()

void DebugHook ( const FTPCIPtr   UNUSEDcipUnused,
char msg 
)

Definition at line 78 of file trace.c.

79{
80 LIBNCFTP_USE_VAR(cipUnused); /* shut up gcc */
81 Trace(0, "%s", msg);
82} /* DebugHook */
#define msg(x)
Definition: auth_time.c:54
#define Trace(x)
Definition: inflate.c:42
#define LIBNCFTP_USE_VAR(a)
Definition: ncftp.h:521

Referenced by UseTrace().

◆ ErrorHook()

void ErrorHook ( const FTPCIPtr   UNUSEDcipUnused,
char msg 
)

Definition at line 66 of file trace.c.

67{
68 LIBNCFTP_USE_VAR(cipUnused); /* shut up gcc */
69
70 /* Will also get Trace'd. */
71 (void) fprintf(stdout, "%s", msg);
72} /* ErrorHook */
#define stdout
Definition: stdio.h:99

Referenced by UseTrace().

◆ OpenTrace()

void OpenTrace ( void  )

Definition at line 109 of file trace.c.

110{
111 FILE *fp;
112 char pathName[256];
113 char tName[32];
114 int pid;
115 const char *cp;
116#if defined(HAVE_SYS_UTSNAME_H) && defined(HAVE_UNAME)
117 struct utsname u;
118#endif
119
120 if (gOurDirectoryPath[0] == '\0')
121 return; /* Don't create in root directory. */
122
123 (void) sprintf(tName, "trace.%u", (unsigned int) (pid = getpid()));
124 (void) OurDirectoryPath(pathName, sizeof(pathName), tName);
125
126 fp = fopen(pathName, FOPEN_WRITE_TEXT);
127 if (fp != NULL) {
128 (void) _chmod(pathName, 00600);
129#ifdef HAVE_SETVBUF
130 (void) setvbuf(fp, gTraceLBuf, _IOLBF, sizeof(gTraceLBuf));
131#endif /* HAVE_SETVBUF */
132 /* Opened the trace file. */
133 (void) time(&gTraceTime);
134 (void) fprintf(fp, "SESSION STARTED at: %s", ctime(&gTraceTime));
135 (void) fprintf(fp, " Program Version: %s\n", gVersion + 5);
136 (void) fprintf(fp, " Library Version: %s\n", gLibNcFTPVersion + 5);
137 (void) fprintf(fp, " Process ID: %u\n", pid);
138 if (gOS[0] != '\0')
139 (void) fprintf(fp, " Platform: %s\n", gOS);
140#if defined(HAVE_SYS_UTSNAME_H) && defined(HAVE_UNAME)
141 if (uname(&u) == 0) {
142 (void) fprintf(fp, " Uname: %.63s|%.63s|%.63s|%.63s|%.63s\r\n", u.sysname, u.nodename, u.release, u.version, u.machine);
143 }
144#endif /* UNAME */
146 (void) fprintf(fp, " Hostname: %s (rc=%d)\n", gLib.ourHostName, gLib.hresult);
147 cp = (const char *) getenv("TERM");
148 if (cp == NULL)
149 cp = "unknown?";
150 (void) fprintf(fp, " Terminal: %s\n", cp);
151 gTraceFile = fp;
152 }
153} /* OpenTrace */
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
#define _IOLBF
Definition: stdio.h:128
_Check_return_opt_ _CRTIMP int __cdecl setvbuf(_Inout_ FILE *_File, _Inout_updates_opt_z_(_Size) char *_Buf, _In_ int _Mode, _In_ size_t _Size)
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
POINT cp
Definition: magnifier.c:59
char gLibNcFTPVersion[64]
Definition: ftp.c:11
char gOS[]
Definition: trace.c:23
FTPLibraryInfo gLib
Definition: main.c:36
char gVersion[]
Definition: init.c:22
char gTraceLBuf[256]
Definition: trace.c:18
#define FOPEN_WRITE_TEXT
Definition: syshdrs.h:83
void FTPInitializeOurHostName(const FTPLIPtr)
Definition: open.c:63
_Check_return_ _CRTIMP int __cdecl _chmod(_In_z_ const char *_Filename, _In_ int _Mode)
int hresult
Definition: ncftp.h:119
char ourHostName[64]
Definition: ncftp.h:118
_In_ ULONG_PTR _In_ ULONG _Out_ ULONG_PTR * pid
Definition: winddi.h:3837

◆ SetDebug()

void SetDebug ( int  i)

Definition at line 88 of file trace.c.

89{
90 gDebug = i;
91} /* SetDebug */
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
int gDebug
Definition: trace.c:19

Referenced by DebugCmd(), and InitConnectionInfo().

◆ Trace()

void Trace ( const int  level,
const char *const  fmt,
  ... 
)

Definition at line 30 of file trace.c.

31{
32 va_list ap;
33 char buf[512];
34 struct tm *ltp;
35
36 if ((gDebug >= level) || (level > 8)) {
37 va_start(ap, fmt);
38#ifdef HAVE_VSNPRINTF
39 (void) vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
40 buf[sizeof(buf) - 1] = '\0';
41#else
42 (void) vsprintf(buf, fmt, ap);
43#endif
44 va_end(ap);
45
47 ltp = localtime(&gTraceTime);
48 if ((gTraceFile != NULL) && (ltp != NULL)) {
49 (void) fprintf(gTraceFile , "%02d:%02d:%02d %s",
50 ltp->tm_hour,
51 ltp->tm_min,
52 ltp->tm_sec,
53 buf
54 );
55 }
56 if (gDebug > level) {
57 (void) fprintf(stdout, "%s", buf);
58 }
59 }
60} /* Trace */
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
GLint level
Definition: gl.h:1546
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
_CRTIMP struct tm *__cdecl localtime(const time_t *_Time)
Definition: time.h:416
Definition: dsound.c:943
Definition: time.h:68
int tm_hour
Definition: time.h:71
int tm_sec
Definition: time.h:69
int tm_min
Definition: time.h:70
#define vsnprintf
Definition: tif_win32.c:406
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36

◆ UseTrace()

void UseTrace ( void  )

Definition at line 97 of file trace.c.

98{
102 gConn.errLog = NULL;
103} /* UseTrace */
FTPConnectionInfo gConn
Definition: main.c:37
void ErrorHook(const FTPCIPtr UNUSED(cipUnused), char *msg)
Definition: trace.c:66
void DebugHook(const FTPCIPtr UNUSED(cipUnused), char *msg)
Definition: trace.c:78
FTPLogProc errLogProc
Definition: ncftp.h:148
FILE * debugLog
Definition: ncftp.h:145
FILE * errLog
Definition: ncftp.h:146
FTPLogProc debugLogProc
Definition: ncftp.h:147

Referenced by InitConnectionInfo().

Variable Documentation

◆ gConn

FTPConnectionInfo gConn
extern

Definition at line 37 of file main.c.

Referenced by CloseHost(), InitConnectionInfo(), main(), OpenURL(), PostInit(), SetStartupURL(), and UseTrace().

◆ gDebug

int gDebug = 0

Definition at line 19 of file trace.c.

Referenced by DebugCmd(), InitConnectionInfo(), SetDebug(), and Trace().

◆ gLib

FTPLibraryInfo gLib
extern

Definition at line 36 of file main.c.

Referenced by InitConnectionInfo(), OpenTrace(), PostInit(), and PreInit().

◆ gOS

char gOS[]

Definition at line 23 of file trace.c.

Referenced by OpenTrace().

◆ gOurDirectoryPath

char gOurDirectoryPath[]
extern

Definition at line 17 of file util.c.

Referenced by CloseTrace(), InitOurDirectory(), OpenTrace(), and OurDirectoryPath().

◆ gTraceFile

FILE* gTraceFile = NULL

Definition at line 17 of file trace.c.

Referenced by CloseTrace(), OpenTrace(), and Trace().

◆ gTraceLBuf

char gTraceLBuf[256]

Definition at line 18 of file trace.c.

Referenced by OpenTrace().

◆ gTraceTime

time_t gTraceTime

Definition at line 16 of file trace.c.

Referenced by CloseTrace(), OpenTrace(), and Trace().

◆ gVersion

char gVersion[]
extern

Definition at line 22 of file init.c.

Referenced by OpenTrace().