2 * Copyright (C) 2008 Greg Kroah-Hartman <greg@kroah.com>
3 * Copyright (C) 2009 Bart Trojanowski <bart@jukie.net>
4 * Copyright (C) 2009 Amir Mohammad Saied <amirsaied@gmail.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
33 #include <sys/types.h>
35 #include <curl/curl.h>
36 #include <readline/readline.h>
37 #include <libxml/xmlmemory.h>
38 #include <libxml/parser.h>
39 #include <libxml/tree.h>
44 #define zalloc(size) calloc(size, 1)
46 #define dbg(format, arg...) \
49 fprintf(stdout, "bti: %s: " format , __func__ , \
93 struct bti_curl_buffer {
99 static void display_help(void)
101 fprintf(stdout, "bti - send tweet to twitter or identi.ca\n");
102 fprintf(stdout, "Version: " VERSION "\n");
103 fprintf(stdout, "Usage:\n");
104 fprintf(stdout, " bti [options]\n");
105 fprintf(stdout, "options are:\n");
106 fprintf(stdout, " --account accountname\n");
107 fprintf(stdout, " --password password\n");
108 fprintf(stdout, " --action action\n");
109 fprintf(stdout, " ('update', 'friends', 'public', 'replies', "
110 "'group' or 'user')\n");
111 fprintf(stdout, " --user screenname\n");
112 fprintf(stdout, " --group groupname\n");
113 fprintf(stdout, " --proxy PROXY:PORT\n");
114 fprintf(stdout, " --host HOST\n");
115 fprintf(stdout, " --logfile logfile\n");
116 fprintf(stdout, " --shrink-urls\n");
117 fprintf(stdout, " --page PAGENUMBER\n");
118 fprintf(stdout, " --bash\n");
119 fprintf(stdout, " --debug\n");
120 fprintf(stdout, " --verbose\n");
121 fprintf(stdout, " --dry-run\n");
122 fprintf(stdout, " --version\n");
123 fprintf(stdout, " --help\n");
126 static void display_version(void)
128 fprintf(stdout, "bti - version %s\n", VERSION);
131 static struct session *session_alloc(void)
133 struct session *session;
135 session = zalloc(sizeof(*session));
141 static void session_free(struct session *session)
145 free(session->password);
146 free(session->account);
147 free(session->tweet);
148 free(session->proxy);
150 free(session->homedir);
152 free(session->group);
153 free(session->hosturl);
154 free(session->hostname);
158 static struct bti_curl_buffer *bti_curl_buffer_alloc(enum action action)
160 struct bti_curl_buffer *buffer;
162 buffer = zalloc(sizeof(*buffer));
166 /* start out with a data buffer of 1 byte to
167 * make the buffer fill logic simpler */
168 buffer->data = zalloc(1);
174 buffer->action = action;
178 static void bti_curl_buffer_free(struct bti_curl_buffer *buffer)
186 static const char *twitter_host = "https://twitter.com/statuses";
187 static const char *identica_host = "https://identi.ca/api/statuses";
188 static const char *twitter_name = "twitter";
189 static const char *identica_name = "identi.ca";
191 static const char *user_uri = "/user_timeline/";
192 static const char *update_uri = "/update.xml";
193 static const char *public_uri = "/public_timeline.xml";
194 static const char *friends_uri = "/friends_timeline.xml";
195 static const char *replies_uri = "/replies.xml";
196 static const char *group_uri = "/../laconica/groups/timeline/";
198 static CURL *curl_init(void)
202 curl = curl_easy_init();
204 fprintf(stderr, "Can not init CURL!\n");
207 /* some ssl sanity checks on the connection we are making */
208 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
209 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
213 static void parse_statuses(xmlDocPtr doc, xmlNodePtr current)
215 xmlChar *text = NULL;
216 xmlChar *user = NULL;
217 xmlChar *created = NULL;
220 current = current->xmlChildrenNode;
221 while (current != NULL) {
222 if (current->type == XML_ELEMENT_NODE) {
223 if (!xmlStrcmp(current->name, (const xmlChar *)"created_at"))
224 created = xmlNodeListGetString(doc, current->xmlChildrenNode, 1);
225 if (!xmlStrcmp(current->name, (const xmlChar *)"text"))
226 text = xmlNodeListGetString(doc, current->xmlChildrenNode, 1);
227 if (!xmlStrcmp(current->name, (const xmlChar *)"user")) {
228 userinfo = current->xmlChildrenNode;
229 while (userinfo != NULL) {
230 if ((!xmlStrcmp(userinfo->name, (const xmlChar *)"screen_name"))) {
233 user = xmlNodeListGetString(doc, userinfo->xmlChildrenNode, 1);
235 userinfo = userinfo->next;
239 if (user && text && created) {
241 printf("[%s] (%.16s) %s\n",
242 user, created, text);
254 current = current->next;
260 static void parse_timeline(char *document)
265 doc = xmlReadMemory(document, strlen(document), "timeline.xml",
266 NULL, XML_PARSE_NOERROR);
270 current = xmlDocGetRootElement(doc);
271 if (current == NULL) {
272 fprintf(stderr, "empty document\n");
277 if (xmlStrcmp(current->name, (const xmlChar *) "statuses")) {
278 fprintf(stderr, "unexpected document type\n");
283 current = current->xmlChildrenNode;
284 while (current != NULL) {
285 if ((!xmlStrcmp(current->name, (const xmlChar *)"status")))
286 parse_statuses(doc, current);
287 current = current->next;
294 static size_t curl_callback(void *buffer, size_t size, size_t nmemb,
297 struct bti_curl_buffer *curl_buf = userp;
298 size_t buffer_size = size * nmemb;
301 if ((!buffer) || (!buffer_size) || (!curl_buf))
304 /* add to the data we already have */
305 temp = zalloc(curl_buf->length + buffer_size + 1);
309 memcpy(temp, curl_buf->data, curl_buf->length);
310 free(curl_buf->data);
311 curl_buf->data = temp;
312 memcpy(&curl_buf->data[curl_buf->length], (char *)buffer, buffer_size);
313 curl_buf->length += buffer_size;
314 if (curl_buf->action)
315 parse_timeline(curl_buf->data);
317 dbg("%s\n", curl_buf->data);
322 static int send_request(struct session *session)
325 char user_password[500];
327 struct bti_curl_buffer *curl_buf;
330 struct curl_httppost *formpost = NULL;
331 struct curl_httppost *lastptr = NULL;
332 struct curl_slist *slist = NULL;
337 curl_buf = bti_curl_buffer_alloc(session->action);
345 if (!session->hosturl)
346 session->hosturl = strdup(twitter_host);
348 switch (session->action) {
350 snprintf(user_password, sizeof(user_password), "%s:%s",
351 session->account, session->password);
352 snprintf(data, sizeof(data), "status=\"%s\"", session->tweet);
353 curl_formadd(&formpost, &lastptr,
354 CURLFORM_COPYNAME, "status",
355 CURLFORM_COPYCONTENTS, session->tweet,
358 curl_formadd(&formpost, &lastptr,
359 CURLFORM_COPYNAME, "source",
360 CURLFORM_COPYCONTENTS, "bti",
363 curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
364 slist = curl_slist_append(slist, "Expect:");
365 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
367 sprintf(endpoint, "%s%s", session->hosturl, update_uri);
368 curl_easy_setopt(curl, CURLOPT_URL, endpoint);
369 curl_easy_setopt(curl, CURLOPT_USERPWD, user_password);
373 snprintf(user_password, sizeof(user_password), "%s:%s",
374 session->account, session->password);
375 sprintf(endpoint, "%s%s?page=%d", session->hosturl,
376 friends_uri, session->page);
377 curl_easy_setopt(curl, CURLOPT_URL, endpoint);
378 curl_easy_setopt(curl, CURLOPT_USERPWD, user_password);
382 sprintf(endpoint, "%s%s%s.xml?page=%d", session->hosturl,
383 user_uri, session->user, session->page);
384 curl_easy_setopt(curl, CURLOPT_URL, endpoint);
388 snprintf(user_password, sizeof(user_password), "%s:%s",
389 session->account, session->password);
390 sprintf(endpoint, "%s%s?page=%d", session->hosturl, replies_uri,
392 curl_easy_setopt(curl, CURLOPT_URL, endpoint);
393 curl_easy_setopt(curl, CURLOPT_USERPWD, user_password);
397 sprintf(endpoint, "%s%s?page=%d", session->hosturl, public_uri,
399 curl_easy_setopt(curl, CURLOPT_URL, endpoint);
403 sprintf(endpoint, "%s%s%s.xml?page=%d", session->hosturl,
404 group_uri, session->group, session->page);
405 curl_easy_setopt(curl, CURLOPT_URL, endpoint);
413 curl_easy_setopt(curl, CURLOPT_PROXY, session->proxy);
416 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
418 dbg("user_password = %s\n", user_password);
419 dbg("data = %s\n", data);
420 dbg("proxy = %s\n", session->proxy);
422 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_callback);
423 curl_easy_setopt(curl, CURLOPT_WRITEDATA, curl_buf);
424 if (!session->dry_run) {
425 res = curl_easy_perform(curl);
426 if (res && !session->bash) {
427 fprintf(stderr, "error(%d) trying to perform "
433 curl_easy_cleanup(curl);
434 if (session->action == ACTION_UPDATE)
435 curl_formfree(formpost);
436 bti_curl_buffer_free(curl_buf);
440 static void parse_configfile(struct session *session)
445 char *account = NULL;
446 char *password = NULL;
449 char *logfile = NULL;
455 /* config file is ~/.bti */
456 file = alloca(strlen(session->homedir) + 7);
458 sprintf(file, "%s/.bti", session->homedir);
460 config_file = fopen(file, "r");
462 /* No error if file does not exist or is unreadable. */
463 if (config_file == NULL)
467 ssize_t n = getline(&line, &len, config_file);
470 if (line[n - 1] == '\n')
472 /* Parse file. Format is the usual value pairs:
475 # is a comment character
477 *strchrnul(line, '#') = '\0';
481 /* Ignore blank lines. */
485 if (!strncasecmp(c, "account", 7) && (c[7] == '=')) {
489 } else if (!strncasecmp(c, "password", 8) &&
493 password = strdup(c);
494 } else if (!strncasecmp(c, "host", 4) &&
499 } else if (!strncasecmp(c, "proxy", 5) &&
504 } else if (!strncasecmp(c, "logfile", 7) &&
509 } else if (!strncasecmp(c, "action", 6) &&
514 } else if (!strncasecmp(c, "user", 4) &&
519 } else if (!strncasecmp(c, "shrink-urls", 11) &&
522 if (!strncasecmp(c, "true", 4) ||
523 !strncasecmp(c, "yes", 3))
525 } else if (!strncasecmp(c, "verbose", 7) &&
528 if (!strncasecmp(c, "true", 4) ||
529 !strncasecmp(c, "yes", 3))
532 } while (!feof(config_file));
535 session->password = password;
537 session->account = account;
539 if (strcasecmp(host, "twitter") == 0) {
540 session->host = HOST_TWITTER;
541 session->hosturl = strdup(twitter_host);
542 session->hostname = strdup(twitter_name);
543 } else if (strcasecmp(host, "identica") == 0) {
544 session->host = HOST_IDENTICA;
545 session->hosturl = strdup(identica_host);
546 session->hostname = strdup(identica_name);
548 session->host = HOST_CUSTOM;
549 session->hosturl = strdup(host);
550 session->hostname = strdup(host);
556 free(session->proxy);
557 session->proxy = proxy;
560 session->logfile = logfile;
562 if (strcasecmp(action, "update") == 0)
563 session->action = ACTION_UPDATE;
564 else if (strcasecmp(action, "friends") == 0)
565 session->action = ACTION_FRIENDS;
566 else if (strcasecmp(action, "user") == 0)
567 session->action = ACTION_USER;
568 else if (strcasecmp(action, "replies") == 0)
569 session->action = ACTION_REPLIES;
570 else if (strcasecmp(action, "public") == 0)
571 session->action = ACTION_PUBLIC;
572 else if (strcasecmp(action, "group") == 0)
573 session->action = ACTION_GROUP;
575 session->action = ACTION_UNKNOWN;
579 session->user = user;
580 session->shrink_urls = shrink_urls;
582 /* Free buffer and close file. */
587 static void log_session(struct session *session, int retval)
592 /* Only log something if we have a log file set */
593 if (!session->logfile)
596 filename = alloca(strlen(session->homedir) +
597 strlen(session->logfile) + 3);
599 sprintf(filename, "%s/%s", session->homedir, session->logfile);
601 log_file = fopen(filename, "a+");
602 if (log_file == NULL)
605 switch (session->action) {
608 fprintf(log_file, "%s: host=%s tweet failed\n",
609 session->time, session->hostname);
611 fprintf(log_file, "%s: host=%s tweet=%s\n",
612 session->time, session->hostname, session->tweet);
615 fprintf(log_file, "%s: host=%s retrieving friends timeline\n",
616 session->time, session->hostname);
619 fprintf(log_file, "%s: host=%s retrieving %s's timeline\n",
620 session->time, session->hostname, session->user);
623 fprintf(log_file, "%s: host=%s retrieving replies\n",
624 session->time, session->hostname);
627 fprintf(log_file, "%s: host=%s retrieving public timeline\n",
628 session->time, session->hostname);
631 fprintf(log_file, "%s: host=%s retrieving group timeline\n",
632 session->time, session->hostname);
641 static char *get_string_from_stdin(void)
646 string = zalloc(1000);
650 if (!fgets(string, 999, stdin))
652 temp = strchr(string, '\n');
657 static void read_password(char *buf, size_t len, char *host)
667 tp.c_lflag &= (~ECHO);
668 tcsetattr(0, TCSANOW, &tp);
670 fprintf(stdout, "Enter password for %s: ", host);
673 retval = scanf("%79s", pwd);
675 fprintf(stdout, "\n");
677 tcsetattr(0, TCSANOW, &old);
679 strncpy(buf, pwd, len);
683 static int find_urls(const char *tweet, int **pranges)
686 * magic obtained from
687 * http://www.geekpedia.com/KB65_How-to-validate-an-URL-using-RegEx-in-Csharp.html
689 static const char *re_magic =
690 "(([a-zA-Z][0-9a-zA-Z+\\-\\.]*:)/{1,3}"
691 "[0-9a-zA-Z;/~?:@&=+$\\.\\-_'()%]+)"
692 "(#[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?";
696 int ovector[10] = {0,};
697 const size_t ovsize = sizeof(ovector)/sizeof(*ovector);
698 int startoffset, tweetlen;
702 int *ranges = malloc(sizeof(int) * rbound);
704 re = pcre_compile(re_magic,
705 PCRE_NO_AUTO_CAPTURE,
706 &errptr, &erroffset, NULL);
708 fprintf(stderr, "pcre_compile @%u: %s\n", erroffset, errptr);
712 tweetlen = strlen(tweet);
713 for (startoffset = 0; startoffset < tweetlen; ) {
715 rc = pcre_exec(re, NULL, tweet, strlen(tweet), startoffset, 0,
717 if (rc == PCRE_ERROR_NOMATCH)
721 fprintf(stderr, "pcre_exec @%u: %s\n",
726 for (i = 0; i < rc; i += 2) {
727 if ((rcount+2) == rbound) {
729 ranges = realloc(ranges, sizeof(int) * rbound);
732 ranges[rcount++] = ovector[i];
733 ranges[rcount++] = ovector[i+1];
736 startoffset = ovector[1];
746 * bidirectional popen() call
748 * @param rwepipe - int array of size three
749 * @param exe - program to run
750 * @param argv - argument list
751 * @return pid or -1 on error
753 * The caller passes in an array of three integers (rwepipe), on successful
754 * execution it can then write to element 0 (stdin of exe), and read from
755 * element 1 (stdout) and 2 (stderr).
757 static int popenRWE(int *rwepipe, const char *exe, const char *const argv[])
787 } else if (pid == 0) {
799 execvp(exe, (char **)argv);
819 static int pcloseRWE(int pid, int *rwepipe)
825 rc = waitpid(pid, &status, 0);
829 static char *shrink_one_url(int *rwepipe, char *big)
831 int biglen = strlen(big);
836 rc = dprintf(rwepipe[0], "%s\n", big);
840 smalllen = biglen + 128;
841 small = malloc(smalllen);
845 rc = read(rwepipe[1], small, smalllen);
846 if (rc < 0 || rc > biglen)
847 goto error_free_small;
849 if (strncmp(small, "http://", 7))
850 goto error_free_small;
853 while (smalllen && isspace(small[smalllen-1]))
854 small[--smalllen] = 0;
864 static char *shrink_urls(char *text)
871 const char *const shrink_args[] = {
877 int inlen = strlen(text);
879 dbg("before len=%u\n", inlen);
881 shrink_pid = popenRWE(shrink_pipe, shrink_args[0], shrink_args);
885 rcount = find_urls(text, &ranges);
889 for (i = 0; i < rcount; i += 2) {
890 int url_start = ranges[i];
891 int url_end = ranges[i+1];
892 int long_url_len = url_end - url_start;
893 char *url = strndup(text + url_start, long_url_len);
895 int not_url_len = url_start - inofs;
897 dbg("long url[%u]: %s\n", long_url_len, url);
898 url = shrink_one_url(shrink_pipe, url);
899 short_url_len = url ? strlen(url) : 0;
900 dbg("short url[%u]: %s\n", short_url_len, url);
902 if (!url || short_url_len >= long_url_len) {
903 /* The short url ended up being too long
906 strncpy(text + outofs, text + inofs,
907 not_url_len + long_url_len);
909 inofs += not_url_len + long_url_len;
910 outofs += not_url_len + long_url_len;
913 /* copy the unmodified block */
914 strncpy(text + outofs, text + inofs, not_url_len);
915 inofs += not_url_len;
916 outofs += not_url_len;
918 /* copy the new url */
919 strncpy(text + outofs, url, short_url_len);
920 inofs += long_url_len;
921 outofs += short_url_len;
927 /* copy the last block after the last match */
929 int tail = inlen - inofs;
931 strncpy(text + outofs, text + inofs, tail);
938 (void)pcloseRWE(shrink_pid, shrink_pipe);
941 dbg("after len=%u\n", outofs);
945 int main(int argc, char *argv[], char *envp[])
947 static const struct option options[] = {
948 { "debug", 0, NULL, 'd' },
949 { "verbose", 0, NULL, 'V' },
950 { "account", 1, NULL, 'a' },
951 { "password", 1, NULL, 'p' },
952 { "host", 1, NULL, 'H' },
953 { "proxy", 1, NULL, 'P' },
954 { "action", 1, NULL, 'A' },
955 { "user", 1, NULL, 'u' },
956 { "group", 1, NULL, 'G' },
957 { "logfile", 1, NULL, 'L' },
958 { "shrink-urls", 0, NULL, 's' },
959 { "help", 0, NULL, 'h' },
960 { "bash", 0, NULL, 'b' },
961 { "dry-run", 0, NULL, 'n' },
962 { "page", 1, NULL, 'g' },
963 { "version", 0, NULL, 'v' },
966 struct session *session;
969 static char password[80];
978 rl_bind_key('\t', rl_insert);
980 session = session_alloc();
982 fprintf(stderr, "no more memory...\n");
986 /* get the current time so that we can log it later */
988 session->time = strdup(ctime(&t));
989 session->time[strlen(session->time)-1] = 0x00;
991 session->homedir = strdup(getenv("HOME"));
993 curl_global_init(CURL_GLOBAL_ALL);
995 /* Set environment variables first, before reading command line options
996 * or config file values. */
997 http_proxy = getenv("http_proxy");
1000 free(session->proxy);
1001 session->proxy = strdup(http_proxy);
1002 dbg("http_proxy = %s\n", session->proxy);
1005 parse_configfile(session);
1008 option = getopt_long_only(argc, argv, "dp:P:H:a:A:u:hg:G:snVv",
1020 if (session->account)
1021 free(session->account);
1022 session->account = strdup(optarg);
1023 dbg("account = %s\n", session->account);
1026 page_nr = atoi(optarg);
1027 dbg("page = %d\n", page_nr);
1028 session->page = page_nr;
1031 if (session->password)
1032 free(session->password);
1033 session->password = strdup(optarg);
1034 dbg("password = %s\n", session->password);
1038 free(session->proxy);
1039 session->proxy = strdup(optarg);
1040 dbg("proxy = %s\n", session->proxy);
1043 if (strcasecmp(optarg, "update") == 0)
1044 session->action = ACTION_UPDATE;
1045 else if (strcasecmp(optarg, "friends") == 0)
1046 session->action = ACTION_FRIENDS;
1047 else if (strcasecmp(optarg, "user") == 0)
1048 session->action = ACTION_USER;
1049 else if (strcasecmp(optarg, "replies") == 0)
1050 session->action = ACTION_REPLIES;
1051 else if (strcasecmp(optarg, "public") == 0)
1052 session->action = ACTION_PUBLIC;
1053 else if (strcasecmp(optarg, "group") == 0)
1054 session->action = ACTION_GROUP;
1056 session->action = ACTION_UNKNOWN;
1057 dbg("action = %d\n", session->action);
1061 free(session->user);
1062 session->user = strdup(optarg);
1063 dbg("user = %s\n", session->user);
1068 free(session->group);
1069 session->group = strdup(optarg);
1070 dbg("group = %s\n", session->group);
1073 if (session->logfile)
1074 free(session->logfile);
1075 session->logfile = strdup(optarg);
1076 dbg("logfile = %s\n", session->logfile);
1079 session->shrink_urls = 1;
1082 if (session->hosturl)
1083 free(session->hosturl);
1084 if (session->hostname)
1085 free(session->hostname);
1086 if (strcasecmp(optarg, "twitter") == 0) {
1087 session->host = HOST_TWITTER;
1088 session->hosturl = strdup(twitter_host);
1089 session->hostname = strdup(twitter_name);
1090 } else if (strcasecmp(optarg, "identica") == 0) {
1091 session->host = HOST_IDENTICA;
1092 session->hosturl = strdup(identica_host);
1093 session->hostname = strdup(identica_name);
1095 session->host = HOST_CUSTOM;
1096 session->hosturl = strdup(optarg);
1097 session->hostname = strdup(optarg);
1099 dbg("host = %d\n", session->host);
1108 session->dry_run = 1;
1120 * Show the version to make it easier to determine what
1126 if (session->action == ACTION_UNKNOWN) {
1127 fprintf(stderr, "Unknown action, valid actions are:\n");
1128 fprintf(stderr, "'update', 'friends', 'public', "
1129 "'replies', 'group' or 'user'.\n");
1133 if (session->host == HOST_TWITTER && session->action == ACTION_GROUP) {
1134 fprintf(stderr, "Groups only work in Identi.ca.\n");
1138 if (session->action == ACTION_GROUP && !session->group) {
1139 fprintf(stdout, "Enter group name: ");
1140 session->group = readline(NULL);
1143 if (!session->account) {
1144 fprintf(stdout, "Enter account for %s: ", session->hostname);
1145 session->account = readline(NULL);
1148 if (!session->password) {
1149 read_password(password, sizeof(password), session->hostname);
1150 session->password = strdup(password);
1153 if (session->action == ACTION_UPDATE) {
1155 tweet = get_string_from_stdin();
1157 tweet = readline("tweet: ");
1158 if (!tweet || strlen(tweet) == 0) {
1163 if (session->shrink_urls)
1164 tweet = shrink_urls(tweet);
1166 session->tweet = zalloc(strlen(tweet) + 10);
1168 sprintf(session->tweet, "%c %s",
1169 getuid() ? '$' : '#', tweet);
1171 sprintf(session->tweet, "%s", tweet);
1174 dbg("tweet = %s\n", session->tweet);
1178 session->user = strdup(session->account);
1180 if (session->page == 0)
1182 dbg("account = %s\n", session->account);
1183 dbg("password = %s\n", session->password);
1184 dbg("host = %d\n", session->host);
1185 dbg("action = %d\n", session->action);
1187 /* fork ourself so that the main shell can get on
1188 * with it's life as we try to connect and handle everything
1190 if (session->bash) {
1193 dbg("child is %d\n", child);
1198 retval = send_request(session);
1199 if (retval && !session->bash)
1200 fprintf(stderr, "operation failed\n");
1202 log_session(session, retval);
1204 session_free(session);