Location: PHPKode > projects > phpSyncML > phpsyncml/index.php
head     1.1;
branch   1.1.1;
access   ;
symbols  start:1.1.1.1 vendor:1.1.1;
locks    ; strict;
comment  @# @;


1.1
date     2005.09.12.14.01.44;  author cyberpunk1971;  state Exp;
branches 1.1.1.1;
next     ;

1.1.1.1
date     2005.09.12.14.01.44;  author cyberpunk1971;  state Exp;
branches ;
next     ;


desc
@@



1.1
log
@Initial revision
@
text
@
#########################################
########################################
#
#    PHPSyncML API
#   phpsyncml.sourceforge.net
#
#   Copyrighted under GPL 2006
#
######################################
#######################################
<?
// Let's parse the config file and get our settings
$config = simplexml_load_file('config/config.xml');
$compression =$config->config->compression;
$base_dir = $config->config->base_dir;
$dbuser = $config->config->database->dbuser;
$dbpass = $config->config->database->dbpass;
$dbtype = $config->config->database->dbtype;

// Import our external resources
include("get_response.php");
dl('wbxml.so');

// Make sure its a syncml request (comment for testing)
#if (@@$_SERVER["CONTENT_TYPE"] != "application/vnd.syncml+wbxml") { 
#	echo "<html>I only speak SyncML.</html>";
#	exit();
#}

//Lets open our log file for debugging purposes
$handler = fopen("progress.xml", "a+");

// assign POST data to variable (comment out for debugging)
#$post_data = $HTTP_RAW_POST_DATA;

// For debugging purposes use predefined wbxml file
if ($hand = fopen($base_dir.'/wbxml/docs/examples/syncml_client_packet_3.wbxml', 'a+')) {
	//echo "opened\n";
} else {
	echo "error";
}

$post_data = fread($hand,filesize($base_dir.'/wbxml/docs/examples/syncml_client_packet_3.wbxml'));

//echo $post_data;

// Extract data
if ($compression == 'xml') {
	$xmlsh = $post_data;
	fwrite($handler,$post_data);
} else {
	$xmlsh = wbxml2xml($post_data);
	// print_r($xmlsh);
	fwrite($handler, $xmlsh);
}

// Load our response into a simplexml object
$xmls = simplexml_load_string($xmlsh);


$synchdr = $xmls->SyncHdr;
$syncbod = $xmls->SyncBody;
$sessid = $synchdr->SessionID;
$mesgid = $synchdr->MsgID;
$source = $synchdr->Source->LocURI;
$i = 1;
$put_response = "<Status><CmdID>$i</CmdID><MsgRef>$mesgid</MsgRef><CmdRef>".$syncbod->Put->CmdID."</CmdRef><Cmd>Put</Cmd><TargetRef>http://128.8.10.81/syncml/index.php</TargetRef><SourceRef>".$syncbod->Put->Item->Source->LocURI."</SourceRef><Data>200</Data></Status>";
header("Content-Type: application/vnd.syncml+xml");
header("Accept-Charset: UTF-8");

$header = "<?xml version='1.0' encoding=\"UTF-8\"?>
<!DOCTYPE SyncML PUBLIC \"-//SYNCML//DTD SyncML 1.1//EN\" \"http://www.syncml.org/docs/syncml_represent_v11_20020213.dtd\">
<SyncML xmlns='SYNCML:SYNCML1.1'><SyncHdr><VerDTD>1.1</VerDTD><VerProto>SyncML/1.1</VerProto><SessionID>".$sessid."</SessionID><MsgID>".$mesgid."</MsgID><Target><LocURI>".$source."</LocURI></Target><Source><LocURI>http://128.8.10.81/syncml/sync.php</LocURI></Source><Meta><MaxMsgSize xmlns='syncml:metinf'>10000</MaxMsgSize></Meta></SyncHdr><SyncBody>";

$send = $header;

#if ($synchdr->Cred->Data != "") {
	$content = "<Status><CmdID>$i</CmdID><MsgRef>$mesgid</MsgRef><CmdRef>0</CmdRef><Cmd>SyncHdr</Cmd><TargetRef>http://128.8.10.81/syncml/index.php</TargetRef><SourceRef>$source</SourceRef><Data>212</Data></Status>";
	$send .= $content;
	$i++;
#}

$put_response = "<Status><CmdID>$i</CmdID><MsgRef>$mesgid</MsgRef><CmdRef>".$syncbod->Put->CmdID."</CmdRef><Cmd>Put</Cmd><TargetRef>http://128.8.10.81/syncml/index.php</TargetRef><SourceRef>".$syncbod->Put->Item->Source->LocURI."</SourceRef><Data>200</Data></Status>";

foreach($syncbod->children() as $key => $value) {
	#echo $key."\n";
	switch ($key) {
		case "Put":
			$send .= $put_response;
			$i++;
			break;
		case "Get":
			$gets = get_response($i,$source,$syncbod->$key->CmdID,$mesgid);
			$send .= $gets;
			$i++;
			break;
		case "Alert":
			$alerts = alert_response($i,$syncbod->$key->CmdID,$mesgid);
			$send .= $alerts;
			$i++;
			break;
		case "Status":
			$status = status_response($i,$syncbod->$key->CmdID,$mesgid);
			$send .= $status;
			$i++;
			break;
		case "Sync":
			$sync = "<Sync><CmdID>$i</CmdID><Target><LocURI>./contact</LocURI></Target><Source><LocURI>contact</LocURI></Source>";
			$send .= $sync;
			$i++;
			foreach($syncbod->Sync->children() as $skey => $svalue) {
				
				switch ($skey) {
					case "Add":
						add_contact();
						$i++;
						break;
					case "Replace":
						replace_contact();
						$i++;
						break;
					case "Delete":
						delete_contact();
						$i++;
						break;
					default:
						break;
				}
			}
			$send .= "</Sync>";
			break;
		default:
			break;
	}
	
}
$send .= "<Final/></SyncBody></SyncML>";
//$sent = xml2wbxml($send);
fwrite($handler, $send);
//exec("xml2wbxml -o output2.xml progress_2.xml");
//echo $sent;
echo $send;

fclose($handler);
?>@


1.1.1.1
log
@Initial import.
@
text
@@
Return current item: phpSyncML