aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-03-23 14:34:11 -0800
committerDavid M. Syzdek <david@syzdek.net>2022-03-23 14:34:11 -0800
commit0e529c59a3ebb64cb477dc1241ec18a815fcfbda (patch)
treee94d0cc977334a6eee0c9fa654b67a8bb1ca2040 /lib
parent404d9df8d50e692f84de659a2a267b312c282cb2 (diff)
downloadtinyrad-0e529c59a3ebb64cb477dc1241ec18a815fcfbda.tar.gz
tinyrad-0e529c59a3ebb64cb477dc1241ec18a815fcfbda.tar.bz2
tinyrad-0e529c59a3ebb64cb477dc1241ec18a815fcfbda.tar.xz
tinyrad-0e529c59a3ebb64cb477dc1241ec18a815fcfbda.zip
libtinyrad: adding tinyrad_set_flag()
Diffstat (limited to 'lib')
-rw-r--r--lib/libtinyrad/lmemory.c59
-rw-r--r--lib/libtinyrad/lmemory.h13
2 files changed, 55 insertions, 17 deletions
diff --git a/lib/libtinyrad/lmemory.c b/lib/libtinyrad/lmemory.c
index b74d375..8a17dba 100644
--- a/lib/libtinyrad/lmemory.c
+++ b/lib/libtinyrad/lmemory.c
@@ -141,6 +141,37 @@ static atomic_flag tinyrad_rand_init = ATOMIC_FLAG_INIT;
141///////////////// 141/////////////////
142#pragma mark - Functions 142#pragma mark - Functions
143 143
144//-------------------------//
145// miscellaneous functions //
146//-------------------------//
147#pragma mark miscellaneous functions
148
149int
150tinyrad_set_flag(
151 unsigned * optsp,
152 unsigned * opts_negp,
153 unsigned opt,
154 int val )
155{
156 unsigned opts;
157 unsigned opts_neg;
158
159 opts = ((optsp)) ? *optsp : 0;
160 opts |= ((val)) ? opt : 0;
161 opts &= (!(val)) ? ~opt : ~0;
162 opts_neg = ((opts_negp)) ? *opts_negp : 0;
163 opts_neg |= (!(val)) ? opt : 0;
164 opts_neg &= ((val)) ? ~opt : ~0;
165
166 if ((optsp))
167 *optsp = opts;
168 if ((opts_negp))
169 *opts_negp = opts_neg;
170
171 return(TRAD_SUCCESS);
172}
173
174
144//------------------// 175//------------------//
145// random functions // 176// random functions //
146//------------------// 177//------------------//
@@ -705,14 +736,10 @@ tinyrad_set_option(
705 if (tr->s != -1) 736 if (tr->s != -1)
706 return(TRAD_EOPTERR); 737 return(TRAD_EOPTERR);
707 opts = tr->opts; 738 opts = tr->opts;
708 if ((*((const int *)invalue))) 739 tinyrad_set_flag(&tr->opts, &tr->opts_neg, TRAD_IPV4, *((const int *)invalue) );
709 tr->opts |= TRAD_IPV4; 740 if (opts != tr->opts)
710 else 741 if ((rc = tinyrad_urldesc_resolve(tr->trud, tr->opts)) != TRAD_SUCCESS)
711 tr->opts &= ~TRAD_IPV4; 742 return(rc);
712 if (opts == tr->opts)
713 break;
714 if ((rc = tinyrad_urldesc_resolve(tr->trud, tr->opts)) != TRAD_SUCCESS)
715 return(rc);
716 break; 743 break;
717 744
718 case TRAD_OPT_IPV6: 745 case TRAD_OPT_IPV6:
@@ -720,14 +747,10 @@ tinyrad_set_option(
720 if (tr->s != -1) 747 if (tr->s != -1)
721 return(TRAD_EOPTERR); 748 return(TRAD_EOPTERR);
722 opts = tr->opts; 749 opts = tr->opts;
723 if ((*((const int *)invalue))) 750 tinyrad_set_flag(&tr->opts, &tr->opts_neg, TRAD_IPV6, *((const int *)invalue) );
724 tr->opts |= TRAD_IPV6; 751 if (opts != tr->opts)
725 else 752 if ((rc = tinyrad_urldesc_resolve(tr->trud, tr->opts)) != TRAD_SUCCESS)
726 tr->opts &= ~TRAD_IPV6; 753 return(rc);
727 if (opts == tr->opts)
728 break;
729 if ((rc = tinyrad_urldesc_resolve(tr->trud, tr->opts)) != TRAD_SUCCESS)
730 return(rc);
731 break; 754 break;
732 755
733 case TRAD_OPT_NETWORK_TIMEOUT: 756 case TRAD_OPT_NETWORK_TIMEOUT:
@@ -742,9 +765,11 @@ tinyrad_set_option(
742 case TRAD_URANDOM: TinyRadDebug(TRAD_DEBUG_ARGS, " <= invalue: %s", "TRAD_URANDOM"); break; 765 case TRAD_URANDOM: TinyRadDebug(TRAD_DEBUG_ARGS, " <= invalue: %s", "TRAD_URANDOM"); break;
743 default: TinyRadDebug(TRAD_DEBUG_ARGS, " <= invalue: %i", *((const int *)invalue)); break; 766 default: TinyRadDebug(TRAD_DEBUG_ARGS, " <= invalue: %i", *((const int *)invalue)); break;
744 }; 767 };
768 opts = tr->opts;
745 tr->opts &= ~(TRAD_RANDOM_MASK); 769 tr->opts &= ~(TRAD_RANDOM_MASK);
746 tr->opts |= (TRAD_RANDOM_MASK & (*((const int *)invalue))); 770 tr->opts |= (TRAD_RANDOM_MASK & (*((const int *)invalue)));
747 tinyrad_srandom(tr); 771 if (opts != tr->opts)
772 tinyrad_srandom(tr);
748 break; 773 break;
749 774
750 case TRAD_OPT_SCHEME: 775 case TRAD_OPT_SCHEME:
diff --git a/lib/libtinyrad/lmemory.h b/lib/libtinyrad/lmemory.h
index 9979dba..15812e4 100644
--- a/lib/libtinyrad/lmemory.h
+++ b/lib/libtinyrad/lmemory.h
@@ -62,6 +62,19 @@
62////////////////// 62//////////////////
63#pragma mark - Prototypes 63#pragma mark - Prototypes
64 64
65//--------------------------//
66// miscellaneous prototypes //
67//--------------------------//
68#pragma mark miscellaneous prototypes
69
70int
71tinyrad_set_flag(
72 unsigned * optsp,
73 unsigned * opts_negp,
74 unsigned opt,
75 int val );
76
77
65//------------------// 78//------------------//
66// random functions // 79// random functions //
67//------------------// 80//------------------//