]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_calendar.c
* Use syslog-compatible logging levels in lprintf(); the loglevel chosen
[citadel.git] / citadel / serv_calendar.c
index 6de73bff40d460bafa902b0227ba77511071baca..beca84454a4d03750b14a04deff2daa59a530be7 100644 (file)
@@ -52,7 +52,7 @@ icalcomponent *icalcomponent_new_citadel_vcalendar(void) {
 
        encaps = icalcomponent_new_vcalendar();
        if (encaps == NULL) {
-               lprintf(3, "Error at %s:%d - could not allocate component!\n",
+               lprintf(CTDL_CRIT, "Error at %s:%d - could not allocate component!\n",
                        __FILE__, __LINE__);
                return NULL;
        }
@@ -209,13 +209,13 @@ void ical_send_a_reply(icalcomponent *request, char *action) {
        strcpy(summary_string, "Calendar item");
 
        if (request == NULL) {
-               lprintf(3, "ERROR: trying to reply to NULL event?\n");
+               lprintf(CTDL_ERR, "ERROR: trying to reply to NULL event?\n");
                return;
        }
 
        the_reply = icalcomponent_new_clone(request);
        if (the_reply == NULL) {
-               lprintf(3, "ERROR: cannot clone request\n");
+               lprintf(CTDL_ERR, "ERROR: cannot clone request\n");
                return;
        }
 
@@ -618,13 +618,13 @@ int ical_update_my_calendar_with_reply(icalcomponent *cal) {
        /* Figure out just what event it is we're dealing with */
        strcpy(uid, "--==<< InVaLiD uId >>==--");
        ical_learn_uid_of_reply(uid, cal);
-       lprintf(9, "UID of event being replied to is <%s>\n", uid);
+       lprintf(CTDL_DEBUG, "UID of event being replied to is <%s>\n", uid);
 
        strcpy(hold_rm, CC->room.QRname);       /* save current room */
 
        if (getroom(&CC->room, USERCALENDARROOM) != 0) {
                getroom(&CC->room, hold_rm);
-               lprintf(3, "cannot get user calendar room\n");
+               lprintf(CTDL_CRIT, "cannot get user calendar room\n");
                return(2);
        }
 
@@ -643,7 +643,7 @@ int ical_update_my_calendar_with_reply(icalcomponent *cal) {
        CtdlFreeMessage(template);
        getroom(&CC->room, hold_rm);    /* return to saved room */
 
-       lprintf(9, "msgnum_being_replaced == %ld\n", msgnum_being_replaced);
+       lprintf(CTDL_DEBUG, "msgnum_being_replaced == %ld\n", msgnum_being_replaced);
        if (msgnum_being_replaced == 0) {
                return(1);                      /* no calendar event found */
        }
@@ -670,7 +670,7 @@ int ical_update_my_calendar_with_reply(icalcomponent *cal) {
 
        original_event = oec.c;
        if (original_event == NULL) {
-               lprintf(3, "ERROR: Original_component is NULL.\n");
+               lprintf(CTDL_ERR, "ERROR: Original_component is NULL.\n");
                return(2);
        }
 
@@ -1158,7 +1158,7 @@ void ical_freebusy(char *who) {
        }
 
        /* Create a VFREEBUSY subcomponent */
-       lprintf(9, "Creating VFREEBUSY component\n");
+       lprintf(CTDL_DEBUG, "Creating VFREEBUSY component\n");
        fb = icalcomponent_new_vfreebusy();
        if (fb == NULL) {
                cprintf("%d Internal error: cannot allocate memory.\n",
@@ -1168,7 +1168,7 @@ void ical_freebusy(char *who) {
                return;
        }
 
-       lprintf(9, "Adding busy time from events\n");
+       lprintf(CTDL_DEBUG, "Adding busy time from events\n");
        CtdlForEachMessage(MSGS_ALL, 0, "text/calendar",
                NULL, ical_freebusy_backend, (void *)fb
        );
@@ -1184,7 +1184,7 @@ void ical_freebusy(char *who) {
         */
 
        /* Put the freebusy component into the calendar component */
-       lprintf(9, "Encapsulating\n");
+       lprintf(CTDL_DEBUG, "Encapsulating\n");
        encaps = ical_encapsulate_subcomponent(fb);
        if (encaps == NULL) {
                icalcomponent_free(fb);
@@ -1195,11 +1195,11 @@ void ical_freebusy(char *who) {
        }
 
        /* Set the method to PUBLISH */
-       lprintf(9, "Setting method\n");
+       lprintf(CTDL_DEBUG, "Setting method\n");
        icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
 
        /* Serialize it */
-       lprintf(9, "Serializing\n");
+       lprintf(CTDL_DEBUG, "Serializing\n");
        serialized_request = strdoop(icalcomponent_as_ical_string(encaps));
        icalcomponent_free(encaps);     /* Don't need this anymore. */
 
@@ -1232,20 +1232,28 @@ void cmd_ical(char *argbuf)
 
        /* Allow "test" and "freebusy" subcommands without logging in. */
 
-       if (!strcmp(subcmd, "test")) {
+       if (!strcasecmp(subcmd, "test")) {
                cprintf("%d This server supports calendaring\n", CIT_OK);
                return;
        }
 
-       if (!strcmp(subcmd, "freebusy")) {
+       if (!strcasecmp(subcmd, "freebusy")) {
                extract(who, argbuf, 1);
                ical_freebusy(who);
                return;
        }
 
+       if (!strcasecmp(subcmd, "sgi")) {
+               CIT_ICAL->server_generated_invitations =
+                       (extract_int(argbuf, 1) ? 1 : 0) ;
+               cprintf("%d %d\n",
+                       CIT_OK, CIT_ICAL->server_generated_invitations);
+               return;
+       }
+
        if (CtdlAccessCheck(ac_logged_in)) return;
 
-       if (!strcmp(subcmd, "respond")) {
+       if (!strcasecmp(subcmd, "respond")) {
                msgnum = extract_long(argbuf, 1);
                extract(partnum, argbuf, 2);
                extract(action, argbuf, 3);
@@ -1253,7 +1261,7 @@ void cmd_ical(char *argbuf)
                return;
        }
 
-       if (!strcmp(subcmd, "handle_rsvp")) {
+       if (!strcasecmp(subcmd, "handle_rsvp")) {
                msgnum = extract_long(argbuf, 1);
                extract(partnum, argbuf, 2);
                extract(action, argbuf, 3);
@@ -1261,7 +1269,7 @@ void cmd_ical(char *argbuf)
                return;
        }
 
-       if (!strcmp(subcmd, "conflicts")) {
+       if (!strcasecmp(subcmd, "conflicts")) {
                msgnum = extract_long(argbuf, 1);
                extract(partnum, argbuf, 2);
                ical_conflicts(msgnum, partnum);
@@ -1286,7 +1294,7 @@ void ical_create_room(void)
 
        /* Set expiration policy to manual; otherwise objects will be lost! */
        if (lgetroom(&qr, USERCALENDARROOM)) {
-               lprintf(3, "Couldn't get the user calendar room!\n");
+               lprintf(CTDL_CRIT, "Couldn't get the user calendar room!\n");
                return;
        }
        qr.QRep.expire_mode = EXPIRE_MANUAL;
@@ -1303,7 +1311,7 @@ void ical_create_room(void)
 
        /* Set expiration policy to manual; otherwise objects will be lost! */
        if (lgetroom(&qr, USERTASKSROOM)) {
-               lprintf(3, "Couldn't get the user calendar room!\n");
+               lprintf(CTDL_CRIT, "Couldn't get the user calendar room!\n");
                return;
        }
        qr.QRep.expire_mode = EXPIRE_MANUAL;
@@ -1338,7 +1346,7 @@ void ical_send_out_invitations(icalcomponent *cal) {
        icalproperty *summary = NULL;
 
        if (cal == NULL) {
-               lprintf(3, "ERROR: trying to reply to NULL event?\n");
+               lprintf(CTDL_ERR, "ERROR: trying to reply to NULL event?\n");
                return;
        }
 
@@ -1356,7 +1364,7 @@ void ical_send_out_invitations(icalcomponent *cal) {
        /* Clone the event */
        the_request = icalcomponent_new_clone(cal);
        if (the_request == NULL) {
-               lprintf(3, "ERROR: cannot clone calendar object\n");
+               lprintf(CTDL_ERR, "ERROR: cannot clone calendar object\n");
                return;
        }
 
@@ -1379,17 +1387,20 @@ void ical_send_out_invitations(icalcomponent *cal) {
                        strcpy(this_attendee, icalproperty_get_attendee(attendee) );
                        if (!strncasecmp(this_attendee, "MAILTO:", 7)) {
                                strcpy(this_attendee, &this_attendee[7]);
-                               snprintf(&attendees_string[strlen(attendees_string)],
-                                       sizeof(attendees_string) - strlen(attendees_string),
-                                       "%s, ",
-                                       this_attendee
-                               );
-                               ++num_attendees;
+
+                               if (!CtdlIsMe(this_attendee)) { /* don't send an invitation to myself! */
+                                       snprintf(&attendees_string[strlen(attendees_string)],
+                                               sizeof(attendees_string) - strlen(attendees_string),
+                                               "%s, ",
+                                               this_attendee
+                                       );
+                                       ++num_attendees;
+                               }
                        }
                }
        }
 
-       lprintf(9, "<%d> attendees: <%s>\n", num_attendees, attendees_string);
+       lprintf(CTDL_DEBUG, "<%d> attendees: <%s>\n", num_attendees, attendees_string);
 
        /* If there are no attendees, there are no invitations to send, so...
         * don't bother putting one together!  Punch out, Maverick!
@@ -1402,7 +1413,7 @@ void ical_send_out_invitations(icalcomponent *cal) {
        /* Encapsulate the VEVENT component into a complete VCALENDAR */
        encaps = icalcomponent_new_vcalendar();
        if (encaps == NULL) {
-               lprintf(3, "Error at %s:%d - could not allocate component!\n",
+               lprintf(CTDL_DEBUG, "Error at %s:%d - could not allocate component!\n",
                        __FILE__, __LINE__);
                icalcomponent_free(the_request);
                return;
@@ -1466,9 +1477,12 @@ void ical_saving_vevent(icalcomponent *cal) {
        icalproperty *organizer = NULL;
        char organizer_string[SIZ];
 
+       /* Don't send out invitations unless the client wants us to. */
+       if (CIT_ICAL->server_generated_invitations == 0) {
+               return;
+       }
+
        /* Don't send out invitations if we've been asked not to. */
-       lprintf(9, "CIT_ICAL->avoid_sending_invitations = %d\n",
-               CIT_ICAL->avoid_sending_invitations);
        if (CIT_ICAL->avoid_sending_invitations > 0) {
                return;
        }
@@ -1646,7 +1660,7 @@ int ical_obj_beforesave(struct CtdlMessage *msg)
        }
        
        /* Oops!  No Content-Type in this message!  How'd that happen? */
-       lprintf(7, "RFC822 message with no Content-Type header!\n");
+       lprintf(CTDL_ERR, "RFC822 message with no Content-Type header!\n");
        return 1;
 }
 
@@ -1723,7 +1737,7 @@ int ical_obj_aftersave(struct CtdlMessage *msg)
        }
        
        /* Oops!  No Content-Type in this message!  How'd that happen? */
-       lprintf(7, "RFC822 message with no Content-Type header!\n");
+       lprintf(CTDL_ERR, "RFC822 message with no Content-Type header!\n");
        return 1;
 }