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.

240 lines
6.3KB

  1. /*
  2. Copyright (C) 2006 Etienne Tasse etasse@yahoo.com
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
  14. */
  15. #include "defs.h"
  16. #include "xmlgeneric.h"
  17. #include <QtCore/QXmlStreamAttributes>
  18. #include <stdio.h>
  19. /* argument storage */
  20. static char* aicicon =0;
  21. static char* aioicon =0;
  22. static char* ahcicon =0;
  23. static char* ahoicon =0;
  24. static char* snmac =0;
  25. static
  26. arglist_t wfff_xml_args[] = {
  27. {
  28. "aicicon", &aicicon, "Infrastructure closed icon name",
  29. "Red Square", ARGTYPE_STRING
  30. },
  31. {
  32. "aioicon", &aioicon, "Infrastructure open icon name",
  33. "Green Square", ARGTYPE_STRING
  34. },
  35. {
  36. "ahcicon", &ahcicon, "Ad-hoc closed icon name",
  37. "Red Diamond", ARGTYPE_STRING
  38. },
  39. {
  40. "ahoicon", &ahoicon, "Ad-hoc open icon name",
  41. "Green Diamond", ARGTYPE_STRING
  42. },
  43. {"snmac", &snmac, "Shortname is MAC address", NULL, ARGTYPE_BOOL },
  44. {0, 0, 0, 0, 0}
  45. };
  46. #define xfreez(p) { if (p) xfree(p); p=0; }
  47. #define MYNAME "wfff_xml"
  48. static xg_callback wfff_s, wfff_e;
  49. static xg_callback wfff_wep, wfff_mac, wfff_type;
  50. static xg_callback wfff_ssid, wfff_chan;
  51. static xg_callback wfff_mnrssi, wfff_mxrssi;
  52. static xg_callback wfff_first, wfff_last;
  53. static xg_callback wfff_hdop, wfff_lat, wfff_lon;
  54. static
  55. xg_tag_mapping loc_map[] = {
  56. { wfff_s, cb_start, "/DocumentElement/AP" },
  57. { wfff_e, cb_end, "/DocumentElement/AP" },
  58. { wfff_wep, cb_cdata, "/DocumentElement/AP/WEP" },
  59. { wfff_mac, cb_cdata, "/DocumentElement/AP/MAC" },
  60. { wfff_ssid, cb_cdata, "/DocumentElement/AP/SSID" },
  61. { wfff_type, cb_cdata, "/DocumentElement/AP/Type" },
  62. { wfff_mnrssi, cb_cdata, "/DocumentElement/AP/MinRSSI" },
  63. { wfff_mxrssi, cb_cdata, "/DocumentElement/AP/MaxRSSI" },
  64. { wfff_chan, cb_cdata, "/DocumentElement/AP/Channel" },
  65. { wfff_first, cb_cdata, "/DocumentElement/AP/FirstSeen" },
  66. { wfff_last, cb_cdata, "/DocumentElement/AP/LastSeen" },
  67. { wfff_hdop, cb_cdata, "/DocumentElement/AP/HDOP" },
  68. { wfff_lat, cb_cdata, "/DocumentElement/AP/Lat" },
  69. { wfff_lon, cb_cdata, "/DocumentElement/AP/Lon" },
  70. { 0,(xg_cb_type)0,0 }
  71. };
  72. /* work variables for wfff_xxx */
  73. static QString ap_mac;
  74. static QString ap_ssid;
  75. static QString ap_type;
  76. static QString ap_wep;
  77. static int ap_chan =0;
  78. static time_t ap_first =0;
  79. static QString ap_last;
  80. static float ap_mnrssi =0.0;
  81. static float ap_mxrssi =0.0;
  82. static float ap_hdop =0.0;
  83. static double ap_lat =0.0;
  84. static double ap_lon =0.0;
  85. /* Start of AP block */
  86. void wfff_s(xg_string, const QXmlStreamAttributes*)
  87. {
  88. ap_mnrssi=0.0;
  89. ap_mxrssi=0.0;
  90. ap_chan=0;
  91. ap_hdop=0.0;
  92. ap_first=0;
  93. ap_last=QString();
  94. ap_lat=0.0;
  95. ap_lon=0.0;
  96. }
  97. void wfff_mac(const QString& args, const QXmlStreamAttributes*) {
  98. ap_mac = args;
  99. }
  100. void wfff_ssid(const QString& args, const QXmlStreamAttributes*) {
  101. ap_ssid = args;
  102. }
  103. void wfff_type(const QString& args, const QXmlStreamAttributes*) {
  104. ap_type = args;
  105. }
  106. void wfff_mnrssi(const QString& args, const QXmlStreamAttributes*) {
  107. ap_mnrssi = args.toDouble();
  108. }
  109. void wfff_mxrssi(const QString& args, const QXmlStreamAttributes*) {
  110. ap_mxrssi = args.toDouble();
  111. }
  112. void wfff_chan(const QString& args, const QXmlStreamAttributes*) {
  113. ap_chan = args.toInt();
  114. }
  115. void wfff_first(const QString& args, const QXmlStreamAttributes*) {
  116. ap_first = xml_parse_time(args).toTime_t();
  117. }
  118. void wfff_last(const QString& args, const QXmlStreamAttributes*) {
  119. ap_last = args;
  120. }
  121. void wfff_wep(const QString& args, const QXmlStreamAttributes*) {
  122. ap_wep = args;
  123. }
  124. void wfff_hdop(const QString& args, const QXmlStreamAttributes*) {
  125. ap_hdop = args.toDouble();
  126. }
  127. void wfff_lat(const QString& args, const QXmlStreamAttributes*) {
  128. ap_lat = args.toDouble();
  129. }
  130. void wfff_lon(const QString& args, const QXmlStreamAttributes*) {
  131. ap_lon = args.toDouble();
  132. }
  133. /* End of AP Block, set waypoint and add */
  134. static long tosscount=0;
  135. void wfff_e(xg_string args, const QXmlStreamAttributes*)
  136. {
  137. Waypoint* wpt_tmp =0;
  138. char desc[255] ="\0";
  139. if ((ap_hdop>=1)&&(ap_hdop<50)) { // Discard invalid GPS fix
  140. wpt_tmp = new Waypoint;
  141. if (snmac) {
  142. wpt_tmp->shortname = ap_mac;
  143. } else {
  144. wpt_tmp->shortname = ap_ssid;
  145. }
  146. snprintf(desc, sizeof desc,
  147. "%s/%s/WEP %s/Ch %d/%2.0fdB/%2.0fdB/%s",
  148. snmac?CSTR(ap_ssid):CSTR(ap_mac), CSTR(ap_type), CSTR(ap_wep),
  149. ap_chan, ap_mnrssi, ap_mxrssi, CSTR(ap_last));
  150. wpt_tmp->description = desc;
  151. wpt_tmp->latitude = ap_lat;
  152. wpt_tmp->longitude = ap_lon;
  153. wpt_tmp->hdop = ap_hdop;
  154. wpt_tmp->altitude = unknown_alt;
  155. wpt_tmp->fix = fix_unknown;
  156. QString ap_wep_(ap_wep);
  157. QString ap_type_(ap_type);
  158. if (ap_wep_.startsWith("on", Qt::CaseInsensitive)) {
  159. if (ap_type_.startsWith("AP", Qt::CaseInsensitive)) {
  160. wpt_tmp->icon_descr = aicicon; /* Infra Closed */
  161. } else {
  162. wpt_tmp->icon_descr = ahcicon; /* AdHoc Closed */
  163. }
  164. } else {
  165. if (ap_type_.startsWith("AP", Qt::CaseInsensitive)) {
  166. wpt_tmp->icon_descr = aioicon; /* Infra Open */
  167. } else {
  168. wpt_tmp->icon_descr = ahoicon; /* AdHoc Open */
  169. }
  170. }
  171. wpt_tmp->SetCreationTime(ap_first);
  172. waypt_add(wpt_tmp);
  173. } else {
  174. tosscount++;
  175. }
  176. }
  177. void
  178. wfff_xml_rd_init(const QString& fname)
  179. {
  180. tosscount = 0;
  181. xml_init(fname, loc_map, NULL);
  182. }
  183. void
  184. wfff_xml_read(void)
  185. {
  186. xml_read();
  187. }
  188. void
  189. wfff_xml_rd_deinit(void)
  190. {
  191. xml_deinit();
  192. if (tosscount) {
  193. warning("Warning: %s reading file. Threw away %ld invalid entries.\n",
  194. MYNAME, tosscount);
  195. }
  196. }
  197. ff_vecs_t wfff_xml_vecs = {
  198. ff_type_file,
  199. {ff_cap_read, ff_cap_none, ff_cap_none},
  200. wfff_xml_rd_init,
  201. 0,
  202. wfff_xml_rd_deinit,
  203. 0,
  204. wfff_xml_read,
  205. 0,
  206. 0,
  207. wfff_xml_args
  208. };