Compare commits
47 Commits
wip-debug-
...
538675de1d
Author | SHA1 | Date | |
---|---|---|---|
538675de1d
|
|||
419e03c46a
|
|||
18e56690fe
|
|||
2d24b78a67
|
|||
2ba548aa28
|
|||
1b2303a47c
|
|||
9408990869
|
|||
e8529a227c
|
|||
45d89aaaf5
|
|||
e7f3322484 | |||
147125eff4
|
|||
ad7a0f2594 | |||
358a279f5c
|
|||
9fc3fef350
|
|||
a194b2d888
|
|||
920b3e119b | |||
91d7474ce0 | |||
3a43428ad4 | |||
d6d487a727 | |||
65059b87d4 | |||
f8d7f82c50
|
|||
d33140ebaf
|
|||
ba88b08a57
|
|||
8c38f0e4ba | |||
648a7848fd
|
|||
f6a1af5d1e
|
|||
a19b6dcd0d
|
|||
9447ad7faf | |||
5eebd5d1cb | |||
7d41fbb519 | |||
ff2c84fb33
|
|||
b807e78ac3 | |||
d8f3c276c0 | |||
c2b4264f32 | |||
0e8514d906 | |||
86a6d2b9d3 | |||
18758ff2fe | |||
1f57b70cef | |||
83cee11e65 | |||
b1cafda669 | |||
d370a9b85d
|
|||
83b2f7358d
|
|||
8ef713ccf2
|
|||
4162e55b83 | |||
d9cedca335
|
|||
820d76d0f5
|
|||
6409e3eedf
|
28
.gitea/PULL_REQUEST_TEMPLATE.yaml
Normal file
@ -0,0 +1,28 @@
|
||||
name: Demande de fusion (Pull Request)
|
||||
about: Créez une demande de fusion pour partager votre travail avec le reste de l'équipe
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Une demande de fusion (Pull Request) a pour objectif de
|
||||
partager au reste de l'équipe un développement réalisé.
|
||||
Décrire les modifications apportées, leur impact et le contexte
|
||||
dans lequel elles ont été réalisées permettra aux relecteurices
|
||||
de plus facilement comprendre et valider votre travail.
|
||||
- type: textarea
|
||||
id: details
|
||||
attributes:
|
||||
label: Détails
|
||||
description: Décrivez le contenu de la PR, son impact concret
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: why
|
||||
attributes:
|
||||
label: Pourquoi ?
|
||||
description: Pourquoi ces modifications sont elles nécessaires ? Dans quel contexte s'inscrivent-elles ?
|
||||
- type: textarea
|
||||
id: documentation
|
||||
attributes:
|
||||
label: Documentation
|
||||
description: Précisez ici des références à des ressources que vous avez utilisées pour réaliser ces modifications
|
29
.gitea/issue_template/BUG_REPORT.yaml
Normal file
@ -0,0 +1,29 @@
|
||||
name: Rapport de bug
|
||||
about: Remplissez un rapport d'erreur
|
||||
title: "[Bug]: "
|
||||
blank_issues_enabled: false
|
||||
labels:
|
||||
- bug
|
||||
- to-triage
|
||||
body:
|
||||
- type: textarea
|
||||
id: what-happened
|
||||
attributes:
|
||||
label: Que se passe-t-il ?
|
||||
description: Décrivez la situation que vous rencontrez
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: environment-description
|
||||
attributes:
|
||||
label: Si le problème semble lié à votre environement, décrivez-le ici
|
||||
placeholder: Windows 10, Firefox 89.0, etc.
|
||||
- type: dropdown
|
||||
id: module
|
||||
attributes:
|
||||
label: Ce problème est il relatif à un ou des modules en particulier ?
|
||||
multiple: true
|
||||
options:
|
||||
- Clego
|
||||
- Tauri
|
||||
- Axum
|
13
.gitea/issue_template/FEATURE.yaml
Normal file
@ -0,0 +1,13 @@
|
||||
name: Proposez une fonctionnalité / amélioration
|
||||
about: Proposez vos idées de fonctionnalités ou d'améliorations
|
||||
blank_issues_enabled: false
|
||||
labels:
|
||||
- feature
|
||||
- to-triage
|
||||
body:
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: Décrivez votre idée
|
||||
validations:
|
||||
required: true
|
20
.gitea/issue_template/QUESTION.yaml
Normal file
@ -0,0 +1,20 @@
|
||||
name: Posez une question
|
||||
about: Une interrogation, une difficulté ? Posez votre question
|
||||
blank_issues_enabled: false
|
||||
labels:
|
||||
- question
|
||||
- to-triage
|
||||
body:
|
||||
- type: textarea
|
||||
id: question
|
||||
attributes:
|
||||
label: Que se passe-t-il ?
|
||||
description: Décrivez la situation que vous rencontrez, posez votre question
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: environment-description
|
||||
attributes:
|
||||
label: Précisez votre environnement
|
||||
description: S'il vous semble pertinent de préciser votre environement, décrivez-le ici
|
||||
placeholder: Windows 10, Firefox 89.0, etc.
|
27
.gitignore
vendored
@ -1,6 +1,23 @@
|
||||
# Ignore Rust target directory
|
||||
/target
|
||||
# ---> Rust
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
debug/
|
||||
target/
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
# Ignore .env files
|
||||
.env
|
||||
.env.build
|
4513
Cargo.lock
generated
19
Cargo.toml
@ -1,12 +1,7 @@
|
||||
[package]
|
||||
name = "utils-debug-c-lib"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
dotenv = "0.15"
|
||||
libc = "0.2"
|
||||
|
||||
[build-dependencies]
|
||||
dotenv = "0.15"
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
members = [
|
||||
"crates/app",
|
||||
"crates/sesam-vitale",
|
||||
"crates/desktop"
|
||||
]
|
||||
|
69
README.md
@ -1,46 +1,39 @@
|
||||
## Requirements
|
||||
# Krys4lide
|
||||
|
||||
- Installer le [package FSV](https://industriels.sesam-vitale.fr/group/fournitures-sesam-vitale)
|
||||
- Les librairies dynamiques (.lib, .dll, ...) fournies ne sont pas installés dans les emplacements standard du système, il faudra donc configurer leur chemin d'installation dans le fichier de configuration `.env.build` (voir ci-dessous)
|
||||
- Le détail des chemins d'installation est donné dans la documentation du package FSV `fsv-mi-004_pack-FSV1.40.14_V2.3.pdf`
|
||||
- Linux - par défaut : `/opt/santesocial/fsv/1.40.13/lib`
|
||||
- Windows - par défaut : `C:\Program Files\santesocial\santesocial\fsv\1.40.14\lib` (ou dans Program Files (x86) si c'est le package 32bits qui a été installé)
|
||||
Logiciel de Pharmacie libre et open-source.
|
||||
|
||||
- Installer la [CryptolibCPS](https://industriels.sesam-vitale.fr/group/galss-cryptolib-cps)
|
||||
- Ce package fourni également l'utilitaire "CPS Gestion" pour obtenir des informations sur le lecteur de carte, etc.
|
||||
- Linux : `cpgeslux`
|
||||
- Windows : `...`
|
||||
## Crates
|
||||
|
||||
## Setup
|
||||
- `app`: Interface du logiciel, servie par un serveur web propulsé par Axum. Utilisable en mode endpoint ou encapsulé dans le client `desktop`
|
||||
- `desktop`: Client desktop propulsé par Tauri, encapsulant le serveur web `app`
|
||||
- `sesam-vitale`: Bibliothèque de gestion des services SESAM-Vitale (Lecture des cartes CPS et Vitale, téléservices ...)
|
||||
|
||||
- Créer et éditer le fichier de configuration de build `.env.build` en s'inspirant d'un des fichiers d'exemple (`.env.build.linux.example`, `.env.build.win.example`...)
|
||||
- Ce fichier est nécessaire pour le build du package Rust
|
||||
- Créer et éditer le fichier de configuration de l'exécution `.env` en s'inspirant d'un des fichiers d'exemple (`.env.linux.example`, `.env.win.example`...)
|
||||
- Ce fichier est nécessaire pour l'exécution du package Rust compilé, et doit donc être présent aux côtés de l'exécutable généré, le cas échéant
|
||||
## Development
|
||||
|
||||
### Pré-requis
|
||||
|
||||
La CLI Tauri est nécessaire au lancement du client `desktop`. Elle peut être installée via Cargo :
|
||||
|
||||
```bash
|
||||
cargo install tauri-cli
|
||||
```
|
||||
|
||||
### Exécution de l'application cliente desktop
|
||||
|
||||
```bash
|
||||
cargo tauri dev
|
||||
```
|
||||
|
||||
### Exécution du serveur web `app` en mode endpoint
|
||||
|
||||
```bash
|
||||
cargo run --bin app
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
### Compilation C
|
||||
Packager le client desktop
|
||||
|
||||
Ce package s'appuie sur deux librairies :
|
||||
- Une librairie statique, compilée à partir des sources (`*.c`, `*.h`) fournies dans le dossier `./src`
|
||||
- Une librairie dynamique, fournie par le package FSV
|
||||
- Windows : on fournit les headers, non présents dans la `.dll` en compilant les fichiers `src/*.def` en leur version binaire `lib/*.lib`
|
||||
|
||||
Pour compiler les fichiers de librairie :
|
||||
|
||||
- Windows : `.\make.bat`
|
||||
- Linux : `make`
|
||||
|
||||
Pour nettoyer le dossier `./lib` :
|
||||
|
||||
- Windows : `.\make.bat /clean`
|
||||
- Linux : `make clean`
|
||||
|
||||
### Compilation Rust
|
||||
|
||||
`cargo build`
|
||||
|
||||
## Run
|
||||
|
||||
`cargo run`
|
||||
```bash
|
||||
cargo tauri build
|
||||
```
|
||||
|
1
crates/app/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
12
crates/app/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "app"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
askama = "0.12.1"
|
||||
askama_axum = "0.4.0"
|
||||
axum = "0.7.5"
|
||||
tokio = { version = "1.39.1", features = ["macros", "rt-multi-thread"] }
|
||||
tower-http = { version = "0.5.2", features = ["fs"] }
|
||||
|
1
crates/app/assets/js/htmx.min.js
vendored
Normal file
27
crates/app/src/lib.rs
Normal file
@ -0,0 +1,27 @@
|
||||
mod templates;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use askama_axum::IntoResponse;
|
||||
use templates::{hello::HelloResponse, index::GetIndexResponse};
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
async fn root() -> impl IntoResponse {
|
||||
return GetIndexResponse {}.into_response();
|
||||
}
|
||||
|
||||
async fn hello() -> impl IntoResponse {
|
||||
return HelloResponse {
|
||||
name: "Theo".to_string(),
|
||||
}
|
||||
.into_response();
|
||||
}
|
||||
|
||||
pub fn get_router(assets_path: &Path) -> axum::Router {
|
||||
let router = axum::Router::new()
|
||||
.nest_service("/assets", ServeDir::new(assets_path))
|
||||
.route("/", axum::routing::get(root))
|
||||
.route("/hello", axum::routing::get(hello));
|
||||
|
||||
router
|
||||
}
|
14
crates/app/src/main.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use ::app::get_router;
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
let assets_path = Path::new(&manifest_dir).join("assets");
|
||||
let router = get_router(assets_path.as_path());
|
||||
|
||||
// TODO: select port based on available port (or ask in CLI)
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
||||
axum::serve(listener, router).await.unwrap();
|
||||
}
|
7
crates/app/src/templates/hello.rs
Normal file
@ -0,0 +1,7 @@
|
||||
use askama::Template;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "hello.html")]
|
||||
pub struct HelloResponse {
|
||||
pub name: String,
|
||||
}
|
5
crates/app/src/templates/index.rs
Normal file
@ -0,0 +1,5 @@
|
||||
use askama::Template;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "index.html")]
|
||||
pub struct GetIndexResponse;
|
2
crates/app/src/templates/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod hello;
|
||||
pub mod index;
|
13
crates/app/templates/base.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>{% block title %}{{ title }}{% endblock %}</title>
|
||||
|
||||
<script src="/assets/js/htmx.min.js"></script>
|
||||
|
||||
{% block head %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
{% block body %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
1
crates/app/templates/hello.html
Normal file
@ -0,0 +1 @@
|
||||
<div>Hello {{name}}!</div>
|
23
crates/app/templates/index.html
Normal file
@ -0,0 +1,23 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Pharma Libre{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
|
||||
<div>
|
||||
<header>
|
||||
<h1>Pharma Libre</h1>
|
||||
</header>
|
||||
<main>
|
||||
<div
|
||||
id="hello"
|
||||
hx-get="/hello"
|
||||
hx-target="this"
|
||||
hx-trigger="load"
|
||||
hx-swap="outerHTML"
|
||||
>
|
||||
Loading...
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
{% endblock %}
|
7
crates/desktop/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
||||
# Generated by Tauri
|
||||
# will have schema files for capabilities auto-completion
|
||||
/gen/schemas
|
24
crates/desktop/Cargo.toml
Normal file
@ -0,0 +1,24 @@
|
||||
[package]
|
||||
name = "desktop"
|
||||
version = "0.1.0"
|
||||
description = "Un logiciel de pharmacie libre et open-source."
|
||||
authors = ["p4pillon"]
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "desktop_lib"
|
||||
crate-type = ["lib", "cdylib", "staticlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2.0.0-beta", features = [] }
|
||||
|
||||
[dependencies]
|
||||
axum = "0.7.5"
|
||||
tauri = { version = "2.0.0-beta", features = [] }
|
||||
tower = "0.4.13"
|
||||
tokio = "1.39.1"
|
||||
|
||||
app = { path = "../app" }
|
||||
http = "1.1.0"
|
||||
bytes = "1.6.1"
|
||||
|
3
crates/desktop/build.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
BIN
crates/desktop/icons/128x128.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
crates/desktop/icons/128x128@2x.png
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
crates/desktop/icons/32x32.png
Normal file
After Width: | Height: | Size: 974 B |
BIN
crates/desktop/icons/Square107x107Logo.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
crates/desktop/icons/Square142x142Logo.png
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
crates/desktop/icons/Square150x150Logo.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
crates/desktop/icons/Square284x284Logo.png
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
crates/desktop/icons/Square30x30Logo.png
Normal file
After Width: | Height: | Size: 903 B |
BIN
crates/desktop/icons/Square310x310Logo.png
Normal file
After Width: | Height: | Size: 8.4 KiB |
BIN
crates/desktop/icons/Square44x44Logo.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
crates/desktop/icons/Square71x71Logo.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
crates/desktop/icons/Square89x89Logo.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
crates/desktop/icons/StoreLogo.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
crates/desktop/icons/icon.icns
Normal file
BIN
crates/desktop/icons/icon.ico
Normal file
After Width: | Height: | Size: 85 KiB |
BIN
crates/desktop/icons/icon.png
Normal file
After Width: | Height: | Size: 14 KiB |
69
crates/desktop/src/lib.rs
Normal file
@ -0,0 +1,69 @@
|
||||
use bytes::Bytes;
|
||||
use http::{request, response, Request, Response};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::body::{to_bytes, Body};
|
||||
|
||||
use axum::Router;
|
||||
|
||||
use tauri::path::BaseDirectory;
|
||||
use tauri::Manager;
|
||||
use tokio::sync::{Mutex, MutexGuard};
|
||||
use tower::{Service, ServiceExt};
|
||||
|
||||
async fn process_tauri_request(
|
||||
tauri_request: Request<Vec<u8>>,
|
||||
mut router: MutexGuard<'_, Router>,
|
||||
) -> Response<Vec<u8>> {
|
||||
let (parts, body): (request::Parts, Vec<u8>) = tauri_request.into_parts();
|
||||
let axum_request: Request<Body> = Request::from_parts(parts, body.into());
|
||||
|
||||
let axum_response: Response<Body> = router
|
||||
.as_service()
|
||||
.ready()
|
||||
.await
|
||||
.expect("Failed to get ready service from router")
|
||||
.call(axum_request)
|
||||
.await
|
||||
.expect("Could not get response from router");
|
||||
|
||||
let (parts, body): (response::Parts, Body) = axum_response.into_parts();
|
||||
let body: Bytes = to_bytes(body, usize::MAX).await.unwrap_or_default();
|
||||
|
||||
let tauri_response: Response<Vec<u8>> = Response::from_parts(parts, body.into());
|
||||
|
||||
tauri_response
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.setup(|app| {
|
||||
let assets_path: PathBuf = app
|
||||
.path()
|
||||
.resolve("assets", BaseDirectory::Resource)
|
||||
.expect("Path should be resolvable");
|
||||
|
||||
// Adds Axum router to application state
|
||||
// This makes it so we can retrieve it from any app instance (see bellow)
|
||||
let router = Arc::new(Mutex::new(app::get_router(&assets_path)));
|
||||
|
||||
app.manage(router);
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.register_asynchronous_uri_scheme_protocol("axum", move |app, request, responder| {
|
||||
// Retrieve the router from the application state and clone it for the async block
|
||||
let router = Arc::clone(&app.state::<Arc<Mutex<axum::Router>>>());
|
||||
|
||||
// Spawn a new async task to process the request
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let router = router.lock().await;
|
||||
let response = process_tauri_request(request, router).await;
|
||||
responder.respond(response);
|
||||
});
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
6
crates/desktop/src/main.rs
Normal file
@ -0,0 +1,6 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
desktop_lib::run()
|
||||
}
|
41
crates/desktop/tauri.conf.json
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"productName": "Logiciel Pharma",
|
||||
"version": "0.0.1",
|
||||
"identifier": "org.p4pillon.pharma.desktop",
|
||||
"build": {
|
||||
"beforeDevCommand": {
|
||||
"cwd": "../app",
|
||||
"script": "cargo run"
|
||||
},
|
||||
"devUrl": "http://localhost:3000",
|
||||
"frontendDist": "axum://place.holder/"
|
||||
},
|
||||
"app": {
|
||||
"withGlobalTauri": true,
|
||||
"windows": [
|
||||
{
|
||||
"title": "Logiciel Pharma",
|
||||
"width": 800,
|
||||
"height": 600
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": null
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"resources": {
|
||||
"../app/assets/": "./assets/"
|
||||
},
|
||||
"targets": "all",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
]
|
||||
}
|
||||
|
||||
}
|
9
crates/sesam-vitale/.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
# Ignore Rust target directory
|
||||
/target
|
||||
|
||||
# Ignore .env files
|
||||
.env
|
||||
.env.build
|
||||
|
||||
# Ignore exploitation files - only usefull for local debugging on windows
|
||||
lib/*.exp
|
11
crates/sesam-vitale/Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "sesam-vitale"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
dotenv = "0.15"
|
||||
libc = "0.2"
|
||||
|
||||
[build-dependencies]
|
||||
dotenv = "0.15"
|
34
crates/sesam-vitale/README.md
Normal file
@ -0,0 +1,34 @@
|
||||
## Requirements
|
||||
|
||||
- Installer le [package FSV](https://industriels.sesam-vitale.fr/group/fournitures-sesam-vitale)
|
||||
- Les librairies dynamiques (.lib, .dll, ...) fournies ne sont pas installés dans les emplacements standard du système, il faudra donc configurer leur chemin d'installation dans le fichier de configuration `.env.build` (voir ci-dessous)
|
||||
- Le détail des chemins d'installation est donné dans la documentation du package FSV `fsv-mi-004_pack-FSV1.40.14_V2.3.pdf`
|
||||
- Linux - par défaut : `/opt/santesocial/fsv/1.40.13/lib`
|
||||
- Windows - par défaut : `C:\Program Files\santesocial\santesocial\fsv\1.40.14\lib` (ou dans Program Files (x86) si c'est le package 32bits qui a été installé)
|
||||
|
||||
- Installer la [CryptolibCPS](https://industriels.sesam-vitale.fr/group/galss-cryptolib-cps)
|
||||
- Ce package fourni également l'utilitaire "CPS Gestion" pour obtenir des informations sur le lecteur de carte, etc.
|
||||
- Linux : `cpgeslux`
|
||||
- Windows : `...`
|
||||
|
||||
## Setup
|
||||
|
||||
- Créer et éditer le fichier de configuration de build `.env.build` en s'inspirant d'un des fichiers d'exemple (`.env.build.linux.example`, `.env.build.win.example`...)
|
||||
- Ce fichier est nécessaire pour le build du package Rust
|
||||
- Créer et éditer le fichier de configuration de l'exécution `.env` en s'inspirant d'un des fichiers d'exemple (`.env.linux.example`, `.env.win.example`...)
|
||||
- Ce fichier est nécessaire pour l'exécution du package Rust compilé, et doit donc être présent aux côtés de l'exécutable généré, le cas échéant
|
||||
|
||||
## Build
|
||||
|
||||
### Windows - Compilation des headers FSV
|
||||
|
||||
Sous windows, la librairie dynamique fournie par le package FSV nécessite des headers qui ne sont pas présents dans la `.dll`. Il est donc nécessaire de fournir ces headers, en les renseignant dans des fichiers `crates/sesam-vitale/src/win/fsv/*.def` qui seront compilés en leur version binaire `crates/sesam-vitale/lib/*.lib`.
|
||||
|
||||
En cas de modification des fichiers `.def`, pour re-compiler ces headers, faire appel au script `scripts/compile_win_headers.bat`.
|
||||
|
||||
| /!\ Attention, le script `compile_win_headers.bat` exécute, en interne, l'utilitaire `vcvarsall.bat` et le linker `lib.exe` de Visual Studio. Visual Studio doit donc être installé et le chemin vers l'intallation le script `vcvarsall.bat`, écrit en dur dans le script `compile_win_headers.bat` doit être adapté à votre installation.
|
||||
|
||||
## À creuser
|
||||
|
||||
- Compilation cross platform facilitée par du Docker : https://github.com/cross-rs/cross
|
||||
- Pour éviter l'usage de dotenv pour la configuration, on peut utiliser https://direnv.net/
|
@ -4,23 +4,33 @@ use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
dotenv::from_filename(".env.build").ok();
|
||||
println!("cargo::rerun-if-changed=.env.build");
|
||||
|
||||
// Load the .env.build file for build-time environment variables
|
||||
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
let manifest_path = PathBuf::from(manifest_dir);
|
||||
dotenv::from_path(manifest_path.join(".env.build")).ok();
|
||||
|
||||
let static_lib_path = PathBuf::from(manifest_dir).join("lib");
|
||||
println!("cargo::rerun-if-env-changed=SESAM_FSV_LIB_PATH");
|
||||
println!("cargo::rerun-if-env-changed=SESAM_FSV_SSVLIB");
|
||||
println!("cargo::rerun-if-changed=.env.build");
|
||||
println!("cargo::rerun-if-changed=build.rs");
|
||||
|
||||
// Add local lib directory to the linker search path (for def files and static libs)
|
||||
let static_lib_path = manifest_path.join("lib");
|
||||
println!("cargo::rustc-link-search=native={}", static_lib_path.display());
|
||||
println!("cargo::rustc-link-lib=static=p4pillondebuglib");
|
||||
|
||||
// Add the SESAM_FSV_LIB_PATH to the linker search path
|
||||
let fsv_lib_path = PathBuf::from(env::var("SESAM_FSV_LIB_PATH").unwrap());
|
||||
println!("cargo::rustc-link-search=native={}", fsv_lib_path.display());
|
||||
println!("cargo::rustc-link-lib=dylib={}", env::var("SESAM_FSV_SSVLIB").unwrap());
|
||||
|
||||
// Add the SESAM_FSV_LIB_PATH to the PATH environment variable
|
||||
if cfg!(target_os = "windows") {
|
||||
let path = env::var("PATH").unwrap_or(String::new());
|
||||
println!("cargo:rustc-env=PATH={};{}", fsv_lib_path.display(), path);
|
||||
} else if cfg!(target_os = "linux") {
|
||||
println!("cargo:rustc-env=LD_LIBRARY_PATH={}", fsv_lib_path.display());
|
||||
}
|
||||
|
||||
// Link the SESAM_FSV_SSVLIB dynamic library
|
||||
println!("cargo::rustc-link-lib=dylib={}", env::var("SESAM_FSV_SSVLIB").unwrap());
|
||||
// TODO : try `raw-dylib` instead of `dylib` on Windows to avoid the need of the `lib` headers compiled from the `def`
|
||||
}
|
0
crates/sesam-vitale/lib/.gitkeep
Normal file
14
crates/sesam-vitale/src/lib.rs
Normal file
@ -0,0 +1,14 @@
|
||||
pub fn add(left: usize, right: usize) -> usize {
|
||||
left + right
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
}
|
||||
}
|
17
crates/sesam-vitale/src/libssv.rs
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* libssv.rs
|
||||
*
|
||||
* Low level bindings to the SSVLIB dynamic library.
|
||||
* TODO : look for creating a dedicated *-sys crate : https://kornel.ski/rust-sys-crate
|
||||
*/
|
||||
|
||||
use libc::{ c_char, c_void, c_ushort, size_t };
|
||||
|
||||
#[cfg_attr(target_os = "linux", link(name = "ssvlux64"))]
|
||||
#[cfg_attr(target_os = "windows", link(name = "ssvw64"))]
|
||||
extern "C" {
|
||||
pub fn SSV_InitLIB2(pcRepSesamIni: *const c_char) -> c_ushort;
|
||||
pub fn SSV_LireCartePS(NomRessourcePS: *const c_char, NomRessourceLecteur: *const c_char, CodePorteurPS: *const c_char, ZDonneesSortie: *mut *mut c_void, TTailleDonneesSortie: *mut size_t) -> c_ushort;
|
||||
pub fn SSV_LireConfig(ZDonneesSortie: *mut *mut c_void, TTailleDonneesSortie: *mut size_t) -> c_ushort;
|
||||
}
|
||||
/* TODO : replace void* by Rust struct : https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs */
|
8
crates/sesam-vitale/src/main.rs
Normal file
@ -0,0 +1,8 @@
|
||||
mod ssvlib_demo;
|
||||
mod libssv;
|
||||
mod ssv_memory;
|
||||
|
||||
fn main() {
|
||||
ssvlib_demo::demo();
|
||||
// XXX
|
||||
}
|
325
crates/sesam-vitale/src/ssv_memory.rs
Normal file
@ -0,0 +1,325 @@
|
||||
/**
|
||||
* Provide functions to manipulate raw memory from SSV library.
|
||||
*/
|
||||
|
||||
// TODO : Est-ce qu'on pourrait/devrait définir un type custom pour représenter les tableaux de bytes ?
|
||||
|
||||
use std::convert::TryFrom;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
struct ElementSize {
|
||||
pub size: usize,
|
||||
pub pad: usize,
|
||||
}
|
||||
|
||||
impl TryFrom<&[u8]> for ElementSize {
|
||||
type Error = &'static str;
|
||||
|
||||
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {
|
||||
/* Longueur:
|
||||
* - si le bit de poids fort du premier octet est à 0, la longueur est codée sur un octet
|
||||
* - si le bit de poids fort du premier octet est à 1, les 7 bits de poids faible codent le nombre d'octets utilisés pour coder la longueur
|
||||
*/
|
||||
if bytes.len() == 0 {
|
||||
return Err("Empty bytes input");
|
||||
}
|
||||
|
||||
let mut element_size = ElementSize { size: 0, pad: 1 };
|
||||
if bytes[0] & 0b1000_0000 == 0 {
|
||||
// Size coded on 1 byte
|
||||
element_size.size = bytes[0] as usize;
|
||||
} else {
|
||||
// Size coded on N bytes
|
||||
// N are the 7 lower bits of the first byte
|
||||
let size_bytes_len = (bytes[0] & 0b0111_1111) as usize;
|
||||
if size_bytes_len > bytes.len() - 1 {
|
||||
return Err("Invalid memory: not enough bytes to read the size");
|
||||
} else if size_bytes_len > 4 {
|
||||
return Err("Invalid memory: size is too big");
|
||||
}
|
||||
let size_bytes = &bytes[1..1 + size_bytes_len];
|
||||
|
||||
// u32::from_be_bytes() requires a 4 bytes array
|
||||
let mut padded_bytes = [0u8; 4];
|
||||
padded_bytes[size_bytes_len..].copy_from_slice(&size_bytes);
|
||||
|
||||
element_size.size = u32::from_be_bytes(padded_bytes) as usize;
|
||||
element_size.pad += size_bytes_len;
|
||||
}
|
||||
Ok(element_size)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Block<'a> {
|
||||
pub id: u16,
|
||||
pub size: usize,
|
||||
pub content: Vec<Field<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a [u8]> for Block<'a> {
|
||||
fn from(bytes: &'a [u8]) -> Self {
|
||||
let mut offset = 0;
|
||||
let id = u16::from_be_bytes(bytes[..2].try_into().unwrap());
|
||||
offset += 2;
|
||||
let ElementSize { size: block_size, pad } = bytes[2..].try_into().unwrap();
|
||||
offset += pad;
|
||||
let raw_content = &bytes[offset..];
|
||||
let mut field_offset = 0;
|
||||
// While there is still content to read, parse Fields
|
||||
let mut content = Vec::new();
|
||||
while field_offset < block_size {
|
||||
let field: Field<'a> = raw_content[field_offset..].into();
|
||||
field_offset += field.size;
|
||||
content.push(field);
|
||||
}
|
||||
Block {
|
||||
id,
|
||||
size: offset + block_size,
|
||||
content,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Field<'a> {
|
||||
pub size: usize,
|
||||
pub content: &'a [u8],
|
||||
}
|
||||
|
||||
impl<'a> From<&'a [u8]> for Field<'a> {
|
||||
fn from(bytes: &'a [u8]) -> Self {
|
||||
let ElementSize { size, pad } = bytes.try_into().unwrap();
|
||||
let contenu = &bytes[pad..pad+size];
|
||||
Field {
|
||||
size: pad+size,
|
||||
content: contenu,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode_ssv_memory(bytes: &[u8], size: usize) -> Vec<Block> {
|
||||
let mut blocks: Vec<Block> = Vec::new();
|
||||
let mut offset = 0;
|
||||
while offset < size {
|
||||
let block: Block = bytes[offset..].into();
|
||||
offset += block.size;
|
||||
blocks.push(block);
|
||||
}
|
||||
blocks
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_element_size {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn short_size() {
|
||||
let bytes: &[u8] = &[0b_0000_0001_u8];
|
||||
let element_size: ElementSize = bytes.try_into().unwrap();
|
||||
assert_eq!(element_size.size, 1);
|
||||
assert_eq!(element_size.pad, 1);
|
||||
|
||||
let bytes: &[u8] = &[0b_0100_0000_u8];
|
||||
let element_size: ElementSize = bytes.try_into().unwrap();
|
||||
assert_eq!(element_size.size, 64);
|
||||
assert_eq!(element_size.pad, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn long_size() {
|
||||
let bytes: &[u8] = &[0b_1000_0010_u8, 0b_0000_0001_u8, 0b_0100_0000_u8];
|
||||
let element_size: ElementSize = bytes.try_into().unwrap();
|
||||
assert_eq!(element_size.size, 320);
|
||||
assert_eq!(element_size.pad, 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn null_size() {
|
||||
let bytes: &[u8] = &[];
|
||||
let result: Result<ElementSize, &str> = bytes.try_into();
|
||||
assert_eq!(
|
||||
result,
|
||||
Err("Empty bytes input"),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_memory() {
|
||||
let bytes: &[u8] = &[0b_1000_0001_u8];
|
||||
let result: Result<ElementSize, &str> = bytes.try_into();
|
||||
assert_eq!(
|
||||
result,
|
||||
Err("Invalid memory: not enough bytes to read the size"),
|
||||
);
|
||||
|
||||
let bytes: &[u8] = &[0b_1000_0010_u8, 1];
|
||||
let result: Result<ElementSize, &str> = bytes.try_into();
|
||||
assert_eq!(
|
||||
result,
|
||||
Err("Invalid memory: not enough bytes to read the size"),
|
||||
);
|
||||
|
||||
let bytes: &[u8] = &[0b_1000_0101_u8, 1, 1, 1, 1, 1];
|
||||
let result: Result<ElementSize, &str> = bytes.try_into();
|
||||
assert_eq!(
|
||||
result,
|
||||
Err("Invalid memory: size is too big"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_field {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn short_size() {
|
||||
let bytes: &[u8] = &[51,
|
||||
1, 48, 1, 56, 11, 57, 57, 55, 48, 48,
|
||||
53, 50, 52, 49, 57, 52, 1, 52, 2, 50,
|
||||
50, 17, 80, 72, 65, 82, 77, 65, 67, 73,
|
||||
69, 78, 48, 48, 53, 50, 52, 49, 57, 9,
|
||||
70, 82, 65, 78, 67, 79, 73, 83, 69, 1,
|
||||
84,
|
||||
];
|
||||
let element: Field = bytes.try_into().unwrap();
|
||||
assert_eq!(element.size, 52);
|
||||
assert_eq!(element.content[..5], [1, 48, 1, 56, 11]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn long_size() {
|
||||
let mut bytes_vec = vec![0b_1000_0010_u8,
|
||||
0b_0000_0001_u8, 0b_0000_0000_u8, // size = 256
|
||||
];
|
||||
// Add 256 bytes to the content
|
||||
bytes_vec.append(&mut vec![1; 256]);
|
||||
let bytes: &[u8] = &bytes_vec;
|
||||
let element: Field = bytes.try_into().unwrap();
|
||||
assert_eq!(element.size, 259);
|
||||
assert_eq!(element.content.len(), 256);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_block {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_francoise_pharmacien0052419_partial_block_1() {
|
||||
let bytes: &[u8] = &[
|
||||
1, 48,
|
||||
1, 56,
|
||||
11, 57, 57, 55, 48, 48, 53, 50, 52, 49, 57, 52,
|
||||
];
|
||||
|
||||
let field1: Field = bytes.into();
|
||||
assert_eq!(field1.size, 2);
|
||||
assert_eq!(field1.content, &[48]);
|
||||
|
||||
let field2: Field = bytes[field1.size..].into();
|
||||
assert_eq!(field2.size, 2);
|
||||
assert_eq!(field2.content, &[56]);
|
||||
|
||||
let field3: Field = bytes[field1.size + field2.size..].into();
|
||||
assert_eq!(field3.size, 12);
|
||||
assert_eq!(field3.content, &[57, 57, 55, 48, 48, 53, 50, 52, 49, 57, 52]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_francoise_pharmacien0052419() {
|
||||
let bytes: &[u8] = &[
|
||||
0, 1, 51, // 3
|
||||
1, 48, // 2
|
||||
1, 56, // 2
|
||||
11, 57, 57, 55, 48, 48, 53, 50, 52, 49, 57, 52, // 12
|
||||
1, 52, // 2
|
||||
2, 50, 50, // 3
|
||||
17, 80, 72, 65, 82, 77, 65, 67, 73, 69, 78, 48, 48, 53, 50, 52, 49, 57, // 18
|
||||
9, 70, 82, 65, 78, 67, 79, 73, 83, 69, // 10
|
||||
1, 84, // 2
|
||||
// total: 54
|
||||
|
||||
0, 2, 83,
|
||||
1, 1,
|
||||
1, 48,
|
||||
1, 49,
|
||||
2, 56, 54,
|
||||
1, 49,
|
||||
9, 48, 66, 48, 50, 50, 49, 57, 53, 56,
|
||||
1, 56,
|
||||
24, 80, 72, 65, 82, 77, 65, 67, 73, 69, 32, 68, 85, 32, 67, 69, 78, 84, 82, 69, 50, 50, 49, 57, 53,
|
||||
8, 48, 48, 50, 48, 50, 52, 49, 57,
|
||||
1, 56,
|
||||
0,
|
||||
1, 48,
|
||||
1, 49,
|
||||
2, 53, 48,
|
||||
2, 49, 48,
|
||||
2, 48, 48,
|
||||
1, 48,
|
||||
1, 48,
|
||||
1, 48,
|
||||
1, 49,
|
||||
1, 49,
|
||||
];
|
||||
|
||||
let first_block: Block = bytes.into();
|
||||
assert_eq!(first_block.id, 1);
|
||||
assert_eq!(first_block.size, 54);
|
||||
assert_eq!(first_block.content.len(), 8);
|
||||
|
||||
let second_block: Block = bytes[first_block.size..].into();
|
||||
assert_eq!(second_block.id, 2);
|
||||
assert_eq!(second_block.size, 86);
|
||||
assert_eq!(second_block.content.len(), 21);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_decode_ssv_memory {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_francoise_pharmacien0052419() {
|
||||
let bytes: &[u8] = &[
|
||||
0, 1, 51, // 3
|
||||
1, 48, // 2
|
||||
1, 56, // 2
|
||||
11, 57, 57, 55, 48, 48, 53, 50, 52, 49, 57, 52, // 12
|
||||
1, 52, // 2
|
||||
2, 50, 50, // 3
|
||||
17, 80, 72, 65, 82, 77, 65, 67, 73, 69, 78, 48, 48, 53, 50, 52, 49, 57, // 18
|
||||
9, 70, 82, 65, 78, 67, 79, 73, 83, 69, // 10
|
||||
1, 84, // 2
|
||||
// total: 54
|
||||
|
||||
0, 2, 83,
|
||||
1, 1,
|
||||
1, 48,
|
||||
1, 49,
|
||||
2, 56, 54,
|
||||
1, 49,
|
||||
9, 48, 66, 48, 50, 50, 49, 57, 53, 56,
|
||||
1, 56,
|
||||
24, 80, 72, 65, 82, 77, 65, 67, 73, 69, 32, 68, 85, 32, 67, 69, 78, 84, 82, 69, 50, 50, 49, 57, 53,
|
||||
8, 48, 48, 50, 48, 50, 52, 49, 57,
|
||||
1, 56,
|
||||
0,
|
||||
1, 48,
|
||||
1, 49,
|
||||
2, 53, 48,
|
||||
2, 49, 48,
|
||||
2, 48, 48,
|
||||
1, 48,
|
||||
1, 48,
|
||||
1, 48,
|
||||
1, 49,
|
||||
1, 49,
|
||||
];
|
||||
let blocks = decode_ssv_memory(&bytes, bytes.len());
|
||||
println!("{:#?}", blocks);
|
||||
assert_eq!(blocks.len(), 2);
|
||||
}
|
||||
}
|
629
crates/sesam-vitale/src/ssvlib_demo.rs
Normal file
@ -0,0 +1,629 @@
|
||||
extern crate dotenv;
|
||||
/**
|
||||
* High level API for the SSV library,
|
||||
* based on the low level bindings in libssv.rs.
|
||||
*
|
||||
*/
|
||||
extern crate libc;
|
||||
|
||||
use libc::{c_void, size_t};
|
||||
use std::ffi::CString;
|
||||
use std::path::PathBuf;
|
||||
use std::ptr;
|
||||
|
||||
use std::env;
|
||||
|
||||
use crate::libssv::{SSV_InitLIB2, SSV_LireCartePS, SSV_LireConfig};
|
||||
|
||||
fn ssv_init_lib_2() {
|
||||
let ini_str = env::var("SESAM_INI_PATH").expect("SESAM_INI_PATH must be set");
|
||||
let ini = CString::new(ini_str).expect("CString::new failed");
|
||||
unsafe {
|
||||
let result = SSV_InitLIB2(ini.as_ptr());
|
||||
println!("SSV_InitLIB2 result: {}", result);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
1. CB = Caractères Binaires »
|
||||
2. CE = Caractères « Etendus » (ISO 8859-1)
|
||||
3. CA = Caractères Alphanumériques (ASCII?)
|
||||
4. CN = Caractères Numériques
|
||||
*/
|
||||
|
||||
#[derive(Debug)]
|
||||
struct CartePS {
|
||||
titulaire: TitulairePS,
|
||||
situations: Vec<SituationPS>,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
struct TitulairePS {
|
||||
type_de_carte_ps: String, // CN
|
||||
type_d_identification_nationale: String, // CN
|
||||
numero_d_identification_nationale: String, // CE - 8 -> 30
|
||||
cle_du_numero_d_identification_nationale: String, // CN
|
||||
code_civilite: String, // CN
|
||||
nom_du_ps: String, // CE - 27
|
||||
prenom_du_ps: String, // CE - 27
|
||||
categorie_carte: char, // CA
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct SituationPS {
|
||||
numero_logique_de_la_situation_de_facturation_du_ps: u8,
|
||||
mode_d_exercice: String,
|
||||
statut_d_exercice: String,
|
||||
secteur_d_activite: String,
|
||||
type_d_identification_structure: String,
|
||||
numero_d_identification_structure: String,
|
||||
cle_du_numero_d_identification_structure: String,
|
||||
raison_sociale_structure: String,
|
||||
numero_d_identification_de_facturation_du_ps: String,
|
||||
cle_du_numero_d_identification_de_facturation_du_ps: String,
|
||||
numero_d_identification_du_ps_remplaçant: String,
|
||||
cle_du_numero_d_identification_du_ps_remplaçant: String,
|
||||
code_conventionnel: String,
|
||||
code_specialite: String,
|
||||
code_zone_tarifaire: String,
|
||||
code_zone_ik: String,
|
||||
code_agrement_1: String,
|
||||
code_agrement_2: String,
|
||||
code_agrement_3: String,
|
||||
habilitation_à_signer_une_facture: String,
|
||||
habilitation_à_signer_un_lot: String,
|
||||
}
|
||||
|
||||
impl Default for SituationPS {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
numero_logique_de_la_situation_de_facturation_du_ps: 0,
|
||||
mode_d_exercice: String::new(),
|
||||
statut_d_exercice: String::new(),
|
||||
secteur_d_activite: String::new(),
|
||||
type_d_identification_structure: String::new(),
|
||||
numero_d_identification_structure: String::new(),
|
||||
cle_du_numero_d_identification_structure: String::new(),
|
||||
raison_sociale_structure: String::new(),
|
||||
numero_d_identification_de_facturation_du_ps: String::new(),
|
||||
cle_du_numero_d_identification_de_facturation_du_ps: String::new(),
|
||||
numero_d_identification_du_ps_remplaçant: String::new(),
|
||||
cle_du_numero_d_identification_du_ps_remplaçant: String::new(),
|
||||
code_conventionnel: String::new(),
|
||||
code_specialite: String::new(),
|
||||
code_zone_tarifaire: String::new(),
|
||||
code_zone_ik: String::new(),
|
||||
code_agrement_1: String::new(),
|
||||
code_agrement_2: String::new(),
|
||||
code_agrement_3: String::new(),
|
||||
habilitation_à_signer_une_facture: String::new(),
|
||||
habilitation_à_signer_un_lot: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn ssv_lire_carte_ps(code_pin :&str, lecteur :&str) {
|
||||
let resource_ps =
|
||||
CString::new(lecteur).expect("CString::new failed");
|
||||
let resource_reader = CString::new("").expect("CString::new failed");
|
||||
let card_number = CString::new(code_pin).expect("CString::new failed");
|
||||
|
||||
let mut buffer: *mut c_void = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
let mut hex_values: &[u8] = &[];
|
||||
unsafe {
|
||||
let result = SSV_LireCartePS(
|
||||
resource_ps.as_ptr(),
|
||||
resource_reader.as_ptr(),
|
||||
card_number.as_ptr(),
|
||||
&mut buffer,
|
||||
&mut size,
|
||||
);
|
||||
println!("SSV_LireCartePS result: {}", result);
|
||||
|
||||
if !buffer.is_null() {
|
||||
hex_values = std::slice::from_raw_parts(buffer as *const u8, size);
|
||||
libc::free(buffer);
|
||||
}
|
||||
}
|
||||
decode_zone_memoire(hex_values);
|
||||
|
||||
/* IDÉE : implémenter decode_zone_memoire sous forme d'itérateur
|
||||
for (group, group_rank) in decode_zone_memoire(...) {
|
||||
for (field, field_rank) in group {
|
||||
match group_rank {
|
||||
GROUP_1: {
|
||||
match field_rank {
|
||||
1 => carte_ps.titulaire.type_de_carte_ps = field.into(),
|
||||
2 => carte_ps.titulaire.type_d_identification_nationale = field.into(),
|
||||
3 => carte_ps.titulaire.numero_d_identification_nationale = field.into(),
|
||||
4 => carte_ps.titulaire.cle_du_numero_d_identification_nationale = field.into(),
|
||||
5 => carte_ps.titulaire.code_civilite = field.into(),
|
||||
6 => carte_ps.titulaire.nom_du_ps = field.into(),
|
||||
7 => carte_ps.titulaire.prenom_du_ps = field.into(),
|
||||
8 => carte_ps.titulaire.categorie_carte = field.into(),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
GROUP_2: {
|
||||
match field_rank {
|
||||
...
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Options possibles :
|
||||
* - Passer un objet de type variable (CartePS, CarteVitale...) et le remplir intelligemment
|
||||
* - Retourner un itérateur et faire le remplissage en dehors de decode_zone_memoire
|
||||
*/
|
||||
pub fn decode_zone_memoire(bytes: &[u8]) {
|
||||
// Maintenant, vous pouvez accéder aux octets individuels dans `donnees`
|
||||
let mut current_pos_general = 0;
|
||||
let mut current_groupe = 0;
|
||||
let mut num_champ = 0;
|
||||
|
||||
let mut carte_ps = CartePS {
|
||||
titulaire: TitulairePS {
|
||||
type_de_carte_ps: String::new(),
|
||||
type_d_identification_nationale: String::new(),
|
||||
numero_d_identification_nationale: String::new(),
|
||||
cle_du_numero_d_identification_nationale: String::new(),
|
||||
code_civilite: String::new(),
|
||||
nom_du_ps: String::new(),
|
||||
prenom_du_ps: String::new(),
|
||||
categorie_carte: ' ',
|
||||
},
|
||||
situations: Vec::new(),
|
||||
};
|
||||
|
||||
println!("--- Decoding Zone Memoire ---");
|
||||
println!("Taille de la zone mémoire: {}", bytes.len());
|
||||
while current_pos_general < bytes.len() - 1 {
|
||||
num_champ = 0;
|
||||
current_groupe =
|
||||
256 * bytes[current_pos_general] as i32 + bytes[current_pos_general + 1] as i32;
|
||||
println!("-- Nouveau groupe : {}", current_groupe);
|
||||
current_pos_general += 2;
|
||||
|
||||
let longueur_groupe: usize;
|
||||
if bytes[current_pos_general] < 128 {
|
||||
longueur_groupe = bytes[current_pos_general] as usize;
|
||||
} else {
|
||||
let nbre_octets_longueur = bytes[current_pos_general] - 128;
|
||||
longueur_groupe = (0..nbre_octets_longueur).fold(0, |acc, i| {
|
||||
current_pos_general += 1;
|
||||
acc + (256_i32.pow(i as u32) * bytes[current_pos_general] as i32) as usize
|
||||
});
|
||||
}
|
||||
println!("--- Longueur groupe: {}", longueur_groupe);
|
||||
current_pos_general += 1;
|
||||
|
||||
let mut current_pos_groupe = 0;
|
||||
while current_pos_groupe < longueur_groupe {
|
||||
num_champ += 1;
|
||||
println!("---- Nouveau champ : {}", num_champ);
|
||||
let longueur_champs: usize;
|
||||
let nbre_octets_longueur: usize;
|
||||
if bytes[current_pos_general] < 128 {
|
||||
longueur_champs = bytes[current_pos_general] as usize;
|
||||
nbre_octets_longueur = 1;
|
||||
} else {
|
||||
nbre_octets_longueur = bytes[current_pos_general] as usize - 128;
|
||||
longueur_champs = (0..nbre_octets_longueur).fold(0, |acc, i| {
|
||||
current_pos_general += 1;
|
||||
current_pos_groupe += 1;
|
||||
acc + (256_i32.pow(i as u32) * bytes[current_pos_general] as i32) as usize
|
||||
});
|
||||
}
|
||||
println!("----- Longueur champ: {}", longueur_champs);
|
||||
|
||||
let mut bytes_champ = vec![0; longueur_champs];
|
||||
if longueur_champs > 0 {
|
||||
bytes_champ.copy_from_slice(
|
||||
&bytes[current_pos_general + nbre_octets_longueur
|
||||
..current_pos_general + nbre_octets_longueur + longueur_champs],
|
||||
);
|
||||
println!("----- Bytes du champ: {:?}", bytes_champ);
|
||||
|
||||
match current_groupe {
|
||||
1 => match num_champ {
|
||||
1 => {
|
||||
carte_ps.titulaire.type_de_carte_ps =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
2 => {
|
||||
carte_ps.titulaire.type_d_identification_nationale =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
3 => {
|
||||
carte_ps.titulaire.numero_d_identification_nationale =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
4 => {
|
||||
carte_ps.titulaire.cle_du_numero_d_identification_nationale =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
5 => {
|
||||
carte_ps.titulaire.code_civilite =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
6 => {
|
||||
carte_ps.titulaire.nom_du_ps =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
7 => {
|
||||
carte_ps.titulaire.prenom_du_ps =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
8 => {
|
||||
carte_ps.titulaire.categorie_carte = bytes_champ[0] as char;
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
2 => match num_champ {
|
||||
1 => {
|
||||
carte_ps.situations.push(SituationPS::default());
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.numero_logique_de_la_situation_de_facturation_du_ps =
|
||||
bytes_champ[0];
|
||||
}
|
||||
2 => {
|
||||
carte_ps.situations.last_mut().unwrap().mode_d_exercice =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
3 => {
|
||||
carte_ps.situations.last_mut().unwrap().statut_d_exercice =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
4 => {
|
||||
carte_ps.situations.last_mut().unwrap().secteur_d_activite =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
5 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.type_d_identification_structure =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
6 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.numero_d_identification_structure =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
7 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.cle_du_numero_d_identification_structure =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
8 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.raison_sociale_structure =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
9 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.numero_d_identification_de_facturation_du_ps =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
10 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.cle_du_numero_d_identification_de_facturation_du_ps =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
11 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.numero_d_identification_du_ps_remplaçant =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
12 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.cle_du_numero_d_identification_du_ps_remplaçant =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
13 => {
|
||||
carte_ps.situations.last_mut().unwrap().code_conventionnel =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
14 => {
|
||||
carte_ps.situations.last_mut().unwrap().code_specialite =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
15 => {
|
||||
carte_ps.situations.last_mut().unwrap().code_zone_tarifaire =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
16 => {
|
||||
carte_ps.situations.last_mut().unwrap().code_zone_ik =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
17 => {
|
||||
carte_ps.situations.last_mut().unwrap().code_agrement_1 =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
18 => {
|
||||
carte_ps.situations.last_mut().unwrap().code_agrement_2 =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
19 => {
|
||||
carte_ps.situations.last_mut().unwrap().code_agrement_3 =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
20 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.habilitation_à_signer_une_facture =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
21 => {
|
||||
carte_ps
|
||||
.situations
|
||||
.last_mut()
|
||||
.unwrap()
|
||||
.habilitation_à_signer_un_lot =
|
||||
String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
} else {
|
||||
println!("----- Pas de bytes pour ce champ");
|
||||
}
|
||||
|
||||
current_pos_general += longueur_champs + nbre_octets_longueur;
|
||||
current_pos_groupe += longueur_champs + nbre_octets_longueur;
|
||||
}
|
||||
}
|
||||
|
||||
println!("CartePS: {:#?}", carte_ps);
|
||||
}
|
||||
|
||||
fn ssv_lire_config() {
|
||||
let mut buffer: *mut c_void = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
unsafe {
|
||||
let result = SSV_LireConfig(&mut buffer, &mut size);
|
||||
println!("SSV_LireConfig result: {}", result);
|
||||
|
||||
if !buffer.is_null() {
|
||||
let hex_values = std::slice::from_raw_parts(buffer as *const u8, size);
|
||||
for &byte in hex_values {
|
||||
print!("{:02X} ", byte);
|
||||
}
|
||||
println!();
|
||||
|
||||
libc::free(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn demo() {
|
||||
/*
|
||||
* TODO : this is probably not working on release, because I'm not sure it exists a CARGO_MANIFEST_DIR and so it can find the `.env`
|
||||
* Maybe we could use a system standard config path to store a config file
|
||||
*/
|
||||
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
let manifest_path = PathBuf::from(manifest_dir);
|
||||
dotenv::from_path(manifest_path.join(".env")).ok();
|
||||
|
||||
println!("------- Demo for the SSV library 2 --------");
|
||||
|
||||
ssv_init_lib_2();
|
||||
let code_pin = "1234";
|
||||
let lecteur = "HID Global OMNIKEY 3x21 Smart Card Reader 0";
|
||||
let carte_ps = ssv_lire_carte_ps2(code_pin, lecteur);
|
||||
println!("CartePS: {:#?}", carte_ps);
|
||||
// ssv_lire_config();
|
||||
|
||||
println!("-----------------------------------------");
|
||||
}
|
||||
|
||||
|
||||
struct field{
|
||||
rank : i32,
|
||||
value : Vec<u8>
|
||||
}
|
||||
impl Default for field {
|
||||
fn default() -> Self {
|
||||
Self {rank: 0,
|
||||
value: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
pub struct group{
|
||||
rank : i32,
|
||||
fields : Vec<field>
|
||||
}
|
||||
impl Default for group {
|
||||
fn default() -> Self {
|
||||
Self {rank: 0,
|
||||
fields: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode_zone_memoire2(bytes: &[u8]) -> Vec<group>{
|
||||
|
||||
let mut current_pos_general = 0;
|
||||
let mut current_groupe = 0;
|
||||
let mut num_champ = 0;
|
||||
let mut longueur_groupe: usize;
|
||||
let mut current_pos_groupe = 0;
|
||||
let mut groups : Vec<group> = Vec::new();
|
||||
|
||||
while current_pos_general < (bytes.len() - 1) {
|
||||
num_champ = 0;
|
||||
current_groupe =
|
||||
256 * bytes[current_pos_general] as i32 + bytes[current_pos_general + 1 ] as i32;
|
||||
current_pos_general += 2;
|
||||
|
||||
groups.push(group::default());
|
||||
groups.last_mut().unwrap().rank=current_groupe;
|
||||
|
||||
if bytes[current_pos_general] < 128 {
|
||||
longueur_groupe = bytes[current_pos_general] as usize;
|
||||
} else {
|
||||
let nbre_octets_longueur = bytes[current_pos_general] - 128;
|
||||
longueur_groupe = (0..nbre_octets_longueur).fold(0, |acc, i| {
|
||||
current_pos_general += 1;
|
||||
acc + (256_i32.pow(i as u32) * bytes[current_pos_general] as i32) as usize
|
||||
});
|
||||
}
|
||||
current_pos_general += 1;
|
||||
println!("------- 3--------");
|
||||
current_pos_groupe = 0;
|
||||
while current_pos_groupe < longueur_groupe {
|
||||
num_champ += 1;
|
||||
let longueur_champs: usize;
|
||||
let nbre_octets_longueur: usize;
|
||||
if bytes[current_pos_general] < 128 {
|
||||
longueur_champs = bytes[current_pos_general] as usize;
|
||||
nbre_octets_longueur = 1;
|
||||
} else {
|
||||
nbre_octets_longueur = bytes[current_pos_general] as usize - 128;
|
||||
longueur_champs = (0..nbre_octets_longueur).fold(0, |acc, i| {
|
||||
current_pos_general += 1;
|
||||
current_pos_groupe += 1;
|
||||
acc + (256_i32.pow(i as u32) * bytes[current_pos_general] as i32) as usize
|
||||
});
|
||||
}
|
||||
|
||||
groups.last_mut().unwrap().fields.push(field::default());
|
||||
groups.last_mut().unwrap().fields.last_mut().unwrap().rank=num_champ;
|
||||
|
||||
if longueur_champs > 0 {
|
||||
let mut bytes_champ = vec![0; longueur_champs];
|
||||
bytes_champ.copy_from_slice(
|
||||
&bytes[current_pos_general + nbre_octets_longueur
|
||||
..current_pos_general + nbre_octets_longueur + longueur_champs],
|
||||
);
|
||||
|
||||
//groups.last_mut().unwrap().fields.last_mut().unwrap().value= String::from_utf8_lossy(&bytes_champ).to_string();
|
||||
groups.last_mut().unwrap().fields.last_mut().unwrap().value= bytes_champ;
|
||||
|
||||
|
||||
}
|
||||
current_pos_general += longueur_champs + nbre_octets_longueur;
|
||||
current_pos_groupe += longueur_champs + nbre_octets_longueur;
|
||||
}
|
||||
}
|
||||
groups
|
||||
}
|
||||
|
||||
fn ssv_lire_carte_ps2(code_pin :&str, lecteur :&str) -> CartePS{
|
||||
let resource_ps = CString::new(lecteur).expect("CString::new failed");
|
||||
let resource_reader = CString::new("").expect("CString::new failed");
|
||||
let card_number = CString::new(code_pin).expect("CString::new failed");
|
||||
|
||||
let mut buffer: *mut c_void = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
let mut hex_values: &[u8] = &[];
|
||||
unsafe {
|
||||
let result = SSV_LireCartePS(
|
||||
resource_ps.as_ptr(),
|
||||
resource_reader.as_ptr(),
|
||||
card_number.as_ptr(),
|
||||
&mut buffer,
|
||||
&mut size,
|
||||
);
|
||||
println!("SSV_LireCartePS result: {}", result);
|
||||
|
||||
if !buffer.is_null() {
|
||||
hex_values = std::slice::from_raw_parts(buffer as *const u8, size);
|
||||
libc::free(buffer);
|
||||
}
|
||||
}
|
||||
let groups= decode_zone_memoire2(hex_values);
|
||||
let mut carte_ps = CartePS {
|
||||
titulaire: TitulairePS {
|
||||
type_de_carte_ps: String::new(),
|
||||
type_d_identification_nationale: String::new(),
|
||||
numero_d_identification_nationale: String::new(),
|
||||
cle_du_numero_d_identification_nationale: String::new(),
|
||||
code_civilite: String::new(),
|
||||
nom_du_ps: String::new(),
|
||||
prenom_du_ps: String::new(),
|
||||
categorie_carte: ' ',
|
||||
},
|
||||
situations: Vec::new(),
|
||||
};
|
||||
for item_group in groups.iter(){
|
||||
for item_field in item_group.fields.iter(){
|
||||
match (item_group.rank,item_field.rank) {
|
||||
(1, 1) => {carte_ps.titulaire.type_de_carte_ps = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(1, 2) => {carte_ps.titulaire.type_d_identification_nationale = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(1, 3) => {carte_ps.titulaire.numero_d_identification_nationale = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(1, 4) => {carte_ps.titulaire.cle_du_numero_d_identification_nationale = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(1, 5) => {carte_ps.titulaire.code_civilite = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(1, 6) => {carte_ps.titulaire.nom_du_ps = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(1, 7) => {carte_ps.titulaire.prenom_du_ps = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(1, 8) => unsafe {carte_ps.titulaire.categorie_carte = char::from_u32_unchecked(item_field.value[0] as u32)}
|
||||
(2, 1) => {carte_ps.situations.push(SituationPS::default());
|
||||
carte_ps.situations.last_mut().unwrap().numero_logique_de_la_situation_de_facturation_du_ps = item_field.value[0];}
|
||||
(2, 2) => {carte_ps.situations.last_mut().unwrap().mode_d_exercice = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 3) => {carte_ps.situations.last_mut().unwrap().statut_d_exercice = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 4) => {carte_ps.situations.last_mut().unwrap().secteur_d_activite = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 5) => {carte_ps.situations.last_mut().unwrap().type_d_identification_structure = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 6) => {carte_ps.situations.last_mut().unwrap().numero_d_identification_structure = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 7) => {carte_ps.situations.last_mut().unwrap().cle_du_numero_d_identification_structure = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 8) => {carte_ps.situations.last_mut().unwrap().raison_sociale_structure = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 9) => {carte_ps.situations.last_mut().unwrap().numero_d_identification_de_facturation_du_ps = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 10) => {carte_ps.situations.last_mut().unwrap().cle_du_numero_d_identification_de_facturation_du_ps = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 11) => {carte_ps.situations.last_mut().unwrap().numero_d_identification_du_ps_remplaçant = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 12) => {carte_ps.situations.last_mut().unwrap().cle_du_numero_d_identification_du_ps_remplaçant = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 13) => {carte_ps.situations.last_mut().unwrap().code_conventionnel = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 14) => {carte_ps.situations.last_mut().unwrap().code_specialite = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 15) => {carte_ps.situations.last_mut().unwrap().code_zone_tarifaire = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 16) => {carte_ps.situations.last_mut().unwrap().code_zone_ik = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 17) => {carte_ps.situations.last_mut().unwrap().code_agrement_1 = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 18) => {carte_ps.situations.last_mut().unwrap().code_agrement_2 = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 19) => {carte_ps.situations.last_mut().unwrap().code_agrement_3 = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 20) => {carte_ps.situations.last_mut().unwrap().habilitation_à_signer_une_facture = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
(2, 21) => {carte_ps.situations.last_mut().unwrap().habilitation_à_signer_un_lot = String::from_utf8_lossy(&item_field.value).to_string();}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
carte_ps
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
BIN
lib/ssvw64.exp
36
make.bat
@ -1,36 +0,0 @@
|
||||
@echo off
|
||||
rem Set variables
|
||||
set SRC_DIR=src
|
||||
set LIB_DIR=lib
|
||||
|
||||
rem Create the %LIB_DIR% directory if it does not exist
|
||||
if not exist %LIB_DIR% mkdir %LIB_DIR%
|
||||
|
||||
if "%1"=="/clean" (
|
||||
goto clean
|
||||
)
|
||||
|
||||
rem Configure the environment for Visual Studio
|
||||
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
|
||||
|
||||
rem Build %SRC_DIR%\*.c files
|
||||
cl /c /Fd:%LIB_DIR%\ /Fo:%LIB_DIR%\ /Iinclude\ /I%SRC_DIR%\ %SRC_DIR%\*.c
|
||||
|
||||
rem Link the object files into a static library
|
||||
lib %LIB_DIR%\*.obj
|
||||
|
||||
rem Create a ssvw64.lib file from a ssvw64.def file
|
||||
lib /def:%SRC_DIR%\ssvw64.def /out:%LIB_DIR%\ssvw64.lib /machine:x64
|
||||
|
||||
rem Build complete
|
||||
pause
|
||||
exit /b 0
|
||||
|
||||
:clean
|
||||
del %LIB_DIR%\*.obj
|
||||
del %LIB_DIR%\*.lib
|
||||
del %LIB_DIR%\*.exp
|
||||
|
||||
rem Clean complete
|
||||
pause
|
||||
exit /b 0
|
32
makefile
@ -1,32 +0,0 @@
|
||||
# Detect the operating system
|
||||
ifeq ($(OS),Windows_NT)
|
||||
MKDIR = if not exist $(LIB_DIR) mkdir $(LIB_DIR)
|
||||
RM = del
|
||||
else
|
||||
MKDIR = mkdir -p $(LIB_DIR)
|
||||
RM = rm -f
|
||||
endif
|
||||
|
||||
CC = gcc
|
||||
AR = ar
|
||||
CFLAGS = -Wall -fPIC
|
||||
SRC_DIR = src
|
||||
LIB_DIR = lib
|
||||
SRC_FILES = $(wildcard $(SRC_DIR)/*.c)
|
||||
OBJ_FILES = $(SRC_FILES:$(SRC_DIR)/%.c=$(LIB_DIR)/%.o)
|
||||
STATIC_LIB = $(LIB_DIR)/libp4pillondebuglib.a
|
||||
|
||||
all: $(STATIC_LIB)
|
||||
|
||||
$(STATIC_LIB): $(OBJ_FILES)
|
||||
$(MKDIR)
|
||||
$(AR) rcs $@ $^
|
||||
|
||||
$(LIB_DIR)/%.o: $(SRC_DIR)/%.c
|
||||
$(MKDIR)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJ_FILES) $(STATIC_LIB)
|
||||
|
||||
.PHONY: all clean
|
0
scripts/.gitkeep
Normal file
26
scripts/compile_win_headers.bat
Normal file
@ -0,0 +1,26 @@
|
||||
@echo off
|
||||
rem Set variables
|
||||
set LIB_DIR=crates/sesam-vitale/lib
|
||||
set DEF_DIR=crates/sesam-vitale/src/win/fsv
|
||||
|
||||
if "%1"=="/clean" (
|
||||
goto clean
|
||||
)
|
||||
|
||||
rem Set the environment for the x64 platform
|
||||
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
|
||||
|
||||
rem Create a ssvw64.lib file from the ssvw64.def file
|
||||
lib /def:ssvw64.def /out:%LIB_DIR%\ssvw64.lib /machine:x64
|
||||
|
||||
rem Build complete
|
||||
pause
|
||||
exit /b 0
|
||||
|
||||
:clean
|
||||
del %LIB_DIR%\*.lib
|
||||
del %LIB_DIR%\*.exp
|
||||
|
||||
rem Clean complete
|
||||
pause
|
||||
exit /b 0
|
@ -1,7 +0,0 @@
|
||||
mod p4pillondebuglib_demo;
|
||||
mod ssvlib_demo;
|
||||
|
||||
fn main() {
|
||||
p4pillondebuglib_demo::demo();
|
||||
ssvlib_demo::demo();
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
// mylib.c
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char* hello() {
|
||||
return "Hello, World!";
|
||||
}
|
||||
|
||||
char* helloName(const char *name) {
|
||||
char *result = (char *)malloc(strlen(name) + 9);
|
||||
if (result) {
|
||||
sprintf(result, "Hello, %s!", name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void helloPtr(char *result) {
|
||||
sprintf(result, "Hello, World!");
|
||||
}
|
||||
|
||||
void helloPtrPtr(char **result, size_t *size) {
|
||||
const char *message = "Hello, World!";
|
||||
*size = strlen(message) + 1; // +1 for null terminator
|
||||
*result = (char *)malloc(*size);
|
||||
if (*result) {
|
||||
strcpy(*result, message);
|
||||
}
|
||||
}
|
||||
|
||||
void helloVoidPtrPtr(void **result, size_t *size) {
|
||||
const char *message = "Hello, World!";
|
||||
*size = strlen(message) + 1; // +1 for null terminator
|
||||
*result = malloc(*size);
|
||||
if (*result != NULL) {
|
||||
strcpy((char *)*result, message);
|
||||
}
|
||||
}
|
||||
|
||||
int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
// Add function returning result in a pointer
|
||||
void addPtr(int a, int b, int *result) {
|
||||
*result = a + b;
|
||||
}
|
||||
|
||||
void fillHexValues(void **result, size_t *size) {
|
||||
unsigned char values[5] = {0x05, 0xE7, 0x02, 0x00, 0x00};
|
||||
|
||||
*size = sizeof(values);
|
||||
*result = malloc(*size);
|
||||
if (*result != NULL) {
|
||||
memcpy(*result, values, *size);
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#ifndef P4PILLONDEBUGLIB_H
|
||||
#define P4PILLONDEBUGLIB_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
char* hello();
|
||||
char* helloName(const char *name);
|
||||
void helloPtr(char *result);
|
||||
void helloPtrPtr(char **result, size_t *size);
|
||||
void helloVoidPtrPtr(void **result, size_t *size);
|
||||
int add(int a, int b);
|
||||
void addPtr(int a, int b, int *result);
|
||||
void fillHexValues(void **result, size_t *size);
|
||||
|
||||
#endif // P4PILLONDEBUGLIB_H
|
@ -1,101 +0,0 @@
|
||||
extern crate libc;
|
||||
|
||||
use libc::{ c_char, c_int, c_void, size_t };
|
||||
use std::ffi::{ CStr, CString };
|
||||
use std::ptr;
|
||||
|
||||
#[link(name = "p4pillondebuglib")]
|
||||
extern "C" {
|
||||
fn hello() -> *const c_char;
|
||||
fn helloName(name: *const c_char) -> *const c_char;
|
||||
fn helloPtr(result: *mut c_char);
|
||||
fn helloPtrPtr(result: *mut *mut c_char, size: *mut size_t);
|
||||
fn helloVoidPtrPtr(result: *mut *mut c_void, size: *mut size_t);
|
||||
fn add(a: c_int, b: c_int) -> c_int;
|
||||
fn addPtr(a: c_int, b: c_int, result: *mut c_int);
|
||||
fn fillHexValues(result: *mut *mut c_void, size: *mut size_t);
|
||||
}
|
||||
|
||||
pub fn demo() {
|
||||
println!("------- Demo for the P4PillonDebugLib ---");
|
||||
|
||||
unsafe {
|
||||
let c_str = hello();
|
||||
let r_str: &str = CStr::from_ptr(c_str).to_str().unwrap();
|
||||
println!("{} from C", r_str);
|
||||
}
|
||||
|
||||
let name = CString::new("John").expect("CString::new failed");
|
||||
unsafe {
|
||||
let c_str = helloName(name.as_ptr());
|
||||
let r_str = CStr::from_ptr(c_str).to_str().expect("Conversion failed");
|
||||
println!("{} from C with name", r_str);
|
||||
|
||||
libc::free(c_str as *mut c_void);
|
||||
}
|
||||
|
||||
let mut buffer: [c_char; 50] = [0; 50];
|
||||
unsafe {
|
||||
helloPtr(buffer.as_mut_ptr());
|
||||
let c_str = CStr::from_ptr(buffer.as_ptr());
|
||||
let r_str = c_str.to_str().unwrap();
|
||||
println!("{} from C Ptr", r_str);
|
||||
}
|
||||
|
||||
let mut buffer: *mut c_char = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
unsafe {
|
||||
helloPtrPtr(&mut buffer, &mut size);
|
||||
|
||||
if !buffer.is_null() {
|
||||
let c_str = CStr::from_ptr(buffer);
|
||||
let r_str = c_str.to_str().unwrap();
|
||||
println!("{} from C Ptr Ptr (size: {})", r_str, size);
|
||||
|
||||
libc::free(buffer as *mut c_void);
|
||||
}
|
||||
}
|
||||
|
||||
let mut buffer: *mut c_void = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
unsafe {
|
||||
helloVoidPtrPtr(&mut buffer, &mut size);
|
||||
|
||||
if !buffer.is_null() {
|
||||
let c_str = CStr::from_ptr(buffer as *const c_char);
|
||||
let r_str = c_str.to_str().unwrap();
|
||||
println!("{} from C Void Ptr Ptr (size: {})", r_str, size);
|
||||
|
||||
libc::free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let result = add(1, 2);
|
||||
println!("Result of 1 + 2 = {}", result);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let mut result = 0;
|
||||
addPtr(1, 2, &mut result);
|
||||
println!("Result Ptr of 1 + 2 = {}", result);
|
||||
}
|
||||
|
||||
let mut buffer: *mut c_void = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
unsafe {
|
||||
fillHexValues(&mut buffer, &mut size);
|
||||
|
||||
if !buffer.is_null() {
|
||||
let hex_values = std::slice::from_raw_parts(buffer as *const u8, size);
|
||||
for &byte in hex_values {
|
||||
print!("{:02X} ", byte);
|
||||
}
|
||||
println!();
|
||||
|
||||
libc::free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
println!("-----------------------------------------");
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
extern crate libc;
|
||||
extern crate dotenv;
|
||||
|
||||
use libc::{ c_char, c_void, c_ushort, size_t };
|
||||
use std::ffi::CString;
|
||||
use std::ptr;
|
||||
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
|
||||
extern "C" {
|
||||
fn SSV_InitLIB2(pcRepSesamIni: *const c_char) -> c_ushort;
|
||||
fn SSV_LireCartePS(NomRessourcePS: *const c_char, NomRessourceLecteur: *const c_char, CodePorteurPS: *const c_char, ZDonneesSortie: *mut *mut c_void, TTailleDonneesSortie: *mut size_t) -> c_ushort;
|
||||
fn SSV_LireConfig(ZDonneesSortie: *mut *mut c_void, TTailleDonneesSortie: *mut size_t) -> c_ushort;
|
||||
}
|
||||
|
||||
fn ssv_init_lib_2() {
|
||||
let ini_str = env::var("SESAM_INI_PATH").expect("SESAM_INI_PATH must be set");
|
||||
let ini = CString::new(ini_str).expect("CString::new failed");
|
||||
unsafe {
|
||||
let result = SSV_InitLIB2(ini.as_ptr());
|
||||
println!("SSV_InitLIB2 result: {}", result);
|
||||
}
|
||||
}
|
||||
|
||||
fn ssv_lire_carte_ps() {
|
||||
let resource_ps = CString::new("PS").expect("CString::new failed");
|
||||
let resource_reader = CString::new("TRANSPA1").expect("CString::new failed");
|
||||
let card_number = CString::new("1234567890").expect("CString::new failed");
|
||||
|
||||
let mut buffer: *mut c_void = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
unsafe {
|
||||
let result = SSV_LireCartePS(
|
||||
resource_ps.as_ptr(),
|
||||
resource_reader.as_ptr(),
|
||||
card_number.as_ptr(),
|
||||
&mut buffer,
|
||||
&mut size
|
||||
);
|
||||
println!("SSV_LireCartePS result: {}", result);
|
||||
|
||||
if !buffer.is_null() {
|
||||
let hex_values = std::slice::from_raw_parts(buffer as *const u8, size);
|
||||
for &byte in hex_values {
|
||||
print!("{:02X} ", byte);
|
||||
}
|
||||
println!();
|
||||
|
||||
libc::free(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn ssv_lire_config() {
|
||||
let mut buffer: *mut c_void = ptr::null_mut();
|
||||
let mut size: size_t = 0;
|
||||
unsafe {
|
||||
let result = SSV_LireConfig(&mut buffer, &mut size);
|
||||
println!("SSV_LireConfig result: {}", result);
|
||||
|
||||
if !buffer.is_null() {
|
||||
let hex_values = std::slice::from_raw_parts(buffer as *const u8, size);
|
||||
for &byte in hex_values {
|
||||
print!("{:02X} ", byte);
|
||||
}
|
||||
println!();
|
||||
|
||||
libc::free(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn demo() {
|
||||
dotenv().ok();
|
||||
|
||||
println!("------- Demo for the SSV library --------");
|
||||
|
||||
ssv_init_lib_2();
|
||||
ssv_lire_carte_ps();
|
||||
ssv_lire_config();
|
||||
|
||||
println!("-----------------------------------------");
|
||||
}
|