Skip to content

Commit 00bee9a

Browse files
committed
Initial commit
0 parents  commit 00bee9a

File tree

8 files changed

+1403
-0
lines changed

8 files changed

+1403
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
Cargo.lock

COPYING

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "smbc"
3+
version = "0.1.0"
4+
authors = ["Konstantin Gribov <[email protected]>"]
5+
6+
repository = "https://github.com/smbc-rs/smbc"
7+
license = "GPL-3.0+"
8+
keywords = ["smbclient", "samba", "cifs"]
9+
10+
[dependencies]
11+
libc = "^0.2.18"
12+
log = "^0.3.6"
13+
smbclient-sys = "^0.1.0"

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# smbc -- `libsmbclient` wrapper
2+
3+
## About
4+
5+
`smbc` is a type-safe wrapper library for `libsmbclient` from [Samba][samba] project.
6+
7+
It use [`smbclient-sys`][smbclient-sys] crate for bindings to `libsmbclient`.
8+
9+
10+
## License
11+
12+
Licensed under [GNU General Public License][gpl] version 3 or any later version.
13+
It can be found at [COPYING](COPYING) or at [GNU][gpl] site.
14+
15+
16+
[gpl]: https://www.gnu.org/licenses/gpl.txt
17+
[samba]: https://www.samba.org

src/lib.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// smbc is library wrapping libsmbclient from Samba project
2+
// Copyright (c) 2016 Konstantin Gribov
3+
//
4+
// This file is part of smbc.
5+
//
6+
// smbc is free software: you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation, either version 3 of the License, or
9+
// (at your option) any later version.
10+
//
11+
// smbc is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU General Public License
17+
// along with smbc. If not, see <http://www.gnu.org/licenses/>.
18+
19+
//! smbc is wrapper around `libsmbclient` from Samba project
20+
//!
21+
//! It provides basic `std::fs`-like API to access SMB/CIFS file shares
22+
//!
23+
//! Primary entrypoint is [`SmbClient`](struct.SmbClient.html) struct.
24+
//!
25+
//! Files are represented by [`SmbFile`](struct.SmbFile.html).
26+
//!
27+
//! Basic example:
28+
//! ```rust
29+
//! fn load
30+
//! # fn main() {}
31+
//! ```
32+
33+
//#![warn(missing_docs)]
34+
35+
#[macro_use]
36+
extern crate log;
37+
extern crate libc;
38+
39+
#[macro_use]
40+
mod util;
41+
42+
/// Module with smbc's Result and Error coercions
43+
pub mod result;
44+
45+
/// Main API module (reexported later)
46+
pub mod smbc;
47+
48+
pub use result::*;
49+
pub use smbc::*;

src/result.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// smbc is library wrapping libsmbclient from Samba project
2+
// Copyright (c) 2016 Konstantin Gribov
3+
//
4+
// This file is part of smbc.
5+
//
6+
// smbc is free software: you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation, either version 3 of the License, or
9+
// (at your option) any later version.
10+
//
11+
// smbc is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU General Public License
17+
// along with smbc. If not, see <http://www.gnu.org/licenses/>.
18+
19+
use std::error;
20+
use std::ffi;
21+
use std::fmt;
22+
use std::io;
23+
use std::result;
24+
25+
pub type Result<T> = result::Result<T, Error>;
26+
27+
#[derive(Debug)]
28+
pub enum Error {
29+
NewContext(io::Error),
30+
InitContext(io::Error),
31+
AuthCallbackPaniced(Box<error::Error>),
32+
NulInPath(ffi::NulError),
33+
Io(io::Error),
34+
}
35+
36+
impl fmt::Display for Error {
37+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
38+
match *self {
39+
Error::NewContext(ref err) => write!(f, "New context error: {}", err),
40+
Error::InitContext(ref err) => write!(f, "Init context error: {}", err),
41+
Error::Io(ref err) => write!(f, "IO error: {}", err),
42+
Error::NulInPath(ref err) => write!(f, "NUL in path: {}", err),
43+
Error::AuthCallbackPaniced(ref err) => write!(f, "Auth callback paniced last time: {}", err)
44+
}
45+
}
46+
}
47+
48+
impl error::Error for Error {
49+
fn description(&self) -> &str {
50+
match *self {
51+
Error::NewContext(ref err) => err.description(),
52+
Error::InitContext(ref err) => err.description(),
53+
Error::Io(ref err) => err.description(),
54+
Error::NulInPath(ref err) => err.description(),
55+
Error::AuthCallbackPaniced(ref _err) => "panic in auth callback",
56+
}
57+
}
58+
59+
fn cause(&self) -> Option<&error::Error> {
60+
match *self {
61+
Error::NewContext(ref err) => Some(err),
62+
Error::InitContext(ref err) => Some(err),
63+
Error::Io(ref err) => Some(err),
64+
Error::NulInPath(ref err) => Some(err),
65+
Error::AuthCallbackPaniced(ref err) => Some(err.as_ref()),
66+
}
67+
}
68+
}
69+
70+
impl From<io::Error> for Error {
71+
fn from(err: io::Error) -> Self {
72+
Error::Io(err)
73+
}
74+
}
75+
76+
impl From<ffi::NulError> for Error {
77+
fn from(err: ffi::NulError) -> Self {
78+
Error::NulInPath(err)
79+
}
80+
}

0 commit comments

Comments
 (0)