[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 3 include_once dirname(__FILE__).'/State.php'; 4 5 class EGW_SyncML_State extends Horde_SyncML_State 6 { 7 /** 8 * Returns the timestamp (if set) of the last change to the 9 * obj:guid, that was caused by the client. This is stored to 10 * avoid mirroring these changes back to the client. 11 */ 12 function getChangeTS($type, $guid) 13 { 14 $mapID = $this->_locName . $this->_sourceURI . $type; 15 16 $db = clone($GLOBALS['phpgw']->db); 17 18 $cols = array('map_timestamp'); 19 20 $where = array 21 ( 22 'map_id' => $mapID, 23 'map_guid' => $guid, 24 ); 25 26 #Horde::logMessage('SyncML: getChangeTS for ' . $mapID .' / '. $guid, __FILE__, __LINE__, PEAR_LOG_DEBUG); 27 28 $db->select('egw_contentmap', $cols, $where, __LINE__, __FILE__); 29 30 if($db->next_record()) 31 { 32 #Horde::logMessage('SyncML: getChangeTS changets is ' . $db->from_timestamp($db->f('map_timestamp')), __FILE__, __LINE__, PEAR_LOG_DEBUG); 33 return $db->from_timestamp($db->f('map_timestamp')); 34 } 35 36 return false; 37 } 38 39 /** 40 * Retrieves information about the clients device info if any. Returns 41 * false if no info found or a DateTreeObject with at least the 42 * following attributes: 43 * 44 * a array containing all available infos about the device 45 */ 46 function getClientDeviceInfo() 47 { 48 $deviceID = $this->_locName . $this->_sourceURI; 49 50 $db = clone($GLOBALS['egw']->db); 51 52 $cols = array 53 ( 54 'dev_dtdversion', 55 'dev_numberofchanges', 56 'dev_largeobjs', 57 'dev_swversion', 58 'dev_oem', 59 'dev_model', 60 'dev_manufacturer', 61 'dev_devicetype', 62 'dev_deviceid', 63 'dev_datastore', 64 ); 65 66 $where = array 67 ( 68 'dev_id' => $deviceID, 69 ); 70 71 $db->select('egw_syncmldevinfo', $cols, $where, __LINE__, __FILE__); 72 73 if($db->next_record()) 74 { 75 $devInfo = array 76 ( 77 'DTDVersion' => $db->f('dev_dtdversion'), 78 'supportNumberOfChanges' => $db->f('dev_numberofchanges'), 79 'supportLargeObjs' => $db->f('dev_largeobjs'), 80 'softwareVersion' => $db->f('dev_swversion'), 81 'oem' => $db->f('dev_oem'), 82 'model' => $db->f('dev_model'), 83 'manufacturer' => $db->f('dev_manufacturer'), 84 'deviceType' => $db->f('dev_devicetype'), 85 'deviceID' => $db->f('dev_deviceid'), 86 'dataStore' => unserialize($db->f('dev_datastore')), 87 ); 88 89 return $devInfo; 90 } 91 92 return false; 93 } 94 95 /** 96 * Retrieves the Horde server guid (like 97 * kronolith:0d1b415fc124d3427722e95f0e926b75) for a given client 98 * locid. Returns false if no such id is stored yet. 99 * 100 * Opposite of getLocId which returns the locid for a given guid. 101 */ 102 function getGlobalUID($type, $locid) 103 { 104 $mapID = $this->_locName . $this->_sourceURI . $type; 105 106 #Horde::logMessage('SyncML: search GlobalUID for ' . $mapID .' / '.$locid, __FILE__, __LINE__, PEAR_LOG_DEBUG); 107 108 $db = clone($GLOBALS['egw']->db); 109 110 $cols = array('map_guid'); 111 112 $where = array 113 ( 114 'map_id' => $mapID, 115 'map_locuid' => $locid, 116 'map_expired' => 0, 117 ); 118 119 $db->select('egw_contentmap', $cols, $where, __LINE__, __FILE__); 120 121 if($db->next_record()) 122 { 123 return $db->f('map_guid'); 124 } 125 126 return false; 127 } 128 129 /** 130 * Converts a EGW GUID (like 131 * kronolith:0d1b415fc124d3427722e95f0e926b75) to a client ID as 132 * used by the sync client (like 12) returns false if no such id 133 * is stored yet. 134 */ 135 function getLocID($type, $guid) 136 { 137 $mapID = $this->_locName . $this->_sourceURI . $type; 138 139 $db = clone($GLOBALS['egw']->db); 140 141 $cols = array('map_locuid'); 142 143 $where = array 144 ( 145 'map_id' => $mapID, 146 'map_guid' => $guid 147 ); 148 Horde::logMessage('SyncML: search LocID for ' . $mapID .' / '.$guid, __FILE__, __LINE__, PEAR_LOG_DEBUG); 149 $db->select('egw_contentmap', $cols, $where, __LINE__, __FILE__); 150 151 if($db->next_record()) 152 { 153 Horde::logMessage('SyncML: found LocID: '.$db->f('map_locuid'), __FILE__, __LINE__, PEAR_LOG_DEBUG); 154 return $db->f('map_locuid'); 155 } 156 157 return false; 158 } 159 160 /** 161 * Retrieves information about the previous sync if any. Returns 162 * false if no info found or a DateTreeObject with at least the 163 * following attributes: 164 * 165 * ClientAnchor: the clients Next Anchor of the previous sync. 166 * ServerAnchor: the Server Next Anchor of the previous sync. 167 */ 168 function getSyncSummary($type) 169 { 170 $deviceID = $this->_locName . $this->_sourceURI; 171 172 $db = clone($GLOBALS['egw']->db); 173 174 $cols = array('sync_serverts','sync_clientts'); 175 176 $where = array 177 ( 178 'dev_id' => $deviceID, 179 'sync_path' => $type 180 ); 181 182 $db->select('egw_syncmlsummary', $cols, $where, __LINE__, __FILE__); 183 184 #Horde::logMessage("SyncML: get SYNCSummary for $deviceID", __FILE__, __LINE__, PEAR_LOG_DEBUG); 185 if($db->next_record()) 186 { 187 #Horde::logMessage("SyncML: get SYNCSummary for $deviceID serverts: ".$db->f('sync_serverts')." clients: ".$db->f('sync_clientts'), __FILE__, __LINE__, PEAR_LOG_DEBUG); 188 $retData = array 189 ( 190 'ClientAnchor' => $db->f('sync_clientts'), 191 'ServerAnchor' => $db->f('sync_serverts'), 192 ); 193 return $retData; 194 } 195 196 return false; 197 198 } 199 200 function isAuthorized() 201 { 202 if (!$this->_isAuthorized) { 203 204 if(!isset($this->_locName) && !isset($this->_password)) 205 { 206 Horde::logMessage('SyncML: Authentication not yet possible currently. Username and password not available' , __FILE__, __LINE__, PEAR_LOG_DEBUG); 207 return FALSE; 208 } 209 210 if(!isset($this->_password)) 211 { 212 Horde::logMessage('SyncML: Authentication not yet possible currently. Password not available' , __FILE__, __LINE__, PEAR_LOG_DEBUG); 213 return FALSE; 214 } 215 216 if(strstr($this->_locName,'@') === False) 217 { 218 $this->_locName .= '@'.$GLOBALS['egw_info']['server']['default_domain']; 219 } 220 221 #Horde::logMessage('SyncML: authenticate with username: ' . $this->_locName . ' and password: ' . $this->_password, __FILE__, __LINE__, PEAR_LOG_DEBUG); 222 223 if($GLOBALS['sessionid'] = $GLOBALS['egw']->session->create($this->_locName,$this->_password,'text','u')) 224 { 225 $this->_isAuthorized = true; 226 Horde::logMessage('SyncML_EGW: Authentication of ' . $this->_locName . '/' . $GLOBALS['sessionid'] . ' succeded' , __FILE__, __LINE__, PEAR_LOG_DEBUG); 227 } 228 else 229 { 230 $this->_isAuthorized = false; 231 Horde::logMessage('SyncML: Authentication of ' . $this->_locName . ' failed' , __FILE__, __LINE__, PEAR_LOG_INFO); 232 } 233 } 234 else 235 { 236 // store sessionID in a variable, because ->verify maybe resets that value 237 $sessionID = session_id(); 238 if(!$GLOBALS['egw']->session->verify($sessionID, 'staticsyncmlkp3')) { 239 Horde::logMessage('SyncML_EGW: egw session(' .$sessionID. ') not verified ' , __FILE__, __LINE__, PEAR_LOG_DEBUG); 240 } 241 } 242 243 return $this->_isAuthorized; 244 } 245 246 /** 247 * Removes the locid<->guid mapping for the given locid. Returns 248 * the guid that was removed or false if no mapping entry was 249 * found. 250 */ 251 function removeUID($type, $locid) 252 { 253 $mapID = $this->_locName . $this->_sourceURI . $type; 254 255 $db = clone($GLOBALS['egw']->db); 256 257 $cols = array('map_guid'); 258 259 $where = array 260 ( 261 'map_id' => $mapID, 262 'map_locuid' => $locid 263 ); 264 265 $db->select('egw_contentmap', $cols, $where, __LINE__, __FILE__); 266 267 if(!$db->next_record()) 268 { 269 Horde::logMessage("SyncML: state->removeUID(type=$type,locid=$locid) : nothing to remove", __FILE__, __LINE__, PEAR_LOG_DEBUG); 270 return false; 271 } 272 273 $guid = $db->f('map_guid'); 274 275 #Horde::logMessage("SyncML: state->removeUID(type=$type,locid=$locid) : removing guid:$guid", __FILE__, __LINE__, PEAR_LOG_DEBUG); 276 277 $db->delete('egw_contentmap', $where, __LINE__, __FILE__); 278 279 return $guid; 280 } 281 282 /** 283 * Puts a given client $locid and Horde server $guid pair into the 284 * map table to allow mapping between the client's and server's 285 * IDs. Actually there are two maps: from the localid to the guid 286 * and vice versa. The localid is converted to a key as follows: 287 * this->_locName . $this->_sourceURI . $type . $locid so you can 288 * have different syncs with different devices. If an entry 289 * already exists, it is overwritten. 290 */ 291 function setUID($type, $locid, $guid, $ts=0) 292 { 293 // fix $guid, it maybe was to long for some devices 294 // format is appname-id-systemid 295 $guidParts = explode('-',$guid); 296 if(count($guidParts) == 3) 297 { 298 $guid = $GLOBALS['egw']->common->generate_uid($guidParts[0],$guidParts[1]); 299 } 300 301 if($ts == 0) 302 { 303 $ts = time(); 304 } 305 306 #Horde::logMessage("SyncML: setUID $type, $locid, $guid, $ts ".count($guidParts), __FILE__, __LINE__, PEAR_LOG_DEBUG); 307 308 $db = clone($GLOBALS['egw']->db); 309 310 $mapID = $this->_locName . $this->_sourceURI . $type; 311 312 // delete all client id's 313 $where = array( 314 'map_id' => $mapID, 315 'map_locuid' => $locid, 316 ); 317 $db->delete('egw_contentmap', $where, __LINE__, __FILE__); 318 319 // delete all egw id's 320 $where = array( 321 'map_id' => $mapID, 322 'map_guid' => $guid, 323 ); 324 $db->delete('egw_contentmap', $where, __LINE__, __FILE__); 325 326 $data = $where + array( 327 'map_locuid' => $locid, 328 'map_timestamp' => $ts, 329 'map_expired' => 0, 330 ); 331 $db->insert('egw_contentmap', $data, $where, __LINE__, __FILE__); 332 333 #Horde::logMessage("SyncML: setUID $type, $locid, $guid, $ts $mapID", __FILE__, __LINE__, PEAR_LOG_DEBUG); 334 335 } 336 337 /** 338 * write clients device info to database 339 */ 340 function writeClientDeviceInfo() 341 { 342 if (!isset($this->_clientDeviceInfo) || !is_array($this->_clientDeviceInfo)) { 343 return false; 344 } 345 346 $deviceID = $this->_locName . $this->_sourceURI; 347 348 $data = array 349 ( 350 'dev_id' => $deviceID, 351 'dev_dtdversion' => $this->_clientDeviceInfo['DTDVersion'], 352 'dev_numberofchanges' => $this->_clientDeviceInfo['supportNumberOfChanges'], 353 'dev_largeobjs' => $this->_clientDeviceInfo['supportLargeObjs'], 354 'dev_swversion' => $this->_clientDeviceInfo['softwareVersion'], 355 'dev_oem' => $this->_clientDeviceInfo['oem'], 356 'dev_model' => $this->_clientDeviceInfo['model'], 357 'dev_manufacturer' => $this->_clientDeviceInfo['manufacturer'], 358 'dev_devicetype' => $this->_clientDeviceInfo['deviceType'], 359 'dev_deviceid' => $this->_clientDeviceInfo['deviceID'], 360 'dev_datastore' => serialize($this->_clientDeviceInfo['dataStore']), 361 ); 362 363 $where = array 364 ( 365 'dev_id' => $deviceID, 366 ); 367 368 $GLOBALS['egw']->db->insert('egw_syncmldevinfo', $data, $where, __LINE__, __FILE__); 369 } 370 371 /** 372 * After a successful sync, the client and server's Next Anchors 373 * are written to the database so they can be used to negotiate 374 * upcoming syncs. 375 */ 376 function writeSyncSummary() 377 { 378 #parent::writeSyncSummary(); 379 380 if (!isset($this->_serverAnchorNext) || !is_array($this->_serverAnchorNext)) { 381 return; 382 } 383 384 $deviceID = $this->_locName . $this->_sourceURI; 385 386 foreach((array)$this->_serverAnchorNext as $type => $a) 387 { 388 Horde::logMessage("SyncML: write SYNCSummary for $deviceID $type serverts: $a clients: ".$this->_clientAnchorNext[$type], __FILE__, __LINE__, PEAR_LOG_DEBUG); 389 390 $where = array 391 ( 392 'dev_id' => $deviceID, 393 'sync_path' => $type, 394 ); 395 396 $data = $where + array 397 ( 398 'sync_serverts' => $a, 399 'sync_clientts' => $this->_clientAnchorNext[$type] 400 ); 401 402 $GLOBALS['egw']->db->insert('egw_syncmlsummary', $data, $where, __LINE__, __FILE__); 403 } 404 } 405 406 407 } 408 409 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |