#include #include #include #include "logAddServ.h" /* A "private" routine */ void write_log(FILE *outFile, char *clnt_name, char *log_msg) { char outbuff[256] ; int wrz ; if (strlen(log_msg) > MAX_MESSAGE_SIZE) log_msg[MAX_MESSAGE_SIZE] = '\0' ; wrz = sprintf(outbuff, "%-*s -- %s\n", MAX_CLIENT_NAME_SIZE, clnt_name, log_msg) ; if (wrz > 0) { fputs(outbuff, outFile) ; fflush(outFile) ; } } /* We can depend on the log_msg being short */ void logServerAction(FILE *outFile, char *clnt_name, char *log_msg) { char outBuff[256] ; (void) strcpy(outBuff, "*** ") ; (void) strcpy(&outBuff[4], log_msg) ; (void) strcat(outBuff, " ***") ; write_log(outFile, clnt_name, outBuff) ; } /* Another "private" routine */ char hexIt(int i) { int tI = i & 0xF ; return tI < 10 ? tI + '0' : tI + ('A'-10) ; } void logUserResponse(FILE *outFile, char *clnt_name, char *user_rsp, int user_rsp_size ) { char outBuff[256] ; int userP, respP, fullOutBuff ; outBuff[0] = '"' ; respP = 1 ; for(userP=0 ; userP= ' ') && (user_rsp[userP] <= '~')) outBuff[respP++] = user_rsp[userP] ; else { outBuff[respP++] = '\\' ; outBuff[respP++] = 'x' ; outBuff[respP++] = hexIt(user_rsp[userP] >> 4) ; outBuff[respP++] = hexIt(user_rsp[userP]) ; } } } if (respP < (MAX_MESSAGE_SIZE-4)) outBuff[respP++] = '\"' ; outBuff[respP] = '\0' ; write_log(outFile, clnt_name, outBuff) ; }