* serv_func.c: added utility function read_server_text()
authorArt Cancro <ajc@citadel.org>
Mon, 26 May 2003 05:28:13 +0000 (05:28 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 26 May 2003 05:28:13 +0000 (05:28 +0000)
* availability.c: banged out more of this code -- still not complete

webcit/ChangeLog
webcit/availability.c
webcit/serv_func.c
webcit/webcit.h

index 6b8709cd097fc33e40548c030183454e5ffdf369..b3cf9ff12a361482e10aa45e8f0449d91e4bcd61 100644 (file)
@@ -1,4 +1,8 @@
 $Log$
+Revision 410.37  2003/05/26 05:28:13  ajc
+* serv_func.c: added utility function read_server_text()
+* availability.c: banged out more of this code -- still not complete
+
 Revision 410.36  2003/05/26 03:28:02  ajc
 * Getting closer to doing the availability check.  Created new source
   module 'availability.c' for this purpose.  Stub function is in place.
@@ -1425,3 +1429,4 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
+
index ceb806e9dd00ca2afbea6475953138e77a98b983..8fa41bf7f3532160311856424df15a882cb0c432 100644 (file)
 
 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
 
+
+
 /*
- * Display an event by itself (for editing)
+ * Utility function to fetch a VFREEBUSY type of thing for
+ * any specified user.
+ */
+icalcomponent *get_freebusy_for_user(char *who) {
+       char buf[SIZ];
+       char *serialized_fb = NULL;
+       icalcomponent *fb = NULL;
+
+       serv_printf("ICAL freebusy|%s", who);
+       serv_gets(buf);
+       if (buf[0] == '1') {
+               serialized_fb = read_server_text();
+       }
+
+       if (serialized_fb == NULL) {
+               return NULL;
+       }
+       
+       fb = icalcomponent_new_from_string(serialized_fb);
+       free(serialized_fb);
+       if (fb == NULL) {
+               return NULL;
+       }
+
+       return fb;
+}
+
+
+
+/*
+ * Back end function for check_attendee_availability()
+ * This one checks an individual attendee against a supplied
+ * event start and end time.  All these fields have already been
+ * broken out.  The result is placed in 'annotation'.
+ */
+void check_individual_attendee(char *attendee_string,
+                               struct icaltimetype event_start,
+                               struct icaltimetype event_end,
+                               char *annotation) {
+
+       icalcomponent *fbc = NULL;
+       icalcomponent *fb = NULL;
+       icalproperty *thisfb = NULL;
+
+       /* Set to 'unknown' right from the beginning.  Unless we learn
+        * something else, that's what we'll go with.
+        */
+       strcpy(annotation, "availability unknown");
+
+       fbc = get_freebusy_for_user(attendee_string);
+       if (fbc == NULL) {
+               return;
+       }
+
+       /* Make sure we're looking at a VFREEBUSY by itself.  What we're probably
+        * looking at initially is a VFREEBUSY encapsulated in a VCALENDAR.
+        */
+       if (icalcomponent_isa(fbc) == ICAL_VCALENDAR_COMPONENT) {
+               fb = icalcomponent_get_first_component(fbc, ICAL_VFREEBUSY_COMPONENT);
+       }
+       else if (icalcomponent_isa(fbc) == ICAL_VFREEBUSY_COMPONENT) {
+               fb = fbc;
+       }
+
+       /* Iterate through all FREEBUSY's looking for conflicts. */
+       if (fb != NULL) {
+
+               strcpy(annotation, "free");
+
+               for (thisfb = icalcomponent_get_first_property(fb, ICAL_FREEBUSY_PROPERTY);
+                   thisfb != NULL;
+                   thisfb = icalcomponent_get_next_property(fb, ICAL_FREEBUSY_PROPERTY) ) {
+       
+                       /* FIXME ... do the check */
+
+               }
+       }
+
+       icalcomponent_free(fbc);
+}
+
+
+
+/*
+ * Check the availability of all attendees for an event (when possible)
+ * and annotate accordingly.
  */
 void check_attendee_availability(icalcomponent *vevent) {
        icalproperty *attendee = NULL;
+       icalproperty *dtstart_p = NULL;
+       icalproperty *dtend_p = NULL;
+       struct icaltimetype dtstart_t;
+       struct icaltimetype dtend_t;
        char attendee_string[SIZ];
+       char annotated_attendee_string[SIZ];
+       char annotation[SIZ];
 
        if (vevent == NULL) {
                return;
@@ -57,9 +150,17 @@ void check_attendee_availability(icalcomponent *vevent) {
                return;
        }
 
+       /*
+        * Learn the start and end times.
+        */
+       dtstart_p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
+       if (dtstart_p != NULL) dtstart_t = icalproperty_get_dtstart(dtstart_p);
+
+       dtend_p = icalcomponent_get_first_property(vevent, ICAL_DTEND_PROPERTY);
+       if (dtend_p != NULL) dtend_t = icalproperty_get_dtend(dtend_p);
 
        /*
-        * Iterate through attendees.  FIXME do something useful.
+        * Iterate through attendees.
         */
        for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
            attendee != NULL;
@@ -72,11 +173,15 @@ void check_attendee_availability(icalcomponent *vevent) {
                        strcpy(attendee_string, &attendee_string[7]);
                        striplt(attendee_string);
 
-                       /* FIXME do something with attendee_string */
-                       lprintf(9, "FIXME with <%s>\n", attendee_string);
+                       check_individual_attendee(attendee_string,
+                                               dtstart_t, dtend_t,
+                                               annotation);
+
+                       /* Replace the attendee name with an annotated one. */
+                       snprintf(annotated_attendee_string, sizeof annotated_attendee_string,
+                               "MAILTO:%s (%s)", attendee_string, annotation);
+                       icalproperty_set_attendee(attendee, annotated_attendee_string);
 
-                       /* participant status 
-                       partstat_as_string(buf, attendee); */
                }
        }
 
index 36e65da7740a52078a7cada2132847e248175339..40b91153479b43201c18da5a3149281cf1d69a51 100644 (file)
@@ -260,3 +260,39 @@ void read_server_binary(char *buffer, size_t total_len) {
 }
 
 
+/*
+ * Read text from server, appending to a string buffer until the
+ * usual 000 terminator is found.  Caller is responsible for freeing
+ * the returned pointer.
+ */
+char *read_server_text(void) {
+       char *text = NULL;
+       size_t bytes_allocated = 0;
+       size_t bytes_read = 0;
+       int linelen;
+       char buf[SIZ];
+
+       text = malloc(SIZ);
+       if (text == NULL) {
+               return(NULL);
+       }
+       strcpy(text, "");
+       bytes_allocated = SIZ;
+
+       while (serv_gets(buf), strcmp(buf, "000")) {
+               linelen = strlen(buf);
+               buf[linelen] = '\n';
+               buf[linelen+1] = 0;
+               ++linelen;
+
+               if ((bytes_read + linelen) >= (bytes_allocated - 2)) {
+                       bytes_allocated = 2 * bytes_allocated;
+                       text = realloc(text, bytes_allocated);
+               }
+
+               strcpy(&text[bytes_read], buf);
+               bytes_read += linelen;
+       }
+
+       return(text);
+}
index 6ec1c553c35cbd15616d3ed90ed2314cc65c1ff5..29d7705cb56933bf4a06c5acc3f1feb2cf7a44d5 100644 (file)
@@ -414,6 +414,7 @@ void check_attendee_availability(icalcomponent *supplied_vevent);
 extern char *months[];
 extern char *days[];
 void read_server_binary(char *buffer, size_t total_len);
+char *read_server_text(void);
 int goto_config_room(void);
 long locate_user_vcard(char *username, long usernum);
 void sleeeeeeeeeep(int);