pike.git / src / modules / CommonLog / clf.c

version» Context lines:

pike.git/src/modules/CommonLog/clf.c:7:   /* MUST BE FIRST */   #include "global.h"   #include "fdlib.h"   #include "stralloc.h"   #include "program.h"   #include "interpret.h"   #include "builtin_functions.h"   #include "module_support.h"   #include "pike_error.h"   #include "bignum.h" - #include "pike_security.h" +       #include "threads.h" - #include <stdio.h> +    #include <fcntl.h>         #define sp Pike_sp      /** Forward declarations of functions implementing Pike functions **/      static void f_read( INT32 args );      
pike.git/src/modules/CommonLog/clf.c:53:   #define CLF_BLOCK_SIZE 4096      /** Externally available functions **/      /* Initialize and start module */      PIKE_MODULE_INIT   {    int i;    -  MEMSET(char_class, CLS_TOKEN, sizeof(char_class)); +  memset(char_class, CLS_TOKEN, sizeof(char_class));    for(i='\0'; i<=' '; i++)    char_class[i] = CLS_WSPACE;    for(i='0'; i<='9'; i++)    char_class[i] = CLS_DIGIT;    char_class['\n'] = CLS_CRLF;    char_class['\r'] = CLS_CRLF;    char_class['"'] = CLS_QUOTE;    char_class['['] = CLS_LBRACK;    char_class[']'] = CLS_RBRACK;    char_class['/'] = CLS_SLASH;
pike.git/src/modules/CommonLog/clf.c:151:    char *read_buf;    struct svalue *logfun, *file;    FD f = -1;    int cls, c, my_fd=1, state=0, tzs=0;    char *char_pointer;    INT32 v=0, yy=0, mm=0, dd=0, h=0, m=0, s=0, tz=0;    ptrdiff_t offs0=0, len=0;    struct svalue *old_sp;    /* #define DYNAMIC_BUF */   #ifdef DYNAMIC_BUF -  dynamic_buffer buf; +  struct byte_buffer buf;   #else - #define BUFSET(X) do { if(bufpos == bufsize) { bufsize *= 2; buf = realloc(buf, bufsize+1); } buf[bufpos++] = c; } while(0) + #define BUFSET(X) do { if(bufpos == bufsize) { bufsize *= 2; buf = xrealloc(buf, bufsize+1); } buf[bufpos++] = c; } while(0)   #define PUSHBUF() do { push_string( make_shared_binary_string( buf,bufpos ) ); bufpos=0; } while(0)    char *buf;    int bufsize=CLF_BLOCK_SIZE, bufpos=0;   #endif       if(args>2 && TYPEOF(sp[-1]) == T_INT) {    offs0 = sp[-1].u.integer;    pop_n_elems(1);    --args;    }    old_sp = sp;    -  get_all_args("CommonLog.read", args, "%*%*", &logfun, &file); +  get_all_args(NULL, args, "%*%*", &logfun, &file);    if(TYPEOF(*logfun) != T_FUNCTION) -  SIMPLE_BAD_ARG_ERROR("CommonLog.read", 1, "function"); +  SIMPLE_ARG_TYPE_ERROR("read", 1, "function");       if(TYPEOF(*file) == T_OBJECT)    {    f = fd_from_object(file->u.object);       if(f == -1) -  Pike_error("CommonLog.read: File is not open.\n"); +  Pike_error("File is not open.\n");    my_fd = 0;    } else if(TYPEOF(*file) == T_STRING &&    file->u.string->size_shift == 0) { - #ifdef PIKE_SECURITY -  if(!CHECK_SECURITY(SECURITY_BIT_SECURITY)) -  { -  if(!CHECK_SECURITY(SECURITY_BIT_CONDITIONAL_IO)) -  Pike_error("Permission denied.\n"); -  push_text("read"); -  push_int(0); -  ref_push_string(file->u.string); -  push_text("r"); -  push_int(00666); -  -  safe_apply(OBJ2CREDS(CURRENT_CREDS)->user,"valid_open",5); -  switch(TYPEOF(Pike_sp[-1])) -  { -  case PIKE_T_INT: -  switch(Pike_sp[-1].u.integer) -  { -  case 0: /* return 0 */ -  errno=EPERM; -  Pike_error("CommonLog.read(): Failed to open file for reading (errno=%d).\n", -  errno); -  -  case 2: /* ok */ -  pop_stack(); -  break; -  -  case 3: /* permission denied */ -  Pike_error("CommonLog.read: permission denied.\n"); -  -  default: -  Pike_error("Error in user->valid_open, wrong return value.\n"); -  } -  break; -  -  default: -  Pike_error("Error in user->valid_open, wrong return type.\n"); -  -  case PIKE_T_STRING: -  /* if(Pike_sp[-1].u.string->shift_size) */ -  /* file=Pike_sp[-1]; */ -  pop_stack(); -  } -  -  } - #endif +     do {    THREADS_ALLOW();    f=fd_open((char *)STR0(file->u.string), fd_RDONLY, 0);    THREADS_DISALLOW();    if (f >= 0 || errno != EINTR) break;    check_threads_etc();    } while (1);       if(f < 0) -  Pike_error("CommonLog.read(): Failed to open file for reading (errno=%d).\n", +  Pike_error("Failed to open file for reading (errno=%d).\n",    errno);    } else -  SIMPLE_BAD_ARG_ERROR("CommonLog.read", 2, "string|Stdio.File"); +  SIMPLE_ARG_TYPE_ERROR("read", 2, "string|Stdio.File");      #ifdef HAVE_LSEEK64    lseek64(f, offs0, SEEK_SET);   #else    fd_lseek(f, offs0, SEEK_SET);   #endif    read_buf = malloc(CLF_BLOCK_SIZE+1);   #ifndef DYNAMIC_BUF    buf = malloc(bufsize);   #endif
pike.git/src/modules/CommonLog/clf.c:301:    } else    pop_n_elems(sp-old_sp);    }    if(cls > CLS_CRLF) {    if(cls == CLS_HYPHEN) {    push_int(0);    state = 2;    break;    }   #ifdef DYNAMIC_BUF -  buf.s.str = NULL; -  initialize_buf( &buf ); -  low_my_putchar( c, &buf ); +  buffer_init( &buf ); +  buffer_add_char( &buf , c);   #else    bufpos = 0;    BUFSET(c);   #endif    state=1;    }    break;    case 1:    if(cls > CLS_CRLF) {   #ifdef DYNAMIC_BUF -  low_my_putchar( c, &buf ); +  buffer_add_char( &buf , c);   #else    BUFSET(c);   #endif    break;    }   #ifdef DYNAMIC_BUF -  push_string( low_free_buf( &buf ) ); /* remotehost */ +  push_string( buffer_finish_pike_string( &buf ) ); /* remotehost */   #else    PUSHBUF();   #endif    state = (cls == CLS_WSPACE? 2:0);    break;    case 2:    if(cls > CLS_CRLF) {    if(cls == CLS_HYPHEN) {    push_int(0);    state = 4;    break;    }   #ifdef DYNAMIC_BUF -  buf.s.str = NULL; -  initialize_buf( &buf ); -  low_my_putchar( c, &buf ); +  buffer_init( &buf ); +  buffer_add_char( &buf , c);   #else    bufpos = 0;    BUFSET(c);   #endif       state=3;    } else if(cls == CLS_CRLF)    state=0;    break;    case 3:    if(cls > CLS_CRLF) {   #ifdef DYNAMIC_BUF -  low_my_putchar( c, &buf ); +  buffer_add_char( &buf , c);   #else    BUFSET(c);   #endif       break;    }   #ifdef DYNAMIC_BUF -  push_string( low_free_buf( &buf ) ); /* rfc931 */ +  push_string( buffer_finish_pike_string( &buf ) ); /* rfc931 */   #else    PUSHBUF(); /* rfc931 */   #endif    state = (cls == CLS_WSPACE? 4:0);    break;    case 4:    if(cls > CLS_CRLF) {    if(cls == CLS_HYPHEN) {    push_int(0);    state = 6;    break;    }   #ifdef DYNAMIC_BUF -  buf.s.str = NULL; -  initialize_buf( &buf ); -  low_my_putchar( c, &buf ); +  buffer_init( &buf ); +  buffer_add_char( &buf , c);   #else    bufpos = 0;    BUFSET(c);   #endif       state=5;    } else if(cls == CLS_CRLF)    state=0;    break;    case 5:    if(cls > CLS_CRLF) {   #ifdef DYNAMIC_BUF -  low_my_putchar( c, &buf ); +  buffer_add_char( &buf , c);   #else    BUFSET(c);   #endif       break;    }   #ifdef DYNAMIC_BUF -  push_string( low_free_buf( &buf ) ); /* authuser */ +  push_string( buffer_finish_pike_string( &buf ) ); /* authuser */   #else    PUSHBUF(); /* authuser */   #endif    state = (cls == CLS_WSPACE? 6:0);    break;    case 6:    if(cls == CLS_LBRACK)    state = 15;    else if(cls == CLS_CRLF)    state = 0;    else if(cls == CLS_HYPHEN) {    push_int(0);    push_int(0);    push_int(0);    state = 7;    }    break;    case 7:    if(cls == CLS_QUOTE) {   #ifdef DYNAMIC_BUF -  buf.s.str = NULL; -  initialize_buf( &buf ); +  buffer_init( &buf );   #else    bufpos = 0;   #endif    state = 31;    } else if(cls == CLS_CRLF)    state = 0;    else if(cls == CLS_HYPHEN) {    push_int(0);    push_int(0);    push_int(0);    state = 10;    }    break;    case 8:    if(cls == CLS_QUOTE)    state = 9;    else if(cls == CLS_CRLF) {   #ifdef DYNAMIC_BUF -  push_string( low_free_buf( &buf ) ); +  push_string( buffer_finish_pike_string( &buf ) );   #else    PUSHBUF();   #endif    state = 0;    } else   #ifdef DYNAMIC_BUF -  low_my_putchar( c, &buf ); +  buffer_add_char( &buf , c);   #else    BUFSET(c);   #endif       break;    case 9:    if(cls > CLS_CRLF) {   #ifdef DYNAMIC_BUF -  low_my_putchar( '"', &buf); -  low_my_putchar( c, &buf); +  buffer_add_char( &buf, '"'); +  buffer_add_char( &buf, c);   #else    BUFSET('"');    BUFSET(c);   #endif    state = 8;    break;    }   #ifdef DYNAMIC_BUF -  push_string( low_free_buf( &buf ) ); /* protocol */ +  push_string( buffer_finish_pike_string( &buf ) ); /* protocol */   #else    PUSHBUF(); /* protoocl */   #endif    state = (cls == CLS_CRLF? 0 : 10);    break;    case 10:    if(cls == CLS_DIGIT) {    v = c&0xf;    state = 11;    } else if(cls == CLS_CRLF)
pike.git/src/modules/CommonLog/clf.c:675:    break;    case 30:    if(cls == CLS_RBRACK)    state = 7;    else if(cls == CLS_CRLF)    state = 0;    break;    case 31:    if(cls == CLS_QUOTE) {   #ifdef DYNAMIC_BUF -  push_string( low_free_buf( &buf ) ); +  push_string( buffer_finish_pike_string( &buf ) );   #else    PUSHBUF();   #endif    push_int(0);    push_int(0);    state = 10;    } else if(cls >= CLS_TOKEN)   #ifdef DYNAMIC_BUF -  low_my_putchar( c, &buf ); +  buffer_add_char( &buf , c);   #else    BUFSET(c);   #endif       else {   #ifdef DYNAMIC_BUF -  push_string( low_free_buf( &buf ) ); /* method */ +  push_string( buffer_finish_pike_string( &buf ) ); /* method */   #else    PUSHBUF(); /* method */   #endif    state = (cls == CLS_CRLF? 0 : 32);    }    break;    case 32:    if(cls == CLS_QUOTE) {    push_int(0);    push_int(0);    state = 10;    } else if(cls >= CLS_TOKEN) {   #ifdef DYNAMIC_BUF -  buf.s.str = NULL; -  initialize_buf( &buf ); -  low_my_putchar( c, &buf ); +  buffer_init( &buf ); +  buffer_add_char( &buf , c);   #else    bufpos = 0;    BUFSET(c);   #endif       state = 33;    } else    if(cls == CLS_CRLF)    state = 0;    break;    case 33:    if(cls == CLS_QUOTE)    state = 34;    else if(cls == CLS_CRLF) {   #ifdef DYNAMIC_BUF -  push_string( low_free_buf( &buf ) ); +  push_string( buffer_finish_pike_string( &buf ) );   #else    PUSHBUF();   #endif    state = 0;    } else if(cls == CLS_WSPACE) {   #ifdef DYNAMIC_BUF -  push_string( low_free_buf( &buf ) ); /* path */ +  push_string( buffer_finish_pike_string( &buf ) ); /* path */   #else    PUSHBUF(); /* path */   #endif    state = 35;    } else   #ifdef DYNAMIC_BUF -  low_my_putchar( c, &buf ); +  buffer_add_char( &buf , c);   #else    BUFSET(c);   #endif       break;    case 34:    if(cls >= CLS_TOKEN) {   #ifdef DYNAMIC_BUF -  low_my_putchar( '"', &buf ); -  low_my_putchar( c, &buf ); +  buffer_add_char( &buf , '"'); +  buffer_add_char( &buf , c);   #else    BUFSET('"');    BUFSET(c);   #endif       state = 33;    } else if(cls == CLS_CRLF) {   #ifdef DYNAMIC_BUF -  push_string( low_free_buf( &buf ) ); +  push_string( buffer_finish_pike_string( &buf ) );   #else    PUSHBUF();   #endif    state = 0;    } else {   #ifdef DYNAMIC_BUF -  push_string( low_free_buf( &buf ) ); +  push_string( buffer_finish_pike_string( &buf ) );   #else    PUSHBUF();   #endif -  push_text("HTTP/0.9"); +  push_static_text("HTTP/0.9");    state = 10;    }    break;    case 35:    if(cls == CLS_QUOTE) { -  push_text("HTTP/0.9"); +  push_static_text("HTTP/0.9");    state = 10;    } else if(cls >= CLS_TOKEN) {   #ifdef DYNAMIC_BUF -  buf.s.str = NULL; -  initialize_buf( &buf ); -  low_my_putchar( c, &buf ); +  buffer_init( &buf ); +  buffer_add_char( &buf , c);   #else    bufpos = 0;    BUFSET(c);   #endif       state = 8;    } else    if(cls == CLS_CRLF)    state = 0;    break;    }    }    }    if(state == 1 || state == 3 || state == 5 ||    state == 8 || state == 9 ||    state == 31 || state == 33 || state == 34) {   #ifdef DYNAMIC_BUF -  push_string( low_free_buf( &buf ) ); +  push_string( buffer_finish_pike_string( &buf ) );   #else    PUSHBUF();   #endif    }    if(sp == old_sp + 15) {    f_aggregate(15);    push_int64(offs0);    apply_svalue(logfun, 2);    pop_stack();    }