sip2

Crates.iosip2
lib.rssip2
version0.3.2
sourcesrc
created_at2022-02-25 15:33:36.743161
updated_at2024-08-21 19:49:17.457226
descriptionSIP2 Library
homepage
repositoryhttps://github.com/kcls/evergreen-universe-rs
max_upload_size
id539488
size98,862
Bill Erickson (berick)

documentation

README

SIP2 Rust Library

Rust SIP2 Client Library

API Docs

https://kcls.github.io/evergreen-universe-rs/sip2/index.html

Two Modes of Operation

Connection API

  • Supports the full SIP2 specification
  • Allows complete control over every fixed field and field value.
  • Gracefully handles unknown / custom message fields.

Client API

  • Sits atop the Connection API and provides canned actions for common tasks.
  • Client methods allow the caller to send messages using a minimal number of parameters without having to create the message by hand.

Running the CLI

cargo run --bin sip2-client-cli -- --sip-user sip-user  \
    --sip-pass sip-pass                                 \
    --item-barcode 30000017113634                       \
    --patron-barcode 394902                             \
    --message-type item-information                     \
    --message-type patron-status                        \
    --message-type patron-information

Connection API Examples

Connection API Spec Building

use sip2::*;

let host = "localhost:6001";
let user = "sip-user";
let pass = "sip-pass";

let con = Connection::new(host).unwrap();

let req = Message::new(
    &spec::M_LOGIN,
    vec![
        FixedField::new(&spec::FF_UID_ALGO, "0").unwrap(),
        FixedField::new(&spec::FF_PWD_ALGO, "0").unwrap(),
    ],
    vec![
        Field::new(spec::F_LOGIN_UID.code, user),
        Field::new(spec::F_LOGIN_PWD.code, pass),
    ]
).expect("Message Has Valid Content");

let resp = con.sendrecv(&req).unwrap();

println!("Received: {}", resp);

// Verify the response reports a successful login
if resp.spec().code == spec::M_LOGIN_RESP.code
    && resp.fixed_fields().len() == 1
    && resp.fixed_fields()[0].value() == "1" {

    println!("Login OK");

} else {

    println!("Login Failed");
}

Connection API Free-Text Message Building

let req = Message::from_values(
    &spec::M_LOGIN,
    &["0", "0"],
    &[("CN", "sip-username"), ("CO", "sip-password")]
).expect("Message Has Valid Content");

Client API example

use sip2::*;

let host = "localhost:6001";
let user = "sip-user";
let pass = "sip-pass";

let mut client = Client::new(host).unwrap();

let params = ParamSet::new();
params.set_sip_user(user);
params.set_sip_pass(pass);

let resp = client.login(&params).unwrap();

prinln!("Received: {}", resp.msg());

match resp.ok() {
    true => println!("Login OK"),
    false => eprintln!("Login Failed"),
}

Commit count: 0

cargo fmt