/[hydra]/hydra/src/escape.c
ViewVC logotype

Annotation of /hydra/src/escape.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Sat Sep 28 16:32:37 2002 UTC (19 years, 2 months ago) by nmav
Branch: MAIN
CVS Tags: hydra_0_1_6_without_hic, hydra_0_0_10, hydra_0_0_8, hydra_0_0_9, hydra_0_0_3, hydra_0_0_6, hydra_0_0_7, hydra_0_0_4, hydra_0_0_5, hydra_0_1_3, hydra_0_1_2, hydra_0_1_1, hydra_0_1_0, hydra_0_1_7, hydra_0_1_6, hydra_0_1_4, hydra_0_1_8, HEAD
Branch point for: hydra_0_1_0_patches
Changes since 1.1: +2 -2 lines
File MIME type: text/plain
In sighup and sigterm, the HIC thread is terminated as well.

1 nmav 1.1 /*
2 nmav 1.2 * Hydra, an http server
3 nmav 1.1 * escape.c
4     * Copyright (C) 2001 Jon Nelson <jnelson@boa.org>
5     * Based on escape.pl, Copyright (C) 1996 Larry Doolittle <ldoolitt@boa.org>
6     * Copyright (C) 2001 Larry Doolittle <ldoolitt@boa.org>
7     *
8     * This program is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License as published by
10     * the Free Software Foundation; either version 1, or (at your option)
11     * any later version.
12     *
13     * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17     *
18     * You should have received a copy of the GNU General Public License
19     * along with this program; if not, write to the Free Software
20     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21     *
22     */
23    
24 nmav 1.2 /* $Id: escape.c,v 1.2 2002/09/28 16:32:37 nmav Exp $ */
25 nmav 1.1
26     /*
27     unreserved = alnum | mark
28     alnum = "0".."9" | "A".."Z" | "a".."z"
29     mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
30     noescape = unreserved | ":" | "@" | "&" | "=" | "+" | "$" | "," | "/"
31     */
32    
33     #ifdef TEST
34     #include <stdio.h>
35     #include <stdlib.h>
36     #else
37     #include "boa.h"
38     #endif
39    
40     #include "escape.h"
41    
42     unsigned long _needs_escape[(NEEDS_ESCAPE_BITS+NEEDS_ESCAPE_WORD_LENGTH-1)/NEEDS_ESCAPE_WORD_LENGTH];
43    
44     void build_needs_escape(void)
45     {
46     unsigned int a, b;
47     const unsigned char special[] =
48     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
49     "abcdefghijklmnopqrstuvwxyz"
50     "0123456789"
51     "-_.!~*'():@&=+$,/?";
52     /* 21 Mar 2002 - jnelson - confirm with Apache 1.3.23 that '?'
53     * is safe to leave unescaped.
54     */
55     unsigned short i, j;
56    
57     b = 1;
58     for (a=0; b!=0; a++) b=b<<1;
59     /* I found $a bit positions available in an unsigned long. */
60     if (a < NEEDS_ESCAPE_WORD_LENGTH) {
61     fprintf(stderr,
62     "NEEDS_ESCAPE_SHIFT configuration error -- "\
63     "%d should be <= log2(%d)\n",
64     NEEDS_ESCAPE_SHIFT, a);
65     exit(1);
66     } else if (a >= 2*NEEDS_ESCAPE_WORD_LENGTH) {
67     /* needs_escape_shift configuration suboptimal */
68     } else {
69     /* Ahh, just right! */;
70     }
71     memset(_needs_escape, ~0, sizeof(_needs_escape));
72     for(i = 0; i < sizeof(special) - 1; ++i) {
73     j=special[i];
74     if (j>=NEEDS_ESCAPE_BITS) {
75     /* warning: character $j will be needlessly escaped. */
76     } else {
77     _needs_escape[NEEDS_ESCAPE_INDEX(j)]&=~NEEDS_ESCAPE_MASK(j);
78     }
79     }
80     }
81    
82     #ifdef TEST
83     int main(void)
84     {
85     int i;
86     build_needs_escape();
87     for(i = 0; i <= NEEDS_ESCAPE_BITS; ++i) {
88     if (needs_escape(i)) {
89     fprintf(stdout, "%3d needs escape.\n", i);
90     }
91     }
92     return(0);
93     }
94     #endif
95    

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26