stuart: server/kolab-resource-handlers/kolab-resource-handlers/freebusy freebusy.php, 1.22, 1.23

cvs at intevation.de cvs at intevation.de
Tue Sep 14 22:33:21 CEST 2004


Author: stuart

Update of /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/freebusy
In directory doto:/tmp/cvs-serv13546/kolab-resource-handlers/kolab-resource-handlers/freebusy

Modified Files:
	freebusy.php 
Log Message:
- Changed $extended to $params['extended'] which can be specified in freebusy.conf (i.e. can always generate xfb's if desired)
- Added $params['cache'] to control whether a cached result is returned, and whether the result of a vfb generation is cached for future use
- Both of the above can be controlled via URL parameters x and c, respectively (e.g. c=0 to turn off caching, c=1 to turn on caching). The URL parameters override the freebusy.conf settings.
- Added the ability to ignore specific events when generating the vfb. This is required for the resmgr script to properly handle event modification. Events can be specified by the url paramter i, and multiple events can be specified by doing e.g. i[]=one&i[]=two. The parameters to i should be urlencode()'ed UIDs of the specific events to ignore. If any events are to be ignored, caching is automatically turned off.
- Some small cleanups.


Index: freebusy.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/freebusy/freebusy.php,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- freebusy.php	10 Sep 2004 10:13:31 -0000	1.22
+++ freebusy.php	14 Sep 2004 20:33:19 -0000	1.23
@@ -216,7 +216,7 @@
 
 function &generateFreeBusy($startstamp = NULL, $endstamp = NULL)
 {
-    global $params, $imap, $user, $messages, $extended;
+    global $params, $imap, $user, $messages;
 
     require_once 'PEAR.php';
     require_once 'Horde/iCalendar.php';
@@ -289,6 +289,12 @@
         }
 
         $uid = $event['uid'];
+        // See if we need to ignore this event
+        if (isset($params['ignore'][$uid])) {
+            trigger_error("Ignoring event with uid=$uid", E_USER_NOTICE);
+            continue;
+        }
+
         $summary = ($event['sensitivity'] == 'public' ? $event['summary'] : '');
 
         trigger_error("Looking at message with uid=$uid and summary=$summary", E_USER_NOTICE);
@@ -302,7 +308,7 @@
             continue;
         }
 
-        if ($extended) {
+        if ($params['extended']) {
             $extra = array(
                 'X-UID'     => base64_encode($uid),
             );
@@ -354,8 +360,31 @@
 $scriptname = basename($_SERVER['SCRIPT_NAME']);
 
 // Should we return extended information?
-//$extended = array_key_exists('x', $GLOBALS['HTTP_GET_VARS']);
-$extended = isset($_GET['x']);
+if (isset($_GET['x'])) {
+    $params['extended'] = !empty($_GET['x']);
+}
+
+// Should we use the caching mechanism?
+if (isset($_GET['c'])) {
+    $params['cache'] = !empty($_GET['c']);
+}
+
+// See what UIDs we should ignore when generating the free/busy list
+$params['ignore'] = empty($_GET['i']) ? array() : $_GET['i'];
+if (!is_array($params['ignore'])) {
+    $params['ignore'] = array($params['ignore']);
+}
+$_temp = $params['ignore'];
+$params['ignore'] = array();
+foreach ($_temp as $uid) {
+    $params['ignore'][urldecode($uid)] = 1;
+}
+
+// Turn off caching if we have to ignore some events, as otherwise we'll be
+// returning incorrect information
+if (!empty($params['ignore'])) {
+    $params['cache'] = false;
+}
 
 // Determine who we're supposed to get f/b info for
 //$user = preg_replace('/\.vfb$/i', '', basename($_SERVER['PATH_INFO']));
@@ -370,7 +399,7 @@
 $fbdir = $params['kolab_prefix'].'/var/kolab/www/freebusy/data/';
 $ifbfilename = $fbdir.$user.'.ifb';
 $xfbfilename = $fbdir.$user.'.xfb';
-$fbfilename = ($extended?$xfbfilename:$ifbfilename);
+$fbfilename = ($params['extended'] ? $xfbfilename : $ifbfilename);
 
 // Handle the case of 'user' instead of 'user at domain'
 if (strstr($user, '@') === false) {
@@ -408,9 +437,10 @@
         if ($params['redirect']) {
             header("Location: $redirect");
         } else {
-
             header("X-Redirect-To: $redirect");
-	    $redirect = 'https://'.urlencode($_SERVER['PHP_AUTH_USER']).':'.urlencode($_SERVER['PHP_AUTH_PW']).'@'.$homeServer . $_SERVER['REQUEST_URI'];
+            $redirect = 'https://' . urlencode($_SERVER['PHP_AUTH_USER']) . ':'
+                . urlencode($_SERVER['PHP_AUTH_PW']) . '@' . $homeServer
+                . $_SERVER['REQUEST_URI'];
             if (!@readfile($redirect)) {
                 notFound("Unable to read free/busy information from $redirect");
             }
@@ -442,8 +472,8 @@
 testLDAPError();
 $ldapresults = @ldap_get_entries($ldap, $ldapsearch);
 testLDAPError();
-if ( is_array($ldapresults) && $ldapresults['count']>0 && array_key_exists('mail', $ldapresults[0])) {
-  $imapuser = $ldapresults[0]['mail'][0];
+if (is_array($ldapresults) && $ldapresults['count'] > 0 && array_key_exists('mail', $ldapresults[0])) {
+    $imapuser = $ldapresults[0]['mail'][0];
 }
 $imappw = $_SERVER['PHP_AUTH_PW'];
 
@@ -465,7 +495,7 @@
 trigger_error("user=$imapuser, mailbox=$fullmbox, fbfilename=$fbfilename", E_USER_NOTICE);
 
 $vfb = false;
-if ($_SERVER['REQUEST_METHOD'] != 'PUT' && ($imapuser || $extended)) {
+if ($_SERVER['REQUEST_METHOD'] != 'PUT' && ($imapuser || $params['extended'])) {
     // Open an IMAP connection to the requested users' calendar
     $imap = @imap_open($fullmbox, $imapuser, $imappw, OP_HALFOPEN );
     if (!$imap ) {
@@ -489,30 +519,26 @@
             // Generate the VFB file
             $vfb = &generateFreeBusy();
             $ts = mktime();
-            if ($vfb) {
-                if ($extended) {
-                    // Don't cache
-                } else {
-                    // Cache the generated free/busy file
-                    storeFreeBusy($fbdir, $fbfilename, $vfb);
-                }
+            // Cache the generated free/busy file
+            if ($vfb && $params['cache'] && !$params['extended']) {
+                storeFreeBusy($fbdir, $fbfilename, $vfb);
             }
         }
     }
 }
 
 if (!$vfb) {
-    if (!file_exists($fbfilename) && $imapuser == $user) {
+    if (!$params['cache'] || (!file_exists($fbfilename) && $imapuser == $user)) {
         notFound("Unable to generate free/busy list");
         exit;
     }
 
     $vfb = file_get_contents($fbfilename);
     $ts = filectime($fbfilename);
-    if (!$vfb && $extended) {
+    if (!$vfb && $params['extended']) {
         // Check if we have a plain fb list
         $vfb = file_get_contents($ifbfilename);
-	$ts = filectime($ifbfilename);
+        $ts = filectime($ifbfilename);
     }
     if (!$vfb) notFound("Unable to locate cached free/busy list");
 }





More information about the commits mailing list