1 #include "ltr_xsl.h"
2
3 typedef struct group_entry_ {
4 XMLSTRING *actions;
5 int action_count;
6 } group_entry;
7
8 typedef struct library_entry_ {
9 XMLDICT *groups;
10 } library_entry;
11
XSLTDefineGroupRights(XSLTGLOBALDATA * data,char * library,char * group,char ** actions,int action_count)12 void XSLTDefineGroupRights(XSLTGLOBALDATA *data, char *library, char *group, char **actions, int action_count)
13 {
14 memory_allocator_set_current(data->allocator);
15
16 XMLSTRING library_string = xmls_new_string_literal(library);
17 library_entry *rights = (library_entry *) dict_find(data->group_rights, library_string);
18 if (rights == NULL)
19 {
20 rights = memory_allocator_new(sizeof(library_entry));
21 rights->groups = dict_new(50);
22 dict_add(data->group_rights, library_string, rights);
23 }
24
25 group_entry *entry = memory_allocator_new(sizeof(group_entry));
26 entry->actions = memory_allocator_new(action_count * sizeof(XMLSTRING));
27 entry->action_count = action_count;
28 for(int i = 0; i < action_count; i++)
29 {
30 entry->actions[i] = xmls_new_string_literal(actions[i]);
31 }
32
33 dict_add(rights->groups, xmls_new_string_literal(group), entry);
34 }
35
XSLTSetUserContext(TRANSFORM_CONTEXT * ctx,char * library,char ** groups,int group_count)36 void XSLTSetUserContext(TRANSFORM_CONTEXT *ctx, char *library, char **groups, int group_count)
37 {
38 memory_allocator_set_current(ctx->allocator);
39
40 dict_free(ctx->user_rights);
41 ctx->user_rights = dict_new(50);
42
43 XMLSTRING library_string = xmls_new_string_literal(library);
44 library_entry *rights = (library_entry *) dict_find(ctx->gctx->group_rights, library_string);
45 if (rights == NULL)
46 {
47 error("XSLTSetUserContext:: unknown library: %s", library);
48 return;
49 }
50
51 for (int i = 0; i < group_count; i++)
52 {
53 XMLSTRING group_string = xmls_new_string_literal(groups[i]);
54 group_entry *entry = (group_entry *) dict_find(rights->groups, group_string);
55 if (entry == NULL)
56 {
57 error("XSLTSetUserContext:: unknown group: %s", group_string->s);
58 continue;
59 }
60
61 for (size_t j = 0; j < entry->action_count; j++)
62 {
63 XMLSTRING action = entry->actions[j];
64 dict_add(ctx->user_rights, action, action);
65 }
66 }
67 }
68