Opera 12.15 Source Code
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.

aitparser.cpp 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4; -*-
  2. *
  3. * Copyright (C) 1995-2011 Opera Software ASA. All rights reserved.
  4. *
  5. * This file is part of the Opera web browser.
  6. * It may not be distributed under any circumstances.
  7. */
  8. #include "core/pch.h"
  9. #ifdef XML_AIT_SUPPORT
  10. #include "modules/dochand/aitparser.h"
  11. #include "modules/hardcore/base/baseincludes.h"
  12. #include "modules/xmlutils/xmlparser.h"
  13. #include "modules/xmlutils/xmlfragment.h"
  14. //static
  15. OP_STATUS AITParser::Parse(URL &url, AITData &ait_data)
  16. {
  17. XMLFragment fragment;
  18. int retval = fragment.Parse(url);
  19. if (OpStatus::IsError(retval))
  20. return retval;
  21. fragment.EnterAnyElement();
  22. // Find all Application elemets that are present and collect their
  23. // information in one large list.
  24. do
  25. {
  26. while (fragment.HasCurrentElement() && !uni_str_eq(fragment.GetElementName().GetLocalPart(), "Application"))
  27. {
  28. if (!fragment.HasMoreElements())
  29. fragment.LeaveElement();
  30. fragment.EnterAnyElement();
  31. }
  32. // Found an application.
  33. if (fragment.HasCurrentElement() && uni_str_eq(fragment.GetElementName().GetLocalPart(), "Application"))
  34. {
  35. OP_STATUS status;
  36. AITApplication *application = OP_NEW(AITApplication, ());
  37. RETURN_OOM_IF_NULL(application);
  38. status = ait_data.applications.Add(application);
  39. if (OpStatus::IsError(status))
  40. {
  41. OP_DELETE(application);
  42. return status;
  43. }
  44. TempBuffer buffer;
  45. // Parse the application data.
  46. do
  47. {
  48. if (!fragment.HasMoreElements())
  49. fragment.LeaveElement();
  50. fragment.EnterAnyElement();
  51. const uni_char *name = fragment.GetElementName().GetLocalPart();
  52. buffer.Clear();
  53. if (uni_str_eq(name, "appName"))
  54. {
  55. fragment.GetAllText(buffer);
  56. RETURN_IF_ERROR(application->name.Set(buffer.GetStorage()));
  57. buffer.Clear();
  58. fragment.LeaveElement();
  59. }
  60. else if (uni_str_eq(name, "applicationIdentifier"))
  61. {
  62. while (fragment.HasMoreElements())
  63. {
  64. if (fragment.EnterAnyElement())
  65. {
  66. fragment.GetAllText(buffer);
  67. const uni_char *tmp_name = fragment.GetElementName().GetLocalPart();
  68. if (uni_str_eq(tmp_name, "orgId"))
  69. application->org_id = uni_atoi(buffer.GetStorage());
  70. else if (uni_str_eq(tmp_name, "appId"))
  71. application->app_id = uni_atoi(buffer.GetStorage());
  72. buffer.Clear();
  73. fragment.LeaveElement();
  74. }
  75. }
  76. fragment.LeaveElement();
  77. }
  78. else if (uni_str_eq(name, "applicationDescriptor"))
  79. {
  80. while (fragment.HasMoreElements())
  81. {
  82. if (fragment.EnterAnyElement())
  83. {
  84. fragment.GetAllText(buffer);
  85. const uni_char *value = buffer.GetStorage();
  86. const uni_char *tmp_name = fragment.GetElementName().GetLocalPart();
  87. if (uni_str_eq(tmp_name, "controlCode") && value)
  88. {
  89. if (uni_str_eq(value, "AUTOSTART"))
  90. application->descriptor.control_code = AITApplicationDescriptor::CONTROL_CODE_AUTOSTART;
  91. else if (uni_str_eq(value, "PRESENT"))
  92. application->descriptor.control_code = AITApplicationDescriptor::CONTROL_CODE_PRESENT;
  93. else if (uni_str_eq(value, "KILL"))
  94. application->descriptor.control_code = AITApplicationDescriptor::CONTROL_CODE_KILL;
  95. else if (uni_str_eq(value, "DISABLED"))
  96. application->descriptor.control_code = AITApplicationDescriptor::CONTROL_CODE_DISABLED;
  97. }
  98. else if (uni_str_eq(tmp_name, "visibility") && value)
  99. {
  100. if (uni_str_eq(value, "NOT_VISIBLE_ALL"))
  101. application->descriptor.visibility = AITApplicationDescriptor::VISIBILITY_NOT_VISIBLE_ALL;
  102. else if (uni_str_eq(value, "NOT_VISIBLE_USERS"))
  103. application->descriptor.visibility = AITApplicationDescriptor::VISIBILITY_NOT_VISIBLE_USERS;
  104. else if (uni_str_eq(value, "VISIBLE_ALL"))
  105. application->descriptor.visibility = AITApplicationDescriptor::VISIBILITY_VISIBLE_ALL;
  106. }
  107. else if (uni_str_eq(tmp_name, "serviceBound") && value)
  108. {
  109. if (uni_str_eq(value, "false"))
  110. application->descriptor.service_bound = FALSE;
  111. else if (uni_str_eq(value, "true"))
  112. application->descriptor.service_bound = TRUE;
  113. }
  114. else if (uni_str_eq(tmp_name, "priority") && value)
  115. {
  116. application->descriptor.priority = static_cast<unsigned char>(uni_strtoul(value, NULL, 16, NULL));
  117. }
  118. else if (uni_str_eq(tmp_name, "mhpVersion"))
  119. {
  120. AITApplicationMhpVersion *mhp_version = OP_NEW(AITApplicationMhpVersion, ());
  121. RETURN_OOM_IF_NULL(mhp_version);
  122. status = application->descriptor.mhp_versions.Add(mhp_version);
  123. if (OpStatus::IsError(status))
  124. {
  125. OP_DELETE(mhp_version);
  126. return status;
  127. }
  128. TempBuffer buffer2;
  129. while (fragment.HasMoreElements())
  130. {
  131. fragment.EnterAnyElement();
  132. const uni_char *tag_name = fragment.GetElementName().GetLocalPart();
  133. if (uni_str_eq(tag_name, "profile"))
  134. {
  135. fragment.GetAllText(buffer2);
  136. mhp_version->profile = static_cast<unsigned short>(uni_atoi(buffer2.GetStorage()));
  137. }
  138. else if (uni_str_eq(tag_name, "versionMajor"))
  139. {
  140. fragment.GetAllText(buffer2);
  141. mhp_version->version_major = static_cast<unsigned char>(uni_atoi(buffer2.GetStorage()));
  142. }
  143. else if (uni_str_eq(tag_name, "versionMinor"))
  144. {
  145. fragment.GetAllText(buffer2);
  146. mhp_version->version_minor = static_cast<unsigned char>(uni_atoi(buffer2.GetStorage()));
  147. }
  148. else if (uni_str_eq(tag_name, "versionMicro"))
  149. {
  150. fragment.GetAllText(buffer2);
  151. mhp_version->version_micro = static_cast<unsigned char>(uni_atoi(buffer2.GetStorage()));
  152. }
  153. buffer2.Clear();
  154. fragment.LeaveElement();
  155. }
  156. }
  157. buffer.Clear();
  158. fragment.LeaveElement();
  159. }
  160. }
  161. fragment.LeaveElement();
  162. }
  163. else if (uni_str_eq(name, "applicationUsageDescriptor"))
  164. {
  165. while (fragment.HasMoreElements())
  166. {
  167. if (fragment.EnterAnyElement())
  168. {
  169. fragment.GetAllText(buffer);
  170. const uni_char *tmp_name = fragment.GetElementName().GetLocalPart();
  171. if (uni_str_eq(tmp_name, "ApplicationUsage"))
  172. {
  173. const uni_char *applicationUsage = buffer.GetStorage();
  174. if (applicationUsage && uni_str_eq(applicationUsage, "urn:dvb:mhp:2009:digitalText"))
  175. application->usage = 0x01;
  176. }
  177. buffer.Clear();
  178. fragment.LeaveElement();
  179. }
  180. }
  181. fragment.LeaveElement();
  182. }
  183. else if (uni_str_eq(name, "applicationTransport"))
  184. {
  185. AITApplicationTransport *transport = OP_NEW(AITApplicationTransport, ());
  186. RETURN_OOM_IF_NULL(transport);
  187. status = application->transports.Add(transport);
  188. if (OpStatus::IsError(status))
  189. {
  190. OP_DELETE(transport);
  191. return status;
  192. }
  193. const uni_char *transport_type = NULL;
  194. XMLCompleteName attr_name;
  195. const uni_char *attr_value;
  196. while(fragment.GetNextAttribute(attr_name, attr_value))
  197. {
  198. if (uni_str_eq(attr_name.GetLocalPart(), "type"))
  199. {
  200. transport_type = attr_value;
  201. break;
  202. }
  203. }
  204. if (!transport_type)
  205. transport_type = UNI_L("");
  206. if (uni_str_eq(transport_type, "mhp:HTTPTransportType"))
  207. {
  208. while (fragment.HasMoreElements())
  209. {
  210. fragment.EnterAnyElement();
  211. const uni_char *tag_name = fragment.GetElementName().GetLocalPart();
  212. if (uni_str_eq(tag_name, "URLBase"))
  213. {
  214. fragment.GetAllText(buffer);
  215. RETURN_IF_ERROR(transport->base_url.Set(buffer.GetStorage()));
  216. buffer.Clear();
  217. }
  218. fragment.LeaveElement();
  219. }
  220. transport->protocol = 0x0003;
  221. }
  222. else if (uni_str_eq(transport_type, "mhp:OCTransportType"))
  223. {
  224. while (fragment.HasMoreElements())
  225. {
  226. fragment.EnterAnyElement();
  227. const uni_char *tag_name = fragment.GetElementName().GetLocalPart();
  228. if (uni_str_eq(tag_name, "DVBTriplet"))
  229. {
  230. const uni_char *original_network_id = fragment.GetAttribute(UNI_L("OrigNetId"));
  231. const uni_char *transport_stream_id = fragment.GetAttribute(UNI_L("TSId"));
  232. const uni_char *service_id = fragment.GetAttribute(UNI_L("ServiceId"));
  233. transport->original_network_id = (original_network_id ? static_cast<unsigned short>(uni_strtoul(original_network_id, NULL, 10, NULL)) : 0);
  234. transport->transport_stream_id = (transport_stream_id ? static_cast<unsigned short>(uni_strtoul(transport_stream_id, NULL, 10, NULL)) : 0);
  235. transport->service_id = (service_id ? static_cast<unsigned short>(uni_strtoul(service_id, NULL, 10, NULL)) : 0);
  236. transport->remote = TRUE;
  237. }
  238. else if (uni_str_eq(tag_name, "ComponentTag"))
  239. {
  240. fragment.GetAllText(buffer);
  241. transport->component_tag = static_cast<unsigned char>(uni_strtoul(buffer.GetStorage(), NULL, 16, NULL));
  242. buffer.Clear();
  243. }
  244. fragment.LeaveElement();
  245. }
  246. transport->protocol = 0x0001;
  247. }
  248. fragment.LeaveElement();
  249. }
  250. else if (uni_str_eq(name, "applicationBoundary"))
  251. {
  252. while (fragment.HasMoreElements())
  253. {
  254. fragment.EnterAnyElement();
  255. const uni_char *tag_name = fragment.GetElementName().GetLocalPart();
  256. if (uni_str_eq(tag_name, "BoundaryExtension"))
  257. {
  258. fragment.GetAllText(buffer);
  259. const uni_char *value = buffer.GetStorage();
  260. if (value)
  261. {
  262. OpString *boundary = OP_NEW(OpString, ());
  263. RETURN_OOM_IF_NULL(boundary);
  264. status = application->boundaries.Add(boundary);
  265. if (OpStatus::IsError(status))
  266. {
  267. OP_DELETE(boundary);
  268. return status;
  269. }
  270. RETURN_IF_ERROR(boundary->Set(value));
  271. }
  272. buffer.Clear();
  273. fragment.LeaveElement();
  274. }
  275. }
  276. fragment.LeaveElement();
  277. }
  278. else if (uni_str_eq(name, "applicationLocation"))
  279. {
  280. fragment.GetAllText(buffer);
  281. RETURN_IF_ERROR(application->location.Set(buffer.GetStorage()));
  282. buffer.Clear();
  283. fragment.LeaveElement();
  284. }
  285. } while (uni_str_eq(fragment.GetElementName().GetLocalPart(), "Application"));
  286. fragment.LeaveElement();
  287. }
  288. // Continue parsing until we have no more elements to enter
  289. // and are at the root of the fragment.
  290. } while (fragment.HasMoreElements() || fragment.HasCurrentElement());
  291. return OpStatus::OK;
  292. }
  293. #endif // XML_AIT_SUPPORT