(
db: *mut GraphLiteDB,
username: *const c_char,
error_out: *mut GraphLiteErrorCode,
)
| 139 | /// * Returned string must be freed with `graphlite_free_string` |
| 140 | #[no_mangle] |
| 141 | pub unsafe extern "C" fn graphlite_create_session( |
| 142 | db: *mut GraphLiteDB, |
| 143 | username: *const c_char, |
| 144 | error_out: *mut GraphLiteErrorCode, |
| 145 | ) -> *mut c_char { |
| 146 | let result = panic::catch_unwind(AssertUnwindSafe(|| { |
| 147 | // Check for null pointers |
| 148 | if db.is_null() { |
| 149 | set_error(error_out, GraphLiteErrorCode::NullPointer); |
| 150 | return ptr::null_mut(); |
| 151 | } |
| 152 | if username.is_null() { |
| 153 | set_error(error_out, GraphLiteErrorCode::NullPointer); |
| 154 | return ptr::null_mut(); |
| 155 | } |
| 156 | |
| 157 | let db_ref = unsafe { &*db }; |
| 158 | |
| 159 | // Convert C string to Rust string |
| 160 | let c_str = unsafe { CStr::from_ptr(username) }; |
| 161 | let username_str = match c_str.to_str() { |
| 162 | Ok(s) => s, |
| 163 | Err(_) => { |
| 164 | set_error(error_out, GraphLiteErrorCode::InvalidUtf8); |
| 165 | return ptr::null_mut(); |
| 166 | } |
| 167 | }; |
| 168 | |
| 169 | // Create session |
| 170 | match db_ref.coordinator.create_simple_session(username_str) { |
| 171 | Ok(session_id) => match CString::new(session_id) { |
| 172 | Ok(c_string) => { |
| 173 | set_error(error_out, GraphLiteErrorCode::Success); |
| 174 | c_string.into_raw() |
| 175 | } |
| 176 | Err(_) => { |
| 177 | set_error(error_out, GraphLiteErrorCode::InvalidUtf8); |
| 178 | ptr::null_mut() |
| 179 | } |
| 180 | }, |
| 181 | Err(_) => { |
| 182 | set_error(error_out, GraphLiteErrorCode::SessionError); |
| 183 | ptr::null_mut() |
| 184 | } |
| 185 | } |
| 186 | })); |
| 187 | |
| 188 | match result { |
| 189 | Ok(ptr) => ptr, |
| 190 | Err(_) => { |
| 191 | set_error(error_out, GraphLiteErrorCode::PanicError); |
| 192 | ptr::null_mut() |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | /// Execute a GQL query and return results as JSON |
| 198 | /// |
nothing calls this directly
no test coverage detected