]> ToastFreeware Gitweb - gregoa/bti.git/commitdiff
add identi.ca support to bti
authorGreg Kroah-Hartman <gregkh@suse.de>
Wed, 22 Oct 2008 18:08:09 +0000 (11:08 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Wed, 22 Oct 2008 18:08:09 +0000 (11:08 -0700)
This added a new host option:
--host command line option
host= config file option

Note, identi.ca sends your password in cleartext over the wire, this
probably isn't a good thing overall...

bti.1
bti.c
bti.example
bti.xml

diff --git a/bti.1 b/bti.1
index 54785dda02ca250126ecd081b5d5ecf75a625c36..ce744c8cf208e8527592e48f2210724d30814c8f 100644 (file)
--- a/bti.1
+++ b/bti.1
 .\"     Title: bti
-.\"    Author: 
-.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
+.\"    Author: [see the "AUTHOR" section]
+.\" Generator: DocBook XSL Stylesheets v1.74.0 <http://docbook.sf.net/>
 .\"      Date: May 2008
 .\"    Manual: bti
 .\"    Source: bti
+.\"  Language: English
 .\"
 .TH "BTI" "1" "May 2008" "bti" "bti"
+.\" -----------------------------------------------------------------
+.\" * (re)Define some macros
+.\" -----------------------------------------------------------------
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.\" toupper - uppercase a string (locale-aware)
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.de toupper
+.tr aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ
+\\$*
+.tr aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz
+..
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.\" SH-xref - format a cross-reference to an SH section
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.de SH-xref
+.ie n \{\
+.\}
+.toupper \\$*
+.el \{\
+\\$*
+.\}
+..
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.\" SH - level-one heading that works better for non-TTY output
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.de1 SH
+.\" put an extra blank line of space above the head in non-TTY output
+.if t \{\
+.sp 1
+.\}
+.sp \\n[PD]u
+.nr an-level 1
+.set-an-margin
+.nr an-prevailing-indent \\n[IN]
+.fi
+.in \\n[an-margin]u
+.ti 0
+.HTML-TAG ".NH \\n[an-level]"
+.it 1 an-trap
+.nr an-no-space-flag 1
+.nr an-break-flag 1
+\." make the size of the head bigger
+.ps +3
+.ft B
+.ne (2v + 1u)
+.ie n \{\
+.\" if n (TTY output), use uppercase
+.toupper \\$*
+.\}
+.el \{\
+.nr an-break-flag 0
+.\" if not n (not TTY), use normal case (not uppercase)
+\\$1
+.in \\n[an-margin]u
+.ti 0
+.\" if not n (not TTY), put a border/line under subheading
+.sp -.6
+\l'\n(.lu'
+.\}
+..
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.\" SS - level-two heading that works better for non-TTY output
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.de1 SS
+.sp \\n[PD]u
+.nr an-level 1
+.set-an-margin
+.nr an-prevailing-indent \\n[IN]
+.fi
+.in \\n[IN]u
+.ti \\n[SN]u
+.it 1 an-trap
+.nr an-no-space-flag 1
+.nr an-break-flag 1
+.ps \\n[PS-SS]u
+\." make the size of the head bigger
+.ps +2
+.ft B
+.ne (2v + 1u)
+.if \\n[.$] \&\\$*
+..
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.\" BB/BE - put background/screen (filled box) around block of text
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.de BB
+.if t \{\
+.sp -.5
+.br
+.in +2n
+.ll -2n
+.gcolor red
+.di BX
+.\}
+..
+.de EB
+.if t \{\
+.if "\\$2"adjust-for-leading-newline" \{\
+.sp -1
+.\}
+.br
+.di
+.in
+.ll
+.gcolor
+.nr BW \\n(.lu-\\n(.i
+.nr BH \\n(dn+.5v
+.ne \\n(BHu+.5v
+.ie "\\$2"adjust-for-leading-newline" \{\
+\M[\\$1]\h'1n'\v'+.5v'\D'P \\n(BWu 0 0 \\n(BHu -\\n(BWu 0 0 -\\n(BHu'\M[]
+.\}
+.el \{\
+\M[\\$1]\h'1n'\v'-.5v'\D'P \\n(BWu 0 0 \\n(BHu -\\n(BWu 0 0 -\\n(BHu'\M[]
+.\}
+.in 0
+.sp -.5v
+.nf
+.BX
+.in
+.sp .5v
+.fi
+.\}
+..
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.\" BM/EM - put colored marker in margin next to block of text
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.de BM
+.if t \{\
+.br
+.ll -2n
+.gcolor red
+.di BX
+.\}
+..
+.de EM
+.if t \{\
+.br
+.di
+.ll
+.gcolor
+.nr BH \\n(dn
+.ne \\n(BHu
+\M[\\$1]\D'P -.75n 0 0 \\n(BHu -(\\n[.i]u - \\n(INu - .75n) 0 0 -\\n(BHu'\M[]
+.in 0
+.nf
+.BX
+.in
+.fi
+.\}
+..
+.\" -----------------------------------------------------------------
+.\" * set default formatting
+.\" -----------------------------------------------------------------
 .\" disable hyphenation
 .nh
 .\" disable justification (adjust text to left margin only)
 .ad l
-.SH "NAME"
-bti - send a tweet to twitter.com from the command line
-.SH "SYNOPSIS"
-.HP 4
-\fBbti\fR [\fB\-\-account\ account\fR] [\fB\-\-password\ password\fR] [\fB\-\-bash\fR] [\fB\-\-debug\fR] [\fB\-\-version\fR] [\fB\-\-help\fR]
+.\" -----------------------------------------------------------------
+.\" * MAIN CONTENT STARTS HERE *
+.\" -----------------------------------------------------------------
+.SH "Name"
+bti \- send a tweet to twitter\&.com or identi\&.ca from the command line
+.SH "Synopsis"
+.fam C
+.HP \w'\fBbti\fR\ 'u
+\fBbti\fR [\fB\-\-account\ account\fR] [\fB\-\-password\ password\fR] [\fB\-\-host\ HOST_NAME\fR] [\fB\-\-bash\fR] [\fB\-\-debug\fR] [\fB\-\-version\fR] [\fB\-\-help\fR]
+.fam
 .SH "DESCRIPTION"
 .PP
-bti sends a twitter message to twitter\.com\.
+bti sends a tweet message to twitter\&.com or identi\&.ca\&.
 .SH "OPTIONS"
 .PP
 \fB\-\-account account\fR
 .RS 4
-Specify the twitter\.com account name\.
+Specify the twitter\&.com or identi\&.ca account name\&.
 .RE
 .PP
 \fB\-\-password password\fR
 .RS 4
-Specify the password of your twitter\.com account\.
+Specify the password of your twitter\&.com or identi\&.ca account\&.
+.RE
+.PP
+\fB\-\-host HOST_NAME\fR
+.RS 4
+Specify the host which you want to send your message to\&. Valid options are "twitter" to send to twitter\&.com and "identica" to send to identi\&.ca\&.
+.sp
+If no host is specified, the default is to send to twitter\&.com\&.
 .RE
 .PP
 \fB\-\-debug\fR
 .RS 4
-Print a whole bunch of debugging messages to stdout\.
+Print a whole bunch of debugging messages to stdout\&.
 .RE
 .PP
 \fB\-\-bash\fR
 .RS 4
-Add the working directory and a \'$\' in the twitter message to help specify it is coming from a command line\. Don\'t put the working directory and the \'$\' in the twitter message\.
+Add the working directory and a \'$\' in the tweet message to help specify it is coming from a command line\&. Don\'t put the working directory and the \'$\' in the tweet message\&.
 .sp
-This mode also does not report back any errors that might have happened when sending the message, and it sends it in the background, returning immediately, allowing the process to continue on\.
+This mode also does not report back any errors that might have happened when sending the message, and it sends it in the background, returning immediately, allowing the process to continue on\&.
 .RE
 .PP
 \fB\-\-version\fR
 .RS 4
-Print version number\.
+Print version number\&.
 .RE
 .PP
 \fB\-\-help\fR
 .RS 4
-Print help text\.
+Print help text\&.
 .RE
 .SH "DESCRIPTION"
 .PP
-bti provides an easy way to send twitter messages direct from the command line or any script\. It reads the message on standard input and uses the account and password settings either from the command line options, or from a config file, to send the message out\.
+bti provides an easy way to send tweet messages direct from the command line or any script\&. It reads the message on standard input and uses the account and password settings either from the command line options, or from a config file, to send the message out\&.
 .PP
-It\'s primary focus is to allow you to log everything that you type into a bash shell, in a crazy, "this is what I\'m doing right now!" type of way, letting the world follow along with you constant moving between directories and refreshing your email queue to see if there\'s anything interesting going on\.
+It\'s primary focus is to allow you to log everything that you type into a bash shell, in a crazy, "this is what I\'m doing right now!" type of way, letting the world follow along with you constant moving between directories and refreshing your email queue to see if there\'s anything interesting going on\&.
 .PP
 To hook bti up to your bash shell, export the following variable:
 .PP
 
-PROMPT_COMMAND=\'history 1 | sed \-e "s/^\es*[0\-9]*\es*//" | bti \-\-bash\'
+\FC PROMPT_COMMAND=\'history 1 | sed \-e "s/^\es*[0\-9]*\es*//" | bti \-\-bash\'\F[]
 .PP
 This example assumes that you have the
-\fI~/\.bti\fR
-set up with your account and password information already in it, otherwise you can specify them as an option\.
+\FC~/\&.bti\F[]
+set up with your account and password information already in it, otherwise you can specify them as an option\&.
 .SH "CONFIGURATION"
 .PP
 The account and password can be stored in a configuration file in the users home directory in a file named
-\fI\.bti\fR
+\FC\&.bti\F[]
 The structure of this file is as follows:
 .PP
 \fBaccount\fR
 .RS 4
-The twitter\.com account name you wish to use to send this message with\.
+The twitter\&.com or identi\&.ca account name you wish to use to send this message with\&.
 .RE
 .PP
 \fBpassword\fR
 .RS 4
-The twitter\.com password for the account you wish to use to send this message with\.
+The twitter\&.com or identi\&.ca password for the account you wish to use to send this message with\&.
+.RE
+.PP
+\fBhost\fR
+.RS 4
+The host you want to use to send the message to\&. Valid options are either "twitter" or "identica" to send to twitter\&.com or identi\&.ca respectively\&.
 .RE
 .PP
 There is an example config file called
-\fIbti\.example\fR
-in the source tree that shows the structure of the file if you need an example to work off of\.
+\FCbti\&.example\F[]
+in the source tree that shows the structure of the file if you need an example to work off of\&.
 .SH "AUTHOR"
 .PP
 Written by Greg Kroah\-Hartman
-<greg@kroah\.com>\.
+\FCgreg@kroah\&.com\F[]\&.
diff --git a/bti.c b/bti.c
index c9b48803260707c9f04601eb1083e859dc90a963..ea464f1d4e3c4ef5f38b17408782c8879464b828 100644 (file)
--- a/bti.c
+++ b/bti.c
 
 static int debug = 0;
 
+enum host {
+       HOST_TWITTER = 0,
+       HOST_IDENTICA = 1,
+};
+
 struct session {
        char *password;
        char *account;
        char *tweet;
        int bash;
+       enum host host;
 };
 
 struct bti_curl_buffer {
@@ -61,6 +67,7 @@ static void display_help(void)
        fprintf(stdout, "options are:\n");
        fprintf(stdout, "  --account accountname\n");
        fprintf(stdout, "  --password password\n");
+       fprintf(stdout, "  --host HOST\n");
        fprintf(stdout, "  --bash\n");
        fprintf(stdout, "  --debug\n");
        fprintf(stdout, "  --version\n");
@@ -136,6 +143,7 @@ static void bti_curl_buffer_free(struct bti_curl_buffer *buffer)
 }
 
 static const char *twitter_url = "https://twitter.com/statuses/update.xml";
+static const char *identica_url = "http://identi.ca/api/statuses/update.xml";
 
 static CURL *curl_init(void)
 {
@@ -208,7 +216,16 @@ static int send_tweet(struct session *session)
                     CURLFORM_END);
 
        curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
-       curl_easy_setopt(curl, CURLOPT_URL, twitter_url);
+
+       switch (session->host) {
+       case HOST_TWITTER:
+               curl_easy_setopt(curl, CURLOPT_URL, twitter_url);
+               break;
+       case HOST_IDENTICA:
+               curl_easy_setopt(curl, CURLOPT_URL, identica_url);
+               break;
+       }
+
        if (debug)
                curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
        curl_easy_setopt(curl, CURLOPT_USERPWD, user_password);
@@ -237,6 +254,7 @@ static void parse_configfile(struct session *session)
        size_t len = 0;
        char *account = NULL;
        char *password = NULL;
+       char *host = NULL;
        char *file;
        char *home = getenv("HOME");
 
@@ -279,13 +297,25 @@ static void parse_configfile(struct session *session)
                        c += 9;
                        if (c[0] != '\0')
                                password = strdup(c);
+               } else if (!strncasecmp(c, "host", 4) &&
+                          (c[4] == '=')) {
+                       c += 5;
+                       if (c[0] != '\0')
+                               host = strdup(c);
                }
        } while (!feof(config_file));
 
        if (password)
                session->password = password;
        if (account)
-               session->account= account;
+               session->account = account;
+       if (host) {
+               if (strcasecmp(host, "twitter") == 0)
+                       session->host = HOST_TWITTER;
+               if (strcasecmp(host, "identica") == 0)
+                       session->host = HOST_IDENTICA;
+               free(host);
+       }
 
        /* Free buffer and close file.  */
        free(line);
@@ -298,6 +328,7 @@ int main(int argc, char *argv[], char *envp[])
                { "debug", 0, NULL, 'd' },
                { "account", 1, NULL, 'a' },
                { "password", 1, NULL, 'p' },
+               { "host", 1, NULL, 'H' },
                { "help", 0, NULL, 'h' },
                { "bash", 0, NULL, 'b' },
                { "version", 0, NULL, 'v' },
@@ -323,7 +354,7 @@ int main(int argc, char *argv[], char *envp[])
        parse_configfile(session);
 
        while (1) {
-               option = getopt_long_only(argc, argv, "dqe:p:a:h",
+               option = getopt_long_only(argc, argv, "dqe:p:H:a:h",
                                          options, NULL);
                if (option == -1)
                        break;
@@ -343,6 +374,13 @@ int main(int argc, char *argv[], char *envp[])
                        session->password = strdup(optarg);
                        dbg("password = %s\n", session->password);
                        break;
+               case 'H':
+                       if (strcasecmp(optarg, "twitter") == 0)
+                               session->host = HOST_TWITTER;
+                       if (strcasecmp(optarg, "identica") == 0)
+                               session->host = HOST_IDENTICA;
+                       dbg("host = %d\n", session->host);
+                       break;
                case 'b':
                        session->bash= 1;
                        break;
@@ -400,6 +438,7 @@ int main(int argc, char *argv[], char *envp[])
        dbg("account = %s\n", session->account);
        dbg("password = %s\n", session->password);
        dbg("tweet = %s\n", session->tweet);
+       dbg("host = %d\n", session->host);
 
        /* fork ourself so that the main shell can get on
         * with it's life as we try to connect and handle everything
index 9f0effc91eab85e38a6c81c948f6e23dbbfb78a0..15ea6b26cfb99f25d83d221a5889939661634869 100644 (file)
@@ -5,3 +5,4 @@
 # a message.
 account=twitmaster
 password=icanhascheezburger
+host=identica
diff --git a/bti.xml b/bti.xml
index f08a7cdf9347857ed819dec1f2120cfe823777e4..0d7767e956316196cf99d07d95b99120a554e1e0 100644 (file)
--- a/bti.xml
+++ b/bti.xml
@@ -20,7 +20,7 @@
 
       <refnamediv>
         <refname>bti</refname>
-        <refpurpose>send a tweet to twitter.com from the command line</refpurpose>
+        <refpurpose>send a tweet to twitter.com or identi.ca from the command line</refpurpose>
       </refnamediv>
 
       <refsynopsisdiv>
@@ -28,6 +28,7 @@
           <command>bti</command>
           <arg><option>--account account</option></arg>
           <arg><option>--password password</option></arg>
+          <arg><option>--host HOST_NAME</option></arg>
           <arg><option>--bash</option></arg>
           <arg><option>--debug</option></arg>
           <arg><option>--version</option></arg>
@@ -36,7 +37,7 @@
       </refsynopsisdiv>
 
       <refsect1><title>DESCRIPTION</title>
-        <para>bti sends a twitter message to twitter.com.
+        <para>bti sends a tweet message to twitter.com or identi.ca.
         </para>
       </refsect1>
 
@@ -46,7 +47,7 @@
             <term><option>--account account</option></term>
             <listitem>
               <para>
-               Specify the twitter.com account name.
+               Specify the twitter.com or identi.ca account name.
              </para>
             </listitem>
           </varlistentry>
             <term><option>--password password</option></term>
             <listitem>
               <para>
-                Specify the password of your twitter.com account.
+                Specify the password of your twitter.com or identi.ca account.
+              </para>
+            </listitem>
+          </varlistentry>
+          <varlistentry>
+            <term><option>--host HOST_NAME</option></term>
+            <listitem>
+              <para>
+               Specify the host which you want to send your message to.  Valid
+               options are "twitter" to send to twitter.com and "identica" to
+               send to identi.ca.
+              </para>
+              <para>
+               If no host is specified, the default is to send to twitter.com.
               </para>
             </listitem>
           </varlistentry>
@@ -68,9 +82,9 @@
             <term><option>--bash</option></term>
             <listitem>
               <para>
-                Add the working directory and a '$' in the twitter message to
+                Add the working directory and a '$' in the tweet message to
                 help specify it is coming from a command line.  Don't put the
-                working directory and the '$' in the twitter message.
+                working directory and the '$' in the tweet message.
              </para>
              <para>
                 This mode also does not report back any errors that might have
       <refsect1>
         <title>DESCRIPTION</title>
         <para>
-          bti provides an easy way to send twitter messages direct from the
+          bti provides an easy way to send tweet messages direct from the
           command line or any script.  It reads the message on standard
           input and uses the account and password settings either from the
           command line options, or from a config file, to send the message
              <term><option>account</option></term>
              <listitem>
                <para>
-                 The twitter.com account name you wish to use to send this
+                 The twitter.com or identi.ca account name you wish to use to send this
                  message with.
                </para>
              </listitem>
              <term><option>password</option></term>
              <listitem>
                <para>
-                 The twitter.com password for the account you wish to use
+                 The twitter.com or identi.ca password for the account you wish to use
                  to send this message with.
                </para>
              </listitem>
            </varlistentry>
+           <varlistentry>
+             <term><option>host</option></term>
+             <listitem>
+               <para>
+                The host you want to use to send the message to.  Valid
+                options are either "twitter" or "identica" to send to
+                twitter.com or identi.ca respectively.
+               </para>
+             </listitem>
+           </varlistentry>
          </variablelist>
          <para>
            There is an example config file called