<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][14999] </title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=14999">14999</a></dd>
<dt>Author</dt> <dd>intralanman</dd>
<dt>Date</dt> <dd>2009-09-27 20:20:15 -0500 (Sun, 27 Sep 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>don't split content body by :'s, thanks Alberto</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunkcontribintralanmanPHPfs_sockfs_sockphp">freeswitch/trunk/contrib/intralanman/PHP/fs_sock/fs_sock.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunkcontribintralanmanPHPfs_sockfs_sockphp"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/contrib/intralanman/PHP/fs_sock/fs_sock.php (14998 => 14999)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/intralanman/PHP/fs_sock/fs_sock.php        2009-09-28 00:55:43 UTC (rev 14998)
+++ freeswitch/trunk/contrib/intralanman/PHP/fs_sock/fs_sock.php        2009-09-28 01:20:15 UTC (rev 14999)
</span><span class="lines">@@ -9,11 +9,11 @@
</span><span class="cx"> *
</span><span class="cx"> */
</span><span class="cx"> class fs_sock {
</span><del>- /**
- * file handler for FreeSWITCH socket connection
- *
- * @var file pointer
- */
</del><ins>+/**
+ * file handler for FreeSWITCH socket connection
+ *
+ * @var file pointer
+ */
</ins><span class="cx"> public $sock;
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -43,10 +43,10 @@
</span><span class="cx"> */
</span><span class="cx"> function fs_sock($vars=null) {
</span><span class="cx"> if (!defined('BUFFER_SIZE')) {
</span><del>- /**
- * This is the buffer size for fread/fgets operations (default 4096)
- * Define BUFFER_SIZE before instantiation to use a different size
- */
</del><ins>+ /**
+ * This is the buffer size for fread/fgets operations (default 4096)
+ * Define BUFFER_SIZE before instantiation to use a different size
+ */
</ins><span class="cx"> define('BUFFER_SIZE', 4096);
</span><span class="cx"> }
</span><span class="cx"> $vars_array = is_array($vars) ? $vars : array();
</span><span class="lines">@@ -77,23 +77,23 @@
</span><span class="cx"> */
</span><span class="cx"> function set_initial_vars($var_array) {
</span><span class="cx"> $defaults = array(
</span><del>- 'host' => '127.0.0.1',
- 'port' => '8021',
- 'pass' => 'ClueCon',
- 'timeout' => 30,
- 'stream_timeout' => 5
</del><ins>+ 'host' => '127.0.0.1',
+ 'port' => '8021',
+ 'pass' => 'ClueCon',
+ 'timeout' => 30,
+ 'stream_timeout' => 5
</ins><span class="cx"> );
</span><span class="cx"> if (array_key_exists('host', $var_array)
</span><del>- && $var_array['host'] == 'localhost') {
- //$this -> debug('Replacing localhost with 127.0.0.1');
</del><ins>+ && $var_array['host'] == 'localhost') {
+ //$this -> debug('Replacing localhost with 127.0.0.1');
</ins><span class="cx"> $var_array['host'] = '127.0.0.1';
</span><span class="cx"> }
</span><span class="cx"> foreach ($defaults as $key => $val) {
</span><span class="cx"> if (array_key_exists($key, $var_array)) {
</span><del>- //$this -> debug("$key found in vars");
</del><ins>+ //$this -> debug("$key found in vars");
</ins><span class="cx"> $connection_settings[$key] = $var_array[$key];
</span><span class="cx"> } else {
</span><del>- //$this -> debug("$key not found in vars");
</del><ins>+ //$this -> debug("$key not found in vars");
</ins><span class="cx"> $connection_settings[$key] = $val;
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="lines">@@ -108,19 +108,19 @@
</span><span class="cx"> * @return boolean
</span><span class="cx"> */
</span><span class="cx"> function sock_connect($sock_array) {
</span><del>- //$this -> debug($sock_array);
</del><ins>+ //$this -> debug($sock_array);
</ins><span class="cx"> $host = $sock_array['host'];
</span><span class="cx"> $port = $sock_array['port'];
</span><span class="cx"> $timeout = $sock_array['timeout'];
</span><span class="cx"> $this -> sock = fsockopen($host, $port, $errno, $errstr, $timeout);
</span><span class="cx"> if (!$this -> sock) {
</span><span class="cx"> $error = sprintf('Unable to connect to %s:%s Error #%s: %s'
</span><del>- , $host, $port, $errno, $errstr
</del><ins>+ , $host, $port, $errno, $errstr
</ins><span class="cx"> );
</span><span class="cx"> trigger_error($error, E_USER_ERROR);
</span><span class="cx"> return false;
</span><span class="cx"> } else {
</span><del>- //$this -> debug(stream_get_meta_data($this -> sock));
</del><ins>+ //$this -> debug(stream_get_meta_data($this -> sock));
</ins><span class="cx"> $this -> set_stream_opts($sock_array);
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="lines">@@ -133,9 +133,9 @@
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><span class="cx"> function set_stream_opts($opts) {
</span><del>- //$this -> debug($opts);
</del><ins>+ //$this -> debug($opts);
</ins><span class="cx"> if (ereg('^[0-9]*\.[0-9]+$', $opts['stream_timeout'])) {
</span><del>- //$this -> debug($opts['stream_timeout'] . ' seems to be a float');
</del><ins>+ //$this -> debug($opts['stream_timeout'] . ' seems to be a float');
</ins><span class="cx"> $time_opts = split('\.', $opts['stream_timeout']);
</span><span class="cx"> //$this -> debug($time_opts);
</span><span class="cx"> $secs = sprintf('%d', $time_opts[0]);
</span><span class="lines">@@ -146,7 +146,7 @@
</span><span class="cx"> }
</span><span class="cx"> if (!stream_set_timeout($this -> sock, $secs, $ms)) {
</span><span class="cx"> $this -> debug(
</span><del>- "Failed to set timeout to $secs seconds and $ms microseconds"
</del><ins>+ "Failed to set timeout to $secs seconds and $ms microseconds"
</ins><span class="cx"> );
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="lines">@@ -160,7 +160,7 @@
</span><span class="cx"> function sock_auth($pass) {
</span><span class="cx"> $reply = $this -> send_command("auth $pass");
</span><span class="cx"> if (is_array($reply) && array_key_exists('Reply-Text', $reply)
</span><del>- && ereg('^\+?OK', $reply['Reply-Text'])) {
</del><ins>+ && ereg('^\+?OK', $reply['Reply-Text'])) {
</ins><span class="cx"> $this -> debug('Successfully authenticated');
</span><span class="cx"> $this -> debug($reply);
</span><span class="cx"> $this -> auth = true;
</span><span class="lines">@@ -200,7 +200,7 @@
</span><span class="cx"> $event[$header] = $value;
</span><span class="cx"> }
</span><span class="cx"> } elseif (is_array($event)
</span><del>- && array_key_exists('Content-Length', $event)) {
</del><ins>+ && array_key_exists('Content-Length', $event)) {
</ins><span class="cx"> $this -> debug("line is empty: " . (empty($trim_line) ? 'true' : 'false'));
</span><span class="cx"> $event['Body'] = $this -> sock_get_length($event['Content-Length']);
</span><span class="cx"> break;
</span><span class="lines">@@ -214,7 +214,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Read $content_len bytes from the socket
</del><ins>+ * Read $content_len bytes from the socket splitting by :
</ins><span class="cx"> *
</span><span class="cx"> * @param integer $content_len
</span><span class="cx"> * @return array
</span><span class="lines">@@ -234,8 +234,8 @@
</span><span class="cx"> $value = trim($split[1]);
</span><span class="cx"> $content[$attribute] = urldecode($value);
</span><span class="cx"> } elseif (empty($trim_line) && is_array($content)
</span><del>- && array_key_exists('Content-Length', $content)) {
- $content['Body'] = $this -> sock_get_length($content['Content-Length']);
</del><ins>+ && array_key_exists('Content-Length', $content)) {
+ $content['Body'] = $this -> sock_get_body($content['Content-Length']);
</ins><span class="cx"> $len += $content['Content-Length'];
</span><span class="cx"> break;
</span><span class="cx"> } elseif (!empty($trim_line)) {
</span><span class="lines">@@ -251,6 +251,32 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * Read $content_len bytes from the socket
+ *
+ * @param integer $content_len
+ * @return array
+ */
+ private function sock_get_body($content_len) {
+ $len = 0;
+ $content = null;
+
+ while ($orig_line = fgets($this -> sock, BUFFER_SIZE)) {
+
+ $len += strlen($orig_line);
+ $trim_line = trim($orig_line);
+
+ $content .= $trim_line;
+
+ if ($len >= $content_len) {
+ break;
+ }
+
+ }
+
+ return $content;
+ }
+
+ /**
</ins><span class="cx"> * Send a command to the FreeSWITCH event socket
</span><span class="cx"> * This method sends a command string to the FreeSWITCH event socket and
</span><span class="cx"> * returns true upon success and false upon failure
</span><span class="lines">@@ -271,7 +297,7 @@
</span><span class="cx"> $this -> sock_put("$cmd\r\n\r\n", $sock);
</span><span class="cx"> if ($this -> command != 'exit') {
</span><span class="cx"> $reply = $this -> sock_get($sock);
</span><del>- //$this -> debug($reply);
</del><ins>+ //$this -> debug($reply);
</ins><span class="cx"> } else {
</span><span class="cx"> unset($this -> command);
</span><span class="cx"> return;
</span><span class="lines">@@ -298,8 +324,8 @@
</span><span class="cx"> while ($reply['Content-Type'] != 'api/response') {
</span><span class="cx"> if (count($reply) > 0) {
</span><span class="cx"> $debug_text = sprintf(
</span><del>- "%s - (%s) != (api/response) adding an event to the output buffer"
- , count($reply), $reply['Content-Type']
</del><ins>+ "%s - (%s) != (api/response) adding an event to the output buffer"
+ , count($reply), $reply['Content-Type']
</ins><span class="cx"> );
</span><span class="cx"> $this -> debug($debug_text);
</span><span class="cx"> $this -> output_buffer[] = $reply;
</span><span class="lines">@@ -320,8 +346,8 @@
</span><span class="cx"> while ($reply['Content-Type'] != 'command/reply') {
</span><span class="cx"> if (count($reply) > 0) {
</span><span class="cx"> $debug_text = sprintf(
</span><del>- "%s - (%s) != (command/reply) adding an event to the output buffer"
- , count($reply), $reply['Content-Type']
</del><ins>+ "%s - (%s) != (command/reply) adding an event to the output buffer"
+ , count($reply), $reply['Content-Type']
</ins><span class="cx"> );
</span><span class="cx"> $this -> debug($debug_text);
</span><span class="cx"> $this -> output_buffer[] = $reply;
</span><span class="lines">@@ -410,10 +436,10 @@
</span><span class="cx"> $this -> debug(")", $spaces);
</span><span class="cx"> } else {
</span><span class="cx"> if (is_array($_SERVER)
</span><del>- && array_key_exists('HTTP_HOST', $_SERVER)) {
</del><ins>+ && array_key_exists('HTTP_HOST', $_SERVER)) {
</ins><span class="cx"> printf("<!--%s%s-->\r\n"
</span><del>- , str_repeat(' ', $spaces)
- , htmlentities($input)
</del><ins>+ , str_repeat(' ', $spaces)
+ , htmlentities($input)
</ins><span class="cx"> );
</span><span class="cx"> } else {
</span><span class="cx"> $input = trim($input);
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>