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.

244 lines
7.9 KiB

  1. #include <util/calendar_parsing.h>
  2. #include <memory>
  3. namespace util {
  4. std::vector<ical::ical_object*> parse_cal_dir() {
  5. std::vector<ical::ical_object*> objects;
  6. std::vector<icalcomponent*> components;
  7. for (boost::filesystem::directory_entry& entry : boost::filesystem::directory_iterator(cal_dir)) {
  8. DEBUG << "Parsing: " + entry.path().generic_string();
  9. ical::ical_object* object = new ical::ical_object();
  10. parse_main_component(object, parse_ics_file(entry.path().generic_string()));
  11. }
  12. return objects;
  13. }
  14. icalcomponent* parse_main_component(ical::ical_object* object, icalcomponent* component) {
  15. icalcomponent* c = icalcomponent_get_first_component(component, ICAL_ANY_COMPONENT);
  16. while(c != 0) {
  17. if(c != 0) {
  18. parse_component(object, c);
  19. }
  20. c = parse_main_component(object, c);
  21. if(c == 0) {
  22. c = icalcomponent_get_next_component(component, ICAL_ANY_COMPONENT);
  23. }
  24. }
  25. return c;
  26. }
  27. void parse_component(ical::ical_object* object, icalcomponent* component) {
  28. switch(icalcomponent_isa(component)) {
  29. case ICAL_VALARM_COMPONENT: break;
  30. case ICAL_NO_COMPONENT:
  31. {
  32. DEBUG << "parsed component: ICAL_NO_COMPONENT";
  33. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  34. break;
  35. }
  36. case ICAL_ANY_COMPONENT:
  37. {
  38. DEBUG << "parsed component: ICAL_ANY_COMPONENT";
  39. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  40. break;
  41. }
  42. case ICAL_XROOT_COMPONENT:
  43. {
  44. DEBUG << "parsed component: ICAL_XROOT_COMPONENT";
  45. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  46. break;
  47. }
  48. case ICAL_XATTACH_COMPONENT:
  49. {
  50. DEBUG << "parsed component: ICAL_XATTACH_COMPONENT";
  51. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  52. break;
  53. }
  54. case ICAL_VEVENT_COMPONENT:
  55. {
  56. DEBUG << "parsed component: ICAL_VEVENT_COMPONENT";
  57. //DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  58. ical::Event(object, component);
  59. break;
  60. }
  61. case ICAL_VTODO_COMPONENT:
  62. {
  63. DEBUG << "parsed component: ICAL_VTODO_COMPONENT";
  64. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  65. break;
  66. }
  67. case ICAL_VJOURNAL_COMPONENT:
  68. {
  69. DEBUG << "parsed component: ICAL_VJOURNAL_COMPONENT";
  70. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  71. break;
  72. }
  73. case ICAL_VCALENDAR_COMPONENT:
  74. {
  75. DEBUG << "parsed component: ICAL_VCALENDAR_COMPONENT";
  76. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  77. break;
  78. }
  79. case ICAL_VAGENDA_COMPONENT:
  80. {
  81. DEBUG << "parsed component: ICAL_VAGENDA_COMPONENT";
  82. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  83. break;
  84. }
  85. case ICAL_VFREEBUSY_COMPONENT:
  86. {
  87. DEBUG << "parsed component: ICAL_VFREEBUSY_COMPONENT";
  88. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  89. break;
  90. }
  91. case ICAL_XAUDIOALARM_COMPONENT:
  92. {
  93. DEBUG << "parsed component: ICAL_XAUDIOALARM_COMPONENT";
  94. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  95. break;
  96. }
  97. case ICAL_XDISPLAYALARM_COMPONENT:
  98. {
  99. DEBUG << "parsed component: ICAL_XDISPLAYALARM_COMPONENT";
  100. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  101. break;
  102. }
  103. case ICAL_XEMAILALARM_COMPONENT:
  104. {
  105. DEBUG << "parsed component: ICAL_XEMAILALARM_COMPONENT";
  106. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  107. break;
  108. }
  109. case ICAL_XPROCEDUREALARM_COMPONENT:
  110. {
  111. DEBUG << "parsed component: ICAL_XPROCEDUREALARM_COMPONENT";
  112. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  113. break;
  114. }
  115. case ICAL_VTIMEZONE_COMPONENT:
  116. {
  117. DEBUG << "parsed component: ICAL_VTIMEZONE_COMPONENT";
  118. break;
  119. }
  120. case ICAL_XSTANDARD_COMPONENT:
  121. {
  122. DEBUG << "parsed component: ICAL_XSTANDARD_COMPONENT";
  123. break;
  124. }
  125. case ICAL_XDAYLIGHT_COMPONENT:
  126. {
  127. DEBUG << "parsed component: ICAL_XDAYLIGHT_COMPONENT";
  128. break;
  129. }
  130. case ICAL_X_COMPONENT:
  131. {
  132. DEBUG << "parsed component: ICAL_X_COMPONENT";
  133. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  134. break;
  135. }
  136. case ICAL_VSCHEDULE_COMPONENT:
  137. {
  138. DEBUG << "parsed component: ICAL_VSCHEDULE_COMPONENT";
  139. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  140. break;
  141. }
  142. case ICAL_VQUERY_COMPONENT:
  143. {
  144. DEBUG << "parsed component: ICAL_VQUERY_COMPONENT";
  145. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  146. break;
  147. }
  148. case ICAL_VREPLY_COMPONENT:
  149. {
  150. DEBUG << "parsed component: ICAL_VREPLY_COMPONENT";
  151. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  152. break;
  153. }
  154. case ICAL_VCAR_COMPONENT:
  155. {
  156. DEBUG << "parsed component: ICAL_VCAR_COMPONENT";
  157. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  158. break;
  159. }
  160. case ICAL_VCOMMAND_COMPONENT:
  161. {
  162. DEBUG << "parsed component: ICAL_VCOMMAND_COMPONENT";
  163. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  164. break;
  165. }
  166. case ICAL_XLICINVALID_COMPONENT:
  167. {
  168. DEBUG << "parsed component: ICAL_XLICINVALID_COMPONENT";
  169. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  170. break;
  171. }
  172. case ICAL_XLICMIMEPART_COMPONENT:
  173. {
  174. DEBUG << "parsed component: ICAL_XLICMIMEPART_COMPONENT";
  175. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  176. break;
  177. }
  178. case ICAL_VAVAILABILITY_COMPONENT:
  179. {
  180. DEBUG << "parsed component: ICAL_VAVAILABILITY_COMPONENT";
  181. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  182. break;
  183. }
  184. case ICAL_XAVAILABLE_COMPONENT:
  185. {
  186. DEBUG << "parsed component: ICAL_XAVAILABLE_COMPONENT";
  187. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  188. break;
  189. }
  190. case ICAL_VPOLL_COMPONENT:
  191. {
  192. DEBUG << "parsed component: ICAL_VPOLL_COMPONENT";
  193. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  194. break;
  195. }
  196. case ICAL_VVOTER_COMPONENT:
  197. {
  198. DEBUG << "parsed component: ICAL_VVOTER_COMPONENT";
  199. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  200. break;
  201. }
  202. case ICAL_XVOTE_COMPONENT:
  203. {
  204. DEBUG << "parsed component: ICAL_XVOTE_COMPONENT";
  205. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  206. break;
  207. }
  208. case ICAL_VPATCH_COMPONENT:
  209. {
  210. DEBUG << "parsed component: ICAL_VPATCH_COMPONENT";
  211. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  212. break;
  213. }
  214. case ICAL_XPATCH_COMPONENT:
  215. {
  216. DEBUG << "parsed component: ICAL_XPATCH_COMPONENT";
  217. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  218. break;
  219. }
  220. default:
  221. DEBUG << "parse_component: something else found";
  222. break;
  223. }
  224. }
  225. std::string slurp(std::ifstream& in) {
  226. std::ostringstream sstr;
  227. sstr << in.rdbuf();
  228. return sstr.str();
  229. }
  230. icalcomponent* parse_ics_file(std::string filename) {
  231. std::ifstream ifs (filename, std::ifstream::in);
  232. return icalparser_parse_string(slurp(ifs).c_str());
  233. }
  234. void debug(icalcomponent* component) {
  235. DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
  236. }
  237. }