$database =
$this->normalize($databaseURI) in every backend method that deals
with databaseURIs and use $database afterwards. However actual usage of
options is up to the backend implementation. SyncML works fine without.
2) Suid and Guid mapping
This is the mapping of client IDs to server IDs and vice versa. Please
note that this map is per user and per client device: the server entry
[email protected] may have ID 720 in your PDA and AA10FC3A in
your mobile phone.
3) Sync Anchors
Exibir arquivo
Open project: horde/horde
Class Usage Examples
Public Properties
Property
Type
Description
$state
Horde_SyncMl_State
The State object.
Protected Properties
Property
Type
Description
$_backendMode
integer
The backend mode. One of the Horde_SyncMl_Backend::MODE_* constants.
$_charset
string
The charset used in the SyncML messages.
$_debugDir
string
The directory where debugging information is stored.
$_debugFiles
boolean
Whether to save SyncML messages in the debug directory.
$_logLevel
string
The log level.
$_logtext
string
The concatenated log messages.
$_syncDeviceID
string
This is used for all data access as an ID to allow to distinguish
between syncs with different devices. $this->_user together with
$this->_syncDeviceID is used as an additional key for all persistence
operations.
$_user
string
The current user.
Public Methods
Method
Description
__construct ( array $params )
Constructor.
addEntry ( string $databaseURI, string $content, string $contentType, string $cuid ) : array
Adds an entry into the server database.
checkAuthentication ( string &$username, string $credData, string $credFormat, string $credType ) : boolean | string
Authenticates the user at the backend.
close ( )
Cleanup public function called after all message processing is finished.
createUidMap ( string $databaseURI, string $cuid, string $suid, integer $timestamp )
Creates a map entry to map between server and client IDs.
deleteEntry ( string $databaseURI, string $cuid ) : boolean
Deletes an entry from the server database.
eraseMap ( string $databaseURI )
Erases all mapping entries for one combination of user, device ID.
factory ( string $driver, array $params = null ) : Horde_SyncMl_Backend
Attempts to return a concrete Horde_SyncMl_Backend instance based on $driver.
getCharset ( ) : string
Returns the charset.
getCurrentTimeStamp ( ) : mixed
Returns the current timestamp in the same format as used by
getServerChanges().
getParameter ( string $url, string $parameter, string $default = null )
Extracts an HTTP GET like parameter from an URL.
getServerChanges ( string $databaseURI, integer $from_ts, integer $to_ts, &$adds, &$mods, &$dels ) : mixed
Returns entries that have been modified in the server database.
getSyncDeviceID ( ) : string
Returns the current device's ID.
getUser ( ) : string
Returns the current user.
isValidDatabaseURI ( string $databaseURI ) : boolean
Returns whether a database URI is valid to be synced with this backend.
logFile ( integer $type, string $content, boolean $wbxml = false, boolean $sessionClose = false )
Logs data to a file in the debug directory.
logMessage ( mixed $message, integer $priority = 'INFO' )
Logs a message in the backend.
normalize ( string $databaseURI ) : string
Normalizes a databaseURI to a database name, so that
_normalize('tasks?ignorecompleted') should return just 'tasks'.
readSyncAnchors ( string $databaseURI ) : mixed
Reads the previously written sync anchors from the database.
replaceEntry ( string $databaseURI, string $content, string $contentType, string $cuid ) : string
Replaces an entry in the server database.
retrieveEntry ( string $databaseURI, string $suid, string $contentType, array $fields ) : mixed
Retrieves an entry from the backend.
sessionClose ( )
Closes the PHP session.
sessionStart ( string $syncDeviceID, $sessionId, integer $backendMode = Horde_SyncMl_Backend::MODE_SERVER )
Starts a PHP session.
setCharset ( string $charset )
Sets the charset.
setUser ( string $user )
Sets the user used for this session.
setupState ( )
Is called after the Horde_SyncMl_State object has been set up, either
restored from the session, or freshly created.
testSetup ( string $user, string $pwd )
Creates a clean test environment in the backend.
testStart ( string $user )
Prepares the test start.
testTearDown ( )
Tears down the test environment after the test is run.
writeSyncAnchors ( string $databaseURI, string $clientAnchorNext, string $serverAnchorNext )
Stores Sync anchors after a successful synchronization to allow two-way
synchronization next time.
Protected Methods
Method
Description
_checkAuthentication ( string $username, string $password ) : boolean | string
Authenticates the user at the backend.
_setAuthenticated ( string $username, string $credData ) : string
Sets a user as being authenticated at the backend.
Method Details
Sets up the default logging mechanism.
public __construct ( array $params )
$params
array
A hash with parameters. The following are
supported by the default implementation.
Individual backends may support other parameters.
- debug_dir: A directory to write debug output
to. Must be writeable by the web
server.
- debug_files: If true, log all incoming and
outgoing packets and data
conversions and devinf log in
debug_dir.
- log_level: Only log entries with at least
this level. Defaults to 'INFO'.
Authenticates the user at the backend.
Sets a user as being authenticated at the backend.
Adds an entry into the server database.
public addEntry ( string $databaseURI, string $content, string $contentType, string $cuid ) : array
$databaseURI
string
URI of Database to sync. Like calendar,
tasks, contacts or notes. May include
optional parameters:
tasks?options=ignorecompleted.
$content
string
The actual data.
$contentType
string
MIME type of the content.
$cuid
string
Client ID of this entry.
return
array
PEAR_Error or suid (Horde guid) of new entry
For some types of authentications (notably auth:basic) the username
gets extracted from the authentication data and is then stored in
username. For security reasons the caller must ensure that this is the
username that is used for the session, overriding any username
specified in .
public checkAuthentication ( string &$username, string $credData, string $credFormat, string $credType ) : boolean | string
$username
string
Username as provided in the .
May be overwritten by $credData.
$credData
string
Authentication data provided by
in the .
$credFormat
string
Format of data as in
the . Typically 'b64'.
$credType
string
Auth type as provided by
in the . Typically
'syncml:auth-basic'.
return
boolean | string
The user name if authentication succeeded, false
otherwise.
Allows for things like closing databases or flushing logs. When
running in test mode, tearDown() must be called rather than close.
public close ( )
If an entry already exists, it is overwritten.
public createUidMap ( string $databaseURI, string $cuid, string $suid, integer $timestamp )
$databaseURI
string
URI of database to sync. Like calendar,
tasks, contacts or notes. May include
optional parameters:
tasks?options=ignorecompleted.
$cuid
string
Client ID of the entry.
$suid
string
Server ID of the entry.
$timestamp
integer
Optional timestamp. This can be used to
'tag' changes made in the backend during the
sync process. This allows to identify these,
and ensure that these changes are not
replicated back to the client (and thus
duplicated). See key concept "Changes and
timestamps".
Deletes an entry from the server database.
public deleteEntry ( string $databaseURI, string $cuid ) : boolean
$databaseURI
string
URI of Database to sync. Like calendar,
tasks, contacts or notes. May include
optional parameters:
tasks?options=ignorecompleted.
$cuid
string
Client ID of the entry.
return
boolean
True on success or false on failed (item not found).
This is used during SlowSync so that we really sync everything properly
and no old mapping entries remain.
Attempts to return a concrete Horde_SyncMl_Backend instance based on $driver.
public factory ( string $driver, array $params = null ) : Horde_SyncMl_Backend
$driver
string
The type of concrete Backend subclass to return.
The code is dynamically included from
Backend/$driver.php if no path is given or
directly with "include_once $driver . '.php'"
if a path is included. So make sure this parameter
is "safe" and not directly taken from web input.
The class in the file must be named
'Horde_SyncMl_Backend_' . basename($driver) and extend
Horde_SyncMl_Backend.
$params
array
A hash containing any additional configuration or
connection parameters a subclass might need.
return
Horde_SyncMl_Backend
The newly created concrete Horde_SyncMl_Backend
instance, or false on an error.
Returns the charset.
public getCharset ( ) : string
return
string
The charset used when talking to the backend.
Backends can use their own way to represent timestamps, like unix epoch
integers or UTC Datetime strings.
public getCurrentTimeStamp ( ) : mixed
return
mixed
A timestamp of the current time.
Example: getParameter('test?q=1', 'q') == 1
Returns entries that have been modified in the server database.
public getServerChanges ( string $databaseURI, integer $from_ts, integer $to_ts, &$adds, &$mods, &$dels ) : mixed
$databaseURI
string
URI of Database to sync. Like calendar,
tasks, contacts or notes. May include
optional parameters:
tasks?options=ignorecompleted.
$from_ts
integer
Start timestamp.
$to_ts
integer
Exclusive end timestamp. Not yet
implemented.
return
mixed
True on success or a PEAR_Error object.
Returns the current device's ID.
public getSyncDeviceID ( ) : string
return
string
The device ID.
Returns the current user.
This default implementation accepts "tasks", "calendar", "notes" and
"contacts". However individual backends may offer replication of
different or completly other databases (like browser bookmarks or
cooking recipes).
public isValidDatabaseURI ( string $databaseURI ) : boolean
$databaseURI
string
URI of a database. Like calendar, tasks,
contacts or notes. May include optional
parameters:
tasks?options=ignorecompleted.
return
boolean
True if a valid URI.
Logs data to a file in the debug directory.
public logFile ( integer $type, string $content, boolean $wbxml = false, boolean $sessionClose = false )
$type
integer
The data type. One of the Horde_SyncMl_Backend::LOGFILE_*
constants.
$content
string
The data content.
$wbxml
boolean
Whether the data is wbxml encoded.
$sessionClose
boolean
Whether this is the last SyncML message
in a session. Bump the file number.
TODO: This should be done via Horde_Log or the equivalent.
public logMessage ( mixed $message, integer $priority = 'INFO' )
$message
mixed
Either a string or a PEAR_Error object.
$priority
integer
The priority of the message. One of:
- EMERG
- ALERT
- CRIT
- ERR
- WARN
- NOTICE
- INFO
- DEBUG
Normalizes a databaseURI to a database name, so that
_normalize('tasks?ignorecompleted') should return just 'tasks'.
Reads the previously written sync anchors from the database.
public readSyncAnchors ( string $databaseURI ) : mixed
$databaseURI
string
URI of database to sync. Like calendar,
tasks, contacts or notes. May include
optional parameters:
tasks?options=ignorecompleted.
return
mixed
Two-element array with client anchor and server anchor as
stored in previous writeSyncAnchor() calls. False if no
data found.
Replaces an entry in the server database.
public replaceEntry ( string $databaseURI, string $content, string $contentType, string $cuid ) : string
$databaseURI
string
URI of Database to sync. Like calendar,
tasks, contacts or notes. May include
optional parameters:
tasks?options=ignorecompleted.
$content
string
The actual data.
$contentType
string
MIME type of the content.
$cuid
string
Client ID of this entry.
return
string
PEAR_Error or server ID (Horde GUID) of modified entry.
Retrieves an entry from the backend.
public retrieveEntry ( string $databaseURI, string $suid, string $contentType, array $fields ) : mixed
$databaseURI
string
URI of Database to sync. Like calendar,
tasks, contacts or notes. May include
optional parameters:
tasks?options=ignorecompleted.
$suid
string
Server unique id of the entry: for horde
this is the guid.
$contentType
string
Content-Type: the MIME type in which the
public function should return the data.
$fields
array
Hash of field names and Horde_SyncMl_Property
properties with the requested fields.
return
mixed
A string with the data entry or a PEAR_Error object.
Starts a PHP session.
public sessionStart ( string $syncDeviceID, $sessionId, integer $backendMode = Horde_SyncMl_Backend::MODE_SERVER )
$syncDeviceID
string
The device ID.
$backendMode
integer
The backend mode, one of the
Horde_SyncMl_Backend::MODE_* constants.
All data passed to the backend uses this charset and data returned from
the backend must use this charset, too.
public setCharset ( string $charset )
$charset
string
A valid charset.
This method is called by SyncML right after sessionStart() when either
authentication is accepted via checkAuthentication() or a valid user
has been retrieved from the state. $this->_user together with
$this->_syncDeviceID is used as an additional key for all persistence
operations.
This method may have to force a "login", when the backend doesn't keep
auth state within a session or when in test mode.
Is called after the Horde_SyncMl_State object has been set up, either
restored from the session, or freshly created.
public setupState ( )
Ensures there's a user with the given credentials and an empty data
store.
Prepares the test start.
Tears down the test environment after the test is run.
public testTearDown ( )
The backend has to store the parameters in its persistence engine
where user, syncDeviceID and database are the keys while client and
server anchor ar the payload. See readSyncAnchors() for retrieval.
public writeSyncAnchors ( string $databaseURI, string $clientAnchorNext, string $serverAnchorNext )
$databaseURI
string
URI of database to sync. Like calendar,
tasks, contacts or notes. May include
optional parameters:
tasks?options=ignorecompleted.
$clientAnchorNext
string
The client anchor as sent by the
client.
$serverAnchorNext
string
The anchor as used internally by the
server.
Property Details
The backend mode. One of the Horde_SyncMl_Backend::MODE_* constants.
protected int $_backendMode
return
integer
The charset used in the SyncML messages.
protected string $_charset
return
string
The directory where debugging information is stored.
protected string $_debugDir
return
string
Whether to save SyncML messages in the debug directory.
protected bool $_debugFiles
return
boolean
The concatenated log messages.
protected string $_logtext
return
string
This is used for all data access as an ID to allow to distinguish
between syncs with different devices. $this->_user together with
$this->_syncDeviceID is used as an additional key for all persistence
operations.
protected string $_syncDeviceID
return
string