Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / servers / exchange / lib / fbtest.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Copyright (C) 2002-2004 Novell, Inc.
4  *
5  * This  program is free  software; you  can redistribute  it and/or
6  * modify it under the terms of version 2  of the GNU General Public
7  * License as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 /* Free/Busy test program. Note though that this uses the code in
21  * e2k-freebusy.c, which is not currently used by Connector itself.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <time.h>
31
32 #include "e2k-freebusy.h"
33 #include "e2k-global-catalog.h"
34 #include "test-utils.h"
35
36 const char *test_program_name = "fbtest";
37
38 void
39 test_main (int argc, char **argv)
40 {
41         E2kGlobalCatalog *gc;
42         E2kGlobalCatalogStatus status;
43         E2kGlobalCatalogEntry *entry;
44         const char *server, *email;
45         E2kContext *ctx;
46         E2kFreebusy *fb;
47         E2kFreebusyEvent event;
48         int ti, bi, oi;
49         char *public_uri;
50         struct tm tm;
51         time_t t;
52
53         if (argc != 3) {
54                 fprintf (stderr, "Usage: %s server email-addr\n", argv[0]);
55                 exit (1);
56         }
57
58         server = argv[1];
59         email = argv[2];
60
61         gc = test_get_gc (server);
62
63         status = e2k_global_catalog_lookup (
64                 gc, NULL, E2K_GLOBAL_CATALOG_LOOKUP_BY_EMAIL,
65                 email, E2K_GLOBAL_CATALOG_LOOKUP_LEGACY_EXCHANGE_DN,
66                 &entry);
67
68         if (status != E2K_GLOBAL_CATALOG_OK) {
69                 fprintf (stderr, "Lookup failed: %d\n", status);
70                 test_quit ();
71                 return;
72         }
73
74         public_uri = g_strdup_printf ("http://%s/public", server);
75         ctx = test_get_context (public_uri);
76         fb = e2k_freebusy_new (ctx, public_uri, entry->legacy_exchange_dn);
77         g_free (public_uri);
78         g_object_unref (ctx);
79
80         if (!fb) {
81                 fprintf (stderr, "Could not get fb props\n");
82                 test_quit ();
83                 return;
84         }
85
86         if (!fb->events[E2K_BUSYSTATUS_ALL]->len) {
87                 printf ("No data\n");
88                 test_quit ();
89                 return;
90         }
91
92         printf ("                         6am      9am      noon     3pm      6pm\n");
93
94         ti = bi = oi = 0;
95         for (t = fb->start; t < fb->end; t += 30 * 60) {
96                 if ((t - fb->start) % (24 * 60 * 60) == 0) {
97                         tm = *localtime (&t);
98                         printf ("\n%02d-%02d: ", tm.tm_mon + 1, tm.tm_mday);
99                 }
100
101                 for (; oi < fb->events[E2K_BUSYSTATUS_OOF]->len; oi++) {
102                         event = g_array_index (fb->events[E2K_BUSYSTATUS_OOF],
103                                                E2kFreebusyEvent, oi);
104                         if (event.end <= t)
105                                 continue;
106                         if (event.start < t + (30 * 60)) {
107                                 printf ("O");
108                                 goto next;
109                         }
110                         if (event.start > t)
111                                 break;
112                 }
113                 for (; bi < fb->events[E2K_BUSYSTATUS_BUSY]->len; bi++) {
114                         event = g_array_index (fb->events[E2K_BUSYSTATUS_BUSY],
115                                                E2kFreebusyEvent, bi);
116                         if (event.end <= t)
117                                 continue;
118                         if (event.start < t + (30 * 60)) {
119                                 printf ("X");
120                                 goto next;
121                         }
122                         if (event.start > t)
123                                 break;
124                 }
125                 for (; ti < fb->events[E2K_BUSYSTATUS_TENTATIVE]->len; ti++) {
126                         event = g_array_index (fb->events[E2K_BUSYSTATUS_TENTATIVE],
127                                                E2kFreebusyEvent, ti);
128                         if (event.end <= t)
129                                 continue;
130                         if (event.start < t + (30 * 60)) {
131                                 printf ("t");
132                                 goto next;
133                         }
134                         if (event.start > t)
135                                 break;
136                 }
137                 printf (".");
138
139         next:
140                 if ((t - fb->start) % (60 * 60))
141                         printf (" ");
142         }
143         printf ("\n");
144
145         test_quit ();
146 }