PageRenderTime 81ms CodeModel.GetById 50ms RepoModel.GetById 0ms app.codeStats 0ms

/ext/flashremoting/lib/typo3/class.flashremoting_base.php

https://github.com/elhakim22003/TypoFlash
PHP | 742 lines | 303 code | 141 blank | 298 comment | 45 complexity | 9a43e0ddce27dc31f4256c8ba8565995 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*if (!extension_loaded('sockets.so') && TYPO3_OS !="WIN") {
  3. //dl loads the extension at runtime
  4. if(!@dl('sockets.so')){
  5. return false;
  6. }
  7. }*/
  8. class flashremoting_base {
  9. function flashremoting_base(){
  10. //constructor
  11. /*
  12. These need to be set in typo3_remoting_config.php which need to be included in each class extending this one
  13. */
  14. //if(isset(RELAY_HOST)){
  15. $this->relayHost = RELAY_HOST;
  16. /*
  17. }else{
  18. $this->relayHost = "localhost";
  19. }
  20. */
  21. //if(isset(RELAY_PORT)){
  22. $this->relayPort = RELAY_PORT;
  23. /*
  24. }else{
  25. $this->relayPort = "8800";
  26. }
  27. */
  28. /*
  29. Method table was removed in AMFPHP 1.9
  30. $this->methodTable = array(
  31. "getActiveFEUser" => array(
  32. "description" => "Returns all data on active FE user",
  33. "access" => "remote"
  34. ),
  35. "getActiveBEUser" => array(
  36. "description" => "Returns all data on active BE user",
  37. "access" => "remote"
  38. ),
  39. "BElogin" => array(
  40. "description" => "Returns object with prop username, first_name, uid,user_groups, relaySuccess (boolean if applicable) of currently logged in typo3 front end user. For functions with roles you must set setCredentials('BEuser') first!",
  41. "access" => "remote"
  42. ),
  43. "FElogin" => array(
  44. "description" => "Returns object with prop username, first_name, uid,user_groups, relaySuccess (boolean if applicable) of currently logged in typo3 front end user. For functions with roles you must set setCredentials('FEuser') first!",
  45. "access" => "remote"
  46. ),
  47. "BElogout" => array(
  48. "description" => "Logs user out of typo3 BE",
  49. "access" => "remote"
  50. ),
  51. "FElogout" => array(
  52. "description" => "Logs user out of typo3 FE",
  53. "access" => "remote"
  54. ),
  55. "remotingLogout" => array(
  56. "description" => "Logs user out of remoting authentication service",
  57. "access" => "remote"
  58. ),
  59. "getCookie" => array(
  60. "description" => "Temp function. Delete!!!!",
  61. "access" => "remote"
  62. )
  63. );
  64. */
  65. /*
  66. //Check if remoting is installed otherwise die
  67. if(!t3lib_extMgm::isLoaded('flashremoting')){
  68. $this->methodTable ='';
  69. }*/
  70. }
  71. /*
  72. This function will authenticate the client before return the value of method call. It is called with the autheticate method in Flash. It is sent on the headers first.
  73. The order is significant. We are assuming that all functions available to FE user is available to BE user.
  74. Specific template level configurations need to be implemented to deal with cases where FE user is doing BE stuff (like FE editing) and vice versa (BE chat).
  75. Changed: Now you have to send role you wish to appear as before calling access limited functions.
  76. */
  77. /*
  78. 20/03/2008
  79. Disabled in AMFPHP 1.9.
  80. Not really needed as long as strict checks are maintained inside the different functions themselves
  81. function _authenticate($role){
  82. if(($role = 'BEuser') && $GLOBALS["BE_USER"]->user['uid']>0){
  83. return "BEuser";
  84. }else if(($role = 'FEuser') && $GLOBALS["FE_USER"]->user['uid']>0){
  85. return "FEuser";
  86. } else {
  87. return false;
  88. }
  89. }*/
  90. function remotingLogout() {
  91. Authenticate::logout();
  92. }
  93. function BElogout() {
  94. $oldUid = $GLOBALS['BE_USER']->user['uid'];
  95. $oldLocation = $GLOBALS['BE_USER']->user['pid'];
  96. $err = $GLOBALS['BE_USER']->logoff();
  97. if (method_exists($this, '_onBElogout')) {
  98. $this->_onBElogout($oldUid, $oldLocation);
  99. }
  100. return $err;
  101. }
  102. function FElogout() {
  103. $oldUid = $GLOBALS['FE_USER']->user['uid'];
  104. $oldLocation = $GLOBALS['FE_USER']->user['pid'];
  105. $err = $GLOBALS['FE_USER']->logoff();
  106. if (method_exists($this, '_onFElogout')) {
  107. $this->_onFElogout($oldUid, $oldLocation);
  108. }
  109. return $err;
  110. }
  111. function getActiveFEuser(){
  112. //return $GLOBALS['R_SQL'];
  113. //return 's FE_loginstatus';
  114. if(is_array($GLOBALS['FE_USER']->user)){
  115. $GLOBALS['FE_USER']->user['remoting_session'] = session_id();
  116. $arr = $GLOBALS['FE_USER']->user;
  117. $arr["password"]="secret";
  118. return $arr;
  119. }else{
  120. return false;
  121. }
  122. }
  123. function getActiveBEuser(){
  124. if($GLOBALS["BE_USER"]->user['uid']>0){
  125. if($GLOBALS['BE_loginstatus'] <0){
  126. //login error from tsfebeuserauth
  127. //errortype 1 usererror, 2 server error
  128. $error = array("errortype"=>2,"errormsg"=>"You have been logged out of BE. Status: ".$GLOBALS['BE_loginstatus']);
  129. return $error;
  130. }
  131. $GLOBALS["BE_USER"]->user['remoting_session'] = session_id();
  132. $GLOBALS['TYPO3_DB']->exec_UPDATEquery('be_sessions',
  133. 'ses_id="'.$GLOBALS['TYPO3_DB']->quoteStr($GLOBALS["BE_USER"]->id, 'be_sessions').'"
  134. AND ses_name="'.$GLOBALS['TYPO3_DB']->quoteStr($GLOBALS["BE_USER"]->name, 'be_sessions').'"',
  135. array('ses_tstamp' => $GLOBALS['EXEC_TIME'])
  136. );
  137. $arr = $GLOBALS["BE_USER"]->user;
  138. $t = explode(' ',$arr['realName']);
  139. if(strlen($t[0])>0){
  140. $arr["first_name"]=$t[0];
  141. }
  142. if(strlen($t[1])>0){
  143. $arr["last_name"]=$t[1];
  144. }
  145. $arr["password"]="secret";
  146. $arr["uc"] = unserialize($arr["uc"]);
  147. return $arr;
  148. }else{
  149. return false;
  150. }
  151. }
  152. function FElogin($usr,$psw,$salt=null){
  153. //don't know why this breaks with remoting..but remember that
  154. //all ordinary classes are included before flash starts due to tx_typoflash page rendering
  155. //$GLOBALS['FE_USER']->lockToDomain = false;//don't know why this breaks with remoting...fix later!
  156. if($salt != null){
  157. $security_level = 'challenged';
  158. }
  159. $this->initFEuser($usr,$psw,$salt,'login',$security_level);
  160. /*if (is_array($GLOBALS['FE_USER']->user)) {
  161. $GLOBALS['TYPO3_DB']->exec_UPDATEquery('fe_users', 'uid='.intval($GLOBALS['FE_USER']->user['uid']), array('is_online' => 1));
  162. }*/
  163. //return $GLOBALS['R_SQL'];
  164. if(is_array($GLOBALS['FE_USER']->user)){
  165. //set status available
  166. //$GLOBALS['TYPO3_DB']->exec_UPDATEquery('fe_users', 'uid='.intval($GLOBALS['FE_USER']->user['uid']), array('status' => 2));
  167. $arr = $this->getActiveFEUser();
  168. if (method_exists($this, '_onFELogin')) {
  169. $arr['relaySuccess'] = $this->_onFELogin(true, $GLOBALS['FE_USER']->user);
  170. }
  171. return $arr;
  172. }else{
  173. if (method_exists($this, '_onFELogin')) {
  174. $this->_onFELogin(false);
  175. }
  176. return false;
  177. }
  178. }
  179. function BElogin($usr, $psw,$salt=null){
  180. //if($GLOBALS['BE_USER'] == null){
  181. require_once('class.flashremoting_beuserauth.php');
  182. $GLOBALS['BE_USER'] = t3lib_div::makeInstance('flashremoting_beuserauth');
  183. //}
  184. $GLOBALS['BE_USER']->formfield_status = "login";
  185. $GLOBALS['BE_USER']->remote_usr = $usr;
  186. $GLOBALS['BE_USER']->remote_psw = $psw;
  187. $GLOBALS['BE_USER']->remote_chalvalue = $salt;
  188. if($salt != null){
  189. $GLOBALS['BE_USER']->security_level = 'challenged';
  190. }
  191. $this->initBEuser();
  192. /*$GLOBALS["BE_USER"] = t3lib_div::makeInstance('flashremoting_beuserauth'); // New backend user object
  193. $GLOBALS["BE_USER"]->sendNoCacheHeaders = false;
  194. $GLOBALS["BE_USER"]->lockIP = false;
  195. $GLOBALS["BE_USER"]->checkPid = 0;
  196. $GLOBALS["BE_USER"]->auth_timeout_field = 60000;
  197. $GLOBALS["BE_USER"]->formfield_status = "login";
  198. $GLOBALS["BE_USER"]->remote_usr = $usr;
  199. $GLOBALS["BE_USER"]->remote_psw = $psw;
  200. $GLOBALS["BE_USER"]->check_authentication();*/
  201. //return array("status:"=>$GLOBALS['BE_loginstatus'],"user id"=>$GLOBALS["BE_USER"]->user['uid'],"sql:"=> $GLOBALS['R_SQL']);
  202. if($GLOBALS["BE_USER"]->user['uid']>0){
  203. $arr = $this->getActiveBEUser();
  204. if (method_exists($this, '_onBELogin')) {
  205. $arr['relaySuccess'] = $this->_onBELogin(true, $GLOBALS['BE_USER']->user);
  206. }
  207. return $arr;
  208. }else{
  209. if (method_exists($this, '_onBELogin')) {
  210. $this->_onBELogin(false);
  211. }
  212. return false;
  213. }
  214. }
  215. function getCookie(){
  216. return $_COOKIE;
  217. }
  218. function initFEuser($usr=null,$psw=null,$salt=null,$formfield_status=null,$security_level=null){
  219. require_once('class.flashremoting_feuserauth.php');
  220. if($GLOBALS['FE_USER'] == null){
  221. $GLOBALS['FE_USER'] = t3lib_div::makeInstance('flashremoting_feuserauth');
  222. }
  223. global $FE_USER;
  224. $FE_USER->formfield_status = $formfield_status;
  225. $FE_USER->remote_usr = $usr;
  226. $FE_USER->remote_psw = $psw;
  227. $FE_USER->remote_chalvalue = $salt;
  228. $FE_USER->security_level = $security_level;
  229. //$FE_USER->lockIP = $GLOBALS['TSFE']->TYPO3_CONF_VARS['FE']['lockIP'];
  230. $FE_USER->checkPid = 0;//borg. disabled checking of pid for logins...dunno where I woudl get it
  231. /*$FE_USER->checkPid = $GLOBALS['TSFE']->TYPO3_CONF_VARS['FE']['checkFeUserPid'];
  232. $FE_USER->checkPid_value = $GLOBALS['TYPO3_DB']->cleanIntList(t3lib_div::_GP('pid')); // List of pid's acceptable*/
  233. // Check if a session is transferred:
  234. if (t3lib_div::_GP('FE_SESSION_KEY')) {
  235. $fe_sParts = explode('-',t3lib_div::_GP('FE_SESSION_KEY'));
  236. /*if (!strcmp(md5($fe_sParts[0].'/'.$this->TYPO3_CONF_VARS['SYS']['encryptionKey']), $fe_sParts[1])) { // If the session key hash check is OK:
  237. $GLOBALS['HTTP_COOKIE_VARS'][$GLOBALS['FE_USER']->name]=$fe_sParts[0];
  238. $FE_USER->forceSetCookie=1;
  239. }*/
  240. }
  241. /*if ($GLOBALS['TSFE']->TYPO3_CONF_VARS['FE']['dontSetCookie']) {
  242. $FE_USER->dontSetCookie=1;
  243. }*/
  244. $FE_USER->auth_timeout_field = 60000;
  245. //$FE_USER->sendNoCacheHeaders = false;
  246. //$FE_USER->lockIP = false;
  247. $FE_USER->user['ses_tstamp'] = $GLOBALS['EXEC_TIME'];
  248. $FE_USER->user['disableIPlock'] = true;
  249. $FE_USER->start();
  250. $FE_USER->unpack_uc('');
  251. $FE_USER->fetchSessionData(); // Gets session data
  252. $recs = t3lib_div::_GP('recs');
  253. if (is_array($recs)) { // If any record registration is submitted, register the record.
  254. $FE_USER->record_registration($recs);
  255. }
  256. // For every 60 seconds the is_online timestamp is updated.
  257. if (is_array($FE_USER->user) && $FE_USER->user['is_online']<($GLOBALS['EXEC_TIME']-60)) {
  258. $GLOBALS['TYPO3_DB']->exec_UPDATEquery('fe_users', 'uid='.intval($FE_USER->user['uid']), array('is_online' => $GLOBALS['EXEC_TIME']));
  259. }
  260. }
  261. function initBEuser(){
  262. $TYPO3_MISC['microtime_BE_USER_start'] = microtime();
  263. global $BE_USER;
  264. //borg+
  265. //tricks,hacks and wild guesses
  266. $BE_USER->sendNoCacheHeaders = false;
  267. $BE_USER->lockIP = false;
  268. $BE_USER->checkPid = 0;
  269. //$BE_USER->dontSetCookie = true;
  270. $BE_USER->auth_timeout_field = 60000;
  271. $BE_USER->user['ses_tstamp'] = $GLOBALS['EXEC_TIME'];
  272. $BE_USER->OS = TYPO3_OS;
  273. $ERR = $BE_USER->start(); // Object is initialized
  274. return $ERR;
  275. $BE_USER->unpack_uc('');
  276. //borg-
  277. if ($BE_USER->user['uid']) {
  278. $BE_USER->fetchGroupData();
  279. //$TSFE->beUserLogin = 1;
  280. }
  281. if ($BE_USER->checkLockToIP() && $BE_USER->checkBackendAccessSettingsFromInitPhp()) {
  282. $BE_USER->extInitFeAdmin();
  283. if ($BE_USER->extAdmEnabled) {
  284. //require_once(t3lib_extMgm::extPath('lang').'lang.php');
  285. //echo t3lib_extMgm::isLoaded('cms');
  286. //$LANG = t3lib_div::makeInstance('language');
  287. //$LANG->init($BE_USER->uc['lang']);
  288. //$BE_USER->extSaveFeAdminConfig();
  289. // Setting some values based on the admin panel
  290. /*$TSFE->forceTemplateParsing = $BE_USER->extGetFeAdminValue('tsdebug', 'forceTemplateParsing');
  291. $TSFE->displayEditIcons = $BE_USER->extGetFeAdminValue('edit', 'displayIcons');
  292. $TSFE->displayFieldEditIcons = $BE_USER->extGetFeAdminValue('edit', 'displayFieldIcons');
  293. if (t3lib_div::_GP('ADMCMD_editIcons')) {
  294. $TSFE->displayFieldEditIcons=1;
  295. $BE_USER->uc['TSFE_adminConfig']['edit_editNoPopup']=1;
  296. }
  297. if (t3lib_div::_GP('ADMCMD_simUser')) {
  298. $BE_USER->uc['TSFE_adminConfig']['preview_simulateUserGroup']=intval(t3lib_div::_GP('ADMCMD_simUser'));
  299. $BE_USER->ext_forcePreview=1;
  300. }
  301. if (t3lib_div::_GP('ADMCMD_simTime')) {
  302. $BE_USER->uc['TSFE_adminConfig']['preview_simulateDate']=intval(t3lib_div::_GP('ADMCMD_simTime'));
  303. $BE_USER->ext_forcePreview=1;
  304. }
  305. */
  306. // Include classes for editing IF editing module in Admin Panel is open (it is assumed that $TSFE->displayEditIcons is set only if the Edit module is open in the Admin Panel)
  307. /*if ($BE_USER->extAdmModuleEnabled('edit') && $BE_USER->extIsAdmMenuOpen('edit')) {
  308. $TSFE->includeTCA();
  309. if ($BE_USER->extIsEditAction()) {
  310. require_once (PATH_t3lib.'class.t3lib_tcemain.php');
  311. $BE_USER->extEditAction();
  312. }
  313. if ($BE_USER->extIsFormShown()) {
  314. require_once(PATH_t3lib.'class.t3lib_tceforms.php');
  315. require_once(PATH_t3lib.'class.t3lib_iconworks.php');
  316. require_once(PATH_t3lib.'class.t3lib_loaddbgroup.php');
  317. require_once(PATH_t3lib.'class.t3lib_transferdata.php');
  318. }
  319. }*/
  320. //if ($TSFE->forceTemplateParsing || $TSFE->displayEditIcons || $TSFE->displayFieldEditIcons) { $TSFE->set_no_cache(); }
  321. }
  322. // $WEBMOUNTS = (string)($BE_USER->groupData['webmounts'])!='' ? explode(',',$BE_USER->groupData['webmounts']) : Array();
  323. // $FILEMOUNTS = $BE_USER->groupData['filemounts'];
  324. } else { // Unset the user initialization.
  325. $BE_USER='';
  326. }
  327. $TYPO3_MISC['microtime_BE_USER_end'] = microtime();
  328. }
  329. /*
  330. This function will pass the result of a remoting call on to
  331. the remoting relay server (xml socket) specified in host and port.
  332. *************
  333. REQUEST TYPES
  334. *************
  335. *************
  336. server_instruction: remoting server instucting relay server
  337. Example:
  338. <request type="server_instruction" client="remoting_server" authentication="k1k2j3h1k23h">
  339. <node id="function" value="addUser"/>
  340. <arg name="location" value="21"/>
  341. <arg name="user" value="1"/>
  342. </request>
  343. All args will be repackaged as an array and passed as second argument after clientId to function.
  344. *************
  345. server_broadcast: remoting server pushing data out via relay
  346. Example 1 - server_broadcast : Remoting server call to flash function
  347. <request type="server_broadcast" client="remoting_server" authentication="k1k2j3h1k23h">
  348. <node id="relay_destination" location="21"/>
  349. <node id="relay_data">
  350. <response type="server_broadcast" origin="remoting_server">
  351. <node id="function" value="onReceivedMsg"/>
  352. <arg name="msg" type="cdata" >
  353. <![CDATA[Nice and quiet today]]>
  354. </arg>
  355. <arg name="channel" value="0"/>
  356. </response>
  357. </node>
  358. </request>
  359. Example 2 - relayed_service_call: Remoting server request of flash to make subsequent remoting callback
  360. <request type="server_broadcast" client="remoting_server" authentication="k1k2j3h1k23h">
  361. <node id="relay_destination" user="112"/>
  362. <node id="relay_data">
  363. <response type="relayed_service_call" origin="remoting_server">
  364. <node id="service" value="multiuser_server.mus_usermanagement"/>
  365. <node id="function" value="refreshUserlist"/>
  366. <arg name="channel" value="0"/>
  367. </response>
  368. </node>
  369. </request>
  370. Example 3 - wddx: Remoting server sending WDDX data straight back to flash
  371. <request type="server_broadcast" client="remoting_server" authentication="k1k2j3h1k23h">
  372. <node id="relay_destination" user="112"/>
  373. <node id="relay_data">
  374. <response type="wddx" origin="remoting_server">
  375. //wddx serialized xml
  376. </response>
  377. </node>
  378. </request>
  379. </response>
  380. *************
  381. client_request: requests directly from clients
  382. Example:
  383. <request type="client_request" client="flash" authentication="k1k2j3h1k23h">
  384. <node id="function" value="identifyClient" />
  385. <arg name="location" value="21" />
  386. <arg name="user" value="1" />
  387. </request>
  388. */
  389. function relayBroadcast($type=null,$obj=null){
  390. $this->sock = @socket_create( AF_INET, SOCK_STREAM, 0 );
  391. if( !$this->sock){
  392. return false;
  393. }
  394. // bind the socket
  395. //possible to specify port as last argument, by which we could lock remoting server down to one port
  396. if( !@socket_bind( $this->sock,$this->relayHost) ){
  397. return false;
  398. }
  399. $xml_root = domxml_new_doc('1.0');
  400. $requestNode = $xml_root->append_child($xml_root->create_element('request'));
  401. $requestNode->set_attribute('type',$type);
  402. $requestNode->set_attribute('client','remoting_server');
  403. $requestNode->set_attribute('authentication','1234');//improve later
  404. switch( $type ){
  405. case "server_instruction":
  406. /*
  407. <request type="server_instruction" client="remoting_server" authentication="k1k2j3h1k23h">
  408. <node id="function" value="addUser"/>
  409. <arg name="location" value="21"/>
  410. <arg name="user" value="1"/>
  411. </request>
  412. */
  413. if(is_string($obj['func'])){
  414. $funcNode = $requestNode->append_child($xml_root->create_element('node'));
  415. $funcNode->set_attribute('id','function');
  416. $funcNode->set_attribute('value',$obj['func']);
  417. }
  418. if(is_array($obj['args'])){
  419. foreach ($obj['args'] as $key=>$value){
  420. $argNode = $requestNode->append_child($xml_root->create_element('arg'));
  421. $argNode->set_attribute('name',$key);
  422. $argNode->set_attribute('value',$value);
  423. }
  424. }
  425. break;
  426. case "server_broadcast":
  427. /*
  428. <request type="server_broadcast" client="remoting_server" authentication="k1k2j3h1k23h">
  429. <node id="relay_destination" user="112"/>
  430. <node id="relay_data">
  431. <response type="server_broadcast" origin="remoting_server">
  432. <node id="target" value="Chat"/>
  433. <node id="function" value="onMsgReceived"/>
  434. <arg name="channel" value="0"/>
  435. <arg name="msg" type="cdata">
  436. <![CDATA[Yippiew!!! Coolioiei! xxx ]]>
  437. </arg>
  438. </response>
  439. </node>
  440. </request>
  441. */
  442. $locNode = $requestNode->append_child($xml_root->create_element('node'));
  443. $locNode->set_attribute('id','relay_destination');
  444. if(isset($obj['location'])){
  445. $locNode->set_attribute('location',$obj['location']);
  446. }
  447. if(isset($obj['user'])){
  448. $locNode->set_attribute('user',$obj['user']);
  449. }
  450. if(isset($obj['channel'])){
  451. $locNode->set_attribute('channel',$obj['channel']);
  452. }
  453. //more than one
  454. if(isset($obj['users'])){
  455. $locNode->set_attribute('users',join(",",$obj['users']));
  456. }
  457. if(isset($obj['relay_data'])){
  458. $dataNode = $requestNode->append_child($xml_root->create_element('node'));
  459. $dataNode->set_attribute('id','relay_data');
  460. $encData = $this->encodeResponse("server_broadcast",$obj['relay_data']);
  461. $dataNode->append_child($encData->clone_node(true));
  462. }
  463. break;
  464. case "relayed_service_call":
  465. /*
  466. <request type="server_broadcast" client="remoting_server" authentication="k1k2j3h1k23h">
  467. <node id="relay_destination" user="112"/>
  468. <node id="relay_data">
  469. <response type="relayed_service_call" origin="remoting_server">
  470. <node id="service" value="multiuser_server.mus_usermanagement"/>
  471. <node id="function" value="refreshUserlist"/>
  472. <arg name="channel" value="0"/>
  473. </response>
  474. </node>
  475. </request>
  476. */
  477. $locNode = $requestNode->append_child($xml_root->create_element('node'));
  478. $locNode->set_attribute('id','relay_destination');
  479. if(isset($obj['location'])){
  480. $locNode->set_attribute('location',$obj['location']);
  481. }
  482. if(isset($obj['user'])){
  483. $locNode->set_attribute('user',$obj['user']);
  484. }
  485. if(isset($obj['relay_data'])){
  486. $dataNode = $requestNode->append_child($xml_root->create_element('node'));
  487. $dataNode->set_attribute('id','relay_data');
  488. $encData = $this->encodeResponse("relayed_service_call",$obj['relay_data']);
  489. $dataNode->append_child($encData->clone_node(true));
  490. }
  491. break;
  492. case "wddx":
  493. /*
  494. <request type="server_broadcast" client="remoting_server" authentication="k1k2j3h1k23h">
  495. <node id="relay_destination" user="112"/>
  496. <node id="relay_data">
  497. <response type="wddx" origin="remoting_server">
  498. //wddx serialized xml
  499. </response>
  500. </node>
  501. </request>
  502. */
  503. if(isset($obj['location'])){
  504. $locNode = $requestNode->append_child($xml_root->create_element('node'));
  505. $locNode->set_attribute('id','relay_destination');
  506. $locNode->set_attribute('location',$obj['location']);
  507. }
  508. if(isset($obj['user'])){
  509. $locNode = $requestNode->append_child($xml_root->create_element('node'));
  510. $locNode->set_attribute('id','relay_destination');
  511. $locNode->set_attribute('user',$obj['user']);
  512. }
  513. if(isset($obj['relay_data'])){
  514. $dataNode->append_child($xml_root->create_element('node'));
  515. $dataNode->set_attribute('id','relay_data');
  516. $encData = $this->encodeResponse("wddx",$obj['relay_data']);
  517. $dataNode->append_child($encData);
  518. }
  519. break;
  520. case "fault":
  521. // error management
  522. break;
  523. }
  524. if( !@socket_connect($this->sock,$this->relayHost,$this->relayPort)){
  525. return false;
  526. }else{
  527. socket_write($this->sock,$xml_root->dump_mem(true) ."\0");
  528. socket_close($this->sock);
  529. return true;
  530. }
  531. }
  532. function encodeResponse( $responseType, $obj = null ){
  533. $xml_root = domxml_new_doc('1.0');
  534. $responseNode = $xml_root->append_child($xml_root->create_element('response'));
  535. $responseNode->set_attribute('type',$responseType);
  536. $responseNode->set_attribute('origin','remoting_server');
  537. switch($responseType){
  538. case "server_broadcast" :
  539. $targNode = $responseNode->append_child($xml_root->create_element('node'));
  540. $targNode->set_attribute('id','target');
  541. $targNode->set_attribute('value',$obj['target']);
  542. $funcNode = $responseNode->append_child($xml_root->create_element('node'));
  543. $funcNode->set_attribute('id','function');
  544. $funcNode->set_attribute('value',$obj['func']);
  545. foreach( $obj['args'] as $n=>$v ){
  546. $argNode = $responseNode->append_child($xml_root->create_element('arg'));
  547. $argNode->set_attribute('name',$n);
  548. if(is_string($v)){
  549. $argNode->set_attribute('type','cdata');
  550. $argNode->append_child($xml_root->create_cdata_section($v));
  551. }else{
  552. $argNode->set_attribute('value',$v);
  553. }
  554. }
  555. return $xml_root->root();
  556. break;
  557. case "relayed_service_call" :
  558. $servNode = $responseNode->append_child($xml_root->create_element('node'));
  559. $servNode->set_attribute('id','service');
  560. $servNode->set_attribute('value',$obj['serv']);
  561. $funcNode = $responseNode->append_child($xml_root->create_element('node'));
  562. $funcNode->set_attribute('id','function');
  563. $funcNode->set_attribute('value',$obj['func']);
  564. foreach( $obj['args'] as $n=>$v ){
  565. $argNode = $responseNode->append_child($xml_root->create_element('arg'));
  566. $argNode->set_attribute('name',$n);
  567. $argNode->set_attribute('value',$v);
  568. }
  569. return $xml_root->root();
  570. break;
  571. default:
  572. return $xml_root->root();
  573. break;
  574. }
  575. }
  576. }
  577. ?>