/* output error message * ----------------------------------------------------------------------- */ int sh_errorn(const char *s, unsigned int len) { sh_msg(NULL); buffer_put(fd_err->w, s, len); buffer_putm(fd_err->w, ": ", strerror(errno), "\n", NULL); buffer_flush(fd_err->w); return 1; }
/* continue/break a loop * ----------------------------------------------------------------------- */ int builtin_break(int argc, char **argv) { unsigned int n = 1; if(argv[1]) { scan_uint(argv[1], &n); if(n == 0) { sh_error(argv[0]); buffer_putm(fd_err->w, ": ", argv[1], ": invalid argument"); buffer_putnlflush(fd_err->w); return 1; } } eval_jump(n, (*argv[0] == 'c')); return 0; }
int main() { char line[8192]; char* dat; char* timestamp; #ifdef oldandslow setvbuf(stdout,printfbuf,_IOFBF,sizeof printfbuf); while (fgets(line,sizeof(line),stdin)) { int tslen; /* chomp */ { int i; for (i=0; i<sizeof(line) && line[i]; ++i) if (line[i]=='\n') break; line[i]=0; } #else buffer_init(buffer_1,write,1,printfbuf,sizeof printfbuf); while (myfgets(line,sizeof(line))+1>1) { int tslen; #endif /* find out what kind of time stamp there is */ tslen=0; if (line[0]=='@') { /* multilog timestamp */ char* x=strchr(line,' '); if (x) { tslen=x-line; if (tslen!=25) tslen=0; } } else if (isdigit(line[0])) { char* x=strchr(line,' '); if (x && x==line+10) { x=strchr(x+1,' '); if (x && x==line+29) tslen=29; } } if (tslen) { dat=line+tslen+1; line[tslen]=0; timestamp=line; } else { dat=line; timestamp=""; } /* element two is the unique key */ { char* fields[21]; char* x=dat; int i; /* early-out skip the field splitting if we are not interested in * the line anyway */ if (*x != 'a' && *x != 'c' && *x != 'G' && *x != 'P' && *x != 'H') continue; /* split into fields */ for (i=0; i<20; ++i) { char* y=strchr(x,' '); if (!y) break; *y=0; fields[i]=x; x=y+1; } fields[i]=x; ++i; if (!strcmp(fields[0],"accept")) { struct node** N; struct node* x; if (i<2) continue; N=lookup(fields[1]); if (!(x=*N)) { *N=malloc(sizeof(**N)); (*N)->next=0; x=*N; } else { free(x->word); #ifdef oldandslow free(x->ip); free(x->port); free(x->timestamp); #endif } #ifndef oldandslow /* reduce allocations */ x->word=allocassert(malloc((fields[4]-fields[1])+(fields[0]-line))); memcpy(x->word,fields[1],fields[4]-fields[1]); x->ip=x->word+(fields[2]-fields[1]); x->port=x->ip+(fields[3]-fields[2]); x->timestamp=x->port+(fields[4]-fields[3]); memcpy(x->timestamp,line,fields[0]-line); #else x->word=allocassert(strdup(fields[1])); x->ip=allocassert(strdup(fields[2])); x->port=allocassert(strdup(fields[3])); x->timestamp=allocassert(strdup(line)); #endif } else if (!strncmp(fields[0],"close/",6)) { struct node** N; N=lookup(fields[1]); if (*N) { struct node* y=(*N)->next; struct node* x=*N; free(x->word); #ifdef oldandslow free(x->ip); free(x->port); free(x->timestamp); #endif free(x); *N=y; } } else if (cmp3(fields[0],"GET") || cmp4(fields[0],"POST") || cmp4(fields[0],"HEAD")) { if (i>6) { /* otherwise it's a format violation and we ignore the line */ struct node** N; N=lookup(fields[1]); #ifdef oldandslow printf("%s %s %s http%s://%s%s %s %s %s\n", timestamp,fields[0],*N?(*N)->ip:"::", strstr(fields[0],"SSL")?"s":"",fields[6],fields[2],fields[3],fields[4],fields[5]); #else buffer_putm(buffer_1,timestamp," ",fields[0]," ",*N?(*N)->ip:"::"," http", strstr(fields[0],"SSL")?"s":"","://",fields[6],fields[2]," ", fields[3]," ",fields[4]," ",fields[5],"\n"); #endif } } } } #ifndef oldandslow buffer_flush(buffer_1); #endif return 0; }
/* begin a {}-block * ----------------------------------------------------------------------- */ void debug_begin(const char *s, int depth) { debug_space(depth); buffer_putm(fd_err->w, COLOR_YELLOW, s, COLOR_CYAN, DEBUG_EQU, DEBUG_BEGIN, COLOR_NONE, NULL); }
/* output error message * ----------------------------------------------------------------------- */ int shell_errorn(const char *s, unsigned int len) { buffer_put(shell_buff, s, len); buffer_putm(shell_buff, ": ", strerror(errno), "\n", NULL); buffer_flush(shell_buff); return 1; }