My favorites
▼
|
Sign in
fscops
OHSM - Online Hierarchical Storage Manager
Project Home
Downloads
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
8
attachment: ohsm_xml_policy_functions.c
(7.6 KB)
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <stdlib.h>
#include "ohsm_user.h"
void
parseinfo (xmlDocPtr doc, xmlNodePtr cur, unsigned int *users,
unsigned int *groups, unsigned int *types)
{
xmlChar *key;
unsigned int temp_uid;
unsigned char temp_tier;
int i = 0;
char *Char;
cur = cur->xmlChildrenNode;
while (cur != NULL)
{
if ((!xmlStrcmp (cur->name, (const xmlChar *) "users")))
{
key = xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
*users = atoi ((char *) key);
printf ("\nThe Number of users : %u", *users);
xmlFree (key);
}
else if ((!xmlStrcmp (cur->name, (const xmlChar *) "groups")))
{
key = xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
*groups = atoi ((char *) key);
printf ("\nNumber of Groups = %u\n", *groups);
xmlFree (key);
i = i + 1;
}
else if ((!xmlStrcmp (cur->name, (const xmlChar *) "types")))
{
key = xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
*types = atoi ((char *) key);
printf ("\nNumber of Types = %u\n", *types);
xmlFree (key);
i = i + 1;
}
/* CASE 1
else
{
printf("ERROR: <%s> not a valid tag",cur->name);
exit(0);
}*/
cur = cur->next;
i++;
}
return;
}
void
print_and_test_user (struct uid_tier *ptr, unsigned int number)
{
int i = 0;
for (i = 0; i < number; i++)
{
printf ("\nUid %u Tier %u", ptr[i].uid, ptr[i].tier);
}
printf ("\n");
}
void
print_and_test_group (struct gid_tier *ptr, unsigned int number)
{
int i = 0;
for (i = 0; i < number; i++)
{
printf ("\nGid %u Tier %u", ptr[i].gid, ptr[i].tier);
}
printf ("\n");
}
void
print_and_test_type (struct name_tier *ptr, unsigned int number)
{
int i = 0;
for (i = 0; i < number; i++)
{
printf ("\nName %s Tier %u", ptr[i].name, ptr[i].tier);
}
printf ("\n");
}
void
parseuser (xmlDocPtr doc, xmlNodePtr cur, const unsigned int number,
struct uid_tier **ptrx)
{
xmlChar *key;
unsigned int temp_uid,temp_uid1;
unsigned char temp_tier,temp_tier1;
unsigned int i = 0;
struct uid_tier *ptr;
ptr =
(struct uid_tier *) malloc ((size_t) (number * sizeof (struct uid_tier)));
if( ptr == NULL)
{
printf("\n\nError in parseuser ");
return;
}
*ptrx = ptr;
cur = cur->xmlChildrenNode;
while (cur != NULL)
{
if ((!xmlStrcmp (cur->name, (const xmlChar *) "user")))
{
key = xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
temp_uid = atoi ((char *) key);
ptr[i].uid = temp_uid;
xmlFree (key);
}
if ((!xmlStrcmp (cur->name, (const xmlChar *) "tier")))
{
key = xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
temp_tier = atoi ((char *) key);
ptr[i].tier = temp_tier;
xmlFree (key);
i++;
}
cur = cur->next;
}
/* CASE 2
for (i=0;i < no_of_users ;i++ )
{
we can include the validation part here
checking all the uid and tierid with each other
}*/
printf ("\n\nPrinting from parseuser :");
print_and_test_user (ptr, number);
return;
}
void
parsegroup (xmlDocPtr doc, xmlNodePtr cur, unsigned int groups,
struct gid_tier **ptrx)
{
xmlChar *key;
unsigned int temp_gid;
unsigned char temp_tier;
unsigned int i = 0;
struct gid_tier *ptr;
ptr =
(struct gid_tier *) malloc ((size_t) (groups * sizeof (struct gid_tier)));
if( ptr == NULL)
{
printf("\n\nError in parsegroup ");
return;
}
*ptrx = ptr;
cur = cur->xmlChildrenNode;
while (cur != NULL)
{
if ((!xmlStrcmp (cur->name, (const xmlChar *) "group")))
{
key = xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
temp_gid = atoi ((char *) key);
// printf ("\nThe Gid : %u", temp_gid);
ptr[i].gid = temp_gid;
xmlFree (key);
}
if ((!xmlStrcmp (cur->name, (const xmlChar *) "tier")))
{
key = xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
temp_tier = atoi ((char *) key);
//printf (" Tier = %u\n", temp_tier);
ptr[i].tier = temp_tier;
xmlFree (key);
i++;
}
cur = cur->next;
}
printf ("\n\nPrinting from parsegroup:");
print_and_test_group (ptr, groups);
return;
}
void
parsetypes (xmlDocPtr doc, xmlNodePtr cur, unsigned int types,
struct name_tier **ptrx)
{
xmlChar *key;
unsigned int temp_gid;
unsigned char temp_tier;
unsigned int i = 0;
char *temp_name = NULL;
struct name_tier *ptr;
ptr =
(struct name_tier *)
malloc ((size_t) (types * sizeof (struct name_tier)));
if( ptr == NULL)
{
printf("\n\nError in parsetypes ");
return;
}
*ptrx = ptr;
cur = cur->xmlChildrenNode;
while (cur != NULL)
{
if ((!xmlStrcmp (cur->name, (const xmlChar *) "type")))
{
key = xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
temp_name = (char *) key;
//printf ("\nThe type : %s", temp_name);
strcpy (ptr[i].name, temp_name);
xmlFree (key);
}
if ((!xmlStrcmp (cur->name, (const xmlChar *) "tier")))
{
key = xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
temp_tier = atoi ((char *) key);
//printf (" Tier = %u\n", temp_tier);
ptr[i].tier = temp_tier;
xmlFree (key);
i++;
}
cur = cur->next;
}
printf ("\n\nPrinting from parsegroup:");
print_and_test_type (ptr, types);
return;
}
static void
parsedoc (char *docname, struct ohsm_xml_output *ptr)
{
xmlDocPtr doc;
xmlNodePtr cur;
unsigned int users, groups, types;
doc = xmlParseFile (docname);
if (doc == NULL)
{
fprintf (stderr, "Document not parsed successfully. \n");
xmlFreeDoc (doc);
return;
}
cur = xmlDocGetRootElement (doc);
if (cur == NULL)
{
fprintf (stderr, "empty document\n");
xmlFreeDoc (doc);
return;
}
if (xmlStrcmp (cur->name, (const xmlChar *) "create"))
{
fprintf (stderr,
"Invalid document Root element not equal to create...\n");
xmlFreeDoc (doc);
return;
}
cur = cur->xmlChildrenNode;
while (cur != NULL)
{
if ((!xmlStrcmp (cur->name, (xmlChar *) "info")))
{
printf ("\n %s \n\n", cur->name);
parseinfo (doc, cur, &users, &groups, &types);
ptr->users = users;
ptr->groups = groups;
ptr->types = types;
}
if ((!xmlStrcmp (cur->name, (const xmlChar *) "users")))
{
printf ("%s \n\n", cur->name);
parseuser (doc, cur, users, &(ptr->uid));
printf ("\n\nPrinting from parsedoc : ");
print_and_test_user (ptr->uid, ptr->users);
}
if ((!xmlStrcmp (cur->name, (const xmlChar *) "groups")))
{
printf ("%s \n\n", cur->name);
parsegroup (doc, cur, groups, &(ptr->gid));
printf ("\n\nPrinting from parsedoc : ");
print_and_test_group (ptr->gid, ptr->groups);
}
if ((!xmlStrcmp (cur->name, (xmlChar *) "types")))
{
printf ("%s\n\n", cur->name);
printf ("\n\nPrinting from parsedoc : ");
parsetypes (doc, cur, types, &(ptr->name));
}
cur = cur->next;
}
xmlFreeDoc (doc);
return;
}
struct ohsm_xml_output *
return_xml_policy_file (void)
{
char name[20] = "policy.xml";
struct ohsm_xml_output *xxx = NULL;
if( !strcmp(name,""))
{
printf ("\n\n\t\tEnter The Name of the Policy file : ");
scanf ("%s", name);
}
printf ("\n\n\t\t The Name of the Policy file is : %s",name);
xxx = (struct ohsm_xml_output *) malloc (sizeof (struct ohsm_xml_output));
if( xxx == NULL)
{
printf("\n\nError in return_xml_policy_file main of xml policy ");
return;
}
parsedoc (name, xxx);
print_and_test_user (xxx->uid, xxx->users);
print_and_test_group (xxx->gid, xxx->groups);
print_and_test_type (xxx->name, xxx->types);
return xxx;
}
Powered by
Google Project Hosting