]> ToastFreeware Gitweb - gregoa/bti.git/blobdiff - bti.c
bti: use ssl for identi.ca
[gregoa/bti.git] / bti.c
diff --git a/bti.c b/bti.c
index 57286d75ac9967e7b05204da8d995bbae0978851..4cdce35e86fc2c6c78433212c81abc8991e247fc 100644 (file)
--- a/bti.c
+++ b/bti.c
@@ -16,6 +16,8 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
+#define _GNU_SOURCE
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
@@ -35,7 +37,6 @@
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <pcre.h>
-#include "bti_version.h"
 
 
 #define zalloc(size)   calloc(size, 1)
@@ -90,7 +91,7 @@ struct bti_curl_buffer {
 static void display_help(void)
 {
        fprintf(stdout, "bti - send tweet to twitter or identi.ca\n");
-       fprintf(stdout, "Version: " BTI_VERSION "\n");
+       fprintf(stdout, "Version: " VERSION "\n");
        fprintf(stdout, "Usage:\n");
        fprintf(stdout, "  bti [options]\n");
        fprintf(stdout, "options are:\n");
@@ -107,13 +108,14 @@ static void display_help(void)
        fprintf(stdout, "  --page PAGENUMBER\n");
        fprintf(stdout, "  --bash\n");
        fprintf(stdout, "  --debug\n");
+       fprintf(stdout, "  --dry-run\n");
        fprintf(stdout, "  --version\n");
        fprintf(stdout, "  --help\n");
 }
 
 static void display_version(void)
 {
-       fprintf(stdout, "bti - version %s\n", BTI_VERSION);
+       fprintf(stdout, "bti - version %s\n", VERSION);
 }
 
 static struct session *session_alloc(void)
@@ -174,11 +176,11 @@ static const char *twitter_public_url  = "http://twitter.com/statuses/public_tim
 static const char *twitter_friends_url = "https://twitter.com/statuses/friends_timeline.xml";
 static const char *twitter_replies_url = "http://twitter.com/statuses/replies.xml";
 
-static const char *identica_user_url    = "http://identi.ca/api/statuses/user_timeline/";
-static const char *identica_update_url  = "http://identi.ca/api/statuses/update.xml";
-static const char *identica_public_url  = "http://identi.ca/api/statuses/public_timeline.xml";
-static const char *identica_friends_url = "http://identi.ca/api/statuses/friends_timeline.xml";
-static const char *identica_replies_url = "http://identi.ca/api/statuses/replies.xml";
+static const char *identica_user_url    = "https://identi.ca/api/statuses/user_timeline/";
+static const char *identica_update_url  = "https://identi.ca/api/statuses/update.xml";
+static const char *identica_public_url  = "https://identi.ca/api/statuses/public_timeline.xml";
+static const char *identica_friends_url = "https://identi.ca/api/statuses/friends_timeline.xml";
+static const char *identica_replies_url = "https://identi.ca/api/statuses/replies.xml";
 
 static CURL *curl_init(void)
 {
@@ -195,15 +197,18 @@ static CURL *curl_init(void)
        return curl;
 }
 
-void parse_statuses(xmlDocPtr doc, xmlNodePtr current)
+static void parse_statuses(xmlDocPtr doc, xmlNodePtr current)
 {
        xmlChar *text = NULL;
        xmlChar *user = NULL;
+       xmlChar *created = NULL;
        xmlNodePtr userinfo;
 
        current = current->xmlChildrenNode;
        while (current != NULL) {
                if (current->type == XML_ELEMENT_NODE) {
+                       if (!xmlStrcmp(current->name, (const xmlChar *)"created_at"))
+                               created = xmlNodeListGetString(doc, current->xmlChildrenNode, 1);
                        if (!xmlStrcmp(current->name, (const xmlChar *)"text"))
                                text = xmlNodeListGetString(doc, current->xmlChildrenNode, 1);
                        if (!xmlStrcmp(current->name, (const xmlChar *)"user")) {
@@ -217,12 +222,16 @@ void parse_statuses(xmlDocPtr doc, xmlNodePtr current)
                                        userinfo = userinfo->next;
                                }
                        }
-                       if (user && text) {
-                               printf("[%s] %s\n", user, text);
+
+                       if (user && text && created) {
+                               printf("[%s] (%.16s) %s\n",
+                                       user, created, text);
                                xmlFree(user);
                                xmlFree(text);
+                               xmlFree(created);
                                user = NULL;
                                text = NULL;
+                               created = NULL;
                        }
                }
                current = current->next;
@@ -265,7 +274,8 @@ static void parse_timeline(char *document)
        return;
 }
 
-size_t curl_callback(void *buffer, size_t size, size_t nmemb, void *userp)
+static size_t curl_callback(void *buffer, size_t size, size_t nmemb,
+                           void *userp)
 {
        struct bti_curl_buffer *curl_buf = userp;
        size_t buffer_size = size * nmemb;
@@ -966,7 +976,7 @@ int main(int argc, char *argv[], char *envp[])
        parse_configfile(session);
 
        while (1) {
-               option = getopt_long_only(argc, argv, "dqe:p:P:H:a:A:u:hg:",
+               option = getopt_long_only(argc, argv, "dqe:p:P:H:a:A:u:hg:sn",
                                          options, NULL);
                if (option == -1)
                        break;
@@ -1091,7 +1101,7 @@ int main(int argc, char *argv[], char *envp[])
 
                session->tweet = zalloc(strlen(tweet) + 10);
                if (session->bash)
-                       sprintf(session->tweet, "$ %s", tweet);
+                       sprintf(session->tweet, "%c %s", getuid() ? '$' : '#', tweet);
                else
                        sprintf(session->tweet, "%s", tweet);