| 1 | /*
|
|---|
| 2 | Netdrive Samba client plugin
|
|---|
| 3 | logging functions
|
|---|
| 4 | Copyright (C) netlabs.org 2003-2008
|
|---|
| 5 |
|
|---|
| 6 | This program is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 9 | (at your option) any later version.
|
|---|
| 10 |
|
|---|
| 11 | This program is distributed in the hope that it will be useful,
|
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | GNU General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with this program; if not, write to the Free Software
|
|---|
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | #define INCL_DOSERRORS
|
|---|
| 22 | #define INCL_DOS
|
|---|
| 23 | #include <os2emx.h>
|
|---|
| 24 | #include <stdio.h>
|
|---|
| 25 | #include <stdlib.h>
|
|---|
| 26 | #include <stdarg.h>
|
|---|
| 27 | #include <string.h>
|
|---|
| 28 | #include <sys/types.h>
|
|---|
| 29 | #include <process.h>
|
|---|
| 30 | #include <sys/time.h>
|
|---|
| 31 |
|
|---|
| 32 | #include "smbwrp.h"
|
|---|
| 33 | //#include "smbcd.h"
|
|---|
| 34 | //#include "config.h"
|
|---|
| 35 |
|
|---|
| 36 | #define SMBCD_MAX_THREADS 250
|
|---|
| 37 |
|
|---|
| 38 | int debuglevel = 0;
|
|---|
| 39 | HMTX logmutex = 0;
|
|---|
| 40 | char *logfile = NULL;
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 | #if 0
|
|---|
| 44 | int debug_parse_levels(const char *params_str)
|
|---|
| 45 | {
|
|---|
| 46 | return 1;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | void dbgflush( void )
|
|---|
| 50 | {
|
|---|
| 51 | // if (!logfile) fflush(stdout);
|
|---|
| 52 | }
|
|---|
| 53 | #endif
|
|---|
| 54 |
|
|---|
| 55 | int debuglvl(int level)
|
|---|
| 56 | {
|
|---|
| 57 | return (level <= debuglevel) ? 1 : 0;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | int debugheader(int level, char * file, char * func, int line)
|
|---|
| 61 | {
|
|---|
| 62 | int rc;
|
|---|
| 63 | if (level > debuglevel)
|
|---|
| 64 | {
|
|---|
| 65 | return 0;
|
|---|
| 66 | }
|
|---|
| 67 | rc = DosRequestMutexSem(logmutex, -1L);
|
|---|
| 68 | if (rc)
|
|---|
| 69 | {
|
|---|
| 70 | return 0;
|
|---|
| 71 | }
|
|---|
| 72 | rc = 1;
|
|---|
| 73 | do
|
|---|
| 74 | {
|
|---|
| 75 | FILE * f;
|
|---|
| 76 | struct timeval tv;
|
|---|
| 77 | time_t t;
|
|---|
| 78 | char buf[80] = {0};
|
|---|
| 79 | if (logfile)
|
|---|
| 80 | {
|
|---|
| 81 | f = fopen(logfile, "a");
|
|---|
| 82 | if (!f)
|
|---|
| 83 | {
|
|---|
| 84 | rc = 0;
|
|---|
| 85 | break;
|
|---|
| 86 | }
|
|---|
| 87 | }
|
|---|
| 88 | else
|
|---|
| 89 | {
|
|---|
| 90 | f = stdout;
|
|---|
| 91 | }
|
|---|
| 92 | gettimeofday(&tv, NULL);
|
|---|
| 93 | t = time(NULL);
|
|---|
| 94 | // strftime(buf,sizeof(buf)-1,"%Y/%m/%d %H:%M:%S", localtime((time_t *)&tv.tv_sec));
|
|---|
| 95 | strftime(buf,sizeof(buf)-1,"%Y/%m/%d %H:%M:%S", localtime(&t));
|
|---|
| 96 | fprintf(f, "%s.%d: %d %d: %s:%s(%d) :", buf, tv.tv_usec / 10000, level, (long)_gettid(), file, func, line);
|
|---|
| 97 | if (logfile)
|
|---|
| 98 | {
|
|---|
| 99 | fclose(f);
|
|---|
| 100 | }
|
|---|
| 101 | }
|
|---|
| 102 | while (0);
|
|---|
| 103 | DosReleaseMutexSem(logmutex);
|
|---|
| 104 | return rc;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | int debugmessage(char * fmt, ...)
|
|---|
| 108 | {
|
|---|
| 109 | int rc;
|
|---|
| 110 | rc = DosRequestMutexSem(logmutex, -1L);
|
|---|
| 111 | if (rc)
|
|---|
| 112 | {
|
|---|
| 113 | return 0;
|
|---|
| 114 | }
|
|---|
| 115 | do
|
|---|
| 116 | {
|
|---|
| 117 | FILE * f;
|
|---|
| 118 | va_list args;
|
|---|
| 119 | if (logfile)
|
|---|
| 120 | {
|
|---|
| 121 | f = fopen(logfile, "a");
|
|---|
| 122 | if (!f)
|
|---|
| 123 | {
|
|---|
| 124 | break;
|
|---|
| 125 | }
|
|---|
| 126 | }
|
|---|
| 127 | else
|
|---|
| 128 | {
|
|---|
| 129 | f = stdout;
|
|---|
| 130 | }
|
|---|
| 131 | va_start(args, fmt);
|
|---|
| 132 | vfprintf(f, fmt, args);
|
|---|
| 133 | va_end(args);
|
|---|
| 134 | if (logfile)
|
|---|
| 135 | {
|
|---|
| 136 | fclose(f);
|
|---|
| 137 | }
|
|---|
| 138 | }
|
|---|
| 139 | while (0);
|
|---|
| 140 | DosReleaseMutexSem(logmutex);
|
|---|
| 141 | return 0;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | void debuglocal(int level, const char * fmt, ...)
|
|---|
| 145 | {
|
|---|
| 146 | int rc;
|
|---|
| 147 | if (level > debuglevel)
|
|---|
| 148 | {
|
|---|
| 149 | return;
|
|---|
| 150 | }
|
|---|
| 151 | rc = DosRequestMutexSem(logmutex, -1L);
|
|---|
| 152 | if (rc)
|
|---|
| 153 | {
|
|---|
| 154 | return;
|
|---|
| 155 | }
|
|---|
| 156 | do
|
|---|
| 157 | {
|
|---|
| 158 | FILE * f;
|
|---|
| 159 | struct timeval tv;
|
|---|
| 160 | char buf[80] = {0};
|
|---|
| 161 | va_list args;
|
|---|
| 162 | if (logfile)
|
|---|
| 163 | {
|
|---|
| 164 | f = fopen(logfile, "a");
|
|---|
| 165 | if (!f)
|
|---|
| 166 | {
|
|---|
| 167 | break;
|
|---|
| 168 | }
|
|---|
| 169 | }
|
|---|
| 170 | else
|
|---|
| 171 | {
|
|---|
| 172 | f = stdout;
|
|---|
| 173 | }
|
|---|
| 174 | gettimeofday(&tv, NULL);
|
|---|
| 175 | strftime(buf,sizeof(buf)-1,"%Y/%m/%d %H:%M:%S", localtime((time_t *)&tv.tv_sec));
|
|---|
| 176 | fprintf(f, "%s.%d: %d %d: ", buf, tv.tv_usec / 10000, level, (long)_gettid());
|
|---|
| 177 | va_start(args, fmt);
|
|---|
| 178 | vfprintf(f, fmt, args);
|
|---|
| 179 | va_end(args);
|
|---|
| 180 | if (logfile)
|
|---|
| 181 | {
|
|---|
| 182 | fclose(f);
|
|---|
| 183 | }
|
|---|
| 184 | }
|
|---|
| 185 | while (0);
|
|---|
| 186 | DosReleaseMutexSem(logmutex);
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|