Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

259 lines
5.9 KiB

  1. using System;
  2. namespace xmlXformer
  3. {
  4. using System.Xml;
  5. using System.Collections;
  6. using System.IO;
  7. class Record : IComparable
  8. {
  9. public int _id;
  10. public string _name;
  11. public string _type;
  12. public string _userType;
  13. public string _attr;
  14. public string _flagsEx;
  15. public Record()
  16. {
  17. _id = 0;
  18. }
  19. public int CompareTo(object a)
  20. {
  21. Record t = (Record)a;
  22. return this._id - t._id;
  23. }
  24. public string AttributeString()
  25. {
  26. if (_attr == null)
  27. {
  28. return "METADATA_NO_ATTRIBUTES";
  29. }
  30. else
  31. {
  32. char[] delim = { '|' };
  33. char[] whitespace = { ' ' };
  34. string[] subAttr = _attr.Split(delim);
  35. string temp = "METADATA_";
  36. for (int i = 0; i < subAttr.Length; i++)
  37. {
  38. if (i > 0)
  39. {
  40. temp = temp + " | METADATA_";
  41. }
  42. temp = temp + subAttr[i].Trim(whitespace);
  43. }
  44. return temp;
  45. }
  46. }
  47. public string ResourceID()
  48. {
  49. if (isHidden())
  50. {
  51. return "0 /* " + _name + " */";
  52. }
  53. else
  54. {
  55. string temp = "IDS_" + _name;
  56. return temp;
  57. }
  58. }
  59. public string MetadataType()
  60. {
  61. string temp;
  62. if (_type == "NTACL" || _type == "IPSECLIST")
  63. _type = "BINARY";
  64. else if (_type == "BOOL")
  65. _type = "DWORD";
  66. else if (_type == "MIMEMAP")
  67. _type = "MULTISZ";
  68. temp = _type + "_METADATA";
  69. return temp;
  70. }
  71. public bool isHidden()
  72. {
  73. return _flagsEx == "HIDDEN";
  74. }
  75. }
  76. /// <summary>
  77. /// Summary description for XFormer.
  78. /// </summary>
  79. class XFormer
  80. {
  81. const int cutoff_id = 10000;
  82. static void Main(string[] args)
  83. {
  84. bool found = false;
  85. bool in_prop = false;
  86. string fileName;
  87. int last_id = cutoff_id;
  88. if (args.Length == 0)
  89. {
  90. Console.WriteLine("Usage:\r\nschemagen <path to IISMeta.xml> <biggest meta id, default = 10000>");
  91. return;
  92. }
  93. fileName = args[0];
  94. if (args.Length > 1)
  95. {
  96. last_id = int.Parse(args[1]);
  97. }
  98. XmlTextReader rdr = new XmlTextReader(fileName);
  99. ArrayList list = new ArrayList();
  100. while (rdr.Read())
  101. {
  102. if (rdr.NodeType != XmlNodeType.Element)
  103. continue;
  104. if (rdr.Name == "Collection" && rdr.HasAttributes)
  105. {
  106. if (!found)
  107. {
  108. for (int i = 0; i < rdr.AttributeCount; i++)
  109. {
  110. rdr.MoveToAttribute(i);
  111. if (rdr.Name == "InternalName" && rdr.Value == "IIsConfigObject")
  112. {
  113. found = true;
  114. break;
  115. }
  116. }
  117. rdr.MoveToElement();
  118. }
  119. else if (in_prop)
  120. {
  121. break;
  122. }
  123. }
  124. else if (rdr.Name == "Property")
  125. {
  126. if (found)
  127. {
  128. Record rec = new Record();
  129. for (int i = 0; i < rdr.AttributeCount; i++)
  130. {
  131. rdr.MoveToAttribute(i);
  132. if (rdr.Name == "InternalName")
  133. {
  134. rec._name = rdr.Value;
  135. }
  136. else if (rdr.Name == "ID")
  137. {
  138. rec._id = int.Parse(rdr.Value);
  139. }
  140. else if (rdr.Name == "Type")
  141. {
  142. rec._type = rdr.Value;
  143. }
  144. else if (rdr.Name == "UserType")
  145. {
  146. rec._userType = rdr.Value;
  147. }
  148. else if (rdr.Name == "Attributes")
  149. {
  150. rec._attr = rdr.Value;
  151. }
  152. else if (rdr.Name == "MetaFlagsEx")
  153. {
  154. rec._flagsEx = rdr.Value;
  155. }
  156. }
  157. rdr.MoveToElement();
  158. if (rec._id != 0)
  159. {
  160. list.Add(rec);
  161. }
  162. }
  163. }
  164. }
  165. if (list.Count > 0)
  166. {
  167. FileInfo f1 = new FileInfo("mbschema.cpp");
  168. StreamWriter mdkeys = f1.CreateText();
  169. FileInfo f2 = new FileInfo("mbschema.rc");
  170. StreamWriter rc = f2.CreateText();
  171. FileInfo f3 = new FileInfo("mbschema.h");
  172. StreamWriter res = f3.CreateText();
  173. int res_base = 60000;
  174. mdkeys.WriteLine("//");
  175. mdkeys.WriteLine("// This is computer generated code");
  176. mdkeys.WriteLine("// please don't edit it manually.");
  177. mdkeys.WriteLine("//");
  178. mdkeys.WriteLine("#include \"stdafx.h\"");
  179. mdkeys.WriteLine("#include \"common.h\"");
  180. mdkeys.WriteLine("#include <iiscnfg.h>");
  181. mdkeys.WriteLine("#include \"mdkeys.h\"");
  182. mdkeys.WriteLine("#include \"mbschema.h\"");
  183. mdkeys.WriteLine("");
  184. mdkeys.WriteLine("const CMetaKey::MDFIELDDEF CMetaKey::s_rgMetaTable[] =");
  185. mdkeys.WriteLine("{");
  186. rc.WriteLine("//");
  187. rc.WriteLine("// This is computer generated code");
  188. rc.WriteLine("// please don't edit it manually.");
  189. rc.WriteLine("//");
  190. rc.WriteLine("#include \"mbschema.h\"");
  191. rc.WriteLine("");
  192. rc.WriteLine("STRINGTABLE DISCARDABLE");
  193. rc.WriteLine("BEGIN");
  194. res.WriteLine("//");
  195. res.WriteLine("// This is computer generated code");
  196. res.WriteLine("// please don't edit it manually.");
  197. res.WriteLine("//");
  198. res.WriteLine("#ifndef IDS_MD_BEGIN_TABLE");
  199. res.WriteLine("#define IDS_MD_BEGIN_TABLE\t" + res_base);
  200. res.WriteLine("#endif\n");
  201. list.Sort();
  202. int prev_id = 0;
  203. for (int i = 0; i < list.Count; i++)
  204. {
  205. Record rec = (Record)list[i];
  206. if (rec._id > last_id)
  207. {
  208. break;
  209. }
  210. if (rec._id == prev_id)
  211. {
  212. continue;
  213. }
  214. mdkeys.Write("\t{ ");
  215. mdkeys.Write("{0}, {1}, {2}, {3}, {4}",
  216. rec._id,
  217. rec.AttributeString(),
  218. rec._userType,
  219. rec.MetadataType(),
  220. rec.ResourceID());
  221. mdkeys.WriteLine(" },");
  222. if (!rec.isHidden())
  223. {
  224. rc.WriteLine("\t{0}\t{1}", rec.ResourceID().PadRight(40, ' '), '"' + rec._name + '"');
  225. res.Write("#define " + rec.ResourceID().PadRight(40, ' '));
  226. res.WriteLine("(IDS_MD_BEGIN_TABLE+{0})", i);
  227. }
  228. prev_id = rec._id;
  229. }
  230. mdkeys.WriteLine("};");
  231. mdkeys.WriteLine("");
  232. mdkeys.WriteLine("const int CMetaKey::s_MetaTableSize = sizeof(CMetaKey::s_rgMetaTable) / sizeof(CMetaKey::s_rgMetaTable[0]);");
  233. mdkeys.WriteLine("");
  234. rc.WriteLine("END");
  235. mdkeys.Close();
  236. rc.Close();
  237. res.Close();
  238. }
  239. }
  240. }
  241. }