| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
| <title>VCL XML RPC: xmlrpc_example.php</title> |
| <link href="doxygen.css" rel="stylesheet" type="text/css"> |
| <link href="tabs.css" rel="stylesheet" type="text/css"> |
| </head><body> |
| <!-- Generated by Doxygen 1.5.3 --> |
| <h1>xmlrpc_example.php</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <?php |
| <a name="l00002"></a>00002 session_start(); |
| <a name="l00003"></a>00003 |
| <a name="l00004"></a>00004 $url = <span class="stringliteral">"http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}"</span>; |
| <a name="l00005"></a>00005 print <span class="stringliteral">"<a href=\"$url?state=test\">Test</a><br>\n"</span>; |
| <a name="l00006"></a>00006 print <span class="stringliteral">"<a href=\"$url?state=listimages\">List Available Images</a><br>\n"</span>; |
| <a name="l00007"></a>00007 print <span class="stringliteral">"<a href=\"$url?state=addrequest\">Add request for Maple 10</a><br>\n"</span>; |
| <a name="l00008"></a>00008 print <span class="stringliteral">"<a href=\"$url?state=requeststatus\">Get status of request</a><br>\n"</span>; |
| <a name="l00009"></a>00009 print <span class="stringliteral">"<a href=\"$url?state=connectdata\">Get connection data</a><br>\n"</span>; |
| <a name="l00010"></a>00010 print <span class="stringliteral">"<a href=\"$url?state=endrequest\">End request</a><br>\n"</span>; |
| <a name="l00011"></a>00011 |
| <a name="l00012"></a>00012 print <span class="stringliteral">"<pre>\n"</span>; |
| <a name="l00013"></a>00013 |
| <a name="l00014"></a>00014 <span class="comment">// test</span> |
| <a name="l00015"></a>00015 <span class="keywordflow">if</span>($_GET['state'] == 'test') { |
| <a name="l00016"></a>00016 $rc = remoteVCLCall('<a name="a0"></a><a class="code" href="xmlrpcWrappers_8php.html#c3e09831835663a8bd79aab3f0ea3e69" title="this is a test function that call be called when getting XML RPC calls to this site...">XMLRPCtest</a>', array('foo')); |
| <a name="l00017"></a>00017 print_r($rc); |
| <a name="l00018"></a>00018 } |
| <a name="l00019"></a>00019 <span class="comment">// list images</span> |
| <a name="l00020"></a>00020 elseif($_GET['state'] == 'listimages') { |
| <a name="l00021"></a>00021 $rc = remoteVCLCall('<a name="a1"></a><a class="code" href="xmlrpcWrappers_8php.html#e2c01a27349e7a7788a42cfb5fe0d5ab" title="gets the images to which the user has acces">XMLRPCgetImages</a>', array()); |
| <a name="l00022"></a>00022 print_r($rc); |
| <a name="l00023"></a>00023 } |
| <a name="l00024"></a>00024 <span class="comment">// add request</span> |
| <a name="l00025"></a>00025 elseif($_GET['state'] == 'addrequest') { |
| <a name="l00026"></a>00026 $rc = remoteVCLCall('<a name="a2"></a><a class="code" href="xmlrpcWrappers_8php.html#e6f9d40f20e08994fa3d82c8dd12bdf5" title="tries to make a request">XMLRPCaddRequest</a>', array(98, 'now', 60)); |
| <a name="l00027"></a>00027 <span class="keywordflow">if</span>($rc['status'] == 'success') { |
| <a name="l00028"></a>00028 print <span class="stringliteral">"request id is {$rc['requestid']}<br>\n"</span>; |
| <a name="l00029"></a>00029 $_SESSION['requestid'] = $rc['requestid']; |
| <a name="l00030"></a>00030 } |
| <a name="l00031"></a>00031 <span class="keywordflow">else</span> { |
| <a name="l00032"></a>00032 print_r($rc); |
| <a name="l00033"></a>00033 } |
| <a name="l00034"></a>00034 } |
| <a name="l00035"></a>00035 <span class="comment">// get request status</span> |
| <a name="l00036"></a>00036 elseif($_GET['state'] == 'requeststatus') { |
| <a name="l00037"></a>00037 <span class="keywordflow">if</span>(! array_key_exists('requestid', $_SESSION)) { |
| <a name="l00038"></a>00038 print <span class="stringliteral">"no request created<br>\n"</span>; |
| <a name="l00039"></a>00039 exit; |
| <a name="l00040"></a>00040 } |
| <a name="l00041"></a>00041 $rc = remoteVCLCall('<a name="a3"></a><a class="code" href="xmlrpcWrappers_8php.html#131560f1aa7577bd1da62d5b7e228e4c" title="determines and returns the status of the request">XMLRPCgetRequestStatus</a>', array($_SESSION['requestid'])); |
| <a name="l00042"></a>00042 print <span class="stringliteral">"current status of request {$_SESSION['requestid']} is {$rc['status']}"</span>; |
| <a name="l00043"></a>00043 } |
| <a name="l00044"></a>00044 <span class="comment">// get connection data</span> |
| <a name="l00045"></a>00045 elseif($_GET['state'] == 'connectdata') { |
| <a name="l00046"></a>00046 <span class="keywordflow">if</span>(! array_key_exists('requestid', $_SESSION)) { |
| <a name="l00047"></a>00047 print <span class="stringliteral">"no request created<br>\n"</span>; |
| <a name="l00048"></a>00048 exit; |
| <a name="l00049"></a>00049 } |
| <a name="l00050"></a>00050 $rc = remoteVCLCall('<a name="a4"></a><a class="code" href="xmlrpcWrappers_8php.html#f8b8c718ea7ea9cc973602a2fe9ae20e" title="if request is ready, adds the connecting user&#39;s computer to the request and returns...">XMLRPCgetRequestConnectData</a>', array($_SESSION['requestid'], $_SERVER[<span class="stringliteral">"REMOTE_ADDR"</span>])); |
| <a name="l00051"></a>00051 <span class="keywordflow">if</span>($rc['status'] == 'ready') |
| <a name="l00052"></a>00052 print_r($rc); |
| <a name="l00053"></a>00053 <span class="keywordflow">else</span> |
| <a name="l00054"></a>00054 print <span class="stringliteral">"status of request is {$rc['status']}"</span>; |
| <a name="l00055"></a>00055 } |
| <a name="l00056"></a>00056 <span class="comment">// end request</span> |
| <a name="l00057"></a>00057 elseif($_GET['state'] == 'endrequest') { |
| <a name="l00058"></a>00058 <span class="keywordflow">if</span>(! array_key_exists('requestid', $_SESSION)) { |
| <a name="l00059"></a>00059 print <span class="stringliteral">"no request created<br>\n"</span>; |
| <a name="l00060"></a>00060 exit; |
| <a name="l00061"></a>00061 } |
| <a name="l00062"></a>00062 $rc = remoteVCLCall('<a name="a5"></a><a class="code" href="xmlrpcWrappers_8php.html#dfdaad6201dbcaaf5c2249a2c38437cc" title="ends/deletes a request">XMLRPCendRequest</a>', array($_SESSION['requestid'])); |
| <a name="l00063"></a>00063 <span class="keywordflow">if</span>($rc['status'] == 'error') |
| <a name="l00064"></a>00064 print_r($rc); |
| <a name="l00065"></a>00065 <span class="keywordflow">else</span> { |
| <a name="l00066"></a>00066 print <span class="stringliteral">"request ended<br>\n"</span>; |
| <a name="l00067"></a>00067 unset($_SESSION['requestid']); |
| <a name="l00068"></a>00068 } |
| <a name="l00069"></a>00069 } |
| <a name="l00070"></a>00070 print <span class="stringliteral">"</pre>\n"</span>; |
| <a name="l00071"></a>00071 |
| <a name="l00072"></a>00072 function remoteVCLCall($method, $args) { |
| <a name="l00073"></a>00073 $request = xmlrpc_encode_request($method, $args); |
| <a name="l00074"></a>00074 $header = <span class="stringliteral">"Content-Type: text/xml\r\n"</span>; |
| <a name="l00075"></a>00075 $header .= <span class="stringliteral">"X-User: userid\r\n"</span>; <span class="comment">// user your userid here</span> |
| <a name="l00076"></a>00076 $header .= <span class="stringliteral">"X-Pass: password\r\n"</span>; <span class="comment">// user your password here</span> |
| <a name="l00077"></a>00077 $header .= <span class="stringliteral">"X-APIVERSION: 1"</span>; <span class="comment">// this is to allow for future changes to the api</span> |
| <a name="l00078"></a>00078 $context = stream_context_create( |
| <a name="l00079"></a>00079 array( |
| <a name="l00080"></a>00080 'http' => array( |
| <a name="l00081"></a>00081 'method' => <span class="stringliteral">"POST"</span>, |
| <a name="l00082"></a>00082 'header' => $header, |
| <a name="l00083"></a>00083 'content' => $request |
| <a name="l00084"></a>00084 ) |
| <a name="l00085"></a>00085 ) |
| <a name="l00086"></a>00086 ); |
| <a name="l00087"></a>00087 $file = file_get_contents(<span class="stringliteral">"https://vcl.ncsu.edu/scheduling/index.php?mode=xmlrpccall"</span>, <span class="keyword">false</span>, $context); |
| <a name="l00088"></a>00088 $response = xmlrpc_decode($file); |
| <a name="l00089"></a>00089 <span class="keywordflow">if</span>(xmlrpc_is_fault($response)) { |
| <a name="l00090"></a>00090 trigger_error(<span class="stringliteral">"xmlrpc: {$response['faultString']} ({$response['faultCode']})"</span>); |
| <a name="l00091"></a>00091 exit; |
| <a name="l00092"></a>00092 } |
| <a name="l00093"></a>00093 <span class="keywordflow">return</span> $response; |
| <a name="l00094"></a>00094 } |
| <a name="l00095"></a>00095 ?> |
| </pre></div> <hr size="1"><address style="text-align: right;"><small>Generated on Wed Dec 19 11:28:46 2007 for VCL XML RPC by |
| <a href="http://www.doxygen.org/index.html"> |
| <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address> |
| </body> |
| </html> |