diff --git a/src/types/client/fcp_types.rs b/src/types/client/fcp_types.rs index f3409d1..9ad5970 100644 --- a/src/types/client/fcp_types.rs +++ b/src/types/client/fcp_types.rs @@ -97,41 +97,69 @@ pub struct ClientPut { data_length: u64, filename: String, content_type: Option<&'static String>, - identifier: Option, - verbosity: Option, - max_retries: Option, - priority_class: Option, - get_chk_only: Option, - global: Option, - dont_compress: Option, - codecs: Option>, - client_token: Option, - persistence: Option, - target_filename: Option, // TODO create filename type (not PATH, ONLY SLASHES) - early_encode: Option, - upload_ffrom: Option, - target_uri: Option, // cloning uri if does not exists - file_hash: Option, //TODO SHAA256 type - binary_blob: Option, - fork_on_cacheable: Option, - extra_inserts_single_block: Option, - extra_inserts_splitfile_header_block: Option, - compatibility_mode: Option, //TODO create enum??? - local_request_only: Option, - override_splitfile_crypto_key: Option, //key in hex - real_time_flag: Option, - metadata_threshold: Option, - data: Option, // Data fromdirect + identifier: Option<&'static String>, + verbosity: Option<&'static VerbosityPut>, + max_retries: Option<&'static Retry>, + priority_class: Option<&'static Priority>, + get_chk_only: Option<&'static bool>, + global: Option<&'static bool>, + dont_compress: Option<&'static bool>, + codecs: Option<&'static String>, // TODO turn into vec and add implementation + client_token: Option<&'static String>, + persistence: Option<&'static Persistence>, + target_filename: Option<&'static String>, // TODO create filename type (&'static not PATH, ONLY SLASHES) + early_encode: Option<&'static bool>, + upload_ffrom: Option<&'static UploadForm>, + target_uri: Option<&'static String>, // cloning uri if does not exists + file_hash: Option<&'static String>, //TODO SHAA256 type + binary_blob: Option<&'static bool>, + fork_on_cacheable: Option<&'static bool>, + extra_inserts_single_block: Option<&'static u32>, + extra_inserts_splitfile_header_block: Option<&'static u32>, + compatibility_mode: Option<&'static String>, //TODO create enum??? + local_request_only: Option<&'static bool>, + override_splitfile_crypto_key: Option<&'static String>, //key in hex + real_time_flag: Option<&'static String>, + metadata_threshold: Option<&'static i64>, + data: Option<&'static String>, // Data fromdirect } impl FcpRequest for ClientPut { fn convert(&self) -> String { + let content_type = to_fcp_unwrap("ContentType=", self.content_type, "\n"); + let identifier = to_fcp_unwrap("Identifier=", self.identifier, "\n"); + let verbosity = to_fcp_unwrap("=", self.verbosity, "\n"); + let max_retries = to_fcp_unwrap("=", self.max_retries, "\n"); + let priority_class = to_fcp_unwrap("=", self.priority_class, "\n"); + let get_chk_only = to_fcp_unwrap("=", self.get_chk_only, "\n"); + let global = to_fcp_unwrap("=", self.global, "\n"); + let dont_compress = to_fcp_unwrap("=", self.dont_compress, "\n"); + let codecs = to_fcp_unwrap("=", self.codecs, "\n"); + let client_token = to_fcp_unwrap("=", self.client_token, "\n"); + let persistence = to_fcp_unwrap("=", self.persistence, "\n"); + let target_filename = to_fcp_unwrap("=", self.target_filename, "\n"); + let early_encode = to_fcp_unwrap("=", self.early_encode, "\n"); + let upload_ffrom = to_fcp_unwrap("=", self.upload_ffrom, "\n"); + let target_uri = to_fcp_unwrap("=", self.target_uri, "\n"); + let file_hash = to_fcp_unwrap("=", self.file_hash, "\n"); + let binary_blob = to_fcp_unwrap("=", self.binary_blob, "\n"); + let fork_on_cacheable = to_fcp_unwrap("=", self.fork_on_cacheable, "\n"); + let extra_inserts_single_block = to_fcp_unwrap("=", self.extra_inserts_single_block, "\n"); + let extra_inserts_splitfile_header_block = + to_fcp_unwrap("=", self.extra_inserts_splitfile_header_block, "\n"); + let compatibility_mode = to_fcp_unwrap("=", self.compatibility_mode, "\n"); + let local_request_only = to_fcp_unwrap("=", self.local_request_only, "\n"); + let override_splitfile_crypto_key = + to_fcp_unwrap("=", self.override_splitfile_crypto_key, "\n"); + let real_time_flag = to_fcp_unwrap("=", self.real_time_flag, "\n"); + let metadata_threshold = to_fcp_unwrap("=", self.metadata_threshold, "\n"); + let data = to_fcp_unwrap("=", self.data, "\n"); + format!( "ClientPut\n\ {}\ {}\ {}\ {}\ - "/* {}\ {}\ {}\ @@ -158,11 +186,37 @@ impl FcpRequest for ClientPut { {}\ EndMessage\n\ {}\ - ",*/, + ", format!("URI={}\n", self.uri), format!("DataLength={}\n", self.data_length), format!("Filename={}\n", self.filename), - to_fcp_unwrap("ContentType", self.content_type, "\n") + content_type, + identifier, + verbosity, + max_retries, + priority_class, + get_chk_only, + global, + dont_compress, + codecs, + client_token, + persistence, + target_filename, + early_encode, + upload_ffrom, + target_uri, + file_hash, + binary_blob, + fork_on_cacheable, + extra_inserts_single_block, + extra_inserts_splitfile_header_block, + compatibility_mode, + local_request_only, + override_splitfile_crypto_key, + real_time_flag, + metadata_threshold, + data, + // to_fcp_unwrap("Verbosity", self.verbosity, "\n"), ) } } diff --git a/src/types/client/types.rs b/src/types/client/types.rs index c396a8a..87924f8 100644 --- a/src/types/client/types.rs +++ b/src/types/client/types.rs @@ -73,6 +73,15 @@ pub enum Retry { Forever, Num(i32), } +impl FcpRequest for Retry { + fn convert(&self) -> String { + match *self { + Retry::None => "0".to_string(), + Retry::Forever => "-1".to_string(), + Retry::Num(num) => num.to_string(), + } + } +} pub enum Persistence { Connection, @@ -190,6 +199,11 @@ impl FcpRequest for u32 { self.to_string() } } +impl FcpRequest for i64 { + fn convert(&self) -> String { + self.to_string() + } +} impl FcpRequest for String { fn convert(&self) -> String { @@ -220,11 +234,7 @@ pub fn fcp_types_unwrap(fcp_type: Option<&T>) -> String { None => String::from(""), } } -pub fn to_fcp_unwrap( - prefix: &'static str, - fcp_type: Option<&T>, - postfix: &'static str, -) -> String { +pub fn to_fcp_unwrap(prefix: &str, fcp_type: Option<&T>, postfix: &str) -> String { match fcp_type { Some(val) => val.fcp_wrap(&prefix, &postfix), None => String::from(""),