Mercurial > crates > nonstick
comparison src/conv.rs @ 59:3f4a77aa88be
Fix string copyting and improve error situation.
This change is too big and includes several things:
- Fix copying strings from PAM by fixing const and mut on pam funcs.
- Improve error enums by simplifying conversions and removing
unnecessary and ambiguous "success" variants.
- Make a bunch of casts nicer.
- Assorted other cleanup.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Wed, 21 May 2025 00:27:18 -0400 |
parents | daa2cde64601 |
children | 05cc2c27334f |
comparison
equal
deleted
inserted
replaced
58:868a278a362c | 59:3f4a77aa88be |
---|---|
1 use libc::{c_char, c_int}; | 1 use libc::{c_char, c_int}; |
2 use std::ffi::{CStr, CString}; | 2 use std::ffi::{CStr, CString}; |
3 use std::ptr; | 3 use std::ptr; |
4 | 4 |
5 use crate::constants::ErrorCode; | |
5 use crate::constants::MessageStyle; | 6 use crate::constants::MessageStyle; |
6 use crate::constants::PamResult; | 7 use crate::constants::PamResult; |
7 use crate::constants::ErrorCode; | |
8 use crate::items::Item; | 8 use crate::items::Item; |
9 | 9 |
10 #[repr(C)] | 10 #[repr(C)] |
11 struct Message { | 11 struct Message { |
12 msg_style: MessageStyle, | 12 msg_style: MessageStyle, |
58 let msg_cstr = CString::new(msg).unwrap(); | 58 let msg_cstr = CString::new(msg).unwrap(); |
59 let msg = Message { | 59 let msg = Message { |
60 msg_style: style, | 60 msg_style: style, |
61 msg: msg_cstr.as_ptr(), | 61 msg: msg_cstr.as_ptr(), |
62 }; | 62 }; |
63 // TODO: These need to be freed! | |
63 let ret = (self.0.conv)(1, &&msg, &mut resp_ptr, self.0.appdata_ptr); | 64 let ret = (self.0.conv)(1, &&msg, &mut resp_ptr, self.0.appdata_ptr); |
64 ErrorCode::result_from(ret)?; | 65 ErrorCode::result_from(ret)?; |
65 | 66 |
66 let result = unsafe { | 67 let result = unsafe { |
67 match (*resp_ptr).resp { | 68 match (*resp_ptr).resp { |