summaryrefslogtreecommitdiff
path: root/src/ar_options_struct.c
diff options
context:
space:
mode:
authorJakub Sławiński2005-08-05 21:45:31 +0200
committerJoshua Judson Rosen2014-07-17 21:14:59 +0200
commit43e8714797d40bcf63efab428dcd25f9caf1d52b (patch)
tree796974a873a97f2a44f872f3dd3587508e35aa64 /src/ar_options_struct.c
parentv0.7.1 (diff)
downloadapf-43e8714797d40bcf63efab428dcd25f9caf1d52b.tar.gz
v0.7.2
- Added: http proxy basic authorization - Fixed: logging initialization after some value checking - Fixed: auto-reconnect failure when --nossl option is set - Added: auto-reconnect when afserver is not reachable on start - Added: auto-reconnect after normal afserver quit - Added: per user statistics: idle time, amount of downloaded/uploaded bytes and current download/upload rate - Added: support for https proxies - Added: possibility to bind sockets on different interfaces - Fixed: receiving incomplete headers from afclient - Fixed: close user connections by afclient
Diffstat (limited to 'src/ar_options_struct.c')
-rw-r--r--src/ar_options_struct.c296
1 files changed, 296 insertions, 0 deletions
diff --git a/src/ar_options_struct.c b/src/ar_options_struct.c
new file mode 100644
index 0000000..0d95dfc
--- /dev/null
+++ b/src/ar_options_struct.c
@@ -0,0 +1,296 @@
+/*
+ * active port forwarder - software for secure forwarding
+ * Copyright (C) 2003,2004,2005 jeremian <jeremian [at] poczta.fm>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "ar_options_struct.h"
+#include "string_functions.h"
+#include "server_check.h"
+
+/*
+ * Function name: ArOptions_new
+ * Description: Create and initialize new ArOptions structure.
+ * Returns: Pointer to newly created ArOptions structure.
+ */
+
+ArOptions*
+ArOptions_new()
+{
+ ArOptions* tmp = calloc(1, sizeof(ArOptions));
+ if (tmp == NULL) {
+ return NULL;
+ }
+ tmp->premature = AR_OPTION_ENABLED;
+ tmp->delay = 5;
+ tmp->tries = -1;
+ return tmp;
+}
+
+/*
+ * Function name: ArOptions_free
+ * Description: Free the memory allocated for ArOptions structure.
+ * Arguments: ao - pointer to pointer to ArOptions structure
+ */
+
+void
+ArOptions_free(ArOptions** ao)
+{
+ if (ao == NULL) {
+ return;
+ }
+ if ((*ao) == NULL) {
+ return;
+ }
+ if ((*ao)->artries) {
+ free((*ao)->artries);
+ (*ao)->artries = NULL;
+ }
+ if ((*ao)->ardelay) {
+ free((*ao)->ardelay);
+ (*ao)->ardelay = NULL;
+ }
+ free((*ao));
+ (*ao) = NULL;
+}
+
+/*
+ * Function name: ArOptions_set_asTries
+ * Description: Set how many times afclient will try to reconnect.
+ * Arguments: ao - pointer to ArOptions structure
+ * tries - how many times afclient will try to reconnect
+ * <0 - unlimited
+ * 0 - disabled
+ * >0 - exact number
+ */
+
+void
+ArOptions_set_arTries(ArOptions* ao, int tries)
+{
+ if (ao == NULL) {
+ return;
+ }
+ ao->tries = tries;
+}
+
+/*
+ * Function name: ArOptions_set_s_arTries
+ * Description: Set string describing how many times afclient will try to reconnect.
+ * This string has to be evaluated later in order to really set arTries value.
+ * Arguments: ao - pointer to ArOptions structure
+ * tries - string describing how many times afclient will try to reconnect.
+ */
+
+void
+ArOptions_set_s_arTries(ArOptions* ao, char* tries)
+{
+ if (ao == NULL) {
+ return;
+ }
+ string_cp(&(ao->artries), tries);
+}
+
+/*
+ * Function name: ArOptions_set_arDelay
+ * Description: Set how long afclient will wait between reconnect tries.
+ * Arguments: ao - pointer to ArOptions structure
+ * delay - how long afclient will wait between reconnect tries
+ */
+
+void
+ArOptions_set_arDelay(ArOptions* ao, int delay)
+{
+ if (ao == NULL) {
+ return;
+ }
+ ao->delay = delay;
+}
+
+/*
+ * Function name: ArOptions_set_s_arDelay
+ * Description: Set string describing how long afclient will wait between reconnect tries.
+ * This string has to be evaluated later in order to really set arDelay value.
+ * Arguments: ao - pointer to ArOptions structure
+ * delay - string describing how long afclient will wait between reconnect tries.
+ */
+
+void
+ArOptions_set_s_arDelay(ArOptions* ao, char* delay)
+{
+ if (ao == NULL) {
+ return;
+ }
+ string_cp(&(ao->ardelay), delay);
+}
+
+/*
+ * Function name: ArOptions_set_arStart
+ * Description: Enable/disable auto-reconnection when afserver is not reachable on start.
+ * Arguments: ao - pointer to ArOptions structure
+ * start - value which enable (AR_OPTION_ENABLED) or disable (AR_OPTION_DISABLED)
+ * auto-reconnection when afserver is not reachable on start
+ */
+
+void
+ArOptions_set_arStart(ArOptions* ao, char start)
+{
+ if (ao == NULL) {
+ return;
+ }
+ ao->start = start;
+}
+
+/*
+ * Function name: ArOptions_set_arQuit
+ * Description: Enable/disable auto-reconnection after normal afserver quit.
+ * Arguments: ao - pointer to ArOptions structure
+ * quit - value which enable (AR_OPTION_ENABLED) or disable (AR_OPTION_DISABLED)
+ * auto-reconnection after normal afserver quit
+ */
+
+void
+ArOptions_set_arQuit(ArOptions* ao, char quit)
+{
+ if (ao == NULL) {
+ return;
+ }
+ ao->quit = quit;
+}
+
+/*
+ * Function name: ArOptions_set_arPremature
+ * Description: Enable/disable auto-reconnection after premature afserver quit.
+ * Arguments: ao - pointer to ArOptions structure
+ * premature - value which enable (AR_OPTION_ENABLED) or disable (AR_OPTION_DISABLED)
+ * auto-reconnection after premature afserver quit
+ */
+
+void
+ArOptions_set_arPremature(ArOptions* ao, char premature)
+{
+ if (ao == NULL) {
+ return;
+ }
+ ao->premature = premature;
+}
+
+/*
+ * Function name: ArOptions_get_arTries
+ * Description: Get how many times afclient will try to reconnect.
+ * Arguments: ao - pointer to ArOptions structure
+ * Returns: How many times afclient will try to reconnect.
+ */
+
+int
+ArOptions_get_arTries(ArOptions* ao)
+{
+ if (ao == NULL) {
+ return 0;
+ }
+ return ao->tries;
+}
+
+/*
+ * Function name: ArOptions_get_arDelay
+ * Description: Get how long afclient will wait between reconnect tries.
+ * Arguments: ao - pointer to ArOptions structure
+ * Returns: How long afclient will wait between reconnect time.
+ */
+
+int
+ArOptions_get_arDelay(ArOptions* ao)
+{
+ if (ao == NULL) {
+ return 0;
+ }
+ return ao->delay;
+}
+
+/*
+ * Function name: ArOptions_get_arStart
+ * Description: Get status of the auto-reconnection when afserver is not reachable on start.
+ * Arguments: ao - pointer to ArOptions structure
+ * Returns: Status of the auto-reconnection when afserver is not reachable on start.
+ */
+
+char
+ArOptions_get_arStart(ArOptions* ao)
+{
+ if (ao == NULL) {
+ return AR_OPTION_DISABLED;
+ }
+ return ao->start;
+}
+
+/*
+ * Function name: ArOptions_get_arQuit
+ * Description: Get status of the auto-reconnection after normal afserver quit.
+ * Arguments: ao - pointer to ArOptions structure
+ * Returns: Status of the auto-reconnection after normal afserver quit.
+ */
+
+char
+ArOptions_get_arQuit(ArOptions* ao)
+{
+ if (ao == NULL) {
+ return AR_OPTION_DISABLED;
+ }
+ return ao->quit;
+}
+
+/*
+ * Function name: ArOptions_get_arPremature
+ * Description: Get status of the auto-reconnection after premature afserver quit.
+ * Arguments: ao - pointer to ArOptions structure
+ * Returns: Status of the auto-reconnection after premature afserver quit.
+ */
+
+char
+ArOptions_get_arPremature(ArOptions* ao)
+{
+ if (ao == NULL) {
+ return AR_OPTION_DISABLED;
+ }
+ return ao->premature;
+}
+
+/*
+ * Function name: ArOptions_evaluate_values
+ * Description: Evaluate arTries and arDelay values. These values are checked, when are not NULL.
+ * arTries have to be an integer, arDelay have to be an integer >0. If any of the
+ * variables is wrong, program terminates abnormally.
+ * Arguments: ao - pointer to ArOptions structure
+ */
+
+void
+ArOptions_evaluate_values(ArOptions* ao)
+{
+ if (ao == NULL) {
+ return;
+ }
+ if (ao->artries) {
+ ao->tries = check_value_liberal(ao->artries, "Invalid ar-tries value");
+ }
+ if (ao->ardelay) {
+ check_value(&(ao->delay), ao->ardelay, "Invalid ar-delay value");
+ }
+}