irctk

libircclient binding for scripts
git clone https://a3nm.net/git/irctk/
Log | Files | Refs | README

commit a719be5a9881c0e1a4257752ad0861e526db9bb1
parent 2f941d3658d6afb14c5a0c77f867a8f53db1639d
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Sat, 16 Jun 2012 17:16:16 +0200

remove useless code

Diffstat:
README | 12++++++------
TODO | 2+-
irctk.c | 241++++++++++++++++++++-----------------------------------------------------------
3 files changed, 66 insertions(+), 189 deletions(-)

diff --git a/README b/README @@ -1,14 +1,14 @@ -irctk is a general-purpose IRC wrapper. It connects to an IRC server -specified as [NICK@]SERVER[:PORT] as a CLI argument, posts what it -receives from stdin and displays what is said to stdout. +irctk is a general-purpose IRC wrapper. It connects to an IRC server specified +as [NICK@]SERVER[:PORT] as a CLI argument, posts what it receives from stdin and +displays what is said to stdout. -Beware, this code is not yet secure or clean. I have been using it -regularly for some time, but your needs might be different from mine. +Beware, this code is not yet secure or clean. I have been using it regularly for +some time, but your needs might be different from mine. irctk is not related to IrcTK by Max Countryman <https://github.com/maxcountryman/irctk>. -To compile, you need libircclient. +To compile, you need libircclient 1.6 <http://www.ulduzsoft.com/libircclient/>. TODO these examples aren't secure diff --git a/TODO b/TODO @@ -2,4 +2,4 @@ http://www.iagora.com/~espel/sirc/sirc.html handle nick following ssl support password support -exit when killed +exit when killed, advertising the signal diff --git a/irctk.c b/irctk.c @@ -442,11 +442,6 @@ void debug_args() args.n_channels, args.interval, args.nick, args.server, args.port, args.password); } - - - - - char* first_chan() { if (args.n_channels) @@ -656,7 +651,8 @@ void dump_event (irc_session_t * session, const char * event, const char * origi } } } else if (atoi(event) == LIBIRC_RFC_ERR_BADCHANNELKEY) { - // TODO report name of channel last joined, die if it was specified on cli + // TODO report name of channel last joined, die if it was the one specified + // on CLI info("Cannot join channel: bad password."); } else if (atoi(event) == LIBIRC_RFC_ERR_INVITEONLYCHAN) { info("Cannot join channel: channel is invite-only."); @@ -729,8 +725,6 @@ void event_kick (irc_session_t * session, const char * event, const char * origi printf("[%s] -!- %s was kicked from %s by %s (%s)\n", params[0], params[1], params[0], origin, params[2]); } -// TODO manage other events! -// TODO manage channel passwords void event_connect (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) { @@ -749,158 +743,67 @@ void event_connect (irc_session_t * session, const char * event, const char * or } -void dcc_recv_callback (irc_session_t * session, irc_dcc_t id, int status, void * ctx, const char * data, unsigned int length) -{ - static int count = 1; - char buf[12]; - - switch (status) - { - case LIBIRC_ERR_CLOSED: - printf ("DCC %d: chat closed\n", id); - break; - - case 0: - if ( !data ) - { - printf ("DCC %d: chat connected\n", id); - irc_dcc_msg (session, id, "Hehe"); - } - else - { - printf ("DCC %d: %s\n", id, data); - sprintf (buf, "DCC [%d]: %d", id, count++); - irc_dcc_msg (session, id, buf); - } - break; - - default: - printf ("DCC %d: error %s\n", id, irc_strerror(status)); - break; - } -} - - -void dcc_file_recv_callback (irc_session_t * session, irc_dcc_t id, int status, void * ctx, const char * data, unsigned int length) -{ - if ( status == 0 && length == 0 ) - { - printf ("File sent successfully\n"); - - if ( ctx ) - fclose ((FILE*) ctx); - } - else if ( status ) - { - printf ("File sent error: %d\n", status); - - if ( ctx ) - fclose ((FILE*) ctx); - } - else - { - if ( ctx ) - fwrite (data, 1, length, (FILE*) ctx); - printf ("File sent progress: %d\n", length); - } -} - - void event_channel (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) { - int i=0; - int ok = 1, ok2; - const char* pruned; - if ( count != 2 ) - return; - - if (args.filter) - if (strcmp(params[0], args.nick)) - { - for (i=0; i<strlen(args.nick); i++) - if (args.nick[i] != params[1][i] || !params[1][i]) - ok = 0; - /* TODO test if ',' or ':' to avoid prefix nicks */ - } + int i=0; + int ok = 1, ok2; + const char* pruned; + if ( count != 2 ) + return; + + if (args.filter) + if (strcmp(params[0], args.nick)) + { + for (i=0; i<strlen(args.nick); i++) + if (args.nick[i] != params[1][i] || !params[1][i]) + ok = 0; + /* TODO test if ',' or ':' to avoid prefix nicks */ + } - if (ok) + if (ok) + { + if (!args.prune) + { + printf ("[%s] <", params[0]); + if (!origin) + printf("someone"); + else + /* not robust, and useless since we use STRIPNICKS */ + //while(origin[i++] != '!') putchar(origin[i-1]); + printf("%s", origin); + printf("> "); + if (params[1][0] == '/' && args.event_to == COMMAND) + printf("/ "); // escape slashes + printf("%s\n", params[1] ); + } else { + pruned = params[1]; + ok2 = 1; + while(pruned[0] != ':') + { + if (!pruned[0] || pruned[0] == ' ') { - if (!args.prune) - { - printf ("[%s] <", params[0]); - if (!origin) - printf("someone"); - else - /* TODO not robust, and useless since we use STRIPNICKS */ - //while(origin[i++] != '!') putchar(origin[i-1]); - printf("%s", origin); - printf("> "); - if (params[1][0] == '/' && args.event_to == COMMAND) - printf("/ "); // escape slashes - printf("%s\n", params[1] ); - } else { - pruned = params[1]; - ok2 = 1; - while(pruned[0] != ':') - { - if (!pruned[0] || pruned[0] == ' ') - { - ok2 = 0; - break; - } - pruned++; - } + ok2 = 0; + break; + } + pruned++; + } - if (ok2) { - pruned++; // skip ':' - while(pruned[0] == ' ') - pruned++; // skip spaces - } - else pruned = params[1]; // no address + if (ok2) { + pruned++; // skip ':' + while(pruned[0] == ' ') + pruned++; // skip spaces + } + else pruned = params[1]; // no address - printf("%s\n", pruned); - } - if (strcmp(params[0], args.nick)) // if addressed in our private chan, reply on the sender's priv chan - strncpy(args.last_chan_in, params[0], MAX_LEN-1); - else strncpy(args.last_chan_in, origin?origin:"someone", MAX_LEN-1); - strncpy(args.last_nick_in, origin?origin:"someone", MAX_LEN-1); - fflush(stdout); - } + printf("%s\n", pruned); + } + if (strcmp(params[0], args.nick)) // if addressed in our private chan, reply on the sender's priv chan + strncpy(args.last_chan_in, params[0], MAX_LEN-1); + else strncpy(args.last_chan_in, origin?origin:"someone", MAX_LEN-1); + strncpy(args.last_nick_in, origin?origin:"someone", MAX_LEN-1); + fflush(stdout); + } - /*irc_target_get_nick (origin, nickbuf, sizeof(nickbuf)); - - if ( !strcmp (params[1], "ctcp") ) - { - irc_cmd_ctcp_request (session, nickbuf, "PING 223"); - irc_cmd_ctcp_request (session, nickbuf, "FINGER"); - irc_cmd_ctcp_request (session, nickbuf, "VERSION"); - irc_cmd_ctcp_request (session, nickbuf, "TIME"); - } - - if ( !strcmp (params[1], "dcc chat") ) - { - irc_dcc_t dccid; - irc_dcc_chat (session, 0, nickbuf, dcc_recv_callback, &dccid); - printf ("DCC chat ID: %d\n", dccid); - } - - if ( !strcmp (params[1], "dcc send") ) - { - irc_dcc_t dccid; - irc_dcc_sendfile (session, 0, nickbuf, "irctest.c", dcc_file_recv_callback, &dccid); - printf ("DCC send ID: %d\n", dccid); - } - - if ( !strcmp (params[1], "topic") ) - irc_cmd_topic (session, params[0], 0); - else if ( strstr (params[1], "topic ") == params[1] ) - irc_cmd_topic (session, params[0], params[1] + 6); - - if ( strstr (params[1], "mode ") == params[1] ) - irc_cmd_channel_mode (session, params[0], params[1] + 5); - - if ( strstr (params[1], "whois ") == params[1] ) - irc_cmd_whois (session, params[1] + 5);*/ } @@ -913,32 +816,12 @@ void event_privmsg (irc_session_t * session, const char * event, const char * or } - -void irc_event_dcc_chat (irc_session_t * session, const char * nick, const char * addr, irc_dcc_t dccid) -{ - printf ("DCC chat [%d] requested from '%s' (%s)\n", dccid, nick, addr); - - irc_dcc_accept (session, dccid, 0, dcc_recv_callback); -} - - -void irc_event_dcc_send (irc_session_t * session, const char * nick, const char * addr, const char * filename, unsigned long size, irc_dcc_t dccid) -{ - FILE * fp; - printf ("DCC send [%d] requested from '%s' (%s): %s (%lu bytes)\n", dccid, nick, addr, filename, size); - - if ( (fp = fopen ("file", "wb")) == 0 ) - abort(); - - irc_dcc_accept (session, dccid, fp, dcc_file_recv_callback); -} - void event_numeric (irc_session_t * session, unsigned int event, const char * origin, const char ** params, unsigned int count) { - char buf[24]; - sprintf (buf, "%d", event); + char buf[24]; + sprintf (buf, "%d", event); - dump_event (session, buf, origin, params, count); + dump_event (session, buf, origin, params, count); } irc_session_t* do_connect() @@ -1018,8 +901,6 @@ int start (int max_wait) gettimeofday(&tp1, NULL); - /* this is here early in order to get the connection working asap - * TODO refactor it with the other copy! */ if (!args.ready) { waiting = 0; @@ -1106,15 +987,11 @@ int main (int argc, char **argv) { initialize_args(); - //debug_args(); argp_parse (&argp, argc, argv, 0, 0, &args); strncpy(args.last_chan_in, first_chan(), MAX_LEN-1); strncpy(args.last_chans_out, first_chan(), MAX_LEN-1); - //debug_args(); - - return start(args.retry_after); }