/* * Copyright (C) 2006 Török Edvin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * */ #include #include #include #include #include #include #include #include #include static int dehex(int c) { int l; if(!isascii(c)) return -1; if(isdigit(c)) return c - '0'; l = tolower(c); if((l >= 'a') && (l <= 'f')) return l + 10 - 'a'; cli_errmsg("hex2int() translation problem (%d)\n", l); return -1; } static const char* red = "\033[1;31m"; static const char* blue = "\033[1;34m"; static const char* green = "\033[1;32m"; static const char* magenta = "\033[1;35m"; static const char* yellow = "\033[1;33m"; static const char* color_off = "\033[0;0m"; /* TODO: for each uppercase letter add a lowercase alternative */ static const unsigned char* normalize_sig(unsigned char* sig,size_t len) { const unsigned char* ret = NULL; const unsigned char* dir = cli_gentempdir("/tmp"); unsigned char* filenam; FILE* f; html_normalise_mem(sig, len, dir , NULL); filenam = cli_malloc(strlen(dir)+20); strcpy(filenam, dir); strcat(filenam,"/"); strcat(filenam,"comment.html"); f = fopen(filenam,"rb"); if(f) { long siz; unsigned char* buff; size_t iread; fseek(f,0,SEEK_END); siz = ftell(f); buff = cli_malloc(siz); fseek(f,0, SEEK_SET); iread = fread(buff, 1, siz, f); if(ferror(f)) perror("Error while reading file!"); fclose(f); ret = cli_str2hex(buff,iread); free(buff); } else cli_dbgmsg("Unable to open:%s",filenam); free(filenam); cli_rmdirs(dir); return ret; } static int cleanup_sig(const char* newsig, const char* sig) { int up = 0; size_t i,j; cli_chomp(newsig); cli_chomp(sig); for(i=0, j=0;j < strlen(sig);) { int new_val; int old_val; if(!isxdigit(newsig[i]) && !isxdigit(sig[j]) && newsig[i] == sig[j]) { switch(sig[j]) { case '{': while (sig[j] != '}') { putc(sig[j++],stdout); i++; } putc(sig[j++],stdout); i++; break; case '(': while(sig[j] != ')') { putc(sig[j++],stdout); i++; } putc(sig[j++],stdout); i++; break; default: putc(sig[j++],stdout); i++; break; } continue; } if(isxdigit(newsig[i]) && isxdigit(newsig[i+1]) && !isxdigit(sig[j])) { printf("%s%c%c%s",blue,newsig[i],newsig[i+1],color_off); up = 1; i += 2; continue; } if(isxdigit(sig[j]) && isxdigit(sig[j+1]) && !isxdigit(newsig[i])) { if( (sig[j] == '2' && sig[j+1] == '0') || (sig[j]=='2' && sig[j+1] == '6')) printf("%c%c",sig[j],sig[j+1]);/* space, and ampersand is normal to be stripped before {,(... */ else { printf("%s{-1}%s",red,color_off); up = 1; } j += 2; continue; } new_val= (dehex(newsig[i])<<4) + dehex(newsig[i+1]); old_val = (dehex(sig[j])<<4) + dehex(sig[j+1]); if(old_val != new_val || old_val==0x26 ) {/* 0x26 needs resync always*/ int resync_needed = 0; if(new_val - old_val == 'a'-'A') { printf("%s(%02x|%02x)%s",green,old_val,new_val,color_off); up = 1; i += 2; j += 2; continue; } switch(old_val) { case 0x09: case 0x0a: case 0x0d: printf("%s{-1}%s",blue,color_off); /* TODO: check why this got stripped */ j += 2; up = 1; break; case 0x20: /*strip extra space*/ j += 2; break; case 0x26: resync_needed = 1; break; default: switch(new_val) { case 0x20: printf("%s{-1}%s",blue,color_off); i += 2; /*TODO:implement*/ up = 1; break; default: resync_needed = 1; } }/*switch old_val */ if(resync_needed) { if(old_val >= 0x80 && new_val == 0x26) { int cnt = 2; i += 2; up = 1; j += 2; if(i < strlen(newsig)) { old_val = (dehex(sig[j])<<4) + dehex(sig[j+1]); new_val = (dehex(newsig[i])<<4) + dehex(newsig[i+1]); if(old_val >=0x80) old_val = 0x26; while(i < strlen(newsig) && new_val != 0x3b ) { i += 2; cnt++; if(i