1
0
mirror of https://e.coding.net/circlecloud/MinecraftAccount.git synced 2025-11-24 21:26:09 +00:00

首次提交...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092
2015-11-01 22:25:03 +08:00
commit 2003fda7cb
409 changed files with 77938 additions and 0 deletions

View File

@@ -0,0 +1,369 @@
<?php
/**********************************************************\
| |
| The implementation of PHPRPC Protocol 3.0 |
| |
| bigint.php |
| |
| Release 3.0.1 |
| Copyright by Team-PHPRPC |
| |
| WebSite: http://www.phprpc.org/ |
| http://www.phprpc.net/ |
| http://www.phprpc.com/ |
| http://sourceforge.net/projects/php-rpc/ |
| |
| Authors: Ma Bingyao <andot@ujn.edu.cn> |
| |
| This file may be distributed and/or modified under the |
| terms of the GNU General Public License (GPL) version |
| 2.0 as published by the Free Software Foundation and |
| appearing in the included file LICENSE. |
| |
\**********************************************************/
/* Big integer expansion library.
*
* Copyright: Ma Bingyao <andot@ujn.edu.cn>
* mgccl <mgcclx@gmail.com>
* Version: 3.0.1
* LastModified: Apr 12, 2010
* This library is free. You can redistribute it and/or modify it under GPL.
*/
if (extension_loaded('gmp')) {
function bigint_dec2num($dec) {
return gmp_init($dec);
}
function bigint_num2dec($num) {
return gmp_strval($num);
}
function bigint_str2num($str) {
return gmp_init("0x".bin2hex($str));
}
function bigint_num2str($num) {
$str = gmp_strval($num, 16);
$len = strlen($str);
if ($len % 2 == 1) {
$str = '0'.$str;
}
return pack("H*", $str);
}
function bigint_random($n, $s) {
$result = gmp_init(0);
for ($i = 0; $i < $n; $i++) {
if (mt_rand(0, 1)) {
gmp_setbit($result, $i);
}
}
if ($s) {
gmp_setbit($result, $n - 1);
}
return $result;
}
function bigint_powmod($x, $y, $m) {
return gmp_powm($x, $y, $m);
}
}
else if (extension_loaded('big_int')) {
function bigint_dec2num($dec) {
return bi_from_str($dec);
}
function bigint_num2dec($num) {
return bi_to_str($num);
}
function bigint_str2num($str) {
return bi_from_str(bin2hex($str), 16);
}
function bigint_num2str($num) {
$str = bi_to_str($num, 16);
$len = strlen($str);
if ($len % 2 == 1) {
$str = '0'.$str;
}
return pack("H*", $str);
}
function bigint_random($n, $s) {
$result = bi_rand($n);
if ($s) {
$result = bi_set_bit($result, $n - 1);
}
return $result;
}
function bigint_powmod($x, $y, $m) {
return bi_powmod($x, $y, $m);
}
}
else if (extension_loaded('bcmath')) {
function bigint_dec2num($dec) {
return $dec;
}
function bigint_num2dec($num) {
return $num;
}
function bigint_str2num($str) {
bcscale(0);
$len = strlen($str);
$result = '0';
$m = '1';
for ($i = 0; $i < $len; $i++) {
$result = bcadd(bcmul($m, ord($str{$len - $i - 1})), $result);
$m = bcmul($m, '256');
}
return $result;
}
function bigint_num2str($num) {
bcscale(0);
$str = "";
while (bccomp($num, '0') == 1) {
$str = chr(bcmod($num, '256')) . $str;
$num = bcdiv($num, '256');
}
return $str;
}
// author of bcmath bigint_random: mgccl <mgcclx@gmail.com>
function bigint_pow($b, $e) {
if ($b == 2) {
$a[96] = '79228162514264337593543950336';
$a[128] = '340282366920938463463374607431768211456';
$a[160] = '1461501637330902918203684832716283019655932542976';
$a[192] = '6277101735386680763835789423207666416102355444464034512896';
$a[256] = '115792089237316195423570985008687907853269984665640564039457584007913129639936';
$a[512] = '13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096';
$a[768] = '1552518092300708935148979488462502555256886017116696611139052038026050952686376886330878408828646477950487730697131073206171580044114814391444287275041181139204454976020849905550265285631598444825262999193716468750892846853816057856';
$a[1024] = '179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137216';
$a[1356] = '1572802244866018108182967249994981337399178505432223228293716677435703277129801955281491139254988030713172834803458459525011536776047399098682525970017006610187370020027540826048617586909475175880278263391147764612823746132583281588112028234096933800670620569966257212339315820309710495898777306979706509398705741430192541287726011814541176060679505247297118998085067003005943214893171428950699778511718055936';
$a[2048] = '32317006071311007300714876688669951960444102669715484032130345427524655138867890893197201411522913463688717960921898019494119559150490921095088152386448283120630877367300996091750197750389652106796057638384067568276792218642619756161838094338476170470581645852036305042887575891541065808607552399123930385521914333389668342420684974786564569494856176035326322058077805659331026192708460314150258592864177116725943603718461857357598351152301645904403697613233287231227125684710820209725157101726931323469678542580656697935045997268352998638215525166389437335543602135433229604645318478604952148193555853611059596230656';
$a[3072] = '5809605995369958062859502533304574370686975176362895236661486152287203730997110225737336044533118407251326157754980517443990529594540047121662885672187032401032111639706440498844049850989051627200244765807041812394729680540024104827976584369381522292361208779044769892743225751738076979568811309579125511333093243519553784816306381580161860200247492568448150242515304449577187604136428738580990172551573934146255830366405915000869643732053218566832545291107903722831634138599586406690325959725187447169059540805012310209639011750748760017095360734234945757416272994856013308616958529958304677637019181594088528345061285863898271763457294883546638879554311615446446330199254382340016292057090751175533888161918987295591531536698701292267685465517437915790823154844634780260102891718032495396075041899485513811126977307478969074857043710716150121315922024556759241239013152919710956468406379442914941614357107914462567329693696';
$a[4096] = '1044388881413152506691752710716624382579964249047383780384233483283953907971557456848826811934997558340890106714439262837987573438185793607263236087851365277945956976543709998340361590134383718314428070011855946226376318839397712745672334684344586617496807908705803704071284048740118609114467977783598029006686938976881787785946905630190260940599579453432823469303026696443059025015972399867714215541693835559885291486318237914434496734087811872639496475100189041349008417061675093668333850551032972088269550769983616369411933015213796825837188091833656751221318492846368125550225998300412344784862595674492194617023806505913245610825731835380087608622102834270197698202313169017678006675195485079921636419370285375124784014907159135459982790513399611551794271106831134090584272884279791554849782954323534517065223269061394905987693002122963395687782878948440616007412945674919823050571642377154816321380631045902916136926708342856440730447899971901781465763473223850267253059899795996090799469201774624817718449867455659250178329070473119433165550807568221846571746373296884912819520317457002440926616910874148385078411929804522981857338977648103126085903001302413467189726673216491511131602920781738033436090243804708340403154190336';
$a[8192] = '1090748135619415929462984244733782862448264161996232692431832786189721331849119295216264234525201987223957291796157025273109870820177184063610979765077554799078906298842192989538609825228048205159696851613591638196771886542609324560121290553901886301017900252535799917200010079600026535836800905297805880952350501630195475653911005312364560014847426035293551245843928918752768696279344088055617515694349945406677825140814900616105920256438504578013326493565836047242407382442812245131517757519164899226365743722432277368075027627883045206501792761700945699168497257879683851737049996900961120515655050115561271491492515342105748966629547032786321505730828430221664970324396138635251626409516168005427623435996308921691446181187406395310665404885739434832877428167407495370993511868756359970390117021823616749458620969857006263612082706715408157066575137281027022310927564910276759160520878304632411049364568754920967322982459184763427383790272448438018526977764941072715611580434690827459339991961414242741410599117426060556483763756314527611362658628383368621157993638020878537675545336789915694234433955666315070087213535470255670312004130725495834508357439653828936077080978550578912967907352780054935621561090795845172954115972927479877527738560008204118558930004777748727761853813510493840581861598652211605960308356405941821189714037868726219481498727603653616298856174822413033485438785324024751419417183012281078209729303537372804574372095228703622776363945290869806258422355148507571039619387449629866808188769662815778153079393179093143648340761738581819563002994422790754955061288818308430079648693232179158765918035565216157115402992120276155607873107937477466841528362987708699450152031231862594203085693838944657061346236704234026821102958954951197087076546186622796294536451620756509351018906023773821539532776208676978589731966330308893304665169436185078350641568336944530051437491311298834367265238595404904273455928723949525227184617404367854754610474377019768025576605881038077270707717942221977090385438585844095492116099852538903974655703943973086090930596963360767529964938414598185705963754561497355827813623833288906309004288017321424808663962671333528009232758350873059614118723781422101460198615747386855096896089189180441339558524822867541113212638793675567650340362970031930023397828465318547238244232028015189689660418822976000815437610652254270163595650875433851147123214227266605403581781469090806576468950587661997186505665475715792896';
return (isset($a[$e]) ? $a[$e] : bcpow(2, $e));
}
return bcpow($b, $e);
}
function bigint_random($n, $s) {
bcscale(0);
$t = bigint_pow(2, $n);
if ($s == 1) {
$m = bcdiv($t, 2);
$t = bcsub($m, 1);
}
else {
$m = 0;
$t = bcsub($t, 1);
}
$l = strlen($t);
$n = (int) ($l / 9) + 1;
$r = '';
while($n) {
$r .= substr('000000000' . mt_rand(0, 999999999), -9);
--$n;
}
$r = substr($r, 0, $l);
while (bccomp($r, $t) == 1) $r = substr($r, 1, $l) . mt_rand(0, 9);
return bcadd($r, $m);
}
if (!function_exists('bcpowmod')) {
function bcpowmod($x, $y, $modulus, $scale = 0) {
$t = '1';
while (bccomp($y, '0')) {
if (bccomp(bcmod($y, '2'), '0')) {
$t = bcmod(bcmul($t, $x), $modulus);
$y = bcsub($y, '1');
}
$x = bcmod(bcmul($x, $x), $modulus);
$y = bcdiv($y, '2');
}
return $t;
}
}
function bigint_powmod($x, $y, $m) {
return bcpowmod($x, $y, $m);
}
}
else {
function bigint_mul($a, $b) {
$n = count($a);
$m = count($b);
$nm = $n + $m;
$c = array_fill(0, $nm, 0);
for ($i = 0; $i < $n; $i++) {
for ($j = 0; $j < $m; $j++) {
$c[$i + $j] += $a[$i] * $b[$j];
$c[$i + $j + 1] += ($c[$i + $j] >> 15) & 0x7fff;
$c[$i + $j] &= 0x7fff;
}
}
return $c;
}
function bigint_div($a, $b, $is_mod = 0) {
$n = count($a);
$m = count($b);
$c = array();
$d = floor(0x8000 / ($b[$m - 1] + 1));
$a = bigint_mul($a, array($d));
$b = bigint_mul($b, array($d));
for ($j = $n - $m; $j >= 0; $j--) {
$tmp = $a[$j + $m] * 0x8000 + $a[$j + $m - 1];
$rr = $tmp % $b[$m - 1];
$qq = round(($tmp - $rr) / $b[$m - 1]);
if (($qq == 0x8000) || (($m > 1) && ($qq * $b[$m - 2] > 0x8000 * $rr + $a[$j + $m - 2]))) {
$qq--;
$rr += $b[$m - 1];
if (($rr < 0x8000) && ($qq * $b[$m - 2] > 0x8000 * $rr + $a[$j + $m - 2])) $qq--;
}
for ($i = 0; $i < $m; $i++) {
$tmp = $i + $j;
$a[$tmp] -= $b[$i] * $qq;
$a[$tmp + 1] += floor($a[$tmp] / 0x8000);
$a[$tmp] &= 0x7fff;
}
$c[$j] = $qq;
if ($a[$tmp + 1] < 0) {
$c[$j]--;
for ($i = 0; $i < $m; $i++) {
$tmp = $i + $j;
$a[$tmp] += $b[$i];
if ($a[$tmp] > 0x7fff) {
$a[$tmp + 1]++;
$a[$tmp] &= 0x7fff;
}
}
}
}
if (!$is_mod) return $c;
$b = array();
for ($i = 0; $i < $m; $i++) $b[$i] = $a[$i];
return bigint_div($b, array($d));
}
function bigint_zerofill($str, $num) {
return str_pad($str, $num, '0', STR_PAD_LEFT);
}
function bigint_dec2num($dec) {
$n = strlen($dec);
$a = array(0);
$n += 4 - ($n % 4);
$dec = bigint_zerofill($dec, $n);
$n >>= 2;
for ($i = 0; $i < $n; $i++) {
$a = bigint_mul($a, array(10000));
$a[0] += (int)substr($dec, 4 * $i, 4);
$m = count($a);
$j = 0;
$a[$m] = 0;
while ($j < $m && $a[$j] > 0x7fff) {
$a[$j++] &= 0x7fff;
$a[$j]++;
}
while ((count($a) > 1) && (!$a[count($a) - 1])) array_pop($a);
}
return $a;
}
function bigint_num2dec($num) {
$n = count($num) << 1;
$b = array();
for ($i = 0; $i < $n; $i++) {
$tmp = bigint_div($num, array(10000), 1);
$b[$i] = bigint_zerofill($tmp[0], 4);
$num = bigint_div($num, array(10000));
}
while ((count($b) > 1) && !(int)$b[count($b) - 1]) array_pop($b);
$n = count($b) - 1;
$b[$n] = (int)$b[$n];
$b = join('', array_reverse($b));
return $b;
}
function bigint_str2num($str) {
$n = strlen($str);
$n += 15 - ($n % 15);
$str = str_pad($str, $n, chr(0), STR_PAD_LEFT);
$j = 0;
$result = array();
for ($i = 0; $i < $n; $i++) {
$result[$j++] = (ord($str{$i++}) << 7) | (ord($str{$i}) >> 1);
$result[$j++] = ((ord($str{$i++}) & 0x01) << 14) | (ord($str{$i++}) << 6) | (ord($str{$i}) >> 2);
$result[$j++] = ((ord($str{$i++}) & 0x03) << 13) | (ord($str{$i++}) << 5) | (ord($str{$i}) >> 3);
$result[$j++] = ((ord($str{$i++}) & 0x07) << 12) | (ord($str{$i++}) << 4) | (ord($str{$i}) >> 4);
$result[$j++] = ((ord($str{$i++}) & 0x0f) << 11) | (ord($str{$i++}) << 3) | (ord($str{$i}) >> 5);
$result[$j++] = ((ord($str{$i++}) & 0x1f) << 10) | (ord($str{$i++}) << 2) | (ord($str{$i}) >> 6);
$result[$j++] = ((ord($str{$i++}) & 0x3f) << 9) | (ord($str{$i++}) << 1) | (ord($str{$i}) >> 7);
$result[$j++] = ((ord($str{$i++}) & 0x7f) << 8) | ord($str{$i});
}
$result = array_reverse($result);
$i = count($result) - 1;
while ($result[$i] == 0) {
array_pop($result);
$i--;
}
return $result;
}
function bigint_num2str($num) {
ksort($num, SORT_NUMERIC);
$n = count($num);
$n += 8 - ($n % 8);
$num = array_reverse(array_pad($num, $n, 0));
$s = '';
for ($i = 0; $i < $n; $i++) {
$s .= chr($num[$i] >> 7);
$s .= chr((($num[$i++] & 0x7f) << 1) | ($num[$i] >> 14));
$s .= chr(($num[$i] >> 6) & 0xff);
$s .= chr((($num[$i++] & 0x3f) << 2) | ($num[$i] >> 13));
$s .= chr(($num[$i] >> 5) & 0xff);
$s .= chr((($num[$i++] & 0x1f) << 3) | ($num[$i] >> 12));
$s .= chr(($num[$i] >> 4) & 0xff);
$s .= chr((($num[$i++] & 0x0f) << 4) | ($num[$i] >> 11));
$s .= chr(($num[$i] >> 3) & 0xff);
$s .= chr((($num[$i++] & 0x07) << 5) | ($num[$i] >> 10));
$s .= chr(($num[$i] >> 2) & 0xff);
$s .= chr((($num[$i++] & 0x03) << 6) | ($num[$i] >> 9));
$s .= chr(($num[$i] >> 1) & 0xff);
$s .= chr((($num[$i++] & 0x01) << 7) | ($num[$i] >> 8));
$s .= chr($num[$i] & 0xff);
}
return ltrim($s, chr(0));
}
function bigint_random($n, $s) {
$lowBitMasks = array(0x0000, 0x0001, 0x0003, 0x0007,
0x000f, 0x001f, 0x003f, 0x007f,
0x00ff, 0x01ff, 0x03ff, 0x07ff,
0x0fff, 0x1fff, 0x3fff);
$r = $n % 15;
$q = floor($n / 15);
$result = array();
for ($i = 0; $i < $q; $i++) {
$result[$i] = mt_rand(0, 0x7fff);
}
if ($r != 0) {
$result[$q] = mt_rand(0, $lowBitMasks[$r]);
if ($s) {
$result[$q] |= 1 << ($r - 1);
}
}
else if ($s) {
$result[$q - 1] |= 0x4000;
}
return $result;
}
function bigint_powmod($x, $y, $m) {
$n = count($y);
$p = array(1);
for ($i = 0; $i < $n - 1; $i++) {
$tmp = $y[$i];
for ($j = 0; $j < 0xf; $j++) {
if ($tmp & 1) $p = bigint_div(bigint_mul($p, $x), $m, 1);
$tmp >>= 1;
$x = bigint_div(bigint_mul($x, $x), $m, 1);
}
}
$tmp = $y[$i];
while ($tmp) {
if ($tmp & 1) $p = bigint_div(bigint_mul($p, $x), $m, 1);
$tmp >>= 1;
$x = bigint_div(bigint_mul($x, $x), $m, 1);
}
return $p;
}
}
?>

View File

@@ -0,0 +1,242 @@
<?php
/**********************************************************\
| |
| The implementation of PHPRPC Protocol 3.0 |
| |
| compat.php |
| |
| Release 3.0.1 |
| Copyright by Team-PHPRPC |
| |
| WebSite: http://www.phprpc.org/ |
| http://www.phprpc.net/ |
| http://www.phprpc.com/ |
| http://sourceforge.net/projects/php-rpc/ |
| |
| Authors: Ma Bingyao <andot@ujn.edu.cn> |
| |
| This file may be distributed and/or modified under the |
| terms of the GNU General Public License (GPL) version |
| 2.0 as published by the Free Software Foundation and |
| appearing in the included file LICENSE. |
| |
\**********************************************************/
/* Provides missing functionality for older versions of PHP.
*
* Copyright: Ma Bingyao <andot@ujn.edu.cn>
* Version: 1.5
* LastModified: Apr 12, 2010
* This library is free. You can redistribute it and/or modify it under GPL.
*/
require_once("phprpc_date.php");
if (!function_exists('file_get_contents')) {
function file_get_contents($filename, $incpath = false, $resource_context = null) {
if (false === $fh = fopen($filename, 'rb', $incpath)) {
user_error('file_get_contents() failed to open stream: No such file or directory',
E_USER_WARNING);
return false;
}
clearstatcache();
if ($fsize = @filesize($filename)) {
$data = fread($fh, $fsize);
}
else {
$data = '';
while (!feof($fh)) {
$data .= fread($fh, 8192);
}
}
fclose($fh);
return $data;
}
}
if (!function_exists('ob_get_clean')) {
function ob_get_clean() {
$contents = ob_get_contents();
if ($contents !== false) ob_end_clean();
return $contents;
}
}
/**
3 more bugs found and fixed:
1. failed to work when the gz contained a filename - FIXED
2. failed to work on 64-bit architecture (checksum) - FIXED
3. failed to work when the gz contained a comment - cannot verify.
Returns some errors (not all!) and filename.
*/
if (!function_exists('gzdecode')) {
function gzdecode($data, &$filename = '', &$error = '', $maxlength = null) {
$len = strlen($data);
if ($len < 18 || strcmp(substr($data, 0, 2), "\x1f\x8b")) {
$error = "Not in GZIP format.";
return null; // Not GZIP format (See RFC 1952)
}
$method = ord(substr($data, 2, 1)); // Compression method
$flags = ord(substr($data, 3, 1)); // Flags
if ($flags & 31 != $flags) {
$error = "Reserved bits not allowed.";
return null;
}
// NOTE: $mtime may be negative (PHP integer limitations)
$mtime = unpack("V", substr($data, 4, 4));
$mtime = $mtime[1];
$xfl = substr($data, 8, 1);
$os = substr($data, 8, 1);
$headerlen = 10;
$extralen = 0;
$extra = "";
if ($flags & 4) {
// 2-byte length prefixed EXTRA data in header
if ($len - $headerlen - 2 < 8) {
return false; // invalid
}
$extralen = unpack("v", substr($data, 8, 2));
$extralen = $extralen[1];
if ($len - $headerlen - 2 - $extralen < 8) {
return false; // invalid
}
$extra = substr($data, 10, $extralen);
$headerlen += 2 + $extralen;
}
$filenamelen = 0;
$filename = "";
if ($flags & 8) {
// C-style string
if ($len - $headerlen - 1 < 8) {
return false; // invalid
}
$filenamelen = strpos(substr($data, $headerlen), chr(0));
if ($filenamelen === false || $len - $headerlen - $filenamelen - 1 < 8) {
return false; // invalid
}
$filename = substr($data, $headerlen, $filenamelen);
$headerlen += $filenamelen + 1;
}
$commentlen = 0;
$comment = "";
if ($flags & 16) {
// C-style string COMMENT data in header
if ($len - $headerlen - 1 < 8) {
return false; // invalid
}
$commentlen = strpos(substr($data, $headerlen), chr(0));
if ($commentlen === false || $len - $headerlen - $commentlen - 1 < 8) {
return false; // Invalid header format
}
$comment = substr($data, $headerlen, $commentlen);
$headerlen += $commentlen + 1;
}
$headercrc = "";
if ($flags & 2) {
// 2-bytes (lowest order) of CRC32 on header present
if ($len - $headerlen - 2 < 8) {
return false; // invalid
}
$calccrc = crc32(substr($data, 0, $headerlen)) & 0xffff;
$headercrc = unpack("v", substr($data, $headerlen, 2));
$headercrc = $headercrc[1];
if ($headercrc != $calccrc) {
$error = "Header checksum failed.";
return false; // Bad header CRC
}
$headerlen += 2;
}
// GZIP FOOTER
$datacrc = unpack("V", substr($data, -8, 4));
$datacrc = sprintf('%u', $datacrc[1] & 0xFFFFFFFF);
$isize = unpack("V", substr($data, -4));
$isize = $isize[1];
// decompression:
$bodylen = $len - $headerlen - 8;
if ($bodylen < 1) {
// IMPLEMENTATION BUG!
return null;
}
$body = substr($data, $headerlen, $bodylen);
$data = "";
if ($bodylen > 0) {
switch ($method) {
case 8:
// Currently the only supported compression method:
$data = gzinflate($body, $maxlength);
break;
default:
$error = "Unknown compression method.";
return false;
}
} // zero-byte body content is allowed
// Verifiy CRC32
$crc = sprintf("%u", crc32($data));
$crcOK = $crc == $datacrc;
$lenOK = $isize == strlen($data);
if (!$lenOK || !$crcOK) {
$error = ( $lenOK ? '' : 'Length check FAILED. ') . ( $crcOK ? '' : 'Checksum FAILED.');
return false;
}
return $data;
}
}
if (version_compare(phpversion(), "5", "<")) {
function serialize_fix($v) {
return str_replace('O:11:"phprpc_date":7:{', 'O:11:"PHPRPC_Date":7:{', serialize($v));
}
}
else {
function serialize_fix($v) {
return serialize($v);
}
}
function declare_empty_class($classname) {
static $callback = null;
$classname = preg_replace('/[^a-zA-Z0-9\_]/', '', $classname);
if ($callback===null) {
$callback = $classname;
return;
}
if ($callback) {
call_user_func($callback, $classname);
}
if (!class_exists($classname)) {
if (version_compare(phpversion(), "5", "<")) {
eval('class ' . $classname . ' { }');
}
else {
eval('
class ' . $classname . ' {
private function __get($name) {
$vars = (array)$this;
$protected_name = "\0*\0$name";
$private_name = "\0'.$classname.'\0$name";
if (array_key_exists($name, $vars)) {
return $this->$name;
}
else if (array_key_exists($protected_name, $vars)) {
return $vars[$protected_name];
}
else if (array_key_exists($private_name, $vars)) {
return $vars[$private_name];
}
else {
$keys = array_keys($vars);
$keys = array_values(preg_grep("/^\\\\x00.*?\\\\x00".$name."$/", $keys));
if (isset($keys[0])) {
return $vars[$keys[0]];
}
else {
return NULL;
}
}
}
}');
}
}
}
declare_empty_class(ini_get('unserialize_callback_func'));
ini_set('unserialize_callback_func', 'declare_empty_class');
?>

View File

@@ -0,0 +1,77 @@
<?php
/**********************************************************\
| |
| The implementation of PHPRPC Protocol 3.0 |
| |
| dhparams.php |
| |
| Release 3.0.1 |
| Copyright by Team-PHPRPC |
| |
| WebSite: http://www.phprpc.org/ |
| http://www.phprpc.net/ |
| http://www.phprpc.com/ |
| http://sourceforge.net/projects/php-rpc/ |
| |
| Authors: Ma Bingyao <andot@ujn.edu.cn> |
| |
| This file may be distributed and/or modified under the |
| terms of the GNU General Public License (GPL) version |
| 2.0 as published by the Free Software Foundation and |
| appearing in the included file LICENSE. |
| |
\**********************************************************/
/* Diffie-Hellman Parameters for PHPRPC.
*
* Copyright: Ma Bingyao <andot@ujn.edu.cn>
* Version: 1.2
* LastModified: Apr 12, 2010
* This library is free. You can redistribute it and/or modify it under GPL.
*/
class DHParams {
var $len;
var $dhParams;
function getNearest($n, $a) {
$j = 0;
$m = abs($a[0] - $n);
for ($i = 1; $i < count($a); $i++) {
$t = abs($a[$i] - $n);
if ($m > $t) {
$m = $t;
$j = $i;
}
}
return $a[$j];
}
function DHParams($len = 128) {
if (extension_loaded('gmp')) {
$a = array(96, 128, 160, 192, 256, 512, 768, 1024, 1536, 2048, 3072, 4096);
}
else if (extension_loaded('big_int')) {
$a = array(96, 128, 160, 192, 256, 512, 768, 1024, 1536);
}
else if (extension_loaded('bcmath')) {
$a = array(96, 128, 160, 192, 256, 512);
}
else {
$a = array(96, 128, 160);
}
$this->len = $this->getNearest($len, $a);
$dhParams = unserialize(file_get_contents("dhparams/{$this->len}.dhp", true));
$this->dhParams = $dhParams[mt_rand(0, count($dhParams) - 1)];
}
function getL() {
return $this->len;
}
function getP() {
return $this->dhParams['p'];
}
function getG() {
return $this->dhParams['g'];
}
function getDHParams() {
return $this->dhParams;
}
}
?>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
XXTEA PHP extension
Ma Bingyao (andot@coolcode.cn)

View File

@@ -0,0 +1,66 @@
Installing of XXTEA PHP package.
There are many ways to build the package. Below you can find details for most
useful ways of package building:
1. with PHP
2. with phpize utility
3. under Windows using Microsoft Visual C (.NET or VC6)
-----------------------------------------------------------------------------
Way 1: Building the package with PHP
-----------------------------------------------------------------------------
1. Create ext/xxtea folder in the php-source-folder. Copy all files
from the package into created folder.
2. Run
./buildconf
to rebuild PHP's configure script.
3. Compile php with option:
--enable-xxtea to build bundled into PHP module
--enable-xxtea=shared to build dinamycally loadable module
-----------------------------------------------------------------------------
Way 2: Building the package with phpize utility
-----------------------------------------------------------------------------
1. Unpack contents of the package.
2. Run
phpize
script, which will prepare environment for building XXTEA package.
3. Run
./configure --enable-xxtea=shared
to generate makefile
4. Run
make
to build XXTEA extension library. It will be placed into
./modules folder.
5. Run
make install
to install XXTEA extension library into PHP
-----------------------------------------------------------------------------
Way 3: Building the package under Windows using Microsoft Visual C (.NET or VC6)
-----------------------------------------------------------------------------
1. Create ext/xxtea folder in the php-source-folder. Copy all files
from the package into created folder.
2. Copy php4ts.lib (for PHP4) or php5ts.lib (for PHP5) static library from
your version of PHP into ext/xxtea folder.
3. Open php_xxtea.sln - solution file under MSVC.NET or php_xxtea.dsw -
workspace file under MSVC6. Try to build Release_php4 (for PHP4) or Release_php5
(for PHP5) configuration.
4. Copy php_xxtea.dll from ext/xxtea/Release_php4 or ext/xxtea/Release_php5
into {extension_dir} folder. Path to {extension_dir} can be found in php.ini
5. Add line
extension=php_xxtea.dll
into php.ini

View File

@@ -0,0 +1,68 @@
--------------------------------------------------------------------
The PHP License, version 3.01
Copyright (c) 1999 - 2006 The PHP Group. All rights reserved.
--------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
modification, is permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The name "PHP" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact group@php.net.
4. Products derived from this software may not be called "PHP", nor
may "PHP" appear in their name, without prior written permission
from group@php.net. You may indicate that your software works in
conjunction with PHP by saying "Foo for PHP" instead of calling
it "PHP Foo" or "phpfoo"
5. The PHP Group may publish revised and/or new versions of the
license from time to time. Each version will be given a
distinguishing version number.
Once covered code has been published under a particular version
of the license, you may always continue to use it under the terms
of that version. You may also choose to use such covered code
under the terms of any subsequent version of the license
published by the PHP Group. No one other than the PHP Group has
the right to modify the terms applicable to covered code created
under this License.
6. Redistributions of any form whatsoever must retain the following
acknowledgment:
"This product includes PHP software, freely available from
<http://www.php.net/software/>".
THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP
DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------
This software consists of voluntary contributions made by many
individuals on behalf of the PHP Group.
The PHP Group can be contacted via Email at group@php.net.
For more information on the PHP Group and the PHP project,
please see <http://www.php.net>.
PHP includes the Zend Engine, freely available at
<http://www.zend.com>.

View File

@@ -0,0 +1,28 @@
XXTEA PHP extension
What is it?
-----------------------------------------------
This extension based on xxtea library, which provides a set of functions
for encrypt or decrypt data with XXTEA algorithm.
How to install it?
-----------------------------------------------
See INSTALL for installation instructions.
How to use it?
-----------------------------------------------
string xxtea_encrypt(string data, string key)
Encrypt data using XXTEA algorithm. The key is a 16 bytes(128 bits) string.
string xxtea_decrypt(string data, string key)
Decrypt data using XXTEA algorithm. The key is a 16 bytes(128 bits) string.
string xxtea_info()
Get the version information.

View File

@@ -0,0 +1,7 @@
PHP_ARG_ENABLE(xxtea, xxtea module,
[ --enable-xxtea Enable xxtea module.])
if test "$PHP_XXTEA" != "no"; then
PHP_NEW_EXTENSION(xxtea, php_xxtea.c xxtea.c, $ext_shared)
AC_DEFINE(HAVE_XXTEA, 1, [Have XXTEA library])
fi

View File

@@ -0,0 +1,6 @@
ARG_ENABLE("xxtea", "xxtea module", "no");
if (PHP_XXTEA != "no") {
EXTENSION("xxtea", "php_xxtea.c xxtea.c");
}

View File

@@ -0,0 +1,193 @@
/***********************************************************************
Copyright 2006-2007 Ma Bingyao
These sources is free software. Redistributions of source code must
retain the above copyright notice. Redistributions in binary form
must reproduce the above copyright notice. You can redistribute it
freely. You can use it with any free or commercial software.
These sources is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. Without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You may contact the author by:
e-mail: andot@coolcode.cn
*************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#if HAVE_XXTEA
#include "php_xxtea.h"
#include "ext/standard/info.h" /* for phpinfo() functions */
#include "xxtea.h"
/* compiled function list so Zend knows what's in this module */
zend_function_entry xxtea_functions[] =
{
ZEND_FE(xxtea_encrypt, NULL)
ZEND_FE(xxtea_decrypt, NULL)
ZEND_FE(xxtea_info, NULL)
{NULL, NULL, NULL}
};
/* compiled module information */
zend_module_entry xxtea_module_entry =
{
STANDARD_MODULE_HEADER,
XXTEA_MODULE_NAME,
xxtea_functions,
ZEND_MINIT(xxtea),
ZEND_MSHUTDOWN(xxtea),
NULL,
NULL,
ZEND_MINFO(xxtea),
XXTEA_VERSION,
STANDARD_MODULE_PROPERTIES
};
/* implement standard "stub" routine to introduce ourselves to Zend */
#if defined(COMPILE_DL_XXTEA)
ZEND_GET_MODULE(xxtea)
#endif
static xxtea_long *xxtea_to_long_array(unsigned char *data, xxtea_long len, int include_length, xxtea_long *ret_len) {
xxtea_long i, n, *result;
n = len >> 2;
n = (((len & 3) == 0) ? n : n + 1);
if (include_length) {
result = (xxtea_long *)emalloc((n + 1) << 2);
result[n] = len;
*ret_len = n + 1;
} else {
result = (xxtea_long *)emalloc(n << 2);
*ret_len = n;
}
memset(result, 0, n << 2);
for (i = 0; i < len; i++) {
result[i >> 2] |= (xxtea_long)data[i] << ((i & 3) << 3);
}
return result;
}
static unsigned char *xxtea_to_byte_array(xxtea_long *data, xxtea_long len, int include_length, xxtea_long *ret_len) {
xxtea_long i, n, m;
unsigned char *result;
n = len << 2;
if (include_length) {
m = data[len - 1];
if ((m < n - 7) || (m > n - 4)) return NULL;
n = m;
}
result = (unsigned char *)emalloc(n + 1);
for (i = 0; i < n; i++) {
result[i] = (unsigned char)((data[i >> 2] >> ((i & 3) << 3)) & 0xff);
}
result[n] = '\0';
*ret_len = n;
return result;
}
static unsigned char *php_xxtea_encrypt(unsigned char *data, xxtea_long len, unsigned char *key, xxtea_long *ret_len) {
unsigned char *result;
xxtea_long *v, *k, v_len, k_len;
v = xxtea_to_long_array(data, len, 1, &v_len);
k = xxtea_to_long_array(key, 16, 0, &k_len);
xxtea_long_encrypt(v, v_len, k);
result = xxtea_to_byte_array(v, v_len, 0, ret_len);
efree(v);
efree(k);
return result;
}
static unsigned char *php_xxtea_decrypt(unsigned char *data, xxtea_long len, unsigned char *key, xxtea_long *ret_len) {
unsigned char *result;
xxtea_long *v, *k, v_len, k_len;
v = xxtea_to_long_array(data, len, 0, &v_len);
k = xxtea_to_long_array(key, 16, 0, &k_len);
xxtea_long_decrypt(v, v_len, k);
result = xxtea_to_byte_array(v, v_len, 1, ret_len);
efree(v);
efree(k);
return result;
}
/* {{{ proto string xxtea_encrypt(string data, string key)
Encrypt string using XXTEA algorithm */
ZEND_FUNCTION(xxtea_encrypt)
{
unsigned char *data, *key;
unsigned char *result;
xxtea_long data_len, key_len, ret_length;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &data, &data_len, &key, &key_len) == FAILURE) {
return;
}
if (data_len == 0) RETVAL_STRINGL(NULL, 0, 0);
if (key_len != 16) RETURN_FALSE;
result = php_xxtea_encrypt(data, data_len, key, &ret_length);
if (result != NULL) {
RETVAL_STRINGL((char *)result, ret_length, 0);
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto string xxtea_decrypt(string data, string key)
Decrypt string using XXTEA algorithm */
ZEND_FUNCTION(xxtea_decrypt)
{
unsigned char *data, *key;
unsigned char *result;
xxtea_long data_len, key_len, ret_length;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &data, &data_len, &key, &key_len) == FAILURE) {
return;
}
if (data_len == 0) RETVAL_STRINGL(NULL, 0, 0);
if (key_len != 16) RETURN_FALSE;
result = php_xxtea_decrypt(data, data_len, key, &ret_length);
if (result != NULL) {
RETVAL_STRINGL((char *)result, ret_length, 0);
} else {
RETURN_FALSE;
}
}
/* }}} */
ZEND_MINIT_FUNCTION(xxtea)
{
return SUCCESS;
}
ZEND_MSHUTDOWN_FUNCTION(xxtea)
{
return SUCCESS;
}
ZEND_MINFO_FUNCTION(xxtea)
{
php_info_print_table_start();
php_info_print_table_row(2, "xxtea support", "enabled");
php_info_print_table_row(2, "xxtea module version", XXTEA_VERSION);
php_info_print_table_row(2, "xxtea author", XXTEA_AUTHOR);
php_info_print_table_row(2, "xxtea homepage", XXTEA_HOMEPAGE);
php_info_print_table_end();
}
ZEND_FUNCTION(xxtea_info)
{
array_init(return_value);
add_assoc_string(return_value, "ext_version", XXTEA_VERSION, 1);
add_assoc_string(return_value, "ext_build_date", XXTEA_BUILD_DATE, 1);
add_assoc_string(return_value, "ext_author", XXTEA_AUTHOR, 1);
add_assoc_string(return_value, "ext_homepage", XXTEA_HOMEPAGE, 1);
}
#endif /* if HAVE_XXTEA */

View File

@@ -0,0 +1,179 @@
# Microsoft Developer Studio Project File - Name="php_xxtea" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=php_xxtea - Win32 Debug_php5
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "php_xxtea.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "php_xxtea.mak" CFG="php_xxtea - Win32 Debug_php5"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "php_xxtea - Win32 Debug_php5" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "php_xxtea - Win32 Release_php5" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "php_xxtea - Win32 Debug_php4" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "php_xxtea - Win32 Release_php4" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "php_xxtea - Win32 Debug_php5"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug_php5"
# PROP BASE Intermediate_Dir "Debug_php5"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug_php5"
# PROP Intermediate_Dir "Debug_php5"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /I "../.." /I "../../main" /I "../../Zend" /I "../../TSRM" /ZI /W3 /Od /D "HAVE_XXTEA" /D "COMPILE_DL_XXTEA" /D "ZTS" /D "NDEBUG" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "ZEND_DEBUG=1" /D "_MBCS" /Gm /GZ /c /GX
# ADD CPP /nologo /MTd /I "../.." /I "../../main" /I "../../Zend" /I "../../TSRM" /ZI /W3 /Od /D "HAVE_XXTEA" /D "COMPILE_DL_XXTEA" /D "ZTS" /D "NDEBUG" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "ZEND_DEBUG=1" /D "_MBCS" /Gm /GZ /c /GX
# ADD BASE MTL /nologo /win32
# ADD MTL /nologo /win32
# ADD BASE RSC /l 1033
# ADD RSC /l 1033
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php5ts.lib /nologo /dll /out:"Debug_php5\php_xxtea.dll" /incremental:yes /libpath:"../../Release_TS" /debug /pdb:"Debug_php5\php_xxtea.pdb" /pdbtype:sept /subsystem:windows /implib:"$(OutDir)/php_xxtea.lib" /machine:ix86
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php5ts.lib /nologo /dll /out:"Debug_php5\php_xxtea.dll" /incremental:yes /libpath:"../../Release_TS" /debug /pdb:"Debug_php5\php_xxtea.pdb" /pdbtype:sept /subsystem:windows /implib:"$(OutDir)/php_xxtea.lib" /machine:ix86
!ELSEIF "$(CFG)" == "php_xxtea - Win32 Release_php5"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release_php5"
# PROP BASE Intermediate_Dir "Release_php5"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release_php5"
# PROP Intermediate_Dir "Release_php5"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MD /I "../.." /I "../../main" /I "../../Zend" /I "../../TSRM" /W3 /O1 /Og /Oi /Os /Oy /GT /G6 /GA /D "HAVE_XXTEA" /D "COMPILE_DL_XXTEA" /D "ZTS" /D "NDEBUG" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "ZEND_DEBUG=0" /D "_MBCS" /GF /Gy /TC /c /GX
# ADD CPP /nologo /MD /I "../.." /I "../../main" /I "../../Zend" /I "../../TSRM" /W3 /O1 /Og /Oi /Os /Oy /GT /G6 /GA /D "HAVE_XXTEA" /D "COMPILE_DL_XXTEA" /D "ZTS" /D "NDEBUG" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "ZEND_DEBUG=0" /D "_MBCS" /GF /Gy /TC /c /GX
# ADD BASE MTL /nologo /win32
# ADD MTL /nologo /win32
# ADD BASE RSC /l 1033
# ADD RSC /l 1033
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php5ts.lib /nologo /dll /out:"Release_php5\php_xxtea.dll" /incremental:no /libpath:"../../Release_TS" /pdbtype:sept /subsystem:windows /opt:ref /opt:icf /implib:"$(OutDir)/php_xxtea.lib" /machine:ix86
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php5ts.lib /nologo /dll /out:"Release_php5\php_xxtea.dll" /incremental:no /libpath:"../../Release_TS" /pdbtype:sept /subsystem:windows /opt:ref /opt:icf /implib:"$(OutDir)/php_xxtea.lib" /machine:ix86
!ELSEIF "$(CFG)" == "php_xxtea - Win32 Debug_php4"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug_php4"
# PROP BASE Intermediate_Dir "Debug_php4"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug_php4"
# PROP Intermediate_Dir "Debug_php4"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /I "../.." /I "../../main" /I "../../Zend" /I "../../TSRM" /ZI /W3 /Od /D "HAVE_XXTEA" /D "COMPILE_DL_XXTEA" /D "ZTS" /D "NDEBUG" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "ZEND_DEBUG=1" /D "_MBCS" /Gm /GZ /c /GX
# ADD CPP /nologo /MTd /I "../.." /I "../../main" /I "../../Zend" /I "../../TSRM" /ZI /W3 /Od /D "HAVE_XXTEA" /D "COMPILE_DL_XXTEA" /D "ZTS" /D "NDEBUG" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "ZEND_DEBUG=1" /D "_MBCS" /Gm /GZ /c /GX
# ADD BASE MTL /nologo /win32
# ADD MTL /nologo /win32
# ADD BASE RSC /l 1033
# ADD RSC /l 1033
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /dll /out:"Debug_php4\php_xxtea.dll" /incremental:yes /libpath:"../../Release_TS" /debug /pdb:"Debug_php4\php_xxtea.pdb" /pdbtype:sept /subsystem:windows /implib:"$(OutDir)/php_xxtea.lib" /machine:ix86
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /dll /out:"Debug_php4\php_xxtea.dll" /incremental:yes /libpath:"../../Release_TS" /debug /pdb:"Debug_php4\php_xxtea.pdb" /pdbtype:sept /subsystem:windows /implib:"$(OutDir)/php_xxtea.lib" /machine:ix86
!ELSEIF "$(CFG)" == "php_xxtea - Win32 Release_php4"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release_php4"
# PROP BASE Intermediate_Dir "Release_php4"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release_php4"
# PROP Intermediate_Dir "Release_php4"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MD /I "../.." /I "../../main" /I "../../Zend" /I "../../TSRM" /W3 /O1 /Og /Oi /Os /Oy /GT /G6 /GA /D "HAVE_XXTEA" /D "COMPILE_DL_XXTEA" /D "ZTS" /D "NDEBUG" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "ZEND_DEBUG=0" /D "_MBCS" /GF /Gy /TC /c /GX
# ADD CPP /nologo /MD /I "../.." /I "../../main" /I "../../Zend" /I "../../TSRM" /W3 /O1 /Og /Oi /Os /Oy /GT /G6 /GA /D "HAVE_XXTEA" /D "COMPILE_DL_XXTEA" /D "ZTS" /D "NDEBUG" /D "ZEND_WIN32" /D "PHP_WIN32" /D "WIN32" /D "ZEND_DEBUG=0" /D "_MBCS" /GF /Gy /TC /c /GX
# ADD BASE MTL /nologo /win32
# ADD MTL /nologo /win32
# ADD BASE RSC /l 1033
# ADD RSC /l 1033
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /dll /out:"Release_php4\php_xxtea.dll" /incremental:no /libpath:"../../Release_TS" /pdbtype:sept /subsystem:windows /opt:ref /opt:icf /implib:"$(OutDir)/php_xxtea.lib" /machine:ix86
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /dll /out:"Release_php4\php_xxtea.dll" /incremental:no /libpath:"../../Release_TS" /pdbtype:sept /subsystem:windows /opt:ref /opt:icf /implib:"$(OutDir)/php_xxtea.lib" /machine:ix86
!ENDIF
# Begin Target
# Name "php_xxtea - Win32 Debug_php5"
# Name "php_xxtea - Win32 Release_php5"
# Name "php_xxtea - Win32 Debug_php4"
# Name "php_xxtea - Win32 Release_php4"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;def;odl;idl;hpj;bat;asm"
# Begin Source File
SOURCE=php_xxtea.c
# End Source File
# Begin Group "lib_xxtea"
# PROP Default_Filter ""
# Begin Source File
SOURCE=xxtea.c
# End Source File
# End Group
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl;inc"
# Begin Source File
SOURCE=php_xxtea.h
# End Source File
# Begin Group "lib_xxtea"
# PROP Default_Filter ""
# Begin Source File
SOURCE=xxtea.h
# End Source File
# End Group
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@@ -0,0 +1,49 @@
/***********************************************************************
Copyright 2006-2007 Ma Bingyao
These sources is free software. Redistributions of source code must
retain the above copyright notice. Redistributions in binary form
must reproduce the above copyright notice. You can redistribute it
freely. You can use it with any free or commercial software.
These sources is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. Without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You may contact the author by:
e-mail: andot@coolcode.cn
*************************************************************************/
#ifndef PHP_XXTEA_H
#define PHP_XXTEA_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if HAVE_XXTEA
extern zend_module_entry xxtea_module_entry;
#define phpext_xxtea_ptr &xxtea_module_entry
#define XXTEA_MODULE_NAME "xxtea"
#define XXTEA_BUILD_DATE __DATE__ " " __TIME__
#define XXTEA_VERSION "1.0.3"
#define XXTEA_AUTHOR "Ma Bingyao"
#define XXTEA_HOMEPAGE "http://www.coolcode.cn/?p=209"
ZEND_MINIT_FUNCTION(xxtea);
ZEND_MSHUTDOWN_FUNCTION(xxtea);
ZEND_MINFO_FUNCTION(xxtea);
/* declaration of functions to be exported */
ZEND_FUNCTION(xxtea_encrypt);
ZEND_FUNCTION(xxtea_decrypt);
ZEND_FUNCTION(xxtea_info);
#else /* if HAVE_XXTEA */
#define phpext_xxtea_ptr NULL
#endif
#endif /* ifndef PHP_XXTEA_H */

View File

@@ -0,0 +1,25 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "php_xxtea", "php_xxtea.vcproj", "{71165FA5-1EBC-4021-AA17-0CCBC7CD5204}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_php4|Win32 = Debug_php4|Win32
Debug_php5|Win32 = Debug_php5|Win32
Release_php4|Win32 = Release_php4|Win32
Release_php5|Win32 = Release_php5|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{71165FA5-1EBC-4021-AA17-0CCBC7CD5204}.Debug_php4|Win32.ActiveCfg = Debug_php4|Win32
{71165FA5-1EBC-4021-AA17-0CCBC7CD5204}.Debug_php4|Win32.Build.0 = Debug_php4|Win32
{71165FA5-1EBC-4021-AA17-0CCBC7CD5204}.Debug_php5|Win32.ActiveCfg = Debug_php5|Win32
{71165FA5-1EBC-4021-AA17-0CCBC7CD5204}.Debug_php5|Win32.Build.0 = Debug_php5|Win32
{71165FA5-1EBC-4021-AA17-0CCBC7CD5204}.Release_php4|Win32.ActiveCfg = Release_php4|Win32
{71165FA5-1EBC-4021-AA17-0CCBC7CD5204}.Release_php4|Win32.Build.0 = Release_php4|Win32
{71165FA5-1EBC-4021-AA17-0CCBC7CD5204}.Release_php5|Win32.ActiveCfg = Release_php5|Win32
{71165FA5-1EBC-4021-AA17-0CCBC7CD5204}.Release_php5|Win32.Build.0 = Release_php5|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,520 @@
<?xml version="1.0" encoding="gb2312"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="php_xxtea"
ProjectGUID="{71165FA5-1EBC-4021-AA17-0CCBC7CD5204}"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug_php5|Win32"
OutputDirectory=".\Debug_php5"
IntermediateDirectory=".\Debug_php5"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
SuppressStartupBanner="true"
TargetEnvironment="1"
TypeLibraryName=".\Debug_php5/php_xxtea.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../..,../../main,../../Zend,../../TSRM"
PreprocessorDefinitions="HAVE_XXTEA;COMPILE_DL_XXTEA;ZTS;NDEBUG;ZEND_WIN32;PHP_WIN32;WIN32;ZEND_DEBUG=1"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
PrecompiledHeaderFile=".\Debug_php5/php_xxtea.pch"
AssemblerListingLocation=".\Debug_php5/"
ObjectFile=".\Debug_php5/"
ProgramDataBaseFileName=".\Debug_php5/"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib php5ts.lib"
OutputFile="Debug_php5\php_xxtea.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="../../Release_TS"
GenerateDebugInformation="true"
ProgramDatabaseFile="Debug_php5\php_xxtea.pdb"
SubSystem="2"
ImportLibrary="$(OutDir)/php_xxtea.lib"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Debug_php5/php_xxtea.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release_php4|Win32"
OutputDirectory=".\Release_php4"
IntermediateDirectory=".\Release_php4"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
SuppressStartupBanner="true"
TargetEnvironment="1"
TypeLibraryName=".\Release_php4/php_xxtea.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/GT /GA "
Optimization="4"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="2"
OmitFramePointers="true"
AdditionalIncludeDirectories="../..,../../main,../../Zend,../../TSRM"
PreprocessorDefinitions="HAVE_XXTEA;COMPILE_DL_XXTEA;ZTS;NDEBUG;ZEND_WIN32;PHP_WIN32;WIN32;ZEND_DEBUG=0"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
PrecompiledHeaderFile=".\Release_php4/php_xxtea.pch"
AssemblerListingLocation=".\Release_php4/"
ObjectFile=".\Release_php4/"
ProgramDataBaseFileName=".\Release_php4/"
WarningLevel="3"
SuppressStartupBanner="true"
CompileAs="1"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib php4ts.lib"
OutputFile="Release_php4\php_xxtea.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="../../Release_TS"
ProgramDatabaseFile=".\Release_php4/php_xxtea.pdb"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
ImportLibrary="$(OutDir)/php_xxtea.lib"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Release_php4/php_xxtea.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release_php5|Win32"
OutputDirectory=".\Release_php5"
IntermediateDirectory=".\Release_php5"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
SuppressStartupBanner="true"
TargetEnvironment="1"
TypeLibraryName=".\Release_php5/php_xxtea.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/GT /GA "
Optimization="4"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="2"
OmitFramePointers="true"
AdditionalIncludeDirectories="../..,../../main,../../Zend,../../TSRM"
PreprocessorDefinitions="HAVE_XXTEA;COMPILE_DL_XXTEA;ZTS;NDEBUG;ZEND_WIN32;PHP_WIN32;WIN32;ZEND_DEBUG=0"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
PrecompiledHeaderFile=".\Release_php5/php_xxtea.pch"
AssemblerListingLocation=".\Release_php5/"
ObjectFile=".\Release_php5/"
ProgramDataBaseFileName=".\Release_php5/"
WarningLevel="3"
SuppressStartupBanner="true"
CompileAs="1"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib php5ts.lib"
OutputFile="Release_php5\php_xxtea.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="../../Release_TS"
ProgramDatabaseFile=".\Release_php5/php_xxtea.pdb"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
ImportLibrary="$(OutDir)/php_xxtea.lib"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Release_php5/php_xxtea.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug_php4|Win32"
OutputDirectory=".\Debug_php4"
IntermediateDirectory=".\Debug_php4"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
SuppressStartupBanner="true"
TargetEnvironment="1"
TypeLibraryName=".\Debug_php4/php_xxtea.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../..,../../main,../../Zend,../../TSRM"
PreprocessorDefinitions="HAVE_XXTEA;COMPILE_DL_XXTEA;ZTS;NDEBUG;ZEND_WIN32;PHP_WIN32;WIN32;ZEND_DEBUG=1"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
PrecompiledHeaderFile=".\Debug_php4/php_xxtea.pch"
AssemblerListingLocation=".\Debug_php4/"
ObjectFile=".\Debug_php4/"
ProgramDataBaseFileName=".\Debug_php4/"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="odbc32.lib odbccp32.lib php4ts.lib"
OutputFile="Debug_php4\php_xxtea.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="../../Release_TS"
GenerateDebugInformation="true"
ProgramDatabaseFile="Debug_php4\php_xxtea.pdb"
SubSystem="2"
ImportLibrary="$(OutDir)/php_xxtea.lib"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\Debug_php4/php_xxtea.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"
>
<File
RelativePath="php_xxtea.c"
>
<FileConfiguration
Name="Debug_php5|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release_php4|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release_php5|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_php4|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<Filter
Name="lib_xxtea"
>
<File
RelativePath="xxtea.c"
>
<FileConfiguration
Name="Debug_php5|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release_php4|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release_php5|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_php4|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
</Filter>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc"
>
<File
RelativePath="php_xxtea.h"
>
</File>
<Filter
Name="lib_xxtea"
>
<File
RelativePath="xxtea.h"
>
</File>
</Filter>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,8 @@
<?php
echo xxtea_decrypt(xxtea_encrypt("", ""), "");
echo xxtea_decrypt(xxtea_encrypt("1", ""), "");
echo xxtea_decrypt(xxtea_encrypt("1", "1"), "1");
echo xxtea_decrypt(xxtea_encrypt("12222222222222", "2222222222222222"), "2222222222222222");
echo xxtea_decrypt(xxtea_encrypt("12222222222222", "22222222222"), "22222222222");
print_r(xxtea_info());
?>

View File

@@ -0,0 +1,54 @@
/***********************************************************************
Copyright 2006-2007 Ma Bingyao
These sources is free software. Redistributions of source code must
retain the above copyright notice. Redistributions in binary form
must reproduce the above copyright notice. You can redistribute it
freely. You can use it with any free or commercial software.
These sources is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. Without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You may contact the author by:
e-mail: andot@coolcode.cn
*************************************************************************/
#include "xxtea.h"
void xxtea_long_encrypt(xxtea_long *v, xxtea_long len, xxtea_long *k) {
xxtea_long n = len - 1;
xxtea_long z = v[n], y = v[0], p, q = 6 + 52 / (n + 1), sum = 0, e;
if (n < 1) {
return;
}
while (0 < q--) {
sum += XXTEA_DELTA;
e = sum >> 2 & 3;
for (p = 0; p < n; p++) {
y = v[p + 1];
z = v[p] += XXTEA_MX;
}
y = v[0];
z = v[n] += XXTEA_MX;
}
}
void xxtea_long_decrypt(xxtea_long *v, xxtea_long len, xxtea_long *k) {
xxtea_long n = len - 1;
xxtea_long z = v[n], y = v[0], p, q = 6 + 52 / (n + 1), sum = q * XXTEA_DELTA, e;
if (n < 1) {
return;
}
while (sum != 0) {
e = sum >> 2 & 3;
for (p = n; p > 0; p--) {
z = v[p - 1];
y = v[p] -= XXTEA_MX;
}
z = v[n];
y = v[0] -= XXTEA_MX;
sum -= XXTEA_DELTA;
}
}

View File

@@ -0,0 +1,47 @@
/***********************************************************************
Copyright 2006-2007 Ma Bingyao
These sources is free software. Redistributions of source code must
retain the above copyright notice. Redistributions in binary form
must reproduce the above copyright notice. You can redistribute it
freely. You can use it with any free or commercial software.
These sources is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. Without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You may contact the author by:
e-mail: andot@coolcode.cn
*************************************************************************/
#ifndef XXTEA_H
#define XXTEA_H
#include <stddef.h> /* for size_t & NULL declarations */
#if defined(_MSC_VER)
typedef unsigned __int32 xxtea_long;
#else
#if defined(__FreeBSD__) && __FreeBSD__ < 5
/* FreeBSD 4 doesn't have stdint.h file */
#include <inttypes.h>
#else
#include <stdint.h>
#endif
typedef uint32_t xxtea_long;
#endif /* end of if defined(_MSC_VER) */
#define XXTEA_MX (z >> 5 ^ y << 2) + (y >> 3 ^ z << 4) ^ (sum ^ y) + (k[p & 3 ^ e] ^ z)
#define XXTEA_DELTA 0x9e3779b9
void xxtea_long_encrypt(xxtea_long *v, xxtea_long len, xxtea_long *k);
void xxtea_long_decrypt(xxtea_long *v, xxtea_long len, xxtea_long *k);
#endif

View File

@@ -0,0 +1,583 @@
<?php
/**********************************************************\
| |
| The implementation of PHPRPC Protocol 3.0 |
| |
| phprpc_client.php |
| |
| Release 3.0.1 |
| Copyright by Team-PHPRPC |
| |
| WebSite: http://www.phprpc.org/ |
| http://www.phprpc.net/ |
| http://www.phprpc.com/ |
| http://sourceforge.net/projects/php-rpc/ |
| |
| Authors: Ma Bingyao <andot@ujn.edu.cn> |
| |
| This file may be distributed and/or modified under the |
| terms of the GNU General Public License (GPL) version |
| 2.0 as published by the Free Software Foundation and |
| appearing in the included file LICENSE. |
| |
\**********************************************************/
/* PHPRPC Client for PHP.
*
* Copyright: Ma Bingyao <andot@ujn.edu.cn>
* Version: 3.0
* LastModified: Apr 12, 2010
* This library is free. You can redistribute it and/or modify it under GPL.
*
/*
* Interfaces
*
* $rpc_client = new PHPRPC_Client();
* $rpc_client->setProxy(NULL);
* $rpc_client->useService('http://www.phprpc.org/server.php');
* $rpc_client->setKeyLength(1024);
* $rpc_client->setEncryptMode(3);
* $args = array(1, 2);
* echo $rpc_client->invoke('add', &$args);
* echo "<br />";
* $n = 3;
* $args = array(&$n);
* echo $rpc_client->invoke('inc', &$args, true);
* echo "<br />";
* echo $rpc_client->sub(3, 2);
* echo "<br />";
* // error handle
* $result = $rpc_client->mul(1, 2); // no mul function
* if (is_a($result, "PHPRPC_Error")) {
* echo $result->toString();
* }
*/
$_PHPRPC_COOKIES = array();
$_PHPRPC_COOKIE = '';
$_PHPRPC_SID = 0;
if (defined('KEEP_PHPRPC_COOKIE_IN_SESSION')) {
if (isset($_SESSION['phprpc_cookies']) and isset($_SESSION['phprpc_cookie'])) {
$_PHPRPC_COOKIES = $_SESSION['phprpc_cookies'];
$_PHPRPC_COOKIE = $_SESSION['phprpc_cookie'];
}
function keep_phprpc_cookie_in_session() {
global $_PHPRPC_COOKIES, $_PHPRPC_COOKIE;
$_SESSION['phprpc_cookies'] = $_PHPRPC_COOKIES;
$_SESSION['phprpc_cookie'] = $_PHPRPC_COOKIE;
}
register_shutdown_function('keep_phprpc_cookie_in_session');
}
class PHPRPC_Error {
var $Number;
var $Message;
function PHPRPC_Error($errno, $errstr) {
$this->Number = $errno;
$this->Message = $errstr;
}
function toString() {
return $this->Number . ":" . $this->Message;
}
function __toString() {
return $this->toString();
}
function getNumber() {
return $this->Number;
}
function getMessage() {
return $this->Message;
}
}
class _PHPRPC_Client {
var $_server;
var $_timeout;
var $_output;
var $_warning;
var $_proxy;
var $_key;
var $_keylen;
var $_encryptMode;
var $_charset;
var $_socket;
var $_clientid;
var $_http_version;
var $_keep_alive;
// Public Methods
function _PHPRPC_Client($serverURL = '') {
global $_PHPRPC_SID;
require_once('compat.php');
//register_shutdown_function(array(&$this, "_disconnect"));
$this->_proxy = NULL;
$this->_timeout = 30;
$this->_clientid = 'php' . rand(1 << 30, 1 << 31) . time() . $_PHPRPC_SID;
$_PHPRPC_SID++;
$this->_socket = false;
if ($serverURL != '') {
$this->useService($serverURL);
}
}
function useService($serverURL, $username = NULL, $password = NULL) {
$this->_disconnect();
$this->_http_version = "1.1";
$this->_keep_alive = true;
$this->_server = array();
$this->_key = NULL;
$this->_keylen = 128;
$this->_encryptMode = 0;
$this->_charset = 'utf-8';
$urlparts = parse_url($serverURL);
if (!isset($urlparts['host'])) {
if (isset($_SERVER["HTTP_HOST"])) {
$urlparts['host'] = $_SERVER["HTTP_HOST"];
}
else if (isset($_SERVER["SERVER_NAME"])) {
$urlparts['host'] = $_SERVER["SERVER_NAME"];
}
else {
$urlparts['host'] = "localhost";
}
if (!isset($_SERVER["HTTPS"]) ||
$_SERVER["HTTPS"] == "off" ||
$_SERVER["HTTPS"] == "") {
$urlparts['scheme'] = "http";
}
else {
$urlparts['scheme'] = "https";
}
$urlparts['port'] = $_SERVER["SERVER_PORT"];
}
if (!isset($urlparts['port'])) {
if ($urlparts['scheme'] == "https") {
$urlparts['port'] = 443;
}
else {
$urlparts['port'] = 80;
}
}
if (!isset($urlparts['path'])) {
$urlparts['path'] = "/";
}
else if (($urlparts['path']{0} != '/') && ($_SERVER["PHP_SELF"]{0} == '/')) {
$urlparts['path'] = substr($_SERVER["PHP_SELF"], 0, strrpos($_SERVER["PHP_SELF"], '/') + 1) . $urlparts['path'];
}
if (isset($urlparts['query'])) {
$urlparts['path'] .= '?' . $urlparts['query'];
}
if (!isset($urlparts['user']) || !is_null($username)) {
$urlparts['user'] = $username;
}
if (!isset($urlparts['pass']) || !is_null($password)) {
$urlparts['pass'] = $password;
}
$this->_server['scheme'] = $urlparts['scheme'];
$this->_server['host'] = $urlparts['host'];
$this->_server['port'] = $urlparts['port'];
$this->_server['path'] = $urlparts['path'];
$this->_server['user'] = $urlparts['user'];
$this->_server['pass'] = $urlparts['pass'];
}
function setProxy($host, $port = NULL, $username = NULL, $password = NULL) {
if (is_null($host)) {
$this->_proxy = NULL;
}
else {
if (is_null($port)) {
$urlparts = parse_url($host);
if (isset($urlparts['host'])) {
$host = $urlparts['host'];
}
if (isset($urlparts['port'])) {
$port = $urlparts['port'];
}
else {
$port = 80;
}
if (isset($urlparts['user']) && is_null($username)) {
$username = $urlparts['user'];
}
if (isset($urlparts['pass']) && is_null($password)) {
$password = $urlparts['pass'];
}
}
$this->_proxy = array();
$this->_proxy['host'] = $host;
$this->_proxy['port'] = $port;
$this->_proxy['user'] = $username;
$this->_proxy['pass'] = $password;
}
}
function setKeyLength($keylen) {
if (!is_null($this->_key)) {
return false;
}
else {
$this->_keylen = $keylen;
return true;
}
}
function getKeyLength() {
return $this->_keylen;
}
function setEncryptMode($encryptMode) {
if (($encryptMode >= 0) && ($encryptMode <= 3)) {
$this->_encryptMode = (int)($encryptMode);
return true;
}
else {
$this->_encryptMode = 0;
return false;
}
}
function getEncryptMode() {
return $this->_encryptMode;
}
function setCharset($charset) {
$this->_charset = $charset;
}
function getCharset() {
return $this->_charset;
}
function setTimeout($timeout) {
$this->_timeout = $timeout;
}
function getTimeout() {
return $this->_timeout;
}
function invoke($funcname, &$args, $byRef = false) {
$result = $this->_key_exchange();
if (is_a($result, 'PHPRPC_Error')) {
return $result;
}
$request = "phprpc_func=$funcname";
if (count($args) > 0) {
$request .= "&phprpc_args=" . base64_encode($this->_encrypt(serialize_fix($args), 1));
}
$request .= "&phprpc_encrypt={$this->_encryptMode}";
if (!$byRef) {
$request .= "&phprpc_ref=false";
}
$request = str_replace('+', '%2B', $request);
$result = $this->_post($request);
if (is_a($result, 'PHPRPC_Error')) {
return $result;
}
$phprpc_errno = 0;
$phprpc_errstr = NULL;
if (isset($result['phprpc_errno'])) {
$phprpc_errno = intval($result['phprpc_errno']);
}
if (isset($result['phprpc_errstr'])) {
$phprpc_errstr = base64_decode($result['phprpc_errstr']);
}
$this->_warning = new PHPRPC_Error($phprpc_errno, $phprpc_errstr);
if (array_key_exists('phprpc_output', $result)) {
$this->_output = base64_decode($result['phprpc_output']);
if ($this->_server['version'] >= 3) {
$this->_output = $this->_decrypt($this->_output, 3);
}
}
else {
$this->_output = '';
}
if (array_key_exists('phprpc_result', $result)) {
if (array_key_exists('phprpc_args', $result)) {
$arguments = unserialize($this->_decrypt(base64_decode($result['phprpc_args']), 1));
for ($i = 0; $i < count($arguments); $i++) {
$args[$i] = $arguments[$i];
}
}
$result = unserialize($this->_decrypt(base64_decode($result['phprpc_result']), 2));
}
else {
$result = $this->_warning;
}
return $result;
}
function getOutput() {
return $this->_output;
}
function getWarning() {
return $this->_warning;
}
function _connect() {
if (is_null($this->_proxy)) {
$host = (($this->_server['scheme'] == "https") ? "ssl://" : "") . $this->_server['host'];
$this->_socket = @pfsockopen($host, $this->_server['port'], $errno, $errstr, $this->_timeout);
}
else {
$host = (($this->_server['scheme'] == "https") ? "ssl://" : "") . $this->_proxy['host'];
$this->_socket = @pfsockopen($host, $this->_proxy['port'], $errno, $errstr, $this->_timeout);
}
if ($this->_socket === false) {
return new PHPRPC_Error($errno, $errstr);
}
stream_set_write_buffer($this->_socket, 0);
socket_set_timeout($this->_socket, $this->_timeout);
return true;
}
function _disconnect() {
if ($this->_socket !== false) {
fclose($this->_socket);
$this->_socket = false;
}
}
function _socket_read($size) {
$content = "";
while (!feof($this->_socket) && ($size > 0)) {
$str = fread($this->_socket, $size);
$content .= $str;
$size -= strlen($str);
}
return $content;
}
function _post($request_body) {
global $_PHPRPC_COOKIE;
$request_body = 'phprpc_id=' . $this->_clientid . '&' . $request_body;
if ($this->_socket === false) {
$error = $this->_connect();
if (is_a($error, 'PHPRPC_Error')) {
return $error;
}
}
if (is_null($this->_proxy)) {
$url = $this->_server['path'];
$connection = "Connection: " . ($this->_keep_alive ? 'Keep-Alive' : 'Close') . "\r\n" .
"Cache-Control: no-cache\r\n";
}
else {
$url = "{$this->_server['scheme']}://{$this->_server['host']}:{$this->_server['port']}{$this->_server['path']}";
$connection = "Proxy-Connection: " . ($this->_keep_alive ? 'keep-alive' : 'close') . "\r\n";
if (!is_null($this->_proxy['user'])) {
$connection .= "Proxy-Authorization: Basic " . base64_encode($this->_proxy['user'] . ":" . $this->_proxy['pass']) . "\r\n";
}
}
$auth = '';
if (!is_null($this->_server['user'])) {
$auth = "Authorization: Basic " . base64_encode($this->_server['user'] . ":" . $this->_server['pass']) . "\r\n";
}
$cookie = '';
if ($_PHPRPC_COOKIE) {
$cookie = "Cookie: " . $_PHPRPC_COOKIE . "\r\n";
}
$content_len = strlen($request_body);
$request =
"POST $url HTTP/{$this->_http_version}\r\n" .
"Host: {$this->_server['host']}:{$this->_server['port']}\r\n" .
"User-Agent: PHPRPC Client 3.0 for PHP\r\n" .
$auth .
$connection .
$cookie .
"Accept: */*\r\n" .
"Accept-Encoding: gzip,deflate\r\n" .
"Content-Type: application/x-www-form-urlencoded; charset={$this->_charset}\r\n" .
"Content-Length: {$content_len}\r\n" .
"\r\n" .
$request_body;
fputs($this->_socket, $request, strlen($request));
while (!feof($this->_socket)) {
$line = fgets($this->_socket);
if (preg_match('/HTTP\/(\d\.\d)\s+(\d+)([^(\r|\n)]*)(\r\n|$)/i', $line, $match)) {
$this->_http_version = $match[1];
$status = (int)$match[2];
$status_message = trim($match[3]);
if ($status != 100 && $status != 200) {
$this->_disconnect();
return new PHPRPC_Error($status, $status_message);
}
}
else {
$this->_disconnect();
return new PHPRPC_Error(E_ERROR, "Illegal HTTP server.");
}
$header = array();
while (!feof($this->_socket) && (($line = fgets($this->_socket)) != "\r\n")) {
$line = explode(':', $line, 2);
$header[strtolower($line[0])][] =trim($line[1]);
}
if ($status == 100) continue;
$response_header = $this->_parseHeader($header);
if (is_a($response_header, 'PHPRPC_Error')) {
$this->_disconnect();
return $response_header;
}
break;
}
$response_body = '';
if (isset($response_header['transfer_encoding']) && (strtolower($response_header['transfer_encoding']) == 'chunked')) {
$s = fgets($this->_socket);
if ($s == "") {
$this->_disconnect();
return array();
}
$chunk_size = (int)hexdec($s);
while ($chunk_size > 0) {
$response_body .= $this->_socket_read($chunk_size);
if (fgets($this->_socket) != "\r\n") {
$this->_disconnect();
return new PHPRPC_Error(1, "Response is incorrect.");
}
$chunk_size = (int)hexdec(fgets($this->_socket));
}
fgets($this->_socket);
}
elseif (isset($response_header['content_length']) && !is_null($response_header['content_length'])) {
$response_body = $this->_socket_read($response_header['content_length']);
}
else {
while (!feof($this->_socket)) {
$response_body .= fread($this->_socket, 4096);
}
$this->_keep_alive = false;
$this->_disconnect();
}
if (isset($response_header['content_encoding']) && (strtolower($response_header['content_encoding']) == 'gzip')) {
$response_body = gzdecode($response_body);
}
if (!$this->_keep_alive) $this->_disconnect();
if ($this->_keep_alive && strtolower($response_header['connection']) == 'close') {
$this->_keep_alive = false;
$this->_disconnect();
}
return $this->_parseBody($response_body);
}
function _parseHeader($header) {
global $_PHPRPC_COOKIE, $_PHPRPC_COOKIES;
if (preg_match('/PHPRPC Server\/([^,]*)(,|$)/i', implode(',', $header['x-powered-by']), $match)) {
$this->_server['version'] = (float)$match[1];
}
else {
return new PHPRPC_Error(E_ERROR, "Illegal PHPRPC server.");
}
if (preg_match('/text\/plain\; charset\=([^,;]*)([,;]|$)/i', $header['content-type'][0], $match)) {
$this->_charset = $match[1];
}
if (isset($header['set-cookie'])) {
foreach ($header['set-cookie'] as $cookie) {
foreach (preg_split('/[;,]\s?/', $cookie) as $c) {
list($name, $value) = explode('=', $c, 2);
if (!in_array($name, array('domain', 'expires', 'path', 'secure'))) {
$_PHPRPC_COOKIES[$name] = $value;
}
}
}
$cookies = array();
foreach ($_PHPRPC_COOKIES as $name => $value) {
$cookies[] = "$name=$value";
}
$_PHPRPC_COOKIE = join('; ', $cookies);
}
if (isset($header['content-length'])) {
$content_length = (int)$header['content-length'][0];
}
else {
$content_length = NULL;
}
$transfer_encoding = isset($header['transfer-encoding']) ? $header['transfer-encoding'][0] : '';
$content_encoding = isset($header['content-encoding']) ? $header['content-encoding'][0] : '';
$connection = isset($header['connection']) ? $header['connection'][0] : 'close';
return array('transfer_encoding' => $transfer_encoding,
'content_encoding' => $content_encoding,
'content_length' => $content_length,
'connection' => $connection);
}
function _parseBody($body) {
$body = explode(";\r\n", $body);
$result = array();
$n = count($body);
for ($i = 0; $i < $n; $i++) {
$p = strpos($body[$i], '=');
if ($p !== false) {
$l = substr($body[$i], 0, $p);
$r = substr($body[$i], $p + 1);
$result[$l] = trim($r, '"');
}
}
return $result;
}
function _key_exchange() {
if (!is_null($this->_key) || ($this->_encryptMode == 0)) return true;
$request = "phprpc_encrypt=true&phprpc_keylen={$this->_keylen}";
$result = $this->_post($request);
if (is_a($result, 'PHPRPC_Error')) {
return $result;
}
if (array_key_exists('phprpc_keylen', $result)) {
$this->_keylen = (int)$result['phprpc_keylen'];
}
else {
$this->_keylen = 128;
}
if (array_key_exists('phprpc_encrypt', $result)) {
$encrypt = unserialize(base64_decode($result['phprpc_encrypt']));
require_once('bigint.php');
require_once('xxtea.php');
$x = bigint_random($this->_keylen - 1, true);
$key = bigint_powmod(bigint_dec2num($encrypt['y']), $x, bigint_dec2num($encrypt['p']));
if ($this->_keylen == 128) {
$key = bigint_num2str($key);
}
else {
$key = pack('H*', md5(bigint_num2dec($key)));
}
$this->_key = str_pad($key, 16, "\0", STR_PAD_LEFT);
$encrypt = bigint_num2dec(bigint_powmod(bigint_dec2num($encrypt['g']), $x, bigint_dec2num($encrypt['p'])));
$request = "phprpc_encrypt=$encrypt";
$result = $this->_post($request);
if (is_a($result, 'PHPRPC_Error')) {
return $result;
}
}
else {
$this->_key = NULL;
$this->_encryptMode = 0;
}
return true;
}
function _encrypt($str, $level) {
if (!is_null($this->_key) && ($this->_encryptMode >= $level)) {
$str = xxtea_encrypt($str, $this->_key);
}
return $str;
}
function _decrypt($str, $level) {
if (!is_null($this->_key) && ($this->_encryptMode >= $level)) {
$str = xxtea_decrypt($str, $this->_key);
}
return $str;
}
}
if (function_exists("overload") && version_compare(phpversion(), "5", "<")) {
eval('
class PHPRPC_Client extends _PHPRPC_Client {
function __call($function, $arguments, &$return) {
$return = $this->invoke($function, $arguments);
return true;
}
}
overload("phprpc_client");
');
}
else {
class PHPRPC_Client extends _PHPRPC_Client {
function __call($function, $arguments) {
return $this->invoke($function, $arguments);
}
}
}
?>

View File

@@ -0,0 +1,522 @@
<?php
/**********************************************************\
| |
| The implementation of PHPRPC Protocol 3.0 |
| |
| phprpc_date.php |
| |
| Release 3.0.1 |
| Copyright by Team-PHPRPC |
| |
| WebSite: http://www.phprpc.org/ |
| http://www.phprpc.net/ |
| http://www.phprpc.com/ |
| http://sourceforge.net/projects/php-rpc/ |
| |
| Authors: Ma Bingyao <andot@ujn.edu.cn> |
| |
| This file may be distributed and/or modified under the |
| terms of the GNU General Public License (GPL) version |
| 2.0 as published by the Free Software Foundation and |
| appearing in the included file LICENSE. |
| |
\**********************************************************/
/* PHPRPC_Date Class for PHP.
*
* Copyright: Ma Bingyao <andot@ujn.edu.cn>
* Version: 1.2
* LastModified: Apr 12, 2010
* This library is free. You can redistribute it and/or modify it under GPL.
*/
class PHPRPC_Date {
// public fields
var $year = 1;
var $month = 1;
var $day = 1;
var $hour = 0;
var $minute = 0;
var $second = 0;
var $millisecond = 0;
// constructor
function PHPRPC_Date() {
$num = func_num_args();
$time = false;
if ($num == 0) {
$time = getdate();
}
if ($num == 1) {
$arg = func_get_arg(0);
if (is_int($arg)) {
$time = getdate($arg);
}
elseif (is_string($arg)) {
$time = getdate(strtotime($arg));
}
}
if (is_array($time)) {
$this->year = $time['year'];
$this->month = $time['mon'];
$this->day = $time['mday'];
$this->hour = $time['hours'];
$this->minute = $time['minutes'];
$this->second = $time['seconds'];
}
}
// public instance methods
function addMilliseconds($milliseconds) {
if (!is_int($milliseconds)) return false;
if ($milliseconds == 0) return true;
$millisecond = $this->millisecond + $milliseconds;
$milliseconds = $millisecond % 1000;
if ($milliseconds < 0) {
$milliseconds += 1000;
}
$seconds = (int)(($millisecond - $milliseconds) / 1000);
$millisecond = (int)$milliseconds;
if ($this->addSeconds($seconds)) {
$this->millisecond = (int)$milliseconds;
return true;
}
else {
return false;
}
}
function addSeconds($seconds) {
if (!is_int($seconds)) return false;
if ($seconds == 0) return true;
$second = $this->second + $seconds;
$seconds = $second % 60;
if ($seconds < 0) {
$seconds += 60;
}
$minutes = (int)(($second - $seconds) / 60);
if ($this->addMinutes($minutes)) {
$this->second = (int)$seconds;
return true;
}
else {
return false;
}
}
function addMinutes($minutes) {
if (!is_int($minutes)) return false;
if ($minutes == 0) return true;
$minute = $this->minute + $minutes;
$minutes = $minute % 60;
if ($minutes < 0) {
$minutes += 60;
}
$hours = (int)(($minute - $minutes) / 60);
if ($this->addHours($hours)) {
$this->minute = (int)$minutes;
return true;
}
else {
return false;
}
}
function addHours($hours) {
if (!is_int($hours)) return false;
if ($hours == 0) return true;
$hour = $this->hour + $hours;
$hours = $hour % 24;
if ($hours < 0) {
$hours += 24;
}
$days = (int)(($hour - $hours) / 24);
if ($this->addDays($days)) {
$this->hour = (int)$hours;
return true;
}
else {
return false;
}
}
function addDays($days) {
if (!is_int($days)) return false;
$year = $this->year;
if ($days == 0) return true;
if ($days >= 146097 || $days <= -146097) {
$remainder = $days % 146097;
if ($remainder < 0) {
$remainder += 146097;
}
$years = 400 * (int)(($days - $remainder) / 146097);
$year += $years;
if ($year < 1 || $year > 9999) return false;
$days = $remainder;
}
if ($days >= 36524 || $days <= -36524) {
$remainder = $days % 36524;
if ($remainder < 0) {
$remainder += 36524;
}
$years = 100 * (int)(($days - $remainder) / 36524);
$year += $years;
if ($year < 1 || $year > 9999) return false;
$days = $remainder;
}
if ($days >= 1461 || $days <= -1461) {
$remainder = $days % 1461;
if ($remainder < 0) {
$remainder += 1461;
}
$years = 4 * (int)(($days - $remainder) / 1461);
$year += $years;
if ($year < 1 || $year > 9999) return false;
$days = $remainder;
}
$month = $this->month;
while ($days >= 365) {
if ($year >= 9999) return false;
if ($month <= 2) {
if ((($year % 4) == 0) ? (($year % 100) == 0) ? (($year % 400) == 0) : true : false) {
$days -= 366;
}
else {
$days -= 365;
}
$year++;
}
else {
$year++;
if ((($year % 4) == 0) ? (($year % 100) == 0) ? (($year % 400) == 0) : true : false) {
$days -= 366;
}
else {
$days -= 365;
}
}
}
while ($days < 0) {
if ($year <= 1) return false;
if ($month <= 2) {
$year--;
if ((($year % 4) == 0) ? (($year % 100) == 0) ? (($year % 400) == 0) : true : false) {
$days += 366;
}
else {
$days += 365;
}
}
else {
if ((($year % 4) == 0) ? (($year % 100) == 0) ? (($year % 400) == 0) : true : false) {
$days += 366;
}
else {
$days += 365;
}
$year--;
}
}
$daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$day = $this->day;
while ($day + $days > $daysInMonth) {
$days -= $daysInMonth - $day + 1;
$month++;
if ($month > 12) {
if ($year >= 9999) return false;
$year++;
$month = 1;
}
$day = 1;
$daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
}
$day += $days;
$this->year = $year;
$this->month = $month;
$this->day = $day;
return true;
}
function addMonths($months) {
if (!is_int($months)) return false;
if ($months == 0) return true;
$month = $this->month + $months;
$months = ($month - 1) % 12 + 1;
if ($months < 1) {
$months += 12;
}
$years = (int)(($month - $months) / 12);
if ($this->addYears($years)) {
$daysInMonth = cal_days_in_month(CAL_GREGORIAN, $months, $this->year);
if ($this->day > $daysInMonth) {
$months++;
$this->day -= $daysInMonth;
}
$this->month = (int)$months;
return true;
}
else {
return false;
}
}
function addYears($years) {
if (!is_int($years)) return false;
if ($years == 0) return true;
$year = $this->year + $years;
if ($year < 1 || $year > 9999) return false;
$this->year = $year;
return true;
}
function after($when) {
if (!is_a($when, 'PHPRPC_Date')) {
$when = PHPRPC_Date::parse($when);
}
if ($this->year < $when->year) return false;
if ($this->year > $when->year) return true;
if ($this->month < $when->month) return false;
if ($this->month > $when->month) return true;
if ($this->day < $when->day) return false;
if ($this->day > $when->day) return true;
if ($this->hour < $when->hour) return false;
if ($this->hour > $when->hour) return true;
if ($this->minute < $when->minute) return false;
if ($this->minute > $when->minute) return true;
if ($this->second < $when->second) return false;
if ($this->second > $when->second) return true;
if ($this->millisecond < $when->millisecond) return false;
if ($this->millisecond > $when->millisecond) return true;
return false;
}
function before($when) {
if (!is_a($when, 'PHPRPC_Date')) {
$when = new PHPRPC_Date($when);
}
if ($this->year < $when->year) return true;
if ($this->year > $when->year) return false;
if ($this->month < $when->month) return true;
if ($this->month > $when->month) return false;
if ($this->day < $when->day) return true;
if ($this->day > $when->day) return false;
if ($this->hour < $when->hour) return true;
if ($this->hour > $when->hour) return false;
if ($this->minute < $when->minute) return true;
if ($this->minute > $when->minute) return false;
if ($this->second < $when->second) return true;
if ($this->second > $when->second) return false;
if ($this->millisecond < $when->millisecond) return true;
if ($this->millisecond > $when->millisecond) return false;
return false;
}
function equals($when) {
if (!is_a($when, 'PHPRPC_Date')) {
$when = new PHPRPC_Date($when);
}
return (($this->year == $when->year) &&
($this->month == $when->month) &&
($this->day == $when->day) &&
($this->hour == $when->hour) &&
($this->minute == $when->minute) &&
($this->second == $when->second) &&
($this->millisecond == $when->millisecond));
}
function set() {
$num = func_num_args();
$args = func_get_args();
if ($num >= 3) {
if (!PHPRPC_Date::isValidDate($args[0], $args[1], $args[2])) {
return false;
}
$this->year = (int)$args[0];
$this->month = (int)$args[1];
$this->day = (int)$args[2];
if ($num == 3) {
return true;
}
}
if ($num >= 6) {
if (!PHPRPC_Date::isValidTime($args[3], $args[4], $args[5])) {
return false;
}
$this->hour = (int)$args[3];
$this->minute = (int)$args[4];
$this->second = (int)$args[5];
if ($num == 6) {
return true;
}
}
if (($num == 7) && ($args[6] >= 0 && $args[6] <= 999)) {
$this->millisecond = (int)$args[6];
return true;
}
return false;
}
function time() {
return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
}
function toString() {
return sprintf('%04d-%02d-%02d %02d:%02d:%02d.%03d',
$this->year, $this->month, $this->day,
$this->hour, $this->minute, $this->second,
$this->millisecond);
}
// magic method for PHP 5
function __toString() {
return $this->toString();
}
// public instance & static methods
function dayOfWeek() {
$num = func_num_args();
if ($num == 3) {
$args = func_get_args();
$y = $args[0];
$m = $args[1];
$d = $args[2];
}
else {
$y = $this->year;
$m = $this->month;
$d = $this->day;
}
$d += $m < 3 ? $y-- : $y - 2;
return ((int)(23 * $m / 9) + $d + 4 + (int)($y / 4) - (int)($y / 100) + (int)($y / 400)) % 7;
}
function dayOfYear() {
static $daysToMonth365 = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365);
static $daysToMonth366 = array(0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366);
$num = func_num_args();
if ($num == 3) {
$args = func_get_args();
$y = $args[0];
$m = $args[1];
$d = $args[2];
}
else {
$y = $this->year;
$m = $this->month;
$d = $this->day;
}
$days = PHPRPC_Date::isLeapYear($y) ? $daysToMonth365 : $daysToMonth366;
return $days[$m - 1] + $d;
}
// public static methods
function now() {
$date = new PHPRPC_Date();
return $date;
}
function today() {
$date = PHPRPC_Date::now();
$date->hour = 0;
$date->minute = 0;
$date->second = 0;
return $date;
}
function parse($dt) {
if (is_a($dt, 'PHPRPC_Date')) {
return $dt;
}
if (is_int($dt)) {
return new PHPRPC_Date($dt);
}
$shortFormat = '(\d|\d{2}|\d{3}|\d{4})-([1-9]|0[1-9]|1[012])-([1-9]|0[1-9]|[12]\d|3[01])';
if (preg_match("/^$shortFormat$/", $dt, $match)) {
$year = intval($match[1]);
$month = intval($match[2]);
$day = intval($match[3]);
if (PHPRPC_Date::isValidDate($year, $month, $day)) {
$date = new PHPRPC_Date(false);
$date->year = $year;
$date->month = $month;
$date->day = $day;
return $date;
}
else {
return false;
}
}
$longFormat = $shortFormat . ' (\d|0\d|1\d|2[0-3]):(\d|[0-5]\d):(\d|[0-5]\d)';
if (preg_match("/^$longFormat$/", $dt, $match)) {
$year = intval($match[1]);
$month = intval($match[2]);
$day = intval($match[3]);
if (PHPRPC_Date::isValidDate($year, $month, $day)) {
$date = new PHPRPC_Date(false);
$date->year = $year;
$date->month = $month;
$date->day = $day;
$date->hour = intval($match[4]);
$date->minute = intval($match[5]);
$date->second = intval($match[6]);
return $date;
}
else {
return false;
}
}
$fullFormat = $longFormat . '\.(\d|\d{2}|\d{3})';
if (preg_match("/^$fullFormat$/", $dt, $match)) {
$year = intval($match[1]);
$month = intval($match[2]);
$day = intval($match[3]);
if (PHPRPC_Date::isValidDate($year, $month, $day)) {
$date = new PHPRPC_Date(false);
$date->year = $year;
$date->month = $month;
$date->day = $day;
$date->hour = intval($match[4]);
$date->minute = intval($match[5]);
$date->second = intval($match[6]);
$date->millisecond = intval($match[7]);
return $date;
}
else {
return false;
}
}
return false;
}
function isLeapYear($year) {
return (($year % 4) == 0) ? (($year % 100) == 0) ? (($year % 400) == 0) : true : false;
}
function daysInMonth($year, $month) {
if (($month < 1) || ($month > 12)) {
return false;
}
return cal_days_in_month(CAL_GREGORIAN, $month, $year);
}
function isValidDate($year, $month, $day) {
if (($year >= 1) && ($year <= 9999)) {
return checkdate($month, $day, $year);
}
return false;
}
function isValidTime($hour, $minute, $second) {
return !(($hour < 0) || ($hour > 23) ||
($minute < 0) || ($minute > 59) ||
($second < 0) || ($second > 59));
}
}
?>

View File

@@ -0,0 +1,496 @@
<?php
/**********************************************************\
| |
| The implementation of PHPRPC Protocol 3.0 |
| |
| phprpc_server.php |
| |
| Release 3.0.1 |
| Copyright by Team-PHPRPC |
| |
| WebSite: http://www.phprpc.org/ |
| http://www.phprpc.net/ |
| http://www.phprpc.com/ |
| http://sourceforge.net/projects/php-rpc/ |
| |
| Authors: Ma Bingyao <andot@ujn.edu.cn> |
| |
| This file may be distributed and/or modified under the |
| terms of the GNU General Public License (GPL) version |
| 2.0 as published by the Free Software Foundation and |
| appearing in the included file LICENSE. |
| |
\**********************************************************/
/* PHPRPC Server for PHP.
*
* Copyright: Ma Bingyao <andot@ujn.edu.cn>
* Version: 3.0
* LastModified: Apr 12, 2010
* This library is free. You can redistribute it and/or modify it under GPL.
*
/*
* Interfaces
*
* function add($a, $b) {
* return $a + $b;
* }
* function sub($a, $b) {
* return $a - $b;
* }
* function inc(&$n) {
* return $n++;
* }
* include('phprpc_server.php');
* $server = new PHPRPC_Server();
* $server->add(array('add', 'sub'));
* $server->add('inc');
* $server->setCharset('UTF-8');
* $server->setDebugMode(true);
* $server->start();
*
*/
class PHPRPC_Server {
var $callback;
var $charset;
var $encode;
var $ref;
var $encrypt;
var $enableGZIP;
var $debug;
var $keylen;
var $key;
var $errno;
var $errstr;
var $functions;
var $cid;
var $buffer;
// Private Methods
function addJsSlashes($str, $flag) {
if ($flag) {
$str = addcslashes($str, "\0..\006\010..\012\014..\037\042\047\134\177..\377");
}
else {
$str = addcslashes($str, "\0..\006\010..\012\014..\037\042\047\134\177");
}
return str_replace(array(chr(7), chr(11)), array('\007', '\013'), $str);
}
function encodeString($str, $flag = true) {
if ($this->encode) {
return base64_encode($str);
}
else {
return $this->addJsSlashes($str, $flag);
}
}
function encryptString($str, $level) {
if ($this->encrypt >= $level) {
$str = xxtea_encrypt($str, $this->key);
}
return $str;
}
function decryptString($str, $level) {
if ($this->encrypt >= $level) {
$str = xxtea_decrypt($str, $this->key);
}
return $str;
}
function sendHeader() {
header("HTTP/1.1 200 OK");
header("Content-Type: text/plain; charset={$this->charset}");
header("X-Powered-By: PHPRPC Server/3.0");
header('P3P: CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"');
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
}
function getRequestURL() {
if (!isset($_SERVER['HTTPS']) ||
$_SERVER['HTTPS'] == 'off' ||
$_SERVER['HTTPS'] == '') {
$scheme = 'http';
}
else {
$scheme = 'https';
}
$host = $_SERVER['SERVER_NAME'];
$port = $_SERVER['SERVER_PORT'];
$path = $_SERVER['SCRIPT_NAME'];
return $scheme . '://' . $host . (($port == 80) ? '' : ':' . $port) . $path;
}
function sendURL() {
if (SID != "") {
$url = $this->getRequestURL();
if (count($_GET) > 0) {
$url .= '?' . strip_tags(SID);
foreach ($_GET as $key => $value) {
if (strpos(strtolower($key), 'phprpc_') !== 0) {
$url .= '&' . $key . '=' . urlencode($value);
}
}
}
$this->buffer .= "phprpc_url=\"" . $this->encodeString($url) . "\";\r\n";
}
}
function gzip($buffer) {
$len = strlen($buffer);
if ($this->enableGZIP && strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip,deflate')) {
$gzbuffer = gzencode($buffer);
$gzlen = strlen($gzbuffer);
if ($len > $gzlen) {
header("Content-Length: $gzlen");
header("Content-Encoding: gzip");
return $gzbuffer;
}
}
header("Content-Length: $len");
return $buffer;
}
function sendCallback() {
$this->buffer .= $this->callback;
echo $this->gzip($this->buffer);
ob_end_flush();
restore_error_handler();
if (function_exists('restore_exception_handler')) {
restore_exception_handler();
}
exit();
}
function sendFunctions() {
$this->buffer .= "phprpc_functions=\"" . $this->encodeString(serialize_fix(array_keys($this->functions))) . "\";\r\n";
$this->sendCallback();
}
function sendOutput($output) {
if ($this->encrypt >= 3) {
$this->buffer .= "phprpc_output=\"" . $this->encodeString(xxtea_encrypt($output, $this->key)) . "\";\r\n";
}
else {
$this->buffer .= "phprpc_output=\"" . $this->encodeString($output, false) . "\";\r\n";
}
}
function sendError($output = NULL) {
if (is_null($output)) {
$output = ob_get_clean();
}
$this->buffer .= "phprpc_errno=\"{$this->errno}\";\r\n";
$this->buffer .= "phprpc_errstr=\"" . $this->encodeString($this->errstr, false) . "\";\r\n";
$this->sendOutput($output);
$this->sendCallback();
}
function fatalErrorHandler($buffer) {
if (preg_match('/<b>(.*?) error<\/b>:(.*?)<br/', $buffer, $match)) {
if ($match[1] == 'Fatal') {
$errno = E_ERROR;
}
else {
$errno = E_COMPILE_ERROR;
}
if ($this->debug) {
$errstr = preg_replace('/<.*?>/', '', $match[2]);
}
else {
$errstr = preg_replace('/ in <b>.*<\/b>$/', '', $match[2]);
}
$buffer = "phprpc_errno=\"{$errno}\";\r\n" .
"phprpc_errstr=\"" . $this->encodeString(trim($errstr), false) . "\";\r\n" .
"phprpc_output=\"\";\r\n" .
$this->callback;
$buffer = $this->gzip($buffer);
}
return $buffer;
}
function errorHandler($errno, $errstr, $errfile, $errline) {
if ($this->debug) {
$errstr .= " in $errfile on line $errline";
}
if (($errno == E_ERROR) or ($errno == E_CORE_ERROR) or
($errno == E_COMPILE_ERROR) or ($errno == E_USER_ERROR)) {
$this->errno = $errno;
$this->errstr = $errstr;
$this->sendError();
}
else {
if (($errno == E_NOTICE) or ($errno == E_USER_NOTICE)) {
if ($this->errno == 0) {
$this->errno = $errno;
$this->errstr = $errstr;
}
}
else {
if (($this->errno == 0) or
($this->errno == E_NOTICE) or
($this->errno == E_USER_NOTICE)) {
$this->errno = $errno;
$this->errstr = $errstr;
}
}
}
return true;
}
function exceptionHandler($exception) {
$this->errno = $exception->getCode();
$this->errstr = $exception->getMessage();
if ($this->debug) {
$this->errstr .= "\nfile: " . $exception->getFile() .
"\nline: " . $exception->getLine() .
"\ntrace: " . $exception->getTraceAsString();
}
$this->sendError();
}
function initErrorHandler() {
$this->errno = 0;
$this->errstr = "";
set_error_handler(array(&$this, 'errorHandler'));
if (function_exists('set_exception_handler')) {
set_exception_handler(array(&$this, 'exceptionHandler'));
}
}
function call($function, &$args) {
if ($this->ref) {
$arguments = array();
for ($i = 0; $i < count($args); $i++) {
$arguments[$i] = &$args[$i];
}
}
else {
$arguments = $args;
}
return call_user_func_array($function, $arguments);
}
function getRequest($name) {
$result = $_REQUEST[$name];
if (get_magic_quotes_gpc()) {
$result = stripslashes($result);
}
return $result;
}
function getBooleanRequest($name) {
$var = true;
if (isset($_REQUEST[$name])) {
$var = strtolower($this->getRequest($name));
if ($var == "false") {
$var = false;
}
}
return $var;
}
function initEncode() {
$this->encode = $this->getBooleanRequest('phprpc_encode');
}
function initRef() {
$this->ref = $this->getBooleanRequest('phprpc_ref');
}
function initCallback() {
if (isset($_REQUEST['phprpc_callback'])) {
$this->callback = base64_decode($this->getRequest('phprpc_callback'));
}
else {
$this->callback = "";
}
}
function initKeylen() {
if (isset($_REQUEST['phprpc_keylen'])) {
$this->keylen = (int)$this->getRequest('phprpc_keylen');
}
else if (isset($_SESSION[$this->cid])) {
$session = unserialize(base64_decode($_SESSION[$this->cid]));
if (isset($session['keylen'])) {
$this->keylen = $session['keylen'];
}
else {
$this->keylen = 128;
}
}
else {
$this->keylen = 128;
}
}
function initClientID() {
$this->cid = 0;
if (isset($_REQUEST['phprpc_id'])) {
$this->cid = $this->getRequest('phprpc_id');
}
$this->cid = "phprpc_" . $this->cid;
}
function initEncrypt() {
$this->encrypt = false;
if (isset($_REQUEST['phprpc_encrypt'])) {
$this->encrypt = $this->getRequest('phprpc_encrypt');
if ($this->encrypt === "true") $this->encrypt = true;
if ($this->encrypt === "false") $this->encrypt = false;
}
}
function initKey() {
if ($this->encrypt == 0) {
return;
}
else if (isset($_SESSION[$this->cid])) {
$session = unserialize(base64_decode($_SESSION[$this->cid]));
if (isset($session['key'])) {
$this->key = $session['key'];
require_once('xxtea.php');
return;
}
}
$this->errno = E_ERROR;
$this->errstr = "Can't find the key for decryption.";
$this->encrypt = 0;
$this->sendError();
}
function getArguments() {
if (isset($_REQUEST['phprpc_args'])) {
$arguments = unserialize($this->decryptString(base64_decode($this->getRequest('phprpc_args')), 1));
ksort($arguments);
}
else {
$arguments = array();
}
return $arguments;
}
function callFunction() {
$this->initKey();
$function = strtolower($this->getRequest('phprpc_func'));
if (array_key_exists($function, $this->functions)) {
$function = $this->functions[$function];
$arguments = $this->getArguments();
$result = $this->encodeString($this->encryptString(serialize_fix($this->call($function, $arguments)), 2));
$output = ob_get_clean();
$this->buffer .= "phprpc_result=\"$result\";\r\n";
if ($this->ref) {
$arguments = $this->encodeString($this->encryptString(serialize_fix($arguments), 1));
$this->buffer .= "phprpc_args=\"$arguments\";\r\n";
}
}
else {
$this->errno = E_ERROR;
$this->errstr = "Can't find this function $function().";
$output = ob_get_clean();
}
$this->sendError($output);
}
function keyExchange() {
require_once('bigint.php');
$this->initKeylen();
if (isset($_SESSION[$this->cid])) {
$session = unserialize(base64_decode($_SESSION[$this->cid]));
}
else {
$session = array();
}
if ($this->encrypt === true) {
require_once('dhparams.php');
$DHParams = new DHParams($this->keylen);
$this->keylen = $DHParams->getL();
$encrypt = $DHParams->getDHParams();
$x = bigint_random($this->keylen - 1, true);
$session['x'] = bigint_num2dec($x);
$session['p'] = $encrypt['p'];
$session['keylen'] = $this->keylen;
$encrypt['y'] = bigint_num2dec(bigint_powmod(bigint_dec2num($encrypt['g']), $x, bigint_dec2num($encrypt['p'])));
$this->buffer .= "phprpc_encrypt=\"" . $this->encodeString(serialize_fix($encrypt)) . "\";\r\n";
if ($this->keylen != 128) {
$this->buffer .= "phprpc_keylen=\"{$this->keylen}\";\r\n";
}
$this->sendURL();
}
else {
$y = bigint_dec2num($this->encrypt);
$x = bigint_dec2num($session['x']);
$p = bigint_dec2num($session['p']);
$key = bigint_powmod($y, $x, $p);
if ($this->keylen == 128) {
$key = bigint_num2str($key);
}
else {
$key = pack('H*', md5(bigint_num2dec($key)));
}
$session['key'] = str_pad($key, 16, "\0", STR_PAD_LEFT);
}
$_SESSION[$this->cid] = base64_encode(serialize($session));
$this->sendCallback();
}
function initSession() {
@ob_start();
ob_implicit_flush(0);
session_start();
}
function initOutputBuffer() {
@ob_start(array(&$this, "fatalErrorHandler"));
ob_implicit_flush(0);
$this->buffer = "";
}
// Public Methods
function PHPRPC_Server() {
require_once('compat.php');
$this->functions = array();
$this->charset = 'UTF-8';
$this->debug = false;
$this->enableGZIP = false;
}
function add($functions, $obj = NULL, $aliases = NULL) {
if (is_null($functions) || (gettype($functions) != gettype($aliases) && !is_null($aliases))) {
return false;
}
if (is_object($functions)) {
$obj = $functions;
$functions = get_class_methods(get_class($obj));
$aliases = $functions;
}
if (is_null($aliases)) {
$aliases = $functions;
}
if (is_string($functions)) {
if (is_null($obj)) {
$this->functions[strtolower($aliases)] = $functions;
}
else if (is_object($obj)) {
$this->functions[strtolower($aliases)] = array(&$obj, $functions);
}
else if (is_string($obj)) {
$this->functions[strtolower($aliases)] = array($obj, $functions);
}
}
else {
if (count($functions) != count($aliases)) {
return false;
}
foreach ($functions as $key => $function) {
$this->add($function, $obj, $aliases[$key]);
}
}
return true;
}
function setCharset($charset) {
$this->charset = $charset;
}
function setDebugMode($debug) {
$this->debug = $debug;
}
function setEnableGZIP($enableGZIP) {
$this->enableGZIP = $enableGZIP;
}
function start() {
while(ob_get_length() !== false) @ob_end_clean();
$this->initOutputBuffer();
$this->sendHeader();
$this->initErrorHandler();
$this->initEncode();
$this->initCallback();
$this->initRef();
$this->initClientID();
$this->initEncrypt();
if (isset($_REQUEST['phprpc_func'])) {
$this->callFunction();
}
else if ($this->encrypt != false) {
$this->keyExchange();
}
else {
$this->sendFunctions();
}
}
}
PHPRPC_Server::initSession();
?>

134
ThinkPHP/Library/Vendor/phpRPC/xxtea.php vendored Normal file
View File

@@ -0,0 +1,134 @@
<?php
/**********************************************************\
| |
| The implementation of PHPRPC Protocol 3.0 |
| |
| xxtea.php |
| |
| Release 3.0.1 |
| Copyright by Team-PHPRPC |
| |
| WebSite: http://www.phprpc.org/ |
| http://www.phprpc.net/ |
| http://www.phprpc.com/ |
| http://sourceforge.net/projects/php-rpc/ |
| |
| Authors: Ma Bingyao <andot@ujn.edu.cn> |
| |
| This file may be distributed and/or modified under the |
| terms of the GNU General Public License (GPL) version |
| 2.0 as published by the Free Software Foundation and |
| appearing in the included file LICENSE. |
| |
\**********************************************************/
/* XXTEA encryption arithmetic library.
*
* Copyright: Ma Bingyao <andot@ujn.edu.cn>
* Version: 1.6
* LastModified: Apr 12, 2010
* This library is free. You can redistribute it and/or modify it under GPL.
*/
if (!extension_loaded('xxtea')) {
function long2str($v, $w) {
$len = count($v);
$n = ($len - 1) << 2;
if ($w) {
$m = $v[$len - 1];
if (($m < $n - 3) || ($m > $n)) return false;
$n = $m;
}
$s = array();
for ($i = 0; $i < $len; $i++) {
$s[$i] = pack("V", $v[$i]);
}
if ($w) {
return substr(join('', $s), 0, $n);
}
else {
return join('', $s);
}
}
function str2long($s, $w) {
$v = unpack("V*", $s. str_repeat("\0", (4 - strlen($s) % 4) & 3));
$v = array_values($v);
if ($w) {
$v[count($v)] = strlen($s);
}
return $v;
}
function int32($n) {
while ($n >= 2147483648) $n -= 4294967296;
while ($n <= -2147483649) $n += 4294967296;
return (int)$n;
}
function xxtea_encrypt($str, $key) {
if ($str == "") {
return "";
}
$v = str2long($str, true);
$k = str2long($key, false);
if (count($k) < 4) {
for ($i = count($k); $i < 4; $i++) {
$k[$i] = 0;
}
}
$n = count($v) - 1;
$z = $v[$n];
$y = $v[0];
$delta = 0x9E3779B9;
$q = floor(6 + 52 / ($n + 1));
$sum = 0;
while (0 < $q--) {
$sum = int32($sum + $delta);
$e = $sum >> 2 & 3;
for ($p = 0; $p < $n; $p++) {
$y = $v[$p + 1];
$mx = int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
$z = $v[$p] = int32($v[$p] + $mx);
}
$y = $v[0];
$mx = int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
$z = $v[$n] = int32($v[$n] + $mx);
}
return long2str($v, false);
}
function xxtea_decrypt($str, $key) {
if ($str == "") {
return "";
}
$v = str2long($str, false);
$k = str2long($key, false);
if (count($k) < 4) {
for ($i = count($k); $i < 4; $i++) {
$k[$i] = 0;
}
}
$n = count($v) - 1;
$z = $v[$n];
$y = $v[0];
$delta = 0x9E3779B9;
$q = floor(6 + 52 / ($n + 1));
$sum = int32($q * $delta);
while ($sum != 0) {
$e = $sum >> 2 & 3;
for ($p = $n; $p > 0; $p--) {
$z = $v[$p - 1];
$mx = int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
$y = $v[$p] = int32($v[$p] - $mx);
}
$z = $v[$n];
$mx = int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z));
$y = $v[0] = int32($v[0] - $mx);
$sum = int32($sum - $delta);
}
return long2str($v, true);
}
}
?>