#pragma module pppdutil_decode_log "X-4" /* ***************************************************************************** * * Copyright © 1996 Digital Equipment Corporation. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by Digital Equipment Corporation. The name of the * Corporation may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * ***************************************************************************** FACILITY: PPPD logger ABSTRACT: Simple program to read the log file and display it one record at a time. AUTHOR: Forrest A. Kenney 17-December-1995 REVISION HISTORY: X-4 BWK004 Barry W. Kierstein 17-DEC-1996 Replaced the standard Digital copyright with one compatible with the CMU copyright. X-3 BWK003 Barry W. Kierstein 24-Jul-1996 Corrected copyright notice. X-2 BWK002 Barry W. Kierstein 11-Jul-1996 Incorporated FREE_DYNAMIC_DESCRIPTOR. X-1 BWK001 Barry W. Kierstein 07-May-1996 Converted this routine from using argc/argv to calling the CLI for the input and output files, and incorporated this module into the main image. */ /* Local constants */ #define MAX_OUT_REC 255 /* Include various necessary description files */ #include #include #include #include #include #include #include "pppddef.h" #include "pppd_log_if.h" #include "pppdutil_common.h" /* **+ ** Function Name ** ** util$convert_log_file ** ** Functional Description: ** ** It assumes that you have supplied the binary log file as the first ** argument and text output file as the second argument. It opens the files ** and then reads one record at a time from the binary log file and converts it ** to ASCII text and writes it to the ASCII text file. It will do this until ** an error occurs reading data or if we cannot convert the binary time into an ** text string. If the time conversion does not work the most probably reason ** is a corrupt log file. ** ** Explicit Inputs: ** ** None ** ** Implicit Inputs: ** ** Input and output files from the CLI. ** ** Local Variables: ** ** binary_filename - Name of the binary log file ** binary_file - File pointer returned by fopen for the binary ** log file ** out_rec - Character string used to build up the ASCII ** representation of a binary log file record ** out_str_len - Length in bytes of the ascii representation of ** a logger record ** output_filename - Name of the ascii representation of the log file ** output_file - File pointer returned by fopen for the ascii ** reprsentation of the log file ** record - Binary record from the log file ** record_count - Count of the number of records in the log file ** status - VMS return status from call to SYS$ASCTIM ** time - VMS string descriptor used by SYS$ASCITM to ** hold ASCII representation of the time stamp ** time_len - Length in bytes of the ** time_str - String used to hold the ASCII representation of ** the time stamp. ** ** Outputs: ** ** None ** ** NOTES: ** ** None ** **- */ $DESCRIPTOR(binary_file_param,"CONVERT_INPUT"); $DESCRIPTOR(output_file_param,"CONVERT_OUTPUT"); util$convert_log_file() { D_DESCRIPTOR binary_filename; D_DESCRIPTOR output_filename; FILE *binary_file; FILE *output_file; int max_filename = NAM$C_MAXRSS+1; /* +1 for trailing '\0' */ char out_rec[MAX_OUT_REC]; int out_str_len; int record_count = 0; int status; short int time_len; logRecord record; char time_str[31]; struct dsc$descriptor_vs time; time.dsc$w_maxstrlen = 31; time.dsc$b_dtype = DSC$K_DTYPE_VT; time.dsc$b_class = DSC$K_CLASS_VS; time.dsc$a_pointer = time_str; /* Get the binary and output filenames */ INIT_DYNAMIC_DESCRIPTOR(binary_filename,max_filename); if (!get_str_qualifier(&binary_file_param,&binary_filename)) { FREE_DYNAMIC_DESCRIPTOR(&binary_filename); return(PPPD$_ABORT); } binary_filename.dsc$a_pointer[binary_filename.dsc$w_length] = '\0'; INIT_DYNAMIC_DESCRIPTOR(output_filename,max_filename); if (!get_str_qualifier(&output_file_param,&output_filename)) { FREE_DYNAMIC_DESCRIPTOR(&binary_filename); FREE_DYNAMIC_DESCRIPTOR(&output_filename); return(PPPD$_ABORT); } output_filename.dsc$a_pointer[output_filename.dsc$w_length] = '\0'; /* We have an input and output so lets open them up */ binary_file = fopen(binary_filename.dsc$a_pointer, "rb", "ctx=rec", "rat=none", "rfm=var", "shr=get"); if (!(binary_file == NULL)) { output_file = fopen(output_filename.dsc$a_pointer, "w+"); if (!(output_file == NULL)) { /* Loop until we get an error reading the input file. Note that if we get an error converting binary time to ASCII format this will break from the loop. */ while(fread((void *)&record, sizeof(logRecord), 1, binary_file) >= 1) { record_count += 1; status = SYS$ASCTIM(&time_len, &time, &record.timeStamp, 0); if (!(status & SS$_NORMAL)) { printf("Error converting time to ASCII format error # %7x\n", status); break; } time_str[time_len] = (char)0; out_str_len = sprintf((void *)out_rec,"%s ", time_str); /* Determine what type of message we have */ switch (record.msgType) { case LOG_EMERG: out_str_len += sprintf((void *)&out_rec[out_str_len], "LOG_EMERG "); break; case LOG_ALERT: out_str_len += sprintf((void *)&out_rec[out_str_len], "LOG_ALERT "); break; case LOG_CRIT: out_str_len += sprintf((void *)&out_rec[out_str_len], "LOG_CRIT "); break; case LOG_ERR: out_str_len += sprintf((void *)&out_rec[out_str_len], "LOG_ERR "); break; case LOG_WARNING: out_str_len += sprintf((void *)&out_rec[out_str_len], "LOG_WARNING "); break; case LOG_NOTICE: out_str_len += sprintf((void *)&out_rec[out_str_len], "LOG_NOTICE "); break; case LOG_INFO: out_str_len += sprintf((void *)&out_rec[out_str_len], "LOG_INFO "); break; case LOG_DEBUG: out_str_len += sprintf((void *)&out_rec[out_str_len], "LOG_DEBUG "); break; case LOG_EOF: out_str_len += sprintf((void *)&out_rec[out_str_len], "LOG_EOF "); break; default: printf("Error unknown record on record %d\n", record_count); break; } /* Get text string and output log record to text file */ record.msg[record.msgLen] = '\0'; out_str_len += sprintf((void *)&out_rec[out_str_len], "%s", record.msg); record.msg[out_str_len] = '\0'; fprintf(output_file, "%s\n", out_rec); } fclose(output_file); } else { signal_error (PPPD$_NOCVTOUTPUT, 1, &output_filename); } fclose(binary_file); } else { signal_error (PPPD$_NOCVTINPUT, 1, &binary_filename); } return(SS$_NORMAL); }