Compare commits
	
		
			8 Commits
		
	
	
		
			a3fef1c38c
			...
			wip-debug-
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 571da52888 | |||
| 
						
						
							
						
						c462442221
	
				 | 
					
					
						|||
| 27d63f467c | |||
| 078523ebad | |||
| 
						
						
							
						
						ec1e147e91
	
				 | 
					
					
						|||
| 
						
						
							
						
						9c1e06915e
	
				 | 
					
					
						|||
| 
						
						
							
						
						7a22503bac
	
				 | 
					
					
						|||
| 
						
						
							
						
						5645f6ab71
	
				 | 
					
					
						
							
								
								
									
										3
									
								
								.env.build.linux.example
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.env.build.linux.example
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					SESAM_FSV_VERSION=1.40.13
 | 
				
			||||||
 | 
					SESAM_FSV_LIB_PATH=/opt/santesocial/fsv/${SESAM_FSV_VERSION}/lib
 | 
				
			||||||
 | 
					SESAM_FSV_SSVLIB=ssvlux64
 | 
				
			||||||
							
								
								
									
										3
									
								
								.env.build.win.example
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.env.build.win.example
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					SESAM_FSV_VERSION=1.40.13
 | 
				
			||||||
 | 
					SESAM_FSV_LIB_PATH="C:/Program Files/santesocial/fsv/${SESAM_FSV_VERSION}/lib"
 | 
				
			||||||
 | 
					SESAM_FSV_SSVLIB=ssvw64
 | 
				
			||||||
							
								
								
									
										2
									
								
								.env.linux.example
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.env.linux.example
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					SESAM_FSV_VERSION=1.40.13
 | 
				
			||||||
 | 
					SESAM_INI_PATH=/etc/opt/santesocial/fsv/${SESAM_FSV_VERSION}/conf/sesam.ini
 | 
				
			||||||
							
								
								
									
										2
									
								
								.env.win.example
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.env.win.example
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					SESAM_FSV_VERSION=1.40.13
 | 
				
			||||||
 | 
					SESAM_INI_PATH=${ALLUSERSPROFILE}\\santesocial\\fsv\\${SESAM_FSV_VERSION}\\conf\\sesam.ini
 | 
				
			||||||
							
								
								
									
										20
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										20
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,16 +1,6 @@
 | 
				
			|||||||
# ---> Rust
 | 
					# Ignore Rust target directory
 | 
				
			||||||
# Generated by Cargo
 | 
					/target
 | 
				
			||||||
# will have compiled files and executables
 | 
					 | 
				
			||||||
debug/
 | 
					 | 
				
			||||||
target/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
 | 
					 | 
				
			||||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
 | 
					 | 
				
			||||||
Cargo.lock
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# These are backup files generated by rustfmt
 | 
					 | 
				
			||||||
**/*.rs.bk
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# MSVC Windows builds of rustc generate these, which store debugging information
 | 
					 | 
				
			||||||
*.pdb
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Ignore .env files
 | 
				
			||||||
 | 
					.env
 | 
				
			||||||
 | 
					.env.build
 | 
				
			||||||
							
								
								
									
										23
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					# This file is automatically @generated by Cargo.
 | 
				
			||||||
 | 
					# It is not intended for manual editing.
 | 
				
			||||||
 | 
					version = 3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[package]]
 | 
				
			||||||
 | 
					name = "dotenv"
 | 
				
			||||||
 | 
					version = "0.15.0"
 | 
				
			||||||
 | 
					source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
				
			||||||
 | 
					checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[package]]
 | 
				
			||||||
 | 
					name = "libc"
 | 
				
			||||||
 | 
					version = "0.2.155"
 | 
				
			||||||
 | 
					source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
				
			||||||
 | 
					checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[package]]
 | 
				
			||||||
 | 
					name = "utils-debug-c-lib"
 | 
				
			||||||
 | 
					version = "0.1.0"
 | 
				
			||||||
 | 
					dependencies = [
 | 
				
			||||||
 | 
					 "dotenv",
 | 
				
			||||||
 | 
					 "libc",
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
							
								
								
									
										12
									
								
								Cargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Cargo.toml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					[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"
 | 
				
			||||||
							
								
								
									
										47
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								README.md
									
									
									
									
									
								
							@@ -1,3 +1,46 @@
 | 
				
			|||||||
# Krys4lide
 | 
					## Requirements
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Logiciel de pharmacie
 | 
					- 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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Compilation C
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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`
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										26
									
								
								build.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								build.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					extern crate dotenv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use std::env;
 | 
				
			||||||
 | 
					use std::path::PathBuf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn main() {
 | 
				
			||||||
 | 
					    dotenv::from_filename(".env.build").ok();
 | 
				
			||||||
 | 
					    println!("cargo::rerun-if-changed=.env.build");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let static_lib_path = PathBuf::from(manifest_dir).join("lib");
 | 
				
			||||||
 | 
					    println!("cargo::rustc-link-search=native={}", static_lib_path.display());
 | 
				
			||||||
 | 
					    println!("cargo::rustc-link-lib=static=p4pillondebuglib");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    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());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    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());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								lib/libp4pillondebuglib.a
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/libp4pillondebuglib.a
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/p4pillondebuglib.lib
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/p4pillondebuglib.lib
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/p4pillondebuglib.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/p4pillondebuglib.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/p4pillondebuglib.obj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/p4pillondebuglib.obj
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/ssvw64.exp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/ssvw64.exp
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/ssvw64.lib
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/ssvw64.lib
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										36
									
								
								make.bat
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								make.bat
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
				
			|||||||
 | 
					@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
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								makefile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
				
			|||||||
 | 
					# 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
 | 
				
			||||||
							
								
								
									
										7
									
								
								src/main.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/main.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					mod p4pillondebuglib_demo;
 | 
				
			||||||
 | 
					mod ssvlib_demo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn main() {
 | 
				
			||||||
 | 
					    p4pillondebuglib_demo::demo();
 | 
				
			||||||
 | 
					    ssvlib_demo::demo();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										57
									
								
								src/p4pillondebuglib.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								src/p4pillondebuglib.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,57 @@
 | 
				
			|||||||
 | 
					// 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);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										15
									
								
								src/p4pillondebuglib.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/p4pillondebuglib.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					#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
 | 
				
			||||||
							
								
								
									
										101
									
								
								src/p4pillondebuglib_demo.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										101
									
								
								src/p4pillondebuglib_demo.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,101 @@
 | 
				
			|||||||
 | 
					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!("-----------------------------------------");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										84
									
								
								src/ssvlib_demo.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								src/ssvlib_demo.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,84 @@
 | 
				
			|||||||
 | 
					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!("-----------------------------------------");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										5
									
								
								src/ssvw64.def
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/ssvw64.def
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					LIBRARY "ssvw64"
 | 
				
			||||||
 | 
					EXPORTS
 | 
				
			||||||
 | 
					    SSV_InitLIB2
 | 
				
			||||||
 | 
					    SSV_LireCartePS
 | 
				
			||||||
 | 
					    SSV_LireConfig
 | 
				
			||||||
		Reference in New Issue
	
	Block a user