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
|
/** BEGIN COPYRIGHT BLOCK
* Copyright 2001 Sun Microsystems, Inc.
* Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
* All rights reserved.
* END COPYRIGHT BLOCK **/
%{
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "libaccess/ava.h"
#include "libaccess/avapfile.h"
#include "netsite.h"
extern int linenum;
extern char yytext[];
static void AddDefType (int defType, char *defId);
static void AddAVA (char* userID);
void yyerror(const char* string);
extern void logerror(const char* string,int num, char *file);
AVAEntry tempEntry;
AVATable entryTable;
%}
%union {
char *string;
int num;
}
%token DEF_C DEF_CO DEF_OU DEF_CN EQ_SIGN DEF_START
%token DEF_L DEF_E DEF_ST
%token <string> USER_ID DEF_ID
%type <num> def.type
%start source
%%
source: ava.database
|
;
ava.database: ava.database ava
| ava
;
ava: USER_ID definitions {AddAVA($1);};
definitions: definition.list
|
;
definition.list: definition.list definition
| definition
;
definition: def.type EQ_SIGN DEF_ID {AddDefType($1, $3);};
def.type: DEF_C {$$ = DEF_C; }
| DEF_CO {$$ = DEF_CO;}
| DEF_OU {$$ = DEF_OU;}
| DEF_CN {$$ = DEF_CN;}
| DEF_L {$$ = DEF_L; }
| DEF_E {$$ = DEF_E; }
| DEF_ST {$$ = DEF_ST;}
;
%%
void yyerror(const char* string) {
logerror(string,linenum,currFile);
}
void AddDefType (int defType, char *defId) {
switch (defType) {
case DEF_C:
tempEntry.country = defId;
break;
case DEF_CO:
tempEntry.company = defId;
break;
case DEF_OU:
if (tempEntry.numOrgs % ORGS_ALLOCSIZE == 0) {
if (tempEntry.numOrgs == 0) {
tempEntry.organizations =
PERM_MALLOC (sizeof (char*) * ORGS_ALLOCSIZE);
} else {
char **temp;
temp =
PERM_MALLOC(sizeof(char*) * (tempEntry.numOrgs + ORGS_ALLOCSIZE));
memcpy (temp, tempEntry.organizations,
sizeof(char*)*tempEntry.numOrgs);
PERM_FREE (tempEntry.organizations);
tempEntry.organizations = temp;
}
}
tempEntry.organizations[tempEntry.numOrgs++] = defId;
break;
case DEF_CN:
tempEntry.CNEntry = defId;
break;
case DEF_E:
tempEntry.email = defId;
break;
case DEF_L:
tempEntry.locality = defId;
break;
case DEF_ST:
tempEntry.state = defId;
break;
default:
break;
}
}
void AddAVA (char* userID) {
AVAEntry *newAVA;
newAVA = (AVAEntry*)PERM_MALLOC(sizeof(AVAEntry));
if (!newAVA) {
yyerror ("Out of Memory in AddAVA");
return;
}
*newAVA = tempEntry;
newAVA->userid = userID;
_addAVAtoTable (newAVA, &entryTable);
tempEntry.CNEntry = tempEntry.userid = tempEntry.country = tempEntry.company = 0;
tempEntry.email = tempEntry.locality = tempEntry.state = NULL;
tempEntry.numOrgs = 0;
}
|