* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#define _GNU_SOURCE
+
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <pcre.h>
-#include "bti_version.h"
#define zalloc(size) calloc(size, 1)
#define dbg(format, arg...) \
do { \
if (debug) \
- printf("%s: " format , __func__ , ## arg); \
+ fprintf(stdout, "bti: %s: " format , __func__ , \
+ ## arg); \
} while (0)
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");
fprintf(stdout, " --host HOST\n");
fprintf(stdout, " --logfile logfile\n");
fprintf(stdout, " --shrink-urls\n");
+ 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)
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)
{
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")) {
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;
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;
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;
}
}
+ /*
+ * Show the version to make it easier to determine what
+ * is going on here
+ */
+ if (debug)
+ display_version();
+
if (session->action == ACTION_UNKNOWN) {
fprintf(stderr, "Unknown action, valid actions are:\n");
fprintf(stderr, "'update', 'friends', 'public', "
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);