Ticket #1546: lighttpd-1.4.13-mod_geoip_redirect.patch

File lighttpd-1.4.13-mod_geoip_redirect.patch, 1.9 kB (added by spillgroup, 7 months ago)
  • src/mod_redirect.c

    Patch for: http://trac.lighttpd.net/trac/ticket/1546
    
    Allows environment variables to be picked up and used in mod_redirect targets. 
    
    
    diff -Bru lighttpd-1.4.13/src/mod_redirect.c lighttpd-1.4.13_mod_geoip/src/mod_redirect.c
    old new  
    242242 
    243243                        pcre_free(list); 
    244244 
     245                        // start environment variable replacement 
     246                        for (n = 0; n < con->environment->used; n++) { 
     247                                data_string *ds; 
     248 
     249                                ds = (data_string *)con->environment->data[n]; 
     250 
     251                                if (ds->value->used && ds->key->used) { 
     252                                        char key[200], *c; 
     253                                        buffer *new_location, *tmp; 
     254                                        int j, cnt; 
     255 
     256                                        // Create KEY: 
     257                                        tmp = buffer_init(); 
     258                                        buffer_prepare_append(tmp, ds->key->used + 2); 
     259                                        for (j = 0; j < ds->key->used - 1; j++) { 
     260                                                tmp->ptr[tmp->used++] = isalpha((unsigned char)ds->key->ptr[j]) ? toupper((unsigned char)ds->key->ptr[j]) : '_'; 
     261                                        } 
     262                                        tmp->ptr[tmp->used++] = '\0'; 
     263                                        snprintf(key, 200, "#%s#", tmp->ptr); 
     264                                        buffer_free(tmp); 
     265                                         
     266                                        // Find environment variable in url: 
     267                                        if((c = strstr(p->location->ptr, key)) == NULL) { 
     268                                                continue; 
     269                                        } 
     270 
     271                                        cnt = c - p->location->ptr; 
     272 
     273                                        // if find then replace this variable it's value: 
     274                                        new_location = buffer_init(); 
     275                                        buffer_append_string_len(new_location, p->location->ptr, cnt); 
     276                                        buffer_append_string_len(new_location, ds->value->ptr, strlen(ds->value->ptr)); 
     277                                        buffer_append_string_len(new_location, p->location->ptr+cnt+strlen(key), p->location->used-1-(cnt+strlen(key))); 
     278                                         
     279                                        buffer_reset(p->location); 
     280                                        buffer_copy_string_buffer(p->location, new_location); 
     281                                        buffer_free(new_location); 
     282                                } 
     283                        } 
     284                        // end environment variable replacement 
     285 
    245286                        response_header_insert(srv, con, CONST_STR_LEN("Location"), CONST_BUF_LEN(p->location)); 
    246287 
    247288                        con->http_status = 301;