ctdb-scripts: Move connection tracking to 10.interface
[samba4-gss.git] / source4 / scripting / bin / gen_wsp_props.py
blobe33169ee50d2b636f646ace648b36259001cb65f
1 #!/usr/bin/env python
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
25 # parsed error data
27 # map of guid to propinfo
28 GuidToPropMap = {}
30 # list of property id to name maps
31 GuidToPropMapLocation = {}
33 props_read = 0
35 class PropInfo:
36 def __init__(self):
37 self.propName = ""
38 self.propId = 0
39 self.inInvertedIndex = "FALSE"
40 self.isColumn = "TRUE"
41 self.canColumnBeIndexed = "TRUE"
42 self.dataType = None
43 self.maxSize = 0
44 self.isVectorProp = "FALSE"
45 self.description = ""
46 self.hasExtraInfo = False
48 def parseCSV(fileContents, hasExtraInfo):
49 global props_read
50 lines = 0
51 for line in fileContents:
52 toParse = line.strip()
53 lines = lines + 1
55 if toParse[0] == '#':
56 continue
58 parsed = toParse.split(',',9)
59 newProp = PropInfo()
60 newProp.hasExtraInfo = hasExtraInfo
61 newProp.propName = parsed[0]
62 guid = parsed[1].upper()
63 newProp.propId = int(parsed[2])
65 if len(parsed[3]):
66 newProp.inInvertedIndex = parsed[3]
67 if len(parsed[4]):
68 newProp.isColumn = parsed[4]
69 if len(parsed[5]):
70 newProp.canColumnBeIndexed = parsed[5]
71 if len(parsed[6]):
72 newProp.dataType = parsed[6]
73 if len(parsed[7]):
74 newProp.maxSize = parsed[7]
75 if len(parsed[8]):
76 newProp.isVectorProp = parsed[8]
77 if len(parsed[9]):
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
87 def parseGuid(guid):
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] + "}"
95 result = result + "}"
96 return result;
98 def getBoolString(boolString):
99 if boolString == "TRUE":
100 return "true"
101 else:
102 return "false"
104 def getVtype(prop):
105 result = "Unknown"
106 if prop.dataType == "GUID":
107 result = "VT_CLSID"
108 if prop.dataType == "String":
109 result = "VT_LPWSTR"
110 if prop.dataType == "BString":
111 result = "VT_BSTR"
112 elif prop.dataType == "Double":
113 result = "VT_R8"
114 elif prop.dataType == "Buffer":
115 result = "VT_BLOB_OBJECT"
116 elif prop.dataType == "Byte":
117 result = "VT_UI1"
118 elif prop.dataType == "UInt64":
119 result = "VT_UI8"
120 elif prop.dataType == "Int64":
121 result = "VT_I8"
122 elif prop.dataType == "UInt32":
123 result = "VT_UI4"
124 elif prop.dataType == "Int32":
125 result = "VT_I4"
126 elif prop.dataType == "UInt16":
127 result = "VT_UI2"
128 elif prop.dataType == "Int16":
129 result = "VT_I2"
130 elif prop.dataType == "DateTime":
131 result = "VT_FILETIME"
132 elif prop.dataType == "Boolean":
133 result = "VT_BOOL"
134 if prop.isVectorProp == "TRUE":
135 result = result + " | VT_VECTOR"
136 return result
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"
142 count = 0
143 for guid in propMap.keys():
144 varName = "guid_properties_%d"%count
145 GuidToPropMapLocation[guid] = varName
146 count = count + 1
148 source = source + "static const struct full_propset_info %s[] = {\n"%varName
149 for props in propMap[guid]:
150 extraInfo = "false"
151 if props.hasExtraInfo:
152 extraInfo = "true"
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)
169 def main ():
170 inputFile = None
171 outputSrcFile = None
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]
180 else:
181 print ("usage: %s property-csv outfile optionalLimitedInfoProps"%(sys.argv[0]))
182 sys.exit(0)
183 fileContents = io.open(inputFile,"rt", encoding='utf8')
184 outputSource = io.open(outputFile,"wt", encoding='utf8')
185 parseCSV(fileContents, True)
186 fileContents.close()
188 if extraPropsLimitedInfo != None:
189 fileContents = io.open(extraPropsLimitedInfo,"rt", encoding='utf8')
190 parseCSV(fileContents, False)
191 fileContents.close()
193 generateSourceCode(GuidToPropMap, outputSource)
195 outputSource.close()
196 print ("ok! parsed %d properties and %d propsets(guid)"%(props_read,len(GuidToPropMap.keys())))
199 if __name__ == '__main__':
201 main()