about summary refs log tree commit diff stats
ModeNameSize
-rw-r--r--000organization.cc5283log stats plain blame
-rw-r--r--001help.cc4012log stats plain blame
-rw-r--r--002test.cc3115log stats plain blame
-rw-r--r--003trace.cc13633log stats plain blame
-rw-r--r--003trace.test.cc3641log stats plain blame
-rw-r--r--010vm.cc10041log stats plain blame
-rw-r--r--011load.cc10913log stats plain blame
-rw-r--r--012transform.cc1639log stats plain blame
-rw-r--r--013literal_string.cc5487log stats plain blame
-rw-r--r--014literal_noninteger.cc833log stats plain blame
-rw-r--r--020run.cc11966log stats plain blame
-rw-r--r--021arithmetic.cc6963log stats plain blame
-rw-r--r--022boolean.cc3020log stats plain blame
-rw-r--r--023jump.cc4834log stats plain blame
-rw-r--r--024compare.cc8079log stats plain blame
-rw-r--r--029tools.cc7809log stats plain blame
-rw-r--r--030container.cc15432log stats plain blame
-rw-r--r--031address.cc4981log stats plain blame
-rw-r--r--032array.cc11308log stats plain blame
-rw-r--r--033exclusive_container.cc5868log stats plain blame
-rw-r--r--034call.cc3914log stats plain blame
-rw-r--r--035call_ingredient.cc4303log stats plain blame
-rw-r--r--036call_reply.cc6047log stats plain blame
-rw-r--r--037recipe.cc1975log stats plain blame
-rw-r--r--038scheduler.cc14853log stats plain blame
-rw-r--r--039wait.cc5516log stats plain blame
-rw-r--r--040brace.cc9371log stats plain blame
-rw-r--r--041jump_target.cc4566log stats plain blame
-rw-r--r--042name.cc9089log stats plain blame
-rw-r--r--043new.cc13918log stats plain blame
-rw-r--r--044space.cc7539log stats plain blame
-rw-r--r--045space_surround.cc1951log stats plain blame
-rw-r--r--046closure_name.cc5999log stats plain blame
-rw-r--r--047global.cc2606log stats plain blame
-rw-r--r--048typecheck.cc2971log stats plain blame
-rw-r--r--050scenario.cc18323log stats plain blame
-rw-r--r--051scenario_test.mu1055log stats plain blame
-rw-r--r--052tangle.cc10470log stats plain blame
-rw-r--r--053continuation.cc9215log stats plain blame
-rw-r--r--060string.mu36717log stats plain blame
-rw-r--r--061channel.mu11764log stats plain blame
-rw-r--r--062array.mu968log stats plain blame
-rw-r--r--063list.mu1568log stats plain blame
-rw-r--r--064random.cc1558log stats plain blame
-rw-r--r--065duplex_list.mu20460log stats plain blame
-rw-r--r--066stream.mu1166log stats plain blame
-rw-r--r--070display.cc13391log stats plain blame
-rw-r--r--071print.mu19074log stats plain blame
-rw-r--r--072scenario_screen.cc12372log stats plain blame
-rw-r--r--073scenario_screen_test.mu690log stats plain blame
-rw-r--r--074console.mu3218log stats plain blame
-rw-r--r--075scenario_console.cc9377log stats plain blame
-rw-r--r--076scenario_console_test.mu638log stats plain blame
-rw-r--r--080trace_browser.cc7720log stats plain blame
-rw-r--r--081run_interactive.cc12555log stats plain blame
-rw-r--r--082persist.cc3500log stats plain blame
-rw-r--r--999spaces.cc1405log stats plain blame
-rw-r--r--Readme.md16035log stats plain blame
d---------arc1164log stats plain
-rwxr-xr-xbuild_and_test_until428log stats plain blame
-rw-r--r--callcc.mu374log stats plain blame
-rw-r--r--cannot_write_tests_for280log stats plain blame
-rw-r--r--channel.mu1059log stats plain blame
-rw-r--r--chessboard.mu23079log stats plain blame
-rw-r--r--console.mu329log stats plain blame
-rw-r--r--counters.mu963log stats plain blame
-rw-r--r--display.mu642log stats plain blame
d---------edit543log stats plain
d---------enumerate76log stats plain
-rw-r--r--factorial.mu567log stats plain blame
-rw-r--r--fork.mu175log stats plain blame
-rw-r--r--global.mu334log stats plain blame
d---------html3568log stats plain
-rw-r--r--index.html14554log stats plain blame
-rw-r--r--makefile2100log stats plain blame
-rwxr-xr-xmu162log stats plain blame
-rw-r--r--mu.vim2912log stats plain blame
-rwxr-xr-xrelayout1053log stats plain blame
d---------sandbox614log stats plain
-rw-r--r--screen.mu737log stats plain blame
-rw-r--r--tangle.mu708log stats plain blame
d---------tangle315log stats plain
d---------termbox394log stats plain
-rwxr-xr-xtest_all_layers272log stats plain blame
-rwxr-xr-xupdate_github_page251log stats plain blame
-rwxr-xr-xupdate_html676log stats plain blame
-rw-r--r--vimrc.vim1950log stats plain blame
-rw-r--r--x.mu151log stats plain blame
WW/Library/Implementation/HTRules.c?id=d3f9d5478df478427c2aa5db4507ddd0a38f0eb6'>d3f9d547 ^
e087f6d4


152e034b ^
d3f9d547 ^
e087f6d4
d3f9d547 ^
e087f6d4













d3f9d547 ^
e087f6d4




0654c702 ^

e087f6d4


d3f9d547 ^
e087f6d4
d3f9d547 ^
e087f6d4









8ce6b560 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404








                                                                            



                                                                               






                                                                               

                    
                                                                           
                    
 
                   
                    
                     










                                

                



                                                                          
                                                                          
















                                                                           
                                                                             


                                                                      
                                                  

  



                                
                                                                

                         

                                         

                                        
                                                 

                                        

                                                         



                                            
            
                        




                              



                                                                       

     


                             









                                          
 



             
                                                                              



                          



                   
                        

                   
                            







                            










                                                                             
                                                                           









                                                                              

                                 







                                                                    
                              







                                                                          
                                                                        
                                                                   
                                                          








                                                                             
                         


                                       





                                                                        


                                                       


                                                 














                                                                           

                                                                
                                   
                 
                                                          
 

                                                                  

                                                                               

                                                                             
                                                        

                                                            
                                       
                                                                            
                                                                


                                                                              

                                                            
                                      
                                                                      


                                                                         
                                       

                                                                            
                                                            

                                                               
                                                                      


                                                        

                                                             





                                                                  

                                                      
                              
                                 














                                                                      

                                     







                                       
 







                                                               
                   
                 
                                   









                                                                              
                                                                  




                                          
                                                






                                                               
                                                         
                                                                        
                        
                                       

                                                              










                                                                        



                                                             


                                                                   
                                                                         
                
                                        
         













                                                                             
                                                  




                                           

                                 


                                     
 
              
                                                                     









                                                                          
                     
/*	Configuration manager for Hypertext Daemon		HTRules.c
**	==========================================
**
**
** History:
**	 3 Jun 91	Written TBL
**	10 Aug 91	Authorisation added after Daniel Martin (pass, fail)
**			Rule order in file changed
**			Comments allowed with # on 1st char of rule line
**	17 Jun 92	Bug fix: pass and fail failed if didn't contain '*' TBL
**	 1 Sep 93	Bug fix: no memory check - Nathan Torkington
**			BYTE_ADDRESSING removed - Arthur Secret
**	11 Sep 93  MD	Changed %i into %d in debug printf.
**			VMS does not recognize %i.
**			Bug Fix: in case of PASS, only one parameter to printf.
**	19 Sep 93  AL	Added Access Authorization stuff.
**	 1 Nov 93  AL	Added htbin.
**
*/

#include <HTUtils.h>

/* (c) CERN WorldWideWeb project 1990,91. See Copyright.html for details */
#include <HTRules.h>

#include <HTFile.h>
#include <LYLeaks.h>
#include <HTAAProt.h>

#define LINE_LENGTH 256


typedef struct _rule {
	struct _rule *	next;
	HTRuleOp	op;
	char *		pattern;
	char *		equiv;
} rule;

#ifndef NO_RULES

/*	Global variables
**	----------------
*/
PUBLIC char *HTBinDir = NULL;	/* Physical /htbin directory path.	*/
				/* In future this should not be global. */
PUBLIC char *HTSearchScript = NULL;	/* Search script name.		*/


/*	Module-wide variables
**	---------------------
*/

PRIVATE rule * rules = 0;	/* Pointer to first on list */
#ifndef PUT_ON_HEAD
PRIVATE rule * rule_tail = 0;	/* Pointer to last on list */
#endif


/*	Add rule to the list					HTAddRule()
**	--------------------
**
**  On entry,
**	pattern 	points to 0-terminated string containing a single "*"
**	equiv		points to the equivalent string with * for the
**			place where the text matched by * goes.
**  On exit,
**	returns 	0 if success, -1 if error.
*/

PUBLIC int HTAddRule ARGS3(
    HTRuleOp,		op,
    CONST char *,	pattern,
    CONST char *,	equiv)
{ /* BYTE_ADDRESSING removed and memory check - AS - 1 Sep 93 */
    rule *	temp;
    char *	pPattern;

    temp = (rule *)malloc(sizeof(*temp));
    if (temp==NULL)
	outofmem(__FILE__, "HTAddRule");
    pPattern = (char *)malloc(strlen(pattern)+1);
    if (pPattern==NULL)
	outofmem(__FILE__, "HTAddRule");
    if (equiv) {		/* Two operands */
	char *	pEquiv = (char *)malloc(strlen(equiv)+1);
	if (pEquiv==NULL)
	    outofmem(__FILE__, "HTAddRule");
	temp->equiv = pEquiv;
	strcpy(pEquiv, equiv);
    } else {
	temp->equiv = 0;
    }
    temp->pattern = pPattern;
    temp->op = op;

    strcpy(pPattern, pattern);
    if (equiv) {
	CTRACE(tfp, "Rule: For `%s' op %d `%s'\n", pattern, op, equiv);
    } else {
	CTRACE(tfp, "Rule: For `%s' op %d\n", pattern, op);
    }

    if (!rules) {
	atexit(HTClearRules);
    }
#ifdef PUT_ON_HEAD
    temp->next = rules;
    rules = temp;
#else
    temp->next = 0;
    if (rule_tail) rule_tail->next = temp;
    else rules = temp;
    rule_tail = temp;
#endif


    return 0;
}


/*	Clear all rules 					HTClearRules()
**	---------------
**
** On exit,
**	There are no rules
**
** See also
**	HTAddRule()
*/
void HTClearRules NOARGS
{
    while (rules) {
	rule * temp = rules;
	rules = temp->next;
	FREE(temp->pattern);
	FREE(temp->equiv);
	FREE(temp);
    }
#ifndef PUT_ON_HEAD
    rule_tail = 0;
#endif
}


/*	Translate by rules					HTTranslate()
**	------------------
**
**	The most recently defined rules are applied first.
**
** On entry,
**	required	points to a string whose equivalent value is neeed
** On exit,
**	returns 	the address of the equivalent string allocated from
**			the heap which the CALLER MUST FREE. If no translation
**			occured, then it is a copy of te original.
** NEW FEATURES:
**			When a "protect" or "defprot" rule is mathed,
**			a call to HTAA_setCurrentProtection() or
**			HTAA_setDefaultProtection() is made to notify
**			the Access Authorization module that the file is
**			protected, and so it knows how to handle it.
**								-- AL
*/
char * HTTranslate ARGS1(
    CONST char *,	required)
{
    rule * r;
    char *current = NULL;
    StrAllocCopy(current, required);

    HTAA_clearProtections();	/* Reset from previous call -- AL */

    for(r = rules; r; r = r->next) {
	char * p = r->pattern;
	int m=0;   /* Number of characters matched against wildcard */
	CONST char * q = current;
	for(;*p && *q; p++, q++) {   /* Find first mismatch */
	    if (*p!=*q) break;
	}

	if (*p == '*') {		/* Match up to wildcard */
	    m = strlen(q) - strlen(p+1); /* Amount to match to wildcard */
	    if(m<0) continue;		/* tail is too short to match */
	    if (0!=strcmp(q+m, p+1)) continue;	/* Tail mismatch */
	} else				/* Not wildcard */
	    if (*p != *q) continue;	/* plain mismatch: go to next rule */

	switch (r->op) {		/* Perform operation */

#ifdef ACCESS_AUTH
	case HT_DefProt:
	case HT_Protect:
	    {
		char *local_copy = NULL;
		char *p2;
		char *eff_ids = NULL;
		char *prot_file = NULL;

		CTRACE(tfp, "HTRule: `%s' matched %s %s: `%s'\n",
			    current,
			    (r->op==HT_Protect ? "Protect" : "DefProt"),
			    "rule, setup",
			    (r->equiv ? r->equiv :
			     (r->op==HT_Protect ?"DEFAULT" :"NULL!!")));

		if (r->equiv) {
		    StrAllocCopy(local_copy, r->equiv);
		    p2 = local_copy;
		    prot_file = HTNextField(&p2);
		    eff_ids = HTNextField(&p2);
		}

		if (r->op == HT_Protect)
		    HTAA_setCurrentProtection(current, prot_file, eff_ids);
		else
		    HTAA_setDefaultProtection(current, prot_file, eff_ids);

		FREE(local_copy);

		/* continue translating rules */
	    }
	    break;
#endif /* ACCESS_AUTH */

	case HT_Pass:				/* Authorised */
		if (!r->equiv) {
		    CTRACE(tfp, "HTRule: Pass `%s'\n", current);
		    return current;
		}
		/* Else fall through ...to map and pass */

	case HT_Map:
	    if (*p == *q) { /* End of both strings, no wildcard */
		  CTRACE(tfp, "For `%s' using `%s'\n", current, r->equiv);
		  StrAllocCopy(current, r->equiv); /* use entire translation */
	    } else {
		  char * ins = strchr(r->equiv, '*');	/* Insertion point */
		  if (ins) {	/* Consistent rule!!! */
			char * temp = (char *)malloc(
				strlen(r->equiv)-1 + m + 1);
			if (temp==NULL)
			    outofmem(__FILE__, "HTTranslate"); /* NT & AS */
			strncpy(temp,	r->equiv, ins-r->equiv);
			/* Note: temp may be unterminated now! */
			strncpy(temp+(ins-r->equiv), q, m);  /* Matched bit */
			strcpy (temp+(ins-r->equiv)+m, ins+1);	/* Last bit */
			CTRACE(tfp, "For `%s' using `%s'\n",
				    current, temp);
			FREE(current);
			current = temp; 		/* Use this */

		    } else {	/* No insertion point */
			char * temp = (char *)malloc(strlen(r->equiv)+1);
			if (temp==NULL)
			    outofmem(__FILE__, "HTTranslate"); /* NT & AS */
			strcpy(temp, r->equiv);
			CTRACE(tfp, "For `%s' using `%s'\n",
						current, temp);
			FREE(current);
			current = temp; 		/* Use this */
		    } /* If no insertion point exists */
		}
		if (r->op == HT_Pass) {
		    CTRACE(tfp, "HTRule: ...and pass `%s'\n",
				current);
		    return current;
		}
		break;

	case HT_Invalid:
	case HT_Fail:				/* Unauthorised */
		CTRACE(tfp, "HTRule: *** FAIL `%s'\n",
			    current);
		FREE(current);
		return (char *)0;
	} /* if tail matches ... switch operation */

    } /* loop over rules */


    return current;
}

/*	Load one line of configuration
**	------------------------------
**
**	Call this, for example, to load a X resource with config info.
**
** returns	0 OK, < 0 syntax error.
*/
PUBLIC int  HTSetConfiguration ARGS1(
    CONST char *,	config)
{
    HTRuleOp op;
    char * line = NULL;
    char * pointer = line;
    char *word1, *word2, *word3;
    float quality, secs, secs_per_byte;
    int maxbytes;
    int status;

    StrAllocCopy(line, config);
    {
	char * p = strchr(line, '#');	/* Chop off comments */
	if (p) *p = 0;
    }
    pointer = line;
    word1 = HTNextField(&pointer);
    if (!word1) {
	FREE(line);
	return 0;
    } ; /* Comment only or blank */

    word2 = HTNextField(&pointer);

    if (0==strcasecomp(word1, "defprot") ||
	0==strcasecomp(word1, "protect"))
	word3 = pointer;  /* The rest of the line to be parsed by AA module */
    else
	word3 = HTNextField(&pointer);	/* Just the next word */

    if (!word2) {
	fprintf(stderr, "HTRule: %s %s\n", RULE_NEEDS_DATA, line);
	FREE(line);
	return -2;	/*syntax error */
    }

    if (0==strcasecomp(word1, "suffix")) {
	char * encoding = HTNextField(&pointer);
	if (pointer) status = sscanf(pointer, "%f", &quality);
	else status = 0;
	HTSetSuffix(word2,	word3,
				encoding ? encoding : "binary",
				status >= 1? quality : 1.0);

    } else if (0==strcasecomp(word1, "presentation")) {
	if (pointer) status = sscanf(pointer, "%f%f%f%d",
			    &quality, &secs, &secs_per_byte, &maxbytes);
	else status = 0;
	HTSetPresentation(word2, word3,
		    status >= 1? quality		: 1.0,
		    status >= 2 ? secs			: 0.0,
		    status >= 3 ? secs_per_byte 	: 0.0,
		    status >= 4 ? maxbytes		: 0 );

    } else if (0==strncasecomp(word1, "htbin", 5) ||
	       0==strncasecomp(word1, "bindir", 6)) {
	StrAllocCopy(HTBinDir, word2);	/* Physical /htbin location */

    } else if (0==strncasecomp(word1, "search", 6)) {
	StrAllocCopy(HTSearchScript, word2);	/* Search script name */

    } else {
	op =	0==strcasecomp(word1, "map")  ? HT_Map
	    :	0==strcasecomp(word1, "pass") ? HT_Pass
	    :	0==strcasecomp(word1, "fail") ? HT_Fail
	    :	0==strcasecomp(word1, "defprot") ? HT_DefProt
	    :	0==strcasecomp(word1, "protect") ? HT_Protect
	    :						HT_Invalid;
	if (op==HT_Invalid) {
	    fprintf(stderr, "HTRule: %s '%s'\n", RULE_INCORRECT, config);
	} else {
	    HTAddRule(op, word2, word3);
	}
    }
    FREE(line);
    return 0;
}


/*	Load the rules from a file				HTLoadRules()
**	--------------------------
**
** On entry,
**	Rules can be in any state
** On exit,
**	Any existing rules will have been kept.
**	Any new rules will have been loaded.
**	Returns 	0 if no error, 0 if error!
**
** Bugs:
**	The strings may not contain spaces.
*/

int HTLoadRules ARGS1(
    CONST char *,	filename)
{
    FILE * fp = fopen(filename, "r");
    char line[LINE_LENGTH+1];

    if (!fp) {
	CTRACE(tfp, "HTRules: Can't open rules file %s\n", filename);
	return -1; /* File open error */
    }
    for(;;) {
	if (!fgets(line, LINE_LENGTH+1, fp)) break;	/* EOF or error */
	(void) HTSetConfiguration(line);
    }
    fclose(fp);
    return 0;		/* No error or syntax errors ignored */
}

#endif /* NO_RULES */