New upstream release, includes a new --proxy options and honours the
[debian/bti.git] / bti.c
diff --git a/bti.c b/bti.c
index f3fc64c..a06c818 100644 (file)
--- a/bti.c
+++ b/bti.c
@@ -336,8 +336,11 @@ static void parse_configfile(struct session *session)
                        session->host = HOST_IDENTICA;
                free(host);
        }
-       if (proxy)
+       if (proxy) {
+               if (session->proxy)
+                       free(session->proxy);
                session->proxy = proxy;
+       }
 
        /* Free buffer and close file.  */
        free(line);
@@ -351,6 +354,7 @@ int main(int argc, char *argv[], char *envp[])
                { "account", 1, NULL, 'a' },
                { "password", 1, NULL, 'p' },
                { "host", 1, NULL, 'H' },
+               { "proxy", 1, NULL, 'P' },
                { "help", 0, NULL, 'h' },
                { "bash", 0, NULL, 'b' },
                { "version", 0, NULL, 'v' },
@@ -361,6 +365,7 @@ int main(int argc, char *argv[], char *envp[])
        char *tweet;
        int retval;
        int option;
+       char *http_proxy;
 #if 0
        char *home = getenv("HOME");
        char *pwd = getenv("PWD");
@@ -373,10 +378,21 @@ int main(int argc, char *argv[], char *envp[])
        }
 
        curl_global_init(CURL_GLOBAL_ALL);
+
+       /* Set environment variables first, before reading command line options
+        * or config file values. */
+       http_proxy = getenv("http_proxy");
+       if (http_proxy) {
+               if (session->proxy)
+                       free(session->proxy);
+               session->proxy = strdup(http_proxy);
+               dbg("http_proxy = %s\n", session->proxy);
+       }
+
        parse_configfile(session);
 
        while (1) {
-               option = getopt_long_only(argc, argv, "dqe:p:H:a:h",
+               option = getopt_long_only(argc, argv, "dqe:p:P:H:a:h",
                                          options, NULL);
                if (option == -1)
                        break;
@@ -396,6 +412,12 @@ int main(int argc, char *argv[], char *envp[])
                        session->password = strdup(optarg);
                        dbg("password = %s\n", session->password);
                        break;
+               case 'P':
+                       if (session->proxy)
+                               free(session->proxy);
+                       session->proxy = strdup(optarg);
+                       dbg("proxy = %s\n", session->proxy);
+                       break;
                case 'H':
                        if (strcasecmp(optarg, "twitter") == 0)
                                session->host = HOST_TWITTER;