]> Pileus Git - lackey/blobdiff - cals/ews.c
Add Exchange Web Services calendar
[lackey] / cals / ews.c
diff --git a/cals/ews.c b/cals/ews.c
new file mode 100644 (file)
index 0000000..b8ecaa3
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2016 Andy Spencer <andy753421@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+
+#include "util.h"
+#include "conf.h"
+#include "date.h"
+#include "cal.h"
+
+/* Local Types */
+typedef struct ews_t {
+       cal_t         cal;
+       struct ews_t *next;
+
+       // Config
+       char         *username;
+       char         *password;
+       char         *location;
+       char         *domain;
+} ews_t;
+
+/* Static data */
+static ews_t *calendars;
+
+/* Local functions */
+static void sync_ews(ews_t *cal)
+{
+       debug("Loading EWS:");
+       debug("  type     = %s", cal->cal.type);
+       debug("  name     = %s", cal->cal.name);
+       debug("  desc     = %s", cal->cal.desc);
+       debug("  username = %s", cal->username);
+       debug("  password = %s", cal->password);
+       debug("  location = %s", cal->location);
+       debug("  domain   = %s", cal->domain);
+}
+
+/* Config parser */
+void ews_config(const char *group, const char *name, const char *key, const char *value)
+{
+       ews_t *cal = NULL, *last = NULL;
+
+       /* Make sure it's valid */
+       if (!match(group, "ews") || !name)
+               return;
+
+       /* Find existing calendar */
+       for (cal = calendars; cal; last = cal, cal = cal->next)
+               if (match(cal->cal.name, name))
+                       break;
+
+       /* Create new calendar */
+       if (!cal) {
+               cal = new0(ews_t);
+               cal->cal.type = "ews";
+               cal->cal.name = get_name(name);
+               if (last)
+                       last->next = cal;
+               else
+                       calendars = cal;
+       }
+
+       /* Set calendar values */
+       if (match(key, "location"))
+               cal->location = get_string(value);
+       else if (match(key, "username"))
+               cal->username = get_string(value);
+       else if (match(key, "password"))
+               cal->password = get_string(value);
+       else if (match(key, "domain"))
+               cal->domain = get_string(value);
+}
+
+/* Cal functions */
+cal_t *ews_cals(void)
+{
+       for (ews_t *cal = calendars; cal; cal = cal->next) {
+               sync_ews(cal);
+               cal->cal.next = &cal->next->cal;
+       }
+
+       return &calendars->cal;
+}
+
+/* Event functions */
+event_t *ews_events(date_t start, date_t end)
+{
+       return NULL;
+}
+
+/* Todo functions */
+todo_t *ews_todos(date_t start, date_t end)
+{
+       return NULL;
+}
+
+/* Test functions */
+void ews_test(char *url, char *user, char *pass)
+{
+       printf("EWS -- test start\n");
+       printf("EWS -- test end\n");
+}