Debian Codegraph @

addons/ooh323c/src/ootrace.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2004-2005 by Objective Systems, Inc.
3 *
4 * This software is furnished under an open source license and may be
5 * used and copied only in accordance with the terms of this license.
6 * The text of the license may generally be found in the root
7 * directory of this installation in the COPYING file. It
8 * can also be viewed online at the following URL:
9 *
10 * http://www.obj-sys.com/open/license.html
11 *
12 * Any redistributions of this file including modified versions must
13 * maintain this copyright notice.
14 *
15 *****************************************************************************/
16
17 #include "asterisk.h"
18 #include "asterisk/lock.h"
19 #include <stdarg.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <time.h>
23
24 #include "ootypes.h"
25 #include "ootrace.h"
26 #include "ooCommon.h"
27 #include "ooCapability.h"
28 #include "ooq931.h"
29 #include "ooh245.h"
30 #include "ooh323ep.h"
31
32 /** Global endpoint structure */
33 extern OOH323EndPoint gH323ep;
34
35 static OOUINT32 gs_traceLevel = TRACELVL;
36
37 void ooSetTraceThreshold(OOUINT32 traceLevel)
38 {
39 gs_traceLevel = traceLevel;
40 }
41
42 void ooTrace(OOUINT32 traceLevel, const char * fmtspec, ...) __attribute__((format(printf, 2, 3)));
43
44 void ooTrace(OOUINT32 traceLevel, const char * fmtspec, ...) {
45 va_list arglist;
46 char *logMessage = NULL;
47 int res = 0;
48 if(traceLevel > gs_traceLevel) return;
49 va_start (arglist, fmtspec);
50 res = ast_vasprintf(&logMessage, fmtspec, arglist);
51 va_end(arglist);
52 if (res < 0 || !logMessage) {
53 return;
54 }
55 ooTraceLogMessage(logMessage);
56 ast_free(logMessage);
57 }
58
59 void ooTraceLogMessage(const char * logMessage)
60 {
61 char timeString[100];
62 char currtime[3];
63 static int lasttime=25;
64 int printDate =0;
65 static int printTime=1;
66
67 #ifdef _WIN32
68
69 SYSTEMTIME systemTime;
70 GetLocalTime(&systemTime);
71 GetTimeFormat(LOCALE_SYSTEM_DEFAULT,0, &systemTime, "HH':'mm':'ss",
72 timeString, 100);
73 GetTimeFormat(LOCALE_SYSTEM_DEFAULT,0, &systemTime, "H", currtime, 3);
74 if(lasttime> atoi(currtime))
75 printDate=1;
76 lasttime = atoi(currtime);
77
78 #else
79 struct tm *ptime;
80 char dateString[10];
81 time_t t = time(NULL);
82 ptime = localtime(&t);
83 strftime(timeString, 100, "%H:%M:%S", ptime);
84 strftime(currtime, 3, "%H", ptime);
85 if(lasttime>atoi(currtime))
86 printDate = 1;
87 lasttime = atoi(currtime);
88 #endif
89
90
91 #ifdef _WIN32
92 if(printDate)
93 {
94 printDate = 0;
95 fprintf(gH323ep.fptraceFile, "---------Date %d/%d/%d---------\n",
96 systemTime.wMonth, systemTime.wDay, systemTime.wYear);
97 }
98 if(printTime) {
99 fprintf(gH323ep.fptraceFile, "%s:%03d %s", timeString,
100 systemTime.wMilliseconds, logMessage);
101 }
102 else
103 fprintf(gH323ep.fptraceFile, "%s", logMessage);
104
105 fflush(gH323ep.fptraceFile);
106 #else
107 if(printDate)
108 {
109 printDate = 0;
110 strftime(dateString, 10, "%d", ptime);
111 fprintf(gH323ep.fptraceFile, "---------Date %s---------\n",
112 dateString);
113 }
114 if(printTime) {
115 struct timeval systemTime;
116 gettimeofday(&systemTime, NULL);
117 fprintf(gH323ep.fptraceFile, "%s:%03ld %s", timeString,
118 (long) systemTime.tv_usec/1000, logMessage);
119 }
120 else
121 fprintf(gH323ep.fptraceFile, "%s", logMessage);
122
123 fflush(gH323ep.fptraceFile);
124 #endif
125
126 if(strchr(logMessage, '\n'))
127 printTime = 1;
128 else
129 printTime = 0;
130
131 }
132
133 int ooLogAsn1Error(int stat, const char * fname, int lno)
134 {
135 OOTRACEERR4("Asn1Error: %d at %s:%d\n", stat, fname, lno);
136 return stat;
137 }