Commit 3a707f506dce28a6f91f9126163f1d03448b94e0

Authored by kevin_fourie
1 parent 99d18660

Merged in from DEV trunk...

WSA-44
"web service unit tests in php need to be incorporated for search"
Added. A little proxy to help with debugging

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@7562 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 165 additions and 0 deletions
ktwebservice/proxy/proxy.php 0 → 100644
  1 +<?php
  2 +
  3 +/**
  4 + * $Id:$
  5 + *
  6 + * KnowledgeTree Open Source Edition
  7 + * Document Management Made Simple
  8 + * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited
  9 + *
  10 + * This program is free software; you can redistribute it and/or modify it under
  11 + * the terms of the GNU General Public License version 3 as published by the
  12 + * Free Software Foundation.
  13 + *
  14 + * This program is distributed in the hope that it will be useful, but WITHOUT
  15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17 + * details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + *
  22 + * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
  23 + * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
  24 + *
  25 + * The interactive user interfaces in modified source and object code versions
  26 + * of this program must display Appropriate Legal Notices, as required under
  27 + * Section 5 of the GNU General Public License version 3.
  28 + *
  29 + * In accordance with Section 7(b) of the GNU General Public License version 3,
  30 + * these Appropriate Legal Notices must retain the display of the "Powered by
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
  34 + * copyright notice.
  35 + * Contributor( s): ______________________________________
  36 + *
  37 + */
  38 +
  39 +set_time_limit(0);
  40 +
  41 +if ($argc < 3)
  42 +{
  43 + die('Usage: proxy.php listenport connectaddr connectport');
  44 +}
  45 +
  46 +$cport = $argv[1];
  47 +$saddress = $argv[2];
  48 +$sport = $argv[2];
  49 +
  50 +
  51 +print "Listening on port: $cport\n";
  52 +print "Connecting to: $saddress:$sport\n";
  53 +
  54 +if (($lsock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false)
  55 +{
  56 + die('Cannot create socket: '. socket_strerror($res));
  57 +}
  58 +
  59 +if (($res = @socket_bind($lsock, '127.0.0.2', $cport)) === false)
  60 +{
  61 + die('Cannot bind socket: ' . socket_strerror($res));
  62 +}
  63 +
  64 +if (($res = socket_listen($lsock, 5)) === false)
  65 +{
  66 + die('Cannot listen on socket: ' . socket_strerror($res));
  67 +}
  68 +
  69 +while(true)
  70 +{
  71 + if (($csock = socket_accept($lsock)) < 0)
  72 + {
  73 + print 'Cannot accept socket: ' . socket_strerror($csock) . "\n";
  74 + continue;
  75 + }
  76 + print "accepting client\n";
  77 +
  78 + if (($ssock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0)
  79 + {
  80 + print('Cannot create socket: '. socket_strerror($res));
  81 + continue;
  82 + }
  83 +
  84 + print "connecting\n";
  85 + if (($res = socket_connect($ssock, $saddress, $sport)) < 0)
  86 + {
  87 + print('Cannot bind socket: ' . socket_strerror($res));
  88 + continue;
  89 + }
  90 +
  91 +
  92 + ob_implicit_flush();
  93 +
  94 + $clientClose = false;
  95 + $serverClose = false;
  96 + while(!$clientClose && !$serverClose)
  97 + {
  98 + $arr = array();
  99 + $carr = array();
  100 + $sarr = array();
  101 +
  102 + if (!$clientClose)
  103 + {
  104 + $arr[]= $csock;
  105 + $carr[]= $csock;
  106 + }
  107 + if (!$serverClose)
  108 + {
  109 + $arr[]= $ssock;
  110 + $sarr[]= $ssock;
  111 + }
  112 +ob_implicit_flush(); $res = socket_select($arr, $e2=null, $e = null, 5);
  113 + if ($res === false)
  114 + {
  115 + print "problem\n";
  116 + break;
  117 + }
  118 + else
  119 + {
  120 + $res = @socket_select($carr, $w = NULL, $e = NULL, 0);
  121 + if (!$clientClose && ($res === 1))
  122 + {
  123 + $buf = @socket_read($csock, 2048, PHP_NORMAL_READ);
  124 + if (strlen($buf) != 0)
  125 + {
  126 + socket_write($ssock, $buf, strlen($buf));
  127 + print "C>>S: $buf\n";
  128 + }
  129 + if ($buf === false)
  130 + {
  131 + $clientClose = true;
  132 + socket_write($ssock, "\n", 1);
  133 + print "close connection to client\n";
  134 + }
  135 +
  136 + }
  137 + $res = @socket_select($sarr, $w = NULL, $e = NULL, 0);
  138 + if (!$serverClose && ($res === 1))
  139 + {
  140 + $buf = @socket_read($ssock, 2048, PHP_NORMAL_READ);
  141 + if (strlen($buf) != 0)
  142 + {
  143 + socket_write($csock, $buf, strlen($buf));
  144 + print "C<<S: $buf\n";
  145 +
  146 + }
  147 + if($buf ===0 )
  148 + {
  149 + print "\n";
  150 + }
  151 + if ($buf === false)
  152 + {
  153 + //socket_close($csock);
  154 + $serverClose = true;
  155 + print "close connection to server\n";
  156 + }
  157 + }
  158 + }
  159 + }
  160 + socket_close($ssock);
  161 + socket_close($csock);
  162 +}
  163 +
  164 +socket_close($lsock);
  165 +?>
0 166 \ No newline at end of file
... ...