chiark / gitweb /
config: allow `special` to override, and set global for ipif
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Aug 2021 21:15:32 +0000 (22:15 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Aug 2021 21:15:32 +0000 (22:15 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
macros/macros.rs
src/bin/server.rs
src/config.rs
src/ini.rs
src/prelude.rs

index 771448e2113d67c9ec543c26d4eb516a8b62d63d..43efcf6cc5174c95a662d204f1a57a123799004a 100644 (file)
@@ -7,6 +7,8 @@ use syn::{Data, DataStruct, DeriveInput, LitStr, Meta, NestedMeta};
 use quote::{quote, quote_spanned, ToTokens};
 use proc_macro2::{Literal, TokenStream};
 
+use std::cell::RefCell;
+
 use itertools::Itertools;
 
 /// Generates config resolver method
@@ -64,11 +66,12 @@ pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
     //dbg!(field);
     let fname = &field.ident.as_ref().unwrap();
     let fname_span = fname.span();
-    let mut skl = None;
-    let mut set_skl = |new| {
-      if let Some(old) = &skl { panic!("dup SKL {} and {} for field {}",
-                                       old, new, &fname); }
-      skl = Some(new);
+    let skl = RefCell::new(None);
+    let set_skl = |new| {
+      let mut skl = skl.borrow_mut();
+      if let Some(old) = &*skl { panic!("dup SKL {} and {} for field {}",
+                                        old, new, &fname); }
+      *skl = Some(new);
     };
     let mut method = quote_spanned!{fname_span=> ordinary };
     for attr in &field.attrs {
@@ -102,12 +105,13 @@ pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
           }
         }
         method = get_path(tmethod);
-        set_skl(get_path(tskl));
+        *skl.borrow_mut() = Some(get_path(tskl));
       }
     }
     let fname_string = fname.to_string();
     let fname_lit = Literal::string( &fname_string );
-    let skl = skl.expect(&format!("SKL not specified! (field {})!", fname));
+    let skl = skl.into_inner()
+      .expect(&format!("SKL not specified! (field {})!", fname));
 
     names.push(quote!{
       (#fname_lit, #skl),
index 20da0ddcfb08da6a367ec0c1003f149419c93830..72fc2dc7830cd03c13abacaf429282e6887b0ed5 100644 (file)
@@ -19,5 +19,7 @@ async fn main() {
   let ics = config::startup("hippotatd", LinkEnd::Server,
                             &opts.config, &opts.log);
 
+  
+
   dbg!(ics);
 }
index bfb345e41dceb988a2588d193cd69aac7246ee11..98e5a1e940f2182cf6bd9f1501f3e450c2eacb71 100644 (file)
@@ -10,7 +10,7 @@ pub struct InstanceConfig {
   // Exceptional settings
   #[special(special_link, SKL::None)]      pub    link:   LinkName,
   #[per_client]                            pub    secret: Secret,
-  #[special(special_ipif, SKL::PerClient)] pub    ipif:   String,
+  #[global] #[special(special_ipif, SKL::PerClient)] pub ipif: String,
 
   // Capped settings:
   #[limited]    pub max_batch_down:               u32,
index 294bea3da9c6134394783091c84f4316e09edae2..20c35342182f43b9d6af8c609f4ba9494cc1ff64 100644 (file)
@@ -4,7 +4,6 @@
 
 use crate::prelude::*;
 
-use std::cell::{RefCell, RefMut};
 use std::io::BufRead;
 use std::rc::Rc;
 
index 5e4261d0407c5e88f405f96006a88122b5f440de..1acbafd14236dc89badfba691adb1e5e31348f9a 100644 (file)
@@ -6,6 +6,7 @@ pub use std::array;
 pub use std::collections::{BTreeSet, HashMap, VecDeque};
 pub use std::convert::{TryFrom, TryInto};
 pub use std::borrow::Cow;
+pub use std::cell::{RefCell, RefMut};
 pub use std::cmp::{min, max};
 pub use std::fs;
 pub use std::fmt::{self, Debug, Display, Write as _};