librpc/rpc: Add windows propertyset info and associated accessor and helper api.
[Samba.git] / librpc / wsp / wsp_util.c
blob33d1056ef69dda7ad4f634f81c1bd852856620eb
1 /*
2 * Unix SMB/CIFS implementation.
4 * Window Search Service
6 * Copyright (c) Noel Power
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "librpc/wsp/wsp_util.h"
23 #include "librpc/gen_ndr/wsp.h"
24 #include "ndr.h"
25 const struct full_propset_info *get_propset_info_with_guid(
26 const char *prop_name,
27 struct GUID *propset_guid)
29 size_t i;
30 const struct full_guid_propset *guid_propset = NULL;
31 const struct full_propset_info *result = NULL;
32 for (i = 0; full_propertyset[i].prop_info != NULL; i++) {
33 const struct full_propset_info *item = NULL;
34 guid_propset = &full_propertyset[i];
35 item = guid_propset->prop_info;
36 while (item->id) {
37 if (strequal(prop_name, item->name)) {
38 *propset_guid = guid_propset->guid;
39 result = item;
40 break;
42 item++;
44 if (result) {
45 break;
48 return result;
51 const struct full_propset_info *get_prop_info(const char *prop_name)
53 const struct full_propset_info *result = NULL;
54 struct GUID guid;
55 result = get_propset_info_with_guid(prop_name, &guid);
56 return result;
59 char *prop_from_fullprop(TALLOC_CTX *ctx, struct wsp_cfullpropspec *fullprop)
61 size_t i;
62 char *result = NULL;
63 const struct full_propset_info *item = NULL;
64 bool search_by_id = (fullprop->ulkind == PRSPEC_PROPID);
66 for (i = 0; full_propertyset[i].prop_info != NULL; i++) {
67 /* find propset */
68 if (GUID_equal(&fullprop->guidpropset,
69 &full_propertyset[i].guid)) {
70 item = full_propertyset[i].prop_info;
71 break;
74 if (item) {
75 while (item->id) {
76 if (search_by_id) {
77 if( fullprop->name_or_id.prspec == item->id) {
78 result = talloc_strdup(ctx, item->name);
79 break;
81 } else if (strcmp(item->name,
82 fullprop->name_or_id.propname.vstring)
83 == 0) {
84 result = talloc_strdup(ctx, item->name);
85 break;
87 item++;
91 if (!result) {
92 result = GUID_string(ctx, &fullprop->guidpropset);
94 if (search_by_id) {
95 result = talloc_asprintf(result, "%s/%d", result,
96 fullprop->name_or_id.prspec);
97 } else {
98 result = talloc_asprintf(result, "%s/%s", result,
99 fullprop->name_or_id.propname.vstring);
102 return result;
105 struct wsp_cfullpropspec *get_full_prop(struct wsp_crestriction *restriction)
107 struct wsp_cfullpropspec *result;
108 switch (restriction->ultype) {
109 case RTPROPERTY:
110 result = &restriction->restriction.cpropertyrestriction.property;
111 break;
112 case RTCONTENT:
113 result = &restriction->restriction.ccontentrestriction.property;
114 break;
115 case RTNATLANGUAGE:
116 result = &restriction->restriction.cnatlanguagerestriction.property;
117 break;
118 default:
119 result = NULL;
120 break;
122 return result;