/* Copyright 1998 Acorn Computers Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* Generic (c.protocol) * * * StB - 09/10/97 - started * */ #include #include #include #include #include" protocol.h" #ifdef USE_SYSLOG #include ".C-veneer.h.syslog" #endif /*#define DEBUG_FILENAME "ADFS::4.$.Trace.ProtoHTTP"*/ #define DEBUG_FILENAME "RAM:$.HTTP_Trace" /*************************************************************/ /* static void protocol_debug(const char *format, ... */ /*************************************************************/ /* Output trace information to the TRACE_FILE */ /*************************************************************/ #ifdef TRACE void protocol_fast_debug(const char *format, ...) { va_list ap; #ifdef USE_SYSLOG static char buffer[1024]; va_start(ap, format); vsprintf(buffer, format, ap); va_end(ap); (void) xsyslog_logmessage("HTTP", buffer, 100); #else FILE *fp = fopen(DEBUG_FILENAME, "a"); if (fp != 0) { va_start(ap, format); (void) vfprintf(fp, format, ap); va_end(ap); fclose(fp); } #endif } #endif #ifdef TRACE void protocol_debug(const char *format, ...) { #ifdef TRACE if (getenv("NoTrace$HTTP")) return; else { va_list ap; #ifdef USE_SYSLOG static char buffer[1024]; va_start(ap, format); vsprintf(buffer, format, ap); va_end(ap); (void) xsyslog_logmessage("HTTP", buffer, 100); #else FILE *fp = fopen(DEBUG_FILENAME, "a"); if (fp != 0) { va_start(ap, format); (void) vfprintf(fp, format, ap); va_end(ap); fclose(fp); } #endif } #else (void) format; #endif } #endif #ifdef TRACE #ifndef USE_SYSLOG static char *filter(char *buf, const char *ptr, int max) { int i; for (i=0; i<=max; ++i) { int p = ptr[i]; if (p<32 || p == 127) buf[i] = '.'; else buf[i] = p; } buf[i] = '\0'; return buf; } #endif void protocol_dump(const char *ptr, int size) { #ifdef TRACE if (getenv("NoTrace$HTTP") || getenv("NoTrace$HTTPRaw")) return; else { #ifdef USE_SYSLOG (void) xsyslog_logdata("HTTP", 100, ptr, size, 0); #else FILE *fp = fopen(DEBUG_FILENAME, "a"); if (fp != NULL) { int ctr; char buf[48]; fprintf(fp, "%08x: ", 0); for (ctr=0; ctr