File Source for phpagi-asmanager.php

# Source for file phpagi-asmanager.php

Documentation is available at phpagi-asmanager.php

1. <?php
2. /**
3. * phpagi-asmanager.php : PHP Asterisk Manager functions
4. * Website: http://phpagi.sourceforge.net
5. *
6. * $Id: phpagi-asmanager.php,v 1.10 2005/05/25 18:43:48 pinhole Exp $
7. *
8. * Copyright (c) 2004 - 2010 Matthew Asham <matthew@ochrelabs.com>, David Eder <david@eder.us> and others
9. * All Rights Reserved.
10. *
11. * This software is released under the terms of the GNU Lesser General Public License v2.1
12. * A copy of which is available from http://www.gnu.org/copyleft/lesser.html
13. *
14. * We would be happy to list your phpagi based application on the phpagi
15. * website. Drop me an Email if you'd like us to list your program.
16. *
17. * @package phpAGI
18. * @version 2.0
19. */
22. /**
23. * Written for PHP 4.3.4, should work with older PHP 4.x versions.
24. * Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/
25. * Gracias. :)
26. *
27. */
29. if(!class_exists('AGI'))
30. {
31. require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpagi.php');
32. }
34. /**
35. * Asterisk Manager class
36. *
37. * @link http://www.voip-info.org/wiki-Asterisk+config+manager.conf
38. * @link http://www.voip-info.org/wiki-Asterisk+manager+API
39. * @example examples/sip_show_peer.php Get information about a sip peer
40. * @package phpAGI
41. */
42. class AGI_AsteriskManager
43. {
44. /**
45. * Config variables
46. *
47. * @var array
48. * @access public
49. */
50. public $config;
52. /**
53. * Socket
54. *
55. * @access public
56. */
57. public $socket = NULL;
59. /**
60. * Server we are connected to
61. *
62. * @access public
63. * @var string
64. */
65. public $server;
67. /**
68. * Port on the server we are connected to
69. *
70. * @access public
71. * @var integer
72. */
73. public $port;
75. /**
76. * Parent AGI
77. *
78. * @access private
79. * @var AGI
80. */
81. private $pagi;
83. /**
84. * Event Handlers
85. *
86. * @access private
87. * @var array
88. */
89. private $event_handlers;
91. /**
92. * Whether we're successfully logged in
93. *
94. * @access private
95. * @var boolean
96. */
97. private $_logged_in = FALSE;
99. /**
100. * Constructor
101. *
102. * @param string $config is the name of the config file to parse or a parent agi from which to read the config
103. * @param array $optconfig is an array of configuration vars and vals, stuffed into $this->config['asmanager']
104. */
105. function AGI_AsteriskManager($config=NULL, $optconfig=array())
106. {
107. // load config
108. if(!is_null($config) && file_exists($config))
109. $this->config = parse_ini_file($config, true);
110. elseif(file_exists(DEFAULT_PHPAGI_CONFIG))
111. $this->config = parse_ini_file(DEFAULT_PHPAGI_CONFIG, true);
113. // If optconfig is specified, stuff vals and vars into 'asmanager' config array.
114. foreach($optconfig as $var=>$val)
115. $this->config['asmanager'][$var] = $val;
117. // add default values to config for uninitialized values
118. if(!isset($this->config['asmanager']['server'])) $this->config['asmanager']['server'] = 'localhost';
119. if(!isset($this->config['asmanager']['port'])) $this->config['asmanager']['port'] = 5038;
120. if(!isset($this->config['asmanager']['username'])) $this->config['asmanager']['username'] = 'phpagi';
121. if(!isset($this->config['asmanager']['secret'])) $this->config['asmanager']['secret'] = 'phpagi';
122. }
124. /**
125. * Send a request
126. *
127. * @param string $action
128. * @param array $parameters
129. * @return array of parameters
130. */
131. function send_request($action, $parameters=array())
132. {
133. $req = "Action: $action\r\n";
134. foreach($parameters as $var=>$val)
135. $req .= "$var: $val\r\n";
136. $req .= "\r\n";
137. fwrite($this->socket, $req);
138. return $this->wait_response();
139. }
141. /**
142. * Wait for a response
143. *
144. * If a request was just sent, this will return the response.
145. * Otherwise, it will loop forever, handling events.
146. *
147. * @param boolean $allow_timeout if the socket times out, return an empty array
148. * @return array of parameters, empty on timeout
149. */
150. function wait_response($allow_timeout=false)
151. {
152. $timeout = false;
153. do
154. {
155. $type = NULL;
156. $parameters = array();
158. $buffer = trim(fgets($this->socket, 4096));
159. while($buffer != '')
160. {
161. $a = strpos($buffer, ':');
162. if($a)
163. {
164. if(!count($parameters)) // first line in a response?
165. {
166. $type = strtolower(substr($buffer, 0, $a));
167. if(substr($buffer, $a + 2) == 'Follows')
168. {
169. // A follows response means there is a miltiline field that follows.
170. $parameters['data'] = '';
171. $buff = fgets($this->socket, 4096);
172. while(substr($buff, 0, 6) != '--END ')
173. {
174. $parameters['data'] .= $buff;
175. $buff = fgets($this->socket, 4096);
176. }
177. }
178. }
180. // store parameter in $parameters
181. $parameters[substr($buffer, 0, $a)] = substr($buffer, $a + 2);
182. }
183. $buffer = trim(fgets($this->socket, 4096));
184. }
186. // process response
187. switch($type)
188. {
189. case '': // timeout occured
190. $timeout = $allow_timeout;
191. break;
192. case 'event':
193. $this->process_event($parameters);
194. break;
195. case 'response':
196. break;
197. default:
198. $this->log('Unhandled response packet from Manager: ' . print_r($parameters, true));
199. break;
200. }
201. } while($type != 'response' && !$timeout);
202. return $parameters;
203. }
205. /**
206. * Connect to Asterisk
207. *
208. * @example examples/sip_show_peer.php Get information about a sip peer
209. *
210. * @param string $server
211. * @param string $username
212. * @param string $secret
213. * @return boolean true on success
214. */
215. function connect($server=NULL, $username=NULL, $secret=NULL)
216. {
217. // use config if not specified
218. if(is_null($server)) $server = $this->config['asmanager']['server'];
219. if(is_null($username)) $username = $this->config['asmanager']['username'];
220. if(is_null($secret)) $secret = $this->config['asmanager']['secret'];
222. // get port from server if specified
223. if(strpos($server, ':') !== false)
224. {
225. $c = explode(':', $server);
226. $this->server = $c[0];
227. $this->port = $c[1];
228. }
229. else
230. {
231. $this->server = $server;
232. $this->port = $this->config['asmanager']['port'];
233. }
235. // connect the socket
236. $errno = $errstr = NULL;
237. $this->socket = @fsockopen($this->server, $this->port, $errno, $errstr);
238. if($this->socket == false)
239. {
240. $this->log("Unable to connect to manager {$this->server}:{$this->port} ($errno): $errstr");
241. return false;
242. }
244. // read the header
245. $str = fgets($this->socket);
246. if($str == false)
247. {
248. // a problem.
249. $this->log("Asterisk Manager header not received.");
250. return false;
251. }
252. else
253. {
254. // note: don't $this->log($str) until someone looks to see why it mangles the logging
255. }
257. // login
258. $res = $this->send_request('login', array('Username'=>$username, 'Secret'=>$secret));
259. if($res['Response'] != 'Success')
260. {
261. $this->_logged_in = FALSE;
262. $this->log("Failed to login.");
263. $this->disconnect();
264. return false;
265. }
266. $this->_logged_in = TRUE;
267. return true;
268. }
270. /**
271. * Disconnect
272. *
273. * @example examples/sip_show_peer.php Get information about a sip peer
274. */
275. function disconnect()
276. {
277. if($this->_logged_in==TRUE)
278. $this->logoff();
279. fclose($this->socket);
280. }
282. // *********************************************************************************************************
283. // ** COMMANDS **
284. // *********************************************************************************************************
286. /**
287. * Set Absolute Timeout
288. *
289. * Hangup a channel after a certain time.
290. *
291. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+AbsoluteTimeout
292. * @param string $channel Channel name to hangup
293. * @param integer $timeout Maximum duration of the call (sec)
294. */
295. function AbsoluteTimeout($channel, $timeout)
296. {
297. return $this->send_request('AbsoluteTimeout', array('Channel'=>$channel, 'Timeout'=>$timeout));
298. }
300. /**
301. * Change monitoring filename of a channel
302. *
303. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ChangeMonitor
304. * @param string $channel the channel to record.
305. * @param string $file the new name of the file created in the monitor spool directory.
306. */
307. function ChangeMonitor($channel, $file)
308. {
309. return $this->send_request('ChangeMontior', array('Channel'=>$channel, 'File'=>$file));
310. }
312. /**
313. * Execute Command
314. *
315. * @example examples/sip_show_peer.php Get information about a sip peer
316. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Command
317. * @link http://www.voip-info.org/wiki-Asterisk+CLI
318. * @param string $command
319. * @param string $actionid message matching variable
320. */
321. function Command($command, $actionid=NULL)
322. {
323. $parameters = array('Command'=>$command);
324. if($actionid) $parameters['ActionID'] = $actionid;
325. return $this->send_request('Command', $parameters);
326. }
328. /**
329. * Enable/Disable sending of events to this manager
330. *
331. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Events
332. * @param string $eventmask is either 'on', 'off', or 'system,call,log'
333. */
334. function Events($eventmask)
335. {
336. return $this->send_request('Events', array('EventMask'=>$eventmask));
337. }
339. /**
340. * Check Extension Status
341. *
342. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ExtensionState
343. * @param string $exten Extension to check state on
344. * @param string $context Context for extension
345. * @param string $actionid message matching variable
346. */
347. function ExtensionState($exten, $context, $actionid=NULL)
348. {
349. $parameters = array('Exten'=>$exten, 'Context'=>$context);
350. if($actionid) $parameters['ActionID'] = $actionid;
351. return $this->send_request('ExtensionState', $parameters);
352. }
354. /**
355. * Gets a Channel Variable
356. *
357. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+GetVar
358. * @link http://www.voip-info.org/wiki-Asterisk+variables
359. * @param string $channel Channel to read variable from
360. * @param string $variable
361. * @param string $actionid message matching variable
362. */
363. function GetVar($channel, $variable, $actionid=NULL)
364. {
365. $parameters = array('Channel'=>$channel, 'Variable'=>$variable);
366. if($actionid) $parameters['ActionID'] = $actionid;
367. return $this->send_request('GetVar', $parameters);
368. }
370. /**
371. * Hangup Channel
372. *
373. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Hangup
374. * @param string $channel The channel name to be hungup
375. */
376. function Hangup($channel)
377. {
378. return $this->send_request('Hangup', array('Channel'=>$channel));
379. }
381. /**
382. * List IAX Peers
383. *
384. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+IAXpeers
385. */
386. function IAXPeers()
387. {
388. return $this->send_request('IAXPeers');
389. }
391. /**
392. * List available manager commands
393. *
394. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ListCommands
395. * @param string $actionid message matching variable
396. */
397. function ListCommands($actionid=NULL)
398. {
399. if($actionid)
400. return $this->send_request('ListCommands', array('ActionID'=>$actionid));
401. else
402. return $this->send_request('ListCommands');
403. }
405. /**
406. * Logoff Manager
407. *
408. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Logoff
409. */
410. function Logoff()
411. {
412. return $this->send_request('Logoff');
413. }
415. /**
416. * Check Mailbox Message Count
417. *
418. * Returns number of new and old messages.
419. * Message: Mailbox Message Count
420. * Mailbox: <mailboxid>
421. * NewMessages: <count>
422. * OldMessages: <count>
423. *
424. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+MailboxCount
425. * @param string $mailbox Full mailbox ID <mailbox>@<vm-context>
426. * @param string $actionid message matching variable
427. */
428. function MailboxCount($mailbox, $actionid=NULL)
429. {
430. $parameters = array('Mailbox'=>$mailbox);
431. if($actionid) $parameters['ActionID'] = $actionid;
432. return $this->send_request('MailboxCount', $parameters);
433. }
435. /**
436. * Check Mailbox
437. *
438. * Returns number of messages.
439. * Message: Mailbox Status
440. * Mailbox: <mailboxid>
441. * Waiting: <count>
442. *
443. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+MailboxStatus
444. * @param string $mailbox Full mailbox ID <mailbox>@<vm-context>
445. * @param string $actionid message matching variable
446. */
447. function MailboxStatus($mailbox, $actionid=NULL)
448. {
449. $parameters = array('Mailbox'=>$mailbox);
450. if($actionid) $parameters['ActionID'] = $actionid;
451. return $this->send_request('MailboxStatus', $parameters);
452. }
454. /**
455. * Monitor a channel
456. *
457. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Monitor
458. * @param string $channel
459. * @param string $file
460. * @param string $format
461. * @param boolean $mix
462. */
463. function Monitor($channel, $file=NULL, $format=NULL, $mix=NULL)
464. {
465. $parameters = array('Channel'=>$channel);
466. if($file) $parameters['File'] = $file;
467. if($format) $parameters['Format'] = $format;
468. if(!is_null($file)) $parameters['Mix'] = ($mix) ? 'true' : 'false';
469. return $this->send_request('Monitor', $parameters);
470. }
472. /**
473. * Originate Call
474. *
475. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Originate
476. * @param string $channel Channel name to call
477. * @param string $exten Extension to use (requires 'Context' and 'Priority')
478. * @param string $context Context to use (requires 'Exten' and 'Priority')
479. * @param string $priority Priority to use (requires 'Exten' and 'Context')
480. * @param string $application Application to use
481. * @param string $data Data to use (requires 'Application')
482. * @param integer $timeout How long to wait for call to be answered (in ms)
483. * @param string $callerid Caller ID to be set on the outgoing channel
484. * @param string $variable Channel variable to set (VAR1=value1|VAR2=value2)
485. * @param string $account Account code
486. * @param boolean $async true fast origination
487. * @param string $actionid message matching variable
488. */
489. function Originate($channel,
490. $exten=NULL, $context=NULL, $priority=NULL,
491. $application=NULL, $data=NULL,
492. $timeout=NULL, $callerid=NULL, $variable=NULL, $account=NULL, $async=NULL, $actionid=NULL)
493. {
494. $parameters = array('Channel'=>$channel);
496. if($exten) $parameters['Exten'] = $exten;
497. if($context) $parameters['Context'] = $context;
498. if($priority) $parameters['Priority'] = $priority;
500. if($application) $parameters['Application'] = $application;
501. if($data) $parameters['Data'] = $data;
503. if($timeout) $parameters['Timeout'] = $timeout;
504. if($callerid) $parameters['CallerID'] = $callerid;
505. if($variable) $parameters['Variable'] = $variable;
506. if($account) $parameters['Account'] = $account;
507. if(!is_null($async)) $parameters['Async'] = ($async) ? 'true' : 'false';
508. if($actionid) $parameters['ActionID'] = $actionid;
510. return $this->send_request('Originate', $parameters);
511. }
513. /**
514. * List parked calls
515. *
516. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ParkedCalls
517. * @param string $actionid message matching variable
518. */
519. function ParkedCalls($actionid=NULL)
520. {
521. if($actionid)
522. return $this->send_request('ParkedCalls', array('ActionID'=>$actionid));
523. else
524. return $this->send_request('ParkedCalls');
525. }
527. /**
528. * Ping
529. *
530. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Ping
531. */
532. function Ping()
533. {
534. return $this->send_request('Ping');
535. }
537. /**
538. * Queue Add
539. *
540. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+QueueAdd
541. * @param string $queue
542. * @param string $interface
543. * @param integer $penalty
544. */
545. function QueueAdd($queue, $interface, $penalty=0)
546. {
547. $parameters = array('Queue'=>$queue, 'Interface'=>$interface);
548. if($penalty) $parameters['Penalty'] = $penalty;
549. return $this->send_request('QueueAdd', $parameters);
550. }
552. /**
553. * Queue Remove
554. *
555. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+QueueRemove
556. * @param string $queue
557. * @param string $interface
558. */
559. function QueueRemove($queue, $interface)
560. {
561. return $this->send_request('QueueRemove', array('Queue'=>$queue, 'Interface'=>$interface));
562. }
564. /**
565. * Queues
566. *
567. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Queues
568. */
569. function Queues()
570. {
571. return $this->send_request('Queues');
572. }
574. /**
575. * Queue Status
576. *
577. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+QueueStatus
578. * @param string $actionid message matching variable
579. */
580. function QueueStatus($actionid=NULL)
581. {
582. if($actionid)
583. return $this->send_request('QueueStatus', array('ActionID'=>$actionid));
584. else
585. return $this->send_request('QueueStatus');
586. }
588. /**
589. * Redirect
590. *
591. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Redirect
592. * @param string $channel
593. * @param string $extrachannel
594. * @param string $exten
595. * @param string $context
596. * @param string $priority
597. */
598. function Redirect($channel, $extrachannel, $exten, $context, $priority)
599. {
600. return $this->send_request('Redirect', array('Channel'=>$channel, 'ExtraChannel'=>$extrachannel, 'Exten'=>$exten,
601. 'Context'=>$context, 'Priority'=>$priority));
602. }
604. /**
605. * Set the CDR UserField
606. *
607. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+SetCDRUserField
608. * @param string $userfield
609. * @param string $channel
610. * @param string $append
611. */
612. function SetCDRUserField($userfield, $channel, $append=NULL)
613. {
614. $parameters = array('UserField'=>$userfield, 'Channel'=>$channel);
615. if($append) $parameters['Append'] = $append;
616. return $this->send_request('SetCDRUserField', $parameters);
617. }
619. /**
620. * Set Channel Variable
621. *
622. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+SetVar
623. * @param string $channel Channel to set variable for
624. * @param string $variable name
625. * @param string $value
626. */
627. function SetVar($channel, $variable, $value)
628. {
629. return $this->send_request('SetVar', array('Channel'=>$channel, 'Variable'=>$variable, 'Value'=>$value));
630. }
632. /**
633. * Channel Status
634. *
635. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Status
636. * @param string $channel
637. * @param string $actionid message matching variable
638. */
639. function Status($channel, $actionid=NULL)
640. {
641. $parameters = array('Channel'=>$channel);
642. if($actionid) $parameters['ActionID'] = $actionid;
643. return $this->send_request('Status', $parameters);
644. }
646. /**
647. * Stop monitoring a channel
648. *
649. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+StopMonitor
650. * @param string $channel
651. */
652. function StopMonitor($channel)
653. {
654. return $this->send_request('StopMonitor', array('Channel'=>$channel));
655. }
657. /**
658. * Dial over Zap channel while offhook
659. *
660. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapDialOffhook
661. * @param string $zapchannel
662. * @param string $number
663. */
664. function ZapDialOffhook($zapchannel, $number)
665. {
666. return $this->send_request('ZapDialOffhook', array('ZapChannel'=>$zapchannel, 'Number'=>$number));
667. }
669. /**
670. * Toggle Zap channel Do Not Disturb status OFF
671. *
672. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapDNDoff
673. * @param string $zapchannel
674. */
675. function ZapDNDoff($zapchannel)
676. {
677. return $this->send_request('ZapDNDoff', array('ZapChannel'=>$zapchannel));
678. }
680. /**
681. * Toggle Zap channel Do Not Disturb status ON
682. *
683. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapDNDon
684. * @param string $zapchannel
685. */
686. function ZapDNDon($zapchannel)
687. {
688. return $this->send_request('ZapDNDon', array('ZapChannel'=>$zapchannel));
689. }
691. /**
692. * Hangup Zap Channel
693. *
694. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapHangup
695. * @param string $zapchannel
696. */
697. function ZapHangup($zapchannel)
698. {
699. return $this->send_request('ZapHangup', array('ZapChannel'=>$zapchannel));
700. }
702. /**
703. * Transfer Zap Channel
704. *
705. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapTransfer
706. * @param string $zapchannel
707. */
708. function ZapTransfer($zapchannel)
709. {
710. return $this->send_request('ZapTransfer', array('ZapChannel'=>$zapchannel));
711. }
713. /**
714. * Zap Show Channels
715. *
716. * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapShowChannels
717. * @param string $actionid message matching variable
718. */
719. function ZapShowChannels($actionid=NULL)
720. {
721. if($actionid)
722. return $this->send_request('ZapShowChannels', array('ActionID'=>$actionid));
723. else
724. return $this->send_request('ZapShowChannels');
725. }
727. // *********************************************************************************************************
728. // ** MISC **
729. // *********************************************************************************************************
731. /*
732. * Log a message
733. *
734. * @param string $message
735. * @param integer $level from 1 to 4
736. */
737. function log($message, $level=1)
738. {
739. if($this->pagi != false)
740. $this->pagi->conlog($message, $level);
741. else
742. error_log(date('r') . ' - ' . $message);
743. }
745. /**
746. * Add event handler
747. *
748. * Known Events include ( http://www.voip-info.org/wiki-asterisk+manager+events )
749. * Link - Fired when two voice channels are linked together and voice data exchange commences.
750. * Unlink - Fired when a link between two voice channels is discontinued, for example, just before call completion.
751. * Newexten -
752. * Hangup -
753. * Newchannel -
754. * Newstate -
755. * Reload - Fired when the "RELOAD" console command is executed.
756. * Shutdown -
757. * ExtensionStatus -
758. * Rename -
759. * Newcallerid -
760. * Alarm -
761. * AlarmClear -
762. * Agentcallbacklogoff -
763. * Agentcallbacklogin -
764. * Agentlogoff -
765. * MeetmeJoin -
766. * MessageWaiting -
767. * join -
768. * leave -
769. * AgentCalled -
770. * ParkedCall - Fired after ParkedCalls
771. * Cdr -
772. * ParkedCallsComplete -
773. * QueueParams -
774. * QueueMember -
775. * QueueStatusEnd -
776. * Status -
777. * StatusComplete -
778. * ZapShowChannels - Fired after ZapShowChannels
779. * ZapShowChannelsComplete -
780. *
781. * @param string $event type or * for default handler
782. * @param string $callback function
783. * @return boolean sucess
784. */
785. function add_event_handler($event, $callback)
786. {
787. $event = strtolower($event);
788. if(isset($this->event_handlers[$event]))
789. {
790. $this->log("$event handler is already defined, not over-writing.");
791. return false;
792. }
793. $this->event_handlers[$event] = $callback;
794. return true;
795. }
797. /**
798. * Process event
799. *
800. * @access private
801. * @param array $parameters
802. * @return mixed result of event handler or false if no handler was found
803. */
804. function process_event($parameters)
805. {
806. $ret = false;
807. $e = strtolower($parameters['Event']);
808. $this->log("Got event.. $e");
810. $handler = '';
811. if(isset($this->event_handlers[$e])) $handler = $this->event_handlers[$e];
812. elseif(isset($this->event_handlers['*'])) $handler = $this->event_handlers['*'];
814. if(function_exists($handler))
815. {
816. $this->log("Execute handler $handler");
817. $ret = $handler($e, $parameters, $this->server, $this->port);
818. }
819. else
820. $this->log("No event handler for event '$e'");
821. return $ret;
822. }
823. }

Documentation generated on Thu, 30 Sep 2010 02:21:47 -0700 by phpDocumentor 1.4.2