]> ToastFreeware Gitweb - gregoa/bti.git/commitdiff
Merge branch 'master' into gregoa
authorgregor herrmann <gregoa@debian.org>
Sun, 10 Jan 2010 00:44:25 +0000 (01:44 +0100)
committergregor herrmann <gregoa@debian.org>
Sun, 10 Jan 2010 00:44:25 +0000 (01:44 +0100)
ChangeLog
RELEASE-NOTES
bti.c
bti.xml
configure.ac

index 2da39c65d5a2b7c4e5c6c16eb0984d3d40df1fa0..88a68ab4c89cd1297425b649260385090648108f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+Summary of changes from v024 to v025
+============================================
+
+Amir Mohammad Saied (3):
+      If there's no host specified, the session host is already pointing to twitter, but hosturl is empty
+      Removing explicit mentions of twitter
+      Merge remote branch 'gregkh/master'
+
+Greg Kroah-Hartman (1):
+      Remove link-time dependancy on readline
+
+gregor herrmann (1):
+      Name correct hosts in prompts.
+
 Summary of changes from v023 to v024
 ============================================
 
index 74a0698aab01c55bcf6114653dc549922345c551..8d405ce2eef68c3d4f1c64fd8c6a50b5a165158b 100644 (file)
@@ -1,3 +1,8 @@
+bti 025
+=============
+remove readline link-time dependancy to make the distro's lives easier
+bugfixes for minor things by Amir and Gregor
+
 bti 024
 =============
 laconica group support from Marvin Vek
diff --git a/bti.c b/bti.c
index bc83cbaeb1be272dba120e474387d766a84b11e8..285fdfadc7471063a1d6bfd7a2135c47edefb065 100644 (file)
--- a/bti.c
+++ b/bti.c
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <curl/curl.h>
-#include <readline/readline.h>
 #include <libxml/xmlmemory.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <pcre.h>
 #include <termios.h>
+#include <dlfcn.h>
 
 
 #define zalloc(size)   calloc(size, 1)
@@ -88,6 +88,8 @@ struct session {
        int page;
        enum host host;
        enum action action;
+       void *readline_handle;
+       char *(*readline)(const char *);
 };
 
 struct bti_curl_buffer {
@@ -128,6 +130,97 @@ static void display_version(void)
        fprintf(stdout, "bti - version %s\n", VERSION);
 }
 
+static char *get_string(const char *name)
+{
+       char *temp;
+       char *string;
+
+       string = zalloc(1000);
+       if (!string)
+               exit(1);
+       if (name != NULL)
+               fprintf(stdout, "%s", name);
+       if (!fgets(string, 999, stdin))
+               return NULL;
+       temp = strchr(string, '\n');
+       *temp = '\0';
+       return string;
+}
+
+/*
+ * Try to get a handle to a readline function from a variety of different
+ * libraries.  If nothing is present on the system, then fall back to an
+ * internal one.
+ *
+ * Logic originally based off of code in the e2fsutils package in the
+ * lib/ss/get_readline.c file, which is licensed under the MIT license.
+ *
+ * This keeps us from having to relicense the bti codebase if readline
+ * ever changes its license, as there is no link-time dependancy.
+ * It is a run-time thing only, and we handle any readline-like library
+ * in the same manner, making bti not be a derivative work of any
+ * other program.
+ */
+static void session_readline_init(struct session *session)
+{
+       /* Libraries we will try to use for readline/editline functionality */
+       const char *libpath = "libreadline.so.6:libreadline.so.5:"
+                               "libreadline.so.4:libreadline.so:libedit.so.2:"
+                               "libedit.so:libeditline.so.0:libeditline.so";
+       void *handle = NULL;
+       char *tmp, *cp, *next;
+       int (*bind_key)(int, void *);
+       void (*insert)(void);
+
+       /* default to internal function if we can't find anything */
+       session->readline = get_string;
+
+       tmp = malloc(strlen(libpath)+1);
+       if (!tmp)
+               return;
+       strcpy(tmp, libpath);
+       for (cp = tmp; cp; cp = next) {
+               next = strchr(cp, ':');
+               if (next)
+                       *next++ = 0;
+               if (*cp == 0)
+                       continue;
+               if ((handle = dlopen(cp, RTLD_NOW))) {
+                       dbg("Using %s for readline library\n", cp);
+                       break;
+               }
+       }
+       free(tmp);
+       if (!handle) {
+               dbg("No readline library found.\n");
+               return;
+       }
+
+       session->readline_handle = handle;
+       session->readline = (char *(*)(const char *))dlsym(handle, "readline");
+       if (session->readline == NULL) {
+               /* something odd happened, default back to internal stuff */
+               session->readline_handle = NULL;
+               session->readline = get_string;
+               return;
+       }
+
+       /*
+        * If we found a library, turn off filename expansion
+        * as that makes no sense from within bti.
+        */
+       bind_key = (int (*)(int, void *))dlsym(handle, "rl_bind_key");
+       insert = (void (*)(void))dlsym(handle, "rl_insert");
+       if (bind_key && insert)
+               bind_key('\t', insert);
+}
+
+static void session_readline_cleanup(struct session *session)
+{
+       if (session->readline_handle)
+               dlclose(session->readline_handle);
+}
+
 static struct session *session_alloc(void)
 {
        struct session *session;
@@ -135,6 +228,7 @@ static struct session *session_alloc(void)
        session = zalloc(sizeof(*session));
        if (!session)
                return NULL;
+       session_readline_init(session);
        return session;
 }
 
@@ -142,6 +236,7 @@ static void session_free(struct session *session)
 {
        if (!session)
                return;
+       session_readline_cleanup(session);
        free(session->password);
        free(session->account);
        free(session->tweet);
@@ -342,6 +437,9 @@ static int send_request(struct session *session)
        if (!curl)
                return -EINVAL;
 
+       if (!session->hosturl)
+               session->hosturl = strdup(twitter_host);
+
        switch (session->action) {
        case ACTION_UPDATE:
                snprintf(user_password, sizeof(user_password), "%s:%s",
@@ -972,7 +1070,6 @@ int main(int argc, char *argv[], char *envp[])
 
        debug = 0;
        verbose = 0;
-       rl_bind_key('\t', rl_insert);
 
        session = session_alloc();
        if (!session) {
@@ -1127,11 +1224,6 @@ int main(int argc, char *argv[], char *envp[])
                goto exit;
        }
 
-       if (!session->host) {
-               fprintf(stderr, "You need to provide a host either in ~/.bti or with --host.\n");
-               goto exit;
-       }
-
        if (session->host == HOST_TWITTER && session->action == ACTION_GROUP) {
                fprintf(stderr, "Groups only work in Identi.ca.\n");
                goto exit;
@@ -1139,12 +1231,12 @@ int main(int argc, char *argv[], char *envp[])
 
        if (session->action == ACTION_GROUP && !session->group) {
                fprintf(stdout, "Enter group name: ");
-               session->group = readline(NULL);
+               session->group = session->readline(NULL);
        }
 
        if (!session->account) {
                fprintf(stdout, "Enter account for %s: ", session->hostname);
-               session->account = readline(NULL);
+               session->account = session->readline(NULL);
        }
 
        if (!session->password) {
@@ -1156,7 +1248,7 @@ int main(int argc, char *argv[], char *envp[])
                if (session->bash)
                        tweet = get_string_from_stdin();
                else
-                       tweet = readline("tweet: ");
+                       tweet = session->readline("tweet: ");
                if (!tweet || strlen(tweet) == 0) {
                        dbg("no tweet?\n");
                        return -1;
diff --git a/bti.xml b/bti.xml
index 020c48c15e8d8efc445159085ec8e3d239d62027..251f476c054f9434e38a7d0373bf8e17078df378 100644 (file)
--- a/bti.xml
+++ b/bti.xml
         you should specify the API URI. For example identi.ca's URI is:
         https://identi.ca/api/statuses
               </para>
+              <para>
+               If no host is specified, the default is to send to twitter.com.
+              </para>
             </listitem>
           </varlistentry>
           <varlistentry>
index e45785cfbfe2655141f3bc271b62df3f554cca15..6e16ce0ed57038a3305d917fff11ddc782b3f398 100644 (file)
@@ -1,7 +1,7 @@
-AC_INIT([bti], [024], [greg@kroah.com])
+AC_INIT([bti], [025], [greg@kroah.com])
 AC_PREREQ(2.60)
 
-AM_INIT_AUTOMAKE(bti, 024)
+AM_INIT_AUTOMAKE(bti, 025)
 dnl AM_CONFIG_HEADER([check-news foreign 1.9 dist-bzip2])
 
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
@@ -15,8 +15,6 @@ AC_PATH_PROG([XSLTPROC], [xsltproc])
 
 dnl FIXME: Replace `main' with a function in `-lnsl':
 AC_CHECK_LIB([nsl], [main])
-dnl FIXME: Replace `main' with a function in `-lreadline':
-AC_CHECK_LIB([readline], [main])
 
 AC_CHECK_LIB([pcre], [main])