New upstream release.
[debian/bti.git] / bti.c
diff --git a/bti.c b/bti.c
index ea464f1d4e3c4ef5f38b17408782c8879464b828..f3fc64c19b3eedc2b470e46ba84cc6b8ebba940e 100644 (file)
--- a/bti.c
+++ b/bti.c
@@ -49,6 +49,7 @@ struct session {
        char *password;
        char *account;
        char *tweet;
+       char *proxy;
        int bash;
        enum host host;
 };
@@ -67,6 +68,7 @@ static void display_help(void)
        fprintf(stdout, "options are:\n");
        fprintf(stdout, "  --account accountname\n");
        fprintf(stdout, "  --password password\n");
+       fprintf(stdout, "  --proxy PROXY:PORT\n");
        fprintf(stdout, "  --host HOST\n");
        fprintf(stdout, "  --bash\n");
        fprintf(stdout, "  --debug\n");
@@ -112,6 +114,7 @@ static void session_free(struct session *session)
        free(session->password);
        free(session->account);
        free(session->tweet);
+       free(session->proxy);
        free(session);
 }
 
@@ -194,6 +197,7 @@ static int send_tweet(struct session *session)
        CURLcode res;
        struct curl_httppost *formpost = NULL;
        struct curl_httppost *lastptr = NULL;
+       struct curl_slist *slist = NULL;
 
        if (!session)
                return -EINVAL;
@@ -220,18 +224,28 @@ static int send_tweet(struct session *session)
        switch (session->host) {
        case HOST_TWITTER:
                curl_easy_setopt(curl, CURLOPT_URL, twitter_url);
+               /*
+                * twitter doesn't like the "Expect: 100-continue" header
+                * anymore, so turn it off.
+                */
+               slist = curl_slist_append(slist, "Expect:");
+               curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
                break;
        case HOST_IDENTICA:
                curl_easy_setopt(curl, CURLOPT_URL, identica_url);
                break;
        }
 
+       if (session->proxy)
+               curl_easy_setopt(curl, CURLOPT_PROXY, session->proxy);
+
        if (debug)
                curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
        curl_easy_setopt(curl, CURLOPT_USERPWD, user_password);
 
        dbg("user_password = %s\n", user_password);
        dbg("data = %s\n", data);
+       dbg("proxy = %s\n", session->proxy);
 
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_callback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, curl_buf);
@@ -255,6 +269,7 @@ static void parse_configfile(struct session *session)
        char *account = NULL;
        char *password = NULL;
        char *host = NULL;
+       char *proxy = NULL;
        char *file;
        char *home = getenv("HOME");
 
@@ -302,6 +317,11 @@ static void parse_configfile(struct session *session)
                        c += 5;
                        if (c[0] != '\0')
                                host = strdup(c);
+               } else if (!strncasecmp(c, "proxy", 5) &&
+                          (c[5] == '=')) {
+                       c += 6;
+                       if (c[0] != '\0')
+                               proxy = strdup(c);
                }
        } while (!feof(config_file));
 
@@ -316,6 +336,8 @@ static void parse_configfile(struct session *session)
                        session->host = HOST_IDENTICA;
                free(host);
        }
+       if (proxy)
+               session->proxy = proxy;
 
        /* Free buffer and close file.  */
        free(line);
@@ -418,7 +440,7 @@ int main(int argc, char *argv[], char *envp[])
        }
 #endif
        tweet = get_string_from_stdin();
-       if (strlen(tweet) == 0) {
+       if (!tweet || strlen(tweet) == 0) {
                dbg("no tweet?\n");
                return -1;
        }