| 1 | /* | 
|---|
| 2 | Netdrive Samba client plugin | 
|---|
| 3 | logging functions | 
|---|
| 4 | Copyright (C) netlabs.org 2003-2012 | 
|---|
| 5 | Copyright (C) bww bitwise works GmbH 2012-2016 | 
|---|
| 6 |  | 
|---|
| 7 | This program is free software; you can redistribute it and/or modify | 
|---|
| 8 | it under the terms of the GNU General Public License as published by | 
|---|
| 9 | the Free Software Foundation; either version 2 of the License, or | 
|---|
| 10 | (at your option) any later version. | 
|---|
| 11 |  | 
|---|
| 12 | This program is distributed in the hope that it will be useful, | 
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 15 | GNU General Public License for more details. | 
|---|
| 16 |  | 
|---|
| 17 | You should have received a copy of the GNU General Public License | 
|---|
| 18 | along with this program; if not, write to the Free Software | 
|---|
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 
|---|
| 20 | */ | 
|---|
| 21 |  | 
|---|
| 22 | #define INCL_DOSERRORS | 
|---|
| 23 | #define INCL_DOS | 
|---|
| 24 | #include <os2emx.h> | 
|---|
| 25 | #include <stdio.h> | 
|---|
| 26 | #include <stdlib.h> | 
|---|
| 27 | #include <stdarg.h> | 
|---|
| 28 | #include <string.h> | 
|---|
| 29 | #include <sys/types.h> | 
|---|
| 30 | #include <sys/time.h> | 
|---|
| 31 | #include <sys/stat.h> | 
|---|
| 32 | #include "nversion.h" | 
|---|
| 33 | #include "smbwrp.h" | 
|---|
| 34 |  | 
|---|
| 35 | void debugInit(Resource *pRes, char *logfileext, int ifL) | 
|---|
| 36 | { | 
|---|
| 37 | if (!pRes) | 
|---|
| 38 | return; | 
|---|
| 39 |  | 
|---|
| 40 | pRes->firstLogLine = 1; | 
|---|
| 41 | pRes->ifL = ifL; | 
|---|
| 42 | APIRET rc = NO_ERROR; | 
|---|
| 43 |  | 
|---|
| 44 | //create the logfile variable | 
|---|
| 45 | char *env = getenv("LOGFILES"); | 
|---|
| 46 | if (env != NULL) | 
|---|
| 47 | { | 
|---|
| 48 | snprintf(pRes->logfile, sizeof(pRes->logfile), "%s/%s.%s", env, "log.ndpsmb", logfileext); | 
|---|
| 49 | snprintf(pRes->smb_logfile, sizeof(pRes->smb_logfile), "%s/%s.%s", env, "log.smbc", logfileext); | 
|---|
| 50 | } | 
|---|
| 51 | else | 
|---|
| 52 | { | 
|---|
| 53 | snprintf(pRes->logfile, sizeof(pRes->logfile), "%s.%s", "log.ndpsmb", logfileext); | 
|---|
| 54 | snprintf(pRes->smb_logfile, sizeof(pRes->smb_logfile), "%s.%s", "log.smbc", logfileext); | 
|---|
| 55 | } | 
|---|
| 56 | pRes->logfileFH = NULL; | 
|---|
| 57 |  | 
|---|
| 58 | return; | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 | void debugDelete() | 
|---|
| 62 | { | 
|---|
| 63 | return; | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | void debugClose(Resource *pRes) | 
|---|
| 67 | { | 
|---|
| 68 | if (pRes && pRes->logfileFH) | 
|---|
| 69 | { | 
|---|
| 70 | fclose(pRes->logfileFH); | 
|---|
| 71 | pRes->logfileFH = NULL; | 
|---|
| 72 | } | 
|---|
| 73 | return; | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | void debuglocal(Resource *pRes, int level, const char * fmt, ...) | 
|---|
| 77 | { | 
|---|
| 78 | FILE *f = NULL; | 
|---|
| 79 | // do we have to log at all | 
|---|
| 80 | if (pRes && (level > pRes->loglevel)) | 
|---|
| 81 | return; | 
|---|
| 82 |  | 
|---|
| 83 | do { | 
|---|
| 84 | struct timeval tv; | 
|---|
| 85 | char buf[80] = {0}; | 
|---|
| 86 | va_list args; | 
|---|
| 87 | if (pRes) | 
|---|
| 88 | { | 
|---|
| 89 | if (!pRes->logfileFH) | 
|---|
| 90 | pRes->logfileFH = fopen(pRes->logfile, "a"); | 
|---|
| 91 | if (!pRes->logfileFH) | 
|---|
| 92 | break; | 
|---|
| 93 | else | 
|---|
| 94 | f = pRes->logfileFH; | 
|---|
| 95 | } | 
|---|
| 96 | else | 
|---|
| 97 | f = stdout; | 
|---|
| 98 |  | 
|---|
| 99 | // in the first log line we write our version of the client | 
|---|
| 100 | if (pRes && pRes->firstLogLine) | 
|---|
| 101 | { | 
|---|
| 102 | fprintf(f, "Samba client %s build %s based on %s\n", VERSION, BUILD, smbwrp_getVersion()); | 
|---|
| 103 | fprintf(f, "This build is maintained by %s\n", VENDOR); | 
|---|
| 104 | fprintf(f, "Working with %s bit fileio NDFS\n", pRes->ifL ? "64" : "32"); | 
|---|
| 105 |  | 
|---|
| 106 | pRes->firstLogLine = 0; | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | gettimeofday(&tv, NULL); | 
|---|
| 110 | strftime(buf,sizeof(buf)-1,"%Y/%m/%d %H:%M:%S", localtime((time_t *)&tv.tv_sec)); | 
|---|
| 111 | fprintf(f, "%s.%d: %d %d: ", buf, tv.tv_usec / 10000, level, (long)_gettid()); | 
|---|
| 112 | va_start(args, fmt); | 
|---|
| 113 | vfprintf(f, fmt, args); | 
|---|
| 114 | va_end(args); | 
|---|
| 115 | #ifdef _DEBUG | 
|---|
| 116 | fflush(f); | 
|---|
| 117 | #endif | 
|---|
| 118 |  | 
|---|
| 119 | } while (0); | 
|---|
| 120 |  | 
|---|
| 121 | return; | 
|---|
| 122 | } | 
|---|