ii-1.7-ucspi.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       ii-1.7-ucspi.diff (5161B)
       ---
            1 diff --git a/ii.1 b/ii.1
            2 index dd1f6e3..c293c37 100644
            3 --- a/ii.1
            4 +++ b/ii.1
            5 @@ -20,6 +20,10 @@ server with basic command line tools.
            6  For example if you will join a channel just do echo "/j #channel" > in
            7  and ii creates a new channel directory with in and out file.
            8  .SH SYNOPSIS
            9 +.B tcpclient
           10 +host
           11 +port
           12 +.RB [ tlsc ]
           13  .B ii
           14  .RB [ \-s
           15  .IR servername ]
           16 @@ -93,5 +97,7 @@ Write to ii (at) modprobe (dot) de for suggestions, fixes, 7|-|>< ;) etc.
           17  Copyright \(co 2005-2006 by Anselm R. Garbe <garbeam (at) gmail (dot) com> and 
           18  Copyright \(co 2005-2008 by Nico Golde <nico (at) ngolde (dot) de>
           19  .SH SEE ALSO
           20 +.BR tcpclient(1),
           21 +.BR tlsc(1),
           22  .BR echo (1),
           23  .BR tail (1),
           24 diff --git a/ii.c b/ii.c
           25 index d93266c..5305869 100644
           26 --- a/ii.c
           27 +++ b/ii.c
           28 @@ -5,9 +5,7 @@
           29  #include <netdb.h>
           30  #include <sys/types.h>
           31  #include <sys/stat.h>
           32 -#include <sys/socket.h>
           33  #include <sys/select.h>
           34 -#include <netinet/in.h>
           35  #include <stdio.h>
           36  #include <stdlib.h>
           37  #include <limits.h>
           38 @@ -19,6 +17,9 @@
           39  #include <time.h>
           40  #include <unistd.h>
           41  
           42 +#define READ_FD 6
           43 +#define WRITE_FD 7
           44 +
           45  #ifndef PIPE_BUF /* FreeBSD don't know PIPE_BUF */
           46  #define PIPE_BUF 4096
           47  #endif
           48 @@ -33,7 +34,6 @@ struct Channel {
           49          Channel *next;
           50  };
           51  
           52 -static int irc;
           53  static time_t last_response;
           54  static Channel *channels = NULL;
           55  static char *host = "irc.freenode.net";
           56 @@ -148,31 +148,7 @@ static void login(char *key, char *fullname) {
           57                                  nick, nick, host, fullname ? fullname : nick);
           58          else snprintf(message, PIPE_BUF, "NICK %s\r\nUSER %s localhost %s :%s\r\n",
           59                                  nick, nick, host, fullname ? fullname : nick);
           60 -        write(irc, message, strlen(message));        /* login */
           61 -}
           62 -
           63 -static int tcpopen(unsigned short port) {
           64 -        int fd;
           65 -        struct sockaddr_in sin;
           66 -        struct hostent *hp = gethostbyname(host);
           67 -
           68 -        memset(&sin, 0, sizeof(struct sockaddr_in));
           69 -        if(!hp) {
           70 -                perror("ii: cannot retrieve host information");
           71 -                exit(EXIT_FAILURE);
           72 -        }
           73 -        sin.sin_family = AF_INET;
           74 -        memcpy(&sin.sin_addr, hp->h_addr, hp->h_length);
           75 -        sin.sin_port = htons(port);
           76 -        if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
           77 -                perror("ii: cannot create socket");
           78 -                exit(EXIT_FAILURE);
           79 -        }
           80 -        if(connect(fd, (const struct sockaddr *) &sin, sizeof(sin)) < 0) {
           81 -                perror("ii: cannot connect to host");
           82 -                exit(EXIT_FAILURE);
           83 -        }
           84 -        return fd;
           85 +        write(WRITE_FD, message, strlen(message));        /* login */
           86  }
           87  
           88  static size_t tokenize(char **result, size_t reslen, char *str, char delim) {
           89 @@ -219,7 +195,7 @@ static void proc_channels_privmsg(char *channel, char *buf) {
           90          snprintf(message, PIPE_BUF, "<%s> %s", nick, buf);
           91          print_out(channel, message);
           92          snprintf(message, PIPE_BUF, "PRIVMSG %s :%s\r\n", channel, buf);
           93 -        write(irc, message, strlen(message));
           94 +        write(WRITE_FD, message, strlen(message));
           95  }
           96  
           97  static void proc_channels_input(Channel *c, char *buf) {
           98 @@ -273,7 +249,7 @@ static void proc_channels_input(Channel *c, char *buf) {
           99                          else
          100                                  snprintf(message, PIPE_BUF,
          101                                                  "PART %s :ii - 500 SLOC are too much\r\n", c->name);
          102 -                        write(irc, message, strlen(message));
          103 +                        write(WRITE_FD, message, strlen(message));
          104                          close(c->fd);
          105                          /*create_filepath(infile, sizeof(infile), c->name, "in");
          106                          unlink(infile); */
          107 @@ -288,7 +264,7 @@ static void proc_channels_input(Channel *c, char *buf) {
          108                  snprintf(message, PIPE_BUF, "%s\r\n", &buf[1]);
          109  
          110          if (message[0] != '\0')
          111 -                write(irc, message, strlen(message));
          112 +                write(WRITE_FD, message, strlen(message));
          113  }
          114  
          115  static void proc_server_cmd(char *buf) {
          116 @@ -339,7 +315,7 @@ static void proc_server_cmd(char *buf) {
          117                  return;
          118          } else if(!strncmp("PING", argv[TOK_CMD], 5)) {
          119                  snprintf(message, PIPE_BUF, "PONG %s\r\n", argv[TOK_TEXT]);
          120 -                write(irc, message, strlen(message));
          121 +                write(WRITE_FD, message, strlen(message));
          122                  return;
          123          } else if(!argv[TOK_NICKSRV] || !argv[TOK_USER]) {        /* server command */
          124                  snprintf(message, PIPE_BUF, "%s%s", argv[TOK_ARG] ? argv[TOK_ARG] : "", argv[TOK_TEXT] ? argv[TOK_TEXT] : "");
          125 @@ -402,7 +378,7 @@ static void handle_channels_input(Channel *c) {
          126  
          127  static void handle_server_output() {
          128          static char buf[PIPE_BUF];
          129 -        if(read_line(irc, PIPE_BUF, buf) == -1) {
          130 +        if(read_line(READ_FD, PIPE_BUF, buf) == -1) {
          131                  perror("ii: remote host closed connection");
          132                  exit(EXIT_FAILURE);
          133          }
          134 @@ -419,8 +395,8 @@ static void run() {
          135          snprintf(ping_msg, sizeof(ping_msg), "PING %s\r\n", host);
          136          for(;;) {
          137                  FD_ZERO(&rd);
          138 -                maxfd = irc;
          139 -                FD_SET(irc, &rd);
          140 +                maxfd = READ_FD;
          141 +                FD_SET(READ_FD, &rd);
          142                  for(c = channels; c; c = c->next) {
          143                          if(maxfd < c->fd)
          144                                  maxfd = c->fd;
          145 @@ -440,10 +416,10 @@ static void run() {
          146                                  print_out(NULL, "-!- ii shutting down: ping timeout");
          147                                  exit(EXIT_FAILURE);
          148                          }
          149 -                        write(irc, ping_msg, strlen(ping_msg));
          150 +                        write(WRITE_FD, ping_msg, strlen(ping_msg));
          151                          continue;
          152                  }
          153 -                if(FD_ISSET(irc, &rd)) {
          154 +                if(FD_ISSET(READ_FD, &rd)) {
          155                          handle_server_output();
          156                          last_response = time(NULL);
          157                  }
          158 @@ -479,7 +455,6 @@ int main(int argc, char *argv[]) {
          159                          default: usage(); break;
          160                  }
          161          }
          162 -        irc = tcpopen(port);
          163          if(!snprintf(path, sizeof(path), "%s/%s", prefix, host)) {
          164                  fputs("ii: path to irc directory too long\n", stderr);
          165                  exit(EXIT_FAILURE);