Ticket #219: lighttpd-1.4.1-include_glob.diff

File lighttpd-1.4.1-include_glob.diff, 6.1 kB (added by Aaron Walker <ka0ttic@…>, 3 years ago)
  • lighttpd-1.4.1

    diff --exclude='*~' --exclude='.*' -I '$Id:' -urN lighttpd-1.4.1.orig/configure.in lighttpd-1.4.1/configure.in
    old new  
    5656sys/socket.h sys/time.h unistd.h sys/sendfile.h sys/uio.h \ 
    5757getopt.h sys/epoll.h sys/select.h poll.h sys/poll.h sys/devpoll.h sys/filio.h \ 
    5858sys/mman.h sys/event.h sys/port.h winsock2.h pwd.h sys/syslimits.h \ 
    59 sys/resource.h sys/un.h syslog.h]) 
     59sys/resource.h sys/un.h syslog.h glob.h]) 
    6060 
    6161# Checks for typedefs, structures, and compiler characteristics. 
    6262AC_C_CONST 
     
    397397                  strdup strerror strstr strtol sendfile  getopt socket \ 
    398398                  gethostbyname poll sigtimedwait epoll_ctl getrlimit chroot \ 
    399399                  getuid select signal pathconf\ 
    400                   writev sigaction sendfile64 send_file kqueue port_create localtime_r]) 
     400                  writev sigaction sendfile64 send_file kqueue port_create localtime_r\ 
     401                  glob]) 
    401402 
    402403AC_MSG_CHECKING(for Large File System support) 
    403404AC_ARG_ENABLE(lfs, 
  • doc/configuration.txt

    diff --exclude='*~' --exclude='.*' -I '$Id:' -urN lighttpd-1.4.1.orig/doc/configuration.txt lighttpd-1.4.1/doc/configuration.txt
    old new  
    3636  <array>  : "(" [ <string> "=>" ] <value> [, [ <string> "=>" ] <value> ]* ")" 
    3737  INCLUDE  : "include" VALUE 
    3838  INCLUDE_SHELL : "include_shell" STRING_VALUE 
     39  INCLUDE_GLOB : "include_glob" STRING_VALUE 
    3940   
    4041Example 
    4142------- 
     
    6465  # read configuration from output of a command 
    6566  include_shell "/usr/local/bin/confmimetype /etc/mime.types" 
    6667 
     68  # include all files matching the specified glob pattern 
     69  include_glob "*.conf" 
     70 
    6771 
    6872Conditional Configuration 
    6973========================= 
  • src/configfile.c

    diff --exclude='*~' --exclude='.*' -I '$Id:' -urN lighttpd-1.4.1.orig/src/configfile.c lighttpd-1.4.1/src/configfile.c
    old new  
    745745                                                tid = TK_INCLUDE; 
    746746                                        } else if (strcmp(token->ptr, "include_shell") == 0) { 
    747747                                                tid = TK_INCLUDE_SHELL; 
     748                                        } else if (strcmp(token->ptr, "include_glob") == 0) { 
     749                                                tid = TK_INCLUDE_GLOB; 
    748750                                        } else if (strcmp(token->ptr, "else") == 0) { 
    749751                                                tid = TK_ELSE; 
    750752                                        } else { 
     
    844846        tokenizer_t t; 
    845847        stream s; 
    846848        int ret; 
     849        size_t i; 
    847850        buffer *filename; 
     851        data_string *ds; 
     852 
     853        /* don't parse it if we've parsed it already */ 
     854        for (i = 0; i < context->parsed->used; i++) { 
     855                if (buffer_is_equal_string( 
     856                                ((data_string *)(context->parsed->data[i]))->value, 
     857                                fn, strlen(fn))) { 
     858                        return 0; 
     859                } 
     860        } 
     861 
     862        ds = data_string_init(); 
     863        buffer_copy_string(ds->value, fn); 
     864        array_insert_unique(context->parsed, (data_unset *)ds); 
    848865 
    849866        if (buffer_is_empty(context->basedir) && 
    850867                        (fn[0] == '/' || fn[0] == '\\') && 
     
    910927        context->ok = 1; 
    911928        context->configs_stack = array_init(); 
    912929        context->configs_stack->is_weakref = 1; 
     930        context->parsed = array_init(); 
    913931        context->basedir = buffer_init(); 
    914932} 
    915933 
    916934static void context_free(config_t *context) { 
    917935        array_free(context->configs_stack); 
     936        array_free(context->parsed); 
    918937        buffer_free(context->basedir); 
    919938} 
    920939 
  • src/configfile.h

    diff --exclude='*~' --exclude='.*' -I '$Id:' -urN lighttpd-1.4.1.orig/src/configfile.h lighttpd-1.4.1/src/configfile.h
    old new  
    1010        int     ok; 
    1111        array  *all_configs; 
    1212        array  *configs_stack; /* to parse nested block */ 
     13        array  *parsed; /* keep track of the configs we've parsed */ 
    1314        data_config *current; /* current started with { */ 
    1415        buffer *basedir; 
    1516} config_t; 
  • src/configparser.y

    diff --exclude='*~' --exclude='.*' -I '$Id:' -urN lighttpd-1.4.1.orig/src/configparser.y lighttpd-1.4.1/src/configparser.y
    old new  
    77#include <stdio.h> 
    88#include <string.h> 
    99#include "config.h" 
     10#ifdef HAVE_GLOB_H 
     11# include <errno.h> 
     12# include <glob.h> 
     13#endif 
    1014#include "configfile.h" 
    1115#include "buffer.h" 
    1216#include "array.h" 
     
    132136metaline ::= condlines(A) EOL. { A = NULL; } 
    133137metaline ::= include. 
    134138metaline ::= include_shell. 
     139metaline ::= include_glob. 
    135140metaline ::= EOL. 
    136141 
    137142%type       value                  {data_unset *} 
     
    504509    A = NULL; 
    505510  } 
    506511} 
     512 
     513include_glob ::= INCLUDE_GLOB stringop(A). { 
     514  if (ctx->ok) { 
     515#ifdef HAVE_GLOB 
     516    size_t i; 
     517    int ret; 
     518    glob_t gbuf; 
     519    buffer *globstr; 
     520 
     521    /* construct full path for passing to glob() */ 
     522    if (buffer_is_empty(ctx->basedir) && 
     523        (A->ptr[0] == '/' || A->ptr[0] == '\\') && 
     524        (A->ptr[0] == '.' && (A->ptr[1] == '/' || A->ptr[1] == '\\'))) { 
     525      globstr = buffer_init_buffer(A); 
     526    } else { 
     527      globstr = buffer_init_buffer(ctx->basedir); 
     528      buffer_append_string_buffer(globstr, A); 
     529    } 
     530 
     531    errno = 0; 
     532    if (0 != (ret = glob(globstr->ptr, GLOB_ERR|GLOB_MARK, NULL, &gbuf))) { 
     533      ctx->ok = 0; 
     534 
     535      if (ret == GLOB_NOMATCH) { 
     536        fprintf(stderr, "nothing matches glob pattern '%s'\n", globstr->ptr); 
     537      } 
     538      else if (errno) { 
     539        fprintf(stderr, "glob: %s\n", strerror(errno)); 
     540      } 
     541      else { 
     542        fprintf(stderr, "internal glob() error\n"); 
     543      } 
     544    } 
     545    else { 
     546      for (i = 0; gbuf.gl_pathv[i] != NULL; i++) { 
     547        const char *path = gbuf.gl_pathv[i]; 
     548 
     549        /* skip directories ('/' is appended due to GLOB_MARK option) */ 
     550        if (path[strlen(path) - 1] == '/') { 
     551          continue; 
     552        } 
     553 
     554        /* remove the basedir we added to get the glob results */ 
     555        if (!buffer_is_empty(ctx->basedir)) { 
     556          path += strlen(ctx->basedir->ptr); 
     557        } 
     558 
     559        if (0 != config_parse_file(ctx->srv, ctx, path)) { 
     560          ctx->ok = 0; 
     561          break; 
     562        } 
     563      } 
     564    } 
     565    buffer_free(globstr); 
     566    globstr = NULL; 
     567    globfree(&gbuf); 
     568 
     569#else 
     570    fprintf(stderr, "The include_glob directive requires the glob() function.\n"); 
     571    ctx->ok = 0; 
     572#endif 
     573 
     574    buffer_free(A); 
     575    A = NULL; 
     576  } 
     577}