3 # Unix SMB/CIFS implementation.
5 # WSP property definitions
7 # Copyright (C) Noel Power
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 from __future__
import unicode_literals
23 import sys
, os
.path
, io
, string
27 # map of guid to propinfo
30 # list of property id to name maps
31 GuidToPropMapLocation
= {}
39 self
.inInvertedIndex
= "FALSE"
40 self
.isColumn
= "TRUE"
41 self
.canColumnBeIndexed
= "TRUE"
44 self
.isVectorProp
= "FALSE"
46 self
.hasExtraInfo
= False
48 def parseCSV(fileContents
, hasExtraInfo
):
51 for line
in fileContents
:
52 toParse
= line
.strip()
58 parsed
= toParse
.split(',',9)
60 newProp
.hasExtraInfo
= hasExtraInfo
61 newProp
.propName
= parsed
[0]
62 guid
= parsed
[1].upper()
63 newProp
.propId
= int(parsed
[2])
66 newProp
.inInvertedIndex
= parsed
[3]
68 newProp
.isColumn
= parsed
[4]
70 newProp
.canColumnBeIndexed
= parsed
[5]
72 newProp
.dataType
= parsed
[6]
74 newProp
.maxSize
= parsed
[7]
76 newProp
.isVectorProp
= parsed
[8]
78 newProp
.description
= parsed
[9]
80 if not guid
in GuidToPropMap
:
81 GuidToPropMap
[guid
] = []
83 GuidToPropMap
[guid
].append(newProp
)
85 props_read
= props_read
+ 1
88 noBrackets
= guid
.split('{')[1].split('}')[0]
89 parts
= noBrackets
.split('-')
90 result
= "{0x" + parts
[0] + ", 0x" + parts
[1] + ", 0x" + parts
[2]
91 result
= result
+ ", {0x" + parts
[3][0:2] + ", 0x" + parts
[3][2:4] + "}, "
92 result
= result
+ "{0x" + parts
[4][0:2] + ", 0x" + parts
[4][2:4] + ", "
93 result
= result
+ "0x" + parts
[4][4:6] + ", 0x" + parts
[4][6:8] + ", "
94 result
= result
+ "0x" + parts
[4][8:10] + ", 0x" + parts
[4][10:12] + "}"
98 def getBoolString(boolString
):
99 if boolString
== "TRUE":
106 if prop
.dataType
== "GUID":
108 if prop
.dataType
== "String":
110 if prop
.dataType
== "BString":
112 elif prop
.dataType
== "Double":
114 elif prop
.dataType
== "Buffer":
115 result
= "VT_BLOB_OBJECT"
116 elif prop
.dataType
== "Byte":
118 elif prop
.dataType
== "UInt64":
120 elif prop
.dataType
== "Int64":
122 elif prop
.dataType
== "UInt32":
124 elif prop
.dataType
== "Int32":
126 elif prop
.dataType
== "UInt16":
128 elif prop
.dataType
== "Int16":
130 elif prop
.dataType
== "DateTime":
131 result
= "VT_FILETIME"
132 elif prop
.dataType
== "Boolean":
134 if prop
.isVectorProp
== "TRUE":
135 result
= result
+ " | VT_VECTOR"
138 def generateSourceCode(propMap
, outputFile
):
139 source
= "#include \"replace.h\"\n"
140 source
= source
+ "#include \"bin/default/librpc/gen_ndr/ndr_wsp.h\"\n"
141 source
= source
+ "#include \"librpc/wsp/wsp_util.h\"\n"
143 for guid
in propMap
.keys():
144 varName
= "guid_properties_%d"%count
145 GuidToPropMapLocation
[guid
] = varName
148 source
= source
+ "static const struct full_propset_info %s[] = {\n"%varName
149 for props
in propMap
[guid
]:
151 if props
.hasExtraInfo
:
153 source
= source
+ "\t{0x%x,\"%s\",%s, %s, %s, %s, %s, %s},\n"%(props
.propId
, props
.propName
, getVtype(props
), extraInfo
, getBoolString(props
.inInvertedIndex
),getBoolString(props
.isColumn
), getBoolString(props
.canColumnBeIndexed
), props
.maxSize
)
155 source
= source
+ "\t{0,NULL,0,false,false,false,false,0}\n};\n\n"
157 source
= source
+ "\n"
159 source
= source
+ "const struct full_guid_propset full_propertyset[] = {\n";
160 for guid
in propMap
.keys():
161 guidBytes
= parseGuid(guid
)
162 varName
= GuidToPropMapLocation
[guid
]
163 source
= source
+ "\t{" + guidBytes
+ "," + varName
+ "},\n"
165 source
= source
+ "\t{{0, 0, 0, {0, 0}, {0, 0, 0, 0, 0, 0}}," + "NULL" + "},\n"
166 source
= source
+ "};\n"
167 outputFile
.write(source
)
172 extraPropsLimitedInfo
= None
173 if len(sys
.argv
) > 3:
174 inputFile
= sys
.argv
[1]
175 outputFile
= sys
.argv
[2]
176 # this file contains extra properties (that don't have the full
177 # set of property information
178 if len(sys
.argv
) > 3:
179 extraPropsLimitedInfo
= sys
.argv
[3]
181 print ("usage: %s property-csv outfile optionalLimitedInfoProps"%(sys
.argv
[0]))
183 fileContents
= io
.open(inputFile
,"rt", encoding
='utf8')
184 outputSource
= io
.open(outputFile
,"wt", encoding
='utf8')
185 parseCSV(fileContents
, True)
188 if extraPropsLimitedInfo
!= None:
189 fileContents
= io
.open(extraPropsLimitedInfo
,"rt", encoding
='utf8')
190 parseCSV(fileContents
, False)
193 generateSourceCode(GuidToPropMap
, outputSource
)
196 print ("ok! parsed %d properties and %d propsets(guid)"%(props_read
,len(GuidToPropMap
.keys())))
199 if __name__
== '__main__':