My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 8 attachment: OHSM_struct.c (4.1 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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include<stdlib.h>

struct name_tier{
char name[10];
char tier[10];
};
typedef struct OHSM_struct {
struct name_tier user[5];
struct name_tier group[5];
struct name_tier directory[5];

} OHSM_struct;

struct OHSM_struct ohsm;

void
parseuser (xmlDocPtr doc, xmlNodePtr cur)
{
xmlChar *key;

int i= 0;
char *Char;

cur = cur->xmlChildrenNode;

while(cur != NULL)
{
if ((!xmlStrcmp(cur->name , (const xmlChar *)"user")))
{
key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
Char=(char*)key;

strcpy(ohsm.user[i].name,Char);

printf("USER = %s",ohsm.user[i].name);
xmlFree(key);

}
if ((!xmlStrcmp(cur->name , (const xmlChar *)"tier")))
{
key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
Char=(char*)key;

strcpy(ohsm.user[i].tier,Char);

printf("\tTier = %s\n",ohsm.user[i].tier);
xmlFree(key);
i=i+1;
}
cur=cur->next;
i++;
}

return;
}



struct OHSM_struct ohsm;

void
parsegroup (xmlDocPtr doc, xmlNodePtr cur)
{
xmlChar *key;

int i= 0;
char *Char;

cur = cur->xmlChildrenNode;

while(cur != NULL)
{
if ((!xmlStrcmp(cur->name , (const xmlChar *)"Group")))
{
key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
Char=(char*)key;

strcpy(ohsm.group[i].name,Char);

printf("Group = %s",ohsm.group[i].name);
xmlFree(key);

}
if ((!xmlStrcmp(cur->name , (const xmlChar *)"tier")))
{
key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
Char=(char*)key;

strcpy(ohsm.group[i].tier,Char);

printf("\tTier = %s\n",ohsm.group[i].tier);
xmlFree(key);
i=i+1;
}
cur=cur->next;
i++;
}

return;
}



struct OHSM_struct ohsm;

void
parsedirectory (xmlDocPtr doc, xmlNodePtr cur)
{
xmlChar *key;

int i= 0;
char *Char;

cur = cur->xmlChildrenNode;

while(cur != NULL)
{
if ((!xmlStrcmp(cur->name , (const xmlChar *)"Directory")))
{
key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
Char=(char*)key;

strcpy(ohsm.directory[i].name,Char);

printf("DIRECTORY = %s",ohsm.directory[i].name);
xmlFree(key);

}
if ((!xmlStrcmp(cur->name , (const xmlChar *)"tier")))
{
key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
Char=(char*)key;

strcpy(ohsm.directory[i].tier,Char);

printf("\tTier = %s\n",ohsm.directory[i].tier);
xmlFree(key);
i=i+1;
}
cur=cur->next;
i++;
}

return;
}



static void parsedoc(char *docname)
{
xmlDocPtr doc;
xmlNodePtr cur;
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, (const xmlChar *)"User"))){
printf("%s \n\n",cur->name);
parseuser(doc, cur);
}

if ((!xmlStrcmp(cur->name, (const xmlChar *)"group"))){
printf("%s \n\n",cur->name);
parsegroup(doc, cur);
}

if ((!xmlStrcmp(cur->name, (const xmlChar *)"directory"))){
printf("%s \n\n",cur->name);
parsedirectory(doc, cur);
}


cur = cur->next;
}

xmlFreeDoc(doc);
return;
}


int main(int argc,char **argv)
{

char *docname;
if (argc <= 1)
{
printf("Document name....");
return(0);
}

docname = argv[1];
parsedoc(docname);

return 0;
}
Powered by Google Project Hosting