Created
June 20, 2012 19:22
-
-
Save jacobandresen/2961684 to your computer and use it in GitHub Desktop.
SIP2 Protocol layer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//2012, reindex.dk. Released under the MIT license. | |
class RxSIP { | |
public static function dispatch ($commandString) { | |
global $PORT; | |
$response = ""; | |
$cmd = substr($commandString, 0, 2); | |
$par = substr($commandString, 2, strlen($commandString)); | |
switch ($cmd) { | |
case "23": //PatronStatusRequest | |
$language = substr($par, 0, 3) ; //3-char | |
$transactionDate = substr($par, 3, 18) ; //18-char YYYYMMDDZZZZHHMMSS | |
$params = array(); | |
$params[0] = $language; | |
$params[1] = $transactionDate; | |
RxSIP::wrap($par, $params, 21); | |
break; | |
case "11": //Checkout | |
$SCRenewalPolicy = substr($par, 0, 1); // 1-char - Y or N | |
$noBlock = substr($par, 1, 1); // 1-char - Y or N | |
$transactionDate = substr($par, 2, 18); // 18-char YYYYMMDDZZZZHHMMSS | |
$nbDueDate = substr($par, 20, 18); // 18-char YYYYMMDDZZZZHHMMSS | |
$params = array(); | |
$params[0] = $SCRenewalPolicy; | |
$params[1] = $noBlock; | |
$params[2] = $transactionDate ; | |
$params[3] = $nbDueDate; | |
RxSIP::wrap($par, $params, 38); | |
break; | |
case "09": //CheckIn | |
$noBlock = substr($par, 0, 1) ; // 1-char - Y or N | |
$transactionDate = substr($par, 1, 18) ; //18-char YYYYMMDDZZZZHHMMSS | |
$returnDate = substr($par, 19, 18) ; //18-char YYYYMMDDZZZZHHMMSS | |
$params = array(); | |
$params[0] = $noBlock; | |
$params[1] = $transactionDate; | |
$params[2] = $returnDate; | |
RxSIP::wrap($par, $params , 37); | |
break; | |
case "99": //SCStatus | |
$statusCode = substr($par, 0, 1); // 1-char : 0, 1 or 2 | |
$maxPrintWidth = substr($par, 1, 3); // 3-char | |
$protocolVersion = substr($par, 4, 4); // 4-char : x.xx | |
$params = array(); | |
$params[0] = $statusCode ; | |
$params[1] = $maxPrintWidth; | |
$params[2] = $protocolVersion; | |
break; | |
//case "97": //ACSResend | |
// break; | |
case "93": //Login | |
$UIDAlgorithm = substr($par, 0, 1); //1-char (The algorithm to encrypt the user ID) | |
$PWDAlgorithm = substr($par, 1, 1); //1-char (The algorithm to encrypt the password) | |
$params = array(); | |
$params[0] = $UIDAlgorithm; | |
$params[1] = $PWDAlgorithm; | |
break; | |
case "63": //PatronInformation | |
$language = substr($par, 0, 3); //3-char | |
$transactionDate = substr($par, 3, 18); //18-char YYYYMMDDZZZZHHMMSS | |
$summary = substr($par, 18, 10); //10-char | |
$params = array(); | |
$params[0] = $language; | |
$params[1] = $transactionDate; | |
RXSIP::wrap($par, $params, 28); | |
break; | |
case "35": //EndPatronSession | |
$transactionDate = substr($par, 0, 18) ; //18-char YYYYMMDDZZZZHHMMSS | |
$params = array(); | |
$params[0] = $transactionDate; | |
RXSIP::wrap($par, $params, 18); | |
break; | |
case "65": //RenewAll | |
$transactionDate = substr($par, 0, 18) ; //18-char YYYYMMDDZZZZHHMMSS | |
$params = array(); | |
$params[0] = $transactionDate; | |
RXSIP::wrap($par, $params, 18); | |
break; | |
default: | |
break; | |
} | |
$p = ( array( $cmd => $params ) ); | |
return $p ; | |
} | |
public static function wrap( $cmd, &$params, $startPosition ) { | |
$vars = explode("|", substr($cmd, $startPosition, strlen($cmd)-$startPosition)); | |
foreach($vars as $var) { | |
$key = substr($var, 0, 2); | |
$value = substr($var, 2, strlen($var)); | |
if (trim($key) <> "") { | |
$params[$key] = $value; | |
} | |
} | |
return $params; | |
} | |
public static function unwrap( $params ) { | |
$response = key($params); | |
foreach($params[key($params)] as $key => $value ) { | |
if (is_numeric($key)) { | |
$response.=$value; | |
} else { | |
$response.="|"; | |
$response.=$key.$value; | |
} | |
} | |
$response.="|"; | |
return $response; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment